option.c 18 KB

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