cp210x.c (fb0b82b32ce17564bc64cede50bf4a3204eecc60) | cp210x.c (274f3b1e82c899fd1b39822c2ee39bbac52f3d3c) |
---|---|
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. --- 140 unchanged lines hidden (view full) --- 149 150MODULE_DEVICE_TABLE(usb, id_table); 151 152static struct usb_driver cp210x_driver = { 153 .name = "cp210x", 154 .probe = usb_serial_probe, 155 .disconnect = usb_serial_disconnect, 156 .id_table = id_table, | 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. --- 140 unchanged lines hidden (view full) --- 149 150MODULE_DEVICE_TABLE(usb, id_table); 151 152static struct usb_driver cp210x_driver = { 153 .name = "cp210x", 154 .probe = usb_serial_probe, 155 .disconnect = usb_serial_disconnect, 156 .id_table = id_table, |
157 .no_dynamic_id = 1, | |
158}; 159 160static struct usb_serial_driver cp210x_device = { 161 .driver = { 162 .owner = THIS_MODULE, 163 .name = "cp210x", 164 }, | 157}; 158 159static struct usb_serial_driver cp210x_device = { 160 .driver = { 161 .owner = THIS_MODULE, 162 .name = "cp210x", 163 }, |
165 .usb_driver = &cp210x_driver, | |
166 .id_table = id_table, 167 .num_ports = 1, 168 .bulk_in_size = 256, 169 .bulk_out_size = 256, 170 .open = cp210x_open, 171 .close = cp210x_close, 172 .break_ctl = cp210x_break_ctl, 173 .set_termios = cp210x_set_termios, 174 .tiocmget = cp210x_tiocmget, 175 .tiocmset = cp210x_tiocmset, 176 .attach = cp210x_startup, 177 .dtr_rts = cp210x_dtr_rts 178}; 179 | 164 .id_table = id_table, 165 .num_ports = 1, 166 .bulk_in_size = 256, 167 .bulk_out_size = 256, 168 .open = cp210x_open, 169 .close = cp210x_close, 170 .break_ctl = cp210x_break_ctl, 171 .set_termios = cp210x_set_termios, 172 .tiocmget = cp210x_tiocmget, 173 .tiocmset = cp210x_tiocmset, 174 .attach = cp210x_startup, 175 .dtr_rts = cp210x_dtr_rts 176}; 177 |
178static struct usb_serial_driver * const serial_drivers[] = { 179 &cp210x_device, NULL 180}; 181 |
|
180/* Config request types */ 181#define REQTYPE_HOST_TO_DEVICE 0x41 182#define REQTYPE_DEVICE_TO_HOST 0xc1 183 184/* Config request codes */ 185#define CP210X_IFC_ENABLE 0x00 186#define CP210X_SET_BAUDDIV 0x01 187#define CP210X_GET_BAUDDIV 0x02 --- 93 unchanged lines hidden (view full) --- 281 /* Convert data into an array of integers */ 282 for (i = 0; i < length; i++) 283 data[i] = le32_to_cpu(buf[i]); 284 285 kfree(buf); 286 287 if (result != size) { 288 dbg("%s - Unable to send config request, " | 182/* Config request types */ 183#define REQTYPE_HOST_TO_DEVICE 0x41 184#define REQTYPE_DEVICE_TO_HOST 0xc1 185 186/* Config request codes */ 187#define CP210X_IFC_ENABLE 0x00 188#define CP210X_SET_BAUDDIV 0x01 189#define CP210X_GET_BAUDDIV 0x02 --- 93 unchanged lines hidden (view full) --- 283 /* Convert data into an array of integers */ 284 for (i = 0; i < length; i++) 285 data[i] = le32_to_cpu(buf[i]); 286 287 kfree(buf); 288 289 if (result != size) { 290 dbg("%s - Unable to send config request, " |
289 "request=0x%x size=%d result=%d\n", | 291 "request=0x%x size=%d result=%d", |
290 __func__, request, size, result); 291 if (result > 0) 292 result = -EPROTO; 293 294 return result; 295 } 296 297 return 0; --- 37 unchanged lines hidden (view full) --- 335 request, REQTYPE_HOST_TO_DEVICE, data[0], 336 0, NULL, 0, 300); 337 } 338 339 kfree(buf); 340 341 if ((size > 2 && result != size) || result < 0) { 342 dbg("%s - Unable to send request, " | 292 __func__, request, size, result); 293 if (result > 0) 294 result = -EPROTO; 295 296 return result; 297 } 298 299 return 0; --- 37 unchanged lines hidden (view full) --- 337 request, REQTYPE_HOST_TO_DEVICE, data[0], 338 0, NULL, 0, 300); 339 } 340 341 kfree(buf); 342 343 if ((size > 2 && result != size) || result < 0) { 344 dbg("%s - Unable to send request, " |
343 "request=0x%x size=%d result=%d\n", | 345 "request=0x%x size=%d result=%d", |
344 __func__, request, size, result); 345 if (result > 0) 346 result = -EPROTO; 347 348 return result; 349 } 350 351 return 0; --- 326 unchanged lines hidden (view full) --- 678 break; 679 /*case CS9: 680 bits |= BITS_DATA_9; 681 dbg("%s - data bits = 9", __func__); 682 break;*/ 683 default: 684 dbg("cp210x driver does not " 685 "support the number of bits requested," | 346 __func__, request, size, result); 347 if (result > 0) 348 result = -EPROTO; 349 350 return result; 351 } 352 353 return 0; --- 326 unchanged lines hidden (view full) --- 680 break; 681 /*case CS9: 682 bits |= BITS_DATA_9; 683 dbg("%s - data bits = 9", __func__); 684 break;*/ 685 default: 686 dbg("cp210x driver does not " 687 "support the number of bits requested," |
686 " using 8 bit mode\n"); | 688 " using 8 bit mode"); |
687 bits |= BITS_DATA_8; 688 break; 689 } 690 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) 691 dbg("Number of data bits requested " | 689 bits |= BITS_DATA_8; 690 break; 691 } 692 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) 693 dbg("Number of data bits requested " |
692 "not supported by device\n"); | 694 "not supported by device"); |
693 } 694 695 if ((cflag & (PARENB|PARODD|CMSPAR)) != 696 (old_cflag & (PARENB|PARODD|CMSPAR))) { 697 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); 698 bits &= ~BITS_PARITY_MASK; 699 if (cflag & PARENB) { 700 if (cflag & CMSPAR) { --- 10 unchanged lines hidden (view full) --- 711 dbg("%s - parity = ODD", __func__); 712 } else { 713 bits |= BITS_PARITY_EVEN; 714 dbg("%s - parity = EVEN", __func__); 715 } 716 } 717 } 718 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) | 695 } 696 697 if ((cflag & (PARENB|PARODD|CMSPAR)) != 698 (old_cflag & (PARENB|PARODD|CMSPAR))) { 699 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); 700 bits &= ~BITS_PARITY_MASK; 701 if (cflag & PARENB) { 702 if (cflag & CMSPAR) { --- 10 unchanged lines hidden (view full) --- 713 dbg("%s - parity = ODD", __func__); 714 } else { 715 bits |= BITS_PARITY_EVEN; 716 dbg("%s - parity = EVEN", __func__); 717 } 718 } 719 } 720 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) |
719 dbg("Parity mode not supported " 720 "by device\n"); | 721 dbg("Parity mode not supported by device"); |
721 } 722 723 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { 724 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); 725 bits &= ~BITS_STOP_MASK; 726 if (cflag & CSTOPB) { 727 bits |= BITS_STOP_2; 728 dbg("%s - stop bits = 2", __func__); 729 } else { 730 bits |= BITS_STOP_1; 731 dbg("%s - stop bits = 1", __func__); 732 } 733 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) 734 dbg("Number of stop bits requested " | 722 } 723 724 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { 725 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); 726 bits &= ~BITS_STOP_MASK; 727 if (cflag & CSTOPB) { 728 bits |= BITS_STOP_2; 729 dbg("%s - stop bits = 2", __func__); 730 } else { 731 bits |= BITS_STOP_1; 732 dbg("%s - stop bits = 1", __func__); 733 } 734 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) 735 dbg("Number of stop bits requested " |
735 "not supported by device\n"); | 736 "not supported by device"); |
736 } 737 738 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { 739 cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16); 740 dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", 741 __func__, modem_ctl[0], modem_ctl[1], 742 modem_ctl[2], modem_ctl[3]); 743 --- 100 unchanged lines hidden (view full) --- 844 845static int cp210x_startup(struct usb_serial *serial) 846{ 847 /* cp210x buffers behave strangely unless device is reset */ 848 usb_reset_device(serial->dev); 849 return 0; 850} 851 | 737 } 738 739 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { 740 cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16); 741 dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", 742 __func__, modem_ctl[0], modem_ctl[1], 743 modem_ctl[2], modem_ctl[3]); 744 --- 100 unchanged lines hidden (view full) --- 845 846static int cp210x_startup(struct usb_serial *serial) 847{ 848 /* cp210x buffers behave strangely unless device is reset */ 849 usb_reset_device(serial->dev); 850 return 0; 851} 852 |
852static int __init cp210x_init(void) 853{ 854 int retval; | 853module_usb_serial_driver(cp210x_driver, serial_drivers); |
855 | 854 |
856 retval = usb_serial_register(&cp210x_device); 857 if (retval) 858 return retval; /* Failed to register */ 859 860 retval = usb_register(&cp210x_driver); 861 if (retval) { 862 /* Failed to register */ 863 usb_serial_deregister(&cp210x_device); 864 return retval; 865 } 866 867 /* Success */ 868 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 869 DRIVER_DESC "\n"); 870 return 0; 871} 872 873static void __exit cp210x_exit(void) 874{ 875 usb_deregister(&cp210x_driver); 876 usb_serial_deregister(&cp210x_device); 877} 878 879module_init(cp210x_init); 880module_exit(cp210x_exit); 881 | |
882MODULE_DESCRIPTION(DRIVER_DESC); 883MODULE_VERSION(DRIVER_VERSION); 884MODULE_LICENSE("GPL"); 885 886module_param(debug, bool, S_IRUGO | S_IWUSR); 887MODULE_PARM_DESC(debug, "Enable verbose debugging messages"); | 855MODULE_DESCRIPTION(DRIVER_DESC); 856MODULE_VERSION(DRIVER_VERSION); 857MODULE_LICENSE("GPL"); 858 859module_param(debug, bool, S_IRUGO | S_IWUSR); 860MODULE_PARM_DESC(debug, "Enable verbose debugging messages"); |