ch341.c 17 KB

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