option.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /*
  2. Option Card (PCMCIA to) USB to Serial Driver
  3. Copyright (C) 2005 Matthias Urlichs <smurf@smurf.noris.de>
  4. This driver is free software; you can redistribute it and/or modify
  5. it under the terms of Version 2 of the GNU General Public License as
  6. published by the Free Software Foundation.
  7. Portions copied from the Keyspan driver by Hugh Blemings <hugh@blemings.org>
  8. History:
  9. 2005-05-19 v0.1 Initial version, based on incomplete docs
  10. and analysis of misbehavior with the standard driver
  11. 2005-05-20 v0.2 Extended the input buffer to avoid losing
  12. random 64-byte chunks of data
  13. 2005-05-21 v0.3 implemented chars_in_buffer()
  14. turned on low_latency
  15. simplified the code somewhat
  16. 2005-05-24 v0.4 option_write() sometimes deadlocked under heavy load
  17. removed some dead code
  18. added sponsor notice
  19. coding style clean-up
  20. 2005-06-20 v0.4.1 add missing braces :-/
  21. killed end-of-line whitespace
  22. 2005-07-15 v0.4.2 rename WLAN product to FUSION, add FUSION2
  23. Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
  24. */
  25. #define DRIVER_VERSION "v0.4"
  26. #define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
  27. #define DRIVER_DESC "Option Card (PC-Card to) USB to Serial Driver"
  28. #include <linux/config.h>
  29. #include <linux/kernel.h>
  30. #include <linux/jiffies.h>
  31. #include <linux/errno.h>
  32. #include <linux/tty.h>
  33. #include <linux/tty_flip.h>
  34. #include <linux/module.h>
  35. #include <linux/usb.h>
  36. #include "usb-serial.h"
  37. /* Function prototypes */
  38. static int option_open (struct usb_serial_port *port, struct file *filp);
  39. static void option_close (struct usb_serial_port *port, struct file *filp);
  40. static int option_startup (struct usb_serial *serial);
  41. static void option_shutdown (struct usb_serial *serial);
  42. static void option_rx_throttle (struct usb_serial_port *port);
  43. static void option_rx_unthrottle (struct usb_serial_port *port);
  44. static int option_write_room (struct usb_serial_port *port);
  45. static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
  46. static int option_write (struct usb_serial_port *port,
  47. const unsigned char *buf, int count);
  48. static int option_chars_in_buffer (struct usb_serial_port *port);
  49. static int option_ioctl (struct usb_serial_port *port, struct file *file,
  50. unsigned int cmd, unsigned long arg);
  51. static void option_set_termios (struct usb_serial_port *port,
  52. struct termios *old);
  53. static void option_break_ctl (struct usb_serial_port *port, int break_state);
  54. static int option_tiocmget (struct usb_serial_port *port, struct file *file);
  55. static int option_tiocmset (struct usb_serial_port *port, struct file *file,
  56. unsigned int set, unsigned int clear);
  57. static int option_send_setup (struct usb_serial_port *port);
  58. /* Vendor and product IDs */
  59. #define OPTION_VENDOR_ID 0x0AF0
  60. #define OPTION_PRODUCT_OLD 0x5000
  61. #define OPTION_PRODUCT_FUSION 0x6000
  62. #define OPTION_PRODUCT_FUSION2 0x6300
  63. static struct usb_device_id option_ids[] = {
  64. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
  65. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
  66. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
  67. { } /* Terminating entry */
  68. };
  69. MODULE_DEVICE_TABLE(usb, option_ids);
  70. static struct usb_driver option_driver = {
  71. .owner = THIS_MODULE,
  72. .name = "option",
  73. .probe = usb_serial_probe,
  74. .disconnect = usb_serial_disconnect,
  75. .id_table = option_ids,
  76. };
  77. /* The card has three separate interfaces, wich the serial driver
  78. * recognizes separately, thus num_port=1.
  79. */
  80. static struct usb_serial_device_type option_3port_device = {
  81. .owner = THIS_MODULE,
  82. .name = "Option 3G data card",
  83. .short_name = "option",
  84. .id_table = option_ids,
  85. .num_interrupt_in = NUM_DONT_CARE,
  86. .num_bulk_in = NUM_DONT_CARE,
  87. .num_bulk_out = NUM_DONT_CARE,
  88. .num_ports = 1, /* 3, but the card reports its ports separately */
  89. .open = option_open,
  90. .close = option_close,
  91. .write = option_write,
  92. .write_room = option_write_room,
  93. .chars_in_buffer = option_chars_in_buffer,
  94. .throttle = option_rx_throttle,
  95. .unthrottle = option_rx_unthrottle,
  96. .ioctl = option_ioctl,
  97. .set_termios = option_set_termios,
  98. .break_ctl = option_break_ctl,
  99. .tiocmget = option_tiocmget,
  100. .tiocmset = option_tiocmset,
  101. .attach = option_startup,
  102. .shutdown = option_shutdown,
  103. .read_int_callback = option_instat_callback,
  104. };
  105. #ifdef CONFIG_USB_DEBUG
  106. static int debug;
  107. #else
  108. #define debug 0
  109. #endif
  110. /* per port private data */
  111. #define N_IN_URB 4
  112. #define N_OUT_URB 1
  113. #define IN_BUFLEN 1024
  114. #define OUT_BUFLEN 128
  115. struct option_port_private {
  116. /* Input endpoints and buffer for this port */
  117. struct urb *in_urbs[N_IN_URB];
  118. char in_buffer[N_IN_URB][IN_BUFLEN];
  119. /* Output endpoints and buffer for this port */
  120. struct urb *out_urbs[N_OUT_URB];
  121. char out_buffer[N_OUT_URB][OUT_BUFLEN];
  122. /* Settings for the port */
  123. int rts_state; /* Handshaking pins (outputs) */
  124. int dtr_state;
  125. int cts_state; /* Handshaking pins (inputs) */
  126. int dsr_state;
  127. int dcd_state;
  128. int ri_state;
  129. unsigned long tx_start_time[N_OUT_URB];
  130. };
  131. /* Functions used by new usb-serial code. */
  132. static int __init
  133. option_init (void)
  134. {
  135. int retval;
  136. retval = usb_serial_register(&option_3port_device);
  137. if (retval)
  138. goto failed_3port_device_register;
  139. retval = usb_register(&option_driver);
  140. if (retval)
  141. goto failed_driver_register;
  142. info(DRIVER_DESC ": " DRIVER_VERSION);
  143. return 0;
  144. failed_driver_register:
  145. usb_serial_deregister (&option_3port_device);
  146. failed_3port_device_register:
  147. return retval;
  148. }
  149. static void __exit
  150. option_exit (void)
  151. {
  152. usb_deregister (&option_driver);
  153. usb_serial_deregister (&option_3port_device);
  154. }
  155. module_init(option_init);
  156. module_exit(option_exit);
  157. static void
  158. option_rx_throttle (struct usb_serial_port *port)
  159. {
  160. dbg("%s", __FUNCTION__);
  161. }
  162. static void
  163. option_rx_unthrottle (struct usb_serial_port *port)
  164. {
  165. dbg("%s", __FUNCTION__);
  166. }
  167. static void
  168. option_break_ctl (struct usb_serial_port *port, int break_state)
  169. {
  170. /* Unfortunately, I don't know how to send a break */
  171. dbg("%s", __FUNCTION__);
  172. }
  173. static void
  174. option_set_termios (struct usb_serial_port *port,
  175. struct termios *old_termios)
  176. {
  177. dbg("%s", __FUNCTION__);
  178. option_send_setup(port);
  179. }
  180. static int
  181. option_tiocmget (struct usb_serial_port *port, struct file *file)
  182. {
  183. unsigned int value;
  184. struct option_port_private *portdata;
  185. portdata = usb_get_serial_port_data(port);
  186. value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
  187. ((portdata->dtr_state) ? TIOCM_DTR : 0) |
  188. ((portdata->cts_state) ? TIOCM_CTS : 0) |
  189. ((portdata->dsr_state) ? TIOCM_DSR : 0) |
  190. ((portdata->dcd_state) ? TIOCM_CAR : 0) |
  191. ((portdata->ri_state) ? TIOCM_RNG : 0);
  192. return value;
  193. }
  194. static int
  195. option_tiocmset (struct usb_serial_port *port, struct file *file,
  196. unsigned int set, unsigned int clear)
  197. {
  198. struct option_port_private *portdata;
  199. portdata = usb_get_serial_port_data(port);
  200. if (set & TIOCM_RTS)
  201. portdata->rts_state = 1;
  202. if (set & TIOCM_DTR)
  203. portdata->dtr_state = 1;
  204. if (clear & TIOCM_RTS)
  205. portdata->rts_state = 0;
  206. if (clear & TIOCM_DTR)
  207. portdata->dtr_state = 0;
  208. return option_send_setup(port);
  209. }
  210. static int
  211. option_ioctl (struct usb_serial_port *port, struct file *file,
  212. unsigned int cmd, unsigned long arg)
  213. {
  214. return -ENOIOCTLCMD;
  215. }
  216. /* Write */
  217. static int
  218. option_write (struct usb_serial_port *port,
  219. const unsigned char *buf, int count)
  220. {
  221. struct option_port_private *portdata;
  222. int i;
  223. int left, todo;
  224. struct urb *this_urb = NULL; /* spurious */
  225. int err;
  226. portdata = usb_get_serial_port_data(port);
  227. dbg("%s: write (%d chars)", __FUNCTION__, count);
  228. i = 0;
  229. left = count;
  230. for (i=0; left > 0 && i < N_OUT_URB; i++) {
  231. todo = left;
  232. if (todo > OUT_BUFLEN)
  233. todo = OUT_BUFLEN;
  234. this_urb = portdata->out_urbs[i];
  235. if (this_urb->status == -EINPROGRESS) {
  236. if (this_urb->transfer_flags & URB_ASYNC_UNLINK)
  237. continue;
  238. if (time_before(jiffies, portdata->tx_start_time[i] + 10 * HZ))
  239. continue;
  240. this_urb->transfer_flags |= URB_ASYNC_UNLINK;
  241. usb_unlink_urb(this_urb);
  242. continue;
  243. }
  244. if (this_urb->status != 0)
  245. dbg("usb_write %p failed (err=%d)", this_urb, this_urb->status);
  246. dbg("%s: endpoint %d buf %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), i);
  247. /* send the data */
  248. memcpy (this_urb->transfer_buffer, buf, todo);
  249. this_urb->transfer_buffer_length = todo;
  250. this_urb->transfer_flags &= ~URB_ASYNC_UNLINK;
  251. this_urb->dev = port->serial->dev;
  252. err = usb_submit_urb(this_urb, GFP_ATOMIC);
  253. if (err) {
  254. dbg("usb_submit_urb %p (write bulk) failed (%d, has %d)", this_urb, err, this_urb->status);
  255. continue;
  256. }
  257. portdata->tx_start_time[i] = jiffies;
  258. buf += todo;
  259. left -= todo;
  260. }
  261. count -= left;
  262. dbg("%s: wrote (did %d)", __FUNCTION__, count);
  263. return count;
  264. }
  265. static void
  266. option_indat_callback (struct urb *urb, struct pt_regs *regs)
  267. {
  268. int i, err;
  269. int endpoint;
  270. struct usb_serial_port *port;
  271. struct tty_struct *tty;
  272. unsigned char *data = urb->transfer_buffer;
  273. dbg("%s: %p", __FUNCTION__, urb);
  274. endpoint = usb_pipeendpoint(urb->pipe);
  275. port = (struct usb_serial_port *) urb->context;
  276. if (urb->status) {
  277. dbg("%s: nonzero status: %d on endpoint %02x.",
  278. __FUNCTION__, urb->status, endpoint);
  279. } else {
  280. tty = port->tty;
  281. if (urb->actual_length) {
  282. for (i = 0; i < urb->actual_length ; ++i) {
  283. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  284. tty_flip_buffer_push(tty);
  285. tty_insert_flip_char(tty, data[i], 0);
  286. }
  287. tty_flip_buffer_push(tty);
  288. } else {
  289. dbg("%s: empty read urb received", __FUNCTION__);
  290. }
  291. /* Resubmit urb so we continue receiving */
  292. if (port->open_count && urb->status != -ESHUTDOWN) {
  293. err = usb_submit_urb(urb, GFP_ATOMIC);
  294. if (err)
  295. printk(KERN_ERR "%s: resubmit read urb failed. (%d)", __FUNCTION__, err);
  296. }
  297. }
  298. return;
  299. }
  300. static void
  301. option_outdat_callback (struct urb *urb, struct pt_regs *regs)
  302. {
  303. struct usb_serial_port *port;
  304. dbg("%s", __FUNCTION__);
  305. port = (struct usb_serial_port *) urb->context;
  306. if (port->open_count)
  307. schedule_work(&port->work);
  308. }
  309. static void
  310. option_instat_callback (struct urb *urb, struct pt_regs *regs)
  311. {
  312. int err;
  313. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  314. struct option_port_private *portdata = usb_get_serial_port_data(port);
  315. struct usb_serial *serial = port->serial;
  316. dbg("%s", __FUNCTION__);
  317. dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
  318. if (urb->status == 0) {
  319. struct usb_ctrlrequest *req_pkt =
  320. (struct usb_ctrlrequest *)urb->transfer_buffer;
  321. if (!req_pkt) {
  322. dbg("%s: NULL req_pkt\n", __FUNCTION__);
  323. return;
  324. }
  325. if ((req_pkt->bRequestType == 0xA1) && (req_pkt->bRequest == 0x20)) {
  326. int old_dcd_state;
  327. unsigned char signals = *((unsigned char *)
  328. urb->transfer_buffer + sizeof(struct usb_ctrlrequest));
  329. dbg("%s: signal x%x", __FUNCTION__, signals);
  330. old_dcd_state = portdata->dcd_state;
  331. portdata->cts_state = 1;
  332. portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
  333. portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
  334. portdata->ri_state = ((signals & 0x08) ? 1 : 0);
  335. if (port->tty && !C_CLOCAL(port->tty)
  336. && old_dcd_state && !portdata->dcd_state) {
  337. tty_hangup(port->tty);
  338. }
  339. } else
  340. dbg("%s: type %x req %x", __FUNCTION__, req_pkt->bRequestType,req_pkt->bRequest);
  341. } else
  342. dbg("%s: error %d", __FUNCTION__, urb->status);
  343. /* Resubmit urb so we continue receiving IRQ data */
  344. if (urb->status != -ESHUTDOWN) {
  345. urb->dev = serial->dev;
  346. err = usb_submit_urb(urb, GFP_ATOMIC);
  347. if (err)
  348. dbg("%s: resubmit intr urb failed. (%d)", __FUNCTION__, err);
  349. }
  350. }
  351. static int
  352. option_write_room (struct usb_serial_port *port)
  353. {
  354. struct option_port_private *portdata;
  355. int i;
  356. int data_len = 0;
  357. struct urb *this_urb;
  358. portdata = usb_get_serial_port_data(port);
  359. for (i=0; i < N_OUT_URB; i++) {
  360. this_urb = portdata->out_urbs[i];
  361. if (this_urb && this_urb->status != -EINPROGRESS)
  362. data_len += OUT_BUFLEN;
  363. }
  364. dbg("%s: %d", __FUNCTION__, data_len);
  365. return data_len;
  366. }
  367. static int
  368. option_chars_in_buffer (struct usb_serial_port *port)
  369. {
  370. struct option_port_private *portdata;
  371. int i;
  372. int data_len = 0;
  373. struct urb *this_urb;
  374. portdata = usb_get_serial_port_data(port);
  375. for (i=0; i < N_OUT_URB; i++) {
  376. this_urb = portdata->out_urbs[i];
  377. if (this_urb && this_urb->status == -EINPROGRESS)
  378. data_len += this_urb->transfer_buffer_length;
  379. }
  380. dbg("%s: %d", __FUNCTION__, data_len);
  381. return data_len;
  382. }
  383. static int
  384. option_open (struct usb_serial_port *port, struct file *filp)
  385. {
  386. struct option_port_private *portdata;
  387. struct usb_serial *serial = port->serial;
  388. int i, err;
  389. struct urb *urb;
  390. portdata = usb_get_serial_port_data(port);
  391. dbg("%s", __FUNCTION__);
  392. /* Set some sane defaults */
  393. portdata->rts_state = 1;
  394. portdata->dtr_state = 1;
  395. /* Reset low level data toggle and start reading from endpoints */
  396. for (i = 0; i < N_IN_URB; i++) {
  397. urb = portdata->in_urbs[i];
  398. if (! urb)
  399. continue;
  400. if (urb->dev != serial->dev) {
  401. dbg("%s: dev %p != %p", __FUNCTION__, urb->dev, serial->dev);
  402. continue;
  403. }
  404. /* make sure endpoint data toggle is synchronized with the device */
  405. usb_clear_halt(urb->dev, urb->pipe);
  406. err = usb_submit_urb(urb, GFP_KERNEL);
  407. if (err) {
  408. dbg("%s: submit urb %d failed (%d) %d", __FUNCTION__, i, err,
  409. urb->transfer_buffer_length);
  410. }
  411. }
  412. /* Reset low level data toggle on out endpoints */
  413. for (i = 0; i < N_OUT_URB; i++) {
  414. urb = portdata->out_urbs[i];
  415. if (! urb)
  416. continue;
  417. urb->dev = serial->dev;
  418. /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */
  419. }
  420. port->tty->low_latency = 1;
  421. option_send_setup(port);
  422. return (0);
  423. }
  424. static inline void
  425. stop_urb (struct urb *urb)
  426. {
  427. if (urb && urb->status == -EINPROGRESS) {
  428. urb->transfer_flags &= ~URB_ASYNC_UNLINK;
  429. usb_kill_urb(urb);
  430. }
  431. }
  432. static void
  433. option_close (struct usb_serial_port *port, struct file *filp)
  434. {
  435. int i;
  436. struct usb_serial *serial = port->serial;
  437. struct option_port_private *portdata;
  438. dbg("%s", __FUNCTION__);
  439. portdata = usb_get_serial_port_data(port);
  440. portdata->rts_state = 0;
  441. portdata->dtr_state = 0;
  442. if (serial->dev) {
  443. option_send_setup(port);
  444. /* Stop reading/writing urbs */
  445. for (i = 0; i < N_IN_URB; i++)
  446. stop_urb(portdata->in_urbs[i]);
  447. for (i = 0; i < N_OUT_URB; i++)
  448. stop_urb(portdata->out_urbs[i]);
  449. }
  450. port->tty = NULL;
  451. }
  452. /* Helper functions used by option_setup_urbs */
  453. static struct urb *
  454. option_setup_urb (struct usb_serial *serial, int endpoint,
  455. int dir, void *ctx, char *buf, int len,
  456. void (*callback)(struct urb *, struct pt_regs *regs))
  457. {
  458. struct urb *urb;
  459. if (endpoint == -1)
  460. return NULL; /* endpoint not needed */
  461. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  462. if (urb == NULL) {
  463. dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
  464. return NULL;
  465. }
  466. /* Fill URB using supplied data. */
  467. usb_fill_bulk_urb(urb, serial->dev,
  468. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  469. buf, len, callback, ctx);
  470. return urb;
  471. }
  472. /* Setup urbs */
  473. static void
  474. option_setup_urbs (struct usb_serial *serial)
  475. {
  476. int j;
  477. struct usb_serial_port *port;
  478. struct option_port_private *portdata;
  479. dbg("%s", __FUNCTION__);
  480. port = serial->port[0];
  481. portdata = usb_get_serial_port_data(port);
  482. /* Do indat endpoints first */
  483. for (j = 0; j <= N_IN_URB; ++j) {
  484. portdata->in_urbs[j] = option_setup_urb (serial,
  485. port->bulk_in_endpointAddress, USB_DIR_IN, port,
  486. portdata->in_buffer[j], IN_BUFLEN, option_indat_callback);
  487. }
  488. /* outdat endpoints */
  489. for (j = 0; j <= N_OUT_URB; ++j) {
  490. portdata->out_urbs[j] = option_setup_urb (serial,
  491. port->bulk_out_endpointAddress, USB_DIR_OUT, port,
  492. portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback);
  493. }
  494. }
  495. static int
  496. option_send_setup (struct usb_serial_port *port)
  497. {
  498. struct usb_serial *serial = port->serial;
  499. struct option_port_private *portdata;
  500. dbg("%s", __FUNCTION__);
  501. portdata = usb_get_serial_port_data(port);
  502. if (port->tty) {
  503. int val = 0;
  504. if (portdata->dtr_state)
  505. val |= 0x01;
  506. if (portdata->rts_state)
  507. val |= 0x02;
  508. return usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  509. 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
  510. }
  511. return 0;
  512. }
  513. static int
  514. option_startup (struct usb_serial *serial)
  515. {
  516. int i, err;
  517. struct usb_serial_port *port;
  518. struct option_port_private *portdata;
  519. dbg("%s", __FUNCTION__);
  520. /* Now setup per port private data */
  521. for (i = 0; i < serial->num_ports; i++) {
  522. port = serial->port[i];
  523. portdata = kmalloc(sizeof(struct option_port_private), GFP_KERNEL);
  524. if (!portdata) {
  525. dbg("%s: kmalloc for option_port_private (%d) failed!.", __FUNCTION__, i);
  526. return (1);
  527. }
  528. memset(portdata, 0, sizeof(struct option_port_private));
  529. usb_set_serial_port_data(port, portdata);
  530. if (! port->interrupt_in_urb)
  531. continue;
  532. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  533. if (err)
  534. dbg("%s: submit irq_in urb failed %d", __FUNCTION__, err);
  535. }
  536. option_setup_urbs(serial);
  537. return (0);
  538. }
  539. static void
  540. option_shutdown (struct usb_serial *serial)
  541. {
  542. int i, j;
  543. struct usb_serial_port *port;
  544. struct option_port_private *portdata;
  545. dbg("%s", __FUNCTION__);
  546. /* Stop reading/writing urbs */
  547. for (i = 0; i < serial->num_ports; ++i) {
  548. port = serial->port[i];
  549. portdata = usb_get_serial_port_data(port);
  550. for (j = 0; j < N_IN_URB; j++)
  551. stop_urb(portdata->in_urbs[j]);
  552. for (j = 0; j < N_OUT_URB; j++)
  553. stop_urb(portdata->out_urbs[j]);
  554. }
  555. /* Now free them */
  556. for (i = 0; i < serial->num_ports; ++i) {
  557. port = serial->port[i];
  558. portdata = usb_get_serial_port_data(port);
  559. for (j = 0; j < N_IN_URB; j++) {
  560. if (portdata->in_urbs[j]) {
  561. usb_free_urb(portdata->in_urbs[j]);
  562. portdata->in_urbs[j] = NULL;
  563. }
  564. }
  565. for (j = 0; j < N_OUT_URB; j++) {
  566. if (portdata->out_urbs[j]) {
  567. usb_free_urb(portdata->out_urbs[j]);
  568. portdata->out_urbs[j] = NULL;
  569. }
  570. }
  571. }
  572. /* Now free per port private data */
  573. for (i = 0; i < serial->num_ports; i++) {
  574. port = serial->port[i];
  575. kfree(usb_get_serial_port_data(port));
  576. }
  577. }
  578. MODULE_AUTHOR(DRIVER_AUTHOR);
  579. MODULE_DESCRIPTION(DRIVER_DESC);
  580. MODULE_VERSION(DRIVER_VERSION);
  581. MODULE_LICENSE("GPL");
  582. #ifdef CONFIG_USB_DEBUG
  583. module_param(debug, bool, S_IRUGO | S_IWUSR);
  584. MODULE_PARM_DESC(debug, "Debug messages");
  585. #endif