blob: 4865aff892e8593484e4aae3cbb2735f2106da14 [file] [log] [blame]
Kevin Lloyd69de51f2006-06-30 11:17:55 -07001/*
Kevin Lloyd033a3fb2006-10-13 23:53:21 -07002 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
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070016*/
17
Kevin Lloyde43062d2007-01-17 16:04:18 -080018#define DRIVER_VERSION "v.1.0.6"
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070019#define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>"
20#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
Kevin Lloyd69de51f2006-06-30 11:17:55 -070021
22#include <linux/kernel.h>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070023#include <linux/jiffies.h>
24#include <linux/errno.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070025#include <linux/tty.h>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070026#include <linux/tty_flip.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070027#include <linux/module.h>
28#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070029#include <linux/usb/serial.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070030
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070031
Kevin Lloyd69de51f2006-06-30 11:17:55 -070032static struct usb_device_id id_table [] = {
Kevin Lloyd69de51f2006-06-30 11:17:55 -070033 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080034 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
Greg Kroah-Hartman90ac3c82002-04-09 12:14:34 -070035 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080036 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
37 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
38 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
Kevin Lloyd69de51f2006-06-30 11:17:55 -070039 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080040 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
Kevin Lloyd69de51f2006-06-30 11:17:55 -070041 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
42 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
43 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070044
45 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
46 { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
Kevin Lloyd69de51f2006-06-30 11:17:55 -070047 { }
48};
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -070049MODULE_DEVICE_TABLE(usb, id_table);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070050
51static struct usb_device_id id_table_1port [] = {
52 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
53 { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
54 { }
55};
56
57static struct usb_device_id id_table_3port [] = {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070058 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080059 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
Greg Kroah-Hartman90ac3c82002-04-09 12:14:34 -070060 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080061 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
62 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
63 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070064 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080065 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070066 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
67 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
68 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
69 { }
70};
71
Kevin Lloyd69de51f2006-06-30 11:17:55 -070072static struct usb_driver sierra_driver = {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070073 .name = "sierra",
74 .probe = usb_serial_probe,
75 .disconnect = usb_serial_disconnect,
76 .id_table = id_table,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -070077 .no_dynamic_id = 1,
Kevin Lloyd69de51f2006-06-30 11:17:55 -070078};
79
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070080
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070081static int debug;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070082
83/* per port private data */
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -070084#define N_IN_URB 4
Kevin Lloyde43062d2007-01-17 16:04:18 -080085#define N_OUT_URB 4
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -070086#define IN_BUFLEN 4096
87#define OUT_BUFLEN 128
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070088
89struct sierra_port_private {
90 /* Input endpoints and buffer for this port */
91 struct urb *in_urbs[N_IN_URB];
92 char in_buffer[N_IN_URB][IN_BUFLEN];
93 /* Output endpoints and buffer for this port */
94 struct urb *out_urbs[N_OUT_URB];
95 char out_buffer[N_OUT_URB][OUT_BUFLEN];
96
97 /* Settings for the port */
98 int rts_state; /* Handshaking pins (outputs) */
99 int dtr_state;
100 int cts_state; /* Handshaking pins (inputs) */
101 int dsr_state;
102 int dcd_state;
103 int ri_state;
104
105 unsigned long tx_start_time[N_OUT_URB];
106};
107
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700108static int sierra_send_setup(struct usb_serial_port *port)
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700109{
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700110 struct usb_serial *serial = port->serial;
111 struct sierra_port_private *portdata;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700112
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700113 dbg("%s", __FUNCTION__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700114
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700115 portdata = usb_get_serial_port_data(port);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700116
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700117 if (port->tty) {
118 int val = 0;
119 if (portdata->dtr_state)
120 val |= 0x01;
121 if (portdata->rts_state)
122 val |= 0x02;
123
124 return usb_control_msg(serial->dev,
125 usb_rcvctrlpipe(serial->dev, 0),
126 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
127 }
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700128
129 return 0;
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700130}
131
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700132static void sierra_rx_throttle(struct usb_serial_port *port)
133{
134 dbg("%s", __FUNCTION__);
135}
136
137static void sierra_rx_unthrottle(struct usb_serial_port *port)
138{
139 dbg("%s", __FUNCTION__);
140}
141
142static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
143{
144 /* Unfortunately, I don't know how to send a break */
145 dbg("%s", __FUNCTION__);
146}
147
148static void sierra_set_termios(struct usb_serial_port *port,
Alan Cox606d0992006-12-08 02:38:45 -0800149 struct ktermios *old_termios)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700150{
151 dbg("%s", __FUNCTION__);
152
153 sierra_send_setup(port);
154}
155
156static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
157{
158 unsigned int value;
159 struct sierra_port_private *portdata;
160
161 portdata = usb_get_serial_port_data(port);
162
163 value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
164 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
165 ((portdata->cts_state) ? TIOCM_CTS : 0) |
166 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
167 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
168 ((portdata->ri_state) ? TIOCM_RNG : 0);
169
170 return value;
171}
172
173static int sierra_tiocmset(struct usb_serial_port *port, struct file *file,
174 unsigned int set, unsigned int clear)
175{
176 struct sierra_port_private *portdata;
177
178 portdata = usb_get_serial_port_data(port);
179
180 if (set & TIOCM_RTS)
181 portdata->rts_state = 1;
182 if (set & TIOCM_DTR)
183 portdata->dtr_state = 1;
184
185 if (clear & TIOCM_RTS)
186 portdata->rts_state = 0;
187 if (clear & TIOCM_DTR)
188 portdata->dtr_state = 0;
189 return sierra_send_setup(port);
190}
191
192static int sierra_ioctl(struct usb_serial_port *port, struct file *file,
193 unsigned int cmd, unsigned long arg)
194{
195 return -ENOIOCTLCMD;
196}
197
198/* Write */
199static int sierra_write(struct usb_serial_port *port,
200 const unsigned char *buf, int count)
201{
202 struct sierra_port_private *portdata;
203 int i;
204 int left, todo;
205 struct urb *this_urb = NULL; /* spurious */
206 int err;
207
208 portdata = usb_get_serial_port_data(port);
209
210 dbg("%s: write (%d chars)", __FUNCTION__, count);
211
212 i = 0;
213 left = count;
214 for (i=0; left > 0 && i < N_OUT_URB; i++) {
215 todo = left;
216 if (todo > OUT_BUFLEN)
217 todo = OUT_BUFLEN;
218
219 this_urb = portdata->out_urbs[i];
220 if (this_urb->status == -EINPROGRESS) {
221 if (time_before(jiffies,
222 portdata->tx_start_time[i] + 10 * HZ))
223 continue;
224 usb_unlink_urb(this_urb);
225 continue;
226 }
227 if (this_urb->status != 0)
228 dbg("usb_write %p failed (err=%d)",
229 this_urb, this_urb->status);
230
231 dbg("%s: endpoint %d buf %d", __FUNCTION__,
232 usb_pipeendpoint(this_urb->pipe), i);
233
234 /* send the data */
235 memcpy (this_urb->transfer_buffer, buf, todo);
236 this_urb->transfer_buffer_length = todo;
237
238 this_urb->dev = port->serial->dev;
239 err = usb_submit_urb(this_urb, GFP_ATOMIC);
240 if (err) {
241 dbg("usb_submit_urb %p (write bulk) failed "
242 "(%d, has %d)", this_urb,
243 err, this_urb->status);
244 continue;
245 }
246 portdata->tx_start_time[i] = jiffies;
247 buf += todo;
248 left -= todo;
249 }
250
251 count -= left;
252 dbg("%s: wrote (did %d)", __FUNCTION__, count);
253 return count;
254}
255
256static void sierra_indat_callback(struct urb *urb)
257{
258 int err;
259 int endpoint;
260 struct usb_serial_port *port;
261 struct tty_struct *tty;
262 unsigned char *data = urb->transfer_buffer;
263
264 dbg("%s: %p", __FUNCTION__, urb);
265
266 endpoint = usb_pipeendpoint(urb->pipe);
267 port = (struct usb_serial_port *) urb->context;
268
269 if (urb->status) {
270 dbg("%s: nonzero status: %d on endpoint %02x.",
271 __FUNCTION__, urb->status, endpoint);
272 } else {
273 tty = port->tty;
274 if (urb->actual_length) {
275 tty_buffer_request_room(tty, urb->actual_length);
276 tty_insert_flip_string(tty, data, urb->actual_length);
277 tty_flip_buffer_push(tty);
278 } else {
279 dbg("%s: empty read urb received", __FUNCTION__);
280 }
281
282 /* Resubmit urb so we continue receiving */
283 if (port->open_count && urb->status != -ESHUTDOWN) {
284 err = usb_submit_urb(urb, GFP_ATOMIC);
285 if (err)
286 printk(KERN_ERR "%s: resubmit read urb failed. "
287 "(%d)", __FUNCTION__, err);
288 }
289 }
290 return;
291}
292
293static void sierra_outdat_callback(struct urb *urb)
294{
295 struct usb_serial_port *port;
296
297 dbg("%s", __FUNCTION__);
298
299 port = (struct usb_serial_port *) urb->context;
300
301 usb_serial_port_softint(port);
302}
303
304static void sierra_instat_callback(struct urb *urb)
305{
306 int err;
307 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
308 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
309 struct usb_serial *serial = port->serial;
310
311 dbg("%s", __FUNCTION__);
312 dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
313
314 if (urb->status == 0) {
315 struct usb_ctrlrequest *req_pkt =
316 (struct usb_ctrlrequest *)urb->transfer_buffer;
317
318 if (!req_pkt) {
319 dbg("%s: NULL req_pkt\n", __FUNCTION__);
320 return;
321 }
322 if ((req_pkt->bRequestType == 0xA1) &&
323 (req_pkt->bRequest == 0x20)) {
324 int old_dcd_state;
325 unsigned char signals = *((unsigned char *)
326 urb->transfer_buffer +
327 sizeof(struct usb_ctrlrequest));
328
329 dbg("%s: signal x%x", __FUNCTION__, signals);
330
331 old_dcd_state = portdata->dcd_state;
332 portdata->cts_state = 1;
333 portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
334 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
335 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
336
337 if (port->tty && !C_CLOCAL(port->tty) &&
338 old_dcd_state && !portdata->dcd_state)
339 tty_hangup(port->tty);
340 } else {
341 dbg("%s: type %x req %x", __FUNCTION__,
342 req_pkt->bRequestType,req_pkt->bRequest);
343 }
344 } else
345 dbg("%s: error %d", __FUNCTION__, urb->status);
346
347 /* Resubmit urb so we continue receiving IRQ data */
348 if (urb->status != -ESHUTDOWN) {
349 urb->dev = serial->dev;
350 err = usb_submit_urb(urb, GFP_ATOMIC);
351 if (err)
352 dbg("%s: resubmit intr urb failed. (%d)",
353 __FUNCTION__, err);
354 }
355}
356
357static int sierra_write_room(struct usb_serial_port *port)
358{
359 struct sierra_port_private *portdata;
360 int i;
361 int data_len = 0;
362 struct urb *this_urb;
363
364 portdata = usb_get_serial_port_data(port);
365
366 for (i=0; i < N_OUT_URB; i++) {
367 this_urb = portdata->out_urbs[i];
368 if (this_urb && this_urb->status != -EINPROGRESS)
369 data_len += OUT_BUFLEN;
370 }
371
372 dbg("%s: %d", __FUNCTION__, data_len);
373 return data_len;
374}
375
376static int sierra_chars_in_buffer(struct usb_serial_port *port)
377{
378 struct sierra_port_private *portdata;
379 int i;
380 int data_len = 0;
381 struct urb *this_urb;
382
383 portdata = usb_get_serial_port_data(port);
384
385 for (i=0; i < N_OUT_URB; i++) {
386 this_urb = portdata->out_urbs[i];
387 if (this_urb && this_urb->status == -EINPROGRESS)
388 data_len += this_urb->transfer_buffer_length;
389 }
390 dbg("%s: %d", __FUNCTION__, data_len);
391 return data_len;
392}
393
394static int sierra_open(struct usb_serial_port *port, struct file *filp)
395{
396 struct sierra_port_private *portdata;
397 struct usb_serial *serial = port->serial;
398 int i, err;
399 struct urb *urb;
Kevin Lloyde43062d2007-01-17 16:04:18 -0800400 int result;
401 __u16 set_mode_dzero = 0x0000;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700402
403 portdata = usb_get_serial_port_data(port);
404
405 dbg("%s", __FUNCTION__);
406
407 /* Set some sane defaults */
408 portdata->rts_state = 1;
409 portdata->dtr_state = 1;
410
411 /* Reset low level data toggle and start reading from endpoints */
412 for (i = 0; i < N_IN_URB; i++) {
413 urb = portdata->in_urbs[i];
414 if (! urb)
415 continue;
416 if (urb->dev != serial->dev) {
417 dbg("%s: dev %p != %p", __FUNCTION__,
418 urb->dev, serial->dev);
419 continue;
420 }
421
422 /*
423 * make sure endpoint data toggle is synchronized with the
424 * device
425 */
426 usb_clear_halt(urb->dev, urb->pipe);
427
428 err = usb_submit_urb(urb, GFP_KERNEL);
429 if (err) {
430 dbg("%s: submit urb %d failed (%d) %d",
431 __FUNCTION__, i, err,
432 urb->transfer_buffer_length);
433 }
434 }
435
436 /* Reset low level data toggle on out endpoints */
437 for (i = 0; i < N_OUT_URB; i++) {
438 urb = portdata->out_urbs[i];
439 if (! urb)
440 continue;
441 urb->dev = serial->dev;
442 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
443 usb_pipeout(urb->pipe), 0); */
444 }
445
446 port->tty->low_latency = 1;
447
Kevin Lloyde43062d2007-01-17 16:04:18 -0800448 /* set mode to D0 */
449 result = usb_control_msg(serial->dev,
450 usb_rcvctrlpipe(serial->dev, 0),
451 0x00, 0x40, set_mode_dzero, 0, NULL,
452 0, USB_CTRL_SET_TIMEOUT);
453
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700454 sierra_send_setup(port);
455
456 return (0);
457}
458
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700459static void sierra_close(struct usb_serial_port *port, struct file *filp)
460{
461 int i;
462 struct usb_serial *serial = port->serial;
463 struct sierra_port_private *portdata;
464
465 dbg("%s", __FUNCTION__);
466 portdata = usb_get_serial_port_data(port);
467
468 portdata->rts_state = 0;
469 portdata->dtr_state = 0;
470
471 if (serial->dev) {
472 sierra_send_setup(port);
473
474 /* Stop reading/writing urbs */
475 for (i = 0; i < N_IN_URB; i++)
Oliver Neukumebcf3ed2007-03-20 13:54:05 +0100476 usb_unlink_urb(portdata->in_urbs[i]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700477 for (i = 0; i < N_OUT_URB; i++)
Oliver Neukumebcf3ed2007-03-20 13:54:05 +0100478 usb_unlink_urb(portdata->out_urbs[i]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700479 }
480 port->tty = NULL;
481}
482
483/* Helper functions used by sierra_setup_urbs */
484static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700485 int dir, void *ctx, char *buf, int len,
486 usb_complete_t callback)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700487{
488 struct urb *urb;
489
490 if (endpoint == -1)
491 return NULL; /* endpoint not needed */
492
493 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
494 if (urb == NULL) {
495 dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
496 return NULL;
497 }
498
499 /* Fill URB using supplied data. */
500 usb_fill_bulk_urb(urb, serial->dev,
501 usb_sndbulkpipe(serial->dev, endpoint) | dir,
502 buf, len, callback, ctx);
503
504 return urb;
505}
506
507/* Setup urbs */
508static void sierra_setup_urbs(struct usb_serial *serial)
509{
510 int i,j;
511 struct usb_serial_port *port;
512 struct sierra_port_private *portdata;
513
514 dbg("%s", __FUNCTION__);
515
516 for (i = 0; i < serial->num_ports; i++) {
517 port = serial->port[i];
518 portdata = usb_get_serial_port_data(port);
519
520 /* Do indat endpoints first */
521 for (j = 0; j < N_IN_URB; ++j) {
522 portdata->in_urbs[j] = sierra_setup_urb (serial,
523 port->bulk_in_endpointAddress, USB_DIR_IN, port,
524 portdata->in_buffer[j], IN_BUFLEN, sierra_indat_callback);
525 }
526
527 /* outdat endpoints */
528 for (j = 0; j < N_OUT_URB; ++j) {
529 portdata->out_urbs[j] = sierra_setup_urb (serial,
530 port->bulk_out_endpointAddress, USB_DIR_OUT, port,
531 portdata->out_buffer[j], OUT_BUFLEN, sierra_outdat_callback);
532 }
533 }
534}
535
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700536static int sierra_startup(struct usb_serial *serial)
537{
538 int i, err;
539 struct usb_serial_port *port;
540 struct sierra_port_private *portdata;
541
542 dbg("%s", __FUNCTION__);
543
544 /* Now setup per port private data */
545 for (i = 0; i < serial->num_ports; i++) {
546 port = serial->port[i];
547 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
548 if (!portdata) {
549 dbg("%s: kmalloc for sierra_port_private (%d) failed!.",
550 __FUNCTION__, i);
551 return (1);
552 }
553
554 usb_set_serial_port_data(port, portdata);
555
556 if (! port->interrupt_in_urb)
557 continue;
558 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
559 if (err)
560 dbg("%s: submit irq_in urb failed %d",
561 __FUNCTION__, err);
562 }
563
564 sierra_setup_urbs(serial);
565
566 return (0);
567}
568
569static void sierra_shutdown(struct usb_serial *serial)
570{
571 int i, j;
572 struct usb_serial_port *port;
573 struct sierra_port_private *portdata;
574
575 dbg("%s", __FUNCTION__);
576
577 /* Stop reading/writing urbs */
578 for (i = 0; i < serial->num_ports; ++i) {
579 port = serial->port[i];
580 portdata = usb_get_serial_port_data(port);
581 for (j = 0; j < N_IN_URB; j++)
Oliver Neukumebcf3ed2007-03-20 13:54:05 +0100582 usb_unlink_urb(portdata->in_urbs[j]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700583 for (j = 0; j < N_OUT_URB; j++)
Oliver Neukumebcf3ed2007-03-20 13:54:05 +0100584 usb_unlink_urb(portdata->out_urbs[j]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700585 }
586
587 /* Now free them */
588 for (i = 0; i < serial->num_ports; ++i) {
589 port = serial->port[i];
590 portdata = usb_get_serial_port_data(port);
591
592 for (j = 0; j < N_IN_URB; j++) {
593 if (portdata->in_urbs[j]) {
594 usb_free_urb(portdata->in_urbs[j]);
595 portdata->in_urbs[j] = NULL;
596 }
597 }
598 for (j = 0; j < N_OUT_URB; j++) {
599 if (portdata->out_urbs[j]) {
600 usb_free_urb(portdata->out_urbs[j]);
601 portdata->out_urbs[j] = NULL;
602 }
603 }
604 }
605
606 /* Now free per port private data */
607 for (i = 0; i < serial->num_ports; i++) {
608 port = serial->port[i];
609 kfree(usb_get_serial_port_data(port));
610 }
611}
612
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700613static struct usb_serial_driver sierra_1port_device = {
614 .driver = {
615 .owner = THIS_MODULE,
616 .name = "sierra1",
617 },
618 .description = "Sierra USB modem (1 port)",
619 .id_table = id_table_1port,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100620 .usb_driver = &sierra_driver,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700621 .num_interrupt_in = NUM_DONT_CARE,
622 .num_bulk_in = 1,
623 .num_bulk_out = 1,
624 .num_ports = 1,
625 .open = sierra_open,
626 .close = sierra_close,
627 .write = sierra_write,
628 .write_room = sierra_write_room,
629 .chars_in_buffer = sierra_chars_in_buffer,
630 .throttle = sierra_rx_throttle,
631 .unthrottle = sierra_rx_unthrottle,
632 .ioctl = sierra_ioctl,
633 .set_termios = sierra_set_termios,
634 .break_ctl = sierra_break_ctl,
635 .tiocmget = sierra_tiocmget,
636 .tiocmset = sierra_tiocmset,
637 .attach = sierra_startup,
638 .shutdown = sierra_shutdown,
639 .read_int_callback = sierra_instat_callback,
640};
641
642static struct usb_serial_driver sierra_3port_device = {
643 .driver = {
644 .owner = THIS_MODULE,
645 .name = "sierra3",
646 },
647 .description = "Sierra USB modem (3 port)",
648 .id_table = id_table_3port,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100649 .usb_driver = &sierra_driver,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700650 .num_interrupt_in = NUM_DONT_CARE,
651 .num_bulk_in = 3,
652 .num_bulk_out = 3,
653 .num_ports = 3,
654 .open = sierra_open,
655 .close = sierra_close,
656 .write = sierra_write,
657 .write_room = sierra_write_room,
658 .chars_in_buffer = sierra_chars_in_buffer,
659 .throttle = sierra_rx_throttle,
660 .unthrottle = sierra_rx_unthrottle,
661 .ioctl = sierra_ioctl,
662 .set_termios = sierra_set_termios,
663 .break_ctl = sierra_break_ctl,
664 .tiocmget = sierra_tiocmget,
665 .tiocmset = sierra_tiocmset,
666 .attach = sierra_startup,
667 .shutdown = sierra_shutdown,
668 .read_int_callback = sierra_instat_callback,
669};
670
671/* Functions used by new usb-serial code. */
672static int __init sierra_init(void)
673{
674 int retval;
675 retval = usb_serial_register(&sierra_1port_device);
676 if (retval)
677 goto failed_1port_device_register;
678 retval = usb_serial_register(&sierra_3port_device);
679 if (retval)
680 goto failed_3port_device_register;
681
682
683 retval = usb_register(&sierra_driver);
684 if (retval)
685 goto failed_driver_register;
686
687 info(DRIVER_DESC ": " DRIVER_VERSION);
688
689 return 0;
690
691failed_driver_register:
692 usb_serial_deregister(&sierra_3port_device);
693failed_3port_device_register:
694 usb_serial_deregister(&sierra_1port_device);
695failed_1port_device_register:
696 return retval;
697}
698
699static void __exit sierra_exit(void)
700{
701 usb_deregister (&sierra_driver);
702 usb_serial_deregister(&sierra_1port_device);
703 usb_serial_deregister(&sierra_3port_device);
704}
705
706module_init(sierra_init);
707module_exit(sierra_exit);
708
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700709MODULE_AUTHOR(DRIVER_AUTHOR);
710MODULE_DESCRIPTION(DRIVER_DESC);
711MODULE_VERSION(DRIVER_VERSION);
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700712MODULE_LICENSE("GPL");
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700713
714#ifdef CONFIG_USB_DEBUG
715module_param(debug, bool, S_IRUGO | S_IWUSR);
716MODULE_PARM_DESC(debug, "Debug messages");
717#endif
718