ch341.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. * Copyright 2007, Frank A Kingswood <frank@kingswood-consulting.co.uk>
  3. * Copyright 2007, Werner Cornelius <werner@cornelius-consult.de>
  4. * Copyright 2009, Boris Hajduk <boris@hajduk.org>
  5. *
  6. * ch341.c implements a serial port driver for the Winchiphead CH341.
  7. *
  8. * The CH341 device can be used to implement an RS232 asynchronous
  9. * serial port, an IEEE-1284 parallel printer port or a memory-like
  10. * interface. In all cases the CH341 supports an I2C interface as well.
  11. * This driver only supports the asynchronous serial interface.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License version
  15. * 2 as published by the Free Software Foundation.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/tty.h>
  20. #include <linux/module.h>
  21. #include <linux/slab.h>
  22. #include <linux/usb.h>
  23. #include <linux/usb/serial.h>
  24. #include <linux/serial.h>
  25. #include <asm/unaligned.h>
  26. #define DEFAULT_BAUD_RATE 9600
  27. #define DEFAULT_TIMEOUT 1000
  28. /* flags for IO-Bits */
  29. #define CH341_BIT_RTS (1 << 6)
  30. #define CH341_BIT_DTR (1 << 5)
  31. /******************************/
  32. /* interrupt pipe definitions */
  33. /******************************/
  34. /* always 4 interrupt bytes */
  35. /* first irq byte normally 0x08 */
  36. /* second irq byte base 0x7d + below */
  37. /* third irq byte base 0x94 + below */
  38. /* fourth irq byte normally 0xee */
  39. /* second interrupt byte */
  40. #define CH341_MULT_STAT 0x04 /* multiple status since last interrupt event */
  41. /* status returned in third interrupt answer byte, inverted in data
  42. from irq */
  43. #define CH341_BIT_CTS 0x01
  44. #define CH341_BIT_DSR 0x02
  45. #define CH341_BIT_RI 0x04
  46. #define CH341_BIT_DCD 0x08
  47. #define CH341_BITS_MODEM_STAT 0x0f /* all bits */
  48. /*******************************/
  49. /* baudrate calculation factor */
  50. /*******************************/
  51. #define CH341_BAUDBASE_FACTOR 1532620800
  52. #define CH341_BAUDBASE_DIVMAX 3
  53. /* Break support - the information used to implement this was gleaned from
  54. * the Net/FreeBSD uchcom.c driver by Takanori Watanabe. Domo arigato.
  55. */
  56. #define CH341_REQ_WRITE_REG 0x9A
  57. #define CH341_REQ_READ_REG 0x95
  58. #define CH341_REG_BREAK1 0x05
  59. #define CH341_REG_BREAK2 0x18
  60. #define CH341_NBREAK_BITS_REG1 0x01
  61. #define CH341_NBREAK_BITS_REG2 0x40
  62. static int debug;
  63. static const struct usb_device_id id_table[] = {
  64. { USB_DEVICE(0x4348, 0x5523) },
  65. { USB_DEVICE(0x1a86, 0x7523) },
  66. { },
  67. };
  68. MODULE_DEVICE_TABLE(usb, id_table);
  69. struct ch341_private {
  70. spinlock_t lock; /* access lock */
  71. wait_queue_head_t delta_msr_wait; /* wait queue for modem status */
  72. unsigned baud_rate; /* set baud rate */
  73. u8 line_control; /* set line control value RTS/DTR */
  74. u8 line_status; /* active status of modem control inputs */
  75. u8 multi_status_change; /* status changed multiple since last call */
  76. };
  77. static int ch341_control_out(struct usb_device *dev, u8 request,
  78. u16 value, u16 index)
  79. {
  80. int r;
  81. dbg("ch341_control_out(%02x,%02x,%04x,%04x)", USB_DIR_OUT|0x40,
  82. (int)request, (int)value, (int)index);
  83. r = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
  84. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  85. value, index, NULL, 0, DEFAULT_TIMEOUT);
  86. return r;
  87. }
  88. static int ch341_control_in(struct usb_device *dev,
  89. u8 request, u16 value, u16 index,
  90. char *buf, unsigned bufsize)
  91. {
  92. int r;
  93. dbg("ch341_control_in(%02x,%02x,%04x,%04x,%p,%u)", USB_DIR_IN|0x40,
  94. (int)request, (int)value, (int)index, buf, (int)bufsize);
  95. r = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), request,
  96. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  97. value, index, buf, bufsize, DEFAULT_TIMEOUT);
  98. return r;
  99. }
  100. static int ch341_set_baudrate(struct usb_device *dev,
  101. struct ch341_private *priv)
  102. {
  103. short a, b;
  104. int r;
  105. unsigned long factor;
  106. short divisor;
  107. dbg("ch341_set_baudrate(%d)", priv->baud_rate);
  108. if (!priv->baud_rate)
  109. return -EINVAL;
  110. factor = (CH341_BAUDBASE_FACTOR / priv->baud_rate);
  111. divisor = CH341_BAUDBASE_DIVMAX;
  112. while ((factor > 0xfff0) && divisor) {
  113. factor >>= 3;
  114. divisor--;
  115. }
  116. if (factor > 0xfff0)
  117. return -EINVAL;
  118. factor = 0x10000 - factor;
  119. a = (factor & 0xff00) | divisor;
  120. b = factor & 0xff;
  121. r = ch341_control_out(dev, 0x9a, 0x1312, a);
  122. if (!r)
  123. r = ch341_control_out(dev, 0x9a, 0x0f2c, b);
  124. return r;
  125. }
  126. static int ch341_set_handshake(struct usb_device *dev, u8 control)
  127. {
  128. dbg("ch341_set_handshake(0x%02x)", control);
  129. return ch341_control_out(dev, 0xa4, ~control, 0);
  130. }
  131. static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv)
  132. {
  133. char *buffer;
  134. int r;
  135. const unsigned size = 8;
  136. unsigned long flags;
  137. dbg("ch341_get_status()");
  138. buffer = kmalloc(size, GFP_KERNEL);
  139. if (!buffer)
  140. return -ENOMEM;
  141. r = ch341_control_in(dev, 0x95, 0x0706, 0, buffer, size);
  142. if (r < 0)
  143. goto out;
  144. /* setup the private status if available */
  145. if (r == 2) {
  146. r = 0;
  147. spin_lock_irqsave(&priv->lock, flags);
  148. priv->line_status = (~(*buffer)) & CH341_BITS_MODEM_STAT;
  149. priv->multi_status_change = 0;
  150. spin_unlock_irqrestore(&priv->lock, flags);
  151. } else
  152. r = -EPROTO;
  153. out: kfree(buffer);
  154. return r;
  155. }
  156. /* -------------------------------------------------------------------------- */
  157. static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
  158. {
  159. char *buffer;
  160. int r;
  161. const unsigned size = 8;
  162. dbg("ch341_configure()");
  163. buffer = kmalloc(size, GFP_KERNEL);
  164. if (!buffer)
  165. return -ENOMEM;
  166. /* expect two bytes 0x27 0x00 */
  167. r = ch341_control_in(dev, 0x5f, 0, 0, buffer, size);
  168. if (r < 0)
  169. goto out;
  170. r = ch341_control_out(dev, 0xa1, 0, 0);
  171. if (r < 0)
  172. goto out;
  173. r = ch341_set_baudrate(dev, priv);
  174. if (r < 0)
  175. goto out;
  176. /* expect two bytes 0x56 0x00 */
  177. r = ch341_control_in(dev, 0x95, 0x2518, 0, buffer, size);
  178. if (r < 0)
  179. goto out;
  180. r = ch341_control_out(dev, 0x9a, 0x2518, 0x0050);
  181. if (r < 0)
  182. goto out;
  183. /* expect 0xff 0xee */
  184. r = ch341_get_status(dev, priv);
  185. if (r < 0)
  186. goto out;
  187. r = ch341_control_out(dev, 0xa1, 0x501f, 0xd90a);
  188. if (r < 0)
  189. goto out;
  190. r = ch341_set_baudrate(dev, priv);
  191. if (r < 0)
  192. goto out;
  193. r = ch341_set_handshake(dev, priv->line_control);
  194. if (r < 0)
  195. goto out;
  196. /* expect 0x9f 0xee */
  197. r = ch341_get_status(dev, priv);
  198. out: kfree(buffer);
  199. return r;
  200. }
  201. /* allocate private data */
  202. static int ch341_attach(struct usb_serial *serial)
  203. {
  204. struct ch341_private *priv;
  205. int r;
  206. dbg("ch341_attach()");
  207. /* private data */
  208. priv = kzalloc(sizeof(struct ch341_private), GFP_KERNEL);
  209. if (!priv)
  210. return -ENOMEM;
  211. spin_lock_init(&priv->lock);
  212. init_waitqueue_head(&priv->delta_msr_wait);
  213. priv->baud_rate = DEFAULT_BAUD_RATE;
  214. priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR;
  215. r = ch341_configure(serial->dev, priv);
  216. if (r < 0)
  217. goto error;
  218. usb_set_serial_port_data(serial->port[0], priv);
  219. return 0;
  220. error: kfree(priv);
  221. return r;
  222. }
  223. static int ch341_carrier_raised(struct usb_serial_port *port)
  224. {
  225. struct ch341_private *priv = usb_get_serial_port_data(port);
  226. if (priv->line_status & CH341_BIT_DCD)
  227. return 1;
  228. return 0;
  229. }
  230. static void ch341_dtr_rts(struct usb_serial_port *port, int on)
  231. {
  232. struct ch341_private *priv = usb_get_serial_port_data(port);
  233. unsigned long flags;
  234. dbg("%s - port %d", __func__, port->number);
  235. /* drop DTR and RTS */
  236. spin_lock_irqsave(&priv->lock, flags);
  237. if (on)
  238. priv->line_control |= CH341_BIT_RTS | CH341_BIT_DTR;
  239. else
  240. priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR);
  241. spin_unlock_irqrestore(&priv->lock, flags);
  242. ch341_set_handshake(port->serial->dev, priv->line_control);
  243. wake_up_interruptible(&priv->delta_msr_wait);
  244. }
  245. static void ch341_close(struct usb_serial_port *port)
  246. {
  247. dbg("%s - port %d", __func__, port->number);
  248. usb_serial_generic_close(port);
  249. usb_kill_urb(port->interrupt_in_urb);
  250. }
  251. /* open this device, set default parameters */
  252. static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port)
  253. {
  254. struct usb_serial *serial = port->serial;
  255. struct ch341_private *priv = usb_get_serial_port_data(serial->port[0]);
  256. int r;
  257. dbg("ch341_open()");
  258. priv->baud_rate = DEFAULT_BAUD_RATE;
  259. r = ch341_configure(serial->dev, priv);
  260. if (r)
  261. goto out;
  262. r = ch341_set_handshake(serial->dev, priv->line_control);
  263. if (r)
  264. goto out;
  265. r = ch341_set_baudrate(serial->dev, priv);
  266. if (r)
  267. goto out;
  268. dbg("%s - submitting interrupt urb", __func__);
  269. port->interrupt_in_urb->dev = serial->dev;
  270. r = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  271. if (r) {
  272. dev_err(&port->dev, "%s - failed submitting interrupt urb,"
  273. " error %d\n", __func__, r);
  274. ch341_close(port);
  275. return -EPROTO;
  276. }
  277. r = usb_serial_generic_open(tty, port);
  278. out: return r;
  279. }
  280. /* Old_termios contains the original termios settings and
  281. * tty->termios contains the new setting to be used.
  282. */
  283. static void ch341_set_termios(struct tty_struct *tty,
  284. struct usb_serial_port *port, struct ktermios *old_termios)
  285. {
  286. struct ch341_private *priv = usb_get_serial_port_data(port);
  287. unsigned baud_rate;
  288. unsigned long flags;
  289. dbg("ch341_set_termios()");
  290. baud_rate = tty_get_baud_rate(tty);
  291. priv->baud_rate = baud_rate;
  292. if (baud_rate) {
  293. spin_lock_irqsave(&priv->lock, flags);
  294. priv->line_control |= (CH341_BIT_DTR | CH341_BIT_RTS);
  295. spin_unlock_irqrestore(&priv->lock, flags);
  296. ch341_set_baudrate(port->serial->dev, priv);
  297. } else {
  298. spin_lock_irqsave(&priv->lock, flags);
  299. priv->line_control &= ~(CH341_BIT_DTR | CH341_BIT_RTS);
  300. spin_unlock_irqrestore(&priv->lock, flags);
  301. }
  302. ch341_set_handshake(port->serial->dev, priv->line_control);
  303. /* Unimplemented:
  304. * (cflag & CSIZE) : data bits [5, 8]
  305. * (cflag & PARENB) : parity {NONE, EVEN, ODD}
  306. * (cflag & CSTOPB) : stop bits [1, 2]
  307. */
  308. }
  309. static void ch341_break_ctl(struct tty_struct *tty, int break_state)
  310. {
  311. const uint16_t ch341_break_reg =
  312. CH341_REG_BREAK1 | ((uint16_t) CH341_REG_BREAK2 << 8);
  313. struct usb_serial_port *port = tty->driver_data;
  314. int r;
  315. uint16_t reg_contents;
  316. uint8_t *break_reg;
  317. dbg("%s()", __func__);
  318. break_reg = kmalloc(2, GFP_KERNEL);
  319. if (!break_reg) {
  320. dev_err(&port->dev, "%s - kmalloc failed\n", __func__);
  321. return;
  322. }
  323. r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG,
  324. ch341_break_reg, 0, break_reg, 2);
  325. if (r < 0) {
  326. dev_err(&port->dev, "%s - USB control read error (%d)\n",
  327. __func__, r);
  328. goto out;
  329. }
  330. dbg("%s - initial ch341 break register contents - reg1: %x, reg2: %x",
  331. __func__, break_reg[0], break_reg[1]);
  332. if (break_state != 0) {
  333. dbg("%s - Enter break state requested", __func__);
  334. break_reg[0] &= ~CH341_NBREAK_BITS_REG1;
  335. break_reg[1] &= ~CH341_NBREAK_BITS_REG2;
  336. } else {
  337. dbg("%s - Leave break state requested", __func__);
  338. break_reg[0] |= CH341_NBREAK_BITS_REG1;
  339. break_reg[1] |= CH341_NBREAK_BITS_REG2;
  340. }
  341. dbg("%s - New ch341 break register contents - reg1: %x, reg2: %x",
  342. __func__, break_reg[0], break_reg[1]);
  343. reg_contents = get_unaligned_le16(break_reg);
  344. r = ch341_control_out(port->serial->dev, CH341_REQ_WRITE_REG,
  345. ch341_break_reg, reg_contents);
  346. if (r < 0)
  347. dev_err(&port->dev, "%s - USB control write error (%d)\n",
  348. __func__, r);
  349. out:
  350. kfree(break_reg);
  351. }
  352. static int ch341_tiocmset(struct tty_struct *tty, struct file *file,
  353. unsigned int set, unsigned int clear)
  354. {
  355. struct usb_serial_port *port = tty->driver_data;
  356. struct ch341_private *priv = usb_get_serial_port_data(port);
  357. unsigned long flags;
  358. u8 control;
  359. spin_lock_irqsave(&priv->lock, flags);
  360. if (set & TIOCM_RTS)
  361. priv->line_control |= CH341_BIT_RTS;
  362. if (set & TIOCM_DTR)
  363. priv->line_control |= CH341_BIT_DTR;
  364. if (clear & TIOCM_RTS)
  365. priv->line_control &= ~CH341_BIT_RTS;
  366. if (clear & TIOCM_DTR)
  367. priv->line_control &= ~CH341_BIT_DTR;
  368. control = priv->line_control;
  369. spin_unlock_irqrestore(&priv->lock, flags);
  370. return ch341_set_handshake(port->serial->dev, control);
  371. }
  372. static void ch341_read_int_callback(struct urb *urb)
  373. {
  374. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  375. unsigned char *data = urb->transfer_buffer;
  376. unsigned int actual_length = urb->actual_length;
  377. int status;
  378. dbg("%s (%d)", __func__, port->number);
  379. switch (urb->status) {
  380. case 0:
  381. /* success */
  382. break;
  383. case -ECONNRESET:
  384. case -ENOENT:
  385. case -ESHUTDOWN:
  386. /* this urb is terminated, clean up */
  387. dbg("%s - urb shutting down with status: %d", __func__,
  388. urb->status);
  389. return;
  390. default:
  391. dbg("%s - nonzero urb status received: %d", __func__,
  392. urb->status);
  393. goto exit;
  394. }
  395. usb_serial_debug_data(debug, &port->dev, __func__,
  396. urb->actual_length, urb->transfer_buffer);
  397. if (actual_length >= 4) {
  398. struct ch341_private *priv = usb_get_serial_port_data(port);
  399. unsigned long flags;
  400. u8 prev_line_status = priv->line_status;
  401. spin_lock_irqsave(&priv->lock, flags);
  402. priv->line_status = (~(data[2])) & CH341_BITS_MODEM_STAT;
  403. if ((data[1] & CH341_MULT_STAT))
  404. priv->multi_status_change = 1;
  405. spin_unlock_irqrestore(&priv->lock, flags);
  406. if ((priv->line_status ^ prev_line_status) & CH341_BIT_DCD) {
  407. struct tty_struct *tty = tty_port_tty_get(&port->port);
  408. if (tty)
  409. usb_serial_handle_dcd_change(port, tty,
  410. priv->line_status & CH341_BIT_DCD);
  411. tty_kref_put(tty);
  412. }
  413. wake_up_interruptible(&priv->delta_msr_wait);
  414. }
  415. exit:
  416. status = usb_submit_urb(urb, GFP_ATOMIC);
  417. if (status)
  418. dev_err(&urb->dev->dev,
  419. "%s - usb_submit_urb failed with result %d\n",
  420. __func__, status);
  421. }
  422. static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
  423. {
  424. struct ch341_private *priv = usb_get_serial_port_data(port);
  425. unsigned long flags;
  426. u8 prevstatus;
  427. u8 status;
  428. u8 changed;
  429. u8 multi_change = 0;
  430. spin_lock_irqsave(&priv->lock, flags);
  431. prevstatus = priv->line_status;
  432. priv->multi_status_change = 0;
  433. spin_unlock_irqrestore(&priv->lock, flags);
  434. while (!multi_change) {
  435. interruptible_sleep_on(&priv->delta_msr_wait);
  436. /* see if a signal did it */
  437. if (signal_pending(current))
  438. return -ERESTARTSYS;
  439. spin_lock_irqsave(&priv->lock, flags);
  440. status = priv->line_status;
  441. multi_change = priv->multi_status_change;
  442. spin_unlock_irqrestore(&priv->lock, flags);
  443. changed = prevstatus ^ status;
  444. if (((arg & TIOCM_RNG) && (changed & CH341_BIT_RI)) ||
  445. ((arg & TIOCM_DSR) && (changed & CH341_BIT_DSR)) ||
  446. ((arg & TIOCM_CD) && (changed & CH341_BIT_DCD)) ||
  447. ((arg & TIOCM_CTS) && (changed & CH341_BIT_CTS))) {
  448. return 0;
  449. }
  450. prevstatus = status;
  451. }
  452. return 0;
  453. }
  454. /*static int ch341_ioctl(struct usb_serial_port *port, struct file *file,*/
  455. static int ch341_ioctl(struct tty_struct *tty, struct file *file,
  456. unsigned int cmd, unsigned long arg)
  457. {
  458. struct usb_serial_port *port = tty->driver_data;
  459. dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
  460. switch (cmd) {
  461. case TIOCMIWAIT:
  462. dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
  463. return wait_modem_info(port, arg);
  464. default:
  465. dbg("%s not supported = 0x%04x", __func__, cmd);
  466. break;
  467. }
  468. return -ENOIOCTLCMD;
  469. }
  470. static int ch341_tiocmget(struct tty_struct *tty, struct file *file)
  471. {
  472. struct usb_serial_port *port = tty->driver_data;
  473. struct ch341_private *priv = usb_get_serial_port_data(port);
  474. unsigned long flags;
  475. u8 mcr;
  476. u8 status;
  477. unsigned int result;
  478. dbg("%s (%d)", __func__, port->number);
  479. spin_lock_irqsave(&priv->lock, flags);
  480. mcr = priv->line_control;
  481. status = priv->line_status;
  482. spin_unlock_irqrestore(&priv->lock, flags);
  483. result = ((mcr & CH341_BIT_DTR) ? TIOCM_DTR : 0)
  484. | ((mcr & CH341_BIT_RTS) ? TIOCM_RTS : 0)
  485. | ((status & CH341_BIT_CTS) ? TIOCM_CTS : 0)
  486. | ((status & CH341_BIT_DSR) ? TIOCM_DSR : 0)
  487. | ((status & CH341_BIT_RI) ? TIOCM_RI : 0)
  488. | ((status & CH341_BIT_DCD) ? TIOCM_CD : 0);
  489. dbg("%s - result = %x", __func__, result);
  490. return result;
  491. }
  492. static int ch341_reset_resume(struct usb_interface *intf)
  493. {
  494. struct usb_device *dev = interface_to_usbdev(intf);
  495. struct usb_serial *serial = NULL;
  496. struct ch341_private *priv;
  497. serial = usb_get_intfdata(intf);
  498. priv = usb_get_serial_port_data(serial->port[0]);
  499. /*reconfigure ch341 serial port after bus-reset*/
  500. ch341_configure(dev, priv);
  501. usb_serial_resume(intf);
  502. return 0;
  503. }
  504. static struct usb_driver ch341_driver = {
  505. .name = "ch341",
  506. .probe = usb_serial_probe,
  507. .disconnect = usb_serial_disconnect,
  508. .suspend = usb_serial_suspend,
  509. .resume = usb_serial_resume,
  510. .reset_resume = ch341_reset_resume,
  511. .id_table = id_table,
  512. .no_dynamic_id = 1,
  513. .supports_autosuspend = 1,
  514. };
  515. static struct usb_serial_driver ch341_device = {
  516. .driver = {
  517. .owner = THIS_MODULE,
  518. .name = "ch341-uart",
  519. },
  520. .id_table = id_table,
  521. .usb_driver = &ch341_driver,
  522. .num_ports = 1,
  523. .open = ch341_open,
  524. .dtr_rts = ch341_dtr_rts,
  525. .carrier_raised = ch341_carrier_raised,
  526. .close = ch341_close,
  527. .ioctl = ch341_ioctl,
  528. .set_termios = ch341_set_termios,
  529. .break_ctl = ch341_break_ctl,
  530. .tiocmget = ch341_tiocmget,
  531. .tiocmset = ch341_tiocmset,
  532. .read_int_callback = ch341_read_int_callback,
  533. .attach = ch341_attach,
  534. };
  535. static int __init ch341_init(void)
  536. {
  537. int retval;
  538. retval = usb_serial_register(&ch341_device);
  539. if (retval)
  540. return retval;
  541. retval = usb_register(&ch341_driver);
  542. if (retval)
  543. usb_serial_deregister(&ch341_device);
  544. return retval;
  545. }
  546. static void __exit ch341_exit(void)
  547. {
  548. usb_deregister(&ch341_driver);
  549. usb_serial_deregister(&ch341_device);
  550. }
  551. module_init(ch341_init);
  552. module_exit(ch341_exit);
  553. MODULE_LICENSE("GPL");
  554. module_param(debug, bool, S_IRUGO | S_IWUSR);
  555. MODULE_PARM_DESC(debug, "Debug enabled or not");
  556. /* EOF ch341.c */