pl2303.c 32 KB

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