blob: 6ee0b89a56de5fe58fd302612593345b1fdef374 [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 */
Danny Budik5b7da8f2007-05-04 16:09:37 -040038 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
Kevin Lloyde43062d2007-01-17 16:04:18 -080039 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
Kevin Lloyd69de51f2006-06-30 11:17:55 -070040 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080041 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
Kevin Lloyd69de51f2006-06-30 11:17:55 -070042 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
43 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */
44 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070045
46 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
47 { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
Kevin Lloyd69de51f2006-06-30 11:17:55 -070048 { }
49};
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -070050MODULE_DEVICE_TABLE(usb, id_table);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070051
52static 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
58static struct usb_device_id id_table_3port [] = {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070059 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080060 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
Greg Kroah-Hartman90ac3c82002-04-09 12:14:34 -070061 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080062 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
63 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
Danny Budik5b7da8f2007-05-04 16:09:37 -040064 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
Kevin Lloyde43062d2007-01-17 16:04:18 -080065 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070066 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080067 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070068 { 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
Kevin Lloyd69de51f2006-06-30 11:17:55 -070074static struct usb_driver sierra_driver = {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070075 .name = "sierra",
76 .probe = usb_serial_probe,
77 .disconnect = usb_serial_disconnect,
78 .id_table = id_table,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -070079 .no_dynamic_id = 1,
Kevin Lloyd69de51f2006-06-30 11:17:55 -070080};
81
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070082
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070083static int debug;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070084
85/* per port private data */
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -070086#define N_IN_URB 4
Kevin Lloyde43062d2007-01-17 16:04:18 -080087#define N_OUT_URB 4
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -070088#define IN_BUFLEN 4096
89#define OUT_BUFLEN 128
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070090
91struct 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
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700110static int sierra_send_setup(struct usb_serial_port *port)
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700111{
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700112 struct usb_serial *serial = port->serial;
113 struct sierra_port_private *portdata;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700114
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700115 dbg("%s", __FUNCTION__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700116
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700117 portdata = usb_get_serial_port_data(port);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700118
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700119 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 }
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700130
131 return 0;
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700132}
133
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700134static void sierra_rx_throttle(struct usb_serial_port *port)
135{
136 dbg("%s", __FUNCTION__);
137}
138
139static void sierra_rx_unthrottle(struct usb_serial_port *port)
140{
141 dbg("%s", __FUNCTION__);
142}
143
144static 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
150static void sierra_set_termios(struct usb_serial_port *port,
Alan Cox606d0992006-12-08 02:38:45 -0800151 struct ktermios *old_termios)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700152{
153 dbg("%s", __FUNCTION__);
154
155 sierra_send_setup(port);
156}
157
158static 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
175static 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
194static 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 */
201static 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
258static 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;
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700265 int status = urb->status;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700266
267 dbg("%s: %p", __FUNCTION__, urb);
268
269 endpoint = usb_pipeendpoint(urb->pipe);
270 port = (struct usb_serial_port *) urb->context;
271
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700272 if (status) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700273 dbg("%s: nonzero status: %d on endpoint %02x.",
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700274 __FUNCTION__, status, endpoint);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700275 } else {
276 tty = port->tty;
277 if (urb->actual_length) {
278 tty_buffer_request_room(tty, urb->actual_length);
279 tty_insert_flip_string(tty, data, urb->actual_length);
280 tty_flip_buffer_push(tty);
281 } else {
282 dbg("%s: empty read urb received", __FUNCTION__);
283 }
284
285 /* Resubmit urb so we continue receiving */
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700286 if (port->open_count && status != -ESHUTDOWN) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700287 err = usb_submit_urb(urb, GFP_ATOMIC);
288 if (err)
289 printk(KERN_ERR "%s: resubmit read urb failed. "
290 "(%d)", __FUNCTION__, err);
291 }
292 }
293 return;
294}
295
296static void sierra_outdat_callback(struct urb *urb)
297{
298 struct usb_serial_port *port;
299
300 dbg("%s", __FUNCTION__);
301
302 port = (struct usb_serial_port *) urb->context;
303
304 usb_serial_port_softint(port);
305}
306
307static void sierra_instat_callback(struct urb *urb)
308{
309 int err;
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700310 int status = urb->status;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700311 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
312 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
313 struct usb_serial *serial = port->serial;
314
315 dbg("%s", __FUNCTION__);
316 dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
317
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700318 if (status == 0) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700319 struct usb_ctrlrequest *req_pkt =
320 (struct usb_ctrlrequest *)urb->transfer_buffer;
321
322 if (!req_pkt) {
323 dbg("%s: NULL req_pkt\n", __FUNCTION__);
324 return;
325 }
326 if ((req_pkt->bRequestType == 0xA1) &&
327 (req_pkt->bRequest == 0x20)) {
328 int old_dcd_state;
329 unsigned char signals = *((unsigned char *)
330 urb->transfer_buffer +
331 sizeof(struct usb_ctrlrequest));
332
333 dbg("%s: signal x%x", __FUNCTION__, signals);
334
335 old_dcd_state = portdata->dcd_state;
336 portdata->cts_state = 1;
337 portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
338 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
339 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
340
341 if (port->tty && !C_CLOCAL(port->tty) &&
342 old_dcd_state && !portdata->dcd_state)
343 tty_hangup(port->tty);
344 } else {
345 dbg("%s: type %x req %x", __FUNCTION__,
346 req_pkt->bRequestType,req_pkt->bRequest);
347 }
348 } else
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700349 dbg("%s: error %d", __FUNCTION__, status);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700350
351 /* Resubmit urb so we continue receiving IRQ data */
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700352 if (status != -ESHUTDOWN) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700353 urb->dev = serial->dev;
354 err = usb_submit_urb(urb, GFP_ATOMIC);
355 if (err)
356 dbg("%s: resubmit intr urb failed. (%d)",
357 __FUNCTION__, err);
358 }
359}
360
361static int sierra_write_room(struct usb_serial_port *port)
362{
363 struct sierra_port_private *portdata;
364 int i;
365 int data_len = 0;
366 struct urb *this_urb;
367
368 portdata = usb_get_serial_port_data(port);
369
370 for (i=0; i < N_OUT_URB; i++) {
371 this_urb = portdata->out_urbs[i];
372 if (this_urb && this_urb->status != -EINPROGRESS)
373 data_len += OUT_BUFLEN;
374 }
375
376 dbg("%s: %d", __FUNCTION__, data_len);
377 return data_len;
378}
379
380static int sierra_chars_in_buffer(struct usb_serial_port *port)
381{
382 struct sierra_port_private *portdata;
383 int i;
384 int data_len = 0;
385 struct urb *this_urb;
386
387 portdata = usb_get_serial_port_data(port);
388
389 for (i=0; i < N_OUT_URB; i++) {
390 this_urb = portdata->out_urbs[i];
391 if (this_urb && this_urb->status == -EINPROGRESS)
392 data_len += this_urb->transfer_buffer_length;
393 }
394 dbg("%s: %d", __FUNCTION__, data_len);
395 return data_len;
396}
397
398static int sierra_open(struct usb_serial_port *port, struct file *filp)
399{
400 struct sierra_port_private *portdata;
401 struct usb_serial *serial = port->serial;
402 int i, err;
403 struct urb *urb;
Kevin Lloyde43062d2007-01-17 16:04:18 -0800404 int result;
405 __u16 set_mode_dzero = 0x0000;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700406
407 portdata = usb_get_serial_port_data(port);
408
409 dbg("%s", __FUNCTION__);
410
411 /* Set some sane defaults */
412 portdata->rts_state = 1;
413 portdata->dtr_state = 1;
414
415 /* Reset low level data toggle and start reading from endpoints */
416 for (i = 0; i < N_IN_URB; i++) {
417 urb = portdata->in_urbs[i];
418 if (! urb)
419 continue;
420 if (urb->dev != serial->dev) {
421 dbg("%s: dev %p != %p", __FUNCTION__,
422 urb->dev, serial->dev);
423 continue;
424 }
425
426 /*
427 * make sure endpoint data toggle is synchronized with the
428 * device
429 */
430 usb_clear_halt(urb->dev, urb->pipe);
431
432 err = usb_submit_urb(urb, GFP_KERNEL);
433 if (err) {
434 dbg("%s: submit urb %d failed (%d) %d",
435 __FUNCTION__, i, err,
436 urb->transfer_buffer_length);
437 }
438 }
439
440 /* Reset low level data toggle on out endpoints */
441 for (i = 0; i < N_OUT_URB; i++) {
442 urb = portdata->out_urbs[i];
443 if (! urb)
444 continue;
445 urb->dev = serial->dev;
446 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
447 usb_pipeout(urb->pipe), 0); */
448 }
449
450 port->tty->low_latency = 1;
451
Kevin Lloyde43062d2007-01-17 16:04:18 -0800452 /* set mode to D0 */
453 result = usb_control_msg(serial->dev,
454 usb_rcvctrlpipe(serial->dev, 0),
455 0x00, 0x40, set_mode_dzero, 0, NULL,
456 0, USB_CTRL_SET_TIMEOUT);
457
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700458 sierra_send_setup(port);
459
460 return (0);
461}
462
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700463static void sierra_close(struct usb_serial_port *port, struct file *filp)
464{
465 int i;
466 struct usb_serial *serial = port->serial;
467 struct sierra_port_private *portdata;
468
469 dbg("%s", __FUNCTION__);
470 portdata = usb_get_serial_port_data(port);
471
472 portdata->rts_state = 0;
473 portdata->dtr_state = 0;
474
475 if (serial->dev) {
476 sierra_send_setup(port);
477
478 /* Stop reading/writing urbs */
479 for (i = 0; i < N_IN_URB; i++)
Oliver Neukumebcf3ed2007-03-20 13:54:05 +0100480 usb_unlink_urb(portdata->in_urbs[i]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700481 for (i = 0; i < N_OUT_URB; i++)
Oliver Neukumebcf3ed2007-03-20 13:54:05 +0100482 usb_unlink_urb(portdata->out_urbs[i]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700483 }
484 port->tty = NULL;
485}
486
487/* Helper functions used by sierra_setup_urbs */
488static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700489 int dir, void *ctx, char *buf, int len,
490 usb_complete_t callback)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700491{
492 struct urb *urb;
493
494 if (endpoint == -1)
495 return NULL; /* endpoint not needed */
496
497 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
498 if (urb == NULL) {
499 dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
500 return NULL;
501 }
502
503 /* Fill URB using supplied data. */
504 usb_fill_bulk_urb(urb, serial->dev,
505 usb_sndbulkpipe(serial->dev, endpoint) | dir,
506 buf, len, callback, ctx);
507
508 return urb;
509}
510
511/* Setup urbs */
512static void sierra_setup_urbs(struct usb_serial *serial)
513{
514 int i,j;
515 struct usb_serial_port *port;
516 struct sierra_port_private *portdata;
517
518 dbg("%s", __FUNCTION__);
519
520 for (i = 0; i < serial->num_ports; i++) {
521 port = serial->port[i];
522 portdata = usb_get_serial_port_data(port);
523
524 /* Do indat endpoints first */
525 for (j = 0; j < N_IN_URB; ++j) {
526 portdata->in_urbs[j] = sierra_setup_urb (serial,
527 port->bulk_in_endpointAddress, USB_DIR_IN, port,
528 portdata->in_buffer[j], IN_BUFLEN, sierra_indat_callback);
529 }
530
531 /* outdat endpoints */
532 for (j = 0; j < N_OUT_URB; ++j) {
533 portdata->out_urbs[j] = sierra_setup_urb (serial,
534 port->bulk_out_endpointAddress, USB_DIR_OUT, port,
535 portdata->out_buffer[j], OUT_BUFLEN, sierra_outdat_callback);
536 }
537 }
538}
539
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700540static int sierra_startup(struct usb_serial *serial)
541{
542 int i, err;
543 struct usb_serial_port *port;
544 struct sierra_port_private *portdata;
545
546 dbg("%s", __FUNCTION__);
547
548 /* Now setup per port private data */
549 for (i = 0; i < serial->num_ports; i++) {
550 port = serial->port[i];
551 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
552 if (!portdata) {
553 dbg("%s: kmalloc for sierra_port_private (%d) failed!.",
554 __FUNCTION__, i);
555 return (1);
556 }
557
558 usb_set_serial_port_data(port, portdata);
559
560 if (! port->interrupt_in_urb)
561 continue;
562 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
563 if (err)
564 dbg("%s: submit irq_in urb failed %d",
565 __FUNCTION__, err);
566 }
567
568 sierra_setup_urbs(serial);
569
570 return (0);
571}
572
573static void sierra_shutdown(struct usb_serial *serial)
574{
575 int i, j;
576 struct usb_serial_port *port;
577 struct sierra_port_private *portdata;
578
579 dbg("%s", __FUNCTION__);
580
581 /* Stop reading/writing urbs */
582 for (i = 0; i < serial->num_ports; ++i) {
583 port = serial->port[i];
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700584 if (!port)
585 continue;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700586 portdata = usb_get_serial_port_data(port);
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700587 if (!portdata)
588 continue;
589
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700590 for (j = 0; j < N_IN_URB; j++)
Oliver Neukumebcf3ed2007-03-20 13:54:05 +0100591 usb_unlink_urb(portdata->in_urbs[j]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700592 for (j = 0; j < N_OUT_URB; j++)
Oliver Neukumebcf3ed2007-03-20 13:54:05 +0100593 usb_unlink_urb(portdata->out_urbs[j]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700594 }
595
596 /* Now free them */
597 for (i = 0; i < serial->num_ports; ++i) {
598 port = serial->port[i];
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700599 if (!port)
600 continue;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700601 portdata = usb_get_serial_port_data(port);
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700602 if (!portdata)
603 continue;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700604
605 for (j = 0; j < N_IN_URB; j++) {
606 if (portdata->in_urbs[j]) {
607 usb_free_urb(portdata->in_urbs[j]);
608 portdata->in_urbs[j] = NULL;
609 }
610 }
611 for (j = 0; j < N_OUT_URB; j++) {
612 if (portdata->out_urbs[j]) {
613 usb_free_urb(portdata->out_urbs[j]);
614 portdata->out_urbs[j] = NULL;
615 }
616 }
617 }
618
619 /* Now free per port private data */
620 for (i = 0; i < serial->num_ports; i++) {
621 port = serial->port[i];
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700622 if (!port)
623 continue;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700624 kfree(usb_get_serial_port_data(port));
625 }
626}
627
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700628static struct usb_serial_driver sierra_1port_device = {
629 .driver = {
630 .owner = THIS_MODULE,
631 .name = "sierra1",
632 },
633 .description = "Sierra USB modem (1 port)",
634 .id_table = id_table_1port,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100635 .usb_driver = &sierra_driver,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700636 .num_interrupt_in = NUM_DONT_CARE,
637 .num_bulk_in = 1,
638 .num_bulk_out = 1,
639 .num_ports = 1,
640 .open = sierra_open,
641 .close = sierra_close,
642 .write = sierra_write,
643 .write_room = sierra_write_room,
644 .chars_in_buffer = sierra_chars_in_buffer,
645 .throttle = sierra_rx_throttle,
646 .unthrottle = sierra_rx_unthrottle,
647 .ioctl = sierra_ioctl,
648 .set_termios = sierra_set_termios,
649 .break_ctl = sierra_break_ctl,
650 .tiocmget = sierra_tiocmget,
651 .tiocmset = sierra_tiocmset,
652 .attach = sierra_startup,
653 .shutdown = sierra_shutdown,
654 .read_int_callback = sierra_instat_callback,
655};
656
657static struct usb_serial_driver sierra_3port_device = {
658 .driver = {
659 .owner = THIS_MODULE,
660 .name = "sierra3",
661 },
662 .description = "Sierra USB modem (3 port)",
663 .id_table = id_table_3port,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100664 .usb_driver = &sierra_driver,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700665 .num_interrupt_in = NUM_DONT_CARE,
666 .num_bulk_in = 3,
667 .num_bulk_out = 3,
668 .num_ports = 3,
669 .open = sierra_open,
670 .close = sierra_close,
671 .write = sierra_write,
672 .write_room = sierra_write_room,
673 .chars_in_buffer = sierra_chars_in_buffer,
674 .throttle = sierra_rx_throttle,
675 .unthrottle = sierra_rx_unthrottle,
676 .ioctl = sierra_ioctl,
677 .set_termios = sierra_set_termios,
678 .break_ctl = sierra_break_ctl,
679 .tiocmget = sierra_tiocmget,
680 .tiocmset = sierra_tiocmset,
681 .attach = sierra_startup,
682 .shutdown = sierra_shutdown,
683 .read_int_callback = sierra_instat_callback,
684};
685
686/* Functions used by new usb-serial code. */
687static int __init sierra_init(void)
688{
689 int retval;
690 retval = usb_serial_register(&sierra_1port_device);
691 if (retval)
692 goto failed_1port_device_register;
693 retval = usb_serial_register(&sierra_3port_device);
694 if (retval)
695 goto failed_3port_device_register;
696
697
698 retval = usb_register(&sierra_driver);
699 if (retval)
700 goto failed_driver_register;
701
702 info(DRIVER_DESC ": " DRIVER_VERSION);
703
704 return 0;
705
706failed_driver_register:
707 usb_serial_deregister(&sierra_3port_device);
708failed_3port_device_register:
709 usb_serial_deregister(&sierra_1port_device);
710failed_1port_device_register:
711 return retval;
712}
713
714static void __exit sierra_exit(void)
715{
716 usb_deregister (&sierra_driver);
717 usb_serial_deregister(&sierra_1port_device);
718 usb_serial_deregister(&sierra_3port_device);
719}
720
721module_init(sierra_init);
722module_exit(sierra_exit);
723
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700724MODULE_AUTHOR(DRIVER_AUTHOR);
725MODULE_DESCRIPTION(DRIVER_DESC);
726MODULE_VERSION(DRIVER_VERSION);
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700727MODULE_LICENSE("GPL");
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700728
729#ifdef CONFIG_USB_DEBUG
730module_param(debug, bool, S_IRUGO | S_IWUSR);
731MODULE_PARM_DESC(debug, "Debug messages");
732#endif
733