MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / serial / option.c.2.6.18
blobb29037a1e0ff49cdfefa22b711224a5ff9384c1c
1 /*
2   USB Driver for GSM modems
4   Copyright (C) 2005  Matthias Urlichs <smurf@smurf.noris.de>
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.
10   Portions copied from the Keyspan driver by Hugh Blemings <hugh@blemings.org>
12   History: see the git log.
14   Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
16   This driver exists because the "normal" serial driver doesn't work too well
17   with GSM modems. Issues:
18   - data loss -- one single Receive URB is not nearly enough
19   - nonstandard flow (Option devices) control
20   - controlling the baud rate doesn't make sense
22   This driver is named "option" because the most common device it's
23   used for is a PC-Card (with an internal OHCI-USB interface, behind
24   which the GSM interface sits), made by Option Inc.
26   Some of the "one port" devices actually exhibit multiple USB instances
27   on the USB bus. This is not a bug, these ports are used for different
28   device features.
31 #define DRIVER_VERSION "v0.7.1"
32 #define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
33 #define DRIVER_DESC "USB Driver for GSM modems"
35 #include <linux/kernel.h>
36 #include <linux/jiffies.h>
37 #include <linux/errno.h>
38 #include <linux/tty.h>
39 #include <linux/tty_flip.h>
40 #include <linux/module.h>
41 #include <linux/usb.h>
42 //#include <linux/usb/serial.h>
43 #include "usb-serial.h"
45 /* Function prototypes */
46 static int  option_open(struct usb_serial_port *port, struct file *filp);
47 static void option_close(struct usb_serial_port *port, struct file *filp);
48 static int  option_startup(struct usb_serial *serial);
49 static void option_shutdown(struct usb_serial *serial);
50 static void option_rx_throttle(struct usb_serial_port *port);
51 static void option_rx_unthrottle(struct usb_serial_port *port);
52 static int  option_write_room(struct usb_serial_port *port);
54 static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
56 static int option_write(struct usb_serial_port *port,
57                         const unsigned char *buf, int count);
59 static int  option_chars_in_buffer(struct usb_serial_port *port);
60 static int  option_ioctl(struct usb_serial_port *port, struct file *file,
61                         unsigned int cmd, unsigned long arg);
62 static void option_set_termios(struct usb_serial_port *port,
63                                 struct termios *old);
64 static void option_break_ctl(struct usb_serial_port *port, int break_state);
65 static int  option_tiocmget(struct usb_serial_port *port, struct file *file);
66 static int  option_tiocmset(struct usb_serial_port *port, struct file *file,
67                                 unsigned int set, unsigned int clear);
68 static int  option_send_setup(struct usb_serial_port *port);
70 /* Vendor and product IDs */
71 #define OPTION_VENDOR_ID                0x0AF0
72 #define HUAWEI_VENDOR_ID                0x12D1
73 #define AUDIOVOX_VENDOR_ID              0x0F3D
74 #define NOVATELWIRELESS_VENDOR_ID       0x1410
75 #define ANYDATA_VENDOR_ID               0x16d5
77 #define OPTION_PRODUCT_OLD              0x5000
78 #define OPTION_PRODUCT_FUSION           0x6000
79 #define OPTION_PRODUCT_FUSION2          0x6300
80 #define OPTION_PRODUCT_COBRA            0x6500
81 #define OPTION_PRODUCT_COBRA2           0x6600
82 #define HUAWEI_PRODUCT_E600             0x1001
83 #define AUDIOVOX_PRODUCT_AIRCARD        0x0112
84 #define NOVATELWIRELESS_PRODUCT_U740    0x1400
85 #define ANYDATA_PRODUCT_ID              0x6501
87 static struct usb_device_id option_ids[] = {
88         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
89         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
90         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
91         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
92         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
93         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
94         { USB_DEVICE(OPTION_VENDOR_ID, 0x6701) },
95         { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
96         { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
97         { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
98         { } /* Terminating entry */
101 static struct usb_device_id option_ids1[] = {
102         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
103         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
104         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
105         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
106         { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
107         { USB_DEVICE(OPTION_VENDOR_ID, 0x6701) },
108         { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
109         { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
110         { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
111         { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
112         { } /* Terminating entry */
115 MODULE_DEVICE_TABLE(usb, option_ids);
117 static struct usb_driver option_driver = {
118         .name       = "option",
119         .probe      = usb_serial_probe,
120         .disconnect = usb_serial_disconnect,
121         .id_table   = option_ids,
122 #if 1  // Add by Jared 03-13-2008
123         .owner      = THIS_MODULE,
124 #else
125         .no_dynamic_id =        1,
126 #endif
129 /* The card has three separate interfaces, which the serial driver
130  * recognizes separately, thus num_port=1.
131  */
133 static struct usb_serial_device_type option_1port_device = {
135         .driver = {
136                 .owner =        THIS_MODULE,
137                 .name =         "option1",
138         },
139         .description       = "GSM modem (1-port)",
141         .owner      = THIS_MODULE,
142         .name              = "Option 3G data card",
143         .short_name        = "option",
144         .id_table          = option_ids1,
145         .num_interrupt_in  = NUM_DONT_CARE,
146         .num_bulk_in       = NUM_DONT_CARE,
147         .num_bulk_out      = NUM_DONT_CARE,
148         .num_ports         = 1,
149         .open              = option_open,
150         .close             = option_close,
151         .write             = option_write,
152         .write_room        = option_write_room,
153         .chars_in_buffer   = option_chars_in_buffer,
154         .throttle          = option_rx_throttle,
155         .unthrottle        = option_rx_unthrottle,
156         .ioctl             = option_ioctl,
157         .set_termios       = option_set_termios,
158         .break_ctl         = option_break_ctl,
159         .tiocmget          = option_tiocmget,
160         .tiocmset          = option_tiocmset,
161         .attach            = option_startup,
162         .shutdown          = option_shutdown,
163         .read_int_callback = option_instat_callback,
166 #ifdef CONFIG_USB_DEBUG
167 static int debug;
168 #else
169 #define debug 0
170 #endif
172 /* per port private data */
174 #define N_IN_URB 4
175 #define N_OUT_URB 1
176 #define IN_BUFLEN 4096
177 #define OUT_BUFLEN 128
179 struct option_port_private {
180         /* Input endpoints and buffer for this port */
181         struct urb *in_urbs[N_IN_URB];
182         char in_buffer[N_IN_URB][IN_BUFLEN];
183         /* Output endpoints and buffer for this port */
184         struct urb *out_urbs[N_OUT_URB];
185         char out_buffer[N_OUT_URB][OUT_BUFLEN];
187         /* Settings for the port */
188         int rts_state;  /* Handshaking pins (outputs) */
189         int dtr_state;
190         int cts_state;  /* Handshaking pins (inputs) */
191         int dsr_state;
192         int dcd_state;
193         int ri_state;
195         unsigned long tx_start_time[N_OUT_URB];
198 /* Functions used by new usb-serial code. */
199 static int __init option_init(void)
201         int retval;
202         retval = usb_serial_register(&option_1port_device);
203         if (retval)
204                 goto failed_1port_device_register;
205         retval = usb_register(&option_driver);
206         if (retval)
207                 goto failed_driver_register;
209         info(DRIVER_DESC ": " DRIVER_VERSION);
211         return 0;
213 failed_driver_register:
214         usb_serial_deregister (&option_1port_device);
215 failed_1port_device_register:
216         return retval;
219 static void __exit option_exit(void)
221         usb_deregister (&option_driver);
222         usb_serial_deregister (&option_1port_device);
225 module_init(option_init);
226 module_exit(option_exit);
228 static void option_rx_throttle(struct usb_serial_port *port)
230         dbg("%s", __FUNCTION__);
233 static void option_rx_unthrottle(struct usb_serial_port *port)
235         dbg("%s", __FUNCTION__);
238 static void option_break_ctl(struct usb_serial_port *port, int break_state)
240         /* Unfortunately, I don't know how to send a break */
241         dbg("%s", __FUNCTION__);
244 static void option_set_termios(struct usb_serial_port *port,
245                         struct termios *old_termios)
247         dbg("%s", __FUNCTION__);
249         option_send_setup(port);
252 static int option_tiocmget(struct usb_serial_port *port, struct file *file)
254         unsigned int value;
255         struct option_port_private *portdata;
257         portdata = usb_get_serial_port_data(port);
259         value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
260                 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
261                 ((portdata->cts_state) ? TIOCM_CTS : 0) |
262                 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
263                 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
264                 ((portdata->ri_state) ? TIOCM_RNG : 0);
266         return value;
269 static int option_tiocmset(struct usb_serial_port *port, struct file *file,
270                         unsigned int set, unsigned int clear)
272         struct option_port_private *portdata;
274         portdata = usb_get_serial_port_data(port);
276         if (set & TIOCM_RTS)
277                 portdata->rts_state = 1;
278         if (set & TIOCM_DTR)
279                 portdata->dtr_state = 1;
281         if (clear & TIOCM_RTS)
282                 portdata->rts_state = 0;
283         if (clear & TIOCM_DTR)
284                 portdata->dtr_state = 0;
285         return option_send_setup(port);
288 static int option_ioctl(struct usb_serial_port *port, struct file *file,
289                         unsigned int cmd, unsigned long arg)
291         return -ENOIOCTLCMD;
294 /* Write */
295 static int option_write(struct usb_serial_port *port,
296                         const unsigned char *buf, int count)
298         struct option_port_private *portdata;
299         int i;
300         int left, todo;
301         struct urb *this_urb = NULL; /* spurious */
302         int err;
304         portdata = usb_get_serial_port_data(port);
306         dbg("%s: write (%d chars)", __FUNCTION__, count);
308         i = 0;
309         left = count;
310         for (i=0; left > 0 && i < N_OUT_URB; i++) {
311                 todo = left;
312                 if (todo > OUT_BUFLEN)
313                         todo = OUT_BUFLEN;
315                 this_urb = portdata->out_urbs[i];
316                 if (this_urb->status == -EINPROGRESS) {
317                         if (time_before(jiffies,
318                                         portdata->tx_start_time[i] + 10 * HZ))
319                                 continue;
320                         usb_unlink_urb(this_urb);
321                         continue;
322                 }
323                 if (this_urb->status != 0)
324                         dbg("usb_write %p failed (err=%d)",
325                                 this_urb, this_urb->status);
327                 dbg("%s: endpoint %d buf %d", __FUNCTION__,
328                         usb_pipeendpoint(this_urb->pipe), i);
330                 /* send the data */
331                 memcpy (this_urb->transfer_buffer, buf, todo);
332                 this_urb->transfer_buffer_length = todo;
334                 this_urb->dev = port->serial->dev;
335                 err = usb_submit_urb(this_urb, GFP_ATOMIC);
336                 if (err) {
337                         dbg("usb_submit_urb %p (write bulk) failed "
338                                 "(%d, has %d)", this_urb,
339                                 err, this_urb->status);
340                         continue;
341                 }
342                 portdata->tx_start_time[i] = jiffies;
343                 buf += todo;
344                 left -= todo;
345         }
347         count -= left;
348         dbg("%s: wrote (did %d)", __FUNCTION__, count);
349         return count;
352 static void option_indat_callback(struct urb *urb, struct pt_regs *regs)
354         int err;
355         int endpoint;
356         struct usb_serial_port *port;
357         struct tty_struct *tty;
358         unsigned char *data = urb->transfer_buffer;
359 #if 1  // Masked by Jared 03-13-2008
360         int i;
361 #endif
363         dbg("%s: %p", __FUNCTION__, urb);
365         endpoint = usb_pipeendpoint(urb->pipe);
366         port = (struct usb_serial_port *) urb->context;
368         if (urb->status) {
369                 dbg("%s: nonzero status: %d on endpoint %02x.",
370                     __FUNCTION__, urb->status, endpoint);
371         } else {
372                 tty = port->tty;
373                 if (urb->actual_length) {
374 #if 0  // Masked by Jared 03-13-2008
375                         tty_buffer_request_room(tty, urb->actual_length);
376                         tty_insert_flip_string(tty, data, urb->actual_length);
377 #else
378                         for(i=0; i<urb->actual_length; i++) {
379                                 if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
380                                         tty_flip_buffer_push(tty);
381                                 }
382                                 tty_insert_flip_char(tty, data[i], 0);
383                         }
384 #endif
386                         tty_flip_buffer_push(tty);
387                 } else {
388                         dbg("%s: empty read urb received", __FUNCTION__);
389                 }
391                 /* Resubmit urb so we continue receiving */
392                 if (port->open_count && urb->status != -ESHUTDOWN) {
393                         err = usb_submit_urb(urb, GFP_ATOMIC);
394                         if (err)
395                                 printk(KERN_ERR "%s: resubmit read urb failed. "
396                                         "(%d)", __FUNCTION__, err);
397                 }
398         }
399         return;
402 static void option_outdat_callback(struct urb *urb, struct pt_regs *regs)
404         struct usb_serial_port *port;
406         dbg("%s", __FUNCTION__);
408         port = (struct usb_serial_port *) urb->context;
410         usb_serial_port_softint(port);
413 static void option_instat_callback(struct urb *urb, struct pt_regs *regs)
415         int err;
416         struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
417         struct option_port_private *portdata = usb_get_serial_port_data(port);
418         struct usb_serial *serial = port->serial;
420         dbg("%s", __FUNCTION__);
421         dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
423         if (urb->status == 0) {
424                 struct usb_ctrlrequest *req_pkt =
425                                 (struct usb_ctrlrequest *)urb->transfer_buffer;
427                 if (!req_pkt) {
428                         dbg("%s: NULL req_pkt\n", __FUNCTION__);
429                         return;
430                 }
431                 if ((req_pkt->bRequestType == 0xA1) &&
432                                 (req_pkt->bRequest == 0x20)) {
433                         int old_dcd_state;
434                         unsigned char signals = *((unsigned char *)
435                                         urb->transfer_buffer +
436                                         sizeof(struct usb_ctrlrequest));
438                         dbg("%s: signal x%x", __FUNCTION__, signals);
440                         old_dcd_state = portdata->dcd_state;
441                         portdata->cts_state = 1;
442                         portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
443                         portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
444                         portdata->ri_state = ((signals & 0x08) ? 1 : 0);
446                         if (port->tty && !C_CLOCAL(port->tty) &&
447                                         old_dcd_state && !portdata->dcd_state)
448                                 tty_hangup(port->tty);
449                 } else {
450                         dbg("%s: type %x req %x", __FUNCTION__,
451                                 req_pkt->bRequestType,req_pkt->bRequest);
452                 }
453         } else
454                 dbg("%s: error %d", __FUNCTION__, urb->status);
456         /* Resubmit urb so we continue receiving IRQ data */
457         if (urb->status != -ESHUTDOWN) {
458                 urb->dev = serial->dev;
459                 err = usb_submit_urb(urb, GFP_ATOMIC);
460                 if (err)
461                         dbg("%s: resubmit intr urb failed. (%d)",
462                                 __FUNCTION__, err);
463         }
466 static int option_write_room(struct usb_serial_port *port)
468         struct option_port_private *portdata;
469         int i;
470         int data_len = 0;
471         struct urb *this_urb;
473         portdata = usb_get_serial_port_data(port);
475         for (i=0; i < N_OUT_URB; i++) {
476                 this_urb = portdata->out_urbs[i];
477                 if (this_urb && this_urb->status != -EINPROGRESS)
478                         data_len += OUT_BUFLEN;
479         }
481         dbg("%s: %d", __FUNCTION__, data_len);
482         return data_len;
485 static int option_chars_in_buffer(struct usb_serial_port *port)
487         struct option_port_private *portdata;
488         int i;
489         int data_len = 0;
490         struct urb *this_urb;
492         portdata = usb_get_serial_port_data(port);
494         for (i=0; i < N_OUT_URB; i++) {
495                 this_urb = portdata->out_urbs[i];
496                 if (this_urb && this_urb->status == -EINPROGRESS)
497                         data_len += this_urb->transfer_buffer_length;
498         }
499         dbg("%s: %d", __FUNCTION__, data_len);
500         return data_len;
503 static int option_open(struct usb_serial_port *port, struct file *filp)
505         struct option_port_private *portdata;
506         struct usb_serial *serial = port->serial;
507         int i, err;
508         struct urb *urb;
510         portdata = usb_get_serial_port_data(port);
512         dbg("%s", __FUNCTION__);
514         /* Set some sane defaults */
515         portdata->rts_state = 1;
516         portdata->dtr_state = 1;
518         /* Reset low level data toggle and start reading from endpoints */
519         for (i = 0; i < N_IN_URB; i++) {
520                 urb = portdata->in_urbs[i];
521                 if (! urb)
522                         continue;
523                 if (urb->dev != serial->dev) {
524                         dbg("%s: dev %p != %p", __FUNCTION__,
525                                 urb->dev, serial->dev);
526                         continue;
527                 }
529                 /*
530                  * make sure endpoint data toggle is synchronized with the
531                  * device
532                  */
533                 usb_clear_halt(urb->dev, urb->pipe);
535                 err = usb_submit_urb(urb, GFP_KERNEL);
536                 if (err) {
537                         dbg("%s: submit urb %d failed (%d) %d",
538                                 __FUNCTION__, i, err,
539                                 urb->transfer_buffer_length);
540                 }
541         }
543         /* Reset low level data toggle on out endpoints */
544         for (i = 0; i < N_OUT_URB; i++) {
545                 urb = portdata->out_urbs[i];
546                 if (! urb)
547                         continue;
548                 urb->dev = serial->dev;
549                 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
550                                 usb_pipeout(urb->pipe), 0); */
551         }
553         port->tty->low_latency = 1;
555         option_send_setup(port);
557         return (0);
560 static inline void stop_urb(struct urb *urb)
562         if (urb && urb->status == -EINPROGRESS)
563                 usb_kill_urb(urb);
566 static void option_close(struct usb_serial_port *port, struct file *filp)
568         int i;
569         struct usb_serial *serial = port->serial;
570         struct option_port_private *portdata;
572         dbg("%s", __FUNCTION__);
573         portdata = usb_get_serial_port_data(port);
575         portdata->rts_state = 0;
576         portdata->dtr_state = 0;
578         if (serial->dev) {
579                 option_send_setup(port);
581                 /* Stop reading/writing urbs */
582                 for (i = 0; i < N_IN_URB; i++)
583                         stop_urb(portdata->in_urbs[i]);
584                 for (i = 0; i < N_OUT_URB; i++)
585                         stop_urb(portdata->out_urbs[i]);
586         }
587         port->tty = NULL;
590 /* Helper functions used by option_setup_urbs */
591 static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
592                 int dir, void *ctx, char *buf, int len,
593                 void (*callback)(struct urb *, struct pt_regs *regs))
595         struct urb *urb;
597         if (endpoint == -1)
598                 return NULL;            /* endpoint not needed */
600         urb = usb_alloc_urb(0, GFP_KERNEL);             /* No ISO */
601         if (urb == NULL) {
602                 dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
603                 return NULL;
604         }
606                 /* Fill URB using supplied data. */
607         usb_fill_bulk_urb(urb, serial->dev,
608                       usb_sndbulkpipe(serial->dev, endpoint) | dir,
609                       buf, len, callback, ctx);
611         return urb;
614 /* Setup urbs */
615 static void option_setup_urbs(struct usb_serial *serial)
617         int i,j;
618         struct usb_serial_port *port;
619         struct option_port_private *portdata;
621         dbg("%s", __FUNCTION__);
623         for (i = 0; i < serial->num_ports; i++) {
624                 port = serial->port[i];
625                 portdata = usb_get_serial_port_data(port);
627         /* Do indat endpoints first */
628                 for (j = 0; j < N_IN_URB; ++j) {
629                         portdata->in_urbs[j] = option_setup_urb (serial,
630                         port->bulk_in_endpointAddress, USB_DIR_IN, port,
631                         portdata->in_buffer[j], IN_BUFLEN, option_indat_callback);
632                 }
634                 /* outdat endpoints */
635                 for (j = 0; j < N_OUT_URB; ++j) {
636                         portdata->out_urbs[j] = option_setup_urb (serial,
637                         port->bulk_out_endpointAddress, USB_DIR_OUT, port,
638                         portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback);
639                 }
640         }
643 static int option_send_setup(struct usb_serial_port *port)
645         struct usb_serial *serial = port->serial;
646         struct option_port_private *portdata;
648         dbg("%s", __FUNCTION__);
650         portdata = usb_get_serial_port_data(port);
652         if (port->tty) {
653                 int val = 0;
654                 if (portdata->dtr_state)
655                         val |= 0x01;
656                 if (portdata->rts_state)
657                         val |= 0x02;
659                 return usb_control_msg(serial->dev,
660                                 usb_rcvctrlpipe(serial->dev, 0),
661                                 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
662         }
664         return 0;
667 static int option_startup(struct usb_serial *serial)
669         int i, err;
670         struct usb_serial_port *port;
671         struct option_port_private *portdata;
673         dbg("%s", __FUNCTION__);
675         /* Now setup per port private data */
676         for (i = 0; i < serial->num_ports; i++) {
677                 port = serial->port[i];
678 #if 0  // Masked by Jared 03-13-2008
679                 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
680 #else
681                 portdata = kmalloc(sizeof(*portdata), GFP_KERNEL);
682                 memset(portdata, 0, sizeof(*portdata));
683 #endif
685                 if (!portdata) {
686                         dbg("%s: kmalloc for option_port_private (%d) failed!.",
687                                         __FUNCTION__, i);
688                         return (1);
689                 }
691                 usb_set_serial_port_data(port, portdata);
693                 if (! port->interrupt_in_urb)
694                         continue;
695                 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
696                 if (err)
697                         dbg("%s: submit irq_in urb failed %d",
698                                 __FUNCTION__, err);
699         }
701         option_setup_urbs(serial);
703         return (0);
706 static void option_shutdown(struct usb_serial *serial)
708         int i, j;
709         struct usb_serial_port *port;
710         struct option_port_private *portdata;
712         dbg("%s", __FUNCTION__);
714         /* Stop reading/writing urbs */
715         for (i = 0; i < serial->num_ports; ++i) {
716                 port = serial->port[i];
717                 portdata = usb_get_serial_port_data(port);
718                 for (j = 0; j < N_IN_URB; j++)
719                         stop_urb(portdata->in_urbs[j]);
720                 for (j = 0; j < N_OUT_URB; j++)
721                         stop_urb(portdata->out_urbs[j]);
722         }
724         /* Now free them */
725         for (i = 0; i < serial->num_ports; ++i) {
726                 port = serial->port[i];
727                 portdata = usb_get_serial_port_data(port);
729                 for (j = 0; j < N_IN_URB; j++) {
730                         if (portdata->in_urbs[j]) {
731                                 usb_free_urb(portdata->in_urbs[j]);
732                                 portdata->in_urbs[j] = NULL;
733                         }
734                 }
735                 for (j = 0; j < N_OUT_URB; j++) {
736                         if (portdata->out_urbs[j]) {
737                                 usb_free_urb(portdata->out_urbs[j]);
738                                 portdata->out_urbs[j] = NULL;
739                         }
740                 }
741         }
743         /* Now free per port private data */
744         for (i = 0; i < serial->num_ports; i++) {
745                 port = serial->port[i];
746                 kfree(usb_get_serial_port_data(port));
747         }
750 MODULE_AUTHOR(DRIVER_AUTHOR);
751 MODULE_DESCRIPTION(DRIVER_DESC);
752 MODULE_VERSION(DRIVER_VERSION);
753 MODULE_LICENSE("GPL");
755 #ifdef CONFIG_USB_DEBUG
756 module_param(debug, bool, S_IRUGO | S_IWUSR);
757 MODULE_PARM_DESC(debug, "Debug messages");
758 #endif