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/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>
57 #include <asm/unaligned.h>
58 #include <linux/usb.h>
59 #include <linux/usb/serial.h>
60 #include "kl5kusb105.h"
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"
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 usb_serial_port *port,
79 static void klsi_105_close (struct usb_serial_port *port,
81 static int klsi_105_write (struct usb_serial_port *port,
82 const unsigned char *buf,
84 static void klsi_105_write_bulk_callback (struct urb *urb);
85 static int klsi_105_chars_in_buffer (struct usb_serial_port *port);
86 static int klsi_105_write_room (struct usb_serial_port *port);
88 static void klsi_105_read_bulk_callback (struct urb *urb);
89 static void klsi_105_set_termios (struct usb_serial_port *port,
90 struct ktermios *old);
91 static void klsi_105_throttle (struct usb_serial_port *port);
92 static void klsi_105_unthrottle (struct usb_serial_port *port);
94 static void klsi_105_break_ctl (struct usb_serial_port *port,
97 static int klsi_105_tiocmget (struct usb_serial_port *port,
99 static int klsi_105_tiocmset (struct usb_serial_port *port,
100 struct file *file, unsigned int set,
104 * All of the device info needed for the KLSI converters.
106 static struct usb_device_id id_table [] = {
107 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) },
108 { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) },
109 { } /* Terminating entry */
112 MODULE_DEVICE_TABLE (usb, id_table);
114 static struct usb_driver kl5kusb105d_driver = {
115 .name = "kl5kusb105d",
116 .probe = usb_serial_probe,
117 .disconnect = usb_serial_disconnect,
118 .id_table = id_table,
122 static struct usb_serial_driver kl5kusb105d_device = {
124 .owner = THIS_MODULE,
125 .name = "kl5kusb105d",
127 .description = "KL5KUSB105D / PalmConnect",
128 .usb_driver = &kl5kusb105d_driver,
129 .id_table = id_table,
131 .open = klsi_105_open,
132 .close = klsi_105_close,
133 .write = klsi_105_write,
134 .write_bulk_callback = klsi_105_write_bulk_callback,
135 .chars_in_buffer = klsi_105_chars_in_buffer,
136 .write_room = klsi_105_write_room,
137 .read_bulk_callback =klsi_105_read_bulk_callback,
138 .set_termios = klsi_105_set_termios,
139 /*.break_ctl = klsi_105_break_ctl,*/
140 .tiocmget = klsi_105_tiocmget,
141 .tiocmset = klsi_105_tiocmset,
142 .attach = klsi_105_startup,
143 .shutdown = klsi_105_shutdown,
144 .throttle = klsi_105_throttle,
145 .unthrottle = klsi_105_unthrottle,
148 struct klsi_105_port_settings {
149 __u8 pktlen; /* always 5, it seems */
154 } __attribute__ ((packed));
156 /* we implement a pool of NUM_URBS urbs per usb_serial */
158 #define URB_TRANSFER_BUFFER_SIZE 64
159 struct klsi_105_private {
160 struct klsi_105_port_settings cfg;
161 struct ktermios termios;
162 unsigned long line_state; /* modem line settings */
164 struct urb * write_urb_pool[NUM_URBS];
166 unsigned long bytes_in;
167 unsigned long bytes_out;
172 * Handle vendor specific USB requests
176 #define KLSI_TIMEOUT 5000 /* default urb timeout */
178 static int klsi_105_chg_port_settings(struct usb_serial_port *port,
179 struct klsi_105_port_settings *settings)
183 rc = usb_control_msg(port->serial->dev,
184 usb_sndctrlpipe(port->serial->dev, 0),
185 KL5KUSB105A_SIO_SET_DATA,
186 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
190 sizeof(struct klsi_105_port_settings),
193 err("Change port settings failed (error = %d)", rc);
194 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
197 settings->baudrate, settings->databits,
198 settings->unknown1, settings->unknown2);
200 } /* klsi_105_chg_port_settings */
202 /* translate a 16-bit status value from the device to linux's TIO bits */
203 static unsigned long klsi_105_status2linestate(const __u16 status)
205 unsigned long res = 0;
207 res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0)
208 | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0)
214 * Read line control via vendor command and return result through
217 /* It seems that the status buffer has always only 2 bytes length */
218 #define KLSI_STATUSBUF_LEN 2
219 static int klsi_105_get_line_state(struct usb_serial_port *port,
220 unsigned long *line_state_p)
223 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1};
226 info("%s - sending SIO Poll request", __func__);
227 rc = usb_control_msg(port->serial->dev,
228 usb_rcvctrlpipe(port->serial->dev, 0),
229 KL5KUSB105A_SIO_POLL,
230 USB_TYPE_VENDOR | USB_DIR_IN,
233 status_buf, KLSI_STATUSBUF_LEN,
237 err("Reading line status failed (error = %d)", rc);
239 status = le16_to_cpu(get_unaligned((__le16 *)status_buf));
241 info("%s - read status %x %x", __func__,
242 status_buf[0], status_buf[1]);
244 *line_state_p = klsi_105_status2linestate(status);
252 * Driver's tty interface functions
255 static int klsi_105_startup (struct usb_serial *serial)
257 struct klsi_105_private *priv;
260 /* check if we support the product id (see keyspan.c)
264 /* allocate the private data structure */
265 for (i=0; i<serial->num_ports; i++) {
266 priv = kmalloc(sizeof(struct klsi_105_private),
269 dbg("%skmalloc for klsi_105_private failed.", __func__);
273 /* set initial values for control structures */
274 priv->cfg.pktlen = 5;
275 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
276 priv->cfg.databits = kl5kusb105a_dtb_8;
277 priv->cfg.unknown1 = 0;
278 priv->cfg.unknown2 = 1;
280 priv->line_state = 0;
284 usb_set_serial_port_data(serial->port[i], priv);
286 spin_lock_init (&priv->lock);
287 for (j=0; j<NUM_URBS; j++) {
288 struct urb* urb = usb_alloc_urb(0, GFP_KERNEL);
290 priv->write_urb_pool[j] = urb;
292 err("No more urbs???");
296 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE,
298 if (!urb->transfer_buffer) {
299 err("%s - out of memory for urb buffers.", __func__);
304 /* priv->termios is left uninitalized until port opening */
305 init_waitqueue_head(&serial->port[i]->write_wait);
311 for (; i >= 0; i--) {
312 priv = usb_get_serial_port_data(serial->port[i]);
313 for (j=0; j < NUM_URBS; j++) {
314 if (priv->write_urb_pool[j]) {
315 kfree(priv->write_urb_pool[j]->transfer_buffer);
316 usb_free_urb(priv->write_urb_pool[j]);
319 usb_set_serial_port_data(serial->port[i], NULL);
322 } /* klsi_105_startup */
325 static void klsi_105_shutdown (struct usb_serial *serial)
331 /* stop reads and writes on all ports */
332 for (i=0; i < serial->num_ports; ++i) {
333 struct klsi_105_private *priv = usb_get_serial_port_data(serial->port[i]);
337 /* kill our write urb pool */
339 struct urb **write_urbs = priv->write_urb_pool;
340 spin_lock_irqsave(&priv->lock,flags);
342 for (j = 0; j < NUM_URBS; j++) {
344 /* FIXME - uncomment the following
345 * usb_kill_urb call when the host
346 * controllers get fixed to set
347 * urb->dev = NULL after the urb is
348 * finished. Otherwise this call
350 /* usb_kill_urb(write_urbs[j]); */
351 kfree(write_urbs[j]->transfer_buffer);
352 usb_free_urb (write_urbs[j]);
356 spin_unlock_irqrestore (&priv->lock, flags);
359 usb_set_serial_port_data(serial->port[i], NULL);
362 } /* klsi_105_shutdown */
364 static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
366 struct klsi_105_private *priv = usb_get_serial_port_data(port);
370 unsigned long line_state;
371 struct klsi_105_port_settings cfg;
374 dbg("%s port %d", __func__, port->number);
376 /* force low_latency on so that our tty_push actually forces
378 * port->tty->low_latency = 1; */
380 /* Do a defined restart:
381 * Set up sane default baud rate and send the 'READ_ON'
383 * FIXME: set modem line control (how?)
384 * Then read the modem line control and store values in
388 cfg.baudrate = kl5kusb105a_sio_b9600;
389 cfg.databits = kl5kusb105a_dtb_8;
392 klsi_105_chg_port_settings(port, &cfg);
394 /* set up termios structure */
395 spin_lock_irqsave (&priv->lock, flags);
396 priv->termios.c_iflag = port->tty->termios->c_iflag;
397 priv->termios.c_oflag = port->tty->termios->c_oflag;
398 priv->termios.c_cflag = port->tty->termios->c_cflag;
399 priv->termios.c_lflag = port->tty->termios->c_lflag;
400 for (i=0; i<NCCS; i++)
401 priv->termios.c_cc[i] = port->tty->termios->c_cc[i];
402 priv->cfg.pktlen = cfg.pktlen;
403 priv->cfg.baudrate = cfg.baudrate;
404 priv->cfg.databits = cfg.databits;
405 priv->cfg.unknown1 = cfg.unknown1;
406 priv->cfg.unknown2 = cfg.unknown2;
407 spin_unlock_irqrestore (&priv->lock, flags);
409 /* READ_ON and urb submission */
410 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
411 usb_rcvbulkpipe(port->serial->dev,
412 port->bulk_in_endpointAddress),
413 port->read_urb->transfer_buffer,
414 port->read_urb->transfer_buffer_length,
415 klsi_105_read_bulk_callback,
418 rc = usb_submit_urb(port->read_urb, GFP_KERNEL);
420 err("%s - failed submitting read urb, error %d", __func__, rc);
425 rc = usb_control_msg(port->serial->dev,
426 usb_sndctrlpipe(port->serial->dev,0),
427 KL5KUSB105A_SIO_CONFIGURE,
428 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
429 KL5KUSB105A_SIO_CONFIGURE_READ_ON,
435 err("Enabling read failed (error = %d)", rc);
438 dbg("%s - enabled reading", __func__);
440 rc = klsi_105_get_line_state(port, &line_state);
442 spin_lock_irqsave (&priv->lock, flags);
443 priv->line_state = line_state;
444 spin_unlock_irqrestore (&priv->lock, flags);
445 dbg("%s - read line state 0x%lx", __func__, line_state);
452 } /* klsi_105_open */
455 static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
457 struct klsi_105_private *priv = usb_get_serial_port_data(port);
460 dbg("%s port %d", __func__, port->number);
462 mutex_lock(&port->serial->disc_mutex);
463 if (!port->serial->disconnected) {
465 rc = usb_control_msg (port->serial->dev,
466 usb_sndctrlpipe(port->serial->dev, 0),
467 KL5KUSB105A_SIO_CONFIGURE,
468 USB_TYPE_VENDOR | USB_DIR_OUT,
469 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
474 err("Disabling read failed (error = %d)", rc);
476 mutex_unlock(&port->serial->disc_mutex);
478 /* shutdown our bulk reads and writes */
479 usb_kill_urb(port->write_urb);
480 usb_kill_urb(port->read_urb);
481 /* unlink our write pool */
483 /* wgg - do I need this? I think so. */
484 usb_kill_urb(port->interrupt_in_urb);
485 info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out);
486 } /* klsi_105_close */
489 /* We need to write a complete 64-byte data block and encode the
490 * number actually sent in the first double-byte, LSB-order. That
491 * leaves at most 62 bytes of payload.
493 #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
496 static int klsi_105_write (struct usb_serial_port *port,
497 const unsigned char *buf, int count)
499 struct klsi_105_private *priv = usb_get_serial_port_data(port);
503 dbg("%s - port %d", __func__, port->number);
506 /* try to find a free urb (write 0 bytes if none) */
507 struct urb *urb = NULL;
510 /* since the pool is per-port we might not need the spin lock !? */
511 spin_lock_irqsave (&priv->lock, flags);
512 for (i=0; i<NUM_URBS; i++) {
513 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
514 urb = priv->write_urb_pool[i];
515 dbg("%s - using pool URB %d", __func__, i);
519 spin_unlock_irqrestore (&priv->lock, flags);
522 dbg("%s - no more free urbs", __func__);
526 if (urb->transfer_buffer == NULL) {
527 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
528 if (urb->transfer_buffer == NULL) {
529 err("%s - no more kernel memory...", __func__);
534 size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
535 size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET);
537 memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
539 /* write payload size into transfer buffer */
540 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
541 ((__u8 *)urb->transfer_buffer)[1] = (__u8) ((size & 0xFF00)>>8);
544 usb_fill_bulk_urb(urb, port->serial->dev,
545 usb_sndbulkpipe(port->serial->dev,
546 port->bulk_out_endpointAddress),
547 urb->transfer_buffer,
548 URB_TRANSFER_BUFFER_SIZE,
549 klsi_105_write_bulk_callback,
552 /* send the data out the bulk port */
553 result = usb_submit_urb(urb, GFP_ATOMIC);
555 err("%s - failed submitting write urb, error %d", __func__, result);
563 /* lockless, but it's for debug info only... */
564 priv->bytes_out+=bytes_sent;
566 return bytes_sent; /* that's how much we wrote */
567 } /* klsi_105_write */
569 static void klsi_105_write_bulk_callback ( struct urb *urb)
571 struct usb_serial_port *port = urb->context;
572 int status = urb->status;
574 dbg("%s - port %d", __func__, port->number);
577 dbg("%s - nonzero write bulk status received: %d", __func__,
582 usb_serial_port_softint(port);
583 } /* klsi_105_write_bulk_completion_callback */
586 /* return number of characters currently in the writing process */
587 static int klsi_105_chars_in_buffer (struct usb_serial_port *port)
592 struct klsi_105_private *priv = usb_get_serial_port_data(port);
594 spin_lock_irqsave (&priv->lock, flags);
596 for (i = 0; i < NUM_URBS; ++i) {
597 if (priv->write_urb_pool[i]->status == -EINPROGRESS) {
598 chars += URB_TRANSFER_BUFFER_SIZE;
602 spin_unlock_irqrestore (&priv->lock, flags);
604 dbg("%s - returns %d", __func__, chars);
608 static int klsi_105_write_room (struct usb_serial_port *port)
613 struct klsi_105_private *priv = usb_get_serial_port_data(port);
615 spin_lock_irqsave (&priv->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->lock, flags);
624 dbg("%s - returns %d", __func__, room);
630 static void klsi_105_read_bulk_callback (struct urb *urb)
632 struct usb_serial_port *port = urb->context;
633 struct klsi_105_private *priv = usb_get_serial_port_data(port);
634 struct tty_struct *tty;
635 unsigned char *data = urb->transfer_buffer;
637 int status = urb->status;
639 dbg("%s - port %d", __func__, port->number);
641 /* The urb might have been killed. */
643 dbg("%s - nonzero read bulk status received: %d", __func__,
648 /* The data received is again preceded by a length double-byte in LSB-
649 * first order (see klsi_105_write() )
651 if (urb->actual_length == 0) {
652 /* empty urbs seem to happen, we ignore them */
653 /* dbg("%s - emtpy URB", __func__); */
655 } else if (urb->actual_length <= 2) {
656 dbg("%s - size %d URB not understood", __func__,
658 usb_serial_debug_data(debug, &port->dev, __func__,
659 urb->actual_length, data);
661 int bytes_sent = ((__u8 *) data)[0] +
662 ((unsigned int) ((__u8 *) data)[1] << 8);
664 /* we should immediately resubmit the URB, before attempting
665 * to pass the data on to the tty layer. But that needs locking
666 * against re-entry an then mixed-up data because of
667 * intermixed tty_flip_buffer_push()s
670 usb_serial_debug_data(debug, &port->dev, __func__,
671 urb->actual_length, data);
673 if (bytes_sent + 2 > urb->actual_length) {
674 dbg("%s - trying to read more data than available"
675 " (%d vs. %d)", __func__,
676 bytes_sent+2, urb->actual_length);
677 /* cap at implied limit */
678 bytes_sent = urb->actual_length - 2;
681 tty_buffer_request_room(tty, bytes_sent);
682 tty_insert_flip_string(tty, data + 2, bytes_sent);
683 tty_flip_buffer_push(tty);
685 /* again lockless, but debug info only */
686 priv->bytes_in += bytes_sent;
688 /* Continue trying to always read */
689 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
690 usb_rcvbulkpipe(port->serial->dev,
691 port->bulk_in_endpointAddress),
692 port->read_urb->transfer_buffer,
693 port->read_urb->transfer_buffer_length,
694 klsi_105_read_bulk_callback,
696 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
698 err("%s - failed resubmitting read urb, error %d", __func__, rc);
699 } /* klsi_105_read_bulk_callback */
702 static void klsi_105_set_termios (struct usb_serial_port *port,
703 struct ktermios *old_termios)
705 struct klsi_105_private *priv = usb_get_serial_port_data(port);
706 struct tty_struct *tty = port->tty;
707 unsigned int iflag = tty->termios->c_iflag;
708 unsigned int old_iflag = old_termios->c_iflag;
709 unsigned int cflag = tty->termios->c_cflag;
710 unsigned int old_cflag = old_termios->c_cflag;
711 struct klsi_105_port_settings cfg;
715 /* lock while we are modifying the settings */
716 spin_lock_irqsave (&priv->lock, flags);
721 baud = tty_get_baud_rate(tty);
723 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) {
724 /* reassert DTR and (maybe) RTS on transition from B0 */
725 if( (old_cflag & CBAUD) == B0 ) {
726 dbg("%s: baud was B0", __func__);
728 priv->control_state |= TIOCM_DTR;
729 /* don't set RTS if using hardware flow control */
730 if (!(old_cflag & CRTSCTS)) {
731 priv->control_state |= TIOCM_RTS;
733 mct_u232_set_modem_ctrl(serial, priv->control_state);
738 case 0: /* handled below */
741 priv->cfg.baudrate = kl5kusb105a_sio_b1200;
744 priv->cfg.baudrate = kl5kusb105a_sio_b2400;
747 priv->cfg.baudrate = kl5kusb105a_sio_b4800;
750 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
753 priv->cfg.baudrate = kl5kusb105a_sio_b19200;
756 priv->cfg.baudrate = kl5kusb105a_sio_b38400;
759 priv->cfg.baudrate = kl5kusb105a_sio_b57600;
762 priv->cfg.baudrate = kl5kusb105a_sio_b115200;
765 dbg("KLSI USB->Serial converter:"
766 " unsupported baudrate request, using default"
768 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
772 if ((cflag & CBAUD) == B0 ) {
773 dbg("%s: baud is B0", __func__);
774 /* Drop RTS and DTR */
775 /* maybe this should be simulated by sending read
776 * disable and read enable messages?
780 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
781 mct_u232_set_modem_ctrl(serial, priv->control_state);
784 tty_encode_baud_rate(tty, baud, baud);
786 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
787 /* set the number of data bits */
788 switch (cflag & CSIZE) {
790 dbg("%s - 5 bits/byte not supported", __func__);
791 spin_unlock_irqrestore (&priv->lock, flags);
794 dbg("%s - 6 bits/byte not supported", __func__);
795 spin_unlock_irqrestore (&priv->lock, flags);
798 priv->cfg.databits = kl5kusb105a_dtb_7;
801 priv->cfg.databits = kl5kusb105a_dtb_8;
804 err("CSIZE was not CS5-CS8, using default of 8");
805 priv->cfg.databits = kl5kusb105a_dtb_8;
811 * Update line control register (LCR)
813 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
814 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) {
816 /* Not currently supported */
817 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB);
823 priv->last_lcr |= (cflag & PARODD) ?
824 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
826 priv->last_lcr |= MCT_U232_PARITY_NONE;
828 /* set the number of stop bits */
829 priv->last_lcr |= (cflag & CSTOPB) ?
830 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
832 mct_u232_set_line_ctrl(serial, priv->last_lcr);
838 * Set flow control: well, I do not really now how to handle DTR/RTS.
839 * Just do what we have seen with SniffUSB on Win98.
841 if( (iflag & IXOFF) != (old_iflag & IXOFF)
842 || (iflag & IXON) != (old_iflag & IXON)
843 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) {
845 /* Not currently supported */
846 tty->termios->c_cflag &= ~CRTSCTS;
847 /* Drop DTR/RTS if no flow control otherwise assert */
849 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) )
850 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
852 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
853 mct_u232_set_modem_ctrl(serial, priv->control_state);
857 memcpy (&cfg, &priv->cfg, sizeof(cfg));
858 spin_unlock_irqrestore (&priv->lock, flags);
860 /* now commit changes to device */
861 klsi_105_chg_port_settings(port, &cfg);
862 } /* klsi_105_set_termios */
866 static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
868 struct usb_serial *serial = port->serial;
869 struct mct_u232_private *priv = (struct mct_u232_private *)port->private;
870 unsigned char lcr = priv->last_lcr;
872 dbg("%sstate=%d", __func__, break_state);
875 lcr |= MCT_U232_SET_BREAK;
877 mct_u232_set_line_ctrl(serial, lcr);
878 } /* mct_u232_break_ctl */
881 static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file)
883 struct klsi_105_private *priv = usb_get_serial_port_data(port);
886 unsigned long line_state;
887 dbg("%s - request, just guessing", __func__);
889 rc = klsi_105_get_line_state(port, &line_state);
891 err("Reading line control failed (error = %d)", rc);
892 /* better return value? EAGAIN? */
896 spin_lock_irqsave (&priv->lock, flags);
897 priv->line_state = line_state;
898 spin_unlock_irqrestore (&priv->lock, flags);
899 dbg("%s - read line state 0x%lx", __func__, line_state);
900 return (int)line_state;
903 static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
904 unsigned int set, unsigned int clear)
906 int retval = -EINVAL;
910 /* if this ever gets implemented, it should be done something like this:
911 struct usb_serial *serial = port->serial;
912 struct klsi_105_private *priv = usb_get_serial_port_data(port);
916 spin_lock_irqsave (&priv->lock, flags);
918 priv->control_state |= TIOCM_RTS;
920 priv->control_state |= TIOCM_DTR;
921 if (clear & TIOCM_RTS)
922 priv->control_state &= ~TIOCM_RTS;
923 if (clear & TIOCM_DTR)
924 priv->control_state &= ~TIOCM_DTR;
925 control = priv->control_state;
926 spin_unlock_irqrestore (&priv->lock, flags);
927 retval = mct_u232_set_modem_ctrl(serial, control);
932 static void klsi_105_throttle (struct usb_serial_port *port)
934 dbg("%s - port %d", __func__, port->number);
935 usb_kill_urb(port->read_urb);
938 static void klsi_105_unthrottle (struct usb_serial_port *port)
942 dbg("%s - port %d", __func__, port->number);
944 port->read_urb->dev = port->serial->dev;
945 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
947 err("%s - failed submitting read urb, error %d", __func__,
953 static int __init klsi_105_init (void)
956 retval = usb_serial_register(&kl5kusb105d_device);
958 goto failed_usb_serial_register;
959 retval = usb_register(&kl5kusb105d_driver);
961 goto failed_usb_register;
963 info(DRIVER_DESC " " DRIVER_VERSION);
966 usb_serial_deregister(&kl5kusb105d_device);
967 failed_usb_serial_register:
972 static void __exit klsi_105_exit (void)
974 usb_deregister (&kl5kusb105d_driver);
975 usb_serial_deregister (&kl5kusb105d_device);
979 module_init (klsi_105_init);
980 module_exit (klsi_105_exit);
982 MODULE_AUTHOR( DRIVER_AUTHOR );
983 MODULE_DESCRIPTION( DRIVER_DESC );
984 MODULE_LICENSE("GPL");
987 module_param(debug, bool, S_IRUGO | S_IWUSR);
988 MODULE_PARM_DESC(debug, "enable extensive debugging messages");
990 /* vim: set sts=8 ts=8 sw=8: */