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 <linux/usb.h>
58 #include <linux/usb/serial.h>
59 #include "kl5kusb105.h"
66 #define DRIVER_VERSION "v0.3a"
67 #define DRIVER_AUTHOR "Utz-Uwe Haus <haus@uuhaus.de>"
68 #define DRIVER_DESC "KLSI KL5KUSB105 chipset USB->Serial Converter driver"
74 static int klsi_105_startup (struct usb_serial *serial);
75 static void klsi_105_shutdown (struct usb_serial *serial);
76 static int klsi_105_open (struct usb_serial_port *port,
78 static void klsi_105_close (struct usb_serial_port *port,
80 static int klsi_105_write (struct usb_serial_port *port,
81 const unsigned char *buf,
83 static void klsi_105_write_bulk_callback (struct urb *urb);
84 static int klsi_105_chars_in_buffer (struct usb_serial_port *port);
85 static int klsi_105_write_room (struct usb_serial_port *port);
87 static void klsi_105_read_bulk_callback (struct urb *urb);
88 static void klsi_105_set_termios (struct usb_serial_port *port,
89 struct ktermios *old);
90 static void klsi_105_throttle (struct usb_serial_port *port);
91 static void klsi_105_unthrottle (struct usb_serial_port *port);
93 static void klsi_105_break_ctl (struct usb_serial_port *port,
96 static int klsi_105_tiocmget (struct usb_serial_port *port,
98 static int klsi_105_tiocmset (struct usb_serial_port *port,
99 struct file *file, unsigned int set,
103 * All of the device info needed for the KLSI converters.
105 static struct usb_device_id id_table [] = {
106 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) },
107 { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) },
108 { } /* Terminating entry */
111 MODULE_DEVICE_TABLE (usb, id_table);
113 static struct usb_driver kl5kusb105d_driver = {
114 .name = "kl5kusb105d",
115 .probe = usb_serial_probe,
116 .disconnect = usb_serial_disconnect,
117 .id_table = id_table,
121 static struct usb_serial_driver kl5kusb105d_device = {
123 .owner = THIS_MODULE,
124 .name = "kl5kusb105d",
126 .description = "KL5KUSB105D / PalmConnect",
127 .usb_driver = &kl5kusb105d_driver,
128 .id_table = id_table,
129 .num_interrupt_in = 1,
133 .open = klsi_105_open,
134 .close = klsi_105_close,
135 .write = klsi_105_write,
136 .write_bulk_callback = klsi_105_write_bulk_callback,
137 .chars_in_buffer = klsi_105_chars_in_buffer,
138 .write_room = klsi_105_write_room,
139 .read_bulk_callback =klsi_105_read_bulk_callback,
140 .set_termios = klsi_105_set_termios,
141 /*.break_ctl = klsi_105_break_ctl,*/
142 .tiocmget = klsi_105_tiocmget,
143 .tiocmset = klsi_105_tiocmset,
144 .attach = klsi_105_startup,
145 .shutdown = klsi_105_shutdown,
146 .throttle = klsi_105_throttle,
147 .unthrottle = klsi_105_unthrottle,
150 struct klsi_105_port_settings {
151 __u8 pktlen; /* always 5, it seems */
156 } __attribute__ ((packed));
158 /* we implement a pool of NUM_URBS urbs per usb_serial */
160 #define URB_TRANSFER_BUFFER_SIZE 64
161 struct klsi_105_private {
162 struct klsi_105_port_settings cfg;
163 struct ktermios termios;
164 unsigned long line_state; /* modem line settings */
166 struct urb * write_urb_pool[NUM_URBS];
168 unsigned long bytes_in;
169 unsigned long bytes_out;
174 * Handle vendor specific USB requests
178 #define KLSI_TIMEOUT 5000 /* default urb timeout */
180 static int klsi_105_chg_port_settings(struct usb_serial_port *port,
181 struct klsi_105_port_settings *settings)
185 rc = usb_control_msg(port->serial->dev,
186 usb_sndctrlpipe(port->serial->dev, 0),
187 KL5KUSB105A_SIO_SET_DATA,
188 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
192 sizeof(struct klsi_105_port_settings),
195 err("Change port settings failed (error = %d)", rc);
196 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
199 settings->baudrate, settings->databits,
200 settings->unknown1, settings->unknown2);
202 } /* klsi_105_chg_port_settings */
204 /* translate a 16-bit status value from the device to linux's TIO bits */
205 static unsigned long klsi_105_status2linestate(const __u16 status)
207 unsigned long res = 0;
209 res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0)
210 | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0)
216 * Read line control via vendor command and return result through
219 /* It seems that the status buffer has always only 2 bytes length */
220 #define KLSI_STATUSBUF_LEN 2
221 static int klsi_105_get_line_state(struct usb_serial_port *port,
222 unsigned long *line_state_p)
225 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1};
228 info("%s - sending SIO Poll request", __FUNCTION__);
229 rc = usb_control_msg(port->serial->dev,
230 usb_rcvctrlpipe(port->serial->dev, 0),
231 KL5KUSB105A_SIO_POLL,
232 USB_TYPE_VENDOR | USB_DIR_IN,
235 status_buf, KLSI_STATUSBUF_LEN,
239 err("Reading line status failed (error = %d)", rc);
241 status = le16_to_cpu(*(u16 *)status_buf);
243 info("%s - read status %x %x", __FUNCTION__,
244 status_buf[0], status_buf[1]);
246 *line_state_p = klsi_105_status2linestate(status);
254 * Driver's tty interface functions
257 static int klsi_105_startup (struct usb_serial *serial)
259 struct klsi_105_private *priv;
262 /* check if we support the product id (see keyspan.c)
266 /* allocate the private data structure */
267 for (i=0; i<serial->num_ports; i++) {
268 priv = kmalloc(sizeof(struct klsi_105_private),
271 dbg("%skmalloc for klsi_105_private failed.", __FUNCTION__);
275 /* set initial values for control structures */
276 priv->cfg.pktlen = 5;
277 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
278 priv->cfg.databits = kl5kusb105a_dtb_8;
279 priv->cfg.unknown1 = 0;
280 priv->cfg.unknown2 = 1;
282 priv->line_state = 0;
286 usb_set_serial_port_data(serial->port[i], priv);
288 spin_lock_init (&priv->lock);
289 for (j=0; j<NUM_URBS; j++) {
290 struct urb* urb = usb_alloc_urb(0, GFP_KERNEL);
292 priv->write_urb_pool[j] = urb;
294 err("No more urbs???");
298 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE,
300 if (!urb->transfer_buffer) {
301 err("%s - out of memory for urb buffers.", __FUNCTION__);
306 /* priv->termios is left uninitalized until port opening */
307 init_waitqueue_head(&serial->port[i]->write_wait);
313 for (; i >= 0; i--) {
314 priv = usb_get_serial_port_data(serial->port[i]);
315 for (j=0; j < NUM_URBS; j++) {
316 if (priv->write_urb_pool[j]) {
317 kfree(priv->write_urb_pool[j]->transfer_buffer);
318 usb_free_urb(priv->write_urb_pool[j]);
321 usb_set_serial_port_data(serial->port[i], NULL);
324 } /* klsi_105_startup */
327 static void klsi_105_shutdown (struct usb_serial *serial)
331 dbg("%s", __FUNCTION__);
333 /* stop reads and writes on all ports */
334 for (i=0; i < serial->num_ports; ++i) {
335 struct klsi_105_private *priv = usb_get_serial_port_data(serial->port[i]);
339 /* kill our write urb pool */
341 struct urb **write_urbs = priv->write_urb_pool;
342 spin_lock_irqsave(&priv->lock,flags);
344 for (j = 0; j < NUM_URBS; j++) {
346 /* FIXME - uncomment the following
347 * usb_kill_urb call when the host
348 * controllers get fixed to set
349 * urb->dev = NULL after the urb is
350 * finished. Otherwise this call
352 /* usb_kill_urb(write_urbs[j]); */
353 kfree(write_urbs[j]->transfer_buffer);
354 usb_free_urb (write_urbs[j]);
358 spin_unlock_irqrestore (&priv->lock, flags);
361 usb_set_serial_port_data(serial->port[i], NULL);
364 } /* klsi_105_shutdown */
366 static int klsi_105_open (struct usb_serial_port *port, struct file *filp)
368 struct klsi_105_private *priv = usb_get_serial_port_data(port);
372 unsigned long line_state;
373 struct klsi_105_port_settings cfg;
376 dbg("%s port %d", __FUNCTION__, port->number);
378 /* force low_latency on so that our tty_push actually forces
380 * port->tty->low_latency = 1; */
382 /* Do a defined restart:
383 * Set up sane default baud rate and send the 'READ_ON'
385 * FIXME: set modem line control (how?)
386 * Then read the modem line control and store values in
390 cfg.baudrate = kl5kusb105a_sio_b9600;
391 cfg.databits = kl5kusb105a_dtb_8;
394 klsi_105_chg_port_settings(port, &cfg);
396 /* set up termios structure */
397 spin_lock_irqsave (&priv->lock, flags);
398 priv->termios.c_iflag = port->tty->termios->c_iflag;
399 priv->termios.c_oflag = port->tty->termios->c_oflag;
400 priv->termios.c_cflag = port->tty->termios->c_cflag;
401 priv->termios.c_lflag = port->tty->termios->c_lflag;
402 for (i=0; i<NCCS; i++)
403 priv->termios.c_cc[i] = port->tty->termios->c_cc[i];
404 priv->cfg.pktlen = cfg.pktlen;
405 priv->cfg.baudrate = cfg.baudrate;
406 priv->cfg.databits = cfg.databits;
407 priv->cfg.unknown1 = cfg.unknown1;
408 priv->cfg.unknown2 = cfg.unknown2;
409 spin_unlock_irqrestore (&priv->lock, flags);
411 /* READ_ON and urb submission */
412 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
413 usb_rcvbulkpipe(port->serial->dev,
414 port->bulk_in_endpointAddress),
415 port->read_urb->transfer_buffer,
416 port->read_urb->transfer_buffer_length,
417 klsi_105_read_bulk_callback,
420 rc = usb_submit_urb(port->read_urb, GFP_KERNEL);
422 err("%s - failed submitting read urb, error %d", __FUNCTION__, rc);
427 rc = usb_control_msg(port->serial->dev,
428 usb_sndctrlpipe(port->serial->dev,0),
429 KL5KUSB105A_SIO_CONFIGURE,
430 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
431 KL5KUSB105A_SIO_CONFIGURE_READ_ON,
437 err("Enabling read failed (error = %d)", rc);
440 dbg("%s - enabled reading", __FUNCTION__);
442 rc = klsi_105_get_line_state(port, &line_state);
444 spin_lock_irqsave (&priv->lock, flags);
445 priv->line_state = line_state;
446 spin_unlock_irqrestore (&priv->lock, flags);
447 dbg("%s - read line state 0x%lx", __FUNCTION__, line_state);
454 } /* klsi_105_open */
457 static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
459 struct klsi_105_private *priv = usb_get_serial_port_data(port);
462 dbg("%s port %d", __FUNCTION__, port->number);
464 mutex_lock(&port->serial->disc_mutex);
465 if (!port->serial->disconnected) {
467 rc = usb_control_msg (port->serial->dev,
468 usb_sndctrlpipe(port->serial->dev, 0),
469 KL5KUSB105A_SIO_CONFIGURE,
470 USB_TYPE_VENDOR | USB_DIR_OUT,
471 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
476 err("Disabling read failed (error = %d)", rc);
478 mutex_unlock(&port->serial->disc_mutex);
480 /* shutdown our bulk reads and writes */
481 usb_kill_urb(port->write_urb);
482 usb_kill_urb(port->read_urb);
483 /* unlink our write pool */
485 /* wgg - do I need this? I think so. */
486 usb_kill_urb(port->interrupt_in_urb);
487 info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out);
488 } /* klsi_105_close */
491 /* We need to write a complete 64-byte data block and encode the
492 * number actually sent in the first double-byte, LSB-order. That
493 * leaves at most 62 bytes of payload.
495 #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
498 static int klsi_105_write (struct usb_serial_port *port,
499 const unsigned char *buf, int count)
501 struct klsi_105_private *priv = usb_get_serial_port_data(port);
505 dbg("%s - port %d", __FUNCTION__, port->number);
508 /* try to find a free urb (write 0 bytes if none) */
509 struct urb *urb = NULL;
512 /* since the pool is per-port we might not need the spin lock !? */
513 spin_lock_irqsave (&priv->lock, flags);
514 for (i=0; i<NUM_URBS; i++) {
515 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
516 urb = priv->write_urb_pool[i];
517 dbg("%s - using pool URB %d", __FUNCTION__, i);
521 spin_unlock_irqrestore (&priv->lock, flags);
524 dbg("%s - no more free urbs", __FUNCTION__);
528 if (urb->transfer_buffer == NULL) {
529 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
530 if (urb->transfer_buffer == NULL) {
531 err("%s - no more kernel memory...", __FUNCTION__);
536 size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
537 size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET);
539 memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
541 /* write payload size into transfer buffer */
542 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
543 ((__u8 *)urb->transfer_buffer)[1] = (__u8) ((size & 0xFF00)>>8);
546 usb_fill_bulk_urb(urb, port->serial->dev,
547 usb_sndbulkpipe(port->serial->dev,
548 port->bulk_out_endpointAddress),
549 urb->transfer_buffer,
550 URB_TRANSFER_BUFFER_SIZE,
551 klsi_105_write_bulk_callback,
554 /* send the data out the bulk port */
555 result = usb_submit_urb(urb, GFP_ATOMIC);
557 err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
565 /* lockless, but it's for debug info only... */
566 priv->bytes_out+=bytes_sent;
568 return bytes_sent; /* that's how much we wrote */
569 } /* klsi_105_write */
571 static void klsi_105_write_bulk_callback ( struct urb *urb)
573 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
574 int status = urb->status;
576 dbg("%s - port %d", __FUNCTION__, port->number);
579 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__,
584 usb_serial_port_softint(port);
585 } /* klsi_105_write_bulk_completion_callback */
588 /* return number of characters currently in the writing process */
589 static int klsi_105_chars_in_buffer (struct usb_serial_port *port)
594 struct klsi_105_private *priv = usb_get_serial_port_data(port);
596 spin_lock_irqsave (&priv->lock, flags);
598 for (i = 0; i < NUM_URBS; ++i) {
599 if (priv->write_urb_pool[i]->status == -EINPROGRESS) {
600 chars += URB_TRANSFER_BUFFER_SIZE;
604 spin_unlock_irqrestore (&priv->lock, flags);
606 dbg("%s - returns %d", __FUNCTION__, chars);
610 static int klsi_105_write_room (struct usb_serial_port *port)
615 struct klsi_105_private *priv = usb_get_serial_port_data(port);
617 spin_lock_irqsave (&priv->lock, flags);
618 for (i = 0; i < NUM_URBS; ++i) {
619 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
620 room += URB_TRANSFER_BUFFER_SIZE;
624 spin_unlock_irqrestore (&priv->lock, flags);
626 dbg("%s - returns %d", __FUNCTION__, room);
632 static void klsi_105_read_bulk_callback (struct urb *urb)
634 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
635 struct klsi_105_private *priv = usb_get_serial_port_data(port);
636 struct tty_struct *tty;
637 unsigned char *data = urb->transfer_buffer;
639 int status = urb->status;
641 dbg("%s - port %d", __FUNCTION__, port->number);
643 /* The urb might have been killed. */
645 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__,
650 /* The data received is again preceded by a length double-byte in LSB-
651 * first order (see klsi_105_write() )
653 if (urb->actual_length == 0) {
654 /* empty urbs seem to happen, we ignore them */
655 /* dbg("%s - emtpy URB", __FUNCTION__); */
657 } else if (urb->actual_length <= 2) {
658 dbg("%s - size %d URB not understood", __FUNCTION__,
660 usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
661 urb->actual_length, data);
663 int bytes_sent = ((__u8 *) data)[0] +
664 ((unsigned int) ((__u8 *) data)[1] << 8);
666 /* we should immediately resubmit the URB, before attempting
667 * to pass the data on to the tty layer. But that needs locking
668 * against re-entry an then mixed-up data because of
669 * intermixed tty_flip_buffer_push()s
672 usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
673 urb->actual_length, data);
675 if (bytes_sent + 2 > urb->actual_length) {
676 dbg("%s - trying to read more data than available"
677 " (%d vs. %d)", __FUNCTION__,
678 bytes_sent+2, urb->actual_length);
679 /* cap at implied limit */
680 bytes_sent = urb->actual_length - 2;
683 tty_buffer_request_room(tty, bytes_sent);
684 tty_insert_flip_string(tty, data + 2, bytes_sent);
685 tty_flip_buffer_push(tty);
687 /* again lockless, but debug info only */
688 priv->bytes_in += bytes_sent;
690 /* Continue trying to always read */
691 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
692 usb_rcvbulkpipe(port->serial->dev,
693 port->bulk_in_endpointAddress),
694 port->read_urb->transfer_buffer,
695 port->read_urb->transfer_buffer_length,
696 klsi_105_read_bulk_callback,
698 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
700 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, rc);
701 } /* klsi_105_read_bulk_callback */
704 static void klsi_105_set_termios (struct usb_serial_port *port,
705 struct ktermios *old_termios)
707 struct klsi_105_private *priv = usb_get_serial_port_data(port);
708 unsigned int iflag = port->tty->termios->c_iflag;
709 unsigned int old_iflag = old_termios->c_iflag;
710 unsigned int cflag = port->tty->termios->c_cflag;
711 unsigned int old_cflag = old_termios->c_cflag;
712 struct klsi_105_port_settings cfg;
715 /* lock while we are modifying the settings */
716 spin_lock_irqsave (&priv->lock, flags);
721 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) {
722 /* reassert DTR and (maybe) RTS on transition from B0 */
723 if( (old_cflag & CBAUD) == B0 ) {
724 dbg("%s: baud was B0", __FUNCTION__);
726 priv->control_state |= TIOCM_DTR;
727 /* don't set RTS if using hardware flow control */
728 if (!(old_cflag & CRTSCTS)) {
729 priv->control_state |= TIOCM_RTS;
731 mct_u232_set_modem_ctrl(serial, priv->control_state);
735 switch(tty_get_baud_rate(port->tty)) {
736 case 0: /* handled below */
739 priv->cfg.baudrate = kl5kusb105a_sio_b1200;
742 priv->cfg.baudrate = kl5kusb105a_sio_b2400;
745 priv->cfg.baudrate = kl5kusb105a_sio_b4800;
748 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
751 priv->cfg.baudrate = kl5kusb105a_sio_b19200;
754 priv->cfg.baudrate = kl5kusb105a_sio_b38400;
757 priv->cfg.baudrate = kl5kusb105a_sio_b57600;
760 priv->cfg.baudrate = kl5kusb105a_sio_b115200;
763 err("KLSI USB->Serial converter:"
764 " unsupported baudrate request, using default"
766 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
769 if ((cflag & CBAUD) == B0 ) {
770 dbg("%s: baud is B0", __FUNCTION__);
771 /* Drop RTS and DTR */
772 /* maybe this should be simulated by sending read
773 * disable and read enable messages?
777 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
778 mct_u232_set_modem_ctrl(serial, priv->control_state);
783 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
784 /* set the number of data bits */
785 switch (cflag & CSIZE) {
787 dbg("%s - 5 bits/byte not supported", __FUNCTION__);
788 spin_unlock_irqrestore (&priv->lock, flags);
791 dbg("%s - 6 bits/byte not supported", __FUNCTION__);
792 spin_unlock_irqrestore (&priv->lock, flags);
795 priv->cfg.databits = kl5kusb105a_dtb_7;
798 priv->cfg.databits = kl5kusb105a_dtb_8;
801 err("CSIZE was not CS5-CS8, using default of 8");
802 priv->cfg.databits = kl5kusb105a_dtb_8;
808 * Update line control register (LCR)
810 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
811 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) {
818 priv->last_lcr |= (cflag & PARODD) ?
819 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
821 priv->last_lcr |= MCT_U232_PARITY_NONE;
823 /* set the number of stop bits */
824 priv->last_lcr |= (cflag & CSTOPB) ?
825 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
827 mct_u232_set_line_ctrl(serial, priv->last_lcr);
833 * Set flow control: well, I do not really now how to handle DTR/RTS.
834 * Just do what we have seen with SniffUSB on Win98.
836 if( (iflag & IXOFF) != (old_iflag & IXOFF)
837 || (iflag & IXON) != (old_iflag & IXON)
838 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) {
840 /* Drop DTR/RTS if no flow control otherwise assert */
842 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) )
843 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
845 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
846 mct_u232_set_modem_ctrl(serial, priv->control_state);
850 memcpy (&cfg, &priv->cfg, sizeof(cfg));
851 spin_unlock_irqrestore (&priv->lock, flags);
853 /* now commit changes to device */
854 klsi_105_chg_port_settings(port, &cfg);
855 } /* klsi_105_set_termios */
859 static void mct_u232_break_ctl( struct usb_serial_port *port, int break_state )
861 struct usb_serial *serial = port->serial;
862 struct mct_u232_private *priv = (struct mct_u232_private *)port->private;
863 unsigned char lcr = priv->last_lcr;
865 dbg("%sstate=%d", __FUNCTION__, break_state);
868 lcr |= MCT_U232_SET_BREAK;
870 mct_u232_set_line_ctrl(serial, lcr);
871 } /* mct_u232_break_ctl */
874 static int klsi_105_tiocmget (struct usb_serial_port *port, struct file *file)
876 struct klsi_105_private *priv = usb_get_serial_port_data(port);
879 unsigned long line_state;
880 dbg("%s - request, just guessing", __FUNCTION__);
882 rc = klsi_105_get_line_state(port, &line_state);
884 err("Reading line control failed (error = %d)", rc);
885 /* better return value? EAGAIN? */
889 spin_lock_irqsave (&priv->lock, flags);
890 priv->line_state = line_state;
891 spin_unlock_irqrestore (&priv->lock, flags);
892 dbg("%s - read line state 0x%lx", __FUNCTION__, line_state);
893 return (int)line_state;
896 static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
897 unsigned int set, unsigned int clear)
899 int retval = -EINVAL;
901 dbg("%s", __FUNCTION__);
903 /* if this ever gets implemented, it should be done something like this:
904 struct usb_serial *serial = port->serial;
905 struct klsi_105_private *priv = usb_get_serial_port_data(port);
909 spin_lock_irqsave (&priv->lock, flags);
911 priv->control_state |= TIOCM_RTS;
913 priv->control_state |= TIOCM_DTR;
914 if (clear & TIOCM_RTS)
915 priv->control_state &= ~TIOCM_RTS;
916 if (clear & TIOCM_DTR)
917 priv->control_state &= ~TIOCM_DTR;
918 control = priv->control_state;
919 spin_unlock_irqrestore (&priv->lock, flags);
920 retval = mct_u232_set_modem_ctrl(serial, control);
925 static void klsi_105_throttle (struct usb_serial_port *port)
927 dbg("%s - port %d", __FUNCTION__, port->number);
928 usb_kill_urb(port->read_urb);
931 static void klsi_105_unthrottle (struct usb_serial_port *port)
935 dbg("%s - port %d", __FUNCTION__, port->number);
937 port->read_urb->dev = port->serial->dev;
938 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
940 err("%s - failed submitting read urb, error %d", __FUNCTION__,
946 static int __init klsi_105_init (void)
949 retval = usb_serial_register(&kl5kusb105d_device);
951 goto failed_usb_serial_register;
952 retval = usb_register(&kl5kusb105d_driver);
954 goto failed_usb_register;
956 info(DRIVER_DESC " " DRIVER_VERSION);
959 usb_serial_deregister(&kl5kusb105d_device);
960 failed_usb_serial_register:
965 static void __exit klsi_105_exit (void)
967 usb_deregister (&kl5kusb105d_driver);
968 usb_serial_deregister (&kl5kusb105d_device);
972 module_init (klsi_105_init);
973 module_exit (klsi_105_exit);
975 MODULE_AUTHOR( DRIVER_AUTHOR );
976 MODULE_DESCRIPTION( DRIVER_DESC );
977 MODULE_LICENSE("GPL");
980 module_param(debug, bool, S_IRUGO | S_IWUSR);
981 MODULE_PARM_DESC(debug, "enable extensive debugging messages");
983 /* vim: set sts=8 ts=8 sw=8: */