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 tty_struct *tty,
78 struct usb_serial_port *port,
80 static void klsi_105_close (struct tty_struct *tty,
81 struct usb_serial_port *port,
83 static int klsi_105_write (struct tty_struct *tty,
84 struct usb_serial_port *port,
85 const unsigned char *buf,
87 static void klsi_105_write_bulk_callback (struct urb *urb);
88 static int klsi_105_chars_in_buffer (struct tty_struct *tty);
89 static int klsi_105_write_room (struct tty_struct *tty);
91 static void klsi_105_read_bulk_callback (struct urb *urb);
92 static void klsi_105_set_termios (struct tty_struct *tty,
93 struct usb_serial_port *port,
94 struct ktermios *old);
95 static void klsi_105_throttle (struct tty_struct *tty);
96 static void klsi_105_unthrottle (struct tty_struct *tty);
98 static void klsi_105_break_ctl (struct tty_struct *tty,
101 static int klsi_105_tiocmget (struct tty_struct *tty,
103 static int klsi_105_tiocmset (struct tty_struct *tty,
104 struct file *file, unsigned int set,
108 * All of the device info needed for the KLSI converters.
110 static struct usb_device_id id_table [] = {
111 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) },
112 { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) },
113 { } /* Terminating entry */
116 MODULE_DEVICE_TABLE (usb, id_table);
118 static struct usb_driver kl5kusb105d_driver = {
119 .name = "kl5kusb105d",
120 .probe = usb_serial_probe,
121 .disconnect = usb_serial_disconnect,
122 .id_table = id_table,
126 static struct usb_serial_driver kl5kusb105d_device = {
128 .owner = THIS_MODULE,
129 .name = "kl5kusb105d",
131 .description = "KL5KUSB105D / PalmConnect",
132 .usb_driver = &kl5kusb105d_driver,
133 .id_table = id_table,
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,
142 .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,
152 struct klsi_105_port_settings {
153 __u8 pktlen; /* always 5, it seems */
158 } __attribute__ ((packed));
160 /* we implement a pool of NUM_URBS urbs per usb_serial */
162 #define URB_TRANSFER_BUFFER_SIZE 64
163 struct klsi_105_private {
164 struct klsi_105_port_settings cfg;
165 struct ktermios termios;
166 unsigned long line_state; /* modem line settings */
168 struct urb * write_urb_pool[NUM_URBS];
170 unsigned long bytes_in;
171 unsigned long bytes_out;
176 * Handle vendor specific USB requests
180 #define KLSI_TIMEOUT 5000 /* default urb timeout */
182 static int klsi_105_chg_port_settings(struct usb_serial_port *port,
183 struct klsi_105_port_settings *settings)
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,
194 sizeof(struct klsi_105_port_settings),
197 err("Change port settings failed (error = %d)", rc);
198 info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
201 settings->baudrate, settings->databits,
202 settings->unknown1, settings->unknown2);
204 } /* klsi_105_chg_port_settings */
206 /* translate a 16-bit status value from the device to linux's TIO bits */
207 static unsigned long klsi_105_status2linestate(const __u16 status)
209 unsigned long res = 0;
211 res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0)
212 | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0)
218 * Read line control via vendor command and return result through
221 /* It seems that the status buffer has always only 2 bytes length */
222 #define KLSI_STATUSBUF_LEN 2
223 static int klsi_105_get_line_state(struct usb_serial_port *port,
224 unsigned long *line_state_p)
227 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1};
230 info("%s - sending SIO Poll request", __func__);
231 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,
237 status_buf, KLSI_STATUSBUF_LEN,
241 err("Reading line status failed (error = %d)", rc);
243 status = get_unaligned_le16(status_buf);
245 info("%s - read status %x %x", __func__,
246 status_buf[0], status_buf[1]);
248 *line_state_p = klsi_105_status2linestate(status);
256 * Driver's tty interface functions
259 static int klsi_105_startup (struct usb_serial *serial)
261 struct klsi_105_private *priv;
264 /* check if we support the product id (see keyspan.c)
268 /* allocate the private data structure */
269 for (i=0; i<serial->num_ports; i++) {
270 priv = kmalloc(sizeof(struct klsi_105_private),
273 dbg("%skmalloc for klsi_105_private failed.", __func__);
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;
284 priv->line_state = 0;
288 usb_set_serial_port_data(serial->port[i], priv);
290 spin_lock_init (&priv->lock);
291 for (j=0; j<NUM_URBS; j++) {
292 struct urb* urb = usb_alloc_urb(0, GFP_KERNEL);
294 priv->write_urb_pool[j] = urb;
296 err("No more urbs???");
300 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE,
302 if (!urb->transfer_buffer) {
303 err("%s - out of memory for urb buffers.", __func__);
308 /* priv->termios is left uninitalized until port opening */
309 init_waitqueue_head(&serial->port[i]->write_wait);
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]);
323 usb_set_serial_port_data(serial->port[i], NULL);
326 } /* klsi_105_startup */
329 static void klsi_105_shutdown (struct usb_serial *serial)
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]);
341 /* kill our write urb pool */
343 struct urb **write_urbs = priv->write_urb_pool;
344 spin_lock_irqsave(&priv->lock,flags);
346 for (j = 0; j < NUM_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
354 /* usb_kill_urb(write_urbs[j]); */
355 kfree(write_urbs[j]->transfer_buffer);
356 usb_free_urb (write_urbs[j]);
360 spin_unlock_irqrestore (&priv->lock, flags);
363 usb_set_serial_port_data(serial->port[i], NULL);
366 } /* klsi_105_shutdown */
368 static int klsi_105_open(struct tty_struct *tty,
369 struct usb_serial_port *port, struct file *filp)
371 struct klsi_105_private *priv = usb_get_serial_port_data(port);
375 unsigned long line_state;
376 struct klsi_105_port_settings cfg;
379 dbg("%s port %d", __func__, port->number);
381 /* force low_latency on so that our tty_push actually forces
383 * tty->low_latency = 1; */
385 /* Do a defined restart:
386 * Set up sane default baud rate and send the 'READ_ON'
388 * FIXME: set modem line control (how?)
389 * Then read the modem line control and store values in
393 cfg.baudrate = kl5kusb105a_sio_b9600;
394 cfg.databits = kl5kusb105a_dtb_8;
397 klsi_105_chg_port_settings(port, &cfg);
399 /* set up termios structure */
400 spin_lock_irqsave (&priv->lock, flags);
401 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;
405 for (i=0; i<NCCS; i++)
406 priv->termios.c_cc[i] = tty->termios->c_cc[i];
407 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);
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,
423 rc = usb_submit_urb(port->read_urb, GFP_KERNEL);
425 err("%s - failed submitting read urb, error %d", __func__, rc);
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,
440 err("Enabling read failed (error = %d)", rc);
443 dbg("%s - enabled reading", __func__);
445 rc = klsi_105_get_line_state(port, &line_state);
447 spin_lock_irqsave (&priv->lock, flags);
448 priv->line_state = line_state;
449 spin_unlock_irqrestore (&priv->lock, flags);
450 dbg("%s - read line state 0x%lx", __func__, line_state);
457 } /* klsi_105_open */
460 static void klsi_105_close(struct tty_struct *tty,
461 struct usb_serial_port *port, struct file *filp)
463 struct klsi_105_private *priv = usb_get_serial_port_data(port);
466 dbg("%s port %d", __func__, port->number);
468 mutex_lock(&port->serial->disc_mutex);
469 if (!port->serial->disconnected) {
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,
480 err("Disabling read failed (error = %d)", rc);
482 mutex_unlock(&port->serial->disc_mutex);
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 */
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 */
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.
499 #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
502 static int klsi_105_write(struct tty_struct *tty,
503 struct usb_serial_port *port, const unsigned char *buf, int count)
505 struct klsi_105_private *priv = usb_get_serial_port_data(port);
509 dbg("%s - port %d", __func__, port->number);
512 /* try to find a free urb (write 0 bytes if none) */
513 struct urb *urb = NULL;
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];
521 dbg("%s - using pool URB %d", __func__, i);
525 spin_unlock_irqrestore (&priv->lock, flags);
528 dbg("%s - no more free urbs", __func__);
532 if (urb->transfer_buffer == NULL) {
533 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
534 if (urb->transfer_buffer == NULL) {
535 err("%s - no more kernel memory...", __func__);
540 size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
541 size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET);
543 memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
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);
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,
558 /* send the data out the bulk port */
559 result = usb_submit_urb(urb, GFP_ATOMIC);
561 err("%s - failed submitting write urb, error %d", __func__, result);
569 /* lockless, but it's for debug info only... */
570 priv->bytes_out+=bytes_sent;
572 return bytes_sent; /* that's how much we wrote */
573 } /* klsi_105_write */
575 static void klsi_105_write_bulk_callback ( struct urb *urb)
577 struct usb_serial_port *port = urb->context;
578 int status = urb->status;
580 dbg("%s - port %d", __func__, port->number);
583 dbg("%s - nonzero write bulk status received: %d", __func__,
588 usb_serial_port_softint(port);
589 } /* klsi_105_write_bulk_completion_callback */
592 /* return number of characters currently in the writing process */
593 static int klsi_105_chars_in_buffer (struct tty_struct *tty)
595 struct usb_serial_port *port = tty->driver_data;
599 struct klsi_105_private *priv = usb_get_serial_port_data(port);
601 spin_lock_irqsave (&priv->lock, flags);
603 for (i = 0; i < NUM_URBS; ++i) {
604 if (priv->write_urb_pool[i]->status == -EINPROGRESS) {
605 chars += URB_TRANSFER_BUFFER_SIZE;
609 spin_unlock_irqrestore (&priv->lock, flags);
611 dbg("%s - returns %d", __func__, chars);
615 static int klsi_105_write_room (struct tty_struct *tty)
617 struct usb_serial_port *port = tty->driver_data;
621 struct klsi_105_private *priv = usb_get_serial_port_data(port);
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;
630 spin_unlock_irqrestore (&priv->lock, flags);
632 dbg("%s - returns %d", __func__, room);
638 static void klsi_105_read_bulk_callback (struct urb *urb)
640 struct usb_serial_port *port = urb->context;
641 struct klsi_105_private *priv = usb_get_serial_port_data(port);
642 struct tty_struct *tty;
643 unsigned char *data = urb->transfer_buffer;
645 int status = urb->status;
647 dbg("%s - port %d", __func__, port->number);
649 /* The urb might have been killed. */
651 dbg("%s - nonzero read bulk status received: %d", __func__,
656 /* The data received is again preceded by a length double-byte in LSB-
657 * first order (see klsi_105_write() )
659 if (urb->actual_length == 0) {
660 /* empty urbs seem to happen, we ignore them */
661 /* dbg("%s - emtpy URB", __func__); */
663 } else if (urb->actual_length <= 2) {
664 dbg("%s - size %d URB not understood", __func__,
666 usb_serial_debug_data(debug, &port->dev, __func__,
667 urb->actual_length, data);
669 int bytes_sent = ((__u8 *) data)[0] +
670 ((unsigned int) ((__u8 *) data)[1] << 8);
671 tty = port->port.tty;
672 /* 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
678 usb_serial_debug_data(debug, &port->dev, __func__,
679 urb->actual_length, data);
681 if (bytes_sent + 2 > urb->actual_length) {
682 dbg("%s - trying to read more data than available"
683 " (%d vs. %d)", __func__,
684 bytes_sent+2, urb->actual_length);
685 /* cap at implied limit */
686 bytes_sent = urb->actual_length - 2;
689 tty_buffer_request_room(tty, bytes_sent);
690 tty_insert_flip_string(tty, data + 2, bytes_sent);
691 tty_flip_buffer_push(tty);
693 /* again lockless, but debug info only */
694 priv->bytes_in += bytes_sent;
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,
704 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
706 err("%s - failed resubmitting read urb, error %d", __func__, rc);
707 } /* klsi_105_read_bulk_callback */
710 static void klsi_105_set_termios (struct tty_struct *tty,
711 struct usb_serial_port *port,
712 struct ktermios *old_termios)
714 struct klsi_105_private *priv = usb_get_serial_port_data(port);
715 unsigned int iflag = tty->termios->c_iflag;
716 unsigned int old_iflag = old_termios->c_iflag;
717 unsigned int cflag = tty->termios->c_cflag;
718 unsigned int old_cflag = old_termios->c_cflag;
719 struct klsi_105_port_settings cfg;
723 /* lock while we are modifying the settings */
724 spin_lock_irqsave (&priv->lock, flags);
729 baud = tty_get_baud_rate(tty);
731 if( (cflag & CBAUD) != (old_cflag & CBAUD) ) {
732 /* reassert DTR and (maybe) RTS on transition from B0 */
733 if( (old_cflag & CBAUD) == B0 ) {
734 dbg("%s: baud was B0", __func__);
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;
741 mct_u232_set_modem_ctrl(serial, priv->control_state);
746 case 0: /* handled below */
749 priv->cfg.baudrate = kl5kusb105a_sio_b1200;
752 priv->cfg.baudrate = kl5kusb105a_sio_b2400;
755 priv->cfg.baudrate = kl5kusb105a_sio_b4800;
758 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
761 priv->cfg.baudrate = kl5kusb105a_sio_b19200;
764 priv->cfg.baudrate = kl5kusb105a_sio_b38400;
767 priv->cfg.baudrate = kl5kusb105a_sio_b57600;
770 priv->cfg.baudrate = kl5kusb105a_sio_b115200;
773 dbg("KLSI USB->Serial converter:"
774 " unsupported baudrate request, using default"
776 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
780 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?
788 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
789 mct_u232_set_modem_ctrl(serial, priv->control_state);
792 tty_encode_baud_rate(tty, baud, baud);
794 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
795 /* set the number of data bits */
796 switch (cflag & CSIZE) {
798 dbg("%s - 5 bits/byte not supported", __func__);
799 spin_unlock_irqrestore (&priv->lock, flags);
802 dbg("%s - 6 bits/byte not supported", __func__);
803 spin_unlock_irqrestore (&priv->lock, flags);
806 priv->cfg.databits = kl5kusb105a_dtb_7;
809 priv->cfg.databits = kl5kusb105a_dtb_8;
812 err("CSIZE was not CS5-CS8, using default of 8");
813 priv->cfg.databits = kl5kusb105a_dtb_8;
819 * Update line control register (LCR)
821 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
822 || (cflag & CSTOPB) != (old_cflag & CSTOPB) ) {
824 /* Not currently supported */
825 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB);
831 priv->last_lcr |= (cflag & PARODD) ?
832 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
834 priv->last_lcr |= MCT_U232_PARITY_NONE;
836 /* set the number of stop bits */
837 priv->last_lcr |= (cflag & CSTOPB) ?
838 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
840 mct_u232_set_line_ctrl(serial, priv->last_lcr);
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.
849 if( (iflag & IXOFF) != (old_iflag & IXOFF)
850 || (iflag & IXON) != (old_iflag & IXON)
851 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) {
853 /* Not currently supported */
854 tty->termios->c_cflag &= ~CRTSCTS;
855 /* Drop DTR/RTS if no flow control otherwise assert */
857 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) )
858 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
860 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
861 mct_u232_set_modem_ctrl(serial, priv->control_state);
865 memcpy (&cfg, &priv->cfg, sizeof(cfg));
866 spin_unlock_irqrestore (&priv->lock, flags);
868 /* now commit changes to device */
869 klsi_105_chg_port_settings(port, &cfg);
870 } /* klsi_105_set_termios */
874 static void mct_u232_break_ctl( struct tty_struct *tty, int break_state )
876 struct usb_serial_port *port = tty->driver_data;
877 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;
881 dbg("%sstate=%d", __func__, break_state);
884 lcr |= MCT_U232_SET_BREAK;
886 mct_u232_set_line_ctrl(serial, lcr);
887 } /* mct_u232_break_ctl */
890 static int klsi_105_tiocmget (struct tty_struct *tty, struct file *file)
892 struct usb_serial_port *port = tty->driver_data;
893 struct klsi_105_private *priv = usb_get_serial_port_data(port);
896 unsigned long line_state;
897 dbg("%s - request, just guessing", __func__);
899 rc = klsi_105_get_line_state(port, &line_state);
901 err("Reading line control failed (error = %d)", rc);
902 /* better return value? EAGAIN? */
906 spin_lock_irqsave (&priv->lock, flags);
907 priv->line_state = line_state;
908 spin_unlock_irqrestore (&priv->lock, flags);
909 dbg("%s - read line state 0x%lx", __func__, line_state);
910 return (int)line_state;
913 static int klsi_105_tiocmset (struct tty_struct *tty, struct file *file,
914 unsigned int set, unsigned int clear)
916 int retval = -EINVAL;
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);
926 spin_lock_irqsave (&priv->lock, flags);
928 priv->control_state |= TIOCM_RTS;
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);
942 static void klsi_105_throttle (struct tty_struct *tty)
944 struct usb_serial_port *port = tty->driver_data;
945 dbg("%s - port %d", __func__, port->number);
946 usb_kill_urb(port->read_urb);
949 static void klsi_105_unthrottle (struct tty_struct *tty)
951 struct usb_serial_port *port = tty->driver_data;
954 dbg("%s - port %d", __func__, port->number);
956 port->read_urb->dev = port->serial->dev;
957 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
959 err("%s - failed submitting read urb, error %d", __func__,
965 static int __init klsi_105_init (void)
968 retval = usb_serial_register(&kl5kusb105d_device);
970 goto failed_usb_serial_register;
971 retval = usb_register(&kl5kusb105d_driver);
973 goto failed_usb_register;
975 info(DRIVER_DESC " " DRIVER_VERSION);
978 usb_serial_deregister(&kl5kusb105d_device);
979 failed_usb_serial_register:
984 static void __exit klsi_105_exit (void)
986 usb_deregister (&kl5kusb105d_driver);
987 usb_serial_deregister (&kl5kusb105d_device);
991 module_init (klsi_105_init);
992 module_exit (klsi_105_exit);
994 MODULE_AUTHOR( DRIVER_AUTHOR );
995 MODULE_DESCRIPTION( DRIVER_DESC );
996 MODULE_LICENSE("GPL");
999 module_param(debug, bool, S_IRUGO | S_IWUSR);
1000 MODULE_PARM_DESC(debug, "enable extensive debugging messages");
1002 /* vim: set sts=8 ts=8 sw=8: */