Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 1 | /* |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 2 | * Copyright (C) 2009 by Bart Hartgers (bart.hartgers+ark3116@gmail.com) |
| 3 | * Original version: |
Werner Lemberg | 2f430b4 | 2006-07-18 17:00:52 +0200 | [diff] [blame] | 4 | * Copyright (C) 2006 |
| 5 | * Simon Schulz (ark3116_driver <at> auctionant.de) |
| 6 | * |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 7 | * ark3116 |
| 8 | * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547, |
| 9 | * productid=0x0232) (used in a datacable called KQ-U8A) |
| 10 | * |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 11 | * Supports full modem status lines, break, hardware flow control. Does not |
| 12 | * support software flow control, since I do not know how to enable it in hw. |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 13 | * |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 14 | * This driver is a essentially new implementation. I initially dug |
| 15 | * into the old ark3116.c driver and suddenly realized the ark3116 is |
| 16 | * a 16450 with a USB interface glued to it. See comments at the |
| 17 | * bottom of this file. |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 18 | * |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 19 | * This program is free software; you can redistribute it and/or modify it |
| 20 | * under the terms of the GNU General Public License as published by the |
| 21 | * Free Software Foundation; either version 2 of the License, or (at your |
| 22 | * option) any later version. |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/init.h> |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 27 | #include <linux/ioctl.h> |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 28 | #include <linux/tty.h> |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 29 | #include <linux/tty_flip.h> |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 32 | #include <linux/usb/serial.h> |
Werner Lemberg | 2f430b4 | 2006-07-18 17:00:52 +0200 | [diff] [blame] | 33 | #include <linux/serial.h> |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 34 | #include <linux/serial_reg.h> |
Alan Cox | c4d0f8c | 2008-04-29 14:35:39 +0100 | [diff] [blame] | 35 | #include <linux/uaccess.h> |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 36 | #include <linux/mutex.h> |
| 37 | #include <linux/spinlock.h> |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 38 | |
| 39 | static int debug; |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 40 | /* |
| 41 | * Version information |
| 42 | */ |
| 43 | |
| 44 | #define DRIVER_VERSION "v0.5" |
| 45 | #define DRIVER_AUTHOR "Bart Hartgers <bart.hartgers+ark3116@gmail.com>" |
| 46 | #define DRIVER_DESC "USB ARK3116 serial/IrDA driver" |
| 47 | #define DRIVER_DEV_DESC "ARK3116 RS232/IrDA" |
| 48 | #define DRIVER_NAME "ark3116" |
| 49 | |
| 50 | /* usb timeout of 1 second */ |
| 51 | #define ARK_TIMEOUT (1*HZ) |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 52 | |
| 53 | static struct usb_device_id id_table [] = { |
| 54 | { USB_DEVICE(0x6547, 0x0232) }, |
Ondrej Zary | 5128a66 | 2009-08-06 16:09:52 -0700 | [diff] [blame] | 55 | { USB_DEVICE(0x18ec, 0x3118) }, /* USB to IrDA adapter */ |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 56 | { }, |
| 57 | }; |
| 58 | MODULE_DEVICE_TABLE(usb, id_table); |
| 59 | |
Ondrej Zary | 5128a66 | 2009-08-06 16:09:52 -0700 | [diff] [blame] | 60 | static int is_irda(struct usb_serial *serial) |
| 61 | { |
| 62 | struct usb_device *dev = serial->dev; |
| 63 | if (le16_to_cpu(dev->descriptor.idVendor) == 0x18ec && |
| 64 | le16_to_cpu(dev->descriptor.idProduct) == 0x3118) |
| 65 | return 1; |
| 66 | return 0; |
| 67 | } |
| 68 | |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 69 | struct ark3116_private { |
| 70 | wait_queue_head_t delta_msr_wait; |
| 71 | struct async_icount icount; |
| 72 | int irda; /* 1 for irda device */ |
| 73 | |
| 74 | /* protects hw register updates */ |
| 75 | struct mutex hw_lock; |
| 76 | |
| 77 | int quot; /* baudrate divisor */ |
| 78 | __u32 lcr; /* line control register value */ |
| 79 | __u32 hcr; /* handshake control register (0x8) |
| 80 | * value */ |
| 81 | __u32 mcr; /* modem contol register value */ |
| 82 | |
| 83 | /* protects the status values below */ |
| 84 | spinlock_t status_lock; |
| 85 | __u32 msr; /* modem status register value */ |
| 86 | __u32 lsr; /* line status register value */ |
| 87 | }; |
| 88 | |
| 89 | static int ark3116_write_reg(struct usb_serial *serial, |
| 90 | unsigned reg, __u8 val) |
| 91 | { |
| 92 | int result; |
| 93 | /* 0xfe 0x40 are magic values taken from original driver */ |
| 94 | result = usb_control_msg(serial->dev, |
| 95 | usb_sndctrlpipe(serial->dev, 0), |
| 96 | 0xfe, 0x40, val, reg, |
| 97 | NULL, 0, ARK_TIMEOUT); |
| 98 | return result; |
| 99 | } |
| 100 | |
| 101 | static int ark3116_read_reg(struct usb_serial *serial, |
| 102 | unsigned reg, unsigned char *buf) |
| 103 | { |
| 104 | int result; |
| 105 | /* 0xfe 0xc0 are magic values taken from original driver */ |
| 106 | result = usb_control_msg(serial->dev, |
| 107 | usb_rcvctrlpipe(serial->dev, 0), |
| 108 | 0xfe, 0xc0, 0, reg, |
| 109 | buf, 1, ARK_TIMEOUT); |
| 110 | if (result < 0) |
| 111 | return result; |
| 112 | else |
| 113 | return buf[0]; |
| 114 | } |
| 115 | |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 116 | static inline void ARK3116_SND(struct usb_serial *serial, int seq, |
| 117 | __u8 request, __u8 requesttype, |
| 118 | __u16 value, __u16 index) |
| 119 | { |
| 120 | int result; |
| 121 | result = usb_control_msg(serial->dev, |
Werner Lemberg | 988440e | 2006-07-18 17:00:22 +0200 | [diff] [blame] | 122 | usb_sndctrlpipe(serial->dev, 0), |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 123 | request, requesttype, value, index, |
Werner Lemberg | 988440e | 2006-07-18 17:00:22 +0200 | [diff] [blame] | 124 | NULL, 0x00, 1000); |
| 125 | dbg("%03d > ok", seq); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static inline void ARK3116_RCV(struct usb_serial *serial, int seq, |
| 129 | __u8 request, __u8 requesttype, |
| 130 | __u16 value, __u16 index, __u8 expected, |
| 131 | char *buf) |
| 132 | { |
| 133 | int result; |
| 134 | result = usb_control_msg(serial->dev, |
Werner Lemberg | 988440e | 2006-07-18 17:00:22 +0200 | [diff] [blame] | 135 | usb_rcvctrlpipe(serial->dev, 0), |
| 136 | request, requesttype, value, index, |
| 137 | buf, 0x0000001, 1000); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 138 | if (result) |
Jan Engelhardt | b268f48 | 2007-05-17 17:16:44 +0200 | [diff] [blame] | 139 | dbg("%03d < %d bytes [0x%02X]", seq, result, |
| 140 | ((unsigned char *)buf)[0]); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 141 | else |
| 142 | dbg("%03d < 0 bytes", seq); |
| 143 | } |
| 144 | |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 145 | static inline void ARK3116_RCV_QUIET(struct usb_serial *serial, |
| 146 | __u8 request, __u8 requesttype, |
| 147 | __u16 value, __u16 index, char *buf) |
| 148 | { |
| 149 | usb_control_msg(serial->dev, |
Werner Lemberg | 988440e | 2006-07-18 17:00:22 +0200 | [diff] [blame] | 150 | usb_rcvctrlpipe(serial->dev, 0), |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 151 | request, requesttype, value, index, |
| 152 | buf, 0x0000001, 1000); |
| 153 | } |
| 154 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 155 | static inline int calc_divisor(int bps) |
| 156 | { |
| 157 | /* Original ark3116 made some exceptions in rounding here |
| 158 | * because windows did the same. Assume that is not really |
| 159 | * necessary. |
| 160 | * Crystal is 12MHz, probably because of USB, but we divide by 4? |
| 161 | */ |
| 162 | return (12000000 + 2*bps) / (4*bps); |
| 163 | } |
| 164 | |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 165 | static int ark3116_attach(struct usb_serial *serial) |
| 166 | { |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 167 | struct usb_serial_port *port = serial->port[0]; |
| 168 | struct ark3116_private *priv; |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 169 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 170 | /* make sure we have our end-points */ |
| 171 | if ((serial->num_bulk_in == 0) || |
| 172 | (serial->num_bulk_out == 0) || |
| 173 | (serial->num_interrupt_in == 0)) { |
| 174 | dev_err(&serial->dev->dev, |
| 175 | "%s - missing endpoint - " |
| 176 | "bulk in: %d, bulk out: %d, int in %d\n", |
| 177 | KBUILD_MODNAME, |
| 178 | serial->num_bulk_in, |
| 179 | serial->num_bulk_out, |
| 180 | serial->num_interrupt_in); |
| 181 | return -EINVAL; |
| 182 | } |
| 183 | |
| 184 | priv = kzalloc(sizeof(struct ark3116_private), |
| 185 | GFP_KERNEL); |
| 186 | if (!priv) |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 187 | return -ENOMEM; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 188 | |
| 189 | init_waitqueue_head(&priv->delta_msr_wait); |
| 190 | mutex_init(&priv->hw_lock); |
| 191 | spin_lock_init(&priv->status_lock); |
| 192 | |
| 193 | priv->irda = is_irda(serial); |
| 194 | |
| 195 | usb_set_serial_port_data(port, priv); |
| 196 | |
| 197 | /* setup the hardware */ |
| 198 | ark3116_write_reg(serial, UART_IER, 0); |
| 199 | /* disable DMA */ |
| 200 | ark3116_write_reg(serial, UART_FCR, 0); |
| 201 | /* handshake control */ |
| 202 | priv->hcr = 0; |
| 203 | ark3116_write_reg(serial, 0x8 , 0); |
| 204 | /* modem control */ |
| 205 | priv->mcr = 0; |
| 206 | ark3116_write_reg(serial, UART_MCR, 0); |
| 207 | |
| 208 | if (!(priv->irda)) { |
| 209 | ark3116_write_reg(serial, 0xb , 0); |
| 210 | } else { |
| 211 | ark3116_write_reg(serial, 0xb , 1); |
| 212 | ark3116_write_reg(serial, 0xc , 0); |
| 213 | ark3116_write_reg(serial, 0xd , 0x41); |
| 214 | ark3116_write_reg(serial, 0xa , 1); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 215 | } |
| 216 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 217 | /* setup baudrate */ |
| 218 | ark3116_write_reg(serial, UART_LCR, UART_LCR_DLAB); |
Ondrej Zary | 5128a66 | 2009-08-06 16:09:52 -0700 | [diff] [blame] | 219 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 220 | /* setup for 9600 8N1 */ |
| 221 | priv->quot = calc_divisor(9600); |
| 222 | ark3116_write_reg(serial, UART_DLL, priv->quot & 0xff); |
| 223 | ark3116_write_reg(serial, UART_DLM, (priv->quot>>8) & 0xff); |
Ondrej Zary | 5128a66 | 2009-08-06 16:09:52 -0700 | [diff] [blame] | 224 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 225 | priv->lcr = UART_LCR_WLEN8; |
| 226 | ark3116_write_reg(serial, UART_LCR, UART_LCR_WLEN8); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 227 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 228 | ark3116_write_reg(serial, 0xe, 0); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 229 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 230 | if (priv->irda) |
| 231 | ark3116_write_reg(serial, 0x9, 0); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 232 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 233 | dev_info(&serial->dev->dev, |
| 234 | "%s using %s mode\n", |
| 235 | KBUILD_MODNAME, |
| 236 | priv->irda ? "IrDA" : "RS232"); |
Werner Lemberg | 988440e | 2006-07-18 17:00:22 +0200 | [diff] [blame] | 237 | return 0; |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 238 | } |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 239 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 240 | static void ark3116_release(struct usb_serial *serial) |
| 241 | { |
| 242 | struct usb_serial_port *port = serial->port[0]; |
| 243 | struct ark3116_private *priv = usb_get_serial_port_data(port); |
| 244 | |
| 245 | /* device is closed, so URBs and DMA should be down */ |
| 246 | |
| 247 | usb_set_serial_port_data(port, NULL); |
| 248 | |
| 249 | mutex_destroy(&priv->hw_lock); |
| 250 | |
| 251 | kfree(priv); |
| 252 | } |
| 253 | |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 254 | static void ark3116_init_termios(struct tty_struct *tty) |
| 255 | { |
| 256 | struct ktermios *termios = tty->termios; |
| 257 | *termios = tty_std_termios; |
| 258 | termios->c_cflag = B9600 | CS8 |
| 259 | | CREAD | HUPCL | CLOCAL; |
| 260 | termios->c_ispeed = 9600; |
| 261 | termios->c_ospeed = 9600; |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 264 | static void ark3116_set_termios(struct tty_struct *tty, |
| 265 | struct usb_serial_port *port, |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 266 | struct ktermios *old_termios) |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 267 | { |
| 268 | struct usb_serial *serial = port->serial; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 269 | struct ark3116_private *priv = usb_get_serial_port_data(port); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 270 | struct ktermios *termios = tty->termios; |
Alan Cox | adb5dca | 2007-10-18 01:24:17 -0700 | [diff] [blame] | 271 | unsigned int cflag = termios->c_cflag; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 272 | int bps = tty_get_baud_rate(tty); |
| 273 | int quot; |
| 274 | __u8 lcr, hcr, eval; |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 275 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 276 | /* set data bit count */ |
| 277 | switch (cflag & CSIZE) { |
| 278 | case CS5: |
| 279 | lcr = UART_LCR_WLEN5; |
Alan Cox | c4d0f8c | 2008-04-29 14:35:39 +0100 | [diff] [blame] | 280 | break; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 281 | case CS6: |
| 282 | lcr = UART_LCR_WLEN6; |
| 283 | break; |
| 284 | case CS7: |
| 285 | lcr = UART_LCR_WLEN7; |
| 286 | break; |
Alan Cox | c4d0f8c | 2008-04-29 14:35:39 +0100 | [diff] [blame] | 287 | default: |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 288 | case CS8: |
| 289 | lcr = UART_LCR_WLEN8; |
| 290 | break; |
| 291 | } |
| 292 | if (cflag & CSTOPB) |
| 293 | lcr |= UART_LCR_STOP; |
| 294 | if (cflag & PARENB) |
| 295 | lcr |= UART_LCR_PARITY; |
| 296 | if (!(cflag & PARODD)) |
| 297 | lcr |= UART_LCR_EPAR; |
| 298 | #ifdef CMSPAR |
| 299 | if (cflag & CMSPAR) |
| 300 | lcr |= UART_LCR_SPAR; |
| 301 | #endif |
| 302 | /* handshake control */ |
| 303 | hcr = (cflag & CRTSCTS) ? 0x03 : 0x00; |
| 304 | |
| 305 | /* calc baudrate */ |
| 306 | dbg("%s - setting bps to %d", __func__, bps); |
| 307 | eval = 0; |
| 308 | switch (bps) { |
Alan Cox | c4d0f8c | 2008-04-29 14:35:39 +0100 | [diff] [blame] | 309 | case 0: |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 310 | quot = calc_divisor(9600); |
| 311 | break; |
| 312 | default: |
| 313 | if ((bps < 75) || (bps > 3000000)) |
| 314 | bps = 9600; |
| 315 | quot = calc_divisor(bps); |
| 316 | break; |
| 317 | case 460800: |
| 318 | eval = 1; |
| 319 | quot = calc_divisor(bps); |
| 320 | break; |
| 321 | case 921600: |
| 322 | eval = 2; |
| 323 | quot = calc_divisor(bps); |
| 324 | break; |
Alan Cox | 568c24a | 2007-06-22 14:36:29 +0100 | [diff] [blame] | 325 | } |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 326 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 327 | /* Update state: synchronize */ |
| 328 | mutex_lock(&priv->hw_lock); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 329 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 330 | /* keep old LCR_SBC bit */ |
| 331 | lcr |= (priv->lcr & UART_LCR_SBC); |
Werner Lemberg | 988440e | 2006-07-18 17:00:22 +0200 | [diff] [blame] | 332 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 333 | dbg("%s - setting hcr:0x%02x,lcr:0x%02x,quot:%d", |
| 334 | __func__, hcr, lcr, quot); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 335 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 336 | /* handshake control */ |
| 337 | if (priv->hcr != hcr) { |
| 338 | priv->hcr = hcr; |
| 339 | ark3116_write_reg(serial, 0x8, hcr); |
| 340 | } |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 341 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 342 | /* baudrate */ |
| 343 | if (priv->quot != quot) { |
| 344 | priv->quot = quot; |
| 345 | priv->lcr = lcr; /* need to write lcr anyway */ |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 346 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 347 | /* disable DMA since transmit/receive is |
| 348 | * shadowed by UART_DLL |
| 349 | */ |
| 350 | ark3116_write_reg(serial, UART_FCR, 0); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 351 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 352 | ark3116_write_reg(serial, UART_LCR, |
| 353 | lcr|UART_LCR_DLAB); |
| 354 | ark3116_write_reg(serial, UART_DLL, quot & 0xff); |
| 355 | ark3116_write_reg(serial, UART_DLM, (quot>>8) & 0xff); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 356 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 357 | /* restore lcr */ |
| 358 | ark3116_write_reg(serial, UART_LCR, lcr); |
| 359 | /* magic baudrate thingy: not sure what it does, |
| 360 | * but windows does this as well. |
| 361 | */ |
| 362 | ark3116_write_reg(serial, 0xe, eval); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 363 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 364 | /* enable DMA */ |
| 365 | ark3116_write_reg(serial, UART_FCR, UART_FCR_DMA_SELECT); |
| 366 | } else if (priv->lcr != lcr) { |
| 367 | priv->lcr = lcr; |
| 368 | ark3116_write_reg(serial, UART_LCR, lcr); |
| 369 | } |
Alan Cox | adb5dca | 2007-10-18 01:24:17 -0700 | [diff] [blame] | 370 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 371 | mutex_unlock(&priv->hw_lock); |
| 372 | |
| 373 | /* check for software flow control */ |
| 374 | if (I_IXOFF(tty) || I_IXON(tty)) { |
| 375 | dev_warn(&serial->dev->dev, |
| 376 | "%s: don't know how to do software flow control\n", |
| 377 | KBUILD_MODNAME); |
| 378 | } |
| 379 | |
| 380 | /* Don't rewrite B0 */ |
| 381 | if (tty_termios_baud_rate(termios)) |
| 382 | tty_termios_encode_baud_rate(termios, bps, bps); |
| 383 | } |
| 384 | |
| 385 | static void ark3116_close(struct usb_serial_port *port) |
| 386 | { |
| 387 | struct usb_serial *serial = port->serial; |
| 388 | |
| 389 | if (serial->dev) { |
| 390 | /* disable DMA */ |
| 391 | ark3116_write_reg(serial, UART_FCR, 0); |
| 392 | |
| 393 | /* deactivate interrupts */ |
| 394 | ark3116_write_reg(serial, UART_IER, 0); |
| 395 | |
| 396 | /* shutdown any bulk reads that might be going on */ |
| 397 | if (serial->num_bulk_out) |
| 398 | usb_kill_urb(port->write_urb); |
| 399 | if (serial->num_bulk_in) |
| 400 | usb_kill_urb(port->read_urb); |
| 401 | if (serial->num_interrupt_in) |
| 402 | usb_kill_urb(port->interrupt_in_urb); |
| 403 | } |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 406 | static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 407 | { |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 408 | struct ark3116_private *priv = usb_get_serial_port_data(port); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 409 | struct usb_serial *serial = port->serial; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 410 | unsigned char *buf; |
| 411 | int result; |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 412 | |
| 413 | buf = kmalloc(1, GFP_KERNEL); |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 414 | if (buf == NULL) |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 415 | return -ENOMEM; |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 416 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 417 | result = usb_serial_generic_open(tty, port); |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 418 | if (result) { |
| 419 | dbg("%s - usb_serial_generic_open failed: %d", |
| 420 | __func__, result); |
Oliver Neukum | 4edf2c8 | 2007-03-26 18:12:44 +0200 | [diff] [blame] | 421 | goto err_out; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 422 | } |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 423 | |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 424 | /* setup termios */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 425 | if (tty) |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 426 | ark3116_set_termios(tty, port, NULL); |
| 427 | |
| 428 | /* remove any data still left: also clears error state */ |
| 429 | ark3116_read_reg(serial, UART_RX, buf); |
| 430 | |
| 431 | /* read modem status */ |
| 432 | priv->msr = ark3116_read_reg(serial, UART_MSR, buf); |
| 433 | /* read line status */ |
| 434 | priv->lsr = ark3116_read_reg(serial, UART_LSR, buf); |
| 435 | |
| 436 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 437 | if (result) { |
| 438 | dev_err(&port->dev, "submit irq_in urb failed %d\n", |
| 439 | result); |
| 440 | ark3116_close(port); |
| 441 | goto err_out; |
| 442 | } |
| 443 | |
| 444 | /* activate interrupts */ |
| 445 | ark3116_write_reg(port->serial, UART_IER, UART_IER_MSI|UART_IER_RLSI); |
| 446 | |
| 447 | /* enable DMA */ |
| 448 | ark3116_write_reg(port->serial, UART_FCR, UART_FCR_DMA_SELECT); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 449 | |
Oliver Neukum | 4edf2c8 | 2007-03-26 18:12:44 +0200 | [diff] [blame] | 450 | err_out: |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 451 | kfree(buf); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 452 | return result; |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 455 | static int ark3116_ioctl(struct tty_struct *tty, struct file *file, |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 456 | unsigned int cmd, unsigned long arg) |
| 457 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 458 | struct usb_serial_port *port = tty->driver_data; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 459 | struct ark3116_private *priv = usb_get_serial_port_data(port); |
Werner Lemberg | 2f430b4 | 2006-07-18 17:00:52 +0200 | [diff] [blame] | 460 | struct serial_struct serstruct; |
| 461 | void __user *user_arg = (void __user *)arg; |
| 462 | |
| 463 | switch (cmd) { |
| 464 | case TIOCGSERIAL: |
| 465 | /* XXX: Some of these values are probably wrong. */ |
Alan Cox | c4d0f8c | 2008-04-29 14:35:39 +0100 | [diff] [blame] | 466 | memset(&serstruct, 0, sizeof(serstruct)); |
Werner Lemberg | 2f430b4 | 2006-07-18 17:00:52 +0200 | [diff] [blame] | 467 | serstruct.type = PORT_16654; |
| 468 | serstruct.line = port->serial->minor; |
| 469 | serstruct.port = port->number; |
| 470 | serstruct.custom_divisor = 0; |
| 471 | serstruct.baud_base = 460800; |
| 472 | |
Alan Cox | c4d0f8c | 2008-04-29 14:35:39 +0100 | [diff] [blame] | 473 | if (copy_to_user(user_arg, &serstruct, sizeof(serstruct))) |
Werner Lemberg | 2f430b4 | 2006-07-18 17:00:52 +0200 | [diff] [blame] | 474 | return -EFAULT; |
| 475 | |
| 476 | return 0; |
| 477 | case TIOCSSERIAL: |
Alan Cox | c4d0f8c | 2008-04-29 14:35:39 +0100 | [diff] [blame] | 478 | if (copy_from_user(&serstruct, user_arg, sizeof(serstruct))) |
Werner Lemberg | 2f430b4 | 2006-07-18 17:00:52 +0200 | [diff] [blame] | 479 | return -EFAULT; |
| 480 | return 0; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 481 | case TIOCMIWAIT: |
| 482 | for (;;) { |
| 483 | struct async_icount prev = priv->icount; |
| 484 | interruptible_sleep_on(&priv->delta_msr_wait); |
| 485 | /* see if a signal did it */ |
| 486 | if (signal_pending(current)) |
| 487 | return -ERESTARTSYS; |
| 488 | if ((prev.rng == priv->icount.rng) && |
| 489 | (prev.dsr == priv->icount.dsr) && |
| 490 | (prev.dcd == priv->icount.dcd) && |
| 491 | (prev.cts == priv->icount.cts)) |
| 492 | return -EIO; |
| 493 | if ((arg & TIOCM_RNG && |
| 494 | (prev.rng != priv->icount.rng)) || |
| 495 | (arg & TIOCM_DSR && |
| 496 | (prev.dsr != priv->icount.dsr)) || |
| 497 | (arg & TIOCM_CD && |
| 498 | (prev.dcd != priv->icount.dcd)) || |
| 499 | (arg & TIOCM_CTS && |
| 500 | (prev.cts != priv->icount.cts))) |
| 501 | return 0; |
| 502 | } |
Werner Lemberg | 2f430b4 | 2006-07-18 17:00:52 +0200 | [diff] [blame] | 503 | break; |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 504 | case TIOCGICOUNT: { |
| 505 | struct serial_icounter_struct icount; |
| 506 | struct async_icount cnow = priv->icount; |
| 507 | memset(&icount, 0, sizeof(icount)); |
| 508 | icount.cts = cnow.cts; |
| 509 | icount.dsr = cnow.dsr; |
| 510 | icount.rng = cnow.rng; |
| 511 | icount.dcd = cnow.dcd; |
| 512 | icount.rx = cnow.rx; |
| 513 | icount.tx = cnow.tx; |
| 514 | icount.frame = cnow.frame; |
| 515 | icount.overrun = cnow.overrun; |
| 516 | icount.parity = cnow.parity; |
| 517 | icount.brk = cnow.brk; |
| 518 | icount.buf_overrun = cnow.buf_overrun; |
| 519 | if (copy_to_user(user_arg, &icount, sizeof(icount))) |
| 520 | return -EFAULT; |
| 521 | return 0; |
| 522 | } |
Werner Lemberg | 2f430b4 | 2006-07-18 17:00:52 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 525 | return -ENOIOCTLCMD; |
| 526 | } |
| 527 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 528 | static int ark3116_tiocmget(struct tty_struct *tty, struct file *file) |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 529 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 530 | struct usb_serial_port *port = tty->driver_data; |
bart.hartgers@gmail.com | 1f71910 | 2009-10-28 10:43:27 +0100 | [diff] [blame^] | 531 | struct ark3116_private *priv = usb_get_serial_port_data(port); |
| 532 | __u32 status; |
| 533 | __u32 ctrl; |
| 534 | unsigned long flags; |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 535 | |
bart.hartgers@gmail.com | 1f71910 | 2009-10-28 10:43:27 +0100 | [diff] [blame^] | 536 | mutex_lock(&priv->hw_lock); |
| 537 | ctrl = priv->mcr; |
| 538 | mutex_unlock(&priv->hw_lock); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 539 | |
bart.hartgers@gmail.com | 1f71910 | 2009-10-28 10:43:27 +0100 | [diff] [blame^] | 540 | spin_lock_irqsave(&priv->status_lock, flags); |
| 541 | status = priv->msr; |
| 542 | spin_unlock_irqrestore(&priv->status_lock, flags); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 543 | |
bart.hartgers@gmail.com | 1f71910 | 2009-10-28 10:43:27 +0100 | [diff] [blame^] | 544 | return (status & UART_MSR_DSR ? TIOCM_DSR : 0) | |
| 545 | (status & UART_MSR_CTS ? TIOCM_CTS : 0) | |
| 546 | (status & UART_MSR_RI ? TIOCM_RI : 0) | |
| 547 | (status & UART_MSR_DCD ? TIOCM_CD : 0) | |
| 548 | (ctrl & UART_MCR_DTR ? TIOCM_DTR : 0) | |
| 549 | (ctrl & UART_MCR_RTS ? TIOCM_RTS : 0) | |
| 550 | (ctrl & UART_MCR_OUT1 ? TIOCM_OUT1 : 0) | |
| 551 | (ctrl & UART_MCR_OUT2 ? TIOCM_OUT2 : 0); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | static struct usb_driver ark3116_driver = { |
| 555 | .name = "ark3116", |
| 556 | .probe = usb_serial_probe, |
| 557 | .disconnect = usb_serial_disconnect, |
| 558 | .id_table = id_table, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 559 | .no_dynamic_id = 1, |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 560 | }; |
| 561 | |
| 562 | static struct usb_serial_driver ark3116_device = { |
| 563 | .driver = { |
| 564 | .owner = THIS_MODULE, |
| 565 | .name = "ark3116", |
| 566 | }, |
| 567 | .id_table = id_table, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 568 | .usb_driver = &ark3116_driver, |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 569 | .num_ports = 1, |
| 570 | .attach = ark3116_attach, |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 571 | .release = ark3116_release, |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 572 | .set_termios = ark3116_set_termios, |
Alan Cox | fe1ae7f | 2009-09-19 13:13:33 -0700 | [diff] [blame] | 573 | .init_termios = ark3116_init_termios, |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 574 | .ioctl = ark3116_ioctl, |
| 575 | .tiocmget = ark3116_tiocmget, |
| 576 | .open = ark3116_open, |
bart.hartgers@gmail.com | f4c1e8d | 2009-10-28 10:43:26 +0100 | [diff] [blame] | 577 | .close = ark3116_close, |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 578 | }; |
| 579 | |
| 580 | static int __init ark3116_init(void) |
| 581 | { |
| 582 | int retval; |
| 583 | |
| 584 | retval = usb_serial_register(&ark3116_device); |
| 585 | if (retval) |
| 586 | return retval; |
| 587 | retval = usb_register(&ark3116_driver); |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 588 | if (retval == 0) { |
| 589 | printk(KERN_INFO "%s:" |
| 590 | DRIVER_VERSION ":" |
| 591 | DRIVER_DESC "\n", |
| 592 | KBUILD_MODNAME); |
| 593 | } else |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 594 | usb_serial_deregister(&ark3116_device); |
| 595 | return retval; |
| 596 | } |
| 597 | |
| 598 | static void __exit ark3116_exit(void) |
| 599 | { |
| 600 | usb_deregister(&ark3116_driver); |
| 601 | usb_serial_deregister(&ark3116_device); |
| 602 | } |
| 603 | |
| 604 | module_init(ark3116_init); |
| 605 | module_exit(ark3116_exit); |
| 606 | MODULE_LICENSE("GPL"); |
| 607 | |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 608 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 609 | MODULE_DESCRIPTION(DRIVER_DESC); |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 610 | |
bart.hartgers@gmail.com | 149fc79 | 2009-10-28 10:43:25 +0100 | [diff] [blame] | 611 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 612 | MODULE_PARM_DESC(debug, "Enable debug"); |
| 613 | |
| 614 | /* |
| 615 | * The following describes what I learned from studying the old |
| 616 | * ark3116.c driver, disassembling the windows driver, and some lucky |
| 617 | * guesses. Since I do not have any datasheet or other |
| 618 | * documentation, inaccuracies are almost guaranteed. |
| 619 | * |
| 620 | * Some specs for the ARK3116 can be found here: |
| 621 | * http://web.archive.org/web/20060318000438/ |
| 622 | * www.arkmicro.com/en/products/view.php?id=10 |
| 623 | * On that page, 2 GPIO pins are mentioned: I assume these are the |
| 624 | * OUT1 and OUT2 pins of the UART, so I added support for those |
| 625 | * through the MCR. Since the pins are not available on my hardware, |
| 626 | * I could not verify this. |
| 627 | * Also, it states there is "on-chip hardware flow control". I have |
| 628 | * discovered how to enable that. Unfortunately, I do not know how to |
| 629 | * enable XON/XOFF (software) flow control, which would need support |
| 630 | * from the chip as well to work. Because of the wording on the web |
| 631 | * page there is a real possibility the chip simply does not support |
| 632 | * software flow control. |
| 633 | * |
| 634 | * I got my ark3116 as part of a mobile phone adapter cable. On the |
| 635 | * PCB, the following numbered contacts are present: |
| 636 | * |
| 637 | * 1:- +5V |
| 638 | * 2:o DTR |
| 639 | * 3:i RX |
| 640 | * 4:i DCD |
| 641 | * 5:o RTS |
| 642 | * 6:o TX |
| 643 | * 7:i RI |
| 644 | * 8:i DSR |
| 645 | * 10:- 0V |
| 646 | * 11:i CTS |
| 647 | * |
| 648 | * On my chip, all signals seem to be 3.3V, but 5V tolerant. But that |
| 649 | * may be different for the one you have ;-). |
| 650 | * |
| 651 | * The windows driver limits the registers to 0-F, so I assume there |
| 652 | * are actually 16 present on the device. |
| 653 | * |
| 654 | * On an UART interrupt, 4 bytes of data come in on the interrupt |
| 655 | * endpoint. The bytes are 0xe8 IIR LSR MSR. |
| 656 | * |
| 657 | * The baudrate seems to be generated from the 12MHz crystal, using |
| 658 | * 4-times subsampling. So quot=12e6/(4*baud). Also see description |
| 659 | * of register E. |
| 660 | * |
| 661 | * Registers 0-7: |
| 662 | * These seem to be the same as for a regular 16450. The FCR is set |
| 663 | * to UART_FCR_DMA_SELECT (0x8), I guess to enable transfers between |
| 664 | * the UART and the USB bridge/DMA engine. |
| 665 | * |
| 666 | * Register 8: |
| 667 | * By trial and error, I found out that bit 0 enables hardware CTS, |
| 668 | * stopping TX when CTS is +5V. Bit 1 does the same for RTS, making |
| 669 | * RTS +5V when the 3116 cannot transfer the data to the USB bus |
| 670 | * (verified by disabling the reading URB). Note that as far as I can |
| 671 | * tell, the windows driver does NOT use this, so there might be some |
| 672 | * hardware bug or something. |
| 673 | * |
| 674 | * According to a patch provided here |
| 675 | * (http://lkml.org/lkml/2009/7/26/56), the ARK3116 can also be used |
| 676 | * as an IrDA dongle. Since I do not have such a thing, I could not |
| 677 | * investigate that aspect. However, I can speculate ;-). |
| 678 | * |
| 679 | * - IrDA encodes data differently than RS232. Most likely, one of |
| 680 | * the bits in registers 9..E enables the IR ENDEC (encoder/decoder). |
| 681 | * - Depending on the IR transceiver, the input and output need to be |
| 682 | * inverted, so there are probably bits for that as well. |
| 683 | * - IrDA is half-duplex, so there should be a bit for selecting that. |
| 684 | * |
| 685 | * This still leaves at least two registers unaccounted for. Perhaps |
| 686 | * The chip can do XON/XOFF or CRC in HW? |
| 687 | * |
| 688 | * Register 9: |
| 689 | * Set to 0x00 for IrDA, when the baudrate is initialised. |
| 690 | * |
| 691 | * Register A: |
| 692 | * Set to 0x01 for IrDA, at init. |
| 693 | * |
| 694 | * Register B: |
| 695 | * Set to 0x01 for IrDA, 0x00 for RS232, at init. |
| 696 | * |
| 697 | * Register C: |
| 698 | * Set to 00 for IrDA, at init. |
| 699 | * |
| 700 | * Register D: |
| 701 | * Set to 0x41 for IrDA, at init. |
| 702 | * |
| 703 | * Register E: |
| 704 | * Somekind of baudrate override. The windows driver seems to set |
| 705 | * this to 0x00 for normal baudrates, 0x01 for 460800, 0x02 for 921600. |
| 706 | * Since 460800 and 921600 cannot be obtained by dividing 3MHz by an integer, |
| 707 | * it could be somekind of subdivisor thingy. |
| 708 | * However,it does not seem to do anything: selecting 921600 (divisor 3, |
| 709 | * reg E=2), still gets 1 MHz. I also checked if registers 9, C or F would |
| 710 | * work, but they don't. |
| 711 | * |
| 712 | * Register F: unknown |
| 713 | */ |