blob: cd009cb280a50b29d80a50610f8303a4badbd9af [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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.
22 *
23 * TEST STATUS:
24 * Basic tests have been performed with minicom/zmodem transfers and
25 * modem dialing under Linux 2.4.0-test10 (for me it works fine).
26 *
27 * 04-Nov-2003 Bill Marr <marr at flex dot com>
28 * - Mimic Windows driver by sending 2 USB 'device request' messages
29 * following normal 'baud rate change' message. This allows data to be
30 * transmitted to RS-232 devices which don't assert the 'CTS' signal.
31 *
32 * 10-Nov-2001 Wolfgang Grandegger
33 * - Fixed an endianess problem with the baudrate selection for PowerPC.
34 *
35 * 06-Dec-2001 Martin Hamilton <martinh@gnu.org>
Alan Coxe19b2562008-07-22 11:14:30 +010036 * - Added support for the Belkin F5U109 DB9 adaptor
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 *
38 * 30-May-2001 Greg Kroah-Hartman
Alan Coxe19b2562008-07-22 11:14:30 +010039 * - switched from using spinlock to a semaphore, which fixes lots of
40 * problems.
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 *
42 * 04-May-2001 Stelian Pop
43 * - Set the maximum bulk output size for Sitecom U232-P25 model to 16 bytes
44 * instead of the device reported 32 (using 32 bytes causes many data
45 * loss, Windows driver uses 16 too).
46 *
47 * 02-May-2001 Stelian Pop
48 * - Fixed the baud calculation for Sitecom U232-P25 model
49 *
50 * 08-Apr-2001 gb
51 * - Identify version on module load.
52 *
Alan Coxe19b2562008-07-22 11:14:30 +010053 * 06-Jan-2001 Cornel Ciocirlan
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * - Added support for Sitecom U232-P25 model (Product Id 0x0230)
55 * - Added support for D-Link DU-H3SP USB BAY (Product Id 0x0200)
56 *
57 * 29-Nov-2000 Greg Kroah-Hartman
58 * - Added device id table to fit with 2.4.0-test11 structure.
59 * - took out DEAL_WITH_TWO_INT_IN_ENDPOINTS #define as it's not needed
60 * (lots of things will change if/when the usb-serial core changes to
61 * handle these issues.
62 *
Alan Coxe19b2562008-07-22 11:14:30 +010063 * 27-Nov-2000 Wolfgang Grandegge
64 * A version for kernel 2.4.0-test10 released to the Linux community
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 * (via linux-usb-devel).
66 */
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#include <linux/kernel.h>
69#include <linux/errno.h>
70#include <linux/init.h>
71#include <linux/slab.h>
72#include <linux/tty.h>
73#include <linux/tty_driver.h>
74#include <linux/tty_flip.h>
75#include <linux/module.h>
76#include <linux/spinlock.h>
Alan Coxe19b2562008-07-22 11:14:30 +010077#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070079#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#include "mct_u232.h"
81
82/*
83 * Version Information
84 */
Dave Platt45b844d2007-05-08 11:00:12 -070085#define DRIVER_VERSION "z2.1" /* Linux in-kernel version */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>"
87#define DRIVER_DESC "Magic Control Technology USB-RS232 converter driver"
88
89static int debug;
90
91/*
92 * Function prototypes
93 */
Alan Coxe19b2562008-07-22 11:14:30 +010094static int mct_u232_startup(struct usb_serial *serial);
Alan Sternf9c99bb2009-06-02 11:53:55 -040095static void mct_u232_release(struct usb_serial *serial);
Alan Coxa509a7e2009-09-19 13:13:26 -070096static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port);
Alan Cox335f8512009-06-11 12:26:29 +010097static void mct_u232_close(struct usb_serial_port *port);
98static void mct_u232_dtr_rts(struct usb_serial_port *port, int on);
Alan Coxe19b2562008-07-22 11:14:30 +010099static void mct_u232_read_int_callback(struct urb *urb);
100static void mct_u232_set_termios(struct tty_struct *tty,
101 struct usb_serial_port *port, struct ktermios *old);
102static void mct_u232_break_ctl(struct tty_struct *tty, int break_state);
103static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file);
104static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
105 unsigned int set, unsigned int clear);
106static void mct_u232_throttle(struct tty_struct *tty);
107static void mct_u232_unthrottle(struct tty_struct *tty);
Dave Platt45b844d2007-05-08 11:00:12 -0700108
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/*
111 * All of the device info needed for the MCT USB-RS232 converter.
112 */
113static struct usb_device_id id_table_combined [] = {
114 { USB_DEVICE(MCT_U232_VID, MCT_U232_PID) },
115 { USB_DEVICE(MCT_U232_VID, MCT_U232_SITECOM_PID) },
116 { USB_DEVICE(MCT_U232_VID, MCT_U232_DU_H3SP_PID) },
117 { USB_DEVICE(MCT_U232_BELKIN_F5U109_VID, MCT_U232_BELKIN_F5U109_PID) },
118 { } /* Terminating entry */
119};
120
Alan Coxe19b2562008-07-22 11:14:30 +0100121MODULE_DEVICE_TABLE(usb, id_table_combined);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123static struct usb_driver mct_u232_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .name = "mct_u232",
125 .probe = usb_serial_probe,
126 .disconnect = usb_serial_disconnect,
127 .id_table = id_table_combined,
Greg Kroah-Hartmanba9dc652005-11-16 13:41:28 -0800128 .no_dynamic_id = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700131static struct usb_serial_driver mct_u232_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700132 .driver = {
133 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700134 .name = "mct_u232",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700135 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700136 .description = "MCT U232",
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100137 .usb_driver = &mct_u232_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 .id_table = id_table_combined,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 .num_ports = 1,
140 .open = mct_u232_open,
141 .close = mct_u232_close,
Alan Cox335f8512009-06-11 12:26:29 +0100142 .dtr_rts = mct_u232_dtr_rts,
Dave Platt45b844d2007-05-08 11:00:12 -0700143 .throttle = mct_u232_throttle,
144 .unthrottle = mct_u232_unthrottle,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 .read_int_callback = mct_u232_read_int_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 .set_termios = mct_u232_set_termios,
147 .break_ctl = mct_u232_break_ctl,
148 .tiocmget = mct_u232_tiocmget,
149 .tiocmset = mct_u232_tiocmset,
150 .attach = mct_u232_startup,
Alan Sternf9c99bb2009-06-02 11:53:55 -0400151 .release = mct_u232_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152};
153
154
155struct mct_u232_private {
156 spinlock_t lock;
157 unsigned int control_state; /* Modem Line Setting (TIOCM) */
158 unsigned char last_lcr; /* Line Control Register */
159 unsigned char last_lsr; /* Line Status Register */
160 unsigned char last_msr; /* Modem Status Register */
Dave Platt45b844d2007-05-08 11:00:12 -0700161 unsigned int rx_flags; /* Throttling flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162};
163
Dave Platt45b844d2007-05-08 11:00:12 -0700164#define THROTTLED 0x01
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/*
167 * Handle vendor specific USB requests
168 */
169
170#define WDR_TIMEOUT 5000 /* default urb timeout */
171
172/*
173 * Later day 2.6.0-test kernels have new baud rates like B230400 which
174 * we do not know how to support. We ignore them for the moment.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 */
Alan Coxe19b2562008-07-22 11:14:30 +0100176static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
177 speed_t value, speed_t *result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Alan Coxd0fab0d2007-12-13 16:15:29 -0800179 *result = value;
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID
Alan Coxe19b2562008-07-22 11:14:30 +0100182 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 switch (value) {
Alan Coxe19b2562008-07-22 11:14:30 +0100184 case 300:
185 return 0x01;
186 case 600:
187 return 0x02; /* this one not tested */
188 case 1200:
189 return 0x03;
190 case 2400:
191 return 0x04;
192 case 4800:
193 return 0x06;
194 case 9600:
195 return 0x08;
196 case 19200:
197 return 0x09;
198 case 38400:
199 return 0x0a;
200 case 57600:
201 return 0x0b;
202 case 115200:
203 return 0x0c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 default:
Alan Coxd0fab0d2007-12-13 16:15:29 -0800205 *result = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return 0x08;
207 }
208 } else {
Alan Coxd0fab0d2007-12-13 16:15:29 -0800209 /* FIXME: Can we use any divider - should we do
210 divider = 115200/value;
211 real baud = 115200/divider */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 switch (value) {
Andrew Mortonb3aceb22007-08-10 14:53:35 -0700213 case 300: break;
214 case 600: break;
215 case 1200: break;
216 case 2400: break;
217 case 4800: break;
218 case 9600: break;
219 case 19200: break;
220 case 38400: break;
221 case 57600: break;
222 case 115200: break;
223 default:
Andrew Mortonb3aceb22007-08-10 14:53:35 -0700224 value = 9600;
Alan Coxd0fab0d2007-12-13 16:15:29 -0800225 *result = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227 return 115200/value;
228 }
229}
230
Alan Cox95da3102008-07-22 11:09:07 +0100231static int mct_u232_set_baud_rate(struct tty_struct *tty,
232 struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
234 __le32 divisor;
Alan Coxe19b2562008-07-22 11:14:30 +0100235 int rc;
236 unsigned char zero_byte = 0;
237 unsigned char cts_enable_byte = 0;
238 speed_t speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Alan Coxe19b2562008-07-22 11:14:30 +0100240 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value,
241 &speed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Alan Coxe19b2562008-07-22 11:14:30 +0100243 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
244 MCT_U232_SET_BAUD_RATE_REQUEST,
245 MCT_U232_SET_REQUEST_TYPE,
246 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE,
247 WDR_TIMEOUT);
Alan Coxd0fab0d2007-12-13 16:15:29 -0800248 if (rc < 0) /*FIXME: What value speed results */
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700249 dev_err(&port->dev, "Set BAUD RATE %d failed (error = %d)\n",
250 value, rc);
Alan Coxd0fab0d2007-12-13 16:15:29 -0800251 else
Alan Cox95da3102008-07-22 11:09:07 +0100252 tty_encode_baud_rate(tty, speed, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
254
255 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
256 always sends two extra USB 'device request' messages after the
257 'baud rate change' message. The actual functionality of the
258 request codes in these messages is not fully understood but these
259 particular codes are never seen in any operation besides a baud
Dave Platt45b844d2007-05-08 11:00:12 -0700260 rate change. Both of these messages send a single byte of data.
261 In the first message, the value of this byte is always zero.
262
263 The second message has been determined experimentally to control
264 whether data will be transmitted to a device which is not asserting
265 the 'CTS' signal. If the second message's data byte is zero, data
266 will be transmitted even if 'CTS' is not asserted (i.e. no hardware
Alan Coxe19b2562008-07-22 11:14:30 +0100267 flow control). if the second message's data byte is nonzero (a
268 value of 1 is used by this driver), data will not be transmitted to
269 a device which is not asserting 'CTS'.
Dave Platt45b844d2007-05-08 11:00:12 -0700270 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
Alan Coxe19b2562008-07-22 11:14:30 +0100273 MCT_U232_SET_UNKNOWN1_REQUEST,
274 MCT_U232_SET_REQUEST_TYPE,
275 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE,
276 WDR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (rc < 0)
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700278 dev_err(&port->dev, "Sending USB device request code %d "
279 "failed (error = %d)\n", MCT_U232_SET_UNKNOWN1_REQUEST,
280 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Alan Coxe19b2562008-07-22 11:14:30 +0100282 if (port && C_CRTSCTS(tty))
Dave Platt45b844d2007-05-08 11:00:12 -0700283 cts_enable_byte = 1;
Dave Platt45b844d2007-05-08 11:00:12 -0700284
Alan Coxe19b2562008-07-22 11:14:30 +0100285 dbg("set_baud_rate: send second control message, data = %02X",
286 cts_enable_byte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
Alan Coxe19b2562008-07-22 11:14:30 +0100288 MCT_U232_SET_CTS_REQUEST,
289 MCT_U232_SET_REQUEST_TYPE,
290 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE,
291 WDR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 if (rc < 0)
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700293 dev_err(&port->dev, "Sending USB device request code %d "
294 "failed (error = %d)\n", MCT_U232_SET_CTS_REQUEST, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Alan Coxe19b2562008-07-22 11:14:30 +0100296 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297} /* mct_u232_set_baud_rate */
298
299static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
300{
Alan Coxe19b2562008-07-22 11:14:30 +0100301 int rc;
302 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
303 MCT_U232_SET_LINE_CTRL_REQUEST,
304 MCT_U232_SET_REQUEST_TYPE,
305 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE,
306 WDR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 if (rc < 0)
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700308 dev_err(&serial->dev->dev,
309 "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 dbg("set_line_ctrl: 0x%x", lcr);
Alan Coxe19b2562008-07-22 11:14:30 +0100311 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312} /* mct_u232_set_line_ctrl */
313
314static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
315 unsigned int control_state)
316{
Alan Coxe19b2562008-07-22 11:14:30 +0100317 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 unsigned char mcr = MCT_U232_MCR_NONE;
319
320 if (control_state & TIOCM_DTR)
321 mcr |= MCT_U232_MCR_DTR;
322 if (control_state & TIOCM_RTS)
323 mcr |= MCT_U232_MCR_RTS;
324
Alan Coxe19b2562008-07-22 11:14:30 +0100325 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
326 MCT_U232_SET_MODEM_CTRL_REQUEST,
327 MCT_U232_SET_REQUEST_TYPE,
328 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE,
329 WDR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 if (rc < 0)
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700331 dev_err(&serial->dev->dev,
332 "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
334
Alan Coxe19b2562008-07-22 11:14:30 +0100335 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336} /* mct_u232_set_modem_ctrl */
337
Alan Coxe19b2562008-07-22 11:14:30 +0100338static int mct_u232_get_modem_stat(struct usb_serial *serial,
339 unsigned char *msr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Alan Coxe19b2562008-07-22 11:14:30 +0100341 int rc;
342 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
343 MCT_U232_GET_MODEM_STAT_REQUEST,
344 MCT_U232_GET_REQUEST_TYPE,
345 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE,
346 WDR_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if (rc < 0) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700348 dev_err(&serial->dev->dev,
349 "Get MODEM STATus failed (error = %d)\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 *msr = 0;
351 }
352 dbg("get_modem_stat: 0x%x", *msr);
Alan Coxe19b2562008-07-22 11:14:30 +0100353 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354} /* mct_u232_get_modem_stat */
355
Alan Coxe19b2562008-07-22 11:14:30 +0100356static void mct_u232_msr_to_state(unsigned int *control_state,
357 unsigned char msr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Alan Coxe19b2562008-07-22 11:14:30 +0100359 /* Translate Control Line states */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 if (msr & MCT_U232_MSR_DSR)
361 *control_state |= TIOCM_DSR;
362 else
363 *control_state &= ~TIOCM_DSR;
364 if (msr & MCT_U232_MSR_CTS)
365 *control_state |= TIOCM_CTS;
366 else
367 *control_state &= ~TIOCM_CTS;
368 if (msr & MCT_U232_MSR_RI)
369 *control_state |= TIOCM_RI;
370 else
371 *control_state &= ~TIOCM_RI;
372 if (msr & MCT_U232_MSR_CD)
373 *control_state |= TIOCM_CD;
374 else
375 *control_state &= ~TIOCM_CD;
Alan Coxe19b2562008-07-22 11:14:30 +0100376 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377} /* mct_u232_msr_to_state */
378
379/*
380 * Driver's tty interface functions
381 */
382
Alan Coxe19b2562008-07-22 11:14:30 +0100383static int mct_u232_startup(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385 struct mct_u232_private *priv;
386 struct usb_serial_port *port, *rport;
387
Eric Sesterhenn80b6ca42006-02-27 21:29:43 +0100388 priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 if (!priv)
390 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 spin_lock_init(&priv->lock);
392 usb_set_serial_port_data(serial->port[0], priv);
393
394 init_waitqueue_head(&serial->port[0]->write_wait);
395
396 /* Puh, that's dirty */
397 port = serial->port[0];
398 rport = serial->port[1];
Mariusz Kozlowski73135bb2006-11-08 15:36:42 +0100399 /* No unlinking, it wasn't submitted yet. */
400 usb_free_urb(port->read_urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 port->read_urb = rport->interrupt_in_urb;
402 rport->interrupt_in_urb = NULL;
403 port->read_urb->context = port;
404
Alan Coxe19b2562008-07-22 11:14:30 +0100405 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406} /* mct_u232_startup */
407
408
Alan Sternf9c99bb2009-06-02 11:53:55 -0400409static void mct_u232_release(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
411 struct mct_u232_private *priv;
412 int i;
Alan Coxe19b2562008-07-22 11:14:30 +0100413
Harvey Harrison441b62c2008-03-03 16:08:34 -0800414 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Alan Coxe19b2562008-07-22 11:14:30 +0100416 for (i = 0; i < serial->num_ports; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 /* My special items, the standard routines free my urbs */
418 priv = usb_get_serial_port_data(serial->port[i]);
Alan Sternf9c99bb2009-06-02 11:53:55 -0400419 kfree(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
Alan Sternf9c99bb2009-06-02 11:53:55 -0400421} /* mct_u232_release */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Alan Coxa509a7e2009-09-19 13:13:26 -0700423static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
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
Harvey Harrison441b62c2008-03-03 16:08:34 -0800433 dbg("%s port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 /* Compensate for a hardware bug: although the Sitecom U232-P25
436 * device reports a maximum output packet size of 32 bytes,
437 * it seems to be able to accept only 16 bytes (and that's what
438 * SniffUSB says too...)
439 */
Alan Coxe19b2562008-07-22 11:14:30 +0100440 if (le16_to_cpu(serial->dev->descriptor.idProduct)
441 == MCT_U232_SITECOM_PID)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 port->bulk_out_size = 16;
443
Alan Coxe19b2562008-07-22 11:14:30 +0100444 /* Do a defined restart: the normal serial device seems to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 * always turn on DTR and RTS here, so do the same. I'm not
446 * sure if this is really necessary. But it should not harm
447 * either.
448 */
449 spin_lock_irqsave(&priv->lock, flags);
Alan Cox95da3102008-07-22 11:09:07 +0100450 if (tty && (tty->termios->c_cflag & CBAUD))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 priv->control_state = TIOCM_DTR | TIOCM_RTS;
452 else
453 priv->control_state = 0;
Alan Coxe19b2562008-07-22 11:14:30 +0100454
455 priv->last_lcr = (MCT_U232_DATA_BITS_8 |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 MCT_U232_PARITY_NONE |
457 MCT_U232_STOP_BITS_1);
458 control_state = priv->control_state;
459 last_lcr = priv->last_lcr;
460 spin_unlock_irqrestore(&priv->lock, flags);
461 mct_u232_set_modem_ctrl(serial, control_state);
462 mct_u232_set_line_ctrl(serial, last_lcr);
463
464 /* Read modem status and update control state */
465 mct_u232_get_modem_stat(serial, &last_msr);
466 spin_lock_irqsave(&priv->lock, flags);
467 priv->last_msr = last_msr;
468 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
469 spin_unlock_irqrestore(&priv->lock, flags);
470
471 port->read_urb->dev = port->serial->dev;
472 retval = usb_submit_urb(port->read_urb, GFP_KERNEL);
473 if (retval) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700474 dev_err(&port->dev,
475 "usb_submit_urb(read bulk) failed pipe 0x%x err %d\n",
476 port->read_urb->pipe, retval);
Oliver Neukum2f007de2007-03-29 10:45:17 +0200477 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 }
479
480 port->interrupt_in_urb->dev = port->serial->dev;
481 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
Oliver Neukum2f007de2007-03-29 10:45:17 +0200482 if (retval) {
483 usb_kill_urb(port->read_urb);
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700484 dev_err(&port->dev,
485 "usb_submit_urb(read int) failed pipe 0x%x err %d",
486 port->interrupt_in_urb->pipe, retval);
Oliver Neukum2f007de2007-03-29 10:45:17 +0200487 goto error;
488 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 return 0;
Oliver Neukum2f007de2007-03-29 10:45:17 +0200490
491error:
492 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493} /* mct_u232_open */
494
Alan Cox335f8512009-06-11 12:26:29 +0100495static void mct_u232_dtr_rts(struct usb_serial_port *port, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Dave Platt45b844d2007-05-08 11:00:12 -0700497 unsigned int control_state;
498 struct mct_u232_private *priv = usb_get_serial_port_data(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Alan Cox335f8512009-06-11 12:26:29 +0100500 mutex_lock(&port->serial->disc_mutex);
501 if (!port->serial->disconnected) {
502 /* drop DTR and RTS */
503 spin_lock_irq(&priv->lock);
504 if (on)
505 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
506 else
Oliver Neukume33fe4d2008-01-21 17:44:10 +0100507 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
Alan Cox335f8512009-06-11 12:26:29 +0100508 control_state = priv->control_state;
509 spin_unlock_irq(&priv->lock);
510 mct_u232_set_modem_ctrl(port->serial, control_state);
Dave Platt45b844d2007-05-08 11:00:12 -0700511 }
Alan Cox335f8512009-06-11 12:26:29 +0100512 mutex_unlock(&port->serial->disc_mutex);
513}
Dave Platt45b844d2007-05-08 11:00:12 -0700514
Alan Cox335f8512009-06-11 12:26:29 +0100515static void mct_u232_close(struct usb_serial_port *port)
516{
517 dbg("%s port %d", __func__, port->number);
Dave Platt45b844d2007-05-08 11:00:12 -0700518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (port->serial->dev) {
520 /* shutdown our urbs */
521 usb_kill_urb(port->write_urb);
522 usb_kill_urb(port->read_urb);
523 usb_kill_urb(port->interrupt_in_urb);
524 }
525} /* mct_u232_close */
526
527
Alan Coxe19b2562008-07-22 11:14:30 +0100528static void mct_u232_read_int_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Ming Leicdc97792008-02-24 18:41:47 +0800530 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 struct mct_u232_private *priv = usb_get_serial_port_data(port);
532 struct usb_serial *serial = port->serial;
533 struct tty_struct *tty;
534 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartmane96da392007-06-15 15:44:13 -0700535 int retval;
536 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 unsigned long flags;
538
Greg Kroah-Hartmane96da392007-06-15 15:44:13 -0700539 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 case 0:
541 /* success */
542 break;
543 case -ECONNRESET:
544 case -ENOENT:
545 case -ESHUTDOWN:
546 /* this urb is terminated, clean up */
Greg Kroah-Hartmane96da392007-06-15 15:44:13 -0700547 dbg("%s - urb shutting down with status: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800548 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 return;
550 default:
Greg Kroah-Hartmane96da392007-06-15 15:44:13 -0700551 dbg("%s - nonzero urb status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800552 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 goto exit;
554 }
555
556 if (!serial) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800557 dbg("%s - bad serial pointer, exiting", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 return;
559 }
560
Alan Coxe19b2562008-07-22 11:14:30 +0100561 dbg("%s - port %d", __func__, port->number);
562 usb_serial_debug_data(debug, &port->dev, __func__,
563 urb->actual_length, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 /*
566 * Work-a-round: handle the 'usual' bulk-in pipe here
567 */
568 if (urb->transfer_buffer_length > 2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (urb->actual_length) {
Jiri Slaby054f2342009-09-06 23:10:10 +0200570 tty = tty_port_tty_get(&port->port);
571 if (tty) {
572 tty_insert_flip_string(tty, data,
573 urb->actual_length);
574 tty_flip_buffer_push(tty);
575 }
Alan Cox4a90f092008-10-13 10:39:46 +0100576 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 }
578 goto exit;
579 }
Alan Coxe19b2562008-07-22 11:14:30 +0100580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 /*
582 * The interrupt-in pipe signals exceptional conditions (modem line
583 * signal changes and errors). data[0] holds MSR, data[1] holds LSR.
584 */
585 spin_lock_irqsave(&priv->lock, flags);
586 priv->last_msr = data[MCT_U232_MSR_INDEX];
Alan Coxe19b2562008-07-22 11:14:30 +0100587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /* Record Control Line states */
589 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
590
591#if 0
Alan Coxe19b2562008-07-22 11:14:30 +0100592 /* Not yet handled. See belkin_sa.c for further information */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 /* Now to report any errors */
594 priv->last_lsr = data[MCT_U232_LSR_INDEX];
595 /*
596 * fill in the flip buffer here, but I do not know the relation
597 * to the current/next receive buffer or characters. I need
598 * to look in to this before committing any code.
599 */
600 if (priv->last_lsr & MCT_U232_LSR_ERR) {
Alan Cox4a90f092008-10-13 10:39:46 +0100601 tty = tty_port_tty_get(&port->port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /* Overrun Error */
603 if (priv->last_lsr & MCT_U232_LSR_OE) {
604 }
605 /* Parity Error */
606 if (priv->last_lsr & MCT_U232_LSR_PE) {
607 }
608 /* Framing Error */
609 if (priv->last_lsr & MCT_U232_LSR_FE) {
610 }
611 /* Break Indicator */
612 if (priv->last_lsr & MCT_U232_LSR_BI) {
613 }
Alan Cox4a90f092008-10-13 10:39:46 +0100614 tty_kref_put(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616#endif
617 spin_unlock_irqrestore(&priv->lock, flags);
618exit:
Alan Coxe19b2562008-07-22 11:14:30 +0100619 retval = usb_submit_urb(urb, GFP_ATOMIC);
Greg Kroah-Hartmane96da392007-06-15 15:44:13 -0700620 if (retval)
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700621 dev_err(&port->dev,
622 "%s - usb_submit_urb failed with result %d\n",
623 __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624} /* mct_u232_read_int_callback */
625
Alan Coxe19b2562008-07-22 11:14:30 +0100626static void mct_u232_set_termios(struct tty_struct *tty,
627 struct usb_serial_port *port,
628 struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
630 struct usb_serial *serial = port->serial;
631 struct mct_u232_private *priv = usb_get_serial_port_data(port);
Alan Cox95da3102008-07-22 11:09:07 +0100632 struct ktermios *termios = tty->termios;
Alan Coxd0fab0d2007-12-13 16:15:29 -0800633 unsigned int cflag = termios->c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 unsigned int old_cflag = old_termios->c_cflag;
635 unsigned long flags;
Dave Platt45b844d2007-05-08 11:00:12 -0700636 unsigned int control_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 unsigned char last_lcr;
638
639 /* get a local copy of the current port settings */
640 spin_lock_irqsave(&priv->lock, flags);
641 control_state = priv->control_state;
642 spin_unlock_irqrestore(&priv->lock, flags);
643 last_lcr = 0;
644
645 /*
646 * Update baud rate.
647 * Do not attempt to cache old rates and skip settings,
648 * disconnects screw such tricks up completely.
649 * Premature optimization is the root of all evil.
650 */
651
Alan Coxe19b2562008-07-22 11:14:30 +0100652 /* reassert DTR and RTS on transition from B0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 if ((old_cflag & CBAUD) == B0) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800654 dbg("%s: baud was B0", __func__);
Dave Platt45b844d2007-05-08 11:00:12 -0700655 control_state |= TIOCM_DTR | TIOCM_RTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 mct_u232_set_modem_ctrl(serial, control_state);
657 }
658
Alan Cox95da3102008-07-22 11:09:07 +0100659 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Alan Coxe19b2562008-07-22 11:14:30 +0100661 if ((cflag & CBAUD) == B0) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800662 dbg("%s: baud is B0", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 /* Drop RTS and DTR */
664 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
Alan Coxe19b2562008-07-22 11:14:30 +0100665 mct_u232_set_modem_ctrl(serial, control_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
667
668 /*
669 * Update line control register (LCR)
670 */
671
672 /* set the parity */
673 if (cflag & PARENB)
674 last_lcr |= (cflag & PARODD) ?
675 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
676 else
677 last_lcr |= MCT_U232_PARITY_NONE;
678
679 /* set the number of data bits */
680 switch (cflag & CSIZE) {
681 case CS5:
682 last_lcr |= MCT_U232_DATA_BITS_5; break;
683 case CS6:
684 last_lcr |= MCT_U232_DATA_BITS_6; break;
685 case CS7:
686 last_lcr |= MCT_U232_DATA_BITS_7; break;
687 case CS8:
688 last_lcr |= MCT_U232_DATA_BITS_8; break;
689 default:
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -0700690 dev_err(&port->dev,
691 "CSIZE was not CS5-CS8, using default of 8\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 last_lcr |= MCT_U232_DATA_BITS_8;
693 break;
694 }
695
Alan Coxd0fab0d2007-12-13 16:15:29 -0800696 termios->c_cflag &= ~CMSPAR;
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 /* set the number of stop bits */
699 last_lcr |= (cflag & CSTOPB) ?
700 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
701
702 mct_u232_set_line_ctrl(serial, last_lcr);
703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 /* save off the modified port settings */
705 spin_lock_irqsave(&priv->lock, flags);
706 priv->control_state = control_state;
707 priv->last_lcr = last_lcr;
708 spin_unlock_irqrestore(&priv->lock, flags);
709} /* mct_u232_set_termios */
710
Alan Cox95da3102008-07-22 11:09:07 +0100711static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
Alan Cox95da3102008-07-22 11:09:07 +0100713 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 struct usb_serial *serial = port->serial;
715 struct mct_u232_private *priv = usb_get_serial_port_data(port);
716 unsigned char lcr;
717 unsigned long flags;
718
Harvey Harrison441b62c2008-03-03 16:08:34 -0800719 dbg("%sstate=%d", __func__, break_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721 spin_lock_irqsave(&priv->lock, flags);
722 lcr = priv->last_lcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 if (break_state)
725 lcr |= MCT_U232_SET_BREAK;
Alan Cox6b447f042009-01-02 13:48:56 +0000726 spin_unlock_irqrestore(&priv->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 mct_u232_set_line_ctrl(serial, lcr);
729} /* mct_u232_break_ctl */
730
731
Alan Cox95da3102008-07-22 11:09:07 +0100732static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Alan Cox95da3102008-07-22 11:09:07 +0100734 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 struct mct_u232_private *priv = usb_get_serial_port_data(port);
736 unsigned int control_state;
737 unsigned long flags;
Alan Coxe19b2562008-07-22 11:14:30 +0100738
Harvey Harrison441b62c2008-03-03 16:08:34 -0800739 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 spin_lock_irqsave(&priv->lock, flags);
742 control_state = priv->control_state;
743 spin_unlock_irqrestore(&priv->lock, flags);
744
745 return control_state;
746}
747
Alan Cox95da3102008-07-22 11:09:07 +0100748static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 unsigned int set, unsigned int clear)
750{
Alan Cox95da3102008-07-22 11:09:07 +0100751 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 struct usb_serial *serial = port->serial;
753 struct mct_u232_private *priv = usb_get_serial_port_data(port);
754 unsigned int control_state;
755 unsigned long flags;
Alan Coxe19b2562008-07-22 11:14:30 +0100756
Harvey Harrison441b62c2008-03-03 16:08:34 -0800757 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 spin_lock_irqsave(&priv->lock, flags);
760 control_state = priv->control_state;
761
762 if (set & TIOCM_RTS)
763 control_state |= TIOCM_RTS;
764 if (set & TIOCM_DTR)
765 control_state |= TIOCM_DTR;
766 if (clear & TIOCM_RTS)
767 control_state &= ~TIOCM_RTS;
768 if (clear & TIOCM_DTR)
769 control_state &= ~TIOCM_DTR;
770
771 priv->control_state = control_state;
772 spin_unlock_irqrestore(&priv->lock, flags);
773 return mct_u232_set_modem_ctrl(serial, control_state);
774}
775
Alan Cox95da3102008-07-22 11:09:07 +0100776static void mct_u232_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777{
Alan Cox95da3102008-07-22 11:09:07 +0100778 struct usb_serial_port *port = tty->driver_data;
Dave Platt45b844d2007-05-08 11:00:12 -0700779 struct mct_u232_private *priv = usb_get_serial_port_data(port);
Dave Platt45b844d2007-05-08 11:00:12 -0700780 unsigned int control_state;
Dave Platt45b844d2007-05-08 11:00:12 -0700781
Harvey Harrison441b62c2008-03-03 16:08:34 -0800782 dbg("%s - port %d", __func__, port->number);
Dave Platt45b844d2007-05-08 11:00:12 -0700783
Oliver Neukum63832512009-10-07 10:50:23 +0200784 spin_lock_irq(&priv->lock);
Dave Platt45b844d2007-05-08 11:00:12 -0700785 priv->rx_flags |= THROTTLED;
786 if (C_CRTSCTS(tty)) {
Alan Cox95da3102008-07-22 11:09:07 +0100787 priv->control_state &= ~TIOCM_RTS;
788 control_state = priv->control_state;
Oliver Neukum63832512009-10-07 10:50:23 +0200789 spin_unlock_irq(&priv->lock);
Alan Cox95da3102008-07-22 11:09:07 +0100790 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
Dave Platt45b844d2007-05-08 11:00:12 -0700791 } else {
Oliver Neukum63832512009-10-07 10:50:23 +0200792 spin_unlock_irq(&priv->lock);
Dave Platt45b844d2007-05-08 11:00:12 -0700793 }
794}
795
796
Alan Cox95da3102008-07-22 11:09:07 +0100797static void mct_u232_unthrottle(struct tty_struct *tty)
Dave Platt45b844d2007-05-08 11:00:12 -0700798{
Alan Cox95da3102008-07-22 11:09:07 +0100799 struct usb_serial_port *port = tty->driver_data;
Dave Platt45b844d2007-05-08 11:00:12 -0700800 struct mct_u232_private *priv = usb_get_serial_port_data(port);
Dave Platt45b844d2007-05-08 11:00:12 -0700801 unsigned int control_state;
Dave Platt45b844d2007-05-08 11:00:12 -0700802
Harvey Harrison441b62c2008-03-03 16:08:34 -0800803 dbg("%s - port %d", __func__, port->number);
Dave Platt45b844d2007-05-08 11:00:12 -0700804
Oliver Neukum63832512009-10-07 10:50:23 +0200805 spin_lock_irq(&priv->lock);
Dave Platt45b844d2007-05-08 11:00:12 -0700806 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) {
Alan Cox95da3102008-07-22 11:09:07 +0100807 priv->rx_flags &= ~THROTTLED;
808 priv->control_state |= TIOCM_RTS;
809 control_state = priv->control_state;
Oliver Neukum63832512009-10-07 10:50:23 +0200810 spin_unlock_irq(&priv->lock);
Alan Cox95da3102008-07-22 11:09:07 +0100811 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
Dave Platt45b844d2007-05-08 11:00:12 -0700812 } else {
Oliver Neukum63832512009-10-07 10:50:23 +0200813 spin_unlock_irq(&priv->lock);
Dave Platt45b844d2007-05-08 11:00:12 -0700814 }
815}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Alan Coxe19b2562008-07-22 11:14:30 +0100817static int __init mct_u232_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
819 int retval;
820 retval = usb_serial_register(&mct_u232_device);
821 if (retval)
822 goto failed_usb_serial_register;
823 retval = usb_register(&mct_u232_driver);
824 if (retval)
825 goto failed_usb_register;
Greg Kroah-Hartmanc197a8d2008-08-18 13:21:04 -0700826 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
827 DRIVER_DESC "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return 0;
829failed_usb_register:
830 usb_serial_deregister(&mct_u232_device);
831failed_usb_serial_register:
832 return retval;
833}
834
835
Alan Coxe19b2562008-07-22 11:14:30 +0100836static void __exit mct_u232_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Alan Coxe19b2562008-07-22 11:14:30 +0100838 usb_deregister(&mct_u232_driver);
839 usb_serial_deregister(&mct_u232_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840}
841
Alan Coxe19b2562008-07-22 11:14:30 +0100842module_init(mct_u232_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843module_exit(mct_u232_exit);
844
Alan Coxe19b2562008-07-22 11:14:30 +0100845MODULE_AUTHOR(DRIVER_AUTHOR);
846MODULE_DESCRIPTION(DRIVER_DESC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847MODULE_LICENSE("GPL");
848
849module_param(debug, bool, S_IRUGO | S_IWUSR);
850MODULE_PARM_DESC(debug, "Debug enabled or not");