pl2303.c 32 KB

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