18 #include <linux/kernel.h>
19 #include <linux/errno.h>
21 #include <linux/slab.h>
22 #include <linux/tty.h>
25 #include <linux/module.h>
34 #if defined(CONFIG_USB_SERIAL_KEYSPAN_PDA) || defined(CONFIG_USB_SERIAL_KEYSPAN_PDA_MODULE)
39 #if defined(CONFIG_USB_SERIAL_XIRCOM) || defined(CONFIG_USB_SERIAL_XIRCOM_MODULE)
48 #define DRIVER_VERSION "v1.1"
50 #define DRIVER_DESC "USB Keyspan PDA Converter driver"
62 #define KEYSPAN_VENDOR_ID 0x06cd
63 #define KEYSPAN_PDA_FAKE_ID 0x0103
64 #define KEYSPAN_PDA_ID 0x0104
67 #define XIRCOM_VENDOR_ID 0x085a
68 #define XIRCOM_FAKE_ID 0x8027
69 #define ENTREGRA_VENDOR_ID 0x1645
70 #define ENTREGRA_FAKE_ID 0x8093
117 static void keyspan_pda_request_unthrottle(
struct work_struct *work)
127 usb_sndctrlpipe(serial->
dev, 0),
137 dev_dbg(&serial->
dev->dev,
"%s - error %d from usb_control_msg\n",
142 static void keyspan_pda_rx_interrupt(
struct urb *
urb)
146 unsigned char *
data = urb->transfer_buffer;
150 priv = usb_get_serial_port_data(port);
160 dev_dbg(&urb->dev->dev,
"%s - urb shutting down with status: %d\n", __func__, status);
163 dev_dbg(&urb->dev->dev,
"%s - nonzero urb status received: %d\n", __func__, status);
172 if (tty && urb->actual_length) {
173 tty_insert_flip_string(tty, data + 1,
174 urb->actual_length - 1);
181 dev_dbg(&port->
dev,
"rx int, d1=%d, d2=%d\n", data[1], data[2]);
202 "%s - usb_submit_urb failed with result %d",
207 static void keyspan_pda_rx_throttle(
struct tty_struct *tty)
221 static void keyspan_pda_rx_unthrottle(
struct tty_struct *tty)
227 dev_dbg(&port->
dev,
"usb_submit_urb(read urb) failed\n");
290 static void keyspan_pda_break_ctl(
struct tty_struct *tty,
int break_state)
297 if (break_state == -1)
304 value, 0,
NULL, 0, 2000);
306 dev_dbg(&port->
dev,
"%s - error %d from usb_control_msg\n",
315 static void keyspan_pda_set_termios(
struct tty_struct *tty,
342 speed = keyspan_pda_setbaud(serial, speed);
345 dev_dbg(&port->
dev,
"can't handle requested baud rate\n");
360 static int keyspan_pda_get_modem_info(
struct usb_serial *serial,
361 unsigned char *value)
373 0, 0, data, 1, 2000);
382 static int keyspan_pda_set_modem_info(
struct usb_serial *serial,
389 value, 0,
NULL, 0, 2000);
393 static int keyspan_pda_tiocmget(
struct tty_struct *tty)
401 rc = keyspan_pda_get_modem_info(serial, &status);
414 static int keyspan_pda_tiocmset(
struct tty_struct *tty,
415 unsigned int set,
unsigned int clear)
422 rc = keyspan_pda_get_modem_info(serial, &status);
435 rc = keyspan_pda_set_modem_info(serial, status);
439 static int keyspan_pda_write(
struct tty_struct *tty,
443 int request_unthrottle = 0;
447 priv = usb_get_serial_port_data(port);
457 dev_dbg(&port->
dev,
"write request of 0 bytes\n");
465 spin_lock_bh(&port->
lock);
467 spin_unlock_bh(&port->
lock);
471 spin_unlock_bh(&port->
lock);
493 usb_rcvctrlpipe(serial->
dev, 0),
503 dev_dbg(&port->
dev,
"roomquery says %d\n", *room);
512 dev_dbg(&port->
dev,
"roomquery returned 0 bytes\n");
521 request_unthrottle = 1;
534 dev_dbg(&port->
dev,
"usb_submit_urb(write bulk) failed\n");
540 request_unthrottle = 1;
543 if (request_unthrottle) {
556 static void keyspan_pda_write_bulk_callback(
struct urb *urb)
562 priv = usb_get_serial_port_data(port);
569 static int keyspan_pda_write_room(
struct tty_struct *tty)
573 priv = usb_get_serial_port_data(port);
581 static int keyspan_pda_chars_in_buffer(
struct tty_struct *tty)
588 priv = usb_get_serial_port_data(port);
596 spin_unlock_irqrestore(&port->
lock, flags);
607 keyspan_pda_set_modem_info(serial, (1<<7) | (1<< 2));
609 keyspan_pda_set_modem_info(serial, 0);
614 static int keyspan_pda_open(
struct tty_struct *tty,
637 dev_dbg(&port->
dev,
"%s - roomquery failed\n", __func__);
641 dev_dbg(&port->
dev,
"%s - roomquery returned 0 bytes\n", __func__);
645 priv = usb_get_serial_port_data(port);
652 dev_dbg(&port->
dev,
"%s - usb_submit_urb(read int) failed\n", __func__);
672 static int keyspan_pda_fake_startup(
struct usb_serial *serial)
683 fw_name =
"keyspan_pda/keyspan_pda.fw";
688 fw_name =
"keyspan_pda/xircom_pgs.fw";
691 dev_err(&serial->
dev->dev,
"%s: unknown vendor, aborting.\n",
697 dev_err(&serial->
dev->dev,
"failed to load firmware \"%s\"\n",
730 usb_set_serial_port_data(port, priv);
739 priv = usb_get_serial_port_data(port);
749 .name =
"keyspan_pda_pre",
751 .description =
"Keyspan PDA - (prerenumeration)",
752 .id_table = id_table_fake,
754 .attach = keyspan_pda_fake_startup,
762 .name =
"xircom_no_firm",
764 .description =
"Xircom / Entregra PGS - (prerenumeration)",
765 .id_table = id_table_fake_xircom,
767 .attach = keyspan_pda_fake_startup,
774 .name =
"keyspan_pda",
776 .description =
"Keyspan PDA",
777 .id_table = id_table_std,
779 .dtr_rts = keyspan_pda_dtr_rts,
780 .open = keyspan_pda_open,
781 .close = keyspan_pda_close,
782 .write = keyspan_pda_write,
783 .write_room = keyspan_pda_write_room,
784 .write_bulk_callback = keyspan_pda_write_bulk_callback,
785 .read_int_callback = keyspan_pda_rx_interrupt,
786 .chars_in_buffer = keyspan_pda_chars_in_buffer,
787 .throttle = keyspan_pda_rx_throttle,
788 .unthrottle = keyspan_pda_rx_unthrottle,
789 .set_termios = keyspan_pda_set_termios,
790 .break_ctl = keyspan_pda_break_ctl,
791 .tiocmget = keyspan_pda_tiocmget,
792 .tiocmset = keyspan_pda_tiocmset,
793 .port_probe = keyspan_pda_port_probe,
794 .port_remove = keyspan_pda_port_remove,
800 &keyspan_pda_fake_device,
803 &xircom_pgs_fake_device,