2 * MCT (Magic Control Technology Corp.) USB RS232 Converter Driver
4 * Copyright (C) 2000 Wolfgang Grandegger (wolfgang@ces.ch)
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.
35 * 06-Dec-2001 Martin Hamilton <martinh@gnu.org>
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 <linux/usb.h>
79 #include <linux/usb/serial.h>
85 #define DRIVER_VERSION "z2.1" /* Linux in-kernel version */
86 #define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>"
87 #define DRIVER_DESC "Magic Control Technology USB-RS232 converter driver"
94 static int mct_u232_startup(struct usb_serial *serial);
95 static void mct_u232_shutdown(struct usb_serial *serial);
96 static int mct_u232_open(struct tty_struct *tty,
97 struct usb_serial_port *port, struct file *filp);
98 static void mct_u232_close(struct tty_struct *tty,
99 struct usb_serial_port *port, struct file *filp);
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 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 .throttle = mct_u232_throttle,
144 .unthrottle = mct_u232_unthrottle,
145 .read_int_callback = mct_u232_read_int_callback,
146 .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,
151 .shutdown = mct_u232_shutdown,
155 struct mct_u232_private {
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 */
161 unsigned int rx_flags; /* Throttling flags */
164 #define THROTTLED 0x01
167 * Handle vendor specific USB requests
170 #define WDR_TIMEOUT 5000 /* default urb timeout */
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.
176 static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
177 speed_t value, speed_t *result)
181 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID
182 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) {
187 return 0x02; /* this one not tested */
209 /* FIXME: Can we use any divider - should we do
210 divider = 115200/value;
211 real baud = 115200/divider */
231 static int mct_u232_set_baud_rate(struct tty_struct *tty,
232 struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
236 unsigned char zero_byte = 0;
237 unsigned char cts_enable_byte = 0;
240 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value,
243 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,
248 if (rc < 0) /*FIXME: What value speed results */
249 err("Set BAUD RATE %d failed (error = %d)", value, rc);
251 tty_encode_baud_rate(tty, speed, speed);
252 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
254 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
255 always sends two extra USB 'device request' messages after the
256 'baud rate change' message. The actual functionality of the
257 request codes in these messages is not fully understood but these
258 particular codes are never seen in any operation besides a baud
259 rate change. Both of these messages send a single byte of data.
260 In the first message, the value of this byte is always zero.
262 The second message has been determined experimentally to control
263 whether data will be transmitted to a device which is not asserting
264 the 'CTS' signal. If the second message's data byte is zero, data
265 will be transmitted even if 'CTS' is not asserted (i.e. no hardware
266 flow control). if the second message's data byte is nonzero (a
267 value of 1 is used by this driver), data will not be transmitted to
268 a device which is not asserting 'CTS'.
271 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
272 MCT_U232_SET_UNKNOWN1_REQUEST,
273 MCT_U232_SET_REQUEST_TYPE,
274 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE,
277 err("Sending USB device request code %d failed (error = %d)",
278 MCT_U232_SET_UNKNOWN1_REQUEST, rc);
280 if (port && C_CRTSCTS(tty))
283 dbg("set_baud_rate: send second control message, data = %02X",
285 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
286 MCT_U232_SET_CTS_REQUEST,
287 MCT_U232_SET_REQUEST_TYPE,
288 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE,
291 err("Sending USB device request code %d failed (error = %d)",
292 MCT_U232_SET_CTS_REQUEST, rc);
295 } /* mct_u232_set_baud_rate */
297 static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
300 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
301 MCT_U232_SET_LINE_CTRL_REQUEST,
302 MCT_U232_SET_REQUEST_TYPE,
303 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE,
306 err("Set LINE CTRL 0x%x failed (error = %d)", lcr, rc);
307 dbg("set_line_ctrl: 0x%x", lcr);
309 } /* mct_u232_set_line_ctrl */
311 static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
312 unsigned int control_state)
315 unsigned char mcr = MCT_U232_MCR_NONE;
317 if (control_state & TIOCM_DTR)
318 mcr |= MCT_U232_MCR_DTR;
319 if (control_state & TIOCM_RTS)
320 mcr |= MCT_U232_MCR_RTS;
322 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
323 MCT_U232_SET_MODEM_CTRL_REQUEST,
324 MCT_U232_SET_REQUEST_TYPE,
325 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE,
328 err("Set MODEM CTRL 0x%x failed (error = %d)", mcr, rc);
329 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
332 } /* mct_u232_set_modem_ctrl */
334 static int mct_u232_get_modem_stat(struct usb_serial *serial,
338 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
339 MCT_U232_GET_MODEM_STAT_REQUEST,
340 MCT_U232_GET_REQUEST_TYPE,
341 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE,
344 err("Get MODEM STATus failed (error = %d)", rc);
347 dbg("get_modem_stat: 0x%x", *msr);
349 } /* mct_u232_get_modem_stat */
351 static void mct_u232_msr_to_state(unsigned int *control_state,
354 /* Translate Control Line states */
355 if (msr & MCT_U232_MSR_DSR)
356 *control_state |= TIOCM_DSR;
358 *control_state &= ~TIOCM_DSR;
359 if (msr & MCT_U232_MSR_CTS)
360 *control_state |= TIOCM_CTS;
362 *control_state &= ~TIOCM_CTS;
363 if (msr & MCT_U232_MSR_RI)
364 *control_state |= TIOCM_RI;
366 *control_state &= ~TIOCM_RI;
367 if (msr & MCT_U232_MSR_CD)
368 *control_state |= TIOCM_CD;
370 *control_state &= ~TIOCM_CD;
371 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state);
372 } /* mct_u232_msr_to_state */
375 * Driver's tty interface functions
378 static int mct_u232_startup(struct usb_serial *serial)
380 struct mct_u232_private *priv;
381 struct usb_serial_port *port, *rport;
383 priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
386 spin_lock_init(&priv->lock);
387 usb_set_serial_port_data(serial->port[0], priv);
389 init_waitqueue_head(&serial->port[0]->write_wait);
391 /* Puh, that's dirty */
392 port = serial->port[0];
393 rport = serial->port[1];
394 /* No unlinking, it wasn't submitted yet. */
395 usb_free_urb(port->read_urb);
396 port->read_urb = rport->interrupt_in_urb;
397 rport->interrupt_in_urb = NULL;
398 port->read_urb->context = port;
401 } /* mct_u232_startup */
404 static void mct_u232_shutdown(struct usb_serial *serial)
406 struct mct_u232_private *priv;
411 for (i = 0; i < serial->num_ports; ++i) {
412 /* My special items, the standard routines free my urbs */
413 priv = usb_get_serial_port_data(serial->port[i]);
415 usb_set_serial_port_data(serial->port[i], NULL);
419 } /* mct_u232_shutdown */
421 static int mct_u232_open(struct tty_struct *tty,
422 struct usb_serial_port *port, struct file *filp)
424 struct usb_serial *serial = port->serial;
425 struct mct_u232_private *priv = usb_get_serial_port_data(port);
427 unsigned int control_state;
429 unsigned char last_lcr;
430 unsigned char last_msr;
432 dbg("%s port %d", __func__, port->number);
434 /* Compensate for a hardware bug: although the Sitecom U232-P25
435 * device reports a maximum output packet size of 32 bytes,
436 * it seems to be able to accept only 16 bytes (and that's what
437 * SniffUSB says too...)
439 if (le16_to_cpu(serial->dev->descriptor.idProduct)
440 == MCT_U232_SITECOM_PID)
441 port->bulk_out_size = 16;
443 /* Do a defined restart: the normal serial device seems to
444 * always turn on DTR and RTS here, so do the same. I'm not
445 * sure if this is really necessary. But it should not harm
448 spin_lock_irqsave(&priv->lock, flags);
449 if (tty && (tty->termios->c_cflag & CBAUD))
450 priv->control_state = TIOCM_DTR | TIOCM_RTS;
452 priv->control_state = 0;
454 priv->last_lcr = (MCT_U232_DATA_BITS_8 |
455 MCT_U232_PARITY_NONE |
456 MCT_U232_STOP_BITS_1);
457 control_state = priv->control_state;
458 last_lcr = priv->last_lcr;
459 spin_unlock_irqrestore(&priv->lock, flags);
460 mct_u232_set_modem_ctrl(serial, control_state);
461 mct_u232_set_line_ctrl(serial, last_lcr);
463 /* Read modem status and update control state */
464 mct_u232_get_modem_stat(serial, &last_msr);
465 spin_lock_irqsave(&priv->lock, flags);
466 priv->last_msr = last_msr;
467 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
468 spin_unlock_irqrestore(&priv->lock, flags);
470 port->read_urb->dev = port->serial->dev;
471 retval = usb_submit_urb(port->read_urb, GFP_KERNEL);
473 err("usb_submit_urb(read bulk) failed pipe 0x%x err %d",
474 port->read_urb->pipe, retval);
478 port->interrupt_in_urb->dev = port->serial->dev;
479 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
481 usb_kill_urb(port->read_urb);
482 err(" usb_submit_urb(read int) failed pipe 0x%x err %d",
483 port->interrupt_in_urb->pipe, retval);
490 } /* mct_u232_open */
493 static void mct_u232_close(struct tty_struct *tty,
494 struct usb_serial_port *port, struct file *filp)
496 unsigned int c_cflag;
497 unsigned int control_state;
498 struct mct_u232_private *priv = usb_get_serial_port_data(port);
499 dbg("%s port %d", __func__, port->number);
502 c_cflag = tty->termios->c_cflag;
503 mutex_lock(&port->serial->disc_mutex);
504 if (c_cflag & HUPCL && !port->serial->disconnected) {
505 /* drop DTR and RTS */
506 spin_lock_irq(&priv->lock);
507 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
508 control_state = priv->control_state;
509 spin_unlock_irq(&priv->lock);
510 mct_u232_set_modem_ctrl(port->serial, control_state);
512 mutex_unlock(&port->serial->disc_mutex);
516 if (port->serial->dev) {
517 /* shutdown our urbs */
518 usb_kill_urb(port->write_urb);
519 usb_kill_urb(port->read_urb);
520 usb_kill_urb(port->interrupt_in_urb);
522 } /* mct_u232_close */
525 static void mct_u232_read_int_callback(struct urb *urb)
527 struct usb_serial_port *port = urb->context;
528 struct mct_u232_private *priv = usb_get_serial_port_data(port);
529 struct usb_serial *serial = port->serial;
530 struct tty_struct *tty;
531 unsigned char *data = urb->transfer_buffer;
533 int status = urb->status;
543 /* this urb is terminated, clean up */
544 dbg("%s - urb shutting down with status: %d",
548 dbg("%s - nonzero urb status received: %d",
554 dbg("%s - bad serial pointer, exiting", __func__);
558 dbg("%s - port %d", __func__, port->number);
559 usb_serial_debug_data(debug, &port->dev, __func__,
560 urb->actual_length, data);
563 * Work-a-round: handle the 'usual' bulk-in pipe here
565 if (urb->transfer_buffer_length > 2) {
566 tty = port->port.tty;
567 if (urb->actual_length) {
568 tty_insert_flip_string(tty, data, urb->actual_length);
569 tty_flip_buffer_push(tty);
575 * The interrupt-in pipe signals exceptional conditions (modem line
576 * signal changes and errors). data[0] holds MSR, data[1] holds LSR.
578 spin_lock_irqsave(&priv->lock, flags);
579 priv->last_msr = data[MCT_U232_MSR_INDEX];
581 /* Record Control Line states */
582 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
585 /* Not yet handled. See belkin_sa.c for further information */
586 /* Now to report any errors */
587 priv->last_lsr = data[MCT_U232_LSR_INDEX];
589 * fill in the flip buffer here, but I do not know the relation
590 * to the current/next receive buffer or characters. I need
591 * to look in to this before committing any code.
593 if (priv->last_lsr & MCT_U232_LSR_ERR) {
594 tty = port->port.tty;
596 if (priv->last_lsr & MCT_U232_LSR_OE) {
599 if (priv->last_lsr & MCT_U232_LSR_PE) {
602 if (priv->last_lsr & MCT_U232_LSR_FE) {
604 /* Break Indicator */
605 if (priv->last_lsr & MCT_U232_LSR_BI) {
609 spin_unlock_irqrestore(&priv->lock, flags);
611 retval = usb_submit_urb(urb, GFP_ATOMIC);
613 err("%s - usb_submit_urb failed with result %d",
615 } /* mct_u232_read_int_callback */
617 static void mct_u232_set_termios(struct tty_struct *tty,
618 struct usb_serial_port *port,
619 struct ktermios *old_termios)
621 struct usb_serial *serial = port->serial;
622 struct mct_u232_private *priv = usb_get_serial_port_data(port);
623 struct ktermios *termios = tty->termios;
624 unsigned int cflag = termios->c_cflag;
625 unsigned int old_cflag = old_termios->c_cflag;
627 unsigned int control_state;
628 unsigned char last_lcr;
630 /* get a local copy of the current port settings */
631 spin_lock_irqsave(&priv->lock, flags);
632 control_state = priv->control_state;
633 spin_unlock_irqrestore(&priv->lock, flags);
638 * Do not attempt to cache old rates and skip settings,
639 * disconnects screw such tricks up completely.
640 * Premature optimization is the root of all evil.
643 /* reassert DTR and RTS on transition from B0 */
644 if ((old_cflag & CBAUD) == B0) {
645 dbg("%s: baud was B0", __func__);
646 control_state |= TIOCM_DTR | TIOCM_RTS;
647 mct_u232_set_modem_ctrl(serial, control_state);
650 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
652 if ((cflag & CBAUD) == B0) {
653 dbg("%s: baud is B0", __func__);
654 /* Drop RTS and DTR */
655 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
656 mct_u232_set_modem_ctrl(serial, control_state);
660 * Update line control register (LCR)
665 last_lcr |= (cflag & PARODD) ?
666 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
668 last_lcr |= MCT_U232_PARITY_NONE;
670 /* set the number of data bits */
671 switch (cflag & CSIZE) {
673 last_lcr |= MCT_U232_DATA_BITS_5; break;
675 last_lcr |= MCT_U232_DATA_BITS_6; break;
677 last_lcr |= MCT_U232_DATA_BITS_7; break;
679 last_lcr |= MCT_U232_DATA_BITS_8; break;
681 err("CSIZE was not CS5-CS8, using default of 8");
682 last_lcr |= MCT_U232_DATA_BITS_8;
686 termios->c_cflag &= ~CMSPAR;
688 /* set the number of stop bits */
689 last_lcr |= (cflag & CSTOPB) ?
690 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
692 mct_u232_set_line_ctrl(serial, last_lcr);
694 /* save off the modified port settings */
695 spin_lock_irqsave(&priv->lock, flags);
696 priv->control_state = control_state;
697 priv->last_lcr = last_lcr;
698 spin_unlock_irqrestore(&priv->lock, flags);
699 } /* mct_u232_set_termios */
701 static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
703 struct usb_serial_port *port = tty->driver_data;
704 struct usb_serial *serial = port->serial;
705 struct mct_u232_private *priv = usb_get_serial_port_data(port);
709 dbg("%sstate=%d", __func__, break_state);
711 spin_lock_irqsave(&priv->lock, flags);
712 lcr = priv->last_lcr;
713 spin_unlock_irqrestore(&priv->lock, flags);
716 lcr |= MCT_U232_SET_BREAK;
718 mct_u232_set_line_ctrl(serial, lcr);
719 } /* mct_u232_break_ctl */
722 static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
724 struct usb_serial_port *port = tty->driver_data;
725 struct mct_u232_private *priv = usb_get_serial_port_data(port);
726 unsigned int control_state;
731 spin_lock_irqsave(&priv->lock, flags);
732 control_state = priv->control_state;
733 spin_unlock_irqrestore(&priv->lock, flags);
735 return control_state;
738 static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
739 unsigned int set, unsigned int clear)
741 struct usb_serial_port *port = tty->driver_data;
742 struct usb_serial *serial = port->serial;
743 struct mct_u232_private *priv = usb_get_serial_port_data(port);
744 unsigned int control_state;
749 spin_lock_irqsave(&priv->lock, flags);
750 control_state = priv->control_state;
753 control_state |= TIOCM_RTS;
755 control_state |= TIOCM_DTR;
756 if (clear & TIOCM_RTS)
757 control_state &= ~TIOCM_RTS;
758 if (clear & TIOCM_DTR)
759 control_state &= ~TIOCM_DTR;
761 priv->control_state = control_state;
762 spin_unlock_irqrestore(&priv->lock, flags);
763 return mct_u232_set_modem_ctrl(serial, control_state);
766 static void mct_u232_throttle(struct tty_struct *tty)
768 struct usb_serial_port *port = tty->driver_data;
769 struct mct_u232_private *priv = usb_get_serial_port_data(port);
771 unsigned int control_state;
773 dbg("%s - port %d", __func__, port->number);
775 spin_lock_irqsave(&priv->lock, flags);
776 priv->rx_flags |= THROTTLED;
777 if (C_CRTSCTS(tty)) {
778 priv->control_state &= ~TIOCM_RTS;
779 control_state = priv->control_state;
780 spin_unlock_irqrestore(&priv->lock, flags);
781 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
783 spin_unlock_irqrestore(&priv->lock, flags);
788 static void mct_u232_unthrottle(struct tty_struct *tty)
790 struct usb_serial_port *port = tty->driver_data;
791 struct mct_u232_private *priv = usb_get_serial_port_data(port);
793 unsigned int control_state;
795 dbg("%s - port %d", __func__, port->number);
797 spin_lock_irqsave(&priv->lock, flags);
798 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) {
799 priv->rx_flags &= ~THROTTLED;
800 priv->control_state |= TIOCM_RTS;
801 control_state = priv->control_state;
802 spin_unlock_irqrestore(&priv->lock, flags);
803 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
805 spin_unlock_irqrestore(&priv->lock, flags);
809 static int __init mct_u232_init(void)
812 retval = usb_serial_register(&mct_u232_device);
814 goto failed_usb_serial_register;
815 retval = usb_register(&mct_u232_driver);
817 goto failed_usb_register;
818 info(DRIVER_DESC " " DRIVER_VERSION);
821 usb_serial_deregister(&mct_u232_device);
822 failed_usb_serial_register:
827 static void __exit mct_u232_exit(void)
829 usb_deregister(&mct_u232_driver);
830 usb_serial_deregister(&mct_u232_device);
833 module_init(mct_u232_init);
834 module_exit(mct_u232_exit);
836 MODULE_AUTHOR(DRIVER_AUTHOR);
837 MODULE_DESCRIPTION(DRIVER_DESC);
838 MODULE_LICENSE("GPL");
840 module_param(debug, bool, S_IRUGO | S_IWUSR);
841 MODULE_PARM_DESC(debug, "Debug enabled or not");