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