cp210x.c (ebfb319bb601e501f77809a83b0b69b529c22a8d) cp210x.c (e2ae67a3b55188b0342522d8139acf013feb2a69)
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.

--- 29 unchanged lines hidden (view full) ---

38 struct ktermios *);
39static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *,
40 struct ktermios*);
41static int cp210x_tiocmget(struct tty_struct *);
42static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int);
43static int cp210x_tiocmset_port(struct usb_serial_port *port,
44 unsigned int, unsigned int);
45static void cp210x_break_ctl(struct tty_struct *, int);
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.

--- 29 unchanged lines hidden (view full) ---

38 struct ktermios *);
39static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *,
40 struct ktermios*);
41static int cp210x_tiocmget(struct tty_struct *);
42static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int);
43static int cp210x_tiocmset_port(struct usb_serial_port *port,
44 unsigned int, unsigned int);
45static void cp210x_break_ctl(struct tty_struct *, int);
46static int cp210x_startup(struct usb_serial *);
47static void cp210x_release(struct usb_serial *);
46static int cp210x_port_probe(struct usb_serial_port *);
47static int cp210x_port_remove(struct usb_serial_port *);
48static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
49
50static const struct usb_device_id id_table[] = {
51 { USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */
52 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
53 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
54 { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
55 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */

--- 136 unchanged lines hidden (view full) ---

192 { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */
193 { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */
194 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
195 { } /* Terminating Entry */
196};
197
198MODULE_DEVICE_TABLE(usb, id_table);
199
48static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
49
50static const struct usb_device_id id_table[] = {
51 { USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */
52 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
53 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
54 { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
55 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */

--- 136 unchanged lines hidden (view full) ---

192 { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */
193 { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */
194 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
195 { } /* Terminating Entry */
196};
197
198MODULE_DEVICE_TABLE(usb, id_table);
199
200struct cp210x_serial_private {
200struct cp210x_port_private {
201 __u8 bInterfaceNumber;
202};
203
204static struct usb_serial_driver cp210x_device = {
205 .driver = {
206 .owner = THIS_MODULE,
207 .name = "cp210x",
208 },
209 .id_table = id_table,
210 .num_ports = 1,
211 .bulk_in_size = 256,
212 .bulk_out_size = 256,
213 .open = cp210x_open,
214 .close = cp210x_close,
215 .break_ctl = cp210x_break_ctl,
216 .set_termios = cp210x_set_termios,
217 .tiocmget = cp210x_tiocmget,
218 .tiocmset = cp210x_tiocmset,
201 __u8 bInterfaceNumber;
202};
203
204static struct usb_serial_driver cp210x_device = {
205 .driver = {
206 .owner = THIS_MODULE,
207 .name = "cp210x",
208 },
209 .id_table = id_table,
210 .num_ports = 1,
211 .bulk_in_size = 256,
212 .bulk_out_size = 256,
213 .open = cp210x_open,
214 .close = cp210x_close,
215 .break_ctl = cp210x_break_ctl,
216 .set_termios = cp210x_set_termios,
217 .tiocmget = cp210x_tiocmget,
218 .tiocmset = cp210x_tiocmset,
219 .attach = cp210x_startup,
220 .release = cp210x_release,
219 .port_probe = cp210x_port_probe,
220 .port_remove = cp210x_port_remove,
221 .dtr_rts = cp210x_dtr_rts
222};
223
224static struct usb_serial_driver * const serial_drivers[] = {
225 &cp210x_device, NULL
226};
227
228/* Config request types */

--- 85 unchanged lines hidden (view full) ---

314 * 'size' is specified in bytes.
315 * 'data' is a pointer to a pre-allocated array of integers large
316 * enough to hold 'size' bytes (with 4 bytes to each integer)
317 */
318static int cp210x_get_config(struct usb_serial_port *port, u8 request,
319 unsigned int *data, int size)
320{
321 struct usb_serial *serial = port->serial;
221 .dtr_rts = cp210x_dtr_rts
222};
223
224static struct usb_serial_driver * const serial_drivers[] = {
225 &cp210x_device, NULL
226};
227
228/* Config request types */

--- 85 unchanged lines hidden (view full) ---

314 * 'size' is specified in bytes.
315 * 'data' is a pointer to a pre-allocated array of integers large
316 * enough to hold 'size' bytes (with 4 bytes to each integer)
317 */
318static int cp210x_get_config(struct usb_serial_port *port, u8 request,
319 unsigned int *data, int size)
320{
321 struct usb_serial *serial = port->serial;
322 struct cp210x_serial_private *spriv = usb_get_serial_data(serial);
322 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
323 __le32 *buf;
324 int result, i, length;
325
326 /* Number of integers required to contain the array */
327 length = (((size - 1) | 3) + 1) / 4;
328
329 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL);
330 if (!buf)
331 return -ENOMEM;
332
333 /* Issue the request, attempting to read 'size' bytes */
334 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
335 request, REQTYPE_INTERFACE_TO_HOST, 0x0000,
323 __le32 *buf;
324 int result, i, length;
325
326 /* Number of integers required to contain the array */
327 length = (((size - 1) | 3) + 1) / 4;
328
329 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL);
330 if (!buf)
331 return -ENOMEM;
332
333 /* Issue the request, attempting to read 'size' bytes */
334 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
335 request, REQTYPE_INTERFACE_TO_HOST, 0x0000,
336 spriv->bInterfaceNumber, buf, size,
336 port_priv->bInterfaceNumber, buf, size,
337 USB_CTRL_GET_TIMEOUT);
338
339 /* Convert data into an array of integers */
340 for (i = 0; i < length; i++)
341 data[i] = le32_to_cpu(buf[i]);
342
343 kfree(buf);
344

--- 14 unchanged lines hidden (view full) ---

359 * Writes to the CP210x configuration registers
360 * Values less than 16 bits wide are sent directly
361 * 'size' is specified in bytes.
362 */
363static int cp210x_set_config(struct usb_serial_port *port, u8 request,
364 unsigned int *data, int size)
365{
366 struct usb_serial *serial = port->serial;
337 USB_CTRL_GET_TIMEOUT);
338
339 /* Convert data into an array of integers */
340 for (i = 0; i < length; i++)
341 data[i] = le32_to_cpu(buf[i]);
342
343 kfree(buf);
344

--- 14 unchanged lines hidden (view full) ---

359 * Writes to the CP210x configuration registers
360 * Values less than 16 bits wide are sent directly
361 * 'size' is specified in bytes.
362 */
363static int cp210x_set_config(struct usb_serial_port *port, u8 request,
364 unsigned int *data, int size)
365{
366 struct usb_serial *serial = port->serial;
367 struct cp210x_serial_private *spriv = usb_get_serial_data(serial);
367 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
368 __le32 *buf;
369 int result, i, length;
370
371 /* Number of integers required to contain the array */
372 length = (((size - 1) | 3) + 1) / 4;
373
374 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL);
375 if (!buf)
376 return -ENOMEM;
377
378 /* Array of integers into bytes */
379 for (i = 0; i < length; i++)
380 buf[i] = cpu_to_le32(data[i]);
381
382 if (size > 2) {
383 result = usb_control_msg(serial->dev,
384 usb_sndctrlpipe(serial->dev, 0),
385 request, REQTYPE_HOST_TO_INTERFACE, 0x0000,
368 __le32 *buf;
369 int result, i, length;
370
371 /* Number of integers required to contain the array */
372 length = (((size - 1) | 3) + 1) / 4;
373
374 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL);
375 if (!buf)
376 return -ENOMEM;
377
378 /* Array of integers into bytes */
379 for (i = 0; i < length; i++)
380 buf[i] = cpu_to_le32(data[i]);
381
382 if (size > 2) {
383 result = usb_control_msg(serial->dev,
384 usb_sndctrlpipe(serial->dev, 0),
385 request, REQTYPE_HOST_TO_INTERFACE, 0x0000,
386 spriv->bInterfaceNumber, buf, size,
386 port_priv->bInterfaceNumber, buf, size,
387 USB_CTRL_SET_TIMEOUT);
388 } else {
389 result = usb_control_msg(serial->dev,
390 usb_sndctrlpipe(serial->dev, 0),
391 request, REQTYPE_HOST_TO_INTERFACE, data[0],
387 USB_CTRL_SET_TIMEOUT);
388 } else {
389 result = usb_control_msg(serial->dev,
390 usb_sndctrlpipe(serial->dev, 0),
391 request, REQTYPE_HOST_TO_INTERFACE, data[0],
392 spriv->bInterfaceNumber, NULL, 0,
392 port_priv->bInterfaceNumber, NULL, 0,
393 USB_CTRL_SET_TIMEOUT);
394 }
395
396 kfree(buf);
397
398 if ((size > 2 && result != size) || result < 0) {
399 dev_dbg(&port->dev, "%s - Unable to send request, request=0x%x size=%d result=%d\n",
400 __func__, request, size, result);

--- 472 unchanged lines hidden (view full) ---

873 state = BREAK_OFF;
874 else
875 state = BREAK_ON;
876 dev_dbg(&port->dev, "%s - turning break %s\n", __func__,
877 state == BREAK_OFF ? "off" : "on");
878 cp210x_set_config(port, CP210X_SET_BREAK, &state, 2);
879}
880
393 USB_CTRL_SET_TIMEOUT);
394 }
395
396 kfree(buf);
397
398 if ((size > 2 && result != size) || result < 0) {
399 dev_dbg(&port->dev, "%s - Unable to send request, request=0x%x size=%d result=%d\n",
400 __func__, request, size, result);

--- 472 unchanged lines hidden (view full) ---

873 state = BREAK_OFF;
874 else
875 state = BREAK_ON;
876 dev_dbg(&port->dev, "%s - turning break %s\n", __func__,
877 state == BREAK_OFF ? "off" : "on");
878 cp210x_set_config(port, CP210X_SET_BREAK, &state, 2);
879}
880
881static int cp210x_startup(struct usb_serial *serial)
881static int cp210x_port_probe(struct usb_serial_port *port)
882{
882{
883 struct usb_serial *serial = port->serial;
883 struct usb_host_interface *cur_altsetting;
884 struct usb_host_interface *cur_altsetting;
884 struct cp210x_serial_private *spriv;
885 struct cp210x_port_private *port_priv;
885
886
886 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
887 if (!spriv)
887 port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL);
888 if (!port_priv)
888 return -ENOMEM;
889
890 cur_altsetting = serial->interface->cur_altsetting;
889 return -ENOMEM;
890
891 cur_altsetting = serial->interface->cur_altsetting;
891 spriv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber;
892 port_priv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber;
892
893
893 usb_set_serial_data(serial, spriv);
894 usb_set_serial_port_data(port, port_priv);
894
895 return 0;
896}
897
895
896 return 0;
897}
898
898static void cp210x_release(struct usb_serial *serial)
899static int cp210x_port_remove(struct usb_serial_port *port)
899{
900{
900 struct cp210x_serial_private *spriv;
901 struct cp210x_port_private *port_priv;
901
902
902 spriv = usb_get_serial_data(serial);
903 kfree(spriv);
903 port_priv = usb_get_serial_port_data(port);
904 kfree(port_priv);
905
906 return 0;
904}
905
906module_usb_serial_driver(serial_drivers, id_table);
907
908MODULE_DESCRIPTION(DRIVER_DESC);
909MODULE_LICENSE("GPL");
907}
908
909module_usb_serial_driver(serial_drivers, id_table);
910
911MODULE_DESCRIPTION(DRIVER_DESC);
912MODULE_LICENSE("GPL");