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