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