blob: 4a38ec8f5fe330fbc008bae1536c118f35645808 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
18 * It seems that KLSI bought some silicon-design information from ScanLogic,
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
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
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 *
43 * The driver skeleton is mainly based on mct_u232.c and various other
44 * pieces of code shamelessly copied from the drivers/usb/serial/ directory.
45 */
46
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#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>
56#include <asm/uaccess.h>
Al Virofd05e722008-04-28 07:00:16 +010057#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070059#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include "kl5kusb105.h"
61
62static 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 */
75static int klsi_105_startup (struct usb_serial *serial);
76static void klsi_105_shutdown (struct usb_serial *serial);
Alan Cox95da3102008-07-22 11:09:07 +010077static int klsi_105_open (struct tty_struct *tty,
78 struct usb_serial_port *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 struct file *filp);
Alan Cox95da3102008-07-22 11:09:07 +010080static void klsi_105_close (struct tty_struct *tty,
81 struct usb_serial_port *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 struct file *filp);
Alan Cox95da3102008-07-22 11:09:07 +010083static int klsi_105_write (struct tty_struct *tty,
84 struct usb_serial_port *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 const unsigned char *buf,
86 int count);
David Howells7d12e782006-10-05 14:55:46 +010087static void klsi_105_write_bulk_callback (struct urb *urb);
Alan Cox95da3102008-07-22 11:09:07 +010088static int klsi_105_chars_in_buffer (struct tty_struct *tty);
89static int klsi_105_write_room (struct tty_struct *tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
David Howells7d12e782006-10-05 14:55:46 +010091static void klsi_105_read_bulk_callback (struct urb *urb);
Alan Cox95da3102008-07-22 11:09:07 +010092static void klsi_105_set_termios (struct tty_struct *tty,
93 struct usb_serial_port *port,
Alan Cox606d0992006-12-08 02:38:45 -080094 struct ktermios *old);
Alan Cox95da3102008-07-22 11:09:07 +010095static void klsi_105_throttle (struct tty_struct *tty);
96static void klsi_105_unthrottle (struct tty_struct *tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/*
Alan Cox95da3102008-07-22 11:09:07 +010098static void klsi_105_break_ctl (struct tty_struct *tty,
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 int break_state );
100 */
Alan Cox95da3102008-07-22 11:09:07 +0100101static int klsi_105_tiocmget (struct tty_struct *tty,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 struct file *file);
Alan Cox95da3102008-07-22 11:09:07 +0100103static int klsi_105_tiocmset (struct tty_struct *tty,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 struct file *file, unsigned int set,
105 unsigned int clear);
106
107/*
108 * All of the device info needed for the KLSI converters.
109 */
110static struct usb_device_id id_table [] = {
111 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) },
112 { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) },
113 { } /* Terminating entry */
114};
115
116MODULE_DEVICE_TABLE (usb, id_table);
117
118static struct usb_driver kl5kusb105d_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .name = "kl5kusb105d",
120 .probe = usb_serial_probe,
121 .disconnect = usb_serial_disconnect,
122 .id_table = id_table,
Greg Kroah-Hartmanba9dc652005-11-16 13:41:28 -0800123 .no_dynamic_id = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124};
125
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700126static struct usb_serial_driver kl5kusb105d_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700127 .driver = {
128 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700129 .name = "kl5kusb105d",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700130 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700131 .description = "KL5KUSB105D / PalmConnect",
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100132 .usb_driver = &kl5kusb105d_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 .id_table = id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 .num_ports = 1,
135 .open = klsi_105_open,
136 .close = klsi_105_close,
137 .write = klsi_105_write,
138 .write_bulk_callback = klsi_105_write_bulk_callback,
139 .chars_in_buffer = klsi_105_chars_in_buffer,
140 .write_room = klsi_105_write_room,
141 .read_bulk_callback =klsi_105_read_bulk_callback,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 .set_termios = klsi_105_set_termios,
143 /*.break_ctl = klsi_105_break_ctl,*/
144 .tiocmget = klsi_105_tiocmget,
145 .tiocmset = klsi_105_tiocmset,
146 .attach = klsi_105_startup,
147 .shutdown = klsi_105_shutdown,
148 .throttle = klsi_105_throttle,
149 .unthrottle = klsi_105_unthrottle,
150};
151
152struct klsi_105_port_settings {
153 __u8 pktlen; /* always 5, it seems */
154 __u8 baudrate;
155 __u8 databits;
156 __u8 unknown1;
157 __u8 unknown2;
158} __attribute__ ((packed));
159
160/* we implement a pool of NUM_URBS urbs per usb_serial */
161#define NUM_URBS 1
162#define URB_TRANSFER_BUFFER_SIZE 64
163struct klsi_105_private {
164 struct klsi_105_port_settings cfg;
Alan Cox606d0992006-12-08 02:38:45 -0800165 struct ktermios termios;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 unsigned long line_state; /* modem line settings */
167 /* write pool */
168 struct urb * write_urb_pool[NUM_URBS];
169 spinlock_t lock;
170 unsigned long bytes_in;
171 unsigned long bytes_out;
172};
173
174
175/*
176 * Handle vendor specific USB requests
177 */
178
179
180#define KLSI_TIMEOUT 5000 /* default urb timeout */
181
182static int klsi_105_chg_port_settings(struct usb_serial_port *port,
183 struct klsi_105_port_settings *settings)
184{
185 int rc;
186
187 rc = usb_control_msg(port->serial->dev,
188 usb_sndctrlpipe(port->serial->dev, 0),
189 KL5KUSB105A_SIO_SET_DATA,
190 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
191 0, /* value */
192 0, /* index */
193 settings,
194 sizeof(struct klsi_105_port_settings),
195 KLSI_TIMEOUT);
196 if (rc < 0)
197 err("Change port settings failed (error = %d)", rc);
198 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800199 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 settings->pktlen,
201 settings->baudrate, settings->databits,
202 settings->unknown1, settings->unknown2);
203 return rc;
204} /* klsi_105_chg_port_settings */
205
206/* translate a 16-bit status value from the device to linux's TIO bits */
207static unsigned long klsi_105_status2linestate(const __u16 status)
208{
209 unsigned long res = 0;
210
211 res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0)
212 | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0)
213 ;
214
215 return res;
216}
217/*
218 * Read line control via vendor command and return result through
219 * *line_state_p
220 */
221/* It seems that the status buffer has always only 2 bytes length */
222#define KLSI_STATUSBUF_LEN 2
223static int klsi_105_get_line_state(struct usb_serial_port *port,
224 unsigned long *line_state_p)
225{
226 int rc;
227 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1};
228 __u16 status;
229
Harvey Harrison441b62c2008-03-03 16:08:34 -0800230 info("%s - sending SIO Poll request", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 rc = usb_control_msg(port->serial->dev,
232 usb_rcvctrlpipe(port->serial->dev, 0),
233 KL5KUSB105A_SIO_POLL,
234 USB_TYPE_VENDOR | USB_DIR_IN,
235 0, /* value */
236 0, /* index */
237 status_buf, KLSI_STATUSBUF_LEN,
238 10000
239 );
240 if (rc < 0)
241 err("Reading line status failed (error = %d)", rc);
242 else {
Harvey Harrisonbd2c7842008-05-01 20:52:57 -0700243 status = get_unaligned_le16(status_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Harvey Harrison441b62c2008-03-03 16:08:34 -0800245 info("%s - read status %x %x", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 status_buf[0], status_buf[1]);
247
248 *line_state_p = klsi_105_status2linestate(status);
249 }
250
251 return rc;
252}
253
254
255/*
256 * Driver's tty interface functions
257 */
258
259static int klsi_105_startup (struct usb_serial *serial)
260{
261 struct klsi_105_private *priv;
Oliver Neukum9306fff2007-03-29 11:23:54 +0200262 int i, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 /* check if we support the product id (see keyspan.c)
265 * FIXME
266 */
267
268 /* allocate the private data structure */
269 for (i=0; i<serial->num_ports; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 priv = kmalloc(sizeof(struct klsi_105_private),
271 GFP_KERNEL);
272 if (!priv) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800273 dbg("%skmalloc for klsi_105_private failed.", __func__);
Oliver Neukum9306fff2007-03-29 11:23:54 +0200274 i--;
275 goto err_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 }
277 /* set initial values for control structures */
278 priv->cfg.pktlen = 5;
279 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
280 priv->cfg.databits = kl5kusb105a_dtb_8;
281 priv->cfg.unknown1 = 0;
282 priv->cfg.unknown2 = 1;
283
284 priv->line_state = 0;
285
286 priv->bytes_in = 0;
287 priv->bytes_out = 0;
288 usb_set_serial_port_data(serial->port[i], priv);
289
290 spin_lock_init (&priv->lock);
291 for (j=0; j<NUM_URBS; j++) {
292 struct urb* urb = usb_alloc_urb(0, GFP_KERNEL);
293
294 priv->write_urb_pool[j] = urb;
295 if (urb == NULL) {
296 err("No more urbs???");
Oliver Neukum9306fff2007-03-29 11:23:54 +0200297 goto err_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE,
301 GFP_KERNEL);
302 if (!urb->transfer_buffer) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800303 err("%s - out of memory for urb buffers.", __func__);
Oliver Neukum9306fff2007-03-29 11:23:54 +0200304 goto err_cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306 }
307
308 /* priv->termios is left uninitalized until port opening */
309 init_waitqueue_head(&serial->port[i]->write_wait);
310 }
311
Oliver Neukum9306fff2007-03-29 11:23:54 +0200312 return 0;
313
314err_cleanup:
315 for (; i >= 0; i--) {
316 priv = usb_get_serial_port_data(serial->port[i]);
317 for (j=0; j < NUM_URBS; j++) {
318 if (priv->write_urb_pool[j]) {
319 kfree(priv->write_urb_pool[j]->transfer_buffer);
320 usb_free_urb(priv->write_urb_pool[j]);
321 }
322 }
323 usb_set_serial_port_data(serial->port[i], NULL);
324 }
325 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326} /* klsi_105_startup */
327
328
329static void klsi_105_shutdown (struct usb_serial *serial)
330{
331 int i;
332
Harvey Harrison441b62c2008-03-03 16:08:34 -0800333 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 /* stop reads and writes on all ports */
336 for (i=0; i < serial->num_ports; ++i) {
337 struct klsi_105_private *priv = usb_get_serial_port_data(serial->port[i]);
338 unsigned long flags;
339
340 if (priv) {
341 /* kill our write urb pool */
342 int j;
343 struct urb **write_urbs = priv->write_urb_pool;
344 spin_lock_irqsave(&priv->lock,flags);
345
346 for (j = 0; j < NUM_URBS; j++) {
347 if (write_urbs[j]) {
348 /* FIXME - uncomment the following
349 * usb_kill_urb call when the host
350 * controllers get fixed to set
351 * urb->dev = NULL after the urb is
352 * finished. Otherwise this call
353 * oopses. */
354 /* usb_kill_urb(write_urbs[j]); */
Jesper Juhl1bc3c9e2005-04-18 17:39:34 -0700355 kfree(write_urbs[j]->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 usb_free_urb (write_urbs[j]);
357 }
358 }
359
360 spin_unlock_irqrestore (&priv->lock, flags);
361
362 kfree(priv);
363 usb_set_serial_port_data(serial->port[i], NULL);
364 }
365 }
366} /* klsi_105_shutdown */
367
Alan Cox95da3102008-07-22 11:09:07 +0100368static int klsi_105_open(struct tty_struct *tty,
369 struct usb_serial_port *port, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
371 struct klsi_105_private *priv = usb_get_serial_port_data(port);
372 int retval = 0;
373 int rc;
374 int i;
375 unsigned long line_state;
376 struct klsi_105_port_settings cfg;
377 unsigned long flags;
378
Harvey Harrison441b62c2008-03-03 16:08:34 -0800379 dbg("%s port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381 /* force low_latency on so that our tty_push actually forces
382 * the data through
Alan Cox95da3102008-07-22 11:09:07 +0100383 * tty->low_latency = 1; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 /* Do a defined restart:
386 * Set up sane default baud rate and send the 'READ_ON'
387 * vendor command.
388 * FIXME: set modem line control (how?)
389 * Then read the modem line control and store values in
390 * priv->line_state.
391 */
392 cfg.pktlen = 5;
393 cfg.baudrate = kl5kusb105a_sio_b9600;
394 cfg.databits = kl5kusb105a_dtb_8;
395 cfg.unknown1 = 0;
396 cfg.unknown2 = 1;
397 klsi_105_chg_port_settings(port, &cfg);
398
399 /* set up termios structure */
400 spin_lock_irqsave (&priv->lock, flags);
Alan Cox95da3102008-07-22 11:09:07 +0100401 priv->termios.c_iflag = tty->termios->c_iflag;
402 priv->termios.c_oflag = tty->termios->c_oflag;
403 priv->termios.c_cflag = tty->termios->c_cflag;
404 priv->termios.c_lflag = tty->termios->c_lflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 for (i=0; i<NCCS; i++)
Alan Cox95da3102008-07-22 11:09:07 +0100406 priv->termios.c_cc[i] = tty->termios->c_cc[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 priv->cfg.pktlen = cfg.pktlen;
408 priv->cfg.baudrate = cfg.baudrate;
409 priv->cfg.databits = cfg.databits;
410 priv->cfg.unknown1 = cfg.unknown1;
411 priv->cfg.unknown2 = cfg.unknown2;
412 spin_unlock_irqrestore (&priv->lock, flags);
413
414 /* READ_ON and urb submission */
415 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
416 usb_rcvbulkpipe(port->serial->dev,
417 port->bulk_in_endpointAddress),
418 port->read_urb->transfer_buffer,
419 port->read_urb->transfer_buffer_length,
420 klsi_105_read_bulk_callback,
421 port);
422
423 rc = usb_submit_urb(port->read_urb, GFP_KERNEL);
424 if (rc) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800425 err("%s - failed submitting read urb, error %d", __func__, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 retval = rc;
427 goto exit;
428 }
429
430 rc = usb_control_msg(port->serial->dev,
431 usb_sndctrlpipe(port->serial->dev,0),
432 KL5KUSB105A_SIO_CONFIGURE,
433 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
434 KL5KUSB105A_SIO_CONFIGURE_READ_ON,
435 0, /* index */
436 NULL,
437 0,
438 KLSI_TIMEOUT);
439 if (rc < 0) {
440 err("Enabling read failed (error = %d)", rc);
441 retval = rc;
442 } else
Harvey Harrison441b62c2008-03-03 16:08:34 -0800443 dbg("%s - enabled reading", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445 rc = klsi_105_get_line_state(port, &line_state);
446 if (rc >= 0) {
447 spin_lock_irqsave (&priv->lock, flags);
448 priv->line_state = line_state;
449 spin_unlock_irqrestore (&priv->lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800450 dbg("%s - read line state 0x%lx", __func__, line_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 retval = 0;
452 } else
453 retval = rc;
454
455exit:
456 return retval;
457} /* klsi_105_open */
458
459
Alan Cox95da3102008-07-22 11:09:07 +0100460static void klsi_105_close(struct tty_struct *tty,
461 struct usb_serial_port *port, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 struct klsi_105_private *priv = usb_get_serial_port_data(port);
464 int rc;
465
Harvey Harrison441b62c2008-03-03 16:08:34 -0800466 dbg("%s port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Oliver Neukum3edbc982008-01-22 12:47:15 +0100468 mutex_lock(&port->serial->disc_mutex);
469 if (!port->serial->disconnected) {
470 /* send READ_OFF */
471 rc = usb_control_msg (port->serial->dev,
472 usb_sndctrlpipe(port->serial->dev, 0),
473 KL5KUSB105A_SIO_CONFIGURE,
474 USB_TYPE_VENDOR | USB_DIR_OUT,
475 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
476 0, /* index */
477 NULL, 0,
478 KLSI_TIMEOUT);
479 if (rc < 0)
480 err("Disabling read failed (error = %d)", rc);
481 }
482 mutex_unlock(&port->serial->disc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 /* shutdown our bulk reads and writes */
485 usb_kill_urb(port->write_urb);
486 usb_kill_urb(port->read_urb);
487 /* unlink our write pool */
488 /* FIXME */
489 /* wgg - do I need this? I think so. */
490 usb_kill_urb(port->interrupt_in_urb);
491 info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out);
492} /* klsi_105_close */
493
494
495/* We need to write a complete 64-byte data block and encode the
496 * number actually sent in the first double-byte, LSB-order. That
497 * leaves at most 62 bytes of payload.
498 */
499#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
500
501
Alan Cox95da3102008-07-22 11:09:07 +0100502static int klsi_105_write(struct tty_struct *tty,
503 struct usb_serial_port *port, const unsigned char *buf, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
505 struct klsi_105_private *priv = usb_get_serial_port_data(port);
506 int result, size;
507 int bytes_sent=0;
508
Harvey Harrison441b62c2008-03-03 16:08:34 -0800509 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 while (count > 0) {
512 /* try to find a free urb (write 0 bytes if none) */
513 struct urb *urb = NULL;
514 unsigned long flags;
515 int i;
516 /* since the pool is per-port we might not need the spin lock !? */
517 spin_lock_irqsave (&priv->lock, flags);
518 for (i=0; i<NUM_URBS; i++) {
519 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
520 urb = priv->write_urb_pool[i];
Harvey Harrison441b62c2008-03-03 16:08:34 -0800521 dbg("%s - using pool URB %d", __func__, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 break;
523 }
524 }
525 spin_unlock_irqrestore (&priv->lock, flags);
526
527 if (urb==NULL) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800528 dbg("%s - no more free urbs", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 goto exit;
530 }
531
532 if (urb->transfer_buffer == NULL) {
533 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
534 if (urb->transfer_buffer == NULL) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800535 err("%s - no more kernel memory...", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 goto exit;
537 }
538 }
539
540 size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
541 size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET);
542
543 memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
544
545 /* write payload size into transfer buffer */
546 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
547 ((__u8 *)urb->transfer_buffer)[1] = (__u8) ((size & 0xFF00)>>8);
548
549 /* set up our urb */
550 usb_fill_bulk_urb(urb, port->serial->dev,
551 usb_sndbulkpipe(port->serial->dev,
552 port->bulk_out_endpointAddress),
553 urb->transfer_buffer,
554 URB_TRANSFER_BUFFER_SIZE,
555 klsi_105_write_bulk_callback,
556 port);
557
558 /* send the data out the bulk port */
559 result = usb_submit_urb(urb, GFP_ATOMIC);
560 if (result) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800561 err("%s - failed submitting write urb, error %d", __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 goto exit;
563 }
564 buf += size;
565 bytes_sent += size;
566 count -= size;
567 }
568exit:
569 /* lockless, but it's for debug info only... */
570 priv->bytes_out+=bytes_sent;
571
572 return bytes_sent; /* that's how much we wrote */
573} /* klsi_105_write */
574
David Howells7d12e782006-10-05 14:55:46 +0100575static void klsi_105_write_bulk_callback ( struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Ming Leicdc97792008-02-24 18:41:47 +0800577 struct usb_serial_port *port = urb->context;
Greg Kroah-Hartman17c1b352007-06-15 15:44:13 -0700578 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Harvey Harrison441b62c2008-03-03 16:08:34 -0800580 dbg("%s - port %d", __func__, port->number);
Greg Kroah-Hartman17c1b352007-06-15 15:44:13 -0700581
582 if (status) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800583 dbg("%s - nonzero write bulk status received: %d", __func__,
Greg Kroah-Hartman17c1b352007-06-15 15:44:13 -0700584 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 return;
586 }
587
Pete Zaitcevcf2c7482006-05-22 21:58:49 -0700588 usb_serial_port_softint(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589} /* klsi_105_write_bulk_completion_callback */
590
591
592/* return number of characters currently in the writing process */
Alan Cox95da3102008-07-22 11:09:07 +0100593static int klsi_105_chars_in_buffer (struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Alan Cox95da3102008-07-22 11:09:07 +0100595 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 int chars = 0;
597 int i;
598 unsigned long flags;
599 struct klsi_105_private *priv = usb_get_serial_port_data(port);
600
601 spin_lock_irqsave (&priv->lock, flags);
602
603 for (i = 0; i < NUM_URBS; ++i) {
604 if (priv->write_urb_pool[i]->status == -EINPROGRESS) {
605 chars += URB_TRANSFER_BUFFER_SIZE;
606 }
607 }
608
609 spin_unlock_irqrestore (&priv->lock, flags);
610
Harvey Harrison441b62c2008-03-03 16:08:34 -0800611 dbg("%s - returns %d", __func__, chars);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 return (chars);
613}
614
Alan Cox95da3102008-07-22 11:09:07 +0100615static int klsi_105_write_room (struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
Alan Cox95da3102008-07-22 11:09:07 +0100617 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 unsigned long flags;
619 int i;
620 int room = 0;
621 struct klsi_105_private *priv = usb_get_serial_port_data(port);
622
623 spin_lock_irqsave (&priv->lock, flags);
624 for (i = 0; i < NUM_URBS; ++i) {
625 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
626 room += URB_TRANSFER_BUFFER_SIZE;
627 }
628 }
629
630 spin_unlock_irqrestore (&priv->lock, flags);
631
Harvey Harrison441b62c2008-03-03 16:08:34 -0800632 dbg("%s - returns %d", __func__, room);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 return (room);
634}
635
636
637
David Howells7d12e782006-10-05 14:55:46 +0100638static void klsi_105_read_bulk_callback (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
Ming Leicdc97792008-02-24 18:41:47 +0800640 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 struct klsi_105_private *priv = usb_get_serial_port_data(port);
642 struct tty_struct *tty;
643 unsigned char *data = urb->transfer_buffer;
644 int rc;
Greg Kroah-Hartman17c1b352007-06-15 15:44:13 -0700645 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Harvey Harrison441b62c2008-03-03 16:08:34 -0800647 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 /* The urb might have been killed. */
Greg Kroah-Hartman17c1b352007-06-15 15:44:13 -0700650 if (status) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800651 dbg("%s - nonzero read bulk status received: %d", __func__,
Greg Kroah-Hartman17c1b352007-06-15 15:44:13 -0700652 status);
653 return;
654 }
655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /* The data received is again preceded by a length double-byte in LSB-
657 * first order (see klsi_105_write() )
658 */
659 if (urb->actual_length == 0) {
660 /* empty urbs seem to happen, we ignore them */
Harvey Harrison441b62c2008-03-03 16:08:34 -0800661 /* dbg("%s - emtpy URB", __func__); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 ;
663 } else if (urb->actual_length <= 2) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800664 dbg("%s - size %d URB not understood", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 urb->actual_length);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800666 usb_serial_debug_data(debug, &port->dev, __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 urb->actual_length, data);
668 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 int bytes_sent = ((__u8 *) data)[0] +
670 ((unsigned int) ((__u8 *) data)[1] << 8);
Alan Cox95da3102008-07-22 11:09:07 +0100671 tty = port->port.tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 /* we should immediately resubmit the URB, before attempting
673 * to pass the data on to the tty layer. But that needs locking
674 * against re-entry an then mixed-up data because of
675 * intermixed tty_flip_buffer_push()s
676 * FIXME
677 */
Harvey Harrison441b62c2008-03-03 16:08:34 -0800678 usb_serial_debug_data(debug, &port->dev, __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 urb->actual_length, data);
680
681 if (bytes_sent + 2 > urb->actual_length) {
682 dbg("%s - trying to read more data than available"
Harvey Harrison441b62c2008-03-03 16:08:34 -0800683 " (%d vs. %d)", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 bytes_sent+2, urb->actual_length);
685 /* cap at implied limit */
686 bytes_sent = urb->actual_length - 2;
687 }
688
Alan Cox33f0f882006-01-09 20:54:13 -0800689 tty_buffer_request_room(tty, bytes_sent);
690 tty_insert_flip_string(tty, data + 2, bytes_sent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 tty_flip_buffer_push(tty);
692
693 /* again lockless, but debug info only */
694 priv->bytes_in += bytes_sent;
695 }
696 /* Continue trying to always read */
697 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
698 usb_rcvbulkpipe(port->serial->dev,
699 port->bulk_in_endpointAddress),
700 port->read_urb->transfer_buffer,
701 port->read_urb->transfer_buffer_length,
702 klsi_105_read_bulk_callback,
703 port);
704 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
705 if (rc)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800706 err("%s - failed resubmitting read urb, error %d", __func__, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707} /* klsi_105_read_bulk_callback */
708
709
Alan Cox95da3102008-07-22 11:09:07 +0100710static void klsi_105_set_termios (struct tty_struct *tty,
711 struct usb_serial_port *port,
Alan Cox606d0992006-12-08 02:38:45 -0800712 struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
714 struct klsi_105_private *priv = usb_get_serial_port_data(port);
Alan Coxa5b6f602008-04-08 17:16:06 +0100715 unsigned int iflag = tty->termios->c_iflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 unsigned int old_iflag = old_termios->c_iflag;
Alan Coxa5b6f602008-04-08 17:16:06 +0100717 unsigned int cflag = tty->termios->c_cflag;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 unsigned int old_cflag = old_termios->c_cflag;
719 struct klsi_105_port_settings cfg;
720 unsigned long flags;
Alan Coxa5b6f602008-04-08 17:16:06 +0100721 speed_t baud;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 /* lock while we are modifying the settings */
724 spin_lock_irqsave (&priv->lock, flags);
725
726 /*
727 * Update baud rate
728 */
Alan Coxa5b6f602008-04-08 17:16:06 +0100729 baud = tty_get_baud_rate(tty);
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) {
732 /* reassert DTR and (maybe) RTS on transition from B0 */
733 if( (old_cflag & CBAUD) == B0 ) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800734 dbg("%s: baud was B0", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#if 0
736 priv->control_state |= TIOCM_DTR;
737 /* don't set RTS if using hardware flow control */
738 if (!(old_cflag & CRTSCTS)) {
739 priv->control_state |= TIOCM_RTS;
740 }
741 mct_u232_set_modem_ctrl(serial, priv->control_state);
742#endif
743 }
Alan Coxa5b6f602008-04-08 17:16:06 +0100744 }
745 switch(baud) {
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700746 case 0: /* handled below */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 break;
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700748 case 1200:
749 priv->cfg.baudrate = kl5kusb105a_sio_b1200;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 break;
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700751 case 2400:
752 priv->cfg.baudrate = kl5kusb105a_sio_b2400;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 break;
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700754 case 4800:
755 priv->cfg.baudrate = kl5kusb105a_sio_b4800;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 break;
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700757 case 9600:
758 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 break;
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700760 case 19200:
761 priv->cfg.baudrate = kl5kusb105a_sio_b19200;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 break;
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700763 case 38400:
764 priv->cfg.baudrate = kl5kusb105a_sio_b38400;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 break;
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700766 case 57600:
767 priv->cfg.baudrate = kl5kusb105a_sio_b57600;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 break;
Alan Cox3f6ff6e2007-08-10 14:53:34 -0700769 case 115200:
770 priv->cfg.baudrate = kl5kusb105a_sio_b115200;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 break;
772 default:
Alan Coxa5b6f602008-04-08 17:16:06 +0100773 dbg("KLSI USB->Serial converter:"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 " unsupported baudrate request, using default"
775 " of 9600");
776 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
Alan Coxa5b6f602008-04-08 17:16:06 +0100777 baud = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 }
Alan Coxa5b6f602008-04-08 17:16:06 +0100780 if ((cflag & CBAUD) == B0 ) {
781 dbg("%s: baud is B0", __func__);
782 /* Drop RTS and DTR */
783 /* maybe this should be simulated by sending read
784 * disable and read enable messages?
785 */
786 ;
787#if 0
788 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
789 mct_u232_set_modem_ctrl(serial, priv->control_state);
790#endif
791 }
792 tty_encode_baud_rate(tty, baud, baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
795 /* set the number of data bits */
796 switch (cflag & CSIZE) {
797 case CS5:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800798 dbg("%s - 5 bits/byte not supported", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 spin_unlock_irqrestore (&priv->lock, flags);
800 return ;
801 case CS6:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800802 dbg("%s - 6 bits/byte not supported", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 spin_unlock_irqrestore (&priv->lock, flags);
804 return ;
805 case CS7:
806 priv->cfg.databits = kl5kusb105a_dtb_7;
807 break;
808 case CS8:
809 priv->cfg.databits = kl5kusb105a_dtb_8;
810 break;
811 default:
812 err("CSIZE was not CS5-CS8, using default of 8");
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))
822 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) {
823
Alan Coxa5b6f602008-04-08 17:16:06 +0100824 /* Not currently supported */
825 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826#if 0
827 priv->last_lcr = 0;
828
829 /* set the parity */
830 if (cflag & PARENB)
831 priv->last_lcr |= (cflag & PARODD) ?
832 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
833 else
834 priv->last_lcr |= MCT_U232_PARITY_NONE;
835
836 /* set the number of stop bits */
837 priv->last_lcr |= (cflag & CSTOPB) ?
838 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
839
840 mct_u232_set_line_ctrl(serial, priv->last_lcr);
841#endif
842 ;
843 }
844
845 /*
846 * Set flow control: well, I do not really now how to handle DTR/RTS.
847 * Just do what we have seen with SniffUSB on Win98.
848 */
849 if( (iflag & IXOFF) != (old_iflag & IXOFF)
850 || (iflag & IXON) != (old_iflag & IXON)
851 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) {
852
Alan Coxa5b6f602008-04-08 17:16:06 +0100853 /* Not currently supported */
854 tty->termios->c_cflag &= ~CRTSCTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 /* Drop DTR/RTS if no flow control otherwise assert */
856#if 0
857 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) )
858 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
859 else
860 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
861 mct_u232_set_modem_ctrl(serial, priv->control_state);
862#endif
863 ;
864 }
865 memcpy (&cfg, &priv->cfg, sizeof(cfg));
866 spin_unlock_irqrestore (&priv->lock, flags);
867
868 /* now commit changes to device */
869 klsi_105_chg_port_settings(port, &cfg);
870} /* klsi_105_set_termios */
871
872
873#if 0
Alan Cox95da3102008-07-22 11:09:07 +0100874static void mct_u232_break_ctl( struct tty_struct *tty, int break_state )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
Alan Cox95da3102008-07-22 11:09:07 +0100876 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 struct usb_serial *serial = port->serial;
878 struct mct_u232_private *priv = (struct mct_u232_private *)port->private;
879 unsigned char lcr = priv->last_lcr;
880
Harvey Harrison441b62c2008-03-03 16:08:34 -0800881 dbg("%sstate=%d", __func__, break_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 if (break_state)
884 lcr |= MCT_U232_SET_BREAK;
885
886 mct_u232_set_line_ctrl(serial, lcr);
887} /* mct_u232_break_ctl */
888#endif
889
Alan Cox95da3102008-07-22 11:09:07 +0100890static int klsi_105_tiocmget (struct tty_struct *tty, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Alan Cox95da3102008-07-22 11:09:07 +0100892 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 struct klsi_105_private *priv = usb_get_serial_port_data(port);
894 unsigned long flags;
895 int rc;
896 unsigned long line_state;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800897 dbg("%s - request, just guessing", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 rc = klsi_105_get_line_state(port, &line_state);
900 if (rc < 0) {
901 err("Reading line control failed (error = %d)", rc);
902 /* better return value? EAGAIN? */
903 return rc;
904 }
905
906 spin_lock_irqsave (&priv->lock, flags);
907 priv->line_state = line_state;
908 spin_unlock_irqrestore (&priv->lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800909 dbg("%s - read line state 0x%lx", __func__, line_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 return (int)line_state;
911}
912
Alan Cox95da3102008-07-22 11:09:07 +0100913static int klsi_105_tiocmset (struct tty_struct *tty, struct file *file,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 unsigned int set, unsigned int clear)
915{
916 int retval = -EINVAL;
917
Harvey Harrison441b62c2008-03-03 16:08:34 -0800918 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
920/* if this ever gets implemented, it should be done something like this:
921 struct usb_serial *serial = port->serial;
922 struct klsi_105_private *priv = usb_get_serial_port_data(port);
923 unsigned long flags;
924 int control;
925
926 spin_lock_irqsave (&priv->lock, flags);
927 if (set & TIOCM_RTS)
928 priv->control_state |= TIOCM_RTS;
929 if (set & TIOCM_DTR)
930 priv->control_state |= TIOCM_DTR;
931 if (clear & TIOCM_RTS)
932 priv->control_state &= ~TIOCM_RTS;
933 if (clear & TIOCM_DTR)
934 priv->control_state &= ~TIOCM_DTR;
935 control = priv->control_state;
936 spin_unlock_irqrestore (&priv->lock, flags);
937 retval = mct_u232_set_modem_ctrl(serial, control);
938*/
939 return retval;
940}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Alan Cox95da3102008-07-22 11:09:07 +0100942static void klsi_105_throttle (struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
Alan Cox95da3102008-07-22 11:09:07 +0100944 struct usb_serial_port *port = tty->driver_data;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800945 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 usb_kill_urb(port->read_urb);
947}
948
Alan Cox95da3102008-07-22 11:09:07 +0100949static void klsi_105_unthrottle (struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950{
Alan Cox95da3102008-07-22 11:09:07 +0100951 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 int result;
953
Harvey Harrison441b62c2008-03-03 16:08:34 -0800954 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956 port->read_urb->dev = port->serial->dev;
957 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
958 if (result)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800959 err("%s - failed submitting read urb, error %d", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 result);
961}
962
963
964
965static int __init klsi_105_init (void)
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
975 info(DRIVER_DESC " " DRIVER_VERSION);
976 return 0;
977failed_usb_register:
978 usb_serial_deregister(&kl5kusb105d_device);
979failed_usb_serial_register:
980 return retval;
981}
982
983
984static void __exit klsi_105_exit (void)
985{
986 usb_deregister (&kl5kusb105d_driver);
987 usb_serial_deregister (&kl5kusb105d_device);
988}
989
990
991module_init (klsi_105_init);
992module_exit (klsi_105_exit);
993
994MODULE_AUTHOR( DRIVER_AUTHOR );
995MODULE_DESCRIPTION( DRIVER_DESC );
996MODULE_LICENSE("GPL");
997
998
999module_param(debug, bool, S_IRUGO | S_IWUSR);
1000MODULE_PARM_DESC(debug, "enable extensive debugging messages");
1001
1002/* vim: set sts=8 ts=8 sw=8: */