option.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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 option_init(void)
  133. {
  134. int retval;
  135. retval = usb_serial_register(&option_3port_device);
  136. if (retval)
  137. goto failed_3port_device_register;
  138. retval = usb_register(&option_driver);
  139. if (retval)
  140. goto failed_driver_register;
  141. info(DRIVER_DESC ": " DRIVER_VERSION);
  142. return 0;
  143. failed_driver_register:
  144. usb_serial_deregister (&option_3port_device);
  145. failed_3port_device_register:
  146. return retval;
  147. }
  148. static void __exit option_exit(void)
  149. {
  150. usb_deregister (&option_driver);
  151. usb_serial_deregister (&option_3port_device);
  152. }
  153. module_init(option_init);
  154. module_exit(option_exit);
  155. static void option_rx_throttle(struct usb_serial_port *port)
  156. {
  157. dbg("%s", __FUNCTION__);
  158. }
  159. static void option_rx_unthrottle(struct usb_serial_port *port)
  160. {
  161. dbg("%s", __FUNCTION__);
  162. }
  163. static void option_break_ctl(struct usb_serial_port *port, int break_state)
  164. {
  165. /* Unfortunately, I don't know how to send a break */
  166. dbg("%s", __FUNCTION__);
  167. }
  168. static void option_set_termios(struct usb_serial_port *port,
  169. struct termios *old_termios)
  170. {
  171. dbg("%s", __FUNCTION__);
  172. option_send_setup(port);
  173. }
  174. static int option_tiocmget(struct usb_serial_port *port, struct file *file)
  175. {
  176. unsigned int value;
  177. struct option_port_private *portdata;
  178. portdata = usb_get_serial_port_data(port);
  179. value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
  180. ((portdata->dtr_state) ? TIOCM_DTR : 0) |
  181. ((portdata->cts_state) ? TIOCM_CTS : 0) |
  182. ((portdata->dsr_state) ? TIOCM_DSR : 0) |
  183. ((portdata->dcd_state) ? TIOCM_CAR : 0) |
  184. ((portdata->ri_state) ? TIOCM_RNG : 0);
  185. return value;
  186. }
  187. static int option_tiocmset(struct usb_serial_port *port, struct file *file,
  188. unsigned int set, unsigned int clear)
  189. {
  190. struct option_port_private *portdata;
  191. portdata = usb_get_serial_port_data(port);
  192. if (set & TIOCM_RTS)
  193. portdata->rts_state = 1;
  194. if (set & TIOCM_DTR)
  195. portdata->dtr_state = 1;
  196. if (clear & TIOCM_RTS)
  197. portdata->rts_state = 0;
  198. if (clear & TIOCM_DTR)
  199. portdata->dtr_state = 0;
  200. return option_send_setup(port);
  201. }
  202. static int option_ioctl(struct usb_serial_port *port, struct file *file,
  203. unsigned int cmd, unsigned long arg)
  204. {
  205. return -ENOIOCTLCMD;
  206. }
  207. /* Write */
  208. static int option_write(struct usb_serial_port *port,
  209. const unsigned char *buf, int count)
  210. {
  211. struct option_port_private *portdata;
  212. int i;
  213. int left, todo;
  214. struct urb *this_urb = NULL; /* spurious */
  215. int err;
  216. portdata = usb_get_serial_port_data(port);
  217. dbg("%s: write (%d chars)", __FUNCTION__, count);
  218. i = 0;
  219. left = count;
  220. for (i=0; left > 0 && i < N_OUT_URB; i++) {
  221. todo = left;
  222. if (todo > OUT_BUFLEN)
  223. todo = OUT_BUFLEN;
  224. this_urb = portdata->out_urbs[i];
  225. if (this_urb->status == -EINPROGRESS) {
  226. if (this_urb->transfer_flags & URB_ASYNC_UNLINK)
  227. continue;
  228. if (time_before(jiffies,
  229. portdata->tx_start_time[i] + 10 * HZ))
  230. continue;
  231. this_urb->transfer_flags |= URB_ASYNC_UNLINK;
  232. usb_unlink_urb(this_urb);
  233. continue;
  234. }
  235. if (this_urb->status != 0)
  236. dbg("usb_write %p failed (err=%d)",
  237. this_urb, this_urb->status);
  238. dbg("%s: endpoint %d buf %d", __FUNCTION__,
  239. usb_pipeendpoint(this_urb->pipe), i);
  240. /* send the data */
  241. memcpy (this_urb->transfer_buffer, buf, todo);
  242. this_urb->transfer_buffer_length = todo;
  243. this_urb->transfer_flags &= ~URB_ASYNC_UNLINK;
  244. this_urb->dev = port->serial->dev;
  245. err = usb_submit_urb(this_urb, GFP_ATOMIC);
  246. if (err) {
  247. dbg("usb_submit_urb %p (write bulk) failed "
  248. "(%d, has %d)", this_urb,
  249. err, this_urb->status);
  250. continue;
  251. }
  252. portdata->tx_start_time[i] = jiffies;
  253. buf += todo;
  254. left -= todo;
  255. }
  256. count -= left;
  257. dbg("%s: wrote (did %d)", __FUNCTION__, count);
  258. return count;
  259. }
  260. static void option_indat_callback(struct urb *urb, struct pt_regs *regs)
  261. {
  262. int i, err;
  263. int endpoint;
  264. struct usb_serial_port *port;
  265. struct tty_struct *tty;
  266. unsigned char *data = urb->transfer_buffer;
  267. dbg("%s: %p", __FUNCTION__, urb);
  268. endpoint = usb_pipeendpoint(urb->pipe);
  269. port = (struct usb_serial_port *) urb->context;
  270. if (urb->status) {
  271. dbg("%s: nonzero status: %d on endpoint %02x.",
  272. __FUNCTION__, urb->status, endpoint);
  273. } else {
  274. tty = port->tty;
  275. if (urb->actual_length) {
  276. for (i = 0; i < urb->actual_length ; ++i) {
  277. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  278. tty_flip_buffer_push(tty);
  279. tty_insert_flip_char(tty, data[i], 0);
  280. }
  281. tty_flip_buffer_push(tty);
  282. } else {
  283. dbg("%s: empty read urb received", __FUNCTION__);
  284. }
  285. /* Resubmit urb so we continue receiving */
  286. if (port->open_count && urb->status != -ESHUTDOWN) {
  287. err = usb_submit_urb(urb, GFP_ATOMIC);
  288. if (err)
  289. printk(KERN_ERR "%s: resubmit read urb failed. "
  290. "(%d)", __FUNCTION__, err);
  291. }
  292. }
  293. return;
  294. }
  295. static void option_outdat_callback(struct urb *urb, struct pt_regs *regs)
  296. {
  297. struct usb_serial_port *port;
  298. dbg("%s", __FUNCTION__);
  299. port = (struct usb_serial_port *) urb->context;
  300. if (port->open_count)
  301. schedule_work(&port->work);
  302. }
  303. static void option_instat_callback(struct urb *urb, struct pt_regs *regs)
  304. {
  305. int err;
  306. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  307. struct option_port_private *portdata = usb_get_serial_port_data(port);
  308. struct usb_serial *serial = port->serial;
  309. dbg("%s", __FUNCTION__);
  310. dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
  311. if (urb->status == 0) {
  312. struct usb_ctrlrequest *req_pkt =
  313. (struct usb_ctrlrequest *)urb->transfer_buffer;
  314. if (!req_pkt) {
  315. dbg("%s: NULL req_pkt\n", __FUNCTION__);
  316. return;
  317. }
  318. if ((req_pkt->bRequestType == 0xA1) &&
  319. (req_pkt->bRequest == 0x20)) {
  320. int old_dcd_state;
  321. unsigned char signals = *((unsigned char *)
  322. urb->transfer_buffer +
  323. sizeof(struct usb_ctrlrequest));
  324. dbg("%s: signal x%x", __FUNCTION__, signals);
  325. old_dcd_state = portdata->dcd_state;
  326. portdata->cts_state = 1;
  327. portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
  328. portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
  329. portdata->ri_state = ((signals & 0x08) ? 1 : 0);
  330. if (port->tty && !C_CLOCAL(port->tty) &&
  331. old_dcd_state && !portdata->dcd_state)
  332. tty_hangup(port->tty);
  333. } else {
  334. dbg("%s: type %x req %x", __FUNCTION__,
  335. req_pkt->bRequestType,req_pkt->bRequest);
  336. }
  337. } else
  338. dbg("%s: error %d", __FUNCTION__, urb->status);
  339. /* Resubmit urb so we continue receiving IRQ data */
  340. if (urb->status != -ESHUTDOWN) {
  341. urb->dev = serial->dev;
  342. err = usb_submit_urb(urb, GFP_ATOMIC);
  343. if (err)
  344. dbg("%s: resubmit intr urb failed. (%d)",
  345. __FUNCTION__, err);
  346. }
  347. }
  348. static int option_write_room(struct usb_serial_port *port)
  349. {
  350. struct option_port_private *portdata;
  351. int i;
  352. int data_len = 0;
  353. struct urb *this_urb;
  354. portdata = usb_get_serial_port_data(port);
  355. for (i=0; i < N_OUT_URB; i++) {
  356. this_urb = portdata->out_urbs[i];
  357. if (this_urb && this_urb->status != -EINPROGRESS)
  358. data_len += OUT_BUFLEN;
  359. }
  360. dbg("%s: %d", __FUNCTION__, data_len);
  361. return data_len;
  362. }
  363. static int option_chars_in_buffer(struct usb_serial_port *port)
  364. {
  365. struct option_port_private *portdata;
  366. int i;
  367. int data_len = 0;
  368. struct urb *this_urb;
  369. portdata = usb_get_serial_port_data(port);
  370. for (i=0; i < N_OUT_URB; i++) {
  371. this_urb = portdata->out_urbs[i];
  372. if (this_urb && this_urb->status == -EINPROGRESS)
  373. data_len += this_urb->transfer_buffer_length;
  374. }
  375. dbg("%s: %d", __FUNCTION__, data_len);
  376. return data_len;
  377. }
  378. static int option_open(struct usb_serial_port *port, struct file *filp)
  379. {
  380. struct option_port_private *portdata;
  381. struct usb_serial *serial = port->serial;
  382. int i, err;
  383. struct urb *urb;
  384. portdata = usb_get_serial_port_data(port);
  385. dbg("%s", __FUNCTION__);
  386. /* Set some sane defaults */
  387. portdata->rts_state = 1;
  388. portdata->dtr_state = 1;
  389. /* Reset low level data toggle and start reading from endpoints */
  390. for (i = 0; i < N_IN_URB; i++) {
  391. urb = portdata->in_urbs[i];
  392. if (! urb)
  393. continue;
  394. if (urb->dev != serial->dev) {
  395. dbg("%s: dev %p != %p", __FUNCTION__,
  396. urb->dev, serial->dev);
  397. continue;
  398. }
  399. /*
  400. * make sure endpoint data toggle is synchronized with the
  401. * device
  402. */
  403. usb_clear_halt(urb->dev, urb->pipe);
  404. err = usb_submit_urb(urb, GFP_KERNEL);
  405. if (err) {
  406. dbg("%s: submit urb %d failed (%d) %d",
  407. __FUNCTION__, i, err,
  408. urb->transfer_buffer_length);
  409. }
  410. }
  411. /* Reset low level data toggle on out endpoints */
  412. for (i = 0; i < N_OUT_URB; i++) {
  413. urb = portdata->out_urbs[i];
  414. if (! urb)
  415. continue;
  416. urb->dev = serial->dev;
  417. /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
  418. 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 stop_urb(struct urb *urb)
  425. {
  426. if (urb && urb->status == -EINPROGRESS) {
  427. urb->transfer_flags &= ~URB_ASYNC_UNLINK;
  428. usb_kill_urb(urb);
  429. }
  430. }
  431. static void option_close(struct usb_serial_port *port, struct file *filp)
  432. {
  433. int i;
  434. struct usb_serial *serial = port->serial;
  435. struct option_port_private *portdata;
  436. dbg("%s", __FUNCTION__);
  437. portdata = usb_get_serial_port_data(port);
  438. portdata->rts_state = 0;
  439. portdata->dtr_state = 0;
  440. if (serial->dev) {
  441. option_send_setup(port);
  442. /* Stop reading/writing urbs */
  443. for (i = 0; i < N_IN_URB; i++)
  444. stop_urb(portdata->in_urbs[i]);
  445. for (i = 0; i < N_OUT_URB; i++)
  446. stop_urb(portdata->out_urbs[i]);
  447. }
  448. port->tty = NULL;
  449. }
  450. /* Helper functions used by option_setup_urbs */
  451. static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
  452. int dir, void *ctx, char *buf, int len,
  453. void (*callback)(struct urb *, struct pt_regs *regs))
  454. {
  455. struct urb *urb;
  456. if (endpoint == -1)
  457. return NULL; /* endpoint not needed */
  458. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  459. if (urb == NULL) {
  460. dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
  461. return NULL;
  462. }
  463. /* Fill URB using supplied data. */
  464. usb_fill_bulk_urb(urb, serial->dev,
  465. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  466. buf, len, callback, ctx);
  467. return urb;
  468. }
  469. /* Setup urbs */
  470. static void option_setup_urbs(struct usb_serial *serial)
  471. {
  472. int j;
  473. struct usb_serial_port *port;
  474. struct option_port_private *portdata;
  475. dbg("%s", __FUNCTION__);
  476. port = serial->port[0];
  477. portdata = usb_get_serial_port_data(port);
  478. /* Do indat endpoints first */
  479. for (j = 0; j <= N_IN_URB; ++j) {
  480. portdata->in_urbs[j] = option_setup_urb (serial,
  481. port->bulk_in_endpointAddress, USB_DIR_IN, port,
  482. portdata->in_buffer[j], IN_BUFLEN, option_indat_callback);
  483. }
  484. /* outdat endpoints */
  485. for (j = 0; j <= N_OUT_URB; ++j) {
  486. portdata->out_urbs[j] = option_setup_urb (serial,
  487. port->bulk_out_endpointAddress, USB_DIR_OUT, port,
  488. portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback);
  489. }
  490. }
  491. static int option_send_setup(struct usb_serial_port *port)
  492. {
  493. struct usb_serial *serial = port->serial;
  494. struct option_port_private *portdata;
  495. dbg("%s", __FUNCTION__);
  496. portdata = usb_get_serial_port_data(port);
  497. if (port->tty) {
  498. int val = 0;
  499. if (portdata->dtr_state)
  500. val |= 0x01;
  501. if (portdata->rts_state)
  502. val |= 0x02;
  503. return usb_control_msg(serial->dev,
  504. usb_rcvctrlpipe(serial->dev, 0),
  505. 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
  506. }
  507. return 0;
  508. }
  509. static int option_startup(struct usb_serial *serial)
  510. {
  511. int i, err;
  512. struct usb_serial_port *port;
  513. struct option_port_private *portdata;
  514. dbg("%s", __FUNCTION__);
  515. /* Now setup per port private data */
  516. for (i = 0; i < serial->num_ports; i++) {
  517. port = serial->port[i];
  518. portdata = kmalloc(sizeof(*portdata), GFP_KERNEL);
  519. if (!portdata) {
  520. dbg("%s: kmalloc for option_port_private (%d) failed!.",
  521. __FUNCTION__, i);
  522. return (1);
  523. }
  524. memset(portdata, 0, sizeof(struct option_port_private));
  525. usb_set_serial_port_data(port, portdata);
  526. if (! port->interrupt_in_urb)
  527. continue;
  528. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  529. if (err)
  530. dbg("%s: submit irq_in urb failed %d",
  531. __FUNCTION__, err);
  532. }
  533. option_setup_urbs(serial);
  534. return (0);
  535. }
  536. static void option_shutdown(struct usb_serial *serial)
  537. {
  538. int i, j;
  539. struct usb_serial_port *port;
  540. struct option_port_private *portdata;
  541. dbg("%s", __FUNCTION__);
  542. /* Stop reading/writing urbs */
  543. for (i = 0; i < serial->num_ports; ++i) {
  544. port = serial->port[i];
  545. portdata = usb_get_serial_port_data(port);
  546. for (j = 0; j < N_IN_URB; j++)
  547. stop_urb(portdata->in_urbs[j]);
  548. for (j = 0; j < N_OUT_URB; j++)
  549. stop_urb(portdata->out_urbs[j]);
  550. }
  551. /* Now free them */
  552. for (i = 0; i < serial->num_ports; ++i) {
  553. port = serial->port[i];
  554. portdata = usb_get_serial_port_data(port);
  555. for (j = 0; j < N_IN_URB; j++) {
  556. if (portdata->in_urbs[j]) {
  557. usb_free_urb(portdata->in_urbs[j]);
  558. portdata->in_urbs[j] = NULL;
  559. }
  560. }
  561. for (j = 0; j < N_OUT_URB; j++) {
  562. if (portdata->out_urbs[j]) {
  563. usb_free_urb(portdata->out_urbs[j]);
  564. portdata->out_urbs[j] = NULL;
  565. }
  566. }
  567. }
  568. /* Now free per port private data */
  569. for (i = 0; i < serial->num_ports; i++) {
  570. port = serial->port[i];
  571. kfree(usb_get_serial_port_data(port));
  572. }
  573. }
  574. MODULE_AUTHOR(DRIVER_AUTHOR);
  575. MODULE_DESCRIPTION(DRIVER_DESC);
  576. MODULE_VERSION(DRIVER_VERSION);
  577. MODULE_LICENSE("GPL");
  578. #ifdef CONFIG_USB_DEBUG
  579. module_param(debug, bool, S_IRUGO | S_IWUSR);
  580. MODULE_PARM_DESC(debug, "Debug messages");
  581. #endif