ark3116.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * Copyright (C) 2009 by Bart Hartgers (bart.hartgers+ark3116@gmail.com)
  3. * Original version:
  4. * Copyright (C) 2006
  5. * Simon Schulz (ark3116_driver <at> auctionant.de)
  6. *
  7. * ark3116
  8. * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547,
  9. * productid=0x0232) (used in a datacable called KQ-U8A)
  10. *
  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.
  13. *
  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.
  18. *
  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. #include <linux/kernel.h>
  25. #include <linux/init.h>
  26. #include <linux/ioctl.h>
  27. #include <linux/tty.h>
  28. #include <linux/tty_flip.h>
  29. #include <linux/module.h>
  30. #include <linux/usb.h>
  31. #include <linux/usb/serial.h>
  32. #include <linux/serial.h>
  33. #include <linux/serial_reg.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/mutex.h>
  36. #include <linux/spinlock.h>
  37. static int debug;
  38. /*
  39. * Version information
  40. */
  41. #define DRIVER_VERSION "v0.5"
  42. #define DRIVER_AUTHOR "Bart Hartgers <bart.hartgers+ark3116@gmail.com>"
  43. #define DRIVER_DESC "USB ARK3116 serial/IrDA driver"
  44. #define DRIVER_DEV_DESC "ARK3116 RS232/IrDA"
  45. #define DRIVER_NAME "ark3116"
  46. /* usb timeout of 1 second */
  47. #define ARK_TIMEOUT (1*HZ)
  48. static struct usb_device_id id_table [] = {
  49. { USB_DEVICE(0x6547, 0x0232) },
  50. { USB_DEVICE(0x18ec, 0x3118) }, /* USB to IrDA adapter */
  51. { },
  52. };
  53. MODULE_DEVICE_TABLE(usb, id_table);
  54. static int is_irda(struct usb_serial *serial)
  55. {
  56. struct usb_device *dev = serial->dev;
  57. if (le16_to_cpu(dev->descriptor.idVendor) == 0x18ec &&
  58. le16_to_cpu(dev->descriptor.idProduct) == 0x3118)
  59. return 1;
  60. return 0;
  61. }
  62. struct ark3116_private {
  63. wait_queue_head_t delta_msr_wait;
  64. struct async_icount icount;
  65. int irda; /* 1 for irda device */
  66. /* protects hw register updates */
  67. struct mutex hw_lock;
  68. int quot; /* baudrate divisor */
  69. __u32 lcr; /* line control register value */
  70. __u32 hcr; /* handshake control register (0x8)
  71. * value */
  72. __u32 mcr; /* modem contol register value */
  73. /* protects the status values below */
  74. spinlock_t status_lock;
  75. __u32 msr; /* modem status register value */
  76. __u32 lsr; /* line status register value */
  77. };
  78. static int ark3116_write_reg(struct usb_serial *serial,
  79. unsigned reg, __u8 val)
  80. {
  81. int result;
  82. /* 0xfe 0x40 are magic values taken from original driver */
  83. result = usb_control_msg(serial->dev,
  84. usb_sndctrlpipe(serial->dev, 0),
  85. 0xfe, 0x40, val, reg,
  86. NULL, 0, ARK_TIMEOUT);
  87. return result;
  88. }
  89. static int ark3116_read_reg(struct usb_serial *serial,
  90. unsigned reg, unsigned char *buf)
  91. {
  92. int result;
  93. /* 0xfe 0xc0 are magic values taken from original driver */
  94. result = usb_control_msg(serial->dev,
  95. usb_rcvctrlpipe(serial->dev, 0),
  96. 0xfe, 0xc0, 0, reg,
  97. buf, 1, ARK_TIMEOUT);
  98. if (result < 0)
  99. return result;
  100. else
  101. return buf[0];
  102. }
  103. static inline void ARK3116_SND(struct usb_serial *serial, int seq,
  104. __u8 request, __u8 requesttype,
  105. __u16 value, __u16 index)
  106. {
  107. int result;
  108. result = usb_control_msg(serial->dev,
  109. usb_sndctrlpipe(serial->dev, 0),
  110. request, requesttype, value, index,
  111. NULL, 0x00, 1000);
  112. dbg("%03d > ok", seq);
  113. }
  114. static inline void ARK3116_RCV(struct usb_serial *serial, int seq,
  115. __u8 request, __u8 requesttype,
  116. __u16 value, __u16 index, __u8 expected,
  117. char *buf)
  118. {
  119. int result;
  120. result = usb_control_msg(serial->dev,
  121. usb_rcvctrlpipe(serial->dev, 0),
  122. request, requesttype, value, index,
  123. buf, 0x0000001, 1000);
  124. if (result)
  125. dbg("%03d < %d bytes [0x%02X]", seq, result,
  126. ((unsigned char *)buf)[0]);
  127. else
  128. dbg("%03d < 0 bytes", seq);
  129. }
  130. static inline void ARK3116_RCV_QUIET(struct usb_serial *serial,
  131. __u8 request, __u8 requesttype,
  132. __u16 value, __u16 index, char *buf)
  133. {
  134. usb_control_msg(serial->dev,
  135. usb_rcvctrlpipe(serial->dev, 0),
  136. request, requesttype, value, index,
  137. buf, 0x0000001, 1000);
  138. }
  139. static int ark3116_attach(struct usb_serial *serial)
  140. {
  141. char *buf;
  142. buf = kmalloc(1, GFP_KERNEL);
  143. if (!buf) {
  144. dbg("error kmalloc -> out of mem?");
  145. return -ENOMEM;
  146. }
  147. if (is_irda(serial))
  148. dbg("IrDA mode");
  149. /* 3 */
  150. ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002);
  151. ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001);
  152. ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008);
  153. ARK3116_SND(serial, 6, 0xFE, 0x40, is_irda(serial) ? 0x0001 : 0x0000,
  154. 0x000B);
  155. if (is_irda(serial)) {
  156. ARK3116_SND(serial, 1001, 0xFE, 0x40, 0x0000, 0x000C);
  157. ARK3116_SND(serial, 1002, 0xFE, 0x40, 0x0041, 0x000D);
  158. ARK3116_SND(serial, 1003, 0xFE, 0x40, 0x0001, 0x000A);
  159. }
  160. /* <-- seq7 */
  161. ARK3116_RCV(serial, 7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
  162. ARK3116_SND(serial, 8, 0xFE, 0x40, 0x0080, 0x0003);
  163. ARK3116_SND(serial, 9, 0xFE, 0x40, 0x001A, 0x0000);
  164. ARK3116_SND(serial, 10, 0xFE, 0x40, 0x0000, 0x0001);
  165. ARK3116_SND(serial, 11, 0xFE, 0x40, 0x0000, 0x0003);
  166. /* <-- seq12 */
  167. ARK3116_RCV(serial, 12, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
  168. ARK3116_SND(serial, 13, 0xFE, 0x40, 0x0000, 0x0004);
  169. /* 14 */
  170. ARK3116_RCV(serial, 14, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
  171. ARK3116_SND(serial, 15, 0xFE, 0x40, 0x0000, 0x0004);
  172. /* 16 */
  173. ARK3116_RCV(serial, 16, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
  174. /* --> seq17 */
  175. ARK3116_SND(serial, 17, 0xFE, 0x40, 0x0001, 0x0004);
  176. /* <-- seq18 */
  177. ARK3116_RCV(serial, 18, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf);
  178. /* --> seq19 */
  179. ARK3116_SND(serial, 19, 0xFE, 0x40, 0x0003, 0x0004);
  180. /* <-- seq20 */
  181. /* seems like serial port status info (RTS, CTS, ...) */
  182. /* returns modem control line status?! */
  183. ARK3116_RCV(serial, 20, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
  184. /* set 9600 baud & do some init?! */
  185. ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
  186. ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000);
  187. ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001);
  188. if (is_irda(serial))
  189. ARK3116_SND(serial, 1004, 0xFE, 0x40, 0x0000, 0x0009);
  190. ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
  191. ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
  192. ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
  193. ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
  194. ARK3116_SND(serial, 154, 0xFE, 0x40, 0x0003, 0x0003);
  195. kfree(buf);
  196. return 0;
  197. }
  198. static void ark3116_init_termios(struct tty_struct *tty)
  199. {
  200. struct ktermios *termios = tty->termios;
  201. *termios = tty_std_termios;
  202. termios->c_cflag = B9600 | CS8
  203. | CREAD | HUPCL | CLOCAL;
  204. termios->c_ispeed = 9600;
  205. termios->c_ospeed = 9600;
  206. }
  207. static void ark3116_set_termios(struct tty_struct *tty,
  208. struct usb_serial_port *port,
  209. struct ktermios *old_termios)
  210. {
  211. struct usb_serial *serial = port->serial;
  212. struct ktermios *termios = tty->termios;
  213. unsigned int cflag = termios->c_cflag;
  214. int baud;
  215. int ark3116_baud;
  216. char *buf;
  217. char config;
  218. config = 0;
  219. dbg("%s - port %d", __func__, port->number);
  220. cflag = termios->c_cflag;
  221. termios->c_cflag &= ~(CMSPAR|CRTSCTS);
  222. buf = kmalloc(1, GFP_KERNEL);
  223. if (!buf) {
  224. dbg("error kmalloc");
  225. *termios = *old_termios;
  226. return;
  227. }
  228. /* set data bit count (8/7/6/5) */
  229. if (cflag & CSIZE) {
  230. switch (cflag & CSIZE) {
  231. case CS5:
  232. config |= 0x00;
  233. dbg("setting CS5");
  234. break;
  235. case CS6:
  236. config |= 0x01;
  237. dbg("setting CS6");
  238. break;
  239. case CS7:
  240. config |= 0x02;
  241. dbg("setting CS7");
  242. break;
  243. default:
  244. dbg("CSIZE was set but not CS5-CS8, using CS8!");
  245. /* fall through */
  246. case CS8:
  247. config |= 0x03;
  248. dbg("setting CS8");
  249. break;
  250. }
  251. }
  252. /* set parity (NONE/EVEN/ODD) */
  253. if (cflag & PARENB) {
  254. if (cflag & PARODD) {
  255. config |= 0x08;
  256. dbg("setting parity to ODD");
  257. } else {
  258. config |= 0x18;
  259. dbg("setting parity to EVEN");
  260. }
  261. } else {
  262. dbg("setting parity to NONE");
  263. }
  264. /* set stop bit (1/2) */
  265. if (cflag & CSTOPB) {
  266. config |= 0x04;
  267. dbg("setting 2 stop bits");
  268. } else {
  269. dbg("setting 1 stop bit");
  270. }
  271. /* set baudrate */
  272. baud = tty_get_baud_rate(tty);
  273. switch (baud) {
  274. case 75:
  275. case 150:
  276. case 300:
  277. case 600:
  278. case 1200:
  279. case 1800:
  280. case 2400:
  281. case 4800:
  282. case 9600:
  283. case 19200:
  284. case 38400:
  285. case 57600:
  286. case 115200:
  287. case 230400:
  288. case 460800:
  289. /* Report the resulting rate back to the caller */
  290. tty_encode_baud_rate(tty, baud, baud);
  291. break;
  292. /* set 9600 as default (if given baudrate is invalid for example) */
  293. default:
  294. tty_encode_baud_rate(tty, 9600, 9600);
  295. case 0:
  296. baud = 9600;
  297. }
  298. /*
  299. * found by try'n'error, be careful, maybe there are other options
  300. * for multiplicator etc! (3.5 for example)
  301. */
  302. if (baud == 460800)
  303. /* strange, for 460800 the formula is wrong
  304. * if using round() then 9600baud is wrong) */
  305. ark3116_baud = 7;
  306. else
  307. ark3116_baud = 3000000 / baud;
  308. /* ? */
  309. ARK3116_RCV(serial, 0, 0xFE, 0xC0, 0x0000, 0x0003, 0x03, buf);
  310. /* offset = buf[0]; */
  311. /* offset = 0x03; */
  312. /* dbg("using 0x%04X as target for 0x0003:", 0x0080 + offset); */
  313. /* set baudrate */
  314. dbg("setting baudrate to %d (->reg=%d)", baud, ark3116_baud);
  315. ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
  316. ARK3116_SND(serial, 148, 0xFE, 0x40,
  317. (ark3116_baud & 0x00FF), 0x0000);
  318. ARK3116_SND(serial, 149, 0xFE, 0x40,
  319. (ark3116_baud & 0xFF00) >> 8, 0x0001);
  320. ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
  321. /* ? */
  322. ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
  323. ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
  324. /* set data bit count, stop bit count & parity: */
  325. dbg("updating bit count, stop bit or parity (cfg=0x%02X)", config);
  326. ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
  327. ARK3116_SND(serial, 154, 0xFE, 0x40, config, 0x0003);
  328. if (cflag & CRTSCTS)
  329. dbg("CRTSCTS not supported by chipset?!");
  330. /* TEST ARK3116_SND(154, 0xFE, 0x40, 0xFFFF, 0x0006); */
  331. kfree(buf);
  332. return;
  333. }
  334. static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
  335. {
  336. struct ktermios tmp_termios;
  337. struct usb_serial *serial = port->serial;
  338. char *buf;
  339. int result = 0;
  340. dbg("%s - port %d", __func__, port->number);
  341. buf = kmalloc(1, GFP_KERNEL);
  342. if (!buf) {
  343. dbg("error kmalloc -> out of mem?");
  344. return -ENOMEM;
  345. }
  346. result = usb_serial_generic_open(tty, port);
  347. if (result)
  348. goto err_out;
  349. /* open */
  350. ARK3116_RCV(serial, 111, 0xFE, 0xC0, 0x0000, 0x0003, 0x02, buf);
  351. ARK3116_SND(serial, 112, 0xFE, 0x40, 0x0082, 0x0003);
  352. ARK3116_SND(serial, 113, 0xFE, 0x40, 0x001A, 0x0000);
  353. ARK3116_SND(serial, 114, 0xFE, 0x40, 0x0000, 0x0001);
  354. ARK3116_SND(serial, 115, 0xFE, 0x40, 0x0002, 0x0003);
  355. ARK3116_RCV(serial, 116, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
  356. ARK3116_SND(serial, 117, 0xFE, 0x40, 0x0002, 0x0004);
  357. ARK3116_RCV(serial, 118, 0xFE, 0xC0, 0x0000, 0x0004, 0x02, buf);
  358. ARK3116_SND(serial, 119, 0xFE, 0x40, 0x0000, 0x0004);
  359. ARK3116_RCV(serial, 120, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
  360. ARK3116_SND(serial, 121, 0xFE, 0x40, 0x0001, 0x0004);
  361. ARK3116_RCV(serial, 122, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf);
  362. ARK3116_SND(serial, 123, 0xFE, 0x40, 0x0003, 0x0004);
  363. /* returns different values (control lines?!) */
  364. ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
  365. /* initialise termios */
  366. if (tty)
  367. ark3116_set_termios(tty, port, &tmp_termios);
  368. err_out:
  369. kfree(buf);
  370. return result;
  371. }
  372. static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
  373. unsigned int cmd, unsigned long arg)
  374. {
  375. struct usb_serial_port *port = tty->driver_data;
  376. struct serial_struct serstruct;
  377. void __user *user_arg = (void __user *)arg;
  378. switch (cmd) {
  379. case TIOCGSERIAL:
  380. /* XXX: Some of these values are probably wrong. */
  381. memset(&serstruct, 0, sizeof(serstruct));
  382. serstruct.type = PORT_16654;
  383. serstruct.line = port->serial->minor;
  384. serstruct.port = port->number;
  385. serstruct.custom_divisor = 0;
  386. serstruct.baud_base = 460800;
  387. if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
  388. return -EFAULT;
  389. return 0;
  390. case TIOCSSERIAL:
  391. if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
  392. return -EFAULT;
  393. return 0;
  394. default:
  395. dbg("%s cmd 0x%04x not supported", __func__, cmd);
  396. break;
  397. }
  398. return -ENOIOCTLCMD;
  399. }
  400. static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
  401. {
  402. struct usb_serial_port *port = tty->driver_data;
  403. struct usb_serial *serial = port->serial;
  404. char *buf;
  405. char temp;
  406. /* seems like serial port status info (RTS, CTS, ...) is stored
  407. * in reg(?) 0x0006
  408. * pcb connection point 11 = GND -> sets bit4 of response
  409. * pcb connection point 7 = GND -> sets bit6 of response
  410. */
  411. buf = kmalloc(1, GFP_KERNEL);
  412. if (!buf) {
  413. dbg("error kmalloc");
  414. return -ENOMEM;
  415. }
  416. /* read register */
  417. ARK3116_RCV_QUIET(serial, 0xFE, 0xC0, 0x0000, 0x0006, buf);
  418. temp = buf[0];
  419. kfree(buf);
  420. /* i do not really know if bit4=CTS and bit6=DSR... just a
  421. * quick guess!
  422. */
  423. return (temp & (1<<4) ? TIOCM_CTS : 0)
  424. | (temp & (1<<6) ? TIOCM_DSR : 0);
  425. }
  426. static struct usb_driver ark3116_driver = {
  427. .name = "ark3116",
  428. .probe = usb_serial_probe,
  429. .disconnect = usb_serial_disconnect,
  430. .id_table = id_table,
  431. .no_dynamic_id = 1,
  432. };
  433. static struct usb_serial_driver ark3116_device = {
  434. .driver = {
  435. .owner = THIS_MODULE,
  436. .name = "ark3116",
  437. },
  438. .id_table = id_table,
  439. .usb_driver = &ark3116_driver,
  440. .num_ports = 1,
  441. .attach = ark3116_attach,
  442. .set_termios = ark3116_set_termios,
  443. .init_termios = ark3116_init_termios,
  444. .ioctl = ark3116_ioctl,
  445. .tiocmget = ark3116_tiocmget,
  446. .open = ark3116_open,
  447. };
  448. static int __init ark3116_init(void)
  449. {
  450. int retval;
  451. retval = usb_serial_register(&ark3116_device);
  452. if (retval)
  453. return retval;
  454. retval = usb_register(&ark3116_driver);
  455. if (retval == 0) {
  456. printk(KERN_INFO "%s:"
  457. DRIVER_VERSION ":"
  458. DRIVER_DESC "\n",
  459. KBUILD_MODNAME);
  460. } else
  461. usb_serial_deregister(&ark3116_device);
  462. return retval;
  463. }
  464. static void __exit ark3116_exit(void)
  465. {
  466. usb_deregister(&ark3116_driver);
  467. usb_serial_deregister(&ark3116_device);
  468. }
  469. module_init(ark3116_init);
  470. module_exit(ark3116_exit);
  471. MODULE_LICENSE("GPL");
  472. MODULE_AUTHOR(DRIVER_AUTHOR);
  473. MODULE_DESCRIPTION(DRIVER_DESC);
  474. module_param(debug, bool, S_IRUGO | S_IWUSR);
  475. MODULE_PARM_DESC(debug, "Enable debug");
  476. /*
  477. * The following describes what I learned from studying the old
  478. * ark3116.c driver, disassembling the windows driver, and some lucky
  479. * guesses. Since I do not have any datasheet or other
  480. * documentation, inaccuracies are almost guaranteed.
  481. *
  482. * Some specs for the ARK3116 can be found here:
  483. * http://web.archive.org/web/20060318000438/
  484. * www.arkmicro.com/en/products/view.php?id=10
  485. * On that page, 2 GPIO pins are mentioned: I assume these are the
  486. * OUT1 and OUT2 pins of the UART, so I added support for those
  487. * through the MCR. Since the pins are not available on my hardware,
  488. * I could not verify this.
  489. * Also, it states there is "on-chip hardware flow control". I have
  490. * discovered how to enable that. Unfortunately, I do not know how to
  491. * enable XON/XOFF (software) flow control, which would need support
  492. * from the chip as well to work. Because of the wording on the web
  493. * page there is a real possibility the chip simply does not support
  494. * software flow control.
  495. *
  496. * I got my ark3116 as part of a mobile phone adapter cable. On the
  497. * PCB, the following numbered contacts are present:
  498. *
  499. * 1:- +5V
  500. * 2:o DTR
  501. * 3:i RX
  502. * 4:i DCD
  503. * 5:o RTS
  504. * 6:o TX
  505. * 7:i RI
  506. * 8:i DSR
  507. * 10:- 0V
  508. * 11:i CTS
  509. *
  510. * On my chip, all signals seem to be 3.3V, but 5V tolerant. But that
  511. * may be different for the one you have ;-).
  512. *
  513. * The windows driver limits the registers to 0-F, so I assume there
  514. * are actually 16 present on the device.
  515. *
  516. * On an UART interrupt, 4 bytes of data come in on the interrupt
  517. * endpoint. The bytes are 0xe8 IIR LSR MSR.
  518. *
  519. * The baudrate seems to be generated from the 12MHz crystal, using
  520. * 4-times subsampling. So quot=12e6/(4*baud). Also see description
  521. * of register E.
  522. *
  523. * Registers 0-7:
  524. * These seem to be the same as for a regular 16450. The FCR is set
  525. * to UART_FCR_DMA_SELECT (0x8), I guess to enable transfers between
  526. * the UART and the USB bridge/DMA engine.
  527. *
  528. * Register 8:
  529. * By trial and error, I found out that bit 0 enables hardware CTS,
  530. * stopping TX when CTS is +5V. Bit 1 does the same for RTS, making
  531. * RTS +5V when the 3116 cannot transfer the data to the USB bus
  532. * (verified by disabling the reading URB). Note that as far as I can
  533. * tell, the windows driver does NOT use this, so there might be some
  534. * hardware bug or something.
  535. *
  536. * According to a patch provided here
  537. * (http://lkml.org/lkml/2009/7/26/56), the ARK3116 can also be used
  538. * as an IrDA dongle. Since I do not have such a thing, I could not
  539. * investigate that aspect. However, I can speculate ;-).
  540. *
  541. * - IrDA encodes data differently than RS232. Most likely, one of
  542. * the bits in registers 9..E enables the IR ENDEC (encoder/decoder).
  543. * - Depending on the IR transceiver, the input and output need to be
  544. * inverted, so there are probably bits for that as well.
  545. * - IrDA is half-duplex, so there should be a bit for selecting that.
  546. *
  547. * This still leaves at least two registers unaccounted for. Perhaps
  548. * The chip can do XON/XOFF or CRC in HW?
  549. *
  550. * Register 9:
  551. * Set to 0x00 for IrDA, when the baudrate is initialised.
  552. *
  553. * Register A:
  554. * Set to 0x01 for IrDA, at init.
  555. *
  556. * Register B:
  557. * Set to 0x01 for IrDA, 0x00 for RS232, at init.
  558. *
  559. * Register C:
  560. * Set to 00 for IrDA, at init.
  561. *
  562. * Register D:
  563. * Set to 0x41 for IrDA, at init.
  564. *
  565. * Register E:
  566. * Somekind of baudrate override. The windows driver seems to set
  567. * this to 0x00 for normal baudrates, 0x01 for 460800, 0x02 for 921600.
  568. * Since 460800 and 921600 cannot be obtained by dividing 3MHz by an integer,
  569. * it could be somekind of subdivisor thingy.
  570. * However,it does not seem to do anything: selecting 921600 (divisor 3,
  571. * reg E=2), still gets 1 MHz. I also checked if registers 9, C or F would
  572. * work, but they don't.
  573. *
  574. * Register F: unknown
  575. */