2 * MCT (Magic Control Technology Corp.) USB RS232 Converter Driver
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.
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.
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.
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.
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).
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.
32 * 10-Nov-2001 Wolfgang Grandegger
33 * - Fixed an endianess problem with the baudrate selection for PowerPC.
36 * - Added support for the Belkin F5U109 DB9 adaptor
38 * 30-May-2001 Greg Kroah-Hartman
39 * - switched from using spinlock to a semaphore, which fixes lots of
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).
47 * 02-May-2001 Stelian Pop
48 * - Fixed the baud calculation for Sitecom U232-P25 model
51 * - Identify version on module load.
53 * 06-Jan-2001 Cornel Ciocirlan
54 * - Added support for Sitecom U232-P25 model (Product Id 0x0230)
55 * - Added support for D-Link DU-H3SP USB BAY (Product Id 0x0200)
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.
63 * 27-Nov-2000 Wolfgang Grandegge
64 * A version for kernel 2.4.0-test10 released to the Linux community
65 * (via linux-usb-devel).
68 #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>
77 #include <linux/uaccess.h>
78 #include <asm/unaligned.h>
79 #include <linux/usb.h>
80 #include <linux/usb/serial.h>
86 #define DRIVER_VERSION "z2.1" /* Linux in-kernel version */
88 #define DRIVER_DESC "Magic Control Technology USB-RS232 converter driver"
95 static int mct_u232_startup(struct usb_serial *serial);
96 static void mct_u232_release(struct usb_serial *serial);
97 static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port);
98 static void mct_u232_close(struct usb_serial_port *port);
99 static void mct_u232_dtr_rts(struct usb_serial_port *port, int on);
100 static void mct_u232_read_int_callback(struct urb *urb);
101 static void mct_u232_set_termios(struct tty_struct *tty,
102 struct usb_serial_port *port, struct ktermios *old);
103 static void mct_u232_break_ctl(struct tty_struct *tty, int break_state);
104 static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file);
105 static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
106 unsigned int set, unsigned int clear);
107 static void mct_u232_throttle(struct tty_struct *tty);
108 static void mct_u232_unthrottle(struct tty_struct *tty);
112 * All of the device info needed for the MCT USB-RS232 converter.
114 static const struct usb_device_id id_table_combined[] = {
115 { USB_DEVICE(MCT_U232_VID, MCT_U232_PID) },
116 { USB_DEVICE(MCT_U232_VID, MCT_U232_SITECOM_PID) },
117 { USB_DEVICE(MCT_U232_VID, MCT_U232_DU_H3SP_PID) },
118 { USB_DEVICE(MCT_U232_BELKIN_F5U109_VID, MCT_U232_BELKIN_F5U109_PID) },
119 { } /* Terminating entry */
122 MODULE_DEVICE_TABLE(usb, id_table_combined);
124 static struct usb_driver mct_u232_driver = {
126 .probe = usb_serial_probe,
127 .disconnect = usb_serial_disconnect,
128 .id_table = id_table_combined,
132 static struct usb_serial_driver mct_u232_device = {
134 .owner = THIS_MODULE,
137 .description = "MCT U232",
138 .usb_driver = &mct_u232_driver,
139 .id_table = id_table_combined,
141 .open = mct_u232_open,
142 .close = mct_u232_close,
143 .dtr_rts = mct_u232_dtr_rts,
144 .throttle = mct_u232_throttle,
145 .unthrottle = mct_u232_unthrottle,
146 .read_int_callback = mct_u232_read_int_callback,
147 .set_termios = mct_u232_set_termios,
148 .break_ctl = mct_u232_break_ctl,
149 .tiocmget = mct_u232_tiocmget,
150 .tiocmset = mct_u232_tiocmset,
151 .attach = mct_u232_startup,
152 .release = mct_u232_release,
156 struct mct_u232_private {
158 unsigned int control_state; /* Modem Line Setting (TIOCM) */
159 unsigned char last_lcr; /* Line Control Register */
160 unsigned char last_lsr; /* Line Status Register */
161 unsigned char last_msr; /* Modem Status Register */
162 unsigned int rx_flags; /* Throttling flags */
165 #define THROTTLED 0x01
168 * Handle vendor specific USB requests
171 #define WDR_TIMEOUT 5000 /* default urb timeout */
174 * Later day 2.6.0-test kernels have new baud rates like B230400 which
175 * we do not know how to support. We ignore them for the moment.
177 static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
178 speed_t value, speed_t *result)
182 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID
183 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) {
188 return 0x02; /* this one not tested */
210 /* FIXME: Can we use any divider - should we do
211 divider = 115200/value;
212 real baud = 115200/divider */
232 static int mct_u232_set_baud_rate(struct tty_struct *tty,
233 struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
235 unsigned int divisor;
238 unsigned char cts_enable_byte = 0;
241 buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
245 divisor = mct_u232_calculate_baud_rate(serial, value, &speed);
246 put_unaligned_le32(cpu_to_le32(divisor), buf);
247 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
248 MCT_U232_SET_BAUD_RATE_REQUEST,
249 MCT_U232_SET_REQUEST_TYPE,
250 0, 0, buf, MCT_U232_SET_BAUD_RATE_SIZE,
252 if (rc < 0) /*FIXME: What value speed results */
253 dev_err(&port->dev, "Set BAUD RATE %d failed (error = %d)\n",
256 tty_encode_baud_rate(tty, speed, speed);
257 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
259 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
260 always sends two extra USB 'device request' messages after the
261 'baud rate change' message. The actual functionality of the
262 request codes in these messages is not fully understood but these
263 particular codes are never seen in any operation besides a baud
264 rate change. Both of these messages send a single byte of data.
265 In the first message, the value of this byte is always zero.
267 The second message has been determined experimentally to control
268 whether data will be transmitted to a device which is not asserting
269 the 'CTS' signal. If the second message's data byte is zero, data
270 will be transmitted even if 'CTS' is not asserted (i.e. no hardware
271 flow control). if the second message's data byte is nonzero (a
272 value of 1 is used by this driver), data will not be transmitted to
273 a device which is not asserting 'CTS'.
277 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
278 MCT_U232_SET_UNKNOWN1_REQUEST,
279 MCT_U232_SET_REQUEST_TYPE,
280 0, 0, buf, MCT_U232_SET_UNKNOWN1_SIZE,
283 dev_err(&port->dev, "Sending USB device request code %d "
284 "failed (error = %d)\n", MCT_U232_SET_UNKNOWN1_REQUEST,
287 if (port && C_CRTSCTS(tty))
290 dbg("set_baud_rate: send second control message, data = %02X",
292 buf[0] = cts_enable_byte;
293 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
294 MCT_U232_SET_CTS_REQUEST,
295 MCT_U232_SET_REQUEST_TYPE,
296 0, 0, buf, MCT_U232_SET_CTS_SIZE,
299 dev_err(&port->dev, "Sending USB device request code %d "
300 "failed (error = %d)\n", MCT_U232_SET_CTS_REQUEST, rc);
304 } /* mct_u232_set_baud_rate */
306 static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
311 buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
316 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
317 MCT_U232_SET_LINE_CTRL_REQUEST,
318 MCT_U232_SET_REQUEST_TYPE,
319 0, 0, buf, MCT_U232_SET_LINE_CTRL_SIZE,
322 dev_err(&serial->dev->dev,
323 "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc);
324 dbg("set_line_ctrl: 0x%x", lcr);
327 } /* mct_u232_set_line_ctrl */
329 static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
330 unsigned int control_state)
336 buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
340 mcr = MCT_U232_MCR_NONE;
341 if (control_state & TIOCM_DTR)
342 mcr |= MCT_U232_MCR_DTR;
343 if (control_state & TIOCM_RTS)
344 mcr |= MCT_U232_MCR_RTS;
347 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
348 MCT_U232_SET_MODEM_CTRL_REQUEST,
349 MCT_U232_SET_REQUEST_TYPE,
350 0, 0, buf, MCT_U232_SET_MODEM_CTRL_SIZE,
353 dev_err(&serial->dev->dev,
354 "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc);
355 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
359 } /* mct_u232_set_modem_ctrl */
361 static int mct_u232_get_modem_stat(struct usb_serial *serial,
367 buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
372 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
373 MCT_U232_GET_MODEM_STAT_REQUEST,
374 MCT_U232_GET_REQUEST_TYPE,
375 0, 0, buf, MCT_U232_GET_MODEM_STAT_SIZE,
378 dev_err(&serial->dev->dev,
379 "Get MODEM STATus failed (error = %d)\n", rc);
384 dbg("get_modem_stat: 0x%x", *msr);
387 } /* mct_u232_get_modem_stat */
389 static void mct_u232_msr_to_state(unsigned int *control_state,
392 /* Translate Control Line states */
393 if (msr & MCT_U232_MSR_DSR)
394 *control_state |= TIOCM_DSR;
396 *control_state &= ~TIOCM_DSR;
397 if (msr & MCT_U232_MSR_CTS)
398 *control_state |= TIOCM_CTS;
400 *control_state &= ~TIOCM_CTS;
401 if (msr & MCT_U232_MSR_RI)
402 *control_state |= TIOCM_RI;
404 *control_state &= ~TIOCM_RI;
405 if (msr & MCT_U232_MSR_CD)
406 *control_state |= TIOCM_CD;
408 *control_state &= ~TIOCM_CD;
409 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state);
410 } /* mct_u232_msr_to_state */
413 * Driver's tty interface functions
416 static int mct_u232_startup(struct usb_serial *serial)
418 struct mct_u232_private *priv;
419 struct usb_serial_port *port, *rport;
421 priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
424 spin_lock_init(&priv->lock);
425 usb_set_serial_port_data(serial->port[0], priv);
427 init_waitqueue_head(&serial->port[0]->write_wait);
429 /* Puh, that's dirty */
430 port = serial->port[0];
431 rport = serial->port[1];
432 /* No unlinking, it wasn't submitted yet. */
433 usb_free_urb(port->read_urb);
434 port->read_urb = rport->interrupt_in_urb;
435 rport->interrupt_in_urb = NULL;
436 port->read_urb->context = port;
439 } /* mct_u232_startup */
442 static void mct_u232_release(struct usb_serial *serial)
444 struct mct_u232_private *priv;
449 for (i = 0; i < serial->num_ports; ++i) {
450 /* My special items, the standard routines free my urbs */
451 priv = usb_get_serial_port_data(serial->port[i]);
454 } /* mct_u232_release */
456 static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port)
458 struct usb_serial *serial = port->serial;
459 struct mct_u232_private *priv = usb_get_serial_port_data(port);
461 unsigned int control_state;
463 unsigned char last_lcr;
464 unsigned char last_msr;
466 dbg("%s port %d", __func__, port->number);
468 /* Compensate for a hardware bug: although the Sitecom U232-P25
469 * device reports a maximum output packet size of 32 bytes,
470 * it seems to be able to accept only 16 bytes (and that's what
471 * SniffUSB says too...)
473 if (le16_to_cpu(serial->dev->descriptor.idProduct)
474 == MCT_U232_SITECOM_PID)
475 port->bulk_out_size = 16;
477 /* Do a defined restart: the normal serial device seems to
478 * always turn on DTR and RTS here, so do the same. I'm not
479 * sure if this is really necessary. But it should not harm
482 spin_lock_irqsave(&priv->lock, flags);
483 if (tty && (tty->termios->c_cflag & CBAUD))
484 priv->control_state = TIOCM_DTR | TIOCM_RTS;
486 priv->control_state = 0;
488 priv->last_lcr = (MCT_U232_DATA_BITS_8 |
489 MCT_U232_PARITY_NONE |
490 MCT_U232_STOP_BITS_1);
491 control_state = priv->control_state;
492 last_lcr = priv->last_lcr;
493 spin_unlock_irqrestore(&priv->lock, flags);
494 mct_u232_set_modem_ctrl(serial, control_state);
495 mct_u232_set_line_ctrl(serial, last_lcr);
497 /* Read modem status and update control state */
498 mct_u232_get_modem_stat(serial, &last_msr);
499 spin_lock_irqsave(&priv->lock, flags);
500 priv->last_msr = last_msr;
501 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
502 spin_unlock_irqrestore(&priv->lock, flags);
504 port->read_urb->dev = port->serial->dev;
505 retval = usb_submit_urb(port->read_urb, GFP_KERNEL);
508 "usb_submit_urb(read bulk) failed pipe 0x%x err %d\n",
509 port->read_urb->pipe, retval);
513 port->interrupt_in_urb->dev = port->serial->dev;
514 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
516 usb_kill_urb(port->read_urb);
518 "usb_submit_urb(read int) failed pipe 0x%x err %d",
519 port->interrupt_in_urb->pipe, retval);
526 } /* mct_u232_open */
528 static void mct_u232_dtr_rts(struct usb_serial_port *port, int on)
530 unsigned int control_state;
531 struct mct_u232_private *priv = usb_get_serial_port_data(port);
533 mutex_lock(&port->serial->disc_mutex);
534 if (!port->serial->disconnected) {
535 /* drop DTR and RTS */
536 spin_lock_irq(&priv->lock);
538 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
540 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
541 control_state = priv->control_state;
542 spin_unlock_irq(&priv->lock);
543 mct_u232_set_modem_ctrl(port->serial, control_state);
545 mutex_unlock(&port->serial->disc_mutex);
548 static void mct_u232_close(struct usb_serial_port *port)
550 dbg("%s port %d", __func__, port->number);
552 usb_serial_generic_close(port);
553 if (port->serial->dev)
554 usb_kill_urb(port->interrupt_in_urb);
555 } /* mct_u232_close */
558 static void mct_u232_read_int_callback(struct urb *urb)
560 struct usb_serial_port *port = urb->context;
561 struct mct_u232_private *priv = usb_get_serial_port_data(port);
562 struct usb_serial *serial = port->serial;
563 struct tty_struct *tty;
564 unsigned char *data = urb->transfer_buffer;
566 int status = urb->status;
576 /* this urb is terminated, clean up */
577 dbg("%s - urb shutting down with status: %d",
581 dbg("%s - nonzero urb status received: %d",
587 dbg("%s - bad serial pointer, exiting", __func__);
591 dbg("%s - port %d", __func__, port->number);
592 usb_serial_debug_data(debug, &port->dev, __func__,
593 urb->actual_length, data);
596 * Work-a-round: handle the 'usual' bulk-in pipe here
598 if (urb->transfer_buffer_length > 2) {
599 if (urb->actual_length) {
600 tty = tty_port_tty_get(&port->port);
602 tty_insert_flip_string(tty, data,
604 tty_flip_buffer_push(tty);
612 * The interrupt-in pipe signals exceptional conditions (modem line
613 * signal changes and errors). data[0] holds MSR, data[1] holds LSR.
615 spin_lock_irqsave(&priv->lock, flags);
616 priv->last_msr = data[MCT_U232_MSR_INDEX];
618 /* Record Control Line states */
619 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
622 /* Not yet handled. See belkin_sa.c for further information */
623 /* Now to report any errors */
624 priv->last_lsr = data[MCT_U232_LSR_INDEX];
626 * fill in the flip buffer here, but I do not know the relation
627 * to the current/next receive buffer or characters. I need
628 * to look in to this before committing any code.
630 if (priv->last_lsr & MCT_U232_LSR_ERR) {
631 tty = tty_port_tty_get(&port->port);
633 if (priv->last_lsr & MCT_U232_LSR_OE) {
636 if (priv->last_lsr & MCT_U232_LSR_PE) {
639 if (priv->last_lsr & MCT_U232_LSR_FE) {
641 /* Break Indicator */
642 if (priv->last_lsr & MCT_U232_LSR_BI) {
647 spin_unlock_irqrestore(&priv->lock, flags);
649 retval = usb_submit_urb(urb, GFP_ATOMIC);
652 "%s - usb_submit_urb failed with result %d\n",
654 } /* mct_u232_read_int_callback */
656 static void mct_u232_set_termios(struct tty_struct *tty,
657 struct usb_serial_port *port,
658 struct ktermios *old_termios)
660 struct usb_serial *serial = port->serial;
661 struct mct_u232_private *priv = usb_get_serial_port_data(port);
662 struct ktermios *termios = tty->termios;
663 unsigned int cflag = termios->c_cflag;
664 unsigned int old_cflag = old_termios->c_cflag;
666 unsigned int control_state;
667 unsigned char last_lcr;
669 /* get a local copy of the current port settings */
670 spin_lock_irqsave(&priv->lock, flags);
671 control_state = priv->control_state;
672 spin_unlock_irqrestore(&priv->lock, flags);
677 * Do not attempt to cache old rates and skip settings,
678 * disconnects screw such tricks up completely.
679 * Premature optimization is the root of all evil.
682 /* reassert DTR and RTS on transition from B0 */
683 if ((old_cflag & CBAUD) == B0) {
684 dbg("%s: baud was B0", __func__);
685 control_state |= TIOCM_DTR | TIOCM_RTS;
686 mct_u232_set_modem_ctrl(serial, control_state);
689 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
691 if ((cflag & CBAUD) == B0) {
692 dbg("%s: baud is B0", __func__);
693 /* Drop RTS and DTR */
694 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
695 mct_u232_set_modem_ctrl(serial, control_state);
699 * Update line control register (LCR)
704 last_lcr |= (cflag & PARODD) ?
705 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
707 last_lcr |= MCT_U232_PARITY_NONE;
709 /* set the number of data bits */
710 switch (cflag & CSIZE) {
712 last_lcr |= MCT_U232_DATA_BITS_5; break;
714 last_lcr |= MCT_U232_DATA_BITS_6; break;
716 last_lcr |= MCT_U232_DATA_BITS_7; break;
718 last_lcr |= MCT_U232_DATA_BITS_8; break;
721 "CSIZE was not CS5-CS8, using default of 8\n");
722 last_lcr |= MCT_U232_DATA_BITS_8;
726 termios->c_cflag &= ~CMSPAR;
728 /* set the number of stop bits */
729 last_lcr |= (cflag & CSTOPB) ?
730 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
732 mct_u232_set_line_ctrl(serial, last_lcr);
734 /* save off the modified port settings */
735 spin_lock_irqsave(&priv->lock, flags);
736 priv->control_state = control_state;
737 priv->last_lcr = last_lcr;
738 spin_unlock_irqrestore(&priv->lock, flags);
739 } /* mct_u232_set_termios */
741 static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
743 struct usb_serial_port *port = tty->driver_data;
744 struct usb_serial *serial = port->serial;
745 struct mct_u232_private *priv = usb_get_serial_port_data(port);
749 dbg("%sstate=%d", __func__, break_state);
751 spin_lock_irqsave(&priv->lock, flags);
752 lcr = priv->last_lcr;
755 lcr |= MCT_U232_SET_BREAK;
756 spin_unlock_irqrestore(&priv->lock, flags);
758 mct_u232_set_line_ctrl(serial, lcr);
759 } /* mct_u232_break_ctl */
762 static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
764 struct usb_serial_port *port = tty->driver_data;
765 struct mct_u232_private *priv = usb_get_serial_port_data(port);
766 unsigned int control_state;
771 spin_lock_irqsave(&priv->lock, flags);
772 control_state = priv->control_state;
773 spin_unlock_irqrestore(&priv->lock, flags);
775 return control_state;
778 static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
779 unsigned int set, unsigned int clear)
781 struct usb_serial_port *port = tty->driver_data;
782 struct usb_serial *serial = port->serial;
783 struct mct_u232_private *priv = usb_get_serial_port_data(port);
784 unsigned int control_state;
789 spin_lock_irqsave(&priv->lock, flags);
790 control_state = priv->control_state;
793 control_state |= TIOCM_RTS;
795 control_state |= TIOCM_DTR;
796 if (clear & TIOCM_RTS)
797 control_state &= ~TIOCM_RTS;
798 if (clear & TIOCM_DTR)
799 control_state &= ~TIOCM_DTR;
801 priv->control_state = control_state;
802 spin_unlock_irqrestore(&priv->lock, flags);
803 return mct_u232_set_modem_ctrl(serial, control_state);
806 static void mct_u232_throttle(struct tty_struct *tty)
808 struct usb_serial_port *port = tty->driver_data;
809 struct mct_u232_private *priv = usb_get_serial_port_data(port);
810 unsigned int control_state;
812 dbg("%s - port %d", __func__, port->number);
814 spin_lock_irq(&priv->lock);
815 priv->rx_flags |= THROTTLED;
816 if (C_CRTSCTS(tty)) {
817 priv->control_state &= ~TIOCM_RTS;
818 control_state = priv->control_state;
819 spin_unlock_irq(&priv->lock);
820 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
822 spin_unlock_irq(&priv->lock);
827 static void mct_u232_unthrottle(struct tty_struct *tty)
829 struct usb_serial_port *port = tty->driver_data;
830 struct mct_u232_private *priv = usb_get_serial_port_data(port);
831 unsigned int control_state;
833 dbg("%s - port %d", __func__, port->number);
835 spin_lock_irq(&priv->lock);
836 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) {
837 priv->rx_flags &= ~THROTTLED;
838 priv->control_state |= TIOCM_RTS;
839 control_state = priv->control_state;
840 spin_unlock_irq(&priv->lock);
841 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
843 spin_unlock_irq(&priv->lock);
847 static int __init mct_u232_init(void)
850 retval = usb_serial_register(&mct_u232_device);
852 goto failed_usb_serial_register;
853 retval = usb_register(&mct_u232_driver);
855 goto failed_usb_register;
856 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
860 usb_serial_deregister(&mct_u232_device);
861 failed_usb_serial_register:
866 static void __exit mct_u232_exit(void)
868 usb_deregister(&mct_u232_driver);
869 usb_serial_deregister(&mct_u232_device);
872 module_init(mct_u232_init);
873 module_exit(mct_u232_exit);
875 MODULE_AUTHOR(DRIVER_AUTHOR);
876 MODULE_DESCRIPTION(DRIVER_DESC);
877 MODULE_LICENSE("GPL");
879 module_param(debug, bool, S_IRUGO | S_IWUSR);
880 MODULE_PARM_DESC(debug, "Debug enabled or not");