fix nf_conntrack_rtsp compile error on 2.6.26 (closes #3797)
[openwrt/staging/wigyori.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 +
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
1490 @@ -0,0 +1,1446 @@
1491 +/*
1492 + * Sierra Wireless CDMA Wireless Serial USB drive
1493 + *
1494 + * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
1495 + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
1496 + *
1497 + *
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.
1501 + *
1502 + * Version history:
1503 + Version 1.03 (Lloyd):
1504 + Included support for DTR control and enhanced buffering (should help
1505 + speed).
1506 + */
1507 +
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>
1523 +
1524 +#ifdef CONFIG_USB_SERIAL_DEBUG
1525 + static int debug = 1;
1526 +#else
1527 + static int debug;
1528 +#endif
1529 +
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
1534 +#endif
1535 +
1536 +#define DRIVER_VERSION "v1.03"
1537 +
1538 +#if 0
1539 +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
1540 +
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
1545 +
1546 +#define SET_CONTROL_LINE_STATE 0x22
1547 +/*
1548 + * Output control lines.
1549 + */
1550 +
1551 +#define ACM_CTRL_DTR 0x01
1552 +#define ACM_CTRL_RTS 0x02
1553 +#endif
1554 +
1555 +//static int sw_attach(struct usb_serial *serial);
1556 +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial);
1557 +
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);
1560 +
1561 +#if 1
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 */
1569 +
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 +/*-----------------------------------------------------------*/
1581 +
1582 +#endif
1583 +
1584 +
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 */
1596 +
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 */
1617 +
1618 + { USB_DEVICE(0x1199, 0x6468) }, /* Sierra Wireless MP3G - EVDO */
1619 + { USB_DEVICE(0x1199, 0x6469) }, /* Sierra Wireless MP3G - UMTS/HSPA */
1620 +
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 */
1624 + { }
1625 +};
1626 +
1627 +MODULE_DEVICE_TABLE(usb, id_table);
1628 +
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,
1635 +};
1636 +
1637 +static struct usb_serial_device_type sierra_device = {
1638 +// .driver = {
1639 + .owner = THIS_MODULE,
1640 + .name = "Sierra Wireless",
1641 +// },
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,
1646 + .num_ports = 3,
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,
1651 +};
1652 +
1653 +#define MAX_NUM_PORTS 8
1654 +
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);
1672 +
1673 +#if 1
1674 +static struct tty_driver serial_tty_driver = {
1675 + .magic = TTY_DRIVER_MAGIC,
1676 + .driver_name = "usb-serial",
1677 +#ifndef CONFIG_DEVFS_FS
1678 + .name = "ttyUSB",
1679 +#else
1680 + .name = "usb/tts/%d",
1681 +#endif
1682 + .major = SERIAL_TTY_MAJOR,
1683 + .minor_start = 0,
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,
1688 +
1689 + .refcount = &serial_refcount,
1690 + .table = serial_tty,
1691 + .termios = serial_termios,
1692 + .termios_locked = serial_termios_locked,
1693 +
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,
1705 +};
1706 +#endif
1707 +
1708 +
1709 +/*****************************************************************************
1710 + * Driver tty interface functions
1711 + *****************************************************************************/
1712 +static struct usb_serial *get_serial_by_minor (unsigned int minor)
1713 +{
1714 + return serial_table[minor];
1715 +}
1716 +
1717 +static int serial_open (struct tty_struct *tty, struct file * filp)
1718 +{
1719 + struct usb_serial *serial;
1720 + struct usb_serial_port *port;
1721 + unsigned int portNumber;
1722 + int retval = 0;
1723 +
1724 + dbg("%s", __FUNCTION__);
1725 +
1726 + /* initialize the pointer incase something fails */
1727 + tty->driver_data = NULL;
1728 +
1729 + /* get the serial object associated with this tty pointer */
1730 + serial = get_serial_by_minor (MINOR(tty->device));
1731 +
1732 + if (serial_paranoia_check (serial, __FUNCTION__))
1733 + return -ENODEV;
1734 +
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;
1739 +
1740 + down (&port->sem);
1741 + port->tty = tty;
1742 +
1743 + /* lock this module before we call it */
1744 + if (serial->type->owner)
1745 + __MOD_INC_USE_COUNT(serial->type->owner);
1746 +
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);
1753 + else
1754 + retval = sw_usb_serial_generic_open(port, filp);//@.@
1755 + }
1756 +
1757 + if (retval) {
1758 + port->open_count = 0;
1759 + if (serial->type->owner)
1760 + __MOD_DEC_USE_COUNT(serial->type->owner);
1761 + }
1762 +
1763 + up (&port->sem);
1764 + return retval;
1765 +}
1766 +
1767 +static void __serial_close(struct usb_serial_port *port, struct file *filp)
1768 +{
1769 + if (!port->open_count) {
1770 + dbg ("%s - port not opened", __FUNCTION__);
1771 + return;
1772 + }
1773 +
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);
1780 + else
1781 + //generic_close(port, filp);
1782 + sw_usb_serial_generic_close(port, filp);
1783 + port->open_count = 0;
1784 + }
1785 +
1786 + if (port->serial->type->owner)
1787 + __MOD_DEC_USE_COUNT(port->serial->type->owner);
1788 +}
1789 +
1790 +static void serial_close(struct tty_struct *tty, struct file * filp)
1791 +{
1792 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1793 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1794 +
1795 + if (!serial)
1796 + return;
1797 +
1798 + down (&port->sem);
1799 +
1800 + dbg("%s - port %d", __FUNCTION__, port->number);
1801 +
1802 + /* if disconnect beat us to the punch here, there's nothing to do */
1803 + if (tty->driver_data) {
1804 + __serial_close(port, filp);
1805 + }
1806 +
1807 + up (&port->sem);
1808 +}
1809 +
1810 +static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
1811 +{
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;
1815 +
1816 + if (!serial)
1817 + return -ENODEV;
1818 +
1819 + down (&port->sem);
1820 +
1821 + dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
1822 +
1823 + if (!port->open_count) {
1824 + dbg("%s - port not opened", __FUNCTION__);
1825 + goto exit;
1826 + }
1827 +
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);
1831 + else
1832 + retval = generic_write(port, from_user, buf, count);
1833 +
1834 +exit:
1835 + up (&port->sem);
1836 + return retval;
1837 +}
1838 +
1839 +static int serial_write_room (struct tty_struct *tty)
1840 +{
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;
1844 +
1845 + if (!serial)
1846 + return -ENODEV;
1847 +
1848 + down (&port->sem);
1849 +
1850 + dbg("%s - port %d", __FUNCTION__, port->number);
1851 +
1852 + if (!port->open_count) {
1853 + dbg("%s - port not open", __FUNCTION__);
1854 + goto exit;
1855 + }
1856 +
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);
1860 + else
1861 + retval = generic_write_room(port);
1862 +
1863 +exit:
1864 + up (&port->sem);
1865 + return retval;
1866 +}
1867 +
1868 +static int serial_chars_in_buffer (struct tty_struct *tty)
1869 +{
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;
1873 +
1874 + if (!serial)
1875 + return -ENODEV;
1876 +
1877 + down (&port->sem);
1878 +
1879 + dbg("%s = port %d", __FUNCTION__, port->number);
1880 +
1881 + if (!port->open_count) {
1882 + dbg("%s - port not open", __FUNCTION__);
1883 + goto exit;
1884 + }
1885 +
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);
1889 + else
1890 + retval = generic_chars_in_buffer(port);
1891 +
1892 +exit:
1893 + up (&port->sem);
1894 + return retval;
1895 +}
1896 +
1897 +static void serial_throttle (struct tty_struct * tty)
1898 +{
1899 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1900 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1901 +
1902 + if (!serial)
1903 + return;
1904 +
1905 + down (&port->sem);
1906 +
1907 + dbg("%s - port %d", __FUNCTION__, port->number);
1908 +
1909 + if (!port->open_count) {
1910 + dbg ("%s - port not open", __FUNCTION__);
1911 + goto exit;
1912 + }
1913 +
1914 + /* pass on to the driver specific version of this function */
1915 + if (serial->type->throttle)
1916 + serial->type->throttle(port);
1917 +
1918 +exit:
1919 + up (&port->sem);
1920 +}
1921 +
1922 +static void serial_unthrottle (struct tty_struct * tty)
1923 +{
1924 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1925 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1926 +
1927 + if (!serial)
1928 + return;
1929 +
1930 + down (&port->sem);
1931 +
1932 + dbg("%s - port %d", __FUNCTION__, port->number);
1933 +
1934 + if (!port->open_count) {
1935 + dbg("%s - port not open", __FUNCTION__);
1936 + goto exit;
1937 + }
1938 +
1939 + /* pass on to the driver specific version of this function */
1940 + if (serial->type->unthrottle)
1941 + serial->type->unthrottle(port);
1942 +
1943 +exit:
1944 + up (&port->sem);
1945 +}
1946 +
1947 +static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
1948 +{
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;
1952 +
1953 + if (!serial)
1954 + return -ENODEV;
1955 +
1956 + down (&port->sem);
1957 +
1958 + dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
1959 +
1960 + if (!port->open_count) {
1961 + dbg ("%s - port not open", __FUNCTION__);
1962 + goto exit;
1963 + }
1964 +
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);
1968 + else
1969 + retval = -ENOIOCTLCMD;
1970 +
1971 +exit:
1972 + up (&port->sem);
1973 + return retval;
1974 +}
1975 +
1976 +static void serial_set_termios (struct tty_struct *tty, struct termios * old)
1977 +{
1978 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1979 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1980 +
1981 + if (!serial)
1982 + return;
1983 +
1984 + down (&port->sem);
1985 +
1986 + dbg("%s - port %d", __FUNCTION__, port->number);
1987 +
1988 + if (!port->open_count) {
1989 + dbg("%s - port not open", __FUNCTION__);
1990 + goto exit;
1991 + }
1992 +
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);
1996 +
1997 +exit:
1998 + up (&port->sem);
1999 +}
2000 +
2001 +static void serial_break (struct tty_struct *tty, int break_state)
2002 +{
2003 + struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
2004 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
2005 +
2006 + if (!serial)
2007 + return;
2008 +
2009 + down (&port->sem);
2010 +
2011 + dbg("%s - port %d", __FUNCTION__, port->number);
2012 +
2013 + if (!port->open_count) {
2014 + dbg("%s - port not open", __FUNCTION__);
2015 + goto exit;
2016 + }
2017 +
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);
2021 +
2022 +exit:
2023 + up (&port->sem);
2024 +}
2025 +#if 0
2026 +static void serial_shutdown (struct usb_serial *serial)
2027 +{
2028 + dbg ("%s", __FUNCTION__);
2029 +
2030 + if (serial->type->shutdown)
2031 + serial->type->shutdown(serial);
2032 + else
2033 + generic_shutdown(serial);
2034 +}
2035 +#endif
2036 +static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
2037 +{
2038 + struct usb_serial *serial;
2039 + int length = 0;
2040 + int i;
2041 + off_t begin = 0;
2042 + char tmp[40];
2043 +
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)
2049 + continue;
2050 +
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);
2058 +
2059 + usb_make_path(serial->dev, tmp, sizeof(tmp));
2060 + length += sprintf (page+length, " path:%s", tmp);
2061 +
2062 + length += sprintf (page+length, "\n");
2063 + if ((length + begin) > (off + count))
2064 + goto done;
2065 + if ((length + begin) < off) {
2066 + begin += length;
2067 + length = 0;
2068 + }
2069 + }
2070 + *eof = 1;
2071 +done:
2072 + if (off >= (length + begin))
2073 + return 0;
2074 + *start = page + (off-begin);
2075 + return ((count < begin+length-off) ? count : begin+length-off);
2076 +}
2077 +
2078 +
2079 +/*-----------------------------------------------------------*/
2080 +static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
2081 +{
2082 + struct usb_serial *serial = port->serial;
2083 + int result;
2084 +
2085 + dbg("%s - port %d", __FUNCTION__, port->number);
2086 +
2087 + if (count == 0) {
2088 + dbg("%s - write request of 0 bytes", __FUNCTION__);
2089 + return (0);
2090 + }
2091 +
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__);
2096 + return (0);
2097 + }
2098 +
2099 + count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
2100 +
2101 + if (from_user) {
2102 + if (copy_from_user(port->write_urb->transfer_buffer, buf, count))
2103 + return -EFAULT;
2104 + }
2105 + else {
2106 + memcpy (port->write_urb->transfer_buffer, buf, count);
2107 + }
2108 +
2109 + usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
2110 +
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);
2119 +
2120 + /* send the data out the bulk port */
2121 + result = usb_submit_urb(port->write_urb);
2122 + if (result)
2123 + err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
2124 + else
2125 + result = count;
2126 +
2127 + return result;
2128 + }
2129 +
2130 + /* no bulk out, so return 0 bytes written */
2131 + return (0);
2132 +}
2133 +
2134 +static int generic_write_room (struct usb_serial_port *port)
2135 +{
2136 + struct usb_serial *serial = port->serial;
2137 + int room = 0;
2138 +
2139 + dbg("%s - port %d", __FUNCTION__, port->number);
2140 +
2141 + if (serial->num_bulk_out) {
2142 + if (port->write_urb->status != -EINPROGRESS)
2143 + room = port->bulk_out_size;
2144 + }
2145 +
2146 + dbg("%s - returns %d", __FUNCTION__, room);
2147 + return (room);
2148 +}
2149 +
2150 +static int generic_chars_in_buffer (struct usb_serial_port *port)
2151 +{
2152 + struct usb_serial *serial = port->serial;
2153 + int chars = 0;
2154 +
2155 + dbg("%s - port %d", __FUNCTION__, port->number);
2156 +
2157 + if (serial->num_bulk_out) {
2158 + if (port->write_urb->status == -EINPROGRESS)
2159 + chars = port->write_urb->transfer_buffer_length;
2160 + }
2161 +
2162 + dbg("%s - returns %d", __FUNCTION__, chars);
2163 + return (chars);
2164 +}
2165 +#if 0
2166 +static void generic_shutdown (struct usb_serial *serial)
2167 +{
2168 + int i;
2169 +
2170 + dbg("%s", __FUNCTION__);
2171 +
2172 + /* stop reads and writes on all ports */
2173 + for (i=0; i < serial->num_ports; ++i) {
2174 + generic_cleanup (&serial->port[i]);
2175 + }
2176 +}
2177 +static void generic_cleanup (struct usb_serial_port *port)
2178 +{
2179 + struct usb_serial *serial = port->serial;
2180 +
2181 + dbg("%s - port %d", __FUNCTION__, port->number);
2182 +
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);
2189 + }
2190 +}
2191 +#endif
2192 +/*----------------------------------------------------------*/
2193 +static void generic_write_bulk_callback (struct urb *urb)
2194 +{
2195 + struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
2196 + struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
2197 +
2198 + dbg("%s - port %d", __FUNCTION__, port->number);
2199 +
2200 + if (!serial) {
2201 + dbg("%s - bad serial pointer, exiting", __FUNCTION__);
2202 + return;
2203 + }
2204 +
2205 + if (urb->status) {
2206 + dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
2207 + return;
2208 + }
2209 +
2210 + queue_task(&port->tqueue, &tq_immediate);
2211 + mark_bh(IMMEDIATE_BH);
2212 +
2213 + return;
2214 +}
2215 +
2216 +static struct usb_serial *get_free_serial (int num_ports, int *minor)
2217 +{
2218 + struct usb_serial *serial = NULL;
2219 + int i, j;
2220 + int good_spot;
2221 +
2222 + dbg("%s %d", __FUNCTION__, num_ports);
2223 +
2224 + *minor = 0;
2225 + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
2226 + if (serial_table[i])
2227 + continue;
2228 +
2229 + good_spot = 1;
2230 + for (j = 1; j <= num_ports-1; ++j)
2231 + if (serial_table[i+j])
2232 + good_spot = 0;
2233 + if (good_spot == 0)
2234 + continue;
2235 +
2236 + if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) {
2237 + err("%s - Out of memory", __FUNCTION__);
2238 + return NULL;
2239 + }
2240 + memset(serial, 0, sizeof(struct usb_serial));
2241 + serial->magic = USB_SERIAL_MAGIC;
2242 + serial_table[i] = serial;
2243 + *minor = i;
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;
2247 + return serial;
2248 + }
2249 + return NULL;
2250 +}
2251 +
2252 +static void return_serial (struct usb_serial *serial)
2253 +{
2254 + int i;
2255 +
2256 + dbg("%s", __FUNCTION__);
2257 +
2258 + if (serial == NULL)
2259 + return;
2260 +
2261 + for (i = 0; i < serial->num_ports; ++i) {
2262 + serial_table[serial->minor + i] = NULL;
2263 + }
2264 +
2265 + return;
2266 +}
2267 +
2268 +static void port_softint(void *private)
2269 +{
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;
2273 +
2274 + dbg("%s - port %d", __FUNCTION__, port->number);
2275 +
2276 + if (!serial)
2277 + return;
2278 +
2279 + tty = port->tty;
2280 + if (!tty)
2281 + return;
2282 +
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);
2286 + }
2287 +
2288 + wake_up_interruptible(&tty->write_wait);
2289 +}
2290 +
2291 +
2292 +static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,
2293 + const struct usb_device_id *id)
2294 +{
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;
2305 + int found;
2306 + int minor;
2307 + int buffer_size;
2308 + int i;
2309 + int num_interrupt_in = 0;
2310 + int num_bulk_in = 0;
2311 + int num_bulk_out = 0;
2312 + int num_ports;
2313 + int max_endpoints;
2314 + const struct usb_device_id *id_pattern = NULL;
2315 +
2316 + /* loop through our list of known serial converters, and see if this
2317 + device matches. */
2318 + found = 0;
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");
2325 + found = 1;
2326 + break;
2327 + }
2328 + }
2329 + if (!found) {
2330 + /* no match */
2331 + dbg("none matched");
2332 + return(NULL);
2333 + }
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];
2339 +
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;
2345 + ++num_bulk_in;
2346 + }
2347 +
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;
2353 + ++num_bulk_out;
2354 + }
2355 +
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;
2362 + }
2363 + }
2364 +
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))) {
2372 + if (ifnum == 1) {
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;
2384 + }
2385 + }
2386 + }
2387 +
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
2391 + */
2392 + if (num_bulk_in == 0 || num_bulk_out == 0) {
2393 + info("PL-2303 hack: descriptors matched but endpoints did not");
2394 + return NULL;
2395 + }
2396 + }
2397 + /* END HORRIBLE HACK FOR PL2303 */
2398 +#endif
2399 +
2400 + /* found all that we need */
2401 + info("%s converter detected", type->name);
2402 +
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.");
2408 + return NULL;
2409 + }
2410 + } else
2411 +#endif
2412 + num_ports = type->num_ports;
2413 +
2414 + serial = get_free_serial (num_ports, &minor);
2415 + if (serial == NULL) {
2416 + err("No more free serial devices");
2417 + return NULL;
2418 + }
2419 +
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;
2430 +
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");
2438 + goto probe_error;
2439 + }
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");
2449 + goto probe_error;
2450 + }
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),
2458 + port);
2459 + }
2460 +
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");
2467 + goto probe_error;
2468 + }
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");
2475 + goto probe_error;
2476 + }
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),
2484 + port);
2485 + }
2486 +
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");
2493 + goto probe_error;
2494 + }
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");
2500 + goto probe_error;
2501 + }
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);
2508 + }
2509 +
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);
2524 + }
2525 +
2526 + /* if this device type has a startup function, call it */
2527 + if (type->startup) {
2528 + i = type->startup (serial);
2529 + if (i < 0)
2530 + goto probe_error;
2531 + if (i > 0)
2532 + return serial;
2533 + }
2534 +
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);
2540 + }
2541 +
2542 + return serial; /* success */
2543 +
2544 +
2545 +probe_error:
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);
2552 + }
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);
2559 + }
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);
2566 + }
2567 +
2568 + /* return the minor range that this device had */
2569 + return_serial (serial);
2570 +
2571 + /* free up any memory that we allocated */
2572 + kfree (serial);
2573 + return NULL;
2574 +}
2575 +
2576 +static void usb_serial_disconnect(struct usb_device *dev, void *ptr)
2577 +{
2578 + struct usb_serial *serial = (struct usb_serial *) ptr;
2579 + struct usb_serial_port *port;
2580 + int i;
2581 +
2582 + dbg ("%s", __FUNCTION__);
2583 + if (serial) {
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);
2592 + }
2593 + port->tty->driver_data = NULL;
2594 + }
2595 + up (&port->sem);
2596 + }
2597 +
2598 + serial->dev = NULL;
2599 + //serial_shutdown (serial);
2600 + sw_usb_serial_generic_shutdown(serial);
2601 +
2602 + for (i = 0; i < serial->num_ports; ++i)
2603 + serial->port[i].open_count = 0;
2604 +
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);
2610 + }
2611 + if (port->bulk_in_buffer)
2612 + kfree (port->bulk_in_buffer);
2613 + }
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);
2619 + }
2620 + if (port->bulk_out_buffer)
2621 + kfree (port->bulk_out_buffer);
2622 + }
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);
2628 + }
2629 + if (port->interrupt_in_buffer)
2630 + kfree (port->interrupt_in_buffer);
2631 + }
2632 +
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);
2636 + }
2637 +
2638 + /* return the minor range that this device had */
2639 + return_serial (serial);
2640 +
2641 + /* free up any memory that we allocated */
2642 + kfree (serial);
2643 +
2644 + } else {
2645 + info("device disconnected");
2646 + }
2647 +
2648 +}
2649 +
2650 +#if 0
2651 +static int sw_attach(struct usb_serial *serial)
2652 +{
2653 + struct usb_device *hdev = serial->dev;
2654 + int rc;
2655 +
2656 + dbg("%s - serial(0x%p)", __FUNCTION__, serial);
2657 +
2658 + rc = usb_control_msg(
2659 + hdev,
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 */
2664 + 0, /* wIndex */
2665 + NULL, /* Data */
2666 + 0, /* wLength */
2667 + 1000); /* Timeout */
2668 +
2669 + err("%s - rc(%d)", __FUNCTION__, rc);
2670 + return rc;
2671 +}
2672 +#endif
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)
2675 +{
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;
2680 + int result;
2681 + int i;
2682 +
2683 + dbg("%s - port %d", __FUNCTION__, port->number);
2684 +
2685 + if (urb->status) {
2686 + dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
2687 + return;
2688 + }
2689 +
2690 + //usb_serial_dbg_data(__FILE__, __FUNCTION__, urb->actual_length, data);
2691 +
2692 + tty = port->tty;
2693 + if (tty && urb->actual_length) {
2694 + #if 0
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);
2698 + #endif
2699 + #if 1
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);
2704 + }
2705 + /* this doesn't actually push the data through unless tty->low_latency is set */
2706 + tty_insert_flip_char(tty, data[i], 0);
2707 + }
2708 + tty_flip_buffer_push(tty);
2709 + #endif
2710 +
2711 + }
2712 + else
2713 + dbg("%s: empty read urb received", __FUNCTION__);
2714 +
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
2726 + if (result)
2727 + dbg("%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
2728 +}
2729 +#if 1
2730 +static int generic_open (struct usb_serial_port *port, struct file *filp)
2731 +{
2732 + struct usb_serial *serial = port->serial;
2733 + int result = 0;
2734 +
2735 + dbg("%s - port %d", __FUNCTION__, port->number);
2736 +
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
2739 + can get lost. */
2740 + if (port->tty)
2741 + port->tty->low_latency = 1;
2742 +
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),
2753 + port);
2754 + result = usb_submit_urb(port->read_urb); //, GFP_KERNEL);
2755 + if (result)
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);
2758 +
2759 + }
2760 +
2761 + return result;
2762 +}
2763 +#endif
2764 +int sw_usb_serial_generic_open (struct usb_serial_port *port, struct file *filp)
2765 +{
2766 + int rc;
2767 + struct usb_serial *serial = port->serial;
2768 + struct usb_device *hdev = serial->dev;
2769 +
2770 + dbg("%s - port %d", __FUNCTION__, port->number);
2771 +
2772 + rc = generic_open(port, filp);
2773 + err("%s - rc(%d)", __FUNCTION__, rc);
2774 +
2775 + if(0 == rc)
2776 + {
2777 + rc = usb_control_msg(
2778 + hdev,
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 */
2783 + 0, /* wIndex */
2784 + NULL, /* Data */
2785 + 0, /* wLength */
2786 + 1000); /* Timeout */
2787 + err("%s - usb_control_msg: rc(%d)", __FUNCTION__, rc);
2788 + }
2789 +
2790 + return rc;
2791 +}
2792 +
2793 +static void generic_cleanup (struct usb_serial_port *port)
2794 +{
2795 + struct usb_serial *serial = port->serial;
2796 +
2797 + dbg("%s - port %d", __FUNCTION__, port->number);
2798 +
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);
2807 + }
2808 +}
2809 +
2810 +static void sw_usb_serial_generic_close (struct usb_serial_port *port, struct file * filp)
2811 +{
2812 + int rc;
2813 + struct usb_serial *serial = port->serial;
2814 + struct usb_device *hdev = serial->dev;
2815 +
2816 + dbg("%s - port %d", __FUNCTION__, port->number);
2817 +
2818 + rc = usb_control_msg(
2819 + hdev,
2820 + usb_sndctrlpipe(hdev, 0),
2821 + SET_CONTROL_LINE_STATE, /* bRequest */
2822 + USB_TYPE_CLASS|USB_RECIP_INTERFACE, /* bmRequestType */
2823 + 0, /* wValue */
2824 + 0, /* wIndex */
2825 + NULL, /* Data */
2826 + 0, /* wLength */
2827 + 1000); /* Timeout */
2828 + err("%s - rc(%d)", __FUNCTION__, rc);
2829 +
2830 + generic_cleanup (port);
2831 +}
2832 +
2833 +static void sw_usb_serial_generic_shutdown(struct usb_serial *serial)
2834 +{
2835 + int i, rc;
2836 + struct usb_device *hdev = serial->dev;
2837 +
2838 + dbg("%s serial(0x%p)", __FUNCTION__, serial);
2839 +
2840 + if(hdev)
2841 + {
2842 + rc = usb_control_msg(
2843 + hdev,
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 */
2848 + 0, /* wIndex */
2849 + NULL, /* Data */
2850 + 0, /* wLength */
2851 + 1000); /* Timeout */
2852 + err("%s - rc(%d)", __FUNCTION__, rc);
2853 + }
2854 +
2855 + /* stop reads and writes on all ports */
2856 + for (i=0; i < serial->num_ports; ++i) {
2857 + generic_cleanup(&serial->port[i]);
2858 + }
2859 +}
2860 +int usb_serial_register(struct usb_serial_device_type *new_device)
2861 +{
2862 + /* Add this device to our list of devices */
2863 + list_add(&new_device->driver_list, &usb_serial_driver_list);
2864 +
2865 + info ("USB Serial support registered for %s", new_device->name);
2866 +
2867 + usb_scan_devices();
2868 +
2869 + return 0;
2870 +}
2871 +
2872 +
2873 +void usb_serial_deregister(struct usb_serial_device_type *device)
2874 +{
2875 + struct usb_serial *serial;
2876 + int i;
2877 +
2878 + info("USB Serial deregistering driver %s", device->name);
2879 +
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);
2886 + }
2887 + }
2888 +
2889 + list_del(&device->driver_list);
2890 +}
2891 +
2892 +static int __init sierra_init(void)
2893 +{
2894 + int retval;
2895 + int i;
2896 +
2897 + /* Initalize our global data */
2898 + for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
2899 + serial_table[i] = NULL;
2900 + }
2901 +
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__);
2907 + return -1;
2908 + }
2909 +
2910 + retval = usb_serial_register(&sierra_device);
2911 + if (retval)
2912 + {
2913 + tty_unregister_driver(&serial_tty_driver);
2914 + printk("%s return usb_serial_register. retval=[%d].\n",__FUNCTION__, retval);
2915 + return retval;
2916 + }
2917 + retval = usb_register(&sierra_driver);
2918 + if (retval){
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);
2922 + return -1;
2923 + }
2924 +
2925 + return retval;
2926 +}
2927 +
2928 +static void __exit sierra_exit(void)
2929 +{
2930 + usb_deregister(&sierra_driver);
2931 + usb_serial_deregister(&sierra_device);
2932 +}
2933 +
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
2940 @@ -0,0 +1,32 @@
2941 +/*
2942 + * Sierra Wireless CDMA Wireless Serial USB drive
2943 + *
2944 + * Current Copy modified by: Kevin Lloyd <linux@sierrawireless.com>
2945 + * Original Copy written by: 2005 Greg Kroah-Hartman <gregkh <at> suse.de>
2946 + *
2947 + *
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.
2951 + *
2952 + * Version history:
2953 + Version 1.03 (Lloyd):
2954 + Included support for DTR control and enhanced buffering (should help
2955 + speed).
2956 + */
2957 +
2958 +#define USB_VENDER_REQUEST_SET_DEVICE_POWER_STATE 0
2959 +
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
2964 +
2965 +#define SET_CONTROL_LINE_STATE 0x22
2966 +/*
2967 + * Output control lines.
2968 + */
2969 +
2970 +#define ACM_CTRL_DTR 0x01
2971 +#define ACM_CTRL_RTS 0x02
2972 +