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! |
| 41 | * 0.1 - can be used to to pilot-xfer -p /dev/ttyUSB0 -l |
| 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); |
| 76 | static void klsi_105_shutdown(struct usb_serial *serial); |
| 77 | static int klsi_105_open(struct tty_struct *tty, |
| 78 | struct usb_serial_port *port, struct file *filp); |
| 79 | static void klsi_105_close(struct tty_struct *tty, |
| 80 | struct usb_serial_port *port, struct file *filp); |
| 81 | static int klsi_105_write(struct tty_struct *tty, |
| 82 | struct usb_serial_port *port, const unsigned char *buf, int count); |
| 83 | static void klsi_105_write_bulk_callback(struct urb *urb); |
| 84 | static int klsi_105_chars_in_buffer(struct tty_struct *tty); |
| 85 | static int klsi_105_write_room(struct tty_struct *tty); |
| 86 | static void klsi_105_read_bulk_callback(struct urb *urb); |
| 87 | static void klsi_105_set_termios(struct tty_struct *tty, |
| 88 | struct usb_serial_port *port, struct ktermios *old); |
| 89 | static void klsi_105_throttle(struct tty_struct *tty); |
| 90 | static void klsi_105_unthrottle(struct tty_struct *tty); |
| 91 | static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file); |
| 92 | static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file, |
| 93 | unsigned int set, unsigned int clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * All of the device info needed for the KLSI converters. |
| 97 | */ |
| 98 | static struct usb_device_id id_table [] = { |
| 99 | { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) }, |
| 100 | { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) }, |
| 101 | { } /* Terminating entry */ |
| 102 | }; |
| 103 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 104 | MODULE_DEVICE_TABLE(usb, id_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | static struct usb_driver kl5kusb105d_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | .name = "kl5kusb105d", |
| 108 | .probe = usb_serial_probe, |
| 109 | .disconnect = usb_serial_disconnect, |
| 110 | .id_table = id_table, |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 111 | .no_dynamic_id = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 114 | static struct usb_serial_driver kl5kusb105d_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 115 | .driver = { |
| 116 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 117 | .name = "kl5kusb105d", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 118 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 119 | .description = "KL5KUSB105D / PalmConnect", |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 120 | .usb_driver = &kl5kusb105d_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | .id_table = id_table, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | .num_ports = 1, |
| 123 | .open = klsi_105_open, |
| 124 | .close = klsi_105_close, |
| 125 | .write = klsi_105_write, |
| 126 | .write_bulk_callback = klsi_105_write_bulk_callback, |
| 127 | .chars_in_buffer = klsi_105_chars_in_buffer, |
| 128 | .write_room = klsi_105_write_room, |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 129 | .read_bulk_callback = klsi_105_read_bulk_callback, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | .set_termios = klsi_105_set_termios, |
| 131 | /*.break_ctl = klsi_105_break_ctl,*/ |
| 132 | .tiocmget = klsi_105_tiocmget, |
| 133 | .tiocmset = klsi_105_tiocmset, |
| 134 | .attach = klsi_105_startup, |
| 135 | .shutdown = klsi_105_shutdown, |
| 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 Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 319 | static void klsi_105_shutdown(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 | unsigned long flags; |
| 330 | |
| 331 | if (priv) { |
| 332 | /* kill our write urb pool */ |
| 333 | int j; |
| 334 | struct urb **write_urbs = priv->write_urb_pool; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 335 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | for (j = 0; j < NUM_URBS; j++) { |
| 338 | if (write_urbs[j]) { |
| 339 | /* FIXME - uncomment the following |
| 340 | * usb_kill_urb call when the host |
| 341 | * controllers get fixed to set |
| 342 | * urb->dev = NULL after the urb is |
| 343 | * finished. Otherwise this call |
| 344 | * oopses. */ |
| 345 | /* usb_kill_urb(write_urbs[j]); */ |
Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 346 | kfree(write_urbs[j]->transfer_buffer); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 347 | usb_free_urb(write_urbs[j]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 350 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | kfree(priv); |
| 352 | usb_set_serial_port_data(serial->port[i], NULL); |
| 353 | } |
| 354 | } |
| 355 | } /* klsi_105_shutdown */ |
| 356 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 357 | static int klsi_105_open(struct tty_struct *tty, |
| 358 | struct usb_serial_port *port, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
| 360 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 361 | int retval = 0; |
| 362 | int rc; |
| 363 | int i; |
| 364 | unsigned long line_state; |
| 365 | struct klsi_105_port_settings cfg; |
| 366 | unsigned long flags; |
| 367 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 368 | dbg("%s port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | /* force low_latency on so that our tty_push actually forces |
| 371 | * the data through |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 372 | * tty->low_latency = 1; */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | /* Do a defined restart: |
| 375 | * Set up sane default baud rate and send the 'READ_ON' |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 376 | * vendor command. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | * FIXME: set modem line control (how?) |
| 378 | * Then read the modem line control and store values in |
| 379 | * priv->line_state. |
| 380 | */ |
| 381 | cfg.pktlen = 5; |
| 382 | cfg.baudrate = kl5kusb105a_sio_b9600; |
| 383 | cfg.databits = kl5kusb105a_dtb_8; |
| 384 | cfg.unknown1 = 0; |
| 385 | cfg.unknown2 = 1; |
| 386 | klsi_105_chg_port_settings(port, &cfg); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | /* set up termios structure */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 389 | spin_lock_irqsave(&priv->lock, flags); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 390 | priv->termios.c_iflag = tty->termios->c_iflag; |
| 391 | priv->termios.c_oflag = tty->termios->c_oflag; |
| 392 | priv->termios.c_cflag = tty->termios->c_cflag; |
| 393 | priv->termios.c_lflag = tty->termios->c_lflag; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 394 | for (i = 0; i < NCCS; i++) |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 395 | priv->termios.c_cc[i] = tty->termios->c_cc[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | priv->cfg.pktlen = cfg.pktlen; |
| 397 | priv->cfg.baudrate = cfg.baudrate; |
| 398 | priv->cfg.databits = cfg.databits; |
| 399 | priv->cfg.unknown1 = cfg.unknown1; |
| 400 | priv->cfg.unknown2 = cfg.unknown2; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 401 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | /* READ_ON and urb submission */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 404 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | usb_rcvbulkpipe(port->serial->dev, |
| 406 | port->bulk_in_endpointAddress), |
| 407 | port->read_urb->transfer_buffer, |
| 408 | port->read_urb->transfer_buffer_length, |
| 409 | klsi_105_read_bulk_callback, |
| 410 | port); |
| 411 | |
| 412 | rc = usb_submit_urb(port->read_urb, GFP_KERNEL); |
| 413 | if (rc) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 414 | dev_err(&port->dev, "%s - failed submitting read urb, " |
| 415 | "error %d\n", __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | retval = rc; |
| 417 | goto exit; |
| 418 | } |
| 419 | |
| 420 | rc = usb_control_msg(port->serial->dev, |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 421 | usb_sndctrlpipe(port->serial->dev, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | KL5KUSB105A_SIO_CONFIGURE, |
| 423 | USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE, |
| 424 | KL5KUSB105A_SIO_CONFIGURE_READ_ON, |
| 425 | 0, /* index */ |
| 426 | NULL, |
| 427 | 0, |
| 428 | KLSI_TIMEOUT); |
| 429 | if (rc < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 430 | dev_err(&port->dev, "Enabling read failed (error = %d)\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | retval = rc; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 432 | } else |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 433 | dbg("%s - enabled reading", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | rc = klsi_105_get_line_state(port, &line_state); |
| 436 | if (rc >= 0) { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 437 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | priv->line_state = line_state; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 439 | spin_unlock_irqrestore(&priv->lock, flags); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 440 | dbg("%s - read line state 0x%lx", __func__, line_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | retval = 0; |
| 442 | } else |
| 443 | retval = rc; |
| 444 | |
| 445 | exit: |
| 446 | return retval; |
| 447 | } /* klsi_105_open */ |
| 448 | |
| 449 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 450 | static void klsi_105_close(struct tty_struct *tty, |
| 451 | struct usb_serial_port *port, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | { |
| 453 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 454 | int rc; |
| 455 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 456 | dbg("%s port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
Oliver Neukum | 3edbc98 | 2008-01-22 12:47:15 +0100 | [diff] [blame] | 458 | mutex_lock(&port->serial->disc_mutex); |
| 459 | if (!port->serial->disconnected) { |
| 460 | /* send READ_OFF */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 461 | rc = usb_control_msg(port->serial->dev, |
| 462 | usb_sndctrlpipe(port->serial->dev, 0), |
| 463 | KL5KUSB105A_SIO_CONFIGURE, |
| 464 | USB_TYPE_VENDOR | USB_DIR_OUT, |
| 465 | KL5KUSB105A_SIO_CONFIGURE_READ_OFF, |
| 466 | 0, /* index */ |
| 467 | NULL, 0, |
| 468 | KLSI_TIMEOUT); |
Oliver Neukum | 3edbc98 | 2008-01-22 12:47:15 +0100 | [diff] [blame] | 469 | if (rc < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 470 | dev_err(&port->dev, |
| 471 | "Disabling read failed (error = %d)\n", rc); |
Oliver Neukum | 3edbc98 | 2008-01-22 12:47:15 +0100 | [diff] [blame] | 472 | } |
| 473 | mutex_unlock(&port->serial->disc_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | /* shutdown our bulk reads and writes */ |
| 476 | usb_kill_urb(port->write_urb); |
| 477 | usb_kill_urb(port->read_urb); |
| 478 | /* unlink our write pool */ |
| 479 | /* FIXME */ |
| 480 | /* wgg - do I need this? I think so. */ |
| 481 | usb_kill_urb(port->interrupt_in_urb); |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 482 | dev_info(&port->serial->dev->dev, |
| 483 | "port stats: %ld bytes in, %ld bytes out\n", |
| 484 | priv->bytes_in, priv->bytes_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } /* klsi_105_close */ |
| 486 | |
| 487 | |
| 488 | /* 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] | 489 | * number actually sent in the first double-byte, LSB-order. That |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | * leaves at most 62 bytes of payload. |
| 491 | */ |
| 492 | #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */ |
| 493 | |
| 494 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 495 | static int klsi_105_write(struct tty_struct *tty, |
| 496 | struct usb_serial_port *port, const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | { |
| 498 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 499 | int result, size; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 500 | int bytes_sent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 502 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | while (count > 0) { |
| 505 | /* try to find a free urb (write 0 bytes if none) */ |
| 506 | struct urb *urb = NULL; |
| 507 | unsigned long flags; |
| 508 | int i; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 509 | /* since the pool is per-port we might not need |
| 510 | the spin lock !? */ |
| 511 | spin_lock_irqsave(&priv->lock, flags); |
| 512 | for (i = 0; i < NUM_URBS; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (priv->write_urb_pool[i]->status != -EINPROGRESS) { |
| 514 | urb = priv->write_urb_pool[i]; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 515 | dbg("%s - using pool URB %d", __func__, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | break; |
| 517 | } |
| 518 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 519 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 521 | if (urb == NULL) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 522 | dbg("%s - no more free urbs", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | goto exit; |
| 524 | } |
| 525 | |
| 526 | if (urb->transfer_buffer == NULL) { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 527 | urb->transfer_buffer = |
| 528 | kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | if (urb->transfer_buffer == NULL) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 530 | dev_err(&port->dev, |
| 531 | "%s - no more kernel memory...\n", |
| 532 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | goto exit; |
| 534 | } |
| 535 | } |
| 536 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 537 | size = min(count, port->bulk_out_size - KLSI_105_DATA_OFFSET); |
| 538 | size = min(size, URB_TRANSFER_BUFFER_SIZE - |
| 539 | KLSI_105_DATA_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 541 | memcpy(urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | /* write payload size into transfer buffer */ |
| 544 | ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF); |
| 545 | ((__u8 *)urb->transfer_buffer)[1] = (__u8) ((size & 0xFF00)>>8); |
| 546 | |
| 547 | /* set up our urb */ |
| 548 | usb_fill_bulk_urb(urb, port->serial->dev, |
| 549 | usb_sndbulkpipe(port->serial->dev, |
| 550 | port->bulk_out_endpointAddress), |
| 551 | urb->transfer_buffer, |
| 552 | URB_TRANSFER_BUFFER_SIZE, |
| 553 | klsi_105_write_bulk_callback, |
| 554 | port); |
| 555 | |
| 556 | /* send the data out the bulk port */ |
| 557 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 558 | if (result) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 559 | dev_err(&port->dev, |
| 560 | "%s - failed submitting write urb, error %d\n", |
| 561 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | goto exit; |
| 563 | } |
| 564 | buf += size; |
| 565 | bytes_sent += size; |
| 566 | count -= size; |
| 567 | } |
| 568 | exit: |
| 569 | /* lockless, but it's for debug info only... */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 570 | priv->bytes_out += bytes_sent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
| 572 | return bytes_sent; /* that's how much we wrote */ |
| 573 | } /* klsi_105_write */ |
| 574 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 575 | static void klsi_105_write_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 577 | struct usb_serial_port *port = urb->context; |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 578 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 580 | dbg("%s - port %d", __func__, port->number); |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 581 | |
| 582 | if (status) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 583 | dbg("%s - nonzero write bulk status received: %d", __func__, |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 584 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | return; |
| 586 | } |
| 587 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 588 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } /* klsi_105_write_bulk_completion_callback */ |
| 590 | |
| 591 | |
| 592 | /* return number of characters currently in the writing process */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 593 | static int klsi_105_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 595 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | int chars = 0; |
| 597 | int i; |
| 598 | unsigned long flags; |
| 599 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 600 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 601 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
| 603 | for (i = 0; i < NUM_URBS; ++i) { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 604 | if (priv->write_urb_pool[i]->status == -EINPROGRESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | chars += URB_TRANSFER_BUFFER_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 608 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 610 | dbg("%s - returns %d", __func__, chars); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 611 | return chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 614 | static int klsi_105_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 616 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | unsigned long flags; |
| 618 | int i; |
| 619 | int room = 0; |
| 620 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 621 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 622 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | for (i = 0; i < NUM_URBS; ++i) { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 624 | if (priv->write_urb_pool[i]->status != -EINPROGRESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | room += URB_TRANSFER_BUFFER_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 628 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 630 | dbg("%s - returns %d", __func__, room); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 631 | return room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | |
| 635 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 636 | static void klsi_105_read_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 638 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 640 | struct tty_struct *tty; |
| 641 | unsigned char *data = urb->transfer_buffer; |
| 642 | int rc; |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 643 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 645 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | /* The urb might have been killed. */ |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 648 | if (status) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 649 | dbg("%s - nonzero read bulk status received: %d", __func__, |
Greg Kroah-Hartman | 17c1b35 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 650 | status); |
| 651 | return; |
| 652 | } |
| 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | /* The data received is again preceded by a length double-byte in LSB- |
| 655 | * first order (see klsi_105_write() ) |
| 656 | */ |
| 657 | if (urb->actual_length == 0) { |
| 658 | /* empty urbs seem to happen, we ignore them */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 659 | /* dbg("%s - emtpy URB", __func__); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | ; |
| 661 | } else if (urb->actual_length <= 2) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 662 | dbg("%s - size %d URB not understood", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | urb->actual_length); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 664 | usb_serial_debug_data(debug, &port->dev, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | urb->actual_length, data); |
| 666 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | int bytes_sent = ((__u8 *) data)[0] + |
| 668 | ((unsigned int) ((__u8 *) data)[1] << 8); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 669 | tty = tty_port_tty_get(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | /* we should immediately resubmit the URB, before attempting |
| 671 | * to pass the data on to the tty layer. But that needs locking |
| 672 | * against re-entry an then mixed-up data because of |
| 673 | * intermixed tty_flip_buffer_push()s |
| 674 | * FIXME |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 675 | */ |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 676 | usb_serial_debug_data(debug, &port->dev, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | urb->actual_length, data); |
| 678 | |
| 679 | if (bytes_sent + 2 > urb->actual_length) { |
| 680 | dbg("%s - trying to read more data than available" |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 681 | " (%d vs. %d)", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | bytes_sent+2, urb->actual_length); |
| 683 | /* cap at implied limit */ |
| 684 | bytes_sent = urb->actual_length - 2; |
| 685 | } |
| 686 | |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 687 | tty_buffer_request_room(tty, bytes_sent); |
| 688 | tty_insert_flip_string(tty, data + 2, bytes_sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | tty_flip_buffer_push(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 690 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | |
| 692 | /* again lockless, but debug info only */ |
| 693 | priv->bytes_in += bytes_sent; |
| 694 | } |
| 695 | /* Continue trying to always read */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 696 | usb_fill_bulk_urb(port->read_urb, port->serial->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | usb_rcvbulkpipe(port->serial->dev, |
| 698 | port->bulk_in_endpointAddress), |
| 699 | port->read_urb->transfer_buffer, |
| 700 | port->read_urb->transfer_buffer_length, |
| 701 | klsi_105_read_bulk_callback, |
| 702 | port); |
| 703 | rc = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
| 704 | if (rc) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 705 | dev_err(&port->dev, |
| 706 | "%s - failed resubmitting read urb, error %d\n", |
| 707 | __func__, rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } /* klsi_105_read_bulk_callback */ |
| 709 | |
| 710 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 711 | static void klsi_105_set_termios(struct tty_struct *tty, |
| 712 | struct usb_serial_port *port, |
| 713 | struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
| 715 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 716 | unsigned int iflag = tty->termios->c_iflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | unsigned int old_iflag = old_termios->c_iflag; |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 718 | unsigned int cflag = tty->termios->c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | unsigned int old_cflag = old_termios->c_cflag; |
| 720 | struct klsi_105_port_settings cfg; |
| 721 | unsigned long flags; |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 722 | speed_t baud; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 723 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | /* lock while we are modifying the settings */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 725 | spin_lock_irqsave(&priv->lock, flags); |
| 726 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | /* |
| 728 | * Update baud rate |
| 729 | */ |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 730 | baud = tty_get_baud_rate(tty); |
| 731 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 732 | if ((cflag & CBAUD) != (old_cflag & CBAUD)) { |
| 733 | /* reassert DTR and (maybe) RTS on transition from B0 */ |
| 734 | if ((old_cflag & CBAUD) == B0) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 735 | dbg("%s: baud was B0", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | #if 0 |
| 737 | priv->control_state |= TIOCM_DTR; |
| 738 | /* don't set RTS if using hardware flow control */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 739 | if (!(old_cflag & CRTSCTS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | priv->control_state |= TIOCM_RTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | mct_u232_set_modem_ctrl(serial, priv->control_state); |
| 742 | #endif |
| 743 | } |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 744 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 745 | switch (baud) { |
| 746 | case 0: /* handled below */ |
| 747 | break; |
| 748 | case 1200: |
| 749 | priv->cfg.baudrate = kl5kusb105a_sio_b1200; |
| 750 | break; |
| 751 | case 2400: |
| 752 | priv->cfg.baudrate = kl5kusb105a_sio_b2400; |
| 753 | break; |
| 754 | case 4800: |
| 755 | priv->cfg.baudrate = kl5kusb105a_sio_b4800; |
| 756 | break; |
| 757 | case 9600: |
| 758 | priv->cfg.baudrate = kl5kusb105a_sio_b9600; |
| 759 | break; |
| 760 | case 19200: |
| 761 | priv->cfg.baudrate = kl5kusb105a_sio_b19200; |
| 762 | break; |
| 763 | case 38400: |
| 764 | priv->cfg.baudrate = kl5kusb105a_sio_b38400; |
| 765 | break; |
| 766 | case 57600: |
| 767 | priv->cfg.baudrate = kl5kusb105a_sio_b57600; |
| 768 | break; |
| 769 | case 115200: |
| 770 | priv->cfg.baudrate = kl5kusb105a_sio_b115200; |
| 771 | break; |
| 772 | default: |
| 773 | dbg("KLSI USB->Serial converter:" |
| 774 | " unsupported baudrate request, using default of 9600"); |
Alan Cox | 3f6ff6e | 2007-08-10 14:53:34 -0700 | [diff] [blame] | 775 | priv->cfg.baudrate = kl5kusb105a_sio_b9600; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 776 | baud = 9600; |
| 777 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 779 | if ((cflag & CBAUD) == B0) { |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 780 | dbg("%s: baud is B0", __func__); |
| 781 | /* Drop RTS and DTR */ |
| 782 | /* maybe this should be simulated by sending read |
| 783 | * disable and read enable messages? |
| 784 | */ |
| 785 | ; |
| 786 | #if 0 |
| 787 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 788 | mct_u232_set_modem_ctrl(serial, priv->control_state); |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 789 | #endif |
| 790 | } |
| 791 | tty_encode_baud_rate(tty, baud, baud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | |
| 793 | if ((cflag & CSIZE) != (old_cflag & CSIZE)) { |
| 794 | /* set the number of data bits */ |
| 795 | switch (cflag & CSIZE) { |
| 796 | case CS5: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 797 | dbg("%s - 5 bits/byte not supported", __func__); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 798 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | return ; |
| 800 | case CS6: |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 801 | dbg("%s - 6 bits/byte not supported", __func__); |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 802 | spin_unlock_irqrestore(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | return ; |
| 804 | case CS7: |
| 805 | priv->cfg.databits = kl5kusb105a_dtb_7; |
| 806 | break; |
| 807 | case CS8: |
| 808 | priv->cfg.databits = kl5kusb105a_dtb_8; |
| 809 | break; |
| 810 | default: |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 811 | dev_err(&port->dev, |
| 812 | "CSIZE was not CS5-CS8, using default of 8\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | priv->cfg.databits = kl5kusb105a_dtb_8; |
| 814 | break; |
| 815 | } |
| 816 | } |
| 817 | |
| 818 | /* |
| 819 | * Update line control register (LCR) |
| 820 | */ |
| 821 | if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD)) |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 822 | || (cflag & CSTOPB) != (old_cflag & CSTOPB)) { |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 823 | /* Not currently supported */ |
| 824 | tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | #if 0 |
| 826 | priv->last_lcr = 0; |
| 827 | |
| 828 | /* set the parity */ |
| 829 | if (cflag & PARENB) |
| 830 | priv->last_lcr |= (cflag & PARODD) ? |
| 831 | MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN; |
| 832 | else |
| 833 | priv->last_lcr |= MCT_U232_PARITY_NONE; |
| 834 | |
| 835 | /* set the number of stop bits */ |
| 836 | priv->last_lcr |= (cflag & CSTOPB) ? |
| 837 | MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1; |
| 838 | |
| 839 | mct_u232_set_line_ctrl(serial, priv->last_lcr); |
| 840 | #endif |
| 841 | ; |
| 842 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | /* |
| 844 | * Set flow control: well, I do not really now how to handle DTR/RTS. |
| 845 | * Just do what we have seen with SniffUSB on Win98. |
| 846 | */ |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 847 | if ((iflag & IXOFF) != (old_iflag & IXOFF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | || (iflag & IXON) != (old_iflag & IXON) |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 849 | || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 850 | /* Not currently supported */ |
| 851 | tty->termios->c_cflag &= ~CRTSCTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | /* Drop DTR/RTS if no flow control otherwise assert */ |
| 853 | #if 0 |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 854 | if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | priv->control_state |= TIOCM_DTR | TIOCM_RTS; |
| 856 | else |
| 857 | priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
| 858 | mct_u232_set_modem_ctrl(serial, priv->control_state); |
| 859 | #endif |
| 860 | ; |
| 861 | } |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 862 | memcpy(&cfg, &priv->cfg, sizeof(cfg)); |
| 863 | spin_unlock_irqrestore(&priv->lock, flags); |
| 864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | /* now commit changes to device */ |
| 866 | klsi_105_chg_port_settings(port, &cfg); |
| 867 | } /* klsi_105_set_termios */ |
| 868 | |
| 869 | |
| 870 | #if 0 |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 871 | 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] | 872 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 873 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | struct usb_serial *serial = port->serial; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 875 | struct mct_u232_private *priv = |
| 876 | (struct mct_u232_private *)port->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | unsigned char lcr = priv->last_lcr; |
| 878 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 879 | dbg("%sstate=%d", __func__, break_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | if (break_state) |
| 882 | lcr |= MCT_U232_SET_BREAK; |
| 883 | |
| 884 | mct_u232_set_line_ctrl(serial, lcr); |
| 885 | } /* mct_u232_break_ctl */ |
| 886 | #endif |
| 887 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 888 | static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 890 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 892 | unsigned long flags; |
| 893 | int rc; |
| 894 | unsigned long line_state; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 895 | dbg("%s - request, just guessing", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
| 897 | rc = klsi_105_get_line_state(port, &line_state); |
| 898 | if (rc < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 899 | dev_err(&port->dev, |
| 900 | "Reading line control failed (error = %d)\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | /* better return value? EAGAIN? */ |
| 902 | return rc; |
| 903 | } |
| 904 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 905 | spin_lock_irqsave(&priv->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | priv->line_state = line_state; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 907 | spin_unlock_irqrestore(&priv->lock, flags); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 908 | dbg("%s - read line state 0x%lx", __func__, line_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | return (int)line_state; |
| 910 | } |
| 911 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 912 | static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file, |
| 913 | unsigned int set, unsigned int clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | { |
| 915 | int retval = -EINVAL; |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 916 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 917 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| 919 | /* if this ever gets implemented, it should be done something like this: |
| 920 | struct usb_serial *serial = port->serial; |
| 921 | struct klsi_105_private *priv = usb_get_serial_port_data(port); |
| 922 | unsigned long flags; |
| 923 | int control; |
| 924 | |
| 925 | spin_lock_irqsave (&priv->lock, flags); |
| 926 | if (set & TIOCM_RTS) |
| 927 | priv->control_state |= TIOCM_RTS; |
| 928 | if (set & TIOCM_DTR) |
| 929 | priv->control_state |= TIOCM_DTR; |
| 930 | if (clear & TIOCM_RTS) |
| 931 | priv->control_state &= ~TIOCM_RTS; |
| 932 | if (clear & TIOCM_DTR) |
| 933 | priv->control_state &= ~TIOCM_DTR; |
| 934 | control = priv->control_state; |
| 935 | spin_unlock_irqrestore (&priv->lock, flags); |
| 936 | retval = mct_u232_set_modem_ctrl(serial, control); |
| 937 | */ |
| 938 | return retval; |
| 939 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 941 | static void klsi_105_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 943 | struct usb_serial_port *port = tty->driver_data; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 944 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | usb_kill_urb(port->read_urb); |
| 946 | } |
| 947 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 948 | static void klsi_105_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 950 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | int result; |
| 952 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 953 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | port->read_urb->dev = port->serial->dev; |
| 956 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
| 957 | if (result) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame^] | 958 | dev_err(&port->dev, |
| 959 | "%s - failed submitting read urb, error %d\n", |
| 960 | __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | |
| 964 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 965 | static int __init klsi_105_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | { |
| 967 | int retval; |
| 968 | retval = usb_serial_register(&kl5kusb105d_device); |
| 969 | if (retval) |
| 970 | goto failed_usb_serial_register; |
| 971 | retval = usb_register(&kl5kusb105d_driver); |
| 972 | if (retval) |
| 973 | goto failed_usb_register; |
| 974 | |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 975 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 976 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | return 0; |
| 978 | failed_usb_register: |
| 979 | usb_serial_deregister(&kl5kusb105d_device); |
| 980 | failed_usb_serial_register: |
| 981 | return retval; |
| 982 | } |
| 983 | |
| 984 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 985 | static void __exit klsi_105_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | { |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 987 | usb_deregister(&kl5kusb105d_driver); |
| 988 | usb_serial_deregister(&kl5kusb105d_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 992 | module_init(klsi_105_init); |
| 993 | module_exit(klsi_105_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Alan Cox | 0c265f4 | 2008-07-22 11:14:00 +0100 | [diff] [blame] | 995 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 996 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 997 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | |
| 999 | |
| 1000 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 1001 | MODULE_PARM_DESC(debug, "enable extensive debugging messages"); |
| 1002 | |
| 1003 | /* vim: set sts=8 ts=8 sw=8: */ |