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_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
,
79 struct usb_serial_port
*port
, struct file
*filp
);
80 static void klsi_105_close(struct usb_serial_port
*port
);
81 static int klsi_105_write(struct tty_struct
*tty
,
82 struct usb_serial_port
*port
, const unsigned char *buf
, int count
);
83 static void klsi_105_write_bulk_callback(struct urb
*urb
);
84 static int klsi_105_chars_in_buffer(struct tty_struct
*tty
);
85 static int klsi_105_write_room(struct tty_struct
*tty
);
86 static void klsi_105_read_bulk_callback(struct urb
*urb
);
87 static void klsi_105_set_termios(struct tty_struct
*tty
,
88 struct usb_serial_port
*port
, struct ktermios
*old
);
89 static void klsi_105_throttle(struct tty_struct
*tty
);
90 static void klsi_105_unthrottle(struct tty_struct
*tty
);
91 static int klsi_105_tiocmget(struct tty_struct
*tty
, struct file
*file
);
92 static int klsi_105_tiocmset(struct tty_struct
*tty
, struct file
*file
,
93 unsigned int set
, unsigned int clear
);
96 * All of the device info needed for the KLSI converters.
98 static struct usb_device_id id_table
[] = {
99 { USB_DEVICE(PALMCONNECT_VID
, PALMCONNECT_PID
) },
100 { USB_DEVICE(KLSI_VID
, KLSI_KL5KUSB105D_PID
) },
101 { } /* Terminating entry */
104 MODULE_DEVICE_TABLE(usb
, id_table
);
106 static struct usb_driver kl5kusb105d_driver
= {
107 .name
= "kl5kusb105d",
108 .probe
= usb_serial_probe
,
109 .disconnect
= usb_serial_disconnect
,
110 .id_table
= id_table
,
114 static struct usb_serial_driver kl5kusb105d_device
= {
116 .owner
= THIS_MODULE
,
117 .name
= "kl5kusb105d",
119 .description
= "KL5KUSB105D / PalmConnect",
120 .usb_driver
= &kl5kusb105d_driver
,
121 .id_table
= id_table
,
123 .open
= klsi_105_open
,
124 .close
= klsi_105_close
,
125 .write
= klsi_105_write
,
126 .write_bulk_callback
= klsi_105_write_bulk_callback
,
127 .chars_in_buffer
= klsi_105_chars_in_buffer
,
128 .write_room
= klsi_105_write_room
,
129 .read_bulk_callback
= klsi_105_read_bulk_callback
,
130 .set_termios
= klsi_105_set_termios
,
131 /*.break_ctl = klsi_105_break_ctl,*/
132 .tiocmget
= klsi_105_tiocmget
,
133 .tiocmset
= klsi_105_tiocmset
,
134 .attach
= klsi_105_startup
,
135 .disconnect
= klsi_105_disconnect
,
136 .release
= klsi_105_release
,
137 .throttle
= klsi_105_throttle
,
138 .unthrottle
= klsi_105_unthrottle
,
141 struct klsi_105_port_settings
{
142 __u8 pktlen
; /* always 5, it seems */
147 } __attribute__ ((packed
));
149 /* we implement a pool of NUM_URBS urbs per usb_serial */
151 #define URB_TRANSFER_BUFFER_SIZE 64
152 struct klsi_105_private
{
153 struct klsi_105_port_settings cfg
;
154 struct ktermios termios
;
155 unsigned long line_state
; /* modem line settings */
157 struct urb
*write_urb_pool
[NUM_URBS
];
159 unsigned long bytes_in
;
160 unsigned long bytes_out
;
165 * Handle vendor specific USB requests
169 #define KLSI_TIMEOUT 5000 /* default urb timeout */
171 static int klsi_105_chg_port_settings(struct usb_serial_port
*port
,
172 struct klsi_105_port_settings
*settings
)
176 rc
= usb_control_msg(port
->serial
->dev
,
177 usb_sndctrlpipe(port
->serial
->dev
, 0),
178 KL5KUSB105A_SIO_SET_DATA
,
179 USB_TYPE_VENDOR
| USB_DIR_OUT
| USB_RECIP_INTERFACE
,
183 sizeof(struct klsi_105_port_settings
),
187 "Change port settings failed (error = %d)\n", rc
);
188 dev_info(&port
->serial
->dev
->dev
,
189 "%d byte block, baudrate %x, databits %d, u1 %d, u2 %d\n",
190 settings
->pktlen
, settings
->baudrate
, settings
->databits
,
191 settings
->unknown1
, settings
->unknown2
);
193 } /* klsi_105_chg_port_settings */
195 /* translate a 16-bit status value from the device to linux's TIO bits */
196 static unsigned long klsi_105_status2linestate(const __u16 status
)
198 unsigned long res
= 0;
200 res
= ((status
& KL5KUSB105A_DSR
) ? TIOCM_DSR
: 0)
201 | ((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
)
216 __u8 status_buf
[KLSI_STATUSBUF_LEN
] = { -1, -1};
219 dev_info(&port
->serial
->dev
->dev
, "sending SIO Poll request\n");
220 rc
= usb_control_msg(port
->serial
->dev
,
221 usb_rcvctrlpipe(port
->serial
->dev
, 0),
222 KL5KUSB105A_SIO_POLL
,
223 USB_TYPE_VENDOR
| USB_DIR_IN
,
226 status_buf
, KLSI_STATUSBUF_LEN
,
230 dev_err(&port
->dev
, "Reading line status failed (error = %d)\n",
233 status
= get_unaligned_le16(status_buf
);
235 dev_info(&port
->serial
->dev
->dev
, "read status %x %x",
236 status_buf
[0], status_buf
[1]);
238 *line_state_p
= klsi_105_status2linestate(status
);
245 * Driver's tty interface functions
248 static int klsi_105_startup(struct usb_serial
*serial
)
250 struct klsi_105_private
*priv
;
253 /* check if we support the product id (see keyspan.c)
257 /* allocate the private data structure */
258 for (i
= 0; i
< serial
->num_ports
; i
++) {
259 priv
= kmalloc(sizeof(struct klsi_105_private
),
262 dbg("%skmalloc for klsi_105_private failed.", __func__
);
266 /* set initial values for control structures */
267 priv
->cfg
.pktlen
= 5;
268 priv
->cfg
.baudrate
= kl5kusb105a_sio_b9600
;
269 priv
->cfg
.databits
= kl5kusb105a_dtb_8
;
270 priv
->cfg
.unknown1
= 0;
271 priv
->cfg
.unknown2
= 1;
273 priv
->line_state
= 0;
277 usb_set_serial_port_data(serial
->port
[i
], priv
);
279 spin_lock_init(&priv
->lock
);
280 for (j
= 0; j
< NUM_URBS
; j
++) {
281 struct urb
*urb
= usb_alloc_urb(0, GFP_KERNEL
);
283 priv
->write_urb_pool
[j
] = urb
;
285 dev_err(&serial
->dev
->dev
, "No more urbs???\n");
289 urb
->transfer_buffer
=
290 kmalloc(URB_TRANSFER_BUFFER_SIZE
, GFP_KERNEL
);
291 if (!urb
->transfer_buffer
) {
292 dev_err(&serial
->dev
->dev
,
293 "%s - out of memory for urb buffers.\n",
299 /* priv->termios is left uninitalized until port opening */
300 init_waitqueue_head(&serial
->port
[i
]->write_wait
);
306 for (; i
>= 0; i
--) {
307 priv
= usb_get_serial_port_data(serial
->port
[i
]);
308 for (j
= 0; j
< NUM_URBS
; j
++) {
309 if (priv
->write_urb_pool
[j
]) {
310 kfree(priv
->write_urb_pool
[j
]->transfer_buffer
);
311 usb_free_urb(priv
->write_urb_pool
[j
]);
314 usb_set_serial_port_data(serial
->port
[i
], NULL
);
317 } /* klsi_105_startup */
320 static void klsi_105_disconnect(struct usb_serial
*serial
)
326 /* stop reads and writes on all ports */
327 for (i
= 0; i
< serial
->num_ports
; ++i
) {
328 struct klsi_105_private
*priv
=
329 usb_get_serial_port_data(serial
->port
[i
]);
332 /* kill our write urb pool */
334 struct urb
**write_urbs
= priv
->write_urb_pool
;
336 for (j
= 0; j
< NUM_URBS
; j
++) {
338 usb_kill_urb(write_urbs
[j
]);
339 usb_free_urb(write_urbs
[j
]);
344 } /* klsi_105_disconnect */
347 static void klsi_105_release(struct usb_serial
*serial
)
353 for (i
= 0; i
< serial
->num_ports
; ++i
) {
354 struct klsi_105_private
*priv
=
355 usb_get_serial_port_data(serial
->port
[i
]);
359 } /* klsi_105_release */
361 static int klsi_105_open(struct tty_struct
*tty
,
362 struct usb_serial_port
*port
, struct file
*filp
)
364 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
368 unsigned long line_state
;
369 struct klsi_105_port_settings cfg
;
372 dbg("%s port %d", __func__
, port
->number
);
374 /* force low_latency on so that our tty_push actually forces
376 * tty->low_latency = 1; */
378 /* Do a defined restart:
379 * Set up sane default baud rate and send the 'READ_ON'
381 * FIXME: set modem line control (how?)
382 * Then read the modem line control and store values in
386 cfg
.baudrate
= kl5kusb105a_sio_b9600
;
387 cfg
.databits
= kl5kusb105a_dtb_8
;
390 klsi_105_chg_port_settings(port
, &cfg
);
392 /* set up termios structure */
393 spin_lock_irqsave(&priv
->lock
, flags
);
394 priv
->termios
.c_iflag
= tty
->termios
->c_iflag
;
395 priv
->termios
.c_oflag
= tty
->termios
->c_oflag
;
396 priv
->termios
.c_cflag
= tty
->termios
->c_cflag
;
397 priv
->termios
.c_lflag
= tty
->termios
->c_lflag
;
398 for (i
= 0; i
< NCCS
; i
++)
399 priv
->termios
.c_cc
[i
] = tty
->termios
->c_cc
[i
];
400 priv
->cfg
.pktlen
= cfg
.pktlen
;
401 priv
->cfg
.baudrate
= cfg
.baudrate
;
402 priv
->cfg
.databits
= cfg
.databits
;
403 priv
->cfg
.unknown1
= cfg
.unknown1
;
404 priv
->cfg
.unknown2
= cfg
.unknown2
;
405 spin_unlock_irqrestore(&priv
->lock
, flags
);
407 /* READ_ON and urb submission */
408 usb_fill_bulk_urb(port
->read_urb
, port
->serial
->dev
,
409 usb_rcvbulkpipe(port
->serial
->dev
,
410 port
->bulk_in_endpointAddress
),
411 port
->read_urb
->transfer_buffer
,
412 port
->read_urb
->transfer_buffer_length
,
413 klsi_105_read_bulk_callback
,
416 rc
= usb_submit_urb(port
->read_urb
, GFP_KERNEL
);
418 dev_err(&port
->dev
, "%s - failed submitting read urb, "
419 "error %d\n", __func__
, rc
);
424 rc
= usb_control_msg(port
->serial
->dev
,
425 usb_sndctrlpipe(port
->serial
->dev
, 0),
426 KL5KUSB105A_SIO_CONFIGURE
,
427 USB_TYPE_VENDOR
|USB_DIR_OUT
|USB_RECIP_INTERFACE
,
428 KL5KUSB105A_SIO_CONFIGURE_READ_ON
,
434 dev_err(&port
->dev
, "Enabling read failed (error = %d)\n", rc
);
437 dbg("%s - enabled reading", __func__
);
439 rc
= klsi_105_get_line_state(port
, &line_state
);
441 spin_lock_irqsave(&priv
->lock
, flags
);
442 priv
->line_state
= line_state
;
443 spin_unlock_irqrestore(&priv
->lock
, flags
);
444 dbg("%s - read line state 0x%lx", __func__
, line_state
);
451 } /* klsi_105_open */
454 static void klsi_105_close(struct usb_serial_port
*port
)
456 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
459 dbg("%s port %d", __func__
, port
->number
);
461 mutex_lock(&port
->serial
->disc_mutex
);
462 if (!port
->serial
->disconnected
) {
464 rc
= usb_control_msg(port
->serial
->dev
,
465 usb_sndctrlpipe(port
->serial
->dev
, 0),
466 KL5KUSB105A_SIO_CONFIGURE
,
467 USB_TYPE_VENDOR
| USB_DIR_OUT
,
468 KL5KUSB105A_SIO_CONFIGURE_READ_OFF
,
474 "Disabling read failed (error = %d)\n", rc
);
476 mutex_unlock(&port
->serial
->disc_mutex
);
478 /* shutdown our bulk reads and writes */
479 usb_kill_urb(port
->write_urb
);
480 usb_kill_urb(port
->read_urb
);
481 /* unlink our write pool */
483 /* wgg - do I need this? I think so. */
484 usb_kill_urb(port
->interrupt_in_urb
);
485 dev_info(&port
->serial
->dev
->dev
,
486 "port stats: %ld bytes in, %ld bytes out\n",
487 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 tty_struct
*tty
,
499 struct usb_serial_port
*port
, const unsigned char *buf
, int count
)
501 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
505 dbg("%s - port %d", __func__
, 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
514 spin_lock_irqsave(&priv
->lock
, flags
);
515 for (i
= 0; i
< NUM_URBS
; i
++) {
516 if (priv
->write_urb_pool
[i
]->status
!= -EINPROGRESS
) {
517 urb
= priv
->write_urb_pool
[i
];
518 dbg("%s - using pool URB %d", __func__
, i
);
522 spin_unlock_irqrestore(&priv
->lock
, flags
);
525 dbg("%s - no more free urbs", __func__
);
529 if (urb
->transfer_buffer
== NULL
) {
530 urb
->transfer_buffer
=
531 kmalloc(URB_TRANSFER_BUFFER_SIZE
, GFP_ATOMIC
);
532 if (urb
->transfer_buffer
== NULL
) {
534 "%s - no more kernel memory...\n",
540 size
= min(count
, port
->bulk_out_size
- KLSI_105_DATA_OFFSET
);
541 size
= min(size
, URB_TRANSFER_BUFFER_SIZE
-
542 KLSI_105_DATA_OFFSET
);
544 memcpy(urb
->transfer_buffer
+ KLSI_105_DATA_OFFSET
, buf
, size
);
546 /* write payload size into transfer buffer */
547 ((__u8
*)urb
->transfer_buffer
)[0] = (__u8
) (size
& 0xFF);
548 ((__u8
*)urb
->transfer_buffer
)[1] = (__u8
) ((size
& 0xFF00)>>8);
551 usb_fill_bulk_urb(urb
, port
->serial
->dev
,
552 usb_sndbulkpipe(port
->serial
->dev
,
553 port
->bulk_out_endpointAddress
),
554 urb
->transfer_buffer
,
555 URB_TRANSFER_BUFFER_SIZE
,
556 klsi_105_write_bulk_callback
,
559 /* send the data out the bulk port */
560 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
563 "%s - failed submitting write urb, error %d\n",
572 /* lockless, but it's for debug info only... */
573 priv
->bytes_out
+= bytes_sent
;
575 return bytes_sent
; /* that's how much we wrote */
576 } /* klsi_105_write */
578 static void klsi_105_write_bulk_callback(struct urb
*urb
)
580 struct usb_serial_port
*port
= urb
->context
;
581 int status
= urb
->status
;
583 dbg("%s - port %d", __func__
, port
->number
);
586 dbg("%s - nonzero write bulk status received: %d", __func__
,
591 usb_serial_port_softint(port
);
592 } /* klsi_105_write_bulk_completion_callback */
595 /* return number of characters currently in the writing process */
596 static int klsi_105_chars_in_buffer(struct tty_struct
*tty
)
598 struct usb_serial_port
*port
= tty
->driver_data
;
602 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
604 spin_lock_irqsave(&priv
->lock
, flags
);
606 for (i
= 0; i
< NUM_URBS
; ++i
) {
607 if (priv
->write_urb_pool
[i
]->status
== -EINPROGRESS
)
608 chars
+= URB_TRANSFER_BUFFER_SIZE
;
611 spin_unlock_irqrestore(&priv
->lock
, flags
);
613 dbg("%s - returns %d", __func__
, chars
);
617 static int klsi_105_write_room(struct tty_struct
*tty
)
619 struct usb_serial_port
*port
= tty
->driver_data
;
623 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
625 spin_lock_irqsave(&priv
->lock
, flags
);
626 for (i
= 0; i
< NUM_URBS
; ++i
) {
627 if (priv
->write_urb_pool
[i
]->status
!= -EINPROGRESS
)
628 room
+= URB_TRANSFER_BUFFER_SIZE
;
631 spin_unlock_irqrestore(&priv
->lock
, flags
);
633 dbg("%s - returns %d", __func__
, room
);
639 static void klsi_105_read_bulk_callback(struct urb
*urb
)
641 struct usb_serial_port
*port
= urb
->context
;
642 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
643 struct tty_struct
*tty
;
644 unsigned char *data
= urb
->transfer_buffer
;
646 int status
= urb
->status
;
648 dbg("%s - port %d", __func__
, port
->number
);
650 /* The urb might have been killed. */
652 dbg("%s - nonzero read bulk status received: %d", __func__
,
657 /* The data received is again preceded by a length double-byte in LSB-
658 * first order (see klsi_105_write() )
660 if (urb
->actual_length
== 0) {
661 /* empty urbs seem to happen, we ignore them */
662 /* dbg("%s - emtpy URB", __func__); */
664 } else if (urb
->actual_length
<= 2) {
665 dbg("%s - size %d URB not understood", __func__
,
667 usb_serial_debug_data(debug
, &port
->dev
, __func__
,
668 urb
->actual_length
, data
);
670 int bytes_sent
= ((__u8
*) data
)[0] +
671 ((unsigned int) ((__u8
*) data
)[1] << 8);
672 tty
= tty_port_tty_get(&port
->port
);
673 /* we should immediately resubmit the URB, before attempting
674 * to pass the data on to the tty layer. But that needs locking
675 * against re-entry an then mixed-up data because of
676 * intermixed tty_flip_buffer_push()s
679 usb_serial_debug_data(debug
, &port
->dev
, __func__
,
680 urb
->actual_length
, data
);
682 if (bytes_sent
+ 2 > urb
->actual_length
) {
683 dbg("%s - trying to read more data than available"
684 " (%d vs. %d)", __func__
,
685 bytes_sent
+2, urb
->actual_length
);
686 /* cap at implied limit */
687 bytes_sent
= urb
->actual_length
- 2;
690 tty_buffer_request_room(tty
, bytes_sent
);
691 tty_insert_flip_string(tty
, data
+ 2, bytes_sent
);
692 tty_flip_buffer_push(tty
);
695 /* again lockless, but debug info only */
696 priv
->bytes_in
+= bytes_sent
;
698 /* Continue trying to always read */
699 usb_fill_bulk_urb(port
->read_urb
, port
->serial
->dev
,
700 usb_rcvbulkpipe(port
->serial
->dev
,
701 port
->bulk_in_endpointAddress
),
702 port
->read_urb
->transfer_buffer
,
703 port
->read_urb
->transfer_buffer_length
,
704 klsi_105_read_bulk_callback
,
706 rc
= usb_submit_urb(port
->read_urb
, GFP_ATOMIC
);
709 "%s - failed resubmitting read urb, error %d\n",
711 } /* klsi_105_read_bulk_callback */
714 static void klsi_105_set_termios(struct tty_struct
*tty
,
715 struct usb_serial_port
*port
,
716 struct ktermios
*old_termios
)
718 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
719 unsigned int iflag
= tty
->termios
->c_iflag
;
720 unsigned int old_iflag
= old_termios
->c_iflag
;
721 unsigned int cflag
= tty
->termios
->c_cflag
;
722 unsigned int old_cflag
= old_termios
->c_cflag
;
723 struct klsi_105_port_settings cfg
;
727 /* lock while we are modifying the settings */
728 spin_lock_irqsave(&priv
->lock
, flags
);
733 baud
= tty_get_baud_rate(tty
);
735 if ((cflag
& CBAUD
) != (old_cflag
& CBAUD
)) {
736 /* reassert DTR and (maybe) RTS on transition from B0 */
737 if ((old_cflag
& CBAUD
) == B0
) {
738 dbg("%s: baud was B0", __func__
);
740 priv
->control_state
|= TIOCM_DTR
;
741 /* don't set RTS if using hardware flow control */
742 if (!(old_cflag
& CRTSCTS
))
743 priv
->control_state
|= TIOCM_RTS
;
744 mct_u232_set_modem_ctrl(serial
, priv
->control_state
);
749 case 0: /* handled below */
752 priv
->cfg
.baudrate
= kl5kusb105a_sio_b1200
;
755 priv
->cfg
.baudrate
= kl5kusb105a_sio_b2400
;
758 priv
->cfg
.baudrate
= kl5kusb105a_sio_b4800
;
761 priv
->cfg
.baudrate
= kl5kusb105a_sio_b9600
;
764 priv
->cfg
.baudrate
= kl5kusb105a_sio_b19200
;
767 priv
->cfg
.baudrate
= kl5kusb105a_sio_b38400
;
770 priv
->cfg
.baudrate
= kl5kusb105a_sio_b57600
;
773 priv
->cfg
.baudrate
= kl5kusb105a_sio_b115200
;
776 dbg("KLSI USB->Serial converter:"
777 " unsupported baudrate request, using default of 9600");
778 priv
->cfg
.baudrate
= kl5kusb105a_sio_b9600
;
782 if ((cflag
& CBAUD
) == B0
) {
783 dbg("%s: baud is B0", __func__
);
784 /* Drop RTS and DTR */
785 /* maybe this should be simulated by sending read
786 * disable and read enable messages?
790 priv
->control_state
&= ~(TIOCM_DTR
| TIOCM_RTS
);
791 mct_u232_set_modem_ctrl(serial
, priv
->control_state
);
794 tty_encode_baud_rate(tty
, baud
, baud
);
796 if ((cflag
& CSIZE
) != (old_cflag
& CSIZE
)) {
797 /* set the number of data bits */
798 switch (cflag
& CSIZE
) {
800 dbg("%s - 5 bits/byte not supported", __func__
);
801 spin_unlock_irqrestore(&priv
->lock
, flags
);
804 dbg("%s - 6 bits/byte not supported", __func__
);
805 spin_unlock_irqrestore(&priv
->lock
, flags
);
808 priv
->cfg
.databits
= kl5kusb105a_dtb_7
;
811 priv
->cfg
.databits
= kl5kusb105a_dtb_8
;
815 "CSIZE was not CS5-CS8, using default of 8\n");
816 priv
->cfg
.databits
= kl5kusb105a_dtb_8
;
822 * Update line control register (LCR)
824 if ((cflag
& (PARENB
|PARODD
)) != (old_cflag
& (PARENB
|PARODD
))
825 || (cflag
& CSTOPB
) != (old_cflag
& CSTOPB
)) {
826 /* Not currently supported */
827 tty
->termios
->c_cflag
&= ~(PARENB
|PARODD
|CSTOPB
);
833 priv
->last_lcr
|= (cflag
& PARODD
) ?
834 MCT_U232_PARITY_ODD
: MCT_U232_PARITY_EVEN
;
836 priv
->last_lcr
|= MCT_U232_PARITY_NONE
;
838 /* set the number of stop bits */
839 priv
->last_lcr
|= (cflag
& CSTOPB
) ?
840 MCT_U232_STOP_BITS_2
: MCT_U232_STOP_BITS_1
;
842 mct_u232_set_line_ctrl(serial
, priv
->last_lcr
);
847 * Set flow control: well, I do not really now how to handle DTR/RTS.
848 * Just do what we have seen with SniffUSB on Win98.
850 if ((iflag
& IXOFF
) != (old_iflag
& IXOFF
)
851 || (iflag
& IXON
) != (old_iflag
& IXON
)
852 || (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
=
879 (struct mct_u232_private
*)port
->private;
880 unsigned char lcr
= priv
->last_lcr
;
882 dbg("%sstate=%d", __func__
, break_state
);
886 lcr
|= MCT_U232_SET_BREAK
;
888 mct_u232_set_line_ctrl(serial
, lcr
);
889 } /* mct_u232_break_ctl */
892 static int klsi_105_tiocmget(struct tty_struct
*tty
, struct file
*file
)
894 struct usb_serial_port
*port
= tty
->driver_data
;
895 struct klsi_105_private
*priv
= usb_get_serial_port_data(port
);
898 unsigned long line_state
;
899 dbg("%s - request, just guessing", __func__
);
901 rc
= klsi_105_get_line_state(port
, &line_state
);
904 "Reading line control failed (error = %d)\n", rc
);
905 /* better return value? EAGAIN? */
909 spin_lock_irqsave(&priv
->lock
, flags
);
910 priv
->line_state
= line_state
;
911 spin_unlock_irqrestore(&priv
->lock
, flags
);
912 dbg("%s - read line state 0x%lx", __func__
, line_state
);
913 return (int)line_state
;
916 static int klsi_105_tiocmset(struct tty_struct
*tty
, struct file
*file
,
917 unsigned int set
, unsigned int clear
)
919 int retval
= -EINVAL
;
923 /* if this ever gets implemented, it should be done something like this:
924 struct usb_serial *serial = port->serial;
925 struct klsi_105_private *priv = usb_get_serial_port_data(port);
929 spin_lock_irqsave (&priv->lock, flags);
931 priv->control_state |= TIOCM_RTS;
933 priv->control_state |= TIOCM_DTR;
934 if (clear & TIOCM_RTS)
935 priv->control_state &= ~TIOCM_RTS;
936 if (clear & TIOCM_DTR)
937 priv->control_state &= ~TIOCM_DTR;
938 control = priv->control_state;
939 spin_unlock_irqrestore (&priv->lock, flags);
940 retval = mct_u232_set_modem_ctrl(serial, control);
945 static void klsi_105_throttle(struct tty_struct
*tty
)
947 struct usb_serial_port
*port
= tty
->driver_data
;
948 dbg("%s - port %d", __func__
, port
->number
);
949 usb_kill_urb(port
->read_urb
);
952 static void klsi_105_unthrottle(struct tty_struct
*tty
)
954 struct usb_serial_port
*port
= tty
->driver_data
;
957 dbg("%s - port %d", __func__
, port
->number
);
959 port
->read_urb
->dev
= port
->serial
->dev
;
960 result
= usb_submit_urb(port
->read_urb
, GFP_ATOMIC
);
963 "%s - failed submitting read urb, error %d\n",
969 static int __init
klsi_105_init(void)
972 retval
= usb_serial_register(&kl5kusb105d_device
);
974 goto failed_usb_serial_register
;
975 retval
= usb_register(&kl5kusb105d_driver
);
977 goto failed_usb_register
;
979 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_VERSION
":"
983 usb_serial_deregister(&kl5kusb105d_device
);
984 failed_usb_serial_register
:
989 static void __exit
klsi_105_exit(void)
991 usb_deregister(&kl5kusb105d_driver
);
992 usb_serial_deregister(&kl5kusb105d_device
);
996 module_init(klsi_105_init
);
997 module_exit(klsi_105_exit
);
999 MODULE_AUTHOR(DRIVER_AUTHOR
);
1000 MODULE_DESCRIPTION(DRIVER_DESC
);
1001 MODULE_LICENSE("GPL");
1004 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
1005 MODULE_PARM_DESC(debug
, "enable extensive debugging messages");
1007 /* vim: set sts=8 ts=8 sw=8: */