fix sierra patches
[openwrt.git] / target / linux / brcm-2.4 / patches / 014-sierra_support.patch
1 diff -Naur linux-2.4.35.4-old/drivers/usb/serial/sierra.c linux-2.4.35.4/drivers/usb/serial/sierra.c
2 --- linux-2.4.35.4-old/drivers/usb/serial/sierra.c 1969-12-31 17:00:00.000000000 -0700
3 +++ linux-2.4.35.4/drivers/usb/serial/sierra.c 2008-01-25 10:21:25.747868456 -0700
4 @@ -0,0 +1,1446 @@
5 +/*
6 + * Sierra Wireless CDMA Wireless Serial USB drive
7 + *
8 + * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
9 + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
10 + *
11 + *
12 + * This program is free software; you can redistribute it and/or
13 + * modify it under the terms of the GNU General Public License version
14 + * 2 as published by the Free Software Foundation.
15 + *
16 + * Version history:
17 + Version 1.03 (Lloyd):
18 + Included support for DTR control and enhanced buffering (should help
19 + speed).
20 + */
21 +
22 +#include <linux/config.h>
23 +#include <linux/kernel.h>
24 +#include <linux/init.h>
25 +#include <linux/slab.h>
26 +#include <linux/tty.h>
27 +#include <linux/tty_driver.h>
28 +#include <linux/tty_flip.h>
29 +#include <linux/module.h>
30 +#include <linux/usb.h>
31 +#include <linux/mm.h>
32 +#include <asm/uaccess.h>
33 +#include <linux/errno.h>
34 +#include <linux/list.h>
35 +#include <linux/spinlock.h>
36 +#include <linux/smp_lock.h>
37 +
38 +#ifdef CONFIG_USB_SERIAL_DEBUG
39 + static int debug = 1;
40 +#else
41 + static int debug;
42 +#endif
43 +
44 +#include "usb-serial.h"
45 +#include "sierra.h"
46 +#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
47 +#include "pl2303.h" // see /* BEGIN HORRIBLE HACK FOR PL2303 */ below
48 +#endif
49 +
50 +#define DRIVER_VERSION "v1.03"
51 +
52 +#if 0
53 +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
54 +
55 +#define USB_DEVICE_POWER_STATE_D0 0x0000
56 +#define USB_DEVICE_POWER_STATE_D1 0x0001
57 +#define USB_DEVICE_POWER_STATE_D2 0x0002
58 +#define USB_DEVICE_POWER_STATE_D3 0x0003
59 +
60 +#define SET_CONTROL_LINE_STATE 0x22
61 +/*
62 + * Output control lines.
63 + */
64 +
65 +#define ACM_CTRL_DTR 0x01
66 +#define ACM_CTRL_RTS 0x02
67 +#endif
68 +
69 +//static int sw_attach(struct usb_serial *serial);
70 +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial);
71 +
72 +static int sw_usb_serial_generic_open(struct usb_serial_port *port, struct file *filp);
73 +static void sw_usb_serial_generic_close(struct usb_serial_port *port, struct file *filp);
74 +
75 +#if 1
76 +/*-----------------------------------------------------------*/
77 +static int serial_refcount;
78 +static struct tty_driver serial_tty_driver;
79 +static struct tty_struct * serial_tty[SERIAL_TTY_MINORS];
80 +static struct termios * serial_termios[SERIAL_TTY_MINORS];
81 +static struct termios * serial_termios_locked[SERIAL_TTY_MINORS];
82 +static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */
83 +
84 +static LIST_HEAD(usb_serial_driver_list);
85 +static struct usb_serial *get_free_serial (int num_ports, int *minor);
86 +static void generic_write_bulk_callback (struct urb *urb);
87 +static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,const struct usb_device_id *id);
88 +static void usb_serial_disconnect(struct usb_device *dev, void *ptr);
89 +static void sw_usb_serial_generic_read_bulk_callback (struct urb *urb);
90 +static void port_softint(void *private);
91 +static void return_serial (struct usb_serial *serial);
92 +static struct usb_serial *get_free_serial (int num_ports, int *minor);
93 +static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data);
94 +/*-----------------------------------------------------------*/
95 +
96 +#endif
97 +
98 +
99 +static struct usb_device_id id_table [] = {
100 + { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
101 + { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
102 + { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
103 + { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
104 + { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
105 + { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
106 + { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
107 + { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
108 + { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
109 + { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless C597 */
110 +
111 + { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
112 + { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
113 + { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
114 + { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
115 + { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */
116 + { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */
117 + { USB_DEVICE(0x03f0, 0x1e1d) }, /* HP hs2300 a.k.a MC8775 */
118 + { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
119 + { USB_DEVICE(0x1199, 0x6821) }, /* Sierra Wireless AirCard 875U */
120 + { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
121 + { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
122 + { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite*/
123 + { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
124 + { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
125 + { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
126 + { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
127 + { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */
128 + { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */
129 + { USB_DEVICE(0x1199, 0x6859) }, /* Sierra Wireless AirCard 885 E */
130 + { USB_DEVICE(0x1199, 0x685A) }, /* Sierra Wireless AirCard 885 E */
131 +
132 + { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */
133 + { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */
134 +
135 + { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
136 + { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra Wireless PC 5220 */
137 + { USB_DEVICE(0x05C6, 0x6613) }, /* Onda H600/ZTE MF330 */
138 + { }
139 +};
140 +
141 +MODULE_DEVICE_TABLE(usb, id_table);
142 +
143 +static struct usb_driver sierra_driver = {
144 +// .owner = THIS_MODULE,
145 + .name = "Sierra wireless",
146 + .probe = usb_serial_probe,
147 + .disconnect = usb_serial_disconnect,
148 + .id_table = id_table,
149 +};
150 +
151 +static struct usb_serial_device_type sierra_device = {
152 +// .driver = {
153 + .owner = THIS_MODULE,
154 + .name = "Sierra Wireless",
155 +// },
156 + .id_table = id_table,
157 + .num_interrupt_in = NUM_DONT_CARE,
158 + .num_bulk_in = NUM_DONT_CARE,
159 + .num_bulk_out = NUM_DONT_CARE,
160 + .num_ports = 3,
161 + //.startup = sw_attach,
162 + .shutdown = sw_usb_serial_generic_shutdown,
163 + .open = sw_usb_serial_generic_open,
164 + .close = sw_usb_serial_generic_close,
165 +};
166 +
167 +#define MAX_NUM_PORTS 8
168 +
169 +/* local function prototypes */
170 +static int serial_open (struct tty_struct *tty, struct file * filp);
171 +static void serial_close (struct tty_struct *tty, struct file * filp);
172 +static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count);
173 +static int serial_write_room (struct tty_struct *tty);
174 +static int serial_chars_in_buffer (struct tty_struct *tty);
175 +static void serial_throttle (struct tty_struct * tty);
176 +static void serial_unthrottle (struct tty_struct * tty);
177 +static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg);
178 +static void serial_set_termios (struct tty_struct *tty, struct termios * old);
179 +//static void serial_shutdown (struct usb_serial *serial);
180 +static void serial_break (struct tty_struct *tty, int break_state);
181 +static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
182 +static int generic_write_room (struct usb_serial_port *port);
183 +static void generic_cleanup (struct usb_serial_port *port);
184 +static int generic_chars_in_buffer (struct usb_serial_port *port);
185 +//static void generic_shutdown (struct usb_serial *serial);
186 +
187 +#if 1
188 +static struct tty_driver serial_tty_driver = {
189 + .magic = TTY_DRIVER_MAGIC,
190 + .driver_name = "usb-serial",
191 +#ifndef CONFIG_DEVFS_FS
192 + .name = "ttyUSB",
193 +#else
194 + .name = "usb/tts/%d",
195 +#endif
196 + .major = SERIAL_TTY_MAJOR,
197 + .minor_start = 0,
198 + .num = SERIAL_TTY_MINORS,
199 + .type = TTY_DRIVER_TYPE_SERIAL,
200 + .subtype = SERIAL_TYPE_NORMAL,
201 + .flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
202 +
203 + .refcount = &serial_refcount,
204 + .table = serial_tty,
205 + .termios = serial_termios,
206 + .termios_locked = serial_termios_locked,
207 +
208 + .open = serial_open,
209 + .close = serial_close,
210 + .write = serial_write,
211 + .write_room = serial_write_room,
212 + .ioctl = serial_ioctl,
213 + .set_termios = serial_set_termios,
214 + .throttle = serial_throttle,
215 + .unthrottle = serial_unthrottle,
216 + .break_ctl = serial_break,
217 + .chars_in_buffer = serial_chars_in_buffer,
218 + .read_proc = serial_read_proc,
219 +};
220 +#endif
221 +
222 +
223 +/*****************************************************************************
224 + * Driver tty interface functions
225 + *****************************************************************************/
226 +static struct usb_serial *get_serial_by_minor (unsigned int minor)
227 +{
228 + return serial_table[minor];
229 +}
230 +
231 +static int serial_open (struct tty_struct *tty, struct file * filp)
232 +{
233 + struct usb_serial *serial;
234 + struct usb_serial_port *port;
235 + unsigned int portNumber;
236 + int retval = 0;
237 +
238 + dbg("%s", __FUNCTION__);
239 +
240 + /* initialize the pointer incase something fails */
241 + tty->driver_data = NULL;
242 +
243 + /* get the serial object associated with this tty pointer */
244 + serial = get_serial_by_minor (MINOR(tty->device));
245 +
246 + if (serial_paranoia_check (serial, __FUNCTION__))
247 + return -ENODEV;
248 +
249 + /* set up our port structure making the tty driver remember our port object, and us it */
250 + portNumber = MINOR(tty->device) - serial->minor;
251 + port = &serial->port[portNumber];
252 + tty->driver_data = port;
253 +
254 + down (&port->sem);
255 + port->tty = tty;
256 +
257 + /* lock this module before we call it */
258 + if (serial->type->owner)
259 + __MOD_INC_USE_COUNT(serial->type->owner);
260 +
261 + ++port->open_count;
262 + if (port->open_count == 1) {
263 + /* only call the device specific open if this
264 + * is the first time the port is opened */
265 + if (serial->type->open)
266 + retval = serial->type->open(port, filp);
267 + else
268 + retval = sw_usb_serial_generic_open(port, filp);//@.@
269 + }
270 +
271 + if (retval) {
272 + port->open_count = 0;
273 + if (serial->type->owner)
274 + __MOD_DEC_USE_COUNT(serial->type->owner);
275 + }
276 +
277 + up (&port->sem);
278 + return retval;
279 +}
280 +
281 +static void __serial_close(struct usb_serial_port *port, struct file *filp)
282 +{
283 + if (!port->open_count) {
284 + dbg ("%s - port not opened", __FUNCTION__);
285 + return;
286 + }
287 +
288 + --port->open_count;
289 + if (port->open_count <= 0) {
290 + /* only call the device specific close if this
291 + * port is being closed by the last owner */
292 + if (port->serial->type->close)
293 + port->serial->type->close(port, filp);
294 + else
295 + //generic_close(port, filp);
296 + sw_usb_serial_generic_close(port, filp);
297 + port->open_count = 0;
298 + }
299 +
300 + if (port->serial->type->owner)
301 + __MOD_DEC_USE_COUNT(port->serial->type->owner);
302 +}
303 +
304 +static void serial_close(struct tty_struct *tty, struct file * filp)
305 +{
306 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
307 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
308 +
309 + if (!serial)
310 + return;
311 +
312 + down (&port->sem);
313 +
314 + dbg("%s - port %d", __FUNCTION__, port->number);
315 +
316 + /* if disconnect beat us to the punch here, there's nothing to do */
317 + if (tty->driver_data) {
318 + __serial_close(port, filp);
319 + }
320 +
321 + up (&port->sem);
322 +}
323 +
324 +static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
325 +{
326 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
327 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
328 + int retval = -EINVAL;
329 +
330 + if (!serial)
331 + return -ENODEV;
332 +
333 + down (&port->sem);
334 +
335 + dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
336 +
337 + if (!port->open_count) {
338 + dbg("%s - port not opened", __FUNCTION__);
339 + goto exit;
340 + }
341 +
342 + /* pass on to the driver specific version of this function if it is available */
343 + if (serial->type->write)
344 + retval = serial->type->write(port, from_user, buf, count);
345 + else
346 + retval = generic_write(port, from_user, buf, count);
347 +
348 +exit:
349 + up (&port->sem);
350 + return retval;
351 +}
352 +
353 +static int serial_write_room (struct tty_struct *tty)
354 +{
355 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
356 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
357 + int retval = -EINVAL;
358 +
359 + if (!serial)
360 + return -ENODEV;
361 +
362 + down (&port->sem);
363 +
364 + dbg("%s - port %d", __FUNCTION__, port->number);
365 +
366 + if (!port->open_count) {
367 + dbg("%s - port not open", __FUNCTION__);
368 + goto exit;
369 + }
370 +
371 + /* pass on to the driver specific version of this function if it is available */
372 + if (serial->type->write_room)
373 + retval = serial->type->write_room(port);
374 + else
375 + retval = generic_write_room(port);
376 +
377 +exit:
378 + up (&port->sem);
379 + return retval;
380 +}
381 +
382 +static int serial_chars_in_buffer (struct tty_struct *tty)
383 +{
384 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
385 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
386 + int retval = -EINVAL;
387 +
388 + if (!serial)
389 + return -ENODEV;
390 +
391 + down (&port->sem);
392 +
393 + dbg("%s = port %d", __FUNCTION__, port->number);
394 +
395 + if (!port->open_count) {
396 + dbg("%s - port not open", __FUNCTION__);
397 + goto exit;
398 + }
399 +
400 + /* pass on to the driver specific version of this function if it is available */
401 + if (serial->type->chars_in_buffer)
402 + retval = serial->type->chars_in_buffer(port);
403 + else
404 + retval = generic_chars_in_buffer(port);
405 +
406 +exit:
407 + up (&port->sem);
408 + return retval;
409 +}
410 +
411 +static void serial_throttle (struct tty_struct * tty)
412 +{
413 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
414 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
415 +
416 + if (!serial)
417 + return;
418 +
419 + down (&port->sem);
420 +
421 + dbg("%s - port %d", __FUNCTION__, port->number);
422 +
423 + if (!port->open_count) {
424 + dbg ("%s - port not open", __FUNCTION__);
425 + goto exit;
426 + }
427 +
428 + /* pass on to the driver specific version of this function */
429 + if (serial->type->throttle)
430 + serial->type->throttle(port);
431 +
432 +exit:
433 + up (&port->sem);
434 +}
435 +
436 +static void serial_unthrottle (struct tty_struct * tty)
437 +{
438 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
439 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
440 +
441 + if (!serial)
442 + return;
443 +
444 + down (&port->sem);
445 +
446 + dbg("%s - port %d", __FUNCTION__, port->number);
447 +
448 + if (!port->open_count) {
449 + dbg("%s - port not open", __FUNCTION__);
450 + goto exit;
451 + }
452 +
453 + /* pass on to the driver specific version of this function */
454 + if (serial->type->unthrottle)
455 + serial->type->unthrottle(port);
456 +
457 +exit:
458 + up (&port->sem);
459 +}
460 +
461 +static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
462 +{
463 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
464 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
465 + int retval = -ENODEV;
466 +
467 + if (!serial)
468 + return -ENODEV;
469 +
470 + down (&port->sem);
471 +
472 + dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
473 +
474 + if (!port->open_count) {
475 + dbg ("%s - port not open", __FUNCTION__);
476 + goto exit;
477 + }
478 +
479 + /* pass on to the driver specific version of this function if it is available */
480 + if (serial->type->ioctl)
481 + retval = serial->type->ioctl(port, file, cmd, arg);
482 + else
483 + retval = -ENOIOCTLCMD;
484 +
485 +exit:
486 + up (&port->sem);
487 + return retval;
488 +}
489 +
490 +static void serial_set_termios (struct tty_struct *tty, struct termios * old)
491 +{
492 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
493 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
494 +
495 + if (!serial)
496 + return;
497 +
498 + down (&port->sem);
499 +
500 + dbg("%s - port %d", __FUNCTION__, port->number);
501 +
502 + if (!port->open_count) {
503 + dbg("%s - port not open", __FUNCTION__);
504 + goto exit;
505 + }
506 +
507 + /* pass on to the driver specific version of this function if it is available */
508 + if (serial->type->set_termios)
509 + serial->type->set_termios(port, old);
510 +
511 +exit:
512 + up (&port->sem);
513 +}
514 +
515 +static void serial_break (struct tty_struct *tty, int break_state)
516 +{
517 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
518 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
519 +
520 + if (!serial)
521 + return;
522 +
523 + down (&port->sem);
524 +
525 + dbg("%s - port %d", __FUNCTION__, port->number);
526 +
527 + if (!port->open_count) {
528 + dbg("%s - port not open", __FUNCTION__);
529 + goto exit;
530 + }
531 +
532 + /* pass on to the driver specific version of this function if it is available */
533 + if (serial->type->break_ctl)
534 + serial->type->break_ctl(port, break_state);
535 +
536 +exit:
537 + up (&port->sem);
538 +}
539 +#if 0
540 +static void serial_shutdown (struct usb_serial *serial)
541 +{
542 + dbg ("%s", __FUNCTION__);
543 +
544 + if (serial->type->shutdown)
545 + serial->type->shutdown(serial);
546 + else
547 + generic_shutdown(serial);
548 +}
549 +#endif
550 +static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
551 +{
552 + struct usb_serial *serial;
553 + int length = 0;
554 + int i;
555 + off_t begin = 0;
556 + char tmp[40];
557 +
558 + dbg("%s", __FUNCTION__);
559 + length += sprintf (page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION);
560 + for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
561 + serial = get_serial_by_minor(i);
562 + if (serial == NULL)
563 + continue;
564 +
565 + length += sprintf (page+length, "%d:", i);
566 + if (serial->type->owner)
567 + length += sprintf (page+length, " module:%s", serial->type->owner->name);
568 + length += sprintf (page+length, " name:\"%s\"", serial->type->name);
569 + length += sprintf (page+length, " vendor:%04x product:%04x", serial->vendor, serial->product);
570 + length += sprintf (page+length, " num_ports:%d", serial->num_ports);
571 + length += sprintf (page+length, " port:%d", i - serial->minor + 1);
572 +
573 + usb_make_path(serial->dev, tmp, sizeof(tmp));
574 + length += sprintf (page+length, " path:%s", tmp);
575 +
576 + length += sprintf (page+length, "\n");
577 + if ((length + begin) > (off + count))
578 + goto done;
579 + if ((length + begin) < off) {
580 + begin += length;
581 + length = 0;
582 + }
583 + }
584 + *eof = 1;
585 +done:
586 + if (off >= (length + begin))
587 + return 0;
588 + *start = page + (off-begin);
589 + return ((count < begin+length-off) ? count : begin+length-off);
590 +}
591 +
592 +
593 +/*-----------------------------------------------------------*/
594 +static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
595 +{
596 + struct usb_serial *serial = port->serial;
597 + int result;
598 +
599 + dbg("%s - port %d", __FUNCTION__, port->number);
600 +
601 + if (count == 0) {
602 + dbg("%s - write request of 0 bytes", __FUNCTION__);
603 + return (0);
604 + }
605 +
606 + /* only do something if we have a bulk out endpoint */
607 + if (serial->num_bulk_out) {
608 + if (port->write_urb->status == -EINPROGRESS) {
609 + dbg("%s - already writing", __FUNCTION__);
610 + return (0);
611 + }
612 +
613 + count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
614 +
615 + if (from_user) {
616 + if (copy_from_user(port->write_urb->transfer_buffer, buf, count))
617 + return -EFAULT;
618 + }
619 + else {
620 + memcpy (port->write_urb->transfer_buffer, buf, count);
621 + }
622 +
623 + usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
624 +
625 + /* set up our urb */
626 + usb_fill_bulk_urb (port->write_urb, serial->dev,
627 + usb_sndbulkpipe (serial->dev,
628 + port->bulk_out_endpointAddress),
629 + port->write_urb->transfer_buffer, count,
630 + ((serial->type->write_bulk_callback) ?
631 + serial->type->write_bulk_callback :
632 + generic_write_bulk_callback), port);
633 +
634 + /* send the data out the bulk port */
635 + result = usb_submit_urb(port->write_urb);
636 + if (result)
637 + err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
638 + else
639 + result = count;
640 +
641 + return result;
642 + }
643 +
644 + /* no bulk out, so return 0 bytes written */
645 + return (0);
646 +}
647 +
648 +static int generic_write_room (struct usb_serial_port *port)
649 +{
650 + struct usb_serial *serial = port->serial;
651 + int room = 0;
652 +
653 + dbg("%s - port %d", __FUNCTION__, port->number);
654 +
655 + if (serial->num_bulk_out) {
656 + if (port->write_urb->status != -EINPROGRESS)
657 + room = port->bulk_out_size;
658 + }
659 +
660 + dbg("%s - returns %d", __FUNCTION__, room);
661 + return (room);
662 +}
663 +
664 +static int generic_chars_in_buffer (struct usb_serial_port *port)
665 +{
666 + struct usb_serial *serial = port->serial;
667 + int chars = 0;
668 +
669 + dbg("%s - port %d", __FUNCTION__, port->number);
670 +
671 + if (serial->num_bulk_out) {
672 + if (port->write_urb->status == -EINPROGRESS)
673 + chars = port->write_urb->transfer_buffer_length;
674 + }
675 +
676 + dbg("%s - returns %d", __FUNCTION__, chars);
677 + return (chars);
678 +}
679 +#if 0
680 +static void generic_shutdown (struct usb_serial *serial)
681 +{
682 + int i;
683 +
684 + dbg("%s", __FUNCTION__);
685 +
686 + /* stop reads and writes on all ports */
687 + for (i=0; i < serial->num_ports; ++i) {
688 + generic_cleanup (&serial->port[i]);
689 + }
690 +}
691 +static void generic_cleanup (struct usb_serial_port *port)
692 +{
693 + struct usb_serial *serial = port->serial;
694 +
695 + dbg("%s - port %d", __FUNCTION__, port->number);
696 +
697 + if (serial->dev) {
698 + /* shutdown any bulk reads that might be going on */
699 + if (serial->num_bulk_out)
700 + usb_unlink_urb (port->write_urb);
701 + if (serial->num_bulk_in)
702 + usb_unlink_urb (port->read_urb);
703 + }
704 +}
705 +#endif
706 +/*----------------------------------------------------------*/
707 +static void generic_write_bulk_callback (struct urb *urb)
708 +{
709 + struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
710 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
711 +
712 + dbg("%s - port %d", __FUNCTION__, port->number);
713 +
714 + if (!serial) {
715 + dbg("%s - bad serial pointer, exiting", __FUNCTION__);
716 + return;
717 + }
718 +
719 + if (urb->status) {
720 + dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
721 + return;
722 + }
723 +
724 + queue_task(&port->tqueue, &tq_immediate);
725 + mark_bh(IMMEDIATE_BH);
726 +
727 + return;
728 +}
729 +
730 +static struct usb_serial *get_free_serial (int num_ports, int *minor)
731 +{
732 + struct usb_serial *serial = NULL;
733 + int i, j;
734 + int good_spot;
735 +
736 + dbg("%s %d", __FUNCTION__, num_ports);
737 +
738 + *minor = 0;
739 + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
740 + if (serial_table[i])
741 + continue;
742 +
743 + good_spot = 1;
744 + for (j = 1; j <= num_ports-1; ++j)
745 + if (serial_table[i+j])
746 + good_spot = 0;
747 + if (good_spot == 0)
748 + continue;
749 +
750 + if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) {
751 + err("%s - Out of memory", __FUNCTION__);
752 + return NULL;
753 + }
754 + memset(serial, 0, sizeof(struct usb_serial));
755 + serial->magic = USB_SERIAL_MAGIC;
756 + serial_table[i] = serial;
757 + *minor = i;
758 + dbg("%s - minor base = %d", __FUNCTION__, *minor);
759 + for (i = *minor+1; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i)
760 + serial_table[i] = serial;
761 + return serial;
762 + }
763 + return NULL;
764 +}
765 +
766 +static void return_serial (struct usb_serial *serial)
767 +{
768 + int i;
769 +
770 + dbg("%s", __FUNCTION__);
771 +
772 + if (serial == NULL)
773 + return;
774 +
775 + for (i = 0; i < serial->num_ports; ++i) {
776 + serial_table[serial->minor + i] = NULL;
777 + }
778 +
779 + return;
780 +}
781 +
782 +static void port_softint(void *private)
783 +{
784 + struct usb_serial_port *port = (struct usb_serial_port *)private;
785 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
786 + struct tty_struct *tty;
787 +
788 + dbg("%s - port %d", __FUNCTION__, port->number);
789 +
790 + if (!serial)
791 + return;
792 +
793 + tty = port->tty;
794 + if (!tty)
795 + return;
796 +
797 + if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) {
798 + dbg("%s - write wakeup call.", __FUNCTION__);
799 + (tty->ldisc.write_wakeup)(tty);
800 + }
801 +
802 + wake_up_interruptible(&tty->write_wait);
803 +}
804 +
805 +
806 +static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,
807 + const struct usb_device_id *id)
808 +{
809 + struct usb_serial *serial = NULL;
810 + struct usb_serial_port *port;
811 + struct usb_interface *interface;
812 + struct usb_interface_descriptor *iface_desc;
813 + struct usb_endpoint_descriptor *endpoint;
814 + struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS];
815 + struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS];
816 + struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS];
817 + struct usb_serial_device_type *type = NULL;
818 + struct list_head *tmp;
819 + int found;
820 + int minor;
821 + int buffer_size;
822 + int i;
823 + int num_interrupt_in = 0;
824 + int num_bulk_in = 0;
825 + int num_bulk_out = 0;
826 + int num_ports;
827 + int max_endpoints;
828 + const struct usb_device_id *id_pattern = NULL;
829 +
830 + /* loop through our list of known serial converters, and see if this
831 + device matches. */
832 + found = 0;
833 + interface = &dev->actconfig->interface[ifnum];
834 + list_for_each (tmp, &usb_serial_driver_list) {
835 + type = list_entry(tmp, struct usb_serial_device_type, driver_list);
836 + id_pattern = usb_match_id(dev, interface, type->id_table);
837 + if (id_pattern != NULL) {
838 + dbg("descriptor matches");
839 + found = 1;
840 + break;
841 + }
842 + }
843 + if (!found) {
844 + /* no match */
845 + dbg("none matched");
846 + return(NULL);
847 + }
848 + /* descriptor matches, let's find the endpoints needed */
849 + /* check out the endpoints */
850 + iface_desc = &interface->altsetting[0];
851 + for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
852 + endpoint = &iface_desc->endpoint[i];
853 +
854 + if ((endpoint->bEndpointAddress & 0x80) &&
855 + ((endpoint->bmAttributes & 3) == 0x02)) {
856 + /* we found a bulk in endpoint */
857 + dbg("found bulk in");
858 + bulk_in_endpoint[num_bulk_in] = endpoint;
859 + ++num_bulk_in;
860 + }
861 +
862 + if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
863 + ((endpoint->bmAttributes & 3) == 0x02)) {
864 + /* we found a bulk out endpoint */
865 + dbg("found bulk out");
866 + bulk_out_endpoint[num_bulk_out] = endpoint;
867 + ++num_bulk_out;
868 + }
869 +
870 + if ((endpoint->bEndpointAddress & 0x80) &&
871 + ((endpoint->bmAttributes & 3) == 0x03)) {
872 + /* we found a interrupt in endpoint */
873 + dbg("found interrupt in");
874 + interrupt_in_endpoint[num_interrupt_in] = endpoint;
875 + ++num_interrupt_in;
876 + }
877 + }
878 +
879 +#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
880 + /* BEGIN HORRIBLE HACK FOR PL2303 */
881 + /* this is needed due to the looney way its endpoints are set up */
882 + if (((dev->descriptor.idVendor == PL2303_VENDOR_ID) &&
883 + (dev->descriptor.idProduct == PL2303_PRODUCT_ID)) ||
884 + ((dev->descriptor.idVendor == ATEN_VENDOR_ID) &&
885 + (dev->descriptor.idProduct == ATEN_PRODUCT_ID))) {
886 + if (ifnum == 1) {
887 + /* check out the endpoints of the other interface*/
888 + interface = &dev->actconfig->interface[ifnum ^ 1];
889 + iface_desc = &interface->altsetting[0];
890 + for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
891 + endpoint = &iface_desc->endpoint[i];
892 + if ((endpoint->bEndpointAddress & 0x80) &&
893 + ((endpoint->bmAttributes & 3) == 0x03)) {
894 + /* we found a interrupt in endpoint */
895 + dbg("found interrupt in for Prolific device on separate interface");
896 + interrupt_in_endpoint[num_interrupt_in] = endpoint;
897 + ++num_interrupt_in;
898 + }
899 + }
900 + }
901 +
902 + /* Now make sure the PL-2303 is configured correctly.
903 + * If not, give up now and hope this hack will work
904 + * properly during a later invocation of usb_serial_probe
905 + */
906 + if (num_bulk_in == 0 || num_bulk_out == 0) {
907 + info("PL-2303 hack: descriptors matched but endpoints did not");
908 + return NULL;
909 + }
910 + }
911 + /* END HORRIBLE HACK FOR PL2303 */
912 +#endif
913 +
914 + /* found all that we need */
915 + info("%s converter detected", type->name);
916 +
917 +#ifdef CONFIG_USB_SERIAL_SIERRAWIRELESS
918 + if (type == &sierra_driver) {
919 + num_ports = num_bulk_out;
920 + if (num_ports == 0) {
921 + err("Sierra 3G device with no bulk out, not allowed.");
922 + return NULL;
923 + }
924 + } else
925 +#endif
926 + num_ports = type->num_ports;
927 +
928 + serial = get_free_serial (num_ports, &minor);
929 + if (serial == NULL) {
930 + err("No more free serial devices");
931 + return NULL;
932 + }
933 +
934 + serial->dev = dev;
935 + serial->type = type;
936 + serial->interface = interface;
937 + serial->minor = minor;
938 + serial->num_ports = num_ports;
939 + serial->num_bulk_in = num_bulk_in;
940 + serial->num_bulk_out = num_bulk_out;
941 + serial->num_interrupt_in = num_interrupt_in;
942 + serial->vendor = dev->descriptor.idVendor;
943 + serial->product = dev->descriptor.idProduct;
944 +
945 + /* set up the endpoint information */
946 + for (i = 0; i < num_bulk_in; ++i) {
947 + endpoint = bulk_in_endpoint[i];
948 + port = &serial->port[i];
949 + port->read_urb = usb_alloc_urb (0);
950 + if (!port->read_urb) {
951 + err("No free urbs available");
952 + goto probe_error;
953 + }
954 +//Amin marked buffer_size = endpoint->wMaxPacketSize;
955 +// ===> 20060310 Amin modify for improve EVDO and HSDPA Card
956 + buffer_size = 2048;
957 + printk("KERNEL DEBUG => USBSERIAL.O buffer_size = 2048\n");
958 +// <=== 20060310 Amin modify for improve EVDO and HSDPA Card
959 + port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
960 + port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
961 + if (!port->bulk_in_buffer) {
962 + err("Couldn't allocate bulk_in_buffer");
963 + goto probe_error;
964 + }
965 + usb_fill_bulk_urb (port->read_urb, dev,
966 + usb_rcvbulkpipe (dev,
967 + endpoint->bEndpointAddress),
968 + port->bulk_in_buffer, buffer_size,
969 + ((serial->type->read_bulk_callback) ?
970 + serial->type->read_bulk_callback :
971 + sw_usb_serial_generic_read_bulk_callback),
972 + port);
973 + }
974 +
975 + for (i = 0; i < num_bulk_out; ++i) {
976 + endpoint = bulk_out_endpoint[i];
977 + port = &serial->port[i];
978 + port->write_urb = usb_alloc_urb(0);
979 + if (!port->write_urb) {
980 + err("No free urbs available");
981 + goto probe_error;
982 + }
983 + buffer_size = endpoint->wMaxPacketSize;
984 + port->bulk_out_size = buffer_size;
985 + port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
986 + port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL);
987 + if (!port->bulk_out_buffer) {
988 + err("Couldn't allocate bulk_out_buffer");
989 + goto probe_error;
990 + }
991 + usb_fill_bulk_urb (port->write_urb, dev,
992 + usb_sndbulkpipe (dev,
993 + endpoint->bEndpointAddress),
994 + port->bulk_out_buffer, buffer_size,
995 + ((serial->type->write_bulk_callback) ?
996 + serial->type->write_bulk_callback :
997 + generic_write_bulk_callback),
998 + port);
999 + }
1000 +
1001 + for (i = 0; i < num_interrupt_in; ++i) {
1002 + endpoint = interrupt_in_endpoint[i];
1003 + port = &serial->port[i];
1004 + port->interrupt_in_urb = usb_alloc_urb(0);
1005 + if (!port->interrupt_in_urb) {
1006 + err("No free urbs available");
1007 + goto probe_error;
1008 + }
1009 + buffer_size = endpoint->wMaxPacketSize;
1010 + port->interrupt_in_endpointAddress = endpoint->bEndpointAddress;
1011 + port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
1012 + if (!port->interrupt_in_buffer) {
1013 + err("Couldn't allocate interrupt_in_buffer");
1014 + goto probe_error;
1015 + }
1016 + usb_fill_int_urb (port->interrupt_in_urb, dev,
1017 + usb_rcvintpipe (dev,
1018 + endpoint->bEndpointAddress),
1019 + port->interrupt_in_buffer, buffer_size,
1020 + serial->type->read_int_callback, port,
1021 + endpoint->bInterval);
1022 + }
1023 +
1024 + /* initialize some parts of the port structures */
1025 + /* we don't use num_ports here cauz some devices have more endpoint pairs than ports */
1026 + max_endpoints = max(num_bulk_in, num_bulk_out);
1027 + max_endpoints = max(max_endpoints, num_interrupt_in);
1028 + max_endpoints = max(max_endpoints, (int)serial->num_ports);
1029 + dbg("%s - setting up %d port structures for this device", __FUNCTION__, max_endpoints);
1030 + for (i = 0; i < max_endpoints; ++i) {
1031 + port = &serial->port[i];
1032 + port->number = i + serial->minor;
1033 + port->serial = serial;
1034 + port->magic = USB_SERIAL_PORT_MAGIC;
1035 + port->tqueue.routine = port_softint;
1036 + port->tqueue.data = port;
1037 + init_MUTEX (&port->sem);
1038 + }
1039 +
1040 + /* if this device type has a startup function, call it */
1041 + if (type->startup) {
1042 + i = type->startup (serial);
1043 + if (i < 0)
1044 + goto probe_error;
1045 + if (i > 0)
1046 + return serial;
1047 + }
1048 +
1049 + /* initialize the devfs nodes for this device and let the user know what ports we are bound to */
1050 + for (i = 0; i < serial->num_ports; ++i) {
1051 + tty_register_devfs (&serial_tty_driver, 0, serial->port[i].number);
1052 + info("%s converter now attached to ttyUSB%d (or usb/tts/%d for devfs)",
1053 + type->name, serial->port[i].number, serial->port[i].number);
1054 + }
1055 +
1056 + return serial; /* success */
1057 +
1058 +
1059 +probe_error:
1060 + for (i = 0; i < num_bulk_in; ++i) {
1061 + port = &serial->port[i];
1062 + if (port->read_urb)
1063 + usb_free_urb (port->read_urb);
1064 + if (port->bulk_in_buffer)
1065 + kfree (port->bulk_in_buffer);
1066 + }
1067 + for (i = 0; i < num_bulk_out; ++i) {
1068 + port = &serial->port[i];
1069 + if (port->write_urb)
1070 + usb_free_urb (port->write_urb);
1071 + if (port->bulk_out_buffer)
1072 + kfree (port->bulk_out_buffer);
1073 + }
1074 + for (i = 0; i < num_interrupt_in; ++i) {
1075 + port = &serial->port[i];
1076 + if (port->interrupt_in_urb)
1077 + usb_free_urb (port->interrupt_in_urb);
1078 + if (port->interrupt_in_buffer)
1079 + kfree (port->interrupt_in_buffer);
1080 + }
1081 +
1082 + /* return the minor range that this device had */
1083 + return_serial (serial);
1084 +
1085 + /* free up any memory that we allocated */
1086 + kfree (serial);
1087 + return NULL;
1088 +}
1089 +
1090 +static void usb_serial_disconnect(struct usb_device *dev, void *ptr)
1091 +{
1092 + struct usb_serial *serial = (struct usb_serial *) ptr;
1093 + struct usb_serial_port *port;
1094 + int i;
1095 +
1096 + dbg ("%s", __FUNCTION__);
1097 + if (serial) {
1098 + /* fail all future close/read/write/ioctl/etc calls */
1099 + for (i = 0; i < serial->num_ports; ++i) {
1100 + port = &serial->port[i];
1101 + down (&port->sem);
1102 + if (port->tty != NULL) {
1103 + while (port->open_count > 0) {
1104 + //__serial_close(port, NULL);
1105 + sw_usb_serial_generic_close(port,NULL);
1106 + }
1107 + port->tty->driver_data = NULL;
1108 + }
1109 + up (&port->sem);
1110 + }
1111 +
1112 + serial->dev = NULL;
1113 + //serial_shutdown (serial);
1114 + sw_usb_serial_generic_shutdown(serial);
1115 +
1116 + for (i = 0; i < serial->num_ports; ++i)
1117 + serial->port[i].open_count = 0;
1118 +
1119 + for (i = 0; i < serial->num_bulk_in; ++i) {
1120 + port = &serial->port[i];
1121 + if (port->read_urb) {
1122 + usb_unlink_urb (port->read_urb);
1123 + usb_free_urb (port->read_urb);
1124 + }
1125 + if (port->bulk_in_buffer)
1126 + kfree (port->bulk_in_buffer);
1127 + }
1128 + for (i = 0; i < serial->num_bulk_out; ++i) {
1129 + port = &serial->port[i];
1130 + if (port->write_urb) {
1131 + usb_unlink_urb (port->write_urb);
1132 + usb_free_urb (port->write_urb);
1133 + }
1134 + if (port->bulk_out_buffer)
1135 + kfree (port->bulk_out_buffer);
1136 + }
1137 + for (i = 0; i < serial->num_interrupt_in; ++i) {
1138 + port = &serial->port[i];
1139 + if (port->interrupt_in_urb) {
1140 + usb_unlink_urb (port->interrupt_in_urb);
1141 + usb_free_urb (port->interrupt_in_urb);
1142 + }
1143 + if (port->interrupt_in_buffer)
1144 + kfree (port->interrupt_in_buffer);
1145 + }
1146 +
1147 + for (i = 0; i < serial->num_ports; ++i) {
1148 + tty_unregister_devfs (&serial_tty_driver, serial->port[i].number);
1149 + info("%s converter now disconnected from ttyUSB%d", serial->type->name, serial->port[i].number);
1150 + }
1151 +
1152 + /* return the minor range that this device had */
1153 + return_serial (serial);
1154 +
1155 + /* free up any memory that we allocated */
1156 + kfree (serial);
1157 +
1158 + } else {
1159 + info("device disconnected");
1160 + }
1161 +
1162 +}
1163 +
1164 +#if 0
1165 +static int sw_attach(struct usb_serial *serial)
1166 +{
1167 + struct usb_device *hdev = serial->dev;
1168 + int rc;
1169 +
1170 + dbg("%s - serial(0x%p)", __FUNCTION__, serial);
1171 +
1172 + rc = usb_control_msg(
1173 + hdev,
1174 + usb_sndctrlpipe(hdev, 0),
1175 + USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE, /* bRequest */
1176 + USB_TYPE_VENDOR|USB_RECIP_DEVICE, /* bmRequestType */
1177 + USB_DEVICE_POWER_STATE_D0, /* wValue */
1178 + 0, /* wIndex */
1179 + NULL, /* Data */
1180 + 0, /* wLength */
1181 + 1000); /* Timeout */
1182 +
1183 + err("%s - rc(%d)", __FUNCTION__, rc);
1184 + return rc;
1185 +}
1186 +#endif
1187 +//void sw_usb_serial_generic_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
1188 +static void sw_usb_serial_generic_read_bulk_callback (struct urb *urb)
1189 +{
1190 + struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1191 + struct usb_serial *serial = port->serial;
1192 + struct tty_struct *tty;
1193 + unsigned char *data = urb->transfer_buffer;
1194 + int result;
1195 + int i;
1196 +
1197 + dbg("%s - port %d", __FUNCTION__, port->number);
1198 +
1199 + if (urb->status) {
1200 + dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
1201 + return;
1202 + }
1203 +
1204 + //usb_serial_dbg_data(__FILE__, __FUNCTION__, urb->actual_length, data);
1205 +
1206 + tty = port->tty;
1207 + if (tty && urb->actual_length) {
1208 + #if 0
1209 + tty_buffer_request_room(tty, urb->actual_length);
1210 + tty_insert_flip_string(tty, data, urb->actual_length);
1211 + tty_flip_buffer_push(tty);
1212 + #endif
1213 + #if 1
1214 + for (i = 0; i < urb->actual_length ; ++i) {
1215 + /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
1216 + if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
1217 + tty_flip_buffer_push(tty);
1218 + }
1219 + /* this doesn't actually push the data through unless tty->low_latency is set */
1220 + tty_insert_flip_char(tty, data[i], 0);
1221 + }
1222 + tty_flip_buffer_push(tty);
1223 + #endif
1224 +
1225 + }
1226 + else
1227 + dbg("%s: empty read urb received", __FUNCTION__);
1228 +
1229 + /* Continue trying to always read */
1230 + usb_fill_bulk_urb (port->read_urb, serial->dev,
1231 + usb_rcvbulkpipe (serial->dev,
1232 + port->bulk_in_endpointAddress),
1233 + port->read_urb->transfer_buffer,
1234 + port->read_urb->transfer_buffer_length,
1235 + ((serial->type->read_bulk_callback) ?
1236 + serial->type->read_bulk_callback :
1237 + sw_usb_serial_generic_read_bulk_callback), port);
1238 + result = usb_submit_urb(port->read_urb);
1239 + //result = usb_submit_urb(port->read_urb, GFP_ATOMIC); //for kernel 2.6
1240 + if (result)
1241 + dbg("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
1242 +}
1243 +#if 1
1244 +static int generic_open (struct usb_serial_port *port, struct file *filp)
1245 +{
1246 + struct usb_serial *serial = port->serial;
1247 + int result = 0;
1248 +
1249 + dbg("%s - port %d", __FUNCTION__, port->number);
1250 +
1251 + /* force low_latency on so that our tty_push actually forces the data through,
1252 + otherwise it is scheduled, and with high data rates (like with OHCI) data
1253 + can get lost. */
1254 + if (port->tty)
1255 + port->tty->low_latency = 1;
1256 +
1257 + /* if we have a bulk interrupt, start reading from it */
1258 + if (serial->num_bulk_in) {
1259 + /* Start reading from the device */
1260 + usb_fill_bulk_urb (port->read_urb, serial->dev,
1261 + usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
1262 + port->read_urb->transfer_buffer,
1263 + port->read_urb->transfer_buffer_length,
1264 + ((serial->type->read_bulk_callback) ?
1265 + serial->type->read_bulk_callback :
1266 + sw_usb_serial_generic_read_bulk_callback),
1267 + port);
1268 + result = usb_submit_urb(port->read_urb); //, GFP_KERNEL);
1269 + if (result)
1270 + //dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
1271 + dbg("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
1272 +
1273 + }
1274 +
1275 + return result;
1276 +}
1277 +#endif
1278 +int sw_usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
1279 +{
1280 + int rc;
1281 + struct usb_serial *serial = port->serial;
1282 + struct usb_device *hdev = serial->dev;
1283 +
1284 + dbg("%s - port %d", __FUNCTION__, port->number);
1285 +
1286 + rc = generic_open(port, filp);
1287 + err("%s - rc(%d)", __FUNCTION__, rc);
1288 +
1289 + if(0 == rc)
1290 + {
1291 + rc = usb_control_msg(
1292 + hdev,
1293 + usb_sndctrlpipe(hdev, 0),
1294 + SET_CONTROL_LINE_STATE, /* bRequest */
1295 + USB_TYPE_CLASS|USB_RECIP_INTERFACE, /* bmRequestType */
1296 + ACM_CTRL_DTR|ACM_CTRL_RTS, /* wValue */
1297 + 0, /* wIndex */
1298 + NULL, /* Data */
1299 + 0, /* wLength */
1300 + 1000); /* Timeout */
1301 + err("%s - usb_control_msg: rc(%d)", __FUNCTION__, rc);
1302 + }
1303 +
1304 + return rc;
1305 +}
1306 +
1307 +static void generic_cleanup (struct usb_serial_port *port)
1308 +{
1309 + struct usb_serial *serial = port->serial;
1310 +
1311 + dbg("%s - port %d", __FUNCTION__, port->number);
1312 +
1313 + if (serial->dev) {
1314 + /* shutdown any bulk reads that might be going on */
1315 + if (serial->num_bulk_out)
1316 + usb_unlink_urb(port->write_urb);
1317 + //usb_kill_urb(port->write_urb);
1318 + if (serial->num_bulk_in)
1319 + usb_unlink_urb(port->read_urb);
1320 + //usb_kill_urb(port->read_urb);
1321 + }
1322 +}
1323 +
1324 +static void sw_usb_serial_generic_close (struct usb_serial_port *port, struct file * filp)
1325 +{
1326 + int rc;
1327 + struct usb_serial *serial = port->serial;
1328 + struct usb_device *hdev = serial->dev;
1329 +
1330 + dbg("%s - port %d", __FUNCTION__, port->number);
1331 +
1332 + rc = usb_control_msg(
1333 + hdev,
1334 + usb_sndctrlpipe(hdev, 0),
1335 + SET_CONTROL_LINE_STATE, /* bRequest */
1336 + USB_TYPE_CLASS|USB_RECIP_INTERFACE, /* bmRequestType */
1337 + 0, /* wValue */
1338 + 0, /* wIndex */
1339 + NULL, /* Data */
1340 + 0, /* wLength */
1341 + 1000); /* Timeout */
1342 + err("%s - rc(%d)", __FUNCTION__, rc);
1343 +
1344 + generic_cleanup (port);
1345 +}
1346 +
1347 +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial)
1348 +{
1349 + int i, rc;
1350 + struct usb_device *hdev = serial->dev;
1351 +
1352 + dbg("%s serial(0x%p)", __FUNCTION__, serial);
1353 +
1354 + if(hdev)
1355 + {
1356 + rc = usb_control_msg(
1357 + hdev,
1358 + usb_sndctrlpipe(hdev, 0),
1359 + USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE, /* bRequest */
1360 + USB_TYPE_VENDOR|USB_RECIP_DEVICE, /* bmRequestType */
1361 + USB_DEVICE_POWER_STATE_D3, /* wValue */
1362 + 0, /* wIndex */
1363 + NULL, /* Data */
1364 + 0, /* wLength */
1365 + 1000); /* Timeout */
1366 + err("%s - rc(%d)", __FUNCTION__, rc);
1367 + }
1368 +
1369 + /* stop reads and writes on all ports */
1370 + for (i=0; i < serial->num_ports; ++i) {
1371 + generic_cleanup(&serial->port[i]);
1372 + }
1373 +}
1374 +int usb_serial_register(struct usb_serial_device_type *new_device)
1375 +{
1376 + /* Add this device to our list of devices */
1377 + list_add(&new_device->driver_list, &usb_serial_driver_list);
1378 +
1379 + info ("USB Serial support registered for %s", new_device->name);
1380 +
1381 + usb_scan_devices();
1382 +
1383 + return 0;
1384 +}
1385 +
1386 +
1387 +void usb_serial_deregister(struct usb_serial_device_type *device)
1388 +{
1389 + struct usb_serial *serial;
1390 + int i;
1391 +
1392 + info("USB Serial deregistering driver %s", device->name);
1393 +
1394 + /* clear out the serial_table if the device is attached to a port */
1395 + for(i = 0; i < SERIAL_TTY_MINORS; ++i) {
1396 + serial = serial_table[i];
1397 + if ((serial != NULL) && (serial->type == device)) {
1398 + usb_driver_release_interface (&sierra_driver, serial->interface);
1399 + usb_serial_disconnect (NULL, serial);
1400 + }
1401 + }
1402 +
1403 + list_del(&device->driver_list);
1404 +}
1405 +
1406 +static int __init sierra_init(void)
1407 +{
1408 + int retval;
1409 + int i;
1410 +
1411 + /* Initalize our global data */
1412 + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
1413 + serial_table[i] = NULL;
1414 + }
1415 +
1416 + /* register the tty driver */
1417 + serial_tty_driver.init_termios = tty_std_termios;
1418 + serial_tty_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1419 + if (tty_register_driver (&serial_tty_driver)) {
1420 + err("%s - failed to register tty driver", __FUNCTION__);
1421 + return -1;
1422 + }
1423 +
1424 + retval = usb_serial_register(&sierra_device);
1425 + if (retval)
1426 + {
1427 + tty_unregister_driver(&serial_tty_driver);
1428 + printk("%s return usb_serial_register. retval=[%d].\n",__FUNCTION__, retval);
1429 + return retval;
1430 + }
1431 + retval = usb_register(&sierra_driver);
1432 + if (retval){
1433 + usb_serial_deregister(&sierra_device);
1434 + tty_unregister_driver(&serial_tty_driver);
1435 + err("usb_register failed for the Sierra 3G USB-Serial driver. Error number %d\n", retval);
1436 + return -1;
1437 + }
1438 +
1439 + return retval;
1440 +}
1441 +
1442 +static void __exit sierra_exit(void)
1443 +{
1444 + usb_deregister(&sierra_driver);
1445 + usb_serial_deregister(&sierra_device);
1446 +}
1447 +
1448 +module_init(sierra_init);
1449 +module_exit(sierra_exit);
1450 +MODULE_LICENSE("GPL");
1451 diff -Naur linux-2.4.35.4-old/drivers/usb/serial/sierra.h linux-2.4.35.4/drivers/usb/serial/sierra.h
1452 --- linux-2.4.35.4-old/drivers/usb/serial/sierra.h 1969-12-31 17:00:00.000000000 -0700
1453 +++ linux-2.4.35.4/drivers/usb/serial/sierra.h 2008-01-25 10:15:35.640743578 -0700
1454 @@ -0,0 +1,32 @@
1455 +/*
1456 + * Sierra Wireless CDMA Wireless Serial USB drive
1457 + *
1458 + * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
1459 + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
1460 + *
1461 + *
1462 + * This program is free software; you can redistribute it and/or
1463 + * modify it under the terms of the GNU General Public License version
1464 + * 2 as published by the Free Software Foundation.
1465 + *
1466 + * Version history:
1467 + Version 1.03 (Lloyd):
1468 + Included support for DTR control and enhanced buffering (should help
1469 + speed).
1470 + */
1471 +
1472 +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
1473 +
1474 +#define USB_DEVICE_POWER_STATE_D0 0x0000
1475 +#define USB_DEVICE_POWER_STATE_D1 0x0001
1476 +#define USB_DEVICE_POWER_STATE_D2 0x0002
1477 +#define USB_DEVICE_POWER_STATE_D3 0x0003
1478 +
1479 +#define SET_CONTROL_LINE_STATE 0x22
1480 +/*
1481 + * Output control lines.
1482 + */
1483 +
1484 +#define ACM_CTRL_DTR 0x01
1485 +#define ACM_CTRL_RTS 0x02
1486 +
This page took 0.112124 seconds and 5 git commands to generate.