blob: 0794ccdebfd402a94fd4b71c8f661901dc873e56 [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
Kevin Lloyd112225b2007-07-16 13:49:27 -07004 Copyright (C) 2006, 2007 Kevin Lloyd <linux@sierrawireless.com>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -07005
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>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070015*/
16
Kevin Lloyd9454c462007-07-16 13:49:29 -070017#define DRIVER_VERSION "v.1.2.5b"
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070018#define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>"
19#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
Kevin Lloyd69de51f2006-06-30 11:17:55 -070020
21#include <linux/kernel.h>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070022#include <linux/jiffies.h>
23#include <linux/errno.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070024#include <linux/tty.h>
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070025#include <linux/tty_flip.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070026#include <linux/module.h>
27#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070028#include <linux/usb/serial.h>
Kevin Lloyd69de51f2006-06-30 11:17:55 -070029
Kevin Lloyd112225b2007-07-16 13:49:27 -070030#define SWIMS_USB_REQUEST_SetMode 0x0B
31#define SWIMS_USB_REQUEST_TYPE_SetMode 0x40
32#define SWIMS_USB_INDEX_SetMode 0x0000
33#define SWIMS_SET_MODE_Modem 0x0001
34
35/* per port private data */
36#define N_IN_URB 4
37#define N_OUT_URB 4
38#define IN_BUFLEN 4096
39
40static int debug;
41
42enum devicetype {
43 DEVICE_3_PORT = 0,
44 DEVICE_1_PORT = 1,
45 DEVICE_INSTALLER = 2,
46};
47
48int sierra_set_power_state(struct usb_device *udev, __u16 swiState)
49{
50 int result;
51 dev_dbg(&udev->dev, "%s", "SET POWER STATE");
52 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
53 0x00, /* __u8 request */
54 0x40, /* __u8 request type */
55 swiState, /* __u16 value */
56 0, /* __u16 index */
57 NULL, /* void *data */
58 0, /* __u16 size */
59 USB_CTRL_SET_TIMEOUT); /* int timeout */
60 return result;
61}
62
63int sierra_set_ms_mode(struct usb_device *udev, __u16 eSocMode)
64{
65 int result;
66 dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH");
67 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
68 SWIMS_USB_REQUEST_SetMode, /* __u8 request */
69 SWIMS_USB_REQUEST_TYPE_SetMode, /* __u8 request type */
70 eSocMode, /* __u16 value */
71 SWIMS_USB_INDEX_SetMode, /* __u16 index */
72 NULL, /* void *data */
73 0, /* __u16 size */
74 USB_CTRL_SET_TIMEOUT); /* int timeout */
75 return result;
76}
77
78int sierra_probe(struct usb_interface *iface, const struct usb_device_id *id)
79{
80 int result;
81 struct usb_device *udev;
82
83 udev = usb_get_dev(interface_to_usbdev(iface));
84
85 /* Check if in installer mode */
86 if (id->driver_info == DEVICE_INSTALLER) {
87 dev_dbg(&udev->dev, "%s", "FOUND DEVICE(SW)\n");
88 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem);
89 /*We do not want to bind to the device when in installer mode*/
90 return -EIO;
91 }
92
93 return usb_serial_probe(iface, id);
94}
Kevin Lloyd033a3fb2006-10-13 23:53:21 -070095
Kevin Lloyd69de51f2006-06-30 11:17:55 -070096static struct usb_device_id id_table [] = {
Kevin Lloyd69de51f2006-06-30 11:17:55 -070097 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
Kevin Lloyde43062d2007-01-17 16:04:18 -080098 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
Greg Kroah-Hartman90ac3c82002-04-09 12:14:34 -070099 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700100 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800101 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
102 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
103 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700104 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
105
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700106 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800107 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700108 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700109 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700110 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700111 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
112 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
113 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
114 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
115 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
116 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700117
Kevin Lloyd112225b2007-07-16 13:49:27 -0700118 { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */
119 { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */
120
121 { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER},
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700122 { }
123};
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700124MODULE_DEVICE_TABLE(usb, id_table);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700125
126static struct usb_device_id id_table_1port [] = {
127 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
128 { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */
129 { }
130};
131
132static struct usb_device_id id_table_3port [] = {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700133 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800134 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700135 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
Greg Kroah-Hartman90ac3c82002-04-09 12:14:34 -0700136 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800137 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
138 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
139 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700140 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/
Kevin Lloyd112225b2007-07-16 13:49:27 -0700141
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700142 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
Kevin Lloyde43062d2007-01-17 16:04:18 -0800143 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700144 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700145 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700146 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
Kevin Lloyd9454c462007-07-16 13:49:29 -0700147 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
148 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
149 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
150 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
151 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */
152 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700153 { }
154};
155
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700156static struct usb_driver sierra_driver = {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700157 .name = "sierra",
Kevin Lloyd112225b2007-07-16 13:49:27 -0700158 .probe = sierra_probe,
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700159 .disconnect = usb_serial_disconnect,
160 .id_table = id_table,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700161 .no_dynamic_id = 1,
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700162};
163
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700164
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700165struct sierra_port_private {
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900166 spinlock_t lock; /* lock the structure */
167 int outstanding_urbs; /* number of out urbs in flight */
168
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700169 /* Input endpoints and buffer for this port */
170 struct urb *in_urbs[N_IN_URB];
171 char in_buffer[N_IN_URB][IN_BUFLEN];
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700172
173 /* Settings for the port */
174 int rts_state; /* Handshaking pins (outputs) */
175 int dtr_state;
176 int cts_state; /* Handshaking pins (inputs) */
177 int dsr_state;
178 int dcd_state;
179 int ri_state;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700180};
181
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700182static int sierra_send_setup(struct usb_serial_port *port)
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700183{
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700184 struct usb_serial *serial = port->serial;
185 struct sierra_port_private *portdata;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700186
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700187 dbg("%s", __FUNCTION__);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700188
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700189 portdata = usb_get_serial_port_data(port);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700190
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700191 if (port->tty) {
192 int val = 0;
193 if (portdata->dtr_state)
194 val |= 0x01;
195 if (portdata->rts_state)
196 val |= 0x02;
197
198 return usb_control_msg(serial->dev,
199 usb_rcvctrlpipe(serial->dev, 0),
200 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
201 }
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700202
203 return 0;
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700204}
205
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700206static void sierra_rx_throttle(struct usb_serial_port *port)
207{
208 dbg("%s", __FUNCTION__);
209}
210
211static void sierra_rx_unthrottle(struct usb_serial_port *port)
212{
213 dbg("%s", __FUNCTION__);
214}
215
216static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
217{
218 /* Unfortunately, I don't know how to send a break */
219 dbg("%s", __FUNCTION__);
220}
221
222static void sierra_set_termios(struct usb_serial_port *port,
Alan Cox606d0992006-12-08 02:38:45 -0800223 struct ktermios *old_termios)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700224{
225 dbg("%s", __FUNCTION__);
226
227 sierra_send_setup(port);
228}
229
230static int sierra_tiocmget(struct usb_serial_port *port, struct file *file)
231{
232 unsigned int value;
233 struct sierra_port_private *portdata;
234
235 portdata = usb_get_serial_port_data(port);
236
237 value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
238 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
239 ((portdata->cts_state) ? TIOCM_CTS : 0) |
240 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
241 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
242 ((portdata->ri_state) ? TIOCM_RNG : 0);
243
244 return value;
245}
246
247static int sierra_tiocmset(struct usb_serial_port *port, struct file *file,
248 unsigned int set, unsigned int clear)
249{
250 struct sierra_port_private *portdata;
251
252 portdata = usb_get_serial_port_data(port);
253
254 if (set & TIOCM_RTS)
255 portdata->rts_state = 1;
256 if (set & TIOCM_DTR)
257 portdata->dtr_state = 1;
258
259 if (clear & TIOCM_RTS)
260 portdata->rts_state = 0;
261 if (clear & TIOCM_DTR)
262 portdata->dtr_state = 0;
263 return sierra_send_setup(port);
264}
265
266static int sierra_ioctl(struct usb_serial_port *port, struct file *file,
267 unsigned int cmd, unsigned long arg)
268{
269 return -ENOIOCTLCMD;
270}
271
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900272static void sierra_outdat_callback(struct urb *urb)
273{
274 struct usb_serial_port *port = urb->context;
275 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
276 int status = urb->status;
277 unsigned long flags;
278
279 dbg("%s - port %d", __FUNCTION__, port->number);
280
281 /* free up the transfer buffer, as usb_free_urb() does not do this */
282 kfree(urb->transfer_buffer);
283
284 if (status)
285 dbg("%s - nonzero write bulk status received: %d",
286 __FUNCTION__, status);
287
288 spin_lock_irqsave(&portdata->lock, flags);
289 --portdata->outstanding_urbs;
290 spin_unlock_irqrestore(&portdata->lock, flags);
291
292 usb_serial_port_softint(port);
293}
294
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700295/* Write */
296static int sierra_write(struct usb_serial_port *port,
297 const unsigned char *buf, int count)
298{
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900299 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
300 struct usb_serial *serial = port->serial;
301 unsigned long flags;
302 unsigned char *buffer;
303 struct urb *urb;
304 int status;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700305
306 portdata = usb_get_serial_port_data(port);
307
308 dbg("%s: write (%d chars)", __FUNCTION__, count);
309
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900310 spin_lock_irqsave(&portdata->lock, flags);
311 if (portdata->outstanding_urbs > N_OUT_URB) {
312 spin_unlock_irqrestore(&portdata->lock, flags);
313 dbg("%s - write limit hit\n", __FUNCTION__);
314 return 0;
315 }
316 portdata->outstanding_urbs++;
317 spin_unlock_irqrestore(&portdata->lock, flags);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700318
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900319 buffer = kmalloc(count, GFP_ATOMIC);
320 if (!buffer) {
321 dev_err(&port->dev, "out of memory\n");
322 count = -ENOMEM;
323 goto error_no_buffer;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700324 }
325
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900326 urb = usb_alloc_urb(0, GFP_ATOMIC);
327 if (!urb) {
328 dev_err(&port->dev, "no more free urbs\n");
329 count = -ENOMEM;
330 goto error_no_urb;
331 }
332
333 memcpy(buffer, buf, count);
334
335 usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer);
336
337 usb_fill_bulk_urb(urb, serial->dev,
338 usb_sndbulkpipe(serial->dev,
339 port->bulk_out_endpointAddress),
340 buffer, count, sierra_outdat_callback, port);
341
342 /* send it down the pipe */
343 status = usb_submit_urb(urb, GFP_ATOMIC);
344 if (status) {
345 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed "
346 "with status = %d\n", __FUNCTION__, status);
347 count = status;
348 goto error;
349 }
350
351 /* we are done with this urb, so let the host driver
352 * really free it when it is finished with it */
353 usb_free_urb(urb);
354
355 return count;
356error:
357 usb_free_urb(urb);
358error_no_urb:
359 kfree(buffer);
360error_no_buffer:
361 spin_lock_irqsave(&portdata->lock, flags);
362 --portdata->outstanding_urbs;
363 spin_unlock_irqrestore(&portdata->lock, flags);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700364 return count;
365}
366
367static void sierra_indat_callback(struct urb *urb)
368{
369 int err;
370 int endpoint;
371 struct usb_serial_port *port;
372 struct tty_struct *tty;
373 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700374 int status = urb->status;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700375
376 dbg("%s: %p", __FUNCTION__, urb);
377
378 endpoint = usb_pipeendpoint(urb->pipe);
379 port = (struct usb_serial_port *) urb->context;
380
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700381 if (status) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700382 dbg("%s: nonzero status: %d on endpoint %02x.",
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700383 __FUNCTION__, status, endpoint);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700384 } else {
385 tty = port->tty;
386 if (urb->actual_length) {
387 tty_buffer_request_room(tty, urb->actual_length);
388 tty_insert_flip_string(tty, data, urb->actual_length);
389 tty_flip_buffer_push(tty);
390 } else {
391 dbg("%s: empty read urb received", __FUNCTION__);
392 }
393
394 /* Resubmit urb so we continue receiving */
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700395 if (port->open_count && status != -ESHUTDOWN) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700396 err = usb_submit_urb(urb, GFP_ATOMIC);
397 if (err)
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900398 dev_err(&port->dev, "resubmit read urb failed."
399 "(%d)", err);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700400 }
401 }
402 return;
403}
404
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700405static void sierra_instat_callback(struct urb *urb)
406{
407 int err;
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700408 int status = urb->status;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700409 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
410 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
411 struct usb_serial *serial = port->serial;
412
413 dbg("%s", __FUNCTION__);
414 dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
415
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700416 if (status == 0) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700417 struct usb_ctrlrequest *req_pkt =
418 (struct usb_ctrlrequest *)urb->transfer_buffer;
419
420 if (!req_pkt) {
421 dbg("%s: NULL req_pkt\n", __FUNCTION__);
422 return;
423 }
424 if ((req_pkt->bRequestType == 0xA1) &&
425 (req_pkt->bRequest == 0x20)) {
426 int old_dcd_state;
427 unsigned char signals = *((unsigned char *)
428 urb->transfer_buffer +
429 sizeof(struct usb_ctrlrequest));
430
431 dbg("%s: signal x%x", __FUNCTION__, signals);
432
433 old_dcd_state = portdata->dcd_state;
434 portdata->cts_state = 1;
435 portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
436 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
437 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
438
439 if (port->tty && !C_CLOCAL(port->tty) &&
440 old_dcd_state && !portdata->dcd_state)
441 tty_hangup(port->tty);
442 } else {
443 dbg("%s: type %x req %x", __FUNCTION__,
444 req_pkt->bRequestType,req_pkt->bRequest);
445 }
446 } else
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700447 dbg("%s: error %d", __FUNCTION__, status);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700448
449 /* Resubmit urb so we continue receiving IRQ data */
Greg Kroah-Hartman17dd2212007-06-15 15:44:13 -0700450 if (status != -ESHUTDOWN) {
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700451 urb->dev = serial->dev;
452 err = usb_submit_urb(urb, GFP_ATOMIC);
453 if (err)
454 dbg("%s: resubmit intr urb failed. (%d)",
455 __FUNCTION__, err);
456 }
457}
458
459static int sierra_write_room(struct usb_serial_port *port)
460{
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900461 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
462 unsigned long flags;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700463
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900464 dbg("%s - port %d", __FUNCTION__, port->number);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700465
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900466 /* try to give a good number back based on if we have any free urbs at
467 * this point in time */
468 spin_lock_irqsave(&portdata->lock, flags);
469 if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) {
470 spin_unlock_irqrestore(&portdata->lock, flags);
471 dbg("%s - write limit hit\n", __FUNCTION__);
472 return 0;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700473 }
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900474 spin_unlock_irqrestore(&portdata->lock, flags);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700475
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900476 return 2048;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700477}
478
479static int sierra_chars_in_buffer(struct usb_serial_port *port)
480{
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900481 dbg("%s - port %d", __FUNCTION__, port->number);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700482
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900483 /*
484 * We can't really account for how much data we
485 * have sent out, but hasn't made it through to the
486 * device as we can't see the backend here, so just
487 * tell the tty layer that everything is flushed.
488 */
489 return 0;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700490}
491
492static int sierra_open(struct usb_serial_port *port, struct file *filp)
493{
494 struct sierra_port_private *portdata;
495 struct usb_serial *serial = port->serial;
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900496 int i;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700497 struct urb *urb;
Kevin Lloyde43062d2007-01-17 16:04:18 -0800498 int result;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700499
500 portdata = usb_get_serial_port_data(port);
501
502 dbg("%s", __FUNCTION__);
503
504 /* Set some sane defaults */
505 portdata->rts_state = 1;
506 portdata->dtr_state = 1;
507
508 /* Reset low level data toggle and start reading from endpoints */
509 for (i = 0; i < N_IN_URB; i++) {
510 urb = portdata->in_urbs[i];
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900511 if (!urb)
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700512 continue;
513 if (urb->dev != serial->dev) {
514 dbg("%s: dev %p != %p", __FUNCTION__,
515 urb->dev, serial->dev);
516 continue;
517 }
518
519 /*
520 * make sure endpoint data toggle is synchronized with the
521 * device
522 */
523 usb_clear_halt(urb->dev, urb->pipe);
524
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900525 result = usb_submit_urb(urb, GFP_KERNEL);
526 if (result) {
527 dev_err(&port->dev, "submit urb %d failed (%d) %d",
528 i, result, urb->transfer_buffer_length);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700529 }
530 }
531
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700532 port->tty->low_latency = 1;
533
534 sierra_send_setup(port);
535
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900536 /* start up the interrupt endpoint if we have one */
537 if (port->interrupt_in_urb) {
538 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
539 if (result)
540 dev_err(&port->dev, "submit irq_in urb failed %d",
541 result);
542 }
543 return 0;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700544}
545
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700546static void sierra_close(struct usb_serial_port *port, struct file *filp)
547{
548 int i;
549 struct usb_serial *serial = port->serial;
550 struct sierra_port_private *portdata;
551
552 dbg("%s", __FUNCTION__);
553 portdata = usb_get_serial_port_data(port);
554
555 portdata->rts_state = 0;
556 portdata->dtr_state = 0;
557
558 if (serial->dev) {
559 sierra_send_setup(port);
560
561 /* Stop reading/writing urbs */
562 for (i = 0; i < N_IN_URB; i++)
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900563 usb_kill_urb(portdata->in_urbs[i]);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700564 }
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900565
566 usb_kill_urb(port->interrupt_in_urb);
567
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700568 port->tty = NULL;
569}
570
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700571static int sierra_startup(struct usb_serial *serial)
572{
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700573 struct usb_serial_port *port;
574 struct sierra_port_private *portdata;
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900575 struct urb *urb;
576 int i;
577 int j;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700578
579 dbg("%s", __FUNCTION__);
580
Kevin Lloyd112225b2007-07-16 13:49:27 -0700581 /*Set Device mode to D0 */
582 sierra_set_power_state(serial->dev, 0x0000);
583
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700584 /* Now setup per port private data */
585 for (i = 0; i < serial->num_ports; i++) {
586 port = serial->port[i];
587 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
588 if (!portdata) {
589 dbg("%s: kmalloc for sierra_port_private (%d) failed!.",
590 __FUNCTION__, i);
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900591 return -ENOMEM;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700592 }
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900593 spin_lock_init(&portdata->lock);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700594
595 usb_set_serial_port_data(port, portdata);
596
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900597 /* initialize the in urbs */
598 for (j = 0; j < N_IN_URB; ++j) {
599 urb = usb_alloc_urb(0, GFP_KERNEL);
600 if (urb == NULL) {
601 dbg("%s: alloc for in port failed.",
602 __FUNCTION__);
603 continue;
604 }
605 /* Fill URB using supplied data. */
606 usb_fill_bulk_urb(urb, serial->dev,
607 usb_rcvbulkpipe(serial->dev,
608 port->bulk_in_endpointAddress),
609 portdata->in_buffer[j], IN_BUFLEN,
610 sierra_indat_callback, port);
611 portdata->in_urbs[j] = urb;
612 }
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700613 }
614
Greg Kroah-Hartman17c23272007-06-20 14:22:23 +0900615 return 0;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700616}
617
618static void sierra_shutdown(struct usb_serial *serial)
619{
620 int i, j;
621 struct usb_serial_port *port;
622 struct sierra_port_private *portdata;
623
624 dbg("%s", __FUNCTION__);
625
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700626 for (i = 0; i < serial->num_ports; ++i) {
627 port = serial->port[i];
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700628 if (!port)
629 continue;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700630 portdata = usb_get_serial_port_data(port);
Greg Kroah-Hartmanf094e4f2007-04-26 00:12:01 -0700631 if (!portdata)
632 continue;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700633
634 for (j = 0; j < N_IN_URB; j++) {
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900635 usb_kill_urb(portdata->in_urbs[j]);
636 usb_free_urb(portdata->in_urbs[j]);
637 portdata->in_urbs[j] = NULL;
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700638 }
Greg Kroah-Hartman9e85c5f2007-06-20 14:22:23 +0900639 kfree(portdata);
640 usb_set_serial_port_data(port, NULL);
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700641 }
642}
643
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700644static struct usb_serial_driver sierra_1port_device = {
645 .driver = {
646 .owner = THIS_MODULE,
647 .name = "sierra1",
648 },
649 .description = "Sierra USB modem (1 port)",
650 .id_table = id_table_1port,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100651 .usb_driver = &sierra_driver,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700652 .num_interrupt_in = NUM_DONT_CARE,
653 .num_bulk_in = 1,
654 .num_bulk_out = 1,
655 .num_ports = 1,
656 .open = sierra_open,
657 .close = sierra_close,
658 .write = sierra_write,
659 .write_room = sierra_write_room,
660 .chars_in_buffer = sierra_chars_in_buffer,
661 .throttle = sierra_rx_throttle,
662 .unthrottle = sierra_rx_unthrottle,
663 .ioctl = sierra_ioctl,
664 .set_termios = sierra_set_termios,
665 .break_ctl = sierra_break_ctl,
666 .tiocmget = sierra_tiocmget,
667 .tiocmset = sierra_tiocmset,
668 .attach = sierra_startup,
669 .shutdown = sierra_shutdown,
670 .read_int_callback = sierra_instat_callback,
671};
672
673static struct usb_serial_driver sierra_3port_device = {
674 .driver = {
675 .owner = THIS_MODULE,
676 .name = "sierra3",
677 },
678 .description = "Sierra USB modem (3 port)",
679 .id_table = id_table_3port,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100680 .usb_driver = &sierra_driver,
Greg Kroah-Hartman964ee1d2006-10-17 10:17:58 -0700681 .num_interrupt_in = NUM_DONT_CARE,
682 .num_bulk_in = 3,
683 .num_bulk_out = 3,
684 .num_ports = 3,
685 .open = sierra_open,
686 .close = sierra_close,
687 .write = sierra_write,
688 .write_room = sierra_write_room,
689 .chars_in_buffer = sierra_chars_in_buffer,
690 .throttle = sierra_rx_throttle,
691 .unthrottle = sierra_rx_unthrottle,
692 .ioctl = sierra_ioctl,
693 .set_termios = sierra_set_termios,
694 .break_ctl = sierra_break_ctl,
695 .tiocmget = sierra_tiocmget,
696 .tiocmset = sierra_tiocmset,
697 .attach = sierra_startup,
698 .shutdown = sierra_shutdown,
699 .read_int_callback = sierra_instat_callback,
700};
701
702/* Functions used by new usb-serial code. */
703static int __init sierra_init(void)
704{
705 int retval;
706 retval = usb_serial_register(&sierra_1port_device);
707 if (retval)
708 goto failed_1port_device_register;
709 retval = usb_serial_register(&sierra_3port_device);
710 if (retval)
711 goto failed_3port_device_register;
712
713
714 retval = usb_register(&sierra_driver);
715 if (retval)
716 goto failed_driver_register;
717
718 info(DRIVER_DESC ": " DRIVER_VERSION);
719
720 return 0;
721
722failed_driver_register:
723 usb_serial_deregister(&sierra_3port_device);
724failed_3port_device_register:
725 usb_serial_deregister(&sierra_1port_device);
726failed_1port_device_register:
727 return retval;
728}
729
730static void __exit sierra_exit(void)
731{
732 usb_deregister (&sierra_driver);
733 usb_serial_deregister(&sierra_1port_device);
734 usb_serial_deregister(&sierra_3port_device);
735}
736
737module_init(sierra_init);
738module_exit(sierra_exit);
739
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700740MODULE_AUTHOR(DRIVER_AUTHOR);
741MODULE_DESCRIPTION(DRIVER_DESC);
742MODULE_VERSION(DRIVER_VERSION);
Kevin Lloyd69de51f2006-06-30 11:17:55 -0700743MODULE_LICENSE("GPL");
Kevin Lloyd033a3fb2006-10-13 23:53:21 -0700744
745#ifdef CONFIG_USB_DEBUG
746module_param(debug, bool, S_IRUGO | S_IWUSR);
747MODULE_PARM_DESC(debug, "Debug messages");
748#endif
749