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 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 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 .shutdown = mct_u232_shutdown,
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)
237 unsigned char zero_byte = 0;
238 unsigned char cts_enable_byte = 0;
241 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value,
244 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
245 MCT_U232_SET_BAUD_RATE_REQUEST,
246 MCT_U232_SET_REQUEST_TYPE,
247 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE,
249 if (rc < 0) /*FIXME: What value speed results */
250 dev_err(&port->dev, "Set BAUD RATE %d failed (error = %d)\n",
253 tty_encode_baud_rate(tty, speed, speed);
254 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
256 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
257 always sends two extra USB 'device request' messages after the
258 'baud rate change' message. The actual functionality of the
259 request codes in these messages is not fully understood but these
260 particular codes are never seen in any operation besides a baud
261 rate change. Both of these messages send a single byte of data.
262 In the first message, the value of this byte is always zero.
264 The second message has been determined experimentally to control
265 whether data will be transmitted to a device which is not asserting
266 the 'CTS' signal. If the second message's data byte is zero, data
267 will be transmitted even if 'CTS' is not asserted (i.e. no hardware
268 flow control). if the second message's data byte is nonzero (a
269 value of 1 is used by this driver), data will not be transmitted to
270 a device which is not asserting 'CTS'.
273 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
274 MCT_U232_SET_UNKNOWN1_REQUEST,
275 MCT_U232_SET_REQUEST_TYPE,
276 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE,
279 dev_err(&port->dev, "Sending USB device request code %d "
280 "failed (error = %d)\n", MCT_U232_SET_UNKNOWN1_REQUEST,
283 if (port && C_CRTSCTS(tty))
286 dbg("set_baud_rate: send second control message, data = %02X",
288 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
289 MCT_U232_SET_CTS_REQUEST,
290 MCT_U232_SET_REQUEST_TYPE,
291 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE,
294 dev_err(&port->dev, "Sending USB device request code %d "
295 "failed (error = %d)\n", MCT_U232_SET_CTS_REQUEST, rc);
298 } /* mct_u232_set_baud_rate */
300 static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
303 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
304 MCT_U232_SET_LINE_CTRL_REQUEST,
305 MCT_U232_SET_REQUEST_TYPE,
306 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE,
309 dev_err(&serial->dev->dev,
310 "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc);
311 dbg("set_line_ctrl: 0x%x", lcr);
313 } /* mct_u232_set_line_ctrl */
315 static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
316 unsigned int control_state)
319 unsigned char mcr = MCT_U232_MCR_NONE;
321 if (control_state & TIOCM_DTR)
322 mcr |= MCT_U232_MCR_DTR;
323 if (control_state & TIOCM_RTS)
324 mcr |= MCT_U232_MCR_RTS;
326 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
327 MCT_U232_SET_MODEM_CTRL_REQUEST,
328 MCT_U232_SET_REQUEST_TYPE,
329 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE,
332 dev_err(&serial->dev->dev,
333 "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc);
334 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
337 } /* mct_u232_set_modem_ctrl */
339 static int mct_u232_get_modem_stat(struct usb_serial *serial,
343 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
344 MCT_U232_GET_MODEM_STAT_REQUEST,
345 MCT_U232_GET_REQUEST_TYPE,
346 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE,
349 dev_err(&serial->dev->dev,
350 "Get MODEM STATus failed (error = %d)\n", rc);
353 dbg("get_modem_stat: 0x%x", *msr);
355 } /* mct_u232_get_modem_stat */
357 static void mct_u232_msr_to_state(unsigned int *control_state,
360 /* Translate Control Line states */
361 if (msr & MCT_U232_MSR_DSR)
362 *control_state |= TIOCM_DSR;
364 *control_state &= ~TIOCM_DSR;
365 if (msr & MCT_U232_MSR_CTS)
366 *control_state |= TIOCM_CTS;
368 *control_state &= ~TIOCM_CTS;
369 if (msr & MCT_U232_MSR_RI)
370 *control_state |= TIOCM_RI;
372 *control_state &= ~TIOCM_RI;
373 if (msr & MCT_U232_MSR_CD)
374 *control_state |= TIOCM_CD;
376 *control_state &= ~TIOCM_CD;
377 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state);
378 } /* mct_u232_msr_to_state */
381 * Driver's tty interface functions
384 static int mct_u232_startup(struct usb_serial *serial)
386 struct mct_u232_private *priv;
387 struct usb_serial_port *port, *rport;
389 priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
392 spin_lock_init(&priv->lock);
393 usb_set_serial_port_data(serial->port[0], priv);
395 init_waitqueue_head(&serial->port[0]->write_wait);
397 /* Puh, that's dirty */
398 port = serial->port[0];
399 rport = serial->port[1];
400 /* No unlinking, it wasn't submitted yet. */
401 usb_free_urb(port->read_urb);
402 port->read_urb = rport->interrupt_in_urb;
403 rport->interrupt_in_urb = NULL;
404 port->read_urb->context = port;
407 } /* mct_u232_startup */
410 static void mct_u232_shutdown(struct usb_serial *serial)
412 struct mct_u232_private *priv;
417 for (i = 0; i < serial->num_ports; ++i) {
418 /* My special items, the standard routines free my urbs */
419 priv = usb_get_serial_port_data(serial->port[i]);
421 usb_set_serial_port_data(serial->port[i], NULL);
425 } /* mct_u232_shutdown */
427 static int mct_u232_open(struct tty_struct *tty,
428 struct usb_serial_port *port, struct file *filp)
430 struct usb_serial *serial = port->serial;
431 struct mct_u232_private *priv = usb_get_serial_port_data(port);
433 unsigned int control_state;
435 unsigned char last_lcr;
436 unsigned char last_msr;
438 dbg("%s port %d", __func__, port->number);
440 /* Compensate for a hardware bug: although the Sitecom U232-P25
441 * device reports a maximum output packet size of 32 bytes,
442 * it seems to be able to accept only 16 bytes (and that's what
443 * SniffUSB says too...)
445 if (le16_to_cpu(serial->dev->descriptor.idProduct)
446 == MCT_U232_SITECOM_PID)
447 port->bulk_out_size = 16;
449 /* Do a defined restart: the normal serial device seems to
450 * always turn on DTR and RTS here, so do the same. I'm not
451 * sure if this is really necessary. But it should not harm
454 spin_lock_irqsave(&priv->lock, flags);
455 if (tty && (tty->termios->c_cflag & CBAUD))
456 priv->control_state = TIOCM_DTR | TIOCM_RTS;
458 priv->control_state = 0;
460 priv->last_lcr = (MCT_U232_DATA_BITS_8 |
461 MCT_U232_PARITY_NONE |
462 MCT_U232_STOP_BITS_1);
463 control_state = priv->control_state;
464 last_lcr = priv->last_lcr;
465 spin_unlock_irqrestore(&priv->lock, flags);
466 mct_u232_set_modem_ctrl(serial, control_state);
467 mct_u232_set_line_ctrl(serial, last_lcr);
469 /* Read modem status and update control state */
470 mct_u232_get_modem_stat(serial, &last_msr);
471 spin_lock_irqsave(&priv->lock, flags);
472 priv->last_msr = last_msr;
473 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
474 spin_unlock_irqrestore(&priv->lock, flags);
476 port->read_urb->dev = port->serial->dev;
477 retval = usb_submit_urb(port->read_urb, GFP_KERNEL);
480 "usb_submit_urb(read bulk) failed pipe 0x%x err %d\n",
481 port->read_urb->pipe, retval);
485 port->interrupt_in_urb->dev = port->serial->dev;
486 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
488 usb_kill_urb(port->read_urb);
490 "usb_submit_urb(read int) failed pipe 0x%x err %d",
491 port->interrupt_in_urb->pipe, retval);
498 } /* mct_u232_open */
500 static void mct_u232_dtr_rts(struct usb_serial_port *port, int on)
502 unsigned int control_state;
503 struct mct_u232_private *priv = usb_get_serial_port_data(port);
505 mutex_lock(&port->serial->disc_mutex);
506 if (!port->serial->disconnected) {
507 /* drop DTR and RTS */
508 spin_lock_irq(&priv->lock);
510 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
512 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
513 control_state = priv->control_state;
514 spin_unlock_irq(&priv->lock);
515 mct_u232_set_modem_ctrl(port->serial, control_state);
517 mutex_unlock(&port->serial->disc_mutex);
520 static void mct_u232_close(struct usb_serial_port *port)
522 dbg("%s port %d", __func__, port->number);
524 if (port->serial->dev) {
525 /* shutdown our urbs */
526 usb_kill_urb(port->write_urb);
527 usb_kill_urb(port->read_urb);
528 usb_kill_urb(port->interrupt_in_urb);
530 } /* mct_u232_close */
533 static void mct_u232_read_int_callback(struct urb *urb)
535 struct usb_serial_port *port = urb->context;
536 struct mct_u232_private *priv = usb_get_serial_port_data(port);
537 struct usb_serial *serial = port->serial;
538 struct tty_struct *tty;
539 unsigned char *data = urb->transfer_buffer;
541 int status = urb->status;
551 /* this urb is terminated, clean up */
552 dbg("%s - urb shutting down with status: %d",
556 dbg("%s - nonzero urb status received: %d",
562 dbg("%s - bad serial pointer, exiting", __func__);
566 dbg("%s - port %d", __func__, port->number);
567 usb_serial_debug_data(debug, &port->dev, __func__,
568 urb->actual_length, data);
571 * Work-a-round: handle the 'usual' bulk-in pipe here
573 if (urb->transfer_buffer_length > 2) {
574 tty = tty_port_tty_get(&port->port);
575 if (urb->actual_length) {
576 tty_insert_flip_string(tty, data, urb->actual_length);
577 tty_flip_buffer_push(tty);
584 * The interrupt-in pipe signals exceptional conditions (modem line
585 * signal changes and errors). data[0] holds MSR, data[1] holds LSR.
587 spin_lock_irqsave(&priv->lock, flags);
588 priv->last_msr = data[MCT_U232_MSR_INDEX];
590 /* Record Control Line states */
591 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
594 /* Not yet handled. See belkin_sa.c for further information */
595 /* Now to report any errors */
596 priv->last_lsr = data[MCT_U232_LSR_INDEX];
598 * fill in the flip buffer here, but I do not know the relation
599 * to the current/next receive buffer or characters. I need
600 * to look in to this before committing any code.
602 if (priv->last_lsr & MCT_U232_LSR_ERR) {
603 tty = tty_port_tty_get(&port->port);
605 if (priv->last_lsr & MCT_U232_LSR_OE) {
608 if (priv->last_lsr & MCT_U232_LSR_PE) {
611 if (priv->last_lsr & MCT_U232_LSR_FE) {
613 /* Break Indicator */
614 if (priv->last_lsr & MCT_U232_LSR_BI) {
619 spin_unlock_irqrestore(&priv->lock, flags);
621 retval = usb_submit_urb(urb, GFP_ATOMIC);
624 "%s - usb_submit_urb failed with result %d\n",
626 } /* mct_u232_read_int_callback */
628 static void mct_u232_set_termios(struct tty_struct *tty,
629 struct usb_serial_port *port,
630 struct ktermios *old_termios)
632 struct usb_serial *serial = port->serial;
633 struct mct_u232_private *priv = usb_get_serial_port_data(port);
634 struct ktermios *termios = tty->termios;
635 unsigned int cflag = termios->c_cflag;
636 unsigned int old_cflag = old_termios->c_cflag;
638 unsigned int control_state;
639 unsigned char last_lcr;
641 /* get a local copy of the current port settings */
642 spin_lock_irqsave(&priv->lock, flags);
643 control_state = priv->control_state;
644 spin_unlock_irqrestore(&priv->lock, flags);
649 * Do not attempt to cache old rates and skip settings,
650 * disconnects screw such tricks up completely.
651 * Premature optimization is the root of all evil.
654 /* reassert DTR and RTS on transition from B0 */
655 if ((old_cflag & CBAUD) == B0) {
656 dbg("%s: baud was B0", __func__);
657 control_state |= TIOCM_DTR | TIOCM_RTS;
658 mct_u232_set_modem_ctrl(serial, control_state);
661 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
663 if ((cflag & CBAUD) == B0) {
664 dbg("%s: baud is B0", __func__);
665 /* Drop RTS and DTR */
666 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
667 mct_u232_set_modem_ctrl(serial, control_state);
671 * Update line control register (LCR)
676 last_lcr |= (cflag & PARODD) ?
677 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
679 last_lcr |= MCT_U232_PARITY_NONE;
681 /* set the number of data bits */
682 switch (cflag & CSIZE) {
684 last_lcr |= MCT_U232_DATA_BITS_5; break;
686 last_lcr |= MCT_U232_DATA_BITS_6; break;
688 last_lcr |= MCT_U232_DATA_BITS_7; break;
690 last_lcr |= MCT_U232_DATA_BITS_8; break;
693 "CSIZE was not CS5-CS8, using default of 8\n");
694 last_lcr |= MCT_U232_DATA_BITS_8;
698 termios->c_cflag &= ~CMSPAR;
700 /* set the number of stop bits */
701 last_lcr |= (cflag & CSTOPB) ?
702 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
704 mct_u232_set_line_ctrl(serial, last_lcr);
706 /* save off the modified port settings */
707 spin_lock_irqsave(&priv->lock, flags);
708 priv->control_state = control_state;
709 priv->last_lcr = last_lcr;
710 spin_unlock_irqrestore(&priv->lock, flags);
711 } /* mct_u232_set_termios */
713 static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
715 struct usb_serial_port *port = tty->driver_data;
716 struct usb_serial *serial = port->serial;
717 struct mct_u232_private *priv = usb_get_serial_port_data(port);
721 dbg("%sstate=%d", __func__, break_state);
723 spin_lock_irqsave(&priv->lock, flags);
724 lcr = priv->last_lcr;
727 lcr |= MCT_U232_SET_BREAK;
728 spin_unlock_irqrestore(&priv->lock, flags);
730 mct_u232_set_line_ctrl(serial, lcr);
731 } /* mct_u232_break_ctl */
734 static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
736 struct usb_serial_port *port = tty->driver_data;
737 struct mct_u232_private *priv = usb_get_serial_port_data(port);
738 unsigned int control_state;
743 spin_lock_irqsave(&priv->lock, flags);
744 control_state = priv->control_state;
745 spin_unlock_irqrestore(&priv->lock, flags);
747 return control_state;
750 static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
751 unsigned int set, unsigned int clear)
753 struct usb_serial_port *port = tty->driver_data;
754 struct usb_serial *serial = port->serial;
755 struct mct_u232_private *priv = usb_get_serial_port_data(port);
756 unsigned int control_state;
761 spin_lock_irqsave(&priv->lock, flags);
762 control_state = priv->control_state;
765 control_state |= TIOCM_RTS;
767 control_state |= TIOCM_DTR;
768 if (clear & TIOCM_RTS)
769 control_state &= ~TIOCM_RTS;
770 if (clear & TIOCM_DTR)
771 control_state &= ~TIOCM_DTR;
773 priv->control_state = control_state;
774 spin_unlock_irqrestore(&priv->lock, flags);
775 return mct_u232_set_modem_ctrl(serial, control_state);
778 static void mct_u232_throttle(struct tty_struct *tty)
780 struct usb_serial_port *port = tty->driver_data;
781 struct mct_u232_private *priv = usb_get_serial_port_data(port);
783 unsigned int control_state;
785 dbg("%s - port %d", __func__, port->number);
787 spin_lock_irqsave(&priv->lock, flags);
788 priv->rx_flags |= THROTTLED;
789 if (C_CRTSCTS(tty)) {
790 priv->control_state &= ~TIOCM_RTS;
791 control_state = priv->control_state;
792 spin_unlock_irqrestore(&priv->lock, flags);
793 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
795 spin_unlock_irqrestore(&priv->lock, flags);
800 static void mct_u232_unthrottle(struct tty_struct *tty)
802 struct usb_serial_port *port = tty->driver_data;
803 struct mct_u232_private *priv = usb_get_serial_port_data(port);
805 unsigned int control_state;
807 dbg("%s - port %d", __func__, port->number);
809 spin_lock_irqsave(&priv->lock, flags);
810 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) {
811 priv->rx_flags &= ~THROTTLED;
812 priv->control_state |= TIOCM_RTS;
813 control_state = priv->control_state;
814 spin_unlock_irqrestore(&priv->lock, flags);
815 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
817 spin_unlock_irqrestore(&priv->lock, flags);
821 static int __init mct_u232_init(void)
824 retval = usb_serial_register(&mct_u232_device);
826 goto failed_usb_serial_register;
827 retval = usb_register(&mct_u232_driver);
829 goto failed_usb_register;
830 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
834 usb_serial_deregister(&mct_u232_device);
835 failed_usb_serial_register:
840 static void __exit mct_u232_exit(void)
842 usb_deregister(&mct_u232_driver);
843 usb_serial_deregister(&mct_u232_device);
846 module_init(mct_u232_init);
847 module_exit(mct_u232_exit);
849 MODULE_AUTHOR(DRIVER_AUTHOR);
850 MODULE_DESCRIPTION(DRIVER_DESC);
851 MODULE_LICENSE("GPL");
853 module_param(debug, bool, S_IRUGO | S_IWUSR);
854 MODULE_PARM_DESC(debug, "Debug enabled or not");