pl2303.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. /*
  2. * Prolific PL2303 USB to serial adaptor driver
  3. *
  4. * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
  5. * Copyright (C) 2003 IBM Corp.
  6. *
  7. * Original driver for 2.2.x by anonymous
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License.
  12. *
  13. * See Documentation/usb/usb-serial.txt for more information on using this driver
  14. *
  15. */
  16. #include <linux/config.h>
  17. #include <linux/kernel.h>
  18. #include <linux/errno.h>
  19. #include <linux/init.h>
  20. #include <linux/slab.h>
  21. #include <linux/tty.h>
  22. #include <linux/tty_driver.h>
  23. #include <linux/tty_flip.h>
  24. #include <linux/serial.h>
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/spinlock.h>
  28. #include <asm/uaccess.h>
  29. #include <linux/usb.h>
  30. #include "usb-serial.h"
  31. #include "pl2303.h"
  32. /*
  33. * Version Information
  34. */
  35. #define DRIVER_DESC "Prolific PL2303 USB to serial adaptor driver"
  36. static int debug;
  37. #define PL2303_CLOSING_WAIT (30*HZ)
  38. #define PL2303_BUF_SIZE 1024
  39. #define PL2303_TMP_BUF_SIZE 1024
  40. struct pl2303_buf {
  41. unsigned int buf_size;
  42. char *buf_buf;
  43. char *buf_get;
  44. char *buf_put;
  45. };
  46. static struct usb_device_id id_table [] = {
  47. { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) },
  48. { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) },
  49. { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ3) },
  50. { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_PHAROS) },
  51. { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
  52. { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) },
  53. { USB_DEVICE(ATEN_VENDOR_ID2, ATEN_PRODUCT_ID) },
  54. { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID) },
  55. { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID_UCSGT) },
  56. { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID) },
  57. { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) },
  58. { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) },
  59. { USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) },
  60. { USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) },
  61. { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) },
  62. { USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) },
  63. { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_ID) },
  64. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_ID) },
  65. { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_SX1) },
  66. { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65) },
  67. { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X75) },
  68. { USB_DEVICE(SYNTECH_VENDOR_ID, SYNTECH_PRODUCT_ID) },
  69. { USB_DEVICE( NOKIA_CA42_VENDOR_ID, NOKIA_CA42_PRODUCT_ID ) },
  70. { } /* Terminating entry */
  71. };
  72. MODULE_DEVICE_TABLE (usb, id_table);
  73. static struct usb_driver pl2303_driver = {
  74. .name = "pl2303",
  75. .probe = usb_serial_probe,
  76. .disconnect = usb_serial_disconnect,
  77. .id_table = id_table,
  78. .no_dynamic_id = 1,
  79. };
  80. #define SET_LINE_REQUEST_TYPE 0x21
  81. #define SET_LINE_REQUEST 0x20
  82. #define SET_CONTROL_REQUEST_TYPE 0x21
  83. #define SET_CONTROL_REQUEST 0x22
  84. #define CONTROL_DTR 0x01
  85. #define CONTROL_RTS 0x02
  86. #define BREAK_REQUEST_TYPE 0x21
  87. #define BREAK_REQUEST 0x23
  88. #define BREAK_ON 0xffff
  89. #define BREAK_OFF 0x0000
  90. #define GET_LINE_REQUEST_TYPE 0xa1
  91. #define GET_LINE_REQUEST 0x21
  92. #define VENDOR_WRITE_REQUEST_TYPE 0x40
  93. #define VENDOR_WRITE_REQUEST 0x01
  94. #define VENDOR_READ_REQUEST_TYPE 0xc0
  95. #define VENDOR_READ_REQUEST 0x01
  96. #define UART_STATE 0x08
  97. #define UART_STATE_TRANSIENT_MASK 0x74
  98. #define UART_DCD 0x01
  99. #define UART_DSR 0x02
  100. #define UART_BREAK_ERROR 0x04
  101. #define UART_RING 0x08
  102. #define UART_FRAME_ERROR 0x10
  103. #define UART_PARITY_ERROR 0x20
  104. #define UART_OVERRUN_ERROR 0x40
  105. #define UART_CTS 0x80
  106. /* function prototypes for a PL2303 serial converter */
  107. static int pl2303_open (struct usb_serial_port *port, struct file *filp);
  108. static void pl2303_close (struct usb_serial_port *port, struct file *filp);
  109. static void pl2303_set_termios (struct usb_serial_port *port,
  110. struct termios *old);
  111. static int pl2303_ioctl (struct usb_serial_port *port, struct file *file,
  112. unsigned int cmd, unsigned long arg);
  113. static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs);
  114. static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
  115. static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
  116. static int pl2303_write (struct usb_serial_port *port,
  117. const unsigned char *buf, int count);
  118. static void pl2303_send (struct usb_serial_port *port);
  119. static int pl2303_write_room(struct usb_serial_port *port);
  120. static int pl2303_chars_in_buffer(struct usb_serial_port *port);
  121. static void pl2303_break_ctl(struct usb_serial_port *port,int break_state);
  122. static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file);
  123. static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
  124. unsigned int set, unsigned int clear);
  125. static int pl2303_startup (struct usb_serial *serial);
  126. static void pl2303_shutdown (struct usb_serial *serial);
  127. static struct pl2303_buf *pl2303_buf_alloc(unsigned int size);
  128. static void pl2303_buf_free(struct pl2303_buf *pb);
  129. static void pl2303_buf_clear(struct pl2303_buf *pb);
  130. static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb);
  131. static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb);
  132. static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
  133. unsigned int count);
  134. static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
  135. unsigned int count);
  136. /* All of the device info needed for the PL2303 SIO serial converter */
  137. static struct usb_serial_driver pl2303_device = {
  138. .driver = {
  139. .owner = THIS_MODULE,
  140. .name = "pl2303",
  141. },
  142. .id_table = id_table,
  143. .num_interrupt_in = NUM_DONT_CARE,
  144. .num_bulk_in = 1,
  145. .num_bulk_out = 1,
  146. .num_ports = 1,
  147. .open = pl2303_open,
  148. .close = pl2303_close,
  149. .write = pl2303_write,
  150. .ioctl = pl2303_ioctl,
  151. .break_ctl = pl2303_break_ctl,
  152. .set_termios = pl2303_set_termios,
  153. .tiocmget = pl2303_tiocmget,
  154. .tiocmset = pl2303_tiocmset,
  155. .read_bulk_callback = pl2303_read_bulk_callback,
  156. .read_int_callback = pl2303_read_int_callback,
  157. .write_bulk_callback = pl2303_write_bulk_callback,
  158. .write_room = pl2303_write_room,
  159. .chars_in_buffer = pl2303_chars_in_buffer,
  160. .attach = pl2303_startup,
  161. .shutdown = pl2303_shutdown,
  162. };
  163. enum pl2303_type {
  164. type_0, /* don't know the difference between type 0 and */
  165. type_1, /* type 1, until someone from prolific tells us... */
  166. HX, /* HX version of the pl2303 chip */
  167. };
  168. struct pl2303_private {
  169. spinlock_t lock;
  170. struct pl2303_buf *buf;
  171. int write_urb_in_use;
  172. wait_queue_head_t delta_msr_wait;
  173. u8 line_control;
  174. u8 line_status;
  175. u8 termios_initialized;
  176. enum pl2303_type type;
  177. };
  178. static int pl2303_startup (struct usb_serial *serial)
  179. {
  180. struct pl2303_private *priv;
  181. enum pl2303_type type = type_0;
  182. int i;
  183. if (serial->dev->descriptor.bDeviceClass == 0x02)
  184. type = type_0;
  185. else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40)
  186. type = HX;
  187. else if (serial->dev->descriptor.bDeviceClass == 0x00)
  188. type = type_1;
  189. else if (serial->dev->descriptor.bDeviceClass == 0xFF)
  190. type = type_1;
  191. dbg("device type: %d", type);
  192. for (i = 0; i < serial->num_ports; ++i) {
  193. priv = kmalloc (sizeof (struct pl2303_private), GFP_KERNEL);
  194. if (!priv)
  195. goto cleanup;
  196. memset (priv, 0x00, sizeof (struct pl2303_private));
  197. spin_lock_init(&priv->lock);
  198. priv->buf = pl2303_buf_alloc(PL2303_BUF_SIZE);
  199. if (priv->buf == NULL) {
  200. kfree(priv);
  201. goto cleanup;
  202. }
  203. init_waitqueue_head(&priv->delta_msr_wait);
  204. priv->type = type;
  205. usb_set_serial_port_data(serial->port[i], priv);
  206. }
  207. return 0;
  208. cleanup:
  209. for (--i; i>=0; --i) {
  210. priv = usb_get_serial_port_data(serial->port[i]);
  211. pl2303_buf_free(priv->buf);
  212. kfree(priv);
  213. usb_set_serial_port_data(serial->port[i], NULL);
  214. }
  215. return -ENOMEM;
  216. }
  217. static int set_control_lines (struct usb_device *dev, u8 value)
  218. {
  219. int retval;
  220. retval = usb_control_msg (dev, usb_sndctrlpipe (dev, 0),
  221. SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
  222. value, 0, NULL, 0, 100);
  223. dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval);
  224. return retval;
  225. }
  226. static int pl2303_write (struct usb_serial_port *port, const unsigned char *buf, int count)
  227. {
  228. struct pl2303_private *priv = usb_get_serial_port_data(port);
  229. unsigned long flags;
  230. dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
  231. if (!count)
  232. return count;
  233. spin_lock_irqsave(&priv->lock, flags);
  234. count = pl2303_buf_put(priv->buf, buf, count);
  235. spin_unlock_irqrestore(&priv->lock, flags);
  236. pl2303_send(port);
  237. return count;
  238. }
  239. static void pl2303_send(struct usb_serial_port *port)
  240. {
  241. int count, result;
  242. struct pl2303_private *priv = usb_get_serial_port_data(port);
  243. unsigned long flags;
  244. dbg("%s - port %d", __FUNCTION__, port->number);
  245. spin_lock_irqsave(&priv->lock, flags);
  246. if (priv->write_urb_in_use) {
  247. spin_unlock_irqrestore(&priv->lock, flags);
  248. return;
  249. }
  250. count = pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer,
  251. port->bulk_out_size);
  252. if (count == 0) {
  253. spin_unlock_irqrestore(&priv->lock, flags);
  254. return;
  255. }
  256. priv->write_urb_in_use = 1;
  257. spin_unlock_irqrestore(&priv->lock, flags);
  258. usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, port->write_urb->transfer_buffer);
  259. port->write_urb->transfer_buffer_length = count;
  260. port->write_urb->dev = port->serial->dev;
  261. result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
  262. if (result) {
  263. dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
  264. priv->write_urb_in_use = 0;
  265. // TODO: reschedule pl2303_send
  266. }
  267. schedule_work(&port->work);
  268. }
  269. static int pl2303_write_room(struct usb_serial_port *port)
  270. {
  271. struct pl2303_private *priv = usb_get_serial_port_data(port);
  272. int room = 0;
  273. unsigned long flags;
  274. dbg("%s - port %d", __FUNCTION__, port->number);
  275. spin_lock_irqsave(&priv->lock, flags);
  276. room = pl2303_buf_space_avail(priv->buf);
  277. spin_unlock_irqrestore(&priv->lock, flags);
  278. dbg("%s - returns %d", __FUNCTION__, room);
  279. return room;
  280. }
  281. static int pl2303_chars_in_buffer(struct usb_serial_port *port)
  282. {
  283. struct pl2303_private *priv = usb_get_serial_port_data(port);
  284. int chars = 0;
  285. unsigned long flags;
  286. dbg("%s - port %d", __FUNCTION__, port->number);
  287. spin_lock_irqsave(&priv->lock, flags);
  288. chars = pl2303_buf_data_avail(priv->buf);
  289. spin_unlock_irqrestore(&priv->lock, flags);
  290. dbg("%s - returns %d", __FUNCTION__, chars);
  291. return chars;
  292. }
  293. static void pl2303_set_termios (struct usb_serial_port *port, struct termios *old_termios)
  294. {
  295. struct usb_serial *serial = port->serial;
  296. struct pl2303_private *priv = usb_get_serial_port_data(port);
  297. unsigned long flags;
  298. unsigned int cflag;
  299. unsigned char *buf;
  300. int baud;
  301. int i;
  302. u8 control;
  303. dbg("%s - port %d", __FUNCTION__, port->number);
  304. if ((!port->tty) || (!port->tty->termios)) {
  305. dbg("%s - no tty structures", __FUNCTION__);
  306. return;
  307. }
  308. spin_lock_irqsave(&priv->lock, flags);
  309. if (!priv->termios_initialized) {
  310. *(port->tty->termios) = tty_std_termios;
  311. port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  312. priv->termios_initialized = 1;
  313. }
  314. spin_unlock_irqrestore(&priv->lock, flags);
  315. cflag = port->tty->termios->c_cflag;
  316. /* check that they really want us to change something */
  317. if (old_termios) {
  318. if ((cflag == old_termios->c_cflag) &&
  319. (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
  320. dbg("%s - nothing to change...", __FUNCTION__);
  321. return;
  322. }
  323. }
  324. buf = kmalloc (7, GFP_KERNEL);
  325. if (!buf) {
  326. dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
  327. return;
  328. }
  329. memset (buf, 0x00, 0x07);
  330. i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
  331. GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
  332. 0, 0, buf, 7, 100);
  333. dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
  334. buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
  335. if (cflag & CSIZE) {
  336. switch (cflag & CSIZE) {
  337. case CS5: buf[6] = 5; break;
  338. case CS6: buf[6] = 6; break;
  339. case CS7: buf[6] = 7; break;
  340. default:
  341. case CS8: buf[6] = 8; break;
  342. }
  343. dbg("%s - data bits = %d", __FUNCTION__, buf[6]);
  344. }
  345. baud = 0;
  346. switch (cflag & CBAUD) {
  347. case B0: baud = 0; break;
  348. case B75: baud = 75; break;
  349. case B150: baud = 150; break;
  350. case B300: baud = 300; break;
  351. case B600: baud = 600; break;
  352. case B1200: baud = 1200; break;
  353. case B1800: baud = 1800; break;
  354. case B2400: baud = 2400; break;
  355. case B4800: baud = 4800; break;
  356. case B9600: baud = 9600; break;
  357. case B19200: baud = 19200; break;
  358. case B38400: baud = 38400; break;
  359. case B57600: baud = 57600; break;
  360. case B115200: baud = 115200; break;
  361. case B230400: baud = 230400; break;
  362. case B460800: baud = 460800; break;
  363. default:
  364. dev_err(&port->dev, "pl2303 driver does not support the baudrate requested (fix it)\n");
  365. break;
  366. }
  367. dbg("%s - baud = %d", __FUNCTION__, baud);
  368. if (baud) {
  369. buf[0] = baud & 0xff;
  370. buf[1] = (baud >> 8) & 0xff;
  371. buf[2] = (baud >> 16) & 0xff;
  372. buf[3] = (baud >> 24) & 0xff;
  373. }
  374. /* For reference buf[4]=0 is 1 stop bits */
  375. /* For reference buf[4]=1 is 1.5 stop bits */
  376. /* For reference buf[4]=2 is 2 stop bits */
  377. if (cflag & CSTOPB) {
  378. buf[4] = 2;
  379. dbg("%s - stop bits = 2", __FUNCTION__);
  380. } else {
  381. buf[4] = 0;
  382. dbg("%s - stop bits = 1", __FUNCTION__);
  383. }
  384. if (cflag & PARENB) {
  385. /* For reference buf[5]=0 is none parity */
  386. /* For reference buf[5]=1 is odd parity */
  387. /* For reference buf[5]=2 is even parity */
  388. /* For reference buf[5]=3 is mark parity */
  389. /* For reference buf[5]=4 is space parity */
  390. if (cflag & PARODD) {
  391. buf[5] = 1;
  392. dbg("%s - parity = odd", __FUNCTION__);
  393. } else {
  394. buf[5] = 2;
  395. dbg("%s - parity = even", __FUNCTION__);
  396. }
  397. } else {
  398. buf[5] = 0;
  399. dbg("%s - parity = none", __FUNCTION__);
  400. }
  401. i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
  402. SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE,
  403. 0, 0, buf, 7, 100);
  404. dbg ("0x21:0x20:0:0 %d", i);
  405. /* change control lines if we are switching to or from B0 */
  406. spin_lock_irqsave(&priv->lock, flags);
  407. control = priv->line_control;
  408. if ((cflag & CBAUD) == B0)
  409. priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
  410. else
  411. priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
  412. if (control != priv->line_control) {
  413. control = priv->line_control;
  414. spin_unlock_irqrestore(&priv->lock, flags);
  415. set_control_lines(serial->dev, control);
  416. } else {
  417. spin_unlock_irqrestore(&priv->lock, flags);
  418. }
  419. buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0;
  420. i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
  421. GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
  422. 0, 0, buf, 7, 100);
  423. dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
  424. buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
  425. if (cflag & CRTSCTS) {
  426. __u16 index;
  427. if (priv->type == HX)
  428. index = 0x61;
  429. else
  430. index = 0x41;
  431. i = usb_control_msg(serial->dev,
  432. usb_sndctrlpipe(serial->dev, 0),
  433. VENDOR_WRITE_REQUEST,
  434. VENDOR_WRITE_REQUEST_TYPE,
  435. 0x0, index, NULL, 0, 100);
  436. dbg ("0x40:0x1:0x0:0x%x %d", index, i);
  437. }
  438. kfree (buf);
  439. }
  440. static int pl2303_open (struct usb_serial_port *port, struct file *filp)
  441. {
  442. struct termios tmp_termios;
  443. struct usb_serial *serial = port->serial;
  444. struct pl2303_private *priv = usb_get_serial_port_data(port);
  445. unsigned char *buf;
  446. int result;
  447. dbg("%s - port %d", __FUNCTION__, port->number);
  448. if (priv->type != HX) {
  449. usb_clear_halt(serial->dev, port->write_urb->pipe);
  450. usb_clear_halt(serial->dev, port->read_urb->pipe);
  451. }
  452. buf = kmalloc(10, GFP_KERNEL);
  453. if (buf==NULL)
  454. return -ENOMEM;
  455. #define FISH(a,b,c,d) \
  456. result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0), \
  457. b, a, c, d, buf, 1, 100); \
  458. dbg("0x%x:0x%x:0x%x:0x%x %d - %x",a,b,c,d,result,buf[0]);
  459. #define SOUP(a,b,c,d) \
  460. result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), \
  461. b, a, c, d, NULL, 0, 100); \
  462. dbg("0x%x:0x%x:0x%x:0x%x %d",a,b,c,d,result);
  463. FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
  464. SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0);
  465. FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
  466. FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
  467. FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
  468. SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1);
  469. FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
  470. FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
  471. SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0, 1);
  472. SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 1, 0);
  473. if (priv->type == HX) {
  474. /* HX chip */
  475. SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 0x44);
  476. /* reset upstream data pipes */
  477. SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 8, 0);
  478. SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 9, 0);
  479. } else {
  480. SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 0x24);
  481. }
  482. kfree(buf);
  483. /* Setup termios */
  484. if (port->tty) {
  485. pl2303_set_termios (port, &tmp_termios);
  486. }
  487. //FIXME: need to assert RTS and DTR if CRTSCTS off
  488. dbg("%s - submitting read urb", __FUNCTION__);
  489. port->read_urb->dev = serial->dev;
  490. result = usb_submit_urb (port->read_urb, GFP_KERNEL);
  491. if (result) {
  492. dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result);
  493. pl2303_close (port, NULL);
  494. return -EPROTO;
  495. }
  496. dbg("%s - submitting interrupt urb", __FUNCTION__);
  497. port->interrupt_in_urb->dev = serial->dev;
  498. result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL);
  499. if (result) {
  500. dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", __FUNCTION__, result);
  501. pl2303_close (port, NULL);
  502. return -EPROTO;
  503. }
  504. return 0;
  505. }
  506. static void pl2303_close (struct usb_serial_port *port, struct file *filp)
  507. {
  508. struct pl2303_private *priv = usb_get_serial_port_data(port);
  509. unsigned long flags;
  510. unsigned int c_cflag;
  511. int bps;
  512. long timeout;
  513. wait_queue_t wait; \
  514. dbg("%s - port %d", __FUNCTION__, port->number);
  515. /* wait for data to drain from the buffer */
  516. spin_lock_irqsave(&priv->lock, flags);
  517. timeout = PL2303_CLOSING_WAIT;
  518. init_waitqueue_entry(&wait, current);
  519. add_wait_queue(&port->tty->write_wait, &wait);
  520. for (;;) {
  521. set_current_state(TASK_INTERRUPTIBLE);
  522. if (pl2303_buf_data_avail(priv->buf) == 0
  523. || timeout == 0 || signal_pending(current)
  524. || !usb_get_intfdata(port->serial->interface)) /* disconnect */
  525. break;
  526. spin_unlock_irqrestore(&priv->lock, flags);
  527. timeout = schedule_timeout(timeout);
  528. spin_lock_irqsave(&priv->lock, flags);
  529. }
  530. set_current_state(TASK_RUNNING);
  531. remove_wait_queue(&port->tty->write_wait, &wait);
  532. /* clear out any remaining data in the buffer */
  533. pl2303_buf_clear(priv->buf);
  534. spin_unlock_irqrestore(&priv->lock, flags);
  535. /* wait for characters to drain from the device */
  536. /* (this is long enough for the entire 256 byte */
  537. /* pl2303 hardware buffer to drain with no flow */
  538. /* control for data rates of 1200 bps or more, */
  539. /* for lower rates we should really know how much */
  540. /* data is in the buffer to compute a delay */
  541. /* that is not unnecessarily long) */
  542. bps = tty_get_baud_rate(port->tty);
  543. if (bps > 1200)
  544. timeout = max((HZ*2560)/bps,HZ/10);
  545. else
  546. timeout = 2*HZ;
  547. schedule_timeout_interruptible(timeout);
  548. /* shutdown our urbs */
  549. dbg("%s - shutting down urbs", __FUNCTION__);
  550. usb_kill_urb(port->write_urb);
  551. usb_kill_urb(port->read_urb);
  552. usb_kill_urb(port->interrupt_in_urb);
  553. if (port->tty) {
  554. c_cflag = port->tty->termios->c_cflag;
  555. if (c_cflag & HUPCL) {
  556. /* drop DTR and RTS */
  557. spin_lock_irqsave(&priv->lock, flags);
  558. priv->line_control = 0;
  559. spin_unlock_irqrestore (&priv->lock, flags);
  560. set_control_lines (port->serial->dev, 0);
  561. }
  562. }
  563. }
  564. static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
  565. unsigned int set, unsigned int clear)
  566. {
  567. struct pl2303_private *priv = usb_get_serial_port_data(port);
  568. unsigned long flags;
  569. u8 control;
  570. if (!usb_get_intfdata(port->serial->interface))
  571. return -ENODEV;
  572. spin_lock_irqsave (&priv->lock, flags);
  573. if (set & TIOCM_RTS)
  574. priv->line_control |= CONTROL_RTS;
  575. if (set & TIOCM_DTR)
  576. priv->line_control |= CONTROL_DTR;
  577. if (clear & TIOCM_RTS)
  578. priv->line_control &= ~CONTROL_RTS;
  579. if (clear & TIOCM_DTR)
  580. priv->line_control &= ~CONTROL_DTR;
  581. control = priv->line_control;
  582. spin_unlock_irqrestore (&priv->lock, flags);
  583. return set_control_lines (port->serial->dev, control);
  584. }
  585. static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file)
  586. {
  587. struct pl2303_private *priv = usb_get_serial_port_data(port);
  588. unsigned long flags;
  589. unsigned int mcr;
  590. unsigned int status;
  591. unsigned int result;
  592. dbg("%s (%d)", __FUNCTION__, port->number);
  593. if (!usb_get_intfdata(port->serial->interface))
  594. return -ENODEV;
  595. spin_lock_irqsave (&priv->lock, flags);
  596. mcr = priv->line_control;
  597. status = priv->line_status;
  598. spin_unlock_irqrestore (&priv->lock, flags);
  599. result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0)
  600. | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0)
  601. | ((status & UART_CTS) ? TIOCM_CTS : 0)
  602. | ((status & UART_DSR) ? TIOCM_DSR : 0)
  603. | ((status & UART_RING) ? TIOCM_RI : 0)
  604. | ((status & UART_DCD) ? TIOCM_CD : 0);
  605. dbg("%s - result = %x", __FUNCTION__, result);
  606. return result;
  607. }
  608. static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
  609. {
  610. struct pl2303_private *priv = usb_get_serial_port_data(port);
  611. unsigned long flags;
  612. unsigned int prevstatus;
  613. unsigned int status;
  614. unsigned int changed;
  615. spin_lock_irqsave (&priv->lock, flags);
  616. prevstatus = priv->line_status;
  617. spin_unlock_irqrestore (&priv->lock, flags);
  618. while (1) {
  619. interruptible_sleep_on(&priv->delta_msr_wait);
  620. /* see if a signal did it */
  621. if (signal_pending(current))
  622. return -ERESTARTSYS;
  623. spin_lock_irqsave (&priv->lock, flags);
  624. status = priv->line_status;
  625. spin_unlock_irqrestore (&priv->lock, flags);
  626. changed=prevstatus^status;
  627. if (((arg & TIOCM_RNG) && (changed & UART_RING)) ||
  628. ((arg & TIOCM_DSR) && (changed & UART_DSR)) ||
  629. ((arg & TIOCM_CD) && (changed & UART_DCD)) ||
  630. ((arg & TIOCM_CTS) && (changed & UART_CTS)) ) {
  631. return 0;
  632. }
  633. prevstatus = status;
  634. }
  635. /* NOTREACHED */
  636. return 0;
  637. }
  638. static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
  639. {
  640. dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd);
  641. switch (cmd) {
  642. case TIOCMIWAIT:
  643. dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
  644. return wait_modem_info(port, arg);
  645. default:
  646. dbg("%s not supported = 0x%04x", __FUNCTION__, cmd);
  647. break;
  648. }
  649. return -ENOIOCTLCMD;
  650. }
  651. static void pl2303_break_ctl (struct usb_serial_port *port, int break_state)
  652. {
  653. struct usb_serial *serial = port->serial;
  654. u16 state;
  655. int result;
  656. dbg("%s - port %d", __FUNCTION__, port->number);
  657. if (break_state == 0)
  658. state = BREAK_OFF;
  659. else
  660. state = BREAK_ON;
  661. dbg("%s - turning break %s", __FUNCTION__, state==BREAK_OFF ? "off" : "on");
  662. result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
  663. BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
  664. 0, NULL, 0, 100);
  665. if (result)
  666. dbg("%s - error sending break = %d", __FUNCTION__, result);
  667. }
  668. static void pl2303_shutdown (struct usb_serial *serial)
  669. {
  670. int i;
  671. struct pl2303_private *priv;
  672. dbg("%s", __FUNCTION__);
  673. for (i = 0; i < serial->num_ports; ++i) {
  674. priv = usb_get_serial_port_data(serial->port[i]);
  675. if (priv) {
  676. pl2303_buf_free(priv->buf);
  677. kfree(priv);
  678. usb_set_serial_port_data(serial->port[i], NULL);
  679. }
  680. }
  681. }
  682. static void pl2303_update_line_status(struct usb_serial_port *port,
  683. unsigned char *data,
  684. unsigned int actual_length)
  685. {
  686. struct pl2303_private *priv = usb_get_serial_port_data(port);
  687. unsigned long flags;
  688. u8 status_idx = UART_STATE;
  689. u8 length = UART_STATE + 1;
  690. if ((le16_to_cpu(port->serial->dev->descriptor.idVendor) == SIEMENS_VENDOR_ID) &&
  691. (le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_X65 ||
  692. le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_SX1 ||
  693. le16_to_cpu(port->serial->dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_X75)) {
  694. length = 1;
  695. status_idx = 0;
  696. }
  697. if (actual_length < length)
  698. goto exit;
  699. /* Save off the uart status for others to look at */
  700. spin_lock_irqsave(&priv->lock, flags);
  701. priv->line_status = data[status_idx];
  702. spin_unlock_irqrestore(&priv->lock, flags);
  703. exit:
  704. return;
  705. }
  706. static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs)
  707. {
  708. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  709. unsigned char *data = urb->transfer_buffer;
  710. unsigned int actual_length = urb->actual_length;
  711. int status;
  712. dbg("%s (%d)", __FUNCTION__, port->number);
  713. switch (urb->status) {
  714. case 0:
  715. /* success */
  716. break;
  717. case -ECONNRESET:
  718. case -ENOENT:
  719. case -ESHUTDOWN:
  720. /* this urb is terminated, clean up */
  721. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  722. return;
  723. default:
  724. dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
  725. goto exit;
  726. }
  727. usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, urb->transfer_buffer);
  728. pl2303_update_line_status(port, data, actual_length);
  729. exit:
  730. status = usb_submit_urb (urb, GFP_ATOMIC);
  731. if (status)
  732. dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
  733. __FUNCTION__, status);
  734. }
  735. static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
  736. {
  737. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  738. struct pl2303_private *priv = usb_get_serial_port_data(port);
  739. struct tty_struct *tty;
  740. unsigned char *data = urb->transfer_buffer;
  741. unsigned long flags;
  742. int i;
  743. int result;
  744. u8 status;
  745. char tty_flag;
  746. dbg("%s - port %d", __FUNCTION__, port->number);
  747. if (urb->status) {
  748. dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
  749. if (!port->open_count) {
  750. dbg("%s - port is closed, exiting.", __FUNCTION__);
  751. return;
  752. }
  753. if (urb->status == -EPROTO) {
  754. /* PL2303 mysteriously fails with -EPROTO reschedule the read */
  755. dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__);
  756. urb->status = 0;
  757. urb->dev = port->serial->dev;
  758. result = usb_submit_urb(urb, GFP_ATOMIC);
  759. if (result)
  760. dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
  761. return;
  762. }
  763. dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
  764. return;
  765. }
  766. usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
  767. /* get tty_flag from status */
  768. tty_flag = TTY_NORMAL;
  769. spin_lock_irqsave(&priv->lock, flags);
  770. status = priv->line_status;
  771. priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
  772. spin_unlock_irqrestore(&priv->lock, flags);
  773. wake_up_interruptible (&priv->delta_msr_wait);
  774. /* break takes precedence over parity, */
  775. /* which takes precedence over framing errors */
  776. if (status & UART_BREAK_ERROR )
  777. tty_flag = TTY_BREAK;
  778. else if (status & UART_PARITY_ERROR)
  779. tty_flag = TTY_PARITY;
  780. else if (status & UART_FRAME_ERROR)
  781. tty_flag = TTY_FRAME;
  782. dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag);
  783. tty = port->tty;
  784. if (tty && urb->actual_length) {
  785. tty_buffer_request_room(tty, urb->actual_length + 1);
  786. /* overrun is special, not associated with a char */
  787. if (status & UART_OVERRUN_ERROR)
  788. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  789. for (i = 0; i < urb->actual_length; ++i)
  790. tty_insert_flip_char (tty, data[i], tty_flag);
  791. tty_flip_buffer_push (tty);
  792. }
  793. /* Schedule the next read _if_ we are still open */
  794. if (port->open_count) {
  795. urb->dev = port->serial->dev;
  796. result = usb_submit_urb(urb, GFP_ATOMIC);
  797. if (result)
  798. dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
  799. }
  800. return;
  801. }
  802. static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
  803. {
  804. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  805. struct pl2303_private *priv = usb_get_serial_port_data(port);
  806. int result;
  807. dbg("%s - port %d", __FUNCTION__, port->number);
  808. switch (urb->status) {
  809. case 0:
  810. /* success */
  811. break;
  812. case -ECONNRESET:
  813. case -ENOENT:
  814. case -ESHUTDOWN:
  815. /* this urb is terminated, clean up */
  816. dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
  817. priv->write_urb_in_use = 0;
  818. return;
  819. default:
  820. /* error in the urb, so we have to resubmit it */
  821. dbg("%s - Overflow in write", __FUNCTION__);
  822. dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
  823. port->write_urb->transfer_buffer_length = 1;
  824. port->write_urb->dev = port->serial->dev;
  825. result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
  826. if (result)
  827. dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", __FUNCTION__, result);
  828. else
  829. return;
  830. }
  831. priv->write_urb_in_use = 0;
  832. /* send any buffered data */
  833. pl2303_send(port);
  834. }
  835. /*
  836. * pl2303_buf_alloc
  837. *
  838. * Allocate a circular buffer and all associated memory.
  839. */
  840. static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
  841. {
  842. struct pl2303_buf *pb;
  843. if (size == 0)
  844. return NULL;
  845. pb = (struct pl2303_buf *)kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
  846. if (pb == NULL)
  847. return NULL;
  848. pb->buf_buf = kmalloc(size, GFP_KERNEL);
  849. if (pb->buf_buf == NULL) {
  850. kfree(pb);
  851. return NULL;
  852. }
  853. pb->buf_size = size;
  854. pb->buf_get = pb->buf_put = pb->buf_buf;
  855. return pb;
  856. }
  857. /*
  858. * pl2303_buf_free
  859. *
  860. * Free the buffer and all associated memory.
  861. */
  862. static void pl2303_buf_free(struct pl2303_buf *pb)
  863. {
  864. if (pb) {
  865. kfree(pb->buf_buf);
  866. kfree(pb);
  867. }
  868. }
  869. /*
  870. * pl2303_buf_clear
  871. *
  872. * Clear out all data in the circular buffer.
  873. */
  874. static void pl2303_buf_clear(struct pl2303_buf *pb)
  875. {
  876. if (pb != NULL)
  877. pb->buf_get = pb->buf_put;
  878. /* equivalent to a get of all data available */
  879. }
  880. /*
  881. * pl2303_buf_data_avail
  882. *
  883. * Return the number of bytes of data available in the circular
  884. * buffer.
  885. */
  886. static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
  887. {
  888. if (pb != NULL)
  889. return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size);
  890. else
  891. return 0;
  892. }
  893. /*
  894. * pl2303_buf_space_avail
  895. *
  896. * Return the number of bytes of space available in the circular
  897. * buffer.
  898. */
  899. static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
  900. {
  901. if (pb != NULL)
  902. return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size);
  903. else
  904. return 0;
  905. }
  906. /*
  907. * pl2303_buf_put
  908. *
  909. * Copy data data from a user buffer and put it into the circular buffer.
  910. * Restrict to the amount of space available.
  911. *
  912. * Return the number of bytes copied.
  913. */
  914. static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
  915. unsigned int count)
  916. {
  917. unsigned int len;
  918. if (pb == NULL)
  919. return 0;
  920. len = pl2303_buf_space_avail(pb);
  921. if (count > len)
  922. count = len;
  923. if (count == 0)
  924. return 0;
  925. len = pb->buf_buf + pb->buf_size - pb->buf_put;
  926. if (count > len) {
  927. memcpy(pb->buf_put, buf, len);
  928. memcpy(pb->buf_buf, buf+len, count - len);
  929. pb->buf_put = pb->buf_buf + count - len;
  930. } else {
  931. memcpy(pb->buf_put, buf, count);
  932. if (count < len)
  933. pb->buf_put += count;
  934. else /* count == len */
  935. pb->buf_put = pb->buf_buf;
  936. }
  937. return count;
  938. }
  939. /*
  940. * pl2303_buf_get
  941. *
  942. * Get data from the circular buffer and copy to the given buffer.
  943. * Restrict to the amount of data available.
  944. *
  945. * Return the number of bytes copied.
  946. */
  947. static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
  948. unsigned int count)
  949. {
  950. unsigned int len;
  951. if (pb == NULL)
  952. return 0;
  953. len = pl2303_buf_data_avail(pb);
  954. if (count > len)
  955. count = len;
  956. if (count == 0)
  957. return 0;
  958. len = pb->buf_buf + pb->buf_size - pb->buf_get;
  959. if (count > len) {
  960. memcpy(buf, pb->buf_get, len);
  961. memcpy(buf+len, pb->buf_buf, count - len);
  962. pb->buf_get = pb->buf_buf + count - len;
  963. } else {
  964. memcpy(buf, pb->buf_get, count);
  965. if (count < len)
  966. pb->buf_get += count;
  967. else /* count == len */
  968. pb->buf_get = pb->buf_buf;
  969. }
  970. return count;
  971. }
  972. static int __init pl2303_init (void)
  973. {
  974. int retval;
  975. retval = usb_serial_register(&pl2303_device);
  976. if (retval)
  977. goto failed_usb_serial_register;
  978. retval = usb_register(&pl2303_driver);
  979. if (retval)
  980. goto failed_usb_register;
  981. info(DRIVER_DESC);
  982. return 0;
  983. failed_usb_register:
  984. usb_serial_deregister(&pl2303_device);
  985. failed_usb_serial_register:
  986. return retval;
  987. }
  988. static void __exit pl2303_exit (void)
  989. {
  990. usb_deregister (&pl2303_driver);
  991. usb_serial_deregister (&pl2303_device);
  992. }
  993. module_init(pl2303_init);
  994. module_exit(pl2303_exit);
  995. MODULE_DESCRIPTION(DRIVER_DESC);
  996. MODULE_LICENSE("GPL");
  997. module_param(debug, bool, S_IRUGO | S_IWUSR);
  998. MODULE_PARM_DESC(debug, "Debug enabled or not");