^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * USB Keyspan PDA / Xircom / Entrega Converter driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1999 - 2001 Greg Kroah-Hartman <greg@kroah.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1999, 2000 Brian Warner <warner@lothar.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2000 Al Borchers <borchers@steinerpoint.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * See Documentation/usb/usb-serial.rst for more information on using this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/tty.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/tty_driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/tty_flip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/usb/serial.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/usb/ezusb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* make a simple define to handle if we are compiling keyspan_pda or xircom support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #if IS_ENABLED(CONFIG_USB_SERIAL_KEYSPAN_PDA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define KEYSPAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #undef KEYSPAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #if IS_ENABLED(CONFIG_USB_SERIAL_XIRCOM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define XIRCOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #undef XIRCOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DRIVER_AUTHOR "Brian Warner <warner@lothar.com>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define DRIVER_DESC "USB Keyspan PDA Converter driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define KEYSPAN_TX_THRESHOLD 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct keyspan_pda_private {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int tx_room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int tx_throttled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct work_struct unthrottle_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct usb_serial *serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct usb_serial_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define KEYSPAN_VENDOR_ID 0x06cd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define KEYSPAN_PDA_FAKE_ID 0x0103
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define KEYSPAN_PDA_ID 0x0104 /* no clue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* For Xircom PGSDB9 and older Entrega version of the same device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define XIRCOM_VENDOR_ID 0x085a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define XIRCOM_FAKE_ID 0x8027
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define XIRCOM_FAKE_ID_2 0x8025 /* "PGMFHUB" serial */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define ENTREGA_VENDOR_ID 0x1645
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define ENTREGA_FAKE_ID 0x8093
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static const struct usb_device_id id_table_combined[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #ifdef KEYSPAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #ifdef XIRCOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) { USB_DEVICE(ENTREGA_VENDOR_ID, ENTREGA_FAKE_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) MODULE_DEVICE_TABLE(usb, id_table_combined);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static const struct usb_device_id id_table_std[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #ifdef KEYSPAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static const struct usb_device_id id_table_fake[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) { } /* Terminating entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #ifdef XIRCOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static const struct usb_device_id id_table_fake_xircom[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID_2) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) { USB_DEVICE(ENTREGA_VENDOR_ID, ENTREGA_FAKE_ID) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static void keyspan_pda_request_unthrottle(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct keyspan_pda_private *priv =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) container_of(work, struct keyspan_pda_private, unthrottle_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct usb_serial *serial = priv->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* ask the device to tell us when the tx buffer becomes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) sufficiently empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) result = usb_control_msg(serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 7, /* request_unthrottle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) USB_TYPE_VENDOR | USB_RECIP_INTERFACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) KEYSPAN_TX_THRESHOLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 0, /* index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) dev_dbg(&serial->dev->dev, "%s - error %d from usb_control_msg\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) __func__, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void keyspan_pda_rx_interrupt(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct usb_serial_port *port = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned char *data = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) unsigned int len = urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int status = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct keyspan_pda_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) case -ECONNRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) case -ESHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* this urb is terminated, clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __func__, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (len < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) dev_warn(&port->dev, "short message received\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* see if the message is data or a status interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) switch (data[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* rest of message is rx data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (len < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) tty_insert_flip_string(&port->port, data + 1, len - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) tty_flip_buffer_push(&port->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* status interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (len < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) dev_warn(&port->dev, "short interrupt message received\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) dev_dbg(&port->dev, "rx int, d1=%d\n", data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) switch (data[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) case 1: /* modemline change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) case 2: /* tx unthrottle interrupt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) spin_lock_irqsave(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) priv->tx_throttled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) priv->tx_room = max(priv->tx_room, KEYSPAN_TX_THRESHOLD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) spin_unlock_irqrestore(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* queue up a wakeup at scheduler time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) usb_serial_port_softint(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) retval = usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) dev_err(&port->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) "%s - usb_submit_urb failed with result %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) __func__, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void keyspan_pda_rx_throttle(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* stop receiving characters. We just turn off the URB request, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) let chars pile up in the device. If we're doing hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) flowcontrol, the device will signal the other end when its buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) fills up. If we're doing XON/XOFF, this would be a good time to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) send an XOFF, although it might make sense to foist that off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) upon the device too. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) usb_kill_urb(port->interrupt_in_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* just restart the receive interrupt URB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) dev_dbg(&port->dev, "usb_submit_urb(read urb) failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int bindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) switch (baud) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) case 110:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) bindex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) case 300:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) bindex = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) case 1200:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) bindex = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) case 2400:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) bindex = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case 4800:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) bindex = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) case 9600:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) bindex = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) case 19200:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) bindex = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) case 38400:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) bindex = 7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) case 57600:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) bindex = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) case 115200:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) bindex = 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) bindex = 5; /* Default to 9600 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) baud = 9600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* rather than figure out how to sleep while waiting for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) to complete, I just use the "legacy" API. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 0, /* set baud */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) USB_TYPE_VENDOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) | USB_RECIP_INTERFACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) | USB_DIR_OUT, /* type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) bindex, /* value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 0, /* index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) NULL, /* &data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 0, /* size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 2000); /* timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return baud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (break_state == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) value = 1; /* start break */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) value = 0; /* clear break */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 4, /* set break */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) value, 0, NULL, 0, 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) dev_dbg(&port->dev, "%s - error %d from usb_control_msg\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) __func__, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /* there is something funky about this.. the TCSBRK that 'cu' performs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) seconds apart, but it feels like the break sent isn't as long as it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) is on /dev/ttyS0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) static void keyspan_pda_set_termios(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct usb_serial_port *port, struct ktermios *old_termios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) speed_t speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /* cflag specifies lots of stuff: number of stop bits, parity, number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) of data bits, baud. What can the device actually handle?:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) CSTOPB (1 stop bit or 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) PARENB (parity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) CSIZE (5bit .. 8bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) There is minimal hw support for parity (a PSW bit seems to hold the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) parity of whatever is in the accumulator). The UART either deals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) with 10 bits (start, 8 data, stop) or 11 bits (start, 8 data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 1 special, stop). So, with firmware changes, we could do:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 8N1: 10 bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 8N2: 11 bit, extra bit always (mark?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 8[EOMS]1: 11 bit, extra bit is parity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 7[EOMS]1: 10 bit, b0/b7 is parity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 7[EOMS]2: 11 bit, b0/b7 is parity, extra bit always (mark?)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) HW flow control is dictated by the tty->termios.c_cflags & CRTSCTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) For now, just do baud. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) speed = tty_get_baud_rate(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) speed = keyspan_pda_setbaud(serial, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (speed == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) dev_dbg(&port->dev, "can't handle requested baud rate\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /* It hasn't changed so.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) speed = tty_termios_baud_rate(old_termios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /* Only speed can change so copy the old h/w parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) then encode the new speed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) tty_termios_copy_hw(&tty->termios, old_termios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) tty_encode_baud_rate(tty, speed, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* modem control pins: DTR and RTS are outputs and can be controlled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) DCD, RI, DSR, CTS are inputs and can be read. All outputs can also be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) read. The byte passed is: DTR(b7) DCD RI DSR CTS RTS(b2) unused unused */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) static int keyspan_pda_get_modem_info(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) unsigned char *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) u8 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) data = kmalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 3, /* get pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 0, 0, data, 1, 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (rc == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) *value = *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) else if (rc >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static int keyspan_pda_set_modem_info(struct usb_serial *serial,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) unsigned char value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 3, /* set pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) value, 0, NULL, 0, 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static int keyspan_pda_tiocmget(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) rc = keyspan_pda_get_modem_info(serial, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) value =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ((status & (1<<7)) ? TIOCM_DTR : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) ((status & (1<<6)) ? TIOCM_CAR : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) ((status & (1<<5)) ? TIOCM_RNG : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) ((status & (1<<4)) ? TIOCM_DSR : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ((status & (1<<3)) ? TIOCM_CTS : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) ((status & (1<<2)) ? TIOCM_RTS : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) return value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static int keyspan_pda_tiocmset(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) unsigned int set, unsigned int clear)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) rc = keyspan_pda_get_modem_info(serial, &status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (set & TIOCM_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) status |= (1<<2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) if (set & TIOCM_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) status |= (1<<7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (clear & TIOCM_RTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) status &= ~(1<<2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (clear & TIOCM_DTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) status &= ~(1<<7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) rc = keyspan_pda_set_modem_info(serial, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static int keyspan_pda_write(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct usb_serial_port *port, const unsigned char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) int request_unthrottle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct keyspan_pda_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* guess how much room is left in the device's ring buffer, and if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) want to send more than that, check first, updating our notion of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) what is left. If our write will result in no room left, ask the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) device to give us an interrupt when the room available rises above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) a threshold, and hold off all writers (eventually, those using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) select() or poll() too) until we receive that unthrottle interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) Block if we can't write anything at all, otherwise write as much as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) we can. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (count == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) dev_dbg(&port->dev, "write request of 0 bytes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /* we might block because of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) the TX urb is in-flight (wait until it completes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) the device is full (wait until it says there is room)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) spin_lock_irqsave(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) spin_unlock_irqrestore(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) clear_bit(0, &port->write_urbs_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) spin_unlock_irqrestore(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /* At this point the URB is in our control, nobody else can submit it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) again (the only sudden transition was the one from EINPROGRESS to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) finished). Also, the tx process is not throttled. So we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) ready to write. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* Check if we might overrun the Tx buffer. If so, ask the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) device how much room it really has. This is done only on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) scheduler time, since usb_control_msg() sleeps. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (count > priv->tx_room && !in_interrupt()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) u8 *room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) room = kmalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (!room) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) rc = usb_control_msg(serial->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 6, /* write_room */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) USB_TYPE_VENDOR | USB_RECIP_INTERFACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 0, /* value: 0 means "remaining room" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 0, /* index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (rc > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) dev_dbg(&port->dev, "roomquery says %d\n", *room);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) priv->tx_room = *room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) kfree(room);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) dev_dbg(&port->dev, "roomquery failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) dev_dbg(&port->dev, "roomquery returned 0 bytes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) rc = -EIO; /* device didn't return any data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (count >= priv->tx_room) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) /* we're about to completely fill the Tx buffer, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) we'll be throttled afterwards. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) count = priv->tx_room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) request_unthrottle = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /* now transfer data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) memcpy(port->write_urb->transfer_buffer, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /* send the data out the bulk port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) port->write_urb->transfer_buffer_length = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) priv->tx_room -= count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) rc = usb_submit_urb(port->write_urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /* There wasn't any room left, so we are throttled until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) the buffer empties a bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) request_unthrottle = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (request_unthrottle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) priv->tx_throttled = 1; /* block writers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) schedule_work(&priv->unthrottle_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (rc <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) set_bit(0, &port->write_urbs_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static void keyspan_pda_write_bulk_callback(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct usb_serial_port *port = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) set_bit(0, &port->write_urbs_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) /* queue up a wakeup at scheduler time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) usb_serial_port_softint(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static int keyspan_pda_write_room(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) struct keyspan_pda_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) int room = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) spin_lock_irqsave(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (test_bit(0, &port->write_urbs_free) && !priv->tx_throttled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) room = priv->tx_room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) spin_unlock_irqrestore(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) return room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static int keyspan_pda_chars_in_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct usb_serial_port *port = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct keyspan_pda_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) /* when throttled, return at least WAKEUP_CHARS to tell select() (via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) n_tty.c:normal_poll() ) that we're not writeable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) spin_lock_irqsave(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) ret = 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) spin_unlock_irqrestore(&port->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) keyspan_pda_set_modem_info(serial, (1 << 7) | (1 << 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) keyspan_pda_set_modem_info(serial, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) static int keyspan_pda_open(struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct usb_serial *serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) u8 *room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct keyspan_pda_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /* find out how much room is in the Tx ring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) room = kmalloc(1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (!room)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 6, /* write_room */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) USB_TYPE_VENDOR | USB_RECIP_INTERFACE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 0, /* value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 0, /* index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 2000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) dev_dbg(&port->dev, "%s - roomquery failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) dev_dbg(&port->dev, "%s - roomquery returned 0 bytes\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) priv->tx_room = *room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) priv->tx_throttled = *room ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) /*Start reading from the device*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) kfree(room);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static void keyspan_pda_close(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct keyspan_pda_private *priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) usb_kill_urb(port->write_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) usb_kill_urb(port->interrupt_in_urb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) cancel_work_sync(&priv->unthrottle_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* download the firmware to a "fake" device (pre-renumeration) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int keyspan_pda_fake_startup(struct usb_serial *serial)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) const char *fw_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /* download the firmware here ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) ezusb_fx1_set_reset(serial->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (0) { ; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) #ifdef KEYSPAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) else if (le16_to_cpu(serial->dev->descriptor.idVendor) == KEYSPAN_VENDOR_ID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) fw_name = "keyspan_pda/keyspan_pda.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) #ifdef XIRCOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) else if ((le16_to_cpu(serial->dev->descriptor.idVendor) == XIRCOM_VENDOR_ID) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) (le16_to_cpu(serial->dev->descriptor.idVendor) == ENTREGA_VENDOR_ID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) fw_name = "keyspan_pda/xircom_pgs.fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) dev_err(&serial->dev->dev, "%s: unknown vendor, aborting.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) fw_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* after downloading firmware Renumeration will occur in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) moment and the new device will bind to the real driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /* we want this device to fail to have a driver assigned to it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) #ifdef KEYSPAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) MODULE_FIRMWARE("keyspan_pda/keyspan_pda.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) #ifdef XIRCOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static int keyspan_pda_port_probe(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) struct keyspan_pda_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (!priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) priv->serial = port->serial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) priv->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) usb_set_serial_port_data(port, priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) static int keyspan_pda_port_remove(struct usb_serial_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) struct keyspan_pda_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) priv = usb_get_serial_port_data(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) kfree(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) #ifdef KEYSPAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) static struct usb_serial_driver keyspan_pda_fake_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) .name = "keyspan_pda_pre",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) .description = "Keyspan PDA - (prerenumeration)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) .id_table = id_table_fake,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) .num_ports = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) .attach = keyspan_pda_fake_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) #ifdef XIRCOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static struct usb_serial_driver xircom_pgs_fake_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .name = "xircom_no_firm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) .description = "Xircom / Entrega PGS - (prerenumeration)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) .id_table = id_table_fake_xircom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) .num_ports = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) .attach = keyspan_pda_fake_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) static struct usb_serial_driver keyspan_pda_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) .name = "keyspan_pda",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) .description = "Keyspan PDA",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) .id_table = id_table_std,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) .num_ports = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) .num_bulk_out = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) .num_interrupt_in = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) .dtr_rts = keyspan_pda_dtr_rts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) .open = keyspan_pda_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) .close = keyspan_pda_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) .write = keyspan_pda_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) .write_room = keyspan_pda_write_room,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) .write_bulk_callback = keyspan_pda_write_bulk_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) .read_int_callback = keyspan_pda_rx_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) .chars_in_buffer = keyspan_pda_chars_in_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) .throttle = keyspan_pda_rx_throttle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) .unthrottle = keyspan_pda_rx_unthrottle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) .set_termios = keyspan_pda_set_termios,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) .break_ctl = keyspan_pda_break_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) .tiocmget = keyspan_pda_tiocmget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) .tiocmset = keyspan_pda_tiocmset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) .port_probe = keyspan_pda_port_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) .port_remove = keyspan_pda_port_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) static struct usb_serial_driver * const serial_drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) &keyspan_pda_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) #ifdef KEYSPAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) &keyspan_pda_fake_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) #ifdef XIRCOM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) &xircom_pgs_fake_device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) module_usb_serial_driver(serial_drivers, id_table_combined);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) MODULE_AUTHOR(DRIVER_AUTHOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) MODULE_LICENSE("GPL");