25 #include <linux/kernel.h>
28 #include <linux/tty.h>
29 #include <linux/slab.h>
31 #include <linux/module.h>
34 #include <linux/serial.h>
44 #define DRIVER_VERSION "v0.7"
46 #define DRIVER_DESC "USB ARK3116 serial/IrDA driver"
47 #define DRIVER_DEV_DESC "ARK3116 RS232/IrDA"
48 #define DRIVER_NAME "ark3116"
51 #define ARK_TIMEOUT (1*HZ)
54 { USB_DEVICE(0x6547, 0x0232) },
55 { USB_DEVICE(0x18ec, 0x3118) },
62 struct usb_device *
dev = serial->
dev;
63 if (
le16_to_cpu(dev->descriptor.idVendor) == 0x18ec &&
89 static int ark3116_write_reg(
struct usb_serial *serial,
95 usb_sndctrlpipe(serial->
dev, 0),
101 static int ark3116_read_reg(
struct usb_serial *serial,
102 unsigned reg,
unsigned char *
buf)
107 usb_rcvctrlpipe(serial->
dev, 0),
116 static inline int calc_divisor(
int bps)
123 return (12000000 + 2*bps) / (4*bps);
126 static int ark3116_attach(
struct usb_serial *serial)
133 "%s - missing endpoint - "
134 "bulk in: %d, bulk out: %d, int in %d\n",
158 priv->
irda = is_irda(serial);
160 usb_set_serial_port_data(port, priv);
163 ark3116_write_reg(serial,
UART_IER, 0);
165 ark3116_write_reg(serial,
UART_FCR, 0);
168 ark3116_write_reg(serial, 0x8 , 0);
171 ark3116_write_reg(serial,
UART_MCR, 0);
174 ark3116_write_reg(serial, 0
xb , 0);
176 ark3116_write_reg(serial, 0
xb , 1);
177 ark3116_write_reg(serial, 0
xc , 0);
178 ark3116_write_reg(serial, 0xd , 0x41);
179 ark3116_write_reg(serial, 0xa , 1);
186 priv->
quot = calc_divisor(9600);
188 ark3116_write_reg(serial,
UART_DLM, (priv->
quot>>8) & 0xff);
193 ark3116_write_reg(serial, 0
xe, 0);
196 ark3116_write_reg(serial, 0x9, 0);
199 "%s using %s mode\n",
201 priv->
irda ?
"IrDA" :
"RS232");
216 static void ark3116_init_termios(
struct tty_struct *tty)
226 static void ark3116_set_termios(
struct tty_struct *tty,
239 switch (cflag &
CSIZE) {
265 hcr = (cflag &
CRTSCTS) ? 0x03 : 0x00;
268 dev_dbg(&port->
dev,
"%s - setting bps to %d\n", __func__, bps);
272 quot = calc_divisor(9600);
275 if ((bps < 75) || (bps > 3000000))
277 quot = calc_divisor(bps);
281 quot = calc_divisor(bps);
285 quot = calc_divisor(bps);
295 dev_dbg(&port->
dev,
"%s - setting hcr:0x%02x,lcr:0x%02x,quot:%d\n",
296 __func__, hcr, lcr, quot);
299 if (priv->
hcr != hcr) {
301 ark3116_write_reg(serial, 0x8, hcr);
305 if (priv->
quot != quot) {
312 ark3116_write_reg(serial,
UART_FCR, 0);
316 ark3116_write_reg(serial,
UART_DLL, quot & 0xff);
317 ark3116_write_reg(serial,
UART_DLM, (quot>>8) & 0xff);
320 ark3116_write_reg(serial,
UART_LCR, lcr);
324 ark3116_write_reg(serial, 0
xe, eval);
328 }
else if (priv->
lcr != lcr) {
330 ark3116_write_reg(serial,
UART_LCR, lcr);
338 "%s: don't know how to do software flow control\n",
353 ark3116_write_reg(serial,
UART_FCR, 0);
356 ark3116_write_reg(serial,
UART_IER, 0);
379 "%s - usb_serial_generic_open failed: %d\n",
385 ark3116_read_reg(serial,
UART_RX, buf);
388 priv->
msr = ark3116_read_reg(serial,
UART_MSR, buf);
390 priv->
lsr = ark3116_read_reg(serial,
UART_LSR, buf);
394 dev_err(&port->
dev,
"submit irq_in urb failed %d\n",
408 ark3116_set_termios(tty, port,
NULL);
415 static int ark3116_get_icount(
struct tty_struct *tty,
425 icount->
rx = cnow.
rx;
426 icount->
tx = cnow.
tx;
435 static int ark3116_ioctl(
struct tty_struct *tty,
436 unsigned int cmd,
unsigned long arg)
446 memset(&serstruct, 0,
sizeof(serstruct));
448 serstruct.line = port->
serial->minor;
449 serstruct.port = port->
number;
450 serstruct.custom_divisor = 0;
451 serstruct.baud_base = 460800;
453 if (
copy_to_user(user_arg, &serstruct,
sizeof(serstruct)))
489 static int ark3116_tiocmget(
struct tty_struct *tty)
515 static int ark3116_tiocmset(
struct tty_struct *tty,
516 unsigned set,
unsigned clr)
551 static void ark3116_break_ctl(
struct tty_struct *tty,
int break_state)
614 static void ark3116_read_int_callback(
struct urb *
urb)
617 int status = urb->status;
618 const __u8 *
data = urb->transfer_buffer;
626 dev_dbg(&port->
dev,
"%s - urb shutting down with status: %d\n",
630 dev_dbg(&port->
dev,
"%s - nonzero urb status received: %d\n",
635 if ((urb->actual_length == 4) && (data[0] == 0xe8)) {
637 dev_dbg(&port->
dev,
"%s: iir=%02x\n", __func__, data[1]);
641 ark3116_update_msr(port, data[3]);
646 ark3116_update_lsr(port, data[2]);
653 usb_serial_debug_data(&port->
dev, __func__,
655 urb->transfer_buffer);
662 "%s - Error %d submitting interrupt urb\n",
678 static void ark3116_process_read_urb(
struct urb *urb)
683 unsigned char *data = urb->transfer_buffer;
691 priv->
lsr &= ~UART_LSR_BRK_ERROR_BITS;
694 if (!urb->actual_length)
701 if (lsr & UART_LSR_BRK_ERROR_BITS) {
702 if (lsr & UART_LSR_BI)
706 else if (lsr & UART_LSR_FE)
726 .attach = ark3116_attach,
727 .port_probe = ark3116_port_probe,
728 .port_remove = ark3116_port_remove,
729 .set_termios = ark3116_set_termios,
730 .init_termios = ark3116_init_termios,
731 .ioctl = ark3116_ioctl,
732 .tiocmget = ark3116_tiocmget,
733 .tiocmset = ark3116_tiocmset,
734 .get_icount = ark3116_get_icount,
735 .open = ark3116_open,
736 .close = ark3116_close,
737 .break_ctl = ark3116_break_ctl,
738 .read_int_callback = ark3116_read_int_callback,
739 .process_read_urb = ark3116_process_read_urb,
743 &ark3116_device,
NULL