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/init.h>
21 #include <linux/slab.h>
22 #include <linux/tty.h>
23 #include <linux/tty_driver.h>
24 #include <linux/tty_flip.h>
25 #include <linux/module.h>
26 #include <linux/spinlock.h>
27 #include <linux/workqueue.h>
28 #include <linux/uaccess.h>
29 #include <linux/usb.h>
30 #include <linux/wait.h>
31 #include <linux/usb/serial.h>
38 #define DRIVER_VERSION "v1.80.1.2"
39 #define DRIVER_AUTHOR "Peter Berger <pberger@brimson.com>, Al Borchers <borchers@steinerpoint.com>"
40 #define DRIVER_DESC "Digi AccelePort USB-2/USB-4 Serial Converter driver"
42 /* port output buffer length -- must be <= transfer buffer length - 2 */
43 /* so we can be sure to send the full buffer in one urb */
44 #define DIGI_OUT_BUF_SIZE 8
46 /* port input buffer length -- must be >= transfer buffer length - 3 */
47 /* so we can be sure to hold at least one full buffer from one urb */
48 #define DIGI_IN_BUF_SIZE 64
50 /* retry timeout while sleeping */
51 #define DIGI_RETRY_TIMEOUT (HZ/10)
53 /* timeout while waiting for tty output to drain in close */
54 /* this delay is used twice in close, so the total delay could */
55 /* be twice this value */
56 #define DIGI_CLOSE_TIMEOUT (5*HZ)
59 /* AccelePort USB Defines */
62 #define DIGI_VENDOR_ID 0x05c5
63 #define DIGI_2_ID 0x0002 /* USB-2 */
64 #define DIGI_4_ID 0x0004 /* USB-4 */
67 * "INB": can be used on the in-band endpoint
68 * "OOB": can be used on the out-of-band endpoint
70 #define DIGI_CMD_SET_BAUD_RATE 0 /* INB, OOB */
71 #define DIGI_CMD_SET_WORD_SIZE 1 /* INB, OOB */
72 #define DIGI_CMD_SET_PARITY 2 /* INB, OOB */
73 #define DIGI_CMD_SET_STOP_BITS 3 /* INB, OOB */
74 #define DIGI_CMD_SET_INPUT_FLOW_CONTROL 4 /* INB, OOB */
75 #define DIGI_CMD_SET_OUTPUT_FLOW_CONTROL 5 /* INB, OOB */
76 #define DIGI_CMD_SET_DTR_SIGNAL 6 /* INB, OOB */
77 #define DIGI_CMD_SET_RTS_SIGNAL 7 /* INB, OOB */
78 #define DIGI_CMD_READ_INPUT_SIGNALS 8 /* OOB */
79 #define DIGI_CMD_IFLUSH_FIFO 9 /* OOB */
80 #define DIGI_CMD_RECEIVE_ENABLE 10 /* INB, OOB */
81 #define DIGI_CMD_BREAK_CONTROL 11 /* INB, OOB */
82 #define DIGI_CMD_LOCAL_LOOPBACK 12 /* INB, OOB */
83 #define DIGI_CMD_TRANSMIT_IDLE 13 /* INB, OOB */
84 #define DIGI_CMD_READ_UART_REGISTER 14 /* OOB */
85 #define DIGI_CMD_WRITE_UART_REGISTER 15 /* INB, OOB */
86 #define DIGI_CMD_AND_UART_REGISTER 16 /* INB, OOB */
87 #define DIGI_CMD_OR_UART_REGISTER 17 /* INB, OOB */
88 #define DIGI_CMD_SEND_DATA 18 /* INB */
89 #define DIGI_CMD_RECEIVE_DATA 19 /* INB */
90 #define DIGI_CMD_RECEIVE_DISABLE 20 /* INB */
91 #define DIGI_CMD_GET_PORT_TYPE 21 /* OOB */
94 #define DIGI_BAUD_50 0
95 #define DIGI_BAUD_75 1
96 #define DIGI_BAUD_110 2
97 #define DIGI_BAUD_150 3
98 #define DIGI_BAUD_200 4
99 #define DIGI_BAUD_300 5
100 #define DIGI_BAUD_600 6
101 #define DIGI_BAUD_1200 7
102 #define DIGI_BAUD_1800 8
103 #define DIGI_BAUD_2400 9
104 #define DIGI_BAUD_4800 10
105 #define DIGI_BAUD_7200 11
106 #define DIGI_BAUD_9600 12
107 #define DIGI_BAUD_14400 13
108 #define DIGI_BAUD_19200 14
109 #define DIGI_BAUD_28800 15
110 #define DIGI_BAUD_38400 16
111 #define DIGI_BAUD_57600 17
112 #define DIGI_BAUD_76800 18
113 #define DIGI_BAUD_115200 19
114 #define DIGI_BAUD_153600 20
115 #define DIGI_BAUD_230400 21
116 #define DIGI_BAUD_460800 22
119 #define DIGI_WORD_SIZE_5 0
120 #define DIGI_WORD_SIZE_6 1
121 #define DIGI_WORD_SIZE_7 2
122 #define DIGI_WORD_SIZE_8 3
124 #define DIGI_PARITY_NONE 0
125 #define DIGI_PARITY_ODD 1
126 #define DIGI_PARITY_EVEN 2
127 #define DIGI_PARITY_MARK 3
128 #define DIGI_PARITY_SPACE 4
130 #define DIGI_STOP_BITS_1 0
131 #define DIGI_STOP_BITS_2 1
133 #define DIGI_INPUT_FLOW_CONTROL_XON_XOFF 1
134 #define DIGI_INPUT_FLOW_CONTROL_RTS 2
135 #define DIGI_INPUT_FLOW_CONTROL_DTR 4
137 #define DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF 1
138 #define DIGI_OUTPUT_FLOW_CONTROL_CTS 2
139 #define DIGI_OUTPUT_FLOW_CONTROL_DSR 4
141 #define DIGI_DTR_INACTIVE 0
142 #define DIGI_DTR_ACTIVE 1
143 #define DIGI_DTR_INPUT_FLOW_CONTROL 2
145 #define DIGI_RTS_INACTIVE 0
146 #define DIGI_RTS_ACTIVE 1
147 #define DIGI_RTS_INPUT_FLOW_CONTROL 2
148 #define DIGI_RTS_TOGGLE 3
150 #define DIGI_FLUSH_TX 1
151 #define DIGI_FLUSH_RX 2
152 #define DIGI_RESUME_TX 4 /* clears xoff condition */
154 #define DIGI_TRANSMIT_NOT_IDLE 0
155 #define DIGI_TRANSMIT_IDLE 1
157 #define DIGI_DISABLE 0
158 #define DIGI_ENABLE 1
160 #define DIGI_DEASSERT 0
161 #define DIGI_ASSERT 1
163 /* in band status codes */
164 #define DIGI_OVERRUN_ERROR 4
165 #define DIGI_PARITY_ERROR 8
166 #define DIGI_FRAMING_ERROR 16
167 #define DIGI_BREAK_ERROR 32
169 /* out of band status */
170 #define DIGI_NO_ERROR 0
171 #define DIGI_BAD_FIRST_PARAMETER 1
172 #define DIGI_BAD_SECOND_PARAMETER 2
173 #define DIGI_INVALID_LINE 3
174 #define DIGI_INVALID_OPCODE 4
177 #define DIGI_READ_INPUT_SIGNALS_SLOT 1
178 #define DIGI_READ_INPUT_SIGNALS_ERR 2
179 #define DIGI_READ_INPUT_SIGNALS_BUSY 4
180 #define DIGI_READ_INPUT_SIGNALS_PE 8
181 #define DIGI_READ_INPUT_SIGNALS_CTS 16
182 #define DIGI_READ_INPUT_SIGNALS_DSR 32
183 #define DIGI_READ_INPUT_SIGNALS_RI 64
184 #define DIGI_READ_INPUT_SIGNALS_DCD 128
190 spinlock_t ds_serial_lock;
191 struct usb_serial_port *ds_oob_port; /* out-of-band port */
192 int ds_oob_port_num; /* index of out-of-band port */
193 int ds_device_started;
197 spinlock_t dp_port_lock;
200 unsigned char dp_out_buf[DIGI_OUT_BUF_SIZE];
201 int dp_write_urb_in_use;
202 unsigned int dp_modem_signals;
203 wait_queue_head_t dp_modem_change_wait;
204 int dp_transmit_idle;
205 wait_queue_head_t dp_transmit_idle_wait;
207 int dp_throttle_restart;
208 wait_queue_head_t dp_flush_wait;
209 wait_queue_head_t dp_close_wait; /* wait queue for close */
210 struct work_struct dp_wakeup_work;
211 struct usb_serial_port *dp_port;
215 /* Local Function Declarations */
217 static void digi_wakeup_write(struct usb_serial_port *port);
218 static void digi_wakeup_write_lock(struct work_struct *work);
219 static int digi_write_oob_command(struct usb_serial_port *port,
220 unsigned char *buf, int count, int interruptible);
221 static int digi_write_inb_command(struct usb_serial_port *port,
222 unsigned char *buf, int count, unsigned long timeout);
223 static int digi_set_modem_signals(struct usb_serial_port *port,
224 unsigned int modem_signals, int interruptible);
225 static int digi_transmit_idle(struct usb_serial_port *port,
226 unsigned long timeout);
227 static void digi_rx_throttle(struct tty_struct *tty);
228 static void digi_rx_unthrottle(struct tty_struct *tty);
229 static void digi_set_termios(struct tty_struct *tty,
230 struct usb_serial_port *port, struct ktermios *old_termios);
231 static void digi_break_ctl(struct tty_struct *tty, int break_state);
232 static int digi_tiocmget(struct tty_struct *tty);
233 static int digi_tiocmset(struct tty_struct *tty, unsigned int set,
235 static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
236 const unsigned char *buf, int count);
237 static void digi_write_bulk_callback(struct urb *urb);
238 static int digi_write_room(struct tty_struct *tty);
239 static int digi_chars_in_buffer(struct tty_struct *tty);
240 static int digi_open(struct tty_struct *tty, struct usb_serial_port *port);
241 static void digi_close(struct usb_serial_port *port);
242 static void digi_dtr_rts(struct usb_serial_port *port, int on);
243 static int digi_startup_device(struct usb_serial *serial);
244 static int digi_startup(struct usb_serial *serial);
245 static void digi_disconnect(struct usb_serial *serial);
246 static void digi_release(struct usb_serial *serial);
247 static int digi_port_probe(struct usb_serial_port *port);
248 static int digi_port_remove(struct usb_serial_port *port);
249 static void digi_read_bulk_callback(struct urb *urb);
250 static int digi_read_inb_callback(struct urb *urb);
251 static int digi_read_oob_callback(struct urb *urb);
254 static const struct usb_device_id id_table_combined[] = {
255 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) },
256 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) },
257 { } /* Terminating entry */
260 static const struct usb_device_id id_table_2[] = {
261 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) },
262 { } /* Terminating entry */
265 static const struct usb_device_id id_table_4[] = {
266 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) },
267 { } /* Terminating entry */
270 MODULE_DEVICE_TABLE(usb, id_table_combined);
272 /* device info needed for the Digi serial converter */
274 static struct usb_serial_driver digi_acceleport_2_device = {
276 .owner = THIS_MODULE,
279 .description = "Digi 2 port USB adapter",
280 .id_table = id_table_2,
284 .dtr_rts = digi_dtr_rts,
286 .write_room = digi_write_room,
287 .write_bulk_callback = digi_write_bulk_callback,
288 .read_bulk_callback = digi_read_bulk_callback,
289 .chars_in_buffer = digi_chars_in_buffer,
290 .throttle = digi_rx_throttle,
291 .unthrottle = digi_rx_unthrottle,
292 .set_termios = digi_set_termios,
293 .break_ctl = digi_break_ctl,
294 .tiocmget = digi_tiocmget,
295 .tiocmset = digi_tiocmset,
296 .attach = digi_startup,
297 .disconnect = digi_disconnect,
298 .release = digi_release,
299 .port_probe = digi_port_probe,
300 .port_remove = digi_port_remove,
303 static struct usb_serial_driver digi_acceleport_4_device = {
305 .owner = THIS_MODULE,
308 .description = "Digi 4 port USB adapter",
309 .id_table = id_table_4,
314 .write_room = digi_write_room,
315 .write_bulk_callback = digi_write_bulk_callback,
316 .read_bulk_callback = digi_read_bulk_callback,
317 .chars_in_buffer = digi_chars_in_buffer,
318 .throttle = digi_rx_throttle,
319 .unthrottle = digi_rx_unthrottle,
320 .set_termios = digi_set_termios,
321 .break_ctl = digi_break_ctl,
322 .tiocmget = digi_tiocmget,
323 .tiocmset = digi_tiocmset,
324 .attach = digi_startup,
325 .disconnect = digi_disconnect,
326 .release = digi_release,
327 .port_probe = digi_port_probe,
328 .port_remove = digi_port_remove,
331 static struct usb_serial_driver * const serial_drivers[] = {
332 &digi_acceleport_2_device, &digi_acceleport_4_device, NULL
338 * Cond Wait Interruptible Timeout Irqrestore
340 * Do spin_unlock_irqrestore and interruptible_sleep_on_timeout
341 * so that wake ups are not lost if they occur between the unlock
342 * and the sleep. In other words, spin_unlock_irqrestore and
343 * interruptible_sleep_on_timeout are "atomic" with respect to
344 * wake ups. This is used to implement condition variables.
346 * interruptible_sleep_on_timeout is deprecated and has been replaced
347 * with the equivalent code.
350 static long cond_wait_interruptible_timeout_irqrestore(
351 wait_queue_head_t *q, long timeout,
352 spinlock_t *lock, unsigned long flags)
357 prepare_to_wait(q, &wait, TASK_INTERRUPTIBLE);
358 spin_unlock_irqrestore(lock, flags);
359 timeout = schedule_timeout(timeout);
360 finish_wait(q, &wait);
369 * Wake up port, line discipline, and tty processes sleeping
373 static void digi_wakeup_write_lock(struct work_struct *work)
375 struct digi_port *priv =
376 container_of(work, struct digi_port, dp_wakeup_work);
377 struct usb_serial_port *port = priv->dp_port;
380 spin_lock_irqsave(&priv->dp_port_lock, flags);
381 digi_wakeup_write(port);
382 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
385 static void digi_wakeup_write(struct usb_serial_port *port)
387 struct tty_struct *tty = tty_port_tty_get(&port->port);
396 * Digi Write OOB Command
398 * Write commands on the out of band port. Commands are 4
399 * bytes each, multiple commands can be sent at once, and
400 * no command will be split across USB packets. Returns 0
401 * if successful, -EINTR if interrupted while sleeping and
402 * the interruptible flag is true, or a negative error
403 * returned by usb_submit_urb.
406 static int digi_write_oob_command(struct usb_serial_port *port,
407 unsigned char *buf, int count, int interruptible)
411 struct usb_serial_port *oob_port = (struct usb_serial_port *)((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
412 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
413 unsigned long flags = 0;
416 "digi_write_oob_command: TOP: port=%d, count=%d\n",
417 oob_priv->dp_port_num, count);
419 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
421 while (oob_priv->dp_write_urb_in_use) {
422 cond_wait_interruptible_timeout_irqrestore(
423 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
424 &oob_priv->dp_port_lock, flags);
425 if (interruptible && signal_pending(current))
427 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
430 /* len must be a multiple of 4, so commands are not split */
431 len = min(count, oob_port->bulk_out_size);
434 memcpy(oob_port->write_urb->transfer_buffer, buf, len);
435 oob_port->write_urb->transfer_buffer_length = len;
436 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
438 oob_priv->dp_write_urb_in_use = 1;
443 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
445 dev_err(&port->dev, "%s: usb_submit_urb failed, ret=%d\n",
453 * Digi Write In Band Command
455 * Write commands on the given port. Commands are 4
456 * bytes each, multiple commands can be sent at once, and
457 * no command will be split across USB packets. If timeout
458 * is non-zero, write in band command will return after
459 * waiting unsuccessfully for the URB status to clear for
460 * timeout ticks. Returns 0 if successful, or a negative
461 * error returned by digi_write.
464 static int digi_write_inb_command(struct usb_serial_port *port,
465 unsigned char *buf, int count, unsigned long timeout)
469 struct digi_port *priv = usb_get_serial_port_data(port);
470 unsigned char *data = port->write_urb->transfer_buffer;
471 unsigned long flags = 0;
473 dev_dbg(&port->dev, "digi_write_inb_command: TOP: port=%d, count=%d\n",
474 priv->dp_port_num, count);
481 spin_lock_irqsave(&priv->dp_port_lock, flags);
482 while (count > 0 && ret == 0) {
483 while (priv->dp_write_urb_in_use &&
484 time_before(jiffies, timeout)) {
485 cond_wait_interruptible_timeout_irqrestore(
486 &port->write_wait, DIGI_RETRY_TIMEOUT,
487 &priv->dp_port_lock, flags);
488 if (signal_pending(current))
490 spin_lock_irqsave(&priv->dp_port_lock, flags);
493 /* len must be a multiple of 4 and small enough to */
494 /* guarantee the write will send buffered data first, */
495 /* so commands are in order with data and not split */
496 len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len);
500 /* write any buffered data first */
501 if (priv->dp_out_buf_len > 0) {
502 data[0] = DIGI_CMD_SEND_DATA;
503 data[1] = priv->dp_out_buf_len;
504 memcpy(data + 2, priv->dp_out_buf,
505 priv->dp_out_buf_len);
506 memcpy(data + 2 + priv->dp_out_buf_len, buf, len);
507 port->write_urb->transfer_buffer_length
508 = priv->dp_out_buf_len + 2 + len;
510 memcpy(data, buf, len);
511 port->write_urb->transfer_buffer_length = len;
514 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
516 priv->dp_write_urb_in_use = 1;
517 priv->dp_out_buf_len = 0;
523 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
527 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
528 __func__, ret, priv->dp_port_num);
534 * Digi Set Modem Signals
536 * Sets or clears DTR and RTS on the port, according to the
537 * modem_signals argument. Use TIOCM_DTR and TIOCM_RTS flags
538 * for the modem_signals argument. Returns 0 if successful,
539 * -EINTR if interrupted while sleeping, or a non-zero error
540 * returned by usb_submit_urb.
543 static int digi_set_modem_signals(struct usb_serial_port *port,
544 unsigned int modem_signals, int interruptible)
548 struct digi_port *port_priv = usb_get_serial_port_data(port);
549 struct usb_serial_port *oob_port = (struct usb_serial_port *) ((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port;
550 struct digi_port *oob_priv = usb_get_serial_port_data(oob_port);
551 unsigned char *data = oob_port->write_urb->transfer_buffer;
552 unsigned long flags = 0;
556 "digi_set_modem_signals: TOP: port=%d, modem_signals=0x%x\n",
557 port_priv->dp_port_num, modem_signals);
559 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
560 spin_lock(&port_priv->dp_port_lock);
562 while (oob_priv->dp_write_urb_in_use) {
563 spin_unlock(&port_priv->dp_port_lock);
564 cond_wait_interruptible_timeout_irqrestore(
565 &oob_port->write_wait, DIGI_RETRY_TIMEOUT,
566 &oob_priv->dp_port_lock, flags);
567 if (interruptible && signal_pending(current))
569 spin_lock_irqsave(&oob_priv->dp_port_lock, flags);
570 spin_lock(&port_priv->dp_port_lock);
572 data[0] = DIGI_CMD_SET_DTR_SIGNAL;
573 data[1] = port_priv->dp_port_num;
574 data[2] = (modem_signals & TIOCM_DTR) ?
575 DIGI_DTR_ACTIVE : DIGI_DTR_INACTIVE;
577 data[4] = DIGI_CMD_SET_RTS_SIGNAL;
578 data[5] = port_priv->dp_port_num;
579 data[6] = (modem_signals & TIOCM_RTS) ?
580 DIGI_RTS_ACTIVE : DIGI_RTS_INACTIVE;
583 oob_port->write_urb->transfer_buffer_length = 8;
585 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC);
587 oob_priv->dp_write_urb_in_use = 1;
588 port_priv->dp_modem_signals =
589 (port_priv->dp_modem_signals&~(TIOCM_DTR|TIOCM_RTS))
590 | (modem_signals&(TIOCM_DTR|TIOCM_RTS));
592 spin_unlock(&port_priv->dp_port_lock);
593 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags);
595 dev_err(&port->dev, "%s: usb_submit_urb failed, ret=%d\n",
603 * Digi transmit idle waits, up to timeout ticks, for the transmitter
604 * to go idle. It returns 0 if successful or a negative error.
606 * There are race conditions here if more than one process is calling
607 * digi_transmit_idle on the same port at the same time. However, this
608 * is only called from close, and only one process can be in close on a
609 * port at a time, so its ok.
612 static int digi_transmit_idle(struct usb_serial_port *port,
613 unsigned long timeout)
616 unsigned char buf[2];
617 struct digi_port *priv = usb_get_serial_port_data(port);
618 unsigned long flags = 0;
620 spin_lock_irqsave(&priv->dp_port_lock, flags);
621 priv->dp_transmit_idle = 0;
622 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
624 buf[0] = DIGI_CMD_TRANSMIT_IDLE;
629 ret = digi_write_inb_command(port, buf, 2, timeout - jiffies);
633 spin_lock_irqsave(&priv->dp_port_lock, flags);
635 while (time_before(jiffies, timeout) && !priv->dp_transmit_idle) {
636 cond_wait_interruptible_timeout_irqrestore(
637 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT,
638 &priv->dp_port_lock, flags);
639 if (signal_pending(current))
641 spin_lock_irqsave(&priv->dp_port_lock, flags);
643 priv->dp_transmit_idle = 0;
644 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
650 static void digi_rx_throttle(struct tty_struct *tty)
653 struct usb_serial_port *port = tty->driver_data;
654 struct digi_port *priv = usb_get_serial_port_data(port);
656 /* stop receiving characters by not resubmitting the read urb */
657 spin_lock_irqsave(&priv->dp_port_lock, flags);
658 priv->dp_throttled = 1;
659 priv->dp_throttle_restart = 0;
660 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
664 static void digi_rx_unthrottle(struct tty_struct *tty)
668 struct usb_serial_port *port = tty->driver_data;
669 struct digi_port *priv = usb_get_serial_port_data(port);
671 spin_lock_irqsave(&priv->dp_port_lock, flags);
673 /* restart read chain */
674 if (priv->dp_throttle_restart)
675 ret = usb_submit_urb(port->read_urb, GFP_ATOMIC);
677 /* turn throttle off */
678 priv->dp_throttled = 0;
679 priv->dp_throttle_restart = 0;
681 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
685 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
686 __func__, ret, priv->dp_port_num);
690 static void digi_set_termios(struct tty_struct *tty,
691 struct usb_serial_port *port, struct ktermios *old_termios)
693 struct digi_port *priv = usb_get_serial_port_data(port);
694 struct device *dev = &port->dev;
695 unsigned int iflag = tty->termios.c_iflag;
696 unsigned int cflag = tty->termios.c_cflag;
697 unsigned int old_iflag = old_termios->c_iflag;
698 unsigned int old_cflag = old_termios->c_cflag;
699 unsigned char buf[32];
700 unsigned int modem_signals;
706 "digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x\n",
707 priv->dp_port_num, iflag, old_iflag, cflag, old_cflag);
710 baud = tty_get_baud_rate(tty);
711 if (baud != tty_termios_baud_rate(old_termios)) {
714 /* reassert DTR and (maybe) RTS on transition from B0 */
715 if ((old_cflag&CBAUD) == B0) {
716 /* don't set RTS if using hardware flow control */
717 /* and throttling input */
718 modem_signals = TIOCM_DTR;
719 if (!(tty->termios.c_cflag & CRTSCTS) ||
720 !test_bit(TTY_THROTTLED, &tty->flags))
721 modem_signals |= TIOCM_RTS;
722 digi_set_modem_signals(port, modem_signals, 1);
725 /* drop DTR and RTS on transition to B0 */
726 case 0: digi_set_modem_signals(port, 0, 1); break;
727 case 50: arg = DIGI_BAUD_50; break;
728 case 75: arg = DIGI_BAUD_75; break;
729 case 110: arg = DIGI_BAUD_110; break;
730 case 150: arg = DIGI_BAUD_150; break;
731 case 200: arg = DIGI_BAUD_200; break;
732 case 300: arg = DIGI_BAUD_300; break;
733 case 600: arg = DIGI_BAUD_600; break;
734 case 1200: arg = DIGI_BAUD_1200; break;
735 case 1800: arg = DIGI_BAUD_1800; break;
736 case 2400: arg = DIGI_BAUD_2400; break;
737 case 4800: arg = DIGI_BAUD_4800; break;
738 case 9600: arg = DIGI_BAUD_9600; break;
739 case 19200: arg = DIGI_BAUD_19200; break;
740 case 38400: arg = DIGI_BAUD_38400; break;
741 case 57600: arg = DIGI_BAUD_57600; break;
742 case 115200: arg = DIGI_BAUD_115200; break;
743 case 230400: arg = DIGI_BAUD_230400; break;
744 case 460800: arg = DIGI_BAUD_460800; break;
746 arg = DIGI_BAUD_9600;
751 buf[i++] = DIGI_CMD_SET_BAUD_RATE;
752 buf[i++] = priv->dp_port_num;
758 tty->termios.c_cflag &= ~CMSPAR;
760 if ((cflag&(PARENB|PARODD)) != (old_cflag&(PARENB|PARODD))) {
763 arg = DIGI_PARITY_ODD;
765 arg = DIGI_PARITY_EVEN;
767 arg = DIGI_PARITY_NONE;
769 buf[i++] = DIGI_CMD_SET_PARITY;
770 buf[i++] = priv->dp_port_num;
775 if ((cflag&CSIZE) != (old_cflag&CSIZE)) {
777 switch (cflag&CSIZE) {
778 case CS5: arg = DIGI_WORD_SIZE_5; break;
779 case CS6: arg = DIGI_WORD_SIZE_6; break;
780 case CS7: arg = DIGI_WORD_SIZE_7; break;
781 case CS8: arg = DIGI_WORD_SIZE_8; break;
784 "digi_set_termios: can't handle word size %d\n",
790 buf[i++] = DIGI_CMD_SET_WORD_SIZE;
791 buf[i++] = priv->dp_port_num;
799 if ((cflag&CSTOPB) != (old_cflag&CSTOPB)) {
802 arg = DIGI_STOP_BITS_2;
804 arg = DIGI_STOP_BITS_1;
806 buf[i++] = DIGI_CMD_SET_STOP_BITS;
807 buf[i++] = priv->dp_port_num;
813 /* set input flow control */
814 if ((iflag&IXOFF) != (old_iflag&IXOFF)
815 || (cflag&CRTSCTS) != (old_cflag&CRTSCTS)) {
818 arg |= DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
820 arg &= ~DIGI_INPUT_FLOW_CONTROL_XON_XOFF;
823 arg |= DIGI_INPUT_FLOW_CONTROL_RTS;
825 /* On USB-4 it is necessary to assert RTS prior */
826 /* to selecting RTS input flow control. */
827 buf[i++] = DIGI_CMD_SET_RTS_SIGNAL;
828 buf[i++] = priv->dp_port_num;
829 buf[i++] = DIGI_RTS_ACTIVE;
833 arg &= ~DIGI_INPUT_FLOW_CONTROL_RTS;
835 buf[i++] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
836 buf[i++] = priv->dp_port_num;
841 /* set output flow control */
842 if ((iflag & IXON) != (old_iflag & IXON)
843 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
846 arg |= DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
848 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_XON_XOFF;
850 if (cflag & CRTSCTS) {
851 arg |= DIGI_OUTPUT_FLOW_CONTROL_CTS;
853 arg &= ~DIGI_OUTPUT_FLOW_CONTROL_CTS;
857 buf[i++] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
858 buf[i++] = priv->dp_port_num;
863 /* set receive enable/disable */
864 if ((cflag & CREAD) != (old_cflag & CREAD)) {
870 buf[i++] = DIGI_CMD_RECEIVE_ENABLE;
871 buf[i++] = priv->dp_port_num;
875 ret = digi_write_oob_command(port, buf, i, 1);
877 dev_dbg(dev, "digi_set_termios: write oob failed, ret=%d\n", ret);
878 tty_encode_baud_rate(tty, baud, baud);
882 static void digi_break_ctl(struct tty_struct *tty, int break_state)
884 struct usb_serial_port *port = tty->driver_data;
885 unsigned char buf[4];
887 buf[0] = DIGI_CMD_BREAK_CONTROL;
888 buf[1] = 2; /* length */
889 buf[2] = break_state ? 1 : 0;
890 buf[3] = 0; /* pad */
891 digi_write_inb_command(port, buf, 4, 0);
895 static int digi_tiocmget(struct tty_struct *tty)
897 struct usb_serial_port *port = tty->driver_data;
898 struct digi_port *priv = usb_get_serial_port_data(port);
902 spin_lock_irqsave(&priv->dp_port_lock, flags);
903 val = priv->dp_modem_signals;
904 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
909 static int digi_tiocmset(struct tty_struct *tty,
910 unsigned int set, unsigned int clear)
912 struct usb_serial_port *port = tty->driver_data;
913 struct digi_port *priv = usb_get_serial_port_data(port);
917 spin_lock_irqsave(&priv->dp_port_lock, flags);
918 val = (priv->dp_modem_signals & ~clear) | set;
919 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
920 return digi_set_modem_signals(port, val, 1);
924 static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
925 const unsigned char *buf, int count)
928 int ret, data_len, new_len;
929 struct digi_port *priv = usb_get_serial_port_data(port);
930 unsigned char *data = port->write_urb->transfer_buffer;
931 unsigned long flags = 0;
934 "digi_write: TOP: port=%d, count=%d, in_interrupt=%ld\n",
935 priv->dp_port_num, count, in_interrupt());
937 /* copy user data (which can sleep) before getting spin lock */
938 count = min(count, port->bulk_out_size-2);
939 count = min(64, count);
941 /* be sure only one write proceeds at a time */
942 /* there are races on the port private buffer */
943 spin_lock_irqsave(&priv->dp_port_lock, flags);
945 /* wait for urb status clear to submit another urb */
946 if (priv->dp_write_urb_in_use) {
947 /* buffer data if count is 1 (probably put_char) if possible */
948 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) {
949 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf;
954 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
958 /* allow space for any buffered data and for new data, up to */
959 /* transfer buffer size - 2 (for command and length bytes) */
960 new_len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len);
961 data_len = new_len + priv->dp_out_buf_len;
964 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
968 port->write_urb->transfer_buffer_length = data_len+2;
970 *data++ = DIGI_CMD_SEND_DATA;
973 /* copy in buffered data first */
974 memcpy(data, priv->dp_out_buf, priv->dp_out_buf_len);
975 data += priv->dp_out_buf_len;
977 /* copy in new data */
978 memcpy(data, buf, new_len);
980 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
982 priv->dp_write_urb_in_use = 1;
984 priv->dp_out_buf_len = 0;
987 /* return length of new data written, or error */
988 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
990 dev_err_console(port,
991 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
992 __func__, ret, priv->dp_port_num);
993 dev_dbg(&port->dev, "digi_write: returning %d\n", ret);
998 static void digi_write_bulk_callback(struct urb *urb)
1001 struct usb_serial_port *port = urb->context;
1002 struct usb_serial *serial;
1003 struct digi_port *priv;
1004 struct digi_serial *serial_priv;
1006 int status = urb->status;
1008 /* port and serial sanity check */
1009 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) {
1010 pr_err("%s: port or port->private is NULL, status=%d\n",
1014 serial = port->serial;
1015 if (serial == NULL || (serial_priv = usb_get_serial_data(serial)) == NULL) {
1017 "%s: serial or serial->private is NULL, status=%d\n",
1022 /* handle oob callback */
1023 if (priv->dp_port_num == serial_priv->ds_oob_port_num) {
1024 dev_dbg(&port->dev, "digi_write_bulk_callback: oob callback\n");
1025 spin_lock(&priv->dp_port_lock);
1026 priv->dp_write_urb_in_use = 0;
1027 wake_up_interruptible(&port->write_wait);
1028 spin_unlock(&priv->dp_port_lock);
1032 /* try to send any buffered data on this port */
1033 spin_lock(&priv->dp_port_lock);
1034 priv->dp_write_urb_in_use = 0;
1035 if (priv->dp_out_buf_len > 0) {
1036 *((unsigned char *)(port->write_urb->transfer_buffer))
1037 = (unsigned char)DIGI_CMD_SEND_DATA;
1038 *((unsigned char *)(port->write_urb->transfer_buffer) + 1)
1039 = (unsigned char)priv->dp_out_buf_len;
1040 port->write_urb->transfer_buffer_length =
1041 priv->dp_out_buf_len + 2;
1042 memcpy(port->write_urb->transfer_buffer + 2, priv->dp_out_buf,
1043 priv->dp_out_buf_len);
1044 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1046 priv->dp_write_urb_in_use = 1;
1047 priv->dp_out_buf_len = 0;
1050 /* wake up processes sleeping on writes immediately */
1051 digi_wakeup_write(port);
1052 /* also queue up a wakeup at scheduler time, in case we */
1053 /* lost the race in write_chan(). */
1054 schedule_work(&priv->dp_wakeup_work);
1056 spin_unlock(&priv->dp_port_lock);
1057 if (ret && ret != -EPERM)
1058 dev_err_console(port,
1059 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
1060 __func__, ret, priv->dp_port_num);
1063 static int digi_write_room(struct tty_struct *tty)
1065 struct usb_serial_port *port = tty->driver_data;
1066 struct digi_port *priv = usb_get_serial_port_data(port);
1068 unsigned long flags = 0;
1070 spin_lock_irqsave(&priv->dp_port_lock, flags);
1072 if (priv->dp_write_urb_in_use)
1075 room = port->bulk_out_size - 2 - priv->dp_out_buf_len;
1077 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1078 dev_dbg(&port->dev, "digi_write_room: port=%d, room=%d\n", priv->dp_port_num, room);
1083 static int digi_chars_in_buffer(struct tty_struct *tty)
1085 struct usb_serial_port *port = tty->driver_data;
1086 struct digi_port *priv = usb_get_serial_port_data(port);
1088 if (priv->dp_write_urb_in_use) {
1089 dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n",
1090 priv->dp_port_num, port->bulk_out_size - 2);
1091 /* return(port->bulk_out_size - 2); */
1094 dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n",
1095 priv->dp_port_num, priv->dp_out_buf_len);
1096 return priv->dp_out_buf_len;
1101 static void digi_dtr_rts(struct usb_serial_port *port, int on)
1103 /* Adjust DTR and RTS */
1104 digi_set_modem_signals(port, on * (TIOCM_DTR|TIOCM_RTS), 1);
1107 static int digi_open(struct tty_struct *tty, struct usb_serial_port *port)
1110 unsigned char buf[32];
1111 struct digi_port *priv = usb_get_serial_port_data(port);
1112 struct ktermios not_termios;
1114 /* be sure the device is started up */
1115 if (digi_startup_device(port->serial) != 0)
1118 /* read modem signals automatically whenever they change */
1119 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS;
1120 buf[1] = priv->dp_port_num;
1121 buf[2] = DIGI_ENABLE;
1125 buf[4] = DIGI_CMD_IFLUSH_FIFO;
1126 buf[5] = priv->dp_port_num;
1127 buf[6] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1130 ret = digi_write_oob_command(port, buf, 8, 1);
1132 dev_dbg(&port->dev, "digi_open: write oob failed, ret=%d\n", ret);
1134 /* set termios settings */
1136 not_termios.c_cflag = ~tty->termios.c_cflag;
1137 not_termios.c_iflag = ~tty->termios.c_iflag;
1138 digi_set_termios(tty, port, ¬_termios);
1144 static void digi_close(struct usb_serial_port *port)
1148 unsigned char buf[32];
1149 struct digi_port *priv = usb_get_serial_port_data(port);
1151 mutex_lock(&port->serial->disc_mutex);
1152 /* if disconnected, just clear flags */
1153 if (port->serial->disconnected)
1156 if (port->serial->dev) {
1157 /* FIXME: Transmit idle belongs in the wait_unti_sent path */
1158 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1160 /* disable input flow control */
1161 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
1162 buf[1] = priv->dp_port_num;
1163 buf[2] = DIGI_DISABLE;
1166 /* disable output flow control */
1167 buf[4] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
1168 buf[5] = priv->dp_port_num;
1169 buf[6] = DIGI_DISABLE;
1172 /* disable reading modem signals automatically */
1173 buf[8] = DIGI_CMD_READ_INPUT_SIGNALS;
1174 buf[9] = priv->dp_port_num;
1175 buf[10] = DIGI_DISABLE;
1178 /* disable receive */
1179 buf[12] = DIGI_CMD_RECEIVE_ENABLE;
1180 buf[13] = priv->dp_port_num;
1181 buf[14] = DIGI_DISABLE;
1185 buf[16] = DIGI_CMD_IFLUSH_FIFO;
1186 buf[17] = priv->dp_port_num;
1187 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1190 ret = digi_write_oob_command(port, buf, 20, 0);
1192 dev_dbg(&port->dev, "digi_close: write oob failed, ret=%d\n", ret);
1194 /* wait for final commands on oob port to complete */
1195 prepare_to_wait(&priv->dp_flush_wait, &wait,
1196 TASK_INTERRUPTIBLE);
1197 schedule_timeout(DIGI_CLOSE_TIMEOUT);
1198 finish_wait(&priv->dp_flush_wait, &wait);
1200 /* shutdown any outstanding bulk writes */
1201 usb_kill_urb(port->write_urb);
1204 spin_lock_irq(&priv->dp_port_lock);
1205 priv->dp_write_urb_in_use = 0;
1206 wake_up_interruptible(&priv->dp_close_wait);
1207 spin_unlock_irq(&priv->dp_port_lock);
1208 mutex_unlock(&port->serial->disc_mutex);
1213 * Digi Startup Device
1215 * Starts reads on all ports. Must be called AFTER startup, with
1216 * urbs initialized. Returns 0 if successful, non-zero error otherwise.
1219 static int digi_startup_device(struct usb_serial *serial)
1222 struct digi_serial *serial_priv = usb_get_serial_data(serial);
1223 struct usb_serial_port *port;
1225 /* be sure this happens exactly once */
1226 spin_lock(&serial_priv->ds_serial_lock);
1227 if (serial_priv->ds_device_started) {
1228 spin_unlock(&serial_priv->ds_serial_lock);
1231 serial_priv->ds_device_started = 1;
1232 spin_unlock(&serial_priv->ds_serial_lock);
1234 /* start reading from each bulk in endpoint for the device */
1235 /* set USB_DISABLE_SPD flag for write bulk urbs */
1236 for (i = 0; i < serial->type->num_ports + 1; i++) {
1237 port = serial->port[i];
1238 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
1241 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
1249 static int digi_port_init(struct usb_serial_port *port, unsigned port_num)
1251 struct digi_port *priv;
1253 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1257 spin_lock_init(&priv->dp_port_lock);
1258 priv->dp_port_num = port_num;
1259 init_waitqueue_head(&priv->dp_modem_change_wait);
1260 init_waitqueue_head(&priv->dp_transmit_idle_wait);
1261 init_waitqueue_head(&priv->dp_flush_wait);
1262 init_waitqueue_head(&priv->dp_close_wait);
1263 INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock);
1264 priv->dp_port = port;
1266 init_waitqueue_head(&port->write_wait);
1268 usb_set_serial_port_data(port, priv);
1273 static int digi_startup(struct usb_serial *serial)
1275 struct digi_serial *serial_priv;
1278 serial_priv = kzalloc(sizeof(*serial_priv), GFP_KERNEL);
1282 spin_lock_init(&serial_priv->ds_serial_lock);
1283 serial_priv->ds_oob_port_num = serial->type->num_ports;
1284 serial_priv->ds_oob_port = serial->port[serial_priv->ds_oob_port_num];
1286 ret = digi_port_init(serial_priv->ds_oob_port,
1287 serial_priv->ds_oob_port_num);
1293 usb_set_serial_data(serial, serial_priv);
1299 static void digi_disconnect(struct usb_serial *serial)
1303 /* stop reads and writes on all ports */
1304 for (i = 0; i < serial->type->num_ports + 1; i++) {
1305 usb_kill_urb(serial->port[i]->read_urb);
1306 usb_kill_urb(serial->port[i]->write_urb);
1311 static void digi_release(struct usb_serial *serial)
1313 struct digi_serial *serial_priv;
1314 struct digi_port *priv;
1316 serial_priv = usb_get_serial_data(serial);
1318 priv = usb_get_serial_port_data(serial_priv->ds_oob_port);
1324 static int digi_port_probe(struct usb_serial_port *port)
1328 port_num = port->number - port->serial->minor;
1330 return digi_port_init(port, port_num);
1333 static int digi_port_remove(struct usb_serial_port *port)
1335 struct digi_port *priv;
1337 priv = usb_get_serial_port_data(port);
1343 static void digi_read_bulk_callback(struct urb *urb)
1345 struct usb_serial_port *port = urb->context;
1346 struct digi_port *priv;
1347 struct digi_serial *serial_priv;
1349 int status = urb->status;
1351 /* port sanity check, do not resubmit if port is not valid */
1354 priv = usb_get_serial_port_data(port);
1356 dev_err(&port->dev, "%s: port->private is NULL, status=%d\n",
1360 if (port->serial == NULL ||
1361 (serial_priv = usb_get_serial_data(port->serial)) == NULL) {
1362 dev_err(&port->dev, "%s: serial is bad or serial->private "
1363 "is NULL, status=%d\n", __func__, status);
1367 /* do not resubmit urb if it has any status error */
1370 "%s: nonzero read bulk status: status=%d, port=%d\n",
1371 __func__, status, priv->dp_port_num);
1375 /* handle oob or inb callback, do not resubmit if error */
1376 if (priv->dp_port_num == serial_priv->ds_oob_port_num) {
1377 if (digi_read_oob_callback(urb) != 0)
1380 if (digi_read_inb_callback(urb) != 0)
1385 ret = usb_submit_urb(urb, GFP_ATOMIC);
1386 if (ret != 0 && ret != -EPERM) {
1388 "%s: failed resubmitting urb, ret=%d, port=%d\n",
1389 __func__, ret, priv->dp_port_num);
1395 * Digi Read INB Callback
1397 * Digi Read INB Callback handles reads on the in band ports, sending
1398 * the data on to the tty subsystem. When called we know port and
1399 * port->private are not NULL and port->serial has been validated.
1400 * It returns 0 if successful, 1 if successful but the port is
1401 * throttled, and -1 if the sanity checks failed.
1404 static int digi_read_inb_callback(struct urb *urb)
1407 struct usb_serial_port *port = urb->context;
1408 struct tty_struct *tty;
1409 struct digi_port *priv = usb_get_serial_port_data(port);
1410 int opcode = ((unsigned char *)urb->transfer_buffer)[0];
1411 int len = ((unsigned char *)urb->transfer_buffer)[1];
1412 int port_status = ((unsigned char *)urb->transfer_buffer)[2];
1413 unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3;
1414 int flag, throttled;
1415 int status = urb->status;
1417 /* do not process callbacks on closed ports */
1418 /* but do continue the read chain */
1419 if (urb->status == -ENOENT)
1422 /* short/multiple packet check */
1423 if (urb->actual_length != len + 2) {
1424 dev_err(&port->dev, "%s: INCOMPLETE OR MULTIPLE PACKET, "
1425 "status=%d, port=%d, opcode=%d, len=%d, "
1426 "actual_length=%d, status=%d\n", __func__, status,
1427 priv->dp_port_num, opcode, len, urb->actual_length,
1432 tty = tty_port_tty_get(&port->port);
1433 spin_lock(&priv->dp_port_lock);
1435 /* check for throttle; if set, do not resubmit read urb */
1436 /* indicate the read chain needs to be restarted on unthrottle */
1437 throttled = priv->dp_throttled;
1439 priv->dp_throttle_restart = 1;
1442 if (tty && opcode == DIGI_CMD_RECEIVE_DATA) {
1443 /* get flag from port_status */
1446 /* overrun is special, not associated with a char */
1447 if (port_status & DIGI_OVERRUN_ERROR)
1448 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1450 /* break takes precedence over parity, */
1451 /* which takes precedence over framing errors */
1452 if (port_status & DIGI_BREAK_ERROR)
1454 else if (port_status & DIGI_PARITY_ERROR)
1456 else if (port_status & DIGI_FRAMING_ERROR)
1459 /* data length is len-1 (one byte of len is port_status) */
1462 tty_insert_flip_string_fixed_flag(tty, data, flag,
1464 tty_flip_buffer_push(tty);
1467 spin_unlock(&priv->dp_port_lock);
1470 if (opcode == DIGI_CMD_RECEIVE_DISABLE)
1471 dev_dbg(&port->dev, "%s: got RECEIVE_DISABLE\n", __func__);
1472 else if (opcode != DIGI_CMD_RECEIVE_DATA)
1473 dev_dbg(&port->dev, "%s: unknown opcode: %d\n", __func__, opcode);
1475 return throttled ? 1 : 0;
1481 * Digi Read OOB Callback
1483 * Digi Read OOB Callback handles reads on the out of band port.
1484 * When called we know port and port->private are not NULL and
1485 * the port->serial is valid. It returns 0 if successful, and
1486 * -1 if the sanity checks failed.
1489 static int digi_read_oob_callback(struct urb *urb)
1492 struct usb_serial_port *port = urb->context;
1493 struct usb_serial *serial = port->serial;
1494 struct tty_struct *tty;
1495 struct digi_port *priv = usb_get_serial_port_data(port);
1496 int opcode, line, status, val;
1500 /* handle each oob command */
1501 for (i = 0; i < urb->actual_length - 3;) {
1502 opcode = ((unsigned char *)urb->transfer_buffer)[i++];
1503 line = ((unsigned char *)urb->transfer_buffer)[i++];
1504 status = ((unsigned char *)urb->transfer_buffer)[i++];
1505 val = ((unsigned char *)urb->transfer_buffer)[i++];
1507 dev_dbg(&port->dev, "digi_read_oob_callback: opcode=%d, line=%d, status=%d, val=%d\n",
1508 opcode, line, status, val);
1510 if (status != 0 || line >= serial->type->num_ports)
1513 port = serial->port[line];
1515 priv = usb_get_serial_port_data(port);
1519 tty = tty_port_tty_get(&port->port);
1523 rts = tty->termios.c_cflag & CRTSCTS;
1525 if (tty && opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1526 spin_lock(&priv->dp_port_lock);
1527 /* convert from digi flags to termiox flags */
1528 if (val & DIGI_READ_INPUT_SIGNALS_CTS) {
1529 priv->dp_modem_signals |= TIOCM_CTS;
1530 /* port must be open to use tty struct */
1532 tty->hw_stopped = 0;
1533 digi_wakeup_write(port);
1536 priv->dp_modem_signals &= ~TIOCM_CTS;
1537 /* port must be open to use tty struct */
1539 tty->hw_stopped = 1;
1541 if (val & DIGI_READ_INPUT_SIGNALS_DSR)
1542 priv->dp_modem_signals |= TIOCM_DSR;
1544 priv->dp_modem_signals &= ~TIOCM_DSR;
1545 if (val & DIGI_READ_INPUT_SIGNALS_RI)
1546 priv->dp_modem_signals |= TIOCM_RI;
1548 priv->dp_modem_signals &= ~TIOCM_RI;
1549 if (val & DIGI_READ_INPUT_SIGNALS_DCD)
1550 priv->dp_modem_signals |= TIOCM_CD;
1552 priv->dp_modem_signals &= ~TIOCM_CD;
1554 wake_up_interruptible(&priv->dp_modem_change_wait);
1555 spin_unlock(&priv->dp_port_lock);
1556 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) {
1557 spin_lock(&priv->dp_port_lock);
1558 priv->dp_transmit_idle = 1;
1559 wake_up_interruptible(&priv->dp_transmit_idle_wait);
1560 spin_unlock(&priv->dp_port_lock);
1561 } else if (opcode == DIGI_CMD_IFLUSH_FIFO) {
1562 wake_up_interruptible(&priv->dp_flush_wait);
1570 module_usb_serial_driver(serial_drivers, id_table_combined);
1572 MODULE_AUTHOR(DRIVER_AUTHOR);
1573 MODULE_DESCRIPTION(DRIVER_DESC);
1574 MODULE_LICENSE("GPL");