ch341.c 17 KB

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