Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * KLSI KL5KUSB105 chip RS232 converter driver |
| 3 | * |
| 4 | * Copyright (C) 2001 Utz-Uwe Haus <haus@uuhaus.de> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * All information about the device was acquired using SniffUSB ans snoopUSB |
| 12 | * on Windows98. |
| 13 | * It was written out of frustration with the PalmConnect USB Serial adapter |
| 14 | * sold by Palm Inc. |
| 15 | * Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided |
| 16 | * information that was not already available. |
| 17 | * |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 18 | * It seems that KLSI bought some silicon-design information from ScanLogic, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * whose SL11R processor is at the core of the KL5KUSB chipset from KLSI. |
| 20 | * KLSI has firmware available for their devices; it is probable that the |
| 21 | * firmware differs from that used by KLSI in their products. If you have an |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 22 | * original KLSI device and can provide some information on it, I would be |
| 23 | * most interested in adding support for it here. If you have any information |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | * on the protocol used (or find errors in my reverse-engineered stuff), please |
| 25 | * let me know. |
| 26 | * |
| 27 | * The code was only tested with a PalmConnect USB adapter; if you |
| 28 | * are adventurous, try it with any KLSI-based device and let me know how it |
| 29 | * breaks so that I can fix it! |
| 30 | */ |
| 31 | |
| 32 | /* TODO: |
| 33 | * check modem line signals |
| 34 | * implement handshaking or decide that we do not support it |
| 35 | */ |
| 36 | |
| 37 | /* History: |
| 38 | * 0.3a - implemented pools of write URBs |
| 39 | * 0.3 - alpha version for public testing |
| 40 | * 0.2 - TIOCMGET works, so autopilot(1) can be used! |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 41 | * 0.1 - can be used to do pilot-xfer -p /dev/ttyUSB0 -l |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | * |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 43 | * The driver skeleton is mainly based on mct_u232.c and various other |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | * pieces of code shamelessly copied from the drivers/usb/serial/ directory. |
| 45 | */ |
| 46 | |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/kernel.h> |
| 49 | #include <linux/errno.h> |
| 50 | #include <linux/init.h> |
| 51 | #include <linux/slab.h> |
| 52 | #include <linux/tty.h> |
| 53 | #include <linux/tty_driver.h> |
| 54 | #include <linux/tty_flip.h> |
| 55 | #include <linux/module.h> |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 56 | #include <linux/uaccess.h> |
Al Viro | fd05e72 | 2008-04-28 07:00:16 +0100 | [diff] [blame] | 57 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 59 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include "kl5kusb105.h" |
| 61 | |
| 62 | static int debug; |
| 63 | |
| 64 | /* |
| 65 | * Version Information |
| 66 | */ |
| 67 | #define DRIVER_VERSION "v0.3a" |
| 68 | #define DRIVER_AUTHOR "Utz-Uwe Haus <haus@uuhaus.de>" |
| 69 | #define DRIVER_DESC "KLSI KL5KUSB105 chipset USB->Serial Converter driver" |
| 70 | |
| 71 | |
| 72 | /* |
| 73 | * Function prototypes |
| 74 | */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 75 | static int klsi_105_startup(struct usb_serial *serial); |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 76 | static void klsi_105_disconnect(struct usb_serial *serial); |
| 77 | static void klsi_105_release(struct usb_serial *serial); |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 78 | static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 79 | static void klsi_105_close(struct usb_serial_port *port); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 80 | static int klsi_105_write(struct tty_struct *tty, |
| 81 | struct usb_serial_port *port, const unsigned char *buf, int count); |
| 82 | static void klsi_105_write_bulk_callback(struct urb *urb); |
| 83 | static int klsi_105_chars_in_buffer(struct tty_struct *tty); |
| 84 | static int klsi_105_write_room(struct tty_struct *tty); |
| 85 | static void klsi_105_read_bulk_callback(struct urb *urb); |
| 86 | static void klsi_105_set_termios(struct tty_struct *tty, |
| 87 | struct usb_serial_port *port, struct ktermios *old); |
| 88 | static void klsi_105_throttle(struct tty_struct *tty); |
| 89 | static void klsi_105_unthrottle(struct tty_struct *tty); |
| 90 | static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file); |
| 91 | static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file, |
| 92 | unsigned int set, unsigned int clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * All of the device info needed for the KLSI converters. |
| 96 | */ |
| 97 | static struct usb_device_id id_table [] = { |
| 98 | { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) }, |
| 99 | { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) }, |
| 100 | { } /* Terminating entry */ |
| 101 | }; |
| 102 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 103 | MODULE_DEVICE_TABLE(usb, id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | static struct usb_driver kl5kusb105d_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | .name = "kl5kusb105d", |
| 107 | .probe = usb_serial_probe, |
| 108 | .disconnect = usb_serial_disconnect, |
| 109 | .id_table = id_table, |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 110 | .no_dynamic_id = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 113 | static struct usb_serial_driver kl5kusb105d_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 114 | .driver = { |
| 115 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 116 | .name = "kl5kusb105d", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 117 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 118 | .description = "KL5KUSB105D / PalmConnect", |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 119 | .usb_driver = &kl5kusb105d_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | .id_table = id_table, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | .num_ports = 1, |
| 122 | .open = klsi_105_open, |
| 123 | .close = klsi_105_close, |
| 124 | .write = klsi_105_write, |
| 125 | .write_bulk_callback = klsi_105_write_bulk_callback, |
| 126 | .chars_in_buffer = klsi_105_chars_in_buffer, |
| 127 | .write_room = klsi_105_write_room, |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 128 | .read_bulk_callback = klsi_105_read_bulk_callback, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | .set_termios = klsi_105_set_termios, |
| 130 | /*.break_ctl = klsi_105_break_ctl,*/ |
| 131 | .tiocmget = klsi_105_tiocmget, |
| 132 | .tiocmset = klsi_105_tiocmset, |
| 133 | .attach = klsi_105_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 134 | .disconnect = klsi_105_disconnect, |
| 135 | .release = klsi_105_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | .throttle = klsi_105_throttle, |
| 137 | .unthrottle = klsi_105_unthrottle, |
| 138 | }; |
| 139 | |
| 140 | struct klsi_105_port_settings { |
| 141 | __u8 pktlen; /* always 5, it seems */ |
| 142 | __u8 baudrate; |
| 143 | __u8 databits; |
| 144 | __u8 unknown1; |
| 145 | __u8 unknown2; |
| 146 | } __attribute__ ((packed)); |
| 147 | |
| 148 | /* we implement a pool of NUM_URBS urbs per usb_serial */ |
| 149 | #define NUM_URBS 1 |
| 150 | #define URB_TRANSFER_BUFFER_SIZE 64 |
| 151 | struct klsi_105_private { |
| 152 | struct klsi_105_port_settings cfg; |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 153 | struct ktermios termios; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | unsigned long line_state; /* modem line settings */ |
| 155 | /* write pool */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 156 | struct urb *write_urb_pool[NUM_URBS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | spinlock_t lock; |
| 158 | unsigned long bytes_in; |
| 159 | unsigned long bytes_out; |
| 160 | }; |
| 161 | |
| 162 | |
| 163 | /* |
| 164 | * Handle vendor specific USB requests |
| 165 | */ |
| 166 | |
| 167 | |
| 168 | #define KLSI_TIMEOUT 5000 /* default urb timeout */ |
| 169 | |
| 170 | static int klsi_105_chg_port_settings(struct usb_serial_port *port, |
| 171 | struct klsi_105_port_settings *settings) |
| 172 | { |
| 173 | int rc; |
| 174 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 175 | rc = usb_control_msg(port->serial->dev, |
| 176 | usb_sndctrlpipe(port->serial->dev, 0), |
| 177 | KL5KUSB105A_SIO_SET_DATA, |
| 178 | USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE, |
| 179 | 0, /* value */ |
| 180 | 0, /* index */ |
| 181 | settings, |
| 182 | sizeof(struct klsi_105_port_settings), |
| 183 | KLSI_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | if (rc < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 185 | dev_err(&port->dev, |
| 186 | "Change port settings failed (error = %d)\n", rc); |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 187 | dev_info(&port->serial->dev->dev, |
| 188 | "%d byte block, baudrate %x, databits %d, u1 %d, u2 %d\n", |
| 189 | settings->pktlen, settings->baudrate, settings->databits, |
| 190 | settings->unknown1, settings->unknown2); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 191 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } /* klsi_105_chg_port_settings */ |
| 193 | |
| 194 | /* translate a 16-bit status value from the device to linux's TIO bits */ |
| 195 | static unsigned long klsi_105_status2linestate(const __u16 status) |
| 196 | { |
| 197 | unsigned long res = 0; |
| 198 | |
| 199 | res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0) |
| 200 | | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0) |
| 201 | ; |
| 202 | |
| 203 | return res; |
| 204 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 205 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | * Read line control via vendor command and return result through |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 207 | * *line_state_p |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | */ |
| 209 | /* It seems that the status buffer has always only 2 bytes length */ |
| 210 | #define KLSI_STATUSBUF_LEN 2 |
| 211 | static int klsi_105_get_line_state(struct usb_serial_port *port, |
| 212 | unsigned long *line_state_p) |
| 213 | { |
| 214 | int rc; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 215 | __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1, -1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | __u16 status; |
| 217 | |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 218 | dev_info(&port->serial->dev->dev, "sending SIO Poll request\n"); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 219 | rc = usb_control_msg(port->serial->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | usb_rcvctrlpipe(port->serial->dev, 0), |
| 221 | KL5KUSB105A_SIO_POLL, |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 222 | USB_TYPE_VENDOR | USB_DIR_IN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | 0, /* value */ |
| 224 | 0, /* index */ |
| 225 | status_buf, KLSI_STATUSBUF_LEN, |
| 226 | 10000 |
| 227 | ); |
| 228 | if (rc < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 229 | dev_err(&port->dev, "Reading line status failed (error = %d)\n", |
| 230 | rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | else { |
Harvey Harrison | bd2c784 | 2008-05-01 20:52:57 -0700 | [diff] [blame] | 232 | status = get_unaligned_le16(status_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 234 | dev_info(&port->serial->dev->dev, "read status %x %x", |
| 235 | status_buf[0], status_buf[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | *line_state_p = klsi_105_status2linestate(status); |
| 238 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 239 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | |
| 243 | /* |
| 244 | * Driver's tty interface functions |
| 245 | */ |
| 246 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 247 | static int klsi_105_startup(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
| 249 | struct klsi_105_private *priv; |
Oliver Neukum | 9306fff | 2007-03-29 11:23:54 +0200 | [diff] [blame] | 250 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | /* check if we support the product id (see keyspan.c) |
| 253 | * FIXME |
| 254 | */ |
| 255 | |
| 256 | /* allocate the private data structure */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 257 | for (i = 0; i < serial->num_ports; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | priv = kmalloc(sizeof(struct klsi_105_private), |
| 259 | GFP_KERNEL); |
| 260 | if (!priv) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 261 | dbg("%skmalloc for klsi_105_private failed.", __func__); |
Oliver Neukum | 9306fff | 2007-03-29 11:23:54 +0200 | [diff] [blame] | 262 | i--; |
| 263 | goto err_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | /* set initial values for control structures */ |
| 266 | priv->cfg.pktlen = 5; |
| 267 | priv->cfg.baudrate = kl5kusb105a_sio_b9600; |
| 268 | priv->cfg.databits = kl5kusb105a_dtb_8; |
| 269 | priv->cfg.unknown1 = 0; |
| 270 | priv->cfg.unknown2 = 1; |
| 271 | |
| 272 | priv->line_state = 0; |
| 273 | |
| 274 | priv->bytes_in = 0; |
| 275 | priv->bytes_out = 0; |
| 276 | usb_set_serial_port_data(serial->port[i], priv); |
| 277 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 278 | spin_lock_init(&priv->lock); |
| 279 | for (j = 0; j < NUM_URBS; j++) { |
| 280 | struct urb *urb = usb_alloc_urb(0, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | priv->write_urb_pool[j] = urb; |
| 283 | if (urb == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 284 | dev_err(&serial->dev->dev, "No more urbs???\n"); |
Oliver Neukum | 9306fff | 2007-03-29 11:23:54 +0200 | [diff] [blame] | 285 | goto err_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 288 | urb->transfer_buffer = |
| 289 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (!urb->transfer_buffer) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 291 | dev_err(&serial->dev->dev, |
| 292 | "%s - out of memory for urb buffers.\n", |
| 293 | __func__); |
Oliver Neukum | 9306fff | 2007-03-29 11:23:54 +0200 | [diff] [blame] | 294 | goto err_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
| 298 | /* priv->termios is left uninitalized until port opening */ |
| 299 | init_waitqueue_head(&serial->port[i]->write_wait); |
| 300 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 301 | |
Oliver Neukum | 9306fff | 2007-03-29 11:23:54 +0200 | [diff] [blame] | 302 | return 0; |
| 303 | |
| 304 | err_cleanup: |
| 305 | for (; i >= 0; i--) { |
| 306 | priv = usb_get_serial_port_data(serial->port[i]); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 307 | for (j = 0; j < NUM_URBS; j++) { |
Oliver Neukum | 9306fff | 2007-03-29 11:23:54 +0200 | [diff] [blame] | 308 | if (priv->write_urb_pool[j]) { |
| 309 | kfree(priv->write_urb_pool[j]->transfer_buffer); |
| 310 | usb_free_urb(priv->write_urb_pool[j]); |
| 311 | } |
| 312 | } |
| 313 | usb_set_serial_port_data(serial->port[i], NULL); |
| 314 | } |
| 315 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } /* klsi_105_startup */ |
| 317 | |
| 318 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 319 | static void klsi_105_disconnect(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { |
| 321 | int i; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 322 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 323 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | /* stop reads and writes on all ports */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 326 | for (i = 0; i < serial->num_ports; ++i) { |
| 327 | struct klsi_105_private *priv = |
| 328 | usb_get_serial_port_data(serial->port[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | if (priv) { |
| 331 | /* kill our write urb pool */ |
| 332 | int j; |
| 333 | struct urb **write_urbs = priv->write_urb_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
| 335 | for (j = 0; j < NUM_URBS; j++) { |
| 336 | if (write_urbs[j]) { |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 337 | usb_kill_urb(write_urbs[j]); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 338 | usb_free_urb(write_urbs[j]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 343 | } /* klsi_105_disconnect */ |
| 344 | |
| 345 | |
| 346 | static void klsi_105_release(struct usb_serial *serial) |
| 347 | { |
| 348 | int i; |
| 349 | |
| 350 | dbg("%s", __func__); |
| 351 | |
| 352 | for (i = 0; i < serial->num_ports; ++i) { |
| 353 | struct klsi_105_private *priv = |
| 354 | usb_get_serial_port_data(serial->port[i]); |
| 355 | |
| 356 | kfree(priv); |
| 357 | } |
| 358 | } /* klsi_105_release */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 360 | static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
| 362 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 363 | int retval = 0; |
| 364 | int rc; |
| 365 | int i; |
| 366 | unsigned long line_state; |
| 367 | struct klsi_105_port_settings cfg; |
| 368 | unsigned long flags; |
| 369 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 370 | dbg("%s port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | /* Do a defined restart: |
| 373 | * Set up sane default baud rate and send the 'READ_ON' |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 374 | * vendor command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | * FIXME: set modem line control (how?) |
| 376 | * Then read the modem line control and store values in |
| 377 | * priv->line_state. |
| 378 | */ |
| 379 | cfg.pktlen = 5; |
| 380 | cfg.baudrate = kl5kusb105a_sio_b9600; |
| 381 | cfg.databits = kl5kusb105a_dtb_8; |
| 382 | cfg.unknown1 = 0; |
| 383 | cfg.unknown2 = 1; |
| 384 | klsi_105_chg_port_settings(port, &cfg); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | /* set up termios structure */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 387 | spin_lock_irqsave(&priv->lock, flags); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 388 | priv->termios.c_iflag = tty->termios->c_iflag; |
| 389 | priv->termios.c_oflag = tty->termios->c_oflag; |
| 390 | priv->termios.c_cflag = tty->termios->c_cflag; |
| 391 | priv->termios.c_lflag = tty->termios->c_lflag; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 392 | for (i = 0; i < NCCS; i++) |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 393 | priv->termios.c_cc[i] = tty->termios->c_cc[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | priv->cfg.pktlen = cfg.pktlen; |
| 395 | priv->cfg.baudrate = cfg.baudrate; |
| 396 | priv->cfg.databits = cfg.databits; |
| 397 | priv->cfg.unknown1 = cfg.unknown1; |
| 398 | priv->cfg.unknown2 = cfg.unknown2; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 399 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | /* READ_ON and urb submission */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 402 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | usb_rcvbulkpipe(port->serial->dev, |
| 404 | port->bulk_in_endpointAddress), |
| 405 | port->read_urb->transfer_buffer, |
| 406 | port->read_urb->transfer_buffer_length, |
| 407 | klsi_105_read_bulk_callback, |
| 408 | port); |
| 409 | |
| 410 | rc = usb_submit_urb(port->read_urb, GFP_KERNEL); |
| 411 | if (rc) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 412 | dev_err(&port->dev, "%s - failed submitting read urb, " |
| 413 | "error %d\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | retval = rc; |
| 415 | goto exit; |
| 416 | } |
| 417 | |
| 418 | rc = usb_control_msg(port->serial->dev, |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 419 | usb_sndctrlpipe(port->serial->dev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | KL5KUSB105A_SIO_CONFIGURE, |
| 421 | USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE, |
| 422 | KL5KUSB105A_SIO_CONFIGURE_READ_ON, |
| 423 | 0, /* index */ |
| 424 | NULL, |
| 425 | 0, |
| 426 | KLSI_TIMEOUT); |
| 427 | if (rc < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 428 | dev_err(&port->dev, "Enabling read failed (error = %d)\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | retval = rc; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 430 | } else |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 431 | dbg("%s - enabled reading", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | rc = klsi_105_get_line_state(port, &line_state); |
| 434 | if (rc >= 0) { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 435 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | priv->line_state = line_state; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 437 | spin_unlock_irqrestore(&priv->lock, flags); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 438 | dbg("%s - read line state 0x%lx", __func__, line_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | retval = 0; |
| 440 | } else |
| 441 | retval = rc; |
| 442 | |
| 443 | exit: |
| 444 | return retval; |
| 445 | } /* klsi_105_open */ |
| 446 | |
| 447 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 448 | static void klsi_105_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
| 450 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 451 | int rc; |
| 452 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 453 | dbg("%s port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Oliver Neukum | 3edbc98 | 2008-01-22 12:47:15 +0100 | [diff] [blame] | 455 | mutex_lock(&port->serial->disc_mutex); |
| 456 | if (!port->serial->disconnected) { |
| 457 | /* send READ_OFF */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 458 | rc = usb_control_msg(port->serial->dev, |
| 459 | usb_sndctrlpipe(port->serial->dev, 0), |
| 460 | KL5KUSB105A_SIO_CONFIGURE, |
| 461 | USB_TYPE_VENDOR | USB_DIR_OUT, |
| 462 | KL5KUSB105A_SIO_CONFIGURE_READ_OFF, |
| 463 | 0, /* index */ |
| 464 | NULL, 0, |
| 465 | KLSI_TIMEOUT); |
Oliver Neukum | 3edbc98 | 2008-01-22 12:47:15 +0100 | [diff] [blame] | 466 | if (rc < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 467 | dev_err(&port->dev, |
| 468 | "Disabling read failed (error = %d)\n", rc); |
Oliver Neukum | 3edbc98 | 2008-01-22 12:47:15 +0100 | [diff] [blame] | 469 | } |
| 470 | mutex_unlock(&port->serial->disc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
| 472 | /* shutdown our bulk reads and writes */ |
| 473 | usb_kill_urb(port->write_urb); |
| 474 | usb_kill_urb(port->read_urb); |
| 475 | /* unlink our write pool */ |
| 476 | /* FIXME */ |
| 477 | /* wgg - do I need this? I think so. */ |
| 478 | usb_kill_urb(port->interrupt_in_urb); |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 479 | dev_info(&port->serial->dev->dev, |
| 480 | "port stats: %ld bytes in, %ld bytes out\n", |
| 481 | priv->bytes_in, priv->bytes_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } /* klsi_105_close */ |
| 483 | |
| 484 | |
| 485 | /* We need to write a complete 64-byte data block and encode the |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 486 | * number actually sent in the first double-byte, LSB-order. That |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | * leaves at most 62 bytes of payload. |
| 488 | */ |
| 489 | #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */ |
| 490 | |
| 491 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 492 | static int klsi_105_write(struct tty_struct *tty, |
| 493 | struct usb_serial_port *port, const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { |
| 495 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 496 | int result, size; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 497 | int bytes_sent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 499 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
| 501 | while (count > 0) { |
| 502 | /* try to find a free urb (write 0 bytes if none) */ |
| 503 | struct urb *urb = NULL; |
| 504 | unsigned long flags; |
| 505 | int i; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 506 | /* since the pool is per-port we might not need |
| 507 | the spin lock !? */ |
| 508 | spin_lock_irqsave(&priv->lock, flags); |
| 509 | for (i = 0; i < NUM_URBS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | if (priv->write_urb_pool[i]->status != -EINPROGRESS) { |
| 511 | urb = priv->write_urb_pool[i]; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 512 | dbg("%s - using pool URB %d", __func__, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | break; |
| 514 | } |
| 515 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 516 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 518 | if (urb == NULL) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 519 | dbg("%s - no more free urbs", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | goto exit; |
| 521 | } |
| 522 | |
| 523 | if (urb->transfer_buffer == NULL) { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 524 | urb->transfer_buffer = |
| 525 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | if (urb->transfer_buffer == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 527 | dev_err(&port->dev, |
| 528 | "%s - no more kernel memory...\n", |
| 529 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | goto exit; |
| 531 | } |
| 532 | } |
| 533 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 534 | size = min(count, port->bulk_out_size - KLSI_105_DATA_OFFSET); |
| 535 | size = min(size, URB_TRANSFER_BUFFER_SIZE - |
| 536 | KLSI_105_DATA_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 538 | memcpy(urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
| 540 | /* write payload size into transfer buffer */ |
| 541 | ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF); |
| 542 | ((__u8 *)urb->transfer_buffer)[1] = (__u8) ((size & 0xFF00)>>8); |
| 543 | |
| 544 | /* set up our urb */ |
| 545 | usb_fill_bulk_urb(urb, port->serial->dev, |
| 546 | usb_sndbulkpipe(port->serial->dev, |
| 547 | port->bulk_out_endpointAddress), |
| 548 | urb->transfer_buffer, |
| 549 | URB_TRANSFER_BUFFER_SIZE, |
| 550 | klsi_105_write_bulk_callback, |
| 551 | port); |
| 552 | |
| 553 | /* send the data out the bulk port */ |
| 554 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 555 | if (result) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 556 | dev_err(&port->dev, |
| 557 | "%s - failed submitting write urb, error %d\n", |
| 558 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | goto exit; |
| 560 | } |
| 561 | buf += size; |
| 562 | bytes_sent += size; |
| 563 | count -= size; |
| 564 | } |
| 565 | exit: |
| 566 | /* lockless, but it's for debug info only... */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 567 | priv->bytes_out += bytes_sent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | return bytes_sent; /* that's how much we wrote */ |
| 570 | } /* klsi_105_write */ |
| 571 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 572 | static void klsi_105_write_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 574 | struct usb_serial_port *port = urb->context; |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 575 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 577 | dbg("%s - port %d", __func__, port->number); |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 578 | |
| 579 | if (status) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 580 | dbg("%s - nonzero write bulk status received: %d", __func__, |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 581 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | return; |
| 583 | } |
| 584 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 585 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } /* klsi_105_write_bulk_completion_callback */ |
| 587 | |
| 588 | |
| 589 | /* return number of characters currently in the writing process */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 590 | static int klsi_105_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 592 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | int chars = 0; |
| 594 | int i; |
| 595 | unsigned long flags; |
| 596 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 597 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 598 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
| 600 | for (i = 0; i < NUM_URBS; ++i) { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 601 | if (priv->write_urb_pool[i]->status == -EINPROGRESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | chars += URB_TRANSFER_BUFFER_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 605 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 607 | dbg("%s - returns %d", __func__, chars); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 608 | return chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 611 | static int klsi_105_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 613 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | unsigned long flags; |
| 615 | int i; |
| 616 | int room = 0; |
| 617 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 618 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 619 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | for (i = 0; i < NUM_URBS; ++i) { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 621 | if (priv->write_urb_pool[i]->status != -EINPROGRESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | room += URB_TRANSFER_BUFFER_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 625 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 627 | dbg("%s - returns %d", __func__, room); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 628 | return room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | |
| 632 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 633 | static void klsi_105_read_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 635 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 637 | struct tty_struct *tty; |
| 638 | unsigned char *data = urb->transfer_buffer; |
| 639 | int rc; |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 640 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 642 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | /* The urb might have been killed. */ |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 645 | if (status) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 646 | dbg("%s - nonzero read bulk status received: %d", __func__, |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 647 | status); |
| 648 | return; |
| 649 | } |
| 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | /* The data received is again preceded by a length double-byte in LSB- |
| 652 | * first order (see klsi_105_write() ) |
| 653 | */ |
| 654 | if (urb->actual_length == 0) { |
| 655 | /* empty urbs seem to happen, we ignore them */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 656 | /* dbg("%s - emtpy URB", __func__); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | ; |
| 658 | } else if (urb->actual_length <= 2) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 659 | dbg("%s - size %d URB not understood", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | urb->actual_length); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 661 | usb_serial_debug_data(debug, &port->dev, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | urb->actual_length, data); |
| 663 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | int bytes_sent = ((__u8 *) data)[0] + |
| 665 | ((unsigned int) ((__u8 *) data)[1] << 8); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 666 | tty = tty_port_tty_get(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | /* we should immediately resubmit the URB, before attempting |
| 668 | * to pass the data on to the tty layer. But that needs locking |
| 669 | * against re-entry an then mixed-up data because of |
| 670 | * intermixed tty_flip_buffer_push()s |
| 671 | * FIXME |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 672 | */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 673 | usb_serial_debug_data(debug, &port->dev, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | urb->actual_length, data); |
| 675 | |
| 676 | if (bytes_sent + 2 > urb->actual_length) { |
| 677 | dbg("%s - trying to read more data than available" |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 678 | " (%d vs. %d)", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | bytes_sent+2, urb->actual_length); |
| 680 | /* cap at implied limit */ |
| 681 | bytes_sent = urb->actual_length - 2; |
| 682 | } |
| 683 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 684 | tty_buffer_request_room(tty, bytes_sent); |
| 685 | tty_insert_flip_string(tty, data + 2, bytes_sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | tty_flip_buffer_push(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 687 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
| 689 | /* again lockless, but debug info only */ |
| 690 | priv->bytes_in += bytes_sent; |
| 691 | } |
| 692 | /* Continue trying to always read */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 693 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | usb_rcvbulkpipe(port->serial->dev, |
| 695 | port->bulk_in_endpointAddress), |
| 696 | port->read_urb->transfer_buffer, |
| 697 | port->read_urb->transfer_buffer_length, |
| 698 | klsi_105_read_bulk_callback, |
| 699 | port); |
| 700 | rc = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
| 701 | if (rc) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 702 | dev_err(&port->dev, |
| 703 | "%s - failed resubmitting read urb, error %d\n", |
| 704 | __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } /* klsi_105_read_bulk_callback */ |
| 706 | |
| 707 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 708 | static void klsi_105_set_termios(struct tty_struct *tty, |
| 709 | struct usb_serial_port *port, |
| 710 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
| 712 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 713 | unsigned int iflag = tty->termios->c_iflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | unsigned int old_iflag = old_termios->c_iflag; |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 715 | unsigned int cflag = tty->termios->c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | unsigned int old_cflag = old_termios->c_cflag; |
| 717 | struct klsi_105_port_settings cfg; |
| 718 | unsigned long flags; |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 719 | speed_t baud; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | /* lock while we are modifying the settings */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 722 | spin_lock_irqsave(&priv->lock, flags); |
| 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | /* |
| 725 | * Update baud rate |
| 726 | */ |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 727 | baud = tty_get_baud_rate(tty); |
| 728 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 729 | if ((cflag & CBAUD) != (old_cflag & CBAUD)) { |
| 730 | /* reassert DTR and (maybe) RTS on transition from B0 */ |
| 731 | if ((old_cflag & CBAUD) == B0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 732 | dbg("%s: baud was B0", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | #if 0 |
| 734 | priv->control_state |= TIOCM_DTR; |
| 735 | /* don't set RTS if using hardware flow control */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 736 | if (!(old_cflag & CRTSCTS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | priv->control_state |= TIOCM_RTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | mct_u232_set_modem_ctrl(serial, priv->control_state); |
| 739 | #endif |
| 740 | } |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 741 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 742 | switch (baud) { |
| 743 | case 0: /* handled below */ |
| 744 | break; |
| 745 | case 1200: |
| 746 | priv->cfg.baudrate = kl5kusb105a_sio_b1200; |
| 747 | break; |
| 748 | case 2400: |
| 749 | priv->cfg.baudrate = kl5kusb105a_sio_b2400; |
| 750 | break; |
| 751 | case 4800: |
| 752 | priv->cfg.baudrate = kl5kusb105a_sio_b4800; |
| 753 | break; |
| 754 | case 9600: |
| 755 | priv->cfg.baudrate = kl5kusb105a_sio_b9600; |
| 756 | break; |
| 757 | case 19200: |
| 758 | priv->cfg.baudrate = kl5kusb105a_sio_b19200; |
| 759 | break; |
| 760 | case 38400: |
| 761 | priv->cfg.baudrate = kl5kusb105a_sio_b38400; |
| 762 | break; |
| 763 | case 57600: |
| 764 | priv->cfg.baudrate = kl5kusb105a_sio_b57600; |
| 765 | break; |
| 766 | case 115200: |
| 767 | priv->cfg.baudrate = kl5kusb105a_sio_b115200; |
| 768 | break; |
| 769 | default: |
| 770 | dbg("KLSI USB->Serial converter:" |
| 771 | " unsupported baudrate request, using default of 9600"); |
Alan Cox | 3f6ff6e | 2007-08-10 14:53:34 -0700 | [diff] [blame] | 772 | priv->cfg.baudrate = kl5kusb105a_sio_b9600; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 773 | baud = 9600; |
| 774 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 776 | if ((cflag & CBAUD) == B0) { |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 777 | dbg("%s: baud is B0", __func__); |
| 778 | /* Drop RTS and DTR */ |
| 779 | /* maybe this should be simulated by sending read |
| 780 | * disable and read enable messages? |
| 781 | */ |
| 782 | ; |
| 783 | #if 0 |
| 784 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 785 | mct_u232_set_modem_ctrl(serial, priv->control_state); |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 786 | #endif |
| 787 | } |
| 788 | tty_encode_baud_rate(tty, baud, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
| 790 | if ((cflag & CSIZE) != (old_cflag & CSIZE)) { |
| 791 | /* set the number of data bits */ |
| 792 | switch (cflag & CSIZE) { |
| 793 | case CS5: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 794 | dbg("%s - 5 bits/byte not supported", __func__); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 795 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | return ; |
| 797 | case CS6: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 798 | dbg("%s - 6 bits/byte not supported", __func__); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 799 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | return ; |
| 801 | case CS7: |
| 802 | priv->cfg.databits = kl5kusb105a_dtb_7; |
| 803 | break; |
| 804 | case CS8: |
| 805 | priv->cfg.databits = kl5kusb105a_dtb_8; |
| 806 | break; |
| 807 | default: |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 808 | dev_err(&port->dev, |
| 809 | "CSIZE was not CS5-CS8, using default of 8\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | priv->cfg.databits = kl5kusb105a_dtb_8; |
| 811 | break; |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * Update line control register (LCR) |
| 817 | */ |
| 818 | if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD)) |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 819 | || (cflag & CSTOPB) != (old_cflag & CSTOPB)) { |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 820 | /* Not currently supported */ |
| 821 | tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | #if 0 |
| 823 | priv->last_lcr = 0; |
| 824 | |
| 825 | /* set the parity */ |
| 826 | if (cflag & PARENB) |
| 827 | priv->last_lcr |= (cflag & PARODD) ? |
| 828 | MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN; |
| 829 | else |
| 830 | priv->last_lcr |= MCT_U232_PARITY_NONE; |
| 831 | |
| 832 | /* set the number of stop bits */ |
| 833 | priv->last_lcr |= (cflag & CSTOPB) ? |
| 834 | MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1; |
| 835 | |
| 836 | mct_u232_set_line_ctrl(serial, priv->last_lcr); |
| 837 | #endif |
| 838 | ; |
| 839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | /* |
| 841 | * Set flow control: well, I do not really now how to handle DTR/RTS. |
| 842 | * Just do what we have seen with SniffUSB on Win98. |
| 843 | */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 844 | if ((iflag & IXOFF) != (old_iflag & IXOFF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | || (iflag & IXON) != (old_iflag & IXON) |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 846 | || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 847 | /* Not currently supported */ |
| 848 | tty->termios->c_cflag &= ~CRTSCTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | /* Drop DTR/RTS if no flow control otherwise assert */ |
| 850 | #if 0 |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 851 | if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | priv->control_state |= TIOCM_DTR | TIOCM_RTS; |
| 853 | else |
| 854 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
| 855 | mct_u232_set_modem_ctrl(serial, priv->control_state); |
| 856 | #endif |
| 857 | ; |
| 858 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 859 | memcpy(&cfg, &priv->cfg, sizeof(cfg)); |
| 860 | spin_unlock_irqrestore(&priv->lock, flags); |
| 861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | /* now commit changes to device */ |
| 863 | klsi_105_chg_port_settings(port, &cfg); |
| 864 | } /* klsi_105_set_termios */ |
| 865 | |
| 866 | |
| 867 | #if 0 |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 868 | static void mct_u232_break_ctl(struct tty_struct *tty, int break_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 870 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | struct usb_serial *serial = port->serial; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 872 | struct mct_u232_private *priv = |
| 873 | (struct mct_u232_private *)port->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | unsigned char lcr = priv->last_lcr; |
| 875 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 876 | dbg("%sstate=%d", __func__, break_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
Alan Cox | 6b447f04 | 2009-01-02 13:48:56 +0000 | [diff] [blame] | 878 | /* LOCKING */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | if (break_state) |
| 880 | lcr |= MCT_U232_SET_BREAK; |
| 881 | |
| 882 | mct_u232_set_line_ctrl(serial, lcr); |
| 883 | } /* mct_u232_break_ctl */ |
| 884 | #endif |
| 885 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 886 | static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 888 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 890 | unsigned long flags; |
| 891 | int rc; |
| 892 | unsigned long line_state; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 893 | dbg("%s - request, just guessing", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | rc = klsi_105_get_line_state(port, &line_state); |
| 896 | if (rc < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 897 | dev_err(&port->dev, |
| 898 | "Reading line control failed (error = %d)\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | /* better return value? EAGAIN? */ |
| 900 | return rc; |
| 901 | } |
| 902 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 903 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | priv->line_state = line_state; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 905 | spin_unlock_irqrestore(&priv->lock, flags); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 906 | dbg("%s - read line state 0x%lx", __func__, line_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | return (int)line_state; |
| 908 | } |
| 909 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 910 | static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file, |
| 911 | unsigned int set, unsigned int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | { |
| 913 | int retval = -EINVAL; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 914 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 915 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
| 917 | /* if this ever gets implemented, it should be done something like this: |
| 918 | struct usb_serial *serial = port->serial; |
| 919 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 920 | unsigned long flags; |
| 921 | int control; |
| 922 | |
| 923 | spin_lock_irqsave (&priv->lock, flags); |
| 924 | if (set & TIOCM_RTS) |
| 925 | priv->control_state |= TIOCM_RTS; |
| 926 | if (set & TIOCM_DTR) |
| 927 | priv->control_state |= TIOCM_DTR; |
| 928 | if (clear & TIOCM_RTS) |
| 929 | priv->control_state &= ~TIOCM_RTS; |
| 930 | if (clear & TIOCM_DTR) |
| 931 | priv->control_state &= ~TIOCM_DTR; |
| 932 | control = priv->control_state; |
| 933 | spin_unlock_irqrestore (&priv->lock, flags); |
| 934 | retval = mct_u232_set_modem_ctrl(serial, control); |
| 935 | */ |
| 936 | return retval; |
| 937 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 939 | static void klsi_105_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 941 | struct usb_serial_port *port = tty->driver_data; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 942 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | usb_kill_urb(port->read_urb); |
| 944 | } |
| 945 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 946 | static void klsi_105_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 948 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | int result; |
| 950 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 951 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
| 953 | port->read_urb->dev = port->serial->dev; |
Oliver Neukum | 6383251 | 2009-10-07 10:50:23 +0200 | [diff] [blame] | 954 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | if (result) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 956 | dev_err(&port->dev, |
| 957 | "%s - failed submitting read urb, error %d\n", |
| 958 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | |
| 962 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 963 | static int __init klsi_105_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
| 965 | int retval; |
| 966 | retval = usb_serial_register(&kl5kusb105d_device); |
| 967 | if (retval) |
| 968 | goto failed_usb_serial_register; |
| 969 | retval = usb_register(&kl5kusb105d_driver); |
| 970 | if (retval) |
| 971 | goto failed_usb_register; |
| 972 | |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 973 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 974 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | return 0; |
| 976 | failed_usb_register: |
| 977 | usb_serial_deregister(&kl5kusb105d_device); |
| 978 | failed_usb_serial_register: |
| 979 | return retval; |
| 980 | } |
| 981 | |
| 982 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 983 | static void __exit klsi_105_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 985 | usb_deregister(&kl5kusb105d_driver); |
| 986 | usb_serial_deregister(&kl5kusb105d_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 990 | module_init(klsi_105_init); |
| 991 | module_exit(klsi_105_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 993 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 994 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 995 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
| 997 | |
| 998 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 999 | MODULE_PARM_DESC(debug, "enable extensive debugging messages"); |
| 1000 | |
| 1001 | /* vim: set sts=8 ts=8 sw=8: */ |