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
6 + * Sierra Wireless CDMA Wireless Serial USB drive
8 + * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
9 + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
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.
17 + Version 1.03 (Lloyd):
18 + Included support for DTR control and enhanced buffering (should help
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>
38 +#ifdef CONFIG_USB_SERIAL_DEBUG
39 + static int debug = 1;
44 +#include "usb-serial.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
50 +#define DRIVER_VERSION "v1.03"
53 +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
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
60 +#define SET_CONTROL_LINE_STATE 0x22
62 + * Output control lines.
65 +#define ACM_CTRL_DTR 0x01
66 +#define ACM_CTRL_RTS 0x02
69 +//static int sw_attach(struct usb_serial *serial);
70 +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial);
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);
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 */
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 +/*-----------------------------------------------------------*/
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 */
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 */
132 + { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */
133 + { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */
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 */
141 +MODULE_DEVICE_TABLE(usb, id_table);
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,
151 +static struct usb_serial_device_type sierra_device = {
153 + .owner = THIS_MODULE,
154 + .name = "Sierra Wireless",
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,
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,
167 +#define MAX_NUM_PORTS 8
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);
188 +static struct tty_driver serial_tty_driver = {
189 + .magic = TTY_DRIVER_MAGIC,
190 + .driver_name = "usb-serial",
191 +#ifndef CONFIG_DEVFS_FS
194 + .name = "usb/tts/%d",
196 + .major = SERIAL_TTY_MAJOR,
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,
203 + .refcount = &serial_refcount,
204 + .table = serial_tty,
205 + .termios = serial_termios,
206 + .termios_locked = serial_termios_locked,
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,
223 +/*****************************************************************************
224 + * Driver tty interface functions
225 + *****************************************************************************/
226 +static struct usb_serial *get_serial_by_minor (unsigned int minor)
228 + return serial_table[minor];
231 +static int serial_open (struct tty_struct *tty, struct file * filp)
233 + struct usb_serial *serial;
234 + struct usb_serial_port *port;
235 + unsigned int portNumber;
238 + dbg("%s", __FUNCTION__);
240 + /* initialize the pointer incase something fails */
241 + tty->driver_data = NULL;
243 + /* get the serial object associated with this tty pointer */
244 + serial = get_serial_by_minor (MINOR(tty->device));
246 + if (serial_paranoia_check (serial, __FUNCTION__))
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;
257 + /* lock this module before we call it */
258 + if (serial->type->owner)
259 + __MOD_INC_USE_COUNT(serial->type->owner);
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);
268 + retval = sw_usb_serial_generic_open(port, filp);//@.@
272 + port->open_count = 0;
273 + if (serial->type->owner)
274 + __MOD_DEC_USE_COUNT(serial->type->owner);
281 +static void __serial_close(struct usb_serial_port *port, struct file *filp)
283 + if (!port->open_count) {
284 + dbg ("%s - port not opened", __FUNCTION__);
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);
295 + //generic_close(port, filp);
296 + sw_usb_serial_generic_close(port, filp);
297 + port->open_count = 0;
300 + if (port->serial->type->owner)
301 + __MOD_DEC_USE_COUNT(port->serial->type->owner);
304 +static void serial_close(struct tty_struct *tty, struct file * filp)
306 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
307 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
314 + dbg("%s - port %d", __FUNCTION__, port->number);
316 + /* if disconnect beat us to the punch here, there's nothing to do */
317 + if (tty->driver_data) {
318 + __serial_close(port, filp);
324 +static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
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;
335 + dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
337 + if (!port->open_count) {
338 + dbg("%s - port not opened", __FUNCTION__);
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);
346 + retval = generic_write(port, from_user, buf, count);
353 +static int serial_write_room (struct tty_struct *tty)
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;
364 + dbg("%s - port %d", __FUNCTION__, port->number);
366 + if (!port->open_count) {
367 + dbg("%s - port not open", __FUNCTION__);
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);
375 + retval = generic_write_room(port);
382 +static int serial_chars_in_buffer (struct tty_struct *tty)
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;
393 + dbg("%s = port %d", __FUNCTION__, port->number);
395 + if (!port->open_count) {
396 + dbg("%s - port not open", __FUNCTION__);
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);
404 + retval = generic_chars_in_buffer(port);
411 +static void serial_throttle (struct tty_struct * tty)
413 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
414 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
421 + dbg("%s - port %d", __FUNCTION__, port->number);
423 + if (!port->open_count) {
424 + dbg ("%s - port not open", __FUNCTION__);
428 + /* pass on to the driver specific version of this function */
429 + if (serial->type->throttle)
430 + serial->type->throttle(port);
436 +static void serial_unthrottle (struct tty_struct * tty)
438 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
439 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
446 + dbg("%s - port %d", __FUNCTION__, port->number);
448 + if (!port->open_count) {
449 + dbg("%s - port not open", __FUNCTION__);
453 + /* pass on to the driver specific version of this function */
454 + if (serial->type->unthrottle)
455 + serial->type->unthrottle(port);
461 +static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
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;
472 + dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
474 + if (!port->open_count) {
475 + dbg ("%s - port not open", __FUNCTION__);
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);
483 + retval = -ENOIOCTLCMD;
490 +static void serial_set_termios (struct tty_struct *tty, struct termios * old)
492 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
493 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
500 + dbg("%s - port %d", __FUNCTION__, port->number);
502 + if (!port->open_count) {
503 + dbg("%s - port not open", __FUNCTION__);
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);
515 +static void serial_break (struct tty_struct *tty, int break_state)
517 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
518 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
525 + dbg("%s - port %d", __FUNCTION__, port->number);
527 + if (!port->open_count) {
528 + dbg("%s - port not open", __FUNCTION__);
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);
540 +static void serial_shutdown (struct usb_serial *serial)
542 + dbg ("%s", __FUNCTION__);
544 + if (serial->type->shutdown)
545 + serial->type->shutdown(serial);
547 + generic_shutdown(serial);
550 +static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
552 + struct usb_serial *serial;
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)
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);
573 + usb_make_path(serial->dev, tmp, sizeof(tmp));
574 + length += sprintf (page+length, " path:%s", tmp);
576 + length += sprintf (page+length, "\n");
577 + if ((length + begin) > (off + count))
579 + if ((length + begin) < off) {
586 + if (off >= (length + begin))
588 + *start = page + (off-begin);
589 + return ((count < begin+length-off) ? count : begin+length-off);
593 +/*-----------------------------------------------------------*/
594 +static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
596 + struct usb_serial *serial = port->serial;
599 + dbg("%s - port %d", __FUNCTION__, port->number);
602 + dbg("%s - write request of 0 bytes", __FUNCTION__);
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__);
613 + count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
616 + if (copy_from_user(port->write_urb->transfer_buffer, buf, count))
620 + memcpy (port->write_urb->transfer_buffer, buf, count);
623 + usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
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);
634 + /* send the data out the bulk port */
635 + result = usb_submit_urb(port->write_urb);
637 + err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
644 + /* no bulk out, so return 0 bytes written */
648 +static int generic_write_room (struct usb_serial_port *port)
650 + struct usb_serial *serial = port->serial;
653 + dbg("%s - port %d", __FUNCTION__, port->number);
655 + if (serial->num_bulk_out) {
656 + if (port->write_urb->status != -EINPROGRESS)
657 + room = port->bulk_out_size;
660 + dbg("%s - returns %d", __FUNCTION__, room);
664 +static int generic_chars_in_buffer (struct usb_serial_port *port)
666 + struct usb_serial *serial = port->serial;
669 + dbg("%s - port %d", __FUNCTION__, port->number);
671 + if (serial->num_bulk_out) {
672 + if (port->write_urb->status == -EINPROGRESS)
673 + chars = port->write_urb->transfer_buffer_length;
676 + dbg("%s - returns %d", __FUNCTION__, chars);
680 +static void generic_shutdown (struct usb_serial *serial)
684 + dbg("%s", __FUNCTION__);
686 + /* stop reads and writes on all ports */
687 + for (i=0; i < serial->num_ports; ++i) {
688 + generic_cleanup (&serial->port[i]);
691 +static void generic_cleanup (struct usb_serial_port *port)
693 + struct usb_serial *serial = port->serial;
695 + dbg("%s - port %d", __FUNCTION__, port->number);
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);
706 +/*----------------------------------------------------------*/
707 +static void generic_write_bulk_callback (struct urb *urb)
709 + struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
710 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
712 + dbg("%s - port %d", __FUNCTION__, port->number);
715 + dbg("%s - bad serial pointer, exiting", __FUNCTION__);
720 + dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
724 + queue_task(&port->tqueue, &tq_immediate);
725 + mark_bh(IMMEDIATE_BH);
730 +static struct usb_serial *get_free_serial (int num_ports, int *minor)
732 + struct usb_serial *serial = NULL;
736 + dbg("%s %d", __FUNCTION__, num_ports);
739 + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
740 + if (serial_table[i])
744 + for (j = 1; j <= num_ports-1; ++j)
745 + if (serial_table[i+j])
747 + if (good_spot == 0)
750 + if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) {
751 + err("%s - Out of memory", __FUNCTION__);
754 + memset(serial, 0, sizeof(struct usb_serial));
755 + serial->magic = USB_SERIAL_MAGIC;
756 + serial_table[i] = serial;
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;
766 +static void return_serial (struct usb_serial *serial)
770 + dbg("%s", __FUNCTION__);
772 + if (serial == NULL)
775 + for (i = 0; i < serial->num_ports; ++i) {
776 + serial_table[serial->minor + i] = NULL;
782 +static void port_softint(void *private)
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;
788 + dbg("%s - port %d", __FUNCTION__, port->number);
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);
802 + wake_up_interruptible(&tty->write_wait);
806 +static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,
807 + const struct usb_device_id *id)
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;
823 + int num_interrupt_in = 0;
824 + int num_bulk_in = 0;
825 + int num_bulk_out = 0;
828 + const struct usb_device_id *id_pattern = NULL;
830 + /* loop through our list of known serial converters, and see if this
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");
845 + dbg("none matched");
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];
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;
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;
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;
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))) {
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;
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
906 + if (num_bulk_in == 0 || num_bulk_out == 0) {
907 + info("PL-2303 hack: descriptors matched but endpoints did not");
911 + /* END HORRIBLE HACK FOR PL2303 */
914 + /* found all that we need */
915 + info("%s converter detected", type->name);
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.");
926 + num_ports = type->num_ports;
928 + serial = get_free_serial (num_ports, &minor);
929 + if (serial == NULL) {
930 + err("No more free serial devices");
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;
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");
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");
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),
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");
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");
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),
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");
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");
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);
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);
1040 + /* if this device type has a startup function, call it */
1041 + if (type->startup) {
1042 + i = type->startup (serial);
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);
1056 + return serial; /* success */
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);
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);
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);
1082 + /* return the minor range that this device had */
1083 + return_serial (serial);
1085 + /* free up any memory that we allocated */
1090 +static void usb_serial_disconnect(struct usb_device *dev, void *ptr)
1092 + struct usb_serial *serial = (struct usb_serial *) ptr;
1093 + struct usb_serial_port *port;
1096 + dbg ("%s", __FUNCTION__);
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);
1107 + port->tty->driver_data = NULL;
1112 + serial->dev = NULL;
1113 + //serial_shutdown (serial);
1114 + sw_usb_serial_generic_shutdown(serial);
1116 + for (i = 0; i < serial->num_ports; ++i)
1117 + serial->port[i].open_count = 0;
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);
1125 + if (port->bulk_in_buffer)
1126 + kfree (port->bulk_in_buffer);
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);
1134 + if (port->bulk_out_buffer)
1135 + kfree (port->bulk_out_buffer);
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);
1143 + if (port->interrupt_in_buffer)
1144 + kfree (port->interrupt_in_buffer);
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);
1152 + /* return the minor range that this device had */
1153 + return_serial (serial);
1155 + /* free up any memory that we allocated */
1159 + info("device disconnected");
1165 +static int sw_attach(struct usb_serial *serial)
1167 + struct usb_device *hdev = serial->dev;
1170 + dbg("%s - serial(0x%p)", __FUNCTION__, serial);
1172 + rc = usb_control_msg(
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 */
1181 + 1000); /* Timeout */
1183 + err("%s - rc(%d)", __FUNCTION__, rc);
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)
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;
1197 + dbg("%s - port %d", __FUNCTION__, port->number);
1199 + if (urb->status) {
1200 + dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
1204 + //usb_serial_dbg_data(__FILE__, __FUNCTION__, urb->actual_length, data);
1207 + if (tty && urb->actual_length) {
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);
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);
1219 + /* this doesn't actually push the data through unless tty->low_latency is set */
1220 + tty_insert_flip_char(tty, data[i], 0);
1222 + tty_flip_buffer_push(tty);
1227 + dbg("%s: empty read urb received", __FUNCTION__);
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
1241 + dbg("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
1244 +static int generic_open (struct usb_serial_port *port, struct file *filp)
1246 + struct usb_serial *serial = port->serial;
1249 + dbg("%s - port %d", __FUNCTION__, port->number);
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
1255 + port->tty->low_latency = 1;
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),
1268 + result = usb_submit_urb(port->read_urb); //, GFP_KERNEL);
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);
1278 +int sw_usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
1281 + struct usb_serial *serial = port->serial;
1282 + struct usb_device *hdev = serial->dev;
1284 + dbg("%s - port %d", __FUNCTION__, port->number);
1286 + rc = generic_open(port, filp);
1287 + err("%s - rc(%d)", __FUNCTION__, rc);
1291 + rc = usb_control_msg(
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 */
1300 + 1000); /* Timeout */
1301 + err("%s - usb_control_msg: rc(%d)", __FUNCTION__, rc);
1307 +static void generic_cleanup (struct usb_serial_port *port)
1309 + struct usb_serial *serial = port->serial;
1311 + dbg("%s - port %d", __FUNCTION__, port->number);
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);
1324 +static void sw_usb_serial_generic_close (struct usb_serial_port *port, struct file * filp)
1327 + struct usb_serial *serial = port->serial;
1328 + struct usb_device *hdev = serial->dev;
1330 + dbg("%s - port %d", __FUNCTION__, port->number);
1332 + rc = usb_control_msg(
1334 + usb_sndctrlpipe(hdev, 0),
1335 + SET_CONTROL_LINE_STATE, /* bRequest */
1336 + USB_TYPE_CLASS|USB_RECIP_INTERFACE, /* bmRequestType */
1341 + 1000); /* Timeout */
1342 + err("%s - rc(%d)", __FUNCTION__, rc);
1344 + generic_cleanup (port);
1347 +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial)
1350 + struct usb_device *hdev = serial->dev;
1352 + dbg("%s serial(0x%p)", __FUNCTION__, serial);
1356 + rc = usb_control_msg(
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 */
1365 + 1000); /* Timeout */
1366 + err("%s - rc(%d)", __FUNCTION__, rc);
1369 + /* stop reads and writes on all ports */
1370 + for (i=0; i < serial->num_ports; ++i) {
1371 + generic_cleanup(&serial->port[i]);
1374 +int usb_serial_register(struct usb_serial_device_type *new_device)
1376 + /* Add this device to our list of devices */
1377 + list_add(&new_device->driver_list, &usb_serial_driver_list);
1379 + info ("USB Serial support registered for %s", new_device->name);
1381 + usb_scan_devices();
1387 +void usb_serial_deregister(struct usb_serial_device_type *device)
1389 + struct usb_serial *serial;
1392 + info("USB Serial deregistering driver %s", device->name);
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);
1403 + list_del(&device->driver_list);
1406 +static int __init sierra_init(void)
1411 + /* Initalize our global data */
1412 + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
1413 + serial_table[i] = NULL;
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__);
1424 + retval = usb_serial_register(&sierra_device);
1427 + tty_unregister_driver(&serial_tty_driver);
1428 + printk("%s return usb_serial_register. retval=[%d].\n",__FUNCTION__, retval);
1431 + retval = usb_register(&sierra_driver);
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);
1442 +static void __exit sierra_exit(void)
1444 + usb_deregister(&sierra_driver);
1445 + usb_serial_deregister(&sierra_device);
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
1456 + * Sierra Wireless CDMA Wireless Serial USB drive
1458 + * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
1459 + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
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.
1466 + * Version history:
1467 + Version 1.03 (Lloyd):
1468 + Included support for DTR control and enhanced buffering (should help
1472 +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
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
1479 +#define SET_CONTROL_LINE_STATE 0x22
1481 + * Output control lines.
1484 +#define ACM_CTRL_DTR 0x01
1485 +#define ACM_CTRL_RTS 0x02
1487 diff -Naur linux-2.4.35.4-old/drivers/usb/serial/sierra.c linux-2.4.35.4/drivers/usb/serial/sierra.c
1488 --- linux-2.4.35.4-old/drivers/usb/serial/sierra.c 1969-12-31 17:00:00.000000000 -0700
1489 +++ linux-2.4.35.4/drivers/usb/serial/sierra.c 2008-01-25 10:21:25.747868456 -0700
1492 + * Sierra Wireless CDMA Wireless Serial USB drive
1494 + * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
1495 + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
1498 + * This program is free software; you can redistribute it and/or
1499 + * modify it under the terms of the GNU General Public License version
1500 + * 2 as published by the Free Software Foundation.
1502 + * Version history:
1503 + Version 1.03 (Lloyd):
1504 + Included support for DTR control and enhanced buffering (should help
1508 +#include <linux/config.h>
1509 +#include <linux/kernel.h>
1510 +#include <linux/init.h>
1511 +#include <linux/slab.h>
1512 +#include <linux/tty.h>
1513 +#include <linux/tty_driver.h>
1514 +#include <linux/tty_flip.h>
1515 +#include <linux/module.h>
1516 +#include <linux/usb.h>
1517 +#include <linux/mm.h>
1518 +#include <asm/uaccess.h>
1519 +#include <linux/errno.h>
1520 +#include <linux/list.h>
1521 +#include <linux/spinlock.h>
1522 +#include <linux/smp_lock.h>
1524 +#ifdef CONFIG_USB_SERIAL_DEBUG
1525 + static int debug = 1;
1530 +#include "usb-serial.h"
1531 +#include "sierra.h"
1532 +#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
1533 +#include "pl2303.h" // see /* BEGIN HORRIBLE HACK FOR PL2303 */ below
1536 +#define DRIVER_VERSION "v1.03"
1539 +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
1541 +#define USB_DEVICE_POWER_STATE_D0 0x0000
1542 +#define USB_DEVICE_POWER_STATE_D1 0x0001
1543 +#define USB_DEVICE_POWER_STATE_D2 0x0002
1544 +#define USB_DEVICE_POWER_STATE_D3 0x0003
1546 +#define SET_CONTROL_LINE_STATE 0x22
1548 + * Output control lines.
1551 +#define ACM_CTRL_DTR 0x01
1552 +#define ACM_CTRL_RTS 0x02
1555 +//static int sw_attach(struct usb_serial *serial);
1556 +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial);
1558 +static int sw_usb_serial_generic_open(struct usb_serial_port *port, struct file *filp);
1559 +static void sw_usb_serial_generic_close(struct usb_serial_port *port, struct file *filp);
1562 +/*-----------------------------------------------------------*/
1563 +static int serial_refcount;
1564 +static struct tty_driver serial_tty_driver;
1565 +static struct tty_struct * serial_tty[SERIAL_TTY_MINORS];
1566 +static struct termios * serial_termios[SERIAL_TTY_MINORS];
1567 +static struct termios * serial_termios_locked[SERIAL_TTY_MINORS];
1568 +static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */
1570 +static LIST_HEAD(usb_serial_driver_list);
1571 +static struct usb_serial *get_free_serial (int num_ports, int *minor);
1572 +static void generic_write_bulk_callback (struct urb *urb);
1573 +static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,const struct usb_device_id *id);
1574 +static void usb_serial_disconnect(struct usb_device *dev, void *ptr);
1575 +static void sw_usb_serial_generic_read_bulk_callback (struct urb *urb);
1576 +static void port_softint(void *private);
1577 +static void return_serial (struct usb_serial *serial);
1578 +static struct usb_serial *get_free_serial (int num_ports, int *minor);
1579 +static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data);
1580 +/*-----------------------------------------------------------*/
1585 +static struct usb_device_id id_table [] = {
1586 + { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
1587 + { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
1588 + { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
1589 + { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
1590 + { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
1591 + { USB_DEVICE(0x1199, 0x0220) }, /* Sierra Wireless MC5725 */
1592 + { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
1593 + { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
1594 + { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
1595 + { USB_DEVICE(0x1199, 0x0023) }, /* Sierra Wireless C597 */
1597 + { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
1598 + { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
1599 + { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
1600 + { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
1601 + { USB_DEVICE(0x1199, 0x6813) }, /* Sierra Wireless MC8775 (Thinkpad internal) */
1602 + { USB_DEVICE(0x1199, 0x6815) }, /* Sierra Wireless MC8775 */
1603 + { USB_DEVICE(0x03f0, 0x1e1d) }, /* HP hs2300 a.k.a MC8775 */
1604 + { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
1605 + { USB_DEVICE(0x1199, 0x6821) }, /* Sierra Wireless AirCard 875U */
1606 + { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
1607 + { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
1608 + { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite*/
1609 + { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
1610 + { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
1611 + { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
1612 + { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
1613 + { USB_DEVICE(0x1199, 0x6855) }, /* Sierra Wireless AirCard 880 U */
1614 + { USB_DEVICE(0x1199, 0x6856) }, /* Sierra Wireless AirCard 881 U */
1615 + { USB_DEVICE(0x1199, 0x6859) }, /* Sierra Wireless AirCard 885 E */
1616 + { USB_DEVICE(0x1199, 0x685A) }, /* Sierra Wireless AirCard 885 E */
1618 + { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */
1619 + { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */
1621 + { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
1622 + { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra Wireless PC 5220 */
1623 + { USB_DEVICE(0x05C6, 0x6613) }, /* Onda H600/ZTE MF330 */
1627 +MODULE_DEVICE_TABLE(usb, id_table);
1629 +static struct usb_driver sierra_driver = {
1630 +// .owner = THIS_MODULE,
1631 + .name = "Sierra wireless",
1632 + .probe = usb_serial_probe,
1633 + .disconnect = usb_serial_disconnect,
1634 + .id_table = id_table,
1637 +static struct usb_serial_device_type sierra_device = {
1639 + .owner = THIS_MODULE,
1640 + .name = "Sierra Wireless",
1642 + .id_table = id_table,
1643 + .num_interrupt_in = NUM_DONT_CARE,
1644 + .num_bulk_in = NUM_DONT_CARE,
1645 + .num_bulk_out = NUM_DONT_CARE,
1647 + //.startup = sw_attach,
1648 + .shutdown = sw_usb_serial_generic_shutdown,
1649 + .open = sw_usb_serial_generic_open,
1650 + .close = sw_usb_serial_generic_close,
1653 +#define MAX_NUM_PORTS 8
1655 +/* local function prototypes */
1656 +static int serial_open (struct tty_struct *tty, struct file * filp);
1657 +static void serial_close (struct tty_struct *tty, struct file * filp);
1658 +static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count);
1659 +static int serial_write_room (struct tty_struct *tty);
1660 +static int serial_chars_in_buffer (struct tty_struct *tty);
1661 +static void serial_throttle (struct tty_struct * tty);
1662 +static void serial_unthrottle (struct tty_struct * tty);
1663 +static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg);
1664 +static void serial_set_termios (struct tty_struct *tty, struct termios * old);
1665 +//static void serial_shutdown (struct usb_serial *serial);
1666 +static void serial_break (struct tty_struct *tty, int break_state);
1667 +static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
1668 +static int generic_write_room (struct usb_serial_port *port);
1669 +static void generic_cleanup (struct usb_serial_port *port);
1670 +static int generic_chars_in_buffer (struct usb_serial_port *port);
1671 +//static void generic_shutdown (struct usb_serial *serial);
1674 +static struct tty_driver serial_tty_driver = {
1675 + .magic = TTY_DRIVER_MAGIC,
1676 + .driver_name = "usb-serial",
1677 +#ifndef CONFIG_DEVFS_FS
1680 + .name = "usb/tts/%d",
1682 + .major = SERIAL_TTY_MAJOR,
1684 + .num = SERIAL_TTY_MINORS,
1685 + .type = TTY_DRIVER_TYPE_SERIAL,
1686 + .subtype = SERIAL_TYPE_NORMAL,
1687 + .flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
1689 + .refcount = &serial_refcount,
1690 + .table = serial_tty,
1691 + .termios = serial_termios,
1692 + .termios_locked = serial_termios_locked,
1694 + .open = serial_open,
1695 + .close = serial_close,
1696 + .write = serial_write,
1697 + .write_room = serial_write_room,
1698 + .ioctl = serial_ioctl,
1699 + .set_termios = serial_set_termios,
1700 + .throttle = serial_throttle,
1701 + .unthrottle = serial_unthrottle,
1702 + .break_ctl = serial_break,
1703 + .chars_in_buffer = serial_chars_in_buffer,
1704 + .read_proc = serial_read_proc,
1709 +/*****************************************************************************
1710 + * Driver tty interface functions
1711 + *****************************************************************************/
1712 +static struct usb_serial *get_serial_by_minor (unsigned int minor)
1714 + return serial_table[minor];
1717 +static int serial_open (struct tty_struct *tty, struct file * filp)
1719 + struct usb_serial *serial;
1720 + struct usb_serial_port *port;
1721 + unsigned int portNumber;
1724 + dbg("%s", __FUNCTION__);
1726 + /* initialize the pointer incase something fails */
1727 + tty->driver_data = NULL;
1729 + /* get the serial object associated with this tty pointer */
1730 + serial = get_serial_by_minor (MINOR(tty->device));
1732 + if (serial_paranoia_check (serial, __FUNCTION__))
1735 + /* set up our port structure making the tty driver remember our port object, and us it */
1736 + portNumber = MINOR(tty->device) - serial->minor;
1737 + port = &serial->port[portNumber];
1738 + tty->driver_data = port;
1740 + down (&port->sem);
1743 + /* lock this module before we call it */
1744 + if (serial->type->owner)
1745 + __MOD_INC_USE_COUNT(serial->type->owner);
1747 + ++port->open_count;
1748 + if (port->open_count == 1) {
1749 + /* only call the device specific open if this
1750 + * is the first time the port is opened */
1751 + if (serial->type->open)
1752 + retval = serial->type->open(port, filp);
1754 + retval = sw_usb_serial_generic_open(port, filp);//@.@
1758 + port->open_count = 0;
1759 + if (serial->type->owner)
1760 + __MOD_DEC_USE_COUNT(serial->type->owner);
1767 +static void __serial_close(struct usb_serial_port *port, struct file *filp)
1769 + if (!port->open_count) {
1770 + dbg ("%s - port not opened", __FUNCTION__);
1774 + --port->open_count;
1775 + if (port->open_count <= 0) {
1776 + /* only call the device specific close if this
1777 + * port is being closed by the last owner */
1778 + if (port->serial->type->close)
1779 + port->serial->type->close(port, filp);
1781 + //generic_close(port, filp);
1782 + sw_usb_serial_generic_close(port, filp);
1783 + port->open_count = 0;
1786 + if (port->serial->type->owner)
1787 + __MOD_DEC_USE_COUNT(port->serial->type->owner);
1790 +static void serial_close(struct tty_struct *tty, struct file * filp)
1792 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1793 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1798 + down (&port->sem);
1800 + dbg("%s - port %d", __FUNCTION__, port->number);
1802 + /* if disconnect beat us to the punch here, there's nothing to do */
1803 + if (tty->driver_data) {
1804 + __serial_close(port, filp);
1810 +static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
1812 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1813 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1814 + int retval = -EINVAL;
1819 + down (&port->sem);
1821 + dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
1823 + if (!port->open_count) {
1824 + dbg("%s - port not opened", __FUNCTION__);
1828 + /* pass on to the driver specific version of this function if it is available */
1829 + if (serial->type->write)
1830 + retval = serial->type->write(port, from_user, buf, count);
1832 + retval = generic_write(port, from_user, buf, count);
1839 +static int serial_write_room (struct tty_struct *tty)
1841 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1842 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1843 + int retval = -EINVAL;
1848 + down (&port->sem);
1850 + dbg("%s - port %d", __FUNCTION__, port->number);
1852 + if (!port->open_count) {
1853 + dbg("%s - port not open", __FUNCTION__);
1857 + /* pass on to the driver specific version of this function if it is available */
1858 + if (serial->type->write_room)
1859 + retval = serial->type->write_room(port);
1861 + retval = generic_write_room(port);
1868 +static int serial_chars_in_buffer (struct tty_struct *tty)
1870 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1871 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1872 + int retval = -EINVAL;
1877 + down (&port->sem);
1879 + dbg("%s = port %d", __FUNCTION__, port->number);
1881 + if (!port->open_count) {
1882 + dbg("%s - port not open", __FUNCTION__);
1886 + /* pass on to the driver specific version of this function if it is available */
1887 + if (serial->type->chars_in_buffer)
1888 + retval = serial->type->chars_in_buffer(port);
1890 + retval = generic_chars_in_buffer(port);
1897 +static void serial_throttle (struct tty_struct * tty)
1899 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1900 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1905 + down (&port->sem);
1907 + dbg("%s - port %d", __FUNCTION__, port->number);
1909 + if (!port->open_count) {
1910 + dbg ("%s - port not open", __FUNCTION__);
1914 + /* pass on to the driver specific version of this function */
1915 + if (serial->type->throttle)
1916 + serial->type->throttle(port);
1922 +static void serial_unthrottle (struct tty_struct * tty)
1924 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1925 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1930 + down (&port->sem);
1932 + dbg("%s - port %d", __FUNCTION__, port->number);
1934 + if (!port->open_count) {
1935 + dbg("%s - port not open", __FUNCTION__);
1939 + /* pass on to the driver specific version of this function */
1940 + if (serial->type->unthrottle)
1941 + serial->type->unthrottle(port);
1947 +static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
1949 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1950 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1951 + int retval = -ENODEV;
1956 + down (&port->sem);
1958 + dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
1960 + if (!port->open_count) {
1961 + dbg ("%s - port not open", __FUNCTION__);
1965 + /* pass on to the driver specific version of this function if it is available */
1966 + if (serial->type->ioctl)
1967 + retval = serial->type->ioctl(port, file, cmd, arg);
1969 + retval = -ENOIOCTLCMD;
1976 +static void serial_set_termios (struct tty_struct *tty, struct termios * old)
1978 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1979 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1984 + down (&port->sem);
1986 + dbg("%s - port %d", __FUNCTION__, port->number);
1988 + if (!port->open_count) {
1989 + dbg("%s - port not open", __FUNCTION__);
1993 + /* pass on to the driver specific version of this function if it is available */
1994 + if (serial->type->set_termios)
1995 + serial->type->set_termios(port, old);
2001 +static void serial_break (struct tty_struct *tty, int break_state)
2003 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
2004 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
2009 + down (&port->sem);
2011 + dbg("%s - port %d", __FUNCTION__, port->number);
2013 + if (!port->open_count) {
2014 + dbg("%s - port not open", __FUNCTION__);
2018 + /* pass on to the driver specific version of this function if it is available */
2019 + if (serial->type->break_ctl)
2020 + serial->type->break_ctl(port, break_state);
2026 +static void serial_shutdown (struct usb_serial *serial)
2028 + dbg ("%s", __FUNCTION__);
2030 + if (serial->type->shutdown)
2031 + serial->type->shutdown(serial);
2033 + generic_shutdown(serial);
2036 +static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
2038 + struct usb_serial *serial;
2044 + dbg("%s", __FUNCTION__);
2045 + length += sprintf (page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION);
2046 + for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
2047 + serial = get_serial_by_minor(i);
2048 + if (serial == NULL)
2051 + length += sprintf (page+length, "%d:", i);
2052 + if (serial->type->owner)
2053 + length += sprintf (page+length, " module:%s", serial->type->owner->name);
2054 + length += sprintf (page+length, " name:\"%s\"", serial->type->name);
2055 + length += sprintf (page+length, " vendor:%04x product:%04x", serial->vendor, serial->product);
2056 + length += sprintf (page+length, " num_ports:%d", serial->num_ports);
2057 + length += sprintf (page+length, " port:%d", i - serial->minor + 1);
2059 + usb_make_path(serial->dev, tmp, sizeof(tmp));
2060 + length += sprintf (page+length, " path:%s", tmp);
2062 + length += sprintf (page+length, "\n");
2063 + if ((length + begin) > (off + count))
2065 + if ((length + begin) < off) {
2072 + if (off >= (length + begin))
2074 + *start = page + (off-begin);
2075 + return ((count < begin+length-off) ? count : begin+length-off);
2079 +/*-----------------------------------------------------------*/
2080 +static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
2082 + struct usb_serial *serial = port->serial;
2085 + dbg("%s - port %d", __FUNCTION__, port->number);
2088 + dbg("%s - write request of 0 bytes", __FUNCTION__);
2092 + /* only do something if we have a bulk out endpoint */
2093 + if (serial->num_bulk_out) {
2094 + if (port->write_urb->status == -EINPROGRESS) {
2095 + dbg("%s - already writing", __FUNCTION__);
2099 + count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
2102 + if (copy_from_user(port->write_urb->transfer_buffer, buf, count))
2106 + memcpy (port->write_urb->transfer_buffer, buf, count);
2109 + usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
2111 + /* set up our urb */
2112 + usb_fill_bulk_urb (port->write_urb, serial->dev,
2113 + usb_sndbulkpipe (serial->dev,
2114 + port->bulk_out_endpointAddress),
2115 + port->write_urb->transfer_buffer, count,
2116 + ((serial->type->write_bulk_callback) ?
2117 + serial->type->write_bulk_callback :
2118 + generic_write_bulk_callback), port);
2120 + /* send the data out the bulk port */
2121 + result = usb_submit_urb(port->write_urb);
2123 + err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
2130 + /* no bulk out, so return 0 bytes written */
2134 +static int generic_write_room (struct usb_serial_port *port)
2136 + struct usb_serial *serial = port->serial;
2139 + dbg("%s - port %d", __FUNCTION__, port->number);
2141 + if (serial->num_bulk_out) {
2142 + if (port->write_urb->status != -EINPROGRESS)
2143 + room = port->bulk_out_size;
2146 + dbg("%s - returns %d", __FUNCTION__, room);
2150 +static int generic_chars_in_buffer (struct usb_serial_port *port)
2152 + struct usb_serial *serial = port->serial;
2155 + dbg("%s - port %d", __FUNCTION__, port->number);
2157 + if (serial->num_bulk_out) {
2158 + if (port->write_urb->status == -EINPROGRESS)
2159 + chars = port->write_urb->transfer_buffer_length;
2162 + dbg("%s - returns %d", __FUNCTION__, chars);
2166 +static void generic_shutdown (struct usb_serial *serial)
2170 + dbg("%s", __FUNCTION__);
2172 + /* stop reads and writes on all ports */
2173 + for (i=0; i < serial->num_ports; ++i) {
2174 + generic_cleanup (&serial->port[i]);
2177 +static void generic_cleanup (struct usb_serial_port *port)
2179 + struct usb_serial *serial = port->serial;
2181 + dbg("%s - port %d", __FUNCTION__, port->number);
2183 + if (serial->dev) {
2184 + /* shutdown any bulk reads that might be going on */
2185 + if (serial->num_bulk_out)
2186 + usb_unlink_urb (port->write_urb);
2187 + if (serial->num_bulk_in)
2188 + usb_unlink_urb (port->read_urb);
2192 +/*----------------------------------------------------------*/
2193 +static void generic_write_bulk_callback (struct urb *urb)
2195 + struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
2196 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
2198 + dbg("%s - port %d", __FUNCTION__, port->number);
2201 + dbg("%s - bad serial pointer, exiting", __FUNCTION__);
2205 + if (urb->status) {
2206 + dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
2210 + queue_task(&port->tqueue, &tq_immediate);
2211 + mark_bh(IMMEDIATE_BH);
2216 +static struct usb_serial *get_free_serial (int num_ports, int *minor)
2218 + struct usb_serial *serial = NULL;
2222 + dbg("%s %d", __FUNCTION__, num_ports);
2225 + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
2226 + if (serial_table[i])
2230 + for (j = 1; j <= num_ports-1; ++j)
2231 + if (serial_table[i+j])
2233 + if (good_spot == 0)
2236 + if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) {
2237 + err("%s - Out of memory", __FUNCTION__);
2240 + memset(serial, 0, sizeof(struct usb_serial));
2241 + serial->magic = USB_SERIAL_MAGIC;
2242 + serial_table[i] = serial;
2244 + dbg("%s - minor base = %d", __FUNCTION__, *minor);
2245 + for (i = *minor+1; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i)
2246 + serial_table[i] = serial;
2252 +static void return_serial (struct usb_serial *serial)
2256 + dbg("%s", __FUNCTION__);
2258 + if (serial == NULL)
2261 + for (i = 0; i < serial->num_ports; ++i) {
2262 + serial_table[serial->minor + i] = NULL;
2268 +static void port_softint(void *private)
2270 + struct usb_serial_port *port = (struct usb_serial_port *)private;
2271 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
2272 + struct tty_struct *tty;
2274 + dbg("%s - port %d", __FUNCTION__, port->number);
2283 + if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup) {
2284 + dbg("%s - write wakeup call.", __FUNCTION__);
2285 + (tty->ldisc.write_wakeup)(tty);
2288 + wake_up_interruptible(&tty->write_wait);
2292 +static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,
2293 + const struct usb_device_id *id)
2295 + struct usb_serial *serial = NULL;
2296 + struct usb_serial_port *port;
2297 + struct usb_interface *interface;
2298 + struct usb_interface_descriptor *iface_desc;
2299 + struct usb_endpoint_descriptor *endpoint;
2300 + struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS];
2301 + struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS];
2302 + struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS];
2303 + struct usb_serial_device_type *type = NULL;
2304 + struct list_head *tmp;
2309 + int num_interrupt_in = 0;
2310 + int num_bulk_in = 0;
2311 + int num_bulk_out = 0;
2313 + int max_endpoints;
2314 + const struct usb_device_id *id_pattern = NULL;
2316 + /* loop through our list of known serial converters, and see if this
2317 + device matches. */
2319 + interface = &dev->actconfig->interface[ifnum];
2320 + list_for_each (tmp, &usb_serial_driver_list) {
2321 + type = list_entry(tmp, struct usb_serial_device_type, driver_list);
2322 + id_pattern = usb_match_id(dev, interface, type->id_table);
2323 + if (id_pattern != NULL) {
2324 + dbg("descriptor matches");
2331 + dbg("none matched");
2334 + /* descriptor matches, let's find the endpoints needed */
2335 + /* check out the endpoints */
2336 + iface_desc = &interface->altsetting[0];
2337 + for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
2338 + endpoint = &iface_desc->endpoint[i];
2340 + if ((endpoint->bEndpointAddress & 0x80) &&
2341 + ((endpoint->bmAttributes & 3) == 0x02)) {
2342 + /* we found a bulk in endpoint */
2343 + dbg("found bulk in");
2344 + bulk_in_endpoint[num_bulk_in] = endpoint;
2348 + if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
2349 + ((endpoint->bmAttributes & 3) == 0x02)) {
2350 + /* we found a bulk out endpoint */
2351 + dbg("found bulk out");
2352 + bulk_out_endpoint[num_bulk_out] = endpoint;
2356 + if ((endpoint->bEndpointAddress & 0x80) &&
2357 + ((endpoint->bmAttributes & 3) == 0x03)) {
2358 + /* we found a interrupt in endpoint */
2359 + dbg("found interrupt in");
2360 + interrupt_in_endpoint[num_interrupt_in] = endpoint;
2361 + ++num_interrupt_in;
2365 +#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
2366 + /* BEGIN HORRIBLE HACK FOR PL2303 */
2367 + /* this is needed due to the looney way its endpoints are set up */
2368 + if (((dev->descriptor.idVendor == PL2303_VENDOR_ID) &&
2369 + (dev->descriptor.idProduct == PL2303_PRODUCT_ID)) ||
2370 + ((dev->descriptor.idVendor == ATEN_VENDOR_ID) &&
2371 + (dev->descriptor.idProduct == ATEN_PRODUCT_ID))) {
2373 + /* check out the endpoints of the other interface*/
2374 + interface = &dev->actconfig->interface[ifnum ^ 1];
2375 + iface_desc = &interface->altsetting[0];
2376 + for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
2377 + endpoint = &iface_desc->endpoint[i];
2378 + if ((endpoint->bEndpointAddress & 0x80) &&
2379 + ((endpoint->bmAttributes & 3) == 0x03)) {
2380 + /* we found a interrupt in endpoint */
2381 + dbg("found interrupt in for Prolific device on separate interface");
2382 + interrupt_in_endpoint[num_interrupt_in] = endpoint;
2383 + ++num_interrupt_in;
2388 + /* Now make sure the PL-2303 is configured correctly.
2389 + * If not, give up now and hope this hack will work
2390 + * properly during a later invocation of usb_serial_probe
2392 + if (num_bulk_in == 0 || num_bulk_out == 0) {
2393 + info("PL-2303 hack: descriptors matched but endpoints did not");
2397 + /* END HORRIBLE HACK FOR PL2303 */
2400 + /* found all that we need */
2401 + info("%s converter detected", type->name);
2403 +#ifdef CONFIG_USB_SERIAL_SIERRAWIRELESS
2404 + if (type == &sierra_driver) {
2405 + num_ports = num_bulk_out;
2406 + if (num_ports == 0) {
2407 + err("Sierra 3G device with no bulk out, not allowed.");
2412 + num_ports = type->num_ports;
2414 + serial = get_free_serial (num_ports, &minor);
2415 + if (serial == NULL) {
2416 + err("No more free serial devices");
2420 + serial->dev = dev;
2421 + serial->type = type;
2422 + serial->interface = interface;
2423 + serial->minor = minor;
2424 + serial->num_ports = num_ports;
2425 + serial->num_bulk_in = num_bulk_in;
2426 + serial->num_bulk_out = num_bulk_out;
2427 + serial->num_interrupt_in = num_interrupt_in;
2428 + serial->vendor = dev->descriptor.idVendor;
2429 + serial->product = dev->descriptor.idProduct;
2431 + /* set up the endpoint information */
2432 + for (i = 0; i < num_bulk_in; ++i) {
2433 + endpoint = bulk_in_endpoint[i];
2434 + port = &serial->port[i];
2435 + port->read_urb = usb_alloc_urb (0);
2436 + if (!port->read_urb) {
2437 + err("No free urbs available");
2440 +//Amin marked buffer_size = endpoint->wMaxPacketSize;
2441 +// ===> 20060310 Amin modify for improve EVDO and HSDPA Card
2442 + buffer_size = 2048;
2443 + printk("KERNEL DEBUG => USBSERIAL.O buffer_size = 2048\n");
2444 +// <=== 20060310 Amin modify for improve EVDO and HSDPA Card
2445 + port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
2446 + port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
2447 + if (!port->bulk_in_buffer) {
2448 + err("Couldn't allocate bulk_in_buffer");
2451 + usb_fill_bulk_urb (port->read_urb, dev,
2452 + usb_rcvbulkpipe (dev,
2453 + endpoint->bEndpointAddress),
2454 + port->bulk_in_buffer, buffer_size,
2455 + ((serial->type->read_bulk_callback) ?
2456 + serial->type->read_bulk_callback :
2457 + sw_usb_serial_generic_read_bulk_callback),
2461 + for (i = 0; i < num_bulk_out; ++i) {
2462 + endpoint = bulk_out_endpoint[i];
2463 + port = &serial->port[i];
2464 + port->write_urb = usb_alloc_urb(0);
2465 + if (!port->write_urb) {
2466 + err("No free urbs available");
2469 + buffer_size = endpoint->wMaxPacketSize;
2470 + port->bulk_out_size = buffer_size;
2471 + port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
2472 + port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL);
2473 + if (!port->bulk_out_buffer) {
2474 + err("Couldn't allocate bulk_out_buffer");
2477 + usb_fill_bulk_urb (port->write_urb, dev,
2478 + usb_sndbulkpipe (dev,
2479 + endpoint->bEndpointAddress),
2480 + port->bulk_out_buffer, buffer_size,
2481 + ((serial->type->write_bulk_callback) ?
2482 + serial->type->write_bulk_callback :
2483 + generic_write_bulk_callback),
2487 + for (i = 0; i < num_interrupt_in; ++i) {
2488 + endpoint = interrupt_in_endpoint[i];
2489 + port = &serial->port[i];
2490 + port->interrupt_in_urb = usb_alloc_urb(0);
2491 + if (!port->interrupt_in_urb) {
2492 + err("No free urbs available");
2495 + buffer_size = endpoint->wMaxPacketSize;
2496 + port->interrupt_in_endpointAddress = endpoint->bEndpointAddress;
2497 + port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
2498 + if (!port->interrupt_in_buffer) {
2499 + err("Couldn't allocate interrupt_in_buffer");
2502 + usb_fill_int_urb (port->interrupt_in_urb, dev,
2503 + usb_rcvintpipe (dev,
2504 + endpoint->bEndpointAddress),
2505 + port->interrupt_in_buffer, buffer_size,
2506 + serial->type->read_int_callback, port,
2507 + endpoint->bInterval);
2510 + /* initialize some parts of the port structures */
2511 + /* we don't use num_ports here cauz some devices have more endpoint pairs than ports */
2512 + max_endpoints = max(num_bulk_in, num_bulk_out);
2513 + max_endpoints = max(max_endpoints, num_interrupt_in);
2514 + max_endpoints = max(max_endpoints, (int)serial->num_ports);
2515 + dbg("%s - setting up %d port structures for this device", __FUNCTION__, max_endpoints);
2516 + for (i = 0; i < max_endpoints; ++i) {
2517 + port = &serial->port[i];
2518 + port->number = i + serial->minor;
2519 + port->serial = serial;
2520 + port->magic = USB_SERIAL_PORT_MAGIC;
2521 + port->tqueue.routine = port_softint;
2522 + port->tqueue.data = port;
2523 + init_MUTEX (&port->sem);
2526 + /* if this device type has a startup function, call it */
2527 + if (type->startup) {
2528 + i = type->startup (serial);
2535 + /* initialize the devfs nodes for this device and let the user know what ports we are bound to */
2536 + for (i = 0; i < serial->num_ports; ++i) {
2537 + tty_register_devfs (&serial_tty_driver, 0, serial->port[i].number);
2538 + info("%s converter now attached to ttyUSB%d (or usb/tts/%d for devfs)",
2539 + type->name, serial->port[i].number, serial->port[i].number);
2542 + return serial; /* success */
2546 + for (i = 0; i < num_bulk_in; ++i) {
2547 + port = &serial->port[i];
2548 + if (port->read_urb)
2549 + usb_free_urb (port->read_urb);
2550 + if (port->bulk_in_buffer)
2551 + kfree (port->bulk_in_buffer);
2553 + for (i = 0; i < num_bulk_out; ++i) {
2554 + port = &serial->port[i];
2555 + if (port->write_urb)
2556 + usb_free_urb (port->write_urb);
2557 + if (port->bulk_out_buffer)
2558 + kfree (port->bulk_out_buffer);
2560 + for (i = 0; i < num_interrupt_in; ++i) {
2561 + port = &serial->port[i];
2562 + if (port->interrupt_in_urb)
2563 + usb_free_urb (port->interrupt_in_urb);
2564 + if (port->interrupt_in_buffer)
2565 + kfree (port->interrupt_in_buffer);
2568 + /* return the minor range that this device had */
2569 + return_serial (serial);
2571 + /* free up any memory that we allocated */
2576 +static void usb_serial_disconnect(struct usb_device *dev, void *ptr)
2578 + struct usb_serial *serial = (struct usb_serial *) ptr;
2579 + struct usb_serial_port *port;
2582 + dbg ("%s", __FUNCTION__);
2584 + /* fail all future close/read/write/ioctl/etc calls */
2585 + for (i = 0; i < serial->num_ports; ++i) {
2586 + port = &serial->port[i];
2587 + down (&port->sem);
2588 + if (port->tty != NULL) {
2589 + while (port->open_count > 0) {
2590 + //__serial_close(port, NULL);
2591 + sw_usb_serial_generic_close(port,NULL);
2593 + port->tty->driver_data = NULL;
2598 + serial->dev = NULL;
2599 + //serial_shutdown (serial);
2600 + sw_usb_serial_generic_shutdown(serial);
2602 + for (i = 0; i < serial->num_ports; ++i)
2603 + serial->port[i].open_count = 0;
2605 + for (i = 0; i < serial->num_bulk_in; ++i) {
2606 + port = &serial->port[i];
2607 + if (port->read_urb) {
2608 + usb_unlink_urb (port->read_urb);
2609 + usb_free_urb (port->read_urb);
2611 + if (port->bulk_in_buffer)
2612 + kfree (port->bulk_in_buffer);
2614 + for (i = 0; i < serial->num_bulk_out; ++i) {
2615 + port = &serial->port[i];
2616 + if (port->write_urb) {
2617 + usb_unlink_urb (port->write_urb);
2618 + usb_free_urb (port->write_urb);
2620 + if (port->bulk_out_buffer)
2621 + kfree (port->bulk_out_buffer);
2623 + for (i = 0; i < serial->num_interrupt_in; ++i) {
2624 + port = &serial->port[i];
2625 + if (port->interrupt_in_urb) {
2626 + usb_unlink_urb (port->interrupt_in_urb);
2627 + usb_free_urb (port->interrupt_in_urb);
2629 + if (port->interrupt_in_buffer)
2630 + kfree (port->interrupt_in_buffer);
2633 + for (i = 0; i < serial->num_ports; ++i) {
2634 + tty_unregister_devfs (&serial_tty_driver, serial->port[i].number);
2635 + info("%s converter now disconnected from ttyUSB%d", serial->type->name, serial->port[i].number);
2638 + /* return the minor range that this device had */
2639 + return_serial (serial);
2641 + /* free up any memory that we allocated */
2645 + info("device disconnected");
2651 +static int sw_attach(struct usb_serial *serial)
2653 + struct usb_device *hdev = serial->dev;
2656 + dbg("%s - serial(0x%p)", __FUNCTION__, serial);
2658 + rc = usb_control_msg(
2660 + usb_sndctrlpipe(hdev, 0),
2661 + USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE, /* bRequest */
2662 + USB_TYPE_VENDOR|USB_RECIP_DEVICE, /* bmRequestType */
2663 + USB_DEVICE_POWER_STATE_D0, /* wValue */
2667 + 1000); /* Timeout */
2669 + err("%s - rc(%d)", __FUNCTION__, rc);
2673 +//void sw_usb_serial_generic_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
2674 +static void sw_usb_serial_generic_read_bulk_callback (struct urb *urb)
2676 + struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
2677 + struct usb_serial *serial = port->serial;
2678 + struct tty_struct *tty;
2679 + unsigned char *data = urb->transfer_buffer;
2683 + dbg("%s - port %d", __FUNCTION__, port->number);
2685 + if (urb->status) {
2686 + dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
2690 + //usb_serial_dbg_data(__FILE__, __FUNCTION__, urb->actual_length, data);
2693 + if (tty && urb->actual_length) {
2695 + tty_buffer_request_room(tty, urb->actual_length);
2696 + tty_insert_flip_string(tty, data, urb->actual_length);
2697 + tty_flip_buffer_push(tty);
2700 + for (i = 0; i < urb->actual_length ; ++i) {
2701 + /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
2702 + if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
2703 + tty_flip_buffer_push(tty);
2705 + /* this doesn't actually push the data through unless tty->low_latency is set */
2706 + tty_insert_flip_char(tty, data[i], 0);
2708 + tty_flip_buffer_push(tty);
2713 + dbg("%s: empty read urb received", __FUNCTION__);
2715 + /* Continue trying to always read */
2716 + usb_fill_bulk_urb (port->read_urb, serial->dev,
2717 + usb_rcvbulkpipe (serial->dev,
2718 + port->bulk_in_endpointAddress),
2719 + port->read_urb->transfer_buffer,
2720 + port->read_urb->transfer_buffer_length,
2721 + ((serial->type->read_bulk_callback) ?
2722 + serial->type->read_bulk_callback :
2723 + sw_usb_serial_generic_read_bulk_callback), port);
2724 + result = usb_submit_urb(port->read_urb);
2725 + //result = usb_submit_urb(port->read_urb, GFP_ATOMIC); //for kernel 2.6
2727 + dbg("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
2730 +static int generic_open (struct usb_serial_port *port, struct file *filp)
2732 + struct usb_serial *serial = port->serial;
2735 + dbg("%s - port %d", __FUNCTION__, port->number);
2737 + /* force low_latency on so that our tty_push actually forces the data through,
2738 + otherwise it is scheduled, and with high data rates (like with OHCI) data
2741 + port->tty->low_latency = 1;
2743 + /* if we have a bulk interrupt, start reading from it */
2744 + if (serial->num_bulk_in) {
2745 + /* Start reading from the device */
2746 + usb_fill_bulk_urb (port->read_urb, serial->dev,
2747 + usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
2748 + port->read_urb->transfer_buffer,
2749 + port->read_urb->transfer_buffer_length,
2750 + ((serial->type->read_bulk_callback) ?
2751 + serial->type->read_bulk_callback :
2752 + sw_usb_serial_generic_read_bulk_callback),
2754 + result = usb_submit_urb(port->read_urb); //, GFP_KERNEL);
2756 + //dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
2757 + dbg("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
2764 +int sw_usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
2767 + struct usb_serial *serial = port->serial;
2768 + struct usb_device *hdev = serial->dev;
2770 + dbg("%s - port %d", __FUNCTION__, port->number);
2772 + rc = generic_open(port, filp);
2773 + err("%s - rc(%d)", __FUNCTION__, rc);
2777 + rc = usb_control_msg(
2779 + usb_sndctrlpipe(hdev, 0),
2780 + SET_CONTROL_LINE_STATE, /* bRequest */
2781 + USB_TYPE_CLASS|USB_RECIP_INTERFACE, /* bmRequestType */
2782 + ACM_CTRL_DTR|ACM_CTRL_RTS, /* wValue */
2786 + 1000); /* Timeout */
2787 + err("%s - usb_control_msg: rc(%d)", __FUNCTION__, rc);
2793 +static void generic_cleanup (struct usb_serial_port *port)
2795 + struct usb_serial *serial = port->serial;
2797 + dbg("%s - port %d", __FUNCTION__, port->number);
2799 + if (serial->dev) {
2800 + /* shutdown any bulk reads that might be going on */
2801 + if (serial->num_bulk_out)
2802 + usb_unlink_urb(port->write_urb);
2803 + //usb_kill_urb(port->write_urb);
2804 + if (serial->num_bulk_in)
2805 + usb_unlink_urb(port->read_urb);
2806 + //usb_kill_urb(port->read_urb);
2810 +static void sw_usb_serial_generic_close (struct usb_serial_port *port, struct file * filp)
2813 + struct usb_serial *serial = port->serial;
2814 + struct usb_device *hdev = serial->dev;
2816 + dbg("%s - port %d", __FUNCTION__, port->number);
2818 + rc = usb_control_msg(
2820 + usb_sndctrlpipe(hdev, 0),
2821 + SET_CONTROL_LINE_STATE, /* bRequest */
2822 + USB_TYPE_CLASS|USB_RECIP_INTERFACE, /* bmRequestType */
2827 + 1000); /* Timeout */
2828 + err("%s - rc(%d)", __FUNCTION__, rc);
2830 + generic_cleanup (port);
2833 +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial)
2836 + struct usb_device *hdev = serial->dev;
2838 + dbg("%s serial(0x%p)", __FUNCTION__, serial);
2842 + rc = usb_control_msg(
2844 + usb_sndctrlpipe(hdev, 0),
2845 + USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE, /* bRequest */
2846 + USB_TYPE_VENDOR|USB_RECIP_DEVICE, /* bmRequestType */
2847 + USB_DEVICE_POWER_STATE_D3, /* wValue */
2851 + 1000); /* Timeout */
2852 + err("%s - rc(%d)", __FUNCTION__, rc);
2855 + /* stop reads and writes on all ports */
2856 + for (i=0; i < serial->num_ports; ++i) {
2857 + generic_cleanup(&serial->port[i]);
2860 +int usb_serial_register(struct usb_serial_device_type *new_device)
2862 + /* Add this device to our list of devices */
2863 + list_add(&new_device->driver_list, &usb_serial_driver_list);
2865 + info ("USB Serial support registered for %s", new_device->name);
2867 + usb_scan_devices();
2873 +void usb_serial_deregister(struct usb_serial_device_type *device)
2875 + struct usb_serial *serial;
2878 + info("USB Serial deregistering driver %s", device->name);
2880 + /* clear out the serial_table if the device is attached to a port */
2881 + for(i = 0; i < SERIAL_TTY_MINORS; ++i) {
2882 + serial = serial_table[i];
2883 + if ((serial != NULL) && (serial->type == device)) {
2884 + usb_driver_release_interface (&sierra_driver, serial->interface);
2885 + usb_serial_disconnect (NULL, serial);
2889 + list_del(&device->driver_list);
2892 +static int __init sierra_init(void)
2897 + /* Initalize our global data */
2898 + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
2899 + serial_table[i] = NULL;
2902 + /* register the tty driver */
2903 + serial_tty_driver.init_termios = tty_std_termios;
2904 + serial_tty_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2905 + if (tty_register_driver (&serial_tty_driver)) {
2906 + err("%s - failed to register tty driver", __FUNCTION__);
2910 + retval = usb_serial_register(&sierra_device);
2913 + tty_unregister_driver(&serial_tty_driver);
2914 + printk("%s return usb_serial_register. retval=[%d].\n",__FUNCTION__, retval);
2917 + retval = usb_register(&sierra_driver);
2919 + usb_serial_deregister(&sierra_device);
2920 + tty_unregister_driver(&serial_tty_driver);
2921 + err("usb_register failed for the Sierra 3G USB-Serial driver. Error number %d\n", retval);
2928 +static void __exit sierra_exit(void)
2930 + usb_deregister(&sierra_driver);
2931 + usb_serial_deregister(&sierra_device);
2934 +module_init(sierra_init);
2935 +module_exit(sierra_exit);
2936 +MODULE_LICENSE("GPL");
2937 diff -Naur linux-2.4.35.4-old/drivers/usb/serial/sierra.h linux-2.4.35.4/drivers/usb/serial/sierra.h
2938 --- linux-2.4.35.4-old/drivers/usb/serial/sierra.h 1969-12-31 17:00:00.000000000 -0700
2939 +++ linux-2.4.35.4/drivers/usb/serial/sierra.h 2008-01-25 10:15:35.640743578 -0700
2942 + * Sierra Wireless CDMA Wireless Serial USB drive
2944 + * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
2945 + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
2948 + * This program is free software; you can redistribute it and/or
2949 + * modify it under the terms of the GNU General Public License version
2950 + * 2 as published by the Free Software Foundation.
2952 + * Version history:
2953 + Version 1.03 (Lloyd):
2954 + Included support for DTR control and enhanced buffering (should help
2958 +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
2960 +#define USB_DEVICE_POWER_STATE_D0 0x0000
2961 +#define USB_DEVICE_POWER_STATE_D1 0x0001
2962 +#define USB_DEVICE_POWER_STATE_D2 0x0002
2963 +#define USB_DEVICE_POWER_STATE_D3 0x0003
2965 +#define SET_CONTROL_LINE_STATE 0x22
2967 + * Output control lines.
2970 +#define ACM_CTRL_DTR 0x01
2971 +#define ACM_CTRL_RTS 0x02