option.c 18 KB

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