38 #include <linux/kernel.h>
39 #include <linux/errno.h>
41 #include <linux/slab.h>
42 #include <linux/tty.h>
45 #include <linux/module.h>
47 #include <asm/unaligned.h>
55 #define DRIVER_VERSION "v0.4"
57 #define DRIVER_DESC "KLSI KL5KUSB105 chipset USB->Serial Converter driver"
67 static void klsi_105_set_termios(
struct tty_struct *tty,
69 static int klsi_105_tiocmget(
struct tty_struct *tty);
70 static int klsi_105_tiocmset(
struct tty_struct *tty,
71 unsigned int set,
unsigned int clear);
72 static void klsi_105_process_read_urb(
struct urb *
urb);
90 .name =
"kl5kusb105d",
92 .description =
"KL5KUSB105D / PalmConnect",
96 .open = klsi_105_open,
97 .close = klsi_105_close,
98 .set_termios = klsi_105_set_termios,
100 .tiocmget = klsi_105_tiocmget,
101 .tiocmset = klsi_105_tiocmset,
102 .port_probe = klsi_105_port_probe,
103 .port_remove = klsi_105_port_remove,
106 .process_read_urb = klsi_105_process_read_urb,
107 .prepare_write_buffer = klsi_105_prepare_write_buffer,
111 &kl5kusb105d_device,
NULL
135 #define KLSI_TIMEOUT 5000
143 usb_sndctrlpipe(port->
serial->dev, 0),
153 "Change port settings failed (error = %d)\n", rc);
155 "%d byte block, baudrate %x, databits %d, u1 %d, u2 %d\n",
162 static unsigned long klsi_105_status2linestate(
const __u16 status)
164 unsigned long res = 0;
178 #define KLSI_STATUSBUF_LEN 2
180 unsigned long *line_state_p)
190 dev_err(&port->
dev,
"%s - out of memory for status buffer.\n",
194 status_buf[0] = 0xff;
195 status_buf[1] = 0xff;
197 usb_rcvctrlpipe(port->
serial->dev, 0),
206 dev_err(&port->
dev,
"Reading line status failed (error = %d)\n",
209 status = get_unaligned_le16(status_buf);
212 status_buf[0], status_buf[1]);
214 *line_state_p = klsi_105_status2linestate(status);
235 priv->
cfg.pktlen = 5;
238 priv->
cfg.unknown1 = 0;
239 priv->
cfg.unknown2 = 1;
247 usb_set_serial_port_data(port, priv);
256 priv = usb_get_serial_port_data(port);
281 dev_err(&port->
dev,
"%s - out of memory for config buffer.\n",
290 klsi_105_chg_port_settings(port, cfg);
294 priv->
termios.c_iflag = tty->termios.c_iflag;
295 priv->
termios.c_oflag = tty->termios.c_oflag;
296 priv->
termios.c_cflag = tty->termios.c_cflag;
297 priv->
termios.c_lflag = tty->termios.c_lflag;
298 for (i = 0; i <
NCCS; i++)
299 priv->
termios.c_cc[i] = tty->termios.c_cc[i];
305 spin_unlock_irqrestore(&priv->
lock, flags);
315 usb_sndctrlpipe(port->
serial->dev, 0),
324 dev_err(&port->
dev,
"Enabling read failed (error = %d)\n", rc);
327 dev_dbg(&port->
dev,
"%s - enabled reading\n", __func__);
329 rc = klsi_105_get_line_state(port, &line_state);
333 spin_unlock_irqrestore(&priv->
lock, flags);
334 dev_dbg(&port->
dev,
"%s - read line state 0x%lx\n", __func__, line_state);
349 if (!port->
serial->disconnected) {
352 usb_sndctrlpipe(port->
serial->dev, 0),
361 "Disabling read failed (error = %d)\n", rc);
376 #define KLSI_HDR_LEN 2
385 put_unaligned_le16(count, buf);
392 static void klsi_105_process_read_urb(
struct urb *
urb)
395 unsigned char *
data = urb->transfer_buffer;
400 if (!urb->actual_length)
404 dev_dbg(&port->
dev,
"%s - malformed packet\n", __func__);
412 len = get_unaligned_le16(data);
414 dev_dbg(&port->
dev,
"%s - packet length mismatch\n", __func__);
423 static void klsi_105_set_termios(
struct tty_struct *tty,
429 unsigned int iflag = tty->termios.c_iflag;
430 unsigned int old_iflag = old_termios->
c_iflag;
431 unsigned int cflag = tty->termios.c_cflag;
432 unsigned int old_cflag = old_termios->
c_cflag;
439 dev_err(dev,
"%s - out of memory for config buffer.\n", __func__);
451 if ((cflag &
CBAUD) != (old_cflag & CBAUD)) {
453 if ((old_cflag & CBAUD) ==
B0) {
454 dev_dbg(dev,
"%s: baud was B0\n", __func__);
460 mct_u232_set_modem_ctrl(
serial, priv->control_state);
492 dev_dbg(dev,
"KLSI USB->Serial converter: unsupported baudrate request, using default of 9600");
497 if ((cflag & CBAUD) ==
B0) {
498 dev_dbg(dev,
"%s: baud is B0\n", __func__);
506 mct_u232_set_modem_ctrl(
serial, priv->control_state);
511 if ((cflag &
CSIZE) != (old_cflag & CSIZE)) {
513 switch (cflag & CSIZE) {
515 dev_dbg(dev,
"%s - 5 bits/byte not supported\n", __func__);
516 spin_unlock_irqrestore(&priv->
lock, flags);
519 dev_dbg(dev,
"%s - 6 bits/byte not supported\n", __func__);
520 spin_unlock_irqrestore(&priv->
lock, flags);
529 dev_err(dev,
"CSIZE was not CS5-CS8, using default of 8\n");
539 || (cflag &
CSTOPB) != (old_cflag & CSTOPB)) {
547 priv->last_lcr |= (cflag &
PARODD) ?
553 priv->last_lcr |= (cflag &
CSTOPB) ?
556 mct_u232_set_line_ctrl(
serial, priv->last_lcr);
564 if ((iflag &
IXOFF) != (old_iflag & IXOFF)
565 || (iflag &
IXON) != (old_iflag & IXON)
566 || (cflag &
CRTSCTS) != (old_cflag & CRTSCTS)) {
568 tty->termios.c_cflag &= ~CRTSCTS;
571 if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
575 mct_u232_set_modem_ctrl(
serial, priv->control_state);
580 spin_unlock_irqrestore(&priv->
lock, flags);
583 klsi_105_chg_port_settings(port, cfg);
589 static void mct_u232_break_ctl(
struct tty_struct *tty,
int break_state)
597 dev_dbg(&port->
dev,
"%s - state=%d\n", __func__, break_state);
603 mct_u232_set_line_ctrl(serial,
lcr);
607 static int klsi_105_tiocmget(
struct tty_struct *tty)
615 rc = klsi_105_get_line_state(port, &line_state);
618 "Reading line control failed (error = %d)\n", rc);
625 spin_unlock_irqrestore(&priv->
lock, flags);
626 dev_dbg(&port->
dev,
"%s - read line state 0x%lx\n", __func__, line_state);
630 static int klsi_105_tiocmset(
struct tty_struct *tty,
631 unsigned int set,
unsigned int clear)