cp210x.c (e7d9facf0bab6d919342fea17c8cc0f65f8a0fe9) | cp210x.c (4295fe7791a1b20c90cbaaa6f23f2fb94218b8a7) |
---|---|
1/* 2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver 3 * 4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License version 8 * 2 as published by the Free Software Foundation. --- 148 unchanged lines hidden (view full) --- 157 { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */ 158 { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */ 159 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */ 160 { } /* Terminating Entry */ 161}; 162 163MODULE_DEVICE_TABLE(usb, id_table); 164 | 1/* 2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver 3 * 4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License version 8 * 2 as published by the Free Software Foundation. --- 148 unchanged lines hidden (view full) --- 157 { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */ 158 { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */ 159 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */ 160 { } /* Terminating Entry */ 161}; 162 163MODULE_DEVICE_TABLE(usb, id_table); 164 |
165struct cp210x_port_private { | 165struct cp210x_serial_private { |
166 __u8 bInterfaceNumber; 167}; 168 169static struct usb_serial_driver cp210x_device = { 170 .driver = { 171 .owner = THIS_MODULE, 172 .name = "cp210x", 173 }, --- 97 unchanged lines hidden (view full) --- 271 * 'size' is specified in bytes. 272 * 'data' is a pointer to a pre-allocated array of integers large 273 * enough to hold 'size' bytes (with 4 bytes to each integer) 274 */ 275static int cp210x_get_config(struct usb_serial_port *port, u8 request, 276 unsigned int *data, int size) 277{ 278 struct usb_serial *serial = port->serial; | 166 __u8 bInterfaceNumber; 167}; 168 169static struct usb_serial_driver cp210x_device = { 170 .driver = { 171 .owner = THIS_MODULE, 172 .name = "cp210x", 173 }, --- 97 unchanged lines hidden (view full) --- 271 * 'size' is specified in bytes. 272 * 'data' is a pointer to a pre-allocated array of integers large 273 * enough to hold 'size' bytes (with 4 bytes to each integer) 274 */ 275static int cp210x_get_config(struct usb_serial_port *port, u8 request, 276 unsigned int *data, int size) 277{ 278 struct usb_serial *serial = port->serial; |
279 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); | 279 struct cp210x_serial_private *spriv = usb_get_serial_data(serial); |
280 __le32 *buf; 281 int result, i, length; 282 283 /* Number of integers required to contain the array */ 284 length = (((size - 1) | 3) + 1)/4; 285 286 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL); 287 if (!buf) { 288 dev_err(&port->dev, "%s - out of memory.\n", __func__); 289 return -ENOMEM; 290 } 291 292 /* Issue the request, attempting to read 'size' bytes */ 293 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 294 request, REQTYPE_INTERFACE_TO_HOST, 0x0000, | 280 __le32 *buf; 281 int result, i, length; 282 283 /* Number of integers required to contain the array */ 284 length = (((size - 1) | 3) + 1)/4; 285 286 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL); 287 if (!buf) { 288 dev_err(&port->dev, "%s - out of memory.\n", __func__); 289 return -ENOMEM; 290 } 291 292 /* Issue the request, attempting to read 'size' bytes */ 293 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 294 request, REQTYPE_INTERFACE_TO_HOST, 0x0000, |
295 port_priv->bInterfaceNumber, buf, size, | 295 spriv->bInterfaceNumber, buf, size, |
296 USB_CTRL_GET_TIMEOUT); 297 298 /* Convert data into an array of integers */ 299 for (i = 0; i < length; i++) 300 data[i] = le32_to_cpu(buf[i]); 301 302 kfree(buf); 303 --- 14 unchanged lines hidden (view full) --- 318 * Writes to the CP210x configuration registers 319 * Values less than 16 bits wide are sent directly 320 * 'size' is specified in bytes. 321 */ 322static int cp210x_set_config(struct usb_serial_port *port, u8 request, 323 unsigned int *data, int size) 324{ 325 struct usb_serial *serial = port->serial; | 296 USB_CTRL_GET_TIMEOUT); 297 298 /* Convert data into an array of integers */ 299 for (i = 0; i < length; i++) 300 data[i] = le32_to_cpu(buf[i]); 301 302 kfree(buf); 303 --- 14 unchanged lines hidden (view full) --- 318 * Writes to the CP210x configuration registers 319 * Values less than 16 bits wide are sent directly 320 * 'size' is specified in bytes. 321 */ 322static int cp210x_set_config(struct usb_serial_port *port, u8 request, 323 unsigned int *data, int size) 324{ 325 struct usb_serial *serial = port->serial; |
326 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); | 326 struct cp210x_serial_private *spriv = usb_get_serial_data(serial); |
327 __le32 *buf; 328 int result, i, length; 329 330 /* Number of integers required to contain the array */ 331 length = (((size - 1) | 3) + 1)/4; 332 333 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL); 334 if (!buf) { --- 5 unchanged lines hidden (view full) --- 340 /* Array of integers into bytes */ 341 for (i = 0; i < length; i++) 342 buf[i] = cpu_to_le32(data[i]); 343 344 if (size > 2) { 345 result = usb_control_msg(serial->dev, 346 usb_sndctrlpipe(serial->dev, 0), 347 request, REQTYPE_HOST_TO_INTERFACE, 0x0000, | 327 __le32 *buf; 328 int result, i, length; 329 330 /* Number of integers required to contain the array */ 331 length = (((size - 1) | 3) + 1)/4; 332 333 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL); 334 if (!buf) { --- 5 unchanged lines hidden (view full) --- 340 /* Array of integers into bytes */ 341 for (i = 0; i < length; i++) 342 buf[i] = cpu_to_le32(data[i]); 343 344 if (size > 2) { 345 result = usb_control_msg(serial->dev, 346 usb_sndctrlpipe(serial->dev, 0), 347 request, REQTYPE_HOST_TO_INTERFACE, 0x0000, |
348 port_priv->bInterfaceNumber, buf, size, | 348 spriv->bInterfaceNumber, buf, size, |
349 USB_CTRL_SET_TIMEOUT); 350 } else { 351 result = usb_control_msg(serial->dev, 352 usb_sndctrlpipe(serial->dev, 0), 353 request, REQTYPE_HOST_TO_INTERFACE, data[0], | 349 USB_CTRL_SET_TIMEOUT); 350 } else { 351 result = usb_control_msg(serial->dev, 352 usb_sndctrlpipe(serial->dev, 0), 353 request, REQTYPE_HOST_TO_INTERFACE, data[0], |
354 port_priv->bInterfaceNumber, NULL, 0, | 354 spriv->bInterfaceNumber, NULL, 0, |
355 USB_CTRL_SET_TIMEOUT); 356 } 357 358 kfree(buf); 359 360 if ((size > 2 && result != size) || result < 0) { 361 dev_dbg(&port->dev, "%s - Unable to send request, request=0x%x size=%d result=%d\n", 362 __func__, request, size, result); --- 477 unchanged lines hidden (view full) --- 840 state = BREAK_ON; 841 dev_dbg(&port->dev, "%s - turning break %s\n", __func__, 842 state == BREAK_OFF ? "off" : "on"); 843 cp210x_set_config(port, CP210X_SET_BREAK, &state, 2); 844} 845 846static int cp210x_startup(struct usb_serial *serial) 847{ | 355 USB_CTRL_SET_TIMEOUT); 356 } 357 358 kfree(buf); 359 360 if ((size > 2 && result != size) || result < 0) { 361 dev_dbg(&port->dev, "%s - Unable to send request, request=0x%x size=%d result=%d\n", 362 __func__, request, size, result); --- 477 unchanged lines hidden (view full) --- 840 state = BREAK_ON; 841 dev_dbg(&port->dev, "%s - turning break %s\n", __func__, 842 state == BREAK_OFF ? "off" : "on"); 843 cp210x_set_config(port, CP210X_SET_BREAK, &state, 2); 844} 845 846static int cp210x_startup(struct usb_serial *serial) 847{ |
848 struct cp210x_port_private *port_priv; 849 int i; | 848 struct usb_host_interface *cur_altsetting; 849 struct cp210x_serial_private *spriv; |
850 851 /* cp210x buffers behave strangely unless device is reset */ 852 usb_reset_device(serial->dev); 853 | 850 851 /* cp210x buffers behave strangely unless device is reset */ 852 usb_reset_device(serial->dev); 853 |
854 for (i = 0; i < serial->num_ports; i++) { 855 port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); 856 if (!port_priv) 857 return -ENOMEM; | 854 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 855 if (!spriv) 856 return -ENOMEM; |
858 | 857 |
859 port_priv->bInterfaceNumber = 860 serial->interface->cur_altsetting->desc.bInterfaceNumber; | 858 cur_altsetting = serial->interface->cur_altsetting; 859 spriv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber; |
861 | 860 |
862 usb_set_serial_port_data(serial->port[i], port_priv); 863 } | 861 usb_set_serial_data(serial, spriv); |
864 865 return 0; 866} 867 868static void cp210x_release(struct usb_serial *serial) 869{ | 862 863 return 0; 864} 865 866static void cp210x_release(struct usb_serial *serial) 867{ |
870 struct cp210x_port_private *port_priv; 871 int i; | 868 struct cp210x_serial_private *spriv; |
872 | 869 |
873 for (i = 0; i < serial->num_ports; i++) { 874 port_priv = usb_get_serial_port_data(serial->port[i]); 875 kfree(port_priv); 876 usb_set_serial_port_data(serial->port[i], NULL); 877 } | 870 spriv = usb_get_serial_data(serial); 871 kfree(spriv); |
878} 879 880module_usb_serial_driver(serial_drivers, id_table); 881 882MODULE_DESCRIPTION(DRIVER_DESC); 883MODULE_VERSION(DRIVER_VERSION); 884MODULE_LICENSE("GPL"); | 872} 873 874module_usb_serial_driver(serial_drivers, id_table); 875 876MODULE_DESCRIPTION(DRIVER_DESC); 877MODULE_VERSION(DRIVER_VERSION); 878MODULE_LICENSE("GPL"); |