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 problems.
41 * 04-May-2001 Stelian Pop
42 * - Set the maximum bulk output size for Sitecom U232-P25 model to 16 bytes
43 * instead of the device reported 32 (using 32 bytes causes many data
44 * loss, Windows driver uses 16 too).
46 * 02-May-2001 Stelian Pop
47 * - Fixed the baud calculation for Sitecom U232-P25 model
50 * - Identify version on module load.
52 * 06-Jan-2001 Cornel Ciocirlan
53 * - Added support for Sitecom U232-P25 model (Product Id 0x0230)
54 * - Added support for D-Link DU-H3SP USB BAY (Product Id 0x0200)
56 * 29-Nov-2000 Greg Kroah-Hartman
57 * - Added device id table to fit with 2.4.0-test11 structure.
58 * - took out DEAL_WITH_TWO_INT_IN_ENDPOINTS #define as it's not needed
59 * (lots of things will change if/when the usb-serial core changes to
60 * handle these issues.
62 * 27-Nov-2000 Wolfgang Grandegger
63 * A version for kernel 2.4.0-test10 released to the Linux community
64 * (via linux-usb-devel).
67 #include <linux/kernel.h>
68 #include <linux/errno.h>
69 #include <linux/init.h>
70 #include <linux/slab.h>
71 #include <linux/tty.h>
72 #include <linux/tty_driver.h>
73 #include <linux/tty_flip.h>
74 #include <linux/module.h>
75 #include <linux/spinlock.h>
76 #include <asm/uaccess.h>
77 #include <linux/usb.h>
78 #include <linux/usb/serial.h>
84 #define DRIVER_VERSION "z2.1" /* Linux in-kernel version */
85 #define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>"
86 #define DRIVER_DESC "Magic Control Technology USB-RS232 converter driver"
93 static int mct_u232_startup (struct usb_serial *serial);
94 static void mct_u232_shutdown (struct usb_serial *serial);
95 static int mct_u232_open (struct tty_struct *tty,
96 struct usb_serial_port *port,
98 static void mct_u232_close (struct tty_struct *tty,
99 struct usb_serial_port *port,
101 static void mct_u232_read_int_callback (struct urb *urb);
102 static void mct_u232_set_termios (struct tty_struct *tty,
103 struct usb_serial_port *port,
104 struct ktermios * old);
105 static void mct_u232_break_ctl (struct tty_struct *tty,
107 static int mct_u232_tiocmget (struct tty_struct *tty,
109 static int mct_u232_tiocmset (struct tty_struct *tty,
110 struct file *file, unsigned int set,
112 static void mct_u232_throttle (struct tty_struct *tty);
113 static void mct_u232_unthrottle (struct tty_struct *tty);
117 * All of the device info needed for the MCT USB-RS232 converter.
119 static struct usb_device_id id_table_combined [] = {
120 { USB_DEVICE(MCT_U232_VID, MCT_U232_PID) },
121 { USB_DEVICE(MCT_U232_VID, MCT_U232_SITECOM_PID) },
122 { USB_DEVICE(MCT_U232_VID, MCT_U232_DU_H3SP_PID) },
123 { USB_DEVICE(MCT_U232_BELKIN_F5U109_VID, MCT_U232_BELKIN_F5U109_PID) },
124 { } /* Terminating entry */
127 MODULE_DEVICE_TABLE (usb, id_table_combined);
129 static struct usb_driver mct_u232_driver = {
131 .probe = usb_serial_probe,
132 .disconnect = usb_serial_disconnect,
133 .id_table = id_table_combined,
137 static struct usb_serial_driver mct_u232_device = {
139 .owner = THIS_MODULE,
142 .description = "MCT U232",
143 .usb_driver = &mct_u232_driver,
144 .id_table = id_table_combined,
146 .open = mct_u232_open,
147 .close = mct_u232_close,
148 .throttle = mct_u232_throttle,
149 .unthrottle = mct_u232_unthrottle,
150 .read_int_callback = mct_u232_read_int_callback,
151 .set_termios = mct_u232_set_termios,
152 .break_ctl = mct_u232_break_ctl,
153 .tiocmget = mct_u232_tiocmget,
154 .tiocmset = mct_u232_tiocmset,
155 .attach = mct_u232_startup,
156 .shutdown = mct_u232_shutdown,
160 struct mct_u232_private {
162 unsigned int control_state; /* Modem Line Setting (TIOCM) */
163 unsigned char last_lcr; /* Line Control Register */
164 unsigned char last_lsr; /* Line Status Register */
165 unsigned char last_msr; /* Modem Status Register */
166 unsigned int rx_flags; /* Throttling flags */
169 #define THROTTLED 0x01
172 * Handle vendor specific USB requests
175 #define WDR_TIMEOUT 5000 /* default urb timeout */
178 * Later day 2.6.0-test kernels have new baud rates like B230400 which
179 * we do not know how to support. We ignore them for the moment.
181 static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result)
185 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID
186 || le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_BELKIN_F5U109_PID) {
188 case 300: return 0x01;
189 case 600: return 0x02; /* this one not tested */
190 case 1200: return 0x03;
191 case 2400: return 0x04;
192 case 4800: return 0x06;
193 case 9600: return 0x08;
194 case 19200: return 0x09;
195 case 38400: return 0x0a;
196 case 57600: return 0x0b;
197 case 115200: return 0x0c;
203 /* FIXME: Can we use any divider - should we do
204 divider = 115200/value;
205 real baud = 115200/divider */
225 static int mct_u232_set_baud_rate(struct tty_struct *tty,
226 struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
230 unsigned char zero_byte = 0;
231 unsigned char cts_enable_byte = 0;
234 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value, &speed));
236 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
237 MCT_U232_SET_BAUD_RATE_REQUEST,
238 MCT_U232_SET_REQUEST_TYPE,
239 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE,
241 if (rc < 0) /*FIXME: What value speed results */
242 err("Set BAUD RATE %d failed (error = %d)", value, rc);
244 tty_encode_baud_rate(tty, speed, speed);
245 dbg("set_baud_rate: value: 0x%x, divisor: 0x%x", value, divisor);
247 /* Mimic the MCT-supplied Windows driver (version 1.21P.0104), which
248 always sends two extra USB 'device request' messages after the
249 'baud rate change' message. The actual functionality of the
250 request codes in these messages is not fully understood but these
251 particular codes are never seen in any operation besides a baud
252 rate change. Both of these messages send a single byte of data.
253 In the first message, the value of this byte is always zero.
255 The second message has been determined experimentally to control
256 whether data will be transmitted to a device which is not asserting
257 the 'CTS' signal. If the second message's data byte is zero, data
258 will be transmitted even if 'CTS' is not asserted (i.e. no hardware
259 flow control). if the second message's data byte is nonzero (a value
260 of 1 is used by this driver), data will not be transmitted to a device
261 which is not asserting 'CTS'.
264 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
265 MCT_U232_SET_UNKNOWN1_REQUEST,
266 MCT_U232_SET_REQUEST_TYPE,
267 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE,
270 err("Sending USB device request code %d failed (error = %d)",
271 MCT_U232_SET_UNKNOWN1_REQUEST, rc);
273 if (port && C_CRTSCTS(tty)) {
277 dbg("set_baud_rate: send second control message, data = %02X", cts_enable_byte);
278 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
279 MCT_U232_SET_CTS_REQUEST,
280 MCT_U232_SET_REQUEST_TYPE,
281 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE,
284 err("Sending USB device request code %d failed (error = %d)",
285 MCT_U232_SET_CTS_REQUEST, rc);
288 } /* mct_u232_set_baud_rate */
290 static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
293 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
294 MCT_U232_SET_LINE_CTRL_REQUEST,
295 MCT_U232_SET_REQUEST_TYPE,
296 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE,
299 err("Set LINE CTRL 0x%x failed (error = %d)", lcr, rc);
300 dbg("set_line_ctrl: 0x%x", lcr);
302 } /* mct_u232_set_line_ctrl */
304 static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
305 unsigned int control_state)
308 unsigned char mcr = MCT_U232_MCR_NONE;
310 if (control_state & TIOCM_DTR)
311 mcr |= MCT_U232_MCR_DTR;
312 if (control_state & TIOCM_RTS)
313 mcr |= MCT_U232_MCR_RTS;
315 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
316 MCT_U232_SET_MODEM_CTRL_REQUEST,
317 MCT_U232_SET_REQUEST_TYPE,
318 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE,
321 err("Set MODEM CTRL 0x%x failed (error = %d)", mcr, rc);
322 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
325 } /* mct_u232_set_modem_ctrl */
327 static int mct_u232_get_modem_stat(struct usb_serial *serial, unsigned char *msr)
330 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
331 MCT_U232_GET_MODEM_STAT_REQUEST,
332 MCT_U232_GET_REQUEST_TYPE,
333 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE,
336 err("Get MODEM STATus failed (error = %d)", rc);
339 dbg("get_modem_stat: 0x%x", *msr);
341 } /* mct_u232_get_modem_stat */
343 static void mct_u232_msr_to_state(unsigned int *control_state, unsigned char msr)
345 /* Translate Control Line states */
346 if (msr & MCT_U232_MSR_DSR)
347 *control_state |= TIOCM_DSR;
349 *control_state &= ~TIOCM_DSR;
350 if (msr & MCT_U232_MSR_CTS)
351 *control_state |= TIOCM_CTS;
353 *control_state &= ~TIOCM_CTS;
354 if (msr & MCT_U232_MSR_RI)
355 *control_state |= TIOCM_RI;
357 *control_state &= ~TIOCM_RI;
358 if (msr & MCT_U232_MSR_CD)
359 *control_state |= TIOCM_CD;
361 *control_state &= ~TIOCM_CD;
362 dbg("msr_to_state: msr=0x%x ==> state=0x%x", msr, *control_state);
363 } /* mct_u232_msr_to_state */
366 * Driver's tty interface functions
369 static int mct_u232_startup (struct usb_serial *serial)
371 struct mct_u232_private *priv;
372 struct usb_serial_port *port, *rport;
374 priv = kzalloc(sizeof(struct mct_u232_private), GFP_KERNEL);
377 spin_lock_init(&priv->lock);
378 usb_set_serial_port_data(serial->port[0], priv);
380 init_waitqueue_head(&serial->port[0]->write_wait);
382 /* Puh, that's dirty */
383 port = serial->port[0];
384 rport = serial->port[1];
385 /* No unlinking, it wasn't submitted yet. */
386 usb_free_urb(port->read_urb);
387 port->read_urb = rport->interrupt_in_urb;
388 rport->interrupt_in_urb = NULL;
389 port->read_urb->context = port;
392 } /* mct_u232_startup */
395 static void mct_u232_shutdown (struct usb_serial *serial)
397 struct mct_u232_private *priv;
402 for (i=0; i < serial->num_ports; ++i) {
403 /* My special items, the standard routines free my urbs */
404 priv = usb_get_serial_port_data(serial->port[i]);
406 usb_set_serial_port_data(serial->port[i], NULL);
410 } /* mct_u232_shutdown */
412 static int mct_u232_open (struct tty_struct *tty,
413 struct usb_serial_port *port, struct file *filp)
415 struct usb_serial *serial = port->serial;
416 struct mct_u232_private *priv = usb_get_serial_port_data(port);
418 unsigned int control_state;
420 unsigned char last_lcr;
421 unsigned char last_msr;
423 dbg("%s port %d", __func__, port->number);
425 /* Compensate for a hardware bug: although the Sitecom U232-P25
426 * device reports a maximum output packet size of 32 bytes,
427 * it seems to be able to accept only 16 bytes (and that's what
428 * SniffUSB says too...)
430 if (le16_to_cpu(serial->dev->descriptor.idProduct) == MCT_U232_SITECOM_PID)
431 port->bulk_out_size = 16;
433 /* Do a defined restart: the normal serial device seems to
434 * always turn on DTR and RTS here, so do the same. I'm not
435 * sure if this is really necessary. But it should not harm
438 spin_lock_irqsave(&priv->lock, flags);
439 if (tty && (tty->termios->c_cflag & CBAUD))
440 priv->control_state = TIOCM_DTR | TIOCM_RTS;
442 priv->control_state = 0;
444 priv->last_lcr = (MCT_U232_DATA_BITS_8 |
445 MCT_U232_PARITY_NONE |
446 MCT_U232_STOP_BITS_1);
447 control_state = priv->control_state;
448 last_lcr = priv->last_lcr;
449 spin_unlock_irqrestore(&priv->lock, flags);
450 mct_u232_set_modem_ctrl(serial, control_state);
451 mct_u232_set_line_ctrl(serial, last_lcr);
453 /* Read modem status and update control state */
454 mct_u232_get_modem_stat(serial, &last_msr);
455 spin_lock_irqsave(&priv->lock, flags);
456 priv->last_msr = last_msr;
457 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
458 spin_unlock_irqrestore(&priv->lock, flags);
460 port->read_urb->dev = port->serial->dev;
461 retval = usb_submit_urb(port->read_urb, GFP_KERNEL);
463 err("usb_submit_urb(read bulk) failed pipe 0x%x err %d",
464 port->read_urb->pipe, retval);
468 port->interrupt_in_urb->dev = port->serial->dev;
469 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
471 usb_kill_urb(port->read_urb);
472 err(" usb_submit_urb(read int) failed pipe 0x%x err %d",
473 port->interrupt_in_urb->pipe, retval);
480 } /* mct_u232_open */
483 static void mct_u232_close(struct tty_struct *tty,
484 struct usb_serial_port *port, struct file *filp)
486 unsigned int c_cflag;
487 unsigned int control_state;
488 struct mct_u232_private *priv = usb_get_serial_port_data(port);
489 dbg("%s port %d", __func__, port->number);
492 c_cflag = tty->termios->c_cflag;
493 mutex_lock(&port->serial->disc_mutex);
494 if (c_cflag & HUPCL && !port->serial->disconnected) {
495 /* drop DTR and RTS */
496 spin_lock_irq(&priv->lock);
497 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
498 control_state = priv->control_state;
499 spin_unlock_irq(&priv->lock);
500 mct_u232_set_modem_ctrl(port->serial, control_state);
502 mutex_unlock(&port->serial->disc_mutex);
506 if (port->serial->dev) {
507 /* shutdown our urbs */
508 usb_kill_urb(port->write_urb);
509 usb_kill_urb(port->read_urb);
510 usb_kill_urb(port->interrupt_in_urb);
512 } /* mct_u232_close */
515 static void mct_u232_read_int_callback (struct urb *urb)
517 struct usb_serial_port *port = urb->context;
518 struct mct_u232_private *priv = usb_get_serial_port_data(port);
519 struct usb_serial *serial = port->serial;
520 struct tty_struct *tty;
521 unsigned char *data = urb->transfer_buffer;
523 int status = urb->status;
533 /* this urb is terminated, clean up */
534 dbg("%s - urb shutting down with status: %d",
538 dbg("%s - nonzero urb status received: %d",
544 dbg("%s - bad serial pointer, exiting", __func__);
548 dbg("%s - port %d", __func__, port->number);
549 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
552 * Work-a-round: handle the 'usual' bulk-in pipe here
554 if (urb->transfer_buffer_length > 2) {
556 tty = port->port.tty;
557 if (urb->actual_length) {
558 for (i = 0; i < urb->actual_length ; ++i) {
559 tty_insert_flip_char(tty, data[i], 0);
561 tty_flip_buffer_push(tty);
567 * The interrupt-in pipe signals exceptional conditions (modem line
568 * signal changes and errors). data[0] holds MSR, data[1] holds LSR.
570 spin_lock_irqsave(&priv->lock, flags);
571 priv->last_msr = data[MCT_U232_MSR_INDEX];
573 /* Record Control Line states */
574 mct_u232_msr_to_state(&priv->control_state, priv->last_msr);
577 /* Not yet handled. See belin_sa.c for further information */
578 /* Now to report any errors */
579 priv->last_lsr = data[MCT_U232_LSR_INDEX];
581 * fill in the flip buffer here, but I do not know the relation
582 * to the current/next receive buffer or characters. I need
583 * to look in to this before committing any code.
585 if (priv->last_lsr & MCT_U232_LSR_ERR) {
586 tty = port->port.tty;
588 if (priv->last_lsr & MCT_U232_LSR_OE) {
591 if (priv->last_lsr & MCT_U232_LSR_PE) {
594 if (priv->last_lsr & MCT_U232_LSR_FE) {
596 /* Break Indicator */
597 if (priv->last_lsr & MCT_U232_LSR_BI) {
601 spin_unlock_irqrestore(&priv->lock, flags);
603 retval = usb_submit_urb (urb, GFP_ATOMIC);
605 err ("%s - usb_submit_urb failed with result %d",
607 } /* mct_u232_read_int_callback */
609 static void mct_u232_set_termios (struct tty_struct *tty,
610 struct usb_serial_port *port,
611 struct ktermios *old_termios)
613 struct usb_serial *serial = port->serial;
614 struct mct_u232_private *priv = usb_get_serial_port_data(port);
615 struct ktermios *termios = tty->termios;
616 unsigned int cflag = termios->c_cflag;
617 unsigned int old_cflag = old_termios->c_cflag;
619 unsigned int control_state;
620 unsigned char last_lcr;
622 /* get a local copy of the current port settings */
623 spin_lock_irqsave(&priv->lock, flags);
624 control_state = priv->control_state;
625 spin_unlock_irqrestore(&priv->lock, flags);
630 * Do not attempt to cache old rates and skip settings,
631 * disconnects screw such tricks up completely.
632 * Premature optimization is the root of all evil.
635 /* reassert DTR and RTS on transition from B0 */
636 if ((old_cflag & CBAUD) == B0) {
637 dbg("%s: baud was B0", __func__);
638 control_state |= TIOCM_DTR | TIOCM_RTS;
639 mct_u232_set_modem_ctrl(serial, control_state);
642 mct_u232_set_baud_rate(tty, serial, port, tty_get_baud_rate(tty));
644 if ((cflag & CBAUD) == B0 ) {
645 dbg("%s: baud is B0", __func__);
646 /* Drop RTS and DTR */
647 control_state &= ~(TIOCM_DTR | TIOCM_RTS);
648 mct_u232_set_modem_ctrl(serial, control_state);
652 * Update line control register (LCR)
657 last_lcr |= (cflag & PARODD) ?
658 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
660 last_lcr |= MCT_U232_PARITY_NONE;
662 /* set the number of data bits */
663 switch (cflag & CSIZE) {
665 last_lcr |= MCT_U232_DATA_BITS_5; break;
667 last_lcr |= MCT_U232_DATA_BITS_6; break;
669 last_lcr |= MCT_U232_DATA_BITS_7; break;
671 last_lcr |= MCT_U232_DATA_BITS_8; break;
673 err("CSIZE was not CS5-CS8, using default of 8");
674 last_lcr |= MCT_U232_DATA_BITS_8;
678 termios->c_cflag &= ~CMSPAR;
680 /* set the number of stop bits */
681 last_lcr |= (cflag & CSTOPB) ?
682 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
684 mct_u232_set_line_ctrl(serial, last_lcr);
686 /* save off the modified port settings */
687 spin_lock_irqsave(&priv->lock, flags);
688 priv->control_state = control_state;
689 priv->last_lcr = last_lcr;
690 spin_unlock_irqrestore(&priv->lock, flags);
691 } /* mct_u232_set_termios */
693 static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
695 struct usb_serial_port *port = tty->driver_data;
696 struct usb_serial *serial = port->serial;
697 struct mct_u232_private *priv = usb_get_serial_port_data(port);
701 dbg("%sstate=%d", __func__, break_state);
703 spin_lock_irqsave(&priv->lock, flags);
704 lcr = priv->last_lcr;
705 spin_unlock_irqrestore(&priv->lock, flags);
708 lcr |= MCT_U232_SET_BREAK;
710 mct_u232_set_line_ctrl(serial, lcr);
711 } /* mct_u232_break_ctl */
714 static int mct_u232_tiocmget(struct tty_struct *tty, struct file *file)
716 struct usb_serial_port *port = tty->driver_data;
717 struct mct_u232_private *priv = usb_get_serial_port_data(port);
718 unsigned int control_state;
723 spin_lock_irqsave(&priv->lock, flags);
724 control_state = priv->control_state;
725 spin_unlock_irqrestore(&priv->lock, flags);
727 return control_state;
730 static int mct_u232_tiocmset(struct tty_struct *tty, struct file *file,
731 unsigned int set, unsigned int clear)
733 struct usb_serial_port *port = tty->driver_data;
734 struct usb_serial *serial = port->serial;
735 struct mct_u232_private *priv = usb_get_serial_port_data(port);
736 unsigned int control_state;
741 spin_lock_irqsave(&priv->lock, flags);
742 control_state = priv->control_state;
745 control_state |= TIOCM_RTS;
747 control_state |= TIOCM_DTR;
748 if (clear & TIOCM_RTS)
749 control_state &= ~TIOCM_RTS;
750 if (clear & TIOCM_DTR)
751 control_state &= ~TIOCM_DTR;
753 priv->control_state = control_state;
754 spin_unlock_irqrestore(&priv->lock, flags);
755 return mct_u232_set_modem_ctrl(serial, control_state);
758 static void mct_u232_throttle(struct tty_struct *tty)
760 struct usb_serial_port *port = tty->driver_data;
761 struct mct_u232_private *priv = usb_get_serial_port_data(port);
763 unsigned int control_state;
765 dbg("%s - port %d", __func__, port->number);
767 spin_lock_irqsave(&priv->lock, flags);
768 priv->rx_flags |= THROTTLED;
769 if (C_CRTSCTS(tty)) {
770 priv->control_state &= ~TIOCM_RTS;
771 control_state = priv->control_state;
772 spin_unlock_irqrestore(&priv->lock, flags);
773 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
775 spin_unlock_irqrestore(&priv->lock, flags);
780 static void mct_u232_unthrottle(struct tty_struct *tty)
782 struct usb_serial_port *port = tty->driver_data;
783 struct mct_u232_private *priv = usb_get_serial_port_data(port);
785 unsigned int control_state;
787 dbg("%s - port %d", __func__, port->number);
789 spin_lock_irqsave(&priv->lock, flags);
790 if ((priv->rx_flags & THROTTLED) && C_CRTSCTS(tty)) {
791 priv->rx_flags &= ~THROTTLED;
792 priv->control_state |= TIOCM_RTS;
793 control_state = priv->control_state;
794 spin_unlock_irqrestore(&priv->lock, flags);
795 (void) mct_u232_set_modem_ctrl(port->serial, control_state);
797 spin_unlock_irqrestore(&priv->lock, flags);
801 static int __init mct_u232_init (void)
804 retval = usb_serial_register(&mct_u232_device);
806 goto failed_usb_serial_register;
807 retval = usb_register(&mct_u232_driver);
809 goto failed_usb_register;
810 info(DRIVER_DESC " " DRIVER_VERSION);
813 usb_serial_deregister(&mct_u232_device);
814 failed_usb_serial_register:
819 static void __exit mct_u232_exit (void)
821 usb_deregister (&mct_u232_driver);
822 usb_serial_deregister (&mct_u232_device);
826 module_init (mct_u232_init);
827 module_exit(mct_u232_exit);
829 MODULE_AUTHOR( DRIVER_AUTHOR );
830 MODULE_DESCRIPTION( DRIVER_DESC );
831 MODULE_LICENSE("GPL");
833 module_param(debug, bool, S_IRUGO | S_IWUSR);
834 MODULE_PARM_DESC(debug, "Debug enabled or not");