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 <linux/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, struct file *filp);
79 static void klsi_105_close(struct usb_serial_port *port);
80 static int klsi_105_write(struct tty_struct *tty,
81 struct usb_serial_port *port, const unsigned char *buf, int count);
82 static void klsi_105_write_bulk_callback(struct urb *urb);
83 static int klsi_105_chars_in_buffer(struct tty_struct *tty);
84 static int klsi_105_write_room(struct tty_struct *tty);
85 static void klsi_105_read_bulk_callback(struct urb *urb);
86 static void klsi_105_set_termios(struct tty_struct *tty,
87 struct usb_serial_port *port, struct ktermios *old);
88 static void klsi_105_throttle(struct tty_struct *tty);
89 static void klsi_105_unthrottle(struct tty_struct *tty);
90 static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file);
91 static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
92 unsigned int set, unsigned int clear);
95 * All of the device info needed for the KLSI converters.
97 static struct usb_device_id id_table [] = {
98 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) },
99 { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) },
100 { } /* Terminating entry */
103 MODULE_DEVICE_TABLE(usb, id_table);
105 static struct usb_driver kl5kusb105d_driver = {
106 .name = "kl5kusb105d",
107 .probe = usb_serial_probe,
108 .disconnect = usb_serial_disconnect,
109 .id_table = id_table,
113 static struct usb_serial_driver kl5kusb105d_device = {
115 .owner = THIS_MODULE,
116 .name = "kl5kusb105d",
118 .description = "KL5KUSB105D / PalmConnect",
119 .usb_driver = &kl5kusb105d_driver,
120 .id_table = id_table,
122 .open = klsi_105_open,
123 .close = klsi_105_close,
124 .write = klsi_105_write,
125 .write_bulk_callback = klsi_105_write_bulk_callback,
126 .chars_in_buffer = klsi_105_chars_in_buffer,
127 .write_room = klsi_105_write_room,
128 .read_bulk_callback = klsi_105_read_bulk_callback,
129 .set_termios = klsi_105_set_termios,
130 /*.break_ctl = klsi_105_break_ctl,*/
131 .tiocmget = klsi_105_tiocmget,
132 .tiocmset = klsi_105_tiocmset,
133 .attach = klsi_105_startup,
134 .shutdown = klsi_105_shutdown,
135 .throttle = klsi_105_throttle,
136 .unthrottle = klsi_105_unthrottle,
139 struct klsi_105_port_settings {
140 __u8 pktlen; /* always 5, it seems */
145 } __attribute__ ((packed));
147 /* we implement a pool of NUM_URBS urbs per usb_serial */
149 #define URB_TRANSFER_BUFFER_SIZE 64
150 struct klsi_105_private {
151 struct klsi_105_port_settings cfg;
152 struct ktermios termios;
153 unsigned long line_state; /* modem line settings */
155 struct urb *write_urb_pool[NUM_URBS];
157 unsigned long bytes_in;
158 unsigned long bytes_out;
163 * Handle vendor specific USB requests
167 #define KLSI_TIMEOUT 5000 /* default urb timeout */
169 static int klsi_105_chg_port_settings(struct usb_serial_port *port,
170 struct klsi_105_port_settings *settings)
174 rc = usb_control_msg(port->serial->dev,
175 usb_sndctrlpipe(port->serial->dev, 0),
176 KL5KUSB105A_SIO_SET_DATA,
177 USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
181 sizeof(struct klsi_105_port_settings),
185 "Change port settings failed (error = %d)\n", rc);
186 dev_info(&port->serial->dev->dev,
187 "%d byte block, baudrate %x, databits %d, u1 %d, u2 %d\n",
188 settings->pktlen, settings->baudrate, settings->databits,
189 settings->unknown1, settings->unknown2);
191 } /* klsi_105_chg_port_settings */
193 /* translate a 16-bit status value from the device to linux's TIO bits */
194 static unsigned long klsi_105_status2linestate(const __u16 status)
196 unsigned long res = 0;
198 res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0)
199 | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0)
205 * Read line control via vendor command and return result through
208 /* It seems that the status buffer has always only 2 bytes length */
209 #define KLSI_STATUSBUF_LEN 2
210 static int klsi_105_get_line_state(struct usb_serial_port *port,
211 unsigned long *line_state_p)
214 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1, -1};
217 dev_info(&port->serial->dev->dev, "sending SIO Poll request\n");
218 rc = usb_control_msg(port->serial->dev,
219 usb_rcvctrlpipe(port->serial->dev, 0),
220 KL5KUSB105A_SIO_POLL,
221 USB_TYPE_VENDOR | USB_DIR_IN,
224 status_buf, KLSI_STATUSBUF_LEN,
228 dev_err(&port->dev, "Reading line status failed (error = %d)\n",
231 status = get_unaligned_le16(status_buf);
233 dev_info(&port->serial->dev->dev, "read status %x %x",
234 status_buf[0], status_buf[1]);
236 *line_state_p = klsi_105_status2linestate(status);
243 * Driver's tty interface functions
246 static int klsi_105_startup(struct usb_serial *serial)
248 struct klsi_105_private *priv;
251 /* check if we support the product id (see keyspan.c)
255 /* allocate the private data structure */
256 for (i = 0; i < serial->num_ports; i++) {
257 priv = kmalloc(sizeof(struct klsi_105_private),
260 dbg("%skmalloc for klsi_105_private failed.", __func__);
264 /* set initial values for control structures */
265 priv->cfg.pktlen = 5;
266 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
267 priv->cfg.databits = kl5kusb105a_dtb_8;
268 priv->cfg.unknown1 = 0;
269 priv->cfg.unknown2 = 1;
271 priv->line_state = 0;
275 usb_set_serial_port_data(serial->port[i], priv);
277 spin_lock_init(&priv->lock);
278 for (j = 0; j < NUM_URBS; j++) {
279 struct urb *urb = usb_alloc_urb(0, GFP_KERNEL);
281 priv->write_urb_pool[j] = urb;
283 dev_err(&serial->dev->dev, "No more urbs???\n");
287 urb->transfer_buffer =
288 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
289 if (!urb->transfer_buffer) {
290 dev_err(&serial->dev->dev,
291 "%s - out of memory for urb buffers.\n",
297 /* priv->termios is left uninitalized until port opening */
298 init_waitqueue_head(&serial->port[i]->write_wait);
304 for (; i >= 0; i--) {
305 priv = usb_get_serial_port_data(serial->port[i]);
306 for (j = 0; j < NUM_URBS; j++) {
307 if (priv->write_urb_pool[j]) {
308 kfree(priv->write_urb_pool[j]->transfer_buffer);
309 usb_free_urb(priv->write_urb_pool[j]);
312 usb_set_serial_port_data(serial->port[i], NULL);
315 } /* klsi_105_startup */
318 static void klsi_105_shutdown(struct usb_serial *serial)
324 /* stop reads and writes on all ports */
325 for (i = 0; i < serial->num_ports; ++i) {
326 struct klsi_105_private *priv =
327 usb_get_serial_port_data(serial->port[i]);
331 /* kill our write urb pool */
333 struct urb **write_urbs = priv->write_urb_pool;
334 spin_lock_irqsave(&priv->lock, flags);
336 for (j = 0; j < NUM_URBS; j++) {
338 /* FIXME - uncomment the following
339 * usb_kill_urb call when the host
340 * controllers get fixed to set
341 * urb->dev = NULL after the urb is
342 * finished. Otherwise this call
344 /* usb_kill_urb(write_urbs[j]); */
345 kfree(write_urbs[j]->transfer_buffer);
346 usb_free_urb(write_urbs[j]);
349 spin_unlock_irqrestore(&priv->lock, flags);
351 usb_set_serial_port_data(serial->port[i], NULL);
354 } /* klsi_105_shutdown */
356 static int klsi_105_open(struct tty_struct *tty,
357 struct usb_serial_port *port, struct file *filp)
359 struct klsi_105_private *priv = usb_get_serial_port_data(port);
363 unsigned long line_state;
364 struct klsi_105_port_settings cfg;
367 dbg("%s port %d", __func__, port->number);
369 /* force low_latency on so that our tty_push actually forces
371 * tty->low_latency = 1; */
373 /* Do a defined restart:
374 * Set up sane default baud rate and send the 'READ_ON'
376 * FIXME: set modem line control (how?)
377 * Then read the modem line control and store values in
381 cfg.baudrate = kl5kusb105a_sio_b9600;
382 cfg.databits = kl5kusb105a_dtb_8;
385 klsi_105_chg_port_settings(port, &cfg);
387 /* set up termios structure */
388 spin_lock_irqsave(&priv->lock, flags);
389 priv->termios.c_iflag = tty->termios->c_iflag;
390 priv->termios.c_oflag = tty->termios->c_oflag;
391 priv->termios.c_cflag = tty->termios->c_cflag;
392 priv->termios.c_lflag = tty->termios->c_lflag;
393 for (i = 0; i < NCCS; i++)
394 priv->termios.c_cc[i] = tty->termios->c_cc[i];
395 priv->cfg.pktlen = cfg.pktlen;
396 priv->cfg.baudrate = cfg.baudrate;
397 priv->cfg.databits = cfg.databits;
398 priv->cfg.unknown1 = cfg.unknown1;
399 priv->cfg.unknown2 = cfg.unknown2;
400 spin_unlock_irqrestore(&priv->lock, flags);
402 /* READ_ON and urb submission */
403 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
404 usb_rcvbulkpipe(port->serial->dev,
405 port->bulk_in_endpointAddress),
406 port->read_urb->transfer_buffer,
407 port->read_urb->transfer_buffer_length,
408 klsi_105_read_bulk_callback,
411 rc = usb_submit_urb(port->read_urb, GFP_KERNEL);
413 dev_err(&port->dev, "%s - failed submitting read urb, "
414 "error %d\n", __func__, rc);
419 rc = usb_control_msg(port->serial->dev,
420 usb_sndctrlpipe(port->serial->dev, 0),
421 KL5KUSB105A_SIO_CONFIGURE,
422 USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
423 KL5KUSB105A_SIO_CONFIGURE_READ_ON,
429 dev_err(&port->dev, "Enabling read failed (error = %d)\n", rc);
432 dbg("%s - enabled reading", __func__);
434 rc = klsi_105_get_line_state(port, &line_state);
436 spin_lock_irqsave(&priv->lock, flags);
437 priv->line_state = line_state;
438 spin_unlock_irqrestore(&priv->lock, flags);
439 dbg("%s - read line state 0x%lx", __func__, line_state);
446 } /* klsi_105_open */
449 static void klsi_105_close(struct usb_serial_port *port)
451 struct klsi_105_private *priv = usb_get_serial_port_data(port);
454 dbg("%s port %d", __func__, port->number);
456 mutex_lock(&port->serial->disc_mutex);
457 if (!port->serial->disconnected) {
459 rc = usb_control_msg(port->serial->dev,
460 usb_sndctrlpipe(port->serial->dev, 0),
461 KL5KUSB105A_SIO_CONFIGURE,
462 USB_TYPE_VENDOR | USB_DIR_OUT,
463 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
469 "Disabling read failed (error = %d)\n", rc);
471 mutex_unlock(&port->serial->disc_mutex);
473 /* shutdown our bulk reads and writes */
474 usb_kill_urb(port->write_urb);
475 usb_kill_urb(port->read_urb);
476 /* unlink our write pool */
478 /* wgg - do I need this? I think so. */
479 usb_kill_urb(port->interrupt_in_urb);
480 dev_info(&port->serial->dev->dev,
481 "port stats: %ld bytes in, %ld bytes out\n",
482 priv->bytes_in, priv->bytes_out);
483 } /* klsi_105_close */
486 /* We need to write a complete 64-byte data block and encode the
487 * number actually sent in the first double-byte, LSB-order. That
488 * leaves at most 62 bytes of payload.
490 #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
493 static int klsi_105_write(struct tty_struct *tty,
494 struct usb_serial_port *port, const unsigned char *buf, int count)
496 struct klsi_105_private *priv = usb_get_serial_port_data(port);
500 dbg("%s - port %d", __func__, port->number);
503 /* try to find a free urb (write 0 bytes if none) */
504 struct urb *urb = NULL;
507 /* since the pool is per-port we might not need
509 spin_lock_irqsave(&priv->lock, flags);
510 for (i = 0; i < NUM_URBS; i++) {
511 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
512 urb = priv->write_urb_pool[i];
513 dbg("%s - using pool URB %d", __func__, i);
517 spin_unlock_irqrestore(&priv->lock, flags);
520 dbg("%s - no more free urbs", __func__);
524 if (urb->transfer_buffer == NULL) {
525 urb->transfer_buffer =
526 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
527 if (urb->transfer_buffer == NULL) {
529 "%s - no more kernel memory...\n",
535 size = min(count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
536 size = min(size, URB_TRANSFER_BUFFER_SIZE -
537 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);
558 "%s - failed submitting write urb, error %d\n",
567 /* lockless, but it's for debug info only... */
568 priv->bytes_out += bytes_sent;
570 return bytes_sent; /* that's how much we wrote */
571 } /* klsi_105_write */
573 static void klsi_105_write_bulk_callback(struct urb *urb)
575 struct usb_serial_port *port = urb->context;
576 int status = urb->status;
578 dbg("%s - port %d", __func__, port->number);
581 dbg("%s - nonzero write bulk status received: %d", __func__,
586 usb_serial_port_softint(port);
587 } /* klsi_105_write_bulk_completion_callback */
590 /* return number of characters currently in the writing process */
591 static int klsi_105_chars_in_buffer(struct tty_struct *tty)
593 struct usb_serial_port *port = tty->driver_data;
597 struct klsi_105_private *priv = usb_get_serial_port_data(port);
599 spin_lock_irqsave(&priv->lock, flags);
601 for (i = 0; i < NUM_URBS; ++i) {
602 if (priv->write_urb_pool[i]->status == -EINPROGRESS)
603 chars += URB_TRANSFER_BUFFER_SIZE;
606 spin_unlock_irqrestore(&priv->lock, flags);
608 dbg("%s - returns %d", __func__, chars);
612 static int klsi_105_write_room(struct tty_struct *tty)
614 struct usb_serial_port *port = tty->driver_data;
618 struct klsi_105_private *priv = usb_get_serial_port_data(port);
620 spin_lock_irqsave(&priv->lock, flags);
621 for (i = 0; i < NUM_URBS; ++i) {
622 if (priv->write_urb_pool[i]->status != -EINPROGRESS)
623 room += URB_TRANSFER_BUFFER_SIZE;
626 spin_unlock_irqrestore(&priv->lock, flags);
628 dbg("%s - returns %d", __func__, room);
634 static void klsi_105_read_bulk_callback(struct urb *urb)
636 struct usb_serial_port *port = urb->context;
637 struct klsi_105_private *priv = usb_get_serial_port_data(port);
638 struct tty_struct *tty;
639 unsigned char *data = urb->transfer_buffer;
641 int status = urb->status;
643 dbg("%s - port %d", __func__, port->number);
645 /* The urb might have been killed. */
647 dbg("%s - nonzero read bulk status received: %d", __func__,
652 /* The data received is again preceded by a length double-byte in LSB-
653 * first order (see klsi_105_write() )
655 if (urb->actual_length == 0) {
656 /* empty urbs seem to happen, we ignore them */
657 /* dbg("%s - emtpy URB", __func__); */
659 } else if (urb->actual_length <= 2) {
660 dbg("%s - size %d URB not understood", __func__,
662 usb_serial_debug_data(debug, &port->dev, __func__,
663 urb->actual_length, data);
665 int bytes_sent = ((__u8 *) data)[0] +
666 ((unsigned int) ((__u8 *) data)[1] << 8);
667 tty = tty_port_tty_get(&port->port);
668 /* we should immediately resubmit the URB, before attempting
669 * to pass the data on to the tty layer. But that needs locking
670 * against re-entry an then mixed-up data because of
671 * intermixed tty_flip_buffer_push()s
674 usb_serial_debug_data(debug, &port->dev, __func__,
675 urb->actual_length, data);
677 if (bytes_sent + 2 > urb->actual_length) {
678 dbg("%s - trying to read more data than available"
679 " (%d vs. %d)", __func__,
680 bytes_sent+2, urb->actual_length);
681 /* cap at implied limit */
682 bytes_sent = urb->actual_length - 2;
685 tty_buffer_request_room(tty, bytes_sent);
686 tty_insert_flip_string(tty, data + 2, bytes_sent);
687 tty_flip_buffer_push(tty);
690 /* again lockless, but debug info only */
691 priv->bytes_in += bytes_sent;
693 /* Continue trying to always read */
694 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
695 usb_rcvbulkpipe(port->serial->dev,
696 port->bulk_in_endpointAddress),
697 port->read_urb->transfer_buffer,
698 port->read_urb->transfer_buffer_length,
699 klsi_105_read_bulk_callback,
701 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
704 "%s - failed resubmitting read urb, error %d\n",
706 } /* klsi_105_read_bulk_callback */
709 static void klsi_105_set_termios(struct tty_struct *tty,
710 struct usb_serial_port *port,
711 struct ktermios *old_termios)
713 struct klsi_105_private *priv = usb_get_serial_port_data(port);
714 unsigned int iflag = tty->termios->c_iflag;
715 unsigned int old_iflag = old_termios->c_iflag;
716 unsigned int cflag = tty->termios->c_cflag;
717 unsigned int old_cflag = old_termios->c_cflag;
718 struct klsi_105_port_settings cfg;
722 /* lock while we are modifying the settings */
723 spin_lock_irqsave(&priv->lock, flags);
728 baud = tty_get_baud_rate(tty);
730 if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
731 /* reassert DTR and (maybe) RTS on transition from B0 */
732 if ((old_cflag & CBAUD) == B0) {
733 dbg("%s: baud was B0", __func__);
735 priv->control_state |= TIOCM_DTR;
736 /* don't set RTS if using hardware flow control */
737 if (!(old_cflag & CRTSCTS))
738 priv->control_state |= TIOCM_RTS;
739 mct_u232_set_modem_ctrl(serial, priv->control_state);
744 case 0: /* handled below */
747 priv->cfg.baudrate = kl5kusb105a_sio_b1200;
750 priv->cfg.baudrate = kl5kusb105a_sio_b2400;
753 priv->cfg.baudrate = kl5kusb105a_sio_b4800;
756 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
759 priv->cfg.baudrate = kl5kusb105a_sio_b19200;
762 priv->cfg.baudrate = kl5kusb105a_sio_b38400;
765 priv->cfg.baudrate = kl5kusb105a_sio_b57600;
768 priv->cfg.baudrate = kl5kusb105a_sio_b115200;
771 dbg("KLSI USB->Serial converter:"
772 " unsupported baudrate request, using default of 9600");
773 priv->cfg.baudrate = kl5kusb105a_sio_b9600;
777 if ((cflag & CBAUD) == B0) {
778 dbg("%s: baud is B0", __func__);
779 /* Drop RTS and DTR */
780 /* maybe this should be simulated by sending read
781 * disable and read enable messages?
785 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
786 mct_u232_set_modem_ctrl(serial, priv->control_state);
789 tty_encode_baud_rate(tty, baud, baud);
791 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
792 /* set the number of data bits */
793 switch (cflag & CSIZE) {
795 dbg("%s - 5 bits/byte not supported", __func__);
796 spin_unlock_irqrestore(&priv->lock, flags);
799 dbg("%s - 6 bits/byte not supported", __func__);
800 spin_unlock_irqrestore(&priv->lock, flags);
803 priv->cfg.databits = kl5kusb105a_dtb_7;
806 priv->cfg.databits = kl5kusb105a_dtb_8;
810 "CSIZE was not CS5-CS8, using default of 8\n");
811 priv->cfg.databits = kl5kusb105a_dtb_8;
817 * Update line control register (LCR)
819 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
820 || (cflag & CSTOPB) != (old_cflag & CSTOPB)) {
821 /* Not currently supported */
822 tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB);
828 priv->last_lcr |= (cflag & PARODD) ?
829 MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
831 priv->last_lcr |= MCT_U232_PARITY_NONE;
833 /* set the number of stop bits */
834 priv->last_lcr |= (cflag & CSTOPB) ?
835 MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
837 mct_u232_set_line_ctrl(serial, priv->last_lcr);
842 * Set flow control: well, I do not really now how to handle DTR/RTS.
843 * Just do what we have seen with SniffUSB on Win98.
845 if ((iflag & IXOFF) != (old_iflag & IXOFF)
846 || (iflag & IXON) != (old_iflag & IXON)
847 || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
848 /* Not currently supported */
849 tty->termios->c_cflag &= ~CRTSCTS;
850 /* Drop DTR/RTS if no flow control otherwise assert */
852 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
853 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
855 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
856 mct_u232_set_modem_ctrl(serial, priv->control_state);
860 memcpy(&cfg, &priv->cfg, sizeof(cfg));
861 spin_unlock_irqrestore(&priv->lock, flags);
863 /* now commit changes to device */
864 klsi_105_chg_port_settings(port, &cfg);
865 } /* klsi_105_set_termios */
869 static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
871 struct usb_serial_port *port = tty->driver_data;
872 struct usb_serial *serial = port->serial;
873 struct mct_u232_private *priv =
874 (struct mct_u232_private *)port->private;
875 unsigned char lcr = priv->last_lcr;
877 dbg("%sstate=%d", __func__, break_state);
881 lcr |= MCT_U232_SET_BREAK;
883 mct_u232_set_line_ctrl(serial, lcr);
884 } /* mct_u232_break_ctl */
887 static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file)
889 struct usb_serial_port *port = tty->driver_data;
890 struct klsi_105_private *priv = usb_get_serial_port_data(port);
893 unsigned long line_state;
894 dbg("%s - request, just guessing", __func__);
896 rc = klsi_105_get_line_state(port, &line_state);
899 "Reading line control failed (error = %d)\n", rc);
900 /* better return value? EAGAIN? */
904 spin_lock_irqsave(&priv->lock, flags);
905 priv->line_state = line_state;
906 spin_unlock_irqrestore(&priv->lock, flags);
907 dbg("%s - read line state 0x%lx", __func__, line_state);
908 return (int)line_state;
911 static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
912 unsigned int set, unsigned int clear)
914 int retval = -EINVAL;
918 /* if this ever gets implemented, it should be done something like this:
919 struct usb_serial *serial = port->serial;
920 struct klsi_105_private *priv = usb_get_serial_port_data(port);
924 spin_lock_irqsave (&priv->lock, flags);
926 priv->control_state |= TIOCM_RTS;
928 priv->control_state |= TIOCM_DTR;
929 if (clear & TIOCM_RTS)
930 priv->control_state &= ~TIOCM_RTS;
931 if (clear & TIOCM_DTR)
932 priv->control_state &= ~TIOCM_DTR;
933 control = priv->control_state;
934 spin_unlock_irqrestore (&priv->lock, flags);
935 retval = mct_u232_set_modem_ctrl(serial, control);
940 static void klsi_105_throttle(struct tty_struct *tty)
942 struct usb_serial_port *port = tty->driver_data;
943 dbg("%s - port %d", __func__, port->number);
944 usb_kill_urb(port->read_urb);
947 static void klsi_105_unthrottle(struct tty_struct *tty)
949 struct usb_serial_port *port = tty->driver_data;
952 dbg("%s - port %d", __func__, port->number);
954 port->read_urb->dev = port->serial->dev;
955 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
958 "%s - failed submitting read urb, error %d\n",
964 static int __init klsi_105_init(void)
967 retval = usb_serial_register(&kl5kusb105d_device);
969 goto failed_usb_serial_register;
970 retval = usb_register(&kl5kusb105d_driver);
972 goto failed_usb_register;
974 printk(KERN_INFO KBUILD_MODNAME ": " 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: */