cp210x.c (31271e9aacaa3c3460cbad8ec62fb5a04a522f5b) | cp210x.c (4f2ab8887479bef2204878ed6d633a515a3e6a0d) |
---|---|
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. --- 21 unchanged lines hidden (view full) --- 30#define DRIVER_VERSION "v0.09" 31#define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver" 32 33/* 34 * Function Prototypes 35 */ 36static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *); 37static void cp210x_close(struct usb_serial_port *); | 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. --- 21 unchanged lines hidden (view full) --- 30#define DRIVER_VERSION "v0.09" 31#define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver" 32 33/* 34 * Function Prototypes 35 */ 36static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *); 37static void cp210x_close(struct usb_serial_port *); |
38static void cp210x_get_termios(struct tty_struct *, 39 struct usb_serial_port *port); | 38static void cp210x_get_termios(struct tty_struct *, struct usb_serial_port *); |
40static void cp210x_get_termios_port(struct usb_serial_port *port, 41 unsigned int *cflagp, unsigned int *baudp); 42static void cp210x_change_speed(struct tty_struct *, struct usb_serial_port *, 43 struct ktermios *); 44static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *, 45 struct ktermios*); 46static int cp210x_tiocmget(struct tty_struct *); 47static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int); --- 116 unchanged lines hidden (view full) --- 164 165struct cp210x_serial_private { 166 __u8 bInterfaceNumber; 167}; 168 169static struct usb_serial_driver cp210x_device = { 170 .driver = { 171 .owner = THIS_MODULE, | 39static void cp210x_get_termios_port(struct usb_serial_port *port, 40 unsigned int *cflagp, unsigned int *baudp); 41static void cp210x_change_speed(struct tty_struct *, struct usb_serial_port *, 42 struct ktermios *); 43static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *, 44 struct ktermios*); 45static int cp210x_tiocmget(struct tty_struct *); 46static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int); --- 116 unchanged lines hidden (view full) --- 163 164struct cp210x_serial_private { 165 __u8 bInterfaceNumber; 166}; 167 168static struct usb_serial_driver cp210x_device = { 169 .driver = { 170 .owner = THIS_MODULE, |
172 .name = "cp210x", | 171 .name = "cp210x", |
173 }, 174 .id_table = id_table, 175 .num_ports = 1, 176 .bulk_in_size = 256, 177 .bulk_out_size = 256, 178 .open = cp210x_open, 179 .close = cp210x_close, 180 .break_ctl = cp210x_break_ctl, 181 .set_termios = cp210x_set_termios, | 172 }, 173 .id_table = id_table, 174 .num_ports = 1, 175 .bulk_in_size = 256, 176 .bulk_out_size = 256, 177 .open = cp210x_open, 178 .close = cp210x_close, 179 .break_ctl = cp210x_break_ctl, 180 .set_termios = cp210x_set_termios, |
182 .tiocmget = cp210x_tiocmget, | 181 .tiocmget = cp210x_tiocmget, |
183 .tiocmset = cp210x_tiocmset, 184 .attach = cp210x_startup, 185 .release = cp210x_release, 186 .dtr_rts = cp210x_dtr_rts 187}; 188 189static struct usb_serial_driver * const serial_drivers[] = { 190 &cp210x_device, NULL --- 85 unchanged lines hidden (view full) --- 276 unsigned int *data, int size) 277{ 278 struct usb_serial *serial = port->serial; 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 */ | 182 .tiocmset = cp210x_tiocmset, 183 .attach = cp210x_startup, 184 .release = cp210x_release, 185 .dtr_rts = cp210x_dtr_rts 186}; 187 188static struct usb_serial_driver * const serial_drivers[] = { 189 &cp210x_device, NULL --- 85 unchanged lines hidden (view full) --- 275 unsigned int *data, int size) 276{ 277 struct usb_serial *serial = port->serial; 278 struct cp210x_serial_private *spriv = usb_get_serial_data(serial); 279 __le32 *buf; 280 int result, i, length; 281 282 /* Number of integers required to contain the array */ |
284 length = (((size - 1) | 3) + 1)/4; | 283 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 */ --- 30 unchanged lines hidden (view full) --- 323 unsigned int *data, int size) 324{ 325 struct usb_serial *serial = port->serial; 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 */ | 284 285 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL); 286 if (!buf) { 287 dev_err(&port->dev, "%s - out of memory.\n", __func__); 288 return -ENOMEM; 289 } 290 291 /* Issue the request, attempting to read 'size' bytes */ --- 30 unchanged lines hidden (view full) --- 322 unsigned int *data, int size) 323{ 324 struct usb_serial *serial = port->serial; 325 struct cp210x_serial_private *spriv = usb_get_serial_data(serial); 326 __le32 *buf; 327 int result, i, length; 328 329 /* Number of integers required to contain the array */ |
331 length = (((size - 1) | 3) + 1)/4; | 330 length = (((size - 1) | 3) + 1) / 4; |
332 333 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL); 334 if (!buf) { | 331 332 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL); 333 if (!buf) { |
335 dev_err(&port->dev, "%s - out of memory.\n", 336 __func__); | 334 dev_err(&port->dev, "%s - out of memory.\n", __func__); |
337 return -ENOMEM; 338 } 339 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) { --- 34 unchanged lines hidden (view full) --- 379{ 380 return cp210x_set_config(port, request, &data, 2); 381} 382 383/* 384 * cp210x_quantise_baudrate 385 * Quantises the baud rate as per AN205 Table 1 386 */ | 335 return -ENOMEM; 336 } 337 338 /* Array of integers into bytes */ 339 for (i = 0; i < length; i++) 340 buf[i] = cpu_to_le32(data[i]); 341 342 if (size > 2) { --- 34 unchanged lines hidden (view full) --- 377{ 378 return cp210x_set_config(port, request, &data, 2); 379} 380 381/* 382 * cp210x_quantise_baudrate 383 * Quantises the baud rate as per AN205 Table 1 384 */ |
387static unsigned int cp210x_quantise_baudrate(unsigned int baud) { | 385static unsigned int cp210x_quantise_baudrate(unsigned int baud) 386{ |
388 if (baud <= 300) 389 baud = 300; 390 else if (baud <= 600) baud = 600; 391 else if (baud <= 1200) baud = 1200; 392 else if (baud <= 1800) baud = 1800; 393 else if (baud <= 2400) baud = 2400; 394 else if (baud <= 4000) baud = 4000; 395 else if (baud <= 4803) baud = 4800; --- 66 unchanged lines hidden (view full) --- 462 struct usb_serial_port *port) 463{ 464 unsigned int baud; 465 466 if (tty) { 467 cp210x_get_termios_port(tty->driver_data, 468 &tty->termios.c_cflag, &baud); 469 tty_encode_baud_rate(tty, baud, baud); | 387 if (baud <= 300) 388 baud = 300; 389 else if (baud <= 600) baud = 600; 390 else if (baud <= 1200) baud = 1200; 391 else if (baud <= 1800) baud = 1800; 392 else if (baud <= 2400) baud = 2400; 393 else if (baud <= 4000) baud = 4000; 394 else if (baud <= 4803) baud = 4800; --- 66 unchanged lines hidden (view full) --- 461 struct usb_serial_port *port) 462{ 463 unsigned int baud; 464 465 if (tty) { 466 cp210x_get_termios_port(tty->driver_data, 467 &tty->termios.c_cflag, &baud); 468 tty_encode_baud_rate(tty, baud, baud); |
470 } 471 472 else { | 469 } else { |
473 unsigned int cflag; 474 cflag = 0; 475 cp210x_get_termios_port(port, &cflag, &baud); 476 } 477} 478 479/* 480 * cp210x_get_termios_port --- 207 unchanged lines hidden (view full) --- 688 dev_dbg(dev, "%s - data bits = 8\n", __func__); 689 break; 690 /*case CS9: 691 bits |= BITS_DATA_9; 692 dev_dbg(dev, "%s - data bits = 9\n", __func__); 693 break;*/ 694 default: 695 dev_dbg(dev, "cp210x driver does not support the number of bits requested, using 8 bit mode\n"); | 470 unsigned int cflag; 471 cflag = 0; 472 cp210x_get_termios_port(port, &cflag, &baud); 473 } 474} 475 476/* 477 * cp210x_get_termios_port --- 207 unchanged lines hidden (view full) --- 685 dev_dbg(dev, "%s - data bits = 8\n", __func__); 686 break; 687 /*case CS9: 688 bits |= BITS_DATA_9; 689 dev_dbg(dev, "%s - data bits = 9\n", __func__); 690 break;*/ 691 default: 692 dev_dbg(dev, "cp210x driver does not support the number of bits requested, using 8 bit mode\n"); |
696 bits |= BITS_DATA_8; 697 break; | 693 bits |= BITS_DATA_8; 694 break; |
698 } 699 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) 700 dev_dbg(dev, "Number of data bits requested not supported by device\n"); 701 } 702 703 if ((cflag & (PARENB|PARODD|CMSPAR)) != 704 (old_cflag & (PARENB|PARODD|CMSPAR))) { 705 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); --- 56 unchanged lines hidden (view full) --- 762 dev_dbg(dev, "%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x\n", 763 __func__, modem_ctl[0], modem_ctl[1], 764 modem_ctl[2], modem_ctl[3]); 765 cp210x_set_config(port, CP210X_SET_FLOW, modem_ctl, 16); 766 } 767 768} 769 | 695 } 696 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2)) 697 dev_dbg(dev, "Number of data bits requested not supported by device\n"); 698 } 699 700 if ((cflag & (PARENB|PARODD|CMSPAR)) != 701 (old_cflag & (PARENB|PARODD|CMSPAR))) { 702 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2); --- 56 unchanged lines hidden (view full) --- 759 dev_dbg(dev, "%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x\n", 760 __func__, modem_ctl[0], modem_ctl[1], 761 modem_ctl[2], modem_ctl[3]); 762 cp210x_set_config(port, CP210X_SET_FLOW, modem_ctl, 16); 763 } 764 765} 766 |
770static int cp210x_tiocmset (struct tty_struct *tty, | 767static int cp210x_tiocmset(struct tty_struct *tty, |
771 unsigned int set, unsigned int clear) 772{ 773 struct usb_serial_port *port = tty->driver_data; 774 return cp210x_tiocmset_port(port, set, clear); 775} 776 777static int cp210x_tiocmset_port(struct usb_serial_port *port, 778 unsigned int set, unsigned int clear) --- 25 unchanged lines hidden (view full) --- 804static void cp210x_dtr_rts(struct usb_serial_port *p, int on) 805{ 806 if (on) 807 cp210x_tiocmset_port(p, TIOCM_DTR|TIOCM_RTS, 0); 808 else 809 cp210x_tiocmset_port(p, 0, TIOCM_DTR|TIOCM_RTS); 810} 811 | 768 unsigned int set, unsigned int clear) 769{ 770 struct usb_serial_port *port = tty->driver_data; 771 return cp210x_tiocmset_port(port, set, clear); 772} 773 774static int cp210x_tiocmset_port(struct usb_serial_port *port, 775 unsigned int set, unsigned int clear) --- 25 unchanged lines hidden (view full) --- 801static void cp210x_dtr_rts(struct usb_serial_port *p, int on) 802{ 803 if (on) 804 cp210x_tiocmset_port(p, TIOCM_DTR|TIOCM_RTS, 0); 805 else 806 cp210x_tiocmset_port(p, 0, TIOCM_DTR|TIOCM_RTS); 807} 808 |
812static int cp210x_tiocmget (struct tty_struct *tty) | 809static int cp210x_tiocmget(struct tty_struct *tty) |
813{ 814 struct usb_serial_port *port = tty->driver_data; 815 unsigned int control; 816 int result; 817 818 cp210x_get_config(port, CP210X_GET_MDMSTS, &control, 1); 819 820 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) 821 |((control & CONTROL_RTS) ? TIOCM_RTS : 0) 822 |((control & CONTROL_CTS) ? TIOCM_CTS : 0) 823 |((control & CONTROL_DSR) ? TIOCM_DSR : 0) 824 |((control & CONTROL_RING)? TIOCM_RI : 0) 825 |((control & CONTROL_DCD) ? TIOCM_CD : 0); 826 827 dev_dbg(&port->dev, "%s - control = 0x%.2x\n", __func__, control); 828 829 return result; 830} 831 | 810{ 811 struct usb_serial_port *port = tty->driver_data; 812 unsigned int control; 813 int result; 814 815 cp210x_get_config(port, CP210X_GET_MDMSTS, &control, 1); 816 817 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) 818 |((control & CONTROL_RTS) ? TIOCM_RTS : 0) 819 |((control & CONTROL_CTS) ? TIOCM_CTS : 0) 820 |((control & CONTROL_DSR) ? TIOCM_DSR : 0) 821 |((control & CONTROL_RING)? TIOCM_RI : 0) 822 |((control & CONTROL_DCD) ? TIOCM_CD : 0); 823 824 dev_dbg(&port->dev, "%s - control = 0x%.2x\n", __func__, control); 825 826 return result; 827} 828 |
832static void cp210x_break_ctl (struct tty_struct *tty, int break_state) | 829static void cp210x_break_ctl(struct tty_struct *tty, int break_state) |
833{ 834 struct usb_serial_port *port = tty->driver_data; 835 unsigned int state; 836 837 if (break_state == 0) 838 state = BREAK_OFF; 839 else 840 state = BREAK_ON; --- 38 unchanged lines hidden --- | 830{ 831 struct usb_serial_port *port = tty->driver_data; 832 unsigned int state; 833 834 if (break_state == 0) 835 state = BREAK_OFF; 836 else 837 state = BREAK_ON; --- 38 unchanged lines hidden --- |