// SPDX-License-Identifier: GPL-2.0+ /* * USB Keyspan PDA / Xircom / Entrega Converter driver * * Copyright (C) 1999 - 2001 Greg Kroah-Hartman <greg@kroah.com> * Copyright (C) 1999, 2000 Brian Warner <warner@lothar.com> * Copyright (C) 2000 Al Borchers <borchers@steinerpoint.com> * Copyright (C) 2020 Johan Hovold <johan@kernel.org> * * See Documentation/usb/usb-serial.rst for more information on using this * driver
*/
/* For Xircom PGSDB9 and older Entrega version of the same device */ #define XIRCOM_VENDOR_ID 0x085a #define XIRCOM_FAKE_ID 0x8027 #define XIRCOM_FAKE_ID_2 0x8025 /* "PGMFHUB" serial */ #define ENTREGA_VENDOR_ID 0x1645 #define ENTREGA_FAKE_ID 0x8093
/* * Ask the device to tell us when the tx buffer becomes * sufficiently empty.
*/
result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0),
7, /* request_unthrottle */
USB_TYPE_VENDOR | USB_RECIP_INTERFACE
| USB_DIR_OUT,
KEYSPAN_TX_THRESHOLD,
0, /* index */
NULL,
0,
2000); if (result < 0)
dev_dbg(&serial->dev->dev, "%s - error %d from usb_control_msg\n",
__func__, result); /* * Need to check available space after requesting notification in case * buffer is already empty so that no notification is sent.
*/
result = keyspan_pda_get_write_room(priv); if (result > KEYSPAN_TX_THRESHOLD) {
spin_lock_irqsave(&port->lock, flags);
priv->tx_room = max(priv->tx_room, result);
spin_unlock_irqrestore(&port->lock, flags);
usb_serial_port_softint(port);
}
}
staticvoid keyspan_pda_rx_interrupt(struct urb *urb)
{ struct usb_serial_port *port = urb->context; unsignedchar *data = urb->transfer_buffer; unsignedint len = urb->actual_length; int retval; int status = urb->status; struct keyspan_pda_private *priv; unsignedlong flags;
priv = usb_get_serial_port_data(port);
switch (status) { case 0: /* success */ break; case -ECONNRESET: case -ENOENT: case -ESHUTDOWN: /* this urb is terminated, clean up */
dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status); return; default:
dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __func__, status); gotoexit;
}
/* see if the message is data or a status interrupt */ switch (data[0]) { case 0: /* rest of message is rx data */ if (len < 2) break;
tty_insert_flip_string(&port->port, data + 1, len - 1);
tty_flip_buffer_push(&port->port); break; case 1: /* status interrupt */ if (len < 2) {
dev_warn(&port->dev, "short interrupt message received\n"); break;
}
dev_dbg(&port->dev, "rx int, d1=%d\n", data[1]); switch (data[1]) { case 1: /* modemline change */ break; case 2: /* tx unthrottle interrupt */
spin_lock_irqsave(&port->lock, flags);
priv->tx_room = max(priv->tx_room, KEYSPAN_TX_THRESHOLD);
spin_unlock_irqrestore(&port->lock, flags);
/* * Stop receiving characters. We just turn off the URB request, and * let chars pile up in the device. If we're doing hardware * flowcontrol, the device will signal the other end when its buffer * fills up. If we're doing XON/XOFF, this would be a good time to * send an XOFF, although it might make sense to foist that off upon * the device too.
*/
usb_kill_urb(port->interrupt_in_urb);
}
/* * cflag specifies lots of stuff: number of stop bits, parity, number * of data bits, baud. What can the device actually handle?: * CSTOPB (1 stop bit or 2) * PARENB (parity) * CSIZE (5bit .. 8bit) * There is minimal hw support for parity (a PSW bit seems to hold the * parity of whatever is in the accumulator). The UART either deals * with 10 bits (start, 8 data, stop) or 11 bits (start, 8 data, * 1 special, stop). So, with firmware changes, we could do: * 8N1: 10 bit * 8N2: 11 bit, extra bit always (mark?) * 8[EOMS]1: 11 bit, extra bit is parity * 7[EOMS]1: 10 bit, b0/b7 is parity * 7[EOMS]2: 11 bit, b0/b7 is parity, extra bit always (mark?) * * HW flow control is dictated by the tty->termios.c_cflags & CRTSCTS * bit. * * For now, just do baud.
*/
speed = tty_get_baud_rate(tty);
speed = keyspan_pda_setbaud(serial, speed);
if (speed == 0) {
dev_dbg(&port->dev, "can't handle requested baud rate\n"); /* It hasn't changed so.. */
speed = tty_termios_baud_rate(old_termios);
} /* * Only speed can change so copy the old h/w parameters then encode * the new speed.
*/
tty_termios_copy_hw(&tty->termios, old_termios);
tty_encode_baud_rate(tty, speed, speed);
}
/* * Modem control pins: DTR and RTS are outputs and can be controlled. * DCD, RI, DSR, CTS are inputs and can be read. All outputs can also be * read. The byte passed is: DTR(b7) DCD RI DSR CTS RTS(b2) unused unused.
*/ staticint keyspan_pda_get_modem_info(struct usb_serial *serial, unsignedchar *value)
{ int rc;
u8 data;
rc = keyspan_pda_get_modem_info(serial, &status); if (rc < 0) return rc;
if (set & TIOCM_RTS)
status |= BIT(2); if (set & TIOCM_DTR)
status |= BIT(7);
if (clear & TIOCM_RTS)
status &= ~BIT(2); if (clear & TIOCM_DTR)
status &= ~BIT(7);
rc = keyspan_pda_set_modem_info(serial, status); return rc;
}
staticint keyspan_pda_write_start(struct usb_serial_port *port)
{ struct keyspan_pda_private *priv = usb_get_serial_port_data(port); unsignedlong flags; struct urb *urb; int count; int room; int rc;
/* * Guess how much room is left in the device's ring buffer. If our * write will result in no room left, ask the device to give us an * interrupt when the room available rises above a threshold but also * query how much room is currently available (in case our guess was * too conservative and the buffer is already empty when the * unthrottle work is scheduled).
*/
/* * We might block because of: * the TX urb is in-flight (wait until it completes) * the device is full (wait until it says there is room)
*/
spin_lock_irqsave(&port->lock, flags);
/* * Stop the interrupt URB first as its completion handler may submit * the write URB.
*/
usb_kill_urb(port->interrupt_in_urb);
usb_kill_urb(port->write_urb);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.