Lines Matching +full:port +full:- +full:2

1 // SPDX-License-Identifier: GPL-2.0+
3 * Digi AccelePort USB-4 and USB-2 Serial Converters
7 * Shamelessly based on Brian Warner's keyspan_pda.c and Greg Kroah-Hartman's
8 * usb-serial driver.
31 #define DRIVER_DESC "Digi AccelePort USB-2/USB-4 Serial Converter driver"
33 /* port output buffer length -- must be <= transfer buffer length - 2 */
37 /* port input buffer length -- must be >= transfer buffer length - 3 */
54 #define DIGI_2_ID 0x0002 /* USB-2 */
55 #define DIGI_4_ID 0x0004 /* USB-4 */
58 * "INB": can be used on the in-band endpoint
59 * "OOB": can be used on the out-of-band endpoint
63 #define DIGI_CMD_SET_PARITY 2 /* INB, OOB */
87 #define DIGI_BAUD_110 2
112 #define DIGI_WORD_SIZE_7 2
117 #define DIGI_PARITY_EVEN 2
125 #define DIGI_INPUT_FLOW_CONTROL_RTS 2
129 #define DIGI_OUTPUT_FLOW_CONTROL_CTS 2
134 #define DIGI_DTR_INPUT_FLOW_CONTROL 2
138 #define DIGI_RTS_INPUT_FLOW_CONTROL 2
142 #define DIGI_FLUSH_RX 2
163 #define DIGI_BAD_SECOND_PARAMETER 2
169 #define DIGI_READ_INPUT_SIGNALS_ERR 2
182 struct usb_serial_port *ds_oob_port; /* out-of-band port */
183 int ds_oob_port_num; /* index of out-of-band port */
207 static int digi_write_oob_command(struct usb_serial_port *port,
209 static int digi_write_inb_command(struct usb_serial_port *port,
211 static int digi_set_modem_signals(struct usb_serial_port *port,
213 static int digi_transmit_idle(struct usb_serial_port *port,
218 struct usb_serial_port *port,
224 static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
229 static int digi_open(struct tty_struct *tty, struct usb_serial_port *port);
230 static void digi_close(struct usb_serial_port *port);
231 static void digi_dtr_rts(struct usb_serial_port *port, int on);
236 static int digi_port_probe(struct usb_serial_port *port);
237 static void digi_port_remove(struct usb_serial_port *port);
267 .description = "Digi 2 port USB adapter",
297 .description = "Digi 4 port USB adapter",
359 * Write commands on the out of band port. Commands are 4
362 * if successful, -EINTR if interrupted while sleeping and
367 static int digi_write_oob_command(struct usb_serial_port *port, in digi_write_oob_command() argument
372 …(struct usb_serial_port *)((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port; in digi_write_oob_command()
376 dev_dbg(&port->dev, in digi_write_oob_command()
377 "digi_write_oob_command: TOP: port=%d, count=%d\n", in digi_write_oob_command()
378 oob_priv->dp_port_num, count); in digi_write_oob_command()
380 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); in digi_write_oob_command()
382 while (oob_priv->dp_write_urb_in_use) { in digi_write_oob_command()
384 &oob_priv->write_wait, DIGI_RETRY_TIMEOUT, in digi_write_oob_command()
385 &oob_priv->dp_port_lock, flags); in digi_write_oob_command()
387 return -EINTR; in digi_write_oob_command()
388 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); in digi_write_oob_command()
392 len = min(count, oob_port->bulk_out_size); in digi_write_oob_command()
395 memcpy(oob_port->write_urb->transfer_buffer, buf, len); in digi_write_oob_command()
396 oob_port->write_urb->transfer_buffer_length = len; in digi_write_oob_command()
397 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC); in digi_write_oob_command()
399 oob_priv->dp_write_urb_in_use = 1; in digi_write_oob_command()
400 count -= len; in digi_write_oob_command()
404 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags); in digi_write_oob_command()
406 dev_err(&port->dev, "%s: usb_submit_urb failed, ret=%d\n", in digi_write_oob_command()
416 * Write commands on the given port. Commands are 4
419 * is non-zero, write in band command will return after
425 static int digi_write_inb_command(struct usb_serial_port *port, in digi_write_inb_command() argument
430 struct digi_port *priv = usb_get_serial_port_data(port); in digi_write_inb_command()
431 unsigned char *data = port->write_urb->transfer_buffer; in digi_write_inb_command()
434 dev_dbg(&port->dev, "digi_write_inb_command: TOP: port=%d, count=%d\n", in digi_write_inb_command()
435 priv->dp_port_num, count); in digi_write_inb_command()
442 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_write_inb_command()
444 while (priv->dp_write_urb_in_use && in digi_write_inb_command()
447 &priv->write_wait, DIGI_RETRY_TIMEOUT, in digi_write_inb_command()
448 &priv->dp_port_lock, flags); in digi_write_inb_command()
450 return -EINTR; in digi_write_inb_command()
451 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_write_inb_command()
457 len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len); in digi_write_inb_command()
462 if (priv->dp_out_buf_len > 0) { in digi_write_inb_command()
464 data[1] = priv->dp_out_buf_len; in digi_write_inb_command()
465 memcpy(data + 2, priv->dp_out_buf, in digi_write_inb_command()
466 priv->dp_out_buf_len); in digi_write_inb_command()
467 memcpy(data + 2 + priv->dp_out_buf_len, buf, len); in digi_write_inb_command()
468 port->write_urb->transfer_buffer_length in digi_write_inb_command()
469 = priv->dp_out_buf_len + 2 + len; in digi_write_inb_command()
472 port->write_urb->transfer_buffer_length = len; in digi_write_inb_command()
475 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); in digi_write_inb_command()
477 priv->dp_write_urb_in_use = 1; in digi_write_inb_command()
478 priv->dp_out_buf_len = 0; in digi_write_inb_command()
479 count -= len; in digi_write_inb_command()
484 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_write_inb_command()
487 dev_err(&port->dev, in digi_write_inb_command()
488 "%s: usb_submit_urb failed, ret=%d, port=%d\n", in digi_write_inb_command()
489 __func__, ret, priv->dp_port_num); in digi_write_inb_command()
497 * Sets or clears DTR and RTS on the port, according to the
500 * -EINTR if interrupted while sleeping, or a non-zero error
504 static int digi_set_modem_signals(struct usb_serial_port *port, in digi_set_modem_signals() argument
509 struct digi_port *port_priv = usb_get_serial_port_data(port); in digi_set_modem_signals()
510 …struct usb_serial_port *) ((struct digi_serial *)(usb_get_serial_data(port->serial)))->ds_oob_port; in digi_set_modem_signals()
512 unsigned char *data = oob_port->write_urb->transfer_buffer; in digi_set_modem_signals()
515 dev_dbg(&port->dev, in digi_set_modem_signals()
516 "digi_set_modem_signals: TOP: port=%d, modem_signals=0x%x\n", in digi_set_modem_signals()
517 port_priv->dp_port_num, modem_signals); in digi_set_modem_signals()
519 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); in digi_set_modem_signals()
520 spin_lock(&port_priv->dp_port_lock); in digi_set_modem_signals()
522 while (oob_priv->dp_write_urb_in_use) { in digi_set_modem_signals()
523 spin_unlock(&port_priv->dp_port_lock); in digi_set_modem_signals()
525 &oob_priv->write_wait, DIGI_RETRY_TIMEOUT, in digi_set_modem_signals()
526 &oob_priv->dp_port_lock, flags); in digi_set_modem_signals()
528 return -EINTR; in digi_set_modem_signals()
529 spin_lock_irqsave(&oob_priv->dp_port_lock, flags); in digi_set_modem_signals()
530 spin_lock(&port_priv->dp_port_lock); in digi_set_modem_signals()
533 data[1] = port_priv->dp_port_num; in digi_set_modem_signals()
534 data[2] = (modem_signals & TIOCM_DTR) ? in digi_set_modem_signals()
538 data[5] = port_priv->dp_port_num; in digi_set_modem_signals()
543 oob_port->write_urb->transfer_buffer_length = 8; in digi_set_modem_signals()
545 ret = usb_submit_urb(oob_port->write_urb, GFP_ATOMIC); in digi_set_modem_signals()
547 oob_priv->dp_write_urb_in_use = 1; in digi_set_modem_signals()
548 port_priv->dp_modem_signals &= ~(TIOCM_DTR | TIOCM_RTS); in digi_set_modem_signals()
549 port_priv->dp_modem_signals |= in digi_set_modem_signals()
552 spin_unlock(&port_priv->dp_port_lock); in digi_set_modem_signals()
553 spin_unlock_irqrestore(&oob_priv->dp_port_lock, flags); in digi_set_modem_signals()
555 dev_err(&port->dev, "%s: usb_submit_urb failed, ret=%d\n", in digi_set_modem_signals()
567 * digi_transmit_idle on the same port at the same time. However, this
569 * port at a time, so its ok.
572 static int digi_transmit_idle(struct usb_serial_port *port, in digi_transmit_idle() argument
576 unsigned char buf[2]; in digi_transmit_idle()
577 struct digi_port *priv = usb_get_serial_port_data(port); in digi_transmit_idle()
580 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_transmit_idle()
581 priv->dp_transmit_idle = 0; in digi_transmit_idle()
582 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_transmit_idle()
589 ret = digi_write_inb_command(port, buf, 2, timeout - jiffies); in digi_transmit_idle()
593 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_transmit_idle()
595 while (time_before(jiffies, timeout) && !priv->dp_transmit_idle) { in digi_transmit_idle()
597 &priv->dp_transmit_idle_wait, DIGI_RETRY_TIMEOUT, in digi_transmit_idle()
598 &priv->dp_port_lock, flags); in digi_transmit_idle()
600 return -EINTR; in digi_transmit_idle()
601 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_transmit_idle()
603 priv->dp_transmit_idle = 0; in digi_transmit_idle()
604 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_transmit_idle()
613 struct usb_serial_port *port = tty->driver_data; in digi_rx_throttle() local
614 struct digi_port *priv = usb_get_serial_port_data(port); in digi_rx_throttle()
617 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_rx_throttle()
618 priv->dp_throttled = 1; in digi_rx_throttle()
619 priv->dp_throttle_restart = 0; in digi_rx_throttle()
620 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_rx_throttle()
628 struct usb_serial_port *port = tty->driver_data; in digi_rx_unthrottle() local
629 struct digi_port *priv = usb_get_serial_port_data(port); in digi_rx_unthrottle()
631 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_rx_unthrottle()
634 if (priv->dp_throttle_restart) in digi_rx_unthrottle()
635 ret = usb_submit_urb(port->read_urb, GFP_ATOMIC); in digi_rx_unthrottle()
638 priv->dp_throttled = 0; in digi_rx_unthrottle()
639 priv->dp_throttle_restart = 0; in digi_rx_unthrottle()
641 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_rx_unthrottle()
644 dev_err(&port->dev, in digi_rx_unthrottle()
645 "%s: usb_submit_urb failed, ret=%d, port=%d\n", in digi_rx_unthrottle()
646 __func__, ret, priv->dp_port_num); in digi_rx_unthrottle()
651 struct usb_serial_port *port, in digi_set_termios() argument
654 struct digi_port *priv = usb_get_serial_port_data(port); in digi_set_termios()
655 struct device *dev = &port->dev; in digi_set_termios()
656 unsigned int iflag = tty->termios.c_iflag; in digi_set_termios()
657 unsigned int cflag = tty->termios.c_cflag; in digi_set_termios()
658 unsigned int old_iflag = old_termios->c_iflag; in digi_set_termios()
659 unsigned int old_cflag = old_termios->c_cflag; in digi_set_termios()
667 "digi_set_termios: TOP: port=%d, iflag=0x%x, old_iflag=0x%x, cflag=0x%x, old_cflag=0x%x\n", in digi_set_termios()
668 priv->dp_port_num, iflag, old_iflag, cflag, old_cflag); in digi_set_termios()
673 arg = -1; in digi_set_termios()
682 digi_set_modem_signals(port, modem_signals, 1); in digi_set_termios()
686 case 0: digi_set_modem_signals(port, 0, 1); break; in digi_set_termios()
710 if (arg != -1) { in digi_set_termios()
712 buf[i++] = priv->dp_port_num; in digi_set_termios()
718 tty->termios.c_cflag &= ~CMSPAR; in digi_set_termios()
730 buf[i++] = priv->dp_port_num; in digi_set_termios()
736 arg = -1; in digi_set_termios()
749 if (arg != -1) { in digi_set_termios()
751 buf[i++] = priv->dp_port_num; in digi_set_termios()
767 buf[i++] = priv->dp_port_num; in digi_set_termios()
785 /* On USB-4 it is necessary to assert RTS prior */ in digi_set_termios()
788 buf[i++] = priv->dp_port_num; in digi_set_termios()
796 buf[i++] = priv->dp_port_num; in digi_set_termios()
816 buf[i++] = priv->dp_port_num; in digi_set_termios()
829 buf[i++] = priv->dp_port_num; in digi_set_termios()
833 ret = digi_write_oob_command(port, buf, i, 1); in digi_set_termios()
842 struct usb_serial_port *port = tty->driver_data; in digi_break_ctl() local
846 buf[1] = 2; /* length */ in digi_break_ctl()
847 buf[2] = break_state ? 1 : 0; in digi_break_ctl()
850 return digi_write_inb_command(port, buf, 4, 0); in digi_break_ctl()
856 struct usb_serial_port *port = tty->driver_data; in digi_tiocmget() local
857 struct digi_port *priv = usb_get_serial_port_data(port); in digi_tiocmget()
861 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_tiocmget()
862 val = priv->dp_modem_signals; in digi_tiocmget()
863 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_tiocmget()
871 struct usb_serial_port *port = tty->driver_data; in digi_tiocmset() local
872 struct digi_port *priv = usb_get_serial_port_data(port); in digi_tiocmset()
876 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_tiocmset()
877 val = (priv->dp_modem_signals & ~clear) | set; in digi_tiocmset()
878 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_tiocmset()
879 return digi_set_modem_signals(port, val, 1); in digi_tiocmset()
883 static int digi_write(struct tty_struct *tty, struct usb_serial_port *port, in digi_write() argument
888 struct digi_port *priv = usb_get_serial_port_data(port); in digi_write()
889 unsigned char *data = port->write_urb->transfer_buffer; in digi_write()
892 dev_dbg(&port->dev, "digi_write: TOP: port=%d, count=%d\n", in digi_write()
893 priv->dp_port_num, count); in digi_write()
896 count = min(count, port->bulk_out_size-2); in digi_write()
900 /* there are races on the port private buffer */ in digi_write()
901 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_write()
904 if (priv->dp_write_urb_in_use) { in digi_write()
906 if (count == 1 && priv->dp_out_buf_len < DIGI_OUT_BUF_SIZE) { in digi_write()
907 priv->dp_out_buf[priv->dp_out_buf_len++] = *buf; in digi_write()
912 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_write()
917 /* transfer buffer size - 2 (for command and length bytes) */ in digi_write()
918 new_len = min(count, port->bulk_out_size-2-priv->dp_out_buf_len); in digi_write()
919 data_len = new_len + priv->dp_out_buf_len; in digi_write()
922 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_write()
926 port->write_urb->transfer_buffer_length = data_len+2; in digi_write()
932 memcpy(data, priv->dp_out_buf, priv->dp_out_buf_len); in digi_write()
933 data += priv->dp_out_buf_len; in digi_write()
938 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); in digi_write()
940 priv->dp_write_urb_in_use = 1; in digi_write()
942 priv->dp_out_buf_len = 0; in digi_write()
946 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_write()
948 dev_err_console(port, in digi_write()
949 "%s: usb_submit_urb failed, ret=%d, port=%d\n", in digi_write()
950 __func__, ret, priv->dp_port_num); in digi_write()
951 dev_dbg(&port->dev, "digi_write: returning %d\n", ret); in digi_write()
959 struct usb_serial_port *port = urb->context; in digi_write_bulk_callback() local
965 int status = urb->status; in digi_write_bulk_callback()
968 /* port and serial sanity check */ in digi_write_bulk_callback()
969 if (port == NULL || (priv = usb_get_serial_port_data(port)) == NULL) { in digi_write_bulk_callback()
970 pr_err("%s: port or port->private is NULL, status=%d\n", in digi_write_bulk_callback()
974 serial = port->serial; in digi_write_bulk_callback()
976 dev_err(&port->dev, in digi_write_bulk_callback()
977 "%s: serial or serial->private is NULL, status=%d\n", in digi_write_bulk_callback()
983 if (priv->dp_port_num == serial_priv->ds_oob_port_num) { in digi_write_bulk_callback()
984 dev_dbg(&port->dev, "digi_write_bulk_callback: oob callback\n"); in digi_write_bulk_callback()
985 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_write_bulk_callback()
986 priv->dp_write_urb_in_use = 0; in digi_write_bulk_callback()
987 wake_up_interruptible(&priv->write_wait); in digi_write_bulk_callback()
988 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_write_bulk_callback()
992 /* try to send any buffered data on this port */ in digi_write_bulk_callback()
994 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_write_bulk_callback()
995 priv->dp_write_urb_in_use = 0; in digi_write_bulk_callback()
996 if (priv->dp_out_buf_len > 0) { in digi_write_bulk_callback()
997 *((unsigned char *)(port->write_urb->transfer_buffer)) in digi_write_bulk_callback()
999 *((unsigned char *)(port->write_urb->transfer_buffer) + 1) in digi_write_bulk_callback()
1000 = (unsigned char)priv->dp_out_buf_len; in digi_write_bulk_callback()
1001 port->write_urb->transfer_buffer_length = in digi_write_bulk_callback()
1002 priv->dp_out_buf_len + 2; in digi_write_bulk_callback()
1003 memcpy(port->write_urb->transfer_buffer + 2, priv->dp_out_buf, in digi_write_bulk_callback()
1004 priv->dp_out_buf_len); in digi_write_bulk_callback()
1005 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC); in digi_write_bulk_callback()
1007 priv->dp_write_urb_in_use = 1; in digi_write_bulk_callback()
1008 priv->dp_out_buf_len = 0; in digi_write_bulk_callback()
1012 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_write_bulk_callback()
1014 if (ret && ret != -EPERM) in digi_write_bulk_callback()
1015 dev_err_console(port, in digi_write_bulk_callback()
1016 "%s: usb_submit_urb failed, ret=%d, port=%d\n", in digi_write_bulk_callback()
1017 __func__, ret, priv->dp_port_num); in digi_write_bulk_callback()
1020 tty_port_tty_wakeup(&port->port); in digi_write_bulk_callback()
1025 struct usb_serial_port *port = tty->driver_data; in digi_write_room() local
1026 struct digi_port *priv = usb_get_serial_port_data(port); in digi_write_room()
1030 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_write_room()
1032 if (priv->dp_write_urb_in_use) in digi_write_room()
1035 room = port->bulk_out_size - 2 - priv->dp_out_buf_len; in digi_write_room()
1037 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_write_room()
1038 dev_dbg(&port->dev, "digi_write_room: port=%d, room=%u\n", priv->dp_port_num, room); in digi_write_room()
1045 struct usb_serial_port *port = tty->driver_data; in digi_chars_in_buffer() local
1046 struct digi_port *priv = usb_get_serial_port_data(port); in digi_chars_in_buffer()
1050 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_chars_in_buffer()
1051 if (priv->dp_write_urb_in_use) in digi_chars_in_buffer()
1052 chars = port->bulk_out_size - 2; in digi_chars_in_buffer()
1054 chars = priv->dp_out_buf_len; in digi_chars_in_buffer()
1055 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_chars_in_buffer()
1057 dev_dbg(&port->dev, "%s: port=%d, chars=%d\n", __func__, in digi_chars_in_buffer()
1058 priv->dp_port_num, chars); in digi_chars_in_buffer()
1062 static void digi_dtr_rts(struct usb_serial_port *port, int on) in digi_dtr_rts() argument
1065 digi_set_modem_signals(port, on * (TIOCM_DTR | TIOCM_RTS), 1); in digi_dtr_rts()
1068 static int digi_open(struct tty_struct *tty, struct usb_serial_port *port) in digi_open() argument
1072 struct digi_port *priv = usb_get_serial_port_data(port); in digi_open()
1076 if (digi_startup_device(port->serial) != 0) in digi_open()
1077 return -ENXIO; in digi_open()
1081 buf[1] = priv->dp_port_num; in digi_open()
1082 buf[2] = DIGI_ENABLE; in digi_open()
1087 buf[5] = priv->dp_port_num; in digi_open()
1091 ret = digi_write_oob_command(port, buf, 8, 1); in digi_open()
1093 dev_dbg(&port->dev, "digi_open: write oob failed, ret=%d\n", ret); in digi_open()
1097 not_termios.c_cflag = ~tty->termios.c_cflag; in digi_open()
1098 not_termios.c_iflag = ~tty->termios.c_iflag; in digi_open()
1099 digi_set_termios(tty, port, &not_termios); in digi_open()
1105 static void digi_close(struct usb_serial_port *port) in digi_close() argument
1110 struct digi_port *priv = usb_get_serial_port_data(port); in digi_close()
1112 mutex_lock(&port->serial->disc_mutex); in digi_close()
1114 if (port->serial->disconnected) in digi_close()
1118 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); in digi_close()
1122 buf[1] = priv->dp_port_num; in digi_close()
1123 buf[2] = DIGI_DISABLE; in digi_close()
1128 buf[5] = priv->dp_port_num; in digi_close()
1134 buf[9] = priv->dp_port_num; in digi_close()
1140 buf[13] = priv->dp_port_num; in digi_close()
1146 buf[17] = priv->dp_port_num; in digi_close()
1150 ret = digi_write_oob_command(port, buf, 20, 0); in digi_close()
1152 dev_dbg(&port->dev, "digi_close: write oob failed, ret=%d\n", in digi_close()
1154 /* wait for final commands on oob port to complete */ in digi_close()
1155 prepare_to_wait(&priv->dp_flush_wait, &wait, in digi_close()
1158 finish_wait(&priv->dp_flush_wait, &wait); in digi_close()
1161 usb_kill_urb(port->write_urb); in digi_close()
1163 spin_lock_irq(&priv->dp_port_lock); in digi_close()
1164 priv->dp_write_urb_in_use = 0; in digi_close()
1165 wake_up_interruptible(&priv->dp_close_wait); in digi_close()
1166 spin_unlock_irq(&priv->dp_port_lock); in digi_close()
1167 mutex_unlock(&port->serial->disc_mutex); in digi_close()
1175 * urbs initialized. Returns 0 if successful, non-zero error otherwise.
1182 struct usb_serial_port *port; in digi_startup_device() local
1185 spin_lock(&serial_priv->ds_serial_lock); in digi_startup_device()
1186 if (serial_priv->ds_device_started) { in digi_startup_device()
1187 spin_unlock(&serial_priv->ds_serial_lock); in digi_startup_device()
1190 serial_priv->ds_device_started = 1; in digi_startup_device()
1191 spin_unlock(&serial_priv->ds_serial_lock); in digi_startup_device()
1195 for (i = 0; i < serial->type->num_ports + 1; i++) { in digi_startup_device()
1196 port = serial->port[i]; in digi_startup_device()
1197 ret = usb_submit_urb(port->read_urb, GFP_KERNEL); in digi_startup_device()
1199 dev_err(&port->dev, in digi_startup_device()
1200 "%s: usb_submit_urb failed, ret=%d, port=%d\n", in digi_startup_device()
1208 static int digi_port_init(struct usb_serial_port *port, unsigned port_num) in digi_port_init() argument
1214 return -ENOMEM; in digi_port_init()
1216 spin_lock_init(&priv->dp_port_lock); in digi_port_init()
1217 priv->dp_port_num = port_num; in digi_port_init()
1218 init_waitqueue_head(&priv->dp_transmit_idle_wait); in digi_port_init()
1219 init_waitqueue_head(&priv->dp_flush_wait); in digi_port_init()
1220 init_waitqueue_head(&priv->dp_close_wait); in digi_port_init()
1221 init_waitqueue_head(&priv->write_wait); in digi_port_init()
1222 priv->dp_port = port; in digi_port_init()
1224 usb_set_serial_port_data(port, priv); in digi_port_init()
1236 return -ENOMEM; in digi_startup()
1238 spin_lock_init(&serial_priv->ds_serial_lock); in digi_startup()
1239 serial_priv->ds_oob_port_num = serial->type->num_ports; in digi_startup()
1240 serial_priv->ds_oob_port = serial->port[serial_priv->ds_oob_port_num]; in digi_startup()
1242 ret = digi_port_init(serial_priv->ds_oob_port, in digi_startup()
1243 serial_priv->ds_oob_port_num); in digi_startup()
1260 for (i = 0; i < serial->type->num_ports + 1; i++) { in digi_disconnect()
1261 usb_kill_urb(serial->port[i]->read_urb); in digi_disconnect()
1262 usb_kill_urb(serial->port[i]->write_urb); in digi_disconnect()
1274 priv = usb_get_serial_port_data(serial_priv->ds_oob_port); in digi_release()
1280 static int digi_port_probe(struct usb_serial_port *port) in digi_port_probe() argument
1282 return digi_port_init(port, port->port_number); in digi_port_probe()
1285 static void digi_port_remove(struct usb_serial_port *port) in digi_port_remove() argument
1289 priv = usb_get_serial_port_data(port); in digi_port_remove()
1295 struct usb_serial_port *port = urb->context; in digi_read_bulk_callback() local
1299 int status = urb->status; in digi_read_bulk_callback()
1301 /* port sanity check, do not resubmit if port is not valid */ in digi_read_bulk_callback()
1302 if (port == NULL) in digi_read_bulk_callback()
1304 priv = usb_get_serial_port_data(port); in digi_read_bulk_callback()
1306 dev_err(&port->dev, "%s: port->private is NULL, status=%d\n", in digi_read_bulk_callback()
1310 if (port->serial == NULL || in digi_read_bulk_callback()
1311 (serial_priv = usb_get_serial_data(port->serial)) == NULL) { in digi_read_bulk_callback()
1312 dev_err(&port->dev, "%s: serial is bad or serial->private " in digi_read_bulk_callback()
1319 dev_err(&port->dev, in digi_read_bulk_callback()
1320 "%s: nonzero read bulk status: status=%d, port=%d\n", in digi_read_bulk_callback()
1321 __func__, status, priv->dp_port_num); in digi_read_bulk_callback()
1326 if (priv->dp_port_num == serial_priv->ds_oob_port_num) { in digi_read_bulk_callback()
1336 if (ret != 0 && ret != -EPERM) { in digi_read_bulk_callback()
1337 dev_err(&port->dev, in digi_read_bulk_callback()
1338 "%s: failed resubmitting urb, ret=%d, port=%d\n", in digi_read_bulk_callback()
1339 __func__, ret, priv->dp_port_num); in digi_read_bulk_callback()
1348 * the data on to the tty subsystem. When called we know port and
1349 * port->private are not NULL and port->serial has been validated.
1350 * It returns 0 if successful, 1 if successful but the port is
1351 * throttled, and -1 if the sanity checks failed.
1356 struct usb_serial_port *port = urb->context; in digi_read_inb_callback() local
1357 struct digi_port *priv = usb_get_serial_port_data(port); in digi_read_inb_callback()
1358 unsigned char *buf = urb->transfer_buffer; in digi_read_inb_callback()
1367 if (urb->actual_length < 2) { in digi_read_inb_callback()
1368 dev_warn(&port->dev, "short packet received\n"); in digi_read_inb_callback()
1369 return -1; in digi_read_inb_callback()
1375 if (urb->actual_length != len + 2) { in digi_read_inb_callback()
1376 dev_err(&port->dev, "malformed packet received: port=%d, opcode=%d, len=%d, actual_length=%u\n", in digi_read_inb_callback()
1377 priv->dp_port_num, opcode, len, urb->actual_length); in digi_read_inb_callback()
1378 return -1; in digi_read_inb_callback()
1382 dev_err(&port->dev, "malformed data packet received\n"); in digi_read_inb_callback()
1383 return -1; in digi_read_inb_callback()
1386 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_read_inb_callback()
1390 throttled = priv->dp_throttled; in digi_read_inb_callback()
1392 priv->dp_throttle_restart = 1; in digi_read_inb_callback()
1396 port_status = buf[2]; in digi_read_inb_callback()
1404 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); in digi_read_inb_callback()
1415 /* data length is len-1 (one byte of len is port_status) */ in digi_read_inb_callback()
1416 --len; in digi_read_inb_callback()
1418 tty_insert_flip_string_fixed_flag(&port->port, data, in digi_read_inb_callback()
1420 tty_flip_buffer_push(&port->port); in digi_read_inb_callback()
1423 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_read_inb_callback()
1426 dev_dbg(&port->dev, "%s: got RECEIVE_DISABLE\n", __func__); in digi_read_inb_callback()
1428 dev_dbg(&port->dev, "%s: unknown opcode: %d\n", __func__, opcode); in digi_read_inb_callback()
1438 * Digi Read OOB Callback handles reads on the out of band port.
1439 * When called we know port and port->private are not NULL and
1440 * the port->serial is valid. It returns 0 if successful, and
1441 * -1 if the sanity checks failed.
1447 struct usb_serial_port *port = urb->context; in digi_read_oob_callback() local
1448 struct usb_serial *serial = port->serial; in digi_read_oob_callback()
1451 unsigned char *buf = urb->transfer_buffer; in digi_read_oob_callback()
1457 if (urb->actual_length < 4) in digi_read_oob_callback()
1458 return -1; in digi_read_oob_callback()
1461 for (i = 0; i < urb->actual_length - 3; i += 4) { in digi_read_oob_callback()
1464 status = buf[i + 2]; in digi_read_oob_callback()
1467 dev_dbg(&port->dev, "digi_read_oob_callback: opcode=%d, line=%d, status=%d, val=%d\n", in digi_read_oob_callback()
1470 if (status != 0 || line >= serial->type->num_ports) in digi_read_oob_callback()
1473 port = serial->port[line]; in digi_read_oob_callback()
1475 priv = usb_get_serial_port_data(port); in digi_read_oob_callback()
1477 return -1; in digi_read_oob_callback()
1479 tty = tty_port_tty_get(&port->port); in digi_read_oob_callback()
1488 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_read_oob_callback()
1491 priv->dp_modem_signals |= TIOCM_CTS; in digi_read_oob_callback()
1495 priv->dp_modem_signals &= ~TIOCM_CTS; in digi_read_oob_callback()
1496 /* port must be open to use tty struct */ in digi_read_oob_callback()
1499 priv->dp_modem_signals |= TIOCM_DSR; in digi_read_oob_callback()
1501 priv->dp_modem_signals &= ~TIOCM_DSR; in digi_read_oob_callback()
1503 priv->dp_modem_signals |= TIOCM_RI; in digi_read_oob_callback()
1505 priv->dp_modem_signals &= ~TIOCM_RI; in digi_read_oob_callback()
1507 priv->dp_modem_signals |= TIOCM_CD; in digi_read_oob_callback()
1509 priv->dp_modem_signals &= ~TIOCM_CD; in digi_read_oob_callback()
1511 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_read_oob_callback()
1514 tty_port_tty_wakeup(&port->port); in digi_read_oob_callback()
1516 spin_lock_irqsave(&priv->dp_port_lock, flags); in digi_read_oob_callback()
1517 priv->dp_transmit_idle = 1; in digi_read_oob_callback()
1518 wake_up_interruptible(&priv->dp_transmit_idle_wait); in digi_read_oob_callback()
1519 spin_unlock_irqrestore(&priv->dp_port_lock, flags); in digi_read_oob_callback()
1521 wake_up_interruptible(&priv->dp_flush_wait); in digi_read_oob_callback()