2 * Digi AccelePort USB-4 and USB-2 Serial Converters
4 * Copyright 2000 by Digi International
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 * Shamelessly based on Brian Warner's keyspan_pda.c and Greg Kroah-Hartman's
14 * Peter Berger (pberger@brimson.com)
15 * Al Borchers (borchers@steinerpoint.com)
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/slab.h>
21 #include <linux/tty.h>
22 #include <linux/tty_driver.h>
23 #include <linux/tty_flip.h>
24 #include <linux/module.h>
25 #include <linux/spinlock.h>
26 #include <linux/uaccess.h>
27 #include <linux/usb.h>
28 #include <linux/wait.h>
29 #include <linux/sched/signal.h>
30 #include <linux/usb/serial.h>
34 #define DRIVER_AUTHOR "Peter Berger <pberger@brimson.com>, Al Borchers <borchers@steinerpoint.com>"
35 #define DRIVER_DESC "Digi AccelePort USB-2/USB-4 Serial Converter driver"
37 /* port output buffer length -- must be <= transfer buffer length - 2 */
38 /* so we can be sure to send the full buffer in one urb */
39 #define DIGI_OUT_BUF_SIZE 8
41 /* port input buffer length -- must be >= transfer buffer length - 3 */
42 /* so we can be sure to hold at least one full buffer from one urb */
43 #define DIGI_IN_BUF_SIZE 64
45 /* retry timeout while sleeping */
46 #define DIGI_RETRY_TIMEOUT (HZ/10)
48 /* timeout while waiting for tty output to drain in close */
49 /* this delay is used twice in close, so the total delay could */
50 /* be twice this value */
51 #define DIGI_CLOSE_TIMEOUT (5*HZ)
54 /* AccelePort USB Defines */
57 #define DIGI_VENDOR_ID 0x05c5
58 #define DIGI_2_ID 0x0002 /* USB-2 */
59 #define DIGI_4_ID 0x0004 /* USB-4 */
62 * "INB": can be used on the in-band endpoint
63 * "OOB": can be used on the out-of-band endpoint
65 #define DIGI_CMD_SET_BAUD_RATE 0 /* INB, OOB */
66 #define DIGI_CMD_SET_WORD_SIZE 1 /* INB, OOB */
67 #define DIGI_CMD_SET_PARITY 2 /* INB, OOB */
68 #define DIGI_CMD_SET_STOP_BITS 3 /* INB, OOB */
69 #define DIGI_CMD_SET_INPUT_FLOW_CONTROL 4 /* INB, OOB */
70 #define DIGI_CMD_SET_OUTPUT_FLOW_CONTROL 5 /* INB, OOB */
71 #define DIGI_CMD_SET_DTR_SIGNAL 6 /* INB, OOB */
72 #define DIGI_CMD_SET_RTS_SIGNAL 7 /* INB, OOB */
73 #define DIGI_CMD_READ_INPUT_SIGNALS 8 /* OOB */
74 #define DIGI_CMD_IFLUSH_FIFO 9 /* OOB */
75 #define DIGI_CMD_RECEIVE_ENABLE 10 /* INB, OOB */
76 #define DIGI_CMD_BREAK_CONTROL 11 /* INB, OOB */
77 #define DIGI_CMD_LOCAL_LOOPBACK 12 /* INB, OOB */
78 #define DIGI_CMD_TRANSMIT_IDLE 13 /* INB, OOB */
79 #define DIGI_CMD_READ_UART_REGISTER 14 /* OOB */
80 #define DIGI_CMD_WRITE_UART_REGISTER 15 /* INB, OOB */
81 #define DIGI_CMD_AND_UART_REGISTER 16 /* INB, OOB */
82 #define DIGI_CMD_OR_UART_REGISTER 17 /* INB, OOB */
83 #define DIGI_CMD_SEND_DATA 18 /* INB */
84 #define DIGI_CMD_RECEIVE_DATA 19 /* INB */
85 #define DIGI_CMD_RECEIVE_DISABLE 20 /* INB */
86 #define DIGI_CMD_GET_PORT_TYPE 21 /* OOB */
89 #define DIGI_BAUD_50 0
90 #define DIGI_BAUD_75 1
91 #define DIGI_BAUD_110 2
92 #define DIGI_BAUD_150 3
93 #define DIGI_BAUD_200 4
94 #define DIGI_BAUD_300 5
95 #define DIGI_BAUD_600 6
96 #define DIGI_BAUD_1200 7
97 #define DIGI_BAUD_1800 8
98 #define DIGI_BAUD_2400 9
99 #define DIGI_BAUD_4800 10
100 #define DIGI_BAUD_7200 11
101 #define DIGI_BAUD_9600 12
102 #define DIGI_BAUD_14400 13
103 #define DIGI_BAUD_19200 14
104 #define DIGI_BAUD_28800 15
105 #define DIGI_BAUD_38400 16
106 #define DIGI_BAUD_57600 17
107 #define DIGI_BAUD_76800 18
108 #define DIGI_BAUD_115200 19
109 #define DIGI_BAUD_153600 20
110 #define DIGI_BAUD_230400 21
111 #define DIGI_BAUD_460800 22
114 #define DIGI_WORD_SIZE_5 0
115 #define DIGI_WORD_SIZE_6 1
116 #define DIGI_WORD_SIZE_7 2
117 #define DIGI_WORD_SIZE_8 3
119 #define DIGI_PARITY_NONE 0
120 #define DIGI_PARITY_ODD 1
121 #define DIGI_PARITY_EVEN 2
122 #define DIGI_PARITY_MARK 3
123 #define DIGI_PARITY_SPACE 4
125 #define DIGI_STOP_BITS_1 0
126 #define DIGI_STOP_BITS_2 1
128 #define DIGI_INPUT_FLOW_CONTROL_XON_XOFF 1
129 #define DIGI_INPUT_FLOW_CONTROL_RTS 2
130 #define DIGI_INPUT_FLOW_CONTROL_DTR 4
132 #define DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF 1
133 #define DIGI_OUTPUT_FLOW_CONTROL_CTS 2
134 #define DIGI_OUTPUT_FLOW_CONTROL_DSR 4
136 #define DIGI_DTR_INACTIVE 0
137 #define DIGI_DTR_ACTIVE 1
138 #define DIGI_DTR_INPUT_FLOW_CONTROL 2
140 #define DIGI_RTS_INACTIVE 0
141 #define DIGI_RTS_ACTIVE 1
142 #define DIGI_RTS_INPUT_FLOW_CONTROL 2
143 #define DIGI_RTS_TOGGLE 3
145 #define DIGI_FLUSH_TX 1
146 #define DIGI_FLUSH_RX 2
147 #define DIGI_RESUME_TX 4 /* clears xoff condition */
149 #define DIGI_TRANSMIT_NOT_IDLE 0
150 #define DIGI_TRANSMIT_IDLE 1
152 #define DIGI_DISABLE 0
153 #define DIGI_ENABLE 1
155 #define DIGI_DEASSERT 0
156 #define DIGI_ASSERT 1
158 /* in band status codes */
159 #define DIGI_OVERRUN_ERROR 4
160 #define DIGI_PARITY_ERROR 8
161 #define DIGI_FRAMING_ERROR 16
162 #define DIGI_BREAK_ERROR 32
164 /* out of band status */
165 #define DIGI_NO_ERROR 0
166 #define DIGI_BAD_FIRST_PARAMETER 1
167 #define DIGI_BAD_SECOND_PARAMETER 2
168 #define DIGI_INVALID_LINE 3
169 #define DIGI_INVALID_OPCODE 4
172 #define DIGI_READ_INPUT_SIGNALS_SLOT 1
173 #define DIGI_READ_INPUT_SIGNALS_ERR 2
174 #define DIGI_READ_INPUT_SIGNALS_BUSY 4
175 #define DIGI_READ_INPUT_SIGNALS_PE 8
176 #define DIGI_READ_INPUT_SIGNALS_CTS 16
177 #define DIGI_READ_INPUT_SIGNALS_DSR 32
178 #define DIGI_READ_INPUT_SIGNALS_RI 64
179 #define DIGI_READ_INPUT_SIGNALS_DCD 128
185 spinlock_t ds_serial_lock;
186 struct usb_serial_port *ds_oob_port; /* out-of-band port */
187 int ds_oob_port_num; /* index of out-of-band port */
188 int ds_device_started;
192 spinlock_t dp_port_lock;
195 unsigned char dp_out_buf[DIGI_OUT_BUF_SIZE];
196 int dp_write_urb_in_use;
197 unsigned int dp_modem_signals;
198 int dp_transmit_idle;
199 wait_queue_head_t dp_transmit_idle_wait;
201 int dp_throttle_restart;
202 wait_queue_head_t dp_flush_wait;
203 wait_queue_head_t dp_close_wait; /* wait queue for close */
204 struct usb_serial_port *dp_port;
208 /* Local Function Declarations */
210 static int digi_write_oob_command(struct usb_serial_port *port,
211 unsigned char *buf, int count, int interruptible);
212 static int digi_write_inb_command(struct usb_serial_port *port,
213 unsigned char *buf, int count, unsigned long timeout);
214 static int digi_set_modem_signals(struct usb_serial_port *port,
215 unsigned int modem_signals, int interruptible);
216 static int digi_transmit_idle(struct usb_serial_port *port,
217 unsigned long timeout);
218 static void digi_rx_throttle(struct tty_struct *tty);
219 static void digi_rx_unthrottle(struct tty_struct *tty);
220 static void digi_set_termios(struct tty_struct *tty,
221 struct usb_serial_port *port, struct ktermios *old_termios);
222 static void digi_break_ctl(struct tty_struct *tty, int break_state);
223 static int digi_tiocmget(struct tty_struct *tty);
224 static int digi_tiocmset(struct tty_struct *tty, unsigned int set,
226 static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
227 const unsigned char *buf, int count);
228 static void digi_write_bulk_callback(struct urb *urb);
229 static int digi_write_room(struct tty_struct *tty);
230 static int digi_chars_in_buffer(struct tty_struct *tty);
231 static int digi_open(struct tty_struct *tty, struct usb_serial_port *port);
232 static void digi_close(struct usb_serial_port *port);
233 static void digi_dtr_rts(struct usb_serial_port *port, int on);
234 static int digi_startup_device(struct usb_serial *serial);
235 static int digi_startup(struct usb_serial *serial);
236 static void digi_disconnect(struct usb_serial *serial);
237 static void digi_release(struct usb_serial *serial);
238 static int digi_port_probe(struct usb_serial_port *port);
239 static int digi_port_remove(struct usb_serial_port *port);
240 static void digi_read_bulk_callback(struct urb *urb);
241 static int digi_read_inb_callback(struct urb *urb);
242 static int digi_read_oob_callback(struct urb *urb);
245 static const struct usb_device_id id_table_combined[] = {
246 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) },
247 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) },
248 { } /* Terminating entry */
251 static const struct usb_device_id id_table_2[] = {
252 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) },
253 { } /* Terminating entry */
256 static const struct usb_device_id id_table_4[] = {
257 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) },
258 { } /* Terminating entry */
261 MODULE_DEVICE_TABLE(usb, id_table_combined);
263 /* device info needed for the Digi serial converter */
265 static struct usb_serial_driver digi_acceleport_2_device = {
267 .owner = THIS_MODULE,
270 .description = "Digi 2 port USB adapter",
271 .id_table = id_table_2,
277 .dtr_rts = digi_dtr_rts,
279 .write_room = digi_write_room,
280 .write_bulk_callback = digi_write_bulk_callback,
281 .read_bulk_callback = digi_read_bulk_callback,
282 .chars_in_buffer = digi_chars_in_buffer,
283 .throttle = digi_rx_throttle,
284 .unthrottle = digi_rx_unthrottle,
285 .set_termios = digi_set_termios,
286 .break_ctl = digi_break_ctl,
287 .tiocmget = digi_tiocmget,
288 .tiocmset = digi_tiocmset,
289 .attach = digi_startup,
290 .disconnect = digi_disconnect,
291 .release = digi_release,
292 .port_probe = digi_port_probe,
293 .port_remove = digi_port_remove,
296 static struct usb_serial_driver digi_acceleport_4_device = {
298 .owner = THIS_MODULE,
301 .description = "Digi 4 port USB adapter",
302 .id_table = id_table_4,
309 .write_room = digi_write_room,
310 .write_bulk_callback = digi_write_bulk_callback,
311 .read_bulk_callback = digi_read_bulk_callback,
312 .chars_in_buffer = digi_chars_in_buffer,
313 .throttle = digi_rx_throttle,
314 .unthrottle = digi_rx_unthrottle,
315 .set_termios = digi_set_termios,
316 .break_ctl = digi_break_ctl,
317 .tiocmget = digi_tiocmget,
318 .tiocmset = digi_tiocmset,
319 .attach = digi_startup,
320 .disconnect = digi_disconnect,
321 .release = digi_release,
322 .port_probe = digi_port_probe,
323 .port_remove = digi_port_remove,
326 static struct usb_serial_driver * const serial_drivers[] = {
327 &digi_acceleport_2_device, &digi_acceleport_4_device, NULL
333 * Cond Wait Interruptible Timeout Irqrestore
335 * Do spin_unlock_irqrestore and interruptible_sleep_on_timeout
336 * so that wake ups are not lost if they occur between the unlock
337 * and the sleep. In other words, spin_unlock_irqrestore and
338 * interruptible_sleep_on_timeout are "atomic" with respect to
339 * wake ups. This is used to implement condition variables.
341 * interruptible_sleep_on_timeout is deprecated and has been replaced
342 * with the equivalent code.
345 static long cond_wait_interruptible_timeout_irqrestore(
346 wait_queue_head_t *q, long timeout,
347 spinlock_t *lock, unsigned long flags)
352 prepare_to_wait(q, &wait, TASK_INTERRUPTIBLE);
353 spin_unlock_irqrestore(lock, flags);
354 timeout = schedule_timeout(timeout);
355 finish_wait(q, &wait);
361 * Digi Write OOB Command
363 * Write commands on the out of band port. Commands are 4
364 * bytes each, multiple commands can be sent at once, and
365 * no command will be split across USB packets. Returns 0
366 * if successful, -EINTR if interrupted while sleeping and
367 * the interruptible flag is true, or a negative error
368 * returned by usb_submit_urb.
371 static int digi_write_oob_command(struct usb_serial_port *port,
372 unsigned char *buf, int count, int interruptible)
376 struct usb_serial_port *oob_port = (struct usb_serial_port *)((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
377 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
378 unsigned long flags = 0;
381 "digi_write_oob_command: TOP: port=%d, count=%d\n",
382 oob_priv->dp_port_num, count);
384 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
386 while (oob_priv->dp_write_urb_in_use) {
387 cond_wait_interruptible_timeout_irqrestore(
388 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
389 &oob_priv->dp_port_lock, flags);
390 if (interruptible && signal_pending(current))
392 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
395 /* len must be a multiple of 4, so commands are not split */
396 len = min(count, oob_port->bulk_out_size);
399 memcpy(oob_port->write_urb->transfer_buffer, buf, len);
400 oob_port->write_urb->transfer_buffer_length = len;
401 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
403 oob_priv->dp_write_urb_in_use = 1;
408 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
410 dev_err(&port->dev, "%s: usb_submit_urb failed, ret=%d\n",
418 * Digi Write In Band Command
420 * Write commands on the given port. Commands are 4
421 * bytes each, multiple commands can be sent at once, and
422 * no command will be split across USB packets. If timeout
423 * is non-zero, write in band command will return after
424 * waiting unsuccessfully for the URB status to clear for
425 * timeout ticks. Returns 0 if successful, or a negative
426 * error returned by digi_write.
429 static int digi_write_inb_command(struct usb_serial_port *port,
430 unsigned char *buf, int count, unsigned long timeout)
434 struct digi_port *priv = usb_get_serial_port_data(port);
435 unsigned char *data = port->write_urb->transfer_buffer;
436 unsigned long flags = 0;
438 dev_dbg(&port->dev, "digi_write_inb_command: TOP: port=%d, count=%d\n",
439 priv->dp_port_num, count);
446 spin_lock_irqsave(&priv->dp_port_lock, flags);
447 while (count > 0 && ret == 0) {
448 while (priv->dp_write_urb_in_use &&
449 time_before(jiffies, timeout)) {
450 cond_wait_interruptible_timeout_irqrestore(
451 &port->write_wait, DIGI_RETRY_TIMEOUT,
452 &priv->dp_port_lock, flags);
453 if (signal_pending(current))
455 spin_lock_irqsave(&priv->dp_port_lock, flags);
458 /* len must be a multiple of 4 and small enough to */
459 /* guarantee the write will send buffered data first, */
460 /* so commands are in order with data and not split */
461 len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len);
465 /* write any buffered data first */
466 if (priv->dp_out_buf_len > 0) {
467 data[0] = DIGI_CMD_SEND_DATA;
468 data[1] = priv->dp_out_buf_len;
469 memcpy(data + 2, priv->dp_out_buf,
470 priv->dp_out_buf_len);
471 memcpy(data + 2 + priv->dp_out_buf_len, buf, len);
472 port->write_urb->transfer_buffer_length
473 = priv->dp_out_buf_len + 2 + len;
475 memcpy(data, buf, len);
476 port->write_urb->transfer_buffer_length = len;
479 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
481 priv->dp_write_urb_in_use = 1;
482 priv->dp_out_buf_len = 0;
488 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
492 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
493 __func__, ret, priv->dp_port_num);
499 * Digi Set Modem Signals
501 * Sets or clears DTR and RTS on the port, according to the
502 * modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags
503 * for the modem_signals argument. Returns 0 if successful,
504 * -EINTR if interrupted while sleeping, or a non-zero error
505 * returned by usb_submit_urb.
508 static int digi_set_modem_signals(struct usb_serial_port *port,
509 unsigned int modem_signals, int interruptible)
513 struct digi_port *port_priv = usb_get_serial_port_data(port);
514 struct usb_serial_port *oob_port = (struct usb_serial_port *) ((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
515 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
516 unsigned char *data = oob_port->write_urb->transfer_buffer;
517 unsigned long flags = 0;
521 "digi_set_modem_signals: TOP: port=%d, modem_signals=0x%x\n",
522 port_priv->dp_port_num, modem_signals);
524 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
525 spin_lock(&port_priv->dp_port_lock);
527 while (oob_priv->dp_write_urb_in_use) {
528 spin_unlock(&port_priv->dp_port_lock);
529 cond_wait_interruptible_timeout_irqrestore(
530 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
531 &oob_priv->dp_port_lock, flags);
532 if (interruptible && signal_pending(current))
534 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
535 spin_lock(&port_priv->dp_port_lock);
537 data[0] = DIGI_CMD_SET_DTR_SIGNAL;
538 data[1] = port_priv->dp_port_num;
539 data[2] = (modem_signals & TIOCM_DTR) ?
540 DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE;
542 data[4] = DIGI_CMD_SET_RTS_SIGNAL;
543 data[5] = port_priv->dp_port_num;
544 data[6] = (modem_signals & TIOCM_RTS) ?
545 DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE;
548 oob_port->write_urb->transfer_buffer_length = 8;
550 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
552 oob_priv->dp_write_urb_in_use = 1;
553 port_priv->dp_modem_signals =
554 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS))
555 | (modem_signals&(TIOCM_DTR|TIOCM_RTS));
557 spin_unlock(&port_priv->dp_port_lock);
558 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
560 dev_err(&port->dev, "%s: usb_submit_urb failed, ret=%d\n",
568 * Digi transmit idle waits, up to timeout ticks, for the transmitter
569 * to go idle. It returns 0 if successful or a negative error.
571 * There are race conditions here if more than one process is calling
572 * digi_transmit_idle on the same port at the same time. However, this
573 * is only called from close, and only one process can be in close on a
574 * port at a time, so its ok.
577 static int digi_transmit_idle(struct usb_serial_port *port,
578 unsigned long timeout)
581 unsigned char buf[2];
582 struct digi_port *priv = usb_get_serial_port_data(port);
583 unsigned long flags = 0;
585 spin_lock_irqsave(&priv->dp_port_lock, flags);
586 priv->dp_transmit_idle = 0;
587 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
589 buf[0] = DIGI_CMD_TRANSMIT_IDLE;
594 ret = digi_write_inb_command(port, buf, 2, timeout - jiffies);
598 spin_lock_irqsave(&priv->dp_port_lock, flags);
600 while (time_before(jiffies, timeout) && !priv->dp_transmit_idle) {
601 cond_wait_interruptible_timeout_irqrestore(
602 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT,
603 &priv->dp_port_lock, flags);
604 if (signal_pending(current))
606 spin_lock_irqsave(&priv->dp_port_lock, flags);
608 priv->dp_transmit_idle = 0;
609 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
615 static void digi_rx_throttle(struct tty_struct *tty)
618 struct usb_serial_port *port = tty->driver_data;
619 struct digi_port *priv = usb_get_serial_port_data(port);
621 /* stop receiving characters by not resubmitting the read urb */
622 spin_lock_irqsave(&priv->dp_port_lock, flags);
623 priv->dp_throttled = 1;
624 priv->dp_throttle_restart = 0;
625 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
629 static void digi_rx_unthrottle(struct tty_struct *tty)
633 struct usb_serial_port *port = tty->driver_data;
634 struct digi_port *priv = usb_get_serial_port_data(port);
636 spin_lock_irqsave(&priv->dp_port_lock, flags);
638 /* restart read chain */
639 if (priv->dp_throttle_restart)
640 ret = usb_submit_urb(port->read_urb, GFP_ATOMIC);
642 /* turn throttle off */
643 priv->dp_throttled = 0;
644 priv->dp_throttle_restart = 0;
646 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
650 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
651 __func__, ret, priv->dp_port_num);
655 static void digi_set_termios(struct tty_struct *tty,
656 struct usb_serial_port *port, struct ktermios *old_termios)
658 struct digi_port *priv = usb_get_serial_port_data(port);
659 struct device *dev = &port->dev;
660 unsigned int iflag = tty->termios.c_iflag;
661 unsigned int cflag = tty->termios.c_cflag;
662 unsigned int old_iflag = old_termios->c_iflag;
663 unsigned int old_cflag = old_termios->c_cflag;
664 unsigned char buf[32];
665 unsigned int modem_signals;
671 "digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x\n",
672 priv->dp_port_num, iflag, old_iflag, cflag, old_cflag);
675 baud = tty_get_baud_rate(tty);
676 if (baud != tty_termios_baud_rate(old_termios)) {
679 /* reassert DTR and (maybe) RTS on transition from B0 */
680 if ((old_cflag & CBAUD) == B0) {
681 /* don't set RTS if using hardware flow control */
682 /* and throttling input */
683 modem_signals = TIOCM_DTR;
684 if (!C_CRTSCTS(tty) || !tty_throttled(tty))
685 modem_signals |= TIOCM_RTS;
686 digi_set_modem_signals(port, modem_signals, 1);
689 /* drop DTR and RTS on transition to B0 */
690 case 0: digi_set_modem_signals(port, 0, 1); break;
691 case 50: arg = DIGI_BAUD_50; break;
692 case 75: arg = DIGI_BAUD_75; break;
693 case 110: arg = DIGI_BAUD_110; break;
694 case 150: arg = DIGI_BAUD_150; break;
695 case 200: arg = DIGI_BAUD_200; break;
696 case 300: arg = DIGI_BAUD_300; break;
697 case 600: arg = DIGI_BAUD_600; break;
698 case 1200: arg = DIGI_BAUD_1200; break;
699 case 1800: arg = DIGI_BAUD_1800; break;
700 case 2400: arg = DIGI_BAUD_2400; break;
701 case 4800: arg = DIGI_BAUD_4800; break;
702 case 9600: arg = DIGI_BAUD_9600; break;
703 case 19200: arg = DIGI_BAUD_19200; break;
704 case 38400: arg = DIGI_BAUD_38400; break;
705 case 57600: arg = DIGI_BAUD_57600; break;
706 case 115200: arg = DIGI_BAUD_115200; break;
707 case 230400: arg = DIGI_BAUD_230400; break;
708 case 460800: arg = DIGI_BAUD_460800; break;
710 arg = DIGI_BAUD_9600;
715 buf[i++] = DIGI_CMD_SET_BAUD_RATE;
716 buf[i++] = priv->dp_port_num;
722 tty->termios.c_cflag &= ~CMSPAR;
724 if ((cflag&(PARENB|PARODD)) != (old_cflag&(PARENB|PARODD))) {
727 arg = DIGI_PARITY_ODD;
729 arg = DIGI_PARITY_EVEN;
731 arg = DIGI_PARITY_NONE;
733 buf[i++] = DIGI_CMD_SET_PARITY;
734 buf[i++] = priv->dp_port_num;
739 if ((cflag&CSIZE) != (old_cflag&CSIZE)) {
741 switch (cflag&CSIZE) {
742 case CS5: arg = DIGI_WORD_SIZE_5; break;
743 case CS6: arg = DIGI_WORD_SIZE_6; break;
744 case CS7: arg = DIGI_WORD_SIZE_7; break;
745 case CS8: arg = DIGI_WORD_SIZE_8; break;
748 "digi_set_termios: can't handle word size %d\n",
754 buf[i++] = DIGI_CMD_SET_WORD_SIZE;
755 buf[i++] = priv->dp_port_num;
763 if ((cflag&CSTOPB) != (old_cflag&CSTOPB)) {
766 arg = DIGI_STOP_BITS_2;
768 arg = DIGI_STOP_BITS_1;
770 buf[i++] = DIGI_CMD_SET_STOP_BITS;
771 buf[i++] = priv->dp_port_num;
777 /* set input flow control */
778 if ((iflag&IXOFF) != (old_iflag&IXOFF)
779 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS)) {
782 arg |= DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
784 arg &= ~DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
787 arg |= DIGI_INPUT_FLOW_CONTROL_RTS;
789 /* On USB-4 it is necessary to assert RTS prior */
790 /* to selecting RTS input flow control. */
791 buf[i++] = DIGI_CMD_SET_RTS_SIGNAL;
792 buf[i++] = priv->dp_port_num;
793 buf[i++] = DIGI_RTS_ACTIVE;
797 arg &= ~DIGI_INPUT_FLOW_CONTROL_RTS;
799 buf[i++] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
800 buf[i++] = priv->dp_port_num;
805 /* set output flow control */
806 if ((iflag & IXON) != (old_iflag & IXON)
807 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
810 arg |= DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
812 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
814 if (cflag & CRTSCTS) {
815 arg |= DIGI_OUTPUT_FLOW_CONTROL_CTS;
817 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_CTS;
820 buf[i++] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
821 buf[i++] = priv->dp_port_num;
826 /* set receive enable/disable */
827 if ((cflag & CREAD) != (old_cflag & CREAD)) {
833 buf[i++] = DIGI_CMD_RECEIVE_ENABLE;
834 buf[i++] = priv->dp_port_num;
838 ret = digi_write_oob_command(port, buf, i, 1);
840 dev_dbg(dev, "digi_set_termios: write oob failed, ret=%d\n", ret);
841 tty_encode_baud_rate(tty, baud, baud);
845 static void digi_break_ctl(struct tty_struct *tty, int break_state)
847 struct usb_serial_port *port = tty->driver_data;
848 unsigned char buf[4];
850 buf[0] = DIGI_CMD_BREAK_CONTROL;
851 buf[1] = 2; /* length */
852 buf[2] = break_state ? 1 : 0;
853 buf[3] = 0; /* pad */
854 digi_write_inb_command(port, buf, 4, 0);
858 static int digi_tiocmget(struct tty_struct *tty)
860 struct usb_serial_port *port = tty->driver_data;
861 struct digi_port *priv = usb_get_serial_port_data(port);
865 spin_lock_irqsave(&priv->dp_port_lock, flags);
866 val = priv->dp_modem_signals;
867 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
872 static int digi_tiocmset(struct tty_struct *tty,
873 unsigned int set, unsigned int clear)
875 struct usb_serial_port *port = tty->driver_data;
876 struct digi_port *priv = usb_get_serial_port_data(port);
880 spin_lock_irqsave(&priv->dp_port_lock, flags);
881 val = (priv->dp_modem_signals & ~clear) | set;
882 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
883 return digi_set_modem_signals(port, val, 1);
887 static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
888 const unsigned char *buf, int count)
891 int ret, data_len, new_len;
892 struct digi_port *priv = usb_get_serial_port_data(port);
893 unsigned char *data = port->write_urb->transfer_buffer;
894 unsigned long flags = 0;
897 "digi_write: TOP: port=%d, count=%d, in_interrupt=%ld\n",
898 priv->dp_port_num, count, in_interrupt());
900 /* copy user data (which can sleep) before getting spin lock */
901 count = min(count, port->bulk_out_size-2);
902 count = min(64, count);
904 /* be sure only one write proceeds at a time */
905 /* there are races on the port private buffer */
906 spin_lock_irqsave(&priv->dp_port_lock, flags);
908 /* wait for urb status clear to submit another urb */
909 if (priv->dp_write_urb_in_use) {
910 /* buffer data if count is 1 (probably put_char) if possible */
911 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) {
912 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf;
917 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
921 /* allow space for any buffered data and for new data, up to */
922 /* transfer buffer size - 2 (for command and length bytes) */
923 new_len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len);
924 data_len = new_len + priv->dp_out_buf_len;
927 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
931 port->write_urb->transfer_buffer_length = data_len+2;
933 *data++ = DIGI_CMD_SEND_DATA;
936 /* copy in buffered data first */
937 memcpy(data, priv->dp_out_buf, priv->dp_out_buf_len);
938 data += priv->dp_out_buf_len;
940 /* copy in new data */
941 memcpy(data, buf, new_len);
943 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
945 priv->dp_write_urb_in_use = 1;
947 priv->dp_out_buf_len = 0;
950 /* return length of new data written, or error */
951 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
953 dev_err_console(port,
954 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
955 __func__, ret, priv->dp_port_num);
956 dev_dbg(&port->dev, "digi_write: returning %d\n", ret);
961 static void digi_write_bulk_callback(struct urb *urb)
964 struct usb_serial_port *port = urb->context;
965 struct usb_serial *serial;
966 struct digi_port *priv;
967 struct digi_serial *serial_priv;
969 int status = urb->status;
972 /* port and serial sanity check */
973 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
974 pr_err("%s: port or port->private is NULL, status=%d\n",
978 serial = port->serial;
979 if (serial == NULL || (serial_priv = usb_get_serial_data(serial)) == NULL) {
981 "%s: serial or serial->private is NULL, status=%d\n",
986 /* handle oob callback */
987 if (priv->dp_port_num == serial_priv->ds_oob_port_num) {
988 dev_dbg(&port->dev, "digi_write_bulk_callback: oob callback\n");
989 spin_lock(&priv->dp_port_lock);
990 priv->dp_write_urb_in_use = 0;
991 wake_up_interruptible(&port->write_wait);
992 spin_unlock(&priv->dp_port_lock);
996 /* try to send any buffered data on this port */
998 spin_lock(&priv->dp_port_lock);
999 priv->dp_write_urb_in_use = 0;
1000 if (priv->dp_out_buf_len > 0) {
1001 *((unsigned char *)(port->write_urb->transfer_buffer))
1002 = (unsigned char)DIGI_CMD_SEND_DATA;
1003 *((unsigned char *)(port->write_urb->transfer_buffer) + 1)
1004 = (unsigned char)priv->dp_out_buf_len;
1005 port->write_urb->transfer_buffer_length =
1006 priv->dp_out_buf_len + 2;
1007 memcpy(port->write_urb->transfer_buffer + 2, priv->dp_out_buf,
1008 priv->dp_out_buf_len);
1009 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1011 priv->dp_write_urb_in_use = 1;
1012 priv->dp_out_buf_len = 0;
1016 spin_unlock(&priv->dp_port_lock);
1018 if (ret && ret != -EPERM)
1019 dev_err_console(port,
1020 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
1021 __func__, ret, priv->dp_port_num);
1024 tty_port_tty_wakeup(&port->port);
1027 static int digi_write_room(struct tty_struct *tty)
1029 struct usb_serial_port *port = tty->driver_data;
1030 struct digi_port *priv = usb_get_serial_port_data(port);
1032 unsigned long flags = 0;
1034 spin_lock_irqsave(&priv->dp_port_lock, flags);
1036 if (priv->dp_write_urb_in_use)
1039 room = port->bulk_out_size - 2 - priv->dp_out_buf_len;
1041 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1042 dev_dbg(&port->dev, "digi_write_room: port=%d, room=%d\n", priv->dp_port_num, room);
1047 static int digi_chars_in_buffer(struct tty_struct *tty)
1049 struct usb_serial_port *port = tty->driver_data;
1050 struct digi_port *priv = usb_get_serial_port_data(port);
1052 if (priv->dp_write_urb_in_use) {
1053 dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n",
1054 priv->dp_port_num, port->bulk_out_size - 2);
1055 /* return(port->bulk_out_size - 2); */
1058 dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n",
1059 priv->dp_port_num, priv->dp_out_buf_len);
1060 return priv->dp_out_buf_len;
1065 static void digi_dtr_rts(struct usb_serial_port *port, int on)
1067 /* Adjust DTR and RTS */
1068 digi_set_modem_signals(port, on * (TIOCM_DTR|TIOCM_RTS), 1);
1071 static int digi_open(struct tty_struct *tty, struct usb_serial_port *port)
1074 unsigned char buf[32];
1075 struct digi_port *priv = usb_get_serial_port_data(port);
1076 struct ktermios not_termios;
1078 /* be sure the device is started up */
1079 if (digi_startup_device(port->serial) != 0)
1082 /* read modem signals automatically whenever they change */
1083 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS;
1084 buf[1] = priv->dp_port_num;
1085 buf[2] = DIGI_ENABLE;
1089 buf[4] = DIGI_CMD_IFLUSH_FIFO;
1090 buf[5] = priv->dp_port_num;
1091 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1094 ret = digi_write_oob_command(port, buf, 8, 1);
1096 dev_dbg(&port->dev, "digi_open: write oob failed, ret=%d\n", ret);
1098 /* set termios settings */
1100 not_termios.c_cflag = ~tty->termios.c_cflag;
1101 not_termios.c_iflag = ~tty->termios.c_iflag;
1102 digi_set_termios(tty, port, ¬_termios);
1108 static void digi_close(struct usb_serial_port *port)
1112 unsigned char buf[32];
1113 struct digi_port *priv = usb_get_serial_port_data(port);
1115 mutex_lock(&port->serial->disc_mutex);
1116 /* if disconnected, just clear flags */
1117 if (port->serial->disconnected)
1120 /* FIXME: Transmit idle belongs in the wait_unti_sent path */
1121 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1123 /* disable input flow control */
1124 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
1125 buf[1] = priv->dp_port_num;
1126 buf[2] = DIGI_DISABLE;
1129 /* disable output flow control */
1130 buf[4] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
1131 buf[5] = priv->dp_port_num;
1132 buf[6] = DIGI_DISABLE;
1135 /* disable reading modem signals automatically */
1136 buf[8] = DIGI_CMD_READ_INPUT_SIGNALS;
1137 buf[9] = priv->dp_port_num;
1138 buf[10] = DIGI_DISABLE;
1141 /* disable receive */
1142 buf[12] = DIGI_CMD_RECEIVE_ENABLE;
1143 buf[13] = priv->dp_port_num;
1144 buf[14] = DIGI_DISABLE;
1148 buf[16] = DIGI_CMD_IFLUSH_FIFO;
1149 buf[17] = priv->dp_port_num;
1150 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1153 ret = digi_write_oob_command(port, buf, 20, 0);
1155 dev_dbg(&port->dev, "digi_close: write oob failed, ret=%d\n",
1157 /* wait for final commands on oob port to complete */
1158 prepare_to_wait(&priv->dp_flush_wait, &wait,
1159 TASK_INTERRUPTIBLE);
1160 schedule_timeout(DIGI_CLOSE_TIMEOUT);
1161 finish_wait(&priv->dp_flush_wait, &wait);
1163 /* shutdown any outstanding bulk writes */
1164 usb_kill_urb(port->write_urb);
1166 spin_lock_irq(&priv->dp_port_lock);
1167 priv->dp_write_urb_in_use = 0;
1168 wake_up_interruptible(&priv->dp_close_wait);
1169 spin_unlock_irq(&priv->dp_port_lock);
1170 mutex_unlock(&port->serial->disc_mutex);
1175 * Digi Startup Device
1177 * Starts reads on all ports. Must be called AFTER startup, with
1178 * urbs initialized. Returns 0 if successful, non-zero error otherwise.
1181 static int digi_startup_device(struct usb_serial *serial)
1184 struct digi_serial *serial_priv = usb_get_serial_data(serial);
1185 struct usb_serial_port *port;
1187 /* be sure this happens exactly once */
1188 spin_lock(&serial_priv->ds_serial_lock);
1189 if (serial_priv->ds_device_started) {
1190 spin_unlock(&serial_priv->ds_serial_lock);
1193 serial_priv->ds_device_started = 1;
1194 spin_unlock(&serial_priv->ds_serial_lock);
1196 /* start reading from each bulk in endpoint for the device */
1197 /* set USB_DISABLE_SPD flag for write bulk urbs */
1198 for (i = 0; i < serial->type->num_ports + 1; i++) {
1199 port = serial->port[i];
1200 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
1203 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
1211 static int digi_port_init(struct usb_serial_port *port, unsigned port_num)
1213 struct digi_port *priv;
1215 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1219 spin_lock_init(&priv->dp_port_lock);
1220 priv->dp_port_num = port_num;
1221 init_waitqueue_head(&priv->dp_transmit_idle_wait);
1222 init_waitqueue_head(&priv->dp_flush_wait);
1223 init_waitqueue_head(&priv->dp_close_wait);
1224 priv->dp_port = port;
1226 init_waitqueue_head(&port->write_wait);
1228 usb_set_serial_port_data(port, priv);
1233 static int digi_startup(struct usb_serial *serial)
1235 struct digi_serial *serial_priv;
1238 serial_priv = kzalloc(sizeof(*serial_priv), GFP_KERNEL);
1242 spin_lock_init(&serial_priv->ds_serial_lock);
1243 serial_priv->ds_oob_port_num = serial->type->num_ports;
1244 serial_priv->ds_oob_port = serial->port[serial_priv->ds_oob_port_num];
1246 ret = digi_port_init(serial_priv->ds_oob_port,
1247 serial_priv->ds_oob_port_num);
1253 usb_set_serial_data(serial, serial_priv);
1259 static void digi_disconnect(struct usb_serial *serial)
1263 /* stop reads and writes on all ports */
1264 for (i = 0; i < serial->type->num_ports + 1; i++) {
1265 usb_kill_urb(serial->port[i]->read_urb);
1266 usb_kill_urb(serial->port[i]->write_urb);
1271 static void digi_release(struct usb_serial *serial)
1273 struct digi_serial *serial_priv;
1274 struct digi_port *priv;
1276 serial_priv = usb_get_serial_data(serial);
1278 priv = usb_get_serial_port_data(serial_priv->ds_oob_port);
1284 static int digi_port_probe(struct usb_serial_port *port)
1286 return digi_port_init(port, port->port_number);
1289 static int digi_port_remove(struct usb_serial_port *port)
1291 struct digi_port *priv;
1293 priv = usb_get_serial_port_data(port);
1299 static void digi_read_bulk_callback(struct urb *urb)
1301 struct usb_serial_port *port = urb->context;
1302 struct digi_port *priv;
1303 struct digi_serial *serial_priv;
1305 int status = urb->status;
1307 /* port sanity check, do not resubmit if port is not valid */
1310 priv = usb_get_serial_port_data(port);
1312 dev_err(&port->dev, "%s: port->private is NULL, status=%d\n",
1316 if (port->serial == NULL ||
1317 (serial_priv = usb_get_serial_data(port->serial)) == NULL) {
1318 dev_err(&port->dev, "%s: serial is bad or serial->private "
1319 "is NULL, status=%d\n", __func__, status);
1323 /* do not resubmit urb if it has any status error */
1326 "%s: nonzero read bulk status: status=%d, port=%d\n",
1327 __func__, status, priv->dp_port_num);
1331 /* handle oob or inb callback, do not resubmit if error */
1332 if (priv->dp_port_num == serial_priv->ds_oob_port_num) {
1333 if (digi_read_oob_callback(urb) != 0)
1336 if (digi_read_inb_callback(urb) != 0)
1341 ret = usb_submit_urb(urb, GFP_ATOMIC);
1342 if (ret != 0 && ret != -EPERM) {
1344 "%s: failed resubmitting urb, ret=%d, port=%d\n",
1345 __func__, ret, priv->dp_port_num);
1351 * Digi Read INB Callback
1353 * Digi Read INB Callback handles reads on the in band ports, sending
1354 * the data on to the tty subsystem. When called we know port and
1355 * port->private are not NULL and port->serial has been validated.
1356 * It returns 0 if successful, 1 if successful but the port is
1357 * throttled, and -1 if the sanity checks failed.
1360 static int digi_read_inb_callback(struct urb *urb)
1362 struct usb_serial_port *port = urb->context;
1363 struct digi_port *priv = usb_get_serial_port_data(port);
1364 unsigned char *buf = urb->transfer_buffer;
1368 unsigned char *data;
1369 int flag, throttled;
1371 /* short/multiple packet check */
1372 if (urb->actual_length < 2) {
1373 dev_warn(&port->dev, "short packet received\n");
1380 if (urb->actual_length != len + 2) {
1381 dev_err(&port->dev, "malformed packet received: port=%d, opcode=%d, len=%d, actual_length=%u\n",
1382 priv->dp_port_num, opcode, len, urb->actual_length);
1386 if (opcode == DIGI_CMD_RECEIVE_DATA && len < 1) {
1387 dev_err(&port->dev, "malformed data packet received\n");
1391 spin_lock(&priv->dp_port_lock);
1393 /* check for throttle; if set, do not resubmit read urb */
1394 /* indicate the read chain needs to be restarted on unthrottle */
1395 throttled = priv->dp_throttled;
1397 priv->dp_throttle_restart = 1;
1400 if (opcode == DIGI_CMD_RECEIVE_DATA) {
1401 port_status = buf[2];
1404 /* get flag from port_status */
1407 /* overrun is special, not associated with a char */
1408 if (port_status & DIGI_OVERRUN_ERROR)
1409 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
1411 /* break takes precedence over parity, */
1412 /* which takes precedence over framing errors */
1413 if (port_status & DIGI_BREAK_ERROR)
1415 else if (port_status & DIGI_PARITY_ERROR)
1417 else if (port_status & DIGI_FRAMING_ERROR)
1420 /* data length is len-1 (one byte of len is port_status) */
1423 tty_insert_flip_string_fixed_flag(&port->port, data,
1425 tty_flip_buffer_push(&port->port);
1428 spin_unlock(&priv->dp_port_lock);
1430 if (opcode == DIGI_CMD_RECEIVE_DISABLE)
1431 dev_dbg(&port->dev, "%s: got RECEIVE_DISABLE\n", __func__);
1432 else if (opcode != DIGI_CMD_RECEIVE_DATA)
1433 dev_dbg(&port->dev, "%s: unknown opcode: %d\n", __func__, opcode);
1435 return throttled ? 1 : 0;
1441 * Digi Read OOB Callback
1443 * Digi Read OOB Callback handles reads on the out of band port.
1444 * When called we know port and port->private are not NULL and
1445 * the port->serial is valid. It returns 0 if successful, and
1446 * -1 if the sanity checks failed.
1449 static int digi_read_oob_callback(struct urb *urb)
1452 struct usb_serial_port *port = urb->context;
1453 struct usb_serial *serial = port->serial;
1454 struct tty_struct *tty;
1455 struct digi_port *priv = usb_get_serial_port_data(port);
1456 unsigned char *buf = urb->transfer_buffer;
1457 int opcode, line, status, val;
1461 if (urb->actual_length < 4)
1464 /* handle each oob command */
1465 for (i = 0; i < urb->actual_length - 3; i += 4) {
1468 status = buf[i + 2];
1471 dev_dbg(&port->dev, "digi_read_oob_callback: opcode=%d, line=%d, status=%d, val=%d\n",
1472 opcode, line, status, val);
1474 if (status != 0 || line >= serial->type->num_ports)
1477 port = serial->port[line];
1479 priv = usb_get_serial_port_data(port);
1483 tty = tty_port_tty_get(&port->port);
1487 rts = C_CRTSCTS(tty);
1489 if (tty && opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1490 bool wakeup = false;
1492 spin_lock(&priv->dp_port_lock);
1493 /* convert from digi flags to termiox flags */
1494 if (val & DIGI_READ_INPUT_SIGNALS_CTS) {
1495 priv->dp_modem_signals |= TIOCM_CTS;
1499 priv->dp_modem_signals &= ~TIOCM_CTS;
1500 /* port must be open to use tty struct */
1502 if (val & DIGI_READ_INPUT_SIGNALS_DSR)
1503 priv->dp_modem_signals |= TIOCM_DSR;
1505 priv->dp_modem_signals &= ~TIOCM_DSR;
1506 if (val & DIGI_READ_INPUT_SIGNALS_RI)
1507 priv->dp_modem_signals |= TIOCM_RI;
1509 priv->dp_modem_signals &= ~TIOCM_RI;
1510 if (val & DIGI_READ_INPUT_SIGNALS_DCD)
1511 priv->dp_modem_signals |= TIOCM_CD;
1513 priv->dp_modem_signals &= ~TIOCM_CD;
1515 spin_unlock(&priv->dp_port_lock);
1518 tty_port_tty_wakeup(&port->port);
1519 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) {
1520 spin_lock(&priv->dp_port_lock);
1521 priv->dp_transmit_idle = 1;
1522 wake_up_interruptible(&priv->dp_transmit_idle_wait);
1523 spin_unlock(&priv->dp_port_lock);
1524 } else if (opcode == DIGI_CMD_IFLUSH_FIFO) {
1525 wake_up_interruptible(&priv->dp_flush_wait);
1533 module_usb_serial_driver(serial_drivers, id_table_combined);
1535 MODULE_AUTHOR(DRIVER_AUTHOR);
1536 MODULE_DESCRIPTION(DRIVER_DESC);
1537 MODULE_LICENSE("GPL");