Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / usb / serial / sierra.c
1 /*
2   USB Driver for Sierra Wireless
3
4   Copyright (C) 2006  Kevin Lloyd <linux@sierrawireless.com>
5
6   IMPORTANT DISCLAIMER: This driver is not commercially supported by
7   Sierra Wireless. Use at your own risk.
8
9   This driver is free software; you can redistribute it and/or modify
10   it under the terms of Version 2 of the GNU General Public License as
11   published by the Free Software Foundation.
12
13   Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de>
14   Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org>
15
16 */
17
18 #define DRIVER_VERSION "v.1.0.6"
19 #define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>"
20 #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
21
22 #include <linux/kernel.h>
23 #include <linux/jiffies.h>
24 #include <linux/errno.h>
25 #include <linux/tty.h>
26 #include <linux/tty_flip.h>
27 #include <linux/module.h>
28 #include <linux/usb.h>
29 #include <linux/usb/serial.h>
30
31
32 static struct usb_device_id id_table [] = {
33         { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
34         { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
35         { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
36         { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
37         { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
38         { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
39         { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
40         { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
41         { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
42         { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
43         { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
44         { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
45
46         { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
47         { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
48         { }
49 };
50 MODULE_DEVICE_TABLE(usb, id_table);
51
52 static struct usb_device_id id_table_1port [] = {
53         { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
54         { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
55         { }
56 };
57
58 static struct usb_device_id id_table_3port [] = {
59         { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
60         { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
61         { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
62         { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
63         { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
64         { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
65         { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
66         { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
67         { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
68         { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
69         { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
70         { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
71         { }
72 };
73
74 static struct usb_driver sierra_driver = {
75         .name       = "sierra",
76         .probe      = usb_serial_probe,
77         .disconnect = usb_serial_disconnect,
78         .id_table   = id_table,
79         .no_dynamic_id =        1,
80 };
81
82
83 static int debug;
84
85 /* per port private data */
86 #define N_IN_URB        4
87 #define N_OUT_URB       4
88 #define IN_BUFLEN       4096
89 #define OUT_BUFLEN      128
90
91 struct sierra_port_private {
92         /* Input endpoints and buffer for this port */
93         struct urb *in_urbs[N_IN_URB];
94         char in_buffer[N_IN_URB][IN_BUFLEN];
95         /* Output endpoints and buffer for this port */
96         struct urb *out_urbs[N_OUT_URB];
97         char out_buffer[N_OUT_URB][OUT_BUFLEN];
98
99         /* Settings for the port */
100         int rts_state;  /* Handshaking pins (outputs) */
101         int dtr_state;
102         int cts_state;  /* Handshaking pins (inputs) */
103         int dsr_state;
104         int dcd_state;
105         int ri_state;
106
107         unsigned long tx_start_time[N_OUT_URB];
108 };
109
110 static int sierra_send_setup(struct usb_serial_port *port)
111 {
112         struct usb_serial *serial = port->serial;
113         struct sierra_port_private *portdata;
114
115         dbg("%s", __FUNCTION__);
116
117         portdata = usb_get_serial_port_data(port);
118
119         if (port->tty) {
120                 int val = 0;
121                 if (portdata->dtr_state)
122                         val |= 0x01;
123                 if (portdata->rts_state)
124                         val |= 0x02;
125
126                 return usb_control_msg(serial->dev,
127                                 usb_rcvctrlpipe(serial->dev, 0),
128                                 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
129         }
130
131         return 0;
132 }
133
134 static void sierra_rx_throttle(struct usb_serial_port *port)
135 {
136         dbg("%s", __FUNCTION__);
137 }
138
139 static void sierra_rx_unthrottle(struct usb_serial_port *port)
140 {
141         dbg("%s", __FUNCTION__);
142 }
143
144 static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
145 {
146         /* Unfortunately, I don't know how to send a break */
147         dbg("%s", __FUNCTION__);
148 }
149
150 static void sierra_set_termios(struct usb_serial_port *port,
151                         struct ktermios *old_termios)
152 {
153         dbg("%s", __FUNCTION__);
154
155         sierra_send_setup(port);
156 }
157
158 static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
159 {
160         unsigned int value;
161         struct sierra_port_private *portdata;
162
163         portdata = usb_get_serial_port_data(port);
164
165         value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
166                 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
167                 ((portdata->cts_state) ? TIOCM_CTS : 0) |
168                 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
169                 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
170                 ((portdata->ri_state) ? TIOCM_RNG : 0);
171
172         return value;
173 }
174
175 static int sierra_tiocmset(struct usb_serial_port *port, struct file *file,
176                         unsigned int set, unsigned int clear)
177 {
178         struct sierra_port_private *portdata;
179
180         portdata = usb_get_serial_port_data(port);
181
182         if (set & TIOCM_RTS)
183                 portdata->rts_state = 1;
184         if (set & TIOCM_DTR)
185                 portdata->dtr_state = 1;
186
187         if (clear & TIOCM_RTS)
188                 portdata->rts_state = 0;
189         if (clear & TIOCM_DTR)
190                 portdata->dtr_state = 0;
191         return sierra_send_setup(port);
192 }
193
194 static int sierra_ioctl(struct usb_serial_port *port, struct file *file,
195                         unsigned int cmd, unsigned long arg)
196 {
197         return -ENOIOCTLCMD;
198 }
199
200 /* Write */
201 static int sierra_write(struct usb_serial_port *port,
202                         const unsigned char *buf, int count)
203 {
204         struct sierra_port_private *portdata;
205         int i;
206         int left, todo;
207         struct urb *this_urb = NULL; /* spurious */
208         int err;
209
210         portdata = usb_get_serial_port_data(port);
211
212         dbg("%s: write (%d chars)", __FUNCTION__, count);
213
214         i = 0;
215         left = count;
216         for (i=0; left > 0 && i < N_OUT_URB; i++) {
217                 todo = left;
218                 if (todo > OUT_BUFLEN)
219                         todo = OUT_BUFLEN;
220
221                 this_urb = portdata->out_urbs[i];
222                 if (this_urb->status == -EINPROGRESS) {
223                         if (time_before(jiffies,
224                                         portdata->tx_start_time[i] + 10 * HZ))
225                                 continue;
226                         usb_unlink_urb(this_urb);
227                         continue;
228                 }
229                 if (this_urb->status != 0)
230                         dbg("usb_write %p failed (err=%d)",
231                                 this_urb, this_urb->status);
232
233                 dbg("%s: endpoint %d buf %d", __FUNCTION__,
234                         usb_pipeendpoint(this_urb->pipe), i);
235
236                 /* send the data */
237                 memcpy (this_urb->transfer_buffer, buf, todo);
238                 this_urb->transfer_buffer_length = todo;
239
240                 this_urb->dev = port->serial->dev;
241                 err = usb_submit_urb(this_urb, GFP_ATOMIC);
242                 if (err) {
243                         dbg("usb_submit_urb %p (write bulk) failed "
244                                 "(%d, has %d)", this_urb,
245                                 err, this_urb->status);
246                         continue;
247                 }
248                 portdata->tx_start_time[i] = jiffies;
249                 buf += todo;
250                 left -= todo;
251         }
252
253         count -= left;
254         dbg("%s: wrote (did %d)", __FUNCTION__, count);
255         return count;
256 }
257
258 static void sierra_indat_callback(struct urb *urb)
259 {
260         int err;
261         int endpoint;
262         struct usb_serial_port *port;
263         struct tty_struct *tty;
264         unsigned char *data = urb->transfer_buffer;
265
266         dbg("%s: %p", __FUNCTION__, urb);
267
268         endpoint = usb_pipeendpoint(urb->pipe);
269         port = (struct usb_serial_port *) urb->context;
270
271         if (urb->status) {
272                 dbg("%s: nonzero status: %d on endpoint %02x.",
273                     __FUNCTION__, urb->status, endpoint);
274         } else {
275                 tty = port->tty;
276                 if (urb->actual_length) {
277                         tty_buffer_request_room(tty, urb->actual_length);
278                         tty_insert_flip_string(tty, data, urb->actual_length);
279                         tty_flip_buffer_push(tty);
280                 } else {
281                         dbg("%s: empty read urb received", __FUNCTION__);
282                 }
283
284                 /* Resubmit urb so we continue receiving */
285                 if (port->open_count && urb->status != -ESHUTDOWN) {
286                         err = usb_submit_urb(urb, GFP_ATOMIC);
287                         if (err)
288                                 printk(KERN_ERR "%s: resubmit read urb failed. "
289                                         "(%d)", __FUNCTION__, err);
290                 }
291         }
292         return;
293 }
294
295 static void sierra_outdat_callback(struct urb *urb)
296 {
297         struct usb_serial_port *port;
298
299         dbg("%s", __FUNCTION__);
300
301         port = (struct usb_serial_port *) urb->context;
302
303         usb_serial_port_softint(port);
304 }
305
306 static void sierra_instat_callback(struct urb *urb)
307 {
308         int err;
309         struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
310         struct sierra_port_private *portdata = usb_get_serial_port_data(port);
311         struct usb_serial *serial = port->serial;
312
313         dbg("%s", __FUNCTION__);
314         dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
315
316         if (urb->status == 0) {
317                 struct usb_ctrlrequest *req_pkt =
318                                 (struct usb_ctrlrequest *)urb->transfer_buffer;
319
320                 if (!req_pkt) {
321                         dbg("%s: NULL req_pkt\n", __FUNCTION__);
322                         return;
323                 }
324                 if ((req_pkt->bRequestType == 0xA1) &&
325                                 (req_pkt->bRequest == 0x20)) {
326                         int old_dcd_state;
327                         unsigned char signals = *((unsigned char *)
328                                         urb->transfer_buffer +
329                                         sizeof(struct usb_ctrlrequest));
330
331                         dbg("%s: signal x%x", __FUNCTION__, signals);
332
333                         old_dcd_state = portdata->dcd_state;
334                         portdata->cts_state = 1;
335                         portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
336                         portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
337                         portdata->ri_state = ((signals & 0x08) ? 1 : 0);
338
339                         if (port->tty && !C_CLOCAL(port->tty) &&
340                                         old_dcd_state && !portdata->dcd_state)
341                                 tty_hangup(port->tty);
342                 } else {
343                         dbg("%s: type %x req %x", __FUNCTION__,
344                                 req_pkt->bRequestType,req_pkt->bRequest);
345                 }
346         } else
347                 dbg("%s: error %d", __FUNCTION__, urb->status);
348
349         /* Resubmit urb so we continue receiving IRQ data */
350         if (urb->status != -ESHUTDOWN) {
351                 urb->dev = serial->dev;
352                 err = usb_submit_urb(urb, GFP_ATOMIC);
353                 if (err)
354                         dbg("%s: resubmit intr urb failed. (%d)",
355                                 __FUNCTION__, err);
356         }
357 }
358
359 static int sierra_write_room(struct usb_serial_port *port)
360 {
361         struct sierra_port_private *portdata;
362         int i;
363         int data_len = 0;
364         struct urb *this_urb;
365
366         portdata = usb_get_serial_port_data(port);
367
368         for (i=0; i < N_OUT_URB; i++) {
369                 this_urb = portdata->out_urbs[i];
370                 if (this_urb && this_urb->status != -EINPROGRESS)
371                         data_len += OUT_BUFLEN;
372         }
373
374         dbg("%s: %d", __FUNCTION__, data_len);
375         return data_len;
376 }
377
378 static int sierra_chars_in_buffer(struct usb_serial_port *port)
379 {
380         struct sierra_port_private *portdata;
381         int i;
382         int data_len = 0;
383         struct urb *this_urb;
384
385         portdata = usb_get_serial_port_data(port);
386
387         for (i=0; i < N_OUT_URB; i++) {
388                 this_urb = portdata->out_urbs[i];
389                 if (this_urb && this_urb->status == -EINPROGRESS)
390                         data_len += this_urb->transfer_buffer_length;
391         }
392         dbg("%s: %d", __FUNCTION__, data_len);
393         return data_len;
394 }
395
396 static int sierra_open(struct usb_serial_port *port, struct file *filp)
397 {
398         struct sierra_port_private *portdata;
399         struct usb_serial *serial = port->serial;
400         int i, err;
401         struct urb *urb;
402         int result;
403         __u16 set_mode_dzero = 0x0000;
404
405         portdata = usb_get_serial_port_data(port);
406
407         dbg("%s", __FUNCTION__);
408
409         /* Set some sane defaults */
410         portdata->rts_state = 1;
411         portdata->dtr_state = 1;
412
413         /* Reset low level data toggle and start reading from endpoints */
414         for (i = 0; i < N_IN_URB; i++) {
415                 urb = portdata->in_urbs[i];
416                 if (! urb)
417                         continue;
418                 if (urb->dev != serial->dev) {
419                         dbg("%s: dev %p != %p", __FUNCTION__,
420                                 urb->dev, serial->dev);
421                         continue;
422                 }
423
424                 /*
425                  * make sure endpoint data toggle is synchronized with the
426                  * device
427                  */
428                 usb_clear_halt(urb->dev, urb->pipe);
429
430                 err = usb_submit_urb(urb, GFP_KERNEL);
431                 if (err) {
432                         dbg("%s: submit urb %d failed (%d) %d",
433                                 __FUNCTION__, i, err,
434                                 urb->transfer_buffer_length);
435                 }
436         }
437
438         /* Reset low level data toggle on out endpoints */
439         for (i = 0; i < N_OUT_URB; i++) {
440                 urb = portdata->out_urbs[i];
441                 if (! urb)
442                         continue;
443                 urb->dev = serial->dev;
444                 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
445                                 usb_pipeout(urb->pipe), 0); */
446         }
447
448         port->tty->low_latency = 1;
449
450         /* set mode to D0 */
451         result = usb_control_msg(serial->dev,
452                                  usb_rcvctrlpipe(serial->dev, 0),
453                                  0x00, 0x40, set_mode_dzero, 0, NULL,
454                                  0, USB_CTRL_SET_TIMEOUT);
455
456         sierra_send_setup(port);
457
458         return (0);
459 }
460
461 static void sierra_close(struct usb_serial_port *port, struct file *filp)
462 {
463         int i;
464         struct usb_serial *serial = port->serial;
465         struct sierra_port_private *portdata;
466
467         dbg("%s", __FUNCTION__);
468         portdata = usb_get_serial_port_data(port);
469
470         portdata->rts_state = 0;
471         portdata->dtr_state = 0;
472
473         if (serial->dev) {
474                 sierra_send_setup(port);
475
476                 /* Stop reading/writing urbs */
477                 for (i = 0; i < N_IN_URB; i++)
478                         usb_unlink_urb(portdata->in_urbs[i]);
479                 for (i = 0; i < N_OUT_URB; i++)
480                         usb_unlink_urb(portdata->out_urbs[i]);
481         }
482         port->tty = NULL;
483 }
484
485 /* Helper functions used by sierra_setup_urbs */
486 static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint,
487                                     int dir, void *ctx, char *buf, int len,
488                                     usb_complete_t callback)
489 {
490         struct urb *urb;
491
492         if (endpoint == -1)
493                 return NULL;            /* endpoint not needed */
494
495         urb = usb_alloc_urb(0, GFP_KERNEL);             /* No ISO */
496         if (urb == NULL) {
497                 dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
498                 return NULL;
499         }
500
501                 /* Fill URB using supplied data. */
502         usb_fill_bulk_urb(urb, serial->dev,
503                       usb_sndbulkpipe(serial->dev, endpoint) | dir,
504                       buf, len, callback, ctx);
505
506         return urb;
507 }
508
509 /* Setup urbs */
510 static void sierra_setup_urbs(struct usb_serial *serial)
511 {
512         int i,j;
513         struct usb_serial_port *port;
514         struct sierra_port_private *portdata;
515
516         dbg("%s", __FUNCTION__);
517
518         for (i = 0; i < serial->num_ports; i++) {
519                 port = serial->port[i];
520                 portdata = usb_get_serial_port_data(port);
521
522         /* Do indat endpoints first */
523                 for (j = 0; j < N_IN_URB; ++j) {
524                         portdata->in_urbs[j] = sierra_setup_urb (serial,
525                         port->bulk_in_endpointAddress, USB_DIR_IN, port,
526                         portdata->in_buffer[j], IN_BUFLEN, sierra_indat_callback);
527                 }
528
529                 /* outdat endpoints */
530                 for (j = 0; j < N_OUT_URB; ++j) {
531                         portdata->out_urbs[j] = sierra_setup_urb (serial,
532                         port->bulk_out_endpointAddress, USB_DIR_OUT, port,
533                         portdata->out_buffer[j], OUT_BUFLEN, sierra_outdat_callback);
534                 }
535         }
536 }
537
538 static int sierra_startup(struct usb_serial *serial)
539 {
540         int i, err;
541         struct usb_serial_port *port;
542         struct sierra_port_private *portdata;
543
544         dbg("%s", __FUNCTION__);
545
546         /* Now setup per port private data */
547         for (i = 0; i < serial->num_ports; i++) {
548                 port = serial->port[i];
549                 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
550                 if (!portdata) {
551                         dbg("%s: kmalloc for sierra_port_private (%d) failed!.",
552                                         __FUNCTION__, i);
553                         return (1);
554                 }
555
556                 usb_set_serial_port_data(port, portdata);
557
558                 if (! port->interrupt_in_urb)
559                         continue;
560                 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
561                 if (err)
562                         dbg("%s: submit irq_in urb failed %d",
563                                 __FUNCTION__, err);
564         }
565
566         sierra_setup_urbs(serial);
567
568         return (0);
569 }
570
571 static void sierra_shutdown(struct usb_serial *serial)
572 {
573         int i, j;
574         struct usb_serial_port *port;
575         struct sierra_port_private *portdata;
576
577         dbg("%s", __FUNCTION__);
578
579         /* Stop reading/writing urbs */
580         for (i = 0; i < serial->num_ports; ++i) {
581                 port = serial->port[i];
582                 if (!port)
583                         continue;
584                 portdata = usb_get_serial_port_data(port);
585                 if (!portdata)
586                         continue;
587
588                 for (j = 0; j < N_IN_URB; j++)
589                         usb_unlink_urb(portdata->in_urbs[j]);
590                 for (j = 0; j < N_OUT_URB; j++)
591                         usb_unlink_urb(portdata->out_urbs[j]);
592         }
593
594         /* Now free them */
595         for (i = 0; i < serial->num_ports; ++i) {
596                 port = serial->port[i];
597                 if (!port)
598                         continue;
599                 portdata = usb_get_serial_port_data(port);
600                 if (!portdata)
601                         continue;
602
603                 for (j = 0; j < N_IN_URB; j++) {
604                         if (portdata->in_urbs[j]) {
605                                 usb_free_urb(portdata->in_urbs[j]);
606                                 portdata->in_urbs[j] = NULL;
607                         }
608                 }
609                 for (j = 0; j < N_OUT_URB; j++) {
610                         if (portdata->out_urbs[j]) {
611                                 usb_free_urb(portdata->out_urbs[j]);
612                                 portdata->out_urbs[j] = NULL;
613                         }
614                 }
615         }
616
617         /* Now free per port private data */
618         for (i = 0; i < serial->num_ports; i++) {
619                 port = serial->port[i];
620                 if (!port)
621                         continue;
622                 kfree(usb_get_serial_port_data(port));
623         }
624 }
625
626 static struct usb_serial_driver sierra_1port_device = {
627         .driver = {
628                 .owner =        THIS_MODULE,
629                 .name =         "sierra1",
630         },
631         .description       = "Sierra USB modem (1 port)",
632         .id_table          = id_table_1port,
633         .usb_driver        = &sierra_driver,
634         .num_interrupt_in  = NUM_DONT_CARE,
635         .num_bulk_in       = 1,
636         .num_bulk_out      = 1,
637         .num_ports         = 1,
638         .open              = sierra_open,
639         .close             = sierra_close,
640         .write             = sierra_write,
641         .write_room        = sierra_write_room,
642         .chars_in_buffer   = sierra_chars_in_buffer,
643         .throttle          = sierra_rx_throttle,
644         .unthrottle        = sierra_rx_unthrottle,
645         .ioctl             = sierra_ioctl,
646         .set_termios       = sierra_set_termios,
647         .break_ctl         = sierra_break_ctl,
648         .tiocmget          = sierra_tiocmget,
649         .tiocmset          = sierra_tiocmset,
650         .attach            = sierra_startup,
651         .shutdown          = sierra_shutdown,
652         .read_int_callback = sierra_instat_callback,
653 };
654
655 static struct usb_serial_driver sierra_3port_device = {
656         .driver = {
657                 .owner =        THIS_MODULE,
658                 .name =         "sierra3",
659         },
660         .description       = "Sierra USB modem (3 port)",
661         .id_table          = id_table_3port,
662         .usb_driver        = &sierra_driver,
663         .num_interrupt_in  = NUM_DONT_CARE,
664         .num_bulk_in       = 3,
665         .num_bulk_out      = 3,
666         .num_ports         = 3,
667         .open              = sierra_open,
668         .close             = sierra_close,
669         .write             = sierra_write,
670         .write_room        = sierra_write_room,
671         .chars_in_buffer   = sierra_chars_in_buffer,
672         .throttle          = sierra_rx_throttle,
673         .unthrottle        = sierra_rx_unthrottle,
674         .ioctl             = sierra_ioctl,
675         .set_termios       = sierra_set_termios,
676         .break_ctl         = sierra_break_ctl,
677         .tiocmget          = sierra_tiocmget,
678         .tiocmset          = sierra_tiocmset,
679         .attach            = sierra_startup,
680         .shutdown          = sierra_shutdown,
681         .read_int_callback = sierra_instat_callback,
682 };
683
684 /* Functions used by new usb-serial code. */
685 static int __init sierra_init(void)
686 {
687         int retval;
688         retval = usb_serial_register(&sierra_1port_device);
689         if (retval)
690                 goto failed_1port_device_register;
691         retval = usb_serial_register(&sierra_3port_device);
692         if (retval)
693                 goto failed_3port_device_register;
694
695
696         retval = usb_register(&sierra_driver);
697         if (retval)
698                 goto failed_driver_register;
699
700         info(DRIVER_DESC ": " DRIVER_VERSION);
701
702         return 0;
703
704 failed_driver_register:
705         usb_serial_deregister(&sierra_3port_device);
706 failed_3port_device_register:
707         usb_serial_deregister(&sierra_1port_device);
708 failed_1port_device_register:
709         return retval;
710 }
711
712 static void __exit sierra_exit(void)
713 {
714         usb_deregister (&sierra_driver);
715         usb_serial_deregister(&sierra_1port_device);
716         usb_serial_deregister(&sierra_3port_device);
717 }
718
719 module_init(sierra_init);
720 module_exit(sierra_exit);
721
722 MODULE_AUTHOR(DRIVER_AUTHOR);
723 MODULE_DESCRIPTION(DRIVER_DESC);
724 MODULE_VERSION(DRIVER_VERSION);
725 MODULE_LICENSE("GPL");
726
727 #ifdef CONFIG_USB_DEBUG
728 module_param(debug, bool, S_IRUGO | S_IWUSR);
729 MODULE_PARM_DESC(debug, "Debug messages");
730 #endif
731