2 * KLSI KL5KUSB105 chip RS232 converter driver
4 * Copyright (C) 2001 Utz-Uwe Haus <haus@uuhaus.de>
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.
11 * All information about the device was acquired using SniffUSB ans snoopUSB
13 * It was written out of frustration with the PalmConnect USB Serial adapter
15 * Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided
16 * information that was not already available.
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
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!
33 * check modem line signals
34 * implement handshaking or decide that we do not support it
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
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.
48 #include <linux/config.h>
49 #include <linux/kernel.h>
50 #include <linux/errno.h>
51 #include <linux/init.h>
52 #include <linux/slab.h>
53 #include <linux/tty.h>
54 #include <linux/tty_driver.h>
55 #include <linux/tty_flip.h>
56 #include <linux/module.h>
57 #include <asm/uaccess.h>
58 #include <linux/usb.h>
60 #ifdef CONFIG_USB_SERIAL_DEBUG
66 #include "usb-serial.h"
67 #include "kl5kusb105.h"
73 #define DRIVER_VERSION "v0.3a"
74 #define DRIVER_AUTHOR "Utz-Uwe Haus <haus@uuhaus.de>"
75 #define DRIVER_DESC "KLSI KL5KUSB105 chipset USB->Serial Converter driver"
81 static int klsi_105_startup (struct usb_serial *serial);
82 static void klsi_105_shutdown (struct usb_serial *serial);
83 static int klsi_105_open (struct usb_serial_port *port,
85 static void klsi_105_close (struct usb_serial_port *port,
87 static int klsi_105_write (struct usb_serial_port *port,
89 const unsigned char *buf,
91 static void klsi_105_write_bulk_callback (struct urb *urb);
92 static int klsi_105_chars_in_buffer (struct usb_serial_port *port);
93 static int klsi_105_write_room (struct usb_serial_port *port);
95 static void klsi_105_read_bulk_callback (struct urb *urb);
96 static void klsi_105_set_termios (struct usb_serial_port *port,
97 struct termios * old);
98 static int klsi_105_ioctl (struct usb_serial_port *port,
102 static void klsi_105_throttle (struct usb_serial_port *port);
103 static void klsi_105_unthrottle (struct usb_serial_port *port);
105 static void klsi_105_break_ctl (struct usb_serial_port *port,
110 * All of the device info needed for the KLSI converters.
112 static struct usb_device_id id_table [] = {
113 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) },
114 { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) },
115 { } /* Terminating entry */
118 MODULE_DEVICE_TABLE (usb, id_table);
121 static struct usb_serial_device_type kl5kusb105d_device = {
122 .owner = THIS_MODULE,
123 .name = "KL5KUSB105D / PalmConnect",
124 .id_table = id_table,
125 .num_interrupt_in = 1,
129 .open = klsi_105_open,
130 .close = klsi_105_close,
131 .write = klsi_105_write,
132 .write_bulk_callback = klsi_105_write_bulk_callback,
133 .chars_in_buffer = klsi_105_chars_in_buffer,
134 .write_room = klsi_105_write_room,
135 .read_bulk_callback =klsi_105_read_bulk_callback,
136 .ioctl = klsi_105_ioctl,
137 .set_termios = klsi_105_set_termios,
138 /*.break_ctl = klsi_105_break_ctl,*/
139 .startup = klsi_105_startup,
140 .shutdown = klsi_105_shutdown,
141 .throttle = klsi_105_throttle,
142 .unthrottle = klsi_105_unthrottle,
145 struct klsi_105_port_settings {
146 __u8 pktlen; /* always 5, it seems */
151 } __attribute__ ((packed));
153 /* we implement a pool of NUM_URBS urbs per usb_serial */
155 #define URB_TRANSFER_BUFFER_SIZE 64
156 struct klsi_105_private {
157 struct klsi_105_port_settings cfg;
158 struct termios termios;
159 unsigned long line_state; /* modem line settings */
161 struct urb * write_urb_pool[NUM_URBS];
162 spinlock_t write_urb_pool_lock;
163 unsigned long bytes_in;
164 unsigned long bytes_out;
169 * Handle vendor specific USB requests
173 #define KLSI_TIMEOUT (HZ * 5 ) /* default urb timeout */
175 static int klsi_105_chg_port_settings(struct usb_serial *serial,
176 struct klsi_105_port_settings *settings)
180 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
181 KL5KUSB105A_SIO_SET_DATA,
182 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
186 sizeof(struct klsi_105_port_settings),
189 err("Change port settings failed (error = %d)", rc);
190 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
193 settings->baudrate, settings->databits,
194 settings->unknown1, settings->unknown2);
196 } /* klsi_105_chg_port_settings */
198 /* translate a 16-bit status value from the device to linux's TIO bits */
199 static unsigned long klsi_105_status2linestate(const __u16 status)
201 unsigned long res = 0;
203 res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0)
204 | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0)
210 * Read line control via vendor command and return result through
213 /* It seems that the status buffer has always only 2 bytes length */
214 #define KLSI_STATUSBUF_LEN 2
215 static int klsi_105_get_line_state(struct usb_serial *serial,
216 unsigned long *line_state_p)
219 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1};
222 info("%s - sending SIO Poll request", __FUNCTION__);
223 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
224 KL5KUSB105A_SIO_POLL,
225 USB_TYPE_VENDOR | USB_DIR_IN,
228 status_buf, KLSI_STATUSBUF_LEN,
232 err("Reading line status failed (error = %d)", rc);
234 status = status_buf[0] + (status_buf[1]<<8);
236 info("%s - read status %x %x", __FUNCTION__,
237 status_buf[0], status_buf[1]);
239 *line_state_p = klsi_105_status2linestate(status);
247 * Driver's tty interface functions
250 static int klsi_105_startup (struct usb_serial *serial)
252 struct klsi_105_private *priv;
255 /* check if we support the product id (see keyspan.c)
259 /* allocate the private data structure */
260 for (i=0; i<serial->num_ports; i++) {
261 serial->port[i].private = kmalloc(sizeof(struct klsi_105_private),
263 if (!serial->port[i].private) {
264 dbg("%skmalloc for klsi_105_private failed.", __FUNCTION__);
265 return (-1); /* error */
267 priv = (struct klsi_105_private *)serial->port[i].private;
268 /* set initial values for control structures */
269 priv->cfg.pktlen = 5;
270 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
271 priv->cfg.databits = kl5kusb105a_dtb_8;
272 priv->cfg.unknown1 = 0;
273 priv->cfg.unknown2 = 1;
275 priv->line_state = 0;
280 spin_lock_init (&priv->write_urb_pool_lock);
281 for (i=0; i<NUM_URBS; i++) {
282 struct urb* urb = usb_alloc_urb(0);
284 priv->write_urb_pool[i] = urb;
286 err("No more urbs???");
290 urb->transfer_buffer = NULL;
291 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE,
293 if (!urb->transfer_buffer) {
294 err("%s - out of memory for urb buffers.", __FUNCTION__);
299 /* priv->termios is left uninitalized until port opening */
300 init_waitqueue_head(&serial->port[i].write_wait);
304 } /* klsi_105_startup */
307 static void klsi_105_shutdown (struct usb_serial *serial)
311 dbg("%s", __FUNCTION__);
313 /* stop reads and writes on all ports */
314 for (i=0; i < serial->num_ports; ++i) {
315 struct klsi_105_private *priv =
316 (struct klsi_105_private*) serial->port[i].private;
320 /* kill our write urb pool */
322 struct urb **write_urbs = priv->write_urb_pool;
323 spin_lock_irqsave(&priv->write_urb_pool_lock,flags);
325 for (j = 0; j < NUM_URBS; j++) {
327 /* FIXME - uncomment the following
328 * usb_unlink_urb call when the host
329 * controllers get fixed to set
330 * urb->dev = NULL after the urb is
331 * finished. Otherwise this call
333 /* usb_unlink_urb(write_urbs[j]); */
334 if (write_urbs[j]->transfer_buffer)
335 kfree(write_urbs[j]->transfer_buffer);
336 usb_free_urb (write_urbs[j]);
340 spin_unlock_irqrestore (&priv->write_urb_pool_lock,
343 kfree(serial->port[i].private);
346 } /* klsi_105_shutdown */
348 static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
350 struct usb_serial *serial = port->serial;
351 struct klsi_105_private *priv = (struct klsi_105_private *)port->private;
355 unsigned long line_state;
357 dbg("%s port %d", __FUNCTION__, port->number);
359 /* force low_latency on so that our tty_push actually forces
361 * port->tty->low_latency = 1; */
363 /* Do a defined restart:
364 * Set up sane default baud rate and send the 'READ_ON'
366 * FIXME: set modem line control (how?)
367 * Then read the modem line control and store values in
370 priv->cfg.pktlen = 5;
371 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
372 priv->cfg.databits = kl5kusb105a_dtb_8;
373 priv->cfg.unknown1 = 0;
374 priv->cfg.unknown2 = 1;
375 klsi_105_chg_port_settings(serial, &(priv->cfg));
377 /* set up termios structure */
378 priv->termios.c_iflag = port->tty->termios->c_iflag;
379 priv->termios.c_oflag = port->tty->termios->c_oflag;
380 priv->termios.c_cflag = port->tty->termios->c_cflag;
381 priv->termios.c_lflag = port->tty->termios->c_lflag;
382 for (i=0; i<NCCS; i++)
383 priv->termios.c_cc[i] = port->tty->termios->c_cc[i];
386 /* READ_ON and urb submission */
387 FILL_BULK_URB(port->read_urb, serial->dev,
388 usb_rcvbulkpipe(serial->dev,
389 port->bulk_in_endpointAddress),
390 port->read_urb->transfer_buffer,
391 port->read_urb->transfer_buffer_length,
392 klsi_105_read_bulk_callback,
394 port->read_urb->transfer_flags |= USB_QUEUE_BULK;
396 rc = usb_submit_urb(port->read_urb);
398 err("%s - failed submitting read urb, error %d", __FUNCTION__, rc);
403 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0),
404 KL5KUSB105A_SIO_CONFIGURE,
405 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
406 KL5KUSB105A_SIO_CONFIGURE_READ_ON,
412 err("Enabling read failed (error = %d)", rc);
415 dbg("%s - enabled reading", __FUNCTION__);
417 rc = klsi_105_get_line_state(serial, &line_state);
419 priv->line_state = line_state;
420 dbg("%s - read line state 0x%lx", __FUNCTION__, line_state);
427 } /* klsi_105_open */
430 static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
432 struct usb_serial *serial;
433 struct klsi_105_private *priv
434 = (struct klsi_105_private *)port->private;
437 dbg("%s port %d", __FUNCTION__, port->number);
439 serial = get_usb_serial (port, __FUNCTION__);
445 rc = usb_control_msg (serial->dev,
446 usb_sndctrlpipe(serial->dev, 0),
447 KL5KUSB105A_SIO_CONFIGURE,
448 USB_TYPE_VENDOR | USB_DIR_OUT,
449 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
454 err("Disabling read failed (error = %d)", rc);
456 /* shutdown our bulk reads and writes */
457 usb_unlink_urb (port->write_urb);
458 usb_unlink_urb (port->read_urb);
459 /* unlink our write pool */
461 /* wgg - do I need this? I think so. */
462 usb_unlink_urb (port->interrupt_in_urb);
463 info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out);
464 } /* klsi_105_close */
467 /* We need to write a complete 64-byte data block and encode the
468 * number actually sent in the first double-byte, LSB-order. That
469 * leaves at most 62 bytes of payload.
471 #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
474 static int klsi_105_write (struct usb_serial_port *port, int from_user,
475 const unsigned char *buf, int count)
477 struct usb_serial *serial = port->serial;
478 struct klsi_105_private *priv =
479 (struct klsi_105_private*) port->private;
483 dbg("%s - port %d", __FUNCTION__, port->number);
486 /* try to find a free urb (write 0 bytes if none) */
487 struct urb *urb = NULL;
490 /* since the pool is per-port we might not need the spin lock !? */
491 spin_lock_irqsave (&priv->write_urb_pool_lock, flags);
492 for (i=0; i<NUM_URBS; i++) {
493 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
494 urb = priv->write_urb_pool[i];
495 dbg("%s - using pool URB %d", __FUNCTION__, i);
499 spin_unlock_irqrestore (&priv->write_urb_pool_lock, flags);
502 dbg("%s - no more free urbs", __FUNCTION__);
506 if (urb->transfer_buffer == NULL) {
507 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
508 if (urb->transfer_buffer == NULL) {
509 err("%s - no more kernel memory...", __FUNCTION__);
514 size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
515 size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET);
518 if (copy_from_user(urb->transfer_buffer
519 + KLSI_105_DATA_OFFSET, buf, size)) {
523 memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET,
527 /* write payload size into transfer buffer */
528 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
529 ((__u8 *)urb->transfer_buffer)[1] = (__u8) ((size & 0xFF00)>>8);
532 FILL_BULK_URB(urb, serial->dev,
533 usb_sndbulkpipe(serial->dev,
534 port->bulk_out_endpointAddress),
535 urb->transfer_buffer,
536 URB_TRANSFER_BUFFER_SIZE,
537 klsi_105_write_bulk_callback,
539 urb->transfer_flags |= USB_QUEUE_BULK;
542 /* send the data out the bulk port */
543 result = usb_submit_urb(urb);
545 err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
553 priv->bytes_out+=bytes_sent;
555 return bytes_sent; /* that's how much we wrote */
556 } /* klsi_105_write */
558 static void klsi_105_write_bulk_callback ( struct urb *urb)
560 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
561 struct usb_serial *serial = port->serial;
563 dbg("%s - port %d", __FUNCTION__, port->number);
566 dbg("%s - bad serial pointer, exiting", __FUNCTION__);
571 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__,
576 /* from generic_write_bulk_callback */
577 queue_task(&port->tqueue, &tq_immediate);
578 mark_bh(IMMEDIATE_BH);
581 } /* klsi_105_write_bulk_completion_callback */
584 /* return number of characters currently in the writing process */
585 static int klsi_105_chars_in_buffer (struct usb_serial_port *port)
590 struct klsi_105_private *priv =
591 (struct klsi_105_private*) port->private;
593 spin_lock_irqsave (&priv->write_urb_pool_lock, flags);
595 for (i = 0; i < NUM_URBS; ++i) {
596 if (priv->write_urb_pool[i]->status == -EINPROGRESS) {
597 chars += URB_TRANSFER_BUFFER_SIZE;
601 spin_unlock_irqrestore (&priv->write_urb_pool_lock, flags);
603 dbg("%s - returns %d", __FUNCTION__, chars);
607 static int klsi_105_write_room (struct usb_serial_port *port)
612 struct klsi_105_private *priv =
613 (struct klsi_105_private*) port->private;
615 spin_lock_irqsave (&priv->write_urb_pool_lock, flags);
616 for (i = 0; i < NUM_URBS; ++i) {
617 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
618 room += URB_TRANSFER_BUFFER_SIZE;
622 spin_unlock_irqrestore (&priv->write_urb_pool_lock, flags);
624 dbg("%s - returns %d", __FUNCTION__, room);
630 static void klsi_105_read_bulk_callback (struct urb *urb)
632 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
633 struct usb_serial *serial = port->serial;
634 struct klsi_105_private *priv =
635 (struct klsi_105_private*) port->private;
636 struct tty_struct *tty;
637 unsigned char *data = urb->transfer_buffer;
640 dbg("%s - port %d", __FUNCTION__, port->number);
642 /* The urb might have been killed. */
644 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__,
649 dbg("%s - bad serial pointer, exiting", __FUNCTION__);
653 /* The data received is again preceded by a length double-byte in LSB-
654 * first order (see klsi_105_write() )
656 if (urb->actual_length == 0) {
657 /* empty urbs seem to happen, we ignore them */
658 /* dbg("%s - emtpy URB", __FUNCTION__); */
660 } else if (urb->actual_length <= 2) {
661 dbg("%s - size %d URB not understood", __FUNCTION__,
663 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
666 int bytes_sent = ((__u8 *) data)[0] +
667 ((unsigned int) ((__u8 *) data)[1] << 8);
669 /* we should immediately resubmit the URB, before attempting
670 * to pass the data on to the tty layer. But that needs locking
671 * against re-entry an then mixed-up data because of
672 * intermixed tty_flip_buffer_push()s
675 usb_serial_debug_data (__FILE__, __FUNCTION__,
676 urb->actual_length, data);
678 if (bytes_sent + 2 > urb->actual_length) {
679 dbg("%s - trying to read more data than available"
680 " (%d vs. %d)", __FUNCTION__,
681 bytes_sent+2, urb->actual_length);
682 /* cap at implied limit */
683 bytes_sent = urb->actual_length - 2;
686 for (i = 2; i < 2+bytes_sent; i++) {
687 /* if we insert more than TTY_FLIPBUF_SIZE characters,
689 if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
690 tty_flip_buffer_push(tty);
692 /* this doesn't actually push the data through unless
693 * tty->low_latency is set */
694 tty_insert_flip_char(tty, ((__u8*) data)[i], 0);
696 tty_flip_buffer_push(tty);
697 priv->bytes_in += bytes_sent;
699 /* Continue trying to always read */
700 FILL_BULK_URB(port->read_urb, serial->dev,
701 usb_rcvbulkpipe(serial->dev,
702 port->bulk_in_endpointAddress),
703 port->read_urb->transfer_buffer,
704 port->read_urb->transfer_buffer_length,
705 klsi_105_read_bulk_callback,
707 rc = usb_submit_urb(port->read_urb);
709 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, rc);
710 } /* klsi_105_read_bulk_callback */
713 static void klsi_105_set_termios (struct usb_serial_port *port,
714 struct termios *old_termios)
716 struct usb_serial *serial = port->serial;
717 struct klsi_105_private *priv = (struct klsi_105_private *)port->private;
718 unsigned int iflag = port->tty->termios->c_iflag;
719 unsigned int old_iflag = old_termios->c_iflag;
720 unsigned int cflag = port->tty->termios->c_cflag;
721 unsigned int old_cflag = old_termios->c_cflag;
726 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) {
727 /* reassert DTR and (maybe) RTS on transition from B0 */
728 if( (old_cflag & CBAUD) == B0 ) {
729 dbg("%s: baud was B0", __FUNCTION__);
731 priv->control_state |= TIOCM_DTR;
732 /* don't set RTS if using hardware flow control */
733 if (!(old_cflag & CRTSCTS)) {
734 priv->control_state |= TIOCM_RTS;
736 mct_u232_set_modem_ctrl(serial, priv->control_state);
740 switch(cflag & CBAUD) {
741 case B0: /* handled below */
743 case B1200: priv->cfg.baudrate = kl5kusb105a_sio_b1200;
745 case B2400: priv->cfg.baudrate = kl5kusb105a_sio_b2400;
747 case B4800: priv->cfg.baudrate = kl5kusb105a_sio_b4800;
749 case B9600: priv->cfg.baudrate = kl5kusb105a_sio_b9600;
751 case B19200: priv->cfg.baudrate = kl5kusb105a_sio_b19200;
753 case B38400: priv->cfg.baudrate = kl5kusb105a_sio_b38400;
755 case B57600: priv->cfg.baudrate = kl5kusb105a_sio_b57600;
757 case B115200: priv->cfg.baudrate = kl5kusb105a_sio_b115200;
760 err("KLSI USB->Serial converter:"
761 " unsupported baudrate request, using default"
763 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
766 if ((cflag & CBAUD) == B0 ) {
767 dbg("%s: baud is B0", __FUNCTION__);
768 /* Drop RTS and DTR */
769 /* maybe this should be simulated by sending read
770 * disable and read enable messages?
774 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
775 mct_u232_set_modem_ctrl(serial, priv->control_state);
780 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
781 /* set the number of data bits */
782 switch (cflag & CSIZE) {
784 dbg("%s - 5 bits/byte not supported", __FUNCTION__);
787 dbg("%s - 6 bits/byte not supported", __FUNCTION__);
790 priv->cfg.databits = kl5kusb105a_dtb_7;
793 priv->cfg.databits = kl5kusb105a_dtb_8;
796 err("CSIZE was not CS5-CS8, using default of 8");
797 priv->cfg.databits = kl5kusb105a_dtb_8;
803 * Update line control register (LCR)
805 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
806 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) {
813 priv->last_lcr |= (cflag & PARODD) ?
814 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
816 priv->last_lcr |= MCT_U232_PARITY_NONE;
818 /* set the number of stop bits */
819 priv->last_lcr |= (cflag & CSTOPB) ?
820 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
822 mct_u232_set_line_ctrl(serial, priv->last_lcr);
828 * Set flow control: well, I do not really now how to handle DTR/RTS.
829 * Just do what we have seen with SniffUSB on Win98.
831 if( (iflag & IXOFF) != (old_iflag & IXOFF)
832 || (iflag & IXON) != (old_iflag & IXON)
833 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) {
835 /* Drop DTR/RTS if no flow control otherwise assert */
837 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) )
838 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
840 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
841 mct_u232_set_modem_ctrl(serial, priv->control_state);
846 /* now commit changes to device */
847 klsi_105_chg_port_settings(serial, &(priv->cfg));
848 } /* klsi_105_set_termios */
852 static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
854 struct usb_serial *serial = port->serial;
855 struct mct_u232_private *priv = (struct mct_u232_private *)port->private;
856 unsigned char lcr = priv->last_lcr;
858 dbg("%sstate=%d", __FUNCTION__, break_state);
861 lcr |= MCT_U232_SET_BREAK;
863 mct_u232_set_line_ctrl(serial, lcr);
864 } /* mct_u232_break_ctl */
867 static int klsi_105_ioctl (struct usb_serial_port *port, struct file * file,
868 unsigned int cmd, unsigned long arg)
870 struct usb_serial *serial = port->serial;
871 struct klsi_105_private *priv = (struct klsi_105_private *)port->private;
874 dbg("%scmd=0x%x", __FUNCTION__, cmd);
876 /* Based on code from acm.c and others */
880 unsigned long line_state;
881 dbg("%s - TIOCMGET request, just guessing", __FUNCTION__);
883 rc = klsi_105_get_line_state(serial, &line_state);
885 err("Reading line control failed (error = %d)", rc);
886 /* better return value? EAGAIN? */
889 priv->line_state = line_state;
890 dbg("%s - read line state 0x%lx", __FUNCTION__, line_state);
892 return put_user(priv->line_state, (unsigned long *) arg);
895 case TIOCMSET: /* Turns on and off the lines as specified by the mask */
896 case TIOCMBIS: /* turns on (Sets) the lines as specified by the mask */
897 case TIOCMBIC: /* turns off (Clears) the lines as specified by the mask */
898 if (get_user(mask, (unsigned long *) arg))
901 if ((cmd == TIOCMSET) || (mask & TIOCM_RTS)) {
903 if( ((cmd == TIOCMSET) && (mask & TIOCM_RTS)) ||
905 dbg("%s - set RTS not handled", __FUNCTION__);
906 /* priv->control_state |= TIOCM_RTS; */
908 dbg("%s - clear RTS not handled", __FUNCTION__);
909 /* priv->control_state &= ~TIOCM_RTS; */
912 if ((cmd == TIOCMSET) || (mask & TIOCM_DTR)) {
914 if( ((cmd == TIOCMSET) && (mask & TIOCM_DTR)) ||
916 dbg("%s - set DTR not handled", __FUNCTION__);
917 /* priv->control_state |= TIOCM_DTR; */
919 dbg("%s - clear DTR not handled", __FUNCTION__);
920 /* priv->control_state &= ~TIOCM_DTR; */
923 mct_u232_set_modem_ctrl(serial, priv->control_state);
928 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
930 dbg("%s - TIOCMIWAIT not handled", __FUNCTION__);
934 /* return count of modemline transitions */
936 dbg("%s - TIOCGICOUNT not handled", __FUNCTION__);
939 /* return current info to caller */
942 dbg("%s - TCGETS data faked/incomplete", __FUNCTION__);
944 retval = verify_area(VERIFY_WRITE, (void *)arg,
945 sizeof(struct termios));
950 kernel_termios_to_user_termios((struct termios *)arg,
955 /* set port termios to the one given by the user */
958 dbg("%s - TCSETS not handled", __FUNCTION__);
960 retval = verify_area(VERIFY_READ, (void *)arg,
961 sizeof(struct termios));
966 user_termios_to_kernel_termios(&priv->termios,
967 (struct termios *)arg);
968 klsi_105_set_termios(port, &priv->termios);
972 /* set port termios and try to wait for completion of last
974 /* We guess here. If there are not too many write urbs
975 * outstanding, we lie. */
976 /* what is the right way to wait here? schedule() ? */
978 while (klsi_105_chars_in_buffer(port) > (NUM_URBS / 4 ) * URB_TRANSFER_BUFFER_SIZE)
984 dbg("%s: arg not supported - 0x%04x", __FUNCTION__,cmd);
985 return(-ENOIOCTLCMD);
989 } /* klsi_105_ioctl */
991 static void klsi_105_throttle (struct usb_serial_port *port)
993 dbg("%s - port %d", __FUNCTION__, port->number);
994 usb_unlink_urb (port->read_urb);
997 static void klsi_105_unthrottle (struct usb_serial_port *port)
1001 dbg("%s - port %d", __FUNCTION__, port->number);
1003 port->read_urb->dev = port->serial->dev;
1004 result = usb_submit_urb(port->read_urb);
1006 err("%s - failed submitting read urb, error %d", __FUNCTION__,
1012 static int __init klsi_105_init (void)
1014 usb_serial_register (&kl5kusb105d_device);
1016 info(DRIVER_DESC " " DRIVER_VERSION);
1021 static void __exit klsi_105_exit (void)
1023 usb_serial_deregister (&kl5kusb105d_device);
1027 module_init (klsi_105_init);
1028 module_exit (klsi_105_exit);
1030 MODULE_AUTHOR( DRIVER_AUTHOR );
1031 MODULE_DESCRIPTION( DRIVER_DESC );
1032 MODULE_LICENSE("GPL");
1035 MODULE_PARM(debug, "i");
1036 MODULE_PARM_DESC(debug, "enable extensive debugging messages");
1038 MODULE_PARM(num_urbs, "i");
1039 MODULE_PARM_DESC(num_urbs, "number of URBs to use in write pool");
1042 /* vim: set sts=8 ts=8 sw=8: */