2 USB Driver for Sierra Wireless
4 Copyright (C) 2006, 2007, 2008 Kevin Lloyd <klloyd@sierrawireless.com>
6 Copyright (C) 2008, 2009 Elina Pasheva, Matthew Safar, Rory Filer
7 <linux@sierrawireless.com>
9 IMPORTANT DISCLAIMER: This driver is not commercially supported by
10 Sierra Wireless. Use at your own risk.
12 This driver is free software; you can redistribute it and/or modify
13 it under the terms of Version 2 of the GNU General Public License as
14 published by the Free Software Foundation.
16 Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de>
17 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org>
19 Back ported to kernel 2.6.23
21 /* Uncomment to log function calls */
23 #define DRIVER_VERSION "v.1.7.0"
24 #define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer"
25 #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
27 #include <linux/kernel.h>
28 #include <linux/jiffies.h>
29 #include <linux/errno.h>
30 #include <linux/tty.h>
31 #include <linux/tty_flip.h>
32 #include <linux/module.h>
33 #include <linux/usb.h>
34 #include <linux/usb/serial.h>
36 #define SWIMS_USB_REQUEST_SetPower 0x00
37 #define SWIMS_USB_REQUEST_SetNmea 0x07
38 #define SWIMS_USB_REQUEST_SetMode 0x0B
39 #define SWIMS_SET_MODE_Modem 0x0001
43 #define IN_BUFLEN 4096
45 #define MAX_TRANSFER (PAGE_SIZE - 512)
46 /* MAX_TRANSFER is chosen so that the VM is not stressed by
47 allocations > PAGE_SIZE and the number of packets in a page
48 is an integer 512 is the largest possible packet on EHCI */
52 static int truinstall
= 1;
53 static int suspend_support
;
60 /* list of interface numbers - used for constructing interface blacklists */
62 const u32 listlen
; /* number of interface numbers on list */
63 const u8
*list
; /* pointer to the array holding the numbers */
66 /* static device type specific data */
67 struct sierra_device_static_info
{
68 const enum devicetype dev_type
;
69 const struct list iface_blacklist
;
72 static int sierra_set_power_state(struct usb_device
*udev
, __u16 swiState
)
75 dev_dbg(&udev
->dev
, "%s\n", __func__
);
76 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
77 SWIMS_USB_REQUEST_SetPower
, /* __u8 request */
78 USB_TYPE_VENDOR
, /* __u8 request type */
79 swiState
, /* __u16 value */
81 NULL
, /* void *data */
83 USB_CTRL_SET_TIMEOUT
); /* int timeout */
87 static int sierra_set_ms_mode(struct usb_device
*udev
, __u16 eSWocMode
)
90 dev_dbg(&udev
->dev
, "%s\n", "DEVICE MODE SWITCH");
91 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
92 SWIMS_USB_REQUEST_SetMode
, /* __u8 request */
93 USB_TYPE_VENDOR
, /* __u8 request type */
94 eSWocMode
, /* __u16 value */
95 0x0000, /* __u16 index */
96 NULL
, /* void *data */
98 USB_CTRL_SET_TIMEOUT
); /* int timeout */
102 static int sierra_vsc_set_nmea(struct usb_device
*udev
, __u16 enable
)
105 dev_dbg(&udev
->dev
, "%s\n", __func__
);
106 result
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0),
107 SWIMS_USB_REQUEST_SetNmea
, /* __u8 request */
108 USB_TYPE_VENDOR
, /* __u8 request type */
109 enable
, /* __u16 value */
110 0x0000, /* __u16 index */
111 NULL
, /* void *data */
113 USB_CTRL_SET_TIMEOUT
); /* int timeout */
117 static int sierra_calc_num_ports(struct usb_serial
*serial
)
120 u8 ifnum
, numendpoints
;
122 dev_dbg(&serial
->dev
->dev
, "%s\n", __func__
);
124 ifnum
= serial
->interface
->cur_altsetting
->desc
.bInterfaceNumber
;
125 numendpoints
= serial
->interface
->cur_altsetting
->desc
.bNumEndpoints
;
127 /* Dummy interface present on some SKUs should be ignored */
130 else if (numendpoints
<= 3)
133 num_ports
= (numendpoints
-1)/2;
137 static int is_blacklisted(const u8 ifnum
, const struct list
*blacklist
)
143 list
= blacklist
->list
;
145 for (i
=0; i
< blacklist
->listlen
; i
++) {
146 if (list
[i
] == ifnum
)
153 static int sierra_calc_interface(struct usb_serial
*serial
)
156 struct usb_interface
*p_interface
;
157 struct usb_host_interface
*p_host_interface
;
158 dev_dbg(&serial
->dev
->dev
, "%s\n", __func__
);
160 /* Get the interface structure pointer from the serial struct */
161 p_interface
= serial
->interface
;
163 /* Get a pointer to the host interface structure */
164 p_host_interface
= p_interface
->cur_altsetting
;
166 /* read the interface descriptor for this active altsetting
167 * to find out the interface number we are on
169 interface
= p_host_interface
->desc
.bInterfaceNumber
;
174 static int sierra_probe(struct usb_serial
*serial
,
175 const struct usb_device_id
*id
)
177 const struct sierra_device_static_info
* info
;
179 struct usb_device
*udev
;
183 dev_dbg(&udev
->dev
, "%s\n", __func__
);
185 /* Check TRU-Install first */
186 info
= (const struct sierra_device_static_info
*)id
->driver_info
;
187 ifclass
= serial
->interface
->cur_altsetting
->desc
.bInterfaceClass
;
188 if (ifclass
== USB_CLASS_MASS_STORAGE
) {
189 /* If TRU-Install support is enabled, force to modem mode */
190 if (truinstall
&& info
&& info
->dev_type
== DEVICE_INSTALLER
) {
191 dev_dbg(&udev
->dev
, "%s\n", "FOUND TRU-INSTALL DEVICE");
192 result
= sierra_set_ms_mode(udev
, SWIMS_SET_MODE_Modem
);
197 ifnum
= sierra_calc_interface(serial
);
198 if (info
&& is_blacklisted(ifnum
, &info
->iface_blacklist
)) {
199 dev_dbg(&serial
->dev
->dev
,
200 "Ignoring blacklisted interface #%d\n", ifnum
);
205 * If this interface supports more than 1 alternate
208 if (serial
->interface
->num_altsetting
== 2) {
209 dev_dbg(&udev
->dev
, "Selecting alt setting for interface %d\n",
211 /* We know the alternate setting is 1 for the MC8785 */
212 usb_set_interface(udev
, ifnum
, 1);
214 /* Be careful here, The ifnum, ifclass etc. might be incorrect, because
215 * of the usb_set_interface call. (all obtained using
216 * serial->interface->cur_altsetting that was changed by that call)
222 static const struct sierra_device_static_info tru_inst_info
= {
223 .dev_type
= DEVICE_INSTALLER
,
226 static const u8 direct_ip_non_serial_ifaces
[] = { 7, 8, 9, 10, 11 };
227 static const struct sierra_device_static_info direct_ip_interface_blacklist
= {
228 .dev_type
= DEVICE_MODEM
,
230 .listlen
= ARRAY_SIZE( direct_ip_non_serial_ifaces
),
231 .list
= direct_ip_non_serial_ifaces
,
235 static struct usb_device_id id_table
[] = {
236 { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */
237 { USB_DEVICE(0x03f0, 0x1B1D) }, /* HP ev2200 a.k.a MC5720 */
238 { USB_DEVICE(0x03F0, 0x211D) }, /* HP ev2210 a.k.a MC5725 */
239 { USB_DEVICE(0x03F0, 0x1E1D) }, /* HP hs2300 a.k.a MC8775 */
241 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
242 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
243 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
244 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
245 { USB_DEVICE(0x1199, 0x0024) }, /* Sierra Wireless MC5727 */
246 { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
247 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
248 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
249 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
250 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
251 { USB_DEVICE(0x1199, 0x0301) }, /* Sierra Wireless USB Dongle 250U */
252 /* Sierra Wireless C597 */
253 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0023, 0xFF, 0xFF, 0xFF) },
254 /* Sierra Wireless Device */
255 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x0025, 0xFF, 0xFF, 0xFF) },
256 { USB_DEVICE(0x1199, 0x0026) }, /* Sierra Wireless Device */
257 { USB_DEVICE(0x1199, 0x0027) }, /* Sierra Wireless Device */
258 { USB_DEVICE(0x1199, 0x0028) }, /* Sierra Wireless Device */
260 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
261 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
262 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
263 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
264 { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Lenovo) */
265 { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */
266 { USB_DEVICE(0x03f0, 0x1e1d) }, /* HP hs2300 a.k.a MC8775 */
267 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
268 { USB_DEVICE(0x1199, 0x6821) }, /* Sierra Wireless AirCard 875U */
269 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780 */
270 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */
271 { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */
272 { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */
273 /* Sierra Wireless MC8790, MC8791, MC8792 Composite */
274 { USB_DEVICE(0x1199, 0x683C) },
275 { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */
276 /* Sierra Wireless MC8790, MC8791, MC8792 */
277 { USB_DEVICE(0x1199, 0x683E) },
278 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
279 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
280 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
281 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
282 { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */
283 { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */
284 { USB_DEVICE(0x1199, 0x6859) }, /* Sierra Wireless AirCard 885 E */
285 { USB_DEVICE(0x1199, 0x685A) }, /* Sierra Wireless AirCard 885 E */
286 /* Sierra Wireless C885 */
287 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6880, 0xFF, 0xFF, 0xFF)},
288 /* Sierra Wireless Device */
289 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6890, 0xFF, 0xFF, 0xFF)},
290 /* Sierra Wireless Device */
291 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6891, 0xFF, 0xFF, 0xFF)},
292 /* Sierra Wireless Device */
293 { USB_DEVICE_AND_INTERFACE_INFO(0x1199, 0x6892, 0xFF, 0xFF, 0xFF)},
295 { USB_DEVICE(0x1199, 0x0FFF),
296 .driver_info
= (kernel_ulong_t
)&tru_inst_info
299 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */
300 .driver_info
= (kernel_ulong_t
)&direct_ip_interface_blacklist
302 { USB_DEVICE(0x0f3d, 0x68A3), /* Airprime/Sierra Wireless Direct IP modems */
303 .driver_info
= (kernel_ulong_t
)&direct_ip_interface_blacklist
305 { USB_DEVICE(0x413C, 0x08133) }, /* Dell Computer Corp. Wireless 5720 VZW Mobile Broadband (EVDO Rev-A) Minicard GPS Port */
309 MODULE_DEVICE_TABLE(usb
, id_table
);
311 /* per port private data */
312 struct sierra_port_private
{
313 spinlock_t lock
; /* lock the structure */
314 int outstanding_urbs
; /* number of out urbs in flight */
316 /* Input endpoints and buffers for this port */
317 struct urb
*in_urbs
[N_IN_URB
];
319 /* Settings for the port */
320 int rts_state
; /* Handshaking pins (outputs) */
322 int cts_state
; /* Handshaking pins (inputs) */
328 static int sierra_send_setup(struct usb_serial_port
*port
)
330 struct usb_serial
*serial
= port
->serial
;
331 struct sierra_port_private
*portdata
;
334 dev_dbg(&port
->dev
, "%s\n", __func__
);
336 portdata
= usb_get_serial_port_data(port
);
341 if (portdata
->dtr_state
)
343 if (portdata
->rts_state
)
346 /* If composite device then properly report interface */
347 if (serial
->num_ports
== 1) {
348 interface
= sierra_calc_interface(serial
);
349 /* Control message is send only to interfaces with
350 * interrupt_in endpoints
352 if(port
->interrupt_in_urb
) {
353 /* send control message */
354 return usb_control_msg(serial
->dev
,
355 usb_rcvctrlpipe(serial
->dev
, 0),
356 0x22, 0x21, val
, interface
,
357 NULL
, 0, USB_CTRL_SET_TIMEOUT
);
361 /* Otherwise the need to do non-composite mapping */
363 if (port
->bulk_out_endpointAddress
== 2)
365 else if (port
->bulk_out_endpointAddress
== 4)
367 else if (port
->bulk_out_endpointAddress
== 5)
370 return usb_control_msg(serial
->dev
,
371 usb_rcvctrlpipe(serial
->dev
, 0),
372 0x22, 0x21, val
, interface
,
373 NULL
, 0, USB_CTRL_SET_TIMEOUT
);
381 static void sierra_set_termios(struct usb_serial_port
*port
,
382 struct ktermios
*old_termios
)
384 dev_dbg(&port
->dev
, "%s\n", __func__
);
385 tty_termios_copy_hw(port
->tty
->termios
, old_termios
);
386 sierra_send_setup(port
);
389 static int sierra_tiocmget(struct usb_serial_port
*port
, struct file
*file
)
392 struct sierra_port_private
*portdata
;
394 dev_dbg(&port
->dev
, "%s\n", __func__
);
395 portdata
= usb_get_serial_port_data(port
);
397 value
= ((portdata
->rts_state
) ? TIOCM_RTS
: 0) |
398 ((portdata
->dtr_state
) ? TIOCM_DTR
: 0) |
399 ((portdata
->cts_state
) ? TIOCM_CTS
: 0) |
400 ((portdata
->dsr_state
) ? TIOCM_DSR
: 0) |
401 ((portdata
->dcd_state
) ? TIOCM_CAR
: 0) |
402 ((portdata
->ri_state
) ? TIOCM_RNG
: 0);
407 static int sierra_tiocmset(struct usb_serial_port
*port
, struct file
*file
,
408 unsigned int set
, unsigned int clear
)
410 struct sierra_port_private
*portdata
;
412 portdata
= usb_get_serial_port_data(port
);
415 portdata
->rts_state
= 1;
417 portdata
->dtr_state
= 1;
419 if (clear
& TIOCM_RTS
)
420 portdata
->rts_state
= 0;
421 if (clear
& TIOCM_DTR
)
422 portdata
->dtr_state
= 0;
423 return sierra_send_setup(port
);
425 static void sierra_release_urb(struct urb
*urb
)
427 struct usb_serial_port
*port
;
430 dev_dbg(&port
->dev
, "%s: %p\n", __func__
, urb
);
431 if (urb
->transfer_buffer
)
432 kfree(urb
->transfer_buffer
);
437 static void sierra_outdat_callback(struct urb
*urb
)
439 struct usb_serial_port
*port
= urb
->context
;
440 struct sierra_port_private
*portdata
= usb_get_serial_port_data(port
);
441 int status
= urb
->status
;
444 dev_dbg(&port
->dev
, "%s - port %d\n", __func__
, port
->number
);
446 /* free up the transfer buffer, as usb_free_urb() does not do this */
447 kfree(urb
->transfer_buffer
);
450 dev_dbg(&port
->dev
, "%s - nonzero write bulk status "
451 "received: %d\n", __func__
, status
);
453 spin_lock_irqsave(&portdata
->lock
, flags
);
454 --portdata
->outstanding_urbs
;
455 spin_unlock_irqrestore(&portdata
->lock
, flags
);
457 usb_serial_port_softint(port
);
461 static int sierra_write(struct usb_serial_port
*port
,
462 const unsigned char *buf
, int count
)
464 struct sierra_port_private
*portdata
= usb_get_serial_port_data(port
);
465 struct usb_serial
*serial
= port
->serial
;
467 unsigned char *buffer
;
469 size_t writesize
= min((size_t)count
, (size_t)MAX_TRANSFER
);
472 /* verify that we actually have some data to write */
476 portdata
= usb_get_serial_port_data(port
);
478 dev_dbg(&port
->dev
, "%s: write (%d bytes)\n", __func__
, writesize
);
480 spin_lock_irqsave(&portdata
->lock
, flags
);
481 if (portdata
->outstanding_urbs
> N_OUT_URB
) {
482 spin_unlock_irqrestore(&portdata
->lock
, flags
);
483 dev_dbg(&port
->dev
, "%s - write limit hit\n", __func__
);
486 portdata
->outstanding_urbs
++;
487 spin_unlock_irqrestore(&portdata
->lock
, flags
);
489 buffer
= kmalloc(writesize
, GFP_ATOMIC
);
491 dev_err(&port
->dev
, "out of memory\n");
493 goto error_no_buffer
;
496 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
498 dev_err(&port
->dev
, "no more free urbs\n");
503 memcpy(buffer
, buf
, writesize
);
505 usb_serial_debug_data(debug
, &port
->dev
, __func__
, writesize
, buffer
);
507 usb_fill_bulk_urb(urb
, serial
->dev
,
508 usb_sndbulkpipe(serial
->dev
,
509 port
->bulk_out_endpointAddress
),
510 buffer
, writesize
, sierra_outdat_callback
, port
);
512 /* Handle the need to send a zero length packet */
513 urb
->transfer_flags
|= URB_ZERO_PACKET
;
515 /* send it down the pipe */
516 retval
= usb_submit_urb(urb
, GFP_ATOMIC
);
518 dev_err(&port
->dev
, "%s - usb_submit_urb(write bulk) failed "
519 "with status = %d\n", __func__
, retval
);
523 /* we are done with this urb, so let the host driver
524 * really free it when it is finished with it */
533 spin_lock_irqsave(&portdata
->lock
, flags
);
534 --portdata
->outstanding_urbs
;
535 spin_unlock_irqrestore(&portdata
->lock
, flags
);
539 static void sierra_indat_callback(struct urb
*urb
)
543 struct usb_serial_port
*port
;
544 struct tty_struct
*tty
;
545 unsigned char *data
= urb
->transfer_buffer
;
546 int status
= urb
->status
;
548 endpoint
= usb_pipeendpoint(urb
->pipe
);
551 dev_dbg(&port
->dev
, "%s: %p\n", __func__
, urb
);
554 dev_dbg(&port
->dev
, "%s: nonzero status: %d on"
555 " endpoint %02x\n", __func__
, status
, endpoint
);
558 if (urb
->actual_length
) {
559 tty_buffer_request_room(tty
, urb
->actual_length
);
560 tty_insert_flip_string(tty
, data
, urb
->actual_length
);
561 tty_flip_buffer_push(tty
);
562 usb_serial_debug_data(debug
, &port
->dev
, __func__
,
563 urb
->actual_length
, data
);
565 dev_dbg(&port
->dev
, "%s: empty read urb"
566 " received\n", __func__
);
570 /* Resubmit urb so we continue receiving */
571 if (port
->open_count
&& status
!= -ESHUTDOWN
&& status
!= -ENOENT
) {
572 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
574 dev_err(&port
->dev
, "resubmit read urb failed."
581 static void sierra_instat_callback(struct urb
*urb
)
584 int status
= urb
->status
;
585 struct usb_serial_port
*port
= urb
->context
;
586 struct sierra_port_private
*portdata
= usb_get_serial_port_data(port
);
587 struct usb_serial
*serial
= port
->serial
;
589 dev_dbg(&port
->dev
, "%s: urb %p port %p has data %p\n", __func__
,
590 urb
, port
, portdata
);
593 struct usb_ctrlrequest
*req_pkt
=
594 (struct usb_ctrlrequest
*)urb
->transfer_buffer
;
597 dev_dbg(&port
->dev
, "%s: NULL req_pkt\n",
601 if ((req_pkt
->bRequestType
== 0xA1) &&
602 (req_pkt
->bRequest
== 0x20)) {
604 unsigned char signals
= *((unsigned char *)
605 urb
->transfer_buffer
+
606 sizeof(struct usb_ctrlrequest
));
608 dev_dbg(&port
->dev
, "%s: signal x%x\n", __func__
,
611 old_dcd_state
= portdata
->dcd_state
;
612 portdata
->cts_state
= 1;
613 portdata
->dcd_state
= ((signals
& 0x01) ? 1 : 0);
614 portdata
->dsr_state
= ((signals
& 0x02) ? 1 : 0);
615 portdata
->ri_state
= ((signals
& 0x08) ? 1 : 0);
617 if (port
->tty
&& !C_CLOCAL(port
->tty
) &&
618 old_dcd_state
&& !portdata
->dcd_state
)
619 tty_hangup(port
->tty
);
621 dev_dbg(&port
->dev
, "%s: type %x req %x\n",
622 __func__
, req_pkt
->bRequestType
,
626 dev_dbg(&port
->dev
, "%s: error %d\n", __func__
, status
);
628 /* Resubmit urb so we continue receiving IRQ data */
629 if (port
->open_count
&& status
!= -ESHUTDOWN
&& status
!= -ENOENT
) {
630 urb
->dev
= serial
->dev
;
631 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
633 dev_err(&port
->dev
, "%s: resubmit intr urb "
634 "failed. (%d)\n", __func__
, err
);
638 static int sierra_write_room(struct usb_serial_port
*port
)
640 struct sierra_port_private
*portdata
= usb_get_serial_port_data(port
);
643 dev_dbg(&port
->dev
, "%s - port %d\n", __func__
, port
->number
);
645 /* try to give a good number back based on if we have any free urbs at
646 * this point in time */
647 spin_lock_irqsave(&portdata
->lock
, flags
);
648 if (portdata
->outstanding_urbs
> N_OUT_URB
* 2 / 3) {
649 spin_unlock_irqrestore(&portdata
->lock
, flags
);
650 dev_dbg(&port
->dev
, "%s - write limit hit\n", __func__
);
653 spin_unlock_irqrestore(&portdata
->lock
, flags
);
658 static void sierra_stop_rx_urbs(struct usb_serial_port
*port
)
661 struct sierra_port_private
*portdata
= usb_get_serial_port_data(port
);
663 for (i
= 0; i
< ARRAY_SIZE(portdata
->in_urbs
); i
++) {
664 usb_kill_urb(portdata
->in_urbs
[i
]);
666 usb_kill_urb(port
->interrupt_in_urb
);
669 static int sierra_submit_rx_urbs(struct usb_serial_port
*port
)
675 struct sierra_port_private
*portdata
= usb_get_serial_port_data(port
);
678 for (i
= 0; i
< ARRAY_SIZE(portdata
->in_urbs
); i
++) {
679 urb
= portdata
->in_urbs
[i
];
682 err
= usb_submit_urb(urb
, GFP_KERNEL
);
684 dev_err(&port
->dev
, "%s: submit urb failed: %d\n",
691 if (ok_cnt
&& port
->interrupt_in_urb
) {
692 err
= usb_submit_urb(port
->interrupt_in_urb
, GFP_KERNEL
);
694 dev_err(&port
->dev
, "%s: submit intr urb failed: %d\n",
699 if (ok_cnt
> 0) /* at least one rx urb submitted */
705 static struct urb
*sierra_setup_urb(struct usb_serial
*serial
, int endpoint
,
706 int dir
, void *ctx
, int len
,
707 usb_complete_t callback
)
715 urb
= usb_alloc_urb( 0, GFP_KERNEL
);
717 dev_dbg(&serial
->dev
->dev
, "%s: alloc for endpoint %d failed\n",
722 buf
= kmalloc(len
, GFP_KERNEL
);
725 /* Fill URB using supplied data */
726 usb_fill_bulk_urb(urb
, serial
->dev
,
727 usb_sndbulkpipe(serial
->dev
, endpoint
) | dir
,
728 buf
, len
, callback
, ctx
);
731 dev_dbg(&serial
->dev
->dev
,"%s %c u:%p d:%p\n", __func__
,
732 dir
== USB_DIR_IN
?'i':'o', urb
, buf
);
734 dev_dbg(&serial
->dev
->dev
,"%s %c u:%p d:%p\n", __func__
,
735 dir
== USB_DIR_IN
?'i':'o', urb
, buf
);
737 sierra_release_urb(urb
);
744 static void sierra_close(struct usb_serial_port
*port
, struct file
*filp
)
747 struct usb_serial
*serial
= port
->serial
;
748 struct sierra_port_private
*portdata
;
750 dev_dbg(&port
->dev
, "%s\n", __func__
);
751 portdata
= usb_get_serial_port_data(port
);
753 portdata
->rts_state
= 0;
754 portdata
->dtr_state
= 0;
757 mutex_lock(&serial
->disc_mutex
);
758 if (!serial
->disconnected
)
759 sierra_send_setup(port
);
760 mutex_unlock(&serial
->disc_mutex
);
762 /* Stop reading urbs */
763 sierra_stop_rx_urbs(port
);
764 /* .. and release them */
765 for (i
= 0; i
< N_IN_URB
; i
++) {
766 sierra_release_urb(portdata
->in_urbs
[i
]);
767 portdata
->in_urbs
[i
] = NULL
;
774 static int sierra_open(struct usb_serial_port
*port
, struct file
*filp
)
776 struct sierra_port_private
*portdata
;
777 struct usb_serial
*serial
= port
->serial
;
783 portdata
= usb_get_serial_port_data(port
);
785 dev_dbg(&port
->dev
, "%s\n", __func__
);
787 /* Set some sane defaults */
788 portdata
->rts_state
= 1;
789 portdata
->dtr_state
= 1;
792 spin_lock_init(&portdata
->lock
);
794 endpoint
= port
->bulk_in_endpointAddress
;
796 for (i
= 0; i
< ARRAY_SIZE(portdata
->in_urbs
); i
++) {
797 urb
= sierra_setup_urb(serial
, endpoint
, USB_DIR_IN
, port
,
798 IN_BUFLEN
, sierra_indat_callback
);
799 portdata
->in_urbs
[i
] = urb
;
801 /* clear halt condition */
802 usb_clear_halt(serial
->dev
,
803 usb_sndbulkpipe(serial
->dev
, endpoint
) | USB_DIR_IN
);
805 err
= sierra_submit_rx_urbs(port
);
807 /* get rid of everything as in close */
808 sierra_close(port
, filp
);
811 sierra_send_setup(port
);
816 static int sierra_startup(struct usb_serial
*serial
)
818 struct usb_serial_port
*port
;
819 struct sierra_port_private
*portdata
;
822 dev_dbg(&serial
->dev
->dev
, "%s\n", __func__
);
824 /* Set Device mode to D0 */
825 sierra_set_power_state(serial
->dev
, 0x0000);
827 /* Check NMEA and set */
829 sierra_vsc_set_nmea(serial
->dev
, 1);
831 /* Now setup per port private data */
832 for (i
= 0; i
< serial
->num_ports
; i
++) {
833 port
= serial
->port
[i
];
834 portdata
= kzalloc(sizeof(*portdata
), GFP_KERNEL
);
836 dev_dbg(&port
->dev
, "%s: kmalloc for "
837 "sierra_port_private (%d) failed!\n",
841 /* Set the port private data pointer */
842 usb_set_serial_port_data(port
, portdata
);
848 static void sierra_shutdown(struct usb_serial
*serial
)
851 struct usb_serial_port
*port
;
852 struct sierra_port_private
*portdata
;
854 dev_dbg(&serial
->dev
->dev
, "%s\n", __func__
);
856 for (i
= 0; i
< serial
->num_ports
; ++i
) {
857 port
= serial
->port
[i
];
860 portdata
= usb_get_serial_port_data(port
);
864 usb_set_serial_port_data(port
, NULL
);
868 int sierra_suspend(struct usb_serial
*serial
, pm_message_t message
)
872 dev_dbg(&serial
->dev
->dev
, "%s\n", __func__
);
874 /* The dummy interface doesn't prevent suspended state */
875 if (serial
->num_ports
== 0)
878 if (!suspend_support
)
881 for (i
=0; i
< serial
->num_ports
; i
++) {
882 sierra_stop_rx_urbs(serial
->port
[i
]);
887 int sierra_resume(struct usb_serial
*serial
)
891 dev_dbg(&serial
->dev
->dev
, "%s\n", __func__
);
893 for (i
=0; i
< serial
->num_ports
; i
++) {
894 sierra_submit_rx_urbs(serial
->port
[i
]);
900 static struct usb_driver sierra_driver
= {
902 .probe
= usb_serial_probe
,
903 .disconnect
= usb_serial_disconnect
,
904 .suspend
= usb_serial_suspend
,
905 .resume
= usb_serial_resume
,
906 .id_table
= id_table
,
909 .supports_autosuspend
= 1,
912 static struct usb_serial_driver sierra_device
= {
914 .owner
= THIS_MODULE
,
917 .description
= "Sierra USB modem",
918 .id_table
= id_table
,
919 .usb_driver
= &sierra_driver
,
920 .num_interrupt_in
= NUM_DONT_CARE
,
921 .num_bulk_in
= NUM_DONT_CARE
,
922 .num_bulk_out
= NUM_DONT_CARE
,
923 .calc_num_ports
= sierra_calc_num_ports
,
924 .probe
= sierra_probe
,
926 .close
= sierra_close
,
927 .write
= sierra_write
,
928 .write_room
= sierra_write_room
,
929 .set_termios
= sierra_set_termios
,
930 .tiocmget
= sierra_tiocmget
,
931 .tiocmset
= sierra_tiocmset
,
932 .attach
= sierra_startup
,
933 .shutdown
= sierra_shutdown
,
934 .read_int_callback
= sierra_instat_callback
,
935 .suspend
= sierra_suspend
,
936 .resume
= sierra_resume
,
939 /* Functions used by new usb-serial code. */
940 static int __init
sierra_init(void)
943 retval
= usb_serial_register(&sierra_device
);
945 goto failed_device_register
;
948 retval
= usb_register(&sierra_driver
);
950 goto failed_driver_register
;
952 info(DRIVER_DESC
": " DRIVER_VERSION
);
956 failed_driver_register
:
957 usb_serial_deregister(&sierra_device
);
958 failed_device_register
:
962 static void __exit
sierra_exit(void)
964 usb_deregister(&sierra_driver
);
965 usb_serial_deregister(&sierra_device
);
968 module_init(sierra_init
);
969 module_exit(sierra_exit
);
971 MODULE_AUTHOR(DRIVER_AUTHOR
);
972 MODULE_DESCRIPTION(DRIVER_DESC
);
973 MODULE_VERSION(DRIVER_VERSION
);
974 MODULE_LICENSE("GPL");
976 module_param(truinstall
, bool, S_IRUGO
| S_IWUSR
);
977 MODULE_PARM_DESC(truinstall
, "TRU-Install support");
979 module_param(nmea
, bool, S_IRUGO
| S_IWUSR
);
980 MODULE_PARM_DESC(nmea
, "NMEA streaming");
982 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
983 MODULE_PARM_DESC(debug
, "Debug messages");
985 module_param(suspend_support
, bool, S_IRUGO
| S_IWUSR
);
986 MODULE_PARM_DESC(suspend_support
, "Selective Suspend support");