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 do 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_disconnect(struct usb_serial
*serial
);
77 static void klsi_105_release(struct usb_serial
*serial
);
78 static int klsi_105_open(struct tty_struct
*tty
, struct usb_serial_port
*port
);
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 const 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 .disconnect
= klsi_105_disconnect
,
135 .release
= klsi_105_release
,
136 .throttle
= klsi_105_throttle
,
137 .unthrottle
= klsi_105_unthrottle
,
140 struct klsi_105_port_settings
{
141 __u8 pktlen
; /* always 5, it seems */
146 } __attribute__ ((packed
));
148 /* we implement a pool of NUM_URBS urbs per usb_serial */
150 #define URB_TRANSFER_BUFFER_SIZE 64
151 struct klsi_105_private
{
152 struct klsi_105_port_settings cfg
;
153 struct ktermios termios
;
154 unsigned long line_state
; /* modem line settings */
156 struct urb
*write_urb_pool
[NUM_URBS
];
158 unsigned long bytes_in
;
159 unsigned long bytes_out
;
164 * Handle vendor specific USB requests
168 #define KLSI_TIMEOUT 5000 /* default urb timeout */
170 static int klsi_105_chg_port_settings(struct usb_serial_port
*port
,
171 struct klsi_105_port_settings
*settings
)
175 rc
= usb_control_msg(port
->serial
->dev
,
176 usb_sndctrlpipe(port
->serial
->dev
, 0),
177 KL5KUSB105A_SIO_SET_DATA
,
178 USB_TYPE_VENDOR
| USB_DIR_OUT
| USB_RECIP_INTERFACE
,
182 sizeof(struct klsi_105_port_settings
),
186 "Change port settings failed (error = %d)\n", rc
);
187 dev_info(&port
->serial
->dev
->dev
,
188 "%d byte block, baudrate %x, databits %d, u1 %d, u2 %d\n",
189 settings
->pktlen
, settings
->baudrate
, settings
->databits
,
190 settings
->unknown1
, settings
->unknown2
);
194 /* translate a 16-bit status value from the device to linux's TIO bits */
195 static unsigned long klsi_105_status2linestate(const __u16 status
)
197 unsigned long res
= 0;
199 res
= ((status
& KL5KUSB105A_DSR
) ? TIOCM_DSR
: 0)
200 | ((status
& KL5KUSB105A_CTS
) ? TIOCM_CTS
: 0)
207 * Read line control via vendor command and return result through
210 /* It seems that the status buffer has always only 2 bytes length */
211 #define KLSI_STATUSBUF_LEN 2
212 static int klsi_105_get_line_state(struct usb_serial_port
*port
,
213 unsigned long *line_state_p
)
219 dev_info(&port
->serial
->dev
->dev
, "sending SIO Poll request\n");
221 status_buf
= kmalloc(KLSI_STATUSBUF_LEN
, GFP_KERNEL
);
223 dev_err(&port
->dev
, "%s - out of memory for status buffer.\n",
227 status_buf
[0] = 0xff;
228 status_buf
[1] = 0xff;
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 dev_err(&port
->dev
, "Reading line status failed (error = %d)\n",
242 status
= get_unaligned_le16(status_buf
);
244 dev_info(&port
->serial
->dev
->dev
, "read status %x %x",
245 status_buf
[0], status_buf
[1]);
247 *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 dev_err(&serial
->dev
->dev
, "No more urbs???\n");
300 urb
->transfer_buffer
=
301 kmalloc(URB_TRANSFER_BUFFER_SIZE
, GFP_KERNEL
);
302 if (!urb
->transfer_buffer
) {
303 dev_err(&serial
->dev
->dev
,
304 "%s - out of memory for urb buffers.\n",
310 /* priv->termios is left uninitalized until port opening */
311 init_waitqueue_head(&serial
->port
[i
]->write_wait
);
317 for (; i
>= 0; i
--) {
318 priv
= usb_get_serial_port_data(serial
->port
[i
]);
319 for (j
= 0; j
< NUM_URBS
; j
++) {
320 if (priv
->write_urb_pool
[j
]) {
321 kfree(priv
->write_urb_pool
[j
]->transfer_buffer
);
322 usb_free_urb(priv
->write_urb_pool
[j
]);
326 usb_set_serial_port_data(serial
->port
[i
], NULL
);
331 static void klsi_105_disconnect(struct usb_serial
*serial
)
337 /* stop reads and writes on all ports */
338 for (i
= 0; i
< serial
->num_ports
; ++i
) {
339 struct klsi_105_private
*priv
=
340 usb_get_serial_port_data(serial
->port
[i
]);
343 /* kill our write urb pool */
345 struct urb
**write_urbs
= priv
->write_urb_pool
;
347 for (j
= 0; j
< NUM_URBS
; j
++) {
349 usb_kill_urb(write_urbs
[j
]);
350 usb_free_urb(write_urbs
[j
]);
357 static void klsi_105_release(struct usb_serial
*serial
)
363 for (i
= 0; i
< serial
->num_ports
; ++i
) {
364 struct klsi_105_private
*priv
=
365 usb_get_serial_port_data(serial
->port
[i
]);
371 static int klsi_105_open(struct tty_struct
*tty
, struct usb_serial_port
*port
)
373 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
377 unsigned long line_state
;
378 struct klsi_105_port_settings
*cfg
;
381 dbg("%s port %d", __func__
, port
->number
);
383 /* Do a defined restart:
384 * Set up sane default baud rate and send the 'READ_ON'
386 * FIXME: set modem line control (how?)
387 * Then read the modem line control and store values in
390 cfg
= kmalloc(sizeof(*cfg
), GFP_KERNEL
);
392 dev_err(&port
->dev
, "%s - out of memory for config buffer.\n",
397 cfg
->baudrate
= kl5kusb105a_sio_b9600
;
398 cfg
->databits
= kl5kusb105a_dtb_8
;
401 klsi_105_chg_port_settings(port
, cfg
);
403 /* set up termios structure */
404 spin_lock_irqsave(&priv
->lock
, flags
);
405 priv
->termios
.c_iflag
= tty
->termios
->c_iflag
;
406 priv
->termios
.c_oflag
= tty
->termios
->c_oflag
;
407 priv
->termios
.c_cflag
= tty
->termios
->c_cflag
;
408 priv
->termios
.c_lflag
= tty
->termios
->c_lflag
;
409 for (i
= 0; i
< NCCS
; i
++)
410 priv
->termios
.c_cc
[i
] = tty
->termios
->c_cc
[i
];
411 priv
->cfg
.pktlen
= cfg
->pktlen
;
412 priv
->cfg
.baudrate
= cfg
->baudrate
;
413 priv
->cfg
.databits
= cfg
->databits
;
414 priv
->cfg
.unknown1
= cfg
->unknown1
;
415 priv
->cfg
.unknown2
= cfg
->unknown2
;
416 spin_unlock_irqrestore(&priv
->lock
, flags
);
418 /* READ_ON and urb submission */
419 usb_fill_bulk_urb(port
->read_urb
, port
->serial
->dev
,
420 usb_rcvbulkpipe(port
->serial
->dev
,
421 port
->bulk_in_endpointAddress
),
422 port
->read_urb
->transfer_buffer
,
423 port
->read_urb
->transfer_buffer_length
,
424 klsi_105_read_bulk_callback
,
427 rc
= usb_submit_urb(port
->read_urb
, GFP_KERNEL
);
429 dev_err(&port
->dev
, "%s - failed submitting read urb, "
430 "error %d\n", __func__
, rc
);
435 rc
= usb_control_msg(port
->serial
->dev
,
436 usb_sndctrlpipe(port
->serial
->dev
, 0),
437 KL5KUSB105A_SIO_CONFIGURE
,
438 USB_TYPE_VENDOR
|USB_DIR_OUT
|USB_RECIP_INTERFACE
,
439 KL5KUSB105A_SIO_CONFIGURE_READ_ON
,
445 dev_err(&port
->dev
, "Enabling read failed (error = %d)\n", rc
);
448 dbg("%s - enabled reading", __func__
);
450 rc
= klsi_105_get_line_state(port
, &line_state
);
452 spin_lock_irqsave(&priv
->lock
, flags
);
453 priv
->line_state
= line_state
;
454 spin_unlock_irqrestore(&priv
->lock
, flags
);
455 dbg("%s - read line state 0x%lx", __func__
, line_state
);
465 static void klsi_105_close(struct usb_serial_port
*port
)
467 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
470 dbg("%s port %d", __func__
, port
->number
);
472 mutex_lock(&port
->serial
->disc_mutex
);
473 if (!port
->serial
->disconnected
) {
475 rc
= usb_control_msg(port
->serial
->dev
,
476 usb_sndctrlpipe(port
->serial
->dev
, 0),
477 KL5KUSB105A_SIO_CONFIGURE
,
478 USB_TYPE_VENDOR
| USB_DIR_OUT
,
479 KL5KUSB105A_SIO_CONFIGURE_READ_OFF
,
485 "Disabling read failed (error = %d)\n", rc
);
487 mutex_unlock(&port
->serial
->disc_mutex
);
489 /* shutdown our bulk reads and writes */
490 usb_kill_urb(port
->write_urb
);
491 usb_kill_urb(port
->read_urb
);
492 /* unlink our write pool */
494 /* wgg - do I need this? I think so. */
495 usb_kill_urb(port
->interrupt_in_urb
);
496 dev_info(&port
->serial
->dev
->dev
,
497 "port stats: %ld bytes in, %ld bytes out\n",
498 priv
->bytes_in
, priv
->bytes_out
);
501 /* We need to write a complete 64-byte data block and encode the
502 * number actually sent in the first double-byte, LSB-order. That
503 * leaves at most 62 bytes of payload.
505 #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
507 static int klsi_105_write(struct tty_struct
*tty
,
508 struct usb_serial_port
*port
, const unsigned char *buf
, int count
)
510 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
514 dbg("%s - port %d", __func__
, port
->number
);
517 /* try to find a free urb (write 0 bytes if none) */
518 struct urb
*urb
= NULL
;
521 /* since the pool is per-port we might not need
523 spin_lock_irqsave(&priv
->lock
, flags
);
524 for (i
= 0; i
< NUM_URBS
; i
++) {
525 if (priv
->write_urb_pool
[i
]->status
!= -EINPROGRESS
) {
526 urb
= priv
->write_urb_pool
[i
];
527 dbg("%s - using pool URB %d", __func__
, i
);
531 spin_unlock_irqrestore(&priv
->lock
, flags
);
534 dbg("%s - no more free urbs", __func__
);
538 if (urb
->transfer_buffer
== NULL
) {
539 urb
->transfer_buffer
=
540 kmalloc(URB_TRANSFER_BUFFER_SIZE
, GFP_ATOMIC
);
541 if (urb
->transfer_buffer
== NULL
) {
543 "%s - no more kernel memory...\n",
549 size
= min(count
, port
->bulk_out_size
- KLSI_105_DATA_OFFSET
);
550 size
= min(size
, URB_TRANSFER_BUFFER_SIZE
-
551 KLSI_105_DATA_OFFSET
);
553 memcpy(urb
->transfer_buffer
+ KLSI_105_DATA_OFFSET
, buf
, size
);
555 /* write payload size into transfer buffer */
556 ((__u8
*)urb
->transfer_buffer
)[0] = (__u8
) (size
& 0xFF);
557 ((__u8
*)urb
->transfer_buffer
)[1] = (__u8
) ((size
& 0xFF00)>>8);
560 usb_fill_bulk_urb(urb
, port
->serial
->dev
,
561 usb_sndbulkpipe(port
->serial
->dev
,
562 port
->bulk_out_endpointAddress
),
563 urb
->transfer_buffer
,
564 URB_TRANSFER_BUFFER_SIZE
,
565 klsi_105_write_bulk_callback
,
568 /* send the data out the bulk port */
569 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
572 "%s - failed submitting write urb, error %d\n",
581 /* lockless, but it's for debug info only... */
582 priv
->bytes_out
+= bytes_sent
;
584 return bytes_sent
; /* that's how much we wrote */
587 static void klsi_105_write_bulk_callback(struct urb
*urb
)
589 struct usb_serial_port
*port
= urb
->context
;
590 int status
= urb
->status
;
592 dbg("%s - port %d", __func__
, port
->number
);
595 dbg("%s - nonzero write bulk status received: %d", __func__
,
600 usb_serial_port_softint(port
);
603 /* return number of characters currently in the writing process */
604 static int klsi_105_chars_in_buffer(struct tty_struct
*tty
)
606 struct usb_serial_port
*port
= tty
->driver_data
;
610 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
612 spin_lock_irqsave(&priv
->lock
, flags
);
614 for (i
= 0; i
< NUM_URBS
; ++i
) {
615 if (priv
->write_urb_pool
[i
]->status
== -EINPROGRESS
)
616 chars
+= URB_TRANSFER_BUFFER_SIZE
;
619 spin_unlock_irqrestore(&priv
->lock
, flags
);
621 dbg("%s - returns %d", __func__
, chars
);
625 static int klsi_105_write_room(struct tty_struct
*tty
)
627 struct usb_serial_port
*port
= tty
->driver_data
;
631 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
633 spin_lock_irqsave(&priv
->lock
, flags
);
634 for (i
= 0; i
< NUM_URBS
; ++i
) {
635 if (priv
->write_urb_pool
[i
]->status
!= -EINPROGRESS
)
636 room
+= URB_TRANSFER_BUFFER_SIZE
;
639 spin_unlock_irqrestore(&priv
->lock
, flags
);
641 dbg("%s - returns %d", __func__
, room
);
645 static void klsi_105_read_bulk_callback(struct urb
*urb
)
647 struct usb_serial_port
*port
= urb
->context
;
648 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
649 struct tty_struct
*tty
;
650 unsigned char *data
= urb
->transfer_buffer
;
652 int status
= urb
->status
;
654 dbg("%s - port %d", __func__
, port
->number
);
656 /* The urb might have been killed. */
658 dbg("%s - nonzero read bulk status received: %d", __func__
,
663 /* The data received is again preceded by a length double-byte in LSB-
664 * first order (see klsi_105_write() )
666 if (urb
->actual_length
== 0) {
667 /* empty urbs seem to happen, we ignore them */
668 /* dbg("%s - emtpy URB", __func__); */
670 } else if (urb
->actual_length
<= 2) {
671 dbg("%s - size %d URB not understood", __func__
,
673 usb_serial_debug_data(debug
, &port
->dev
, __func__
,
674 urb
->actual_length
, data
);
676 int bytes_sent
= ((__u8
*) data
)[0] +
677 ((unsigned int) ((__u8
*) data
)[1] << 8);
678 tty
= tty_port_tty_get(&port
->port
);
679 /* we should immediately resubmit the URB, before attempting
680 * to pass the data on to the tty layer. But that needs locking
681 * against re-entry an then mixed-up data because of
682 * intermixed tty_flip_buffer_push()s
685 usb_serial_debug_data(debug
, &port
->dev
, __func__
,
686 urb
->actual_length
, data
);
688 if (bytes_sent
+ 2 > urb
->actual_length
) {
689 dbg("%s - trying to read more data than available"
690 " (%d vs. %d)", __func__
,
691 bytes_sent
+2, urb
->actual_length
);
692 /* cap at implied limit */
693 bytes_sent
= urb
->actual_length
- 2;
696 tty_insert_flip_string(tty
, data
+ 2, bytes_sent
);
697 tty_flip_buffer_push(tty
);
700 /* again lockless, but debug info only */
701 priv
->bytes_in
+= bytes_sent
;
703 /* Continue trying to always read */
704 usb_fill_bulk_urb(port
->read_urb
, port
->serial
->dev
,
705 usb_rcvbulkpipe(port
->serial
->dev
,
706 port
->bulk_in_endpointAddress
),
707 port
->read_urb
->transfer_buffer
,
708 port
->read_urb
->transfer_buffer_length
,
709 klsi_105_read_bulk_callback
,
711 rc
= usb_submit_urb(port
->read_urb
, GFP_ATOMIC
);
714 "%s - failed resubmitting read urb, error %d\n",
718 static void klsi_105_set_termios(struct tty_struct
*tty
,
719 struct usb_serial_port
*port
,
720 struct ktermios
*old_termios
)
722 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
723 unsigned int iflag
= tty
->termios
->c_iflag
;
724 unsigned int old_iflag
= old_termios
->c_iflag
;
725 unsigned int cflag
= tty
->termios
->c_cflag
;
726 unsigned int old_cflag
= old_termios
->c_cflag
;
727 struct klsi_105_port_settings
*cfg
;
731 cfg
= kmalloc(sizeof(*cfg
), GFP_KERNEL
);
733 dev_err(&port
->dev
, "%s - out of memory for config buffer.\n",
738 /* lock while we are modifying the settings */
739 spin_lock_irqsave(&priv
->lock
, flags
);
744 baud
= tty_get_baud_rate(tty
);
746 if ((cflag
& CBAUD
) != (old_cflag
& CBAUD
)) {
747 /* reassert DTR and (maybe) RTS on transition from B0 */
748 if ((old_cflag
& CBAUD
) == B0
) {
749 dbg("%s: baud was B0", __func__
);
751 priv
->control_state
|= TIOCM_DTR
;
752 /* don't set RTS if using hardware flow control */
753 if (!(old_cflag
& CRTSCTS
))
754 priv
->control_state
|= TIOCM_RTS
;
755 mct_u232_set_modem_ctrl(serial
, priv
->control_state
);
760 case 0: /* handled below */
763 priv
->cfg
.baudrate
= kl5kusb105a_sio_b1200
;
766 priv
->cfg
.baudrate
= kl5kusb105a_sio_b2400
;
769 priv
->cfg
.baudrate
= kl5kusb105a_sio_b4800
;
772 priv
->cfg
.baudrate
= kl5kusb105a_sio_b9600
;
775 priv
->cfg
.baudrate
= kl5kusb105a_sio_b19200
;
778 priv
->cfg
.baudrate
= kl5kusb105a_sio_b38400
;
781 priv
->cfg
.baudrate
= kl5kusb105a_sio_b57600
;
784 priv
->cfg
.baudrate
= kl5kusb105a_sio_b115200
;
787 dbg("KLSI USB->Serial converter:"
788 " unsupported baudrate request, using default of 9600");
789 priv
->cfg
.baudrate
= kl5kusb105a_sio_b9600
;
793 if ((cflag
& CBAUD
) == B0
) {
794 dbg("%s: baud is B0", __func__
);
795 /* Drop RTS and DTR */
796 /* maybe this should be simulated by sending read
797 * disable and read enable messages?
801 priv
->control_state
&= ~(TIOCM_DTR
| TIOCM_RTS
);
802 mct_u232_set_modem_ctrl(serial
, priv
->control_state
);
805 tty_encode_baud_rate(tty
, baud
, baud
);
807 if ((cflag
& CSIZE
) != (old_cflag
& CSIZE
)) {
808 /* set the number of data bits */
809 switch (cflag
& CSIZE
) {
811 dbg("%s - 5 bits/byte not supported", __func__
);
812 spin_unlock_irqrestore(&priv
->lock
, flags
);
815 dbg("%s - 6 bits/byte not supported", __func__
);
816 spin_unlock_irqrestore(&priv
->lock
, flags
);
819 priv
->cfg
.databits
= kl5kusb105a_dtb_7
;
822 priv
->cfg
.databits
= kl5kusb105a_dtb_8
;
826 "CSIZE was not CS5-CS8, using default of 8\n");
827 priv
->cfg
.databits
= kl5kusb105a_dtb_8
;
833 * Update line control register (LCR)
835 if ((cflag
& (PARENB
|PARODD
)) != (old_cflag
& (PARENB
|PARODD
))
836 || (cflag
& CSTOPB
) != (old_cflag
& CSTOPB
)) {
837 /* Not currently supported */
838 tty
->termios
->c_cflag
&= ~(PARENB
|PARODD
|CSTOPB
);
844 priv
->last_lcr
|= (cflag
& PARODD
) ?
845 MCT_U232_PARITY_ODD
: MCT_U232_PARITY_EVEN
;
847 priv
->last_lcr
|= MCT_U232_PARITY_NONE
;
849 /* set the number of stop bits */
850 priv
->last_lcr
|= (cflag
& CSTOPB
) ?
851 MCT_U232_STOP_BITS_2
: MCT_U232_STOP_BITS_1
;
853 mct_u232_set_line_ctrl(serial
, priv
->last_lcr
);
858 * Set flow control: well, I do not really now how to handle DTR/RTS.
859 * Just do what we have seen with SniffUSB on Win98.
861 if ((iflag
& IXOFF
) != (old_iflag
& IXOFF
)
862 || (iflag
& IXON
) != (old_iflag
& IXON
)
863 || (cflag
& CRTSCTS
) != (old_cflag
& CRTSCTS
)) {
864 /* Not currently supported */
865 tty
->termios
->c_cflag
&= ~CRTSCTS
;
866 /* Drop DTR/RTS if no flow control otherwise assert */
868 if ((iflag
& IXOFF
) || (iflag
& IXON
) || (cflag
& CRTSCTS
))
869 priv
->control_state
|= TIOCM_DTR
| TIOCM_RTS
;
871 priv
->control_state
&= ~(TIOCM_DTR
| TIOCM_RTS
);
872 mct_u232_set_modem_ctrl(serial
, priv
->control_state
);
876 memcpy(cfg
, &priv
->cfg
, sizeof(*cfg
));
877 spin_unlock_irqrestore(&priv
->lock
, flags
);
879 /* now commit changes to device */
880 klsi_105_chg_port_settings(port
, cfg
);
886 static void mct_u232_break_ctl(struct tty_struct
*tty
, int break_state
)
888 struct usb_serial_port
*port
= tty
->driver_data
;
889 struct usb_serial
*serial
= port
->serial
;
890 struct mct_u232_private
*priv
=
891 (struct mct_u232_private
*)port
->private;
892 unsigned char lcr
= priv
->last_lcr
;
894 dbg("%sstate=%d", __func__
, break_state
);
898 lcr
|= MCT_U232_SET_BREAK
;
900 mct_u232_set_line_ctrl(serial
, lcr
);
904 static int klsi_105_tiocmget(struct tty_struct
*tty
, struct file
*file
)
906 struct usb_serial_port
*port
= tty
->driver_data
;
907 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
910 unsigned long line_state
;
911 dbg("%s - request, just guessing", __func__
);
913 rc
= klsi_105_get_line_state(port
, &line_state
);
916 "Reading line control failed (error = %d)\n", rc
);
917 /* better return value? EAGAIN? */
921 spin_lock_irqsave(&priv
->lock
, flags
);
922 priv
->line_state
= line_state
;
923 spin_unlock_irqrestore(&priv
->lock
, flags
);
924 dbg("%s - read line state 0x%lx", __func__
, line_state
);
925 return (int)line_state
;
928 static int klsi_105_tiocmset(struct tty_struct
*tty
, struct file
*file
,
929 unsigned int set
, unsigned int clear
)
931 int retval
= -EINVAL
;
935 /* if this ever gets implemented, it should be done something like this:
936 struct usb_serial *serial = port->serial;
937 struct klsi_105_private *priv = usb_get_serial_port_data(port);
941 spin_lock_irqsave (&priv->lock, flags);
943 priv->control_state |= TIOCM_RTS;
945 priv->control_state |= TIOCM_DTR;
946 if (clear & TIOCM_RTS)
947 priv->control_state &= ~TIOCM_RTS;
948 if (clear & TIOCM_DTR)
949 priv->control_state &= ~TIOCM_DTR;
950 control = priv->control_state;
951 spin_unlock_irqrestore (&priv->lock, flags);
952 retval = mct_u232_set_modem_ctrl(serial, control);
957 static void klsi_105_throttle(struct tty_struct
*tty
)
959 struct usb_serial_port
*port
= tty
->driver_data
;
960 dbg("%s - port %d", __func__
, port
->number
);
961 usb_kill_urb(port
->read_urb
);
964 static void klsi_105_unthrottle(struct tty_struct
*tty
)
966 struct usb_serial_port
*port
= tty
->driver_data
;
969 dbg("%s - port %d", __func__
, port
->number
);
971 port
->read_urb
->dev
= port
->serial
->dev
;
972 result
= usb_submit_urb(port
->read_urb
, GFP_KERNEL
);
975 "%s - failed submitting read urb, error %d\n",
980 static int __init
klsi_105_init(void)
983 retval
= usb_serial_register(&kl5kusb105d_device
);
985 goto failed_usb_serial_register
;
986 retval
= usb_register(&kl5kusb105d_driver
);
988 goto failed_usb_register
;
990 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_VERSION
":"
994 usb_serial_deregister(&kl5kusb105d_device
);
995 failed_usb_serial_register
:
999 static void __exit
klsi_105_exit(void)
1001 usb_deregister(&kl5kusb105d_driver
);
1002 usb_serial_deregister(&kl5kusb105d_device
);
1006 module_init(klsi_105_init
);
1007 module_exit(klsi_105_exit
);
1009 MODULE_AUTHOR(DRIVER_AUTHOR
);
1010 MODULE_DESCRIPTION(DRIVER_DESC
);
1011 MODULE_LICENSE("GPL");
1014 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
1015 MODULE_PARM_DESC(debug
, "enable extensive debugging messages");