pl2303.c 32 KB

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