1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284#include <linux/config.h>
285#include <linux/kernel.h>
286#include <linux/sched.h>
287#include <linux/signal.h>
288#include <linux/errno.h>
289#include <linux/poll.h>
290#include <linux/init.h>
291#include <linux/slab.h>
292#include <linux/fcntl.h>
293#include <linux/tty.h>
294#include <linux/tty_driver.h>
295#include <linux/tty_flip.h>
296#include <linux/module.h>
297#include <linux/spinlock.h>
298#include <linux/list.h>
299#include <linux/smp_lock.h>
300#include <linux/usb.h>
301
302#ifdef CONFIG_USB_SERIAL_DEBUG
303 static int debug = 1;
304#else
305 static int debug;
306#endif
307
308#include "usb-serial.h"
309#include "pl2303.h"
310
311
312
313
314#define DRIVER_VERSION "v1.4"
315#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux-usb/"
316#define DRIVER_DESC "USB Serial Driver core"
317
318
319
320
321static int generic_open (struct usb_serial_port *port, struct file *filp);
322static void generic_close (struct usb_serial_port *port, struct file *filp);
323static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
324static int generic_write_room (struct usb_serial_port *port);
325static int generic_chars_in_buffer (struct usb_serial_port *port);
326static void generic_read_bulk_callback (struct urb *urb);
327static void generic_write_bulk_callback (struct urb *urb);
328static void generic_shutdown (struct usb_serial *serial);
329
330
331#ifdef CONFIG_USB_SERIAL_GENERIC
332static __u16 vendor = 0x05f9;
333static __u16 product = 0xffff;
334
335static struct usb_device_id generic_device_ids[2];
336
337
338static struct usb_serial_device_type generic_device = {
339 .owner = THIS_MODULE,
340 .name = "Generic",
341 .id_table = generic_device_ids,
342 .num_interrupt_in = NUM_DONT_CARE,
343 .num_bulk_in = NUM_DONT_CARE,
344 .num_bulk_out = NUM_DONT_CARE,
345 .num_ports = 1,
346 .shutdown = generic_shutdown,
347};
348#endif
349
350
351
352
353#define POST_BSIZE 100
354struct usb_serial_post_job {
355 struct list_head link;
356 struct usb_serial_port *port;
357 int len;
358 char buff[POST_BSIZE];
359};
360static spinlock_t post_lock = SPIN_LOCK_UNLOCKED;
361static struct list_head post_list = LIST_HEAD_INIT(post_list);
362static struct tq_struct post_task;
363
364
365static int serial_open (struct tty_struct *tty, struct file * filp);
366static void serial_close (struct tty_struct *tty, struct file * filp);
367static int __serial_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
368static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count);
369static int serial_post_job(struct usb_serial_port *port, int from_user,
370 int gfp, const unsigned char *buf, int count);
371static int serial_post_one(struct usb_serial_port *port, int from_user,
372 int gfp, const unsigned char *buf, int count);
373static int serial_write_room (struct tty_struct *tty);
374static int serial_chars_in_buffer (struct tty_struct *tty);
375static void serial_throttle (struct tty_struct * tty);
376static void serial_unthrottle (struct tty_struct * tty);
377static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg);
378static void serial_set_termios (struct tty_struct *tty, struct termios * old);
379static void serial_shutdown (struct usb_serial *serial);
380
381static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,
382 const struct usb_device_id *id);
383static void usb_serial_disconnect(struct usb_device *dev, void *ptr);
384
385static struct usb_driver usb_serial_driver = {
386 .name = "serial",
387 .probe = usb_serial_probe,
388 .disconnect = usb_serial_disconnect,
389 .id_table = NULL,
390};
391
392
393
394
395
396
397
398
399
400static int serial_refcount;
401static struct tty_driver serial_tty_driver;
402static struct tty_struct * serial_tty[SERIAL_TTY_MINORS];
403static struct termios * serial_termios[SERIAL_TTY_MINORS];
404static struct termios * serial_termios_locked[SERIAL_TTY_MINORS];
405static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
406
407
408static LIST_HEAD(usb_serial_driver_list);
409
410
411static struct usb_serial *get_serial_by_minor (unsigned int minor)
412{
413 return serial_table[minor];
414}
415
416
417static struct usb_serial *get_free_serial (int num_ports, int *minor)
418{
419 struct usb_serial *serial = NULL;
420 int i, j;
421 int good_spot;
422
423 dbg("%s %d", __FUNCTION__, num_ports);
424
425 *minor = 0;
426 for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
427 if (serial_table[i])
428 continue;
429
430 good_spot = 1;
431 for (j = 1; j <= num_ports-1; ++j)
432 if (serial_table[i+j])
433 good_spot = 0;
434 if (good_spot == 0)
435 continue;
436
437 if (!(serial = kmalloc(sizeof(struct usb_serial), GFP_KERNEL))) {
438 err("%s - Out of memory", __FUNCTION__);
439 return NULL;
440 }
441 memset(serial, 0, sizeof(struct usb_serial));
442 serial->magic = USB_SERIAL_MAGIC;
443 serial_table[i] = serial;
444 *minor = i;
445 dbg("%s - minor base = %d", __FUNCTION__, *minor);
446 for (i = *minor+1; (i < (*minor + num_ports)) && (i < SERIAL_TTY_MINORS); ++i)
447 serial_table[i] = serial;
448 return serial;
449 }
450 return NULL;
451}
452
453static void return_serial (struct usb_serial *serial)
454{
455 int i;
456
457 dbg("%s", __FUNCTION__);
458
459 if (serial == NULL)
460 return;
461
462 for (i = 0; i < serial->num_ports; ++i) {
463 serial_table[serial->minor + i] = NULL;
464 }
465
466 return;
467}
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485static void post_helper(void *arg)
486{
487 struct list_head *pos;
488 struct usb_serial_post_job *job;
489 struct usb_serial_port *port;
490 struct usb_serial *serial;
491 unsigned int flags;
492
493 spin_lock_irqsave(&post_lock, flags);
494 pos = post_list.next;
495 while (pos != &post_list) {
496 job = list_entry(pos, struct usb_serial_post_job, link);
497 port = job->port;
498
499 serial = port->serial;
500 if (port->write_busy) {
501 dbg("%s - port %d busy", __FUNCTION__, port->number);
502 pos = pos->next;
503 continue;
504 }
505 list_del(&job->link);
506 spin_unlock_irqrestore(&post_lock, flags);
507
508 down(&port->sem);
509 dbg("%s - port %d len %d backlog %d", __FUNCTION__,
510 port->number, job->len, port->write_backlog);
511 if (port->tty != NULL) {
512 int rc;
513 int sent = 0;
514 while (sent < job->len) {
515 rc = __serial_write(port, 0, job->buff + sent, job->len - sent);
516 if ((rc < 0) || signal_pending(current))
517 break;
518 sent += rc;
519 if ((sent < job->len) && current->need_resched)
520 schedule();
521 }
522 }
523 up(&port->sem);
524
525 spin_lock_irqsave(&post_lock, flags);
526 port->write_backlog -= job->len;
527 kfree(job);
528 if (--serial->ref == 0)
529 kfree(serial);
530
531 pos = post_list.next;
532 }
533 spin_unlock_irqrestore(&post_lock, flags);
534}
535
536#ifdef USES_EZUSB_FUNCTIONS
537
538#define CPUCS_REG 0x7F92
539
540int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data, int length, __u8 bRequest)
541{
542 int result;
543 unsigned char *transfer_buffer;
544
545
546 if (!serial->dev) {
547 dbg("%s - no physical device present, failing.", __FUNCTION__);
548 return -ENODEV;
549 }
550
551 transfer_buffer = kmalloc (length, GFP_KERNEL);
552 if (!transfer_buffer) {
553 err("%s - kmalloc(%d) failed.", __FUNCTION__, length);
554 return -ENOMEM;
555 }
556 memcpy (transfer_buffer, data, length);
557 result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), bRequest, 0x40, address, 0, transfer_buffer, length, 3*HZ);
558 kfree (transfer_buffer);
559 return result;
560}
561
562int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit)
563{
564 int response;
565 dbg("%s - %d", __FUNCTION__, reset_bit);
566 response = ezusb_writememory (serial, CPUCS_REG, &reset_bit, 1, 0xa0);
567 if (response < 0) {
568 err("%s- %d failed", __FUNCTION__, reset_bit);
569 }
570 return response;
571}
572
573#endif
574
575
576
577
578static int serial_open (struct tty_struct *tty, struct file * filp)
579{
580 struct usb_serial *serial;
581 struct usb_serial_port *port;
582 unsigned int portNumber;
583 int retval = 0;
584
585 dbg("%s", __FUNCTION__);
586
587
588 tty->driver_data = NULL;
589
590
591 serial = get_serial_by_minor (MINOR(tty->device));
592
593 if (serial_paranoia_check (serial, __FUNCTION__))
594 return -ENODEV;
595
596
597 portNumber = MINOR(tty->device) - serial->minor;
598 port = &serial->port[portNumber];
599 tty->driver_data = port;
600
601 down (&port->sem);
602 port->tty = tty;
603
604
605 if (serial->type->owner)
606 __MOD_INC_USE_COUNT(serial->type->owner);
607
608 ++port->open_count;
609 if (port->open_count == 1) {
610
611
612 if (serial->type->open)
613 retval = serial->type->open(port, filp);
614 else
615 retval = generic_open(port, filp);
616 }
617
618 if (retval) {
619 port->open_count = 0;
620 if (serial->type->owner)
621 __MOD_DEC_USE_COUNT(serial->type->owner);
622 }
623
624 up (&port->sem);
625 return retval;
626}
627
628static void __serial_close(struct usb_serial_port *port, struct file *filp)
629{
630 if (!port->open_count) {
631 dbg ("%s - port not opened", __FUNCTION__);
632 return;
633 }
634
635 --port->open_count;
636 if (port->open_count <= 0) {
637
638
639 if (port->serial->type->close)
640 port->serial->type->close(port, filp);
641 else
642 generic_close(port, filp);
643 port->open_count = 0;
644 if (port->tty) {
645 port->tty->driver_data = NULL;
646 port->tty = NULL;
647 }
648 }
649
650 if (port->serial->type->owner)
651 __MOD_DEC_USE_COUNT(port->serial->type->owner);
652}
653
654static void serial_close(struct tty_struct *tty, struct file * filp)
655{
656 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
657 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
658
659 if (!serial)
660 return;
661
662 down (&port->sem);
663
664 dbg("%s - port %d", __FUNCTION__, port->number);
665
666
667 if (tty->driver_data) {
668
669
670
671
672
673
674#if I_AM_A_DARING_HACKER
675 tty->closing = 1;
676 up (&port->sem);
677 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
678 tty_wait_until_sent(tty, info->closing_wait);
679 down (&port->sem);
680 if (!tty->driver_data) ;
681#endif
682 __serial_close(port, filp);
683 }
684
685 up (&port->sem);
686}
687
688static int __serial_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
689{
690 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
691 int retval = -EINVAL;
692
693 if (!serial)
694 return -ENODEV;
695
696 dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
697
698 if (!port->open_count) {
699 dbg("%s - port not opened", __FUNCTION__);
700 goto exit;
701 }
702
703
704 if (serial->type->write)
705 retval = serial->type->write(port, from_user, buf, count);
706 else
707 retval = generic_write(port, from_user, buf, count);
708
709exit:
710 return retval;
711}
712
713static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
714{
715 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
716 int rc;
717
718 if (!port)
719 return -ENODEV;
720
721 if (!in_interrupt()) {
722
723
724
725
726 post_helper(NULL);
727
728 down(&port->sem);
729
730
731
732
733
734
735 if (port->write_busy) {
736 up(&port->sem);
737 return serial_post_job(port, from_user, GFP_KERNEL,
738 buf, count);
739 }
740
741 rc = __serial_write(port, from_user, buf, count);
742 up(&port->sem);
743 return rc;
744 }
745
746 if (from_user) {
747
748
749
750
751
752 err("user data in interrupt write");
753 return -EINVAL;
754 }
755
756 return serial_post_job(port, 0, GFP_ATOMIC, buf, count);
757}
758
759static int serial_post_job(struct usb_serial_port *port, int from_user,
760 int gfp, const unsigned char *buf, int count)
761{
762 int done = 0, length;
763 int rc;
764
765 if (port == NULL)
766 return -EPIPE;
767
768 if (count >= 512) {
769 static int rate = 0;
770
771
772
773
774
775
776 if (++rate % 1000 < 3) {
777 err("too much data (%d) from %s", count,
778 from_user? "user": "kernel");
779 }
780 count = 512;
781 }
782
783 while (done < count) {
784 length = count - done;
785 if (length > POST_BSIZE)
786 length = POST_BSIZE;
787 if (length > port->bulk_out_size)
788 length = port->bulk_out_size;
789
790 rc = serial_post_one(port, from_user, gfp, buf + done, length);
791 if (rc <= 0) {
792 if (done != 0)
793 return done;
794 return rc;
795 }
796 done += rc;
797 }
798
799 return done;
800}
801
802static int serial_post_one(struct usb_serial_port *port, int from_user,
803 int gfp, const unsigned char *buf, int count)
804{
805 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
806 struct usb_serial_post_job *job;
807 unsigned long flags;
808
809 dbg("%s - port %d user %d count %d", __FUNCTION__, port->number, from_user, count);
810
811 job = kmalloc(sizeof(struct usb_serial_post_job), gfp);
812 if (job == NULL)
813 return -ENOMEM;
814
815 job->port = port;
816 if (count >= POST_BSIZE)
817 count = POST_BSIZE;
818 job->len = count;
819
820 if (from_user) {
821 if (copy_from_user(job->buff, buf, count)) {
822 kfree(job);
823 return -EFAULT;
824 }
825 } else {
826 memcpy(job->buff, buf, count);
827 }
828
829 spin_lock_irqsave(&post_lock, flags);
830 port->write_backlog += count;
831 list_add_tail(&job->link, &post_list);
832 serial->ref++;
833 schedule_task(&post_task);
834 spin_unlock_irqrestore(&post_lock, flags);
835
836 return count;
837}
838
839static int serial_write_room (struct tty_struct *tty)
840{
841 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
842 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
843 int retval = -EINVAL;
844
845 if (!serial)
846 return -ENODEV;
847
848 if (in_interrupt()) {
849 retval = 0;
850 if (!port->write_busy && port->write_backlog == 0)
851 retval = port->bulk_out_size;
852 dbg("%s - returns %d", __FUNCTION__, retval);
853 return retval;
854 }
855
856 down (&port->sem);
857
858 dbg("%s - port %d", __FUNCTION__, port->number);
859
860 if (!port->open_count) {
861 dbg("%s - port not open", __FUNCTION__);
862 goto exit;
863 }
864
865
866 if (serial->type->write_room)
867 retval = serial->type->write_room(port);
868 else
869 retval = generic_write_room(port);
870
871exit:
872 up (&port->sem);
873 return retval;
874}
875
876static int serial_chars_in_buffer (struct tty_struct *tty)
877{
878 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
879 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
880 int retval = -EINVAL;
881
882 if (!serial)
883 return -ENODEV;
884
885 down (&port->sem);
886
887 if (!port->open_count) {
888 dbg("%s - port %d: not open", __FUNCTION__, port->number);
889 goto exit;
890 }
891
892
893 if (serial->type->chars_in_buffer)
894 retval = serial->type->chars_in_buffer(port);
895 else
896 retval = generic_chars_in_buffer(port);
897
898exit:
899 up (&port->sem);
900 return retval;
901}
902
903static void serial_throttle (struct tty_struct * tty)
904{
905 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
906 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
907
908 if (!serial)
909 return;
910
911 down (&port->sem);
912
913 dbg("%s - port %d", __FUNCTION__, port->number);
914
915 if (!port->open_count) {
916 dbg ("%s - port not open", __FUNCTION__);
917 goto exit;
918 }
919
920
921 if (serial->type->throttle)
922 serial->type->throttle(port);
923
924exit:
925 up (&port->sem);
926}
927
928static void serial_unthrottle (struct tty_struct * tty)
929{
930 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
931 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
932
933 if (!serial)
934 return;
935
936 down (&port->sem);
937
938 dbg("%s - port %d", __FUNCTION__, port->number);
939
940 if (!port->open_count) {
941 dbg("%s - port not open", __FUNCTION__);
942 goto exit;
943 }
944
945
946 if (serial->type->unthrottle)
947 serial->type->unthrottle(port);
948
949exit:
950 up (&port->sem);
951}
952
953static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
954{
955 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
956 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
957 int retval = -ENODEV;
958
959 if (!serial)
960 return -ENODEV;
961
962 down (&port->sem);
963
964 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
965
966 if (!port->open_count) {
967 dbg ("%s - port not open", __FUNCTION__);
968 goto exit;
969 }
970
971
972 if (serial->type->ioctl)
973 retval = serial->type->ioctl(port, file, cmd, arg);
974 else
975 retval = -ENOIOCTLCMD;
976
977exit:
978 up (&port->sem);
979 return retval;
980}
981
982static void serial_set_termios (struct tty_struct *tty, struct termios * old)
983{
984 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
985 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
986
987 if (!serial)
988 return;
989
990 down (&port->sem);
991
992 dbg("%s - port %d", __FUNCTION__, port->number);
993
994 if (!port->open_count) {
995 dbg("%s - port not open", __FUNCTION__);
996 goto exit;
997 }
998
999
1000 if (serial->type->set_termios)
1001 serial->type->set_termios(port, old);
1002
1003exit:
1004 up (&port->sem);
1005}
1006
1007static void serial_break (struct tty_struct *tty, int break_state)
1008{
1009 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
1010 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1011
1012 if (!serial)
1013 return;
1014
1015 down (&port->sem);
1016
1017 dbg("%s - port %d", __FUNCTION__, port->number);
1018
1019 if (!port->open_count) {
1020 dbg("%s - port not open", __FUNCTION__);
1021 goto exit;
1022 }
1023
1024
1025 if (serial->type->break_ctl)
1026 serial->type->break_ctl(port, break_state);
1027
1028exit:
1029 up (&port->sem);
1030}
1031
1032static void serial_shutdown (struct usb_serial *serial)
1033{
1034 dbg ("%s", __FUNCTION__);
1035
1036 if (serial->type->shutdown)
1037 serial->type->shutdown(serial);
1038 else
1039 generic_shutdown(serial);
1040}
1041
1042static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data)
1043{
1044 struct usb_serial *serial;
1045 int length = 0;
1046 int i;
1047 off_t begin = 0;
1048 char tmp[40];
1049
1050 dbg("%s", __FUNCTION__);
1051 length += sprintf (page, "usbserinfo:1.0 driver:%s\n", DRIVER_VERSION);
1052 for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) {
1053 serial = get_serial_by_minor(i);
1054 if (serial == NULL)
1055 continue;
1056
1057 length += sprintf (page+length, "%d:", i);
1058 if (serial->type->owner)
1059 length += sprintf (page+length, " module:%s", serial->type->owner->name);
1060 length += sprintf (page+length, " name:\"%s\"", serial->type->name);
1061 length += sprintf (page+length, " vendor:%04x product:%04x", serial->vendor, serial->product);
1062 length += sprintf (page+length, " num_ports:%d", serial->num_ports);
1063 length += sprintf (page+length, " port:%d", i - serial->minor + 1);
1064
1065 usb_make_path(serial->dev, tmp, sizeof(tmp));
1066 length += sprintf (page+length, " path:%s", tmp);
1067
1068 length += sprintf (page+length, "\n");
1069 if ((length + begin) > (off + count))
1070 goto done;
1071 if ((length + begin) < off) {
1072 begin += length;
1073 length = 0;
1074 }
1075 }
1076 *eof = 1;
1077done:
1078 if (off >= (length + begin))
1079 return 0;
1080 *start = page + (off-begin);
1081 return ((count < begin+length-off) ? count : begin+length-off);
1082}
1083
1084
1085
1086
1087static int generic_open (struct usb_serial_port *port, struct file *filp)
1088{
1089 struct usb_serial *serial = port->serial;
1090 int result = 0;
1091
1092 if (port_paranoia_check (port, __FUNCTION__))
1093 return -ENODEV;
1094
1095 dbg("%s - port %d", __FUNCTION__, port->number);
1096
1097
1098
1099
1100 if (port->tty)
1101 port->tty->low_latency = 1;
1102
1103
1104 if (serial->num_bulk_in) {
1105
1106 usb_fill_bulk_urb (port->read_urb, serial->dev,
1107 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
1108 port->read_urb->transfer_buffer,
1109 port->read_urb->transfer_buffer_length,
1110 ((serial->type->read_bulk_callback) ?
1111 serial->type->read_bulk_callback :
1112 generic_read_bulk_callback),
1113 port);
1114 result = usb_submit_urb(port->read_urb);
1115 if (result)
1116 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
1117 }
1118
1119 return result;
1120}
1121
1122static void generic_cleanup (struct usb_serial_port *port)
1123{
1124 struct usb_serial *serial = port->serial;
1125
1126 dbg("%s - port %d", __FUNCTION__, port->number);
1127
1128 if (serial->dev) {
1129
1130 if (serial->num_bulk_out)
1131 usb_unlink_urb (port->write_urb);
1132 if (serial->num_bulk_in)
1133 usb_unlink_urb (port->read_urb);
1134 }
1135}
1136
1137static void generic_close (struct usb_serial_port *port, struct file * filp)
1138{
1139 dbg("%s - port %d", __FUNCTION__, port->number);
1140 generic_cleanup (port);
1141}
1142
1143static int generic_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
1144{
1145 struct usb_serial *serial = port->serial;
1146 int result;
1147 unsigned long flags;
1148
1149 if (count == 0) {
1150 dbg("%s - write request of 0 bytes", __FUNCTION__);
1151 return (0);
1152 }
1153 if (count < 0) {
1154 err("%s - port %d: write request of %d bytes", __FUNCTION__,
1155 port->number, count);
1156 return (0);
1157 }
1158
1159
1160 if (serial->num_bulk_out) {
1161 if (port->write_busy) {
1162
1163 info("%s - already writing", __FUNCTION__);
1164 return (0);
1165 }
1166
1167 count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
1168
1169 if (from_user) {
1170 if (copy_from_user(port->write_urb->transfer_buffer, buf, count))
1171 return -EFAULT;
1172 } else {
1173 memcpy (port->write_urb->transfer_buffer, buf, count);
1174 }
1175 dbg("%s - port %d [%d]", __FUNCTION__, port->number, count);
1176
1177
1178 usb_fill_bulk_urb (port->write_urb, serial->dev,
1179 usb_sndbulkpipe (serial->dev,
1180 port->bulk_out_endpointAddress),
1181 port->write_urb->transfer_buffer, count,
1182 ((serial->type->write_bulk_callback) ?
1183 serial->type->write_bulk_callback :
1184 generic_write_bulk_callback), port);
1185
1186
1187 port->write_busy = 1;
1188 result = usb_submit_urb(port->write_urb);
1189 if (result) {
1190 err("%s - port %d: failed submitting write urb (%d)",
1191 __FUNCTION__, port->number, result);
1192 port->write_busy = 0;
1193 spin_lock_irqsave(&post_lock, flags);
1194 if (port->write_backlog != 0)
1195 schedule_task(&post_task);
1196 spin_unlock_irqrestore(&post_lock, flags);
1197
1198 } else
1199 result = count;
1200
1201 return result;
1202 }
1203
1204
1205 return (0);
1206}
1207
1208static int generic_write_room (struct usb_serial_port *port)
1209{
1210 struct usb_serial *serial = port->serial;
1211 int room = 0;
1212
1213 if (serial->num_bulk_out) {
1214 if (!port->write_busy && port->write_backlog == 0)
1215 room = port->bulk_out_size;
1216 }
1217
1218 dbg("%s - port %d, returns %d", __FUNCTION__, port->number, room);
1219 return (room);
1220}
1221
1222static int generic_chars_in_buffer (struct usb_serial_port *port)
1223{
1224 struct usb_serial *serial = port->serial;
1225 int chars = 0;
1226
1227 dbg("%s - port %d", __FUNCTION__, port->number);
1228
1229 if (serial->num_bulk_out) {
1230 if (port->write_busy)
1231 chars += port->write_urb->transfer_buffer_length;
1232 chars += port->write_backlog;
1233 }
1234
1235 dbg("%s - returns %d", __FUNCTION__, chars);
1236 return (chars);
1237}
1238
1239static void generic_read_bulk_callback (struct urb *urb)
1240{
1241 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1242 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1243 struct tty_struct *tty;
1244 unsigned char *data = urb->transfer_buffer;
1245 int i;
1246 int result;
1247
1248 dbg("%s - port %d", __FUNCTION__, port->number);
1249
1250 if (!serial) {
1251 dbg("%s - bad serial pointer, exiting", __FUNCTION__);
1252 return;
1253 }
1254
1255 if (urb->status) {
1256 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
1257 return;
1258 }
1259
1260 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
1261
1262 tty = port->tty;
1263 if (tty && urb->actual_length) {
1264 for (i = 0; i < urb->actual_length ; ++i) {
1265
1266 if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
1267 tty_flip_buffer_push(tty);
1268 }
1269
1270 tty_insert_flip_char(tty, data[i], 0);
1271 }
1272 tty_flip_buffer_push(tty);
1273 }
1274
1275
1276 usb_fill_bulk_urb (port->read_urb, serial->dev,
1277 usb_rcvbulkpipe (serial->dev,
1278 port->bulk_in_endpointAddress),
1279 port->read_urb->transfer_buffer,
1280 port->read_urb->transfer_buffer_length,
1281 ((serial->type->read_bulk_callback) ?
1282 serial->type->read_bulk_callback :
1283 generic_read_bulk_callback), port);
1284 result = usb_submit_urb(port->read_urb);
1285 if (result)
1286 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
1287}
1288
1289static void generic_write_bulk_callback (struct urb *urb)
1290{
1291 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1292 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1293
1294 dbg("%s - port %d", __FUNCTION__, port->number);
1295
1296 port->write_busy = 0;
1297 wmb();
1298
1299 if (!serial) {
1300 err("%s - null serial pointer, exiting", __FUNCTION__);
1301 return;
1302 }
1303
1304 if (urb->status) {
1305 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
1306 }
1307
1308 queue_task(&port->tqueue, &tq_immediate);
1309 mark_bh(IMMEDIATE_BH);
1310
1311 return;
1312}
1313
1314static void generic_shutdown (struct usb_serial *serial)
1315{
1316 int i;
1317
1318 dbg("%s", __FUNCTION__);
1319
1320
1321 for (i=0; i < serial->num_ports; ++i) {
1322 generic_cleanup (&serial->port[i]);
1323 }
1324}
1325
1326static void port_softint(void *private)
1327{
1328 struct usb_serial_port *port = (struct usb_serial_port *)private;
1329 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
1330 struct tty_struct *tty;
1331 unsigned long flags;
1332 struct tty_ldisc *ld;
1333
1334 dbg("%s - port %d", __FUNCTION__, port->number);
1335
1336 if (!serial)
1337 return;
1338
1339 spin_lock_irqsave(&post_lock, flags);
1340 if (port->write_backlog != 0)
1341 schedule_task(&post_task);
1342 spin_unlock_irqrestore(&post_lock, flags);
1343
1344 tty = port->tty;
1345 if (!tty)
1346 return;
1347
1348 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))) {
1349 ld = tty_ldisc_ref(tty);
1350 if(ld) {
1351 if(ld->write_wakeup) {
1352 ld->write_wakeup(tty);
1353 dbg("%s - write wakeup call.", __FUNCTION__);
1354 }
1355 tty_ldisc_deref(ld);
1356 }
1357 }
1358
1359 wake_up_interruptible(&tty->write_wait);
1360}
1361
1362
1363static void * usb_serial_probe(struct usb_device *dev, unsigned int ifnum,
1364 const struct usb_device_id *id)
1365{
1366 struct usb_serial *serial = NULL;
1367 struct usb_serial_port *port;
1368 struct usb_interface *interface;
1369 struct usb_interface_descriptor *iface_desc;
1370 struct usb_endpoint_descriptor *endpoint;
1371 struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS];
1372 struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS];
1373 struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS];
1374 struct usb_serial_device_type *type = NULL;
1375 struct list_head *tmp;
1376 int found;
1377 int minor;
1378 int buffer_size;
1379 int i;
1380 int num_interrupt_in = 0;
1381 int num_bulk_in = 0;
1382 int num_bulk_out = 0;
1383 int num_ports;
1384 int max_endpoints;
1385 const struct usb_device_id *id_pattern = NULL;
1386 unsigned long flags;
1387
1388
1389
1390 found = 0;
1391 interface = &dev->actconfig->interface[ifnum];
1392 list_for_each (tmp, &usb_serial_driver_list) {
1393 type = list_entry(tmp, struct usb_serial_device_type, driver_list);
1394 id_pattern = usb_match_id(dev, interface, type->id_table);
1395 if (id_pattern != NULL) {
1396 dbg("descriptor matches");
1397 found = 1;
1398 break;
1399 }
1400 }
1401 if (!found) {
1402
1403 dbg("none matched");
1404 return(NULL);
1405 }
1406
1407
1408
1409 iface_desc = &interface->altsetting[0];
1410 for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
1411 endpoint = &iface_desc->endpoint[i];
1412
1413 if ((endpoint->bEndpointAddress & 0x80) &&
1414 ((endpoint->bmAttributes & 3) == 0x02)) {
1415
1416 dbg("found bulk in");
1417 bulk_in_endpoint[num_bulk_in] = endpoint;
1418 ++num_bulk_in;
1419 }
1420
1421 if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
1422 ((endpoint->bmAttributes & 3) == 0x02)) {
1423
1424 dbg("found bulk out");
1425 bulk_out_endpoint[num_bulk_out] = endpoint;
1426 ++num_bulk_out;
1427 }
1428
1429 if ((endpoint->bEndpointAddress & 0x80) &&
1430 ((endpoint->bmAttributes & 3) == 0x03)) {
1431
1432 dbg("found interrupt in");
1433 interrupt_in_endpoint[num_interrupt_in] = endpoint;
1434 ++num_interrupt_in;
1435 }
1436 }
1437
1438#if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE)
1439
1440
1441 if (((dev->descriptor.idVendor == PL2303_VENDOR_ID) &&
1442 (dev->descriptor.idProduct == PL2303_PRODUCT_ID)) ||
1443 ((dev->descriptor.idVendor == ATEN_VENDOR_ID) &&
1444 (dev->descriptor.idProduct == ATEN_PRODUCT_ID))) {
1445 if (ifnum == 1) {
1446
1447 struct usb_interface *other_iface;
1448
1449 other_iface = &dev->actconfig->interface[ifnum ^ 1];
1450 iface_desc = &other_iface->altsetting[0];
1451 for (i = 0; i < iface_desc->bNumEndpoints; ++i) {
1452 endpoint = &iface_desc->endpoint[i];
1453 if ((endpoint->bEndpointAddress & 0x80) &&
1454 ((endpoint->bmAttributes & 3) == 0x03)) {
1455
1456 dbg("found interrupt in for Prolific device on separate interface");
1457 interrupt_in_endpoint[num_interrupt_in] = endpoint;
1458 ++num_interrupt_in;
1459 }
1460 }
1461 }
1462
1463
1464
1465
1466
1467 if (num_bulk_in == 0 || num_bulk_out == 0) {
1468 info("PL-2303 hack: descriptors matched but endpoints did not");
1469 return NULL;
1470 }
1471 }
1472
1473#endif
1474
1475
1476 info("%s converter detected", type->name);
1477
1478#ifdef CONFIG_USB_SERIAL_GENERIC
1479 if (type == &generic_device) {
1480 num_ports = num_bulk_out;
1481 if (num_ports == 0) {
1482 err("Generic device with no bulk out, not allowed.");
1483 return NULL;
1484 }
1485 } else
1486#endif
1487 num_ports = type->num_ports;
1488
1489 serial = get_free_serial (num_ports, &minor);
1490 if (serial == NULL) {
1491 err("No more free serial devices");
1492 return NULL;
1493 }
1494
1495 serial->dev = dev;
1496 serial->type = type;
1497 serial->interface = interface;
1498 serial->minor = minor;
1499 serial->num_ports = num_ports;
1500 serial->num_bulk_in = num_bulk_in;
1501 serial->num_bulk_out = num_bulk_out;
1502 serial->num_interrupt_in = num_interrupt_in;
1503 serial->vendor = dev->descriptor.idVendor;
1504 serial->product = dev->descriptor.idProduct;
1505
1506
1507 for (i = 0; i < num_bulk_in; ++i) {
1508 endpoint = bulk_in_endpoint[i];
1509 port = &serial->port[i];
1510 port->read_urb = usb_alloc_urb (0);
1511 if (!port->read_urb) {
1512 err("No free urbs available");
1513 goto probe_error;
1514 }
1515 buffer_size = endpoint->wMaxPacketSize;
1516 port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
1517 port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
1518 if (!port->bulk_in_buffer) {
1519 err("Couldn't allocate bulk_in_buffer");
1520 goto probe_error;
1521 }
1522 usb_fill_bulk_urb (port->read_urb, dev,
1523 usb_rcvbulkpipe (dev,
1524 endpoint->bEndpointAddress),
1525 port->bulk_in_buffer, buffer_size,
1526 ((serial->type->read_bulk_callback) ?
1527 serial->type->read_bulk_callback :
1528 generic_read_bulk_callback),
1529 port);
1530 }
1531
1532 for (i = 0; i < num_bulk_out; ++i) {
1533 endpoint = bulk_out_endpoint[i];
1534 port = &serial->port[i];
1535 port->write_urb = usb_alloc_urb(0);
1536 if (!port->write_urb) {
1537 err("No free urbs available");
1538 goto probe_error;
1539 }
1540 buffer_size = endpoint->wMaxPacketSize;
1541 port->bulk_out_size = buffer_size;
1542 port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
1543 port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL);
1544 if (!port->bulk_out_buffer) {
1545 err("Couldn't allocate bulk_out_buffer");
1546 goto probe_error;
1547 }
1548 usb_fill_bulk_urb (port->write_urb, dev,
1549 usb_sndbulkpipe (dev,
1550 endpoint->bEndpointAddress),
1551 port->bulk_out_buffer, buffer_size,
1552 ((serial->type->write_bulk_callback) ?
1553 serial->type->write_bulk_callback :
1554 generic_write_bulk_callback),
1555 port);
1556 }
1557
1558 for (i = 0; i < num_interrupt_in; ++i) {
1559 endpoint = interrupt_in_endpoint[i];
1560 port = &serial->port[i];
1561 port->interrupt_in_urb = usb_alloc_urb(0);
1562 if (!port->interrupt_in_urb) {
1563 err("No free urbs available");
1564 goto probe_error;
1565 }
1566 buffer_size = endpoint->wMaxPacketSize;
1567 port->interrupt_in_endpointAddress = endpoint->bEndpointAddress;
1568 port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL);
1569 if (!port->interrupt_in_buffer) {
1570 err("Couldn't allocate interrupt_in_buffer");
1571 goto probe_error;
1572 }
1573 usb_fill_int_urb (port->interrupt_in_urb, dev,
1574 usb_rcvintpipe (dev,
1575 endpoint->bEndpointAddress),
1576 port->interrupt_in_buffer, buffer_size,
1577 serial->type->read_int_callback, port,
1578 endpoint->bInterval);
1579 }
1580
1581
1582
1583 max_endpoints = max(num_bulk_in, num_bulk_out);
1584 max_endpoints = max(max_endpoints, num_interrupt_in);
1585 max_endpoints = max(max_endpoints, (int)serial->num_ports);
1586 dbg("%s - setting up %d port structures for this device", __FUNCTION__, max_endpoints);
1587 for (i = 0; i < max_endpoints; ++i) {
1588 port = &serial->port[i];
1589 port->number = i + serial->minor;
1590 port->serial = serial;
1591 port->magic = USB_SERIAL_PORT_MAGIC;
1592 port->tqueue.routine = port_softint;
1593 port->tqueue.data = port;
1594 init_MUTEX (&port->sem);
1595 }
1596
1597 spin_lock_irqsave(&post_lock, flags);
1598 serial->ref = 1;
1599 spin_unlock_irqrestore(&post_lock, flags);
1600
1601
1602 if (type->startup) {
1603 i = type->startup (serial);
1604 if (i < 0)
1605 goto startup_error;
1606 if (i > 0)
1607 return serial;
1608 }
1609
1610
1611 for (i = 0; i < serial->num_ports; ++i) {
1612 tty_register_devfs (&serial_tty_driver, 0, serial->port[i].number);
1613 info("%s converter now attached to ttyUSB%d (or usb/tts/%d for devfs)",
1614 type->name, serial->port[i].number, serial->port[i].number);
1615 }
1616
1617 return serial;
1618
1619
1620startup_error:
1621 spin_lock_irqsave(&post_lock, flags);
1622 if (serial->ref != 1) {
1623 err("bug in component startup: ref %d\n", serial->ref);
1624 }
1625 spin_unlock_irqrestore(&post_lock, flags);
1626probe_error:
1627 for (i = 0; i < num_bulk_in; ++i) {
1628 port = &serial->port[i];
1629 if (port->read_urb)
1630 usb_free_urb (port->read_urb);
1631 if (port->bulk_in_buffer)
1632 kfree (port->bulk_in_buffer);
1633 }
1634 for (i = 0; i < num_bulk_out; ++i) {
1635 port = &serial->port[i];
1636 if (port->write_urb)
1637 usb_free_urb (port->write_urb);
1638 if (port->bulk_out_buffer)
1639 kfree (port->bulk_out_buffer);
1640 }
1641 for (i = 0; i < num_interrupt_in; ++i) {
1642 port = &serial->port[i];
1643 if (port->interrupt_in_urb)
1644 usb_free_urb (port->interrupt_in_urb);
1645 if (port->interrupt_in_buffer)
1646 kfree (port->interrupt_in_buffer);
1647 }
1648
1649
1650 return_serial (serial);
1651
1652
1653 kfree (serial);
1654 return NULL;
1655}
1656
1657static void usb_serial_disconnect(struct usb_device *dev, void *ptr)
1658{
1659 struct usb_serial *serial = (struct usb_serial *) ptr;
1660 struct usb_serial_port *port;
1661 unsigned long flags;
1662 int i;
1663
1664 dbg ("%s", __FUNCTION__);
1665 if (serial) {
1666
1667 for (i = 0; i < serial->num_ports; ++i) {
1668 port = &serial->port[i];
1669 down (&port->sem);
1670 if (port->tty != NULL)
1671 while (port->open_count > 0)
1672 __serial_close(port, NULL);
1673 up (&port->sem);
1674 }
1675
1676 serial->dev = NULL;
1677 serial_shutdown (serial);
1678
1679 for (i = 0; i < serial->num_ports; ++i)
1680 serial->port[i].open_count = 0;
1681
1682 for (i = 0; i < serial->num_bulk_in; ++i) {
1683 port = &serial->port[i];
1684 if (port->read_urb) {
1685 usb_unlink_urb (port->read_urb);
1686 usb_free_urb (port->read_urb);
1687 }
1688 if (port->bulk_in_buffer)
1689 kfree (port->bulk_in_buffer);
1690 }
1691 for (i = 0; i < serial->num_bulk_out; ++i) {
1692 port = &serial->port[i];
1693 if (port->write_urb) {
1694 usb_unlink_urb (port->write_urb);
1695 usb_free_urb (port->write_urb);
1696 }
1697 if (port->bulk_out_buffer)
1698 kfree (port->bulk_out_buffer);
1699 }
1700 for (i = 0; i < serial->num_interrupt_in; ++i) {
1701 port = &serial->port[i];
1702 if (port->interrupt_in_urb) {
1703 usb_unlink_urb (port->interrupt_in_urb);
1704 usb_free_urb (port->interrupt_in_urb);
1705 }
1706 if (port->interrupt_in_buffer)
1707 kfree (port->interrupt_in_buffer);
1708 }
1709
1710 for (i = 0; i < serial->num_ports; ++i) {
1711 tty_unregister_devfs (&serial_tty_driver, serial->port[i].number);
1712 info("%s converter now disconnected from ttyUSB%d", serial->type->name, serial->port[i].number);
1713 }
1714
1715
1716 return_serial (serial);
1717
1718
1719 spin_lock_irqsave(&post_lock, flags);
1720 if (--serial->ref == 0)
1721 kfree(serial);
1722 spin_unlock_irqrestore(&post_lock, flags);
1723
1724 } else {
1725 info("device disconnected");
1726 }
1727
1728}
1729
1730
1731static struct tty_driver serial_tty_driver = {
1732 .magic = TTY_DRIVER_MAGIC,
1733 .driver_name = "usb-serial",
1734#ifndef CONFIG_DEVFS_FS
1735 .name = "ttyUSB",
1736#else
1737 .name = "usb/tts/%d",
1738#endif
1739 .major = SERIAL_TTY_MAJOR,
1740 .minor_start = 0,
1741 .num = SERIAL_TTY_MINORS,
1742 .type = TTY_DRIVER_TYPE_SERIAL,
1743 .subtype = SERIAL_TYPE_NORMAL,
1744 .flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS,
1745
1746 .refcount = &serial_refcount,
1747 .table = serial_tty,
1748 .termios = serial_termios,
1749 .termios_locked = serial_termios_locked,
1750
1751 .open = serial_open,
1752 .close = serial_close,
1753 .write = serial_write,
1754 .write_room = serial_write_room,
1755 .ioctl = serial_ioctl,
1756 .set_termios = serial_set_termios,
1757 .throttle = serial_throttle,
1758 .unthrottle = serial_unthrottle,
1759 .break_ctl = serial_break,
1760 .chars_in_buffer = serial_chars_in_buffer,
1761 .read_proc = serial_read_proc,
1762};
1763
1764
1765static int __init usb_serial_init(void)
1766{
1767 int i;
1768 int result;
1769
1770
1771 for (i = 0; i < SERIAL_TTY_MINORS; ++i) {
1772 serial_table[i] = NULL;
1773 }
1774 post_task.routine = post_helper;
1775
1776
1777 serial_tty_driver.init_termios = tty_std_termios;
1778 serial_tty_driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1779 if (tty_register_driver (&serial_tty_driver)) {
1780 err("%s - failed to register tty driver", __FUNCTION__);
1781 return -1;
1782 }
1783
1784
1785 result = usb_register(&usb_serial_driver);
1786 if (result < 0) {
1787 tty_unregister_driver(&serial_tty_driver);
1788 err("usb_register failed for the usb-serial driver. Error number %d", result);
1789 return -1;
1790 }
1791
1792#ifdef CONFIG_USB_SERIAL_GENERIC
1793 generic_device_ids[0].idVendor = vendor;
1794 generic_device_ids[0].idProduct = product;
1795 generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
1796
1797 usb_serial_register (&generic_device);
1798#endif
1799
1800 info(DRIVER_DESC " " DRIVER_VERSION);
1801
1802 return 0;
1803}
1804
1805
1806static void __exit usb_serial_exit(void)
1807{
1808
1809#ifdef CONFIG_USB_SERIAL_GENERIC
1810
1811 usb_serial_deregister (&generic_device);
1812#endif
1813
1814 usb_deregister(&usb_serial_driver);
1815 tty_unregister_driver(&serial_tty_driver);
1816}
1817
1818
1819module_init(usb_serial_init);
1820module_exit(usb_serial_exit);
1821
1822
1823int usb_serial_register(struct usb_serial_device_type *new_device)
1824{
1825
1826 list_add(&new_device->driver_list, &usb_serial_driver_list);
1827
1828 info ("USB Serial support registered for %s", new_device->name);
1829
1830 usb_scan_devices();
1831
1832 return 0;
1833}
1834
1835
1836void usb_serial_deregister(struct usb_serial_device_type *device)
1837{
1838 struct usb_serial *serial;
1839 int i;
1840
1841 info("USB Serial deregistering driver %s", device->name);
1842
1843
1844 for(i = 0; i < SERIAL_TTY_MINORS; ++i) {
1845 serial = serial_table[i];
1846 if ((serial != NULL) && (serial->type == device)) {
1847 usb_driver_release_interface (&usb_serial_driver, serial->interface);
1848 usb_serial_disconnect (NULL, serial);
1849 }
1850 }
1851
1852 list_del(&device->driver_list);
1853}
1854
1855
1856
1857
1858
1859EXPORT_SYMBOL(usb_serial_register);
1860EXPORT_SYMBOL(usb_serial_deregister);
1861#ifdef USES_EZUSB_FUNCTIONS
1862 EXPORT_SYMBOL(ezusb_writememory);
1863 EXPORT_SYMBOL(ezusb_set_reset);
1864#endif
1865
1866
1867
1868MODULE_AUTHOR( DRIVER_AUTHOR );
1869MODULE_DESCRIPTION( DRIVER_DESC );
1870MODULE_LICENSE("GPL");
1871
1872MODULE_PARM(debug, "i");
1873MODULE_PARM_DESC(debug, "Debug enabled or not");
1874
1875#ifdef CONFIG_USB_SERIAL_GENERIC
1876MODULE_PARM(vendor, "h");
1877MODULE_PARM_DESC(vendor, "User specified USB idVendor");
1878
1879MODULE_PARM(product, "h");
1880MODULE_PARM_DESC(product, "User specified USB idProduct");
1881#endif
1882