pl2303.c 32 KB

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