Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * MCT (Magic Control Technology Corp.) USB RS232 Converter Driver |
| 3 | * |
| 4 | * Copyright (C) 2000 Wolfgang Grandegger (wolfgang@ces.ch) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is largely derived from the Belkin USB Serial Adapter Driver |
| 12 | * (see belkin_sa.[ch]). All of the information about the device was acquired |
| 13 | * by using SniffUSB on Windows98. For technical details see mct_u232.h. |
| 14 | * |
| 15 | * William G. Greathouse and Greg Kroah-Hartman provided great help on how to |
| 16 | * do the reverse engineering and how to write a USB serial device driver. |
| 17 | * |
| 18 | * TO BE DONE, TO BE CHECKED: |
| 19 | * DTR/RTS signal handling may be incomplete or incorrect. I have mainly |
| 20 | * implemented what I have seen with SniffUSB or found in belkin_sa.c. |
| 21 | * For further TODOs check also belkin_sa.c. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | */ |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/kernel.h> |
| 25 | #include <linux/errno.h> |
| 26 | #include <linux/init.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/tty.h> |
| 29 | #include <linux/tty_driver.h> |
| 30 | #include <linux/tty_flip.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/spinlock.h> |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 33 | #include <linux/uaccess.h> |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 34 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 36 | #include <linux/usb/serial.h> |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 37 | #include <linux/serial.h> |
| 38 | #include <linux/ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "mct_u232.h" |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>" |
| 42 | #define DRIVER_DESC "Magic Control Technology USB-RS232 converter driver" |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* |
| 45 | * Function prototypes |
| 46 | */ |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 47 | static int mct_u232_startup(struct usb_serial *serial); |
Johan Hovold | a8f2ae7 | 2012-10-25 10:29:13 +0200 | [diff] [blame] | 48 | static int mct_u232_port_probe(struct usb_serial_port *port); |
| 49 | static int mct_u232_port_remove(struct usb_serial_port *remove); |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 50 | static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 51 | static void mct_u232_close(struct usb_serial_port *port); |
| 52 | static void mct_u232_dtr_rts(struct usb_serial_port *port, int on); |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 53 | static void mct_u232_read_int_callback(struct urb *urb); |
| 54 | static void mct_u232_set_termios(struct tty_struct *tty, |
| 55 | struct usb_serial_port *port, struct ktermios *old); |
| 56 | static void mct_u232_break_ctl(struct tty_struct *tty, int break_state); |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 57 | static int mct_u232_tiocmget(struct tty_struct *tty); |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 58 | static int mct_u232_tiocmset(struct tty_struct *tty, |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 59 | unsigned int set, unsigned int clear); |
Randy Dunlap | 4acfaf8 | 2011-04-03 11:42:00 -0700 | [diff] [blame] | 60 | static int mct_u232_ioctl(struct tty_struct *tty, |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 61 | unsigned int cmd, unsigned long arg); |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 62 | static void mct_u232_throttle(struct tty_struct *tty); |
| 63 | static void mct_u232_unthrottle(struct tty_struct *tty); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 64 | |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* |
| 67 | * All of the device info needed for the MCT USB-RS232 converter. |
| 68 | */ |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 69 | static const struct usb_device_id id_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { USB_DEVICE(MCT_U232_VID, MCT_U232_PID) }, |
| 71 | { USB_DEVICE(MCT_U232_VID, MCT_U232_SITECOM_PID) }, |
| 72 | { USB_DEVICE(MCT_U232_VID, MCT_U232_DU_H3SP_PID) }, |
| 73 | { USB_DEVICE(MCT_U232_BELKIN_F5U109_VID, MCT_U232_BELKIN_F5U109_PID) }, |
| 74 | { } /* Terminating entry */ |
| 75 | }; |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 76 | MODULE_DEVICE_TABLE(usb, id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 78 | static struct usb_serial_driver mct_u232_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 79 | .driver = { |
| 80 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 81 | .name = "mct_u232", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 82 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 83 | .description = "MCT U232", |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 84 | .id_table = id_table, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | .num_ports = 1, |
| 86 | .open = mct_u232_open, |
| 87 | .close = mct_u232_close, |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 88 | .dtr_rts = mct_u232_dtr_rts, |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 89 | .throttle = mct_u232_throttle, |
| 90 | .unthrottle = mct_u232_unthrottle, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | .read_int_callback = mct_u232_read_int_callback, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | .set_termios = mct_u232_set_termios, |
| 93 | .break_ctl = mct_u232_break_ctl, |
| 94 | .tiocmget = mct_u232_tiocmget, |
| 95 | .tiocmset = mct_u232_tiocmset, |
| 96 | .attach = mct_u232_startup, |
Johan Hovold | a8f2ae7 | 2012-10-25 10:29:13 +0200 | [diff] [blame] | 97 | .port_probe = mct_u232_port_probe, |
| 98 | .port_remove = mct_u232_port_remove, |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 99 | .ioctl = mct_u232_ioctl, |
Johan Hovold | 468c740 | 2013-03-21 12:37:12 +0100 | [diff] [blame^] | 100 | .get_icount = usb_serial_generic_get_icount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
Alan Stern | 4d2a7af | 2012-02-23 14:57:09 -0500 | [diff] [blame] | 103 | static struct usb_serial_driver * const serial_drivers[] = { |
| 104 | &mct_u232_device, NULL |
| 105 | }; |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | struct mct_u232_private { |
| 108 | spinlock_t lock; |
| 109 | unsigned int control_state; /* Modem Line Setting (TIOCM) */ |
| 110 | unsigned char last_lcr; /* Line Control Register */ |
| 111 | unsigned char last_lsr; /* Line Status Register */ |
| 112 | unsigned char last_msr; /* Modem Status Register */ |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 113 | unsigned int rx_flags; /* Throttling flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 116 | #define THROTTLED 0x01 |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | /* |
| 119 | * Handle vendor specific USB requests |
| 120 | */ |
| 121 | |
| 122 | #define WDR_TIMEOUT 5000 /* default urb timeout */ |
| 123 | |
| 124 | /* |
| 125 | * Later day 2.6.0-test kernels have new baud rates like B230400 which |
| 126 | * we do not know how to support. We ignore them for the moment. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | */ |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 128 | static int mct_u232_calculate_baud_rate(struct usb_serial *serial, |
| 129 | speed_t value, speed_t *result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
Alan Cox | d0fab0d | 2007-12-13 16:15:29 -0800 | [diff] [blame] | 131 | *result = value; |
| 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 134 | || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | switch (value) { |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 136 | case 300: |
| 137 | return 0x01; |
| 138 | case 600: |
| 139 | return 0x02; /* this one not tested */ |
| 140 | case 1200: |
| 141 | return 0x03; |
| 142 | case 2400: |
| 143 | return 0x04; |
| 144 | case 4800: |
| 145 | return 0x06; |
| 146 | case 9600: |
| 147 | return 0x08; |
| 148 | case 19200: |
| 149 | return 0x09; |
| 150 | case 38400: |
| 151 | return 0x0a; |
| 152 | case 57600: |
| 153 | return 0x0b; |
| 154 | case 115200: |
| 155 | return 0x0c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | default: |
Alan Cox | d0fab0d | 2007-12-13 16:15:29 -0800 | [diff] [blame] | 157 | *result = 9600; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | return 0x08; |
| 159 | } |
| 160 | } else { |
Alan Cox | d0fab0d | 2007-12-13 16:15:29 -0800 | [diff] [blame] | 161 | /* FIXME: Can we use any divider - should we do |
| 162 | divider = 115200/value; |
| 163 | real baud = 115200/divider */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | switch (value) { |
Andrew Morton | b3aceb2 | 2007-08-10 14:53:35 -0700 | [diff] [blame] | 165 | case 300: break; |
| 166 | case 600: break; |
| 167 | case 1200: break; |
| 168 | case 2400: break; |
| 169 | case 4800: break; |
| 170 | case 9600: break; |
| 171 | case 19200: break; |
| 172 | case 38400: break; |
| 173 | case 57600: break; |
| 174 | case 115200: break; |
| 175 | default: |
Andrew Morton | b3aceb2 | 2007-08-10 14:53:35 -0700 | [diff] [blame] | 176 | value = 9600; |
Alan Cox | d0fab0d | 2007-12-13 16:15:29 -0800 | [diff] [blame] | 177 | *result = 9600; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | return 115200/value; |
| 180 | } |
| 181 | } |
| 182 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 183 | static int mct_u232_set_baud_rate(struct tty_struct *tty, |
| 184 | struct usb_serial *serial, struct usb_serial_port *port, speed_t value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 186 | unsigned int divisor; |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 187 | int rc; |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 188 | unsigned char *buf; |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 189 | unsigned char cts_enable_byte = 0; |
| 190 | speed_t speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 192 | buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL); |
| 193 | if (buf == NULL) |
| 194 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 196 | divisor = mct_u232_calculate_baud_rate(serial, value, &speed); |
| 197 | put_unaligned_le32(cpu_to_le32(divisor), buf); |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 198 | rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
| 199 | MCT_U232_SET_BAUD_RATE_REQUEST, |
| 200 | MCT_U232_SET_REQUEST_TYPE, |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 201 | 0, 0, buf, MCT_U232_SET_BAUD_RATE_SIZE, |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 202 | WDR_TIMEOUT); |
Alan Cox | d0fab0d | 2007-12-13 16:15:29 -0800 | [diff] [blame] | 203 | if (rc < 0) /*FIXME: What value speed results */ |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 204 | dev_err(&port->dev, "Set BAUD RATE %d failed (error = %d)\n", |
| 205 | value, rc); |
Alan Cox | d0fab0d | 2007-12-13 16:15:29 -0800 | [diff] [blame] | 206 | else |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 207 | tty_encode_baud_rate(tty, speed, speed); |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 208 | dev_dbg(&port->dev, "set_baud_rate: value: 0x%x, divisor: 0x%x\n", value, divisor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which |
| 211 | always sends two extra USB 'device request' messages after the |
| 212 | 'baud rate change' message. The actual functionality of the |
| 213 | request codes in these messages is not fully understood but these |
| 214 | particular codes are never seen in any operation besides a baud |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 215 | rate change. Both of these messages send a single byte of data. |
| 216 | In the first message, the value of this byte is always zero. |
| 217 | |
| 218 | The second message has been determined experimentally to control |
| 219 | whether data will be transmitted to a device which is not asserting |
| 220 | the 'CTS' signal. If the second message's data byte is zero, data |
| 221 | will be transmitted even if 'CTS' is not asserted (i.e. no hardware |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 222 | flow control). if the second message's data byte is nonzero (a |
| 223 | value of 1 is used by this driver), data will not be transmitted to |
| 224 | a device which is not asserting 'CTS'. |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 225 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 227 | buf[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 229 | MCT_U232_SET_UNKNOWN1_REQUEST, |
| 230 | MCT_U232_SET_REQUEST_TYPE, |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 231 | 0, 0, buf, MCT_U232_SET_UNKNOWN1_SIZE, |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 232 | WDR_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (rc < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 234 | dev_err(&port->dev, "Sending USB device request code %d " |
| 235 | "failed (error = %d)\n", MCT_U232_SET_UNKNOWN1_REQUEST, |
| 236 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 238 | if (port && C_CRTSCTS(tty)) |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 239 | cts_enable_byte = 1; |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 240 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 241 | dev_dbg(&port->dev, "set_baud_rate: send second control message, data = %02X\n", |
| 242 | cts_enable_byte); |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 243 | buf[0] = cts_enable_byte; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 245 | MCT_U232_SET_CTS_REQUEST, |
| 246 | MCT_U232_SET_REQUEST_TYPE, |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 247 | 0, 0, buf, MCT_U232_SET_CTS_SIZE, |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 248 | WDR_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | if (rc < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 250 | dev_err(&port->dev, "Sending USB device request code %d " |
| 251 | "failed (error = %d)\n", MCT_U232_SET_CTS_REQUEST, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 253 | kfree(buf); |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 254 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } /* mct_u232_set_baud_rate */ |
| 256 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 257 | static int mct_u232_set_line_ctrl(struct usb_serial_port *port, |
| 258 | unsigned char lcr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 260 | int rc; |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 261 | unsigned char *buf; |
| 262 | |
| 263 | buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL); |
| 264 | if (buf == NULL) |
| 265 | return -ENOMEM; |
| 266 | |
| 267 | buf[0] = lcr; |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 268 | rc = usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0), |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 269 | MCT_U232_SET_LINE_CTRL_REQUEST, |
| 270 | MCT_U232_SET_REQUEST_TYPE, |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 271 | 0, 0, buf, MCT_U232_SET_LINE_CTRL_SIZE, |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 272 | WDR_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (rc < 0) |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 274 | dev_err(&port->dev, "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc); |
| 275 | dev_dbg(&port->dev, "set_line_ctrl: 0x%x\n", lcr); |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 276 | kfree(buf); |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 277 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } /* mct_u232_set_line_ctrl */ |
| 279 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 280 | static int mct_u232_set_modem_ctrl(struct usb_serial_port *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | unsigned int control_state) |
| 282 | { |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 283 | int rc; |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 284 | unsigned char mcr; |
| 285 | unsigned char *buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 287 | buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL); |
| 288 | if (buf == NULL) |
| 289 | return -ENOMEM; |
| 290 | |
| 291 | mcr = MCT_U232_MCR_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (control_state & TIOCM_DTR) |
| 293 | mcr |= MCT_U232_MCR_DTR; |
| 294 | if (control_state & TIOCM_RTS) |
| 295 | mcr |= MCT_U232_MCR_RTS; |
| 296 | |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 297 | buf[0] = mcr; |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 298 | rc = usb_control_msg(port->serial->dev, usb_sndctrlpipe(port->serial->dev, 0), |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 299 | MCT_U232_SET_MODEM_CTRL_REQUEST, |
| 300 | MCT_U232_SET_REQUEST_TYPE, |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 301 | 0, 0, buf, MCT_U232_SET_MODEM_CTRL_SIZE, |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 302 | WDR_TIMEOUT); |
Alan Cox | 1aa3c63 | 2012-05-22 20:45:13 +0100 | [diff] [blame] | 303 | kfree(buf); |
| 304 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 305 | dev_dbg(&port->dev, "set_modem_ctrl: state=0x%x ==> mcr=0x%x\n", control_state, mcr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Alan Cox | 1aa3c63 | 2012-05-22 20:45:13 +0100 | [diff] [blame] | 307 | if (rc < 0) { |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 308 | dev_err(&port->dev, "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc); |
Alan Cox | 1aa3c63 | 2012-05-22 20:45:13 +0100 | [diff] [blame] | 309 | return rc; |
| 310 | } |
| 311 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } /* mct_u232_set_modem_ctrl */ |
| 313 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 314 | static int mct_u232_get_modem_stat(struct usb_serial_port *port, |
| 315 | unsigned char *msr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | { |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 317 | int rc; |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 318 | unsigned char *buf; |
| 319 | |
| 320 | buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL); |
| 321 | if (buf == NULL) { |
| 322 | *msr = 0; |
| 323 | return -ENOMEM; |
| 324 | } |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 325 | rc = usb_control_msg(port->serial->dev, usb_rcvctrlpipe(port->serial->dev, 0), |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 326 | MCT_U232_GET_MODEM_STAT_REQUEST, |
| 327 | MCT_U232_GET_REQUEST_TYPE, |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 328 | 0, 0, buf, MCT_U232_GET_MODEM_STAT_SIZE, |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 329 | WDR_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (rc < 0) { |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 331 | dev_err(&port->dev, "Get MODEM STATus failed (error = %d)\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | *msr = 0; |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 333 | } else { |
| 334 | *msr = buf[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 336 | dev_dbg(&port->dev, "get_modem_stat: 0x%x\n", *msr); |
Pete Zaitcev | af2ac1a | 2009-12-07 20:29:05 -0700 | [diff] [blame] | 337 | kfree(buf); |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 338 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } /* mct_u232_get_modem_stat */ |
| 340 | |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 341 | static void mct_u232_msr_to_icount(struct async_icount *icount, |
| 342 | unsigned char msr) |
| 343 | { |
| 344 | /* Translate Control Line states */ |
| 345 | if (msr & MCT_U232_MSR_DDSR) |
| 346 | icount->dsr++; |
| 347 | if (msr & MCT_U232_MSR_DCTS) |
| 348 | icount->cts++; |
| 349 | if (msr & MCT_U232_MSR_DRI) |
| 350 | icount->rng++; |
| 351 | if (msr & MCT_U232_MSR_DCD) |
| 352 | icount->dcd++; |
| 353 | } /* mct_u232_msr_to_icount */ |
| 354 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 355 | static void mct_u232_msr_to_state(struct usb_serial_port *port, |
| 356 | unsigned int *control_state, unsigned char msr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 358 | /* Translate Control Line states */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (msr & MCT_U232_MSR_DSR) |
| 360 | *control_state |= TIOCM_DSR; |
| 361 | else |
| 362 | *control_state &= ~TIOCM_DSR; |
| 363 | if (msr & MCT_U232_MSR_CTS) |
| 364 | *control_state |= TIOCM_CTS; |
| 365 | else |
| 366 | *control_state &= ~TIOCM_CTS; |
| 367 | if (msr & MCT_U232_MSR_RI) |
| 368 | *control_state |= TIOCM_RI; |
| 369 | else |
| 370 | *control_state &= ~TIOCM_RI; |
| 371 | if (msr & MCT_U232_MSR_CD) |
| 372 | *control_state |= TIOCM_CD; |
| 373 | else |
| 374 | *control_state &= ~TIOCM_CD; |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 375 | dev_dbg(&port->dev, "msr_to_state: msr=0x%x ==> state=0x%x\n", msr, *control_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } /* mct_u232_msr_to_state */ |
| 377 | |
| 378 | /* |
| 379 | * Driver's tty interface functions |
| 380 | */ |
| 381 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 382 | static int mct_u232_startup(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | struct usb_serial_port *port, *rport; |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | /* Puh, that's dirty */ |
| 387 | port = serial->port[0]; |
| 388 | rport = serial->port[1]; |
Mariusz Kozlowski | 73135bb | 2006-11-08 15:36:42 +0100 | [diff] [blame] | 389 | /* No unlinking, it wasn't submitted yet. */ |
| 390 | usb_free_urb(port->read_urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | port->read_urb = rport->interrupt_in_urb; |
| 392 | rport->interrupt_in_urb = NULL; |
| 393 | port->read_urb->context = port; |
| 394 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 395 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } /* mct_u232_startup */ |
| 397 | |
Johan Hovold | a8f2ae7 | 2012-10-25 10:29:13 +0200 | [diff] [blame] | 398 | static int mct_u232_port_probe(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | { |
| 400 | struct mct_u232_private *priv; |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 401 | |
Johan Hovold | a8f2ae7 | 2012-10-25 10:29:13 +0200 | [diff] [blame] | 402 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 403 | if (!priv) |
| 404 | return -ENOMEM; |
| 405 | |
| 406 | spin_lock_init(&priv->lock); |
Johan Hovold | a8f2ae7 | 2012-10-25 10:29:13 +0200 | [diff] [blame] | 407 | |
| 408 | usb_set_serial_port_data(port, priv); |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | static int mct_u232_port_remove(struct usb_serial_port *port) |
| 414 | { |
| 415 | struct mct_u232_private *priv; |
| 416 | |
| 417 | priv = usb_get_serial_port_data(port); |
| 418 | kfree(priv); |
| 419 | |
| 420 | return 0; |
| 421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 423 | static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
| 425 | struct usb_serial *serial = port->serial; |
| 426 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
| 427 | int retval = 0; |
| 428 | unsigned int control_state; |
| 429 | unsigned long flags; |
| 430 | unsigned char last_lcr; |
| 431 | unsigned char last_msr; |
| 432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | /* Compensate for a hardware bug: although the Sitecom U232-P25 |
| 434 | * device reports a maximum output packet size of 32 bytes, |
| 435 | * it seems to be able to accept only 16 bytes (and that's what |
| 436 | * SniffUSB says too...) |
| 437 | */ |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 438 | if (le16_to_cpu(serial->dev->descriptor.idProduct) |
| 439 | == MCT_U232_SITECOM_PID) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | port->bulk_out_size = 16; |
| 441 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 442 | /* Do a defined restart: the normal serial device seems to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | * always turn on DTR and RTS here, so do the same. I'm not |
| 444 | * sure if this is really necessary. But it should not harm |
| 445 | * either. |
| 446 | */ |
| 447 | spin_lock_irqsave(&priv->lock, flags); |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 448 | if (tty && (tty->termios.c_cflag & CBAUD)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | priv->control_state = TIOCM_DTR | TIOCM_RTS; |
| 450 | else |
| 451 | priv->control_state = 0; |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 452 | |
| 453 | priv->last_lcr = (MCT_U232_DATA_BITS_8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | MCT_U232_PARITY_NONE | |
| 455 | MCT_U232_STOP_BITS_1); |
| 456 | control_state = priv->control_state; |
| 457 | last_lcr = priv->last_lcr; |
| 458 | spin_unlock_irqrestore(&priv->lock, flags); |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 459 | mct_u232_set_modem_ctrl(port, control_state); |
| 460 | mct_u232_set_line_ctrl(port, last_lcr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
| 462 | /* Read modem status and update control state */ |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 463 | mct_u232_get_modem_stat(port, &last_msr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | spin_lock_irqsave(&priv->lock, flags); |
| 465 | priv->last_msr = last_msr; |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 466 | mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | spin_unlock_irqrestore(&priv->lock, flags); |
| 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | retval = usb_submit_urb(port->read_urb, GFP_KERNEL); |
| 470 | if (retval) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 471 | dev_err(&port->dev, |
| 472 | "usb_submit_urb(read bulk) failed pipe 0x%x err %d\n", |
| 473 | port->read_urb->pipe, retval); |
Oliver Neukum | 2f007de | 2007-03-29 10:45:17 +0200 | [diff] [blame] | 474 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
Oliver Neukum | 2f007de | 2007-03-29 10:45:17 +0200 | [diff] [blame] | 478 | if (retval) { |
| 479 | usb_kill_urb(port->read_urb); |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 480 | dev_err(&port->dev, |
| 481 | "usb_submit_urb(read int) failed pipe 0x%x err %d", |
| 482 | port->interrupt_in_urb->pipe, retval); |
Oliver Neukum | 2f007de | 2007-03-29 10:45:17 +0200 | [diff] [blame] | 483 | goto error; |
| 484 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | return 0; |
Oliver Neukum | 2f007de | 2007-03-29 10:45:17 +0200 | [diff] [blame] | 486 | |
| 487 | error: |
| 488 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } /* mct_u232_open */ |
| 490 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 491 | static void mct_u232_dtr_rts(struct usb_serial_port *port, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 493 | unsigned int control_state; |
| 494 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
Johan Hovold | b2ca699 | 2013-02-13 17:53:28 +0100 | [diff] [blame] | 496 | spin_lock_irq(&priv->lock); |
| 497 | if (on) |
| 498 | priv->control_state |= TIOCM_DTR | TIOCM_RTS; |
| 499 | else |
| 500 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
| 501 | control_state = priv->control_state; |
| 502 | spin_unlock_irq(&priv->lock); |
| 503 | |
| 504 | mct_u232_set_modem_ctrl(port, control_state); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 505 | } |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 506 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 507 | static void mct_u232_close(struct usb_serial_port *port) |
| 508 | { |
Johan Hovold | 5260e45 | 2012-10-25 10:29:14 +0200 | [diff] [blame] | 509 | /* |
| 510 | * Must kill the read urb as it is actually an interrupt urb, which |
| 511 | * generic close thus fails to kill. |
| 512 | */ |
| 513 | usb_kill_urb(port->read_urb); |
| 514 | usb_kill_urb(port->interrupt_in_urb); |
| 515 | |
| 516 | usb_serial_generic_close(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } /* mct_u232_close */ |
| 518 | |
| 519 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 520 | static void mct_u232_read_int_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 522 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | e96da39 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 525 | int retval; |
| 526 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | unsigned long flags; |
| 528 | |
Greg Kroah-Hartman | e96da39 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 529 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | case 0: |
| 531 | /* success */ |
| 532 | break; |
| 533 | case -ECONNRESET: |
| 534 | case -ENOENT: |
| 535 | case -ESHUTDOWN: |
| 536 | /* this urb is terminated, clean up */ |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 537 | dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n", |
| 538 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return; |
| 540 | default: |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 541 | dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n", |
| 542 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | goto exit; |
| 544 | } |
| 545 | |
Greg Kroah-Hartman | 59d33f2 | 2012-09-18 09:58:57 +0100 | [diff] [blame] | 546 | usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
| 548 | /* |
| 549 | * Work-a-round: handle the 'usual' bulk-in pipe here |
| 550 | */ |
| 551 | if (urb->transfer_buffer_length > 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | if (urb->actual_length) { |
Jiri Slaby | 2e124b4 | 2013-01-03 15:53:06 +0100 | [diff] [blame] | 553 | tty_insert_flip_string(&port->port, data, |
| 554 | urb->actual_length); |
| 555 | tty_flip_buffer_push(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
| 557 | goto exit; |
| 558 | } |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | /* |
| 561 | * The interrupt-in pipe signals exceptional conditions (modem line |
| 562 | * signal changes and errors). data[0] holds MSR, data[1] holds LSR. |
| 563 | */ |
| 564 | spin_lock_irqsave(&priv->lock, flags); |
| 565 | priv->last_msr = data[MCT_U232_MSR_INDEX]; |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | /* Record Control Line states */ |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 568 | mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Johan Hovold | 468c740 | 2013-03-21 12:37:12 +0100 | [diff] [blame^] | 570 | mct_u232_msr_to_icount(&port->icount, priv->last_msr); |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | #if 0 |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 573 | /* Not yet handled. See belkin_sa.c for further information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | /* Now to report any errors */ |
| 575 | priv->last_lsr = data[MCT_U232_LSR_INDEX]; |
| 576 | /* |
| 577 | * fill in the flip buffer here, but I do not know the relation |
| 578 | * to the current/next receive buffer or characters. I need |
| 579 | * to look in to this before committing any code. |
| 580 | */ |
| 581 | if (priv->last_lsr & MCT_U232_LSR_ERR) { |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 582 | tty = tty_port_tty_get(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | /* Overrun Error */ |
| 584 | if (priv->last_lsr & MCT_U232_LSR_OE) { |
| 585 | } |
| 586 | /* Parity Error */ |
| 587 | if (priv->last_lsr & MCT_U232_LSR_PE) { |
| 588 | } |
| 589 | /* Framing Error */ |
| 590 | if (priv->last_lsr & MCT_U232_LSR_FE) { |
| 591 | } |
| 592 | /* Break Indicator */ |
| 593 | if (priv->last_lsr & MCT_U232_LSR_BI) { |
| 594 | } |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 595 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
| 597 | #endif |
Johan Hovold | cf1d244 | 2013-03-19 09:21:18 +0100 | [diff] [blame] | 598 | wake_up_interruptible(&port->delta_msr_wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | spin_unlock_irqrestore(&priv->lock, flags); |
| 600 | exit: |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 601 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Greg Kroah-Hartman | e96da39 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 602 | if (retval) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 603 | dev_err(&port->dev, |
| 604 | "%s - usb_submit_urb failed with result %d\n", |
| 605 | __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } /* mct_u232_read_int_callback */ |
| 607 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 608 | static void mct_u232_set_termios(struct tty_struct *tty, |
| 609 | struct usb_serial_port *port, |
| 610 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
| 612 | struct usb_serial *serial = port->serial; |
| 613 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
Alan Cox | adc8d74 | 2012-07-14 15:31:47 +0100 | [diff] [blame] | 614 | struct ktermios *termios = &tty->termios; |
Alan Cox | d0fab0d | 2007-12-13 16:15:29 -0800 | [diff] [blame] | 615 | unsigned int cflag = termios->c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | unsigned int old_cflag = old_termios->c_cflag; |
| 617 | unsigned long flags; |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 618 | unsigned int control_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | unsigned char last_lcr; |
| 620 | |
| 621 | /* get a local copy of the current port settings */ |
| 622 | spin_lock_irqsave(&priv->lock, flags); |
| 623 | control_state = priv->control_state; |
| 624 | spin_unlock_irqrestore(&priv->lock, flags); |
| 625 | last_lcr = 0; |
| 626 | |
| 627 | /* |
| 628 | * Update baud rate. |
| 629 | * Do not attempt to cache old rates and skip settings, |
| 630 | * disconnects screw such tricks up completely. |
| 631 | * Premature optimization is the root of all evil. |
| 632 | */ |
| 633 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 634 | /* reassert DTR and RTS on transition from B0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | if ((old_cflag & CBAUD) == B0) { |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 636 | dev_dbg(&port->dev, "%s: baud was B0\n", __func__); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 637 | control_state |= TIOCM_DTR | TIOCM_RTS; |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 638 | mct_u232_set_modem_ctrl(port, control_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 641 | mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 643 | if ((cflag & CBAUD) == B0) { |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 644 | dev_dbg(&port->dev, "%s: baud is B0\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | /* Drop RTS and DTR */ |
| 646 | control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 647 | mct_u232_set_modem_ctrl(port, control_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | /* |
| 651 | * Update line control register (LCR) |
| 652 | */ |
| 653 | |
| 654 | /* set the parity */ |
| 655 | if (cflag & PARENB) |
| 656 | last_lcr |= (cflag & PARODD) ? |
| 657 | MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN; |
| 658 | else |
| 659 | last_lcr |= MCT_U232_PARITY_NONE; |
| 660 | |
| 661 | /* set the number of data bits */ |
| 662 | switch (cflag & CSIZE) { |
| 663 | case CS5: |
| 664 | last_lcr |= MCT_U232_DATA_BITS_5; break; |
| 665 | case CS6: |
| 666 | last_lcr |= MCT_U232_DATA_BITS_6; break; |
| 667 | case CS7: |
| 668 | last_lcr |= MCT_U232_DATA_BITS_7; break; |
| 669 | case CS8: |
| 670 | last_lcr |= MCT_U232_DATA_BITS_8; break; |
| 671 | default: |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 672 | dev_err(&port->dev, |
| 673 | "CSIZE was not CS5-CS8, using default of 8\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | last_lcr |= MCT_U232_DATA_BITS_8; |
| 675 | break; |
| 676 | } |
| 677 | |
Alan Cox | d0fab0d | 2007-12-13 16:15:29 -0800 | [diff] [blame] | 678 | termios->c_cflag &= ~CMSPAR; |
| 679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | /* set the number of stop bits */ |
| 681 | last_lcr |= (cflag & CSTOPB) ? |
| 682 | MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1; |
| 683 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 684 | mct_u232_set_line_ctrl(port, last_lcr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | /* save off the modified port settings */ |
| 687 | spin_lock_irqsave(&priv->lock, flags); |
| 688 | priv->control_state = control_state; |
| 689 | priv->last_lcr = last_lcr; |
| 690 | spin_unlock_irqrestore(&priv->lock, flags); |
| 691 | } /* mct_u232_set_termios */ |
| 692 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 693 | static void mct_u232_break_ctl(struct tty_struct *tty, int break_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 695 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
| 697 | unsigned char lcr; |
| 698 | unsigned long flags; |
| 699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | spin_lock_irqsave(&priv->lock, flags); |
| 701 | lcr = priv->last_lcr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
| 703 | if (break_state) |
| 704 | lcr |= MCT_U232_SET_BREAK; |
Alan Cox | 6b447f04 | 2009-01-02 13:48:56 +0000 | [diff] [blame] | 705 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 707 | mct_u232_set_line_ctrl(port, lcr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } /* mct_u232_break_ctl */ |
| 709 | |
| 710 | |
Alan Cox | 60b33c1 | 2011-02-14 16:26:14 +0000 | [diff] [blame] | 711 | static int mct_u232_tiocmget(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 713 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
| 715 | unsigned int control_state; |
| 716 | unsigned long flags; |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | spin_lock_irqsave(&priv->lock, flags); |
| 719 | control_state = priv->control_state; |
| 720 | spin_unlock_irqrestore(&priv->lock, flags); |
| 721 | |
| 722 | return control_state; |
| 723 | } |
| 724 | |
Alan Cox | 20b9d17 | 2011-02-14 16:26:50 +0000 | [diff] [blame] | 725 | static int mct_u232_tiocmset(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | unsigned int set, unsigned int clear) |
| 727 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 728 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
| 730 | unsigned int control_state; |
| 731 | unsigned long flags; |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | spin_lock_irqsave(&priv->lock, flags); |
| 734 | control_state = priv->control_state; |
| 735 | |
| 736 | if (set & TIOCM_RTS) |
| 737 | control_state |= TIOCM_RTS; |
| 738 | if (set & TIOCM_DTR) |
| 739 | control_state |= TIOCM_DTR; |
| 740 | if (clear & TIOCM_RTS) |
| 741 | control_state &= ~TIOCM_RTS; |
| 742 | if (clear & TIOCM_DTR) |
| 743 | control_state &= ~TIOCM_DTR; |
| 744 | |
| 745 | priv->control_state = control_state; |
| 746 | spin_unlock_irqrestore(&priv->lock, flags); |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 747 | return mct_u232_set_modem_ctrl(port, control_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 750 | static void mct_u232_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 752 | struct usb_serial_port *port = tty->driver_data; |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 753 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 754 | unsigned int control_state; |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 755 | |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 756 | spin_lock_irq(&priv->lock); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 757 | priv->rx_flags |= THROTTLED; |
| 758 | if (C_CRTSCTS(tty)) { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 759 | priv->control_state &= ~TIOCM_RTS; |
| 760 | control_state = priv->control_state; |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 761 | spin_unlock_irq(&priv->lock); |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 762 | mct_u232_set_modem_ctrl(port, control_state); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 763 | } else { |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 764 | spin_unlock_irq(&priv->lock); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 765 | } |
| 766 | } |
| 767 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 768 | static void mct_u232_unthrottle(struct tty_struct *tty) |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 769 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 770 | struct usb_serial_port *port = tty->driver_data; |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 771 | struct mct_u232_private *priv = usb_get_serial_port_data(port); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 772 | unsigned int control_state; |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 773 | |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 774 | spin_lock_irq(&priv->lock); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 775 | if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 776 | priv->rx_flags &= ~THROTTLED; |
| 777 | priv->control_state |= TIOCM_RTS; |
| 778 | control_state = priv->control_state; |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 779 | spin_unlock_irq(&priv->lock); |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 780 | mct_u232_set_modem_ctrl(port, control_state); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 781 | } else { |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 782 | spin_unlock_irq(&priv->lock); |
Dave Platt | 45b844d | 2007-05-08 11:00:12 -0700 | [diff] [blame] | 783 | } |
| 784 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
Randy Dunlap | 4acfaf8 | 2011-04-03 11:42:00 -0700 | [diff] [blame] | 786 | static int mct_u232_ioctl(struct tty_struct *tty, |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 787 | unsigned int cmd, unsigned long arg) |
| 788 | { |
| 789 | DEFINE_WAIT(wait); |
| 790 | struct usb_serial_port *port = tty->driver_data; |
| 791 | struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port); |
| 792 | struct async_icount cnow, cprev; |
| 793 | unsigned long flags; |
| 794 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 795 | dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd); |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 796 | |
| 797 | switch (cmd) { |
| 798 | |
| 799 | case TIOCMIWAIT: |
| 800 | |
Greg Kroah-Hartman | 4a770cc | 2012-09-14 15:08:30 -0700 | [diff] [blame] | 801 | dev_dbg(&port->dev, "%s TIOCMIWAIT", __func__); |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 802 | |
| 803 | spin_lock_irqsave(&mct_u232_port->lock, flags); |
Johan Hovold | 468c740 | 2013-03-21 12:37:12 +0100 | [diff] [blame^] | 804 | cprev = port->icount; |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 805 | spin_unlock_irqrestore(&mct_u232_port->lock, flags); |
| 806 | for ( ; ; ) { |
Johan Hovold | cf1d244 | 2013-03-19 09:21:18 +0100 | [diff] [blame] | 807 | prepare_to_wait(&port->delta_msr_wait, |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 808 | &wait, TASK_INTERRUPTIBLE); |
| 809 | schedule(); |
Johan Hovold | cf1d244 | 2013-03-19 09:21:18 +0100 | [diff] [blame] | 810 | finish_wait(&port->delta_msr_wait, &wait); |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 811 | /* see if a signal did it */ |
| 812 | if (signal_pending(current)) |
| 813 | return -ERESTARTSYS; |
Johan Hovold | cf1d244 | 2013-03-19 09:21:18 +0100 | [diff] [blame] | 814 | |
| 815 | if (port->serial->disconnected) |
| 816 | return -EIO; |
| 817 | |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 818 | spin_lock_irqsave(&mct_u232_port->lock, flags); |
Johan Hovold | 468c740 | 2013-03-21 12:37:12 +0100 | [diff] [blame^] | 819 | cnow = port->icount; |
Vadim Tsozik | 7af75af | 2011-01-09 01:00:11 -0500 | [diff] [blame] | 820 | spin_unlock_irqrestore(&mct_u232_port->lock, flags); |
| 821 | if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && |
| 822 | cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) |
| 823 | return -EIO; /* no change => error */ |
| 824 | if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || |
| 825 | ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || |
| 826 | ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || |
| 827 | ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) { |
| 828 | return 0; |
| 829 | } |
| 830 | cprev = cnow; |
| 831 | } |
| 832 | |
| 833 | } |
| 834 | return -ENOIOCTLCMD; |
| 835 | } |
| 836 | |
Greg Kroah-Hartman | 68e2411 | 2012-05-08 15:46:14 -0700 | [diff] [blame] | 837 | module_usb_serial_driver(serial_drivers, id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
Alan Cox | e19b256 | 2008-07-22 11:14:30 +0100 | [diff] [blame] | 839 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 840 | MODULE_DESCRIPTION(DRIVER_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | MODULE_LICENSE("GPL"); |