aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pobox.com>2005-09-14 08:19:08 -0400
committerJeff Garzik <jgarzik@pobox.com>2005-09-14 08:19:08 -0400
commit905ec87e93bc9e01b15c60035cd6a50c636cbaef (patch)
tree46fd7618d6511611ffc19eb0dd4d7bc6b90a41c2 /drivers/usb
parent1d6ae775d7a948c9575658eb41184fd2e506c0df (diff)
parent2f4ba45a75d6383b4a1201169a808ffea416ffa0 (diff)
Merge /spare/repo/linux-2.6/
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/atm/cxacru.c2
-rw-r--r--drivers/usb/class/Kconfig21
-rw-r--r--drivers/usb/class/audio.c12
-rw-r--r--drivers/usb/class/usblp.c9
-rw-r--r--drivers/usb/core/Makefile4
-rw-r--r--drivers/usb/core/devio.c102
-rw-r--r--drivers/usb/core/hcd-pci.c28
-rw-r--r--drivers/usb/core/hcd.c3
-rw-r--r--drivers/usb/core/hcd.h8
-rw-r--r--drivers/usb/core/hub.c126
-rw-r--r--drivers/usb/core/hub.h7
-rw-r--r--drivers/usb/core/inode.c9
-rw-r--r--drivers/usb/core/message.c8
-rw-r--r--drivers/usb/core/urb.c26
-rw-r--r--drivers/usb/core/usb.c35
-rw-r--r--drivers/usb/core/usb.h5
-rw-r--r--drivers/usb/gadget/ether.c33
-rw-r--r--drivers/usb/gadget/file_storage.c33
-rw-r--r--drivers/usb/gadget/gadget_chips.h55
-rw-r--r--drivers/usb/gadget/inode.c1
-rw-r--r--drivers/usb/gadget/serial.c51
-rw-r--r--drivers/usb/gadget/zero.c48
-rw-r--r--drivers/usb/host/ehci-hcd.c32
-rw-r--r--drivers/usb/host/ehci-hub.c27
-rw-r--r--drivers/usb/host/ehci-q.c7
-rw-r--r--drivers/usb/host/ehci-sched.c4
-rw-r--r--drivers/usb/host/ehci.h3
-rw-r--r--drivers/usb/host/hc_crisv10.c4
-rw-r--r--drivers/usb/host/isp116x-hcd.c88
-rw-r--r--drivers/usb/host/ohci-dbg.c9
-rw-r--r--drivers/usb/host/ohci-hcd.c14
-rw-r--r--drivers/usb/host/ohci-hub.c22
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c24
-rw-r--r--drivers/usb/host/ohci-pxa27x.c48
-rw-r--r--drivers/usb/host/ohci-s3c2410.c4
-rw-r--r--drivers/usb/host/ohci.h1
-rw-r--r--drivers/usb/host/uhci-hcd.c62
-rw-r--r--drivers/usb/host/uhci-hcd.h11
-rw-r--r--drivers/usb/host/uhci-hub.c11
-rw-r--r--drivers/usb/host/uhci-q.c2
-rw-r--r--drivers/usb/input/Kconfig34
-rw-r--r--drivers/usb/input/Makefile2
-rw-r--r--drivers/usb/input/appletouch.c469
-rw-r--r--drivers/usb/input/hid-core.c81
-rw-r--r--drivers/usb/input/hid-debug.h34
-rw-r--r--drivers/usb/input/hid-input.c66
-rw-r--r--drivers/usb/input/hid.h9
-rw-r--r--drivers/usb/input/hiddev.c1
-rw-r--r--drivers/usb/input/keyspan_remote.c5
-rw-r--r--drivers/usb/input/map_to_7segment.h189
-rw-r--r--drivers/usb/input/yealink.c1013
-rw-r--r--drivers/usb/input/yealink.h220
-rw-r--r--drivers/usb/media/stv680.c26
-rw-r--r--drivers/usb/misc/auerswald.c3
-rw-r--r--drivers/usb/misc/ldusb.c6
-rw-r--r--drivers/usb/misc/sisusbvga/Kconfig42
-rw-r--r--drivers/usb/misc/sisusbvga/Makefile4
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c467
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.h73
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_con.c1658
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_init.c1047
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_init.h830
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_struct.h169
-rw-r--r--drivers/usb/misc/usbtest.c2
-rw-r--r--drivers/usb/misc/uss720.c393
-rw-r--r--drivers/usb/mon/Makefile2
-rw-r--r--drivers/usb/mon/mon_dma.c55
-rw-r--r--drivers/usb/mon/mon_text.c37
-rw-r--r--drivers/usb/mon/usb_mon.h4
-rw-r--r--drivers/usb/net/Kconfig208
-rw-r--r--drivers/usb/net/Makefile8
-rw-r--r--drivers/usb/net/asix.c948
-rw-r--r--drivers/usb/net/catc.c2
-rw-r--r--drivers/usb/net/cdc_ether.c509
-rw-r--r--drivers/usb/net/cdc_subset.c335
-rw-r--r--drivers/usb/net/gl620a.c407
-rw-r--r--drivers/usb/net/kaweth.c1
-rw-r--r--drivers/usb/net/net1080.c622
-rw-r--r--drivers/usb/net/pegasus.c1
-rw-r--r--drivers/usb/net/plusb.c156
-rw-r--r--drivers/usb/net/rndis_host.c615
-rw-r--r--drivers/usb/net/rtl8150.c1
-rw-r--r--drivers/usb/net/usbnet.c3226
-rw-r--r--drivers/usb/net/usbnet.h193
-rw-r--r--drivers/usb/net/zaurus.c386
-rw-r--r--drivers/usb/net/zd1201.c1
-rw-r--r--drivers/usb/serial/cp2101.c5
-rw-r--r--drivers/usb/serial/cypress_m8.c254
-rw-r--r--drivers/usb/serial/ftdi_sio.c58
-rw-r--r--drivers/usb/serial/ftdi_sio.h54
-rw-r--r--drivers/usb/serial/keyspan.c8
-rw-r--r--drivers/usb/serial/option.c203
-rw-r--r--drivers/usb/serial/pl2303.c10
-rw-r--r--drivers/usb/serial/pl2303.h4
-rw-r--r--drivers/usb/serial/usb-serial.c24
-rw-r--r--drivers/usb/storage/Kconfig12
-rw-r--r--drivers/usb/storage/Makefile1
-rw-r--r--drivers/usb/storage/onetouch.c210
-rw-r--r--drivers/usb/storage/onetouch.h9
-rw-r--r--drivers/usb/storage/scsiglue.c28
-rw-r--r--drivers/usb/storage/shuttle_usbat.c97
-rw-r--r--drivers/usb/storage/transport.c17
-rw-r--r--drivers/usb/storage/unusual_devs.h54
-rw-r--r--drivers/usb/storage/usb.c90
-rw-r--r--drivers/usb/storage/usb.h1
105 files changed, 12399 insertions, 4299 deletions
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index 8e184e2641cb..79861ee12a29 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -715,13 +715,11 @@ static int cxacru_bind(struct usbatm_data *usbatm_instance,
715 usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD), 715 usb_dev, usb_rcvintpipe(usb_dev, CXACRU_EP_CMD),
716 instance->rcv_buf, PAGE_SIZE, 716 instance->rcv_buf, PAGE_SIZE,
717 cxacru_blocking_completion, &instance->rcv_done, 1); 717 cxacru_blocking_completion, &instance->rcv_done, 1);
718 instance->rcv_urb->transfer_flags |= URB_ASYNC_UNLINK;
719 718
720 usb_fill_int_urb(instance->snd_urb, 719 usb_fill_int_urb(instance->snd_urb,
721 usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD), 720 usb_dev, usb_sndintpipe(usb_dev, CXACRU_EP_CMD),
722 instance->snd_buf, PAGE_SIZE, 721 instance->snd_buf, PAGE_SIZE,
723 cxacru_blocking_completion, &instance->snd_done, 4); 722 cxacru_blocking_completion, &instance->snd_done, 4);
724 instance->snd_urb->transfer_flags |= URB_ASYNC_UNLINK;
725 723
726 init_MUTEX(&instance->cm_serialize); 724 init_MUTEX(&instance->cm_serialize);
727 725
diff --git a/drivers/usb/class/Kconfig b/drivers/usb/class/Kconfig
index 0561d0234f23..333e39bb105f 100644
--- a/drivers/usb/class/Kconfig
+++ b/drivers/usb/class/Kconfig
@@ -4,9 +4,22 @@
4comment "USB Device Class drivers" 4comment "USB Device Class drivers"
5 depends on USB 5 depends on USB
6 6
7config OBSOLETE_OSS_USB_DRIVER
8 bool "Obsolete OSS USB drivers"
9 depends on USB && SOUND
10 help
11 This option enables support for the obsolete USB Audio and Midi
12 drivers that are scheduled for removal in the near future since
13 there are ALSA drivers for the same hardware.
14
15 Please contact Adrian Bunk <bunk@stusta.de> if you had to
16 say Y here because of missing support in the ALSA drivers.
17
18 If unsure, say N.
19
7config USB_AUDIO 20config USB_AUDIO
8 tristate "USB Audio support" 21 tristate "USB Audio support"
9 depends on USB && SOUND 22 depends on USB && SOUND && OBSOLETE_OSS_USB_DRIVER
10 help 23 help
11 Say Y here if you want to connect USB audio equipment such as 24 Say Y here if you want to connect USB audio equipment such as
12 speakers to your computer's USB port. You only need this if you use 25 speakers to your computer's USB port. You only need this if you use
@@ -40,10 +53,12 @@ config USB_BLUETOOTH_TTY
40 53
41config USB_MIDI 54config USB_MIDI
42 tristate "USB MIDI support" 55 tristate "USB MIDI support"
43 depends on USB && SOUND 56 depends on USB && SOUND && OBSOLETE_OSS_USB_DRIVER
44 ---help--- 57 ---help---
45 Say Y here if you want to connect a USB MIDI device to your 58 Say Y here if you want to connect a USB MIDI device to your
46 computer's USB port. This driver is for devices that comply with 59 computer's USB port. You only need this if you use the OSS
60 sound system; USB MIDI devices are supported by ALSA's USB
61 audio driver. This driver is for devices that comply with
47 'Universal Serial Bus Device Class Definition for MIDI Device'. 62 'Universal Serial Bus Device Class Definition for MIDI Device'.
48 63
49 The following devices are known to work: 64 The following devices are known to work:
diff --git a/drivers/usb/class/audio.c b/drivers/usb/class/audio.c
index f8f21567cc22..50858273f8d3 100644
--- a/drivers/usb/class/audio.c
+++ b/drivers/usb/class/audio.c
@@ -631,8 +631,10 @@ static void usbin_stop(struct usb_audiodev *as)
631 i = u->flags; 631 i = u->flags;
632 spin_unlock_irqrestore(&as->lock, flags); 632 spin_unlock_irqrestore(&as->lock, flags);
633 while (i & (FLG_URB0RUNNING|FLG_URB1RUNNING|FLG_SYNC0RUNNING|FLG_SYNC1RUNNING)) { 633 while (i & (FLG_URB0RUNNING|FLG_URB1RUNNING|FLG_SYNC0RUNNING|FLG_SYNC1RUNNING)) {
634 set_current_state(notkilled ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); 634 if (notkilled)
635 schedule_timeout(1); 635 schedule_timeout_interruptible(1);
636 else
637 schedule_timeout_uninterruptible(1);
636 spin_lock_irqsave(&as->lock, flags); 638 spin_lock_irqsave(&as->lock, flags);
637 i = u->flags; 639 i = u->flags;
638 spin_unlock_irqrestore(&as->lock, flags); 640 spin_unlock_irqrestore(&as->lock, flags);
@@ -1102,8 +1104,10 @@ static void usbout_stop(struct usb_audiodev *as)
1102 i = u->flags; 1104 i = u->flags;
1103 spin_unlock_irqrestore(&as->lock, flags); 1105 spin_unlock_irqrestore(&as->lock, flags);
1104 while (i & (FLG_URB0RUNNING|FLG_URB1RUNNING|FLG_SYNC0RUNNING|FLG_SYNC1RUNNING)) { 1106 while (i & (FLG_URB0RUNNING|FLG_URB1RUNNING|FLG_SYNC0RUNNING|FLG_SYNC1RUNNING)) {
1105 set_current_state(notkilled ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); 1107 if (notkilled)
1106 schedule_timeout(1); 1108 schedule_timeout_interruptible(1);
1109 else
1110 schedule_timeout_uninterruptible(1);
1107 spin_lock_irqsave(&as->lock, flags); 1111 spin_lock_irqsave(&as->lock, flags);
1108 i = u->flags; 1112 i = u->flags;
1109 spin_unlock_irqrestore(&as->lock, flags); 1113 spin_unlock_irqrestore(&as->lock, flags);
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 7ce43fb8118a..e195709c9c7f 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -310,8 +310,9 @@ static int usblp_check_status(struct usblp *usblp, int err)
310 310
311 error = usblp_read_status (usblp, usblp->statusbuf); 311 error = usblp_read_status (usblp, usblp->statusbuf);
312 if (error < 0) { 312 if (error < 0) {
313 err("usblp%d: error %d reading printer status", 313 if (printk_ratelimit())
314 usblp->minor, error); 314 err("usblp%d: error %d reading printer status",
315 usblp->minor, error);
315 return 0; 316 return 0;
316 } 317 }
317 318
@@ -604,7 +605,9 @@ static int usblp_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
604 605
605 case LPGETSTATUS: 606 case LPGETSTATUS:
606 if (usblp_read_status(usblp, usblp->statusbuf)) { 607 if (usblp_read_status(usblp, usblp->statusbuf)) {
607 err("usblp%d: failed reading printer status", usblp->minor); 608 if (printk_ratelimit())
609 err("usblp%d: failed reading printer status",
610 usblp->minor);
608 retval = -EIO; 611 retval = -EIO;
609 goto done; 612 goto done;
610 } 613 }
diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index 9e8c377b8161..d5503cf0bf74 100644
--- a/drivers/usb/core/Makefile
+++ b/drivers/usb/core/Makefile
@@ -3,14 +3,14 @@
3# 3#
4 4
5usbcore-objs := usb.o hub.o hcd.o urb.o message.o \ 5usbcore-objs := usb.o hub.o hcd.o urb.o message.o \
6 config.o file.o buffer.o sysfs.o 6 config.o file.o buffer.o sysfs.o devio.o
7 7
8ifeq ($(CONFIG_PCI),y) 8ifeq ($(CONFIG_PCI),y)
9 usbcore-objs += hcd-pci.o 9 usbcore-objs += hcd-pci.o
10endif 10endif
11 11
12ifeq ($(CONFIG_USB_DEVICEFS),y) 12ifeq ($(CONFIG_USB_DEVICEFS),y)
13 usbcore-objs += devio.o inode.o devices.o 13 usbcore-objs += inode.o devices.o
14endif 14endif
15 15
16obj-$(CONFIG_USB) += usbcore.o 16obj-$(CONFIG_USB) += usbcore.o
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index f86bf1454e21..b4265aa7d45e 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -43,6 +43,7 @@
43#include <linux/module.h> 43#include <linux/module.h>
44#include <linux/usb.h> 44#include <linux/usb.h>
45#include <linux/usbdevice_fs.h> 45#include <linux/usbdevice_fs.h>
46#include <linux/cdev.h>
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
47#include <asm/byteorder.h> 48#include <asm/byteorder.h>
48#include <linux/moduleparam.h> 49#include <linux/moduleparam.h>
@@ -50,6 +51,10 @@
50#include "hcd.h" /* for usbcore internals */ 51#include "hcd.h" /* for usbcore internals */
51#include "usb.h" 52#include "usb.h"
52 53
54#define USB_MAXBUS 64
55#define USB_DEVICE_MAX USB_MAXBUS * 128
56static struct class *usb_device_class;
57
53struct async { 58struct async {
54 struct list_head asynclist; 59 struct list_head asynclist;
55 struct dev_state *ps; 60 struct dev_state *ps;
@@ -71,6 +76,8 @@ MODULE_PARM_DESC (usbfs_snoop, "true to log all usbfs traffic");
71 dev_info( dev , format , ## arg); \ 76 dev_info( dev , format , ## arg); \
72 } while (0) 77 } while (0)
73 78
79#define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0)
80
74 81
75#define MAX_USBFS_BUFFER_SIZE 16384 82#define MAX_USBFS_BUFFER_SIZE 16384
76 83
@@ -487,7 +494,7 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype, unsig
487 */ 494 */
488static int usbdev_open(struct inode *inode, struct file *file) 495static int usbdev_open(struct inode *inode, struct file *file)
489{ 496{
490 struct usb_device *dev; 497 struct usb_device *dev = NULL;
491 struct dev_state *ps; 498 struct dev_state *ps;
492 int ret; 499 int ret;
493 500
@@ -501,11 +508,16 @@ static int usbdev_open(struct inode *inode, struct file *file)
501 508
502 lock_kernel(); 509 lock_kernel();
503 ret = -ENOENT; 510 ret = -ENOENT;
504 dev = usb_get_dev(inode->u.generic_ip); 511 /* check if we are called from a real node or usbfs */
512 if (imajor(inode) == USB_DEVICE_MAJOR)
513 dev = usbdev_lookup_minor(iminor(inode));
514 if (!dev)
515 dev = inode->u.generic_ip;
505 if (!dev) { 516 if (!dev) {
506 kfree(ps); 517 kfree(ps);
507 goto out; 518 goto out;
508 } 519 }
520 usb_get_dev(dev);
509 ret = 0; 521 ret = 0;
510 ps->dev = dev; 522 ps->dev = dev;
511 ps->file = file; 523 ps->file = file;
@@ -1226,7 +1238,6 @@ static int proc_ioctl (struct dev_state *ps, void __user *arg)
1226 int retval = 0; 1238 int retval = 0;
1227 struct usb_interface *intf = NULL; 1239 struct usb_interface *intf = NULL;
1228 struct usb_driver *driver = NULL; 1240 struct usb_driver *driver = NULL;
1229 int i;
1230 1241
1231 /* get input parameters and alloc buffer */ 1242 /* get input parameters and alloc buffer */
1232 if (copy_from_user(&ctrl, arg, sizeof (ctrl))) 1243 if (copy_from_user(&ctrl, arg, sizeof (ctrl)))
@@ -1258,15 +1269,6 @@ static int proc_ioctl (struct dev_state *ps, void __user *arg)
1258 /* disconnect kernel driver from interface */ 1269 /* disconnect kernel driver from interface */
1259 case USBDEVFS_DISCONNECT: 1270 case USBDEVFS_DISCONNECT:
1260 1271
1261 /* don't allow the user to unbind the hub driver from
1262 * a hub with children to manage */
1263 for (i = 0; i < ps->dev->maxchild; ++i) {
1264 if (ps->dev->children[i])
1265 retval = -EBUSY;
1266 }
1267 if (retval)
1268 break;
1269
1270 down_write(&usb_bus_type.subsys.rwsem); 1272 down_write(&usb_bus_type.subsys.rwsem);
1271 if (intf->dev.driver) { 1273 if (intf->dev.driver) {
1272 driver = to_usb_driver(intf->dev.driver); 1274 driver = to_usb_driver(intf->dev.driver);
@@ -1477,3 +1479,79 @@ struct file_operations usbfs_device_file_operations = {
1477 .open = usbdev_open, 1479 .open = usbdev_open,
1478 .release = usbdev_release, 1480 .release = usbdev_release,
1479}; 1481};
1482
1483struct usb_device *usbdev_lookup_minor(int minor)
1484{
1485 struct class_device *class_dev;
1486 struct usb_device *dev = NULL;
1487
1488 down(&usb_device_class->sem);
1489 list_for_each_entry(class_dev, &usb_device_class->children, node) {
1490 if (class_dev->devt == MKDEV(USB_DEVICE_MAJOR, minor)) {
1491 dev = class_dev->class_data;
1492 break;
1493 }
1494 }
1495 up(&usb_device_class->sem);
1496
1497 return dev;
1498};
1499
1500void usbdev_add(struct usb_device *dev)
1501{
1502 int minor = ((dev->bus->busnum-1) * 128) + (dev->devnum-1);
1503
1504 dev->class_dev = class_device_create(usb_device_class,
1505 MKDEV(USB_DEVICE_MAJOR, minor), &dev->dev,
1506 "usbdev%d.%d", dev->bus->busnum, dev->devnum);
1507
1508 dev->class_dev->class_data = dev;
1509}
1510
1511void usbdev_remove(struct usb_device *dev)
1512{
1513 class_device_unregister(dev->class_dev);
1514}
1515
1516static struct cdev usb_device_cdev = {
1517 .kobj = {.name = "usb_device", },
1518 .owner = THIS_MODULE,
1519};
1520
1521int __init usbdev_init(void)
1522{
1523 int retval;
1524
1525 retval = register_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX,
1526 "usb_device");
1527 if (retval) {
1528 err("unable to register minors for usb_device");
1529 goto out;
1530 }
1531 cdev_init(&usb_device_cdev, &usbfs_device_file_operations);
1532 retval = cdev_add(&usb_device_cdev, USB_DEVICE_DEV, USB_DEVICE_MAX);
1533 if (retval) {
1534 err("unable to get usb_device major %d", USB_DEVICE_MAJOR);
1535 unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
1536 goto out;
1537 }
1538 usb_device_class = class_create(THIS_MODULE, "usb_device");
1539 if (IS_ERR(usb_device_class)) {
1540 err("unable to register usb_device class");
1541 retval = PTR_ERR(usb_device_class);
1542 usb_device_class = NULL;
1543 cdev_del(&usb_device_cdev);
1544 unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
1545 }
1546
1547out:
1548 return retval;
1549}
1550
1551void usbdev_cleanup(void)
1552{
1553 class_destroy(usb_device_class);
1554 cdev_del(&usb_device_cdev);
1555 unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
1556}
1557
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index fc056062c960..cbb451d227d2 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -121,10 +121,6 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
121 } 121 }
122 } 122 }
123 123
124#ifdef CONFIG_PCI_NAMES
125 hcd->product_desc = dev->pretty_name;
126#endif
127
128 pci_set_master (dev); 124 pci_set_master (dev);
129 125
130 retval = usb_add_hcd (hcd, dev->irq, SA_SHIRQ); 126 retval = usb_add_hcd (hcd, dev->irq, SA_SHIRQ);
@@ -264,8 +260,10 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message)
264 retval = pci_set_power_state (dev, PCI_D3hot); 260 retval = pci_set_power_state (dev, PCI_D3hot);
265 if (retval == 0) { 261 if (retval == 0) {
266 dev_dbg (hcd->self.controller, "--> PCI D3\n"); 262 dev_dbg (hcd->self.controller, "--> PCI D3\n");
267 pci_enable_wake (dev, PCI_D3hot, hcd->remote_wakeup); 263 retval = pci_enable_wake (dev, PCI_D3hot, hcd->remote_wakeup);
268 pci_enable_wake (dev, PCI_D3cold, hcd->remote_wakeup); 264 if (retval)
265 break;
266 retval = pci_enable_wake (dev, PCI_D3cold, hcd->remote_wakeup);
269 } else if (retval < 0) { 267 } else if (retval < 0) {
270 dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n", 268 dev_dbg (&dev->dev, "PCI D3 suspend fail, %d\n",
271 retval); 269 retval);
@@ -339,8 +337,20 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
339 dev->current_state); 337 dev->current_state);
340 } 338 }
341#endif 339#endif
342 pci_enable_wake (dev, dev->current_state, 0); 340 retval = pci_enable_wake (dev, dev->current_state, 0);
343 pci_enable_wake (dev, PCI_D3cold, 0); 341 if (retval) {
342 dev_err(hcd->self.controller,
343 "can't enable_wake to %d, %d!\n",
344 dev->current_state, retval);
345 return retval;
346 }
347 retval = pci_enable_wake (dev, PCI_D3cold, 0);
348 if (retval) {
349 dev_err(hcd->self.controller,
350 "can't enable_wake to %d, %d!\n",
351 PCI_D3cold, retval);
352 return retval;
353 }
344 } else { 354 } else {
345 /* Same basic cases: clean (powered/not), dirty */ 355 /* Same basic cases: clean (powered/not), dirty */
346 dev_dbg(hcd->self.controller, "PCI legacy resume\n"); 356 dev_dbg(hcd->self.controller, "PCI legacy resume\n");
@@ -380,7 +390,7 @@ int usb_hcd_pci_resume (struct pci_dev *dev)
380 usb_hc_died (hcd); 390 usb_hc_died (hcd);
381 } 391 }
382 392
383 pci_enable_device(dev); 393 retval = pci_enable_device(dev);
384 return retval; 394 return retval;
385} 395}
386EXPORT_SYMBOL (usb_hcd_pci_resume); 396EXPORT_SYMBOL (usb_hcd_pci_resume);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 12ecdb03ee5f..1017a97a418b 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1606,7 +1606,7 @@ irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs * r)
1606 return IRQ_NONE; 1606 return IRQ_NONE;
1607 1607
1608 hcd->saw_irq = 1; 1608 hcd->saw_irq = 1;
1609 if (hcd->state != start && hcd->state == HC_STATE_HALT) 1609 if (hcd->state == HC_STATE_HALT)
1610 usb_hc_died (hcd); 1610 usb_hc_died (hcd);
1611 return IRQ_HANDLED; 1611 return IRQ_HANDLED;
1612} 1612}
@@ -1630,7 +1630,6 @@ void usb_hc_died (struct usb_hcd *hcd)
1630 spin_lock_irqsave (&hcd_root_hub_lock, flags); 1630 spin_lock_irqsave (&hcd_root_hub_lock, flags);
1631 if (hcd->rh_registered) { 1631 if (hcd->rh_registered) {
1632 hcd->poll_rh = 0; 1632 hcd->poll_rh = 0;
1633 del_timer(&hcd->rh_timer);
1634 1633
1635 /* make khubd clean up old urbs and devices */ 1634 /* make khubd clean up old urbs and devices */
1636 usb_set_device_state (hcd->self.root_hub, 1635 usb_set_device_state (hcd->self.root_hub,
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 28055f95645b..ac451fa7e4d2 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -339,11 +339,11 @@ extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb);
339 * to preallocate bandwidth) 339 * to preallocate bandwidth)
340 */ 340 */
341#define USB2_HOST_DELAY 5 /* nsec, guess */ 341#define USB2_HOST_DELAY 5 /* nsec, guess */
342#define HS_NSECS(bytes) ( ((55 * 8 * 2083)/1000) \ 342#define HS_NSECS(bytes) ( ((55 * 8 * 2083) \
343 + ((2083UL * (3167 + BitTime (bytes)))/1000) \ 343 + (2083UL * (3 + BitTime(bytes))))/1000 \
344 + USB2_HOST_DELAY) 344 + USB2_HOST_DELAY)
345#define HS_NSECS_ISO(bytes) ( ((38 * 8 * 2083)/1000) \ 345#define HS_NSECS_ISO(bytes) ( ((38 * 8 * 2083) \
346 + ((2083UL * (3167 + BitTime (bytes)))/1000) \ 346 + (2083UL * (3 + BitTime(bytes))))/1000 \
347 + USB2_HOST_DELAY) 347 + USB2_HOST_DELAY)
348#define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes)) 348#define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes))
349#define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes)) 349#define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes))
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index c9412daff682..a12cab5314e9 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -435,6 +435,7 @@ void usb_hub_tt_clear_buffer (struct usb_device *udev, int pipe)
435static void hub_power_on(struct usb_hub *hub) 435static void hub_power_on(struct usb_hub *hub)
436{ 436{
437 int port1; 437 int port1;
438 unsigned pgood_delay = hub->descriptor->bPwrOn2PwrGood * 2;
438 439
439 /* if hub supports power switching, enable power on each port */ 440 /* if hub supports power switching, enable power on each port */
440 if ((hub->descriptor->wHubCharacteristics & HUB_CHAR_LPSM) < 2) { 441 if ((hub->descriptor->wHubCharacteristics & HUB_CHAR_LPSM) < 2) {
@@ -444,8 +445,8 @@ static void hub_power_on(struct usb_hub *hub)
444 USB_PORT_FEAT_POWER); 445 USB_PORT_FEAT_POWER);
445 } 446 }
446 447
447 /* Wait for power to be enabled */ 448 /* Wait at least 100 msec for power to become stable */
448 msleep(hub->descriptor->bPwrOn2PwrGood * 2); 449 msleep(max(pgood_delay, (unsigned) 100));
449} 450}
450 451
451static void hub_quiesce(struct usb_hub *hub) 452static void hub_quiesce(struct usb_hub *hub)
@@ -492,6 +493,23 @@ static int hub_hub_status(struct usb_hub *hub,
492 return ret; 493 return ret;
493} 494}
494 495
496static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
497{
498 struct usb_device *hdev = hub->hdev;
499 int ret;
500
501 if (hdev->children[port1-1] && set_state) {
502 usb_set_device_state(hdev->children[port1-1],
503 USB_STATE_NOTATTACHED);
504 }
505 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE);
506 if (ret)
507 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
508 port1, ret);
509
510 return ret;
511}
512
495static int hub_configure(struct usb_hub *hub, 513static int hub_configure(struct usb_hub *hub,
496 struct usb_endpoint_descriptor *endpoint) 514 struct usb_endpoint_descriptor *endpoint)
497{ 515{
@@ -610,19 +628,33 @@ static int hub_configure(struct usb_hub *hub,
610 break; 628 break;
611 } 629 }
612 630
631 /* Note 8 FS bit times == (8 bits / 12000000 bps) ~= 666ns */
613 switch (hub->descriptor->wHubCharacteristics & HUB_CHAR_TTTT) { 632 switch (hub->descriptor->wHubCharacteristics & HUB_CHAR_TTTT) {
614 case 0x00: 633 case HUB_TTTT_8_BITS:
615 if (hdev->descriptor.bDeviceProtocol != 0) 634 if (hdev->descriptor.bDeviceProtocol != 0) {
616 dev_dbg(hub_dev, "TT requires at most 8 FS bit times\n"); 635 hub->tt.think_time = 666;
636 dev_dbg(hub_dev, "TT requires at most %d "
637 "FS bit times (%d ns)\n",
638 8, hub->tt.think_time);
639 }
617 break; 640 break;
618 case 0x20: 641 case HUB_TTTT_16_BITS:
619 dev_dbg(hub_dev, "TT requires at most 16 FS bit times\n"); 642 hub->tt.think_time = 666 * 2;
643 dev_dbg(hub_dev, "TT requires at most %d "
644 "FS bit times (%d ns)\n",
645 16, hub->tt.think_time);
620 break; 646 break;
621 case 0x40: 647 case HUB_TTTT_24_BITS:
622 dev_dbg(hub_dev, "TT requires at most 24 FS bit times\n"); 648 hub->tt.think_time = 666 * 3;
649 dev_dbg(hub_dev, "TT requires at most %d "
650 "FS bit times (%d ns)\n",
651 24, hub->tt.think_time);
623 break; 652 break;
624 case 0x60: 653 case HUB_TTTT_32_BITS:
625 dev_dbg(hub_dev, "TT requires at most 32 FS bit times\n"); 654 hub->tt.think_time = 666 * 4;
655 dev_dbg(hub_dev, "TT requires at most %d "
656 "FS bit times (%d ns)\n",
657 32, hub->tt.think_time);
626 break; 658 break;
627 } 659 }
628 660
@@ -712,20 +744,36 @@ fail:
712 744
713static unsigned highspeed_hubs; 745static unsigned highspeed_hubs;
714 746
747/* Called after the hub driver is unbound from a hub with children */
748static void hub_remove_children_work(void *__hub)
749{
750 struct usb_hub *hub = __hub;
751 struct usb_device *hdev = hub->hdev;
752 int i;
753
754 kfree(hub);
755
756 usb_lock_device(hdev);
757 for (i = 0; i < hdev->maxchild; ++i) {
758 if (hdev->children[i])
759 usb_disconnect(&hdev->children[i]);
760 }
761 usb_unlock_device(hdev);
762 usb_put_dev(hdev);
763}
764
715static void hub_disconnect(struct usb_interface *intf) 765static void hub_disconnect(struct usb_interface *intf)
716{ 766{
717 struct usb_hub *hub = usb_get_intfdata (intf); 767 struct usb_hub *hub = usb_get_intfdata (intf);
718 struct usb_device *hdev; 768 struct usb_device *hdev;
769 int n, port1;
719 770
720 if (!hub) 771 usb_set_intfdata (intf, NULL);
721 return;
722 hdev = hub->hdev; 772 hdev = hub->hdev;
723 773
724 if (hdev->speed == USB_SPEED_HIGH) 774 if (hdev->speed == USB_SPEED_HIGH)
725 highspeed_hubs--; 775 highspeed_hubs--;
726 776
727 usb_set_intfdata (intf, NULL);
728
729 hub_quiesce(hub); 777 hub_quiesce(hub);
730 usb_free_urb(hub->urb); 778 usb_free_urb(hub->urb);
731 hub->urb = NULL; 779 hub->urb = NULL;
@@ -746,8 +794,27 @@ static void hub_disconnect(struct usb_interface *intf)
746 hub->buffer = NULL; 794 hub->buffer = NULL;
747 } 795 }
748 796
749 /* Free the memory */ 797 /* If there are any children then this is an unbind only, not a
750 kfree(hub); 798 * physical disconnection. The active ports must be disabled
799 * and later on we must call usb_disconnect(). We can't call
800 * it now because we may not hold the hub's device lock.
801 */
802 n = 0;
803 for (port1 = 1; port1 <= hdev->maxchild; ++port1) {
804 if (hdev->children[port1 - 1]) {
805 ++n;
806 hub_port_disable(hub, port1, 1);
807 }
808 }
809
810 if (n == 0)
811 kfree(hub);
812 else {
813 /* Reuse the hub->leds work_struct for our own purposes */
814 INIT_WORK(&hub->leds, hub_remove_children_work, hub);
815 schedule_work(&hub->leds);
816 usb_get_dev(hdev);
817 }
751} 818}
752 819
753static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id) 820static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
@@ -1051,6 +1118,7 @@ void usb_disconnect(struct usb_device **pdev)
1051 dev_dbg (&udev->dev, "unregistering device\n"); 1118 dev_dbg (&udev->dev, "unregistering device\n");
1052 release_address(udev); 1119 release_address(udev);
1053 usbfs_remove_device(udev); 1120 usbfs_remove_device(udev);
1121 usbdev_remove(udev);
1054 usb_remove_sysfs_dev_files(udev); 1122 usb_remove_sysfs_dev_files(udev);
1055 1123
1056 /* Avoid races with recursively_mark_NOTATTACHED() */ 1124 /* Avoid races with recursively_mark_NOTATTACHED() */
@@ -1290,6 +1358,7 @@ int usb_new_device(struct usb_device *udev)
1290 /* USB device state == configured ... usable */ 1358 /* USB device state == configured ... usable */
1291 1359
1292 /* add a /proc/bus/usb entry */ 1360 /* add a /proc/bus/usb entry */
1361 usbdev_add(udev);
1293 usbfs_add_device(udev); 1362 usbfs_add_device(udev);
1294 return 0; 1363 return 0;
1295 1364
@@ -1392,7 +1461,7 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
1392 port1, status); 1461 port1, status);
1393 else { 1462 else {
1394 status = hub_port_wait_reset(hub, port1, udev, delay); 1463 status = hub_port_wait_reset(hub, port1, udev, delay);
1395 if (status) 1464 if (status && status != -ENOTCONN)
1396 dev_dbg(hub->intfdev, 1465 dev_dbg(hub->intfdev,
1397 "port_wait_reset: err = %d\n", 1466 "port_wait_reset: err = %d\n",
1398 status); 1467 status);
@@ -1401,8 +1470,8 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
1401 /* return on disconnect or reset */ 1470 /* return on disconnect or reset */
1402 switch (status) { 1471 switch (status) {
1403 case 0: 1472 case 0:
1404 /* TRSTRCY = 10 ms */ 1473 /* TRSTRCY = 10 ms; plus some extra */
1405 msleep(10); 1474 msleep(10 + 40);
1406 /* FALL THROUGH */ 1475 /* FALL THROUGH */
1407 case -ENOTCONN: 1476 case -ENOTCONN:
1408 case -ENODEV: 1477 case -ENODEV:
@@ -1428,23 +1497,6 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
1428 return status; 1497 return status;
1429} 1498}
1430 1499
1431static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
1432{
1433 struct usb_device *hdev = hub->hdev;
1434 int ret;
1435
1436 if (hdev->children[port1-1] && set_state) {
1437 usb_set_device_state(hdev->children[port1-1],
1438 USB_STATE_NOTATTACHED);
1439 }
1440 ret = clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE);
1441 if (ret)
1442 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
1443 port1, ret);
1444
1445 return ret;
1446}
1447
1448/* 1500/*
1449 * Disable a port and mark a logical connnect-change event, so that some 1501 * Disable a port and mark a logical connnect-change event, so that some
1450 * time later khubd will disconnect() any existing usb_device on the port 1502 * time later khubd will disconnect() any existing usb_device on the port
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index 53bf5649621e..e7fa9b5a521e 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -157,6 +157,12 @@ enum hub_led_mode {
157 157
158struct usb_device; 158struct usb_device;
159 159
160/* Transaction Translator Think Times, in bits */
161#define HUB_TTTT_8_BITS 0x00
162#define HUB_TTTT_16_BITS 0x20
163#define HUB_TTTT_24_BITS 0x40
164#define HUB_TTTT_32_BITS 0x60
165
160/* 166/*
161 * As of USB 2.0, full/low speed devices are segregated into trees. 167 * As of USB 2.0, full/low speed devices are segregated into trees.
162 * One type grows from USB 1.1 host controllers (OHCI, UHCI etc). 168 * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
@@ -170,6 +176,7 @@ struct usb_device;
170struct usb_tt { 176struct usb_tt {
171 struct usb_device *hub; /* upstream highspeed hub */ 177 struct usb_device *hub; /* upstream highspeed hub */
172 int multi; /* true means one TT per port */ 178 int multi; /* true means one TT per port */
179 unsigned think_time; /* think time in ns */
173 180
174 /* for control/bulk error recovery (CLEAR_TT_BUFFER) */ 181 /* for control/bulk error recovery (CLEAR_TT_BUFFER) */
175 spinlock_t lock; 182 spinlock_t lock;
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index c3e3a95d3804..640f41e47029 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -728,15 +728,9 @@ int __init usbfs_init(void)
728{ 728{
729 int retval; 729 int retval;
730 730
731 retval = usb_register(&usbfs_driver);
732 if (retval)
733 return retval;
734
735 retval = register_filesystem(&usb_fs_type); 731 retval = register_filesystem(&usb_fs_type);
736 if (retval) { 732 if (retval)
737 usb_deregister(&usbfs_driver);
738 return retval; 733 return retval;
739 }
740 734
741 /* create mount point for usbfs */ 735 /* create mount point for usbfs */
742 usbdir = proc_mkdir("usb", proc_bus); 736 usbdir = proc_mkdir("usb", proc_bus);
@@ -746,7 +740,6 @@ int __init usbfs_init(void)
746 740
747void usbfs_cleanup(void) 741void usbfs_cleanup(void)
748{ 742{
749 usb_deregister(&usbfs_driver);
750 unregister_filesystem(&usb_fs_type); 743 unregister_filesystem(&usb_fs_type);
751 if (usbdir) 744 if (usbdir)
752 remove_proc_entry("usb", proc_bus); 745 remove_proc_entry("usb", proc_bus);
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 88d1b376f67c..c47c8052b486 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -48,7 +48,6 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int* actual_length)
48 48
49 init_completion(&done); 49 init_completion(&done);
50 urb->context = &done; 50 urb->context = &done;
51 urb->transfer_flags |= URB_ASYNC_UNLINK;
52 urb->actual_length = 0; 51 urb->actual_length = 0;
53 status = usb_submit_urb(urb, GFP_NOIO); 52 status = usb_submit_urb(urb, GFP_NOIO);
54 53
@@ -266,7 +265,9 @@ static void sg_complete (struct urb *urb, struct pt_regs *regs)
266 continue; 265 continue;
267 if (found) { 266 if (found) {
268 status = usb_unlink_urb (io->urbs [i]); 267 status = usb_unlink_urb (io->urbs [i]);
269 if (status != -EINPROGRESS && status != -EBUSY) 268 if (status != -EINPROGRESS
269 && status != -ENODEV
270 && status != -EBUSY)
270 dev_err (&io->dev->dev, 271 dev_err (&io->dev->dev,
271 "%s, unlink --> %d\n", 272 "%s, unlink --> %d\n",
272 __FUNCTION__, status); 273 __FUNCTION__, status);
@@ -357,8 +358,7 @@ int usb_sg_init (
357 if (!io->urbs) 358 if (!io->urbs)
358 goto nomem; 359 goto nomem;
359 360
360 urb_flags = URB_ASYNC_UNLINK | URB_NO_TRANSFER_DMA_MAP 361 urb_flags = URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT;
361 | URB_NO_INTERRUPT;
362 if (usb_pipein (pipe)) 362 if (usb_pipein (pipe))
363 urb_flags |= URB_SHORT_NOT_OK; 363 urb_flags |= URB_SHORT_NOT_OK;
364 364
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index c0feee25ff0a..c846fefb7386 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -309,9 +309,8 @@ int usb_submit_urb(struct urb *urb, unsigned mem_flags)
309 unsigned int allowed; 309 unsigned int allowed;
310 310
311 /* enforce simple/standard policy */ 311 /* enforce simple/standard policy */
312 allowed = URB_ASYNC_UNLINK; // affects later unlinks 312 allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP |
313 allowed |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); 313 URB_NO_INTERRUPT);
314 allowed |= URB_NO_INTERRUPT;
315 switch (temp) { 314 switch (temp) {
316 case PIPE_BULK: 315 case PIPE_BULK:
317 if (is_out) 316 if (is_out)
@@ -400,14 +399,8 @@ int usb_submit_urb(struct urb *urb, unsigned mem_flags)
400 * canceled (rather than any other code) and will quickly be removed 399 * canceled (rather than any other code) and will quickly be removed
401 * from host controller data structures. 400 * from host controller data structures.
402 * 401 *
403 * In the past, clearing the URB_ASYNC_UNLINK transfer flag for the 402 * This request is always asynchronous.
404 * URB indicated that the request was synchronous. This usage is now 403 * Success is indicated by returning -EINPROGRESS,
405 * deprecated; if the flag is clear the call will be forwarded to
406 * usb_kill_urb() and the return value will be 0. In the future, drivers
407 * should call usb_kill_urb() directly for synchronous unlinking.
408 *
409 * When the URB_ASYNC_UNLINK transfer flag for the URB is set, this
410 * request is asynchronous. Success is indicated by returning -EINPROGRESS,
411 * at which time the URB will normally have been unlinked but not yet 404 * at which time the URB will normally have been unlinked but not yet
412 * given back to the device driver. When it is called, the completion 405 * given back to the device driver. When it is called, the completion
413 * function will see urb->status == -ECONNRESET. Failure is indicated 406 * function will see urb->status == -ECONNRESET. Failure is indicated
@@ -453,17 +446,6 @@ int usb_unlink_urb(struct urb *urb)
453{ 446{
454 if (!urb) 447 if (!urb)
455 return -EINVAL; 448 return -EINVAL;
456 if (!(urb->transfer_flags & URB_ASYNC_UNLINK)) {
457#ifdef CONFIG_DEBUG_KERNEL
458 if (printk_ratelimit()) {
459 printk(KERN_NOTICE "usb_unlink_urb() is deprecated for "
460 "synchronous unlinks. Use usb_kill_urb() instead.\n");
461 WARN_ON(1);
462 }
463#endif
464 usb_kill_urb(urb);
465 return 0;
466 }
467 if (!(urb->dev && urb->dev->bus && urb->dev->bus->op)) 449 if (!(urb->dev && urb->dev->bus && urb->dev->bus->op))
468 return -ENODEV; 450 return -ENODEV;
469 return urb->dev->bus->op->unlink_urb(urb, -ECONNRESET); 451 return urb->dev->bus->op->unlink_urb(urb, -ECONNRESET);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 2cddd8a00437..087af73a59dd 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -65,6 +65,16 @@ static int generic_probe (struct device *dev)
65} 65}
66static int generic_remove (struct device *dev) 66static int generic_remove (struct device *dev)
67{ 67{
68 struct usb_device *udev = to_usb_device(dev);
69
70 /* if this is only an unbind, not a physical disconnect, then
71 * unconfigure the device */
72 if (udev->state == USB_STATE_CONFIGURED)
73 usb_set_configuration(udev, 0);
74
75 /* in case the call failed or the device was suspended */
76 if (udev->state >= USB_STATE_CONFIGURED)
77 usb_disable_device(udev, 0);
68 return 0; 78 return 0;
69} 79}
70 80
@@ -912,7 +922,7 @@ int usb_trylock_device(struct usb_device *udev)
912 * is neither BINDING nor BOUND. Rather than sleeping to wait for the 922 * is neither BINDING nor BOUND. Rather than sleeping to wait for the
913 * lock, the routine polls repeatedly. This is to prevent deadlock with 923 * lock, the routine polls repeatedly. This is to prevent deadlock with
914 * disconnect; in some drivers (such as usb-storage) the disconnect() 924 * disconnect; in some drivers (such as usb-storage) the disconnect()
915 * callback will block waiting for a device reset to complete. 925 * or suspend() method will block waiting for a device reset to complete.
916 * 926 *
917 * Returns a negative error code for failure, otherwise 1 or 0 to indicate 927 * Returns a negative error code for failure, otherwise 1 or 0 to indicate
918 * that the device will or will not have to be unlocked. (0 can be 928 * that the device will or will not have to be unlocked. (0 can be
@@ -922,6 +932,8 @@ int usb_trylock_device(struct usb_device *udev)
922int usb_lock_device_for_reset(struct usb_device *udev, 932int usb_lock_device_for_reset(struct usb_device *udev,
923 struct usb_interface *iface) 933 struct usb_interface *iface)
924{ 934{
935 unsigned long jiffies_expire = jiffies + HZ;
936
925 if (udev->state == USB_STATE_NOTATTACHED) 937 if (udev->state == USB_STATE_NOTATTACHED)
926 return -ENODEV; 938 return -ENODEV;
927 if (udev->state == USB_STATE_SUSPENDED) 939 if (udev->state == USB_STATE_SUSPENDED)
@@ -938,6 +950,12 @@ int usb_lock_device_for_reset(struct usb_device *udev,
938 } 950 }
939 951
940 while (!usb_trylock_device(udev)) { 952 while (!usb_trylock_device(udev)) {
953
954 /* If we can't acquire the lock after waiting one second,
955 * we're probably deadlocked */
956 if (time_after(jiffies, jiffies_expire))
957 return -EBUSY;
958
941 msleep(15); 959 msleep(15);
942 if (udev->state == USB_STATE_NOTATTACHED) 960 if (udev->state == USB_STATE_NOTATTACHED)
943 return -ENODEV; 961 return -ENODEV;
@@ -1478,13 +1496,18 @@ static int __init usb_init(void)
1478 retval = usb_major_init(); 1496 retval = usb_major_init();
1479 if (retval) 1497 if (retval)
1480 goto major_init_failed; 1498 goto major_init_failed;
1499 retval = usb_register(&usbfs_driver);
1500 if (retval)
1501 goto driver_register_failed;
1502 retval = usbdev_init();
1503 if (retval)
1504 goto usbdevice_init_failed;
1481 retval = usbfs_init(); 1505 retval = usbfs_init();
1482 if (retval) 1506 if (retval)
1483 goto fs_init_failed; 1507 goto fs_init_failed;
1484 retval = usb_hub_init(); 1508 retval = usb_hub_init();
1485 if (retval) 1509 if (retval)
1486 goto hub_init_failed; 1510 goto hub_init_failed;
1487
1488 retval = driver_register(&usb_generic_driver); 1511 retval = driver_register(&usb_generic_driver);
1489 if (!retval) 1512 if (!retval)
1490 goto out; 1513 goto out;
@@ -1493,7 +1516,11 @@ static int __init usb_init(void)
1493hub_init_failed: 1516hub_init_failed:
1494 usbfs_cleanup(); 1517 usbfs_cleanup();
1495fs_init_failed: 1518fs_init_failed:
1496 usb_major_cleanup(); 1519 usbdev_cleanup();
1520usbdevice_init_failed:
1521 usb_deregister(&usbfs_driver);
1522driver_register_failed:
1523 usb_major_cleanup();
1497major_init_failed: 1524major_init_failed:
1498 usb_host_cleanup(); 1525 usb_host_cleanup();
1499host_init_failed: 1526host_init_failed:
@@ -1514,6 +1541,8 @@ static void __exit usb_exit(void)
1514 driver_unregister(&usb_generic_driver); 1541 driver_unregister(&usb_generic_driver);
1515 usb_major_cleanup(); 1542 usb_major_cleanup();
1516 usbfs_cleanup(); 1543 usbfs_cleanup();
1544 usb_deregister(&usbfs_driver);
1545 usbdev_cleanup();
1517 usb_hub_cleanup(); 1546 usb_hub_cleanup();
1518 usb_host_cleanup(); 1547 usb_host_cleanup();
1519 bus_unregister(&usb_bus_type); 1548 bus_unregister(&usb_bus_type);
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 2c690f6d4c18..83d48c8133af 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -37,6 +37,11 @@ extern struct file_operations usbfs_devices_fops;
37extern struct file_operations usbfs_device_file_operations; 37extern struct file_operations usbfs_device_file_operations;
38extern void usbfs_conn_disc_event(void); 38extern void usbfs_conn_disc_event(void);
39 39
40extern int usbdev_init(void);
41extern void usbdev_cleanup(void);
42extern void usbdev_add(struct usb_device *dev);
43extern void usbdev_remove(struct usb_device *dev);
44extern struct usb_device *usbdev_lookup_minor(int minor);
40 45
41struct dev_state { 46struct dev_state {
42 struct list_head list; /* state list */ 47 struct list_head list; /* state list */
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 8509e955007d..49459e33e952 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -2181,6 +2181,7 @@ eth_bind (struct usb_gadget *gadget)
2181 u8 cdc = 1, zlp = 1, rndis = 1; 2181 u8 cdc = 1, zlp = 1, rndis = 1;
2182 struct usb_ep *in_ep, *out_ep, *status_ep = NULL; 2182 struct usb_ep *in_ep, *out_ep, *status_ep = NULL;
2183 int status = -ENOMEM; 2183 int status = -ENOMEM;
2184 int gcnum;
2184 2185
2185 /* these flags are only ever cleared; compiler take note */ 2186 /* these flags are only ever cleared; compiler take note */
2186#ifndef DEV_CONFIG_CDC 2187#ifndef DEV_CONFIG_CDC
@@ -2194,44 +2195,26 @@ eth_bind (struct usb_gadget *gadget)
2194 * standard protocol is _strongly_ preferred for interop purposes. 2195 * standard protocol is _strongly_ preferred for interop purposes.
2195 * (By everyone except Microsoft.) 2196 * (By everyone except Microsoft.)
2196 */ 2197 */
2197 if (gadget_is_net2280 (gadget)) { 2198 if (gadget_is_pxa (gadget)) {
2198 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
2199 } else if (gadget_is_dummy (gadget)) {
2200 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0202);
2201 } else if (gadget_is_pxa (gadget)) {
2202 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0203);
2203 /* pxa doesn't support altsettings */ 2199 /* pxa doesn't support altsettings */
2204 cdc = 0; 2200 cdc = 0;
2205 } else if (gadget_is_sh(gadget)) { 2201 } else if (gadget_is_sh(gadget)) {
2206 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0204);
2207 /* sh doesn't support multiple interfaces or configs */ 2202 /* sh doesn't support multiple interfaces or configs */
2208 cdc = 0; 2203 cdc = 0;
2209 rndis = 0; 2204 rndis = 0;
2210 } else if (gadget_is_sa1100 (gadget)) { 2205 } else if (gadget_is_sa1100 (gadget)) {
2211 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0205);
2212 /* hardware can't write zlps */ 2206 /* hardware can't write zlps */
2213 zlp = 0; 2207 zlp = 0;
2214 /* sa1100 CAN do CDC, without status endpoint ... we use 2208 /* sa1100 CAN do CDC, without status endpoint ... we use
2215 * non-CDC to be compatible with ARM Linux-2.4 "usb-eth". 2209 * non-CDC to be compatible with ARM Linux-2.4 "usb-eth".
2216 */ 2210 */
2217 cdc = 0; 2211 cdc = 0;
2218 } else if (gadget_is_goku (gadget)) { 2212 }
2219 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0206); 2213
2220 } else if (gadget_is_mq11xx (gadget)) { 2214 gcnum = usb_gadget_controller_number (gadget);
2221 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0207); 2215 if (gcnum >= 0)
2222 } else if (gadget_is_omap (gadget)) { 2216 device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum);
2223 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0208); 2217 else {
2224 } else if (gadget_is_lh7a40x(gadget)) {
2225 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0209);
2226 } else if (gadget_is_n9604(gadget)) {
2227 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0210);
2228 } else if (gadget_is_pxa27x(gadget)) {
2229 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0211);
2230 } else if (gadget_is_s3c2410(gadget)) {
2231 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0212);
2232 } else if (gadget_is_at91(gadget)) {
2233 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0213);
2234 } else {
2235 /* can't assume CDC works. don't want to default to 2218 /* can't assume CDC works. don't want to default to
2236 * anything less functional on CDC-capable hardware, 2219 * anything less functional on CDC-capable hardware,
2237 * so we fail in this case. 2220 * so we fail in this case.
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 4f57085619b4..a41d9d4baee3 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -3713,6 +3713,7 @@ static void fsg_unbind(struct usb_gadget *gadget)
3713static int __init check_parameters(struct fsg_dev *fsg) 3713static int __init check_parameters(struct fsg_dev *fsg)
3714{ 3714{
3715 int prot; 3715 int prot;
3716 int gcnum;
3716 3717
3717 /* Store the default values */ 3718 /* Store the default values */
3718 mod_data.transport_type = USB_PR_BULK; 3719 mod_data.transport_type = USB_PR_BULK;
@@ -3724,33 +3725,13 @@ static int __init check_parameters(struct fsg_dev *fsg)
3724 mod_data.can_stall = 0; 3725 mod_data.can_stall = 0;
3725 3726
3726 if (mod_data.release == 0xffff) { // Parameter wasn't set 3727 if (mod_data.release == 0xffff) { // Parameter wasn't set
3727 if (gadget_is_net2280(fsg->gadget))
3728 mod_data.release = 0x0301;
3729 else if (gadget_is_dummy(fsg->gadget))
3730 mod_data.release = 0x0302;
3731 else if (gadget_is_pxa(fsg->gadget))
3732 mod_data.release = 0x0303;
3733 else if (gadget_is_sh(fsg->gadget))
3734 mod_data.release = 0x0304;
3735
3736 /* The sa1100 controller is not supported */ 3728 /* The sa1100 controller is not supported */
3737 3729 if (gadget_is_sa1100(fsg->gadget))
3738 else if (gadget_is_goku(fsg->gadget)) 3730 gcnum = -1;
3739 mod_data.release = 0x0306; 3731 else
3740 else if (gadget_is_mq11xx(fsg->gadget)) 3732 gcnum = usb_gadget_controller_number(fsg->gadget);
3741 mod_data.release = 0x0307; 3733 if (gcnum >= 0)
3742 else if (gadget_is_omap(fsg->gadget)) 3734 mod_data.release = 0x0300 + gcnum;
3743 mod_data.release = 0x0308;
3744 else if (gadget_is_lh7a40x(fsg->gadget))
3745 mod_data.release = 0x0309;
3746 else if (gadget_is_n9604(fsg->gadget))
3747 mod_data.release = 0x0310;
3748 else if (gadget_is_pxa27x(fsg->gadget))
3749 mod_data.release = 0x0311;
3750 else if (gadget_is_s3c2410(gadget))
3751 mod_data.release = 0x0312;
3752 else if (gadget_is_at91(fsg->gadget))
3753 mod_data.release = 0x0313;
3754 else { 3735 else {
3755 WARN(fsg, "controller '%s' not recognized\n", 3736 WARN(fsg, "controller '%s' not recognized\n",
3756 fsg->gadget->name); 3737 fsg->gadget->name);
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index ea2eb52c766d..8cbae21d84b9 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -5,6 +5,7 @@
5 * 5 *
6 * This could eventually work like the ARM mach_is_*() stuff, driven by 6 * This could eventually work like the ARM mach_is_*() stuff, driven by
7 * some config file that gets updated as new hardware is supported. 7 * some config file that gets updated as new hardware is supported.
8 * (And avoiding the runtime comparisons in typical one-choice cases.)
8 * 9 *
9 * NOTE: some of these controller drivers may not be available yet. 10 * NOTE: some of these controller drivers may not be available yet.
10 */ 11 */
@@ -86,7 +87,61 @@
86#define gadget_is_at91(g) 0 87#define gadget_is_at91(g) 0
87#endif 88#endif
88 89
90#ifdef CONFIG_USB_GADGET_IMX
91#define gadget_is_imx(g) !strcmp("imx_udc", (g)->name)
92#else
93#define gadget_is_imx(g) 0
94#endif
95
89// CONFIG_USB_GADGET_SX2 96// CONFIG_USB_GADGET_SX2
90// CONFIG_USB_GADGET_AU1X00 97// CONFIG_USB_GADGET_AU1X00
91// ... 98// ...
92 99
100
101/**
102 * usb_gadget_controller_number - support bcdDevice id convention
103 * @gadget: the controller being driven
104 *
105 * Return a 2-digit BCD value associated with the peripheral controller,
106 * suitable for use as part of a bcdDevice value, or a negative error code.
107 *
108 * NOTE: this convention is purely optional, and has no meaning in terms of
109 * any USB specification. If you want to use a different convention in your
110 * gadget driver firmware -- maybe a more formal revision ID -- feel free.
111 *
112 * Hosts see these bcdDevice numbers, and are allowed (but not encouraged!)
113 * to change their behavior accordingly. For example it might help avoiding
114 * some chip bug.
115 */
116static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
117{
118 if (gadget_is_net2280(gadget))
119 return 0x01;
120 else if (gadget_is_dummy(gadget))
121 return 0x02;
122 else if (gadget_is_pxa(gadget))
123 return 0x03;
124 else if (gadget_is_sh(gadget))
125 return 0x04;
126 else if (gadget_is_sa1100(gadget))
127 return 0x05;
128 else if (gadget_is_goku(gadget))
129 return 0x06;
130 else if (gadget_is_mq11xx(gadget))
131 return 0x07;
132 else if (gadget_is_omap(gadget))
133 return 0x08;
134 else if (gadget_is_lh7a40x(gadget))
135 return 0x09;
136 else if (gadget_is_n9604(gadget))
137 return 0x10;
138 else if (gadget_is_pxa27x(gadget))
139 return 0x11;
140 else if (gadget_is_s3c2410(gadget))
141 return 0x12;
142 else if (gadget_is_at91(gadget))
143 return 0x13;
144 else if (gadget_is_imx(gadget))
145 return 0x14;
146 return -ENOENT;
147}
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 020815397a49..5c40980a5bd9 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -483,6 +483,7 @@ ep_release (struct inode *inode, struct file *fd)
483 data->state = STATE_EP_DISABLED; 483 data->state = STATE_EP_DISABLED;
484 data->desc.bDescriptorType = 0; 484 data->desc.bDescriptorType = 0;
485 data->hs_desc.bDescriptorType = 0; 485 data->hs_desc.bDescriptorType = 0;
486 usb_ep_disable(data->ep);
486 } 487 }
487 put_ep (data); 488 put_ep (data);
488 return 0; 489 return 0;
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 9e4f1c6935a5..c925d9222f53 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -1422,49 +1422,20 @@ static int gs_bind(struct usb_gadget *gadget)
1422 int ret; 1422 int ret;
1423 struct usb_ep *ep; 1423 struct usb_ep *ep;
1424 struct gs_dev *dev; 1424 struct gs_dev *dev;
1425 int gcnum;
1425 1426
1426 /* device specific */ 1427 /* Some controllers can't support CDC ACM:
1427 if (gadget_is_net2280(gadget)) { 1428 * - sh doesn't support multiple interfaces or configs;
1428 gs_device_desc.bcdDevice = 1429 * - sa1100 doesn't have a third interrupt endpoint
1429 __constant_cpu_to_le16(GS_VERSION_NUM|0x0001); 1430 */
1430 } else if (gadget_is_pxa(gadget)) { 1431 if (gadget_is_sh(gadget) || gadget_is_sa1100(gadget))
1431 gs_device_desc.bcdDevice =
1432 __constant_cpu_to_le16(GS_VERSION_NUM|0x0002);
1433 } else if (gadget_is_sh(gadget)) {
1434 gs_device_desc.bcdDevice =
1435 __constant_cpu_to_le16(GS_VERSION_NUM|0x0003);
1436 /* sh doesn't support multiple interfaces or configs */
1437 use_acm = 0; 1432 use_acm = 0;
1438 } else if (gadget_is_sa1100(gadget)) { 1433
1439 gs_device_desc.bcdDevice = 1434 gcnum = usb_gadget_controller_number(gadget);
1440 __constant_cpu_to_le16(GS_VERSION_NUM|0x0004); 1435 if (gcnum >= 0)
1441 /* sa1100 doesn't support necessary endpoints */
1442 use_acm = 0;
1443 } else if (gadget_is_goku(gadget)) {
1444 gs_device_desc.bcdDevice =
1445 __constant_cpu_to_le16(GS_VERSION_NUM|0x0005);
1446 } else if (gadget_is_mq11xx(gadget)) {
1447 gs_device_desc.bcdDevice =
1448 __constant_cpu_to_le16(GS_VERSION_NUM|0x0006);
1449 } else if (gadget_is_omap(gadget)) {
1450 gs_device_desc.bcdDevice =
1451 __constant_cpu_to_le16(GS_VERSION_NUM|0x0007);
1452 } else if (gadget_is_lh7a40x(gadget)) {
1453 gs_device_desc.bcdDevice =
1454 __constant_cpu_to_le16(GS_VERSION_NUM|0x0008);
1455 } else if (gadget_is_n9604(gadget)) {
1456 gs_device_desc.bcdDevice =
1457 __constant_cpu_to_le16(GS_VERSION_NUM|0x0009);
1458 } else if (gadget_is_pxa27x(gadget)) {
1459 gs_device_desc.bcdDevice =
1460 __constant_cpu_to_le16(GS_VERSION_NUM|0x0011);
1461 } else if (gadget_is_s3c2410(gadget)) {
1462 gs_device_desc.bcdDevice =
1463 __constant_cpu_to_le16(GS_VERSION_NUM|0x0012);
1464 } else if (gadget_is_at91(gadget)) {
1465 gs_device_desc.bcdDevice = 1436 gs_device_desc.bcdDevice =
1466 __constant_cpu_to_le16(GS_VERSION_NUM|0x0013); 1437 cpu_to_le16(GS_VERSION_NUM | gcnum);
1467 } else { 1438 else {
1468 printk(KERN_WARNING "gs_bind: controller '%s' not recognized\n", 1439 printk(KERN_WARNING "gs_bind: controller '%s' not recognized\n",
1469 gadget->name); 1440 gadget->name);
1470 /* unrecognized, but safe unless bulk is REALLY quirky */ 1441 /* unrecognized, but safe unless bulk is REALLY quirky */
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index bb9b2d94eed5..6890e773b2a2 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -1139,6 +1139,13 @@ zero_bind (struct usb_gadget *gadget)
1139{ 1139{
1140 struct zero_dev *dev; 1140 struct zero_dev *dev;
1141 struct usb_ep *ep; 1141 struct usb_ep *ep;
1142 int gcnum;
1143
1144 /* FIXME this can't yet work right with SH ... it has only
1145 * one configuration, numbered one.
1146 */
1147 if (gadget_is_sh(gadget))
1148 return -ENODEV;
1142 1149
1143 /* Bulk-only drivers like this one SHOULD be able to 1150 /* Bulk-only drivers like this one SHOULD be able to
1144 * autoconfigure on any sane usb controller driver, 1151 * autoconfigure on any sane usb controller driver,
@@ -1161,43 +1168,10 @@ autoconf_fail:
1161 EP_OUT_NAME = ep->name; 1168 EP_OUT_NAME = ep->name;
1162 ep->driver_data = ep; /* claim */ 1169 ep->driver_data = ep; /* claim */
1163 1170
1164 1171 gcnum = usb_gadget_controller_number (gadget);
1165 /* 1172 if (gcnum >= 0)
1166 * DRIVER POLICY CHOICE: you may want to do this differently. 1173 device_desc.bcdDevice = cpu_to_le16 (0x0200 + gcnum);
1167 * One thing to avoid is reusing a bcdDevice revision code 1174 else {
1168 * with different host-visible configurations or behavior
1169 * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
1170 */
1171 if (gadget_is_net2280 (gadget)) {
1172 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
1173 } else if (gadget_is_pxa (gadget)) {
1174 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0203);
1175#if 0
1176 } else if (gadget_is_sh(gadget)) {
1177 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0204);
1178 /* SH has only one configuration; see "loopdefault" */
1179 device_desc.bNumConfigurations = 1;
1180 /* FIXME make 1 == default.bConfigurationValue */
1181#endif
1182 } else if (gadget_is_sa1100 (gadget)) {
1183 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0205);
1184 } else if (gadget_is_goku (gadget)) {
1185 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0206);
1186 } else if (gadget_is_mq11xx (gadget)) {
1187 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0207);
1188 } else if (gadget_is_omap (gadget)) {
1189 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0208);
1190 } else if (gadget_is_lh7a40x(gadget)) {
1191 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0209);
1192 } else if (gadget_is_n9604(gadget)) {
1193 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0210);
1194 } else if (gadget_is_pxa27x(gadget)) {
1195 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0211);
1196 } else if (gadget_is_s3c2410(gadget)) {
1197 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0212);
1198 } else if (gadget_is_at91(gadget)) {
1199 device_desc.bcdDevice = __constant_cpu_to_le16 (0x0213);
1200 } else {
1201 /* gadget zero is so simple (for now, no altsettings) that 1175 /* gadget zero is so simple (for now, no altsettings) that
1202 * it SHOULD NOT have problems with bulk-capable hardware. 1176 * it SHOULD NOT have problems with bulk-capable hardware.
1203 * so warn about unrcognized controllers, don't panic. 1177 * so warn about unrcognized controllers, don't panic.
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 149b13fc0a71..b948ffd94f45 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -400,6 +400,23 @@ static int ehci_hc_reset (struct usb_hcd *hcd)
400 return -EIO; 400 return -EIO;
401 } 401 }
402 break; 402 break;
403 case PCI_VENDOR_ID_NVIDIA:
404 /* NVidia reports that certain chips don't handle
405 * QH, ITD, or SITD addresses above 2GB. (But TD,
406 * data buffer, and periodic schedule are normal.)
407 */
408 switch (pdev->device) {
409 case 0x003c: /* MCP04 */
410 case 0x005b: /* CK804 */
411 case 0x00d8: /* CK8 */
412 case 0x00e8: /* CK8S */
413 if (pci_set_consistent_dma_mask(pdev,
414 DMA_31BIT_MASK) < 0)
415 ehci_warn (ehci, "can't enable NVidia "
416 "workaround for >2GB RAM\n");
417 break;
418 }
419 break;
403 } 420 }
404 421
405 /* optional debug port, normally in the first BAR */ 422 /* optional debug port, normally in the first BAR */
@@ -549,7 +566,9 @@ static int ehci_start (struct usb_hcd *hcd)
549 hcd->can_wakeup = (port_wake & 1) != 0; 566 hcd->can_wakeup = (port_wake & 1) != 0;
550 567
551 /* help hc dma work well with cachelines */ 568 /* help hc dma work well with cachelines */
552 pci_set_mwi (pdev); 569 retval = pci_set_mwi(pdev);
570 if (retval)
571 ehci_dbg(ehci, "unable to enable MWI - not fatal.\n");
553 } 572 }
554#endif 573#endif
555 574
@@ -757,12 +776,16 @@ static int ehci_resume (struct usb_hcd *hcd)
757 if (time_before (jiffies, ehci->next_statechange)) 776 if (time_before (jiffies, ehci->next_statechange))
758 msleep (100); 777 msleep (100);
759 778
760 /* If any port is suspended, we know we can/must resume the HC. */ 779 /* If any port is suspended (or owned by the companion),
780 * we know we can/must resume the HC (and mustn't reset it).
781 */
761 for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; ) { 782 for (port = HCS_N_PORTS (ehci->hcs_params); port > 0; ) {
762 u32 status; 783 u32 status;
763 port--; 784 port--;
764 status = readl (&ehci->regs->port_status [port]); 785 status = readl (&ehci->regs->port_status [port]);
765 if (status & PORT_SUSPEND) { 786 if (!(status & PORT_POWER))
787 continue;
788 if (status & (PORT_SUSPEND | PORT_OWNER)) {
766 down (&hcd->self.root_hub->serialize); 789 down (&hcd->self.root_hub->serialize);
767 retval = ehci_hub_resume (hcd); 790 retval = ehci_hub_resume (hcd);
768 up (&hcd->self.root_hub->serialize); 791 up (&hcd->self.root_hub->serialize);
@@ -1124,8 +1147,7 @@ rescan:
1124 case QH_STATE_UNLINK: /* wait for hw to finish? */ 1147 case QH_STATE_UNLINK: /* wait for hw to finish? */
1125idle_timeout: 1148idle_timeout:
1126 spin_unlock_irqrestore (&ehci->lock, flags); 1149 spin_unlock_irqrestore (&ehci->lock, flags);
1127 set_current_state (TASK_UNINTERRUPTIBLE); 1150 schedule_timeout_uninterruptible(1);
1128 schedule_timeout (1);
1129 goto rescan; 1151 goto rescan;
1130 case QH_STATE_IDLE: /* fully unlinked */ 1152 case QH_STATE_IDLE: /* fully unlinked */
1131 if (list_empty (&qh->qtd_list)) { 1153 if (list_empty (&qh->qtd_list)) {
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 36cc1f2218d5..18d3f2270316 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -54,7 +54,7 @@ static int ehci_hub_suspend (struct usb_hcd *hcd)
54 /* suspend any active/unsuspended ports, maybe allow wakeup */ 54 /* suspend any active/unsuspended ports, maybe allow wakeup */
55 while (port--) { 55 while (port--) {
56 u32 __iomem *reg = &ehci->regs->port_status [port]; 56 u32 __iomem *reg = &ehci->regs->port_status [port];
57 u32 t1 = readl (reg); 57 u32 t1 = readl (reg) & ~PORT_RWC_BITS;
58 u32 t2 = t1; 58 u32 t2 = t1;
59 59
60 if ((t1 & PORT_PE) && !(t1 & PORT_OWNER)) 60 if ((t1 & PORT_PE) && !(t1 & PORT_OWNER))
@@ -115,7 +115,8 @@ static int ehci_hub_resume (struct usb_hcd *hcd)
115 i = HCS_N_PORTS (ehci->hcs_params); 115 i = HCS_N_PORTS (ehci->hcs_params);
116 while (i--) { 116 while (i--) {
117 temp = readl (&ehci->regs->port_status [i]); 117 temp = readl (&ehci->regs->port_status [i]);
118 temp &= ~(PORT_WKOC_E|PORT_WKDISC_E|PORT_WKCONN_E); 118 temp &= ~(PORT_RWC_BITS
119 | PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E);
119 if (temp & PORT_SUSPEND) { 120 if (temp & PORT_SUSPEND) {
120 ehci->reset_done [i] = jiffies + msecs_to_jiffies (20); 121 ehci->reset_done [i] = jiffies + msecs_to_jiffies (20);
121 temp |= PORT_RESUME; 122 temp |= PORT_RESUME;
@@ -128,7 +129,7 @@ static int ehci_hub_resume (struct usb_hcd *hcd)
128 temp = readl (&ehci->regs->port_status [i]); 129 temp = readl (&ehci->regs->port_status [i]);
129 if ((temp & PORT_SUSPEND) == 0) 130 if ((temp & PORT_SUSPEND) == 0)
130 continue; 131 continue;
131 temp &= ~PORT_RESUME; 132 temp &= ~(PORT_RWC_BITS | PORT_RESUME);
132 writel (temp, &ehci->regs->port_status [i]); 133 writel (temp, &ehci->regs->port_status [i]);
133 ehci_vdbg (ehci, "resumed port %d\n", i + 1); 134 ehci_vdbg (ehci, "resumed port %d\n", i + 1);
134 } 135 }
@@ -191,6 +192,7 @@ static int check_reset_complete (
191 192
192 // what happens if HCS_N_CC(params) == 0 ? 193 // what happens if HCS_N_CC(params) == 0 ?
193 port_status |= PORT_OWNER; 194 port_status |= PORT_OWNER;
195 port_status &= ~PORT_RWC_BITS;
194 writel (port_status, &ehci->regs->port_status [index]); 196 writel (port_status, &ehci->regs->port_status [index]);
195 197
196 } else 198 } else
@@ -233,7 +235,8 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
233 if (temp & PORT_OWNER) { 235 if (temp & PORT_OWNER) {
234 /* don't report this in GetPortStatus */ 236 /* don't report this in GetPortStatus */
235 if (temp & PORT_CSC) { 237 if (temp & PORT_CSC) {
236 temp &= ~PORT_CSC; 238 temp &= ~PORT_RWC_BITS;
239 temp |= PORT_CSC;
237 writel (temp, &ehci->regs->port_status [i]); 240 writel (temp, &ehci->regs->port_status [i]);
238 } 241 }
239 continue; 242 continue;
@@ -343,7 +346,7 @@ static int ehci_hub_control (
343 &ehci->regs->port_status [wIndex]); 346 &ehci->regs->port_status [wIndex]);
344 break; 347 break;
345 case USB_PORT_FEAT_C_ENABLE: 348 case USB_PORT_FEAT_C_ENABLE:
346 writel (temp | PORT_PEC, 349 writel((temp & ~PORT_RWC_BITS) | PORT_PEC,
347 &ehci->regs->port_status [wIndex]); 350 &ehci->regs->port_status [wIndex]);
348 break; 351 break;
349 case USB_PORT_FEAT_SUSPEND: 352 case USB_PORT_FEAT_SUSPEND:
@@ -353,7 +356,8 @@ static int ehci_hub_control (
353 if ((temp & PORT_PE) == 0) 356 if ((temp & PORT_PE) == 0)
354 goto error; 357 goto error;
355 /* resume signaling for 20 msec */ 358 /* resume signaling for 20 msec */
356 writel ((temp & ~PORT_WAKE_BITS) | PORT_RESUME, 359 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
360 writel (temp | PORT_RESUME,
357 &ehci->regs->port_status [wIndex]); 361 &ehci->regs->port_status [wIndex]);
358 ehci->reset_done [wIndex] = jiffies 362 ehci->reset_done [wIndex] = jiffies
359 + msecs_to_jiffies (20); 363 + msecs_to_jiffies (20);
@@ -364,15 +368,15 @@ static int ehci_hub_control (
364 break; 368 break;
365 case USB_PORT_FEAT_POWER: 369 case USB_PORT_FEAT_POWER:
366 if (HCS_PPC (ehci->hcs_params)) 370 if (HCS_PPC (ehci->hcs_params))
367 writel (temp & ~PORT_POWER, 371 writel (temp & ~(PORT_RWC_BITS | PORT_POWER),
368 &ehci->regs->port_status [wIndex]); 372 &ehci->regs->port_status [wIndex]);
369 break; 373 break;
370 case USB_PORT_FEAT_C_CONNECTION: 374 case USB_PORT_FEAT_C_CONNECTION:
371 writel (temp | PORT_CSC, 375 writel((temp & ~PORT_RWC_BITS) | PORT_CSC,
372 &ehci->regs->port_status [wIndex]); 376 &ehci->regs->port_status [wIndex]);
373 break; 377 break;
374 case USB_PORT_FEAT_C_OVER_CURRENT: 378 case USB_PORT_FEAT_C_OVER_CURRENT:
375 writel (temp | PORT_OCC, 379 writel((temp & ~PORT_RWC_BITS) | PORT_OCC,
376 &ehci->regs->port_status [wIndex]); 380 &ehci->regs->port_status [wIndex]);
377 break; 381 break;
378 case USB_PORT_FEAT_C_RESET: 382 case USB_PORT_FEAT_C_RESET:
@@ -416,7 +420,7 @@ static int ehci_hub_control (
416 420
417 /* stop resume signaling */ 421 /* stop resume signaling */
418 temp = readl (&ehci->regs->port_status [wIndex]); 422 temp = readl (&ehci->regs->port_status [wIndex]);
419 writel (temp & ~PORT_RESUME, 423 writel (temp & ~(PORT_RWC_BITS | PORT_RESUME),
420 &ehci->regs->port_status [wIndex]); 424 &ehci->regs->port_status [wIndex]);
421 retval = handshake ( 425 retval = handshake (
422 &ehci->regs->port_status [wIndex], 426 &ehci->regs->port_status [wIndex],
@@ -437,7 +441,7 @@ static int ehci_hub_control (
437 ehci->reset_done [wIndex] = 0; 441 ehci->reset_done [wIndex] = 0;
438 442
439 /* force reset to complete */ 443 /* force reset to complete */
440 writel (temp & ~PORT_RESET, 444 writel (temp & ~(PORT_RWC_BITS | PORT_RESET),
441 &ehci->regs->port_status [wIndex]); 445 &ehci->regs->port_status [wIndex]);
442 /* REVISIT: some hardware needs 550+ usec to clear 446 /* REVISIT: some hardware needs 550+ usec to clear
443 * this bit; seems too long to spin routinely... 447 * this bit; seems too long to spin routinely...
@@ -500,6 +504,7 @@ static int ehci_hub_control (
500 if (temp & PORT_OWNER) 504 if (temp & PORT_OWNER)
501 break; 505 break;
502 506
507 temp &= ~PORT_RWC_BITS;
503 switch (wValue) { 508 switch (wValue) {
504 case USB_PORT_FEAT_SUSPEND: 509 case USB_PORT_FEAT_SUSPEND:
505 if ((temp & PORT_PE) == 0 510 if ((temp & PORT_PE) == 0
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 20df01a79b2e..940d38ca7d91 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -677,6 +677,9 @@ qh_make (
677 goto done; 677 goto done;
678 } 678 }
679 } else { 679 } else {
680 struct usb_tt *tt = urb->dev->tt;
681 int think_time;
682
680 /* gap is f(FS/LS transfer times) */ 683 /* gap is f(FS/LS transfer times) */
681 qh->gap_uf = 1 + usb_calc_bus_time (urb->dev->speed, 684 qh->gap_uf = 1 + usb_calc_bus_time (urb->dev->speed,
682 is_input, 0, maxp) / (125 * 1000); 685 is_input, 0, maxp) / (125 * 1000);
@@ -690,6 +693,10 @@ qh_make (
690 qh->c_usecs = HS_USECS (0); 693 qh->c_usecs = HS_USECS (0);
691 } 694 }
692 695
696 think_time = tt ? tt->think_time : 0;
697 qh->tt_usecs = NS_TO_US (think_time +
698 usb_calc_bus_time (urb->dev->speed,
699 is_input, 0, max_packet (maxp)));
693 qh->period = urb->interval; 700 qh->period = urb->interval;
694 } 701 }
695 } 702 }
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 4c972b57c7c3..ccc7300baa6d 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -700,6 +700,7 @@ iso_stream_init (
700 700
701 } else { 701 } else {
702 u32 addr; 702 u32 addr;
703 int think_time;
703 704
704 addr = dev->ttport << 24; 705 addr = dev->ttport << 24;
705 if (!ehci_is_TDI(ehci) 706 if (!ehci_is_TDI(ehci)
@@ -709,6 +710,9 @@ iso_stream_init (
709 addr |= epnum << 8; 710 addr |= epnum << 8;
710 addr |= dev->devnum; 711 addr |= dev->devnum;
711 stream->usecs = HS_USECS_ISO (maxp); 712 stream->usecs = HS_USECS_ISO (maxp);
713 think_time = dev->tt ? dev->tt->think_time : 0;
714 stream->tt_usecs = NS_TO_US (think_time + usb_calc_bus_time (
715 dev->speed, is_input, 1, maxp));
712 if (is_input) { 716 if (is_input) {
713 u32 tmp; 717 u32 tmp;
714 718
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index a7542157534c..f34a0516d35f 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -263,6 +263,7 @@ struct ehci_regs {
263#define PORT_PE (1<<2) /* port enable */ 263#define PORT_PE (1<<2) /* port enable */
264#define PORT_CSC (1<<1) /* connect status change */ 264#define PORT_CSC (1<<1) /* connect status change */
265#define PORT_CONNECT (1<<0) /* device connected */ 265#define PORT_CONNECT (1<<0) /* device connected */
266#define PORT_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
266} __attribute__ ((packed)); 267} __attribute__ ((packed));
267 268
268/* Appendix C, Debug port ... intended for use with special "debug devices" 269/* Appendix C, Debug port ... intended for use with special "debug devices"
@@ -421,6 +422,7 @@ struct ehci_qh {
421 u8 usecs; /* intr bandwidth */ 422 u8 usecs; /* intr bandwidth */
422 u8 gap_uf; /* uframes split/csplit gap */ 423 u8 gap_uf; /* uframes split/csplit gap */
423 u8 c_usecs; /* ... split completion bw */ 424 u8 c_usecs; /* ... split completion bw */
425 u16 tt_usecs; /* tt downstream bandwidth */
424 unsigned short period; /* polling interval */ 426 unsigned short period; /* polling interval */
425 unsigned short start; /* where polling starts */ 427 unsigned short start; /* where polling starts */
426#define NO_FRAME ((unsigned short)~0) /* pick new start */ 428#define NO_FRAME ((unsigned short)~0) /* pick new start */
@@ -479,6 +481,7 @@ struct ehci_iso_stream {
479 */ 481 */
480 u8 interval; 482 u8 interval;
481 u8 usecs, c_usecs; 483 u8 usecs, c_usecs;
484 u16 tt_usecs;
482 u16 maxp; 485 u16 maxp;
483 u16 raw_mask; 486 u16 raw_mask;
484 unsigned bandwidth; 487 unsigned bandwidth;
diff --git a/drivers/usb/host/hc_crisv10.c b/drivers/usb/host/hc_crisv10.c
index 81f8f6b7fdce..a8267cf17db4 100644
--- a/drivers/usb/host/hc_crisv10.c
+++ b/drivers/usb/host/hc_crisv10.c
@@ -178,8 +178,8 @@ static __u8 root_hub_hub_des[] =
178 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */ 178 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
179}; 179};
180 180
181static struct timer_list bulk_start_timer = TIMER_INITIALIZER(NULL, 0, 0); 181static DEFINE_TIMER(bulk_start_timer, NULL, 0, 0);
182static struct timer_list bulk_eot_timer = TIMER_INITIALIZER(NULL, 0, 0); 182static DEFINE_TIMER(bulk_eot_timer, NULL, 0, 0);
183 183
184/* We want the start timer to expire before the eot timer, because the former might start 184/* We want the start timer to expire before the eot timer, because the former might start
185 traffic, thus making it unnecessary for the latter to time out. */ 185 traffic, thus making it unnecessary for the latter to time out. */
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 75128c371800..41bbae83fc71 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -83,7 +83,7 @@
83#include "../core/hcd.h" 83#include "../core/hcd.h"
84#include "isp116x.h" 84#include "isp116x.h"
85 85
86#define DRIVER_VERSION "08 Apr 2005" 86#define DRIVER_VERSION "05 Aug 2005"
87#define DRIVER_DESC "ISP116x USB Host Controller Driver" 87#define DRIVER_DESC "ISP116x USB Host Controller Driver"
88 88
89MODULE_DESCRIPTION(DRIVER_DESC); 89MODULE_DESCRIPTION(DRIVER_DESC);
@@ -629,14 +629,12 @@ static irqreturn_t isp116x_irq(struct usb_hcd *hcd, struct pt_regs *regs)
629 ERR("Unrecoverable error\n"); 629 ERR("Unrecoverable error\n");
630 /* What should we do here? Reset? */ 630 /* What should we do here? Reset? */
631 } 631 }
632 if (intstat & HCINT_RHSC) { 632 if (intstat & HCINT_RHSC)
633 isp116x->rhstatus = 633 /* When root hub or any of its ports is going
634 isp116x_read_reg32(isp116x, HCRHSTATUS); 634 to come out of suspend, it may take more
635 isp116x->rhport[0] = 635 than 10ms for status bits to stabilize. */
636 isp116x_read_reg32(isp116x, HCRHPORT1); 636 mod_timer(&hcd->rh_timer, jiffies
637 isp116x->rhport[1] = 637 + msecs_to_jiffies(20) + 1);
638 isp116x_read_reg32(isp116x, HCRHPORT2);
639 }
640 if (intstat & HCINT_RD) { 638 if (intstat & HCINT_RD) {
641 DBG("---- remote wakeup\n"); 639 DBG("---- remote wakeup\n");
642 schedule_work(&isp116x->rh_resume); 640 schedule_work(&isp116x->rh_resume);
@@ -925,20 +923,27 @@ static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
925{ 923{
926 struct isp116x *isp116x = hcd_to_isp116x(hcd); 924 struct isp116x *isp116x = hcd_to_isp116x(hcd);
927 int ports, i, changed = 0; 925 int ports, i, changed = 0;
926 unsigned long flags;
928 927
929 if (!HC_IS_RUNNING(hcd->state)) 928 if (!HC_IS_RUNNING(hcd->state))
930 return -ESHUTDOWN; 929 return -ESHUTDOWN;
931 930
932 ports = isp116x->rhdesca & RH_A_NDP; 931 /* Report no status change now, if we are scheduled to be
932 called later */
933 if (timer_pending(&hcd->rh_timer))
934 return 0;
933 935
934 /* init status */ 936 ports = isp116x->rhdesca & RH_A_NDP;
937 spin_lock_irqsave(&isp116x->lock, flags);
938 isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
935 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC)) 939 if (isp116x->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
936 buf[0] = changed = 1; 940 buf[0] = changed = 1;
937 else 941 else
938 buf[0] = 0; 942 buf[0] = 0;
939 943
940 for (i = 0; i < ports; i++) { 944 for (i = 0; i < ports; i++) {
941 u32 status = isp116x->rhport[i]; 945 u32 status = isp116x->rhport[i] =
946 isp116x_read_reg32(isp116x, i ? HCRHPORT2 : HCRHPORT1);
942 947
943 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 948 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
944 | RH_PS_OCIC | RH_PS_PRSC)) { 949 | RH_PS_OCIC | RH_PS_PRSC)) {
@@ -947,6 +952,7 @@ static int isp116x_hub_status_data(struct usb_hcd *hcd, char *buf)
947 continue; 952 continue;
948 } 953 }
949 } 954 }
955 spin_unlock_irqrestore(&isp116x->lock, flags);
950 return changed; 956 return changed;
951} 957}
952 958
@@ -1463,10 +1469,6 @@ static int isp116x_sw_reset(struct isp116x *isp116x)
1463 return ret; 1469 return ret;
1464} 1470}
1465 1471
1466/*
1467 Reset. Tries to perform platform-specific hardware
1468 reset first; falls back to software reset.
1469*/
1470static int isp116x_reset(struct usb_hcd *hcd) 1472static int isp116x_reset(struct usb_hcd *hcd)
1471{ 1473{
1472 struct isp116x *isp116x = hcd_to_isp116x(hcd); 1474 struct isp116x *isp116x = hcd_to_isp116x(hcd);
@@ -1474,17 +1476,7 @@ static int isp116x_reset(struct usb_hcd *hcd)
1474 u16 clkrdy = 0; 1476 u16 clkrdy = 0;
1475 int ret = 0, timeout = 15 /* ms */ ; 1477 int ret = 0, timeout = 15 /* ms */ ;
1476 1478
1477 if (isp116x->board && isp116x->board->reset) { 1479 ret = isp116x_sw_reset(isp116x);
1478 /* Hardware reset */
1479 isp116x->board->reset(hcd->self.controller, 1);
1480 msleep(10);
1481 if (isp116x->board->clock)
1482 isp116x->board->clock(hcd->self.controller, 1);
1483 msleep(1);
1484 isp116x->board->reset(hcd->self.controller, 0);
1485 } else
1486 ret = isp116x_sw_reset(isp116x);
1487
1488 if (ret) 1480 if (ret)
1489 return ret; 1481 return ret;
1490 1482
@@ -1501,10 +1493,7 @@ static int isp116x_reset(struct usb_hcd *hcd)
1501 ERR("Clock not ready after 20ms\n"); 1493 ERR("Clock not ready after 20ms\n");
1502 /* After sw_reset the clock won't report to be ready, if 1494 /* After sw_reset the clock won't report to be ready, if
1503 H_WAKEUP pin is high. */ 1495 H_WAKEUP pin is high. */
1504 if (!isp116x->board || !isp116x->board->reset) 1496 ERR("Please make sure that the H_WAKEUP pin is pulled low!\n");
1505 ERR("The driver does not support hardware wakeup.\n");
1506 ERR("Please make sure that the H_WAKEUP pin "
1507 "is pulled low!\n");
1508 ret = -ENODEV; 1497 ret = -ENODEV;
1509 } 1498 }
1510 return ret; 1499 return ret;
@@ -1527,15 +1516,7 @@ static void isp116x_stop(struct usb_hcd *hcd)
1527 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS); 1516 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1528 spin_unlock_irqrestore(&isp116x->lock, flags); 1517 spin_unlock_irqrestore(&isp116x->lock, flags);
1529 1518
1530 /* Put the chip into reset state */ 1519 isp116x_sw_reset(isp116x);
1531 if (isp116x->board && isp116x->board->reset)
1532 isp116x->board->reset(hcd->self.controller, 0);
1533 else
1534 isp116x_sw_reset(isp116x);
1535
1536 /* Stop the clock */
1537 if (isp116x->board && isp116x->board->clock)
1538 isp116x->board->clock(hcd->self.controller, 0);
1539} 1520}
1540 1521
1541/* 1522/*
@@ -1561,6 +1542,9 @@ static int isp116x_start(struct usb_hcd *hcd)
1561 return -ENODEV; 1542 return -ENODEV;
1562 } 1543 }
1563 1544
1545 /* To be removed in future */
1546 hcd->uses_new_polling = 1;
1547
1564 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE); 1548 isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1565 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE); 1549 isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1566 1550
@@ -1569,7 +1553,7 @@ static int isp116x_start(struct usb_hcd *hcd)
1569 if (board->sel15Kres) 1553 if (board->sel15Kres)
1570 val |= HCHWCFG_15KRSEL; 1554 val |= HCHWCFG_15KRSEL;
1571 /* Remote wakeup won't work without working clock */ 1555 /* Remote wakeup won't work without working clock */
1572 if (board->clknotstop || board->remote_wakeup_enable) 1556 if (board->remote_wakeup_enable)
1573 val |= HCHWCFG_CLKNOTSTOP; 1557 val |= HCHWCFG_CLKNOTSTOP;
1574 if (board->oc_enable) 1558 if (board->oc_enable)
1575 val |= HCHWCFG_ANALOG_OC; 1559 val |= HCHWCFG_ANALOG_OC;
@@ -1580,16 +1564,13 @@ static int isp116x_start(struct usb_hcd *hcd)
1580 isp116x_write_reg16(isp116x, HCHWCFG, val); 1564 isp116x_write_reg16(isp116x, HCHWCFG, val);
1581 1565
1582 /* ----- Root hub conf */ 1566 /* ----- Root hub conf */
1583 val = 0; 1567 val = (25 << 24) & RH_A_POTPGT;
1584 /* AN10003_1.pdf recommends NPS to be always 1 */ 1568 /* AN10003_1.pdf recommends RH_A_NPS (no power switching) to
1585 if (board->no_power_switching) 1569 be always set. Yet, instead, we request individual port
1586 val |= RH_A_NPS; 1570 power switching. */
1587 if (board->power_switching_mode) 1571 val |= RH_A_PSM;
1588 val |= RH_A_PSM; 1572 /* Report overcurrent per port */
1589 if (board->potpg) 1573 val |= RH_A_OCPM;
1590 val |= (board->potpg << 24) & RH_A_POTPGT;
1591 else
1592 val |= (25 << 24) & RH_A_POTPGT;
1593 isp116x_write_reg32(isp116x, HCRHDESCA, val); 1574 isp116x_write_reg32(isp116x, HCRHDESCA, val);
1594 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA); 1575 isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1595 1576
@@ -1619,9 +1600,6 @@ static int isp116x_start(struct usb_hcd *hcd)
1619 1600
1620 /* Go operational */ 1601 /* Go operational */
1621 val = HCCONTROL_USB_OPER; 1602 val = HCCONTROL_USB_OPER;
1622 /* Remote wakeup connected - NOT SUPPORTED */
1623 /* if (board->remote_wakeup_connected)
1624 val |= HCCONTROL_RWC; */
1625 if (board->remote_wakeup_enable) 1603 if (board->remote_wakeup_enable)
1626 val |= HCCONTROL_RWE; 1604 val |= HCCONTROL_RWE;
1627 isp116x_write_reg32(isp116x, HCCONTROL, val); 1605 isp116x_write_reg32(isp116x, HCCONTROL, val);
@@ -1670,7 +1648,7 @@ static int __init_or_module isp116x_remove(struct device *dev)
1670 struct platform_device *pdev; 1648 struct platform_device *pdev;
1671 struct resource *res; 1649 struct resource *res;
1672 1650
1673 if(!hcd) 1651 if (!hcd)
1674 return 0; 1652 return 0;
1675 isp116x = hcd_to_isp116x(hcd); 1653 isp116x = hcd_to_isp116x(hcd);
1676 pdev = container_of(dev, struct platform_device, dev); 1654 pdev = container_of(dev, struct platform_device, dev);
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 447f488f5d93..7924c74f958e 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -228,23 +228,22 @@ ohci_dump_roothub (
228 char **next, 228 char **next,
229 unsigned *size) 229 unsigned *size)
230{ 230{
231 u32 temp, ndp, i; 231 u32 temp, i;
232 232
233 temp = roothub_a (controller); 233 temp = roothub_a (controller);
234 if (temp == ~(u32)0) 234 if (temp == ~(u32)0)
235 return; 235 return;
236 ndp = (temp & RH_A_NDP);
237 236
238 if (verbose) { 237 if (verbose) {
239 ohci_dbg_sw (controller, next, size, 238 ohci_dbg_sw (controller, next, size,
240 "roothub.a %08x POTPGT=%d%s%s%s%s%s NDP=%d\n", temp, 239 "roothub.a %08x POTPGT=%d%s%s%s%s%s NDP=%d(%d)\n", temp,
241 ((temp & RH_A_POTPGT) >> 24) & 0xff, 240 ((temp & RH_A_POTPGT) >> 24) & 0xff,
242 (temp & RH_A_NOCP) ? " NOCP" : "", 241 (temp & RH_A_NOCP) ? " NOCP" : "",
243 (temp & RH_A_OCPM) ? " OCPM" : "", 242 (temp & RH_A_OCPM) ? " OCPM" : "",
244 (temp & RH_A_DT) ? " DT" : "", 243 (temp & RH_A_DT) ? " DT" : "",
245 (temp & RH_A_NPS) ? " NPS" : "", 244 (temp & RH_A_NPS) ? " NPS" : "",
246 (temp & RH_A_PSM) ? " PSM" : "", 245 (temp & RH_A_PSM) ? " PSM" : "",
247 ndp 246 (temp & RH_A_NDP), controller->num_ports
248 ); 247 );
249 temp = roothub_b (controller); 248 temp = roothub_b (controller);
250 ohci_dbg_sw (controller, next, size, 249 ohci_dbg_sw (controller, next, size,
@@ -266,7 +265,7 @@ ohci_dump_roothub (
266 ); 265 );
267 } 266 }
268 267
269 for (i = 0; i < ndp; i++) { 268 for (i = 0; i < controller->num_ports; i++) {
270 temp = roothub_portstatus (controller, i); 269 temp = roothub_portstatus (controller, i);
271 dbg_port_sw (controller, i, temp, next, size); 270 dbg_port_sw (controller, i, temp, next, size);
272 } 271 }
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 56b43f2a0e52..67c1aa5eb1c1 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -382,8 +382,7 @@ sanitize:
382 goto sanitize; 382 goto sanitize;
383 } 383 }
384 spin_unlock_irqrestore (&ohci->lock, flags); 384 spin_unlock_irqrestore (&ohci->lock, flags);
385 set_current_state (TASK_UNINTERRUPTIBLE); 385 schedule_timeout_uninterruptible(1);
386 schedule_timeout (1);
387 goto rescan; 386 goto rescan;
388 case ED_IDLE: /* fully unlinked */ 387 case ED_IDLE: /* fully unlinked */
389 if (list_empty (&ed->td_list)) { 388 if (list_empty (&ed->td_list)) {
@@ -485,6 +484,10 @@ static int ohci_init (struct ohci_hcd *ohci)
485 // flush the writes 484 // flush the writes
486 (void) ohci_readl (ohci, &ohci->regs->control); 485 (void) ohci_readl (ohci, &ohci->regs->control);
487 486
487 /* Read the number of ports unless overridden */
488 if (ohci->num_ports == 0)
489 ohci->num_ports = roothub_a(ohci) & RH_A_NDP;
490
488 if (ohci->hcca) 491 if (ohci->hcca)
489 return 0; 492 return 0;
490 493
@@ -561,10 +564,8 @@ static int ohci_run (struct ohci_hcd *ohci)
561 msleep(temp); 564 msleep(temp);
562 temp = roothub_a (ohci); 565 temp = roothub_a (ohci);
563 if (!(temp & RH_A_NPS)) { 566 if (!(temp & RH_A_NPS)) {
564 unsigned ports = temp & RH_A_NDP;
565
566 /* power down each port */ 567 /* power down each port */
567 for (temp = 0; temp < ports; temp++) 568 for (temp = 0; temp < ohci->num_ports; temp++)
568 ohci_writel (ohci, RH_PS_LSDA, 569 ohci_writel (ohci, RH_PS_LSDA,
569 &ohci->regs->roothub.portstatus [temp]); 570 &ohci->regs->roothub.portstatus [temp]);
570 } 571 }
@@ -720,6 +721,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd, struct pt_regs *ptregs)
720 721
721 if (ints & OHCI_INTR_RD) { 722 if (ints & OHCI_INTR_RD) {
722 ohci_vdbg (ohci, "resume detect\n"); 723 ohci_vdbg (ohci, "resume detect\n");
724 ohci_writel (ohci, OHCI_INTR_RD, &regs->intrstatus);
723 if (hcd->state != HC_STATE_QUIESCING) 725 if (hcd->state != HC_STATE_QUIESCING)
724 schedule_work(&ohci->rh_resume); 726 schedule_work(&ohci->rh_resume);
725 } 727 }
@@ -861,7 +863,7 @@ static int ohci_restart (struct ohci_hcd *ohci)
861 * and that if we try to turn them back on the root hub 863 * and that if we try to turn them back on the root hub
862 * will respond to CSC processing. 864 * will respond to CSC processing.
863 */ 865 */
864 i = roothub_a (ohci) & RH_A_NDP; 866 i = ohci->num_ports;
865 while (i--) 867 while (i--)
866 ohci_writel (ohci, RH_PS_PSS, 868 ohci_writel (ohci, RH_PS_PSS,
867 &ohci->regs->roothub.portstatus [temp]); 869 &ohci->regs->roothub.portstatus [temp]);
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 83ca4549a50e..ce7b28da7a15 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -184,7 +184,7 @@ static int ohci_hub_resume (struct usb_hcd *hcd)
184 if (status != -EINPROGRESS) 184 if (status != -EINPROGRESS)
185 return status; 185 return status;
186 186
187 temp = roothub_a (ohci) & RH_A_NDP; 187 temp = ohci->num_ports;
188 enables = 0; 188 enables = 0;
189 while (temp--) { 189 while (temp--) {
190 u32 stat = ohci_readl (ohci, 190 u32 stat = ohci_readl (ohci,
@@ -304,7 +304,7 @@ static int
304ohci_hub_status_data (struct usb_hcd *hcd, char *buf) 304ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
305{ 305{
306 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 306 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
307 int ports, i, changed = 0, length = 1; 307 int i, changed = 0, length = 1;
308 int can_suspend = hcd->can_wakeup; 308 int can_suspend = hcd->can_wakeup;
309 unsigned long flags; 309 unsigned long flags;
310 310
@@ -319,9 +319,10 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
319 goto done; 319 goto done;
320 } 320 }
321 321
322 ports = roothub_a (ohci) & RH_A_NDP; 322 /* undocumented erratum seen on at least rev D */
323 if (ports > MAX_ROOT_PORTS) { 323 if ((ohci->flags & OHCI_QUIRK_AMD756)
324 ohci_err (ohci, "bogus NDP=%d, rereads as NDP=%d\n", ports, 324 && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) {
325 ohci_warn (ohci, "bogus NDP, rereads as NDP=%d\n",
325 ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP); 326 ohci_readl (ohci, &ohci->regs->roothub.a) & RH_A_NDP);
326 /* retry later; "should not happen" */ 327 /* retry later; "should not happen" */
327 goto done; 328 goto done;
@@ -332,13 +333,13 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
332 buf [0] = changed = 1; 333 buf [0] = changed = 1;
333 else 334 else
334 buf [0] = 0; 335 buf [0] = 0;
335 if (ports > 7) { 336 if (ohci->num_ports > 7) {
336 buf [1] = 0; 337 buf [1] = 0;
337 length++; 338 length++;
338 } 339 }
339 340
340 /* look at each port */ 341 /* look at each port */
341 for (i = 0; i < ports; i++) { 342 for (i = 0; i < ohci->num_ports; i++) {
342 u32 status = roothub_portstatus (ohci, i); 343 u32 status = roothub_portstatus (ohci, i);
343 344
344 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 345 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
@@ -395,15 +396,14 @@ ohci_hub_descriptor (
395 struct usb_hub_descriptor *desc 396 struct usb_hub_descriptor *desc
396) { 397) {
397 u32 rh = roothub_a (ohci); 398 u32 rh = roothub_a (ohci);
398 int ports = rh & RH_A_NDP;
399 u16 temp; 399 u16 temp;
400 400
401 desc->bDescriptorType = 0x29; 401 desc->bDescriptorType = 0x29;
402 desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24; 402 desc->bPwrOn2PwrGood = (rh & RH_A_POTPGT) >> 24;
403 desc->bHubContrCurrent = 0; 403 desc->bHubContrCurrent = 0;
404 404
405 desc->bNbrPorts = ports; 405 desc->bNbrPorts = ohci->num_ports;
406 temp = 1 + (ports / 8); 406 temp = 1 + (ohci->num_ports / 8);
407 desc->bDescLength = 7 + 2 * temp; 407 desc->bDescLength = 7 + 2 * temp;
408 408
409 temp = 0; 409 temp = 0;
@@ -421,7 +421,7 @@ ohci_hub_descriptor (
421 rh = roothub_b (ohci); 421 rh = roothub_b (ohci);
422 memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 422 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
423 desc->bitmap [0] = rh & RH_B_DR; 423 desc->bitmap [0] = rh & RH_B_DR;
424 if (ports > 7) { 424 if (ohci->num_ports > 7) {
425 desc->bitmap [1] = (rh & RH_B_DR) >> 8; 425 desc->bitmap [1] = (rh & RH_B_DR) >> 8;
426 desc->bitmap [2] = 0xff; 426 desc->bitmap [2] = 0xff;
427 } else 427 } else
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index 17964c39d06a..251533363028 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -14,8 +14,6 @@
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#include <asm/usb.h>
18
19/* configure so an HC device and id are always provided */ 17/* configure so an HC device and id are always provided */
20/* always called with process context; sleeping is OK */ 18/* always called with process context; sleeping is OK */
21 19
@@ -23,9 +21,7 @@
23 * usb_hcd_ppc_soc_probe - initialize On-Chip HCDs 21 * usb_hcd_ppc_soc_probe - initialize On-Chip HCDs
24 * Context: !in_interrupt() 22 * Context: !in_interrupt()
25 * 23 *
26 * Allocates basic resources for this USB host controller, and 24 * Allocates basic resources for this USB host controller.
27 * then invokes the start() method for the HCD associated with it
28 * through the hotplug entry's driver_data.
29 * 25 *
30 * Store this function in the HCD's struct pci_driver as probe(). 26 * Store this function in the HCD's struct pci_driver as probe().
31 */ 27 */
@@ -37,7 +33,6 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
37 struct ohci_hcd *ohci; 33 struct ohci_hcd *ohci;
38 struct resource *res; 34 struct resource *res;
39 int irq; 35 int irq;
40 struct usb_hcd_platform_data *pd = pdev->dev.platform_data;
41 36
42 pr_debug("initializing PPC-SOC USB Controller\n"); 37 pr_debug("initializing PPC-SOC USB Controller\n");
43 38
@@ -73,9 +68,6 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
73 goto err2; 68 goto err2;
74 } 69 }
75 70
76 if (pd->start && (retval = pd->start(pdev)))
77 goto err3;
78
79 ohci = hcd_to_ohci(hcd); 71 ohci = hcd_to_ohci(hcd);
80 ohci->flags |= OHCI_BIG_ENDIAN; 72 ohci->flags |= OHCI_BIG_ENDIAN;
81 ohci_hcd_init(ohci); 73 ohci_hcd_init(ohci);
@@ -85,9 +77,7 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
85 return retval; 77 return retval;
86 78
87 pr_debug("Removing PPC-SOC USB Controller\n"); 79 pr_debug("Removing PPC-SOC USB Controller\n");
88 if (pd && pd->stop) 80
89 pd->stop(pdev);
90 err3:
91 iounmap(hcd->regs); 81 iounmap(hcd->regs);
92 err2: 82 err2:
93 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 83 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
@@ -105,25 +95,21 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
105 * @pdev: USB Host Controller being removed 95 * @pdev: USB Host Controller being removed
106 * Context: !in_interrupt() 96 * Context: !in_interrupt()
107 * 97 *
108 * Reverses the effect of usb_hcd_ppc_soc_probe(), first invoking 98 * Reverses the effect of usb_hcd_ppc_soc_probe().
109 * the HCD's stop() method. It is always called from a thread 99 * It is always called from a thread
110 * context, normally "rmmod", "apmd", or something similar. 100 * context, normally "rmmod", "apmd", or something similar.
111 * 101 *
112 */ 102 */
113static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd, 103static void usb_hcd_ppc_soc_remove(struct usb_hcd *hcd,
114 struct platform_device *pdev) 104 struct platform_device *pdev)
115{ 105{
116 struct usb_hcd_platform_data *pd = pdev->dev.platform_data;
117
118 usb_remove_hcd(hcd); 106 usb_remove_hcd(hcd);
119 107
120 pr_debug("stopping PPC-SOC USB Controller\n"); 108 pr_debug("stopping PPC-SOC USB Controller\n");
121 if (pd && pd->stop)
122 pd->stop(pdev);
123 109
124 iounmap(hcd->regs); 110 iounmap(hcd->regs);
125 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 111 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
126 usb_hcd_put(hcd); 112 usb_put_hcd(hcd);
127} 113}
128 114
129static int __devinit 115static int __devinit
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index e5bc1789d18a..2fdb262d4726 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -75,33 +75,6 @@ static int pxa27x_ohci_select_pmm( int mode )
75 return 0; 75 return 0;
76} 76}
77 77
78/*
79 If you select PMM_PERPORT_MODE, you should set the port power
80 */
81static int pxa27x_ohci_set_port_power( int port )
82{
83 if ( (pxa27x_ohci_pmm_state==PMM_PERPORT_MODE)
84 && (port>0) && (port<PXA_UHC_MAX_PORTNUM) ) {
85 UHCRHPS(port) |= 0x100;
86 return 0;
87 }
88 return -1;
89}
90
91/*
92 If you select PMM_PERPORT_MODE, you should set the port power
93 */
94static int pxa27x_ohci_clear_port_power( int port )
95{
96 if ( (pxa27x_ohci_pmm_state==PMM_PERPORT_MODE)
97 && (port>0) && (port<PXA_UHC_MAX_PORTNUM) ) {
98 UHCRHPS(port) |= 0x200;
99 return 0;
100 }
101
102 return -1;
103}
104
105extern int usb_disabled(void); 78extern int usb_disabled(void);
106 79
107/*-------------------------------------------------------------------------*/ 80/*-------------------------------------------------------------------------*/
@@ -130,11 +103,17 @@ static void pxa27x_start_hc(struct platform_device *dev)
130 Polarity Low to active low. Supply power to USB ports. */ 103 Polarity Low to active low. Supply power to USB ports. */
131 UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) & 104 UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &
132 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE); 105 ~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);
106
107 pxa27x_ohci_pmm_state = PMM_PERPORT_MODE;
133 } 108 }
134 109
135 UHCHR &= ~UHCHR_SSE; 110 UHCHR &= ~UHCHR_SSE;
136 111
137 UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE); 112 UHCHIE = (UHCHIE_UPRIE | UHCHIE_RWIE);
113
114 /* Clear any OTG Pin Hold */
115 if (PSSR & PSSR_OTGPH)
116 PSSR |= PSSR_OTGPH;
138} 117}
139 118
140static void pxa27x_stop_hc(struct platform_device *dev) 119static void pxa27x_stop_hc(struct platform_device *dev)
@@ -198,17 +177,7 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver,
198 pxa27x_start_hc(dev); 177 pxa27x_start_hc(dev);
199 178
200 /* Select Power Management Mode */ 179 /* Select Power Management Mode */
201 pxa27x_ohci_select_pmm( PMM_PERPORT_MODE ); 180 pxa27x_ohci_select_pmm(pxa27x_ohci_pmm_state);
202
203 /* If choosing PMM_PERPORT_MODE, we should set the port power before we use it. */
204 if (pxa27x_ohci_set_port_power(1) < 0)
205 printk(KERN_ERR "Setting port 1 power failed.\n");
206
207 if (pxa27x_ohci_clear_port_power(2) < 0)
208 printk(KERN_ERR "Setting port 2 power failed.\n");
209
210 if (pxa27x_ohci_clear_port_power(3) < 0)
211 printk(KERN_ERR "Setting port 3 power failed.\n");
212 181
213 ohci_hcd_init(hcd_to_ohci(hcd)); 182 ohci_hcd_init(hcd_to_ohci(hcd));
214 183
@@ -258,6 +227,9 @@ ohci_pxa27x_start (struct usb_hcd *hcd)
258 227
259 ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci); 228 ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
260 229
230 /* The value of NDP in roothub_a is incorrect on this hardware */
231 ohci->num_ports = 3;
232
261 if ((ret = ohci_init(ohci)) < 0) 233 if ((ret = ohci_init(ohci)) < 0)
262 return ret; 234 return ret;
263 235
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index e9401662503c..3d9bcf78a9a4 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -129,7 +129,7 @@ static void s3c2410_usb_set_power(struct s3c2410_hcd_info *info,
129 129
130 if (info->power_control != NULL) { 130 if (info->power_control != NULL) {
131 info->port[port-1].power = to; 131 info->port[port-1].power = to;
132 (info->power_control)(port, to); 132 (info->power_control)(port-1, to);
133 } 133 }
134} 134}
135 135
@@ -339,8 +339,8 @@ int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
339 struct usb_hcd *hcd = NULL; 339 struct usb_hcd *hcd = NULL;
340 int retval; 340 int retval;
341 341
342 s3c2410_usb_set_power(dev->dev.platform_data, 0, 1);
343 s3c2410_usb_set_power(dev->dev.platform_data, 1, 1); 342 s3c2410_usb_set_power(dev->dev.platform_data, 1, 1);
343 s3c2410_usb_set_power(dev->dev.platform_data, 2, 1);
344 344
345 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx"); 345 hcd = usb_create_hcd(driver, &dev->dev, "s3c24xx");
346 if (hcd == NULL) 346 if (hcd == NULL)
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 71cdd2262860..8a9b9d9209e9 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -383,6 +383,7 @@ struct ohci_hcd {
383 /* 383 /*
384 * driver state 384 * driver state
385 */ 385 */
386 int num_ports;
386 int load [NUM_INTS]; 387 int load [NUM_INTS];
387 u32 hc_control; /* copy of hc control reg */ 388 u32 hc_control; /* copy of hc control reg */
388 unsigned long next_statechange; /* suspend/resume */ 389 unsigned long next_statechange; /* suspend/resume */
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 0d5d2545bf07..0c024898cbea 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -97,14 +97,9 @@ static void uhci_get_current_frame_number(struct uhci_hcd *uhci);
97/* to make sure it doesn't hog all of the bandwidth */ 97/* to make sure it doesn't hog all of the bandwidth */
98#define DEPTH_INTERVAL 5 98#define DEPTH_INTERVAL 5
99 99
100static inline void restart_timer(struct uhci_hcd *uhci)
101{
102 mod_timer(&uhci->stall_timer, jiffies + msecs_to_jiffies(100));
103}
104
105#include "uhci-hub.c"
106#include "uhci-debug.c" 100#include "uhci-debug.c"
107#include "uhci-q.c" 101#include "uhci-q.c"
102#include "uhci-hub.c"
108 103
109/* 104/*
110 * Make sure the controller is completely inactive, unable to 105 * Make sure the controller is completely inactive, unable to
@@ -160,7 +155,6 @@ static void hc_died(struct uhci_hcd *uhci)
160{ 155{
161 reset_hc(uhci); 156 reset_hc(uhci);
162 uhci->hc_inaccessible = 1; 157 uhci->hc_inaccessible = 1;
163 del_timer(&uhci->stall_timer);
164} 158}
165 159
166/* 160/*
@@ -287,8 +281,11 @@ __acquires(uhci->lock)
287 /* Enable resume-detect interrupts if they work. 281 /* Enable resume-detect interrupts if they work.
288 * Then enter Global Suspend mode, still configured. 282 * Then enter Global Suspend mode, still configured.
289 */ 283 */
290 int_enable = (resume_detect_interrupts_are_broken(uhci) ? 284 uhci->working_RD = 1;
291 0 : USBINTR_RESUME); 285 int_enable = USBINTR_RESUME;
286 if (resume_detect_interrupts_are_broken(uhci)) {
287 uhci->working_RD = int_enable = 0;
288 }
292 outw(int_enable, uhci->io_addr + USBINTR); 289 outw(int_enable, uhci->io_addr + USBINTR);
293 outw(USBCMD_EGSM | USBCMD_CF, uhci->io_addr + USBCMD); 290 outw(USBCMD_EGSM | USBCMD_CF, uhci->io_addr + USBCMD);
294 mb(); 291 mb();
@@ -315,7 +312,6 @@ __acquires(uhci->lock)
315 312
316 uhci->rh_state = new_state; 313 uhci->rh_state = new_state;
317 uhci->is_stopped = UHCI_IS_STOPPED; 314 uhci->is_stopped = UHCI_IS_STOPPED;
318 del_timer(&uhci->stall_timer);
319 uhci_to_hcd(uhci)->poll_rh = !int_enable; 315 uhci_to_hcd(uhci)->poll_rh = !int_enable;
320 316
321 uhci_scan_schedule(uhci, NULL); 317 uhci_scan_schedule(uhci, NULL);
@@ -335,7 +331,6 @@ static void start_rh(struct uhci_hcd *uhci)
335 mb(); 331 mb();
336 uhci->rh_state = UHCI_RH_RUNNING; 332 uhci->rh_state = UHCI_RH_RUNNING;
337 uhci_to_hcd(uhci)->poll_rh = 1; 333 uhci_to_hcd(uhci)->poll_rh = 1;
338 restart_timer(uhci);
339} 334}
340 335
341static void wakeup_rh(struct uhci_hcd *uhci) 336static void wakeup_rh(struct uhci_hcd *uhci)
@@ -374,20 +369,6 @@ __acquires(uhci->lock)
374 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies); 369 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies);
375} 370}
376 371
377static void stall_callback(unsigned long _uhci)
378{
379 struct uhci_hcd *uhci = (struct uhci_hcd *) _uhci;
380 unsigned long flags;
381
382 spin_lock_irqsave(&uhci->lock, flags);
383 uhci_scan_schedule(uhci, NULL);
384 check_fsbr(uhci);
385
386 if (!uhci->is_stopped)
387 restart_timer(uhci);
388 spin_unlock_irqrestore(&uhci->lock, flags);
389}
390
391static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs) 372static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs)
392{ 373{
393 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 374 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
@@ -418,8 +399,10 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs)
418 "host controller halted, " 399 "host controller halted, "
419 "very bad!\n"); 400 "very bad!\n");
420 hc_died(uhci); 401 hc_died(uhci);
421 spin_unlock_irqrestore(&uhci->lock, flags); 402
422 return IRQ_HANDLED; 403 /* Force a callback in case there are
404 * pending unlinks */
405 mod_timer(&hcd->rh_timer, jiffies);
423 } 406 }
424 spin_unlock_irqrestore(&uhci->lock, flags); 407 spin_unlock_irqrestore(&uhci->lock, flags);
425 } 408 }
@@ -427,10 +410,11 @@ static irqreturn_t uhci_irq(struct usb_hcd *hcd, struct pt_regs *regs)
427 410
428 if (status & USBSTS_RD) 411 if (status & USBSTS_RD)
429 usb_hcd_poll_rh_status(hcd); 412 usb_hcd_poll_rh_status(hcd);
430 413 else {
431 spin_lock_irqsave(&uhci->lock, flags); 414 spin_lock_irqsave(&uhci->lock, flags);
432 uhci_scan_schedule(uhci, regs); 415 uhci_scan_schedule(uhci, regs);
433 spin_unlock_irqrestore(&uhci->lock, flags); 416 spin_unlock_irqrestore(&uhci->lock, flags);
417 }
434 418
435 return IRQ_HANDLED; 419 return IRQ_HANDLED;
436} 420}
@@ -595,10 +579,6 @@ static int uhci_start(struct usb_hcd *hcd)
595 579
596 init_waitqueue_head(&uhci->waitqh); 580 init_waitqueue_head(&uhci->waitqh);
597 581
598 init_timer(&uhci->stall_timer);
599 uhci->stall_timer.function = stall_callback;
600 uhci->stall_timer.data = (unsigned long) uhci;
601
602 uhci->fl = dma_alloc_coherent(uhci_dev(uhci), sizeof(*uhci->fl), 582 uhci->fl = dma_alloc_coherent(uhci_dev(uhci), sizeof(*uhci->fl),
603 &dma_handle, 0); 583 &dma_handle, 0);
604 if (!uhci->fl) { 584 if (!uhci->fl) {
@@ -745,11 +725,11 @@ static void uhci_stop(struct usb_hcd *hcd)
745 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 725 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
746 726
747 spin_lock_irq(&uhci->lock); 727 spin_lock_irq(&uhci->lock);
748 reset_hc(uhci); 728 if (!uhci->hc_inaccessible)
729 reset_hc(uhci);
749 uhci_scan_schedule(uhci, NULL); 730 uhci_scan_schedule(uhci, NULL);
750 spin_unlock_irq(&uhci->lock); 731 spin_unlock_irq(&uhci->lock);
751 732
752 del_timer_sync(&uhci->stall_timer);
753 release_uhci(uhci); 733 release_uhci(uhci);
754} 734}
755 735
@@ -811,13 +791,12 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message)
811 */ 791 */
812 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0); 792 pci_write_config_word(to_pci_dev(uhci_dev(uhci)), USBLEGSUP, 0);
813 uhci->hc_inaccessible = 1; 793 uhci->hc_inaccessible = 1;
794 hcd->poll_rh = 0;
814 795
815 /* FIXME: Enable non-PME# remote wakeup? */ 796 /* FIXME: Enable non-PME# remote wakeup? */
816 797
817done: 798done:
818 spin_unlock_irq(&uhci->lock); 799 spin_unlock_irq(&uhci->lock);
819 if (rc == 0)
820 del_timer_sync(&hcd->rh_timer);
821 return rc; 800 return rc;
822} 801}
823 802
@@ -850,8 +829,11 @@ static int uhci_resume(struct usb_hcd *hcd)
850 829
851 spin_unlock_irq(&uhci->lock); 830 spin_unlock_irq(&uhci->lock);
852 831
853 if (hcd->poll_rh) 832 if (!uhci->working_RD) {
833 /* Suspended root hub needs to be polled */
834 hcd->poll_rh = 1;
854 usb_hcd_poll_rh_status(hcd); 835 usb_hcd_poll_rh_status(hcd);
836 }
855 return 0; 837 return 0;
856} 838}
857#endif 839#endif
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index bf9c5f9b508b..282f40b75881 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -345,9 +345,6 @@ enum uhci_rh_state {
345 345
346/* 346/*
347 * This describes the full uhci information. 347 * This describes the full uhci information.
348 *
349 * Note how the "proper" USB information is just
350 * a subset of what the full implementation needs.
351 */ 348 */
352struct uhci_hcd { 349struct uhci_hcd {
353 350
@@ -360,8 +357,6 @@ struct uhci_hcd {
360 struct dma_pool *qh_pool; 357 struct dma_pool *qh_pool;
361 struct dma_pool *td_pool; 358 struct dma_pool *td_pool;
362 359
363 struct usb_bus *bus;
364
365 struct uhci_td *term_td; /* Terminating TD, see UHCI bug */ 360 struct uhci_td *term_td; /* Terminating TD, see UHCI bug */
366 struct uhci_qh *skelqh[UHCI_NUM_SKELQH]; /* Skeleton QH's */ 361 struct uhci_qh *skelqh[UHCI_NUM_SKELQH]; /* Skeleton QH's */
367 362
@@ -380,6 +375,8 @@ struct uhci_hcd {
380 unsigned int scan_in_progress:1; /* Schedule scan is running */ 375 unsigned int scan_in_progress:1; /* Schedule scan is running */
381 unsigned int need_rescan:1; /* Redo the schedule scan */ 376 unsigned int need_rescan:1; /* Redo the schedule scan */
382 unsigned int hc_inaccessible:1; /* HC is suspended or dead */ 377 unsigned int hc_inaccessible:1; /* HC is suspended or dead */
378 unsigned int working_RD:1; /* Suspended root hub doesn't
379 need to be polled */
383 380
384 /* Support for port suspend/resume/reset */ 381 /* Support for port suspend/resume/reset */
385 unsigned long port_c_suspend; /* Bit-arrays of ports */ 382 unsigned long port_c_suspend; /* Bit-arrays of ports */
@@ -405,9 +402,7 @@ struct uhci_hcd {
405 /* List of URB's awaiting completion callback */ 402 /* List of URB's awaiting completion callback */
406 struct list_head complete_list; /* P: uhci->lock */ 403 struct list_head complete_list; /* P: uhci->lock */
407 404
408 int rh_numports; 405 int rh_numports; /* Number of root-hub ports */
409
410 struct timer_list stall_timer;
411 406
412 wait_queue_head_t waitqh; /* endpoint_disable waiters */ 407 wait_queue_head_t waitqh; /* endpoint_disable waiters */
413}; 408};
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 4eace2b19ddb..a71e48a66805 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -145,15 +145,16 @@ static int uhci_hub_status_data(struct usb_hcd *hcd, char *buf)
145{ 145{
146 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 146 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
147 unsigned long flags; 147 unsigned long flags;
148 int status; 148 int status = 0;
149 149
150 spin_lock_irqsave(&uhci->lock, flags); 150 spin_lock_irqsave(&uhci->lock, flags);
151 if (uhci->hc_inaccessible) {
152 status = 0;
153 goto done;
154 }
155 151
152 uhci_scan_schedule(uhci, NULL);
153 if (uhci->hc_inaccessible)
154 goto done;
155 check_fsbr(uhci);
156 uhci_check_ports(uhci); 156 uhci_check_ports(uhci);
157
157 status = get_hub_status_data(uhci, buf); 158 status = get_hub_status_data(uhci, buf);
158 159
159 switch (uhci->rh_state) { 160 switch (uhci->rh_state) {
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index bbb36cd6ed61..ea0d168a8c67 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -33,7 +33,7 @@ static void uhci_free_pending_tds(struct uhci_hcd *uhci);
33static inline void uhci_set_next_interrupt(struct uhci_hcd *uhci) 33static inline void uhci_set_next_interrupt(struct uhci_hcd *uhci)
34{ 34{
35 if (uhci->is_stopped) 35 if (uhci->is_stopped)
36 mod_timer(&uhci->stall_timer, jiffies); 36 mod_timer(&uhci_to_hcd(uhci)->rh_timer, jiffies);
37 uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC); 37 uhci->term_td->status |= cpu_to_le32(TD_CTRL_IOC);
38} 38}
39 39
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 298e4a25e3d3..1e53934907c0 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -230,6 +230,20 @@ config USB_EGALAX
230 To compile this driver as a module, choose M here: the 230 To compile this driver as a module, choose M here: the
231 module will be called touchkitusb. 231 module will be called touchkitusb.
232 232
233config USB_YEALINK
234 tristate "Yealink usb-p1k voip phone"
235 depends on USB && INPUT && EXPERIMENTAL
236 ---help---
237 Say Y here if you want to enable keyboard and LCD functions of the
238 Yealink usb-p1k usb phones. The audio part is enabled by the generic
239 usb sound driver, so you might want to enable that as well.
240
241 For information about how to use these additional functions, see
242 <file:Documentation/input/yealink.txt>.
243
244 To compile this driver as a module, choose M here: the module will be
245 called yealink.
246
233config USB_XPAD 247config USB_XPAD
234 tristate "X-Box gamepad support" 248 tristate "X-Box gamepad support"
235 depends on USB && INPUT 249 depends on USB && INPUT
@@ -272,3 +286,23 @@ config USB_KEYSPAN_REMOTE
272 286
273 To compile this driver as a module, choose M here: the module will 287 To compile this driver as a module, choose M here: the module will
274 be called keyspan_remote. 288 be called keyspan_remote.
289
290config USB_APPLETOUCH
291 tristate "Apple USB Touchpad support"
292 depends on USB && INPUT
293 ---help---
294 Say Y here if you want to use an Apple USB Touchpad.
295
296 These are the touchpads that can be found on post-February 2005
297 Apple Powerbooks (prior models have a Synaptics touchpad connected
298 to the ADB bus).
299
300 This driver provides a basic mouse driver but can be interfaced
301 with the synaptics X11 driver to provide acceleration and
302 scrolling in X11.
303
304 For further information, see
305 <file:Documentation/input/appletouch.txt>.
306
307 To compile this driver as a module, choose M here: the
308 module will be called appletouch.
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
index f1547be632d4..5e03b93f29f6 100644
--- a/drivers/usb/input/Makefile
+++ b/drivers/usb/input/Makefile
@@ -39,4 +39,6 @@ obj-$(CONFIG_USB_EGALAX) += touchkitusb.o
39obj-$(CONFIG_USB_POWERMATE) += powermate.o 39obj-$(CONFIG_USB_POWERMATE) += powermate.o
40obj-$(CONFIG_USB_WACOM) += wacom.o 40obj-$(CONFIG_USB_WACOM) += wacom.o
41obj-$(CONFIG_USB_ACECAD) += acecad.o 41obj-$(CONFIG_USB_ACECAD) += acecad.o
42obj-$(CONFIG_USB_YEALINK) += yealink.o
42obj-$(CONFIG_USB_XPAD) += xpad.o 43obj-$(CONFIG_USB_XPAD) += xpad.o
44obj-$(CONFIG_USB_APPLETOUCH) += appletouch.o
diff --git a/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c
new file mode 100644
index 000000000000..e03c1c567a14
--- /dev/null
+++ b/drivers/usb/input/appletouch.c
@@ -0,0 +1,469 @@
1/*
2 * Apple USB Touchpad (for post-February 2005 PowerBooks) driver
3 *
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2005 Johannes Berg (johannes@sipsolutions.net)
6 * Copyright (C) 2005 Stelian Pop (stelian@popies.net)
7 * Copyright (C) 2005 Frank Arnold (frank@scirocco-5v-turbo.de)
8 * Copyright (C) 2005 Peter Osterlund (petero2@telia.com)
9 *
10 * Thanks to Alex Harper <basilisk@foobox.net> for his inputs.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 */
27
28#include <linux/config.h>
29#include <linux/kernel.h>
30#include <linux/errno.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/module.h>
34#include <linux/usb.h>
35#include <linux/input.h>
36#include <linux/usb_input.h>
37
38/* Apple has powerbooks which have the keyboard with different Product IDs */
39#define APPLE_VENDOR_ID 0x05AC
40
41#define ATP_DEVICE(prod) \
42 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
43 USB_DEVICE_ID_MATCH_INT_CLASS | \
44 USB_DEVICE_ID_MATCH_INT_PROTOCOL, \
45 .idVendor = APPLE_VENDOR_ID, \
46 .idProduct = (prod), \
47 .bInterfaceClass = 0x03, \
48 .bInterfaceProtocol = 0x02
49
50/* table of devices that work with this driver */
51static struct usb_device_id atp_table [] = {
52 { ATP_DEVICE(0x020E) },
53 { ATP_DEVICE(0x020F) },
54 { ATP_DEVICE(0x030A) },
55 { ATP_DEVICE(0x030B) },
56 { } /* Terminating entry */
57};
58MODULE_DEVICE_TABLE (usb, atp_table);
59
60/* size of a USB urb transfer */
61#define ATP_DATASIZE 81
62
63/*
64 * number of sensors. Note that only 16 instead of 26 X (horizontal)
65 * sensors exist on 12" and 15" PowerBooks. All models have 16 Y
66 * (vertical) sensors.
67 */
68#define ATP_XSENSORS 26
69#define ATP_YSENSORS 16
70
71/* amount of fuzz this touchpad generates */
72#define ATP_FUZZ 16
73
74/* maximum pressure this driver will report */
75#define ATP_PRESSURE 300
76/*
77 * multiplication factor for the X and Y coordinates.
78 * We try to keep the touchpad aspect ratio while still doing only simple
79 * arithmetics.
80 * The factors below give coordinates like:
81 * 0 <= x < 960 on 12" and 15" Powerbooks
82 * 0 <= x < 1600 on 17" Powerbooks
83 * 0 <= y < 646
84 */
85#define ATP_XFACT 64
86#define ATP_YFACT 43
87
88/*
89 * Threshold for the touchpad sensors. Any change less than ATP_THRESHOLD is
90 * ignored.
91 */
92#define ATP_THRESHOLD 5
93
94/* Structure to hold all of our device specific stuff */
95struct atp {
96 struct usb_device * udev; /* usb device */
97 struct urb * urb; /* usb request block */
98 signed char * data; /* transferred data */
99 int open; /* non-zero if opened */
100 struct input_dev input; /* input dev */
101 int valid; /* are the sensors valid ? */
102 int x_old; /* last reported x/y, */
103 int y_old; /* used for smoothing */
104 /* current value of the sensors */
105 signed char xy_cur[ATP_XSENSORS + ATP_YSENSORS];
106 /* last value of the sensors */
107 signed char xy_old[ATP_XSENSORS + ATP_YSENSORS];
108 /* accumulated sensors */
109 int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
110};
111
112#define dbg_dump(msg, tab) \
113 if (debug > 1) { \
114 int i; \
115 printk("appletouch: %s %lld", msg, (long long)jiffies); \
116 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) \
117 printk(" %02x", tab[i]); \
118 printk("\n"); \
119 }
120
121#define dprintk(format, a...) \
122 do { \
123 if (debug) printk(format, ##a); \
124 } while (0)
125
126MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold");
127MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver");
128MODULE_LICENSE("GPL");
129
130static int debug = 1;
131module_param(debug, int, 0644);
132MODULE_PARM_DESC(debug, "Activate debugging output");
133
134static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
135 int *z, int *fingers)
136{
137 int i;
138 /* values to calculate mean */
139 int pcum = 0, psum = 0;
140
141 *fingers = 0;
142
143 for (i = 0; i < nb_sensors; i++) {
144 if (xy_sensors[i] < ATP_THRESHOLD)
145 continue;
146 if ((i - 1 < 0) || (xy_sensors[i - 1] < ATP_THRESHOLD))
147 (*fingers)++;
148 pcum += xy_sensors[i] * i;
149 psum += xy_sensors[i];
150 }
151
152 if (psum > 0) {
153 *z = psum;
154 return pcum * fact / psum;
155 }
156
157 return 0;
158}
159
160static inline void atp_report_fingers(struct input_dev *input, int fingers)
161{
162 input_report_key(input, BTN_TOOL_FINGER, fingers == 1);
163 input_report_key(input, BTN_TOOL_DOUBLETAP, fingers == 2);
164 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2);
165}
166
167static void atp_complete(struct urb* urb, struct pt_regs* regs)
168{
169 int x, y, x_z, y_z, x_f, y_f;
170 int retval, i;
171 struct atp *dev = urb->context;
172
173 switch (urb->status) {
174 case 0:
175 /* success */
176 break;
177 case -ECONNRESET:
178 case -ENOENT:
179 case -ESHUTDOWN:
180 /* This urb is terminated, clean up */
181 dbg("%s - urb shutting down with status: %d",
182 __FUNCTION__, urb->status);
183 return;
184 default:
185 dbg("%s - nonzero urb status received: %d",
186 __FUNCTION__, urb->status);
187 goto exit;
188 }
189
190 /* drop incomplete datasets */
191 if (dev->urb->actual_length != ATP_DATASIZE) {
192 dprintk("appletouch: incomplete data package.\n");
193 goto exit;
194 }
195
196 /* reorder the sensors values */
197 for (i = 0; i < 8; i++) {
198 /* X values */
199 dev->xy_cur[i ] = dev->data[5 * i + 2];
200 dev->xy_cur[i + 8] = dev->data[5 * i + 4];
201 dev->xy_cur[i + 16] = dev->data[5 * i + 42];
202 if (i < 2)
203 dev->xy_cur[i + 24] = dev->data[5 * i + 44];
204
205 /* Y values */
206 dev->xy_cur[i + 26] = dev->data[5 * i + 1];
207 dev->xy_cur[i + 34] = dev->data[5 * i + 3];
208 }
209
210 dbg_dump("sample", dev->xy_cur);
211
212 if (!dev->valid) {
213 /* first sample */
214 dev->valid = 1;
215 dev->x_old = dev->y_old = -1;
216 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
217
218 /* 17" Powerbooks have 10 extra X sensors */
219 for (i = 16; i < ATP_XSENSORS; i++)
220 if (dev->xy_cur[i]) {
221 printk("appletouch: 17\" model detected.\n");
222 input_set_abs_params(&dev->input, ABS_X, 0,
223 (ATP_XSENSORS - 1) *
224 ATP_XFACT - 1,
225 ATP_FUZZ, 0);
226 break;
227 }
228
229 goto exit;
230 }
231
232 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
233 /* accumulate the change */
234 signed char change = dev->xy_old[i] - dev->xy_cur[i];
235 dev->xy_acc[i] -= change;
236
237 /* prevent down drifting */
238 if (dev->xy_acc[i] < 0)
239 dev->xy_acc[i] = 0;
240 }
241
242 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
243
244 dbg_dump("accumulator", dev->xy_acc);
245
246 x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS,
247 ATP_XFACT, &x_z, &x_f);
248 y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS,
249 ATP_YFACT, &y_z, &y_f);
250
251 if (x && y) {
252 if (dev->x_old != -1) {
253 x = (dev->x_old * 3 + x) >> 2;
254 y = (dev->y_old * 3 + y) >> 2;
255 dev->x_old = x;
256 dev->y_old = y;
257
258 if (debug > 1)
259 printk("appletouch: X: %3d Y: %3d "
260 "Xz: %3d Yz: %3d\n",
261 x, y, x_z, y_z);
262
263 input_report_key(&dev->input, BTN_TOUCH, 1);
264 input_report_abs(&dev->input, ABS_X, x);
265 input_report_abs(&dev->input, ABS_Y, y);
266 input_report_abs(&dev->input, ABS_PRESSURE,
267 min(ATP_PRESSURE, x_z + y_z));
268 atp_report_fingers(&dev->input, max(x_f, y_f));
269 }
270 dev->x_old = x;
271 dev->y_old = y;
272 }
273 else if (!x && !y) {
274
275 dev->x_old = dev->y_old = -1;
276 input_report_key(&dev->input, BTN_TOUCH, 0);
277 input_report_abs(&dev->input, ABS_PRESSURE, 0);
278 atp_report_fingers(&dev->input, 0);
279
280 /* reset the accumulator on release */
281 memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
282 }
283
284 input_report_key(&dev->input, BTN_LEFT, !!dev->data[80]);
285
286 input_sync(&dev->input);
287
288exit:
289 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
290 if (retval) {
291 err("%s - usb_submit_urb failed with result %d",
292 __FUNCTION__, retval);
293 }
294}
295
296static int atp_open(struct input_dev *input)
297{
298 struct atp *dev = input->private;
299
300 if (usb_submit_urb(dev->urb, GFP_ATOMIC))
301 return -EIO;
302
303 dev->open = 1;
304 return 0;
305}
306
307static void atp_close(struct input_dev *input)
308{
309 struct atp *dev = input->private;
310
311 usb_kill_urb(dev->urb);
312 dev->open = 0;
313}
314
315static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id)
316{
317 struct atp *dev = NULL;
318 struct usb_host_interface *iface_desc;
319 struct usb_endpoint_descriptor *endpoint;
320 int int_in_endpointAddr = 0;
321 int i, retval = -ENOMEM;
322
323 /* allocate memory for our device state and initialize it */
324 dev = kmalloc(sizeof(struct atp), GFP_KERNEL);
325 if (dev == NULL) {
326 err("Out of memory");
327 goto err_kmalloc;
328 }
329 memset(dev, 0, sizeof(struct atp));
330
331 dev->udev = interface_to_usbdev(iface);
332
333 /* set up the endpoint information */
334 /* use only the first interrupt-in endpoint */
335 iface_desc = iface->cur_altsetting;
336 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
337 endpoint = &iface_desc->endpoint[i].desc;
338 if (!int_in_endpointAddr &&
339 (endpoint->bEndpointAddress & USB_DIR_IN) &&
340 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
341 == USB_ENDPOINT_XFER_INT)) {
342 /* we found an interrupt in endpoint */
343 int_in_endpointAddr = endpoint->bEndpointAddress;
344 break;
345 }
346 }
347 if (!int_in_endpointAddr) {
348 retval = -EIO;
349 err("Could not find int-in endpoint");
350 goto err_endpoint;
351 }
352
353 /* save our data pointer in this interface device */
354 usb_set_intfdata(iface, dev);
355
356 dev->urb = usb_alloc_urb(0, GFP_KERNEL);
357 if (!dev->urb) {
358 retval = -ENOMEM;
359 goto err_usballoc;
360 }
361 dev->data = usb_buffer_alloc(dev->udev, ATP_DATASIZE, GFP_KERNEL,
362 &dev->urb->transfer_dma);
363 if (!dev->data) {
364 retval = -ENOMEM;
365 goto err_usbbufalloc;
366 }
367 usb_fill_int_urb(dev->urb, dev->udev,
368 usb_rcvintpipe(dev->udev, int_in_endpointAddr),
369 dev->data, ATP_DATASIZE, atp_complete, dev, 1);
370
371 init_input_dev(&dev->input);
372 dev->input.name = "appletouch";
373 dev->input.dev = &iface->dev;
374 dev->input.private = dev;
375 dev->input.open = atp_open;
376 dev->input.close = atp_close;
377
378 usb_to_input_id(dev->udev, &dev->input.id);
379
380 set_bit(EV_ABS, dev->input.evbit);
381
382 /*
383 * 12" and 15" Powerbooks only have 16 x sensors,
384 * 17" models are detected later.
385 */
386 input_set_abs_params(&dev->input, ABS_X, 0,
387 (16 - 1) * ATP_XFACT - 1, ATP_FUZZ, 0);
388 input_set_abs_params(&dev->input, ABS_Y, 0,
389 (ATP_YSENSORS - 1) * ATP_YFACT - 1, ATP_FUZZ, 0);
390 input_set_abs_params(&dev->input, ABS_PRESSURE, 0, ATP_PRESSURE, 0, 0);
391
392 set_bit(EV_KEY, dev->input.evbit);
393 set_bit(BTN_TOUCH, dev->input.keybit);
394 set_bit(BTN_TOOL_FINGER, dev->input.keybit);
395 set_bit(BTN_TOOL_DOUBLETAP, dev->input.keybit);
396 set_bit(BTN_TOOL_TRIPLETAP, dev->input.keybit);
397 set_bit(BTN_LEFT, dev->input.keybit);
398
399 input_register_device(&dev->input);
400
401 printk(KERN_INFO "input: appletouch connected\n");
402
403 return 0;
404
405err_usbbufalloc:
406 usb_free_urb(dev->urb);
407err_usballoc:
408 usb_set_intfdata(iface, NULL);
409err_endpoint:
410 kfree(dev);
411err_kmalloc:
412 return retval;
413}
414
415static void atp_disconnect(struct usb_interface *iface)
416{
417 struct atp *dev = usb_get_intfdata(iface);
418
419 usb_set_intfdata(iface, NULL);
420 if (dev) {
421 usb_kill_urb(dev->urb);
422 input_unregister_device(&dev->input);
423 usb_free_urb(dev->urb);
424 usb_buffer_free(dev->udev, ATP_DATASIZE,
425 dev->data, dev->urb->transfer_dma);
426 kfree(dev);
427 }
428 printk(KERN_INFO "input: appletouch disconnected\n");
429}
430
431static int atp_suspend(struct usb_interface *iface, pm_message_t message)
432{
433 struct atp *dev = usb_get_intfdata(iface);
434 usb_kill_urb(dev->urb);
435 dev->valid = 0;
436 return 0;
437}
438
439static int atp_resume(struct usb_interface *iface)
440{
441 struct atp *dev = usb_get_intfdata(iface);
442 if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC))
443 return -EIO;
444
445 return 0;
446}
447
448static struct usb_driver atp_driver = {
449 .owner = THIS_MODULE,
450 .name = "appletouch",
451 .probe = atp_probe,
452 .disconnect = atp_disconnect,
453 .suspend = atp_suspend,
454 .resume = atp_resume,
455 .id_table = atp_table,
456};
457
458static int __init atp_init(void)
459{
460 return usb_register(&atp_driver);
461}
462
463static void __exit atp_exit(void)
464{
465 usb_deregister(&atp_driver);
466}
467
468module_init(atp_init);
469module_exit(atp_exit);
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index b2cb2b35892e..a99865c689c5 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -2,7 +2,8 @@
2 * USB HID support for Linux 2 * USB HID support for Linux
3 * 3 *
4 * Copyright (c) 1999 Andreas Gal 4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2001 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
6 */ 7 */
7 8
8/* 9/*
@@ -38,7 +39,7 @@
38 * Version Information 39 * Version Information
39 */ 40 */
40 41
41#define DRIVER_VERSION "v2.01" 42#define DRIVER_VERSION "v2.6"
42#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik" 43#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
43#define DRIVER_DESC "USB HID core driver" 44#define DRIVER_DESC "USB HID core driver"
44#define DRIVER_LICENSE "GPL" 45#define DRIVER_LICENSE "GPL"
@@ -1058,8 +1059,8 @@ static int hid_submit_ctrl(struct hid_device *hid)
1058 if (maxpacket > 0) { 1059 if (maxpacket > 0) {
1059 padlen = (len + maxpacket - 1) / maxpacket; 1060 padlen = (len + maxpacket - 1) / maxpacket;
1060 padlen *= maxpacket; 1061 padlen *= maxpacket;
1061 if (padlen > HID_BUFFER_SIZE) 1062 if (padlen > hid->bufsize)
1062 padlen = HID_BUFFER_SIZE; 1063 padlen = hid->bufsize;
1063 } else 1064 } else
1064 padlen = 0; 1065 padlen = 0;
1065 hid->urbctrl->transfer_buffer_length = padlen; 1066 hid->urbctrl->transfer_buffer_length = padlen;
@@ -1096,6 +1097,7 @@ static void hid_irq_out(struct urb *urb, struct pt_regs *regs)
1096 1097
1097 switch (urb->status) { 1098 switch (urb->status) {
1098 case 0: /* success */ 1099 case 0: /* success */
1100 break;
1099 case -ESHUTDOWN: /* unplug */ 1101 case -ESHUTDOWN: /* unplug */
1100 case -EILSEQ: /* unplug timeout on uhci */ 1102 case -EILSEQ: /* unplug timeout on uhci */
1101 unplug = 1; 1103 unplug = 1;
@@ -1143,6 +1145,7 @@ static void hid_ctrl(struct urb *urb, struct pt_regs *regs)
1143 case 0: /* success */ 1145 case 0: /* success */
1144 if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN) 1146 if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN)
1145 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs); 1147 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs);
1148 break;
1146 case -ESHUTDOWN: /* unplug */ 1149 case -ESHUTDOWN: /* unplug */
1147 case -EILSEQ: /* unplug timectrl on uhci */ 1150 case -EILSEQ: /* unplug timectrl on uhci */
1148 unplug = 1; 1151 unplug = 1;
@@ -1284,13 +1287,8 @@ void hid_init_reports(struct hid_device *hid)
1284 struct hid_report *report; 1287 struct hid_report *report;
1285 int err, ret; 1288 int err, ret;
1286 1289
1287 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) { 1290 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
1288 int size = ((report->size - 1) >> 3) + 1 + hid->report_enum[HID_INPUT_REPORT].numbered;
1289 if (size > HID_BUFFER_SIZE) size = HID_BUFFER_SIZE;
1290 if (size > hid->urbin->transfer_buffer_length)
1291 hid->urbin->transfer_buffer_length = size;
1292 hid_submit_report(hid, report, USB_DIR_IN); 1291 hid_submit_report(hid, report, USB_DIR_IN);
1293 }
1294 1292
1295 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) 1293 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
1296 hid_submit_report(hid, report, USB_DIR_IN); 1294 hid_submit_report(hid, report, USB_DIR_IN);
@@ -1372,12 +1370,14 @@ void hid_init_reports(struct hid_device *hid)
1372#define USB_VENDOR_ID_A4TECH 0x09da 1370#define USB_VENDOR_ID_A4TECH 0x09da
1373#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006 1371#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
1374 1372
1375#define USB_VENDOR_ID_AASHIMA 0x06D6 1373#define USB_VENDOR_ID_AASHIMA 0x06d6
1376#define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025 1374#define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025
1375#define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026
1377 1376
1378#define USB_VENDOR_ID_CYPRESS 0x04b4 1377#define USB_VENDOR_ID_CYPRESS 0x04b4
1379#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 1378#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001
1380#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 1379#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500
1380#define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417
1381 1381
1382#define USB_VENDOR_ID_BERKSHIRE 0x0c98 1382#define USB_VENDOR_ID_BERKSHIRE 0x0c98
1383#define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140 1383#define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140
@@ -1432,7 +1432,7 @@ void hid_init_reports(struct hid_device *hid)
1432#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004 1432#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
1433 1433
1434#define USB_VENDOR_ID_LD 0x0f11 1434#define USB_VENDOR_ID_LD 0x0f11
1435#define USB_DEVICE_ID_CASSY 0x1000 1435#define USB_DEVICE_ID_CASSY 0x1000
1436#define USB_DEVICE_ID_POCKETCASSY 0x1010 1436#define USB_DEVICE_ID_POCKETCASSY 0x1010
1437#define USB_DEVICE_ID_MOBILECASSY 0x1020 1437#define USB_DEVICE_ID_MOBILECASSY 0x1020
1438#define USB_DEVICE_ID_JWM 0x1080 1438#define USB_DEVICE_ID_JWM 0x1080
@@ -1444,6 +1444,8 @@ void hid_init_reports(struct hid_device *hid)
1444#define USB_DEVICE_ID_NETWORKANALYSER 0x2020 1444#define USB_DEVICE_ID_NETWORKANALYSER 0x2020
1445#define USB_DEVICE_ID_POWERCONTROL 0x2030 1445#define USB_DEVICE_ID_POWERCONTROL 0x2030
1446 1446
1447#define USB_VENDOR_ID_APPLE 0x05ac
1448#define USB_DEVICE_ID_APPLE_POWERMOUSE 0x0304
1447 1449
1448/* 1450/*
1449 * Alphabetically sorted blacklist by quirk type. 1451 * Alphabetically sorted blacklist by quirk type.
@@ -1468,6 +1470,7 @@ static struct hid_blacklist {
1468 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE }, 1470 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW48, HID_QUIRK_IGNORE },
1469 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE }, 1471 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW28, HID_QUIRK_IGNORE },
1470 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE }, 1472 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE },
1473 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE },
1471 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE }, 1474 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE },
1472 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE }, 1475 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE },
1473 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE }, 1476 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE },
@@ -1548,10 +1551,12 @@ static struct hid_blacklist {
1548 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_USBHUB_KB, HID_QUIRK_NOGET}, 1551 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_USBHUB_KB, HID_QUIRK_NOGET},
1549 { USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET }, 1552 { USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET },
1550 1553
1554 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_POWERMOUSE, HID_QUIRK_2WHEEL_POWERMOUSE },
1551 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 }, 1555 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
1552 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 }, 1556 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 },
1553 1557
1554 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD }, 1558 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD },
1559 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD },
1555 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, 1560 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD },
1556 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, 1561 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
1557 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 1562 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
@@ -1564,15 +1569,32 @@ static struct hid_blacklist {
1564 { 0, 0 } 1569 { 0, 0 }
1565}; 1570};
1566 1571
1572/*
1573 * Traverse the supplied list of reports and find the longest
1574 */
1575static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *max)
1576{
1577 struct hid_report *report;
1578 int size;
1579
1580 list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
1581 size = ((report->size - 1) >> 3) + 1;
1582 if (type == HID_INPUT_REPORT && hid->report_enum[type].numbered)
1583 size++;
1584 if (*max < size)
1585 *max = size;
1586 }
1587}
1588
1567static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) 1589static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
1568{ 1590{
1569 if (!(hid->inbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->inbuf_dma))) 1591 if (!(hid->inbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->inbuf_dma)))
1570 return -1; 1592 return -1;
1571 if (!(hid->outbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->outbuf_dma))) 1593 if (!(hid->outbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->outbuf_dma)))
1572 return -1; 1594 return -1;
1573 if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), SLAB_ATOMIC, &hid->cr_dma))) 1595 if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), SLAB_ATOMIC, &hid->cr_dma)))
1574 return -1; 1596 return -1;
1575 if (!(hid->ctrlbuf = usb_buffer_alloc(dev, HID_BUFFER_SIZE, SLAB_ATOMIC, &hid->ctrlbuf_dma))) 1597 if (!(hid->ctrlbuf = usb_buffer_alloc(dev, hid->bufsize, SLAB_ATOMIC, &hid->ctrlbuf_dma)))
1576 return -1; 1598 return -1;
1577 1599
1578 return 0; 1600 return 0;
@@ -1581,13 +1603,13 @@ static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
1581static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) 1603static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
1582{ 1604{
1583 if (hid->inbuf) 1605 if (hid->inbuf)
1584 usb_buffer_free(dev, HID_BUFFER_SIZE, hid->inbuf, hid->inbuf_dma); 1606 usb_buffer_free(dev, hid->bufsize, hid->inbuf, hid->inbuf_dma);
1585 if (hid->outbuf) 1607 if (hid->outbuf)
1586 usb_buffer_free(dev, HID_BUFFER_SIZE, hid->outbuf, hid->outbuf_dma); 1608 usb_buffer_free(dev, hid->bufsize, hid->outbuf, hid->outbuf_dma);
1587 if (hid->cr) 1609 if (hid->cr)
1588 usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma); 1610 usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma);
1589 if (hid->ctrlbuf) 1611 if (hid->ctrlbuf)
1590 usb_buffer_free(dev, HID_BUFFER_SIZE, hid->ctrlbuf, hid->ctrlbuf_dma); 1612 usb_buffer_free(dev, hid->bufsize, hid->ctrlbuf, hid->ctrlbuf_dma);
1591} 1613}
1592 1614
1593static struct hid_device *usb_hid_configure(struct usb_interface *intf) 1615static struct hid_device *usb_hid_configure(struct usb_interface *intf)
@@ -1598,7 +1620,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1598 struct hid_device *hid; 1620 struct hid_device *hid;
1599 unsigned quirks = 0, rsize = 0; 1621 unsigned quirks = 0, rsize = 0;
1600 char *buf, *rdesc; 1622 char *buf, *rdesc;
1601 int n; 1623 int n, insize = 0;
1602 1624
1603 for (n = 0; hid_blacklist[n].idVendor; n++) 1625 for (n = 0; hid_blacklist[n].idVendor; n++)
1604 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) && 1626 if ((hid_blacklist[n].idVendor == le16_to_cpu(dev->descriptor.idVendor)) &&
@@ -1652,6 +1674,19 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1652 kfree(rdesc); 1674 kfree(rdesc);
1653 hid->quirks = quirks; 1675 hid->quirks = quirks;
1654 1676
1677 hid->bufsize = HID_MIN_BUFFER_SIZE;
1678 hid_find_max_report(hid, HID_INPUT_REPORT, &hid->bufsize);
1679 hid_find_max_report(hid, HID_OUTPUT_REPORT, &hid->bufsize);
1680 hid_find_max_report(hid, HID_FEATURE_REPORT, &hid->bufsize);
1681
1682 if (hid->bufsize > HID_MAX_BUFFER_SIZE)
1683 hid->bufsize = HID_MAX_BUFFER_SIZE;
1684
1685 hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
1686
1687 if (insize > HID_MAX_BUFFER_SIZE)
1688 insize = HID_MAX_BUFFER_SIZE;
1689
1655 if (hid_alloc_buffers(dev, hid)) { 1690 if (hid_alloc_buffers(dev, hid)) {
1656 hid_free_buffers(dev, hid); 1691 hid_free_buffers(dev, hid);
1657 goto fail; 1692 goto fail;
@@ -1682,10 +1717,10 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1682 if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL))) 1717 if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
1683 goto fail; 1718 goto fail;
1684 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 1719 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
1685 usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, 0, 1720 usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, insize,
1686 hid_irq_in, hid, interval); 1721 hid_irq_in, hid, interval);
1687 hid->urbin->transfer_dma = hid->inbuf_dma; 1722 hid->urbin->transfer_dma = hid->inbuf_dma;
1688 hid->urbin->transfer_flags |=(URB_NO_TRANSFER_DMA_MAP | URB_ASYNC_UNLINK); 1723 hid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1689 } else { 1724 } else {
1690 if (hid->urbout) 1725 if (hid->urbout)
1691 continue; 1726 continue;
@@ -1695,7 +1730,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1695 usb_fill_int_urb(hid->urbout, dev, pipe, hid->outbuf, 0, 1730 usb_fill_int_urb(hid->urbout, dev, pipe, hid->outbuf, 0,
1696 hid_irq_out, hid, interval); 1731 hid_irq_out, hid, interval);
1697 hid->urbout->transfer_dma = hid->outbuf_dma; 1732 hid->urbout->transfer_dma = hid->outbuf_dma;
1698 hid->urbout->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_ASYNC_UNLINK); 1733 hid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1699 } 1734 }
1700 } 1735 }
1701 1736
@@ -1747,7 +1782,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1747 hid->ctrlbuf, 1, hid_ctrl, hid); 1782 hid->ctrlbuf, 1, hid_ctrl, hid);
1748 hid->urbctrl->setup_dma = hid->cr_dma; 1783 hid->urbctrl->setup_dma = hid->cr_dma;
1749 hid->urbctrl->transfer_dma = hid->ctrlbuf_dma; 1784 hid->urbctrl->transfer_dma = hid->ctrlbuf_dma;
1750 hid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP | URB_ASYNC_UNLINK); 1785 hid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
1751 1786
1752 return hid; 1787 return hid;
1753 1788
diff --git a/drivers/usb/input/hid-debug.h b/drivers/usb/input/hid-debug.h
index 52437e5e2e78..ceebab99eff2 100644
--- a/drivers/usb/input/hid-debug.h
+++ b/drivers/usb/input/hid-debug.h
@@ -85,6 +85,23 @@ static const struct hid_usage_entry hid_usage_table[] = {
85 {0, 0x91, "D-PadDown"}, 85 {0, 0x91, "D-PadDown"},
86 {0, 0x92, "D-PadRight"}, 86 {0, 0x92, "D-PadRight"},
87 {0, 0x93, "D-PadLeft"}, 87 {0, 0x93, "D-PadLeft"},
88 { 2, 0, "Simulation" },
89 {0, 0xb0, "Aileron"},
90 {0, 0xb1, "AileronTrim"},
91 {0, 0xb2, "Anti-Torque"},
92 {0, 0xb3, "Autopilot"},
93 {0, 0xb4, "Chaff"},
94 {0, 0xb5, "Collective"},
95 {0, 0xb6, "DiveBrake"},
96 {0, 0xb7, "ElectronicCountermeasures"},
97 {0, 0xb8, "Elevator"},
98 {0, 0xb9, "ElevatorTrim"},
99 {0, 0xba, "Rudder"},
100 {0, 0xbb, "Throttle"},
101 {0, 0xbc, "FlightCommunications"},
102 {0, 0xbd, "FlareRelease"},
103 {0, 0xbe, "LandingGear"},
104 {0, 0xbf, "ToeBrake"},
88 { 7, 0, "Keyboard" }, 105 { 7, 0, "Keyboard" },
89 { 8, 0, "LED" }, 106 { 8, 0, "LED" },
90 {0, 0x01, "NumLock"}, 107 {0, 0x01, "NumLock"},
@@ -92,6 +109,7 @@ static const struct hid_usage_entry hid_usage_table[] = {
92 {0, 0x03, "ScrollLock"}, 109 {0, 0x03, "ScrollLock"},
93 {0, 0x04, "Compose"}, 110 {0, 0x04, "Compose"},
94 {0, 0x05, "Kana"}, 111 {0, 0x05, "Kana"},
112 {0, 0x4b, "GenericIndicator"},
95 { 9, 0, "Button" }, 113 { 9, 0, "Button" },
96 { 10, 0, "Ordinal" }, 114 { 10, 0, "Ordinal" },
97 { 12, 0, "Consumer" }, 115 { 12, 0, "Consumer" },
@@ -574,7 +592,8 @@ static char *keys[KEY_MAX + 1] = {
574 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move", 592 [KEY_EXIT] = "Exit", [KEY_MOVE] = "Move",
575 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp", 593 [KEY_EDIT] = "Edit", [KEY_SCROLLUP] = "ScrollUp",
576 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis", 594 [KEY_SCROLLDOWN] = "ScrollDown", [KEY_KPLEFTPAREN] = "KPLeftParenthesis",
577 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_F13] = "F13", 595 [KEY_KPRIGHTPAREN] = "KPRightParenthesis", [KEY_NEW] = "New",
596 [KEY_REDO] = "Redo", [KEY_F13] = "F13",
578 [KEY_F14] = "F14", [KEY_F15] = "F15", 597 [KEY_F14] = "F14", [KEY_F15] = "F15",
579 [KEY_F16] = "F16", [KEY_F17] = "F17", 598 [KEY_F16] = "F16", [KEY_F17] = "F17",
580 [KEY_F18] = "F18", [KEY_F19] = "F19", 599 [KEY_F18] = "F18", [KEY_F19] = "F19",
@@ -584,15 +603,15 @@ static char *keys[KEY_MAX + 1] = {
584 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3", 603 [KEY_PAUSECD] = "PauseCD", [KEY_PROG3] = "Prog3",
585 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend", 604 [KEY_PROG4] = "Prog4", [KEY_SUSPEND] = "Suspend",
586 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play", 605 [KEY_CLOSE] = "Close", [KEY_PLAY] = "Play",
587 [KEY_FASTFORWARD] = "Fast Forward", [KEY_BASSBOOST] = "Bass Boost", 606 [KEY_FASTFORWARD] = "FastForward", [KEY_BASSBOOST] = "BassBoost",
588 [KEY_PRINT] = "Print", [KEY_HP] = "HP", 607 [KEY_PRINT] = "Print", [KEY_HP] = "HP",
589 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound", 608 [KEY_CAMERA] = "Camera", [KEY_SOUND] = "Sound",
590 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email", 609 [KEY_QUESTION] = "Question", [KEY_EMAIL] = "Email",
591 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search", 610 [KEY_CHAT] = "Chat", [KEY_SEARCH] = "Search",
592 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance", 611 [KEY_CONNECT] = "Connect", [KEY_FINANCE] = "Finance",
593 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop", 612 [KEY_SPORT] = "Sport", [KEY_SHOP] = "Shop",
594 [KEY_ALTERASE] = "Alternate Erase", [KEY_CANCEL] = "Cancel", 613 [KEY_ALTERASE] = "AlternateErase", [KEY_CANCEL] = "Cancel",
595 [KEY_BRIGHTNESSDOWN] = "Brightness down", [KEY_BRIGHTNESSUP] = "Brightness up", 614 [KEY_BRIGHTNESSDOWN] = "BrightnessDown", [KEY_BRIGHTNESSUP] = "BrightnessUp",
596 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown", 615 [KEY_MEDIA] = "Media", [KEY_UNKNOWN] = "Unknown",
597 [BTN_0] = "Btn0", [BTN_1] = "Btn1", 616 [BTN_0] = "Btn0", [BTN_1] = "Btn1",
598 [BTN_2] = "Btn2", [BTN_3] = "Btn3", 617 [BTN_2] = "Btn2", [BTN_3] = "Btn3",
@@ -622,8 +641,8 @@ static char *keys[KEY_MAX + 1] = {
622 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger", 641 [BTN_TOOL_AIRBRUSH] = "ToolAirbrush", [BTN_TOOL_FINGER] = "ToolFinger",
623 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens", 642 [BTN_TOOL_MOUSE] = "ToolMouse", [BTN_TOOL_LENS] = "ToolLens",
624 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus", 643 [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus",
625 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "Tool Doubletap", 644 [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "ToolDoubleTap",
626 [BTN_TOOL_TRIPLETAP] = "Tool Tripletap", [BTN_GEAR_DOWN] = "WheelBtn", 645 [BTN_TOOL_TRIPLETAP] = "ToolTripleTap", [BTN_GEAR_DOWN] = "WheelBtn",
627 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok", 646 [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok",
628 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto", 647 [KEY_SELECT] = "Select", [KEY_GOTO] = "Goto",
629 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2", 648 [KEY_CLEAR] = "Clear", [KEY_POWER2] = "Power2",
@@ -659,6 +678,9 @@ static char *keys[KEY_MAX + 1] = {
659 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL", 678 [KEY_TWEN] = "TWEN", [KEY_DEL_EOL] = "DeleteEOL",
660 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine", 679 [KEY_DEL_EOS] = "DeleteEOS", [KEY_INS_LINE] = "InsertLine",
661 [KEY_DEL_LINE] = "DeleteLine", 680 [KEY_DEL_LINE] = "DeleteLine",
681 [KEY_SEND] = "Send", [KEY_REPLY] = "Reply",
682 [KEY_FORWARDMAIL] = "ForwardMail", [KEY_SAVE] = "Save",
683 [KEY_DOCUMENTS] = "Documents",
662}; 684};
663 685
664static char *relatives[REL_MAX + 1] = { 686static char *relatives[REL_MAX + 1] = {
diff --git a/drivers/usb/input/hid-input.c b/drivers/usb/input/hid-input.c
index 63a4db721f7e..0b6452248a39 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/usb/input/hid-input.c
@@ -78,8 +78,8 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
78{ 78{
79 struct input_dev *input = &hidinput->input; 79 struct input_dev *input = &hidinput->input;
80 struct hid_device *device = hidinput->input.private; 80 struct hid_device *device = hidinput->input.private;
81 int max, code; 81 int max = 0, code;
82 unsigned long *bit; 82 unsigned long *bit = NULL;
83 83
84 field->hidinput = hidinput; 84 field->hidinput = hidinput;
85 85
@@ -131,6 +131,15 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
131 map_key(code); 131 map_key(code);
132 break; 132 break;
133 133
134
135 case HID_UP_SIMULATION:
136
137 switch (usage->hid & 0xffff) {
138 case 0xba: map_abs(ABS_RUDDER); break;
139 case 0xbb: map_abs(ABS_THROTTLE); break;
140 }
141 break;
142
134 case HID_UP_GENDESK: 143 case HID_UP_GENDESK:
135 144
136 if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */ 145 if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */
@@ -238,8 +247,12 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
238 case 0x000: goto ignore; 247 case 0x000: goto ignore;
239 case 0x034: map_key_clear(KEY_SLEEP); break; 248 case 0x034: map_key_clear(KEY_SLEEP); break;
240 case 0x036: map_key_clear(BTN_MISC); break; 249 case 0x036: map_key_clear(BTN_MISC); break;
250 case 0x045: map_key_clear(KEY_RADIO); break;
241 case 0x08a: map_key_clear(KEY_WWW); break; 251 case 0x08a: map_key_clear(KEY_WWW); break;
252 case 0x08d: map_key_clear(KEY_PROGRAM); break;
242 case 0x095: map_key_clear(KEY_HELP); break; 253 case 0x095: map_key_clear(KEY_HELP); break;
254 case 0x09c: map_key_clear(KEY_CHANNELUP); break;
255 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break;
243 case 0x0b0: map_key_clear(KEY_PLAY); break; 256 case 0x0b0: map_key_clear(KEY_PLAY); break;
244 case 0x0b1: map_key_clear(KEY_PAUSE); break; 257 case 0x0b1: map_key_clear(KEY_PAUSE); break;
245 case 0x0b2: map_key_clear(KEY_RECORD); break; 258 case 0x0b2: map_key_clear(KEY_RECORD); break;
@@ -259,6 +272,11 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
259 case 0x18a: map_key_clear(KEY_MAIL); break; 272 case 0x18a: map_key_clear(KEY_MAIL); break;
260 case 0x192: map_key_clear(KEY_CALC); break; 273 case 0x192: map_key_clear(KEY_CALC); break;
261 case 0x194: map_key_clear(KEY_FILE); break; 274 case 0x194: map_key_clear(KEY_FILE); break;
275 case 0x1a7: map_key_clear(KEY_DOCUMENTS); break;
276 case 0x201: map_key_clear(KEY_NEW); break;
277 case 0x207: map_key_clear(KEY_SAVE); break;
278 case 0x208: map_key_clear(KEY_PRINT); break;
279 case 0x209: map_key_clear(KEY_PROPS); break;
262 case 0x21a: map_key_clear(KEY_UNDO); break; 280 case 0x21a: map_key_clear(KEY_UNDO); break;
263 case 0x21b: map_key_clear(KEY_COPY); break; 281 case 0x21b: map_key_clear(KEY_COPY); break;
264 case 0x21c: map_key_clear(KEY_CUT); break; 282 case 0x21c: map_key_clear(KEY_CUT); break;
@@ -271,7 +289,11 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
271 case 0x227: map_key_clear(KEY_REFRESH); break; 289 case 0x227: map_key_clear(KEY_REFRESH); break;
272 case 0x22a: map_key_clear(KEY_BOOKMARKS); break; 290 case 0x22a: map_key_clear(KEY_BOOKMARKS); break;
273 case 0x238: map_rel(REL_HWHEEL); break; 291 case 0x238: map_rel(REL_HWHEEL); break;
274 default: goto unknown; 292 case 0x279: map_key_clear(KEY_REDO); break;
293 case 0x289: map_key_clear(KEY_REPLY); break;
294 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break;
295 case 0x28c: map_key_clear(KEY_SEND); break;
296 default: goto ignore;
275 } 297 }
276 break; 298 break;
277 299
@@ -296,9 +318,42 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
296 break; 318 break;
297 319
298 case HID_UP_MSVENDOR: 320 case HID_UP_MSVENDOR:
299
300 goto ignore; 321 goto ignore;
301 322
323 case HID_UP_CUSTOM: /* Reported on Logitech and Powerbook USB keyboards */
324
325 set_bit(EV_REP, input->evbit);
326 switch(usage->hid & HID_USAGE) {
327 case 0x003: map_key_clear(KEY_FN); break;
328 default: goto ignore;
329 }
330 break;
331
332 case HID_UP_LOGIVENDOR: /* Reported on Logitech Ultra X Media Remote */
333
334 set_bit(EV_REP, input->evbit);
335 switch(usage->hid & HID_USAGE) {
336 case 0x004: map_key_clear(KEY_AGAIN); break;
337 case 0x00d: map_key_clear(KEY_HOME); break;
338 case 0x024: map_key_clear(KEY_SHUFFLE); break;
339 case 0x025: map_key_clear(KEY_TV); break;
340 case 0x026: map_key_clear(KEY_MENU); break;
341 case 0x031: map_key_clear(KEY_AUDIO); break;
342 case 0x032: map_key_clear(KEY_SUBTITLE); break;
343 case 0x033: map_key_clear(KEY_LAST); break;
344 case 0x047: map_key_clear(KEY_MP3); break;
345 case 0x048: map_key_clear(KEY_DVD); break;
346 case 0x049: map_key_clear(KEY_MEDIA); break;
347 case 0x04a: map_key_clear(KEY_VIDEO); break;
348 case 0x04b: map_key_clear(KEY_ANGLE); break;
349 case 0x04c: map_key_clear(KEY_LANGUAGE); break;
350 case 0x04d: map_key_clear(KEY_SUBTITLE); break;
351 case 0x051: map_key_clear(KEY_RED); break;
352 case 0x052: map_key_clear(KEY_CLOSE); break;
353 default: goto ignore;
354 }
355 break;
356
302 case HID_UP_PID: 357 case HID_UP_PID:
303 358
304 set_bit(EV_FF, input->evbit); 359 set_bit(EV_FF, input->evbit);
@@ -349,6 +404,9 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
349 if (usage->code > max) 404 if (usage->code > max)
350 goto ignore; 405 goto ignore;
351 406
407 if (((device->quirks & (HID_QUIRK_2WHEEL_POWERMOUSE)) && (usage->hid == 0x00010032)))
408 map_rel(REL_HWHEEL);
409
352 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5)) && 410 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5)) &&
353 (usage->type == EV_REL) && (usage->code == REL_WHEEL)) 411 (usage->type == EV_REL) && (usage->code == REL_WHEEL))
354 set_bit(REL_HWHEEL, bit); 412 set_bit(REL_HWHEEL, bit);
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index c1b6b69bc4a4..ec2412c42f1e 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -173,6 +173,7 @@ struct hid_item {
173 173
174#define HID_UP_UNDEFINED 0x00000000 174#define HID_UP_UNDEFINED 0x00000000
175#define HID_UP_GENDESK 0x00010000 175#define HID_UP_GENDESK 0x00010000
176#define HID_UP_SIMULATION 0x00020000
176#define HID_UP_KEYBOARD 0x00070000 177#define HID_UP_KEYBOARD 0x00070000
177#define HID_UP_LED 0x00080000 178#define HID_UP_LED 0x00080000
178#define HID_UP_BUTTON 0x00090000 179#define HID_UP_BUTTON 0x00090000
@@ -182,6 +183,8 @@ struct hid_item {
182#define HID_UP_PID 0x000f0000 183#define HID_UP_PID 0x000f0000
183#define HID_UP_HPVENDOR 0xff7f0000 184#define HID_UP_HPVENDOR 0xff7f0000
184#define HID_UP_MSVENDOR 0xff000000 185#define HID_UP_MSVENDOR 0xff000000
186#define HID_UP_CUSTOM 0x00ff0000
187#define HID_UP_LOGIVENDOR 0xffbc0000
185 188
186#define HID_USAGE 0x0000ffff 189#define HID_USAGE 0x0000ffff
187 190
@@ -242,6 +245,7 @@ struct hid_item {
242#define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x080 245#define HID_QUIRK_2WHEEL_MOUSE_HACK_7 0x080
243#define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x100 246#define HID_QUIRK_2WHEEL_MOUSE_HACK_5 0x100
244#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x200 247#define HID_QUIRK_2WHEEL_MOUSE_HACK_ON 0x200
248#define HID_QUIRK_2WHEEL_POWERMOUSE 0x400
245 249
246/* 250/*
247 * This is the global environment of the parser. This information is 251 * This is the global environment of the parser. This information is
@@ -348,7 +352,8 @@ struct hid_report_enum {
348 352
349#define HID_REPORT_TYPES 3 353#define HID_REPORT_TYPES 3
350 354
351#define HID_BUFFER_SIZE 64 /* use 64 for compatibility with all possible packetlen */ 355#define HID_MIN_BUFFER_SIZE 64 /* make sure there is at least a packet size of space */
356#define HID_MAX_BUFFER_SIZE 4096 /* 4kb */
352#define HID_CONTROL_FIFO_SIZE 256 /* to init devices with >100 reports */ 357#define HID_CONTROL_FIFO_SIZE 256 /* to init devices with >100 reports */
353#define HID_OUTPUT_FIFO_SIZE 64 358#define HID_OUTPUT_FIFO_SIZE 64
354 359
@@ -386,6 +391,8 @@ struct hid_device { /* device report descriptor */
386 391
387 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ 392 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
388 393
394 unsigned int bufsize; /* URB buffer size */
395
389 struct urb *urbin; /* Input URB */ 396 struct urb *urbin; /* Input URB */
390 char *inbuf; /* Input buffer */ 397 char *inbuf; /* Input buffer */
391 dma_addr_t inbuf_dma; /* Input buffer dma */ 398 dma_addr_t inbuf_dma; /* Input buffer dma */
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 4c13331b5f41..d32427818af7 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -507,6 +507,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
507 return -EINVAL; 507 return -EINVAL;
508 508
509 hid_submit_report(hid, report, USB_DIR_OUT); 509 hid_submit_report(hid, report, USB_DIR_OUT);
510 hid_wait_io(hid);
510 511
511 return 0; 512 return 0;
512 513
diff --git a/drivers/usb/input/keyspan_remote.c b/drivers/usb/input/keyspan_remote.c
index 67dc93685203..99de1b33c07d 100644
--- a/drivers/usb/input/keyspan_remote.c
+++ b/drivers/usb/input/keyspan_remote.c
@@ -431,11 +431,6 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic
431 struct usb_endpoint_descriptor *endpoint; 431 struct usb_endpoint_descriptor *endpoint;
432 struct usb_device *udev = usb_get_dev(interface_to_usbdev(interface)); 432 struct usb_device *udev = usb_get_dev(interface_to_usbdev(interface));
433 433
434 /* See if the offered device matches what we can accept */
435 if ((udev->descriptor.idVendor != USB_KEYSPAN_VENDOR_ID) ||
436 (udev->descriptor.idProduct != USB_KEYSPAN_PRODUCT_UIA11) )
437 return -ENODEV;
438
439 /* allocate memory for our device state and initialize it */ 434 /* allocate memory for our device state and initialize it */
440 remote = kmalloc(sizeof(*remote), GFP_KERNEL); 435 remote = kmalloc(sizeof(*remote), GFP_KERNEL);
441 if (remote == NULL) { 436 if (remote == NULL) {
diff --git a/drivers/usb/input/map_to_7segment.h b/drivers/usb/input/map_to_7segment.h
new file mode 100644
index 000000000000..52ff27f15127
--- /dev/null
+++ b/drivers/usb/input/map_to_7segment.h
@@ -0,0 +1,189 @@
1/*
2 * drivers/usb/input/map_to_7segment.h
3 *
4 * Copyright (c) 2005 Henk Vergonet <Henk.Vergonet@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef MAP_TO_7SEGMENT_H
22#define MAP_TO_7SEGMENT_H
23
24/* This file provides translation primitives and tables for the conversion
25 * of (ASCII) characters to a 7-segments notation.
26 *
27 * The 7 segment's wikipedia notation below is used as standard.
28 * See: http://en.wikipedia.org/wiki/Seven_segment_display
29 *
30 * Notation: +-a-+
31 * f b
32 * +-g-+
33 * e c
34 * +-d-+
35 *
36 * Usage:
37 *
38 * Register a map variable, and fill it with a character set:
39 * static SEG7_DEFAULT_MAP(map_seg7);
40 *
41 *
42 * Then use for conversion:
43 * seg7 = map_to_seg7(&map_seg7, some_char);
44 * ...
45 *
46 * In device drivers it is recommended, if required, to make the char map
47 * accessible via the sysfs interface using the following scheme:
48 *
49 * static ssize_t show_map(struct device *dev, char *buf) {
50 * memcpy(buf, &map_seg7, sizeof(map_seg7));
51 * return sizeof(map_seg7);
52 * }
53 * static ssize_t store_map(struct device *dev, const char *buf, size_t cnt) {
54 * if(cnt != sizeof(map_seg7))
55 * return -EINVAL;
56 * memcpy(&map_seg7, buf, cnt);
57 * return cnt;
58 * }
59 * static DEVICE_ATTR(map_seg7, PERMS_RW, show_map, store_map);
60 *
61 * History:
62 * 2005-05-31 RFC linux-kernel@vger.kernel.org
63 */
64#include <linux/errno.h>
65
66
67#define BIT_SEG7_A 0
68#define BIT_SEG7_B 1
69#define BIT_SEG7_C 2
70#define BIT_SEG7_D 3
71#define BIT_SEG7_E 4
72#define BIT_SEG7_F 5
73#define BIT_SEG7_G 6
74#define BIT_SEG7_RESERVED 7
75
76struct seg7_conversion_map {
77 unsigned char table[128];
78};
79
80static inline int map_to_seg7(struct seg7_conversion_map *map, int c)
81{
82 return c & 0x7f ? map->table[c] : -EINVAL;
83}
84
85#define SEG7_CONVERSION_MAP(_name, _map) \
86 struct seg7_conversion_map _name = { .table = { _map } }
87
88/*
89 * It is recommended to use a facility that allows user space to redefine
90 * custom character sets for LCD devices. Please use a sysfs interface
91 * as described above.
92 */
93#define MAP_TO_SEG7_SYSFS_FILE "map_seg7"
94
95/*******************************************************************************
96 * ASCII conversion table
97 ******************************************************************************/
98
99#define _SEG7(l,a,b,c,d,e,f,g) \
100 ( a<<BIT_SEG7_A | b<<BIT_SEG7_B | c<<BIT_SEG7_C | d<<BIT_SEG7_D | \
101 e<<BIT_SEG7_E | f<<BIT_SEG7_F | g<<BIT_SEG7_G )
102
103#define _MAP_0_32_ASCII_SEG7_NON_PRINTABLE \
104 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
105
106#define _MAP_33_47_ASCII_SEG7_SYMBOL \
107 _SEG7('!',0,0,0,0,1,1,0), _SEG7('"',0,1,0,0,0,1,0), _SEG7('#',0,1,1,0,1,1,0),\
108 _SEG7('$',1,0,1,1,0,1,1), _SEG7('%',0,0,1,0,0,1,0), _SEG7('&',1,0,1,1,1,1,1),\
109 _SEG7('\'',0,0,0,0,0,1,0),_SEG7('(',1,0,0,1,1,1,0), _SEG7(')',1,1,1,1,0,0,0),\
110 _SEG7('*',0,1,1,0,1,1,1), _SEG7('+',0,1,1,0,0,0,1), _SEG7(',',0,0,0,0,1,0,0),\
111 _SEG7('-',0,0,0,0,0,0,1), _SEG7('.',0,0,0,0,1,0,0), _SEG7('/',0,1,0,0,1,0,1),
112
113#define _MAP_48_57_ASCII_SEG7_NUMERIC \
114 _SEG7('0',1,1,1,1,1,1,0), _SEG7('1',0,1,1,0,0,0,0), _SEG7('2',1,1,0,1,1,0,1),\
115 _SEG7('3',1,1,1,1,0,0,1), _SEG7('4',0,1,1,0,0,1,1), _SEG7('5',1,0,1,1,0,1,1),\
116 _SEG7('6',1,0,1,1,1,1,1), _SEG7('7',1,1,1,0,0,0,0), _SEG7('8',1,1,1,1,1,1,1),\
117 _SEG7('9',1,1,1,1,0,1,1),
118
119#define _MAP_58_64_ASCII_SEG7_SYMBOL \
120 _SEG7(':',0,0,0,1,0,0,1), _SEG7(';',0,0,0,1,0,0,1), _SEG7('<',1,0,0,0,0,1,1),\
121 _SEG7('=',0,0,0,1,0,0,1), _SEG7('>',1,1,0,0,0,0,1), _SEG7('?',1,1,1,0,0,1,0),\
122 _SEG7('@',1,1,0,1,1,1,1),
123
124#define _MAP_65_90_ASCII_SEG7_ALPHA_UPPR \
125 _SEG7('A',1,1,1,0,1,1,1), _SEG7('B',1,1,1,1,1,1,1), _SEG7('C',1,0,0,1,1,1,0),\
126 _SEG7('D',1,1,1,1,1,1,0), _SEG7('E',1,0,0,1,1,1,1), _SEG7('F',1,0,0,0,1,1,1),\
127 _SEG7('G',1,1,1,1,0,1,1), _SEG7('H',0,1,1,0,1,1,1), _SEG7('I',0,1,1,0,0,0,0),\
128 _SEG7('J',0,1,1,1,0,0,0), _SEG7('K',0,1,1,0,1,1,1), _SEG7('L',0,0,0,1,1,1,0),\
129 _SEG7('M',1,1,1,0,1,1,0), _SEG7('N',1,1,1,0,1,1,0), _SEG7('O',1,1,1,1,1,1,0),\
130 _SEG7('P',1,1,0,0,1,1,1), _SEG7('Q',1,1,1,1,1,1,0), _SEG7('R',1,1,1,0,1,1,1),\
131 _SEG7('S',1,0,1,1,0,1,1), _SEG7('T',0,0,0,1,1,1,1), _SEG7('U',0,1,1,1,1,1,0),\
132 _SEG7('V',0,1,1,1,1,1,0), _SEG7('W',0,1,1,1,1,1,1), _SEG7('X',0,1,1,0,1,1,1),\
133 _SEG7('Y',0,1,1,0,0,1,1), _SEG7('Z',1,1,0,1,1,0,1),
134
135#define _MAP_91_96_ASCII_SEG7_SYMBOL \
136 _SEG7('[',1,0,0,1,1,1,0), _SEG7('\\',0,0,1,0,0,1,1),_SEG7(']',1,1,1,1,0,0,0),\
137 _SEG7('^',1,1,0,0,0,1,0), _SEG7('_',0,0,0,1,0,0,0), _SEG7('`',0,1,0,0,0,0,0),
138
139#define _MAP_97_122_ASCII_SEG7_ALPHA_LOWER \
140 _SEG7('A',1,1,1,0,1,1,1), _SEG7('b',0,0,1,1,1,1,1), _SEG7('c',0,0,0,1,1,0,1),\
141 _SEG7('d',0,1,1,1,1,0,1), _SEG7('E',1,0,0,1,1,1,1), _SEG7('F',1,0,0,0,1,1,1),\
142 _SEG7('G',1,1,1,1,0,1,1), _SEG7('h',0,0,1,0,1,1,1), _SEG7('i',0,0,1,0,0,0,0),\
143 _SEG7('j',0,0,1,1,0,0,0), _SEG7('k',0,0,1,0,1,1,1), _SEG7('L',0,0,0,1,1,1,0),\
144 _SEG7('M',1,1,1,0,1,1,0), _SEG7('n',0,0,1,0,1,0,1), _SEG7('o',0,0,1,1,1,0,1),\
145 _SEG7('P',1,1,0,0,1,1,1), _SEG7('q',1,1,1,0,0,1,1), _SEG7('r',0,0,0,0,1,0,1),\
146 _SEG7('S',1,0,1,1,0,1,1), _SEG7('T',0,0,0,1,1,1,1), _SEG7('u',0,0,1,1,1,0,0),\
147 _SEG7('v',0,0,1,1,1,0,0), _SEG7('W',0,1,1,1,1,1,1), _SEG7('X',0,1,1,0,1,1,1),\
148 _SEG7('y',0,1,1,1,0,1,1), _SEG7('Z',1,1,0,1,1,0,1),
149
150#define _MAP_123_126_ASCII_SEG7_SYMBOL \
151 _SEG7('{',1,0,0,1,1,1,0), _SEG7('|',0,0,0,0,1,1,0), _SEG7('}',1,1,1,1,0,0,0),\
152 _SEG7('~',1,0,0,0,0,0,0),
153
154/* Maps */
155
156/* This set tries to map as close as possible to the visible characteristics
157 * of the ASCII symbol, lowercase and uppercase letters may differ in
158 * presentation on the display.
159 */
160#define MAP_ASCII7SEG_ALPHANUM \
161 _MAP_0_32_ASCII_SEG7_NON_PRINTABLE \
162 _MAP_33_47_ASCII_SEG7_SYMBOL \
163 _MAP_48_57_ASCII_SEG7_NUMERIC \
164 _MAP_58_64_ASCII_SEG7_SYMBOL \
165 _MAP_65_90_ASCII_SEG7_ALPHA_UPPR \
166 _MAP_91_96_ASCII_SEG7_SYMBOL \
167 _MAP_97_122_ASCII_SEG7_ALPHA_LOWER \
168 _MAP_123_126_ASCII_SEG7_SYMBOL
169
170/* This set tries to map as close as possible to the symbolic characteristics
171 * of the ASCII character for maximum discrimination.
172 * For now this means all alpha chars are in lower case representations.
173 * (This for example facilitates the use of hex numbers with uppercase input.)
174 */
175#define MAP_ASCII7SEG_ALPHANUM_LC \
176 _MAP_0_32_ASCII_SEG7_NON_PRINTABLE \
177 _MAP_33_47_ASCII_SEG7_SYMBOL \
178 _MAP_48_57_ASCII_SEG7_NUMERIC \
179 _MAP_58_64_ASCII_SEG7_SYMBOL \
180 _MAP_97_122_ASCII_SEG7_ALPHA_LOWER \
181 _MAP_91_96_ASCII_SEG7_SYMBOL \
182 _MAP_97_122_ASCII_SEG7_ALPHA_LOWER \
183 _MAP_123_126_ASCII_SEG7_SYMBOL
184
185#define SEG7_DEFAULT_MAP(_name) \
186 SEG7_CONVERSION_MAP(_name,MAP_ASCII7SEG_ALPHANUM)
187
188#endif /* MAP_TO_7SEGMENT_H */
189
diff --git a/drivers/usb/input/yealink.c b/drivers/usb/input/yealink.c
new file mode 100644
index 000000000000..58a176ef96a5
--- /dev/null
+++ b/drivers/usb/input/yealink.c
@@ -0,0 +1,1013 @@
1/*
2 * drivers/usb/input/yealink.c
3 *
4 * Copyright (c) 2005 Henk Vergonet <Henk.Vergonet@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20/*
21 * Description:
22 * Driver for the USB-P1K voip usb phone.
23 * This device is produced by Yealink Network Technology Co Ltd
24 * but may be branded under several names:
25 * - Yealink usb-p1k
26 * - Tiptel 115
27 * - ...
28 *
29 * This driver is based on:
30 * - the usbb2k-api http://savannah.nongnu.org/projects/usbb2k-api/
31 * - information from http://memeteau.free.fr/usbb2k
32 * - the xpad-driver drivers/usb/input/xpad.c
33 *
34 * Thanks to:
35 * - Olivier Vandorpe, for providing the usbb2k-api.
36 * - Martin Diehl, for spotting my memory allocation bug.
37 *
38 * History:
39 * 20050527 henk First version, functional keyboard. Keyboard events
40 * will pop-up on the ../input/eventX bus.
41 * 20050531 henk Added led, LCD, dialtone and sysfs interface.
42 * 20050610 henk Cleanups, make it ready for public consumption.
43 * 20050630 henk Cleanups, fixes in response to comments.
44 * 20050701 henk sysfs write serialisation, fix potential unload races
45 * 20050801 henk Added ringtone, restructure USB
46 * 20050816 henk Merge 2.6.13-rc6
47 */
48
49#include <linux/config.h>
50#include <linux/kernel.h>
51#include <linux/input.h>
52#include <linux/init.h>
53#include <linux/slab.h>
54#include <linux/module.h>
55#include <linux/rwsem.h>
56#include <linux/usb.h>
57
58#include "map_to_7segment.h"
59#include "yealink.h"
60
61#define DRIVER_VERSION "yld-20050816"
62#define DRIVER_AUTHOR "Henk Vergonet"
63#define DRIVER_DESC "Yealink phone driver"
64
65#define YEALINK_POLLING_FREQUENCY 10 /* in [Hz] */
66
67struct yld_status {
68 u8 lcd[24];
69 u8 led;
70 u8 dialtone;
71 u8 ringtone;
72 u8 keynum;
73} __attribute__ ((packed));
74
75/*
76 * Register the LCD segment and icon map
77 */
78#define _LOC(k,l) { .a = (k), .m = (l) }
79#define _SEG(t, a, am, b, bm, c, cm, d, dm, e, em, f, fm, g, gm) \
80 { .type = (t), \
81 .u = { .s = { _LOC(a, am), _LOC(b, bm), _LOC(c, cm), \
82 _LOC(d, dm), _LOC(e, em), _LOC(g, gm), \
83 _LOC(f, fm) } } }
84#define _PIC(t, h, hm, n) \
85 { .type = (t), \
86 .u = { .p = { .name = (n), .a = (h), .m = (hm) } } }
87
88static const struct lcd_segment_map {
89 char type;
90 union {
91 struct pictogram_map {
92 u8 a,m;
93 char name[10];
94 } p;
95 struct segment_map {
96 u8 a,m;
97 } s[7];
98 } u;
99} lcdMap[] = {
100#include "yealink.h"
101};
102
103struct yealink_dev {
104 struct input_dev idev; /* input device */
105 struct usb_device *udev; /* usb device */
106
107 /* irq input channel */
108 struct yld_ctl_packet *irq_data;
109 dma_addr_t irq_dma;
110 struct urb *urb_irq;
111
112 /* control output channel */
113 struct yld_ctl_packet *ctl_data;
114 dma_addr_t ctl_dma;
115 struct usb_ctrlrequest *ctl_req;
116 dma_addr_t ctl_req_dma;
117 struct urb *urb_ctl;
118
119 char phys[64]; /* physical device path */
120
121 u8 lcdMap[ARRAY_SIZE(lcdMap)]; /* state of LCD, LED ... */
122 int key_code; /* last reported key */
123
124 int stat_ix;
125 union {
126 struct yld_status s;
127 u8 b[sizeof(struct yld_status)];
128 } master, copy;
129};
130
131
132/*******************************************************************************
133 * Yealink lcd interface
134 ******************************************************************************/
135
136/*
137 * Register a default 7 segment character set
138 */
139static SEG7_DEFAULT_MAP(map_seg7);
140
141 /* Display a char,
142 * char '\9' and '\n' are placeholders and do not overwrite the original text.
143 * A space will always hide an icon.
144 */
145static int setChar(struct yealink_dev *yld, int el, int chr)
146{
147 int i, a, m, val;
148
149 if (el >= ARRAY_SIZE(lcdMap))
150 return -EINVAL;
151
152 if (chr == '\t' || chr == '\n')
153 return 0;
154
155 yld->lcdMap[el] = chr;
156
157 if (lcdMap[el].type == '.') {
158 a = lcdMap[el].u.p.a;
159 m = lcdMap[el].u.p.m;
160 if (chr != ' ')
161 yld->master.b[a] |= m;
162 else
163 yld->master.b[a] &= ~m;
164 return 0;
165 }
166
167 val = map_to_seg7(&map_seg7, chr);
168 for (i = 0; i < ARRAY_SIZE(lcdMap[0].u.s); i++) {
169 m = lcdMap[el].u.s[i].m;
170
171 if (m == 0)
172 continue;
173
174 a = lcdMap[el].u.s[i].a;
175 if (val & 1)
176 yld->master.b[a] |= m;
177 else
178 yld->master.b[a] &= ~m;
179 val = val >> 1;
180 }
181 return 0;
182};
183
184/*******************************************************************************
185 * Yealink key interface
186 ******************************************************************************/
187
188/* Map device buttons to internal key events.
189 *
190 * USB-P1K button layout:
191 *
192 * up
193 * IN OUT
194 * down
195 *
196 * pickup C hangup
197 * 1 2 3
198 * 4 5 6
199 * 7 8 9
200 * * 0 #
201 *
202 * The "up" and "down" keys, are symbolised by arrows on the button.
203 * The "pickup" and "hangup" keys are symbolised by a green and red phone
204 * on the button.
205 */
206static int map_p1k_to_key(int scancode)
207{
208 switch(scancode) { /* phone key: */
209 case 0x23: return KEY_LEFT; /* IN */
210 case 0x33: return KEY_UP; /* up */
211 case 0x04: return KEY_RIGHT; /* OUT */
212 case 0x24: return KEY_DOWN; /* down */
213 case 0x03: return KEY_ENTER; /* pickup */
214 case 0x14: return KEY_BACKSPACE; /* C */
215 case 0x13: return KEY_ESC; /* hangup */
216 case 0x00: return KEY_1; /* 1 */
217 case 0x01: return KEY_2; /* 2 */
218 case 0x02: return KEY_3; /* 3 */
219 case 0x10: return KEY_4; /* 4 */
220 case 0x11: return KEY_5; /* 5 */
221 case 0x12: return KEY_6; /* 6 */
222 case 0x20: return KEY_7; /* 7 */
223 case 0x21: return KEY_8; /* 8 */
224 case 0x22: return KEY_9; /* 9 */
225 case 0x30: return KEY_KPASTERISK; /* * */
226 case 0x31: return KEY_0; /* 0 */
227 case 0x32: return KEY_LEFTSHIFT |
228 KEY_3 << 8; /* # */
229 }
230 return -EINVAL;
231}
232
233/* Completes a request by converting the data into events for the
234 * input subsystem.
235 *
236 * The key parameter can be cascaded: key2 << 8 | key1
237 */
238static void report_key(struct yealink_dev *yld, int key, struct pt_regs *regs)
239{
240 struct input_dev *idev = &yld->idev;
241
242 input_regs(idev, regs);
243 if (yld->key_code >= 0) {
244 /* old key up */
245 input_report_key(idev, yld->key_code & 0xff, 0);
246 if (yld->key_code >> 8)
247 input_report_key(idev, yld->key_code >> 8, 0);
248 }
249
250 yld->key_code = key;
251 if (key >= 0) {
252 /* new valid key */
253 input_report_key(idev, key & 0xff, 1);
254 if (key >> 8)
255 input_report_key(idev, key >> 8, 1);
256 }
257 input_sync(idev);
258}
259
260/*******************************************************************************
261 * Yealink usb communication interface
262 ******************************************************************************/
263
264static int yealink_cmd(struct yealink_dev *yld, struct yld_ctl_packet *p)
265{
266 u8 *buf = (u8 *)p;
267 int i;
268 u8 sum = 0;
269
270 for(i=0; i<USB_PKT_LEN-1; i++)
271 sum -= buf[i];
272 p->sum = sum;
273 return usb_control_msg(yld->udev,
274 usb_sndctrlpipe(yld->udev, 0),
275 USB_REQ_SET_CONFIGURATION,
276 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
277 0x200, 3,
278 p, sizeof(*p),
279 USB_CTRL_SET_TIMEOUT);
280}
281
282static u8 default_ringtone[] = {
283 0xEF, /* volume [0-255] */
284 0xFB, 0x1E, 0x00, 0x0C, /* 1250 [hz], 12/100 [s] */
285 0xFC, 0x18, 0x00, 0x0C, /* 1000 [hz], 12/100 [s] */
286 0xFB, 0x1E, 0x00, 0x0C,
287 0xFC, 0x18, 0x00, 0x0C,
288 0xFB, 0x1E, 0x00, 0x0C,
289 0xFC, 0x18, 0x00, 0x0C,
290 0xFB, 0x1E, 0x00, 0x0C,
291 0xFC, 0x18, 0x00, 0x0C,
292 0xFF, 0xFF, 0x01, 0x90, /* silent, 400/100 [s] */
293 0x00, 0x00 /* end of sequence */
294};
295
296static int yealink_set_ringtone(struct yealink_dev *yld, u8 *buf, size_t size)
297{
298 struct yld_ctl_packet *p = yld->ctl_data;
299 int ix, len;
300
301 if (size <= 0)
302 return -EINVAL;
303
304 /* Set the ringtone volume */
305 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
306 yld->ctl_data->cmd = CMD_RING_VOLUME;
307 yld->ctl_data->size = 1;
308 yld->ctl_data->data[0] = buf[0];
309 yealink_cmd(yld, p);
310
311 buf++;
312 size--;
313
314 p->cmd = CMD_RING_NOTE;
315 ix = 0;
316 while (size != ix) {
317 len = size - ix;
318 if (len > sizeof(p->data))
319 len = sizeof(p->data);
320 p->size = len;
321 p->offset = cpu_to_be16(ix);
322 memcpy(p->data, &buf[ix], len);
323 yealink_cmd(yld, p);
324 ix += len;
325 }
326 return 0;
327}
328
329/* keep stat_master & stat_copy in sync.
330 */
331static int yealink_do_idle_tasks(struct yealink_dev *yld)
332{
333 u8 val;
334 int i, ix, len;
335
336 ix = yld->stat_ix;
337
338 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
339 yld->ctl_data->cmd = CMD_KEYPRESS;
340 yld->ctl_data->size = 1;
341 yld->ctl_data->sum = 0xff - CMD_KEYPRESS;
342
343 /* If state update pointer wraps do a KEYPRESS first. */
344 if (ix >= sizeof(yld->master)) {
345 yld->stat_ix = 0;
346 return 0;
347 }
348
349 /* find update candidates: copy != master */
350 do {
351 val = yld->master.b[ix];
352 if (val != yld->copy.b[ix])
353 goto send_update;
354 } while (++ix < sizeof(yld->master));
355
356 /* nothing todo, wait a bit and poll for a KEYPRESS */
357 yld->stat_ix = 0;
358 /* TODO how can we wait abit. ??
359 * msleep_interruptible(1000 / YEALINK_POLLING_FREQUENCY);
360 */
361 return 0;
362
363send_update:
364
365 /* Setup an appropriate update request */
366 yld->copy.b[ix] = val;
367 yld->ctl_data->data[0] = val;
368
369 switch(ix) {
370 case offsetof(struct yld_status, led):
371 yld->ctl_data->cmd = CMD_LED;
372 yld->ctl_data->sum = -1 - CMD_LED - val;
373 break;
374 case offsetof(struct yld_status, dialtone):
375 yld->ctl_data->cmd = CMD_DIALTONE;
376 yld->ctl_data->sum = -1 - CMD_DIALTONE - val;
377 break;
378 case offsetof(struct yld_status, ringtone):
379 yld->ctl_data->cmd = CMD_RINGTONE;
380 yld->ctl_data->sum = -1 - CMD_RINGTONE - val;
381 break;
382 case offsetof(struct yld_status, keynum):
383 val--;
384 val &= 0x1f;
385 yld->ctl_data->cmd = CMD_SCANCODE;
386 yld->ctl_data->offset = cpu_to_be16(val);
387 yld->ctl_data->data[0] = 0;
388 yld->ctl_data->sum = -1 - CMD_SCANCODE - val;
389 break;
390 default:
391 len = sizeof(yld->master.s.lcd) - ix;
392 if (len > sizeof(yld->ctl_data->data))
393 len = sizeof(yld->ctl_data->data);
394
395 /* Combine up to <len> consecutive LCD bytes in a singe request
396 */
397 yld->ctl_data->cmd = CMD_LCD;
398 yld->ctl_data->offset = cpu_to_be16(ix);
399 yld->ctl_data->size = len;
400 yld->ctl_data->sum = -CMD_LCD - ix - val - len;
401 for(i=1; i<len; i++) {
402 ix++;
403 val = yld->master.b[ix];
404 yld->copy.b[ix] = val;
405 yld->ctl_data->data[i] = val;
406 yld->ctl_data->sum -= val;
407 }
408 }
409 yld->stat_ix = ix + 1;
410 return 1;
411}
412
413/* Decide on how to handle responses
414 *
415 * The state transition diagram is somethhing like:
416 *
417 * syncState<--+
418 * | |
419 * | idle
420 * \|/ |
421 * init --ok--> waitForKey --ok--> getKey
422 * ^ ^ |
423 * | +-------ok-------+
424 * error,start
425 *
426 */
427static void urb_irq_callback(struct urb *urb, struct pt_regs *regs)
428{
429 struct yealink_dev *yld = urb->context;
430 int ret;
431
432 if (urb->status)
433 err("%s - urb status %d", __FUNCTION__, urb->status);
434
435 switch (yld->irq_data->cmd) {
436 case CMD_KEYPRESS:
437
438 yld->master.s.keynum = yld->irq_data->data[0];
439 break;
440
441 case CMD_SCANCODE:
442 dbg("get scancode %x", yld->irq_data->data[0]);
443
444 report_key(yld, map_p1k_to_key(yld->irq_data->data[0]), regs);
445 break;
446
447 default:
448 err("unexpected response %x", yld->irq_data->cmd);
449 }
450
451 yealink_do_idle_tasks(yld);
452
453 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC);
454 if (ret)
455 err("%s - usb_submit_urb failed %d", __FUNCTION__, ret);
456}
457
458static void urb_ctl_callback(struct urb *urb, struct pt_regs *regs)
459{
460 struct yealink_dev *yld = urb->context;
461 int ret;
462
463 if (urb->status)
464 err("%s - urb status %d", __FUNCTION__, urb->status);
465
466 switch (yld->ctl_data->cmd) {
467 case CMD_KEYPRESS:
468 case CMD_SCANCODE:
469 /* ask for a response */
470 ret = usb_submit_urb(yld->urb_irq, GFP_ATOMIC);
471 break;
472 default:
473 /* send new command */
474 yealink_do_idle_tasks(yld);
475 ret = usb_submit_urb(yld->urb_ctl, GFP_ATOMIC);
476 }
477
478 if (ret)
479 err("%s - usb_submit_urb failed %d", __FUNCTION__, ret);
480}
481
482/*******************************************************************************
483 * input event interface
484 ******************************************************************************/
485
486/* TODO should we issue a ringtone on a SND_BELL event?
487static int input_ev(struct input_dev *dev, unsigned int type,
488 unsigned int code, int value)
489{
490
491 if (type != EV_SND)
492 return -EINVAL;
493
494 switch (code) {
495 case SND_BELL:
496 case SND_TONE:
497 break;
498 default:
499 return -EINVAL;
500 }
501
502 return 0;
503}
504*/
505
506static int input_open(struct input_dev *dev)
507{
508 struct yealink_dev *yld = dev->private;
509 int i, ret;
510
511 dbg("%s", __FUNCTION__);
512
513 /* force updates to device */
514 for (i = 0; i<sizeof(yld->master); i++)
515 yld->copy.b[i] = ~yld->master.b[i];
516 yld->key_code = -1; /* no keys pressed */
517
518 yealink_set_ringtone(yld, default_ringtone, sizeof(default_ringtone));
519
520 /* issue INIT */
521 memset(yld->ctl_data, 0, sizeof(*(yld->ctl_data)));
522 yld->ctl_data->cmd = CMD_INIT;
523 yld->ctl_data->size = 10;
524 yld->ctl_data->sum = 0x100-CMD_INIT-10;
525 if ((ret = usb_submit_urb(yld->urb_ctl, GFP_KERNEL)) != 0) {
526 dbg("%s - usb_submit_urb failed with result %d",
527 __FUNCTION__, ret);
528 return ret;
529 }
530 return 0;
531}
532
533static void input_close(struct input_dev *dev)
534{
535 struct yealink_dev *yld = dev->private;
536
537 usb_kill_urb(yld->urb_ctl);
538 usb_kill_urb(yld->urb_irq);
539}
540
541/*******************************************************************************
542 * sysfs interface
543 ******************************************************************************/
544
545static DECLARE_RWSEM(sysfs_rwsema);
546
547/* Interface to the 7-segments translation table aka. char set.
548 */
549static ssize_t show_map(struct device *dev, struct device_attribute *attr,
550 char *buf)
551{
552 memcpy(buf, &map_seg7, sizeof(map_seg7));
553 return sizeof(map_seg7);
554}
555
556static ssize_t store_map(struct device *dev, struct device_attribute *attr,
557 const char *buf, size_t cnt)
558{
559 if (cnt != sizeof(map_seg7))
560 return -EINVAL;
561 memcpy(&map_seg7, buf, sizeof(map_seg7));
562 return sizeof(map_seg7);
563}
564
565/* Interface to the LCD.
566 */
567
568/* Reading /sys/../lineX will return the format string with its settings:
569 *
570 * Example:
571 * cat ./line3
572 * 888888888888
573 * Linux Rocks!
574 */
575static ssize_t show_line(struct device *dev, char *buf, int a, int b)
576{
577 struct yealink_dev *yld;
578 int i;
579
580 down_read(&sysfs_rwsema);
581 yld = dev_get_drvdata(dev);
582 if (yld == NULL) {
583 up_read(&sysfs_rwsema);
584 return -ENODEV;
585 }
586
587 for (i = a; i < b; i++)
588 *buf++ = lcdMap[i].type;
589 *buf++ = '\n';
590 for (i = a; i < b; i++)
591 *buf++ = yld->lcdMap[i];
592 *buf++ = '\n';
593 *buf = 0;
594
595 up_read(&sysfs_rwsema);
596 return 3 + ((b - a) << 1);
597}
598
599static ssize_t show_line1(struct device *dev, struct device_attribute *attr,
600 char *buf)
601{
602 return show_line(dev, buf, LCD_LINE1_OFFSET, LCD_LINE2_OFFSET);
603}
604
605static ssize_t show_line2(struct device *dev, struct device_attribute *attr,
606 char *buf)
607{
608 return show_line(dev, buf, LCD_LINE2_OFFSET, LCD_LINE3_OFFSET);
609}
610
611static ssize_t show_line3(struct device *dev, struct device_attribute *attr,
612 char *buf)
613{
614 return show_line(dev, buf, LCD_LINE3_OFFSET, LCD_LINE4_OFFSET);
615}
616
617/* Writing to /sys/../lineX will set the coresponding LCD line.
618 * - Excess characters are ignored.
619 * - If less characters are written than allowed, the remaining digits are
620 * unchanged.
621 * - The '\n' or '\t' char is a placeholder, it does not overwrite the
622 * original content.
623 */
624static ssize_t store_line(struct device *dev, const char *buf, size_t count,
625 int el, size_t len)
626{
627 struct yealink_dev *yld;
628 int i;
629
630 down_write(&sysfs_rwsema);
631 yld = dev_get_drvdata(dev);
632 if (yld == NULL) {
633 up_write(&sysfs_rwsema);
634 return -ENODEV;
635 }
636
637 if (len > count)
638 len = count;
639 for (i = 0; i < len; i++)
640 setChar(yld, el++, buf[i]);
641
642 up_write(&sysfs_rwsema);
643 return count;
644}
645
646static ssize_t store_line1(struct device *dev, struct device_attribute *attr,
647 const char *buf, size_t count)
648{
649 return store_line(dev, buf, count, LCD_LINE1_OFFSET, LCD_LINE1_SIZE);
650}
651
652static ssize_t store_line2(struct device *dev, struct device_attribute *attr,
653 const char *buf, size_t count)
654{
655 return store_line(dev, buf, count, LCD_LINE2_OFFSET, LCD_LINE2_SIZE);
656}
657
658static ssize_t store_line3(struct device *dev, struct device_attribute *attr,
659 const char *buf, size_t count)
660{
661 return store_line(dev, buf, count, LCD_LINE3_OFFSET, LCD_LINE3_SIZE);
662}
663
664/* Interface to visible and audible "icons", these include:
665 * pictures on the LCD, the LED, and the dialtone signal.
666 */
667
668/* Get a list of "switchable elements" with their current state. */
669static ssize_t get_icons(struct device *dev, struct device_attribute *attr,
670 char *buf)
671{
672 struct yealink_dev *yld;
673 int i, ret = 1;
674
675 down_read(&sysfs_rwsema);
676 yld = dev_get_drvdata(dev);
677 if (yld == NULL) {
678 up_read(&sysfs_rwsema);
679 return -ENODEV;
680 }
681
682 for (i = 0; i < ARRAY_SIZE(lcdMap); i++) {
683 if (lcdMap[i].type != '.')
684 continue;
685 ret += sprintf(&buf[ret], "%s %s\n",
686 yld->lcdMap[i] == ' ' ? " " : "on",
687 lcdMap[i].u.p.name);
688 }
689 up_read(&sysfs_rwsema);
690 return ret;
691}
692
693/* Change the visibility of a particular element. */
694static ssize_t set_icon(struct device *dev, const char *buf, size_t count,
695 int chr)
696{
697 struct yealink_dev *yld;
698 int i;
699
700 down_write(&sysfs_rwsema);
701 yld = dev_get_drvdata(dev);
702 if (yld == NULL) {
703 up_write(&sysfs_rwsema);
704 return -ENODEV;
705 }
706
707 for (i = 0; i < ARRAY_SIZE(lcdMap); i++) {
708 if (lcdMap[i].type != '.')
709 continue;
710 if (strncmp(buf, lcdMap[i].u.p.name, count) == 0) {
711 setChar(yld, i, chr);
712 break;
713 }
714 }
715
716 up_write(&sysfs_rwsema);
717 return count;
718}
719
720static ssize_t show_icon(struct device *dev, struct device_attribute *attr,
721 const char *buf, size_t count)
722{
723 return set_icon(dev, buf, count, buf[0]);
724}
725
726static ssize_t hide_icon(struct device *dev, struct device_attribute *attr,
727 const char *buf, size_t count)
728{
729 return set_icon(dev, buf, count, ' ');
730}
731
732/* Upload a ringtone to the device.
733 */
734
735/* Stores raw ringtone data in the phone */
736static ssize_t store_ringtone(struct device *dev,
737 struct device_attribute *attr,
738 const char *buf, size_t count)
739{
740 struct yealink_dev *yld;
741
742 down_write(&sysfs_rwsema);
743 yld = dev_get_drvdata(dev);
744 if (yld == NULL) {
745 up_write(&sysfs_rwsema);
746 return -ENODEV;
747 }
748
749 /* TODO locking with async usb control interface??? */
750 yealink_set_ringtone(yld, (char *)buf, count);
751 up_write(&sysfs_rwsema);
752 return count;
753}
754
755#define _M444 S_IRUGO
756#define _M664 S_IRUGO|S_IWUSR|S_IWGRP
757#define _M220 S_IWUSR|S_IWGRP
758
759static DEVICE_ATTR(map_seg7 , _M664, show_map , store_map );
760static DEVICE_ATTR(line1 , _M664, show_line1 , store_line1 );
761static DEVICE_ATTR(line2 , _M664, show_line2 , store_line2 );
762static DEVICE_ATTR(line3 , _M664, show_line3 , store_line3 );
763static DEVICE_ATTR(get_icons , _M444, get_icons , NULL );
764static DEVICE_ATTR(show_icon , _M220, NULL , show_icon );
765static DEVICE_ATTR(hide_icon , _M220, NULL , hide_icon );
766static DEVICE_ATTR(ringtone , _M220, NULL , store_ringtone);
767
768static struct attribute *yld_attributes[] = {
769 &dev_attr_line1.attr,
770 &dev_attr_line2.attr,
771 &dev_attr_line3.attr,
772 &dev_attr_get_icons.attr,
773 &dev_attr_show_icon.attr,
774 &dev_attr_hide_icon.attr,
775 &dev_attr_map_seg7.attr,
776 &dev_attr_ringtone.attr,
777 NULL
778};
779
780static struct attribute_group yld_attr_group = {
781 .attrs = yld_attributes
782};
783
784/*******************************************************************************
785 * Linux interface and usb initialisation
786 ******************************************************************************/
787
788static const struct yld_device {
789 u16 idVendor;
790 u16 idProduct;
791 char *name;
792} yld_device[] = {
793 { 0x6993, 0xb001, "Yealink usb-p1k" },
794};
795
796static struct usb_device_id usb_table [] = {
797 { USB_INTERFACE_INFO(USB_CLASS_HID, 0, 0) },
798 { }
799};
800
801static int usb_cleanup(struct yealink_dev *yld, int err)
802{
803 if (yld == NULL)
804 return err;
805
806 if (yld->urb_irq) {
807 usb_kill_urb(yld->urb_irq);
808 usb_free_urb(yld->urb_irq);
809 }
810 if (yld->urb_ctl)
811 usb_free_urb(yld->urb_ctl);
812 if (yld->idev.dev)
813 input_unregister_device(&yld->idev);
814 if (yld->ctl_req)
815 usb_buffer_free(yld->udev, sizeof(*(yld->ctl_req)),
816 yld->ctl_req, yld->ctl_req_dma);
817 if (yld->ctl_data)
818 usb_buffer_free(yld->udev, USB_PKT_LEN,
819 yld->ctl_data, yld->ctl_dma);
820 if (yld->irq_data)
821 usb_buffer_free(yld->udev, USB_PKT_LEN,
822 yld->irq_data, yld->irq_dma);
823 kfree(yld);
824 return err;
825}
826
827static void usb_disconnect(struct usb_interface *intf)
828{
829 struct yealink_dev *yld;
830
831 down_write(&sysfs_rwsema);
832 yld = usb_get_intfdata(intf);
833 sysfs_remove_group(&intf->dev.kobj, &yld_attr_group);
834 usb_set_intfdata(intf, NULL);
835 up_write(&sysfs_rwsema);
836
837 usb_cleanup(yld, 0);
838}
839
840static int usb_match(struct usb_device *udev)
841{
842 int i;
843 u16 idVendor = le16_to_cpu(udev->descriptor.idVendor);
844 u16 idProduct = le16_to_cpu(udev->descriptor.idProduct);
845
846 for (i = 0; i < ARRAY_SIZE(yld_device); i++) {
847 if ((idVendor == yld_device[i].idVendor) &&
848 (idProduct == yld_device[i].idProduct))
849 return i;
850 }
851 return -ENODEV;
852}
853
854static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
855{
856 struct usb_device *udev = interface_to_usbdev (intf);
857 struct usb_host_interface *interface;
858 struct usb_endpoint_descriptor *endpoint;
859 struct yealink_dev *yld;
860 char path[64];
861 int ret, pipe, i;
862
863 i = usb_match(udev);
864 if (i < 0)
865 return -ENODEV;
866
867 interface = intf->cur_altsetting;
868 endpoint = &interface->endpoint[0].desc;
869 if (!(endpoint->bEndpointAddress & 0x80))
870 return -EIO;
871 if ((endpoint->bmAttributes & 3) != 3)
872 return -EIO;
873
874 if ((yld = kmalloc(sizeof(struct yealink_dev), GFP_KERNEL)) == NULL)
875 return -ENOMEM;
876
877 memset(yld, 0, sizeof(*yld));
878 yld->udev = udev;
879
880 /* allocate usb buffers */
881 yld->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN,
882 SLAB_ATOMIC, &yld->irq_dma);
883 if (yld->irq_data == NULL)
884 return usb_cleanup(yld, -ENOMEM);
885
886 yld->ctl_data = usb_buffer_alloc(udev, USB_PKT_LEN,
887 SLAB_ATOMIC, &yld->ctl_dma);
888 if (!yld->ctl_data)
889 return usb_cleanup(yld, -ENOMEM);
890
891 yld->ctl_req = usb_buffer_alloc(udev, sizeof(*(yld->ctl_req)),
892 SLAB_ATOMIC, &yld->ctl_req_dma);
893 if (yld->ctl_req == NULL)
894 return usb_cleanup(yld, -ENOMEM);
895
896 /* allocate urb structures */
897 yld->urb_irq = usb_alloc_urb(0, GFP_KERNEL);
898 if (yld->urb_irq == NULL)
899 return usb_cleanup(yld, -ENOMEM);
900
901 yld->urb_ctl = usb_alloc_urb(0, GFP_KERNEL);
902 if (yld->urb_ctl == NULL)
903 return usb_cleanup(yld, -ENOMEM);
904
905 /* get a handle to the interrupt data pipe */
906 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
907 ret = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
908 if (ret != USB_PKT_LEN)
909 err("invalid payload size %d, expected %d", ret, USB_PKT_LEN);
910
911 /* initialise irq urb */
912 usb_fill_int_urb(yld->urb_irq, udev, pipe, yld->irq_data,
913 USB_PKT_LEN,
914 urb_irq_callback,
915 yld, endpoint->bInterval);
916 yld->urb_irq->transfer_dma = yld->irq_dma;
917 yld->urb_irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
918 yld->urb_irq->dev = udev;
919
920 /* initialise ctl urb */
921 yld->ctl_req->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE |
922 USB_DIR_OUT;
923 yld->ctl_req->bRequest = USB_REQ_SET_CONFIGURATION;
924 yld->ctl_req->wValue = cpu_to_le16(0x200);
925 yld->ctl_req->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
926 yld->ctl_req->wLength = cpu_to_le16(USB_PKT_LEN);
927
928 usb_fill_control_urb(yld->urb_ctl, udev, usb_sndctrlpipe(udev, 0),
929 (void *)yld->ctl_req, yld->ctl_data, USB_PKT_LEN,
930 urb_ctl_callback, yld);
931 yld->urb_ctl->setup_dma = yld->ctl_req_dma;
932 yld->urb_ctl->transfer_dma = yld->ctl_dma;
933 yld->urb_ctl->transfer_flags |= URB_NO_SETUP_DMA_MAP |
934 URB_NO_TRANSFER_DMA_MAP;
935 yld->urb_ctl->dev = udev;
936
937 /* find out the physical bus location */
938 if (usb_make_path(udev, path, sizeof(path)) > 0)
939 snprintf(yld->phys, sizeof(yld->phys)-1, "%s/input0", path);
940
941 /* register settings for the input device */
942 init_input_dev(&yld->idev);
943 yld->idev.private = yld;
944 yld->idev.id.bustype = BUS_USB;
945 yld->idev.id.vendor = le16_to_cpu(udev->descriptor.idVendor);
946 yld->idev.id.product = le16_to_cpu(udev->descriptor.idProduct);
947 yld->idev.id.version = le16_to_cpu(udev->descriptor.bcdDevice);
948 yld->idev.dev = &intf->dev;
949 yld->idev.name = yld_device[i].name;
950 yld->idev.phys = yld->phys;
951 /* yld->idev.event = input_ev; TODO */
952 yld->idev.open = input_open;
953 yld->idev.close = input_close;
954
955 /* register available key events */
956 yld->idev.evbit[0] = BIT(EV_KEY);
957 for (i = 0; i < 256; i++) {
958 int k = map_p1k_to_key(i);
959 if (k >= 0) {
960 set_bit(k & 0xff, yld->idev.keybit);
961 if (k >> 8)
962 set_bit(k >> 8, yld->idev.keybit);
963 }
964 }
965
966 printk(KERN_INFO "input: %s on %s\n", yld->idev.name, path);
967
968 input_register_device(&yld->idev);
969
970 usb_set_intfdata(intf, yld);
971
972 /* clear visible elements */
973 for (i=0; i<ARRAY_SIZE(lcdMap); i++)
974 setChar(yld, i, ' ');
975
976 /* display driver version on LCD line 3 */
977 store_line3(&intf->dev, NULL,
978 DRIVER_VERSION, sizeof(DRIVER_VERSION));
979
980 /* Register sysfs hooks (don't care about failure) */
981 sysfs_create_group(&intf->dev.kobj, &yld_attr_group);
982 return 0;
983}
984
985static struct usb_driver yealink_driver = {
986 .owner = THIS_MODULE,
987 .name = "yealink",
988 .probe = usb_probe,
989 .disconnect = usb_disconnect,
990 .id_table = usb_table,
991};
992
993static int __init yealink_dev_init(void)
994{
995 int ret = usb_register(&yealink_driver);
996 if (ret == 0)
997 info(DRIVER_DESC ":" DRIVER_VERSION);
998 return ret;
999}
1000
1001static void __exit yealink_dev_exit(void)
1002{
1003 usb_deregister(&yealink_driver);
1004}
1005
1006module_init(yealink_dev_init);
1007module_exit(yealink_dev_exit);
1008
1009MODULE_DEVICE_TABLE (usb, usb_table);
1010
1011MODULE_AUTHOR(DRIVER_AUTHOR);
1012MODULE_DESCRIPTION(DRIVER_DESC);
1013MODULE_LICENSE("GPL");
diff --git a/drivers/usb/input/yealink.h b/drivers/usb/input/yealink.h
new file mode 100644
index 000000000000..48af0be9cbdf
--- /dev/null
+++ b/drivers/usb/input/yealink.h
@@ -0,0 +1,220 @@
1/*
2 * drivers/usb/input/yealink.h
3 *
4 * Copyright (c) 2005 Henk Vergonet <Henk.Vergonet@gmail.com>
5 *
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21#ifndef INPUT_YEALINK_H
22#define INPUT_YEALINK_H
23
24/* Using the control channel on interface 3 various aspects of the phone
25 * can be controlled like LCD, LED, dialtone and the ringtone.
26 */
27
28struct yld_ctl_packet {
29 u8 cmd; /* command code, see below */
30 u8 size; /* 1-11, size of used data bytes. */
31 u16 offset; /* internal packet offset */
32 u8 data[11];
33 s8 sum; /* negative sum of 15 preceding bytes */
34} __attribute__ ((packed));
35
36#define USB_PKT_LEN sizeof(struct yld_ctl_packet)
37
38/* The following yld_ctl_packet's are available: */
39
40/* Init registers
41 *
42 * cmd 0x8e
43 * size 10
44 * offset 0
45 * data 0,0,0,0....
46 */
47#define CMD_INIT 0x8e
48
49/* Request key scan
50 *
51 * cmd 0x80
52 * size 1
53 * offset 0
54 * data[0] on return returns the key number, if it changes there's a new
55 * key pressed.
56 */
57#define CMD_KEYPRESS 0x80
58
59/* Request scancode
60 *
61 * cmd 0x81
62 * size 1
63 * offset key number [0-1f]
64 * data[0] on return returns the scancode
65 */
66#define CMD_SCANCODE 0x81
67
68/* Set LCD
69 *
70 * cmd 0x04
71 * size 1-11
72 * offset 0-23
73 * data segment bits
74 */
75#define CMD_LCD 0x04
76
77/* Set led
78 *
79 * cmd 0x05
80 * size 1
81 * offset 0
82 * data[0] 0 OFF / 1 ON
83 */
84#define CMD_LED 0x05
85
86/* Set ringtone volume
87 *
88 * cmd 0x11
89 * size 1
90 * offset 0
91 * data[0] 0-0xff volume
92 */
93#define CMD_RING_VOLUME 0x11
94
95/* Set ringtone notes
96 *
97 * cmd 0x02
98 * size 1-11
99 * offset 0->
100 * data binary representation LE16(-freq), LE16(duration) ....
101 */
102#define CMD_RING_NOTE 0x02
103
104/* Sound ringtone via the speaker on the back
105 *
106 * cmd 0x03
107 * size 1
108 * offset 0
109 * data[0] 0 OFF / 0x24 ON
110 */
111#define CMD_RINGTONE 0x03
112
113/* Sound dial tone via the ear speaker
114 *
115 * cmd 0x09
116 * size 1
117 * offset 0
118 * data[0] 0 OFF / 1 ON
119 */
120#define CMD_DIALTONE 0x09
121
122#endif /* INPUT_YEALINK_H */
123
124
125#if defined(_SEG) && defined(_PIC)
126/* This table maps the LCD segments onto individual bit positions in the
127 * yld_status struct.
128 */
129
130/* LCD, each segment must be driven seperately.
131 *
132 * Layout:
133 *
134 * |[] [][] [][] [][] in |[][]
135 * |[] M [][] D [][] : [][] out |[][]
136 * store
137 *
138 * NEW REP SU MO TU WE TH FR SA
139 *
140 * [] [] [] [] [] [] [] [] [] [] [] []
141 * [] [] [] [] [] [] [] [] [] [] [] []
142 */
143
144/* Line 1
145 * Format : 18.e8.M8.88...188
146 * Icon names : M D : IN OUT STORE
147 */
148#define LCD_LINE1_OFFSET 0
149#define LCD_LINE1_SIZE 17
150
151/* Note: first g then f => ! ! */
152/* _SEG( type a b c d e g f ) */
153 _SEG('1', 0,0 , 22,2 , 22,2 , 0,0 , 0,0 , 0,0 , 0,0 ),
154 _SEG('8', 20,1 , 20,2 , 20,4 , 20,8 , 21,4 , 21,2 , 21,1 ),
155 _PIC('.', 22,1 , "M" ),
156 _SEG('e', 18,1 , 18,2 , 18,4 , 18,1 , 19,2 , 18,1 , 19,1 ),
157 _SEG('8', 16,1 , 16,2 , 16,4 , 16,8 , 17,4 , 17,2 , 17,1 ),
158 _PIC('.', 15,8 , "D" ),
159 _SEG('M', 14,1 , 14,2 , 14,4 , 14,1 , 15,4 , 15,2 , 15,1 ),
160 _SEG('8', 12,1 , 12,2 , 12,4 , 12,8 , 13,4 , 13,2 , 13,1 ),
161 _PIC('.', 11,8 , ":" ),
162 _SEG('8', 10,1 , 10,2 , 10,4 , 10,8 , 11,4 , 11,2 , 11,1 ),
163 _SEG('8', 8,1 , 8,2 , 8,4 , 8,8 , 9,4 , 9,2 , 9,1 ),
164 _PIC('.', 7,1 , "IN" ),
165 _PIC('.', 7,2 , "OUT" ),
166 _PIC('.', 7,4 , "STORE" ),
167 _SEG('1', 0,0 , 5,1 , 5,1 , 0,0 , 0,0 , 0,0 , 0,0 ),
168 _SEG('8', 4,1 , 4,2 , 4,4 , 4,8 , 5,8 , 5,4 , 5,2 ),
169 _SEG('8', 2,1 , 2,2 , 2,4 , 2,8 , 3,4 , 3,2 , 3,1 ),
170
171/* Line 2
172 * Format : .........
173 * Pict. name : NEW REP SU MO TU WE TH FR SA
174 */
175#define LCD_LINE2_OFFSET LCD_LINE1_OFFSET + LCD_LINE1_SIZE
176#define LCD_LINE2_SIZE 9
177
178 _PIC('.', 23,2 , "NEW" ),
179 _PIC('.', 23,4 , "REP" ),
180 _PIC('.', 1,8 , "SU" ),
181 _PIC('.', 1,4 , "MO" ),
182 _PIC('.', 1,2 , "TU" ),
183 _PIC('.', 1,1 , "WE" ),
184 _PIC('.', 0,1 , "TH" ),
185 _PIC('.', 0,2 , "FR" ),
186 _PIC('.', 0,4 , "SA" ),
187
188/* Line 3
189 * Format : 888888888888
190 */
191#define LCD_LINE3_OFFSET LCD_LINE2_OFFSET + LCD_LINE2_SIZE
192#define LCD_LINE3_SIZE 12
193
194 _SEG('8', 22,16, 22,32, 22,64, 22,128, 23,128, 23,64, 23,32 ),
195 _SEG('8', 20,16, 20,32, 20,64, 20,128, 21,128, 21,64, 21,32 ),
196 _SEG('8', 18,16, 18,32, 18,64, 18,128, 19,128, 19,64, 19,32 ),
197 _SEG('8', 16,16, 16,32, 16,64, 16,128, 17,128, 17,64, 17,32 ),
198 _SEG('8', 14,16, 14,32, 14,64, 14,128, 15,128, 15,64, 15,32 ),
199 _SEG('8', 12,16, 12,32, 12,64, 12,128, 13,128, 13,64, 13,32 ),
200 _SEG('8', 10,16, 10,32, 10,64, 10,128, 11,128, 11,64, 11,32 ),
201 _SEG('8', 8,16, 8,32, 8,64, 8,128, 9,128, 9,64, 9,32 ),
202 _SEG('8', 6,16, 6,32, 6,64, 6,128, 7,128, 7,64, 7,32 ),
203 _SEG('8', 4,16, 4,32, 4,64, 4,128, 5,128, 5,64, 5,32 ),
204 _SEG('8', 2,16, 2,32, 2,64, 2,128, 3,128, 3,64, 3,32 ),
205 _SEG('8', 0,16, 0,32, 0,64, 0,128, 1,128, 1,64, 1,32 ),
206
207/* Line 4
208 *
209 * The LED, DIALTONE and RINGTONE are implemented as icons and use the same
210 * sysfs interface.
211 */
212#define LCD_LINE4_OFFSET LCD_LINE3_OFFSET + LCD_LINE3_SIZE
213
214 _PIC('.', offsetof(struct yld_status, led) , 0x01, "LED" ),
215 _PIC('.', offsetof(struct yld_status, dialtone) , 0x01, "DIALTONE" ),
216 _PIC('.', offsetof(struct yld_status, ringtone) , 0x24, "RINGTONE" ),
217
218#undef _SEG
219#undef _PIC
220#endif /* _SEG && _PIC */
diff --git a/drivers/usb/media/stv680.c b/drivers/usb/media/stv680.c
index 7398a7f19c1e..0fd0fa9fec21 100644
--- a/drivers/usb/media/stv680.c
+++ b/drivers/usb/media/stv680.c
@@ -260,7 +260,7 @@ static int stv_stop_video (struct usb_stv *dev)
260 PDEBUG (0, "STV(i): Camera set to original resolution"); 260 PDEBUG (0, "STV(i): Camera set to original resolution");
261 } 261 }
262 /* origMode */ 262 /* origMode */
263 kfree (buf); 263 kfree(buf);
264 return i; 264 return i;
265} 265}
266 266
@@ -276,7 +276,7 @@ static int stv_set_video_mode (struct usb_stv *dev)
276 } 276 }
277 277
278 if ((i = stv_set_config (dev, 1, 0, 0)) < 0) { 278 if ((i = stv_set_config (dev, 1, 0, 0)) < 0) {
279 kfree (buf); 279 kfree(buf);
280 return i; 280 return i;
281 } 281 }
282 282
@@ -301,13 +301,13 @@ static int stv_set_video_mode (struct usb_stv *dev)
301 goto exit; 301 goto exit;
302 302
303error: 303error:
304 kfree (buf); 304 kfree(buf);
305 if (stop_video == 1) 305 if (stop_video == 1)
306 stv_stop_video (dev); 306 stv_stop_video (dev);
307 return -1; 307 return -1;
308 308
309exit: 309exit:
310 kfree (buf); 310 kfree(buf);
311 return 0; 311 return 0;
312} 312}
313 313
@@ -327,7 +327,7 @@ static int stv_init (struct usb_stv *stv680)
327 327
328 /* set config 1, interface 0, alternate 0 */ 328 /* set config 1, interface 0, alternate 0 */
329 if ((i = stv_set_config (stv680, 1, 0, 0)) < 0) { 329 if ((i = stv_set_config (stv680, 1, 0, 0)) < 0) {
330 kfree (buffer); 330 kfree(buffer);
331 PDEBUG (0, "STV(e): set config 1,0,0 failed"); 331 PDEBUG (0, "STV(e): set config 1,0,0 failed");
332 return -1; 332 return -1;
333 } 333 }
@@ -435,11 +435,11 @@ static int stv_init (struct usb_stv *stv680)
435error: 435error:
436 i = stv_sndctrl (0, stv680, 0x80, 0, buffer, 0x02); /* Get Last Error */ 436 i = stv_sndctrl (0, stv680, 0x80, 0, buffer, 0x02); /* Get Last Error */
437 PDEBUG (1, "STV(i): last error: %i, command = 0x%x", buffer[0], buffer[1]); 437 PDEBUG (1, "STV(i): last error: %i, command = 0x%x", buffer[0], buffer[1]);
438 kfree (buffer); 438 kfree(buffer);
439 return -1; 439 return -1;
440 440
441exit: 441exit:
442 kfree (buffer); 442 kfree(buffer);
443 443
444 /* video = 320x240, 352x288 */ 444 /* video = 320x240, 352x288 */
445 if (stv680->CIF == 1) { 445 if (stv680->CIF == 1) {
@@ -708,10 +708,10 @@ static int stv680_stop_stream (struct usb_stv *stv680)
708 usb_kill_urb (stv680->urb[i]); 708 usb_kill_urb (stv680->urb[i]);
709 usb_free_urb (stv680->urb[i]); 709 usb_free_urb (stv680->urb[i]);
710 stv680->urb[i] = NULL; 710 stv680->urb[i] = NULL;
711 kfree (stv680->sbuf[i].data); 711 kfree(stv680->sbuf[i].data);
712 } 712 }
713 for (i = 0; i < STV680_NUMSCRATCH; i++) { 713 for (i = 0; i < STV680_NUMSCRATCH; i++) {
714 kfree (stv680->scratch[i].data); 714 kfree(stv680->scratch[i].data);
715 stv680->scratch[i].data = NULL; 715 stv680->scratch[i].data = NULL;
716 } 716 }
717 717
@@ -1068,7 +1068,7 @@ static int stv_close (struct inode *inode, struct file *file)
1068 stv680->user = 0; 1068 stv680->user = 0;
1069 1069
1070 if (stv680->removed) { 1070 if (stv680->removed) {
1071 kfree (stv680); 1071 kfree(stv680);
1072 stv680 = NULL; 1072 stv680 = NULL;
1073 PDEBUG (0, "STV(i): device unregistered"); 1073 PDEBUG (0, "STV(i): device unregistered");
1074 } 1074 }
@@ -1445,14 +1445,14 @@ static inline void usb_stv680_remove_disconnected (struct usb_stv *stv680)
1445 usb_kill_urb (stv680->urb[i]); 1445 usb_kill_urb (stv680->urb[i]);
1446 usb_free_urb (stv680->urb[i]); 1446 usb_free_urb (stv680->urb[i]);
1447 stv680->urb[i] = NULL; 1447 stv680->urb[i] = NULL;
1448 kfree (stv680->sbuf[i].data); 1448 kfree(stv680->sbuf[i].data);
1449 } 1449 }
1450 for (i = 0; i < STV680_NUMSCRATCH; i++) 1450 for (i = 0; i < STV680_NUMSCRATCH; i++)
1451 kfree (stv680->scratch[i].data); 1451 kfree(stv680->scratch[i].data);
1452 PDEBUG (0, "STV(i): %s disconnected", stv680->camera_name); 1452 PDEBUG (0, "STV(i): %s disconnected", stv680->camera_name);
1453 1453
1454 /* Free the memory */ 1454 /* Free the memory */
1455 kfree (stv680); 1455 kfree(stv680);
1456} 1456}
1457 1457
1458static void stv680_disconnect (struct usb_interface *intf) 1458static void stv680_disconnect (struct usb_interface *intf)
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index 6f7994f5a714..ae4681f9f0ea 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -426,7 +426,7 @@ static int auerchain_submit_urb (pauerchain_t acp, struct urb * urb)
426 426
427/* cancel an urb which is submitted to the chain 427/* cancel an urb which is submitted to the chain
428 the result is 0 if the urb is cancelled, or -EINPROGRESS if 428 the result is 0 if the urb is cancelled, or -EINPROGRESS if
429 URB_ASYNC_UNLINK is set and the function is successfully started. 429 the function is successfully started.
430*/ 430*/
431static int auerchain_unlink_urb (pauerchain_t acp, struct urb * urb) 431static int auerchain_unlink_urb (pauerchain_t acp, struct urb * urb)
432{ 432{
@@ -515,7 +515,6 @@ static void auerchain_unlink_all (pauerchain_t acp)
515 acep = acp->active; 515 acep = acp->active;
516 if (acep) { 516 if (acep) {
517 urbp = acep->urbp; 517 urbp = acep->urbp;
518 urbp->transfer_flags &= ~URB_ASYNC_UNLINK;
519 dbg ("unlink active urb"); 518 dbg ("unlink active urb");
520 usb_kill_urb (urbp); 519 usb_kill_urb (urbp);
521 } 520 }
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index ad17892aac9e..7e93ac96490f 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -464,7 +464,7 @@ static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
464 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_tail*(sizeof(size_t)+dev->interrupt_in_endpoint_size)); 464 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_tail*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
465 bytes_to_read = min(count, *actual_buffer); 465 bytes_to_read = min(count, *actual_buffer);
466 if (bytes_to_read < *actual_buffer) 466 if (bytes_to_read < *actual_buffer)
467 dev_warn(&dev->intf->dev, "Read buffer overflow, %d bytes dropped\n", 467 dev_warn(&dev->intf->dev, "Read buffer overflow, %zd bytes dropped\n",
468 *actual_buffer-bytes_to_read); 468 *actual_buffer-bytes_to_read);
469 469
470 /* copy one interrupt_in_buffer from ring_buffer into userspace */ 470 /* copy one interrupt_in_buffer from ring_buffer into userspace */
@@ -528,8 +528,8 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
528 /* write the data into interrupt_out_buffer from userspace */ 528 /* write the data into interrupt_out_buffer from userspace */
529 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size); 529 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);
530 if (bytes_to_write < count) 530 if (bytes_to_write < count)
531 dev_warn(&dev->intf->dev, "Write buffer overflow, %d bytes dropped\n",count-bytes_to_write); 531 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write);
532 dbg_info(&dev->intf->dev, "%s: count = %d, bytes_to_write = %d\n", __FUNCTION__, count, bytes_to_write); 532 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __FUNCTION__, count, bytes_to_write);
533 533
534 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) { 534 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
535 retval = -EFAULT; 535 retval = -EFAULT;
diff --git a/drivers/usb/misc/sisusbvga/Kconfig b/drivers/usb/misc/sisusbvga/Kconfig
index 3957e144caf7..7603cbe0865d 100644
--- a/drivers/usb/misc/sisusbvga/Kconfig
+++ b/drivers/usb/misc/sisusbvga/Kconfig
@@ -4,11 +4,43 @@ config USB_SISUSBVGA
4 depends on USB && USB_EHCI_HCD 4 depends on USB && USB_EHCI_HCD
5 ---help--- 5 ---help---
6 Say Y here if you intend to attach a USB2VGA dongle based on a 6 Say Y here if you intend to attach a USB2VGA dongle based on a
7 Net2280 and a SiS315 chip. 7 Net2280 and a SiS315 chip.
8 8
9 Note that this device requires a USB 2.0 host controller. It will not 9 Note that this device requires a USB 2.0 host controller. It will not
10 work with USB 1.x controllers. 10 work with USB 1.x controllers.
11 11
12 To compile this driver as a module, choose M here: the module will be 12 To compile this driver as a module, choose M here; the module will be
13 called sisusb. If unsure, say N. 13 called sisusbvga. If unsure, say N.
14
15config USB_SISUSBVGA_CON
16 bool "Text console and mode switching support" if USB_SISUSBVGA
17 depends on VT
18 select FONT_8x16
19 ---help---
20 Say Y here if you want a VGA text console via the USB dongle or
21 want to support userland applications that utilize the driver's
22 display mode switching capabilities.
23
24 Note that this console supports VGA/EGA text mode only.
25
26 By default, the console part of the driver will not kick in when
27 the driver is initialized. If you want the driver to take over
28 one or more of the consoles, you need to specify the number of
29 the first and last consoles (starting at 1) as driver parameters.
30
31 For example, if the driver is compiled as a module:
32
33 modprobe sisusbvga first=1 last=5
34
35 If you use hotplug, add this to your modutils config files with
36 the "options" keyword, such as eg.
37
38 options sisusbvga first=1 last=5
39
40 If the driver is compiled into the kernel image, the parameters
41 must be given in the kernel command like, such as
42
43 sisusbvga.first=1 sisusbvga.last=5
44
45
14 46
diff --git a/drivers/usb/misc/sisusbvga/Makefile b/drivers/usb/misc/sisusbvga/Makefile
index 76f1643ceaf8..7f934cfc906c 100644
--- a/drivers/usb/misc/sisusbvga/Makefile
+++ b/drivers/usb/misc/sisusbvga/Makefile
@@ -2,5 +2,7 @@
2# Makefile for the sisusb driver (if driver is inside kernel tree). 2# Makefile for the sisusb driver (if driver is inside kernel tree).
3# 3#
4 4
5obj-$(CONFIG_USB_SISUSBVGA) += sisusb.o 5obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga.o
6
7sisusbvga-objs := sisusb.o sisusb_init.o sisusb_con.o
6 8
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 2fd12264fd53..39db3155723a 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles 2 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
3 * 3 *
4 * Main part
5 *
4 * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria 6 * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
5 * 7 *
6 * If distributed as part of the Linux kernel, this code is licensed under the 8 * If distributed as part of the Linux kernel, this code is licensed under the
@@ -48,16 +50,60 @@
48#include <linux/kref.h> 50#include <linux/kref.h>
49#include <linux/usb.h> 51#include <linux/usb.h>
50#include <linux/smp_lock.h> 52#include <linux/smp_lock.h>
53#include <linux/vmalloc.h>
51 54
52#include "sisusb.h" 55#include "sisusb.h"
53 56
57#ifdef INCL_SISUSB_CON
58#include <linux/font.h>
59#endif
60
54#define SISUSB_DONTSYNC 61#define SISUSB_DONTSYNC
55 62
56/* Forward declarations / clean-up routines */ 63/* Forward declarations / clean-up routines */
57 64
65#ifdef INCL_SISUSB_CON
66int sisusb_setreg(struct sisusb_usb_data *sisusb, int port, u8 data);
67int sisusb_getreg(struct sisusb_usb_data *sisusb, int port, u8 *data);
68int sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 data);
69int sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 *data);
70int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port, u8 idx, u8 myand, u8 myor);
71int sisusb_setidxregor(struct sisusb_usb_data *sisusb, int port, u8 index, u8 myor);
72int sisusb_setidxregand(struct sisusb_usb_data *sisusb, int port, u8 idx, u8 myand);
73
74int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data);
75int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 *data);
76int sisusb_writew(struct sisusb_usb_data *sisusb, u32 adr, u16 data);
77int sisusb_readw(struct sisusb_usb_data *sisusb, u32 adr, u16 *data);
78int sisusb_copy_memory(struct sisusb_usb_data *sisusb, char *src,
79 u32 dest, int length, size_t *bytes_written);
80
81int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init);
82
83extern int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
84extern int SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo);
85
86extern void sisusb_init_concode(void);
87extern int sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last);
88extern void sisusb_console_exit(struct sisusb_usb_data *sisusb);
89
90extern void sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location);
91
92extern int sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
93 u8 *arg, int cmapsz, int ch512, int dorecalc,
94 struct vc_data *c, int fh, int uplock);
95
96static int sisusb_first_vc = 0;
97static int sisusb_last_vc = 0;
98module_param_named(first, sisusb_first_vc, int, 0);
99module_param_named(last, sisusb_last_vc, int, 0);
100MODULE_PARM_DESC(first, "Number of first console to take over (1 - MAX_NR_CONSOLES)");
101MODULE_PARM_DESC(last, "Number of last console to take over (1 - MAX_NR_CONSOLES)");
102#endif
103
58static struct usb_driver sisusb_driver; 104static struct usb_driver sisusb_driver;
59 105
60static DECLARE_MUTEX(disconnect_sem); 106DECLARE_MUTEX(disconnect_sem);
61 107
62static void 108static void
63sisusb_free_buffers(struct sisusb_usb_data *sisusb) 109sisusb_free_buffers(struct sisusb_usb_data *sisusb)
@@ -229,7 +275,7 @@ sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe,
229 usb_fill_bulk_urb(urb, sisusb->sisusb_dev, pipe, data, len, 275 usb_fill_bulk_urb(urb, sisusb->sisusb_dev, pipe, data, len,
230 sisusb_bulk_completeout, &sisusb->urbout_context[index]); 276 sisusb_bulk_completeout, &sisusb->urbout_context[index]);
231 277
232 urb->transfer_flags |= (tflags | URB_ASYNC_UNLINK); 278 urb->transfer_flags |= tflags;
233 urb->actual_length = 0; 279 urb->actual_length = 0;
234 280
235 if ((urb->transfer_dma = transfer_dma)) 281 if ((urb->transfer_dma = transfer_dma))
@@ -295,7 +341,7 @@ sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data,
295 usb_fill_bulk_urb(urb, sisusb->sisusb_dev, pipe, data, len, 341 usb_fill_bulk_urb(urb, sisusb->sisusb_dev, pipe, data, len,
296 sisusb_bulk_completein, sisusb); 342 sisusb_bulk_completein, sisusb);
297 343
298 urb->transfer_flags |= (tflags | URB_ASYNC_UNLINK); 344 urb->transfer_flags |= tflags;
299 urb->actual_length = 0; 345 urb->actual_length = 0;
300 346
301 if ((urb->transfer_dma = transfer_dma)) 347 if ((urb->transfer_dma = transfer_dma))
@@ -639,7 +685,10 @@ static int sisusb_send_bridge_packet(struct sisusb_usb_data *sisusb, int len,
639 685
640/* The following routines assume being used to transfer byte, word, 686/* The following routines assume being used to transfer byte, word,
641 * long etc. 687 * long etc.
642 * This means that they assume "data" in machine endianness format. 688 * This means that
689 * - the write routines expect "data" in machine endianness format.
690 * The data will be converted to leXX in sisusb_xxx_packet.
691 * - the read routines can expect read data in machine-endianess.
643 */ 692 */
644 693
645static int sisusb_write_memio_byte(struct sisusb_usb_data *sisusb, int type, 694static int sisusb_write_memio_byte(struct sisusb_usb_data *sisusb, int type,
@@ -839,7 +888,7 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
839 if (get_user(swap16, (u16 __user *)userbuffer)) 888 if (get_user(swap16, (u16 __user *)userbuffer))
840 return -EFAULT; 889 return -EFAULT;
841 } else 890 } else
842 swap16 = (kernbuffer[0] << 8) | kernbuffer[1]; 891 swap16 = *((u16 *)kernbuffer);
843 892
844 ret = sisusb_write_memio_word(sisusb, 893 ret = sisusb_write_memio_word(sisusb,
845 SISUSB_TYPE_MEM, 894 SISUSB_TYPE_MEM,
@@ -855,14 +904,25 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
855 if (userbuffer) { 904 if (userbuffer) {
856 if (copy_from_user(&buf, userbuffer, 3)) 905 if (copy_from_user(&buf, userbuffer, 3))
857 return -EFAULT; 906 return -EFAULT;
858 907#ifdef __BIG_ENDIAN
859 swap32 = (buf[0] << 16) | 908 swap32 = (buf[0] << 16) |
860 (buf[1] << 8) | 909 (buf[1] << 8) |
861 buf[2]; 910 buf[2];
911#else
912 swap32 = (buf[2] << 16) |
913 (buf[1] << 8) |
914 buf[0];
915#endif
862 } else 916 } else
917#ifdef __BIG_ENDIAN
863 swap32 = (kernbuffer[0] << 16) | 918 swap32 = (kernbuffer[0] << 16) |
864 (kernbuffer[1] << 8) | 919 (kernbuffer[1] << 8) |
865 kernbuffer[2]; 920 kernbuffer[2];
921#else
922 swap32 = (kernbuffer[2] << 16) |
923 (kernbuffer[1] << 8) |
924 kernbuffer[0];
925#endif
866 926
867 ret = sisusb_write_memio_24bit(sisusb, 927 ret = sisusb_write_memio_24bit(sisusb,
868 SISUSB_TYPE_MEM, 928 SISUSB_TYPE_MEM,
@@ -879,10 +939,7 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
879 if (get_user(swap32, (u32 __user *)userbuffer)) 939 if (get_user(swap32, (u32 __user *)userbuffer))
880 return -EFAULT; 940 return -EFAULT;
881 } else 941 } else
882 swap32 = (kernbuffer[0] << 24) | 942 swap32 = *((u32 *)kernbuffer);
883 (kernbuffer[1] << 16) |
884 (kernbuffer[2] << 8) |
885 kernbuffer[3];
886 943
887 ret = sisusb_write_memio_long(sisusb, 944 ret = sisusb_write_memio_long(sisusb,
888 SISUSB_TYPE_MEM, 945 SISUSB_TYPE_MEM,
@@ -1005,6 +1062,10 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
1005 return ret ? -EIO : 0; 1062 return ret ? -EIO : 0;
1006} 1063}
1007 1064
1065/* Remember: Read data in packet is in machine-endianess! So for
1066 * byte, word, 24bit, long no endian correction is necessary.
1067 */
1068
1008static int sisusb_read_memio_byte(struct sisusb_usb_data *sisusb, int type, 1069static int sisusb_read_memio_byte(struct sisusb_usb_data *sisusb, int type,
1009 u32 addr, u8 *data) 1070 u32 addr, u8 *data)
1010{ 1071{
@@ -1191,8 +1252,7 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
1191 (u16 __user *)userbuffer)) 1252 (u16 __user *)userbuffer))
1192 return -EFAULT; 1253 return -EFAULT;
1193 } else { 1254 } else {
1194 kernbuffer[0] = swap16 >> 8; 1255 *((u16 *)kernbuffer) = swap16;
1195 kernbuffer[1] = swap16 & 0xff;
1196 } 1256 }
1197 } 1257 }
1198 return ret; 1258 return ret;
@@ -1202,9 +1262,15 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
1202 addr, &swap32); 1262 addr, &swap32);
1203 if (!ret) { 1263 if (!ret) {
1204 (*bytes_read) += 3; 1264 (*bytes_read) += 3;
1265#ifdef __BIG_ENDIAN
1205 buf[0] = (swap32 >> 16) & 0xff; 1266 buf[0] = (swap32 >> 16) & 0xff;
1206 buf[1] = (swap32 >> 8) & 0xff; 1267 buf[1] = (swap32 >> 8) & 0xff;
1207 buf[2] = swap32 & 0xff; 1268 buf[2] = swap32 & 0xff;
1269#else
1270 buf[2] = (swap32 >> 16) & 0xff;
1271 buf[1] = (swap32 >> 8) & 0xff;
1272 buf[0] = swap32 & 0xff;
1273#endif
1208 if (userbuffer) { 1274 if (userbuffer) {
1209 if (copy_to_user(userbuffer, &buf[0], 3)) 1275 if (copy_to_user(userbuffer, &buf[0], 3))
1210 return -EFAULT; 1276 return -EFAULT;
@@ -1228,10 +1294,7 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
1228 1294
1229 userbuffer += 4; 1295 userbuffer += 4;
1230 } else { 1296 } else {
1231 kernbuffer[0] = (swap32 >> 24) & 0xff; 1297 *((u32 *)kernbuffer) = swap32;
1232 kernbuffer[1] = (swap32 >> 16) & 0xff;
1233 kernbuffer[2] = (swap32 >> 8) & 0xff;
1234 kernbuffer[3] = swap32 & 0xff;
1235 kernbuffer += 4; 1298 kernbuffer += 4;
1236 } 1299 }
1237 addr += 4; 1300 addr += 4;
@@ -1289,7 +1352,24 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
1289 1352
1290/* High level: Gfx (indexed) register access */ 1353/* High level: Gfx (indexed) register access */
1291 1354
1292static int 1355#ifdef INCL_SISUSB_CON
1356int
1357sisusb_setreg(struct sisusb_usb_data *sisusb, int port, u8 data)
1358{
1359 return sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port, data);
1360}
1361
1362int
1363sisusb_getreg(struct sisusb_usb_data *sisusb, int port, u8 *data)
1364{
1365 return sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, port, data);
1366}
1367#endif
1368
1369#ifndef INCL_SISUSB_CON
1370static
1371#endif
1372int
1293sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 data) 1373sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 data)
1294{ 1374{
1295 int ret; 1375 int ret;
@@ -1298,7 +1378,10 @@ sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 data)
1298 return ret; 1378 return ret;
1299} 1379}
1300 1380
1301static int 1381#ifndef INCL_SISUSB_CON
1382static
1383#endif
1384int
1302sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 *data) 1385sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 *data)
1303{ 1386{
1304 int ret; 1387 int ret;
@@ -1307,7 +1390,10 @@ sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 *data)
1307 return ret; 1390 return ret;
1308} 1391}
1309 1392
1310static int 1393#ifndef INCL_SISUSB_CON
1394static
1395#endif
1396int
1311sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port, u8 idx, 1397sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port, u8 idx,
1312 u8 myand, u8 myor) 1398 u8 myand, u8 myor)
1313{ 1399{
@@ -1336,18 +1422,89 @@ sisusb_setidxregmask(struct sisusb_usb_data *sisusb, int port, u8 idx,
1336 return ret; 1422 return ret;
1337} 1423}
1338 1424
1339static int 1425#ifndef INCL_SISUSB_CON
1426static
1427#endif
1428int
1340sisusb_setidxregor(struct sisusb_usb_data *sisusb, int port, u8 index, u8 myor) 1429sisusb_setidxregor(struct sisusb_usb_data *sisusb, int port, u8 index, u8 myor)
1341{ 1430{
1342 return(sisusb_setidxregandor(sisusb, port, index, 0xff, myor)); 1431 return(sisusb_setidxregandor(sisusb, port, index, 0xff, myor));
1343} 1432}
1344 1433
1345static int 1434#ifndef INCL_SISUSB_CON
1435static
1436#endif
1437int
1346sisusb_setidxregand(struct sisusb_usb_data *sisusb, int port, u8 idx, u8 myand) 1438sisusb_setidxregand(struct sisusb_usb_data *sisusb, int port, u8 idx, u8 myand)
1347{ 1439{
1348 return(sisusb_setidxregandor(sisusb, port, idx, myand, 0x00)); 1440 return(sisusb_setidxregandor(sisusb, port, idx, myand, 0x00));
1349} 1441}
1350 1442
1443/* Write/read video ram */
1444
1445#ifdef INCL_SISUSB_CON
1446int
1447sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data)
1448{
1449 return(sisusb_write_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data));
1450}
1451
1452int
1453sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 *data)
1454{
1455 return(sisusb_read_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data));
1456}
1457
1458int
1459sisusb_writew(struct sisusb_usb_data *sisusb, u32 adr, u16 data)
1460{
1461 return(sisusb_write_memio_word(sisusb, SISUSB_TYPE_MEM, adr, data));
1462}
1463
1464int
1465sisusb_readw(struct sisusb_usb_data *sisusb, u32 adr, u16 *data)
1466{
1467 return(sisusb_read_memio_word(sisusb, SISUSB_TYPE_MEM, adr, data));
1468}
1469
1470int
1471sisusb_copy_memory(struct sisusb_usb_data *sisusb, char *src,
1472 u32 dest, int length, size_t *bytes_written)
1473{
1474 return(sisusb_write_mem_bulk(sisusb, dest, src, length, NULL, 0, bytes_written));
1475}
1476
1477#ifdef SISUSBENDIANTEST
1478int
1479sisusb_read_memory(struct sisusb_usb_data *sisusb, char *dest,
1480 u32 src, int length, size_t *bytes_written)
1481{
1482 return(sisusb_read_mem_bulk(sisusb, src, dest, length, NULL, bytes_written));
1483}
1484#endif
1485#endif
1486
1487#ifdef SISUSBENDIANTEST
1488static void
1489sisusb_testreadwrite(struct sisusb_usb_data *sisusb)
1490{
1491 static char srcbuffer[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
1492 char destbuffer[10];
1493 size_t dummy;
1494 int i,j;
1495
1496 sisusb_copy_memory(sisusb, srcbuffer, sisusb->vrambase, 7, &dummy);
1497
1498 for(i = 1; i <= 7; i++) {
1499 printk(KERN_DEBUG "sisusb: rwtest %d bytes\n", i);
1500 sisusb_read_memory(sisusb, destbuffer, sisusb->vrambase, i, &dummy);
1501 for(j = 0; j < i; j++) {
1502 printk(KERN_DEBUG "sisusb: rwtest read[%d] = %x\n", j, destbuffer[j]);
1503 }
1504 }
1505}
1506#endif
1507
1351/* access pci config registers (reg numbers 0, 4, 8, etc) */ 1508/* access pci config registers (reg numbers 0, 4, 8, etc) */
1352 1509
1353static int 1510static int
@@ -2270,6 +2427,129 @@ sisusb_init_gfxdevice(struct sisusb_usb_data *sisusb, int initscreen)
2270 return ret; 2427 return ret;
2271} 2428}
2272 2429
2430
2431#ifdef INCL_SISUSB_CON
2432
2433/* Set up default text mode:
2434 - Set text mode (0x03)
2435 - Upload default font
2436 - Upload user font (if available)
2437*/
2438
2439int
2440sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
2441{
2442 int ret = 0, slot = sisusb->font_slot, i;
2443 struct font_desc *myfont;
2444 u8 *tempbuf;
2445 u16 *tempbufb;
2446 size_t written;
2447 static char bootstring[] = "SiSUSB VGA text console, (C) 2005 Thomas Winischhofer.";
2448 static char bootlogo[] = "(o_ //\\ V_/_";
2449
2450 /* sisusb->lock is down */
2451
2452 if (!sisusb->SiS_Pr)
2453 return 1;
2454
2455 sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
2456 sisusb->SiS_Pr->sisusb = (void *)sisusb;
2457
2458 /* Set mode 0x03 */
2459 SiSUSBSetMode(sisusb->SiS_Pr, 0x03);
2460
2461 if (!(myfont = find_font("VGA8x16")))
2462 return 1;
2463
2464 if (!(tempbuf = vmalloc(8192)))
2465 return 1;
2466
2467 for (i = 0; i < 256; i++)
2468 memcpy(tempbuf + (i * 32), myfont->data + (i * 16), 16);
2469
2470 /* Upload default font */
2471 ret = sisusbcon_do_font_op(sisusb, 1, 0, tempbuf, 8192, 0, 1, NULL, 16, 0);
2472
2473 vfree(tempbuf);
2474
2475 /* Upload user font (and reset current slot) */
2476 if (sisusb->font_backup) {
2477 ret |= sisusbcon_do_font_op(sisusb, 1, 2, sisusb->font_backup,
2478 8192, sisusb->font_backup_512, 1, NULL,
2479 sisusb->font_backup_height, 0);
2480 if (slot != 2)
2481 sisusbcon_do_font_op(sisusb, 1, 0, NULL, 0, 0, 1,
2482 NULL, 16, 0);
2483 }
2484
2485 if (init && !sisusb->scrbuf) {
2486
2487 if ((tempbuf = vmalloc(8192))) {
2488
2489 i = 4096;
2490 tempbufb = (u16 *)tempbuf;
2491 while (i--)
2492 *(tempbufb++) = 0x0720;
2493
2494 i = 0;
2495 tempbufb = (u16 *)tempbuf;
2496 while (bootlogo[i]) {
2497 *(tempbufb++) = 0x0700 | bootlogo[i++];
2498 if (!(i % 4))
2499 tempbufb += 76;
2500 }
2501
2502 i = 0;
2503 tempbufb = (u16 *)tempbuf + 6;
2504 while (bootstring[i])
2505 *(tempbufb++) = 0x0700 | bootstring[i++];
2506
2507 ret |= sisusb_copy_memory(sisusb, tempbuf,
2508 sisusb->vrambase, 8192, &written);
2509
2510 vfree(tempbuf);
2511
2512 }
2513
2514 } else if (sisusb->scrbuf) {
2515
2516 ret |= sisusb_copy_memory(sisusb, (char *)sisusb->scrbuf,
2517 sisusb->vrambase, sisusb->scrbuf_size, &written);
2518
2519 }
2520
2521 if (sisusb->sisusb_cursor_size_from >= 0 &&
2522 sisusb->sisusb_cursor_size_to >= 0) {
2523 sisusb_setidxreg(sisusb, SISCR, 0x0a,
2524 sisusb->sisusb_cursor_size_from);
2525 sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0,
2526 sisusb->sisusb_cursor_size_to);
2527 } else {
2528 sisusb_setidxreg(sisusb, SISCR, 0x0a, 0x2d);
2529 sisusb_setidxreg(sisusb, SISCR, 0x0b, 0x0e);
2530 sisusb->sisusb_cursor_size_to = -1;
2531 }
2532
2533 slot = sisusb->sisusb_cursor_loc;
2534 if(slot < 0) slot = 0;
2535
2536 sisusb->sisusb_cursor_loc = -1;
2537 sisusb->bad_cursor_pos = 1;
2538
2539 sisusb_set_cursor(sisusb, slot);
2540
2541 sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
2542 sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
2543
2544 sisusb->textmodedestroyed = 0;
2545
2546 /* sisusb->lock is down */
2547
2548 return ret;
2549}
2550
2551#endif
2552
2273/* fops */ 2553/* fops */
2274 2554
2275static int 2555static int
@@ -2329,7 +2609,7 @@ sisusb_open(struct inode *inode, struct file *file)
2329 } 2609 }
2330 } 2610 }
2331 2611
2332 /* increment usage count for the device */ 2612 /* Increment usage count for our sisusb */
2333 kref_get(&sisusb->kref); 2613 kref_get(&sisusb->kref);
2334 2614
2335 sisusb->isopen = 1; 2615 sisusb->isopen = 1;
@@ -2340,12 +2620,10 @@ sisusb_open(struct inode *inode, struct file *file)
2340 2620
2341 up(&disconnect_sem); 2621 up(&disconnect_sem);
2342 2622
2343 printk(KERN_DEBUG "sisusbvga[%d]: opened", sisusb->minor);
2344
2345 return 0; 2623 return 0;
2346} 2624}
2347 2625
2348static void 2626void
2349sisusb_delete(struct kref *kref) 2627sisusb_delete(struct kref *kref)
2350{ 2628{
2351 struct sisusb_usb_data *sisusb = to_sisusb_dev(kref); 2629 struct sisusb_usb_data *sisusb = to_sisusb_dev(kref);
@@ -2359,6 +2637,9 @@ sisusb_delete(struct kref *kref)
2359 sisusb->sisusb_dev = NULL; 2637 sisusb->sisusb_dev = NULL;
2360 sisusb_free_buffers(sisusb); 2638 sisusb_free_buffers(sisusb);
2361 sisusb_free_urbs(sisusb); 2639 sisusb_free_urbs(sisusb);
2640#ifdef INCL_SISUSB_CON
2641 kfree(sisusb->SiS_Pr);
2642#endif
2362 kfree(sisusb); 2643 kfree(sisusb);
2363} 2644}
2364 2645
@@ -2395,8 +2676,6 @@ sisusb_release(struct inode *inode, struct file *file)
2395 2676
2396 up(&disconnect_sem); 2677 up(&disconnect_sem);
2397 2678
2398 printk(KERN_DEBUG "sisusbvga[%d]: released", myminor);
2399
2400 return 0; 2679 return 0;
2401} 2680}
2402 2681
@@ -2733,6 +3012,12 @@ sisusb_handle_command(struct sisusb_usb_data *sisusb, struct sisusb_command *y,
2733 int retval, port, length; 3012 int retval, port, length;
2734 u32 address; 3013 u32 address;
2735 3014
3015 /* All our commands require the device
3016 * to be initialized.
3017 */
3018 if (!sisusb->devinit)
3019 return -ENODEV;
3020
2736 port = y->data3 - 3021 port = y->data3 -
2737 SISUSB_PCI_PSEUDO_IOPORTBASE + 3022 SISUSB_PCI_PSEUDO_IOPORTBASE +
2738 SISUSB_PCI_IOPORTBASE; 3023 SISUSB_PCI_IOPORTBASE;
@@ -2774,6 +3059,10 @@ sisusb_handle_command(struct sisusb_usb_data *sisusb, struct sisusb_command *y,
2774 break; 3059 break;
2775 3060
2776 case SUCMD_CLRSCR: 3061 case SUCMD_CLRSCR:
3062 /* Gfx core must be initialized */
3063 if (!sisusb->gfxinit)
3064 return -ENODEV;
3065
2777 length = (y->data0 << 16) | (y->data1 << 8) | y->data2; 3066 length = (y->data0 << 16) | (y->data1 << 8) | y->data2;
2778 address = y->data3 - 3067 address = y->data3 -
2779 SISUSB_PCI_PSEUDO_MEMBASE + 3068 SISUSB_PCI_PSEUDO_MEMBASE +
@@ -2781,11 +3070,61 @@ sisusb_handle_command(struct sisusb_usb_data *sisusb, struct sisusb_command *y,
2781 retval = sisusb_clear_vram(sisusb, address, length); 3070 retval = sisusb_clear_vram(sisusb, address, length);
2782 break; 3071 break;
2783 3072
3073 case SUCMD_HANDLETEXTMODE:
3074 retval = 0;
3075#ifdef INCL_SISUSB_CON
3076 /* Gfx core must be initialized, SiS_Pr must exist */
3077 if (!sisusb->gfxinit || !sisusb->SiS_Pr)
3078 return -ENODEV;
3079
3080 switch (y->data0) {
3081 case 0:
3082 retval = sisusb_reset_text_mode(sisusb, 0);
3083 break;
3084 case 1:
3085 sisusb->textmodedestroyed = 1;
3086 break;
3087 }
3088#endif
3089 break;
3090
3091#ifdef INCL_SISUSB_CON
3092 case SUCMD_SETMODE:
3093 /* Gfx core must be initialized, SiS_Pr must exist */
3094 if (!sisusb->gfxinit || !sisusb->SiS_Pr)
3095 return -ENODEV;
3096
3097 retval = 0;
3098
3099 sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
3100 sisusb->SiS_Pr->sisusb = (void *)sisusb;
3101
3102 if (SiSUSBSetMode(sisusb->SiS_Pr, y->data3))
3103 retval = -EINVAL;
3104
3105 break;
3106
3107 case SUCMD_SETVESAMODE:
3108 /* Gfx core must be initialized, SiS_Pr must exist */
3109 if (!sisusb->gfxinit || !sisusb->SiS_Pr)
3110 return -ENODEV;
3111
3112 retval = 0;
3113
3114 sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
3115 sisusb->SiS_Pr->sisusb = (void *)sisusb;
3116
3117 if (SiSUSBSetVESAMode(sisusb->SiS_Pr, y->data3))
3118 retval = -EINVAL;
3119
3120 break;
3121#endif
3122
2784 default: 3123 default:
2785 retval = -EINVAL; 3124 retval = -EINVAL;
2786 } 3125 }
2787 3126
2788 if(retval > 0) 3127 if (retval > 0)
2789 retval = -EIO; 3128 retval = -EIO;
2790 3129
2791 return retval; 3130 return retval;
@@ -2835,6 +3174,11 @@ sisusb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
2835 x.sisusb_vramsize = sisusb->vramsize; 3174 x.sisusb_vramsize = sisusb->vramsize;
2836 x.sisusb_minor = sisusb->minor; 3175 x.sisusb_minor = sisusb->minor;
2837 x.sisusb_fbdevactive= 0; 3176 x.sisusb_fbdevactive= 0;
3177#ifdef INCL_SISUSB_CON
3178 x.sisusb_conactive = sisusb->haveconsole ? 1 : 0;
3179#else
3180 x.sisusb_conactive = 0;
3181#endif
2838 3182
2839 if (copy_to_user((void __user *)arg, &x, sizeof(x))) 3183 if (copy_to_user((void __user *)arg, &x, sizeof(x)))
2840 retval = -EFAULT; 3184 retval = -EFAULT;
@@ -2895,9 +3239,13 @@ static struct file_operations usb_sisusb_fops = {
2895}; 3239};
2896 3240
2897static struct usb_class_driver usb_sisusb_class = { 3241static struct usb_class_driver usb_sisusb_class = {
3242#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13)
2898 .name = "usb/sisusbvga%d", 3243 .name = "usb/sisusbvga%d",
2899 .fops = &usb_sisusb_fops,
2900 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, 3244 .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
3245#else
3246 .name = "sisusbvga%d",
3247#endif
3248 .fops = &usb_sisusb_fops,
2901 .minor_base = SISUSB_MINOR 3249 .minor_base = SISUSB_MINOR
2902}; 3250};
2903 3251
@@ -2994,12 +3342,25 @@ static int sisusb_probe(struct usb_interface *intf,
2994 printk(KERN_INFO "sisusbvga[%d]: Allocated %d output buffers\n", 3342 printk(KERN_INFO "sisusbvga[%d]: Allocated %d output buffers\n",
2995 sisusb->minor, sisusb->numobufs); 3343 sisusb->minor, sisusb->numobufs);
2996 3344
3345#ifdef INCL_SISUSB_CON
3346 /* Allocate our SiS_Pr */
3347 if (!(sisusb->SiS_Pr = kmalloc(sizeof(struct SiS_Private), GFP_KERNEL))) {
3348 printk(KERN_ERR
3349 "sisusbvga[%d]: Failed to allocate SiS_Pr\n",
3350 sisusb->minor);
3351 }
3352#endif
3353
2997 /* Do remaining init stuff */ 3354 /* Do remaining init stuff */
2998 3355
2999 init_waitqueue_head(&sisusb->wait_q); 3356 init_waitqueue_head(&sisusb->wait_q);
3000 3357
3001 usb_set_intfdata(intf, sisusb); 3358 usb_set_intfdata(intf, sisusb);
3002 3359
3360 usb_get_dev(sisusb->sisusb_dev);
3361
3362 sisusb->present = 1;
3363
3003#ifdef SISUSB_OLD_CONFIG_COMPAT 3364#ifdef SISUSB_OLD_CONFIG_COMPAT
3004 { 3365 {
3005 int ret; 3366 int ret;
@@ -3014,14 +3375,19 @@ static int sisusb_probe(struct usb_interface *intf,
3014 sisusb->minor); 3375 sisusb->minor);
3015 else 3376 else
3016 sisusb->ioctl32registered = 1; 3377 sisusb->ioctl32registered = 1;
3017
3018 } 3378 }
3019#endif 3379#endif
3020 3380
3021 sisusb->present = 1;
3022
3023 if (dev->speed == USB_SPEED_HIGH) { 3381 if (dev->speed == USB_SPEED_HIGH) {
3024 if (sisusb_init_gfxdevice(sisusb, 1)) 3382 int initscreen = 1;
3383#ifdef INCL_SISUSB_CON
3384 if (sisusb_first_vc > 0 &&
3385 sisusb_last_vc > 0 &&
3386 sisusb_first_vc <= sisusb_last_vc &&
3387 sisusb_last_vc <= MAX_NR_CONSOLES)
3388 initscreen = 0;
3389#endif
3390 if (sisusb_init_gfxdevice(sisusb, initscreen))
3025 printk(KERN_ERR 3391 printk(KERN_ERR
3026 "sisusbvga[%d]: Failed to early " 3392 "sisusbvga[%d]: Failed to early "
3027 "initialize device\n", 3393 "initialize device\n",
@@ -3035,6 +3401,16 @@ static int sisusb_probe(struct usb_interface *intf,
3035 3401
3036 sisusb->ready = 1; 3402 sisusb->ready = 1;
3037 3403
3404#ifdef SISUSBENDIANTEST
3405 printk(KERN_DEBUG "sisusb: *** RWTEST ***\n");
3406 sisusb_testreadwrite(sisusb);
3407 printk(KERN_DEBUG "sisusb: *** RWTEST END ***\n");
3408#endif
3409
3410#ifdef INCL_SISUSB_CON
3411 sisusb_console_init(sisusb, sisusb_first_vc, sisusb_last_vc);
3412#endif
3413
3038 return 0; 3414 return 0;
3039 3415
3040error_4: 3416error_4:
@@ -3053,13 +3429,20 @@ static void sisusb_disconnect(struct usb_interface *intf)
3053 struct sisusb_usb_data *sisusb; 3429 struct sisusb_usb_data *sisusb;
3054 int minor; 3430 int minor;
3055 3431
3056 down(&disconnect_sem);
3057
3058 /* This should *not* happen */ 3432 /* This should *not* happen */
3059 if (!(sisusb = usb_get_intfdata(intf))) { 3433 if (!(sisusb = usb_get_intfdata(intf)))
3060 up(&disconnect_sem);
3061 return; 3434 return;
3062 } 3435
3436#ifdef INCL_SISUSB_CON
3437 sisusb_console_exit(sisusb);
3438#endif
3439
3440 /* The above code doesn't need the disconnect
3441 * semaphore to be down; its meaning is to
3442 * protect all other routines from the disconnect
3443 * case, not the other way round.
3444 */
3445 down(&disconnect_sem);
3063 3446
3064 down(&sisusb->lock); 3447 down(&sisusb->lock);
3065 3448
@@ -3123,11 +3506,17 @@ static int __init usb_sisusb_init(void)
3123{ 3506{
3124 int retval; 3507 int retval;
3125 3508
3509#ifdef INCL_SISUSB_CON
3510 sisusb_init_concode();
3511#endif
3512
3126 if (!(retval = usb_register(&sisusb_driver))) { 3513 if (!(retval = usb_register(&sisusb_driver))) {
3514
3127 printk(KERN_INFO "sisusb: Driver version %d.%d.%d\n", 3515 printk(KERN_INFO "sisusb: Driver version %d.%d.%d\n",
3128 SISUSB_VERSION, SISUSB_REVISION, SISUSB_PATCHLEVEL); 3516 SISUSB_VERSION, SISUSB_REVISION, SISUSB_PATCHLEVEL);
3129 printk(KERN_INFO 3517 printk(KERN_INFO
3130 "sisusb: Copyright (C) 2005 Thomas Winischhofer\n"); 3518 "sisusb: Copyright (C) 2005 Thomas Winischhofer\n");
3519
3131 } 3520 }
3132 3521
3133 return retval; 3522 return retval;
@@ -3142,6 +3531,6 @@ module_init(usb_sisusb_init);
3142module_exit(usb_sisusb_exit); 3531module_exit(usb_sisusb_exit);
3143 3532
3144MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>"); 3533MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>");
3145MODULE_DESCRIPTION("sisusb - Driver for Net2280/SiS315-based USB2VGA dongles"); 3534MODULE_DESCRIPTION("sisusbvga - Driver for Net2280/SiS315-based USB2VGA dongles");
3146MODULE_LICENSE("GPL"); 3535MODULE_LICENSE("GPL");
3147 3536
diff --git a/drivers/usb/misc/sisusbvga/sisusb.h b/drivers/usb/misc/sisusbvga/sisusb.h
index 1306d006a25a..401ff21d7881 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.h
+++ b/drivers/usb/misc/sisusbvga/sisusb.h
@@ -46,15 +46,36 @@
46#endif 46#endif
47#endif 47#endif
48 48
49/* For older kernels, support for text consoles is by default
50 * off. To ensable text console support, change the following:
51 */
52#if 0
53#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13)
54#define CONFIG_USB_SISUSBVGA_CON
55#endif
56#endif
57
49/* Version Information */ 58/* Version Information */
50 59
51#define SISUSB_VERSION 0 60#define SISUSB_VERSION 0
52#define SISUSB_REVISION 0 61#define SISUSB_REVISION 0
53#define SISUSB_PATCHLEVEL 7 62#define SISUSB_PATCHLEVEL 8
63
64/* Include console and mode switching code? */
65
66#ifdef CONFIG_USB_SISUSBVGA_CON
67#define INCL_SISUSB_CON 1
68#endif
69
70#ifdef INCL_SISUSB_CON
71#include <linux/console.h>
72#include <linux/vt_kern.h>
73#include "sisusb_struct.h"
74#endif
54 75
55/* USB related */ 76/* USB related */
56 77
57#define SISUSB_MINOR 133 /* FIXME */ 78#define SISUSB_MINOR 133 /* official */
58 79
59/* Size of the sisusb input/output buffers */ 80/* Size of the sisusb input/output buffers */
60#define SISUSB_IBUF_SIZE 0x01000 81#define SISUSB_IBUF_SIZE 0x01000
@@ -131,6 +152,26 @@ struct sisusb_usb_data {
131 unsigned char gfxinit; /* graphics core initialized? */ 152 unsigned char gfxinit; /* graphics core initialized? */
132 unsigned short chipid, chipvendor; 153 unsigned short chipid, chipvendor;
133 unsigned short chiprevision; 154 unsigned short chiprevision;
155#ifdef INCL_SISUSB_CON
156 struct SiS_Private *SiS_Pr;
157 unsigned long scrbuf;
158 unsigned int scrbuf_size;
159 int haveconsole, con_first, con_last;
160 int havethisconsole[MAX_NR_CONSOLES];
161 int textmodedestroyed;
162 unsigned int sisusb_num_columns; /* real number, not vt's idea */
163 int cur_start_addr, con_rolled_over;
164 int sisusb_cursor_loc, bad_cursor_pos;
165 int sisusb_cursor_size_from;
166 int sisusb_cursor_size_to;
167 int current_font_height, current_font_512;
168 int font_backup_size, font_backup_height, font_backup_512;
169 char *font_backup;
170 int font_slot;
171 struct vc_data *sisusb_display_fg;
172 int is_gfx;
173 int con_blanked;
174#endif
134}; 175};
135 176
136#define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref) 177#define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref)
@@ -249,7 +290,9 @@ struct sisusb_info {
249 290
250 __u32 sisusb_fbdevactive; /* != 0 if framebuffer device active */ 291 __u32 sisusb_fbdevactive; /* != 0 if framebuffer device active */
251 292
252 __u8 sisusb_reserved[32]; /* for future use */ 293 __u32 sisusb_conactive; /* != 0 if console driver active */
294
295 __u8 sisusb_reserved[28]; /* for future use */
253}; 296};
254 297
255struct sisusb_command { 298struct sisusb_command {
@@ -261,18 +304,24 @@ struct sisusb_command {
261 __u32 data4; /* for future use */ 304 __u32 data4; /* for future use */
262}; 305};
263 306
264#define SUCMD_GET 0x01 /* for all: data0 = index, data3 = port */ 307#define SUCMD_GET 0x01 /* for all: data0 = index, data3 = port */
265#define SUCMD_SET 0x02 /* data1 = value */ 308#define SUCMD_SET 0x02 /* data1 = value */
266#define SUCMD_SETOR 0x03 /* data1 = or */ 309#define SUCMD_SETOR 0x03 /* data1 = or */
267#define SUCMD_SETAND 0x04 /* data1 = and */ 310#define SUCMD_SETAND 0x04 /* data1 = and */
268#define SUCMD_SETANDOR 0x05 /* data1 = and, data2 = or */ 311#define SUCMD_SETANDOR 0x05 /* data1 = and, data2 = or */
269#define SUCMD_SETMASK 0x06 /* data1 = data, data2 = mask */ 312#define SUCMD_SETMASK 0x06 /* data1 = data, data2 = mask */
270 313
271#define SUCMD_CLRSCR 0x07 /* data0:1:2 = length, data3 = address */ 314#define SUCMD_CLRSCR 0x07 /* data0:1:2 = length, data3 = address */
315
316#define SUCMD_HANDLETEXTMODE 0x08 /* Reset/destroy text mode */
317
318#define SUCMD_SETMODE 0x09 /* Set a display mode (data3 = SiS mode) */
319#define SUCMD_SETVESAMODE 0x0a /* Set a display mode (data3 = VESA mode) */
272 320
273#define SISUSB_COMMAND _IOWR(0xF3,0x3D,struct sisusb_command) 321#define SISUSB_COMMAND _IOWR(0xF3,0x3D,struct sisusb_command)
274#define SISUSB_GET_CONFIG_SIZE _IOR(0xF3,0x3E,__u32) 322#define SISUSB_GET_CONFIG_SIZE _IOR(0xF3,0x3E,__u32)
275#define SISUSB_GET_CONFIG _IOR(0xF3,0x3F,struct sisusb_info) 323#define SISUSB_GET_CONFIG _IOR(0xF3,0x3F,struct sisusb_info)
324
276 325
277#endif /* SISUSB_H */ 326#endif /* SISUSB_H */
278 327
diff --git a/drivers/usb/misc/sisusbvga/sisusb_con.c b/drivers/usb/misc/sisusbvga/sisusb_con.c
new file mode 100644
index 000000000000..24584463553d
--- /dev/null
+++ b/drivers/usb/misc/sisusbvga/sisusb_con.c
@@ -0,0 +1,1658 @@
1/*
2 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
3 *
4 * VGA text mode console part
5 *
6 * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
7 *
8 * If distributed as part of the Linux kernel, this code is licensed under the
9 * terms of the GPL v2.
10 *
11 * Otherwise, the following license terms apply:
12 *
13 * * Redistribution and use in source and binary forms, with or without
14 * * modification, are permitted provided that the following conditions
15 * * are met:
16 * * 1) Redistributions of source code must retain the above copyright
17 * * notice, this list of conditions and the following disclaimer.
18 * * 2) Redistributions in binary form must reproduce the above copyright
19 * * notice, this list of conditions and the following disclaimer in the
20 * * documentation and/or other materials provided with the distribution.
21 * * 3) The name of the author may not be used to endorse or promote products
22 * * derived from this software without specific psisusbr written permission.
23 * *
24 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
25 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Thomas Winischhofer <thomas@winischhofer.net>
36 *
37 * Portions based on vgacon.c which are
38 * Created 28 Sep 1997 by Geert Uytterhoeven
39 * Rewritten by Martin Mares <mj@ucw.cz>, July 1998
40 * based on code Copyright (C) 1991, 1992 Linus Torvalds
41 * 1995 Jay Estabrook
42 *
43 * A note on using in_atomic() in here: We can't handle console
44 * calls from non-schedulable context due to our USB-dependend
45 * nature. For now, this driver just ignores any calls if it
46 * detects this state.
47 *
48 */
49
50#include <linux/config.h>
51#include <linux/version.h>
52#include <linux/module.h>
53#include <linux/kernel.h>
54#include <linux/signal.h>
55#include <linux/sched.h>
56#include <linux/fs.h>
57#include <linux/tty.h>
58#include <linux/console.h>
59#include <linux/string.h>
60#include <linux/kd.h>
61#include <linux/init.h>
62#include <linux/slab.h>
63#include <linux/vt_kern.h>
64#include <linux/selection.h>
65#include <linux/spinlock.h>
66#include <linux/kref.h>
67#include <linux/smp_lock.h>
68#include <linux/ioport.h>
69#include <linux/interrupt.h>
70#include <linux/vmalloc.h>
71
72#include "sisusb.h"
73
74#ifdef INCL_SISUSB_CON
75extern int sisusb_setreg(struct sisusb_usb_data *, int, u8);
76extern int sisusb_getreg(struct sisusb_usb_data *, int, u8 *);
77extern int sisusb_setidxreg(struct sisusb_usb_data *, int, u8, u8);
78extern int sisusb_getidxreg(struct sisusb_usb_data *, int, u8, u8 *);
79extern int sisusb_setidxregor(struct sisusb_usb_data *, int, u8, u8);
80extern int sisusb_setidxregand(struct sisusb_usb_data *, int, u8, u8);
81extern int sisusb_setidxregandor(struct sisusb_usb_data *, int, u8, u8, u8);
82
83extern int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data);
84extern int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 *data);
85extern int sisusb_writew(struct sisusb_usb_data *sisusb, u32 adr, u16 data);
86extern int sisusb_readw(struct sisusb_usb_data *sisusb, u32 adr, u16 *data);
87extern int sisusb_copy_memory(struct sisusb_usb_data *sisusb, char *src,
88 u32 dest, int length, size_t *bytes_written);
89
90extern void sisusb_delete(struct kref *kref);
91extern int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init);
92
93extern int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
94
95#define sisusbcon_writew(val, addr) (*(addr) = (val))
96#define sisusbcon_readw(addr) (*(addr))
97#define sisusbcon_memmovew(d, s, c) memmove(d, s, c)
98#define sisusbcon_memcpyw(d, s, c) memcpy(d, s, c)
99
100/* vc_data -> sisusb conversion table */
101static struct sisusb_usb_data *mysisusbs[MAX_NR_CONSOLES];
102
103/* Forward declaration */
104static const struct consw sisusb_con;
105
106extern struct semaphore disconnect_sem;
107
108static inline void
109sisusbcon_memsetw(u16 *s, u16 c, unsigned int count)
110{
111 count /= 2;
112 while (count--)
113 sisusbcon_writew(c, s++);
114}
115
116static inline void
117sisusb_initialize(struct sisusb_usb_data *sisusb)
118{
119 /* Reset cursor and start address */
120 if (sisusb_setidxreg(sisusb, SISCR, 0x0c, 0x00))
121 return;
122 if (sisusb_setidxreg(sisusb, SISCR, 0x0d, 0x00))
123 return;
124 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, 0x00))
125 return;
126 sisusb_setidxreg(sisusb, SISCR, 0x0f, 0x00);
127}
128
129static inline void
130sisusbcon_set_start_address(struct sisusb_usb_data *sisusb, struct vc_data *c)
131{
132 sisusb->cur_start_addr = (c->vc_visible_origin - sisusb->scrbuf) / 2;
133
134 sisusb_setidxreg(sisusb, SISCR, 0x0c, (sisusb->cur_start_addr >> 8));
135 sisusb_setidxreg(sisusb, SISCR, 0x0d, (sisusb->cur_start_addr & 0xff));
136}
137
138void
139sisusb_set_cursor(struct sisusb_usb_data *sisusb, unsigned int location)
140{
141 if (sisusb->sisusb_cursor_loc == location)
142 return;
143
144 sisusb->sisusb_cursor_loc = location;
145
146 /* Hardware bug: Text cursor appears twice or not at all
147 * at some positions. Work around it with the cursor skew
148 * bits.
149 */
150
151 if ((location & 0x0007) == 0x0007) {
152 sisusb->bad_cursor_pos = 1;
153 location--;
154 if (sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0x1f, 0x20))
155 return;
156 } else if (sisusb->bad_cursor_pos) {
157 if (sisusb_setidxregand(sisusb, SISCR, 0x0b, 0x1f))
158 return;
159 sisusb->bad_cursor_pos = 0;
160 }
161
162 if (sisusb_setidxreg(sisusb, SISCR, 0x0e, (location >> 8)))
163 return;
164 sisusb_setidxreg(sisusb, SISCR, 0x0f, (location & 0xff));
165}
166
167static inline struct sisusb_usb_data *
168sisusb_get_sisusb(unsigned short console)
169{
170 return mysisusbs[console];
171}
172
173static inline int
174sisusb_sisusb_valid(struct sisusb_usb_data *sisusb)
175{
176 if (!sisusb->present || !sisusb->ready || !sisusb->sisusb_dev)
177 return 0;
178
179 return 1;
180}
181
182static struct sisusb_usb_data *
183sisusb_get_sisusb_lock_and_check(unsigned short console)
184{
185 struct sisusb_usb_data *sisusb;
186
187 /* We can't handle console calls in non-schedulable
188 * context due to our locks and the USB transport.
189 * So we simply ignore them. This should only affect
190 * some calls to printk.
191 */
192 if (in_atomic())
193 return NULL;
194
195 if (!(sisusb = sisusb_get_sisusb(console)))
196 return NULL;
197
198 down(&sisusb->lock);
199
200 if (!sisusb_sisusb_valid(sisusb) ||
201 !sisusb->havethisconsole[console]) {
202 up(&sisusb->lock);
203 return NULL;
204 }
205
206 return sisusb;
207}
208
209static int
210sisusb_is_inactive(struct vc_data *c, struct sisusb_usb_data *sisusb)
211{
212 if (sisusb->is_gfx ||
213 sisusb->textmodedestroyed ||
214 c->vc_mode != KD_TEXT)
215 return 1;
216
217 return 0;
218}
219
220/* con_startup console interface routine */
221static const char *
222sisusbcon_startup(void)
223{
224 return "SISUSBCON";
225}
226
227/* con_init console interface routine */
228static void
229sisusbcon_init(struct vc_data *c, int init)
230{
231 struct sisusb_usb_data *sisusb;
232 int cols, rows;
233
234 /* This is called by take_over_console(),
235 * ie by us/under our control. It is
236 * only called after text mode and fonts
237 * are set up/restored.
238 */
239
240 down(&disconnect_sem);
241
242 if (!(sisusb = sisusb_get_sisusb(c->vc_num))) {
243 up(&disconnect_sem);
244 return;
245 }
246
247 down(&sisusb->lock);
248
249 if (!sisusb_sisusb_valid(sisusb)) {
250 up(&sisusb->lock);
251 up(&disconnect_sem);
252 return;
253 }
254
255 c->vc_can_do_color = 1;
256
257 c->vc_complement_mask = 0x7700;
258
259 c->vc_hi_font_mask = sisusb->current_font_512 ? 0x0800 : 0;
260
261 sisusb->haveconsole = 1;
262
263 sisusb->havethisconsole[c->vc_num] = 1;
264
265 /* We only support 640x400 */
266 c->vc_scan_lines = 400;
267
268 c->vc_font.height = sisusb->current_font_height;
269
270 /* We only support width = 8 */
271 cols = 80;
272 rows = c->vc_scan_lines / c->vc_font.height;
273
274 /* Increment usage count for our sisusb.
275 * Doing so saves us from upping/downing
276 * the disconnect semaphore; we can't
277 * lose our sisusb until this is undone
278 * in con_deinit. For all other console
279 * interface functions, it suffices to
280 * use sisusb->lock and do a quick check
281 * of sisusb for device disconnection.
282 */
283 kref_get(&sisusb->kref);
284
285 if (!*c->vc_uni_pagedir_loc)
286 con_set_default_unimap(c);
287
288 up(&sisusb->lock);
289
290 up(&disconnect_sem);
291
292 if (init) {
293 c->vc_cols = cols;
294 c->vc_rows = rows;
295 } else
296 vc_resize(c, cols, rows);
297}
298
299/* con_deinit console interface routine */
300static void
301sisusbcon_deinit(struct vc_data *c)
302{
303 struct sisusb_usb_data *sisusb;
304 int i;
305
306 /* This is called by take_over_console()
307 * and others, ie not under our control.
308 */
309
310 down(&disconnect_sem);
311
312 if (!(sisusb = sisusb_get_sisusb(c->vc_num))) {
313 up(&disconnect_sem);
314 return;
315 }
316
317 down(&sisusb->lock);
318
319 /* Clear ourselves in mysisusbs */
320 mysisusbs[c->vc_num] = NULL;
321
322 sisusb->havethisconsole[c->vc_num] = 0;
323
324 /* Free our font buffer if all consoles are gone */
325 if (sisusb->font_backup) {
326 for(i = 0; i < MAX_NR_CONSOLES; i++) {
327 if (sisusb->havethisconsole[c->vc_num])
328 break;
329 }
330 if (i == MAX_NR_CONSOLES) {
331 vfree(sisusb->font_backup);
332 sisusb->font_backup = NULL;
333 }
334 }
335
336 up(&sisusb->lock);
337
338 /* decrement the usage count on our sisusb */
339 kref_put(&sisusb->kref, sisusb_delete);
340
341 up(&disconnect_sem);
342}
343
344/* interface routine */
345static u8
346sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
347 u8 blink, u8 underline, u8 reverse)
348{
349 u8 attr = color;
350
351 if (underline)
352 attr = (attr & 0xf0) | c->vc_ulcolor;
353 else if (intensity == 0)
354 attr = (attr & 0xf0) | c->vc_halfcolor;
355
356 if (reverse)
357 attr = ((attr) & 0x88) |
358 ((((attr) >> 4) |
359 ((attr) << 4)) & 0x77);
360
361 if (blink)
362 attr ^= 0x80;
363
364 if (intensity == 2)
365 attr ^= 0x08;
366
367 return attr;
368}
369
370/* Interface routine */
371static void
372sisusbcon_invert_region(struct vc_data *vc, u16 *p, int count)
373{
374 /* Invert a region. This is called with a pointer
375 * to the console's internal screen buffer. So we
376 * simply do the inversion there and rely on
377 * a call to putc(s) to update the real screen.
378 */
379
380 while (count--) {
381 u16 a = sisusbcon_readw(p);
382
383 a = ((a) & 0x88ff) |
384 (((a) & 0x7000) >> 4) |
385 (((a) & 0x0700) << 4);
386
387 sisusbcon_writew(a, p++);
388 }
389}
390
391#define SISUSB_VADDR(x,y) \
392 ((u16 *)c->vc_origin + \
393 (y) * sisusb->sisusb_num_columns + \
394 (x))
395
396#define SISUSB_HADDR(x,y) \
397 ((u16 *)(sisusb->vrambase + (c->vc_origin - sisusb->scrbuf)) + \
398 (y) * sisusb->sisusb_num_columns + \
399 (x))
400
401/* Interface routine */
402static void
403sisusbcon_putc(struct vc_data *c, int ch, int y, int x)
404{
405 struct sisusb_usb_data *sisusb;
406 ssize_t written;
407
408 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
409 return;
410
411 /* sisusb->lock is down */
412
413 /* Don't need to put the character into buffer ourselves,
414 * because the vt does this BEFORE calling us.
415 */
416#if 0
417 sisusbcon_writew(ch, SISUSB_VADDR(x, y));
418#endif
419
420 if (sisusb_is_inactive(c, sisusb)) {
421 up(&sisusb->lock);
422 return;
423 }
424
425
426 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
427 (u32)SISUSB_HADDR(x, y), 2, &written);
428
429 up(&sisusb->lock);
430}
431
432/* Interface routine */
433static void
434sisusbcon_putcs(struct vc_data *c, const unsigned short *s,
435 int count, int y, int x)
436{
437 struct sisusb_usb_data *sisusb;
438 ssize_t written;
439 u16 *dest;
440 int i;
441
442 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
443 return;
444
445 /* sisusb->lock is down */
446
447 /* Need to put the characters into the buffer ourselves,
448 * because the vt does this AFTER calling us.
449 */
450
451 dest = SISUSB_VADDR(x, y);
452
453 for (i = count; i > 0; i--)
454 sisusbcon_writew(sisusbcon_readw(s++), dest++);
455
456 if (sisusb_is_inactive(c, sisusb)) {
457 up(&sisusb->lock);
458 return;
459 }
460
461 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(x, y),
462 (u32)SISUSB_HADDR(x, y), count * 2, &written);
463
464 up(&sisusb->lock);
465}
466
467/* Interface routine */
468static void
469sisusbcon_clear(struct vc_data *c, int y, int x, int height, int width)
470{
471 struct sisusb_usb_data *sisusb;
472 u16 eattr = c->vc_video_erase_char;
473 ssize_t written;
474 int i, length, cols;
475 u16 *dest;
476
477 if (width <= 0 || height <= 0)
478 return;
479
480 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
481 return;
482
483 /* sisusb->lock is down */
484
485 /* Need to clear buffer ourselves, because the vt does
486 * this AFTER calling us.
487 */
488
489 dest = SISUSB_VADDR(x, y);
490
491 cols = sisusb->sisusb_num_columns;
492
493 if (width > cols)
494 width = cols;
495
496 if (x == 0 && width >= c->vc_cols) {
497
498 sisusbcon_memsetw(dest, eattr, height * cols * 2);
499
500 } else {
501
502 for (i = height; i > 0; i--, dest += cols)
503 sisusbcon_memsetw(dest, eattr, width * 2);
504
505 }
506
507 if (sisusb_is_inactive(c, sisusb)) {
508 up(&sisusb->lock);
509 return;
510 }
511
512 length = ((height * cols) - x - (cols - width - x)) * 2;
513
514
515 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(x, y),
516 (u32)SISUSB_HADDR(x, y), length, &written);
517
518 up(&sisusb->lock);
519}
520
521/* Interface routine */
522static void
523sisusbcon_bmove(struct vc_data *c, int sy, int sx,
524 int dy, int dx, int height, int width)
525{
526 struct sisusb_usb_data *sisusb;
527 ssize_t written;
528 int cols, length;
529#if 0
530 u16 *src, *dest;
531 int i;
532#endif
533
534 if (width <= 0 || height <= 0)
535 return;
536
537 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
538 return;
539
540 /* sisusb->lock is down */
541
542 cols = sisusb->sisusb_num_columns;
543
544 /* Don't need to move data outselves, because
545 * vt does this BEFORE calling us.
546 * This is only used by vt's insert/deletechar.
547 */
548#if 0
549 if (sx == 0 && dx == 0 && width >= c->vc_cols && width <= cols) {
550
551 sisusbcon_memmovew(SISUSB_VADDR(0, dy), SISUSB_VADDR(0, sy),
552 height * width * 2);
553
554 } else if (dy < sy || (dy == sy && dx < sx)) {
555
556 src = SISUSB_VADDR(sx, sy);
557 dest = SISUSB_VADDR(dx, dy);
558
559 for (i = height; i > 0; i--) {
560 sisusbcon_memmovew(dest, src, width * 2);
561 src += cols;
562 dest += cols;
563 }
564
565 } else {
566
567 src = SISUSB_VADDR(sx, sy + height - 1);
568 dest = SISUSB_VADDR(dx, dy + height - 1);
569
570 for (i = height; i > 0; i--) {
571 sisusbcon_memmovew(dest, src, width * 2);
572 src -= cols;
573 dest -= cols;
574 }
575
576 }
577#endif
578
579 if (sisusb_is_inactive(c, sisusb)) {
580 up(&sisusb->lock);
581 return;
582 }
583
584 length = ((height * cols) - dx - (cols - width - dx)) * 2;
585
586
587 sisusb_copy_memory(sisusb, (unsigned char *)SISUSB_VADDR(dx, dy),
588 (u32)SISUSB_HADDR(dx, dy), length, &written);
589
590 up(&sisusb->lock);
591}
592
593/* interface routine */
594static int
595sisusbcon_switch(struct vc_data *c)
596{
597 struct sisusb_usb_data *sisusb;
598 ssize_t written;
599 int length;
600
601 /* Returnvalue 0 means we have fully restored screen,
602 * and vt doesn't need to call do_update_region().
603 * Returnvalue != 0 naturally means the opposite.
604 */
605
606 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
607 return 0;
608
609 /* sisusb->lock is down */
610
611 /* Don't write to screen if in gfx mode */
612 if (sisusb_is_inactive(c, sisusb)) {
613 up(&sisusb->lock);
614 return 0;
615 }
616
617 /* That really should not happen. It would mean we are
618 * being called while the vc is using its private buffer
619 * as origin.
620 */
621 if (c->vc_origin == (unsigned long)c->vc_screenbuf) {
622 up(&sisusb->lock);
623 printk(KERN_DEBUG "sisusb: ASSERT ORIGIN != SCREENBUF!\n");
624 return 0;
625 }
626
627 /* Check that we don't copy too much */
628 length = min((int)c->vc_screenbuf_size,
629 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
630
631 /* Restore the screen contents */
632 sisusbcon_memcpyw((u16 *)c->vc_origin, (u16 *)c->vc_screenbuf,
633 length);
634
635 sisusb_copy_memory(sisusb, (unsigned char *)c->vc_origin,
636 (u32)SISUSB_HADDR(0, 0),
637 length, &written);
638
639 up(&sisusb->lock);
640
641 return 0;
642}
643
644/* interface routine */
645static void
646sisusbcon_save_screen(struct vc_data *c)
647{
648 struct sisusb_usb_data *sisusb;
649 int length;
650
651 /* Save the current screen contents to vc's private
652 * buffer.
653 */
654
655 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
656 return;
657
658 /* sisusb->lock is down */
659
660 if (sisusb_is_inactive(c, sisusb)) {
661 up(&sisusb->lock);
662 return;
663 }
664
665 /* Check that we don't copy too much */
666 length = min((int)c->vc_screenbuf_size,
667 (int)(sisusb->scrbuf + sisusb->scrbuf_size - c->vc_origin));
668
669 /* Save the screen contents to vc's private buffer */
670 sisusbcon_memcpyw((u16 *)c->vc_screenbuf, (u16 *)c->vc_origin,
671 length);
672
673 up(&sisusb->lock);
674}
675
676/* interface routine */
677static int
678sisusbcon_set_palette(struct vc_data *c, unsigned char *table)
679{
680 struct sisusb_usb_data *sisusb;
681 int i, j;
682
683 /* Return value not used by vt */
684
685 if (!CON_IS_VISIBLE(c))
686 return -EINVAL;
687
688 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
689 return -EINVAL;
690
691 /* sisusb->lock is down */
692
693 if (sisusb_is_inactive(c, sisusb)) {
694 up(&sisusb->lock);
695 return -EINVAL;
696 }
697
698 for (i = j = 0; i < 16; i++) {
699 if (sisusb_setreg(sisusb, SISCOLIDX, table[i]))
700 break;
701 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
702 break;
703 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
704 break;
705 if (sisusb_setreg(sisusb, SISCOLDATA, c->vc_palette[j++] >> 2))
706 break;
707 }
708
709 up(&sisusb->lock);
710
711 return 0;
712}
713
714/* interface routine */
715static int
716sisusbcon_blank(struct vc_data *c, int blank, int mode_switch)
717{
718 struct sisusb_usb_data *sisusb;
719 u8 sr1, cr17, pmreg, cr63;
720 ssize_t written;
721 int ret = 0;
722
723 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
724 return 0;
725
726 /* sisusb->lock is down */
727
728 if (mode_switch)
729 sisusb->is_gfx = blank ? 1 : 0;
730
731 if (sisusb_is_inactive(c, sisusb)) {
732 up(&sisusb->lock);
733 return 0;
734 }
735
736 switch (blank) {
737
738 case 1: /* Normal blanking: Clear screen */
739 case -1:
740 sisusbcon_memsetw((u16 *)c->vc_origin,
741 c->vc_video_erase_char,
742 c->vc_screenbuf_size);
743 sisusb_copy_memory(sisusb,
744 (unsigned char *)c->vc_origin,
745 (u32)(sisusb->vrambase +
746 (c->vc_origin - sisusb->scrbuf)),
747 c->vc_screenbuf_size, &written);
748 sisusb->con_blanked = 1;
749 ret = 1;
750 break;
751
752 default: /* VESA blanking */
753 switch (blank) {
754 case 0: /* Unblank */
755 sr1 = 0x00;
756 cr17 = 0x80;
757 pmreg = 0x00;
758 cr63 = 0x00;
759 ret = 1;
760 sisusb->con_blanked = 0;
761 break;
762 case VESA_VSYNC_SUSPEND + 1:
763 sr1 = 0x20;
764 cr17 = 0x80;
765 pmreg = 0x80;
766 cr63 = 0x40;
767 break;
768 case VESA_HSYNC_SUSPEND + 1:
769 sr1 = 0x20;
770 cr17 = 0x80;
771 pmreg = 0x40;
772 cr63 = 0x40;
773 break;
774 case VESA_POWERDOWN + 1:
775 sr1 = 0x20;
776 cr17 = 0x00;
777 pmreg = 0xc0;
778 cr63 = 0x40;
779 break;
780 default:
781 up(&sisusb->lock);
782 return -EINVAL;
783 }
784
785 sisusb_setidxregandor(sisusb, SISSR, 0x01, ~0x20, sr1);
786 sisusb_setidxregandor(sisusb, SISCR, 0x17, 0x7f, cr17);
787 sisusb_setidxregandor(sisusb, SISSR, 0x1f, 0x3f, pmreg);
788 sisusb_setidxregandor(sisusb, SISCR, 0x63, 0xbf, cr63);
789
790 }
791
792 up(&sisusb->lock);
793
794 return ret;
795}
796
797/* interface routine */
798static int
799sisusbcon_scrolldelta(struct vc_data *c, int lines)
800{
801 struct sisusb_usb_data *sisusb;
802 int margin = c->vc_size_row * 4;
803 int ul, we, p, st;
804
805 /* The return value does not seem to be used */
806
807 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
808 return 0;
809
810 /* sisusb->lock is down */
811
812 if (sisusb_is_inactive(c, sisusb)) {
813 up(&sisusb->lock);
814 return 0;
815 }
816
817 if (!lines) /* Turn scrollback off */
818 c->vc_visible_origin = c->vc_origin;
819 else {
820
821 if (sisusb->con_rolled_over >
822 (c->vc_scr_end - sisusb->scrbuf) + margin) {
823
824 ul = c->vc_scr_end - sisusb->scrbuf;
825 we = sisusb->con_rolled_over + c->vc_size_row;
826
827 } else {
828
829 ul = 0;
830 we = sisusb->scrbuf_size;
831
832 }
833
834 p = (c->vc_visible_origin - sisusb->scrbuf - ul + we) % we +
835 lines * c->vc_size_row;
836
837 st = (c->vc_origin - sisusb->scrbuf - ul + we) % we;
838
839 if (st < 2 * margin)
840 margin = 0;
841
842 if (p < margin)
843 p = 0;
844
845 if (p > st - margin)
846 p = st;
847
848 c->vc_visible_origin = sisusb->scrbuf + (p + ul) % we;
849 }
850
851 sisusbcon_set_start_address(sisusb, c);
852
853 up(&sisusb->lock);
854
855 return 1;
856}
857
858/* Interface routine */
859static void
860sisusbcon_cursor(struct vc_data *c, int mode)
861{
862 struct sisusb_usb_data *sisusb;
863 int from, to, baseline;
864
865 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
866 return;
867
868 /* sisusb->lock is down */
869
870 if (sisusb_is_inactive(c, sisusb)) {
871 up(&sisusb->lock);
872 return;
873 }
874
875 if (c->vc_origin != c->vc_visible_origin) {
876 c->vc_visible_origin = c->vc_origin;
877 sisusbcon_set_start_address(sisusb, c);
878 }
879
880 if (mode == CM_ERASE) {
881 sisusb_setidxregor(sisusb, SISCR, 0x0a, 0x20);
882 sisusb->sisusb_cursor_size_to = -1;
883 up(&sisusb->lock);
884 return;
885 }
886
887 sisusb_set_cursor(sisusb, (c->vc_pos - sisusb->scrbuf) / 2);
888
889 baseline = c->vc_font.height - (c->vc_font.height < 10 ? 1 : 2);
890
891 switch (c->vc_cursor_type & 0x0f) {
892 case CUR_BLOCK: from = 1;
893 to = c->vc_font.height;
894 break;
895 case CUR_TWO_THIRDS: from = c->vc_font.height / 3;
896 to = baseline;
897 break;
898 case CUR_LOWER_HALF: from = c->vc_font.height / 2;
899 to = baseline;
900 break;
901 case CUR_LOWER_THIRD: from = (c->vc_font.height * 2) / 3;
902 to = baseline;
903 break;
904 case CUR_NONE: from = 31;
905 to = 30;
906 break;
907 default:
908 case CUR_UNDERLINE: from = baseline - 1;
909 to = baseline;
910 break;
911 }
912
913 if (sisusb->sisusb_cursor_size_from != from ||
914 sisusb->sisusb_cursor_size_to != to) {
915
916 sisusb_setidxreg(sisusb, SISCR, 0x0a, from);
917 sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0, to);
918
919 sisusb->sisusb_cursor_size_from = from;
920 sisusb->sisusb_cursor_size_to = to;
921 }
922
923 up(&sisusb->lock);
924}
925
926static int
927sisusbcon_scroll_area(struct vc_data *c, struct sisusb_usb_data *sisusb,
928 int t, int b, int dir, int lines)
929{
930 int cols = sisusb->sisusb_num_columns;
931 int length = ((b - t) * cols) * 2;
932 u16 eattr = c->vc_video_erase_char;
933 ssize_t written;
934
935 /* sisusb->lock is down */
936
937 /* Scroll an area which does not match the
938 * visible screen's dimensions. This needs
939 * to be done separately, as it does not
940 * use hardware panning.
941 */
942
943 switch (dir) {
944
945 case SM_UP:
946 sisusbcon_memmovew(SISUSB_VADDR(0, t),
947 SISUSB_VADDR(0, t + lines),
948 (b - t - lines) * cols * 2);
949 sisusbcon_memsetw(SISUSB_VADDR(0, b - lines), eattr,
950 lines * cols * 2);
951 break;
952
953 case SM_DOWN:
954 sisusbcon_memmovew(SISUSB_VADDR(0, t + lines),
955 SISUSB_VADDR(0, t),
956 (b - t - lines) * cols * 2);
957 sisusbcon_memsetw(SISUSB_VADDR(0, t), eattr,
958 lines * cols * 2);
959 break;
960 }
961
962 sisusb_copy_memory(sisusb, (char *)SISUSB_VADDR(0, t),
963 (u32)SISUSB_HADDR(0, t), length, &written);
964
965 up(&sisusb->lock);
966
967 return 1;
968}
969
970/* Interface routine */
971static int
972sisusbcon_scroll(struct vc_data *c, int t, int b, int dir, int lines)
973{
974 struct sisusb_usb_data *sisusb;
975 u16 eattr = c->vc_video_erase_char;
976 ssize_t written;
977 int copyall = 0;
978 unsigned long oldorigin;
979 unsigned int delta = lines * c->vc_size_row;
980 u32 originoffset;
981
982 /* Returning != 0 means we have done the scrolling successfully.
983 * Returning 0 makes vt do the scrolling on its own.
984 * Note that con_scroll is only called if the console is
985 * visible. In that case, the origin should be our buffer,
986 * not the vt's private one.
987 */
988
989 if (!lines)
990 return 1;
991
992 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
993 return 0;
994
995 /* sisusb->lock is down */
996
997 if (sisusb_is_inactive(c, sisusb)) {
998 up(&sisusb->lock);
999 return 0;
1000 }
1001
1002 /* Special case */
1003 if (t || b != c->vc_rows)
1004 return sisusbcon_scroll_area(c, sisusb, t, b, dir, lines);
1005
1006 if (c->vc_origin != c->vc_visible_origin) {
1007 c->vc_visible_origin = c->vc_origin;
1008 sisusbcon_set_start_address(sisusb, c);
1009 }
1010
1011 /* limit amount to maximum realistic size */
1012 if (lines > c->vc_rows)
1013 lines = c->vc_rows;
1014
1015 oldorigin = c->vc_origin;
1016
1017 switch (dir) {
1018
1019 case SM_UP:
1020
1021 if (c->vc_scr_end + delta >=
1022 sisusb->scrbuf + sisusb->scrbuf_size) {
1023 sisusbcon_memcpyw((u16 *)sisusb->scrbuf,
1024 (u16 *)(oldorigin + delta),
1025 c->vc_screenbuf_size - delta);
1026 c->vc_origin = sisusb->scrbuf;
1027 sisusb->con_rolled_over = oldorigin - sisusb->scrbuf;
1028 copyall = 1;
1029 } else
1030 c->vc_origin += delta;
1031
1032 sisusbcon_memsetw(
1033 (u16 *)(c->vc_origin + c->vc_screenbuf_size - delta),
1034 eattr, delta);
1035
1036 break;
1037
1038 case SM_DOWN:
1039
1040 if (oldorigin - delta < sisusb->scrbuf) {
1041 sisusbcon_memmovew((u16 *)(sisusb->scrbuf +
1042 sisusb->scrbuf_size -
1043 c->vc_screenbuf_size +
1044 delta),
1045 (u16 *)oldorigin,
1046 c->vc_screenbuf_size - delta);
1047 c->vc_origin = sisusb->scrbuf +
1048 sisusb->scrbuf_size -
1049 c->vc_screenbuf_size;
1050 sisusb->con_rolled_over = 0;
1051 copyall = 1;
1052 } else
1053 c->vc_origin -= delta;
1054
1055 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
1056
1057 scr_memsetw((u16 *)(c->vc_origin), eattr, delta);
1058
1059 break;
1060 }
1061
1062 originoffset = (u32)(c->vc_origin - sisusb->scrbuf);
1063
1064 if (copyall)
1065 sisusb_copy_memory(sisusb,
1066 (char *)c->vc_origin,
1067 (u32)(sisusb->vrambase + originoffset),
1068 c->vc_screenbuf_size, &written);
1069 else if (dir == SM_UP)
1070 sisusb_copy_memory(sisusb,
1071 (char *)c->vc_origin + c->vc_screenbuf_size - delta,
1072 (u32)sisusb->vrambase + originoffset +
1073 c->vc_screenbuf_size - delta,
1074 delta, &written);
1075 else
1076 sisusb_copy_memory(sisusb,
1077 (char *)c->vc_origin,
1078 (u32)(sisusb->vrambase + originoffset),
1079 delta, &written);
1080
1081 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
1082 c->vc_visible_origin = c->vc_origin;
1083
1084 sisusbcon_set_start_address(sisusb, c);
1085
1086 c->vc_pos = c->vc_pos - oldorigin + c->vc_origin;
1087
1088 up(&sisusb->lock);
1089
1090 return 1;
1091}
1092
1093/* Interface routine */
1094static int
1095sisusbcon_set_origin(struct vc_data *c)
1096{
1097 struct sisusb_usb_data *sisusb;
1098
1099 /* Returning != 0 means we were successful.
1100 * Returning 0 will vt make to use its own
1101 * screenbuffer as the origin.
1102 */
1103
1104 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1105 return 0;
1106
1107 /* sisusb->lock is down */
1108
1109 if (sisusb_is_inactive(c, sisusb) || sisusb->con_blanked) {
1110 up(&sisusb->lock);
1111 return 0;
1112 }
1113
1114 c->vc_origin = c->vc_visible_origin = sisusb->scrbuf;
1115
1116 sisusbcon_set_start_address(sisusb, c);
1117
1118 sisusb->con_rolled_over = 0;
1119
1120 up(&sisusb->lock);
1121
1122 return 1;
1123}
1124
1125/* Interface routine */
1126static int
1127sisusbcon_resize(struct vc_data *c, unsigned int newcols, unsigned int newrows)
1128{
1129 struct sisusb_usb_data *sisusb;
1130 int fh;
1131
1132 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1133 return -ENODEV;
1134
1135 fh = sisusb->current_font_height;
1136
1137 up(&sisusb->lock);
1138
1139 /* We are quite unflexible as regards resizing. The vt code
1140 * handles sizes where the line length isn't equal the pitch
1141 * quite badly. As regards the rows, our panning tricks only
1142 * work well if the number of rows equals the visible number
1143 * of rows.
1144 */
1145
1146 if (newcols != 80 || c->vc_scan_lines / fh != newrows)
1147 return -EINVAL;
1148
1149 return 0;
1150}
1151
1152int
1153sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
1154 u8 *arg, int cmapsz, int ch512, int dorecalc,
1155 struct vc_data *c, int fh, int uplock)
1156{
1157 int font_select = 0x00, i, err = 0;
1158 u32 offset = 0;
1159 u8 dummy;
1160
1161 /* sisusb->lock is down */
1162
1163 /*
1164 * The default font is kept in slot 0.
1165 * A user font is loaded in slot 2 (256 ch)
1166 * or 2+3 (512 ch).
1167 */
1168
1169 if ((slot != 0 && slot != 2) || !fh) {
1170 if (uplock)
1171 up(&sisusb->lock);
1172 return -EINVAL;
1173 }
1174
1175 if (set)
1176 sisusb->font_slot = slot;
1177
1178 /* Default font is always 256 */
1179 if (slot == 0)
1180 ch512 = 0;
1181 else
1182 offset = 4 * cmapsz;
1183
1184 font_select = (slot == 0) ? 0x00 : (ch512 ? 0x0e : 0x0a);
1185
1186 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
1187 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x04); /* Write to plane 2 */
1188 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x07); /* Memory mode a0-bf */
1189 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset */
1190
1191 if (err)
1192 goto font_op_error;
1193
1194 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x03); /* Select plane read 2 */
1195 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x00); /* Disable odd/even */
1196 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x00); /* Address range a0-bf */
1197
1198 if (err)
1199 goto font_op_error;
1200
1201 if (arg) {
1202 if (set)
1203 for (i = 0; i < cmapsz; i++) {
1204 err |= sisusb_writeb(sisusb,
1205 sisusb->vrambase + offset + i,
1206 arg[i]);
1207 if (err)
1208 break;
1209 }
1210 else
1211 for (i = 0; i < cmapsz; i++) {
1212 err |= sisusb_readb(sisusb,
1213 sisusb->vrambase + offset + i,
1214 &arg[i]);
1215 if (err)
1216 break;
1217 }
1218
1219 /*
1220 * In 512-character mode, the character map is not contiguous if
1221 * we want to remain EGA compatible -- which we do
1222 */
1223
1224 if (ch512) {
1225 if (set)
1226 for (i = 0; i < cmapsz; i++) {
1227 err |= sisusb_writeb(sisusb,
1228 sisusb->vrambase + offset +
1229 (2 * cmapsz) + i,
1230 arg[cmapsz + i]);
1231 if (err)
1232 break;
1233 }
1234 else
1235 for (i = 0; i < cmapsz; i++) {
1236 err |= sisusb_readb(sisusb,
1237 sisusb->vrambase + offset +
1238 (2 * cmapsz) + i,
1239 &arg[cmapsz + i]);
1240 if (err)
1241 break;
1242 }
1243 }
1244 }
1245
1246 if (err)
1247 goto font_op_error;
1248
1249 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x01); /* Reset */
1250 err |= sisusb_setidxreg(sisusb, SISSR, 0x02, 0x03); /* Write to planes 0+1 */
1251 err |= sisusb_setidxreg(sisusb, SISSR, 0x04, 0x03); /* Memory mode a0-bf */
1252 if (set)
1253 sisusb_setidxreg(sisusb, SISSR, 0x03, font_select);
1254 err |= sisusb_setidxreg(sisusb, SISSR, 0x00, 0x03); /* Reset end */
1255
1256 if (err)
1257 goto font_op_error;
1258
1259 err |= sisusb_setidxreg(sisusb, SISGR, 0x04, 0x00); /* Select plane read 0 */
1260 err |= sisusb_setidxreg(sisusb, SISGR, 0x05, 0x10); /* Enable odd/even */
1261 err |= sisusb_setidxreg(sisusb, SISGR, 0x06, 0x06); /* Address range b8-bf */
1262
1263 if (err)
1264 goto font_op_error;
1265
1266 if ((set) && (ch512 != sisusb->current_font_512)) {
1267
1268 /* Font is shared among all our consoles.
1269 * And so is the hi_font_mask.
1270 */
1271 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1272 struct vc_data *c = vc_cons[i].d;
1273 if (c && c->vc_sw == &sisusb_con)
1274 c->vc_hi_font_mask = ch512 ? 0x0800 : 0;
1275 }
1276
1277 sisusb->current_font_512 = ch512;
1278
1279 /* color plane enable register:
1280 256-char: enable intensity bit
1281 512-char: disable intensity bit */
1282 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1283 sisusb_setreg(sisusb, SISAR, 0x12);
1284 sisusb_setreg(sisusb, SISAR, ch512 ? 0x07 : 0x0f);
1285
1286 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1287 sisusb_setreg(sisusb, SISAR, 0x20);
1288 sisusb_getreg(sisusb, SISINPSTAT, &dummy);
1289 }
1290
1291 if (dorecalc) {
1292
1293 /*
1294 * Adjust the screen to fit a font of a certain height
1295 */
1296
1297 unsigned char ovr, vde, fsr;
1298 int rows = 0, maxscan = 0;
1299
1300 if (c) {
1301
1302 /* Number of video rows */
1303 rows = c->vc_scan_lines / fh;
1304 /* Scan lines to actually display-1 */
1305 maxscan = rows * fh - 1;
1306
1307 /*printk(KERN_DEBUG "sisusb recalc rows %d maxscan %d fh %d sl %d\n",
1308 rows, maxscan, fh, c->vc_scan_lines);*/
1309
1310 sisusb_getidxreg(sisusb, SISCR, 0x07, &ovr);
1311 vde = maxscan & 0xff;
1312 ovr = (ovr & 0xbd) |
1313 ((maxscan & 0x100) >> 7) |
1314 ((maxscan & 0x200) >> 3);
1315 sisusb_setidxreg(sisusb, SISCR, 0x07, ovr);
1316 sisusb_setidxreg(sisusb, SISCR, 0x12, vde);
1317
1318 }
1319
1320 sisusb_getidxreg(sisusb, SISCR, 0x09, &fsr);
1321 fsr = (fsr & 0xe0) | (fh - 1);
1322 sisusb_setidxreg(sisusb, SISCR, 0x09, fsr);
1323 sisusb->current_font_height = fh;
1324
1325 sisusb->sisusb_cursor_size_from = -1;
1326 sisusb->sisusb_cursor_size_to = -1;
1327
1328 }
1329
1330 if (uplock)
1331 up(&sisusb->lock);
1332
1333 if (dorecalc && c) {
1334 int i, rows = c->vc_scan_lines / fh;
1335
1336 /* Now adjust our consoles' size */
1337
1338 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1339 struct vc_data *vc = vc_cons[i].d;
1340
1341 if (vc && vc->vc_sw == &sisusb_con) {
1342 if (CON_IS_VISIBLE(vc)) {
1343 vc->vc_sw->con_cursor(vc, CM_DRAW);
1344 }
1345 vc->vc_font.height = fh;
1346 vc_resize(vc, 0, rows);
1347 }
1348 }
1349 }
1350
1351 return 0;
1352
1353font_op_error:
1354 if (uplock)
1355 up(&sisusb->lock);
1356
1357 return -EIO;
1358}
1359
1360/* Interface routine */
1361static int
1362sisusbcon_font_set(struct vc_data *c, struct console_font *font,
1363 unsigned flags)
1364{
1365 struct sisusb_usb_data *sisusb;
1366 unsigned charcount = font->charcount;
1367
1368 if (font->width != 8 || (charcount != 256 && charcount != 512))
1369 return -EINVAL;
1370
1371 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1372 return -ENODEV;
1373
1374 /* sisusb->lock is down */
1375
1376 /* Save the user-provided font into a buffer. This
1377 * is used for restoring text mode after quitting
1378 * from X and for the con_getfont routine.
1379 */
1380 if (sisusb->font_backup) {
1381 if (sisusb->font_backup_size < charcount) {
1382 vfree(sisusb->font_backup);
1383 sisusb->font_backup = NULL;
1384 }
1385 }
1386
1387 if (!sisusb->font_backup)
1388 sisusb->font_backup = vmalloc(charcount * 32);
1389
1390 if (sisusb->font_backup) {
1391 memcpy(sisusb->font_backup, font->data, charcount * 32);
1392 sisusb->font_backup_size = charcount;
1393 sisusb->font_backup_height = font->height;
1394 sisusb->font_backup_512 = (charcount == 512) ? 1 : 0;
1395 }
1396
1397 /* do_font_op ups sisusb->lock */
1398
1399 return sisusbcon_do_font_op(sisusb, 1, 2, font->data,
1400 8192, (charcount == 512),
1401 (!(flags & KD_FONT_FLAG_DONT_RECALC)) ? 1 : 0,
1402 c, font->height, 1);
1403}
1404
1405/* Interface routine */
1406static int
1407sisusbcon_font_get(struct vc_data *c, struct console_font *font)
1408{
1409 struct sisusb_usb_data *sisusb;
1410
1411 if (!(sisusb = sisusb_get_sisusb_lock_and_check(c->vc_num)))
1412 return -ENODEV;
1413
1414 /* sisusb->lock is down */
1415
1416 font->width = 8;
1417 font->height = c->vc_font.height;
1418 font->charcount = 256;
1419
1420 if (!font->data) {
1421 up(&sisusb->lock);
1422 return 0;
1423 }
1424
1425 if (!sisusb->font_backup) {
1426 up(&sisusb->lock);
1427 return -ENODEV;
1428 }
1429
1430 /* Copy 256 chars only, like vgacon */
1431 memcpy(font->data, sisusb->font_backup, 256 * 32);
1432
1433 up(&sisusb->lock);
1434
1435 return 0;
1436}
1437
1438/*
1439 * The console `switch' structure for the sisusb console
1440 */
1441
1442static const struct consw sisusb_con = {
1443 .owner = THIS_MODULE,
1444 .con_startup = sisusbcon_startup,
1445 .con_init = sisusbcon_init,
1446 .con_deinit = sisusbcon_deinit,
1447 .con_clear = sisusbcon_clear,
1448 .con_putc = sisusbcon_putc,
1449 .con_putcs = sisusbcon_putcs,
1450 .con_cursor = sisusbcon_cursor,
1451 .con_scroll = sisusbcon_scroll,
1452 .con_bmove = sisusbcon_bmove,
1453 .con_switch = sisusbcon_switch,
1454 .con_blank = sisusbcon_blank,
1455 .con_font_set = sisusbcon_font_set,
1456 .con_font_get = sisusbcon_font_get,
1457 .con_set_palette = sisusbcon_set_palette,
1458 .con_scrolldelta = sisusbcon_scrolldelta,
1459 .con_build_attr = sisusbcon_build_attr,
1460 .con_invert_region = sisusbcon_invert_region,
1461 .con_set_origin = sisusbcon_set_origin,
1462 .con_save_screen = sisusbcon_save_screen,
1463 .con_resize = sisusbcon_resize,
1464};
1465
1466/* Our very own dummy console driver */
1467
1468static const char *sisusbdummycon_startup(void)
1469{
1470 return "SISUSBVGADUMMY";
1471}
1472
1473static void sisusbdummycon_init(struct vc_data *vc, int init)
1474{
1475 vc->vc_can_do_color = 1;
1476 if (init) {
1477 vc->vc_cols = 80;
1478 vc->vc_rows = 25;
1479 } else
1480 vc_resize(vc, 80, 25);
1481}
1482
1483static int sisusbdummycon_dummy(void)
1484{
1485 return 0;
1486}
1487
1488#define SISUSBCONDUMMY (void *)sisusbdummycon_dummy
1489
1490const struct consw sisusb_dummy_con = {
1491 .owner = THIS_MODULE,
1492 .con_startup = sisusbdummycon_startup,
1493 .con_init = sisusbdummycon_init,
1494 .con_deinit = SISUSBCONDUMMY,
1495 .con_clear = SISUSBCONDUMMY,
1496 .con_putc = SISUSBCONDUMMY,
1497 .con_putcs = SISUSBCONDUMMY,
1498 .con_cursor = SISUSBCONDUMMY,
1499 .con_scroll = SISUSBCONDUMMY,
1500 .con_bmove = SISUSBCONDUMMY,
1501 .con_switch = SISUSBCONDUMMY,
1502 .con_blank = SISUSBCONDUMMY,
1503 .con_font_set = SISUSBCONDUMMY,
1504 .con_font_get = SISUSBCONDUMMY,
1505 .con_font_default = SISUSBCONDUMMY,
1506 .con_font_copy = SISUSBCONDUMMY,
1507 .con_set_palette = SISUSBCONDUMMY,
1508 .con_scrolldelta = SISUSBCONDUMMY,
1509};
1510
1511int
1512sisusb_console_init(struct sisusb_usb_data *sisusb, int first, int last)
1513{
1514 int i, ret, minor = sisusb->minor;
1515
1516 down(&disconnect_sem);
1517
1518 down(&sisusb->lock);
1519
1520 /* Erm.. that should not happen */
1521 if (sisusb->haveconsole || !sisusb->SiS_Pr) {
1522 up(&sisusb->lock);
1523 up(&disconnect_sem);
1524 return 1;
1525 }
1526
1527 sisusb->con_first = first;
1528 sisusb->con_last = last;
1529
1530 if (first > last ||
1531 first > MAX_NR_CONSOLES ||
1532 last > MAX_NR_CONSOLES) {
1533 up(&sisusb->lock);
1534 up(&disconnect_sem);
1535 return 1;
1536 }
1537
1538 /* If gfxcore not initialized or no consoles given, quit graciously */
1539 if (!sisusb->gfxinit || first < 1 || last < 1) {
1540 up(&sisusb->lock);
1541 up(&disconnect_sem);
1542 return 0;
1543 }
1544
1545 sisusb->sisusb_cursor_loc = -1;
1546 sisusb->sisusb_cursor_size_from = -1;
1547 sisusb->sisusb_cursor_size_to = -1;
1548
1549 /* Set up text mode (and upload default font) */
1550 if (sisusb_reset_text_mode(sisusb, 1)) {
1551 up(&sisusb->lock);
1552 up(&disconnect_sem);
1553 printk(KERN_ERR
1554 "sisusbvga[%d]: Failed to set up text mode\n",
1555 minor);
1556 return 1;
1557 }
1558
1559 /* Initialize some gfx registers */
1560 sisusb_initialize(sisusb);
1561
1562 for (i = first - 1; i <= last - 1; i++) {
1563 /* Save sisusb for our interface routines */
1564 mysisusbs[i] = sisusb;
1565 }
1566
1567 /* Initial console setup */
1568 sisusb->sisusb_num_columns = 80;
1569
1570 /* Use a 32K buffer (matches b8000-bffff area) */
1571 sisusb->scrbuf_size = 32 * 1024;
1572
1573 /* Allocate screen buffer */
1574 if (!(sisusb->scrbuf = (unsigned long)vmalloc(sisusb->scrbuf_size))) {
1575 up(&sisusb->lock);
1576 up(&disconnect_sem);
1577 printk(KERN_ERR
1578 "sisusbvga[%d]: Failed to allocate screen buffer\n",
1579 minor);
1580 return 1;
1581 }
1582
1583 up(&sisusb->lock);
1584 up(&disconnect_sem);
1585
1586 /* Now grab the desired console(s) */
1587 ret = take_over_console(&sisusb_con, first - 1, last - 1, 0);
1588
1589 if (!ret)
1590 sisusb->haveconsole = 1;
1591 else {
1592 for (i = first - 1; i <= last - 1; i++)
1593 mysisusbs[i] = NULL;
1594 }
1595
1596 return ret;
1597}
1598
1599void
1600sisusb_console_exit(struct sisusb_usb_data *sisusb)
1601{
1602 int i;
1603
1604 /* This is called if the device is disconnected
1605 * and while disconnect and lock semaphores
1606 * are up. This should be save because we
1607 * can't lose our sisusb any other way but by
1608 * disconnection (and hence, the disconnect
1609 * sema is for protecting all other access
1610 * functions from disconnection, not the
1611 * other way round).
1612 */
1613
1614 /* Now what do we do in case of disconnection:
1615 * One alternative would be to simply call
1616 * give_up_console(). Nah, not a good idea.
1617 * give_up_console() is obviously buggy as it
1618 * only discards the consw pointer from the
1619 * driver_map, but doesn't adapt vc->vc_sw
1620 * of the affected consoles. Hence, the next
1621 * call to any of the console functions will
1622 * eventually take a trip to oops county.
1623 * Also, give_up_console for some reason
1624 * doesn't decrement our module refcount.
1625 * Instead, we switch our consoles to a private
1626 * dummy console. This, of course, keeps our
1627 * refcount up as well, but it works perfectly.
1628 */
1629
1630 if (sisusb->haveconsole) {
1631 for (i = 0; i < MAX_NR_CONSOLES; i++)
1632 if (sisusb->havethisconsole[i])
1633 take_over_console(&sisusb_dummy_con, i, i, 0);
1634 /* At this point, con_deinit for all our
1635 * consoles is executed by take_over_console().
1636 */
1637 sisusb->haveconsole = 0;
1638 }
1639
1640 vfree((void *)sisusb->scrbuf);
1641 sisusb->scrbuf = 0;
1642
1643 vfree(sisusb->font_backup);
1644 sisusb->font_backup = NULL;
1645}
1646
1647void __init sisusb_init_concode(void)
1648{
1649 int i;
1650
1651 for (i = 0; i < MAX_NR_CONSOLES; i++)
1652 mysisusbs[i] = NULL;
1653}
1654
1655#endif /* INCL_CON */
1656
1657
1658
diff --git a/drivers/usb/misc/sisusbvga/sisusb_init.c b/drivers/usb/misc/sisusbvga/sisusb_init.c
new file mode 100644
index 000000000000..f28bc240f9b6
--- /dev/null
+++ b/drivers/usb/misc/sisusbvga/sisusb_init.c
@@ -0,0 +1,1047 @@
1/*
2 * sisusb - usb kernel driver for SiS315(E) based USB2VGA dongles
3 *
4 * Display mode initializing code
5 *
6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 *
8 * If distributed as part of the Linux kernel, this code is licensed under the
9 * terms of the GPL v2.
10 *
11 * Otherwise, the following license terms apply:
12 *
13 * * Redistribution and use in source and binary forms, with or without
14 * * modification, are permitted provided that the following conditions
15 * * are met:
16 * * 1) Redistributions of source code must retain the above copyright
17 * * notice, this list of conditions and the following disclaimer.
18 * * 2) Redistributions in binary form must reproduce the above copyright
19 * * notice, this list of conditions and the following disclaimer in the
20 * * documentation and/or other materials provided with the distribution.
21 * * 3) The name of the author may not be used to endorse or promote products
22 * * derived from this software without specific prior written permission.
23 * *
24 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Thomas Winischhofer <thomas@winischhofer.net>
36 *
37 */
38
39#include <linux/config.h>
40#include <linux/version.h>
41#include <linux/module.h>
42#include <linux/kernel.h>
43#include <linux/errno.h>
44#include <linux/poll.h>
45#include <linux/init.h>
46#include <linux/slab.h>
47#include <linux/spinlock.h>
48#include <linux/kref.h>
49
50#include "sisusb.h"
51
52#ifdef INCL_SISUSB_CON
53
54#include "sisusb_init.h"
55
56/*********************************************/
57/* POINTER INITIALIZATION */
58/*********************************************/
59
60static void
61SiSUSB_InitPtr(struct SiS_Private *SiS_Pr)
62{
63 SiS_Pr->SiS_ModeResInfo = SiSUSB_ModeResInfo;
64 SiS_Pr->SiS_StandTable = SiSUSB_StandTable;
65
66 SiS_Pr->SiS_SModeIDTable = SiSUSB_SModeIDTable;
67 SiS_Pr->SiS_EModeIDTable = SiSUSB_EModeIDTable;
68 SiS_Pr->SiS_RefIndex = SiSUSB_RefIndex;
69 SiS_Pr->SiS_CRT1Table = SiSUSB_CRT1Table;
70
71 SiS_Pr->SiS_VCLKData = SiSUSB_VCLKData;
72}
73
74/*********************************************/
75/* HELPER: Get ModeID */
76/*********************************************/
77
78unsigned short
79SiSUSB_GetModeID(int HDisplay, int VDisplay, int Depth)
80{
81 unsigned short ModeIndex = 0;
82
83 switch (HDisplay)
84 {
85 case 320:
86 if (VDisplay == 200)
87 ModeIndex = ModeIndex_320x200[Depth];
88 else if (VDisplay == 240)
89 ModeIndex = ModeIndex_320x240[Depth];
90 break;
91 case 400:
92 if (VDisplay == 300)
93 ModeIndex = ModeIndex_400x300[Depth];
94 break;
95 case 512:
96 if (VDisplay == 384)
97 ModeIndex = ModeIndex_512x384[Depth];
98 break;
99 case 640:
100 if (VDisplay == 480)
101 ModeIndex = ModeIndex_640x480[Depth];
102 else if (VDisplay == 400)
103 ModeIndex = ModeIndex_640x400[Depth];
104 break;
105 case 720:
106 if (VDisplay == 480)
107 ModeIndex = ModeIndex_720x480[Depth];
108 else if (VDisplay == 576)
109 ModeIndex = ModeIndex_720x576[Depth];
110 break;
111 case 768:
112 if (VDisplay == 576)
113 ModeIndex = ModeIndex_768x576[Depth];
114 break;
115 case 800:
116 if (VDisplay == 600)
117 ModeIndex = ModeIndex_800x600[Depth];
118 else if (VDisplay == 480)
119 ModeIndex = ModeIndex_800x480[Depth];
120 break;
121 case 848:
122 if (VDisplay == 480)
123 ModeIndex = ModeIndex_848x480[Depth];
124 break;
125 case 856:
126 if (VDisplay == 480)
127 ModeIndex = ModeIndex_856x480[Depth];
128 break;
129 case 960:
130 if (VDisplay == 540)
131 ModeIndex = ModeIndex_960x540[Depth];
132 else if (VDisplay == 600)
133 ModeIndex = ModeIndex_960x600[Depth];
134 break;
135 case 1024:
136 if (VDisplay == 576)
137 ModeIndex = ModeIndex_1024x576[Depth];
138 else if (VDisplay == 768)
139 ModeIndex = ModeIndex_1024x768[Depth];
140 break;
141 case 1152:
142 if (VDisplay == 864)
143 ModeIndex = ModeIndex_1152x864[Depth];
144 break;
145 case 1280:
146 switch (VDisplay) {
147 case 720:
148 ModeIndex = ModeIndex_1280x720[Depth];
149 break;
150 case 768:
151 ModeIndex = ModeIndex_1280x768[Depth];
152 break;
153 case 1024:
154 ModeIndex = ModeIndex_1280x1024[Depth];
155 break;
156 }
157 }
158
159 return ModeIndex;
160}
161
162/*********************************************/
163/* HELPER: SetReg, GetReg */
164/*********************************************/
165
166static void
167SiS_SetReg(struct SiS_Private *SiS_Pr, unsigned long port,
168 unsigned short index, unsigned short data)
169{
170 sisusb_setidxreg(SiS_Pr->sisusb, port, index, data);
171}
172
173static void
174SiS_SetRegByte(struct SiS_Private *SiS_Pr, unsigned long port,
175 unsigned short data)
176{
177 sisusb_setreg(SiS_Pr->sisusb, port, data);
178}
179
180static unsigned char
181SiS_GetReg(struct SiS_Private *SiS_Pr, unsigned long port,
182 unsigned short index)
183{
184 u8 data;
185
186 sisusb_getidxreg(SiS_Pr->sisusb, port, index, &data);
187
188 return data;
189}
190
191static unsigned char
192SiS_GetRegByte(struct SiS_Private *SiS_Pr, unsigned long port)
193{
194 u8 data;
195
196 sisusb_getreg(SiS_Pr->sisusb, port, &data);
197
198 return data;
199}
200
201static void
202SiS_SetRegANDOR(struct SiS_Private *SiS_Pr, unsigned long port,
203 unsigned short index, unsigned short DataAND,
204 unsigned short DataOR)
205{
206 sisusb_setidxregandor(SiS_Pr->sisusb, port, index, DataAND, DataOR);
207}
208
209static void
210SiS_SetRegAND(struct SiS_Private *SiS_Pr, unsigned long port,
211 unsigned short index, unsigned short DataAND)
212{
213 sisusb_setidxregand(SiS_Pr->sisusb, port, index, DataAND);
214}
215
216static void
217SiS_SetRegOR(struct SiS_Private *SiS_Pr,unsigned long port,
218 unsigned short index, unsigned short DataOR)
219{
220 sisusb_setidxregor(SiS_Pr->sisusb, port, index, DataOR);
221}
222
223/*********************************************/
224/* HELPER: DisplayOn, DisplayOff */
225/*********************************************/
226
227static void
228SiS_DisplayOn(struct SiS_Private *SiS_Pr)
229{
230 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, 0xDF);
231}
232
233/*********************************************/
234/* HELPER: Init Port Addresses */
235/*********************************************/
236
237void
238SiSUSBRegInit(struct SiS_Private *SiS_Pr, unsigned long BaseAddr)
239{
240 SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
241 SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
242 SiS_Pr->SiS_P3c0 = BaseAddr + 0x10;
243 SiS_Pr->SiS_P3ce = BaseAddr + 0x1e;
244 SiS_Pr->SiS_P3c2 = BaseAddr + 0x12;
245 SiS_Pr->SiS_P3ca = BaseAddr + 0x1a;
246 SiS_Pr->SiS_P3c6 = BaseAddr + 0x16;
247 SiS_Pr->SiS_P3c7 = BaseAddr + 0x17;
248 SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
249 SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
250 SiS_Pr->SiS_P3cb = BaseAddr + 0x1b;
251 SiS_Pr->SiS_P3cc = BaseAddr + 0x1c;
252 SiS_Pr->SiS_P3cd = BaseAddr + 0x1d;
253 SiS_Pr->SiS_P3da = BaseAddr + 0x2a;
254 SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;
255}
256
257/*********************************************/
258/* HELPER: GetSysFlags */
259/*********************************************/
260
261static void
262SiS_GetSysFlags(struct SiS_Private *SiS_Pr)
263{
264 SiS_Pr->SiS_MyCR63 = 0x63;
265}
266
267/*********************************************/
268/* HELPER: Init PCI & Engines */
269/*********************************************/
270
271static void
272SiSInitPCIetc(struct SiS_Private *SiS_Pr)
273{
274 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x20, 0xa1);
275 /* - Enable 2D (0x40)
276 * - Enable 3D (0x02)
277 * - Enable 3D vertex command fetch (0x10)
278 * - Enable 3D command parser (0x08)
279 * - Enable 3D G/L transformation engine (0x80)
280 */
281 SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1E, 0xDA);
282}
283
284/*********************************************/
285/* HELPER: SET SEGMENT REGISTERS */
286/*********************************************/
287
288static void
289SiS_SetSegRegLower(struct SiS_Private *SiS_Pr, unsigned short value)
290{
291 unsigned short temp;
292
293 value &= 0x00ff;
294 temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb) & 0xf0;
295 temp |= (value >> 4);
296 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb, temp);
297 temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd) & 0xf0;
298 temp |= (value & 0x0f);
299 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd, temp);
300}
301
302static void
303SiS_SetSegRegUpper(struct SiS_Private *SiS_Pr, unsigned short value)
304{
305 unsigned short temp;
306
307 value &= 0x00ff;
308 temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb) & 0x0f;
309 temp |= (value & 0xf0);
310 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cb, temp);
311 temp = SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd) & 0x0f;
312 temp |= (value << 4);
313 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3cd, temp);
314}
315
316static void
317SiS_SetSegmentReg(struct SiS_Private *SiS_Pr, unsigned short value)
318{
319 SiS_SetSegRegLower(SiS_Pr, value);
320 SiS_SetSegRegUpper(SiS_Pr, value);
321}
322
323static void
324SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr)
325{
326 SiS_SetSegmentReg(SiS_Pr, 0);
327}
328
329static void
330SiS_SetSegmentRegOver(struct SiS_Private *SiS_Pr, unsigned short value)
331{
332 unsigned short temp = value >> 8;
333
334 temp &= 0x07;
335 temp |= (temp << 4);
336 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1d, temp);
337 SiS_SetSegmentReg(SiS_Pr, value);
338}
339
340static void
341SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr)
342{
343 SiS_SetSegmentRegOver(SiS_Pr, 0);
344}
345
346static void
347SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr)
348{
349 SiS_ResetSegmentReg(SiS_Pr);
350 SiS_ResetSegmentRegOver(SiS_Pr);
351}
352
353/*********************************************/
354/* HELPER: SearchModeID */
355/*********************************************/
356
357static int
358SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
359 unsigned short *ModeIdIndex)
360{
361 if ((*ModeNo) <= 0x13) {
362
363 if ((*ModeNo) != 0x03)
364 return 0;
365
366 (*ModeIdIndex) = 0;
367
368 } else {
369
370 for(*ModeIdIndex = 0; ;(*ModeIdIndex)++) {
371
372 if (SiS_Pr->SiS_EModeIDTable[*ModeIdIndex].Ext_ModeID == (*ModeNo))
373 break;
374
375 if (SiS_Pr->SiS_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
376 return 0;
377 }
378
379 }
380
381 return 1;
382}
383
384/*********************************************/
385/* HELPER: ENABLE CRT1 */
386/*********************************************/
387
388static void
389SiS_HandleCRT1(struct SiS_Private *SiS_Pr)
390{
391 /* Enable CRT1 gating */
392 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4, SiS_Pr->SiS_MyCR63, 0xbf);
393}
394
395/*********************************************/
396/* HELPER: GetColorDepth */
397/*********************************************/
398
399static unsigned short
400SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
401 unsigned short ModeIdIndex)
402{
403 static const unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8};
404 unsigned short modeflag;
405 short index;
406
407 if (ModeNo <= 0x13) {
408 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
409 } else {
410 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
411 }
412
413 index = (modeflag & ModeTypeMask) - ModeEGA;
414 if (index < 0) index = 0;
415 return ColorDepth[index];
416}
417
418/*********************************************/
419/* HELPER: GetOffset */
420/*********************************************/
421
422static unsigned short
423SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
424 unsigned short ModeIdIndex, unsigned short rrti)
425{
426 unsigned short xres, temp, colordepth, infoflag;
427
428 infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag;
429 xres = SiS_Pr->SiS_RefIndex[rrti].XRes;
430
431 colordepth = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex);
432
433 temp = xres / 16;
434
435 if (infoflag & InterlaceMode)
436 temp <<= 1;
437
438 temp *= colordepth;
439
440 if (xres % 16)
441 temp += (colordepth >> 1);
442
443 return temp;
444}
445
446/*********************************************/
447/* SEQ */
448/*********************************************/
449
450static void
451SiS_SetSeqRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
452{
453 unsigned char SRdata;
454 int i;
455
456 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x00, 0x03);
457
458 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0] | 0x20;
459 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, SRdata);
460
461 for(i = 2; i <= 4; i++) {
462 SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i-1];
463 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, i, SRdata);
464 }
465}
466
467/*********************************************/
468/* MISC */
469/*********************************************/
470
471static void
472SiS_SetMiscRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
473{
474 unsigned char Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC;
475
476 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c2, Miscdata);
477}
478
479/*********************************************/
480/* CRTC */
481/*********************************************/
482
483static void
484SiS_SetCRTCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
485{
486 unsigned char CRTCdata;
487 unsigned short i;
488
489 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4, 0x11, 0x7f);
490
491 for(i = 0; i <= 0x18; i++) {
492 CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
493 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, i, CRTCdata);
494 }
495}
496
497/*********************************************/
498/* ATT */
499/*********************************************/
500
501static void
502SiS_SetATTRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
503{
504 unsigned char ARdata;
505 unsigned short i;
506
507 for(i = 0; i <= 0x13; i++) {
508 ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i];
509 SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da);
510 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, i);
511 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, ARdata);
512 }
513 SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da);
514 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x14);
515 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x00);
516
517 SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da);
518 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c0, 0x20);
519 SiS_GetRegByte(SiS_Pr, SiS_Pr->SiS_P3da);
520}
521
522/*********************************************/
523/* GRC */
524/*********************************************/
525
526static void
527SiS_SetGRCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
528{
529 unsigned char GRdata;
530 unsigned short i;
531
532 for(i = 0; i <= 0x08; i++) {
533 GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i];
534 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3ce, i, GRdata);
535 }
536
537 if (SiS_Pr->SiS_ModeType > ModeVGA) {
538 /* 256 color disable */
539 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3ce, 0x05, 0xBF);
540 }
541}
542
543/*********************************************/
544/* CLEAR EXTENDED REGISTERS */
545/*********************************************/
546
547static void
548SiS_ClearExt1Regs(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
549{
550 int i;
551
552 for(i = 0x0A; i <= 0x0E; i++) {
553 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, i, 0x00);
554 }
555
556 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x37, 0xFE);
557}
558
559/*********************************************/
560/* Get rate index */
561/*********************************************/
562
563static unsigned short
564SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
565 unsigned short ModeIdIndex)
566{
567 unsigned short rrti, i, index, temp;
568
569 if (ModeNo <= 0x13)
570 return 0xFFFF;
571
572 index = SiS_GetReg(SiS_Pr,SiS_Pr->SiS_P3d4, 0x33) & 0x0F;
573 if (index > 0) index--;
574
575 rrti = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
576 ModeNo = SiS_Pr->SiS_RefIndex[rrti].ModeID;
577
578 i = 0;
579 do {
580 if (SiS_Pr->SiS_RefIndex[rrti + i].ModeID != ModeNo)
581 break;
582
583 temp = SiS_Pr->SiS_RefIndex[rrti + i].Ext_InfoFlag & ModeTypeMask;
584 if (temp < SiS_Pr->SiS_ModeType)
585 break;
586
587 i++;
588 index--;
589 } while(index != 0xFFFF);
590
591 i--;
592
593 return (rrti + i);
594}
595
596/*********************************************/
597/* SYNC */
598/*********************************************/
599
600static void
601SiS_SetCRT1Sync(struct SiS_Private *SiS_Pr, unsigned short rrti)
602{
603 unsigned short sync = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag >> 8;
604 sync &= 0xC0;
605 sync |= 0x2f;
606 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c2, sync);
607}
608
609/*********************************************/
610/* CRTC/2 */
611/*********************************************/
612
613static void
614SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
615 unsigned short ModeIdIndex, unsigned short rrti)
616{
617 unsigned char index;
618 unsigned short temp, i, j, modeflag;
619
620 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3d4,0x11,0x7f);
621
622 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
623
624 index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRT1CRTC;
625
626 for(i = 0,j = 0; i <= 7; i++, j++) {
627 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j,
628 SiS_Pr->SiS_CRT1Table[index].CR[i]);
629 }
630 for(j = 0x10; i <= 10; i++, j++) {
631 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j,
632 SiS_Pr->SiS_CRT1Table[index].CR[i]);
633 }
634 for(j = 0x15; i <= 12; i++, j++) {
635 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, j,
636 SiS_Pr->SiS_CRT1Table[index].CR[i]);
637 }
638 for(j = 0x0A; i <= 15; i++, j++) {
639 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, j,
640 SiS_Pr->SiS_CRT1Table[index].CR[i]);
641 }
642
643 temp = SiS_Pr->SiS_CRT1Table[index].CR[16] & 0xE0;
644 SiS_SetReg(SiS_Pr,SiS_Pr->SiS_P3c4, 0x0E, temp);
645
646 temp = ((SiS_Pr->SiS_CRT1Table[index].CR[16]) & 0x01) << 5;
647 if (modeflag & DoubleScanMode) temp |= 0x80;
648 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3d4, 0x09, 0x5F, temp);
649
650 if (SiS_Pr->SiS_ModeType > ModeVGA)
651 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x14, 0x4F);
652}
653
654/*********************************************/
655/* OFFSET & PITCH */
656/*********************************************/
657/* (partly overruled by SetPitch() in XF86) */
658/*********************************************/
659
660static void
661SiS_SetCRT1Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
662 unsigned short ModeIdIndex, unsigned short rrti)
663{
664 unsigned short du = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, rrti);
665 unsigned short infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag;
666 unsigned short temp;
667
668 temp = (du >> 8) & 0x0f;
669 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0E, 0xF0, temp);
670
671 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x13, (du & 0xFF));
672
673 if (infoflag & InterlaceMode) du >>= 1;
674
675 du <<= 5;
676 temp = (du >> 8) & 0xff;
677 if (du & 0xff) temp++;
678 temp++;
679 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x10, temp);
680}
681
682/*********************************************/
683/* VCLK */
684/*********************************************/
685
686static void
687SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
688 unsigned short rrti)
689{
690 unsigned short index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRTVCLK;
691 unsigned short clka = SiS_Pr->SiS_VCLKData[index].SR2B;
692 unsigned short clkb = SiS_Pr->SiS_VCLKData[index].SR2C;
693
694 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4,0x31,0xCF);
695
696 SiS_SetReg(SiS_Pr,SiS_Pr->SiS_P3c4,0x2B,clka);
697 SiS_SetReg(SiS_Pr,SiS_Pr->SiS_P3c4,0x2C,clkb);
698 SiS_SetReg(SiS_Pr,SiS_Pr->SiS_P3c4,0x2D,0x01);
699}
700
701/*********************************************/
702/* FIFO */
703/*********************************************/
704
705static void
706SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
707 unsigned short mi)
708{
709 unsigned short modeflag = SiS_Pr->SiS_EModeIDTable[mi].Ext_ModeFlag;
710
711 /* disable auto-threshold */
712 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x3D, 0xFE);
713
714 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x08, 0xAE);
715 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x09, 0xF0);
716
717 if (ModeNo <= 0x13)
718 return;
719
720 if ((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) {
721 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x08, 0x34);
722 SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x3D, 0x01);
723 }
724}
725
726/*********************************************/
727/* MODE REGISTERS */
728/*********************************************/
729
730static void
731SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
732 unsigned short rrti)
733{
734 unsigned short data = 0, VCLK = 0, index = 0;
735
736 if (ModeNo > 0x13) {
737 index = SiS_Pr->SiS_RefIndex[rrti].Ext_CRTVCLK;
738 VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
739 }
740
741 if (VCLK >= 166) data |= 0x0c;
742 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x32, 0xf3, data);
743
744 if (VCLK >= 166)
745 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1f, 0xe7);
746
747 /* DAC speed */
748 data = 0x03;
749 if (VCLK >= 260)
750 data = 0x00;
751 else if (VCLK >= 160)
752 data = 0x01;
753 else if (VCLK >= 135)
754 data = 0x02;
755
756 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x07, 0xF8, data);
757}
758
759static void
760SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
761 unsigned short ModeIdIndex, unsigned short rrti)
762{
763 unsigned short data, infoflag = 0, modeflag;
764
765 if (ModeNo <= 0x13)
766 modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
767 else {
768 modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
769 infoflag = SiS_Pr->SiS_RefIndex[rrti].Ext_InfoFlag;
770 }
771
772 /* Disable DPMS */
773 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x1F, 0x3F);
774
775 data = 0;
776 if (ModeNo > 0x13) {
777 if (SiS_Pr->SiS_ModeType > ModeEGA) {
778 data |= 0x02;
779 data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2);
780 }
781 if (infoflag & InterlaceMode) data |= 0x20;
782 }
783 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x06, 0xC0, data);
784
785 data = 0;
786 if (infoflag & InterlaceMode) {
787 /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
788 unsigned short hrs = (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x04) |
789 ((SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0b) & 0xc0) << 2)) - 3;
790 unsigned short hto = (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x00) |
791 ((SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0b) & 0x03) << 8)) + 5;
792 data = hrs - (hto >> 1) + 3;
793 }
794 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x19, (data & 0xFF));
795 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3d4, 0x1a, 0xFC, (data >> 8));
796
797 if (modeflag & HalfDCLK)
798 SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x01, 0x08);
799
800 data = 0;
801 if (modeflag & LineCompareOff)
802 data = 0x08;
803 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0F, 0xB7, data);
804
805 if ((SiS_Pr->SiS_ModeType == ModeEGA) && (ModeNo > 0x13))
806 SiS_SetRegOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x0F, 0x40);
807
808 SiS_SetRegAND(SiS_Pr, SiS_Pr->SiS_P3c4, 0x31, 0xfb);
809
810 data = 0x60;
811 if (SiS_Pr->SiS_ModeType != ModeText) {
812 data ^= 0x60;
813 if (SiS_Pr->SiS_ModeType != ModeEGA)
814 data ^= 0xA0;
815 }
816 SiS_SetRegANDOR(SiS_Pr, SiS_Pr->SiS_P3c4, 0x21, 0x1F, data);
817
818 SiS_SetVCLKState(SiS_Pr, ModeNo, rrti);
819
820 if (SiS_GetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x31) & 0x40)
821 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x52, 0x2c);
822 else
823 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x52, 0x6c);
824}
825
826/*********************************************/
827/* LOAD DAC */
828/*********************************************/
829
830static void
831SiS_WriteDAC(struct SiS_Private *SiS_Pr, unsigned long DACData,
832 unsigned short shiftflag, unsigned short dl, unsigned short ah,
833 unsigned short al, unsigned short dh)
834{
835 unsigned short d1, d2, d3;
836
837 switch (dl) {
838 case 0:
839 d1 = dh; d2 = ah; d3 = al;
840 break;
841 case 1:
842 d1 = ah; d2 = al; d3 = dh;
843 break;
844 default:
845 d1 = al; d2 = dh; d3 = ah;
846 }
847 SiS_SetRegByte(SiS_Pr, DACData, (d1 << shiftflag));
848 SiS_SetRegByte(SiS_Pr, DACData, (d2 << shiftflag));
849 SiS_SetRegByte(SiS_Pr, DACData, (d3 << shiftflag));
850}
851
852static void
853SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short mi)
854{
855 unsigned short data, data2, time, i, j, k, m, n, o;
856 unsigned short si, di, bx, sf;
857 unsigned long DACAddr, DACData;
858 const unsigned char *table = NULL;
859
860 if (ModeNo < 0x13)
861 data = SiS_Pr->SiS_SModeIDTable[mi].St_ModeFlag;
862 else
863 data = SiS_Pr->SiS_EModeIDTable[mi].Ext_ModeFlag;
864
865 data &= DACInfoFlag;
866
867 j = time = 64;
868 if (data == 0x00)
869 table = SiS_MDA_DAC;
870 else if (data == 0x08)
871 table = SiS_CGA_DAC;
872 else if (data == 0x10)
873 table = SiS_EGA_DAC;
874 else {
875 j = 16;
876 time = 256;
877 table = SiS_VGA_DAC;
878 }
879
880 DACAddr = SiS_Pr->SiS_P3c8;
881 DACData = SiS_Pr->SiS_P3c9;
882 sf = 0;
883 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c6, 0xFF);
884
885 SiS_SetRegByte(SiS_Pr, DACAddr, 0x00);
886
887 for(i = 0; i < j; i++) {
888 data = table[i];
889 for(k = 0; k < 3; k++) {
890 data2 = 0;
891 if (data & 0x01) data2 += 0x2A;
892 if (data & 0x02) data2 += 0x15;
893 SiS_SetRegByte(SiS_Pr, DACData, (data2 << sf));
894 data >>= 2;
895 }
896 }
897
898 if (time == 256) {
899 for(i = 16; i < 32; i++) {
900 data = table[i] << sf;
901 for(k = 0; k < 3; k++)
902 SiS_SetRegByte(SiS_Pr, DACData, data);
903 }
904 si = 32;
905 for(m = 0; m < 9; m++) {
906 di = si;
907 bx = si + 4;
908 for(n = 0; n < 3; n++) {
909 for(o = 0; o < 5; o++) {
910 SiS_WriteDAC(SiS_Pr, DACData, sf, n,
911 table[di], table[bx], table[si]);
912 si++;
913 }
914 si -= 2;
915 for(o = 0; o < 3; o++) {
916 SiS_WriteDAC(SiS_Pr, DACData, sf, n,
917 table[di], table[si], table[bx]);
918 si--;
919 }
920 }
921 si += 5;
922 }
923 }
924}
925
926/*********************************************/
927/* SET CRT1 REGISTER GROUP */
928/*********************************************/
929
930static void
931SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
932 unsigned short ModeIdIndex)
933{
934 unsigned short StandTableIndex, rrti;
935
936 SiS_Pr->SiS_CRT1Mode = ModeNo;
937
938 if (ModeNo <= 0x13)
939 StandTableIndex = 0;
940 else
941 StandTableIndex = 1;
942
943 SiS_ResetSegmentRegisters(SiS_Pr);
944 SiS_SetSeqRegs(SiS_Pr, StandTableIndex);
945 SiS_SetMiscRegs(SiS_Pr, StandTableIndex);
946 SiS_SetCRTCRegs(SiS_Pr, StandTableIndex);
947 SiS_SetATTRegs(SiS_Pr, StandTableIndex);
948 SiS_SetGRCRegs(SiS_Pr, StandTableIndex);
949 SiS_ClearExt1Regs(SiS_Pr, ModeNo);
950
951 rrti = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
952
953 if (rrti != 0xFFFF) {
954 SiS_SetCRT1Sync(SiS_Pr, rrti);
955 SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, rrti);
956 SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, rrti);
957 SiS_SetCRT1VCLK(SiS_Pr, ModeNo, rrti);
958 }
959
960 SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex);
961
962 SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, rrti);
963
964 SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
965
966 SiS_DisplayOn(SiS_Pr);
967}
968
969/*********************************************/
970/* SiSSetMode() */
971/*********************************************/
972
973int
974SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
975{
976 unsigned short ModeIdIndex;
977 unsigned long BaseAddr = SiS_Pr->IOAddress;
978
979 SiSUSB_InitPtr(SiS_Pr);
980 SiSUSBRegInit(SiS_Pr, BaseAddr);
981 SiS_GetSysFlags(SiS_Pr);
982
983 if (!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex)))
984 return 0;
985
986 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3c4, 0x05, 0x86);
987
988 SiSInitPCIetc(SiS_Pr);
989
990 ModeNo &= 0x7f;
991
992 SiS_Pr->SiS_ModeType =
993 SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag & ModeTypeMask;
994
995 SiS_Pr->SiS_SetFlag = LowModeTests;
996
997 /* Set mode on CRT1 */
998 SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
999
1000 SiS_HandleCRT1(SiS_Pr);
1001
1002 SiS_DisplayOn(SiS_Pr);
1003 SiS_SetRegByte(SiS_Pr, SiS_Pr->SiS_P3c6, 0xFF);
1004
1005 /* Store mode number */
1006 SiS_SetReg(SiS_Pr, SiS_Pr->SiS_P3d4, 0x34, ModeNo);
1007
1008 return 1;
1009}
1010
1011int
1012SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo)
1013{
1014 unsigned short ModeNo = 0;
1015 int i;
1016
1017 SiSUSB_InitPtr(SiS_Pr);
1018
1019 if (VModeNo == 0x03) {
1020
1021 ModeNo = 0x03;
1022
1023 } else {
1024
1025 i = 0;
1026 do {
1027
1028 if (SiS_Pr->SiS_EModeIDTable[i].Ext_VESAID == VModeNo) {
1029 ModeNo = SiS_Pr->SiS_EModeIDTable[i].Ext_ModeID;
1030 break;
1031 }
1032
1033 } while (SiS_Pr->SiS_EModeIDTable[i++].Ext_ModeID != 0xff);
1034
1035 }
1036
1037 if (!ModeNo)
1038 return 0;
1039
1040 return SiSUSBSetMode(SiS_Pr, ModeNo);
1041}
1042
1043#endif /* INCL_SISUSB_CON */
1044
1045
1046
1047
diff --git a/drivers/usb/misc/sisusbvga/sisusb_init.h b/drivers/usb/misc/sisusbvga/sisusb_init.h
new file mode 100644
index 000000000000..5b11577835c8
--- /dev/null
+++ b/drivers/usb/misc/sisusbvga/sisusb_init.h
@@ -0,0 +1,830 @@
1/* $XFree86$ */
2/* $XdotOrg$ */
3/*
4 * Data and prototypes for init.c
5 *
6 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
7 *
8 * If distributed as part of the Linux kernel, the following license terms
9 * apply:
10 *
11 * * This program is free software; you can redistribute it and/or modify
12 * * it under the terms of the GNU General Public License as published by
13 * * the Free Software Foundation; either version 2 of the named License,
14 * * or any later version.
15 * *
16 * * This program is distributed in the hope that it will be useful,
17 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * * GNU General Public License for more details.
20 * *
21 * * You should have received a copy of the GNU General Public License
22 * * along with this program; if not, write to the Free Software
23 * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
24 *
25 * Otherwise, the following license terms apply:
26 *
27 * * Redistribution and use in source and binary forms, with or without
28 * * modification, are permitted provided that the following conditions
29 * * are met:
30 * * 1) Redistributions of source code must retain the above copyright
31 * * notice, this list of conditions and the following disclaimer.
32 * * 2) Redistributions in binary form must reproduce the above copyright
33 * * notice, this list of conditions and the following disclaimer in the
34 * * documentation and/or other materials provided with the distribution.
35 * * 3) The name of the author may not be used to endorse or promote products
36 * * derived from this software without specific prior written permission.
37 * *
38 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
41 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
42 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
47 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 *
49 * Author: Thomas Winischhofer <thomas@winischhofer.net>
50 *
51 */
52
53#ifndef _SISUSB_INIT_H_
54#define _SISUSB_INIT_H_
55
56/* SiS_ModeType */
57#define ModeText 0x00
58#define ModeCGA 0x01
59#define ModeEGA 0x02
60#define ModeVGA 0x03
61#define Mode15Bpp 0x04
62#define Mode16Bpp 0x05
63#define Mode24Bpp 0x06
64#define Mode32Bpp 0x07
65
66#define ModeTypeMask 0x07
67#define IsTextMode 0x07
68
69#define DACInfoFlag 0x0018
70#define MemoryInfoFlag 0x01E0
71#define MemorySizeShift 5
72
73/* modeflag */
74#define Charx8Dot 0x0200
75#define LineCompareOff 0x0400
76#define CRT2Mode 0x0800
77#define HalfDCLK 0x1000
78#define NoSupportSimuTV 0x2000
79#define NoSupportLCDScale 0x4000 /* SiS bridge: No scaling possible (no matter what panel) */
80#define DoubleScanMode 0x8000
81
82/* Infoflag */
83#define SupportTV 0x0008
84#define SupportTV1024 0x0800
85#define SupportCHTV 0x0800
86#define Support64048060Hz 0x0800 /* Special for 640x480 LCD */
87#define SupportHiVision 0x0010
88#define SupportYPbPr750p 0x1000
89#define SupportLCD 0x0020
90#define SupportRAMDAC2 0x0040 /* All (<= 100Mhz) */
91#define SupportRAMDAC2_135 0x0100 /* All except DH (<= 135Mhz) */
92#define SupportRAMDAC2_162 0x0200 /* B, C (<= 162Mhz) */
93#define SupportRAMDAC2_202 0x0400 /* C (<= 202Mhz) */
94#define InterlaceMode 0x0080
95#define SyncPP 0x0000
96#define SyncPN 0x4000
97#define SyncNP 0x8000
98#define SyncNN 0xc000
99
100/* SetFlag */
101#define ProgrammingCRT2 0x0001
102#define LowModeTests 0x0002
103#define LCDVESATiming 0x0008
104#define EnableLVDSDDA 0x0010
105#define SetDispDevSwitchFlag 0x0020
106#define CheckWinDos 0x0040
107#define SetDOSMode 0x0080
108
109/* Index in ModeResInfo table */
110#define SIS_RI_320x200 0
111#define SIS_RI_320x240 1
112#define SIS_RI_320x400 2
113#define SIS_RI_400x300 3
114#define SIS_RI_512x384 4
115#define SIS_RI_640x400 5
116#define SIS_RI_640x480 6
117#define SIS_RI_800x600 7
118#define SIS_RI_1024x768 8
119#define SIS_RI_1280x1024 9
120#define SIS_RI_1600x1200 10
121#define SIS_RI_1920x1440 11
122#define SIS_RI_2048x1536 12
123#define SIS_RI_720x480 13
124#define SIS_RI_720x576 14
125#define SIS_RI_1280x960 15
126#define SIS_RI_800x480 16
127#define SIS_RI_1024x576 17
128#define SIS_RI_1280x720 18
129#define SIS_RI_856x480 19
130#define SIS_RI_1280x768 20
131#define SIS_RI_1400x1050 21
132#define SIS_RI_1152x864 22 /* Up to here SiS conforming */
133#define SIS_RI_848x480 23
134#define SIS_RI_1360x768 24
135#define SIS_RI_1024x600 25
136#define SIS_RI_1152x768 26
137#define SIS_RI_768x576 27
138#define SIS_RI_1360x1024 28
139#define SIS_RI_1680x1050 29
140#define SIS_RI_1280x800 30
141#define SIS_RI_1920x1080 31
142#define SIS_RI_960x540 32
143#define SIS_RI_960x600 33
144
145#define SIS_VIDEO_CAPTURE 0x00 - 0x30
146#define SIS_VIDEO_PLAYBACK 0x02 - 0x30
147#define SIS_CRT2_PORT_04 0x04 - 0x30
148
149/* Mode numbers */
150static const unsigned short ModeIndex_320x200[] = {0x59, 0x41, 0x00, 0x4f};
151static const unsigned short ModeIndex_320x240[] = {0x50, 0x56, 0x00, 0x53};
152static const unsigned short ModeIndex_400x300[] = {0x51, 0x57, 0x00, 0x54};
153static const unsigned short ModeIndex_512x384[] = {0x52, 0x58, 0x00, 0x5c};
154static const unsigned short ModeIndex_640x400[] = {0x2f, 0x5d, 0x00, 0x5e};
155static const unsigned short ModeIndex_640x480[] = {0x2e, 0x44, 0x00, 0x62};
156static const unsigned short ModeIndex_720x480[] = {0x31, 0x33, 0x00, 0x35};
157static const unsigned short ModeIndex_720x576[] = {0x32, 0x34, 0x00, 0x36};
158static const unsigned short ModeIndex_768x576[] = {0x5f, 0x60, 0x00, 0x61};
159static const unsigned short ModeIndex_800x480[] = {0x70, 0x7a, 0x00, 0x76};
160static const unsigned short ModeIndex_800x600[] = {0x30, 0x47, 0x00, 0x63};
161static const unsigned short ModeIndex_848x480[] = {0x39, 0x3b, 0x00, 0x3e};
162static const unsigned short ModeIndex_856x480[] = {0x3f, 0x42, 0x00, 0x45};
163static const unsigned short ModeIndex_960x540[] = {0x1d, 0x1e, 0x00, 0x1f};
164static const unsigned short ModeIndex_960x600[] = {0x20, 0x21, 0x00, 0x22};
165static const unsigned short ModeIndex_1024x768[] = {0x38, 0x4a, 0x00, 0x64};
166static const unsigned short ModeIndex_1024x576[] = {0x71, 0x74, 0x00, 0x77};
167static const unsigned short ModeIndex_1152x864[] = {0x29, 0x2a, 0x00, 0x2b};
168static const unsigned short ModeIndex_1280x720[] = {0x79, 0x75, 0x00, 0x78};
169static const unsigned short ModeIndex_1280x768[] = {0x23, 0x24, 0x00, 0x25};
170static const unsigned short ModeIndex_1280x1024[] = {0x3a, 0x4d, 0x00, 0x65};
171
172static const unsigned char SiS_MDA_DAC[] =
173{
174 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
175 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
176 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
177 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
178 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
179 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
180 0x15,0x15,0x15,0x15,0x15,0x15,0x15,0x15,
181 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F
182};
183
184static const unsigned char SiS_CGA_DAC[] =
185{
186 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
187 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
188 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
189 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
190 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
191 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
192 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
193 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F
194};
195
196static const unsigned char SiS_EGA_DAC[] =
197{
198 0x00,0x10,0x04,0x14,0x01,0x11,0x05,0x15,
199 0x20,0x30,0x24,0x34,0x21,0x31,0x25,0x35,
200 0x08,0x18,0x0C,0x1C,0x09,0x19,0x0D,0x1D,
201 0x28,0x38,0x2C,0x3C,0x29,0x39,0x2D,0x3D,
202 0x02,0x12,0x06,0x16,0x03,0x13,0x07,0x17,
203 0x22,0x32,0x26,0x36,0x23,0x33,0x27,0x37,
204 0x0A,0x1A,0x0E,0x1E,0x0B,0x1B,0x0F,0x1F,
205 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F
206};
207
208static const unsigned char SiS_VGA_DAC[] =
209{
210 0x00,0x10,0x04,0x14,0x01,0x11,0x09,0x15,
211 0x2A,0x3A,0x2E,0x3E,0x2B,0x3B,0x2F,0x3F,
212 0x00,0x05,0x08,0x0B,0x0E,0x11,0x14,0x18,
213 0x1C,0x20,0x24,0x28,0x2D,0x32,0x38,0x3F,
214 0x00,0x10,0x1F,0x2F,0x3F,0x1F,0x27,0x2F,
215 0x37,0x3F,0x2D,0x31,0x36,0x3A,0x3F,0x00,
216 0x07,0x0E,0x15,0x1C,0x0E,0x11,0x15,0x18,
217 0x1C,0x14,0x16,0x18,0x1A,0x1C,0x00,0x04,
218 0x08,0x0C,0x10,0x08,0x0A,0x0C,0x0E,0x10,
219 0x0B,0x0C,0x0D,0x0F,0x10
220};
221
222static const struct SiS_St SiSUSB_SModeIDTable[] =
223{
224 {0x03,0x0010,0x18,0x02,0x02,0x00,0x01,0x03,0x40},
225 {0xff,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
226};
227
228static const struct SiS_StResInfo_S SiSUSB_StResInfo[] =
229{
230 { 640,400},
231 { 640,350},
232 { 720,400},
233 { 720,350},
234 { 640,480}
235};
236
237static const struct SiS_ModeResInfo SiSUSB_ModeResInfo[] =
238{
239 { 320, 200, 8, 8}, /* 0x00 */
240 { 320, 240, 8, 8}, /* 0x01 */
241 { 320, 400, 8, 8}, /* 0x02 */
242 { 400, 300, 8, 8}, /* 0x03 */
243 { 512, 384, 8, 8}, /* 0x04 */
244 { 640, 400, 8,16}, /* 0x05 */
245 { 640, 480, 8,16}, /* 0x06 */
246 { 800, 600, 8,16}, /* 0x07 */
247 { 1024, 768, 8,16}, /* 0x08 */
248 { 1280,1024, 8,16}, /* 0x09 */
249 { 1600,1200, 8,16}, /* 0x0a */
250 { 1920,1440, 8,16}, /* 0x0b */
251 { 2048,1536, 8,16}, /* 0x0c */
252 { 720, 480, 8,16}, /* 0x0d */
253 { 720, 576, 8,16}, /* 0x0e */
254 { 1280, 960, 8,16}, /* 0x0f */
255 { 800, 480, 8,16}, /* 0x10 */
256 { 1024, 576, 8,16}, /* 0x11 */
257 { 1280, 720, 8,16}, /* 0x12 */
258 { 856, 480, 8,16}, /* 0x13 */
259 { 1280, 768, 8,16}, /* 0x14 */
260 { 1400,1050, 8,16}, /* 0x15 */
261 { 1152, 864, 8,16}, /* 0x16 */
262 { 848, 480, 8,16}, /* 0x17 */
263 { 1360, 768, 8,16}, /* 0x18 */
264 { 1024, 600, 8,16}, /* 0x19 */
265 { 1152, 768, 8,16}, /* 0x1a */
266 { 768, 576, 8,16}, /* 0x1b */
267 { 1360,1024, 8,16}, /* 0x1c */
268 { 1680,1050, 8,16}, /* 0x1d */
269 { 1280, 800, 8,16}, /* 0x1e */
270 { 1920,1080, 8,16}, /* 0x1f */
271 { 960, 540, 8,16}, /* 0x20 */
272 { 960, 600, 8,16} /* 0x21 */
273};
274
275static const struct SiS_StandTable SiSUSB_StandTable[] =
276{
277 /* MD_3_400 - mode 0x03 - 400 */
278 {
279 0x50,0x18,0x10,0x1000,
280 { 0x00,0x03,0x00,0x02 },
281 0x67,
282 { 0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,0x1f,
283 0x00,0x4f,0x0d,0x0e,0x00,0x00,0x00,0x00,
284 0x9c,0x8e,0x8f,0x28,0x1f,0x96,0xb9,0xa3,
285 0xff },
286 { 0x00,0x01,0x02,0x03,0x04,0x05,0x14,0x07,
287 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
288 0x0c,0x00,0x0f,0x08 },
289 { 0x00,0x00,0x00,0x00,0x00,0x10,0x0e,0x00, 0xff }
290 },
291 /* Generic for VGA and higher */
292 {
293 0x00,0x00,0x00,0x0000,
294 { 0x01,0x0f,0x00,0x0e },
295 0x23,
296 { 0x5f,0x4f,0x50,0x82,0x54,0x80,0x0b,0x3e,
297 0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
298 0xea,0x8c,0xdf,0x28,0x40,0xe7,0x04,0xa3,
299 0xff },
300 { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
301 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
302 0x01,0x00,0x00,0x00 },
303 { 0x00,0x00,0x00,0x00,0x00,0x40,0x05,0x0f, 0xff }
304 }
305};
306
307static const struct SiS_Ext SiSUSB_EModeIDTable[] =
308{
309 {0x2e,0x0a1b,0x0101,SIS_RI_640x480, 0x00,0x00,0x05,0x05,0x08, 2}, /* 640x480x8 */
310 {0x2f,0x0a1b,0x0100,SIS_RI_640x400, 0x00,0x00,0x05,0x05,0x10, 0}, /* 640x400x8 */
311 {0x30,0x2a1b,0x0103,SIS_RI_800x600, 0x00,0x00,0x07,0x06,0x00, 3}, /* 800x600x8 */
312 {0x31,0x4a1b,0x0000,SIS_RI_720x480, 0x00,0x00,0x06,0x06,0x11,-1}, /* 720x480x8 */
313 {0x32,0x4a1b,0x0000,SIS_RI_720x576, 0x00,0x00,0x06,0x06,0x12,-1}, /* 720x576x8 */
314 {0x33,0x4a1d,0x0000,SIS_RI_720x480, 0x00,0x00,0x06,0x06,0x11,-1}, /* 720x480x16 */
315 {0x34,0x6a1d,0x0000,SIS_RI_720x576, 0x00,0x00,0x06,0x06,0x12,-1}, /* 720x576x16 */
316 {0x35,0x4a1f,0x0000,SIS_RI_720x480, 0x00,0x00,0x06,0x06,0x11,-1}, /* 720x480x32 */
317 {0x36,0x6a1f,0x0000,SIS_RI_720x576, 0x00,0x00,0x06,0x06,0x12,-1}, /* 720x576x32 */
318 {0x38,0x0a1b,0x0105,SIS_RI_1024x768, 0x00,0x00,0x08,0x07,0x13, 4}, /* 1024x768x8 */
319 {0x3a,0x0e3b,0x0107,SIS_RI_1280x1024,0x00,0x00,0x00,0x00,0x2f, 8}, /* 1280x1024x8 */
320 {0x41,0x9a1d,0x010e,SIS_RI_320x200, 0x00,0x00,0x04,0x04,0x1a, 0}, /* 320x200x16 */
321 {0x44,0x0a1d,0x0111,SIS_RI_640x480, 0x00,0x00,0x05,0x05,0x08, 2}, /* 640x480x16 */
322 {0x47,0x2a1d,0x0114,SIS_RI_800x600, 0x00,0x00,0x07,0x06,0x00, 3}, /* 800x600x16 */
323 {0x4a,0x0a3d,0x0117,SIS_RI_1024x768, 0x00,0x00,0x08,0x07,0x13, 4}, /* 1024x768x16 */
324 {0x4d,0x0e7d,0x011a,SIS_RI_1280x1024,0x00,0x00,0x00,0x00,0x2f, 8}, /* 1280x1024x16 */
325 {0x50,0x9a1b,0x0132,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x1b, 2}, /* 320x240x8 */
326 {0x51,0xba1b,0x0133,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x1c, 3}, /* 400x300x8 */
327 {0x52,0xba1b,0x0134,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x1d, 4}, /* 512x384x8 */
328 {0x56,0x9a1d,0x0135,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x1b, 2}, /* 320x240x16 */
329 {0x57,0xba1d,0x0136,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x1c, 3}, /* 400x300x16 */
330 {0x58,0xba1d,0x0137,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x1d, 4}, /* 512x384x16 */
331 {0x59,0x9a1b,0x0138,SIS_RI_320x200, 0x00,0x00,0x04,0x04,0x1a, 0}, /* 320x200x8 */
332 {0x5c,0xba1f,0x0000,SIS_RI_512x384, 0x00,0x00,0x00,0x00,0x1d, 4}, /* 512x384x32 */
333 {0x5d,0x0a1d,0x0139,SIS_RI_640x400, 0x00,0x00,0x05,0x07,0x10, 0}, /* 640x400x16 */
334 {0x5e,0x0a1f,0x0000,SIS_RI_640x400, 0x00,0x00,0x05,0x07,0x10, 0}, /* 640x400x32 */
335 {0x62,0x0a3f,0x013a,SIS_RI_640x480, 0x00,0x00,0x05,0x05,0x08, 2}, /* 640x480x32 */
336 {0x63,0x2a3f,0x013b,SIS_RI_800x600, 0x00,0x00,0x07,0x06,0x00, 3}, /* 800x600x32 */
337 {0x64,0x0a7f,0x013c,SIS_RI_1024x768, 0x00,0x00,0x08,0x07,0x13, 4}, /* 1024x768x32 */
338 {0x65,0x0eff,0x013d,SIS_RI_1280x1024,0x00,0x00,0x00,0x00,0x2f, 8}, /* 1280x1024x32 */
339 {0x70,0x6a1b,0x0000,SIS_RI_800x480, 0x00,0x00,0x07,0x07,0x1e,-1}, /* 800x480x8 */
340 {0x71,0x4a1b,0x0000,SIS_RI_1024x576, 0x00,0x00,0x00,0x00,0x21,-1}, /* 1024x576x8 */
341 {0x74,0x4a1d,0x0000,SIS_RI_1024x576, 0x00,0x00,0x00,0x00,0x21,-1}, /* 1024x576x16 */
342 {0x75,0x0a3d,0x0000,SIS_RI_1280x720, 0x00,0x00,0x00,0x00,0x24, 5}, /* 1280x720x16 */
343 {0x76,0x6a1f,0x0000,SIS_RI_800x480, 0x00,0x00,0x07,0x07,0x1e,-1}, /* 800x480x32 */
344 {0x77,0x4a1f,0x0000,SIS_RI_1024x576, 0x00,0x00,0x00,0x00,0x21,-1}, /* 1024x576x32 */
345 {0x78,0x0a3f,0x0000,SIS_RI_1280x720, 0x00,0x00,0x00,0x00,0x24, 5}, /* 1280x720x32 */
346 {0x79,0x0a3b,0x0000,SIS_RI_1280x720, 0x00,0x00,0x00,0x00,0x24, 5}, /* 1280x720x8 */
347 {0x7a,0x6a1d,0x0000,SIS_RI_800x480, 0x00,0x00,0x07,0x07,0x1e,-1}, /* 800x480x16 */
348 {0x23,0x0e3b,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x27, 6}, /* 1280x768x8 */
349 {0x24,0x0e7d,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x27, 6}, /* 1280x768x16 */
350 {0x25,0x0eff,0x0000,SIS_RI_1280x768, 0x00,0x00,0x00,0x00,0x27, 6}, /* 1280x768x32 */
351 {0x39,0x6a1b,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x28,-1}, /* 848x480 */
352 {0x3b,0x6a3d,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x28,-1},
353 {0x3e,0x6a7f,0x0000,SIS_RI_848x480, 0x00,0x00,0x00,0x00,0x28,-1},
354 {0x3f,0x6a1b,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x2a,-1}, /* 856x480 */
355 {0x42,0x6a3d,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x2a,-1},
356 {0x45,0x6a7f,0x0000,SIS_RI_856x480, 0x00,0x00,0x00,0x00,0x2a,-1},
357 {0x4f,0x9a1f,0x0000,SIS_RI_320x200, 0x00,0x00,0x04,0x04,0x1a, 0}, /* 320x200x32 */
358 {0x53,0x9a1f,0x0000,SIS_RI_320x240, 0x00,0x00,0x04,0x04,0x1b, 2}, /* 320x240x32 */
359 {0x54,0xba1f,0x0000,SIS_RI_400x300, 0x00,0x00,0x07,0x07,0x1c, 3}, /* 400x300x32 */
360 {0x5f,0x6a1b,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x2c,-1}, /* 768x576 */
361 {0x60,0x6a1d,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x2c,-1},
362 {0x61,0x6a3f,0x0000,SIS_RI_768x576, 0x00,0x00,0x06,0x06,0x2c,-1},
363 {0x1d,0x6a1b,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x2d,-1}, /* 960x540 */
364 {0x1e,0x6a3d,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x2d,-1},
365 {0x1f,0x6a7f,0x0000,SIS_RI_960x540, 0x00,0x00,0x00,0x00,0x2d,-1},
366 {0x20,0x6a1b,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x2e,-1}, /* 960x600 */
367 {0x21,0x6a3d,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x2e,-1},
368 {0x22,0x6a7f,0x0000,SIS_RI_960x600, 0x00,0x00,0x00,0x00,0x2e,-1},
369 {0x29,0x4e1b,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x33,-1}, /* 1152x864 */
370 {0x2a,0x4e3d,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x33,-1},
371 {0x2b,0x4e7f,0x0000,SIS_RI_1152x864, 0x00,0x00,0x00,0x00,0x33,-1},
372 {0xff,0x0000,0x0000,0, 0x00,0x00,0x00,0x00,0x00,-1}
373};
374
375static const struct SiS_Ext2 SiSUSB_RefIndex[] =
376{
377 {0x085f,0x0d,0x03,0x05,0x05,0x30, 800, 600, 0x40, 0x00, 0x00}, /* 0x0 */
378 {0x0067,0x0e,0x04,0x05,0x05,0x30, 800, 600, 0x40, 0x00, 0x00}, /* 0x1 */
379 {0x0067,0x0f,0x08,0x48,0x05,0x30, 800, 600, 0x40, 0x00, 0x00}, /* 0x2 */
380 {0x0067,0x10,0x07,0x8b,0x05,0x30, 800, 600, 0x40, 0x00, 0x00}, /* 0x3 */
381 {0x0047,0x11,0x0a,0x00,0x05,0x30, 800, 600, 0x40, 0x00, 0x00}, /* 0x4 */
382 {0x0047,0x12,0x0d,0x00,0x05,0x30, 800, 600, 0x40, 0x00, 0x00}, /* 0x5 */
383 {0x0047,0x13,0x13,0x00,0x05,0x30, 800, 600, 0x20, 0x00, 0x00}, /* 0x6 */
384 {0x0107,0x14,0x1c,0x00,0x05,0x30, 800, 600, 0x20, 0x00, 0x00}, /* 0x7 */
385 {0xc85f,0x05,0x00,0x04,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00}, /* 0x8 */
386 {0xc067,0x06,0x02,0x04,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00}, /* 0x9 */
387 {0xc067,0x07,0x02,0x47,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00}, /* 0xa */
388 {0xc067,0x08,0x03,0x8a,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00}, /* 0xb */
389 {0xc047,0x09,0x05,0x00,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00}, /* 0xc */
390 {0xc047,0x0a,0x09,0x00,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00}, /* 0xd */
391 {0xc047,0x0b,0x0e,0x00,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00}, /* 0xe */
392 {0xc047,0x0c,0x15,0x00,0x04,0x2e, 640, 480, 0x40, 0x00, 0x00}, /* 0xf */
393 {0x487f,0x04,0x00,0x00,0x00,0x2f, 640, 400, 0x30, 0x55, 0x6e}, /* 0x10 */
394 {0xc06f,0x3c,0x01,0x06,0x13,0x31, 720, 480, 0x30, 0x00, 0x00}, /* 0x11 */
395 {0x006f,0x3d,0x6f,0x06,0x14,0x32, 720, 576, 0x30, 0x00, 0x00}, /* 0x12 (6f was 03) */
396 {0x0087,0x15,0x06,0x00,0x06,0x38,1024, 768, 0x30, 0x00, 0x00}, /* 0x13 */
397 {0xc877,0x16,0x0b,0x06,0x06,0x38,1024, 768, 0x20, 0x00, 0x00}, /* 0x14 */
398 {0xc067,0x17,0x0f,0x49,0x06,0x38,1024, 768, 0x20, 0x00, 0x00}, /* 0x15 */
399 {0x0067,0x18,0x11,0x00,0x06,0x38,1024, 768, 0x20, 0x00, 0x00}, /* 0x16 */
400 {0x0047,0x19,0x16,0x8c,0x06,0x38,1024, 768, 0x20, 0x00, 0x00}, /* 0x17 */
401 {0x0107,0x1a,0x1b,0x00,0x06,0x38,1024, 768, 0x10, 0x00, 0x00}, /* 0x18 */
402 {0x0107,0x1b,0x1f,0x00,0x06,0x38,1024, 768, 0x10, 0x00, 0x00}, /* 0x19 */
403 {0x407f,0x00,0x00,0x00,0x00,0x41, 320, 200, 0x30, 0x56, 0x4e}, /* 0x1a */
404 {0xc07f,0x01,0x00,0x04,0x04,0x50, 320, 240, 0x30, 0x00, 0x00}, /* 0x1b */
405 {0x007f,0x02,0x04,0x05,0x05,0x51, 400, 300, 0x30, 0x00, 0x00}, /* 0x1c */
406 {0xc077,0x03,0x0b,0x06,0x06,0x52, 512, 384, 0x30, 0x00, 0x00}, /* 0x1d */
407 {0x0077,0x32,0x40,0x08,0x18,0x70, 800, 480, 0x30, 0x00, 0x00}, /* 0x1e */
408 {0x0047,0x33,0x07,0x08,0x18,0x70, 800, 480, 0x30, 0x00, 0x00}, /* 0x1f */
409 {0x0047,0x34,0x0a,0x08,0x18,0x70, 800, 480, 0x30, 0x00, 0x00}, /* 0x20 */
410 {0x0077,0x35,0x0b,0x09,0x19,0x71,1024, 576, 0x30, 0x00, 0x00}, /* 0x21 */
411 {0x0047,0x36,0x11,0x09,0x19,0x71,1024, 576, 0x30, 0x00, 0x00}, /* 0x22 */
412 {0x0047,0x37,0x16,0x09,0x19,0x71,1024, 576, 0x30, 0x00, 0x00}, /* 0x23 */
413 {0x1137,0x38,0x19,0x0a,0x0c,0x75,1280, 720, 0x30, 0x00, 0x00}, /* 0x24 */
414 {0x1107,0x39,0x1e,0x0a,0x0c,0x75,1280, 720, 0x30, 0x00, 0x00}, /* 0x25 */
415 {0x1307,0x3a,0x20,0x0a,0x0c,0x75,1280, 720, 0x30, 0x00, 0x00}, /* 0x26 */
416 {0x0077,0x42,0x5b,0x08,0x11,0x23,1280, 768, 0x30, 0x00, 0x00}, /* 0x27 */
417 {0x0087,0x45,0x57,0x00,0x16,0x39, 848, 480, 0x30, 0x00, 0x00}, /* 0x28 38Hzi */
418 {0xc067,0x46,0x55,0x0b,0x16,0x39, 848, 480, 0x30, 0x00, 0x00}, /* 0x29 848x480-60Hz */
419 {0x0087,0x47,0x57,0x00,0x17,0x3f, 856, 480, 0x30, 0x00, 0x00}, /* 0x2a 856x480-38Hzi */
420 {0xc067,0x48,0x57,0x00,0x17,0x3f, 856, 480, 0x30, 0x00, 0x00}, /* 0x2b 856x480-60Hz */
421 {0x006f,0x4d,0x71,0x06,0x15,0x5f, 768, 576, 0x30, 0x00, 0x00}, /* 0x2c 768x576-56Hz */
422 {0x0067,0x52,0x6a,0x00,0x1c,0x1d, 960, 540, 0x30, 0x00, 0x00}, /* 0x2d 960x540 60Hz */
423 {0x0077,0x53,0x6b,0x0b,0x1d,0x20, 960, 600, 0x30, 0x00, 0x00}, /* 0x2e 960x600 60Hz */
424 {0x0087,0x1c,0x11,0x00,0x07,0x3a,1280,1024, 0x30, 0x00, 0x00}, /* 0x2f */
425 {0x0137,0x1d,0x19,0x07,0x07,0x3a,1280,1024, 0x00, 0x00, 0x00}, /* 0x30 */
426 {0x0107,0x1e,0x1e,0x00,0x07,0x3a,1280,1024, 0x00, 0x00, 0x00}, /* 0x31 */
427 {0x0207,0x1f,0x20,0x00,0x07,0x3a,1280,1024, 0x00, 0x00, 0x00}, /* 0x32 */
428 {0x0127,0x54,0x6d,0x00,0x1a,0x29,1152, 864, 0x30, 0x00, 0x00}, /* 0x33 1152x864-60Hz */
429 {0x0127,0x44,0x19,0x00,0x1a,0x29,1152, 864, 0x30, 0x00, 0x00}, /* 0x34 1152x864-75Hz */
430 {0x0127,0x4a,0x1e,0x00,0x1a,0x29,1152, 864, 0x30, 0x00, 0x00}, /* 0x35 1152x864-85Hz */
431 {0xffff,0x00,0x00,0x00,0x00,0x00, 0, 0, 0, 0x00, 0x00}
432};
433
434static const struct SiS_CRT1Table SiSUSB_CRT1Table[] =
435{
436 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0xbf,0x1f,
437 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x00,
438 0x00}}, /* 0x0 */
439 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0x0b,0x3e,
440 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x00,
441 0x00}}, /* 0x1 */
442 {{0x3d,0x31,0x31,0x81,0x37,0x1f,0x72,0xf0,
443 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x05,
444 0x01}}, /* 0x2 */
445 {{0x4f,0x3f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
446 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x01,
447 0x01}}, /* 0x3 */
448 {{0x5f,0x4f,0x50,0x82,0x55,0x81,0xbf,0x1f,
449 0x9c,0x8e,0x8f,0x96,0xb9,0x30,0x00,0x05,
450 0x00}}, /* 0x4 */
451 {{0x5f,0x4f,0x4f,0x83,0x55,0x81,0x0b,0x3e,
452 0xe9,0x8b,0xdf,0xe8,0x0c,0x00,0x00,0x05,
453 0x00}}, /* 0x5 */
454 {{0x63,0x4f,0x4f,0x87,0x56,0x9b,0x06,0x3e,
455 0xe8,0x8a,0xdf,0xe7,0x07,0x00,0x00,0x01,
456 0x00}}, /* 0x6 */
457 {{0x64,0x4f,0x4f,0x88,0x55,0x9d,0xf2,0x1f,
458 0xe0,0x83,0xdf,0xdf,0xf3,0x10,0x00,0x01,
459 0x00}}, /* 0x7 */
460 {{0x63,0x4f,0x4f,0x87,0x5a,0x81,0xfb,0x1f,
461 0xe0,0x83,0xdf,0xdf,0xfc,0x10,0x00,0x05,
462 0x00}}, /* 0x8 */
463 {{0x65,0x4f,0x4f,0x89,0x58,0x80,0xfb,0x1f,
464 0xe0,0x83,0xdf,0xdf,0xfc,0x10,0x00,0x05,
465 0x61}}, /* 0x9 */
466 {{0x65,0x4f,0x4f,0x89,0x58,0x80,0x01,0x3e,
467 0xe0,0x83,0xdf,0xdf,0x02,0x00,0x00,0x05,
468 0x61}}, /* 0xa */
469 {{0x67,0x4f,0x4f,0x8b,0x58,0x81,0x0d,0x3e,
470 0xe0,0x83,0xdf,0xdf,0x0e,0x00,0x00,0x05,
471 0x61}}, /* 0xb */
472 {{0x65,0x4f,0x4f,0x89,0x57,0x9f,0xfb,0x1f,
473 0xe6,0x8a,0xdf,0xdf,0xfc,0x10,0x00,0x01,
474 0x00}}, /* 0xc */
475 {{0x7b,0x63,0x63,0x9f,0x6a,0x93,0x6f,0xf0,
476 0x58,0x8a,0x57,0x57,0x70,0x20,0x00,0x05,
477 0x01}}, /* 0xd */
478 {{0x7f,0x63,0x63,0x83,0x6c,0x1c,0x72,0xf0,
479 0x58,0x8c,0x57,0x57,0x73,0x20,0x00,0x06,
480 0x01}}, /* 0xe */
481 {{0x7d,0x63,0x63,0x81,0x6e,0x1d,0x98,0xf0,
482 0x7c,0x82,0x57,0x57,0x99,0x00,0x00,0x06,
483 0x01}}, /* 0xf */
484 {{0x7f,0x63,0x63,0x83,0x69,0x13,0x6f,0xf0,
485 0x58,0x8b,0x57,0x57,0x70,0x20,0x00,0x06,
486 0x01}}, /* 0x10 */
487 {{0x7e,0x63,0x63,0x82,0x6b,0x13,0x75,0xf0,
488 0x58,0x8b,0x57,0x57,0x76,0x20,0x00,0x06,
489 0x01}}, /* 0x11 */
490 {{0x81,0x63,0x63,0x85,0x6d,0x18,0x7a,0xf0,
491 0x58,0x8b,0x57,0x57,0x7b,0x20,0x00,0x06,
492 0x61}}, /* 0x12 */
493 {{0x83,0x63,0x63,0x87,0x6e,0x19,0x81,0xf0,
494 0x58,0x8b,0x57,0x57,0x82,0x20,0x00,0x06,
495 0x61}}, /* 0x13 */
496 {{0x85,0x63,0x63,0x89,0x6f,0x1a,0x91,0xf0,
497 0x58,0x8b,0x57,0x57,0x92,0x20,0x00,0x06,
498 0x61}}, /* 0x14 */
499 {{0x99,0x7f,0x7f,0x9d,0x84,0x1a,0x96,0x1f,
500 0x7f,0x83,0x7f,0x7f,0x97,0x10,0x00,0x02,
501 0x00}}, /* 0x15 */
502 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x24,0xf5,
503 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x02,
504 0x01}}, /* 0x16 */
505 {{0xa1,0x7f,0x7f,0x85,0x86,0x97,0x24,0xf5,
506 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x02,
507 0x01}}, /* 0x17 */
508 {{0x9f,0x7f,0x7f,0x83,0x85,0x91,0x1e,0xf5,
509 0x00,0x83,0xff,0xff,0x1f,0x10,0x00,0x02,
510 0x01}}, /* 0x18 */
511 {{0xa7,0x7f,0x7f,0x8b,0x89,0x95,0x26,0xf5,
512 0x00,0x83,0xff,0xff,0x27,0x10,0x00,0x02,
513 0x01}}, /* 0x19 */
514 {{0xa9,0x7f,0x7f,0x8d,0x8c,0x9a,0x2c,0xf5,
515 0x00,0x83,0xff,0xff,0x2d,0x14,0x00,0x02,
516 0x62}}, /* 0x1a */
517 {{0xab,0x7f,0x7f,0x8f,0x8d,0x9b,0x35,0xf5,
518 0x00,0x83,0xff,0xff,0x36,0x14,0x00,0x02,
519 0x62}}, /* 0x1b */
520 {{0xcf,0x9f,0x9f,0x93,0xb2,0x01,0x14,0xba,
521 0x00,0x83,0xff,0xff,0x15,0x00,0x00,0x03,
522 0x00}}, /* 0x1c */
523 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0x5a,
524 0x00,0x83,0xff,0xff,0x29,0x09,0x00,0x07,
525 0x01}}, /* 0x1d */
526 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0x5a,
527 0x00,0x83,0xff,0xff,0x29,0x09,0x00,0x07,
528 0x01}}, /* 0x1e */
529 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0x5a,
530 0x00,0x83,0xff,0xff,0x2f,0x09,0x00,0x07,
531 0x01}}, /* 0x1f */
532 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
533 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
534 0x00}}, /* 0x20 */
535 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
536 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
537 0x00}}, /* 0x21 */
538 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
539 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
540 0x00}}, /* 0x22 */
541 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
542 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
543 0x00}}, /* 0x23 */
544 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
545 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
546 0x00}}, /* 0x24 */
547 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
548 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
549 0x00}}, /* 0x25 */
550 {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,
551 0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
552 0x00}}, /* 0x26 */
553 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f,
554 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01,
555 0x00}}, /* 0x27 */
556 {{0x43,0xef,0xef,0x87,0x06,0x00,0xd4,0x1f,
557 0xa0,0x83,0x9f,0x9f,0xd5,0x1f,0x41,0x05,
558 0x63}}, /* 0x28 */
559 {{0x45,0xef,0xef,0x89,0x07,0x01,0xd9,0x1f,
560 0xa0,0x83,0x9f,0x9f,0xda,0x1f,0x41,0x05,
561 0x63}}, /* 0x29 */
562 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f,
563 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01,
564 0x00}}, /* 0x2a */
565 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f,
566 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01,
567 0x00}}, /* 0x2b */
568 {{0x40,0xef,0xef,0x84,0x03,0x1d,0xda,0x1f,
569 0xa0,0x83,0x9f,0x9f,0xdb,0x1f,0x41,0x01,
570 0x00}}, /* 0x2c */
571 {{0x59,0xff,0xff,0x9d,0x17,0x13,0x33,0xba,
572 0x00,0x83,0xff,0xff,0x34,0x0f,0x41,0x05,
573 0x44}}, /* 0x2d */
574 {{0x5b,0xff,0xff,0x9f,0x18,0x14,0x38,0xba,
575 0x00,0x83,0xff,0xff,0x39,0x0f,0x41,0x05,
576 0x44}}, /* 0x2e */
577 {{0x5b,0xff,0xff,0x9f,0x18,0x14,0x3d,0xba,
578 0x00,0x83,0xff,0xff,0x3e,0x0f,0x41,0x05,
579 0x44}}, /* 0x2f */
580 {{0x5d,0xff,0xff,0x81,0x19,0x95,0x41,0xba,
581 0x00,0x84,0xff,0xff,0x42,0x0f,0x41,0x05,
582 0x44}}, /* 0x30 */
583 {{0x55,0xff,0xff,0x99,0x0d,0x0c,0x3e,0xba,
584 0x00,0x84,0xff,0xff,0x3f,0x0f,0x41,0x05,
585 0x00}}, /* 0x31 */
586 {{0x7f,0x63,0x63,0x83,0x6c,0x1c,0x72,0xba,
587 0x27,0x8b,0xdf,0xdf,0x73,0x00,0x00,0x06,
588 0x01}}, /* 0x32 */
589 {{0x7f,0x63,0x63,0x83,0x69,0x13,0x6f,0xba,
590 0x26,0x89,0xdf,0xdf,0x6f,0x00,0x00,0x06,
591 0x01}}, /* 0x33 */
592 {{0x7f,0x63,0x63,0x82,0x6b,0x13,0x75,0xba,
593 0x29,0x8c,0xdf,0xdf,0x75,0x00,0x00,0x06,
594 0x01}}, /* 0x34 */
595 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x24,0xf1,
596 0xaf,0x85,0x3f,0x3f,0x25,0x30,0x00,0x02,
597 0x01}}, /* 0x35 */
598 {{0x9f,0x7f,0x7f,0x83,0x85,0x91,0x1e,0xf1,
599 0xad,0x81,0x3f,0x3f,0x1f,0x30,0x00,0x02,
600 0x01}}, /* 0x36 */
601 {{0xa7,0x7f,0x7f,0x88,0x89,0x95,0x26,0xf1,
602 0xb1,0x85,0x3f,0x3f,0x27,0x30,0x00,0x02,
603 0x01}}, /* 0x37 */
604 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x28,0xc4,
605 0x7a,0x8e,0xcf,0xcf,0x29,0x21,0x00,0x07,
606 0x01}}, /* 0x38 */
607 {{0xce,0x9f,0x9f,0x92,0xa5,0x17,0x28,0xd4,
608 0x7a,0x8e,0xcf,0xcf,0x29,0x21,0x00,0x07,
609 0x01}}, /* 0x39 */
610 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0x2e,0xd4,
611 0x7d,0x81,0xcf,0xcf,0x2f,0x21,0x00,0x07,
612 0x01}}, /* 0x3a */
613 {{0xdc,0x9f,0x9f,0x80,0xaf,0x9d,0xe6,0xff,
614 0xc0,0x83,0xbf,0xbf,0xe7,0x10,0x00,0x07,
615 0x01}}, /* 0x3b */
616 {{0x6b,0x59,0x59,0x8f,0x5e,0x8c,0x0b,0x3e,
617 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x05,
618 0x00}}, /* 0x3c */
619 {{0x6d,0x59,0x59,0x91,0x60,0x89,0x53,0xf0,
620 0x41,0x84,0x3f,0x3f,0x54,0x00,0x00,0x05,
621 0x41}}, /* 0x3d */
622 {{0x86,0x6a,0x6a,0x8a,0x74,0x06,0x8c,0x15,
623 0x4f,0x83,0xef,0xef,0x8d,0x30,0x00,0x02,
624 0x00}}, /* 0x3e */
625 {{0x81,0x6a,0x6a,0x85,0x70,0x00,0x0f,0x3e,
626 0xeb,0x8e,0xdf,0xdf,0x10,0x00,0x00,0x02,
627 0x00}}, /* 0x3f */
628 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x1e,0xf1,
629 0xae,0x85,0x57,0x57,0x1f,0x30,0x00,0x02,
630 0x01}}, /* 0x40 */
631 {{0xa3,0x7f,0x7f,0x87,0x86,0x97,0x24,0xf5,
632 0x02,0x88,0xff,0xff,0x25,0x10,0x00,0x02,
633 0x01}}, /* 0x41 */
634 {{0xce,0x9f,0x9f,0x92,0xa9,0x17,0x20,0xf5,
635 0x03,0x88,0xff,0xff,0x21,0x10,0x00,0x07,
636 0x01}}, /* 0x42 */
637 {{0xe6,0xae,0xae,0x8a,0xbd,0x90,0x3d,0x10,
638 0x1a,0x8d,0x19,0x19,0x3e,0x2f,0x00,0x03,
639 0x00}}, /* 0x43 */
640 {{0xc3,0x8f,0x8f,0x87,0x9b,0x0b,0x82,0xef,
641 0x60,0x83,0x5f,0x5f,0x83,0x10,0x00,0x07,
642 0x01}}, /* 0x44 */
643 {{0x86,0x69,0x69,0x8A,0x74,0x06,0x8C,0x15,
644 0x4F,0x83,0xEF,0xEF,0x8D,0x30,0x00,0x02,
645 0x00}}, /* 0x45 */
646 {{0x83,0x69,0x69,0x87,0x6f,0x1d,0x03,0x3E,
647 0xE5,0x8d,0xDF,0xe4,0x04,0x00,0x00,0x06,
648 0x00}}, /* 0x46 */
649 {{0x86,0x6A,0x6A,0x8A,0x74,0x06,0x8C,0x15,
650 0x4F,0x83,0xEF,0xEF,0x8D,0x30,0x00,0x02,
651 0x00}}, /* 0x47 */
652 {{0x81,0x6A,0x6A,0x85,0x70,0x00,0x0F,0x3E,
653 0xEB,0x8E,0xDF,0xDF,0x10,0x00,0x00,0x02,
654 0x00}}, /* 0x48 */
655 {{0xdd,0xa9,0xa9,0x81,0xb4,0x97,0x26,0xfd,
656 0x01,0x8d,0xff,0x00,0x27,0x10,0x00,0x03,
657 0x01}}, /* 0x49 */
658 {{0xd9,0x8f,0x8f,0x9d,0xba,0x0a,0x8a,0xff,
659 0x60,0x8b,0x5f,0x5f,0x8b,0x10,0x00,0x03,
660 0x01}}, /* 0x4a */
661 {{0xea,0xae,0xae,0x8e,0xba,0x82,0x40,0x10,
662 0x1b,0x87,0x19,0x1a,0x41,0x0f,0x00,0x03,
663 0x00}}, /* 0x4b */
664 {{0xd3,0x9f,0x9f,0x97,0xab,0x1f,0xf1,0xff,
665 0xc0,0x83,0xbf,0xbf,0xf2,0x10,0x00,0x07,
666 0x01}}, /* 0x4c */
667 {{0x75,0x5f,0x5f,0x99,0x66,0x90,0x53,0xf0,
668 0x41,0x84,0x3f,0x3f,0x54,0x00,0x00,0x05,
669 0x41}},
670 {{0x2d,0x27,0x28,0x90,0x2c,0x80,0x0b,0x3e,
671 0xe9,0x8b,0xdf,0xe7,0x04,0x00,0x00,0x00,
672 0x00}}, /* 0x4e */
673 {{0xcd,0x9f,0x9f,0x91,0xab,0x1c,0x3a,0xff,
674 0x20,0x83,0x1f,0x1f,0x3b,0x10,0x00,0x07,
675 0x21}}, /* 0x4f */
676 {{0x15,0xd1,0xd1,0x99,0xe2,0x19,0x3d,0x10,
677 0x1a,0x8d,0x19,0x19,0x3e,0x2f,0x01,0x0c,
678 0x20}}, /* 0x50 */
679 {{0x0e,0xef,0xef,0x92,0xfe,0x03,0x30,0xf0,
680 0x1e,0x83,0x1b,0x1c,0x31,0x00,0x01,0x00,
681 0x61}}, /* 0x51 */
682 {{0x85,0x77,0x77,0x89,0x7d,0x01,0x31,0xf0,
683 0x1e,0x84,0x1b,0x1c,0x32,0x00,0x00,0x02,
684 0x41}}, /* 0x52 */
685 {{0x87,0x77,0x77,0x8b,0x81,0x0b,0x68,0xf0,
686 0x5a,0x80,0x57,0x57,0x69,0x00,0x00,0x02,
687 0x01}}, /* 0x53 */
688 {{0xcd,0x8f,0x8f,0x91,0x9b,0x1b,0x7a,0xff,
689 0x64,0x8c,0x5f,0x62,0x7b,0x10,0x00,0x07,
690 0x41}} /* 0x54 */
691};
692
693static struct SiS_VCLKData SiSUSB_VCLKData[] =
694{
695 { 0x1b,0xe1, 25}, /* 0x00 */
696 { 0x4e,0xe4, 28}, /* 0x01 */
697 { 0x57,0xe4, 31}, /* 0x02 */
698 { 0xc3,0xc8, 36}, /* 0x03 */
699 { 0x42,0xe2, 40}, /* 0x04 */
700 { 0xfe,0xcd, 43}, /* 0x05 */
701 { 0x5d,0xc4, 44}, /* 0x06 */
702 { 0x52,0xe2, 49}, /* 0x07 */
703 { 0x53,0xe2, 50}, /* 0x08 */
704 { 0x74,0x67, 52}, /* 0x09 */
705 { 0x6d,0x66, 56}, /* 0x0a */
706 { 0x5a,0x64, 65}, /* 0x0b */
707 { 0x46,0x44, 67}, /* 0x0c */
708 { 0xb1,0x46, 68}, /* 0x0d */
709 { 0xd3,0x4a, 72}, /* 0x0e */
710 { 0x29,0x61, 75}, /* 0x0f */
711 { 0x6e,0x46, 76}, /* 0x10 */
712 { 0x2b,0x61, 78}, /* 0x11 */
713 { 0x31,0x42, 79}, /* 0x12 */
714 { 0xab,0x44, 83}, /* 0x13 */
715 { 0x46,0x25, 84}, /* 0x14 */
716 { 0x78,0x29, 86}, /* 0x15 */
717 { 0x62,0x44, 94}, /* 0x16 */
718 { 0x2b,0x41,104}, /* 0x17 */
719 { 0x3a,0x23,105}, /* 0x18 */
720 { 0x70,0x44,108}, /* 0x19 */
721 { 0x3c,0x23,109}, /* 0x1a */
722 { 0x5e,0x43,113}, /* 0x1b */
723 { 0xbc,0x44,116}, /* 0x1c */
724 { 0xe0,0x46,132}, /* 0x1d */
725 { 0x54,0x42,135}, /* 0x1e */
726 { 0xea,0x2a,139}, /* 0x1f */
727 { 0x41,0x22,157}, /* 0x20 */
728 { 0x70,0x24,162}, /* 0x21 */
729 { 0x30,0x21,175}, /* 0x22 */
730 { 0x4e,0x22,189}, /* 0x23 */
731 { 0xde,0x26,194}, /* 0x24 */
732 { 0x62,0x06,202}, /* 0x25 */
733 { 0x3f,0x03,229}, /* 0x26 */
734 { 0xb8,0x06,234}, /* 0x27 */
735 { 0x34,0x02,253}, /* 0x28 */
736 { 0x58,0x04,255}, /* 0x29 */
737 { 0x24,0x01,265}, /* 0x2a */
738 { 0x9b,0x02,267}, /* 0x2b */
739 { 0x70,0x05,270}, /* 0x2c */
740 { 0x25,0x01,272}, /* 0x2d */
741 { 0x9c,0x02,277}, /* 0x2e */
742 { 0x27,0x01,286}, /* 0x2f */
743 { 0x3c,0x02,291}, /* 0x30 */
744 { 0xef,0x0a,292}, /* 0x31 */
745 { 0xf6,0x0a,310}, /* 0x32 */
746 { 0x95,0x01,315}, /* 0x33 */
747 { 0xf0,0x09,324}, /* 0x34 */
748 { 0xfe,0x0a,331}, /* 0x35 */
749 { 0xf3,0x09,332}, /* 0x36 */
750 { 0xea,0x08,340}, /* 0x37 */
751 { 0xe8,0x07,376}, /* 0x38 */
752 { 0xde,0x06,389}, /* 0x39 */
753 { 0x52,0x2a, 54}, /* 0x3a 301 TV */
754 { 0x52,0x6a, 27}, /* 0x3b 301 TV */
755 { 0x62,0x24, 70}, /* 0x3c 301 TV */
756 { 0x62,0x64, 70}, /* 0x3d 301 TV */
757 { 0xa8,0x4c, 30}, /* 0x3e 301 TV */
758 { 0x20,0x26, 33}, /* 0x3f 301 TV */
759 { 0x31,0xc2, 39}, /* 0x40 */
760 { 0x60,0x36, 30}, /* 0x41 Chrontel */
761 { 0x40,0x4a, 28}, /* 0x42 Chrontel */
762 { 0x9f,0x46, 44}, /* 0x43 Chrontel */
763 { 0x97,0x2c, 26}, /* 0x44 */
764 { 0x44,0xe4, 25}, /* 0x45 Chrontel */
765 { 0x7e,0x32, 47}, /* 0x46 Chrontel */
766 { 0x8a,0x24, 31}, /* 0x47 Chrontel */
767 { 0x97,0x2c, 26}, /* 0x48 Chrontel */
768 { 0xce,0x3c, 39}, /* 0x49 */
769 { 0x52,0x4a, 36}, /* 0x4a Chrontel */
770 { 0x34,0x61, 95}, /* 0x4b */
771 { 0x78,0x27,108}, /* 0x4c - was 102 */
772 { 0x66,0x43,123}, /* 0x4d Modes 0x26-0x28 (1400x1050) */
773 { 0x41,0x4e, 21}, /* 0x4e */
774 { 0xa1,0x4a, 29}, /* 0x4f Chrontel */
775 { 0x19,0x42, 42}, /* 0x50 */
776 { 0x54,0x46, 58}, /* 0x51 Chrontel */
777 { 0x25,0x42, 61}, /* 0x52 */
778 { 0x44,0x44, 66}, /* 0x53 Chrontel */
779 { 0x3a,0x62, 70}, /* 0x54 Chrontel */
780 { 0x62,0xc6, 34}, /* 0x55 848x480-60 */
781 { 0x6a,0xc6, 37}, /* 0x56 848x480-75 - TEMP */
782 { 0xbf,0xc8, 35}, /* 0x57 856x480-38i,60 */
783 { 0x30,0x23, 88}, /* 0x58 1360x768-62 (is 60Hz!) */
784 { 0x52,0x07,149}, /* 0x59 1280x960-85 */
785 { 0x56,0x07,156}, /* 0x5a 1400x1050-75 */
786 { 0x70,0x29, 81}, /* 0x5b 1280x768 LCD */
787 { 0x45,0x25, 83}, /* 0x5c 1280x800 */
788 { 0x70,0x0a,147}, /* 0x5d 1680x1050 */
789 { 0x70,0x24,162}, /* 0x5e 1600x1200 */
790 { 0x5a,0x64, 65}, /* 0x5f 1280x720 - temp */
791 { 0x63,0x46, 68}, /* 0x60 1280x768_2 */
792 { 0x31,0x42, 79}, /* 0x61 1280x768_3 - temp */
793 { 0, 0, 0}, /* 0x62 - custom (will be filled out at run-time) */
794 { 0x5a,0x64, 65}, /* 0x63 1280x720 (LCD LVDS) */
795 { 0x70,0x28, 90}, /* 0x64 1152x864@60 */
796 { 0x41,0xc4, 32}, /* 0x65 848x480@60 */
797 { 0x5c,0xc6, 32}, /* 0x66 856x480@60 */
798 { 0x76,0xe7, 27}, /* 0x67 720x480@60 */
799 { 0x5f,0xc6, 33}, /* 0x68 720/768x576@60 */
800 { 0x52,0x27, 75}, /* 0x69 1920x1080i 60Hz interlaced */
801 { 0x7c,0x6b, 38}, /* 0x6a 960x540@60 */
802 { 0xe3,0x56, 41}, /* 0x6b 960x600@60 */
803 { 0x45,0x25, 83}, /* 0x6c 1280x800 */
804 { 0x70,0x28, 90}, /* 0x6d 1152x864@60 */
805 { 0x15,0xe1, 20}, /* 0x6e 640x400@60 (fake, not actually used) */
806 { 0x5f,0xc6, 33}, /* 0x6f 720x576@60 */
807 { 0x37,0x5a, 10}, /* 0x70 320x200@60 (fake, not actually used) */
808 { 0x2b,0xc2, 35} /* 0x71 768@576@60 */
809};
810
811void SiSUSBRegInit(struct SiS_Private *SiS_Pr, unsigned long BaseAddr);
812unsigned short SiSUSB_GetModeID(int HDisplay, int VDisplay, int Depth);
813int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
814int SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo);
815
816extern int sisusb_setreg(struct sisusb_usb_data *sisusb, int port, u8 data);
817extern int sisusb_getreg(struct sisusb_usb_data *sisusb, int port, u8 *data);
818extern int sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port,
819 u8 index, u8 data);
820extern int sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port,
821 u8 index, u8 *data);
822extern int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port,
823 u8 idx, u8 myand, u8 myor);
824extern int sisusb_setidxregor(struct sisusb_usb_data *sisusb, int port,
825 u8 index, u8 myor);
826extern int sisusb_setidxregand(struct sisusb_usb_data *sisusb, int port,
827 u8 idx, u8 myand);
828
829#endif
830
diff --git a/drivers/usb/misc/sisusbvga/sisusb_struct.h b/drivers/usb/misc/sisusbvga/sisusb_struct.h
new file mode 100644
index 000000000000..94edd4726c42
--- /dev/null
+++ b/drivers/usb/misc/sisusbvga/sisusb_struct.h
@@ -0,0 +1,169 @@
1/*
2 * General structure definitions for universal mode switching modules
3 *
4 * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
5 *
6 * If distributed as part of the Linux kernel, the following license terms
7 * apply:
8 *
9 * * This program is free software; you can redistribute it and/or modify
10 * * it under the terms of the GNU General Public License as published by
11 * * the Free Software Foundation; either version 2 of the named License,
12 * * or any later version.
13 * *
14 * * This program is distributed in the hope that it will be useful,
15 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * * GNU General Public License for more details.
18 * *
19 * * You should have received a copy of the GNU General Public License
20 * * along with this program; if not, write to the Free Software
21 * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
22 *
23 * Otherwise, the following license terms apply:
24 *
25 * * Redistribution and use in source and binary forms, with or without
26 * * modification, are permitted provided that the following conditions
27 * * are met:
28 * * 1) Redistributions of source code must retain the above copyright
29 * * notice, this list of conditions and the following disclaimer.
30 * * 2) Redistributions in binary form must reproduce the above copyright
31 * * notice, this list of conditions and the following disclaimer in the
32 * * documentation and/or other materials provided with the distribution.
33 * * 3) The name of the author may not be used to endorse or promote products
34 * * derived from this software without specific prior written permission.
35 * *
36 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
37 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
40 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
45 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 *
47 * Author: Thomas Winischhofer <thomas@winischhofer.net>
48 *
49 */
50
51#ifndef _SISUSB_STRUCT_H_
52#define _SISUSB_STRUCT_H_
53
54struct SiS_St {
55 unsigned char St_ModeID;
56 unsigned short St_ModeFlag;
57 unsigned char St_StTableIndex;
58 unsigned char St_CRT2CRTC;
59 unsigned char St_ResInfo;
60 unsigned char VB_StTVFlickerIndex;
61 unsigned char VB_StTVEdgeIndex;
62 unsigned char VB_StTVYFilterIndex;
63 unsigned char St_PDC;
64};
65
66struct SiS_StandTable
67{
68 unsigned char CRT_COLS;
69 unsigned char ROWS;
70 unsigned char CHAR_HEIGHT;
71 unsigned short CRT_LEN;
72 unsigned char SR[4];
73 unsigned char MISC;
74 unsigned char CRTC[0x19];
75 unsigned char ATTR[0x14];
76 unsigned char GRC[9];
77};
78
79struct SiS_StResInfo_S {
80 unsigned short HTotal;
81 unsigned short VTotal;
82};
83
84struct SiS_Ext
85{
86 unsigned char Ext_ModeID;
87 unsigned short Ext_ModeFlag;
88 unsigned short Ext_VESAID;
89 unsigned char Ext_RESINFO;
90 unsigned char VB_ExtTVFlickerIndex;
91 unsigned char VB_ExtTVEdgeIndex;
92 unsigned char VB_ExtTVYFilterIndex;
93 unsigned char VB_ExtTVYFilterIndexROM661;
94 unsigned char REFindex;
95 char ROMMODEIDX661;
96};
97
98struct SiS_Ext2
99{
100 unsigned short Ext_InfoFlag;
101 unsigned char Ext_CRT1CRTC;
102 unsigned char Ext_CRTVCLK;
103 unsigned char Ext_CRT2CRTC;
104 unsigned char Ext_CRT2CRTC_NS;
105 unsigned char ModeID;
106 unsigned short XRes;
107 unsigned short YRes;
108 unsigned char Ext_PDC;
109 unsigned char Ext_FakeCRT2CRTC;
110 unsigned char Ext_FakeCRT2Clk;
111};
112
113struct SiS_CRT1Table
114{
115 unsigned char CR[17];
116};
117
118struct SiS_VCLKData
119{
120 unsigned char SR2B,SR2C;
121 unsigned short CLOCK;
122};
123
124struct SiS_ModeResInfo
125{
126 unsigned short HTotal;
127 unsigned short VTotal;
128 unsigned char XChar;
129 unsigned char YChar;
130};
131
132struct SiS_Private
133{
134 void *sisusb;
135
136 unsigned long IOAddress;
137
138 unsigned long SiS_P3c4;
139 unsigned long SiS_P3d4;
140 unsigned long SiS_P3c0;
141 unsigned long SiS_P3ce;
142 unsigned long SiS_P3c2;
143 unsigned long SiS_P3ca;
144 unsigned long SiS_P3c6;
145 unsigned long SiS_P3c7;
146 unsigned long SiS_P3c8;
147 unsigned long SiS_P3c9;
148 unsigned long SiS_P3cb;
149 unsigned long SiS_P3cc;
150 unsigned long SiS_P3cd;
151 unsigned long SiS_P3da;
152 unsigned long SiS_Part1Port;
153
154 unsigned char SiS_MyCR63;
155 unsigned short SiS_CRT1Mode;
156 unsigned short SiS_ModeType;
157 unsigned short SiS_SetFlag;
158
159 const struct SiS_StandTable *SiS_StandTable;
160 const struct SiS_St *SiS_SModeIDTable;
161 const struct SiS_Ext *SiS_EModeIDTable;
162 const struct SiS_Ext2 *SiS_RefIndex;
163 const struct SiS_CRT1Table *SiS_CRT1Table;
164 struct SiS_VCLKData *SiS_VCLKData;
165 const struct SiS_ModeResInfo *SiS_ModeResInfo;
166};
167
168#endif
169
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index fd7fb98e4b20..54799eb0bc60 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -986,7 +986,6 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
986 986
987 u->context = &context; 987 u->context = &context;
988 u->complete = ctrl_complete; 988 u->complete = ctrl_complete;
989 u->transfer_flags |= URB_ASYNC_UNLINK;
990 } 989 }
991 990
992 /* queue the urbs */ 991 /* queue the urbs */
@@ -1052,7 +1051,6 @@ static int unlink1 (struct usbtest_dev *dev, int pipe, int size, int async)
1052 urb = simple_alloc_urb (testdev_to_usbdev (dev), pipe, size); 1051 urb = simple_alloc_urb (testdev_to_usbdev (dev), pipe, size);
1053 if (!urb) 1052 if (!urb)
1054 return -ENOMEM; 1053 return -ENOMEM;
1055 urb->transfer_flags |= URB_ASYNC_UNLINK;
1056 urb->context = &completion; 1054 urb->context = &completion;
1057 urb->complete = unlink1_callback; 1055 urb->complete = unlink1_callback;
1058 1056
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index faa74436de52..03fb70ef2eb3 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -3,8 +3,8 @@
3/* 3/*
4 * uss720.c -- USS720 USB Parport Cable. 4 * uss720.c -- USS720 USB Parport Cable.
5 * 5 *
6 * Copyright (C) 1999 6 * Copyright (C) 1999, 2005
7 * Thomas Sailer (sailer@ife.ee.ethz.ch) 7 * Thomas Sailer (t.sailer@alumni.ethz.ch)
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -23,103 +23,240 @@
23 * Based on parport_pc.c 23 * Based on parport_pc.c
24 * 24 *
25 * History: 25 * History:
26 * 0.1 04.08.99 Created 26 * 0.1 04.08.1999 Created
27 * 0.2 07.08.99 Some fixes mainly suggested by Tim Waugh 27 * 0.2 07.08.1999 Some fixes mainly suggested by Tim Waugh
28 * Interrupt handling currently disabled because 28 * Interrupt handling currently disabled because
29 * usb_request_irq crashes somewhere within ohci.c 29 * usb_request_irq crashes somewhere within ohci.c
30 * for no apparent reason (that is for me, anyway) 30 * for no apparent reason (that is for me, anyway)
31 * ECP currently untested 31 * ECP currently untested
32 * 0.3 10.08.99 fixing merge errors 32 * 0.3 10.08.1999 fixing merge errors
33 * 0.4 13.08.99 Added Vendor/Product ID of Brad Hard's cable 33 * 0.4 13.08.1999 Added Vendor/Product ID of Brad Hard's cable
34 * 0.5 20.09.99 usb_control_msg wrapper used 34 * 0.5 20.09.1999 usb_control_msg wrapper used
35 * Nov01.00 usb_device_table support by Adam J. Richter 35 * Nov01.2000 usb_device_table support by Adam J. Richter
36 * 08.04.01 Identify version on module load. gb 36 * 08.04.2001 Identify version on module load. gb
37 * 0.6 02.09.2005 Fix "scheduling in interrupt" problem by making save/restore
38 * context asynchronous
37 * 39 *
38 */ 40 */
39 41
40/*****************************************************************************/ 42/*****************************************************************************/
41 43
44#define DEBUG
45
42#include <linux/module.h> 46#include <linux/module.h>
43#include <linux/socket.h> 47#include <linux/socket.h>
44#include <linux/parport.h> 48#include <linux/parport.h>
45#include <linux/init.h> 49#include <linux/init.h>
46#include <linux/usb.h> 50#include <linux/usb.h>
47#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/completion.h>
53#include <linux/kref.h>
48 54
49/* 55/*
50 * Version Information 56 * Version Information
51 */ 57 */
52#define DRIVER_VERSION "v0.5" 58#define DRIVER_VERSION "v0.6"
53#define DRIVER_AUTHOR "Thomas M. Sailer, sailer@ife.ee.ethz.ch" 59#define DRIVER_AUTHOR "Thomas M. Sailer, t.sailer@alumni.ethz.ch"
54#define DRIVER_DESC "USB Parport Cable driver for Cables using the Lucent Technologies USS720 Chip" 60#define DRIVER_DESC "USB Parport Cable driver for Cables using the Lucent Technologies USS720 Chip"
55 61
56/* --------------------------------------------------------------------- */ 62/* --------------------------------------------------------------------- */
57 63
58struct parport_uss720_private { 64struct parport_uss720_private {
59 struct usb_device *usbdev; 65 struct usb_device *usbdev;
60 void *irqhandle; 66 struct parport *pp;
61 unsigned int irqpipe; 67 struct kref ref_count;
62 unsigned char reg[7]; /* USB registers */ 68 __u8 reg[7]; /* USB registers */
69 struct list_head asynclist;
70 spinlock_t asynclock;
71};
72
73struct uss720_async_request {
74 struct parport_uss720_private *priv;
75 struct kref ref_count;
76 struct list_head asynclist;
77 struct completion compl;
78 struct urb *urb;
79 struct usb_ctrlrequest dr;
80 __u8 reg[7];
63}; 81};
64 82
65/* --------------------------------------------------------------------- */ 83/* --------------------------------------------------------------------- */
66 84
67static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val) 85static void destroy_priv(struct kref *kref)
68{ 86{
69 struct parport_uss720_private *priv = pp->private_data; 87 struct parport_uss720_private *priv = container_of(kref, struct parport_uss720_private, ref_count);
70 struct usb_device *usbdev = priv->usbdev;
71 static const unsigned char regindex[9] = {
72 4, 0, 1, 5, 5, 0, 2, 3, 6
73 };
74 int ret;
75 88
76 if (!usbdev) 89 usb_put_dev(priv->usbdev);
77 return -1; 90 kfree(priv);
78 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev,0), 3, 0xc0, ((unsigned int)reg) << 8, 0, priv->reg, 7, 1000); 91 dbg("destroying priv datastructure");
79 if (ret != 7) { 92}
80 printk(KERN_DEBUG "uss720: get_1284_register(%d) failed, status 0x%x expected 7\n", 93
81 (unsigned int)reg, ret); 94static void destroy_async(struct kref *kref)
82 ret = -1; 95{
83 } else { 96 struct uss720_async_request *rq = container_of(kref, struct uss720_async_request, ref_count);
97 struct parport_uss720_private *priv = rq->priv;
98 unsigned long flags;
99
100 if (likely(rq->urb))
101 usb_free_urb(rq->urb);
102 spin_lock_irqsave(&priv->asynclock, flags);
103 list_del_init(&rq->asynclist);
104 spin_unlock_irqrestore(&priv->asynclock, flags);
105 kfree(rq);
106 kref_put(&priv->ref_count, destroy_priv);
107}
108
109/* --------------------------------------------------------------------- */
110
111static void async_complete(struct urb *urb, struct pt_regs *ptregs)
112{
113 struct uss720_async_request *rq;
114 struct parport *pp;
115 struct parport_uss720_private *priv;
116
117 rq = urb->context;
118 priv = rq->priv;
119 pp = priv->pp;
120 if (urb->status) {
121 err("async_complete: urb error %d", urb->status);
122 } else if (rq->dr.bRequest == 3) {
123 memcpy(priv->reg, rq->reg, sizeof(priv->reg));
84#if 0 124#if 0
85 printk(KERN_DEBUG "uss720: get_1284_register(%d) return %02x %02x %02x %02x %02x %02x %02x\n", 125 dbg("async_complete regs %02x %02x %02x %02x %02x %02x %02x",
86 (unsigned int)reg, (unsigned int)priv->reg[0], (unsigned int)priv->reg[1], 126 (unsigned int)priv->reg[0], (unsigned int)priv->reg[1], (unsigned int)priv->reg[2],
87 (unsigned int)priv->reg[2], (unsigned int)priv->reg[3], (unsigned int)priv->reg[4], 127 (unsigned int)priv->reg[3], (unsigned int)priv->reg[4], (unsigned int)priv->reg[5],
88 (unsigned int)priv->reg[5], (unsigned int)priv->reg[6]); 128 (unsigned int)priv->reg[6]);
89#endif 129#endif
90 /* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */ 130 /* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
91 if (priv->reg[2] & priv->reg[1] & 0x10) 131 if (rq->reg[2] & rq->reg[1] & 0x10 && pp)
92 parport_generic_irq(0, pp, NULL); 132 parport_generic_irq(0, pp, NULL);
93 ret = 0;
94 } 133 }
95 if (val) 134 complete(&rq->compl);
96 *val = priv->reg[(reg >= 9) ? 0 : regindex[reg]]; 135 kref_put(&rq->ref_count, destroy_async);
97 return ret;
98} 136}
99 137
100static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val) 138static struct uss720_async_request *submit_async_request(struct parport_uss720_private *priv,
139 __u8 request, __u8 requesttype, __u16 value, __u16 index,
140 unsigned int mem_flags)
101{ 141{
102 struct parport_uss720_private *priv = pp->private_data; 142 struct usb_device *usbdev;
103 struct usb_device *usbdev = priv->usbdev; 143 struct uss720_async_request *rq;
144 unsigned long flags;
104 int ret; 145 int ret;
105 146
147 if (!priv)
148 return NULL;
149 usbdev = priv->usbdev;
106 if (!usbdev) 150 if (!usbdev)
107 return -1; 151 return NULL;
108 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev,0), 4, 0x40, (((unsigned int)reg) << 8) | val, 0, NULL, 0, 1000); 152 rq = kmalloc(sizeof(struct uss720_async_request), mem_flags);
109 if (ret) { 153 if (!rq) {
110 printk(KERN_DEBUG "uss720: set_1284_register(%u,0x%02x) failed, status 0x%x\n", 154 err("submit_async_request out of memory");
111 (unsigned int)reg, (unsigned int)val, ret); 155 return NULL;
112 } else { 156 }
113#if 0 157 kref_init(&rq->ref_count);
114 printk(KERN_DEBUG "uss720: set_1284_register(%u,0x%02x)\n", 158 INIT_LIST_HEAD(&rq->asynclist);
115 (unsigned int)reg, (unsigned int)val); 159 init_completion(&rq->compl);
116#endif 160 kref_get(&priv->ref_count);
161 rq->priv = priv;
162 rq->urb = usb_alloc_urb(0, mem_flags);
163 if (!rq->urb) {
164 kref_put(&rq->ref_count, destroy_async);
165 err("submit_async_request out of memory");
166 return NULL;
167 }
168 rq->dr.bRequestType = requesttype;
169 rq->dr.bRequest = request;
170 rq->dr.wValue = cpu_to_le16(value);
171 rq->dr.wIndex = cpu_to_le16(index);
172 rq->dr.wLength = cpu_to_le16((request == 3) ? sizeof(rq->reg) : 0);
173 usb_fill_control_urb(rq->urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0),
174 (unsigned char *)&rq->dr,
175 (request == 3) ? rq->reg : NULL, (request == 3) ? sizeof(rq->reg) : 0, async_complete, rq);
176 /* rq->urb->transfer_flags |= URB_ASYNC_UNLINK; */
177 spin_lock_irqsave(&priv->asynclock, flags);
178 list_add_tail(&rq->asynclist, &priv->asynclist);
179 spin_unlock_irqrestore(&priv->asynclock, flags);
180 ret = usb_submit_urb(rq->urb, mem_flags);
181 if (!ret) {
182 kref_get(&rq->ref_count);
183 return rq;
117 } 184 }
185 kref_put(&rq->ref_count, destroy_async);
186 err("submit_async_request submit_urb failed with %d", ret);
187 return NULL;
188}
189
190static unsigned int kill_all_async_requests_priv(struct parport_uss720_private *priv)
191{
192 struct uss720_async_request *rq;
193 unsigned long flags;
194 unsigned int ret = 0;
195
196 spin_lock_irqsave(&priv->asynclock, flags);
197 list_for_each_entry(rq, &priv->asynclist, asynclist) {
198 usb_unlink_urb(rq->urb);
199 ret++;
200 }
201 spin_unlock_irqrestore(&priv->asynclock, flags);
118 return ret; 202 return ret;
119} 203}
120 204
121/* --------------------------------------------------------------------- */ 205/* --------------------------------------------------------------------- */
122 206
207static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val, unsigned int mem_flags)
208{
209 struct parport_uss720_private *priv;
210 struct uss720_async_request *rq;
211 static const unsigned char regindex[9] = {
212 4, 0, 1, 5, 5, 0, 2, 3, 6
213 };
214 int ret;
215
216 if (!pp)
217 return -EIO;
218 priv = pp->private_data;
219 rq = submit_async_request(priv, 3, 0xc0, ((unsigned int)reg) << 8, 0, mem_flags);
220 if (!rq) {
221 err("get_1284_register(%u) failed", (unsigned int)reg);
222 return -EIO;
223 }
224 if (!val) {
225 kref_put(&rq->ref_count, destroy_async);
226 return 0;
227 }
228 if (wait_for_completion_timeout(&rq->compl, HZ)) {
229 ret = rq->urb->status;
230 *val = priv->reg[(reg >= 9) ? 0 : regindex[reg]];
231 if (ret)
232 warn("get_1284_register: usb error %d", ret);
233 kref_put(&rq->ref_count, destroy_async);
234 return ret;
235 }
236 warn("get_1284_register timeout");
237 kill_all_async_requests_priv(priv);
238 return -EIO;
239}
240
241static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val, unsigned int mem_flags)
242{
243 struct parport_uss720_private *priv;
244 struct uss720_async_request *rq;
245
246 if (!pp)
247 return -EIO;
248 priv = pp->private_data;
249 rq = submit_async_request(priv, 4, 0x40, (((unsigned int)reg) << 8) | val, 0, mem_flags);
250 if (!rq) {
251 err("set_1284_register(%u,%u) failed", (unsigned int)reg, (unsigned int)val);
252 return -EIO;
253 }
254 kref_put(&rq->ref_count, destroy_async);
255 return 0;
256}
257
258/* --------------------------------------------------------------------- */
259
123/* ECR modes */ 260/* ECR modes */
124#define ECR_SPP 00 261#define ECR_SPP 00
125#define ECR_PS2 01 262#define ECR_PS2 01
@@ -132,8 +269,9 @@ static int change_mode(struct parport *pp, int m)
132{ 269{
133 struct parport_uss720_private *priv = pp->private_data; 270 struct parport_uss720_private *priv = pp->private_data;
134 int mode; 271 int mode;
272 __u8 reg;
135 273
136 if (get_1284_register(pp, 6, NULL)) 274 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
137 return -EIO; 275 return -EIO;
138 /* Bits <7:5> contain the mode. */ 276 /* Bits <7:5> contain the mode. */
139 mode = (priv->reg[2] >> 5) & 0x7; 277 mode = (priv->reg[2] >> 5) & 0x7;
@@ -153,7 +291,7 @@ static int change_mode(struct parport *pp, int m)
153 case ECR_ECP: /* ECP Parallel Port mode */ 291 case ECR_ECP: /* ECP Parallel Port mode */
154 /* Poll slowly. */ 292 /* Poll slowly. */
155 for (;;) { 293 for (;;) {
156 if (get_1284_register(pp, 6, NULL)) 294 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
157 return -EIO; 295 return -EIO;
158 if (priv->reg[2] & 0x01) 296 if (priv->reg[2] & 0x01)
159 break; 297 break;
@@ -167,7 +305,9 @@ static int change_mode(struct parport *pp, int m)
167 } 305 }
168 } 306 }
169 /* Set the mode. */ 307 /* Set the mode. */
170 if (set_1284_register(pp, 6, m << 5)) 308 if (set_1284_register(pp, 6, m << 5, GFP_KERNEL))
309 return -EIO;
310 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
171 return -EIO; 311 return -EIO;
172 return 0; 312 return 0;
173} 313}
@@ -179,7 +319,7 @@ static int clear_epp_timeout(struct parport *pp)
179{ 319{
180 unsigned char stat; 320 unsigned char stat;
181 321
182 if (get_1284_register(pp, 1, &stat)) 322 if (get_1284_register(pp, 1, &stat, GFP_KERNEL))
183 return 1; 323 return 1;
184 return stat & 1; 324 return stat & 1;
185} 325}
@@ -205,14 +345,14 @@ static int uss720_irq(int usbstatus, void *buffer, int len, void *dev_id)
205 345
206static void parport_uss720_write_data(struct parport *pp, unsigned char d) 346static void parport_uss720_write_data(struct parport *pp, unsigned char d)
207{ 347{
208 set_1284_register(pp, 0, d); 348 set_1284_register(pp, 0, d, GFP_KERNEL);
209} 349}
210 350
211static unsigned char parport_uss720_read_data(struct parport *pp) 351static unsigned char parport_uss720_read_data(struct parport *pp)
212{ 352{
213 unsigned char ret; 353 unsigned char ret;
214 354
215 if (get_1284_register(pp, 0, &ret)) 355 if (get_1284_register(pp, 0, &ret, GFP_KERNEL))
216 return 0; 356 return 0;
217 return ret; 357 return ret;
218} 358}
@@ -222,7 +362,7 @@ static void parport_uss720_write_control(struct parport *pp, unsigned char d)
222 struct parport_uss720_private *priv = pp->private_data; 362 struct parport_uss720_private *priv = pp->private_data;
223 363
224 d = (d & 0xf) | (priv->reg[1] & 0xf0); 364 d = (d & 0xf) | (priv->reg[1] & 0xf0);
225 if (set_1284_register(pp, 2, d)) 365 if (set_1284_register(pp, 2, d, GFP_KERNEL))
226 return; 366 return;
227 priv->reg[1] = d; 367 priv->reg[1] = d;
228} 368}
@@ -241,7 +381,7 @@ static unsigned char parport_uss720_frob_control(struct parport *pp, unsigned ch
241 mask &= 0x0f; 381 mask &= 0x0f;
242 val &= 0x0f; 382 val &= 0x0f;
243 d = (priv->reg[1] & (~mask)) ^ val; 383 d = (priv->reg[1] & (~mask)) ^ val;
244 if (set_1284_register(pp, 2, d)) 384 if (set_1284_register(pp, 2, d, GFP_KERNEL))
245 return 0; 385 return 0;
246 priv->reg[1] = d; 386 priv->reg[1] = d;
247 return d & 0xf; 387 return d & 0xf;
@@ -251,7 +391,7 @@ static unsigned char parport_uss720_read_status(struct parport *pp)
251{ 391{
252 unsigned char ret; 392 unsigned char ret;
253 393
254 if (get_1284_register(pp, 1, &ret)) 394 if (get_1284_register(pp, 1, &ret, GFP_KERNEL))
255 return 0; 395 return 0;
256 return ret & 0xf8; 396 return ret & 0xf8;
257} 397}
@@ -262,7 +402,7 @@ static void parport_uss720_disable_irq(struct parport *pp)
262 unsigned char d; 402 unsigned char d;
263 403
264 d = priv->reg[1] & ~0x10; 404 d = priv->reg[1] & ~0x10;
265 if (set_1284_register(pp, 2, d)) 405 if (set_1284_register(pp, 2, d, GFP_KERNEL))
266 return; 406 return;
267 priv->reg[1] = d; 407 priv->reg[1] = d;
268} 408}
@@ -273,7 +413,7 @@ static void parport_uss720_enable_irq(struct parport *pp)
273 unsigned char d; 413 unsigned char d;
274 414
275 d = priv->reg[1] | 0x10; 415 d = priv->reg[1] | 0x10;
276 if (set_1284_register(pp, 2, d)) 416 if (set_1284_register(pp, 2, d, GFP_KERNEL))
277 return; 417 return;
278 priv->reg[1] = d; 418 priv->reg[1] = d;
279} 419}
@@ -284,7 +424,7 @@ static void parport_uss720_data_forward (struct parport *pp)
284 unsigned char d; 424 unsigned char d;
285 425
286 d = priv->reg[1] & ~0x20; 426 d = priv->reg[1] & ~0x20;
287 if (set_1284_register(pp, 2, d)) 427 if (set_1284_register(pp, 2, d, GFP_KERNEL))
288 return; 428 return;
289 priv->reg[1] = d; 429 priv->reg[1] = d;
290} 430}
@@ -295,7 +435,7 @@ static void parport_uss720_data_reverse (struct parport *pp)
295 unsigned char d; 435 unsigned char d;
296 436
297 d = priv->reg[1] | 0x20; 437 d = priv->reg[1] | 0x20;
298 if (set_1284_register(pp, 2, d)) 438 if (set_1284_register(pp, 2, d, GFP_KERNEL))
299 return; 439 return;
300 priv->reg[1] = d; 440 priv->reg[1] = d;
301} 441}
@@ -310,17 +450,23 @@ static void parport_uss720_save_state(struct parport *pp, struct parport_state *
310{ 450{
311 struct parport_uss720_private *priv = pp->private_data; 451 struct parport_uss720_private *priv = pp->private_data;
312 452
313 if (get_1284_register(pp, 2, NULL)) 453#if 0
454 if (get_1284_register(pp, 2, NULL, GFP_ATOMIC))
314 return; 455 return;
456#endif
315 s->u.pc.ctr = priv->reg[1]; 457 s->u.pc.ctr = priv->reg[1];
316 s->u.pc.ecr = priv->reg[2]; 458 s->u.pc.ecr = priv->reg[2];
317} 459}
318 460
319static void parport_uss720_restore_state(struct parport *pp, struct parport_state *s) 461static void parport_uss720_restore_state(struct parport *pp, struct parport_state *s)
320{ 462{
321 set_1284_register(pp, 2, s->u.pc.ctr); 463 struct parport_uss720_private *priv = pp->private_data;
322 set_1284_register(pp, 6, s->u.pc.ecr); 464
323 get_1284_register(pp, 2, NULL); 465 set_1284_register(pp, 2, s->u.pc.ctr, GFP_ATOMIC);
466 set_1284_register(pp, 6, s->u.pc.ecr, GFP_ATOMIC);
467 get_1284_register(pp, 2, NULL, GFP_ATOMIC);
468 priv->reg[1] = s->u.pc.ctr;
469 priv->reg[2] = s->u.pc.ecr;
324} 470}
325 471
326static size_t parport_uss720_epp_read_data(struct parport *pp, void *buf, size_t length, int flags) 472static size_t parport_uss720_epp_read_data(struct parport *pp, void *buf, size_t length, int flags)
@@ -331,7 +477,7 @@ static size_t parport_uss720_epp_read_data(struct parport *pp, void *buf, size_t
331 if (change_mode(pp, ECR_EPP)) 477 if (change_mode(pp, ECR_EPP))
332 return 0; 478 return 0;
333 for (; got < length; got++) { 479 for (; got < length; got++) {
334 if (get_1284_register(pp, 4, (char *)buf)) 480 if (get_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
335 break; 481 break;
336 buf++; 482 buf++;
337 if (priv->reg[0] & 0x01) { 483 if (priv->reg[0] & 0x01) {
@@ -352,10 +498,10 @@ static size_t parport_uss720_epp_write_data(struct parport *pp, const void *buf,
352 if (change_mode(pp, ECR_EPP)) 498 if (change_mode(pp, ECR_EPP))
353 return 0; 499 return 0;
354 for (; written < length; written++) { 500 for (; written < length; written++) {
355 if (set_1284_register(pp, 4, (char *)buf)) 501 if (set_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
356 break; 502 break;
357 ((char*)buf)++; 503 ((char*)buf)++;
358 if (get_1284_register(pp, 1, NULL)) 504 if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
359 break; 505 break;
360 if (priv->reg[0] & 0x01) { 506 if (priv->reg[0] & 0x01) {
361 clear_epp_timeout(pp); 507 clear_epp_timeout(pp);
@@ -390,7 +536,7 @@ static size_t parport_uss720_epp_read_addr(struct parport *pp, void *buf, size_t
390 if (change_mode(pp, ECR_EPP)) 536 if (change_mode(pp, ECR_EPP))
391 return 0; 537 return 0;
392 for (; got < length; got++) { 538 for (; got < length; got++) {
393 if (get_1284_register(pp, 3, (char *)buf)) 539 if (get_1284_register(pp, 3, (char *)buf, GFP_KERNEL))
394 break; 540 break;
395 buf++; 541 buf++;
396 if (priv->reg[0] & 0x01) { 542 if (priv->reg[0] & 0x01) {
@@ -410,10 +556,10 @@ static size_t parport_uss720_epp_write_addr(struct parport *pp, const void *buf,
410 if (change_mode(pp, ECR_EPP)) 556 if (change_mode(pp, ECR_EPP))
411 return 0; 557 return 0;
412 for (; written < length; written++) { 558 for (; written < length; written++) {
413 if (set_1284_register(pp, 3, *(char *)buf)) 559 if (set_1284_register(pp, 3, *(char *)buf, GFP_KERNEL))
414 break; 560 break;
415 buf++; 561 buf++;
416 if (get_1284_register(pp, 1, NULL)) 562 if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
417 break; 563 break;
418 if (priv->reg[0] & 0x01) { 564 if (priv->reg[0] & 0x01) {
419 clear_epp_timeout(pp); 565 clear_epp_timeout(pp);
@@ -467,7 +613,7 @@ static size_t parport_uss720_ecp_write_addr(struct parport *pp, const void *buff
467 if (change_mode(pp, ECR_ECP)) 613 if (change_mode(pp, ECR_ECP))
468 return 0; 614 return 0;
469 for (; written < len; written++) { 615 for (; written < len; written++) {
470 if (set_1284_register(pp, 5, *(char *)buffer)) 616 if (set_1284_register(pp, 5, *(char *)buffer, GFP_KERNEL))
471 break; 617 break;
472 buffer++; 618 buffer++;
473 } 619 }
@@ -536,93 +682,91 @@ static struct parport_operations parport_uss720_ops =
536static int uss720_probe(struct usb_interface *intf, 682static int uss720_probe(struct usb_interface *intf,
537 const struct usb_device_id *id) 683 const struct usb_device_id *id)
538{ 684{
539 struct usb_device *usbdev = interface_to_usbdev(intf); 685 struct usb_device *usbdev = usb_get_dev(interface_to_usbdev(intf));
540 struct usb_host_interface *interface; 686 struct usb_host_interface *interface;
541 struct usb_host_endpoint *endpoint; 687 struct usb_host_endpoint *endpoint;
542 struct parport_uss720_private *priv; 688 struct parport_uss720_private *priv;
543 struct parport *pp; 689 struct parport *pp;
690 unsigned char reg;
544 int i; 691 int i;
545 692
546 printk(KERN_DEBUG "uss720: probe: vendor id 0x%x, device id 0x%x\n", 693 dbg("probe: vendor id 0x%x, device id 0x%x\n",
547 le16_to_cpu(usbdev->descriptor.idVendor), 694 le16_to_cpu(usbdev->descriptor.idVendor),
548 le16_to_cpu(usbdev->descriptor.idProduct)); 695 le16_to_cpu(usbdev->descriptor.idProduct));
549 696
550 /* our known interfaces have 3 alternate settings */ 697 /* our known interfaces have 3 alternate settings */
551 if (intf->num_altsetting != 3) 698 if (intf->num_altsetting != 3) {
699 usb_put_dev(usbdev);
552 return -ENODEV; 700 return -ENODEV;
553 701 }
554 i = usb_set_interface(usbdev, intf->altsetting->desc.bInterfaceNumber, 2); 702 i = usb_set_interface(usbdev, intf->altsetting->desc.bInterfaceNumber, 2);
555 printk(KERN_DEBUG "uss720: set inteface result %d\n", i); 703 dbg("set inteface result %d", i);
556 704
557 interface = intf->cur_altsetting; 705 interface = intf->cur_altsetting;
558 706
559 /* 707 /*
560 * Allocate parport interface 708 * Allocate parport interface
561 */ 709 */
562 printk(KERN_INFO "uss720: (C) 1999 by Thomas Sailer, <sailer@ife.ee.ethz.ch>\n"); 710 if (!(priv = kcalloc(sizeof(struct parport_uss720_private), 1, GFP_KERNEL))) {
563 711 usb_put_dev(usbdev);
564 if (!(priv = kmalloc(sizeof(struct parport_uss720_private), GFP_KERNEL)))
565 return -ENOMEM; 712 return -ENOMEM;
713 }
714 priv->pp = NULL;
715 priv->usbdev = usbdev;
716 kref_init(&priv->ref_count);
717 spin_lock_init(&priv->asynclock);
718 INIT_LIST_HEAD(&priv->asynclist);
566 if (!(pp = parport_register_port(0, PARPORT_IRQ_NONE, PARPORT_DMA_NONE, &parport_uss720_ops))) { 719 if (!(pp = parport_register_port(0, PARPORT_IRQ_NONE, PARPORT_DMA_NONE, &parport_uss720_ops))) {
567 printk(KERN_WARNING "usb-uss720: could not register parport\n"); 720 warn("could not register parport");
568 goto probe_abort; 721 goto probe_abort;
569 } 722 }
570 723
724 priv->pp = pp;
571 pp->private_data = priv; 725 pp->private_data = priv;
572 priv->usbdev = usbdev;
573 pp->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP | PARPORT_MODE_ECP | PARPORT_MODE_COMPAT; 726 pp->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP | PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
574 727
575 /* set the USS720 control register to manual mode, no ECP compression, enable all ints */ 728 /* set the USS720 control register to manual mode, no ECP compression, enable all ints */
576 set_1284_register(pp, 7, 0x00); 729 set_1284_register(pp, 7, 0x00, GFP_KERNEL);
577 set_1284_register(pp, 6, 0x30); /* PS/2 mode */ 730 set_1284_register(pp, 6, 0x30, GFP_KERNEL); /* PS/2 mode */
578 set_1284_register(pp, 2, 0x0c); 731 set_1284_register(pp, 2, 0x0c, GFP_KERNEL);
579 /* debugging */ 732 /* debugging */
580 get_1284_register(pp, 0, NULL); 733 get_1284_register(pp, 0, &reg, GFP_KERNEL);
581 printk("uss720: reg: %02x %02x %02x %02x %02x %02x %02x\n", 734 dbg("reg: %02x %02x %02x %02x %02x %02x %02x",
582 priv->reg[0], priv->reg[1], priv->reg[2], priv->reg[3], priv->reg[4], priv->reg[5], priv->reg[6]); 735 priv->reg[0], priv->reg[1], priv->reg[2], priv->reg[3], priv->reg[4], priv->reg[5], priv->reg[6]);
583 736
584 endpoint = &interface->endpoint[2]; 737 endpoint = &interface->endpoint[2];
585 printk(KERN_DEBUG "uss720: epaddr %d interval %d\n", endpoint->desc.bEndpointAddress, endpoint->desc.bInterval); 738 dbg("epaddr %d interval %d", endpoint->desc.bEndpointAddress, endpoint->desc.bInterval);
586#if 0
587 priv->irqpipe = usb_rcvctrlpipe(usbdev, endpoint->bEndpointAddress);
588 i = usb_request_irq(usbdev, priv->irqpipe,
589 uss720_irq, endpoint->bInterval,
590 pp, &priv->irqhandle);
591 if (i) {
592 printk (KERN_WARNING "usb-uss720: usb_request_irq failed (0x%x)\n", i);
593 goto probe_abort_port;
594 }
595#endif
596 parport_announce_port(pp); 739 parport_announce_port(pp);
597 740
598 usb_set_intfdata (intf, pp); 741 usb_set_intfdata(intf, pp);
599 return 0; 742 return 0;
600 743
601#if 0
602probe_abort_port:
603 parport_put_port(pp);
604#endif
605probe_abort: 744probe_abort:
606 kfree(priv); 745 kill_all_async_requests_priv(priv);
746 kref_put(&priv->ref_count, destroy_priv);
607 return -ENODEV; 747 return -ENODEV;
608} 748}
609 749
610static void uss720_disconnect(struct usb_interface *intf) 750static void uss720_disconnect(struct usb_interface *intf)
611{ 751{
612 struct parport *pp = usb_get_intfdata (intf); 752 struct parport *pp = usb_get_intfdata(intf);
613 struct parport_uss720_private *priv; 753 struct parport_uss720_private *priv;
754 struct usb_device *usbdev;
614 755
615 usb_set_intfdata (intf, NULL); 756 dbg("disconnect");
757 usb_set_intfdata(intf, NULL);
616 if (pp) { 758 if (pp) {
617 priv = pp->private_data; 759 priv = pp->private_data;
618 parport_remove_port(pp); 760 usbdev = priv->usbdev;
619#if 0
620 usb_release_irq(usbdev, priv->irqhandle, priv->irqpipe);
621#endif
622 priv->usbdev = NULL; 761 priv->usbdev = NULL;
762 priv->pp = NULL;
763 dbg("parport_remove_port");
764 parport_remove_port(pp);
623 parport_put_port(pp); 765 parport_put_port(pp);
624 kfree(priv); 766 kill_all_async_requests_priv(priv);
767 kref_put(&priv->ref_count, destroy_priv);
625 } 768 }
769 dbg("disconnect done");
626} 770}
627 771
628/* table of cables that work through this driver */ 772/* table of cables that work through this driver */
@@ -647,8 +791,8 @@ static struct usb_driver uss720_driver = {
647 791
648/* --------------------------------------------------------------------- */ 792/* --------------------------------------------------------------------- */
649 793
650MODULE_AUTHOR( DRIVER_AUTHOR ); 794MODULE_AUTHOR(DRIVER_AUTHOR);
651MODULE_DESCRIPTION( DRIVER_DESC ); 795MODULE_DESCRIPTION(DRIVER_DESC);
652MODULE_LICENSE("GPL"); 796MODULE_LICENSE("GPL");
653 797
654static int __init uss720_init(void) 798static int __init uss720_init(void)
@@ -659,6 +803,9 @@ static int __init uss720_init(void)
659 goto out; 803 goto out;
660 804
661 info(DRIVER_VERSION ":" DRIVER_DESC); 805 info(DRIVER_VERSION ":" DRIVER_DESC);
806 info("NOTE: this is a special purpose driver to allow nonstandard");
807 info("protocols (eg. bitbang) over USS720 usb to parallel cables");
808 info("If you just want to connect to a printer, use usblp instead");
662out: 809out:
663 return retval; 810 return retval;
664} 811}
diff --git a/drivers/usb/mon/Makefile b/drivers/usb/mon/Makefile
index b0015b8a1d1f..3cf3ea3a88ed 100644
--- a/drivers/usb/mon/Makefile
+++ b/drivers/usb/mon/Makefile
@@ -2,7 +2,7 @@
2# Makefile for USB Core files and filesystem 2# Makefile for USB Core files and filesystem
3# 3#
4 4
5usbmon-objs := mon_main.o mon_stat.o mon_text.o 5usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_dma.o
6 6
7# This does not use CONFIG_USB_MON because we want this to use a tristate. 7# This does not use CONFIG_USB_MON because we want this to use a tristate.
8obj-$(CONFIG_USB) += usbmon.o 8obj-$(CONFIG_USB) += usbmon.o
diff --git a/drivers/usb/mon/mon_dma.c b/drivers/usb/mon/mon_dma.c
new file mode 100644
index 000000000000..0a1367b760a0
--- /dev/null
+++ b/drivers/usb/mon/mon_dma.c
@@ -0,0 +1,55 @@
1/*
2 * The USB Monitor, inspired by Dave Harding's USBMon.
3 *
4 * mon_dma.c: Library which snoops on DMA areas.
5 *
6 * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com)
7 */
8#include <linux/kernel.h>
9#include <linux/list.h>
10#include <linux/highmem.h>
11#include <asm/page.h>
12
13#include <linux/usb.h> /* Only needed for declarations in usb_mon.h */
14#include "usb_mon.h"
15
16#ifdef __i386__ /* CONFIG_ARCH_I386 does not exit */
17#define MON_HAS_UNMAP 1
18
19#define phys_to_page(phys) pfn_to_page((phys) >> PAGE_SHIFT)
20
21char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
22{
23 struct page *pg;
24 unsigned long flags;
25 unsigned char *map;
26 unsigned char *ptr;
27
28 /*
29 * On i386, a DMA handle is the "physical" address of a page.
30 * In other words, the bus address is equal to physical address.
31 * There is no IOMMU.
32 */
33 pg = phys_to_page(dma_addr);
34
35 /*
36 * We are called from hardware IRQs in case of callbacks.
37 * But we can be called from softirq or process context in case
38 * of submissions. In such case, we need to protect KM_IRQ0.
39 */
40 local_irq_save(flags);
41 map = kmap_atomic(pg, KM_IRQ0);
42 ptr = map + (dma_addr & (PAGE_SIZE-1));
43 memcpy(dst, ptr, len);
44 kunmap_atomic(map, KM_IRQ0);
45 local_irq_restore(flags);
46 return 0;
47}
48#endif /* __i386__ */
49
50#ifndef MON_HAS_UNMAP
51char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
52{
53 return 'D';
54}
55#endif
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 26266b30028e..17d0190ef64e 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -79,7 +79,7 @@ static inline char mon_text_get_setup(struct mon_event_text *ep,
79 return '-'; 79 return '-';
80 80
81 if (urb->transfer_flags & URB_NO_SETUP_DMA_MAP) 81 if (urb->transfer_flags & URB_NO_SETUP_DMA_MAP)
82 return 'D'; 82 return mon_dmapeek(ep->setup, urb->setup_dma, SETUP_MAX);
83 if (urb->setup_packet == NULL) 83 if (urb->setup_packet == NULL)
84 return 'Z'; /* '0' would be not as pretty. */ 84 return 'Z'; /* '0' would be not as pretty. */
85 85
@@ -91,25 +91,11 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
91 int len, char ev_type) 91 int len, char ev_type)
92{ 92{
93 int pipe = urb->pipe; 93 int pipe = urb->pipe;
94 unsigned char *data;
95
96 /*
97 * The check to see if it's safe to poke at data has an enormous
98 * number of corner cases, but it seems that the following is
99 * more or less safe.
100 *
101 * We do not even try to look transfer_buffer, because it can
102 * contain non-NULL garbage in case the upper level promised to
103 * set DMA for the HCD.
104 */
105 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
106 return 'D';
107 94
108 if (len <= 0) 95 if (len <= 0)
109 return 'L'; 96 return 'L';
110 97 if (len >= DATA_MAX)
111 if ((data = urb->transfer_buffer) == NULL) 98 len = DATA_MAX;
112 return 'Z'; /* '0' would be not as pretty. */
113 99
114 /* 100 /*
115 * Bulk is easy to shortcut reliably. 101 * Bulk is easy to shortcut reliably.
@@ -126,8 +112,21 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
126 } 112 }
127 } 113 }
128 114
129 if (len >= DATA_MAX) 115 /*
130 len = DATA_MAX; 116 * The check to see if it's safe to poke at data has an enormous
117 * number of corner cases, but it seems that the following is
118 * more or less safe.
119 *
120 * We do not even try to look transfer_buffer, because it can
121 * contain non-NULL garbage in case the upper level promised to
122 * set DMA for the HCD.
123 */
124 if (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
125 return mon_dmapeek(ep->data, urb->transfer_dma, len);
126
127 if (urb->transfer_buffer == NULL)
128 return 'Z'; /* '0' would be not as pretty. */
129
131 memcpy(ep->data, urb->transfer_buffer, len); 130 memcpy(ep->data, urb->transfer_buffer, len);
132 return 0; 131 return 0;
133} 132}
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h
index 9b06784d2c48..4be0f9346071 100644
--- a/drivers/usb/mon/usb_mon.h
+++ b/drivers/usb/mon/usb_mon.h
@@ -45,6 +45,10 @@ struct mon_reader {
45void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r); 45void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r);
46void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r); 46void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r);
47 47
48/*
49 */
50extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len);
51
48extern struct semaphore mon_lock; 52extern struct semaphore mon_lock;
49 53
50extern struct file_operations mon_fops_text; 54extern struct file_operations mon_fops_text;
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
index b104430e2c6a..8c010bb44eb8 100644
--- a/drivers/usb/net/Kconfig
+++ b/drivers/usb/net/Kconfig
@@ -99,7 +99,7 @@ config USB_USBNET
99 with "minidrivers" built around a common network driver core 99 with "minidrivers" built around a common network driver core
100 that supports deep queues for efficient transfers. (This gives 100 that supports deep queues for efficient transfers. (This gives
101 better performance with small packets and at high speeds). 101 better performance with small packets and at high speeds).
102 102
103 The USB host runs "usbnet", and the other end of the link might be: 103 The USB host runs "usbnet", and the other end of the link might be:
104 104
105 - Another USB host, when using USB "network" or "data transfer" 105 - Another USB host, when using USB "network" or "data transfer"
@@ -125,38 +125,63 @@ config USB_USBNET
125 To compile this driver as a module, choose M here: the 125 To compile this driver as a module, choose M here: the
126 module will be called usbnet. 126 module will be called usbnet.
127 127
128comment "USB Host-to-Host Cables" 128config USB_NET_AX8817X
129 depends on USB_USBNET 129 tristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters"
130 130 depends on USB_USBNET && NET_ETHERNET
131config USB_ALI_M5632 131 select CRC32
132 boolean "ALi M5632 based 'USB 2.0 Data Link' cables" 132 select MII
133 depends on USB_USBNET
134 default y 133 default y
135 help 134 help
136 Choose this option if you're using a host-to-host cable 135 This option adds support for ASIX AX88xxx based USB 2.0
137 based on this design, which supports USB 2.0 high speed. 136 10/100 Ethernet adapters.
138 137
139config USB_AN2720 138 This driver should work with at least the following devices:
140 boolean "AnchorChips 2720 based cables (Xircom PGUNET, ...)" 139 * Aten UC210T
141 depends on USB_USBNET 140 * ASIX AX88172
142 default y 141 * Billionton Systems, USB2AR
143 help 142 * Buffalo LUA-U2-KTX
144 Choose this option if you're using a host-to-host cable 143 * Corega FEther USB2-TX
145 based on this design. Note that AnchorChips is now a 144 * D-Link DUB-E100
146 Cypress brand. 145 * Hawking UF200
146 * Linksys USB200M
147 * Netgear FA120
148 * Sitecom LN-029
149 * Intellinet USB 2.0 Ethernet
150 * ST Lab USB 2.0 Ethernet
151 * TrendNet TU2-ET100
147 152
148config USB_BELKIN 153 This driver creates an interface named "ethX", where X depends on
149 boolean "eTEK based host-to-host cables (Advance, Belkin, ...)" 154 what other networking devices you have in use.
155
156
157config USB_NET_CDCETHER
158 tristate "CDC Ethernet support (smart devices such as cable modems)"
150 depends on USB_USBNET 159 depends on USB_USBNET
151 default y 160 default y
152 help 161 help
153 Choose this option if you're using a host-to-host cable 162 This option supports devices conforming to the Communication Device
154 based on this design: two NetChip 2890 chips and an Atmel 163 Class (CDC) Ethernet Control Model, a specification that's easy to
155 microcontroller, with LEDs that indicate traffic. 164 implement in device firmware. The CDC specifications are available
165 from <http://www.usb.org/>.
156 166
157config USB_GENESYS 167 CDC Ethernet is an implementation option for DOCSIS cable modems
158 boolean "GeneSys GL620USB-A based cables" 168 that support USB connectivity, used for non-Microsoft USB hosts.
159 default y 169 The Linux-USB CDC Ethernet Gadget driver is an open implementation.
170 This driver should work with at least the following devices:
171
172 * Ericsson PipeRider (all variants)
173 * Motorola (DM100 and SB4100)
174 * Broadcom Cable Modem (reference design)
175 * Toshiba PCX1100U
176 * ...
177
178 This driver creates an interface named "ethX", where X depends on
179 what other networking devices you have in use. However, if the
180 IEEE 802 "local assignment" bit is set in the address, a "usbX"
181 name is used instead.
182
183config USB_NET_GL620A
184 tristate "GeneSys GL620USB-A based cables"
160 depends on USB_USBNET 185 depends on USB_USBNET
161 help 186 help
162 Choose this option if you're using a host-to-host cable, 187 Choose this option if you're using a host-to-host cable,
@@ -164,38 +189,78 @@ config USB_GENESYS
164 189
165 Note that the half-duplex "GL620USB" is not supported. 190 Note that the half-duplex "GL620USB" is not supported.
166 191
167config USB_NET1080 192config USB_NET_NET1080
168 boolean "NetChip 1080 based cables (Laplink, ...)" 193 tristate "NetChip 1080 based cables (Laplink, ...)"
169 default y 194 default y
170 depends on USB_USBNET 195 depends on USB_USBNET
171 help 196 help
172 Choose this option if you're using a host-to-host cable based 197 Choose this option if you're using a host-to-host cable based
173 on this design: one NetChip 1080 chips and supporting logic, 198 on this design: one NetChip 1080 chip and supporting logic,
174 supporting LEDs that indicate traffic 199 optionally with LEDs that indicate traffic
175 200
176config USB_PL2301 201config USB_NET_PLUSB
177 boolean "Prolific PL-2301/2302 based cables" 202 tristate "Prolific PL-2301/2302 based cables"
178 default y 203 # if the handshake/init/reset problems, from original 'plusb',
179 # handshake/init/reset problems, from original 'plusb' driver 204 # are ever resolved ... then remove "experimental"
180 depends on USB_USBNET && EXPERIMENTAL 205 depends on USB_USBNET && EXPERIMENTAL
181 help 206 help
182 Choose this option if you're using a host-to-host cable 207 Choose this option if you're using a host-to-host cable
183 with one of these chips. 208 with one of these chips.
184 209
185config USB_KC2190 210config USB_NET_RNDIS_HOST
186 boolean "KT Technology KC2190 based cables (InstaNet)" 211 tristate "Host for RNDIS devices (EXPERIMENTAL)"
187 default y
188 depends on USB_USBNET && EXPERIMENTAL 212 depends on USB_USBNET && EXPERIMENTAL
213 select USB_NET_CDCETHER
189 help 214 help
190 Choose this option if you're using a host-to-host cable 215 This option enables hosting "Remote NDIS" USB networking links,
191 with one of these chips. 216 as encouraged by Microsoft (instead of CDC Ethernet!) for use in
217 various devices that may only support this protocol.
192 218
193comment "Intelligent USB Devices/Gadgets" 219 Avoid using this protocol unless you have no better options.
220 The protocol specification is incomplete, and is controlled by
221 (and for) Microsoft; it isn't an "Open" ecosystem or market.
222
223config USB_NET_CDC_SUBSET
224 tristate "Simple USB Network Links (CDC Ethernet subset)"
194 depends on USB_USBNET 225 depends on USB_USBNET
226 help
227 This driver module supports USB network devices that can work
228 without any device-specific information. Select it if you have
229 one of these drivers.
230
231 Note that while many USB host-to-host cables can work in this mode,
232 that may mean not being able to talk to Win32 systems or more
233 commonly not being able to handle certain events (like replugging
234 the host on the other end) very well. Also, these devices will
235 not generally have permanently assigned Ethernet addresses.
236
237config USB_ALI_M5632
238 boolean "ALi M5632 based 'USB 2.0 Data Link' cables"
239 depends on USB_NET_CDC_SUBSET
240 help
241 Choose this option if you're using a host-to-host cable
242 based on this design, which supports USB 2.0 high speed.
243
244config USB_AN2720
245 boolean "AnchorChips 2720 based cables (Xircom PGUNET, ...)"
246 depends on USB_NET_CDC_SUBSET
247 help
248 Choose this option if you're using a host-to-host cable
249 based on this design. Note that AnchorChips is now a
250 Cypress brand.
251
252config USB_BELKIN
253 boolean "eTEK based host-to-host cables (Advance, Belkin, ...)"
254 depends on USB_NET_CDC_SUBSET
255 default y
256 help
257 Choose this option if you're using a host-to-host cable
258 based on this design: two NetChip 2890 chips and an Atmel
259 microcontroller, with LEDs that indicate traffic.
195 260
196config USB_ARMLINUX 261config USB_ARMLINUX
197 boolean "Embedded ARM Linux links (iPaq, ...)" 262 boolean "Embedded ARM Linux links (iPaq, ...)"
198 depends on USB_USBNET 263 depends on USB_NET_CDC_SUBSET
199 default y 264 default y
200 help 265 help
201 Choose this option to support the "usb-eth" networking driver 266 Choose this option to support the "usb-eth" networking driver
@@ -212,15 +277,15 @@ config USB_ARMLINUX
212 277
213config USB_EPSON2888 278config USB_EPSON2888
214 boolean "Epson 2888 based firmware (DEVELOPMENT)" 279 boolean "Epson 2888 based firmware (DEVELOPMENT)"
215 depends on USB_USBNET 280 depends on USB_NET_CDC_SUBSET
216 default y
217 help 281 help
218 Choose this option to support the usb networking links used 282 Choose this option to support the usb networking links used
219 by some sample firmware from Epson. 283 by some sample firmware from Epson.
220 284
221config USB_ZAURUS 285config USB_NET_ZAURUS
222 boolean "Sharp Zaurus (stock ROMs) and compatible" 286 tristate "Sharp Zaurus (stock ROMs) and compatible"
223 depends on USB_USBNET 287 depends on USB_USBNET
288 select USB_NET_CDCETHER
224 select CRC32 289 select CRC32
225 default y 290 default y
226 help 291 help
@@ -235,61 +300,6 @@ config USB_ZAURUS
235 really need this non-conformant variant of CDC Ethernet (or in 300 really need this non-conformant variant of CDC Ethernet (or in
236 some cases CDC MDLM) protocol, not "g_ether". 301 some cases CDC MDLM) protocol, not "g_ether".
237 302
238config USB_CDCETHER
239 boolean "CDC Ethernet support (smart devices such as cable modems)"
240 depends on USB_USBNET
241 default y
242 help
243 This option supports devices conforming to the Communication Device
244 Class (CDC) Ethernet Control Model, a specification that's easy to
245 implement in device firmware. The CDC specifications are available
246 from <http://www.usb.org/>.
247
248 CDC Ethernet is an implementation option for DOCSIS cable modems
249 that support USB connectivity, used for non-Microsoft USB hosts.
250 This driver should work with at least the following devices:
251
252 * Ericsson PipeRider (all variants)
253 * Motorola (DM100 and SB4100)
254 * Broadcom Cable Modem (reference design)
255 * Toshiba PCX1100U
256 * ...
257
258 This driver creates an interface named "ethX", where X depends on
259 what other networking devices you have in use. However, if the
260 IEEE 802 "local assignment" bit is set in the address, a "usbX"
261 name is used instead.
262
263comment "USB Network Adapters"
264 depends on USB_USBNET
265
266config USB_AX8817X
267 boolean "ASIX AX88xxx Based USB 2.0 Ethernet Devices"
268 depends on USB_USBNET && NET_ETHERNET
269 select CRC32
270 select MII
271 default y
272 help
273 This option adds support for ASIX AX88xxx based USB 2.0
274 10/100 Ethernet devices.
275
276 This driver should work with at least the following devices:
277 * Aten UC210T
278 * ASIX AX88172
279 * Billionton Systems, USB2AR
280 * Buffalo LUA-U2-KTX
281 * Corega FEther USB2-TX
282 * D-Link DUB-E100
283 * Hawking UF200
284 * Linksys USB200M
285 * Netgear FA120
286 * Sitecom LN-029
287 * Intellinet USB 2.0 Ethernet
288 * ST Lab USB 2.0 Ethernet
289 * TrendNet TU2-ET100
290
291 This driver creates an interface named "ethX", where X depends on
292 what other networking devices you have in use.
293 303
294config USB_ZD1201 304config USB_ZD1201
295 tristate "USB ZD1201 based Wireless device support" 305 tristate "USB ZD1201 based Wireless device support"
diff --git a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile
index fe3fd4115e1e..222c0495f791 100644
--- a/drivers/usb/net/Makefile
+++ b/drivers/usb/net/Makefile
@@ -6,5 +6,13 @@ obj-$(CONFIG_USB_CATC) += catc.o
6obj-$(CONFIG_USB_KAWETH) += kaweth.o 6obj-$(CONFIG_USB_KAWETH) += kaweth.o
7obj-$(CONFIG_USB_PEGASUS) += pegasus.o 7obj-$(CONFIG_USB_PEGASUS) += pegasus.o
8obj-$(CONFIG_USB_RTL8150) += rtl8150.o 8obj-$(CONFIG_USB_RTL8150) += rtl8150.o
9obj-$(CONFIG_USB_NET_AX8817X) += asix.o
10obj-$(CONFIG_USB_NET_CDCETHER) += cdc_ether.o
11obj-$(CONFIG_USB_NET_GL620A) += gl620a.o
12obj-$(CONFIG_USB_NET_NET1080) += net1080.o
13obj-$(CONFIG_USB_NET_PLUSB) += plusb.o
14obj-$(CONFIG_USB_NET_RNDIS_HOST) += rndis_host.o
15obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o
16obj-$(CONFIG_USB_NET_ZAURUS) += zaurus.o
9obj-$(CONFIG_USB_USBNET) += usbnet.o 17obj-$(CONFIG_USB_USBNET) += usbnet.o
10obj-$(CONFIG_USB_ZD1201) += zd1201.o 18obj-$(CONFIG_USB_ZD1201) += zd1201.o
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
new file mode 100644
index 000000000000..861f00a43750
--- /dev/null
+++ b/drivers/usb/net/asix.c
@@ -0,0 +1,948 @@
1/*
2 * ASIX AX8817X based USB 2.0 Ethernet Devices
3 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
4 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
5 * Copyright (c) 2002-2003 TiVo Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22// #define DEBUG // error path messages, extra info
23// #define VERBOSE // more; success messages
24
25#include <linux/config.h>
26#ifdef CONFIG_USB_DEBUG
27# define DEBUG
28#endif
29#include <linux/module.h>
30#include <linux/kmod.h>
31#include <linux/sched.h>
32#include <linux/init.h>
33#include <linux/netdevice.h>
34#include <linux/etherdevice.h>
35#include <linux/ethtool.h>
36#include <linux/workqueue.h>
37#include <linux/mii.h>
38#include <linux/usb.h>
39#include <linux/crc32.h>
40
41#include "usbnet.h"
42
43
44/* ASIX AX8817X based USB 2.0 Ethernet Devices */
45
46#define AX_CMD_SET_SW_MII 0x06
47#define AX_CMD_READ_MII_REG 0x07
48#define AX_CMD_WRITE_MII_REG 0x08
49#define AX_CMD_SET_HW_MII 0x0a
50#define AX_CMD_READ_EEPROM 0x0b
51#define AX_CMD_WRITE_EEPROM 0x0c
52#define AX_CMD_WRITE_ENABLE 0x0d
53#define AX_CMD_WRITE_DISABLE 0x0e
54#define AX_CMD_WRITE_RX_CTL 0x10
55#define AX_CMD_READ_IPG012 0x11
56#define AX_CMD_WRITE_IPG0 0x12
57#define AX_CMD_WRITE_IPG1 0x13
58#define AX_CMD_WRITE_IPG2 0x14
59#define AX_CMD_WRITE_MULTI_FILTER 0x16
60#define AX_CMD_READ_NODE_ID 0x17
61#define AX_CMD_READ_PHY_ID 0x19
62#define AX_CMD_READ_MEDIUM_STATUS 0x1a
63#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
64#define AX_CMD_READ_MONITOR_MODE 0x1c
65#define AX_CMD_WRITE_MONITOR_MODE 0x1d
66#define AX_CMD_WRITE_GPIOS 0x1f
67#define AX_CMD_SW_RESET 0x20
68#define AX_CMD_SW_PHY_STATUS 0x21
69#define AX_CMD_SW_PHY_SELECT 0x22
70#define AX88772_CMD_READ_NODE_ID 0x13
71
72#define AX_MONITOR_MODE 0x01
73#define AX_MONITOR_LINK 0x02
74#define AX_MONITOR_MAGIC 0x04
75#define AX_MONITOR_HSFS 0x10
76
77/* AX88172 Medium Status Register values */
78#define AX_MEDIUM_FULL_DUPLEX 0x02
79#define AX_MEDIUM_TX_ABORT_ALLOW 0x04
80#define AX_MEDIUM_FLOW_CONTROL_EN 0x10
81
82#define AX_MCAST_FILTER_SIZE 8
83#define AX_MAX_MCAST 64
84
85#define AX_EEPROM_LEN 0x40
86
87#define AX_SWRESET_CLEAR 0x00
88#define AX_SWRESET_RR 0x01
89#define AX_SWRESET_RT 0x02
90#define AX_SWRESET_PRTE 0x04
91#define AX_SWRESET_PRL 0x08
92#define AX_SWRESET_BZ 0x10
93#define AX_SWRESET_IPRL 0x20
94#define AX_SWRESET_IPPD 0x40
95
96#define AX88772_IPG0_DEFAULT 0x15
97#define AX88772_IPG1_DEFAULT 0x0c
98#define AX88772_IPG2_DEFAULT 0x12
99
100#define AX88772_MEDIUM_FULL_DUPLEX 0x0002
101#define AX88772_MEDIUM_RESERVED 0x0004
102#define AX88772_MEDIUM_RX_FC_ENABLE 0x0010
103#define AX88772_MEDIUM_TX_FC_ENABLE 0x0020
104#define AX88772_MEDIUM_PAUSE_FORMAT 0x0080
105#define AX88772_MEDIUM_RX_ENABLE 0x0100
106#define AX88772_MEDIUM_100MB 0x0200
107#define AX88772_MEDIUM_DEFAULT \
108 (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \
109 AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \
110 AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE )
111
112#define AX_EEPROM_MAGIC 0xdeadbeef
113
114/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
115struct ax8817x_data {
116 u8 multi_filter[AX_MCAST_FILTER_SIZE];
117};
118
119struct ax88172_int_data {
120 u16 res1;
121 u8 link;
122 u16 res2;
123 u8 status;
124 u16 res3;
125} __attribute__ ((packed));
126
127static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
128 u16 size, void *data)
129{
130 return usb_control_msg(
131 dev->udev,
132 usb_rcvctrlpipe(dev->udev, 0),
133 cmd,
134 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
135 value,
136 index,
137 data,
138 size,
139 USB_CTRL_GET_TIMEOUT);
140}
141
142static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
143 u16 size, void *data)
144{
145 return usb_control_msg(
146 dev->udev,
147 usb_sndctrlpipe(dev->udev, 0),
148 cmd,
149 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
150 value,
151 index,
152 data,
153 size,
154 USB_CTRL_SET_TIMEOUT);
155}
156
157static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
158{
159 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
160
161 if (urb->status < 0)
162 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
163 urb->status);
164
165 kfree(req);
166 usb_free_urb(urb);
167}
168
169static void ax8817x_status(struct usbnet *dev, struct urb *urb)
170{
171 struct ax88172_int_data *event;
172 int link;
173
174 if (urb->actual_length < 8)
175 return;
176
177 event = urb->transfer_buffer;
178 link = event->link & 0x01;
179 if (netif_carrier_ok(dev->net) != link) {
180 if (link) {
181 netif_carrier_on(dev->net);
182 usbnet_defer_kevent (dev, EVENT_LINK_RESET );
183 } else
184 netif_carrier_off(dev->net);
185 devdbg(dev, "ax8817x - Link Status is: %d", link);
186 }
187}
188
189static void
190ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
191 u16 size, void *data)
192{
193 struct usb_ctrlrequest *req;
194 int status;
195 struct urb *urb;
196
197 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
198 devdbg(dev, "Error allocating URB in write_cmd_async!");
199 return;
200 }
201
202 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
203 deverr(dev, "Failed to allocate memory for control request");
204 usb_free_urb(urb);
205 return;
206 }
207
208 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
209 req->bRequest = cmd;
210 req->wValue = cpu_to_le16(value);
211 req->wIndex = cpu_to_le16(index);
212 req->wLength = cpu_to_le16(size);
213
214 usb_fill_control_urb(urb, dev->udev,
215 usb_sndctrlpipe(dev->udev, 0),
216 (void *)req, data, size,
217 ax8817x_async_cmd_callback, req);
218
219 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
220 deverr(dev, "Error submitting the control message: status=%d",
221 status);
222 kfree(req);
223 usb_free_urb(urb);
224 }
225}
226
227static void ax8817x_set_multicast(struct net_device *net)
228{
229 struct usbnet *dev = netdev_priv(net);
230 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
231 u8 rx_ctl = 0x8c;
232
233 if (net->flags & IFF_PROMISC) {
234 rx_ctl |= 0x01;
235 } else if (net->flags & IFF_ALLMULTI
236 || net->mc_count > AX_MAX_MCAST) {
237 rx_ctl |= 0x02;
238 } else if (net->mc_count == 0) {
239 /* just broadcast and directed */
240 } else {
241 /* We use the 20 byte dev->data
242 * for our 8 byte filter buffer
243 * to avoid allocating memory that
244 * is tricky to free later */
245 struct dev_mc_list *mc_list = net->mc_list;
246 u32 crc_bits;
247 int i;
248
249 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
250
251 /* Build the multicast hash filter. */
252 for (i = 0; i < net->mc_count; i++) {
253 crc_bits =
254 ether_crc(ETH_ALEN,
255 mc_list->dmi_addr) >> 26;
256 data->multi_filter[crc_bits >> 3] |=
257 1 << (crc_bits & 7);
258 mc_list = mc_list->next;
259 }
260
261 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
262 AX_MCAST_FILTER_SIZE, data->multi_filter);
263
264 rx_ctl |= 0x10;
265 }
266
267 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
268}
269
270static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
271{
272 struct usbnet *dev = netdev_priv(netdev);
273 u16 res;
274 u8 buf[1];
275
276 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
277 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id,
278 (__u16)loc, 2, (u16 *)&res);
279 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
280
281 return res & 0xffff;
282}
283
284/* same as above, but converts resulting value to cpu byte order */
285static int ax8817x_mdio_read_le(struct net_device *netdev, int phy_id, int loc)
286{
287 return le16_to_cpu(ax8817x_mdio_read(netdev,phy_id, loc));
288}
289
290static void
291ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
292{
293 struct usbnet *dev = netdev_priv(netdev);
294 u16 res = val;
295 u8 buf[1];
296
297 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
298 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id,
299 (__u16)loc, 2, (u16 *)&res);
300 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
301}
302
303/* same as above, but converts new value to le16 byte order before writing */
304static void
305ax8817x_mdio_write_le(struct net_device *netdev, int phy_id, int loc, int val)
306{
307 ax8817x_mdio_write( netdev, phy_id, loc, cpu_to_le16(val) );
308}
309
310static int ax88172_link_reset(struct usbnet *dev)
311{
312 u16 lpa;
313 u16 adv;
314 u16 res;
315 u8 mode;
316
317 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN;
318 lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
319 adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
320 res = mii_nway_result(lpa|adv);
321 if (res & LPA_DUPLEX)
322 mode |= AX_MEDIUM_FULL_DUPLEX;
323 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
324
325 return 0;
326}
327
328static void
329ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
330{
331 struct usbnet *dev = netdev_priv(net);
332 u8 opt;
333
334 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
335 wolinfo->supported = 0;
336 wolinfo->wolopts = 0;
337 return;
338 }
339 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
340 wolinfo->wolopts = 0;
341 if (opt & AX_MONITOR_MODE) {
342 if (opt & AX_MONITOR_LINK)
343 wolinfo->wolopts |= WAKE_PHY;
344 if (opt & AX_MONITOR_MAGIC)
345 wolinfo->wolopts |= WAKE_MAGIC;
346 }
347}
348
349static int
350ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
351{
352 struct usbnet *dev = netdev_priv(net);
353 u8 opt = 0;
354 u8 buf[1];
355
356 if (wolinfo->wolopts & WAKE_PHY)
357 opt |= AX_MONITOR_LINK;
358 if (wolinfo->wolopts & WAKE_MAGIC)
359 opt |= AX_MONITOR_MAGIC;
360 if (opt != 0)
361 opt |= AX_MONITOR_MODE;
362
363 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
364 opt, 0, 0, &buf) < 0)
365 return -EINVAL;
366
367 return 0;
368}
369
370static int ax8817x_get_eeprom_len(struct net_device *net)
371{
372 return AX_EEPROM_LEN;
373}
374
375static int ax8817x_get_eeprom(struct net_device *net,
376 struct ethtool_eeprom *eeprom, u8 *data)
377{
378 struct usbnet *dev = netdev_priv(net);
379 u16 *ebuf = (u16 *)data;
380 int i;
381
382 /* Crude hack to ensure that we don't overwrite memory
383 * if an odd length is supplied
384 */
385 if (eeprom->len % 2)
386 return -EINVAL;
387
388 eeprom->magic = AX_EEPROM_MAGIC;
389
390 /* ax8817x returns 2 bytes from eeprom on read */
391 for (i=0; i < eeprom->len / 2; i++) {
392 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
393 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
394 return -EINVAL;
395 }
396 return 0;
397}
398
399static void ax8817x_get_drvinfo (struct net_device *net,
400 struct ethtool_drvinfo *info)
401{
402 /* Inherit standard device info */
403 usbnet_get_drvinfo(net, info);
404 info->eedump_len = 0x3e;
405}
406
407static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
408{
409 struct usbnet *dev = netdev_priv(net);
410
411 return mii_ethtool_gset(&dev->mii,cmd);
412}
413
414static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
415{
416 struct usbnet *dev = netdev_priv(net);
417
418 return mii_ethtool_sset(&dev->mii,cmd);
419}
420
421/* We need to override some ethtool_ops so we require our
422 own structure so we don't interfere with other usbnet
423 devices that may be connected at the same time. */
424static struct ethtool_ops ax8817x_ethtool_ops = {
425 .get_drvinfo = ax8817x_get_drvinfo,
426 .get_link = ethtool_op_get_link,
427 .get_msglevel = usbnet_get_msglevel,
428 .set_msglevel = usbnet_set_msglevel,
429 .get_wol = ax8817x_get_wol,
430 .set_wol = ax8817x_set_wol,
431 .get_eeprom_len = ax8817x_get_eeprom_len,
432 .get_eeprom = ax8817x_get_eeprom,
433 .get_settings = ax8817x_get_settings,
434 .set_settings = ax8817x_set_settings,
435};
436
437static int ax8817x_ioctl (struct net_device *net, struct ifreq *rq, int cmd)
438{
439 struct usbnet *dev = netdev_priv(net);
440
441 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
442}
443
444static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
445{
446 int ret = 0;
447 void *buf;
448 int i;
449 unsigned long gpio_bits = dev->driver_info->data;
450
451 usbnet_get_endpoints(dev,intf);
452
453 buf = kmalloc(ETH_ALEN, GFP_KERNEL);
454 if(!buf) {
455 ret = -ENOMEM;
456 goto out1;
457 }
458
459 /* Toggle the GPIOs in a manufacturer/model specific way */
460 for (i = 2; i >= 0; i--) {
461 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
462 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
463 buf)) < 0)
464 goto out2;
465 msleep(5);
466 }
467
468 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL,
469 0x80, 0, 0, buf)) < 0) {
470 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
471 goto out2;
472 }
473
474 /* Get the MAC address */
475 memset(buf, 0, ETH_ALEN);
476 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID,
477 0, 0, 6, buf)) < 0) {
478 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
479 goto out2;
480 }
481 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
482
483 /* Get the PHY id */
484 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID,
485 0, 0, 2, buf)) < 0) {
486 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
487 goto out2;
488 } else if (ret < 2) {
489 /* this should always return 2 bytes */
490 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
491 ret);
492 ret = -EIO;
493 goto out2;
494 }
495
496 /* Initialize MII structure */
497 dev->mii.dev = dev->net;
498 dev->mii.mdio_read = ax8817x_mdio_read;
499 dev->mii.mdio_write = ax8817x_mdio_write;
500 dev->mii.phy_id_mask = 0x3f;
501 dev->mii.reg_num_mask = 0x1f;
502 dev->mii.phy_id = *((u8 *)buf + 1);
503 dev->net->do_ioctl = ax8817x_ioctl;
504
505 dev->net->set_multicast_list = ax8817x_set_multicast;
506 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
507
508 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
509 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE,
510 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
511 mii_nway_restart(&dev->mii);
512
513 return 0;
514out2:
515 kfree(buf);
516out1:
517 return ret;
518}
519
520static struct ethtool_ops ax88772_ethtool_ops = {
521 .get_drvinfo = ax8817x_get_drvinfo,
522 .get_link = ethtool_op_get_link,
523 .get_msglevel = usbnet_get_msglevel,
524 .set_msglevel = usbnet_set_msglevel,
525 .get_wol = ax8817x_get_wol,
526 .set_wol = ax8817x_set_wol,
527 .get_eeprom_len = ax8817x_get_eeprom_len,
528 .get_eeprom = ax8817x_get_eeprom,
529 .get_settings = ax8817x_get_settings,
530 .set_settings = ax8817x_set_settings,
531};
532
533static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
534{
535 int ret;
536 void *buf;
537
538 usbnet_get_endpoints(dev,intf);
539
540 buf = kmalloc(6, GFP_KERNEL);
541 if(!buf) {
542 dbg ("Cannot allocate memory for buffer");
543 ret = -ENOMEM;
544 goto out1;
545 }
546
547 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
548 0x00B0, 0, 0, buf)) < 0)
549 goto out2;
550
551 msleep(5);
552 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT,
553 0x0001, 0, 0, buf)) < 0) {
554 dbg("Select PHY #1 failed: %d", ret);
555 goto out2;
556 }
557
558 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD,
559 0, 0, buf)) < 0) {
560 dbg("Failed to power down internal PHY: %d", ret);
561 goto out2;
562 }
563
564 msleep(150);
565 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR,
566 0, 0, buf)) < 0) {
567 dbg("Failed to perform software reset: %d", ret);
568 goto out2;
569 }
570
571 msleep(150);
572 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET,
573 AX_SWRESET_IPRL | AX_SWRESET_PRL,
574 0, 0, buf)) < 0) {
575 dbg("Failed to set Internal/External PHY reset control: %d",
576 ret);
577 goto out2;
578 }
579
580 msleep(150);
581 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL,
582 0x0000, 0, 0, buf)) < 0) {
583 dbg("Failed to reset RX_CTL: %d", ret);
584 goto out2;
585 }
586
587 /* Get the MAC address */
588 memset(buf, 0, ETH_ALEN);
589 if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID,
590 0, 0, ETH_ALEN, buf)) < 0) {
591 dbg("Failed to read MAC address: %d", ret);
592 goto out2;
593 }
594 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
595
596 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII,
597 0, 0, 0, buf)) < 0) {
598 dbg("Enabling software MII failed: %d", ret);
599 goto out2;
600 }
601
602 if (((ret = ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG,
603 0x0010, 2, 2, buf)) < 0)
604 || (*((u16 *)buf) != 0x003b)) {
605 dbg("Read PHY register 2 must be 0x3b00: %d", ret);
606 goto out2;
607 }
608
609 /* Initialize MII structure */
610 dev->mii.dev = dev->net;
611 dev->mii.mdio_read = ax8817x_mdio_read;
612 dev->mii.mdio_write = ax8817x_mdio_write;
613 dev->mii.phy_id_mask = 0xff;
614 dev->mii.reg_num_mask = 0xff;
615 dev->net->do_ioctl = ax8817x_ioctl;
616
617 /* Get the PHY id */
618 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID,
619 0, 0, 2, buf)) < 0) {
620 dbg("Error reading PHY ID: %02x", ret);
621 goto out2;
622 } else if (ret < 2) {
623 /* this should always return 2 bytes */
624 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
625 ret);
626 ret = -EIO;
627 goto out2;
628 }
629 dev->mii.phy_id = *((u8 *)buf + 1);
630
631 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL,
632 0, 0, buf)) < 0) {
633 dbg("Set external PHY reset pin level: %d", ret);
634 goto out2;
635 }
636 msleep(150);
637 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_RESET,
638 AX_SWRESET_IPRL | AX_SWRESET_PRL,
639 0, 0, buf)) < 0) {
640 dbg("Set Internal/External PHY reset control: %d", ret);
641 goto out2;
642 }
643 msleep(150);
644
645
646 dev->net->set_multicast_list = ax8817x_set_multicast;
647 dev->net->ethtool_ops = &ax88772_ethtool_ops;
648
649 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
650 ax8817x_mdio_write_le(dev->net, dev->mii.phy_id, MII_ADVERTISE,
651 ADVERTISE_ALL | ADVERTISE_CSMA);
652 mii_nway_restart(&dev->mii);
653
654 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE,
655 AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
656 dbg("Write medium mode register: %d", ret);
657 goto out2;
658 }
659
660 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0,
661 AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,
662 AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
663 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
664 goto out2;
665 }
666 if ((ret =
667 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
668 dbg("Failed to set hardware MII: %02x", ret);
669 goto out2;
670 }
671
672 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
673 if ((ret =
674 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0,
675 buf)) < 0) {
676 dbg("Reset RX_CTL failed: %d", ret);
677 goto out2;
678 }
679
680 kfree(buf);
681
682 /* Asix framing packs multiple eth frames into a 2K usb bulk transfer */
683 if (dev->driver_info->flags & FLAG_FRAMING_AX) {
684 /* hard_mtu is still the default - the device does not support
685 jumbo eth frames */
686 dev->rx_urb_size = 2048;
687 }
688
689 return 0;
690
691out2:
692 kfree(buf);
693out1:
694 return ret;
695}
696
697static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
698{
699 u8 *head;
700 u32 header;
701 char *packet;
702 struct sk_buff *ax_skb;
703 u16 size;
704
705 head = (u8 *) skb->data;
706 memcpy(&header, head, sizeof(header));
707 le32_to_cpus(&header);
708 packet = head + sizeof(header);
709
710 skb_pull(skb, 4);
711
712 while (skb->len > 0) {
713 if ((short)(header & 0x0000ffff) !=
714 ~((short)((header & 0xffff0000) >> 16))) {
715 devdbg(dev,"header length data is error");
716 }
717 /* get the packet length */
718 size = (u16) (header & 0x0000ffff);
719
720 if ((skb->len) - ((size + 1) & 0xfffe) == 0)
721 return 2;
722 if (size > ETH_FRAME_LEN) {
723 devdbg(dev,"invalid rx length %d", size);
724 return 0;
725 }
726 ax_skb = skb_clone(skb, GFP_ATOMIC);
727 if (ax_skb) {
728 ax_skb->len = size;
729 ax_skb->data = packet;
730 ax_skb->tail = packet + size;
731 usbnet_skb_return(dev, ax_skb);
732 } else {
733 return 0;
734 }
735
736 skb_pull(skb, (size + 1) & 0xfffe);
737
738 if (skb->len == 0)
739 break;
740
741 head = (u8 *) skb->data;
742 memcpy(&header, head, sizeof(header));
743 le32_to_cpus(&header);
744 packet = head + sizeof(header);
745 skb_pull(skb, 4);
746 }
747
748 if (skb->len < 0) {
749 devdbg(dev,"invalid rx length %d", skb->len);
750 return 0;
751 }
752 return 1;
753}
754
755static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
756 unsigned flags)
757{
758 int padlen;
759 int headroom = skb_headroom(skb);
760 int tailroom = skb_tailroom(skb);
761 u32 packet_len;
762 u32 padbytes = 0xffff0000;
763
764 padlen = ((skb->len + 4) % 512) ? 0 : 4;
765
766 if ((!skb_cloned(skb))
767 && ((headroom + tailroom) >= (4 + padlen))) {
768 if ((headroom < 4) || (tailroom < padlen)) {
769 skb->data = memmove(skb->head + 4, skb->data, skb->len);
770 skb->tail = skb->data + skb->len;
771 }
772 } else {
773 struct sk_buff *skb2;
774 skb2 = skb_copy_expand(skb, 4, padlen, flags);
775 dev_kfree_skb_any(skb);
776 skb = skb2;
777 if (!skb)
778 return NULL;
779 }
780
781 skb_push(skb, 4);
782 packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
783 memcpy(skb->data, &packet_len, sizeof(packet_len));
784
785 if ((skb->len % 512) == 0) {
786 memcpy( skb->tail, &padbytes, sizeof(padbytes));
787 skb_put(skb, sizeof(padbytes));
788 }
789 return skb;
790}
791
792static int ax88772_link_reset(struct usbnet *dev)
793{
794 u16 lpa;
795 u16 adv;
796 u16 res;
797 u16 mode;
798
799 mode = AX88772_MEDIUM_DEFAULT;
800 lpa = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_LPA);
801 adv = ax8817x_mdio_read_le(dev->net, dev->mii.phy_id, MII_ADVERTISE);
802 res = mii_nway_result(lpa|adv);
803
804 if ((res & LPA_DUPLEX) == 0)
805 mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
806 if ((res & LPA_100) == 0)
807 mode &= ~AX88772_MEDIUM_100MB;
808 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
809
810 return 0;
811}
812
813static const struct driver_info ax8817x_info = {
814 .description = "ASIX AX8817x USB 2.0 Ethernet",
815 .bind = ax8817x_bind,
816 .status = ax8817x_status,
817 .link_reset = ax88172_link_reset,
818 .reset = ax88172_link_reset,
819 .flags = FLAG_ETHER,
820 .data = 0x00130103,
821};
822
823static const struct driver_info dlink_dub_e100_info = {
824 .description = "DLink DUB-E100 USB Ethernet",
825 .bind = ax8817x_bind,
826 .status = ax8817x_status,
827 .link_reset = ax88172_link_reset,
828 .reset = ax88172_link_reset,
829 .flags = FLAG_ETHER,
830 .data = 0x009f9d9f,
831};
832
833static const struct driver_info netgear_fa120_info = {
834 .description = "Netgear FA-120 USB Ethernet",
835 .bind = ax8817x_bind,
836 .status = ax8817x_status,
837 .link_reset = ax88172_link_reset,
838 .reset = ax88172_link_reset,
839 .flags = FLAG_ETHER,
840 .data = 0x00130103,
841};
842
843static const struct driver_info hawking_uf200_info = {
844 .description = "Hawking UF200 USB Ethernet",
845 .bind = ax8817x_bind,
846 .status = ax8817x_status,
847 .link_reset = ax88172_link_reset,
848 .reset = ax88172_link_reset,
849 .flags = FLAG_ETHER,
850 .data = 0x001f1d1f,
851};
852
853static const struct driver_info ax88772_info = {
854 .description = "ASIX AX88772 USB 2.0 Ethernet",
855 .bind = ax88772_bind,
856 .status = ax8817x_status,
857 .link_reset = ax88772_link_reset,
858 .reset = ax88772_link_reset,
859 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
860 .rx_fixup = ax88772_rx_fixup,
861 .tx_fixup = ax88772_tx_fixup,
862 .data = 0x00130103,
863};
864
865static const struct usb_device_id products [] = {
866{
867 // Linksys USB200M
868 USB_DEVICE (0x077b, 0x2226),
869 .driver_info = (unsigned long) &ax8817x_info,
870}, {
871 // Netgear FA120
872 USB_DEVICE (0x0846, 0x1040),
873 .driver_info = (unsigned long) &netgear_fa120_info,
874}, {
875 // DLink DUB-E100
876 USB_DEVICE (0x2001, 0x1a00),
877 .driver_info = (unsigned long) &dlink_dub_e100_info,
878}, {
879 // Intellinet, ST Lab USB Ethernet
880 USB_DEVICE (0x0b95, 0x1720),
881 .driver_info = (unsigned long) &ax8817x_info,
882}, {
883 // Hawking UF200, TrendNet TU2-ET100
884 USB_DEVICE (0x07b8, 0x420a),
885 .driver_info = (unsigned long) &hawking_uf200_info,
886}, {
887 // Billionton Systems, USB2AR
888 USB_DEVICE (0x08dd, 0x90ff),
889 .driver_info = (unsigned long) &ax8817x_info,
890}, {
891 // ATEN UC210T
892 USB_DEVICE (0x0557, 0x2009),
893 .driver_info = (unsigned long) &ax8817x_info,
894}, {
895 // Buffalo LUA-U2-KTX
896 USB_DEVICE (0x0411, 0x003d),
897 .driver_info = (unsigned long) &ax8817x_info,
898}, {
899 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
900 USB_DEVICE (0x6189, 0x182d),
901 .driver_info = (unsigned long) &ax8817x_info,
902}, {
903 // corega FEther USB2-TX
904 USB_DEVICE (0x07aa, 0x0017),
905 .driver_info = (unsigned long) &ax8817x_info,
906}, {
907 // Surecom EP-1427X-2
908 USB_DEVICE (0x1189, 0x0893),
909 .driver_info = (unsigned long) &ax8817x_info,
910}, {
911 // goodway corp usb gwusb2e
912 USB_DEVICE (0x1631, 0x6200),
913 .driver_info = (unsigned long) &ax8817x_info,
914}, {
915 // ASIX AX88772 10/100
916 USB_DEVICE (0x0b95, 0x7720),
917 .driver_info = (unsigned long) &ax88772_info,
918},
919 { }, // END
920};
921MODULE_DEVICE_TABLE(usb, products);
922
923static struct usb_driver asix_driver = {
924 .owner = THIS_MODULE,
925 .name = "asix",
926 .id_table = products,
927 .probe = usbnet_probe,
928 .suspend = usbnet_suspend,
929 .resume = usbnet_resume,
930 .disconnect = usbnet_disconnect,
931};
932
933static int __init asix_init(void)
934{
935 return usb_register(&asix_driver);
936}
937module_init(asix_init);
938
939static void __exit asix_exit(void)
940{
941 usb_deregister(&asix_driver);
942}
943module_exit(asix_exit);
944
945MODULE_AUTHOR("David Hollis");
946MODULE_DESCRIPTION("ASIX AX8817X based USB 2.0 Ethernet Devices");
947MODULE_LICENSE("GPL");
948
diff --git a/drivers/usb/net/catc.c b/drivers/usb/net/catc.c
index c8be912f24e1..37ef365a2472 100644
--- a/drivers/usb/net/catc.c
+++ b/drivers/usb/net/catc.c
@@ -383,7 +383,6 @@ static void catc_tx_done(struct urb *urb, struct pt_regs *regs)
383 383
384 if (urb->status == -ECONNRESET) { 384 if (urb->status == -ECONNRESET) {
385 dbg("Tx Reset."); 385 dbg("Tx Reset.");
386 urb->transfer_flags &= ~URB_ASYNC_UNLINK;
387 urb->status = 0; 386 urb->status = 0;
388 catc->netdev->trans_start = jiffies; 387 catc->netdev->trans_start = jiffies;
389 catc->stats.tx_errors++; 388 catc->stats.tx_errors++;
@@ -445,7 +444,6 @@ static void catc_tx_timeout(struct net_device *netdev)
445 struct catc *catc = netdev_priv(netdev); 444 struct catc *catc = netdev_priv(netdev);
446 445
447 warn("Transmit timed out."); 446 warn("Transmit timed out.");
448 catc->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
449 usb_unlink_urb(catc->tx_urb); 447 usb_unlink_urb(catc->tx_urb);
450} 448}
451 449
diff --git a/drivers/usb/net/cdc_ether.c b/drivers/usb/net/cdc_ether.c
new file mode 100644
index 000000000000..652b04bbf6af
--- /dev/null
+++ b/drivers/usb/net/cdc_ether.c
@@ -0,0 +1,509 @@
1/*
2 * CDC Ethernet based networking peripherals
3 * Copyright (C) 2003-2005 by David Brownell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// #define DEBUG // error path messages, extra info
21// #define VERBOSE // more; success messages
22
23#include <linux/config.h>
24#ifdef CONFIG_USB_DEBUG
25# define DEBUG
26#endif
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <linux/init.h>
30#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/ctype.h>
33#include <linux/ethtool.h>
34#include <linux/workqueue.h>
35#include <linux/mii.h>
36#include <linux/usb.h>
37#include <linux/usb_cdc.h>
38
39#include "usbnet.h"
40
41
42/*
43 * probes control interface, claims data interface, collects the bulk
44 * endpoints, activates data interface (if needed), maybe sets MTU.
45 * all pure cdc, except for certain firmware workarounds, and knowing
46 * that rndis uses one different rule.
47 */
48int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
49{
50 u8 *buf = intf->cur_altsetting->extra;
51 int len = intf->cur_altsetting->extralen;
52 struct usb_interface_descriptor *d;
53 struct cdc_state *info = (void *) &dev->data;
54 int status;
55 int rndis;
56 struct usb_driver *driver = driver_of(intf);
57
58 if (sizeof dev->data < sizeof *info)
59 return -EDOM;
60
61 /* expect strict spec conformance for the descriptors, but
62 * cope with firmware which stores them in the wrong place
63 */
64 if (len == 0 && dev->udev->actconfig->extralen) {
65 /* Motorola SB4100 (and others: Brad Hards says it's
66 * from a Broadcom design) put CDC descriptors here
67 */
68 buf = dev->udev->actconfig->extra;
69 len = dev->udev->actconfig->extralen;
70 if (len)
71 dev_dbg(&intf->dev,
72 "CDC descriptors on config\n");
73 }
74
75 /* this assumes that if there's a non-RNDIS vendor variant
76 * of cdc-acm, it'll fail RNDIS requests cleanly.
77 */
78 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
79
80 memset(info, 0, sizeof *info);
81 info->control = intf;
82 while (len > 3) {
83 if (buf [1] != USB_DT_CS_INTERFACE)
84 goto next_desc;
85
86 /* use bDescriptorSubType to identify the CDC descriptors.
87 * We expect devices with CDC header and union descriptors.
88 * For CDC Ethernet we need the ethernet descriptor.
89 * For RNDIS, ignore two (pointless) CDC modem descriptors
90 * in favor of a complicated OID-based RPC scheme doing what
91 * CDC Ethernet achieves with a simple descriptor.
92 */
93 switch (buf [2]) {
94 case USB_CDC_HEADER_TYPE:
95 if (info->header) {
96 dev_dbg(&intf->dev, "extra CDC header\n");
97 goto bad_desc;
98 }
99 info->header = (void *) buf;
100 if (info->header->bLength != sizeof *info->header) {
101 dev_dbg(&intf->dev, "CDC header len %u\n",
102 info->header->bLength);
103 goto bad_desc;
104 }
105 break;
106 case USB_CDC_UNION_TYPE:
107 if (info->u) {
108 dev_dbg(&intf->dev, "extra CDC union\n");
109 goto bad_desc;
110 }
111 info->u = (void *) buf;
112 if (info->u->bLength != sizeof *info->u) {
113 dev_dbg(&intf->dev, "CDC union len %u\n",
114 info->u->bLength);
115 goto bad_desc;
116 }
117
118 /* we need a master/control interface (what we're
119 * probed with) and a slave/data interface; union
120 * descriptors sort this all out.
121 */
122 info->control = usb_ifnum_to_if(dev->udev,
123 info->u->bMasterInterface0);
124 info->data = usb_ifnum_to_if(dev->udev,
125 info->u->bSlaveInterface0);
126 if (!info->control || !info->data) {
127 dev_dbg(&intf->dev,
128 "master #%u/%p slave #%u/%p\n",
129 info->u->bMasterInterface0,
130 info->control,
131 info->u->bSlaveInterface0,
132 info->data);
133 goto bad_desc;
134 }
135 if (info->control != intf) {
136 dev_dbg(&intf->dev, "bogus CDC Union\n");
137 /* Ambit USB Cable Modem (and maybe others)
138 * interchanges master and slave interface.
139 */
140 if (info->data == intf) {
141 info->data = info->control;
142 info->control = intf;
143 } else
144 goto bad_desc;
145 }
146
147 /* a data interface altsetting does the real i/o */
148 d = &info->data->cur_altsetting->desc;
149 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
150 dev_dbg(&intf->dev, "slave class %u\n",
151 d->bInterfaceClass);
152 goto bad_desc;
153 }
154 break;
155 case USB_CDC_ETHERNET_TYPE:
156 if (info->ether) {
157 dev_dbg(&intf->dev, "extra CDC ether\n");
158 goto bad_desc;
159 }
160 info->ether = (void *) buf;
161 if (info->ether->bLength != sizeof *info->ether) {
162 dev_dbg(&intf->dev, "CDC ether len %u\n",
163 info->ether->bLength);
164 goto bad_desc;
165 }
166 dev->hard_mtu = le16_to_cpu(
167 info->ether->wMaxSegmentSize);
168 /* because of Zaurus, we may be ignoring the host
169 * side link address we were given.
170 */
171 break;
172 }
173next_desc:
174 len -= buf [0]; /* bLength */
175 buf += buf [0];
176 }
177
178 if (!info->header || !info->u || (!rndis && !info->ether)) {
179 dev_dbg(&intf->dev, "missing cdc %s%s%sdescriptor\n",
180 info->header ? "" : "header ",
181 info->u ? "" : "union ",
182 info->ether ? "" : "ether ");
183 goto bad_desc;
184 }
185
186 /* claim data interface and set it up ... with side effects.
187 * network traffic can't flow until an altsetting is enabled.
188 */
189 status = usb_driver_claim_interface(driver, info->data, dev);
190 if (status < 0)
191 return status;
192 status = usbnet_get_endpoints(dev, info->data);
193 if (status < 0) {
194 /* ensure immediate exit from usbnet_disconnect */
195 usb_set_intfdata(info->data, NULL);
196 usb_driver_release_interface(driver, info->data);
197 return status;
198 }
199
200 /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
201 dev->status = NULL;
202 if (info->control->cur_altsetting->desc.bNumEndpoints == 1) {
203 struct usb_endpoint_descriptor *desc;
204
205 dev->status = &info->control->cur_altsetting->endpoint [0];
206 desc = &dev->status->desc;
207 if (desc->bmAttributes != USB_ENDPOINT_XFER_INT
208 || !(desc->bEndpointAddress & USB_DIR_IN)
209 || (le16_to_cpu(desc->wMaxPacketSize)
210 < sizeof(struct usb_cdc_notification))
211 || !desc->bInterval) {
212 dev_dbg(&intf->dev, "bad notification endpoint\n");
213 dev->status = NULL;
214 }
215 }
216 if (rndis && !dev->status) {
217 dev_dbg(&intf->dev, "missing RNDIS status endpoint\n");
218 usb_set_intfdata(info->data, NULL);
219 usb_driver_release_interface(driver, info->data);
220 return -ENODEV;
221 }
222 return 0;
223
224bad_desc:
225 dev_info(&dev->udev->dev, "bad CDC descriptors\n");
226 return -ENODEV;
227}
228EXPORT_SYMBOL_GPL(usbnet_generic_cdc_bind);
229
230void usbnet_cdc_unbind(struct usbnet *dev, struct usb_interface *intf)
231{
232 struct cdc_state *info = (void *) &dev->data;
233 struct usb_driver *driver = driver_of(intf);
234
235 /* disconnect master --> disconnect slave */
236 if (intf == info->control && info->data) {
237 /* ensure immediate exit from usbnet_disconnect */
238 usb_set_intfdata(info->data, NULL);
239 usb_driver_release_interface(driver, info->data);
240 info->data = NULL;
241 }
242
243 /* and vice versa (just in case) */
244 else if (intf == info->data && info->control) {
245 /* ensure immediate exit from usbnet_disconnect */
246 usb_set_intfdata(info->control, NULL);
247 usb_driver_release_interface(driver, info->control);
248 info->control = NULL;
249 }
250}
251EXPORT_SYMBOL_GPL(usbnet_cdc_unbind);
252
253
254/*-------------------------------------------------------------------------
255 *
256 * Communications Device Class, Ethernet Control model
257 *
258 * Takes two interfaces. The DATA interface is inactive till an altsetting
259 * is selected. Configuration data includes class descriptors. There's
260 * an optional status endpoint on the control interface.
261 *
262 * This should interop with whatever the 2.4 "CDCEther.c" driver
263 * (by Brad Hards) talked with, with more functionality.
264 *
265 *-------------------------------------------------------------------------*/
266
267static void dumpspeed(struct usbnet *dev, __le32 *speeds)
268{
269 if (netif_msg_timer(dev))
270 devinfo(dev, "link speeds: %u kbps up, %u kbps down",
271 __le32_to_cpu(speeds[0]) / 1000,
272 __le32_to_cpu(speeds[1]) / 1000);
273}
274
275static void cdc_status(struct usbnet *dev, struct urb *urb)
276{
277 struct usb_cdc_notification *event;
278
279 if (urb->actual_length < sizeof *event)
280 return;
281
282 /* SPEED_CHANGE can get split into two 8-byte packets */
283 if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) {
284 dumpspeed(dev, (__le32 *) urb->transfer_buffer);
285 return;
286 }
287
288 event = urb->transfer_buffer;
289 switch (event->bNotificationType) {
290 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
291 if (netif_msg_timer(dev))
292 devdbg(dev, "CDC: carrier %s",
293 event->wValue ? "on" : "off");
294 if (event->wValue)
295 netif_carrier_on(dev->net);
296 else
297 netif_carrier_off(dev->net);
298 break;
299 case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */
300 if (netif_msg_timer(dev))
301 devdbg(dev, "CDC: speed change (len %d)",
302 urb->actual_length);
303 if (urb->actual_length != (sizeof *event + 8))
304 set_bit(EVENT_STS_SPLIT, &dev->flags);
305 else
306 dumpspeed(dev, (__le32 *) &event[1]);
307 break;
308 /* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS),
309 * but there are no standard formats for the response data.
310 */
311 default:
312 deverr(dev, "CDC: unexpected notification %02x!",
313 event->bNotificationType);
314 break;
315 }
316}
317
318static u8 nibble(unsigned char c)
319{
320 if (likely(isdigit(c)))
321 return c - '0';
322 c = toupper(c);
323 if (likely(isxdigit(c)))
324 return 10 + c - 'A';
325 return 0;
326}
327
328static inline int
329get_ethernet_addr(struct usbnet *dev, struct usb_cdc_ether_desc *e)
330{
331 int tmp, i;
332 unsigned char buf [13];
333
334 tmp = usb_string(dev->udev, e->iMACAddress, buf, sizeof buf);
335 if (tmp != 12) {
336 dev_dbg(&dev->udev->dev,
337 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
338 if (tmp >= 0)
339 tmp = -EINVAL;
340 return tmp;
341 }
342 for (i = tmp = 0; i < 6; i++, tmp += 2)
343 dev->net->dev_addr [i] =
344 (nibble(buf [tmp]) << 4) + nibble(buf [tmp + 1]);
345 return 0;
346}
347
348static int cdc_bind(struct usbnet *dev, struct usb_interface *intf)
349{
350 int status;
351 struct cdc_state *info = (void *) &dev->data;
352
353 status = usbnet_generic_cdc_bind(dev, intf);
354 if (status < 0)
355 return status;
356
357 status = get_ethernet_addr(dev, info->ether);
358 if (status < 0) {
359 usb_set_intfdata(info->data, NULL);
360 usb_driver_release_interface(driver_of(intf), info->data);
361 return status;
362 }
363
364 /* FIXME cdc-ether has some multicast code too, though it complains
365 * in routine cases. info->ether describes the multicast support.
366 * Implement that here, manipulating the cdc filter as needed.
367 */
368 return 0;
369}
370
371static const struct driver_info cdc_info = {
372 .description = "CDC Ethernet Device",
373 .flags = FLAG_ETHER,
374 // .check_connect = cdc_check_connect,
375 .bind = cdc_bind,
376 .unbind = usbnet_cdc_unbind,
377 .status = cdc_status,
378};
379
380/*-------------------------------------------------------------------------*/
381
382
383static const struct usb_device_id products [] = {
384/*
385 * BLACKLIST !!
386 *
387 * First blacklist any products that are egregiously nonconformant
388 * with the CDC Ethernet specs. Minor braindamage we cope with; when
389 * they're not even trying, needing a separate driver is only the first
390 * of the differences to show up.
391 */
392
393#define ZAURUS_MASTER_INTERFACE \
394 .bInterfaceClass = USB_CLASS_COMM, \
395 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
396 .bInterfaceProtocol = USB_CDC_PROTO_NONE
397
398/* SA-1100 based Sharp Zaurus ("collie"), or compatible;
399 * wire-incompatible with true CDC Ethernet implementations.
400 * (And, it seems, needlessly so...)
401 */
402{
403 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
404 | USB_DEVICE_ID_MATCH_DEVICE,
405 .idVendor = 0x04DD,
406 .idProduct = 0x8004,
407 ZAURUS_MASTER_INTERFACE,
408 .driver_info = 0,
409},
410
411/* PXA-25x based Sharp Zaurii. Note that it seems some of these
412 * (later models especially) may have shipped only with firmware
413 * advertising false "CDC MDLM" compatibility ... but we're not
414 * clear which models did that, so for now let's assume the worst.
415 */
416{
417 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
418 | USB_DEVICE_ID_MATCH_DEVICE,
419 .idVendor = 0x04DD,
420 .idProduct = 0x8005, /* A-300 */
421 ZAURUS_MASTER_INTERFACE,
422 .driver_info = 0,
423}, {
424 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
425 | USB_DEVICE_ID_MATCH_DEVICE,
426 .idVendor = 0x04DD,
427 .idProduct = 0x8006, /* B-500/SL-5600 */
428 ZAURUS_MASTER_INTERFACE,
429 .driver_info = 0,
430}, {
431 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
432 | USB_DEVICE_ID_MATCH_DEVICE,
433 .idVendor = 0x04DD,
434 .idProduct = 0x8007, /* C-700 */
435 ZAURUS_MASTER_INTERFACE,
436 .driver_info = 0,
437}, {
438 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
439 | USB_DEVICE_ID_MATCH_DEVICE,
440 .idVendor = 0x04DD,
441 .idProduct = 0x9031, /* C-750 C-760 */
442 ZAURUS_MASTER_INTERFACE,
443 .driver_info = 0,
444}, {
445 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
446 | USB_DEVICE_ID_MATCH_DEVICE,
447 .idVendor = 0x04DD,
448 .idProduct = 0x9032, /* SL-6000 */
449 ZAURUS_MASTER_INTERFACE,
450 .driver_info = 0,
451}, {
452 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
453 | USB_DEVICE_ID_MATCH_DEVICE,
454 .idVendor = 0x04DD,
455 /* reported with some C860 units */
456 .idProduct = 0x9050, /* C-860 */
457 ZAURUS_MASTER_INTERFACE,
458 .driver_info = 0,
459},
460
461/*
462 * WHITELIST!!!
463 *
464 * CDC Ether uses two interfaces, not necessarily consecutive.
465 * We match the main interface, ignoring the optional device
466 * class so we could handle devices that aren't exclusively
467 * CDC ether.
468 *
469 * NOTE: this match must come AFTER entries blacklisting devices
470 * because of bugs/quirks in a given product (like Zaurus, above).
471 */
472{
473 USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
474 USB_CDC_PROTO_NONE),
475 .driver_info = (unsigned long) &cdc_info,
476},
477 { }, // END
478};
479MODULE_DEVICE_TABLE(usb, products);
480
481static struct usb_driver cdc_driver = {
482 .owner = THIS_MODULE,
483 .name = "cdc_ether",
484 .id_table = products,
485 .probe = usbnet_probe,
486 .disconnect = usbnet_disconnect,
487 .suspend = usbnet_suspend,
488 .resume = usbnet_resume,
489};
490
491
492static int __init cdc_init(void)
493{
494 BUG_ON((sizeof(((struct usbnet *)0)->data)
495 < sizeof(struct cdc_state)));
496
497 return usb_register(&cdc_driver);
498}
499module_init(cdc_init);
500
501static void __exit cdc_exit(void)
502{
503 usb_deregister(&cdc_driver);
504}
505module_exit(cdc_exit);
506
507MODULE_AUTHOR("David Brownell");
508MODULE_DESCRIPTION("USB CDC Ethernet devices");
509MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/cdc_subset.c b/drivers/usb/net/cdc_subset.c
new file mode 100644
index 000000000000..f1730b685fd2
--- /dev/null
+++ b/drivers/usb/net/cdc_subset.c
@@ -0,0 +1,335 @@
1/*
2 * Simple "CDC Subset" USB Networking Links
3 * Copyright (C) 2000-2005 by David Brownell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/config.h>
21#ifdef CONFIG_USB_DEBUG
22# define DEBUG
23#endif
24#include <linux/module.h>
25#include <linux/kmod.h>
26#include <linux/sched.h>
27#include <linux/init.h>
28#include <linux/netdevice.h>
29#include <linux/etherdevice.h>
30#include <linux/ethtool.h>
31#include <linux/workqueue.h>
32#include <linux/mii.h>
33#include <linux/usb.h>
34
35#include "usbnet.h"
36
37
38/*
39 * This supports simple USB network links that don't require any special
40 * framing or hardware control operations. The protocol used here is a
41 * strict subset of CDC Ethernet, with three basic differences reflecting
42 * the goal that almost any hardware should run it:
43 *
44 * - Minimal runtime control: one interface, no altsettings, and
45 * no vendor or class specific control requests. If a device is
46 * configured, it is allowed to exchange packets with the host.
47 * Fancier models would mean not working on some hardware.
48 *
49 * - Minimal manufacturing control: no IEEE "Organizationally
50 * Unique ID" required, or an EEPROMs to store one. Each host uses
51 * one random "locally assigned" Ethernet address instead, which can
52 * of course be overridden using standard tools like "ifconfig".
53 * (With 2^46 such addresses, same-net collisions are quite rare.)
54 *
55 * - There is no additional framing data for USB. Packets are written
56 * exactly as in CDC Ethernet, starting with an Ethernet header and
57 * terminated by a short packet. However, the host will never send a
58 * zero length packet; some systems can't handle those robustly.
59 *
60 * Anything that can transmit and receive USB bulk packets can implement
61 * this protocol. That includes both smart peripherals and quite a lot
62 * of "host-to-host" USB cables (which embed two devices back-to-back).
63 *
64 * Note that although Linux may use many of those host-to-host links
65 * with this "cdc_subset" framing, that doesn't mean there may not be a
66 * better approach. Handling the "other end unplugs/replugs" scenario
67 * well tends to require chip-specific vendor requests. Also, Windows
68 * peers at the other end of host-to-host cables may expect their own
69 * framing to be used rather than this "cdc_subset" model.
70 */
71
72#if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX)
73/* PDA style devices are always connected if present */
74static int always_connected (struct usbnet *dev)
75{
76 return 0;
77}
78#endif
79
80#ifdef CONFIG_USB_ALI_M5632
81#define HAVE_HARDWARE
82
83/*-------------------------------------------------------------------------
84 *
85 * ALi M5632 driver ... does high speed
86 *
87 *-------------------------------------------------------------------------*/
88
89static const struct driver_info ali_m5632_info = {
90 .description = "ALi M5632",
91};
92
93
94#endif
95
96
97#ifdef CONFIG_USB_AN2720
98#define HAVE_HARDWARE
99
100/*-------------------------------------------------------------------------
101 *
102 * AnchorChips 2720 driver ... http://www.cypress.com
103 *
104 * This doesn't seem to have a way to detect whether the peer is
105 * connected, or need any reset handshaking. It's got pretty big
106 * internal buffers (handles most of a frame's worth of data).
107 * Chip data sheets don't describe any vendor control messages.
108 *
109 *-------------------------------------------------------------------------*/
110
111static const struct driver_info an2720_info = {
112 .description = "AnchorChips/Cypress 2720",
113 // no reset available!
114 // no check_connect available!
115
116 .in = 2, .out = 2, // direction distinguishes these
117};
118
119#endif /* CONFIG_USB_AN2720 */
120
121
122#ifdef CONFIG_USB_BELKIN
123#define HAVE_HARDWARE
124
125/*-------------------------------------------------------------------------
126 *
127 * Belkin F5U104 ... two NetChip 2280 devices + Atmel AVR microcontroller
128 *
129 * ... also two eTEK designs, including one sold as "Advance USBNET"
130 *
131 *-------------------------------------------------------------------------*/
132
133static const struct driver_info belkin_info = {
134 .description = "Belkin, eTEK, or compatible",
135};
136
137#endif /* CONFIG_USB_BELKIN */
138
139
140
141#ifdef CONFIG_USB_EPSON2888
142#define HAVE_HARDWARE
143
144/*-------------------------------------------------------------------------
145 *
146 * EPSON USB clients
147 *
148 * This is the same idea as Linux PDAs (below) except the firmware in the
149 * device might not be Tux-powered. Epson provides reference firmware that
150 * implements this interface. Product developers can reuse or modify that
151 * code, such as by using their own product and vendor codes.
152 *
153 * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
154 *
155 *-------------------------------------------------------------------------*/
156
157static const struct driver_info epson2888_info = {
158 .description = "Epson USB Device",
159 .check_connect = always_connected,
160
161 .in = 4, .out = 3,
162};
163
164#endif /* CONFIG_USB_EPSON2888 */
165
166
167#ifdef CONFIG_USB_KC2190
168#define HAVE_HARDWARE
169static const struct driver_info kc2190_info = {
170 .description = "KC Technology KC-190",
171};
172#endif /* CONFIG_USB_KC2190 */
173
174
175#ifdef CONFIG_USB_ARMLINUX
176#define HAVE_HARDWARE
177
178/*-------------------------------------------------------------------------
179 *
180 * Intel's SA-1100 chip integrates basic USB support, and is used
181 * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
182 * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
183 * network using minimal USB framing data.
184 *
185 * This describes the driver currently in standard ARM Linux kernels.
186 * The Zaurus uses a different driver (see later).
187 *
188 * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
189 * and different USB endpoint numbering than the SA1100 devices. The
190 * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
191 * so we rely on the endpoint descriptors.
192 *
193 *-------------------------------------------------------------------------*/
194
195static const struct driver_info linuxdev_info = {
196 .description = "Linux Device",
197 .check_connect = always_connected,
198};
199
200static const struct driver_info yopy_info = {
201 .description = "Yopy",
202 .check_connect = always_connected,
203};
204
205static const struct driver_info blob_info = {
206 .description = "Boot Loader OBject",
207 .check_connect = always_connected,
208};
209
210#endif /* CONFIG_USB_ARMLINUX */
211
212
213/*-------------------------------------------------------------------------*/
214
215#ifndef HAVE_HARDWARE
216#error You need to configure some hardware for this driver
217#endif
218
219/*
220 * chip vendor names won't normally be on the cables, and
221 * may not be on the device.
222 */
223
224static const struct usb_device_id products [] = {
225
226#ifdef CONFIG_USB_ALI_M5632
227{
228 USB_DEVICE (0x0402, 0x5632), // ALi defaults
229 .driver_info = (unsigned long) &ali_m5632_info,
230},
231#endif
232
233#ifdef CONFIG_USB_AN2720
234{
235 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
236 .driver_info = (unsigned long) &an2720_info,
237}, {
238 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
239 .driver_info = (unsigned long) &an2720_info,
240},
241#endif
242
243#ifdef CONFIG_USB_BELKIN
244{
245 USB_DEVICE (0x050d, 0x0004), // Belkin
246 .driver_info = (unsigned long) &belkin_info,
247}, {
248 USB_DEVICE (0x056c, 0x8100), // eTEK
249 .driver_info = (unsigned long) &belkin_info,
250}, {
251 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
252 .driver_info = (unsigned long) &belkin_info,
253},
254#endif
255
256#ifdef CONFIG_USB_EPSON2888
257{
258 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
259 .driver_info = (unsigned long) &epson2888_info,
260},
261#endif
262
263#ifdef CONFIG_USB_KC2190
264{
265 USB_DEVICE (0x050f, 0x0190), // KC-190
266 .driver_info = (unsigned long) &kc2190_info,
267},
268#endif
269
270#ifdef CONFIG_USB_ARMLINUX
271/*
272 * SA-1100 using standard ARM Linux kernels, or compatible.
273 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
274 * The sa-1100 "usb-eth" driver handles the basic framing.
275 *
276 * PXA25x or PXA210 ... these use a "usb-eth" driver much like
277 * the sa1100 one, but hardware uses different endpoint numbers.
278 *
279 * Or the Linux "Ethernet" gadget on hardware that can't talk
280 * CDC Ethernet (e.g., no altsettings), in either of two modes:
281 * - acting just like the old "usb-eth" firmware, though
282 * the implementation is different
283 * - supporting RNDIS as the first/default configuration for
284 * MS-Windows interop; Linux needs to use the other config
285 */
286{
287 // 1183 = 0x049F, both used as hex values?
288 // Compaq "Itsy" vendor/product id
289 USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
290 .driver_info = (unsigned long) &linuxdev_info,
291}, {
292 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
293 .driver_info = (unsigned long) &yopy_info,
294}, {
295 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
296 .driver_info = (unsigned long) &blob_info,
297}, {
298 // Linux Ethernet/RNDIS gadget on pxa210/25x/26x, second config
299 // e.g. Gumstix, current OpenZaurus, ...
300 USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
301 .driver_info = (unsigned long) &linuxdev_info,
302},
303#endif
304
305 { }, // END
306};
307MODULE_DEVICE_TABLE(usb, products);
308
309/*-------------------------------------------------------------------------*/
310
311static struct usb_driver cdc_subset_driver = {
312 .owner = THIS_MODULE,
313 .name = "cdc_subset",
314 .probe = usbnet_probe,
315 .suspend = usbnet_suspend,
316 .resume = usbnet_resume,
317 .disconnect = usbnet_disconnect,
318 .id_table = products,
319};
320
321static int __init cdc_subset_init(void)
322{
323 return usb_register(&cdc_subset_driver);
324}
325module_init(cdc_subset_init);
326
327static void __exit cdc_subset_exit(void)
328{
329 usb_deregister(&cdc_subset_driver);
330}
331module_exit(cdc_subset_exit);
332
333MODULE_AUTHOR("David Brownell");
334MODULE_DESCRIPTION("Simple 'CDC Subset' USB networking links");
335MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/gl620a.c b/drivers/usb/net/gl620a.c
new file mode 100644
index 000000000000..c8763ae33c73
--- /dev/null
+++ b/drivers/usb/net/gl620a.c
@@ -0,0 +1,407 @@
1/*
2 * GeneSys GL620USB-A based links
3 * Copyright (C) 2001 by Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
4 * Copyright (C) 2001 by Stanislav Brabec <utx@penguin.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// #define DEBUG // error path messages, extra info
22// #define VERBOSE // more; success messages
23
24#include <linux/config.h>
25#ifdef CONFIG_USB_DEBUG
26# define DEBUG
27#endif
28#include <linux/module.h>
29#include <linux/sched.h>
30#include <linux/init.h>
31#include <linux/netdevice.h>
32#include <linux/etherdevice.h>
33#include <linux/ethtool.h>
34#include <linux/workqueue.h>
35#include <linux/mii.h>
36#include <linux/usb.h>
37
38#include "usbnet.h"
39
40
41/*
42 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
43 *
44 * ... should partially interop with the Win32 driver for this hardware.
45 * The GeneSys docs imply there's some NDIS issue motivating this framing.
46 *
47 * Some info from GeneSys:
48 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
49 * (Some cables, like the BAFO-100c, use the half duplex version.)
50 * - For the full duplex model, the low bit of the version code says
51 * which side is which ("left/right").
52 * - For the half duplex type, a control/interrupt handshake settles
53 * the transfer direction. (That's disabled here, partially coded.)
54 * A control URB would block until other side writes an interrupt.
55 *
56 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
57 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
58 */
59
60// control msg write command
61#define GENELINK_CONNECT_WRITE 0xF0
62// interrupt pipe index
63#define GENELINK_INTERRUPT_PIPE 0x03
64// interrupt read buffer size
65#define INTERRUPT_BUFSIZE 0x08
66// interrupt pipe interval value
67#define GENELINK_INTERRUPT_INTERVAL 0x10
68// max transmit packet number per transmit
69#define GL_MAX_TRANSMIT_PACKETS 32
70// max packet length
71#define GL_MAX_PACKET_LEN 1514
72// max receive buffer size
73#define GL_RCV_BUF_SIZE \
74 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
75
76struct gl_packet {
77 u32 packet_length;
78 char packet_data [1];
79};
80
81struct gl_header {
82 u32 packet_count;
83 struct gl_packet packets;
84};
85
86#ifdef GENELINK_ACK
87
88// FIXME: this code is incomplete, not debugged; it doesn't
89// handle interrupts correctly; it should use the generic
90// status IRQ code (which didn't exist back in 2001).
91
92struct gl_priv {
93 struct urb *irq_urb;
94 char irq_buf [INTERRUPT_BUFSIZE];
95};
96
97static inline int gl_control_write(struct usbnet *dev, u8 request, u16 value)
98{
99 int retval;
100
101 retval = usb_control_msg(dev->udev,
102 usb_sndctrlpipe(dev->udev, 0),
103 request,
104 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
105 value,
106 0, // index
107 0, // data buffer
108 0, // size
109 USB_CTRL_SET_TIMEOUT);
110 return retval;
111}
112
113static void gl_interrupt_complete(struct urb *urb, struct pt_regs *regs)
114{
115 int status = urb->status;
116
117 switch (status) {
118 case 0:
119 /* success */
120 break;
121 case -ECONNRESET:
122 case -ENOENT:
123 case -ESHUTDOWN:
124 /* this urb is terminated, clean up */
125 dbg("%s - urb shutting down with status: %d",
126 __FUNCTION__, status);
127 return;
128 default:
129 dbg("%s - nonzero urb status received: %d",
130 __FUNCTION__, urb->status);
131 }
132
133 status = usb_submit_urb(urb, GFP_ATOMIC);
134 if (status)
135 err("%s - usb_submit_urb failed with result %d",
136 __FUNCTION__, status);
137}
138
139static int gl_interrupt_read(struct usbnet *dev)
140{
141 struct gl_priv *priv = dev->priv_data;
142 int retval;
143
144 // issue usb interrupt read
145 if (priv && priv->irq_urb) {
146 // submit urb
147 if ((retval = usb_submit_urb(priv->irq_urb, GFP_KERNEL)) != 0)
148 dbg("gl_interrupt_read: submit fail - %X...", retval);
149 else
150 dbg("gl_interrupt_read: submit success...");
151 }
152
153 return 0;
154}
155
156// check whether another side is connected
157static int genelink_check_connect(struct usbnet *dev)
158{
159 int retval;
160
161 dbg("genelink_check_connect...");
162
163 // detect whether another side is connected
164 if ((retval = gl_control_write(dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
165 dbg("%s: genelink_check_connect write fail - %X",
166 dev->net->name, retval);
167 return retval;
168 }
169
170 // usb interrupt read to ack another side
171 if ((retval = gl_interrupt_read(dev)) != 0) {
172 dbg("%s: genelink_check_connect read fail - %X",
173 dev->net->name, retval);
174 return retval;
175 }
176
177 dbg("%s: genelink_check_connect read success", dev->net->name);
178 return 0;
179}
180
181// allocate and initialize the private data for genelink
182static int genelink_init(struct usbnet *dev)
183{
184 struct gl_priv *priv;
185
186 // allocate the private data structure
187 if ((priv = kmalloc(sizeof *priv, GFP_KERNEL)) == 0) {
188 dbg("%s: cannot allocate private data per device",
189 dev->net->name);
190 return -ENOMEM;
191 }
192
193 // allocate irq urb
194 if ((priv->irq_urb = usb_alloc_urb(0, GFP_KERNEL)) == 0) {
195 dbg("%s: cannot allocate private irq urb per device",
196 dev->net->name);
197 kfree(priv);
198 return -ENOMEM;
199 }
200
201 // fill irq urb
202 usb_fill_int_urb(priv->irq_urb, dev->udev,
203 usb_rcvintpipe(dev->udev, GENELINK_INTERRUPT_PIPE),
204 priv->irq_buf, INTERRUPT_BUFSIZE,
205 gl_interrupt_complete, 0,
206 GENELINK_INTERRUPT_INTERVAL);
207
208 // set private data pointer
209 dev->priv_data = priv;
210
211 return 0;
212}
213
214// release the private data
215static int genelink_free(struct usbnet *dev)
216{
217 struct gl_priv *priv = dev->priv_data;
218
219 if (!priv)
220 return 0;
221
222// FIXME: can't cancel here; it's synchronous, and
223// should have happened earlier in any case (interrupt
224// handling needs to be generic)
225
226 // cancel irq urb first
227 usb_kill_urb(priv->irq_urb);
228
229 // free irq urb
230 usb_free_urb(priv->irq_urb);
231
232 // free the private data structure
233 kfree(priv);
234
235 return 0;
236}
237
238#endif
239
240static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
241{
242 struct gl_header *header;
243 struct gl_packet *packet;
244 struct sk_buff *gl_skb;
245 u32 size;
246
247 header = (struct gl_header *) skb->data;
248
249 // get the packet count of the received skb
250 le32_to_cpus(&header->packet_count);
251 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
252 || (header->packet_count < 0)) {
253 dbg("genelink: invalid received packet count %d",
254 header->packet_count);
255 return 0;
256 }
257
258 // set the current packet pointer to the first packet
259 packet = &header->packets;
260
261 // decrement the length for the packet count size 4 bytes
262 skb_pull(skb, 4);
263
264 while (header->packet_count > 1) {
265 // get the packet length
266 size = le32_to_cpu(packet->packet_length);
267
268 // this may be a broken packet
269 if (size > GL_MAX_PACKET_LEN) {
270 dbg("genelink: invalid rx length %d", size);
271 return 0;
272 }
273
274 // allocate the skb for the individual packet
275 gl_skb = alloc_skb(size, GFP_ATOMIC);
276 if (gl_skb) {
277
278 // copy the packet data to the new skb
279 memcpy(skb_put(gl_skb, size),
280 packet->packet_data, size);
281 usbnet_skb_return(dev, gl_skb);
282 }
283
284 // advance to the next packet
285 packet = (struct gl_packet *)
286 &packet->packet_data [size];
287 header->packet_count--;
288
289 // shift the data pointer to the next gl_packet
290 skb_pull(skb, size + 4);
291 }
292
293 // skip the packet length field 4 bytes
294 skb_pull(skb, 4);
295
296 if (skb->len > GL_MAX_PACKET_LEN) {
297 dbg("genelink: invalid rx length %d", skb->len);
298 return 0;
299 }
300 return 1;
301}
302
303static struct sk_buff *
304genelink_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags)
305{
306 int padlen;
307 int length = skb->len;
308 int headroom = skb_headroom(skb);
309 int tailroom = skb_tailroom(skb);
310 u32 *packet_count;
311 u32 *packet_len;
312
313 // FIXME: magic numbers, bleech
314 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
315
316 if ((!skb_cloned(skb))
317 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
318 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
319 skb->data = memmove(skb->head + (4 + 4*1),
320 skb->data, skb->len);
321 skb->tail = skb->data + skb->len;
322 }
323 } else {
324 struct sk_buff *skb2;
325 skb2 = skb_copy_expand(skb, (4 + 4*1) , padlen, flags);
326 dev_kfree_skb_any(skb);
327 skb = skb2;
328 if (!skb)
329 return NULL;
330 }
331
332 // attach the packet count to the header
333 packet_count = (u32 *) skb_push(skb, (4 + 4*1));
334 packet_len = packet_count + 1;
335
336 *packet_count = cpu_to_le32(1);
337 *packet_len = cpu_to_le32(length);
338
339 // add padding byte
340 if ((skb->len % dev->maxpacket) == 0)
341 skb_put(skb, 1);
342
343 return skb;
344}
345
346static int genelink_bind(struct usbnet *dev, struct usb_interface *intf)
347{
348 dev->hard_mtu = GL_RCV_BUF_SIZE;
349 dev->net->hard_header_len += 4;
350 dev->in = usb_rcvbulkpipe(dev->udev, dev->driver_info->in);
351 dev->out = usb_sndbulkpipe(dev->udev, dev->driver_info->out);
352 return 0;
353}
354
355static const struct driver_info genelink_info = {
356 .description = "Genesys GeneLink",
357 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
358 .bind = genelink_bind,
359 .rx_fixup = genelink_rx_fixup,
360 .tx_fixup = genelink_tx_fixup,
361
362 .in = 1, .out = 2,
363
364#ifdef GENELINK_ACK
365 .check_connect =genelink_check_connect,
366#endif
367};
368
369static const struct usb_device_id products [] = {
370
371{
372 USB_DEVICE(0x05e3, 0x0502), // GL620USB-A
373 .driver_info = (unsigned long) &genelink_info,
374},
375 /* NOT: USB_DEVICE(0x05e3, 0x0501), // GL620USB
376 * that's half duplex, not currently supported
377 */
378 { }, // END
379};
380MODULE_DEVICE_TABLE(usb, products);
381
382static struct usb_driver gl620a_driver = {
383 .owner = THIS_MODULE,
384 .name = "gl620a",
385 .id_table = products,
386 .probe = usbnet_probe,
387 .disconnect = usbnet_disconnect,
388 .suspend = usbnet_suspend,
389 .resume = usbnet_resume,
390};
391
392static int __init usbnet_init(void)
393{
394 return usb_register(&gl620a_driver);
395}
396module_init(usbnet_init);
397
398static void __exit usbnet_exit(void)
399{
400 usb_deregister(&gl620a_driver);
401}
402module_exit(usbnet_exit);
403
404MODULE_AUTHOR("Jiun-Jie Huang");
405MODULE_DESCRIPTION("GL620-USB-A Host-to-Host Link cables");
406MODULE_LICENSE("GPL");
407
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
index 7ffa99b9760f..e04b0ce3611a 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/usb/net/kaweth.c
@@ -787,7 +787,6 @@ static int kaweth_start_xmit(struct sk_buff *skb, struct net_device *net)
787 kaweth_usb_transmit_complete, 787 kaweth_usb_transmit_complete,
788 kaweth); 788 kaweth);
789 kaweth->end = 0; 789 kaweth->end = 0;
790 kaweth->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
791 790
792 if((res = usb_submit_urb(kaweth->tx_urb, GFP_ATOMIC))) 791 if((res = usb_submit_urb(kaweth->tx_urb, GFP_ATOMIC)))
793 { 792 {
diff --git a/drivers/usb/net/net1080.c b/drivers/usb/net/net1080.c
new file mode 100644
index 000000000000..a4309c4a491b
--- /dev/null
+++ b/drivers/usb/net/net1080.c
@@ -0,0 +1,622 @@
1/*
2 * Net1080 based USB host-to-host cables
3 * Copyright (C) 2000-2005 by David Brownell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// #define DEBUG // error path messages, extra info
21// #define VERBOSE // more; success messages
22
23#include <linux/config.h>
24#ifdef CONFIG_USB_DEBUG
25# define DEBUG
26#endif
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <linux/init.h>
30#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/ethtool.h>
33#include <linux/workqueue.h>
34#include <linux/mii.h>
35#include <linux/usb.h>
36
37#include <asm/unaligned.h>
38
39#include "usbnet.h"
40
41
42/*
43 * Netchip 1080 driver ... http://www.netchip.com
44 * (Sept 2004: End-of-life announcement has been sent.)
45 * Used in (some) LapLink cables
46 */
47
48#define frame_errors data[1]
49
50/*
51 * NetChip framing of ethernet packets, supporting additional error
52 * checks for links that may drop bulk packets from inside messages.
53 * Odd USB length == always short read for last usb packet.
54 * - nc_header
55 * - Ethernet header (14 bytes)
56 * - payload
57 * - (optional padding byte, if needed so length becomes odd)
58 * - nc_trailer
59 *
60 * This framing is to be avoided for non-NetChip devices.
61 */
62
63struct nc_header { // packed:
64 __le16 hdr_len; // sizeof nc_header (LE, all)
65 __le16 packet_len; // payload size (including ethhdr)
66 __le16 packet_id; // detects dropped packets
67#define MIN_HEADER 6
68
69 // all else is optional, and must start with:
70 // __le16 vendorId; // from usb-if
71 // __le16 productId;
72} __attribute__((__packed__));
73
74#define PAD_BYTE ((unsigned char)0xAC)
75
76struct nc_trailer {
77 __le16 packet_id;
78} __attribute__((__packed__));
79
80// packets may use FLAG_FRAMING_NC and optional pad
81#define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
82 + sizeof (struct ethhdr) \
83 + (mtu) \
84 + 1 \
85 + sizeof (struct nc_trailer))
86
87#define MIN_FRAMED FRAMED_SIZE(0)
88
89/* packets _could_ be up to 64KB... */
90#define NC_MAX_PACKET 32767
91
92
93/*
94 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
95 * before the hardware drops it. If that's done, the driver will need to
96 * frame network packets to guard against the dropped USB packets. The win32
97 * driver sets this for both sides of the link.
98 */
99#define NC_READ_TTL_MS ((u8)255) // ms
100
101/*
102 * We ignore most registers and EEPROM contents.
103 */
104#define REG_USBCTL ((u8)0x04)
105#define REG_TTL ((u8)0x10)
106#define REG_STATUS ((u8)0x11)
107
108/*
109 * Vendor specific requests to read/write data
110 */
111#define REQUEST_REGISTER ((u8)0x10)
112#define REQUEST_EEPROM ((u8)0x11)
113
114static int
115nc_vendor_read(struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
116{
117 int status = usb_control_msg(dev->udev,
118 usb_rcvctrlpipe(dev->udev, 0),
119 req,
120 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
121 0, regnum,
122 retval_ptr, sizeof *retval_ptr,
123 USB_CTRL_GET_TIMEOUT);
124 if (status > 0)
125 status = 0;
126 if (!status)
127 le16_to_cpus(retval_ptr);
128 return status;
129}
130
131static inline int
132nc_register_read(struct usbnet *dev, u8 regnum, u16 *retval_ptr)
133{
134 return nc_vendor_read(dev, REQUEST_REGISTER, regnum, retval_ptr);
135}
136
137// no retval ... can become async, usable in_interrupt()
138static void
139nc_vendor_write(struct usbnet *dev, u8 req, u8 regnum, u16 value)
140{
141 usb_control_msg(dev->udev,
142 usb_sndctrlpipe(dev->udev, 0),
143 req,
144 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
145 value, regnum,
146 NULL, 0, // data is in setup packet
147 USB_CTRL_SET_TIMEOUT);
148}
149
150static inline void
151nc_register_write(struct usbnet *dev, u8 regnum, u16 value)
152{
153 nc_vendor_write(dev, REQUEST_REGISTER, regnum, value);
154}
155
156
157#if 0
158static void nc_dump_registers(struct usbnet *dev)
159{
160 u8 reg;
161 u16 *vp = kmalloc(sizeof (u16));
162
163 if (!vp) {
164 dbg("no memory?");
165 return;
166 }
167
168 dbg("%s registers:", dev->net->name);
169 for (reg = 0; reg < 0x20; reg++) {
170 int retval;
171
172 // reading some registers is trouble
173 if (reg >= 0x08 && reg <= 0xf)
174 continue;
175 if (reg >= 0x12 && reg <= 0x1e)
176 continue;
177
178 retval = nc_register_read(dev, reg, vp);
179 if (retval < 0)
180 dbg("%s reg [0x%x] ==> error %d",
181 dev->net->name, reg, retval);
182 else
183 dbg("%s reg [0x%x] = 0x%x",
184 dev->net->name, reg, *vp);
185 }
186 kfree(vp);
187}
188#endif
189
190
191/*-------------------------------------------------------------------------*/
192
193/*
194 * Control register
195 */
196
197#define USBCTL_WRITABLE_MASK 0x1f0f
198// bits 15-13 reserved, r/o
199#define USBCTL_ENABLE_LANG (1 << 12)
200#define USBCTL_ENABLE_MFGR (1 << 11)
201#define USBCTL_ENABLE_PROD (1 << 10)
202#define USBCTL_ENABLE_SERIAL (1 << 9)
203#define USBCTL_ENABLE_DEFAULTS (1 << 8)
204// bits 7-4 reserved, r/o
205#define USBCTL_FLUSH_OTHER (1 << 3)
206#define USBCTL_FLUSH_THIS (1 << 2)
207#define USBCTL_DISCONN_OTHER (1 << 1)
208#define USBCTL_DISCONN_THIS (1 << 0)
209
210static inline void nc_dump_usbctl(struct usbnet *dev, u16 usbctl)
211{
212 if (!netif_msg_link(dev))
213 return;
214 devdbg(dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
215 " this%s%s;"
216 " other%s%s; r/o 0x%x",
217 dev->udev->bus->bus_name, dev->udev->devpath,
218 usbctl,
219 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
220 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
221 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
222 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
223 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
224
225 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
226 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
227 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
228 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
229 usbctl & ~USBCTL_WRITABLE_MASK
230 );
231}
232
233/*-------------------------------------------------------------------------*/
234
235/*
236 * Status register
237 */
238
239#define STATUS_PORT_A (1 << 15)
240
241#define STATUS_CONN_OTHER (1 << 14)
242#define STATUS_SUSPEND_OTHER (1 << 13)
243#define STATUS_MAILBOX_OTHER (1 << 12)
244#define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
245
246#define STATUS_CONN_THIS (1 << 6)
247#define STATUS_SUSPEND_THIS (1 << 5)
248#define STATUS_MAILBOX_THIS (1 << 4)
249#define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
250
251#define STATUS_UNSPEC_MASK 0x0c8c
252#define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
253
254
255static inline void nc_dump_status(struct usbnet *dev, u16 status)
256{
257 if (!netif_msg_link(dev))
258 return;
259 devdbg(dev, "net1080 %s-%s status 0x%x:"
260 " this (%c) PKT=%d%s%s%s;"
261 " other PKT=%d%s%s%s; unspec 0x%x",
262 dev->udev->bus->bus_name, dev->udev->devpath,
263 status,
264
265 // XXX the packet counts don't seem right
266 // (1 at reset, not 0); maybe UNSPEC too
267
268 (status & STATUS_PORT_A) ? 'A' : 'B',
269 STATUS_PACKETS_THIS(status),
270 (status & STATUS_CONN_THIS) ? " CON" : "",
271 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
272 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
273
274 STATUS_PACKETS_OTHER(status),
275 (status & STATUS_CONN_OTHER) ? " CON" : "",
276 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
277 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
278
279 status & STATUS_UNSPEC_MASK
280 );
281}
282
283/*-------------------------------------------------------------------------*/
284
285/*
286 * TTL register
287 */
288
289#define TTL_THIS(ttl) (0x00ff & ttl)
290#define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
291#define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
292
293static inline void nc_dump_ttl(struct usbnet *dev, u16 ttl)
294{
295 if (netif_msg_link(dev))
296 devdbg(dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
297 dev->udev->bus->bus_name, dev->udev->devpath,
298 ttl, TTL_THIS(ttl), TTL_OTHER(ttl));
299}
300
301/*-------------------------------------------------------------------------*/
302
303static int net1080_reset(struct usbnet *dev)
304{
305 u16 usbctl, status, ttl;
306 u16 *vp = kmalloc(sizeof (u16), GFP_KERNEL);
307 int retval;
308
309 if (!vp)
310 return -ENOMEM;
311
312 // nc_dump_registers(dev);
313
314 if ((retval = nc_register_read(dev, REG_STATUS, vp)) < 0) {
315 dbg("can't read %s-%s status: %d",
316 dev->udev->bus->bus_name, dev->udev->devpath, retval);
317 goto done;
318 }
319 status = *vp;
320 nc_dump_status(dev, status);
321
322 if ((retval = nc_register_read(dev, REG_USBCTL, vp)) < 0) {
323 dbg("can't read USBCTL, %d", retval);
324 goto done;
325 }
326 usbctl = *vp;
327 nc_dump_usbctl(dev, usbctl);
328
329 nc_register_write(dev, REG_USBCTL,
330 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
331
332 if ((retval = nc_register_read(dev, REG_TTL, vp)) < 0) {
333 dbg("can't read TTL, %d", retval);
334 goto done;
335 }
336 ttl = *vp;
337 // nc_dump_ttl(dev, ttl);
338
339 nc_register_write(dev, REG_TTL,
340 MK_TTL(NC_READ_TTL_MS, TTL_OTHER(ttl)) );
341 dbg("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
342
343 if (netif_msg_link(dev))
344 devinfo(dev, "port %c, peer %sconnected",
345 (status & STATUS_PORT_A) ? 'A' : 'B',
346 (status & STATUS_CONN_OTHER) ? "" : "dis"
347 );
348 retval = 0;
349
350done:
351 kfree(vp);
352 return retval;
353}
354
355static int net1080_check_connect(struct usbnet *dev)
356{
357 int retval;
358 u16 status;
359 u16 *vp = kmalloc(sizeof (u16), GFP_KERNEL);
360
361 if (!vp)
362 return -ENOMEM;
363 retval = nc_register_read(dev, REG_STATUS, vp);
364 status = *vp;
365 kfree(vp);
366 if (retval != 0) {
367 dbg("%s net1080_check_conn read - %d", dev->net->name, retval);
368 return retval;
369 }
370 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
371 return -ENOLINK;
372 return 0;
373}
374
375static void nc_flush_complete(struct urb *urb, struct pt_regs *regs)
376{
377 kfree(urb->context);
378 usb_free_urb(urb);
379}
380
381static void nc_ensure_sync(struct usbnet *dev)
382{
383 dev->frame_errors++;
384 if (dev->frame_errors > 5) {
385 struct urb *urb;
386 struct usb_ctrlrequest *req;
387 int status;
388
389 /* Send a flush */
390 urb = usb_alloc_urb(0, SLAB_ATOMIC);
391 if (!urb)
392 return;
393
394 req = kmalloc(sizeof *req, GFP_ATOMIC);
395 if (!req) {
396 usb_free_urb(urb);
397 return;
398 }
399
400 req->bRequestType = USB_DIR_OUT
401 | USB_TYPE_VENDOR
402 | USB_RECIP_DEVICE;
403 req->bRequest = REQUEST_REGISTER;
404 req->wValue = cpu_to_le16(USBCTL_FLUSH_THIS
405 | USBCTL_FLUSH_OTHER);
406 req->wIndex = cpu_to_le16(REG_USBCTL);
407 req->wLength = cpu_to_le16(0);
408
409 /* queue an async control request, we don't need
410 * to do anything when it finishes except clean up.
411 */
412 usb_fill_control_urb(urb, dev->udev,
413 usb_sndctrlpipe(dev->udev, 0),
414 (unsigned char *) req,
415 NULL, 0,
416 nc_flush_complete, req);
417 status = usb_submit_urb(urb, GFP_ATOMIC);
418 if (status) {
419 kfree(req);
420 usb_free_urb(urb);
421 return;
422 }
423
424 if (netif_msg_rx_err(dev))
425 devdbg(dev, "flush net1080; too many framing errors");
426 dev->frame_errors = 0;
427 }
428}
429
430static int net1080_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
431{
432 struct nc_header *header;
433 struct nc_trailer *trailer;
434 u16 hdr_len, packet_len;
435
436 if (!(skb->len & 0x01)) {
437#ifdef DEBUG
438 struct net_device *net = dev->net;
439 dbg("rx framesize %d range %d..%d mtu %d", skb->len,
440 net->hard_header_len, dev->hard_mtu, net->mtu);
441#endif
442 dev->stats.rx_frame_errors++;
443 nc_ensure_sync(dev);
444 return 0;
445 }
446
447 header = (struct nc_header *) skb->data;
448 hdr_len = le16_to_cpup(&header->hdr_len);
449 packet_len = le16_to_cpup(&header->packet_len);
450 if (FRAMED_SIZE(packet_len) > NC_MAX_PACKET) {
451 dev->stats.rx_frame_errors++;
452 dbg("packet too big, %d", packet_len);
453 nc_ensure_sync(dev);
454 return 0;
455 } else if (hdr_len < MIN_HEADER) {
456 dev->stats.rx_frame_errors++;
457 dbg("header too short, %d", hdr_len);
458 nc_ensure_sync(dev);
459 return 0;
460 } else if (hdr_len > MIN_HEADER) {
461 // out of band data for us?
462 dbg("header OOB, %d bytes", hdr_len - MIN_HEADER);
463 nc_ensure_sync(dev);
464 // switch (vendor/product ids) { ... }
465 }
466 skb_pull(skb, hdr_len);
467
468 trailer = (struct nc_trailer *)
469 (skb->data + skb->len - sizeof *trailer);
470 skb_trim(skb, skb->len - sizeof *trailer);
471
472 if ((packet_len & 0x01) == 0) {
473 if (skb->data [packet_len] != PAD_BYTE) {
474 dev->stats.rx_frame_errors++;
475 dbg("bad pad");
476 return 0;
477 }
478 skb_trim(skb, skb->len - 1);
479 }
480 if (skb->len != packet_len) {
481 dev->stats.rx_frame_errors++;
482 dbg("bad packet len %d (expected %d)",
483 skb->len, packet_len);
484 nc_ensure_sync(dev);
485 return 0;
486 }
487 if (header->packet_id != get_unaligned(&trailer->packet_id)) {
488 dev->stats.rx_fifo_errors++;
489 dbg("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
490 le16_to_cpu(header->packet_id),
491 le16_to_cpu(trailer->packet_id));
492 return 0;
493 }
494#if 0
495 devdbg(dev, "frame <rx h %d p %d id %d", header->hdr_len,
496 header->packet_len, header->packet_id);
497#endif
498 dev->frame_errors = 0;
499 return 1;
500}
501
502static struct sk_buff *
503net1080_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags)
504{
505 int padlen;
506 struct sk_buff *skb2;
507 struct nc_header *header = NULL;
508 struct nc_trailer *trailer = NULL;
509 int len = skb->len;
510
511 padlen = ((len + sizeof (struct nc_header)
512 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
513 if (!skb_cloned(skb)) {
514 int headroom = skb_headroom(skb);
515 int tailroom = skb_tailroom(skb);
516
517 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
518 && sizeof (struct nc_header) <= headroom)
519 /* There's enough head and tail room */
520 goto encapsulate;
521
522 if ((sizeof (struct nc_header) + padlen
523 + sizeof (struct nc_trailer)) <
524 (headroom + tailroom)) {
525 /* There's enough total room, so just readjust */
526 skb->data = memmove(skb->head
527 + sizeof (struct nc_header),
528 skb->data, skb->len);
529 skb->tail = skb->data + len;
530 goto encapsulate;
531 }
532 }
533
534 /* Create a new skb to use with the correct size */
535 skb2 = skb_copy_expand(skb,
536 sizeof (struct nc_header),
537 sizeof (struct nc_trailer) + padlen,
538 flags);
539 dev_kfree_skb_any(skb);
540 if (!skb2)
541 return skb2;
542 skb = skb2;
543
544encapsulate:
545 /* header first */
546 header = (struct nc_header *) skb_push(skb, sizeof *header);
547 header->hdr_len = cpu_to_le16(sizeof (*header));
548 header->packet_len = cpu_to_le16(len);
549 header->packet_id = cpu_to_le16((u16)dev->xid++);
550
551 /* maybe pad; then trailer */
552 if (!((skb->len + sizeof *trailer) & 0x01))
553 *skb_put(skb, 1) = PAD_BYTE;
554 trailer = (struct nc_trailer *) skb_put(skb, sizeof *trailer);
555 put_unaligned(header->packet_id, &trailer->packet_id);
556#if 0
557 devdbg(dev, "frame >tx h %d p %d id %d",
558 header->hdr_len, header->packet_len,
559 header->packet_id);
560#endif
561 return skb;
562}
563
564static int net1080_bind(struct usbnet *dev, struct usb_interface *intf)
565{
566 unsigned extra = sizeof (struct nc_header)
567 + 1
568 + sizeof (struct nc_trailer);
569
570 dev->net->hard_header_len += extra;
571 dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
572 dev->hard_mtu = NC_MAX_PACKET;
573 return usbnet_get_endpoints (dev, intf);
574}
575
576static const struct driver_info net1080_info = {
577 .description = "NetChip TurboCONNECT",
578 .flags = FLAG_FRAMING_NC,
579 .bind = net1080_bind,
580 .reset = net1080_reset,
581 .check_connect = net1080_check_connect,
582 .rx_fixup = net1080_rx_fixup,
583 .tx_fixup = net1080_tx_fixup,
584};
585
586static const struct usb_device_id products [] = {
587{
588 USB_DEVICE(0x0525, 0x1080), // NetChip ref design
589 .driver_info = (unsigned long) &net1080_info,
590}, {
591 USB_DEVICE(0x06D0, 0x0622), // Laplink Gold
592 .driver_info = (unsigned long) &net1080_info,
593},
594 { }, // END
595};
596MODULE_DEVICE_TABLE(usb, products);
597
598static struct usb_driver net1080_driver = {
599 .owner = THIS_MODULE,
600 .name = "net1080",
601 .id_table = products,
602 .probe = usbnet_probe,
603 .disconnect = usbnet_disconnect,
604 .suspend = usbnet_suspend,
605 .resume = usbnet_resume,
606};
607
608static int __init net1080_init(void)
609{
610 return usb_register(&net1080_driver);
611}
612module_init(net1080_init);
613
614static void __exit net1080_exit(void)
615{
616 usb_deregister(&net1080_driver);
617}
618module_exit(net1080_exit);
619
620MODULE_AUTHOR("David Brownell");
621MODULE_DESCRIPTION("NetChip 1080 based USB Host-to-Host Links");
622MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index fcd6d3ccef44..7484d34780fc 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -825,7 +825,6 @@ static void pegasus_tx_timeout(struct net_device *net)
825 pegasus_t *pegasus = netdev_priv(net); 825 pegasus_t *pegasus = netdev_priv(net);
826 if (netif_msg_timer(pegasus)) 826 if (netif_msg_timer(pegasus))
827 printk(KERN_WARNING "%s: tx timeout\n", net->name); 827 printk(KERN_WARNING "%s: tx timeout\n", net->name);
828 pegasus->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
829 usb_unlink_urb(pegasus->tx_urb); 828 usb_unlink_urb(pegasus->tx_urb);
830 pegasus->stats.tx_errors++; 829 pegasus->stats.tx_errors++;
831} 830}
diff --git a/drivers/usb/net/plusb.c b/drivers/usb/net/plusb.c
new file mode 100644
index 000000000000..74c2b3581c76
--- /dev/null
+++ b/drivers/usb/net/plusb.c
@@ -0,0 +1,156 @@
1/*
2 * PL-2301/2302 USB host-to-host link cables
3 * Copyright (C) 2000-2005 by David Brownell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// #define DEBUG // error path messages, extra info
21// #define VERBOSE // more; success messages
22
23#include <linux/config.h>
24#ifdef CONFIG_USB_DEBUG
25# define DEBUG
26#endif
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <linux/init.h>
30#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/ethtool.h>
33#include <linux/workqueue.h>
34#include <linux/mii.h>
35#include <linux/usb.h>
36
37#include "usbnet.h"
38
39
40/*
41 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
42 *
43 * The protocol and handshaking used here should be bug-compatible
44 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
45 *
46 * HEADS UP: this handshaking isn't all that robust. This driver
47 * gets confused easily if you unplug one end of the cable then
48 * try to connect it again; you'll need to restart both ends. The
49 * "naplink" software (used by some PlayStation/2 deveopers) does
50 * the handshaking much better! Also, sometimes this hardware
51 * seems to get wedged under load. Prolific docs are weak, and
52 * don't identify differences between PL2301 and PL2302, much less
53 * anything to explain the different PL2302 versions observed.
54 */
55
56/*
57 * Bits 0-4 can be used for software handshaking; they're set from
58 * one end, cleared from the other, "read" with the interrupt byte.
59 */
60#define PL_S_EN (1<<7) /* (feature only) suspend enable */
61/* reserved bit -- rx ready (6) ? */
62#define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
63#define PL_RESET_OUT (1<<4) /* reset output pipe */
64#define PL_RESET_IN (1<<3) /* reset input pipe */
65#define PL_TX_C (1<<2) /* transmission complete */
66#define PL_TX_REQ (1<<1) /* transmission received */
67#define PL_PEER_E (1<<0) /* peer exists */
68
69static inline int
70pl_vendor_req(struct usbnet *dev, u8 req, u8 val, u8 index)
71{
72 return usb_control_msg(dev->udev,
73 usb_rcvctrlpipe(dev->udev, 0),
74 req,
75 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
76 val, index,
77 NULL, 0,
78 USB_CTRL_GET_TIMEOUT);
79}
80
81static inline int
82pl_clear_QuickLink_features(struct usbnet *dev, int val)
83{
84 return pl_vendor_req(dev, 1, (u8) val, 0);
85}
86
87static inline int
88pl_set_QuickLink_features(struct usbnet *dev, int val)
89{
90 return pl_vendor_req(dev, 3, (u8) val, 0);
91}
92
93static int pl_reset(struct usbnet *dev)
94{
95 /* some units seem to need this reset, others reject it utterly.
96 * FIXME be more like "naplink" or windows drivers.
97 */
98 (void) pl_set_QuickLink_features(dev,
99 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
100 return 0;
101}
102
103static const struct driver_info prolific_info = {
104 .description = "Prolific PL-2301/PL-2302",
105 .flags = FLAG_NO_SETINT,
106 /* some PL-2302 versions seem to fail usb_set_interface() */
107 .reset = pl_reset,
108};
109
110
111/*-------------------------------------------------------------------------*/
112
113/*
114 * Proilific's name won't normally be on the cables, and
115 * may not be on the device.
116 */
117
118static const struct usb_device_id products [] = {
119
120{
121 USB_DEVICE(0x067b, 0x0000), // PL-2301
122 .driver_info = (unsigned long) &prolific_info,
123}, {
124 USB_DEVICE(0x067b, 0x0001), // PL-2302
125 .driver_info = (unsigned long) &prolific_info,
126},
127
128 { }, // END
129};
130MODULE_DEVICE_TABLE(usb, products);
131
132static struct usb_driver plusb_driver = {
133 .owner = THIS_MODULE,
134 .name = "plusb",
135 .id_table = products,
136 .probe = usbnet_probe,
137 .disconnect = usbnet_disconnect,
138 .suspend = usbnet_suspend,
139 .resume = usbnet_resume,
140};
141
142static int __init plusb_init(void)
143{
144 return usb_register(&plusb_driver);
145}
146module_init(plusb_init);
147
148static void __exit plusb_exit(void)
149{
150 usb_deregister(&plusb_driver);
151}
152module_exit(plusb_exit);
153
154MODULE_AUTHOR("David Brownell");
155MODULE_DESCRIPTION("Prolific PL-2301/2302 USB Host to Host Link Driver");
156MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/rndis_host.c b/drivers/usb/net/rndis_host.c
new file mode 100644
index 000000000000..2ed2e5fb7778
--- /dev/null
+++ b/drivers/usb/net/rndis_host.c
@@ -0,0 +1,615 @@
1/*
2 * Host Side support for RNDIS Networking Links
3 * Copyright (C) 2005 by David Brownell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// #define DEBUG // error path messages, extra info
21// #define VERBOSE // more; success messages
22
23#include <linux/config.h>
24#ifdef CONFIG_USB_DEBUG
25# define DEBUG
26#endif
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <linux/init.h>
30#include <linux/netdevice.h>
31#include <linux/etherdevice.h>
32#include <linux/ethtool.h>
33#include <linux/workqueue.h>
34#include <linux/mii.h>
35#include <linux/usb.h>
36#include <linux/usb_cdc.h>
37
38#include "usbnet.h"
39
40
41/*
42 * RNDIS is NDIS remoted over USB. It's a MSFT variant of CDC ACM ... of
43 * course ACM was intended for modems, not Ethernet links! USB's standard
44 * for Ethernet links is "CDC Ethernet", which is significantly simpler.
45 */
46
47/*
48 * CONTROL uses CDC "encapsulated commands" with funky notifications.
49 * - control-out: SEND_ENCAPSULATED
50 * - interrupt-in: RESPONSE_AVAILABLE
51 * - control-in: GET_ENCAPSULATED
52 *
53 * We'll try to ignore the RESPONSE_AVAILABLE notifications.
54 */
55struct rndis_msg_hdr {
56 __le32 msg_type; /* RNDIS_MSG_* */
57 __le32 msg_len;
58 // followed by data that varies between messages
59 __le32 request_id;
60 __le32 status;
61 // ... and more
62} __attribute__ ((packed));
63
64/* RNDIS defines this (absurdly huge) control timeout */
65#define RNDIS_CONTROL_TIMEOUT_MS (10 * 1000)
66
67
68#define ccpu2 __constant_cpu_to_le32
69
70#define RNDIS_MSG_COMPLETION ccpu2(0x80000000)
71
72/* codes for "msg_type" field of rndis messages;
73 * only the data channel uses packet messages (maybe batched);
74 * everything else goes on the control channel.
75 */
76#define RNDIS_MSG_PACKET ccpu2(0x00000001) /* 1-N packets */
77#define RNDIS_MSG_INIT ccpu2(0x00000002)
78#define RNDIS_MSG_INIT_C (RNDIS_MSG_INIT|RNDIS_MSG_COMPLETION)
79#define RNDIS_MSG_HALT ccpu2(0x00000003)
80#define RNDIS_MSG_QUERY ccpu2(0x00000004)
81#define RNDIS_MSG_QUERY_C (RNDIS_MSG_QUERY|RNDIS_MSG_COMPLETION)
82#define RNDIS_MSG_SET ccpu2(0x00000005)
83#define RNDIS_MSG_SET_C (RNDIS_MSG_SET|RNDIS_MSG_COMPLETION)
84#define RNDIS_MSG_RESET ccpu2(0x00000006)
85#define RNDIS_MSG_RESET_C (RNDIS_MSG_RESET|RNDIS_MSG_COMPLETION)
86#define RNDIS_MSG_INDICATE ccpu2(0x00000007)
87#define RNDIS_MSG_KEEPALIVE ccpu2(0x00000008)
88#define RNDIS_MSG_KEEPALIVE_C (RNDIS_MSG_KEEPALIVE|RNDIS_MSG_COMPLETION)
89
90/* codes for "status" field of completion messages */
91#define RNDIS_STATUS_SUCCESS ccpu2(0x00000000)
92#define RNDIS_STATUS_FAILURE ccpu2(0xc0000001)
93#define RNDIS_STATUS_INVALID_DATA ccpu2(0xc0010015)
94#define RNDIS_STATUS_NOT_SUPPORTED ccpu2(0xc00000bb)
95#define RNDIS_STATUS_MEDIA_CONNECT ccpu2(0x4001000b)
96#define RNDIS_STATUS_MEDIA_DISCONNECT ccpu2(0x4001000c)
97
98
99struct rndis_data_hdr {
100 __le32 msg_type; /* RNDIS_MSG_PACKET */
101 __le32 msg_len; // rndis_data_hdr + data_len + pad
102 __le32 data_offset; // 36 -- right after header
103 __le32 data_len; // ... real packet size
104
105 __le32 oob_data_offset; // zero
106 __le32 oob_data_len; // zero
107 __le32 num_oob; // zero
108 __le32 packet_data_offset; // zero
109
110 __le32 packet_data_len; // zero
111 __le32 vc_handle; // zero
112 __le32 reserved; // zero
113} __attribute__ ((packed));
114
115struct rndis_init { /* OUT */
116 // header and:
117 __le32 msg_type; /* RNDIS_MSG_INIT */
118 __le32 msg_len; // 24
119 __le32 request_id;
120 __le32 major_version; // of rndis (1.0)
121 __le32 minor_version;
122 __le32 max_transfer_size;
123} __attribute__ ((packed));
124
125struct rndis_init_c { /* IN */
126 // header and:
127 __le32 msg_type; /* RNDIS_MSG_INIT_C */
128 __le32 msg_len;
129 __le32 request_id;
130 __le32 status;
131 __le32 major_version; // of rndis (1.0)
132 __le32 minor_version;
133 __le32 device_flags;
134 __le32 medium; // zero == 802.3
135 __le32 max_packets_per_message;
136 __le32 max_transfer_size;
137 __le32 packet_alignment; // max 7; (1<<n) bytes
138 __le32 af_list_offset; // zero
139 __le32 af_list_size; // zero
140} __attribute__ ((packed));
141
142struct rndis_halt { /* OUT (no reply) */
143 // header and:
144 __le32 msg_type; /* RNDIS_MSG_HALT */
145 __le32 msg_len;
146 __le32 request_id;
147} __attribute__ ((packed));
148
149struct rndis_query { /* OUT */
150 // header and:
151 __le32 msg_type; /* RNDIS_MSG_QUERY */
152 __le32 msg_len;
153 __le32 request_id;
154 __le32 oid;
155 __le32 len;
156 __le32 offset;
157/*?*/ __le32 handle; // zero
158} __attribute__ ((packed));
159
160struct rndis_query_c { /* IN */
161 // header and:
162 __le32 msg_type; /* RNDIS_MSG_QUERY_C */
163 __le32 msg_len;
164 __le32 request_id;
165 __le32 status;
166 __le32 len;
167 __le32 offset;
168} __attribute__ ((packed));
169
170struct rndis_set { /* OUT */
171 // header and:
172 __le32 msg_type; /* RNDIS_MSG_SET */
173 __le32 msg_len;
174 __le32 request_id;
175 __le32 oid;
176 __le32 len;
177 __le32 offset;
178/*?*/ __le32 handle; // zero
179} __attribute__ ((packed));
180
181struct rndis_set_c { /* IN */
182 // header and:
183 __le32 msg_type; /* RNDIS_MSG_SET_C */
184 __le32 msg_len;
185 __le32 request_id;
186 __le32 status;
187} __attribute__ ((packed));
188
189struct rndis_reset { /* IN */
190 // header and:
191 __le32 msg_type; /* RNDIS_MSG_RESET */
192 __le32 msg_len;
193 __le32 reserved;
194} __attribute__ ((packed));
195
196struct rndis_reset_c { /* OUT */
197 // header and:
198 __le32 msg_type; /* RNDIS_MSG_RESET_C */
199 __le32 msg_len;
200 __le32 status;
201 __le32 addressing_lost;
202} __attribute__ ((packed));
203
204struct rndis_indicate { /* IN (unrequested) */
205 // header and:
206 __le32 msg_type; /* RNDIS_MSG_INDICATE */
207 __le32 msg_len;
208 __le32 status;
209 __le32 length;
210 __le32 offset;
211/**/ __le32 diag_status;
212 __le32 error_offset;
213/**/ __le32 message;
214} __attribute__ ((packed));
215
216struct rndis_keepalive { /* OUT (optionally IN) */
217 // header and:
218 __le32 msg_type; /* RNDIS_MSG_KEEPALIVE */
219 __le32 msg_len;
220 __le32 request_id;
221} __attribute__ ((packed));
222
223struct rndis_keepalive_c { /* IN (optionally OUT) */
224 // header and:
225 __le32 msg_type; /* RNDIS_MSG_KEEPALIVE_C */
226 __le32 msg_len;
227 __le32 request_id;
228 __le32 status;
229} __attribute__ ((packed));
230
231/* NOTE: about 30 OIDs are "mandatory" for peripherals to support ... and
232 * there are gobs more that may optionally be supported. We'll avoid as much
233 * of that mess as possible.
234 */
235#define OID_802_3_PERMANENT_ADDRESS ccpu2(0x01010101)
236#define OID_GEN_CURRENT_PACKET_FILTER ccpu2(0x0001010e)
237
238/*
239 * RNDIS notifications from device: command completion; "reverse"
240 * keepalives; etc
241 */
242static void rndis_status(struct usbnet *dev, struct urb *urb)
243{
244 devdbg(dev, "rndis status urb, len %d stat %d",
245 urb->actual_length, urb->status);
246 // FIXME for keepalives, respond immediately (asynchronously)
247 // if not an RNDIS status, do like cdc_status(dev,urb) does
248}
249
250/*
251 * RPC done RNDIS-style. Caller guarantees:
252 * - message is properly byteswapped
253 * - there's no other request pending
254 * - buf can hold up to 1KB response (required by RNDIS spec)
255 * On return, the first few entries are already byteswapped.
256 *
257 * Call context is likely probe(), before interface name is known,
258 * which is why we won't try to use it in the diagnostics.
259 */
260static int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf)
261{
262 struct cdc_state *info = (void *) &dev->data;
263 int retval;
264 unsigned count;
265 __le32 rsp;
266 u32 xid = 0, msg_len, request_id;
267
268 /* REVISIT when this gets called from contexts other than probe() or
269 * disconnect(): either serialize, or dispatch responses on xid
270 */
271
272 /* Issue the request; don't bother byteswapping our xid */
273 if (likely(buf->msg_type != RNDIS_MSG_HALT
274 && buf->msg_type != RNDIS_MSG_RESET)) {
275 xid = dev->xid++;
276 if (!xid)
277 xid = dev->xid++;
278 buf->request_id = (__force __le32) xid;
279 }
280 retval = usb_control_msg(dev->udev,
281 usb_sndctrlpipe(dev->udev, 0),
282 USB_CDC_SEND_ENCAPSULATED_COMMAND,
283 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
284 0, info->u->bMasterInterface0,
285 buf, le32_to_cpu(buf->msg_len),
286 RNDIS_CONTROL_TIMEOUT_MS);
287 if (unlikely(retval < 0 || xid == 0))
288 return retval;
289
290 // FIXME Seems like some devices discard responses when
291 // we time out and cancel our "get response" requests...
292 // so, this is fragile. Probably need to poll for status.
293
294 /* ignore status endpoint, just poll the control channel;
295 * the request probably completed immediately
296 */
297 rsp = buf->msg_type | RNDIS_MSG_COMPLETION;
298 for (count = 0; count < 10; count++) {
299 memset(buf, 0, 1024);
300 retval = usb_control_msg(dev->udev,
301 usb_rcvctrlpipe(dev->udev, 0),
302 USB_CDC_GET_ENCAPSULATED_RESPONSE,
303 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
304 0, info->u->bMasterInterface0,
305 buf, 1024,
306 RNDIS_CONTROL_TIMEOUT_MS);
307 if (likely(retval >= 8)) {
308 msg_len = le32_to_cpu(buf->msg_len);
309 request_id = (__force u32) buf->request_id;
310 if (likely(buf->msg_type == rsp)) {
311 if (likely(request_id == xid)) {
312 if (unlikely(rsp == RNDIS_MSG_RESET_C))
313 return 0;
314 if (likely(RNDIS_STATUS_SUCCESS
315 == buf->status))
316 return 0;
317 dev_dbg(&info->control->dev,
318 "rndis reply status %08x\n",
319 le32_to_cpu(buf->status));
320 return -EL3RST;
321 }
322 dev_dbg(&info->control->dev,
323 "rndis reply id %d expected %d\n",
324 request_id, xid);
325 /* then likely retry */
326 } else switch (buf->msg_type) {
327 case RNDIS_MSG_INDICATE: { /* fault */
328 // struct rndis_indicate *msg = (void *)buf;
329 dev_info(&info->control->dev,
330 "rndis fault indication\n");
331 }
332 break;
333 case RNDIS_MSG_KEEPALIVE: { /* ping */
334 struct rndis_keepalive_c *msg = (void *)buf;
335
336 msg->msg_type = RNDIS_MSG_KEEPALIVE_C;
337 msg->msg_len = ccpu2(sizeof *msg);
338 msg->status = RNDIS_STATUS_SUCCESS;
339 retval = usb_control_msg(dev->udev,
340 usb_sndctrlpipe(dev->udev, 0),
341 USB_CDC_SEND_ENCAPSULATED_COMMAND,
342 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
343 0, info->u->bMasterInterface0,
344 msg, sizeof *msg,
345 RNDIS_CONTROL_TIMEOUT_MS);
346 if (unlikely(retval < 0))
347 dev_dbg(&info->control->dev,
348 "rndis keepalive err %d\n",
349 retval);
350 }
351 break;
352 default:
353 dev_dbg(&info->control->dev,
354 "unexpected rndis msg %08x len %d\n",
355 le32_to_cpu(buf->msg_type), msg_len);
356 }
357 } else {
358 /* device probably issued a protocol stall; ignore */
359 dev_dbg(&info->control->dev,
360 "rndis response error, code %d\n", retval);
361 }
362 msleep(2);
363 }
364 dev_dbg(&info->control->dev, "rndis response timeout\n");
365 return -ETIMEDOUT;
366}
367
368static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
369{
370 int retval;
371 struct net_device *net = dev->net;
372 union {
373 void *buf;
374 struct rndis_msg_hdr *header;
375 struct rndis_init *init;
376 struct rndis_init_c *init_c;
377 struct rndis_query *get;
378 struct rndis_query_c *get_c;
379 struct rndis_set *set;
380 struct rndis_set_c *set_c;
381 } u;
382 u32 tmp;
383
384 /* we can't rely on i/o from stack working, or stack allocation */
385 u.buf = kmalloc(1024, GFP_KERNEL);
386 if (!u.buf)
387 return -ENOMEM;
388 retval = usbnet_generic_cdc_bind(dev, intf);
389 if (retval < 0)
390 goto done;
391
392 net->hard_header_len += sizeof (struct rndis_data_hdr);
393
394 /* initialize; max transfer is 16KB at full speed */
395 u.init->msg_type = RNDIS_MSG_INIT;
396 u.init->msg_len = ccpu2(sizeof *u.init);
397 u.init->major_version = ccpu2(1);
398 u.init->minor_version = ccpu2(0);
399 u.init->max_transfer_size = ccpu2(net->mtu + net->hard_header_len);
400
401 retval = rndis_command(dev, u.header);
402 if (unlikely(retval < 0)) {
403 /* it might not even be an RNDIS device!! */
404 dev_err(&intf->dev, "RNDIS init failed, %d\n", retval);
405fail:
406 usb_driver_release_interface(driver_of(intf),
407 ((struct cdc_state *)&(dev->data))->data);
408 goto done;
409 }
410 dev->hard_mtu = le32_to_cpu(u.init_c->max_transfer_size);
411 /* REVISIT: peripheral "alignment" request is ignored ... */
412 dev_dbg(&intf->dev, "hard mtu %u, align %d\n", dev->hard_mtu,
413 1 << le32_to_cpu(u.init_c->packet_alignment));
414
415 /* get designated host ethernet address */
416 memset(u.get, 0, sizeof *u.get);
417 u.get->msg_type = RNDIS_MSG_QUERY;
418 u.get->msg_len = ccpu2(sizeof *u.get);
419 u.get->oid = OID_802_3_PERMANENT_ADDRESS;
420
421 retval = rndis_command(dev, u.header);
422 if (unlikely(retval < 0)) {
423 dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval);
424 goto fail;
425 }
426 tmp = le32_to_cpu(u.get_c->offset);
427 if (unlikely((tmp + 8) > (1024 - ETH_ALEN)
428 || u.get_c->len != ccpu2(ETH_ALEN))) {
429 dev_err(&intf->dev, "rndis ethaddr off %d len %d ?\n",
430 tmp, le32_to_cpu(u.get_c->len));
431 retval = -EDOM;
432 goto fail;
433 }
434 memcpy(net->dev_addr, tmp + (char *)&u.get_c->request_id, ETH_ALEN);
435
436 /* set a nonzero filter to enable data transfers */
437 memset(u.set, 0, sizeof *u.set);
438 u.set->msg_type = RNDIS_MSG_SET;
439 u.set->msg_len = ccpu2(4 + sizeof *u.set);
440 u.set->oid = OID_GEN_CURRENT_PACKET_FILTER;
441 u.set->len = ccpu2(4);
442 u.set->offset = ccpu2((sizeof *u.set) - 8);
443 *(__le32 *)(u.buf + sizeof *u.set) = ccpu2(DEFAULT_FILTER);
444
445 retval = rndis_command(dev, u.header);
446 if (unlikely(retval < 0)) {
447 dev_err(&intf->dev, "rndis set packet filter, %d\n", retval);
448 goto fail;
449 }
450
451 retval = 0;
452done:
453 kfree(u.buf);
454 return retval;
455}
456
457static void rndis_unbind(struct usbnet *dev, struct usb_interface *intf)
458{
459 struct rndis_halt *halt;
460
461 /* try to clear any rndis state/activity (no i/o from stack!) */
462 halt = kcalloc(1, sizeof *halt, SLAB_KERNEL);
463 if (halt) {
464 halt->msg_type = RNDIS_MSG_HALT;
465 halt->msg_len = ccpu2(sizeof *halt);
466 (void) rndis_command(dev, (void *)halt);
467 kfree(halt);
468 }
469
470 return usbnet_cdc_unbind(dev, intf);
471}
472
473/*
474 * DATA -- host must not write zlps
475 */
476static int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
477{
478 /* peripheral may have batched packets to us... */
479 while (likely(skb->len)) {
480 struct rndis_data_hdr *hdr = (void *)skb->data;
481 struct sk_buff *skb2;
482 u32 msg_len, data_offset, data_len;
483
484 msg_len = le32_to_cpu(hdr->msg_len);
485 data_offset = le32_to_cpu(hdr->data_offset);
486 data_len = le32_to_cpu(hdr->data_len);
487
488 /* don't choke if we see oob, per-packet data, etc */
489 if (unlikely(hdr->msg_type != RNDIS_MSG_PACKET
490 || skb->len < msg_len
491 || (data_offset + data_len + 8) > msg_len)) {
492 dev->stats.rx_frame_errors++;
493 devdbg(dev, "bad rndis message %d/%d/%d/%d, len %d",
494 le32_to_cpu(hdr->msg_type),
495 msg_len, data_offset, data_len, skb->len);
496 return 0;
497 }
498 skb_pull(skb, 8 + data_offset);
499
500 /* at most one packet left? */
501 if (likely((data_len - skb->len) <= sizeof *hdr)) {
502 skb_trim(skb, data_len);
503 break;
504 }
505
506 /* try to return all the packets in the batch */
507 skb2 = skb_clone(skb, GFP_ATOMIC);
508 if (unlikely(!skb2))
509 break;
510 skb_pull(skb, msg_len - sizeof *hdr);
511 skb_trim(skb2, data_len);
512 usbnet_skb_return(dev, skb2);
513 }
514
515 /* caller will usbnet_skb_return the remaining packet */
516 return 1;
517}
518
519static struct sk_buff *
520rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags)
521{
522 struct rndis_data_hdr *hdr;
523 struct sk_buff *skb2;
524 unsigned len = skb->len;
525
526 if (likely(!skb_cloned(skb))) {
527 int room = skb_headroom(skb);
528
529 /* enough head room as-is? */
530 if (unlikely((sizeof *hdr) <= room))
531 goto fill;
532
533 /* enough room, but needs to be readjusted? */
534 room += skb_tailroom(skb);
535 if (likely((sizeof *hdr) <= room)) {
536 skb->data = memmove(skb->head + sizeof *hdr,
537 skb->data, len);
538 skb->tail = skb->data + len;
539 goto fill;
540 }
541 }
542
543 /* create a new skb, with the correct size (and tailpad) */
544 skb2 = skb_copy_expand(skb, sizeof *hdr, 1, flags);
545 dev_kfree_skb_any(skb);
546 if (unlikely(!skb2))
547 return skb2;
548 skb = skb2;
549
550 /* fill out the RNDIS header. we won't bother trying to batch
551 * packets; Linux minimizes wasted bandwidth through tx queues.
552 */
553fill:
554 hdr = (void *) __skb_push(skb, sizeof *hdr);
555 memset(hdr, 0, sizeof *hdr);
556 hdr->msg_type = RNDIS_MSG_PACKET;
557 hdr->msg_len = cpu_to_le32(skb->len);
558 hdr->data_offset = ccpu2(sizeof(*hdr) - 8);
559 hdr->data_len = cpu_to_le32(len);
560
561 /* FIXME make the last packet always be short ... */
562 return skb;
563}
564
565
566static const struct driver_info rndis_info = {
567 .description = "RNDIS device",
568 .flags = FLAG_ETHER | FLAG_FRAMING_RN,
569 .bind = rndis_bind,
570 .unbind = rndis_unbind,
571 .status = rndis_status,
572 .rx_fixup = rndis_rx_fixup,
573 .tx_fixup = rndis_tx_fixup,
574};
575
576#undef ccpu2
577
578
579/*-------------------------------------------------------------------------*/
580
581static const struct usb_device_id products [] = {
582{
583 /* RNDIS is MSFT's un-official variant of CDC ACM */
584 USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
585 .driver_info = (unsigned long) &rndis_info,
586},
587 { }, // END
588};
589MODULE_DEVICE_TABLE(usb, products);
590
591static struct usb_driver rndis_driver = {
592 .owner = THIS_MODULE,
593 .name = "rndis_host",
594 .id_table = products,
595 .probe = usbnet_probe,
596 .disconnect = usbnet_disconnect,
597 .suspend = usbnet_suspend,
598 .resume = usbnet_resume,
599};
600
601static int __init rndis_init(void)
602{
603 return usb_register(&rndis_driver);
604}
605module_init(rndis_init);
606
607static void __exit rndis_exit(void)
608{
609 usb_deregister(&rndis_driver);
610}
611module_exit(rndis_exit);
612
613MODULE_AUTHOR("David Brownell");
614MODULE_DESCRIPTION("USB Host side RNDIS driver");
615MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index 59ab40ebb394..c3d4e3589e30 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -653,7 +653,6 @@ static void rtl8150_tx_timeout(struct net_device *netdev)
653{ 653{
654 rtl8150_t *dev = netdev_priv(netdev); 654 rtl8150_t *dev = netdev_priv(netdev);
655 warn("%s: Tx timeout.", netdev->name); 655 warn("%s: Tx timeout.", netdev->name);
656 dev->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
657 usb_unlink_urb(dev->tx_urb); 656 usb_unlink_urb(dev->tx_urb);
658 dev->stats.tx_errors++; 657 dev->stats.tx_errors++;
659} 658}
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index a2f67245f6da..6c460918d54f 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -1,10 +1,7 @@
1/* 1/*
2 * USB Networking Links 2 * USB Network driver infrastructure
3 * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net> 3 * Copyright (C) 2000-2005 by David Brownell
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 4 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
6 * Copyright (C) 2005 Phil Chang <pchang23@sbcglobal.net>
7 * Copyright (c) 2002-2003 TiVo Inc.
8 * 5 *
9 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
@@ -23,95 +20,15 @@
23 20
24/* 21/*
25 * This is a generic "USB networking" framework that works with several 22 * This is a generic "USB networking" framework that works with several
26 * kinds of full and high speed networking devices: 23 * kinds of full and high speed networking devices: host-to-host cables,
27 * 24 * smart usb peripherals, and actual Ethernet adapters.
28 * + USB host-to-host "network cables", used for IP-over-USB links. 25 *
29 * These are often used for Laplink style connectivity products. 26 * These devices usually differ in terms of control protocols (if they
30 * - AnchorChip 2720 27 * even have one!) and sometimes they define new framing to wrap or batch
31 * - Belkin, eTEK (interops with Win32 drivers) 28 * Ethernet packets. Otherwise, they talk to USB pretty much the same,
32 * - GeneSys GL620USB-A 29 * so interface (un)binding, endpoint I/O queues, fault handling, and other
33 * - NetChip 1080 (interoperates with NetChip Win32 drivers) 30 * issues can usefully be addressed by this framework.
34 * - Prolific PL-2301/2302 (replaces "plusb" driver) 31 */
35 * - KC Technology KC2190
36 *
37 * + Smart USB devices can support such links directly, using Internet
38 * standard protocols instead of proprietary host-to-device links.
39 * - Linux PDAs like iPaq, Yopy, and Zaurus
40 * - The BLOB boot loader (for diskless booting)
41 * - Linux "gadgets", perhaps using PXA-2xx or Net2280 controllers
42 * - Devices using EPSON's sample USB firmware
43 * - CDC-Ethernet class devices, such as many cable modems
44 *
45 * + Adapters to networks such as Ethernet.
46 * - AX8817X based USB 2.0 products
47 *
48 * Links to these devices can be bridged using Linux Ethernet bridging.
49 * With minor exceptions, these all use similar USB framing for network
50 * traffic, but need different protocols for control traffic.
51 *
52 * USB devices can implement their side of this protocol at the cost
53 * of two bulk endpoints; it's not restricted to "cable" applications.
54 * See the SA1110, Zaurus, or EPSON device/client support in this driver;
55 * slave/target drivers such as "usb-eth" (on most SA-1100 PDAs) or
56 * "g_ether" (in the Linux "gadget" framework) implement that behavior
57 * within devices.
58 *
59 *
60 * CHANGELOG:
61 *
62 * 13-sep-2000 experimental, new
63 * 10-oct-2000 usb_device_id table created.
64 * 28-oct-2000 misc fixes; mostly, discard more TTL-mangled rx packets.
65 * 01-nov-2000 usb_device_id table and probing api update by
66 * Adam J. Richter <adam@yggdrasil.com>.
67 * 18-dec-2000 (db) tx watchdog, "net1080" renaming to "usbnet", device_info
68 * and prolific support, isolate net1080-specific bits, cleanup.
69 * fix unlink_urbs oops in D3 PM resume code path.
70 *
71 * 02-feb-2001 (db) fix tx skb sharing, packet length, match_flags, ...
72 * 08-feb-2001 stubbed in "linuxdev", maybe the SA-1100 folk can use it;
73 * AnchorChips 2720 support (from spec) for testing;
74 * fix bit-ordering problem with ethernet multicast addr
75 * 19-feb-2001 Support for clearing halt conditions. SA1100 UDC support
76 * updates. Oleg Drokin (green@iXcelerator.com)
77 * 25-mar-2001 More SA-1100 updates, including workaround for ip problem
78 * expecting cleared skb->cb and framing change to match latest
79 * handhelds.org version (Oleg). Enable device IDs from the
80 * Win32 Belkin driver; other cleanups (db).
81 * 16-jul-2001 Bugfixes for uhci oops-on-unplug, Belkin support, various
82 * cleanups for problems not yet seen in the field. (db)
83 * 17-oct-2001 Handle "Advance USBNET" product, like Belkin/eTEK devices,
84 * from Ioannis Mavroukakis <i.mavroukakis@btinternet.com>;
85 * rx unlinks somehow weren't async; minor cleanup.
86 * 03-nov-2001 Merged GeneSys driver; original code from Jiun-Jie Huang
87 * <huangjj@genesyslogic.com.tw>, updated by Stanislav Brabec
88 * <utx@penguin.cz>. Made framing options (NetChip/GeneSys)
89 * tie mostly to (sub)driver info. Workaround some PL-2302
90 * chips that seem to reject SET_INTERFACE requests.
91 *
92 * 06-apr-2002 Added ethtool support, based on a patch from Brad Hards.
93 * Level of diagnostics is more configurable; they use device
94 * location (usb_device->devpath) instead of address (2.5).
95 * For tx_fixup, memflags can't be NOIO.
96 * 07-may-2002 Generalize/cleanup keventd support, handling rx stalls (mostly
97 * for USB 2.0 TTs) and memory shortages (potential) too. (db)
98 * Use "locally assigned" IEEE802 address space. (Brad Hards)
99 * 18-oct-2002 Support for Zaurus (Pavel Machek), related cleanup (db).
100 * 14-dec-2002 Remove Zaurus-private crc32 code (Pavel); 2.5 oops fix,
101 * cleanups and stubbed PXA-250 support (db), fix for framing
102 * issues on Z, net1080, and gl620a (Toby Milne)
103 *
104 * 31-mar-2003 Use endpoint descriptors: high speed support, simpler sa1100
105 * vs pxa25x, and CDC Ethernet. Throttle down log floods on
106 * disconnect; other cleanups. (db) Flush net1080 fifos
107 * after several sequential framing errors. (Johannes Erdfelt)
108 * 22-aug-2003 AX8817X support (Dave Hollis).
109 * 14-jun-2004 Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan
110 * (Neil Bortnak)
111 * 03-nov-2004 Trivial patch for KC2190 (KC-190) chip. (Jonathan McDowell)
112 *
113 * 01-feb-2005 AX88772 support (Phil Chang & Dave Hollis)
114 *-------------------------------------------------------------------------*/
115 32
116// #define DEBUG // error path messages, extra info 33// #define DEBUG // error path messages, extra info
117// #define VERBOSE // more; success messages 34// #define VERBOSE // more; success messages
@@ -121,24 +38,18 @@
121# define DEBUG 38# define DEBUG
122#endif 39#endif
123#include <linux/module.h> 40#include <linux/module.h>
124#include <linux/kmod.h>
125#include <linux/sched.h> 41#include <linux/sched.h>
126#include <linux/init.h> 42#include <linux/init.h>
127#include <linux/netdevice.h> 43#include <linux/netdevice.h>
128#include <linux/etherdevice.h> 44#include <linux/etherdevice.h>
129#include <linux/random.h>
130#include <linux/ethtool.h> 45#include <linux/ethtool.h>
131#include <linux/workqueue.h> 46#include <linux/workqueue.h>
132#include <linux/mii.h> 47#include <linux/mii.h>
133#include <asm/uaccess.h>
134#include <asm/unaligned.h>
135#include <linux/usb.h> 48#include <linux/usb.h>
136#include <asm/io.h>
137#include <asm/scatterlist.h>
138#include <linux/mm.h>
139#include <linux/dma-mapping.h>
140 49
141#define DRIVER_VERSION "03-Nov-2004" 50#include "usbnet.h"
51
52#define DRIVER_VERSION "22-Aug-2005"
142 53
143 54
144/*-------------------------------------------------------------------------*/ 55/*-------------------------------------------------------------------------*/
@@ -149,15 +60,14 @@
149 * One maximum size Ethernet packet takes twenty four of them. 60 * One maximum size Ethernet packet takes twenty four of them.
150 * For high speed, each frame comfortably fits almost 36 max size 61 * For high speed, each frame comfortably fits almost 36 max size
151 * Ethernet packets (so queues should be bigger). 62 * Ethernet packets (so queues should be bigger).
63 *
64 * REVISIT qlens should be members of 'struct usbnet'; the goal is to
65 * let the USB host controller be busy for 5msec or more before an irq
66 * is required, under load. Jumbograms change the equation.
152 */ 67 */
153#define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) 68#define RX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
154#define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4) 69#define TX_QLEN(dev) (((dev)->udev->speed == USB_SPEED_HIGH) ? 60 : 4)
155 70
156// packets are always ethernet inside
157// ... except they can be bigger (limit of 64K with NetChip framing)
158#define MIN_PACKET sizeof(struct ethhdr)
159#define MAX_PACKET 32768
160
161// reawaken network queue this soon after stopping; else watchdog barks 71// reawaken network queue this soon after stopping; else watchdog barks
162#define TX_TIMEOUT_JIFFIES (5*HZ) 72#define TX_TIMEOUT_JIFFIES (5*HZ)
163 73
@@ -165,9 +75,6 @@
165// us (it polls at HZ/4 usually) before we report too many false errors. 75// us (it polls at HZ/4 usually) before we report too many false errors.
166#define THROTTLE_JIFFIES (HZ/8) 76#define THROTTLE_JIFFIES (HZ/8)
167 77
168// for vendor-specific control operations
169#define CONTROL_TIMEOUT_MS 500
170
171// between wakeups 78// between wakeups
172#define UNLINK_TIMEOUT_MS 3 79#define UNLINK_TIMEOUT_MS 3
173 80
@@ -176,109 +83,6 @@
176// randomly generated ethernet address 83// randomly generated ethernet address
177static u8 node_id [ETH_ALEN]; 84static u8 node_id [ETH_ALEN];
178 85
179// state we keep for each device we handle
180struct usbnet {
181 // housekeeping
182 struct usb_device *udev;
183 struct driver_info *driver_info;
184 wait_queue_head_t *wait;
185
186 // i/o info: pipes etc
187 unsigned in, out;
188 struct usb_host_endpoint *status;
189 unsigned maxpacket;
190 struct timer_list delay;
191
192 // protocol/interface state
193 struct net_device *net;
194 struct net_device_stats stats;
195 int msg_enable;
196 unsigned long data [5];
197
198 struct mii_if_info mii;
199
200 // various kinds of pending driver work
201 struct sk_buff_head rxq;
202 struct sk_buff_head txq;
203 struct sk_buff_head done;
204 struct urb *interrupt;
205 struct tasklet_struct bh;
206
207 struct work_struct kevent;
208 unsigned long flags;
209# define EVENT_TX_HALT 0
210# define EVENT_RX_HALT 1
211# define EVENT_RX_MEMORY 2
212# define EVENT_STS_SPLIT 3
213# define EVENT_LINK_RESET 4
214};
215
216// device-specific info used by the driver
217struct driver_info {
218 char *description;
219
220 int flags;
221/* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
222#define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
223#define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
224#define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
225#define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
226
227#define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
228#define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
229
230#define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
231
232 /* init device ... can sleep, or cause probe() failure */
233 int (*bind)(struct usbnet *, struct usb_interface *);
234
235 /* cleanup device ... can sleep, but can't fail */
236 void (*unbind)(struct usbnet *, struct usb_interface *);
237
238 /* reset device ... can sleep */
239 int (*reset)(struct usbnet *);
240
241 /* see if peer is connected ... can sleep */
242 int (*check_connect)(struct usbnet *);
243
244 /* for status polling */
245 void (*status)(struct usbnet *, struct urb *);
246
247 /* link reset handling, called from defer_kevent */
248 int (*link_reset)(struct usbnet *);
249
250 /* fixup rx packet (strip framing) */
251 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
252
253 /* fixup tx packet (add framing) */
254 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
255 struct sk_buff *skb, int flags);
256
257 // FIXME -- also an interrupt mechanism
258 // useful for at least PL2301/2302 and GL620USB-A
259 // and CDC use them to report 'is it connected' changes
260
261 /* for new devices, use the descriptor-reading code instead */
262 int in; /* rx endpoint */
263 int out; /* tx endpoint */
264
265 unsigned long data; /* Misc driver specific data */
266};
267
268// we record the state for each of our queued skbs
269enum skb_state {
270 illegal = 0,
271 tx_start, tx_done,
272 rx_start, rx_done, rx_cleanup
273};
274
275struct skb_data { // skb->cb is one of these
276 struct urb *urb;
277 struct usbnet *dev;
278 enum skb_state state;
279 size_t length;
280};
281
282static const char driver_name [] = "usbnet"; 86static const char driver_name [] = "usbnet";
283 87
284/* use ethtool to change the level for any given device */ 88/* use ethtool to change the level for any given device */
@@ -286,39 +90,10 @@ static int msg_level = -1;
286module_param (msg_level, int, 0); 90module_param (msg_level, int, 0);
287MODULE_PARM_DESC (msg_level, "Override default message level"); 91MODULE_PARM_DESC (msg_level, "Override default message level");
288 92
289
290#ifdef DEBUG
291#define devdbg(usbnet, fmt, arg...) \
292 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
293#else
294#define devdbg(usbnet, fmt, arg...) do {} while(0)
295#endif
296
297#define deverr(usbnet, fmt, arg...) \
298 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
299#define devwarn(usbnet, fmt, arg...) \
300 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
301
302#define devinfo(usbnet, fmt, arg...) \
303 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
304
305/*-------------------------------------------------------------------------*/ 93/*-------------------------------------------------------------------------*/
306 94
307static void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
308static u32 usbnet_get_link (struct net_device *);
309static u32 usbnet_get_msglevel (struct net_device *);
310static void usbnet_set_msglevel (struct net_device *, u32);
311static void defer_kevent (struct usbnet *, int);
312
313/* mostly for PDA style devices, which are always connected if present */
314static int always_connected (struct usbnet *dev)
315{
316 return 0;
317}
318
319/* handles CDC Ethernet and many other network "bulk data" interfaces */ 95/* handles CDC Ethernet and many other network "bulk data" interfaces */
320static int 96int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
321get_endpoints (struct usbnet *dev, struct usb_interface *intf)
322{ 97{
323 int tmp; 98 int tmp;
324 struct usb_host_interface *alt = NULL; 99 struct usb_host_interface *alt = NULL;
@@ -382,6 +157,7 @@ get_endpoints (struct usbnet *dev, struct usb_interface *intf)
382 dev->status = status; 157 dev->status = status;
383 return 0; 158 return 0;
384} 159}
160EXPORT_SYMBOL_GPL(usbnet_get_endpoints);
385 161
386static void intr_complete (struct urb *urb, struct pt_regs *regs); 162static void intr_complete (struct urb *urb, struct pt_regs *regs);
387 163
@@ -421,7 +197,11 @@ static int init_status (struct usbnet *dev, struct usb_interface *intf)
421 return 0; 197 return 0;
422} 198}
423 199
424static void skb_return (struct usbnet *dev, struct sk_buff *skb) 200/* Passes this packet up the stack, updating its accounting.
201 * Some link protocols batch packets, so their rx_fixup paths
202 * can return clones as well as just modify the original skb.
203 */
204void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)
425{ 205{
426 int status; 206 int status;
427 207
@@ -438,2425 +218,7 @@ static void skb_return (struct usbnet *dev, struct sk_buff *skb)
438 if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev)) 218 if (status != NET_RX_SUCCESS && netif_msg_rx_err (dev))
439 devdbg (dev, "netif_rx status %d", status); 219 devdbg (dev, "netif_rx status %d", status);
440} 220}
441 221EXPORT_SYMBOL_GPL(usbnet_skb_return);
442
443#ifdef CONFIG_USB_ALI_M5632
444#define HAVE_HARDWARE
445
446/*-------------------------------------------------------------------------
447 *
448 * ALi M5632 driver ... does high speed
449 *
450 *-------------------------------------------------------------------------*/
451
452static const struct driver_info ali_m5632_info = {
453 .description = "ALi M5632",
454};
455
456
457#endif
458
459
460#ifdef CONFIG_USB_AN2720
461#define HAVE_HARDWARE
462
463/*-------------------------------------------------------------------------
464 *
465 * AnchorChips 2720 driver ... http://www.cypress.com
466 *
467 * This doesn't seem to have a way to detect whether the peer is
468 * connected, or need any reset handshaking. It's got pretty big
469 * internal buffers (handles most of a frame's worth of data).
470 * Chip data sheets don't describe any vendor control messages.
471 *
472 *-------------------------------------------------------------------------*/
473
474static const struct driver_info an2720_info = {
475 .description = "AnchorChips/Cypress 2720",
476 // no reset available!
477 // no check_connect available!
478
479 .in = 2, .out = 2, // direction distinguishes these
480};
481
482#endif /* CONFIG_USB_AN2720 */
483
484
485#ifdef CONFIG_USB_AX8817X
486/* ASIX AX8817X based USB 2.0 Ethernet Devices */
487
488#define HAVE_HARDWARE
489#define NEED_MII
490
491#include <linux/crc32.h>
492
493#define AX_CMD_SET_SW_MII 0x06
494#define AX_CMD_READ_MII_REG 0x07
495#define AX_CMD_WRITE_MII_REG 0x08
496#define AX_CMD_SET_HW_MII 0x0a
497#define AX_CMD_READ_EEPROM 0x0b
498#define AX_CMD_WRITE_EEPROM 0x0c
499#define AX_CMD_WRITE_ENABLE 0x0d
500#define AX_CMD_WRITE_DISABLE 0x0e
501#define AX_CMD_WRITE_RX_CTL 0x10
502#define AX_CMD_READ_IPG012 0x11
503#define AX_CMD_WRITE_IPG0 0x12
504#define AX_CMD_WRITE_IPG1 0x13
505#define AX_CMD_WRITE_IPG2 0x14
506#define AX_CMD_WRITE_MULTI_FILTER 0x16
507#define AX_CMD_READ_NODE_ID 0x17
508#define AX_CMD_READ_PHY_ID 0x19
509#define AX_CMD_READ_MEDIUM_STATUS 0x1a
510#define AX_CMD_WRITE_MEDIUM_MODE 0x1b
511#define AX_CMD_READ_MONITOR_MODE 0x1c
512#define AX_CMD_WRITE_MONITOR_MODE 0x1d
513#define AX_CMD_WRITE_GPIOS 0x1f
514#define AX_CMD_SW_RESET 0x20
515#define AX_CMD_SW_PHY_STATUS 0x21
516#define AX_CMD_SW_PHY_SELECT 0x22
517#define AX88772_CMD_READ_NODE_ID 0x13
518
519#define AX_MONITOR_MODE 0x01
520#define AX_MONITOR_LINK 0x02
521#define AX_MONITOR_MAGIC 0x04
522#define AX_MONITOR_HSFS 0x10
523
524/* AX88172 Medium Status Register values */
525#define AX_MEDIUM_FULL_DUPLEX 0x02
526#define AX_MEDIUM_TX_ABORT_ALLOW 0x04
527#define AX_MEDIUM_FLOW_CONTROL_EN 0x10
528
529#define AX_MCAST_FILTER_SIZE 8
530#define AX_MAX_MCAST 64
531
532#define AX_EEPROM_LEN 0x40
533
534#define AX_SWRESET_CLEAR 0x00
535#define AX_SWRESET_RR 0x01
536#define AX_SWRESET_RT 0x02
537#define AX_SWRESET_PRTE 0x04
538#define AX_SWRESET_PRL 0x08
539#define AX_SWRESET_BZ 0x10
540#define AX_SWRESET_IPRL 0x20
541#define AX_SWRESET_IPPD 0x40
542
543#define AX88772_IPG0_DEFAULT 0x15
544#define AX88772_IPG1_DEFAULT 0x0c
545#define AX88772_IPG2_DEFAULT 0x12
546
547#define AX88772_MEDIUM_FULL_DUPLEX 0x0002
548#define AX88772_MEDIUM_RESERVED 0x0004
549#define AX88772_MEDIUM_RX_FC_ENABLE 0x0010
550#define AX88772_MEDIUM_TX_FC_ENABLE 0x0020
551#define AX88772_MEDIUM_PAUSE_FORMAT 0x0080
552#define AX88772_MEDIUM_RX_ENABLE 0x0100
553#define AX88772_MEDIUM_100MB 0x0200
554#define AX88772_MEDIUM_DEFAULT \
555 (AX88772_MEDIUM_FULL_DUPLEX | AX88772_MEDIUM_RX_FC_ENABLE | \
556 AX88772_MEDIUM_TX_FC_ENABLE | AX88772_MEDIUM_100MB | \
557 AX88772_MEDIUM_RESERVED | AX88772_MEDIUM_RX_ENABLE )
558
559#define AX_EEPROM_MAGIC 0xdeadbeef
560
561/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
562struct ax8817x_data {
563 u8 multi_filter[AX_MCAST_FILTER_SIZE];
564};
565
566struct ax88172_int_data {
567 u16 res1;
568 u8 link;
569 u16 res2;
570 u8 status;
571 u16 res3;
572} __attribute__ ((packed));
573
574static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
575 u16 size, void *data)
576{
577 return usb_control_msg(
578 dev->udev,
579 usb_rcvctrlpipe(dev->udev, 0),
580 cmd,
581 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
582 value,
583 index,
584 data,
585 size,
586 CONTROL_TIMEOUT_MS);
587}
588
589static int ax8817x_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
590 u16 size, void *data)
591{
592 return usb_control_msg(
593 dev->udev,
594 usb_sndctrlpipe(dev->udev, 0),
595 cmd,
596 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
597 value,
598 index,
599 data,
600 size,
601 CONTROL_TIMEOUT_MS);
602}
603
604static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
605{
606 struct usb_ctrlrequest *req = (struct usb_ctrlrequest *)urb->context;
607
608 if (urb->status < 0)
609 printk(KERN_DEBUG "ax8817x_async_cmd_callback() failed with %d",
610 urb->status);
611
612 kfree(req);
613 usb_free_urb(urb);
614}
615
616static void ax8817x_status(struct usbnet *dev, struct urb *urb)
617{
618 struct ax88172_int_data *event;
619 int link;
620
621 if (urb->actual_length < 8)
622 return;
623
624 event = urb->transfer_buffer;
625 link = event->link & 0x01;
626 if (netif_carrier_ok(dev->net) != link) {
627 if (link) {
628 netif_carrier_on(dev->net);
629 defer_kevent (dev, EVENT_LINK_RESET );
630 } else
631 netif_carrier_off(dev->net);
632 devdbg(dev, "ax8817x - Link Status is: %d", link);
633 }
634}
635
636static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
637 u16 size, void *data)
638{
639 struct usb_ctrlrequest *req;
640 int status;
641 struct urb *urb;
642
643 if ((urb = usb_alloc_urb(0, GFP_ATOMIC)) == NULL) {
644 devdbg(dev, "Error allocating URB in write_cmd_async!");
645 return;
646 }
647
648 if ((req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC)) == NULL) {
649 deverr(dev, "Failed to allocate memory for control request");
650 usb_free_urb(urb);
651 return;
652 }
653
654 req->bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
655 req->bRequest = cmd;
656 req->wValue = cpu_to_le16(value);
657 req->wIndex = cpu_to_le16(index);
658 req->wLength = cpu_to_le16(size);
659
660 usb_fill_control_urb(urb, dev->udev,
661 usb_sndctrlpipe(dev->udev, 0),
662 (void *)req, data, size,
663 ax8817x_async_cmd_callback, req);
664
665 if((status = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
666 deverr(dev, "Error submitting the control message: status=%d", status);
667 kfree(req);
668 usb_free_urb(urb);
669 }
670}
671
672static void ax8817x_set_multicast(struct net_device *net)
673{
674 struct usbnet *dev = netdev_priv(net);
675 struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
676 u8 rx_ctl = 0x8c;
677
678 if (net->flags & IFF_PROMISC) {
679 rx_ctl |= 0x01;
680 } else if (net->flags & IFF_ALLMULTI
681 || net->mc_count > AX_MAX_MCAST) {
682 rx_ctl |= 0x02;
683 } else if (net->mc_count == 0) {
684 /* just broadcast and directed */
685 } else {
686 /* We use the 20 byte dev->data
687 * for our 8 byte filter buffer
688 * to avoid allocating memory that
689 * is tricky to free later */
690 struct dev_mc_list *mc_list = net->mc_list;
691 u32 crc_bits;
692 int i;
693
694 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
695
696 /* Build the multicast hash filter. */
697 for (i = 0; i < net->mc_count; i++) {
698 crc_bits =
699 ether_crc(ETH_ALEN,
700 mc_list->dmi_addr) >> 26;
701 data->multi_filter[crc_bits >> 3] |=
702 1 << (crc_bits & 7);
703 mc_list = mc_list->next;
704 }
705
706 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
707 AX_MCAST_FILTER_SIZE, data->multi_filter);
708
709 rx_ctl |= 0x10;
710 }
711
712 ax8817x_write_cmd_async(dev, AX_CMD_WRITE_RX_CTL, rx_ctl, 0, 0, NULL);
713}
714
715static int ax8817x_mdio_read(struct net_device *netdev, int phy_id, int loc)
716{
717 struct usbnet *dev = netdev_priv(netdev);
718 u16 res;
719 u8 buf[1];
720
721 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
722 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
723 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
724
725 return res & 0xffff;
726}
727
728static void ax8817x_mdio_write(struct net_device *netdev, int phy_id, int loc, int val)
729{
730 struct usbnet *dev = netdev_priv(netdev);
731 u16 res = val;
732 u8 buf[1];
733
734 ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf);
735 ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG, phy_id, (__u16)loc, 2, (u16 *)&res);
736 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf);
737}
738
739static int ax88172_link_reset(struct usbnet *dev)
740{
741 u16 lpa;
742 u8 mode;
743
744 mode = AX_MEDIUM_TX_ABORT_ALLOW | AX_MEDIUM_FLOW_CONTROL_EN;
745 lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA);
746 if (lpa & LPA_DUPLEX)
747 mode |= AX_MEDIUM_FULL_DUPLEX;
748 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
749
750 return 0;
751}
752
753static void ax8817x_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
754{
755 struct usbnet *dev = netdev_priv(net);
756 u8 opt;
757
758 if (ax8817x_read_cmd(dev, AX_CMD_READ_MONITOR_MODE, 0, 0, 1, &opt) < 0) {
759 wolinfo->supported = 0;
760 wolinfo->wolopts = 0;
761 return;
762 }
763 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
764 wolinfo->wolopts = 0;
765 if (opt & AX_MONITOR_MODE) {
766 if (opt & AX_MONITOR_LINK)
767 wolinfo->wolopts |= WAKE_PHY;
768 if (opt & AX_MONITOR_MAGIC)
769 wolinfo->wolopts |= WAKE_MAGIC;
770 }
771}
772
773static int ax8817x_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo)
774{
775 struct usbnet *dev = netdev_priv(net);
776 u8 opt = 0;
777 u8 buf[1];
778
779 if (wolinfo->wolopts & WAKE_PHY)
780 opt |= AX_MONITOR_LINK;
781 if (wolinfo->wolopts & WAKE_MAGIC)
782 opt |= AX_MONITOR_MAGIC;
783 if (opt != 0)
784 opt |= AX_MONITOR_MODE;
785
786 if (ax8817x_write_cmd(dev, AX_CMD_WRITE_MONITOR_MODE,
787 opt, 0, 0, &buf) < 0)
788 return -EINVAL;
789
790 return 0;
791}
792
793static int ax8817x_get_eeprom_len(struct net_device *net)
794{
795 return AX_EEPROM_LEN;
796}
797
798static int ax8817x_get_eeprom(struct net_device *net,
799 struct ethtool_eeprom *eeprom, u8 *data)
800{
801 struct usbnet *dev = netdev_priv(net);
802 u16 *ebuf = (u16 *)data;
803 int i;
804
805 /* Crude hack to ensure that we don't overwrite memory
806 * if an odd length is supplied
807 */
808 if (eeprom->len % 2)
809 return -EINVAL;
810
811 eeprom->magic = AX_EEPROM_MAGIC;
812
813 /* ax8817x returns 2 bytes from eeprom on read */
814 for (i=0; i < eeprom->len / 2; i++) {
815 if (ax8817x_read_cmd(dev, AX_CMD_READ_EEPROM,
816 eeprom->offset + i, 0, 2, &ebuf[i]) < 0)
817 return -EINVAL;
818 }
819 return 0;
820}
821
822static void ax8817x_get_drvinfo (struct net_device *net,
823 struct ethtool_drvinfo *info)
824{
825 /* Inherit standard device info */
826 usbnet_get_drvinfo(net, info);
827 info->eedump_len = 0x3e;
828}
829
830static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
831{
832 struct usbnet *dev = netdev_priv(net);
833
834 return mii_ethtool_gset(&dev->mii,cmd);
835}
836
837static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
838{
839 struct usbnet *dev = netdev_priv(net);
840
841 return mii_ethtool_sset(&dev->mii,cmd);
842}
843
844/* We need to override some ethtool_ops so we require our
845 own structure so we don't interfere with other usbnet
846 devices that may be connected at the same time. */
847static struct ethtool_ops ax8817x_ethtool_ops = {
848 .get_drvinfo = ax8817x_get_drvinfo,
849 .get_link = ethtool_op_get_link,
850 .get_msglevel = usbnet_get_msglevel,
851 .set_msglevel = usbnet_set_msglevel,
852 .get_wol = ax8817x_get_wol,
853 .set_wol = ax8817x_set_wol,
854 .get_eeprom_len = ax8817x_get_eeprom_len,
855 .get_eeprom = ax8817x_get_eeprom,
856 .get_settings = ax8817x_get_settings,
857 .set_settings = ax8817x_set_settings,
858};
859
860static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
861{
862 int ret = 0;
863 void *buf;
864 int i;
865 unsigned long gpio_bits = dev->driver_info->data;
866
867 get_endpoints(dev,intf);
868
869 buf = kmalloc(ETH_ALEN, GFP_KERNEL);
870 if(!buf) {
871 ret = -ENOMEM;
872 goto out1;
873 }
874
875 /* Toggle the GPIOs in a manufacturer/model specific way */
876 for (i = 2; i >= 0; i--) {
877 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
878 (gpio_bits >> (i * 8)) & 0xff, 0, 0,
879 buf)) < 0)
880 goto out2;
881 msleep(5);
882 }
883
884 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x80, 0, 0, buf)) < 0) {
885 dbg("send AX_CMD_WRITE_RX_CTL failed: %d", ret);
886 goto out2;
887 }
888
889 /* Get the MAC address */
890 memset(buf, 0, ETH_ALEN);
891 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_NODE_ID, 0, 0, 6, buf)) < 0) {
892 dbg("read AX_CMD_READ_NODE_ID failed: %d", ret);
893 goto out2;
894 }
895 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
896
897 /* Get the PHY id */
898 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
899 dbg("error on read AX_CMD_READ_PHY_ID: %02x", ret);
900 goto out2;
901 } else if (ret < 2) {
902 /* this should always return 2 bytes */
903 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x", ret);
904 ret = -EIO;
905 goto out2;
906 }
907
908 /* Initialize MII structure */
909 dev->mii.dev = dev->net;
910 dev->mii.mdio_read = ax8817x_mdio_read;
911 dev->mii.mdio_write = ax8817x_mdio_write;
912 dev->mii.phy_id_mask = 0x3f;
913 dev->mii.reg_num_mask = 0x1f;
914 dev->mii.phy_id = *((u8 *)buf + 1);
915
916 dev->net->set_multicast_list = ax8817x_set_multicast;
917 dev->net->ethtool_ops = &ax8817x_ethtool_ops;
918
919 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
920 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
921 ADVERTISE_ALL | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP);
922 mii_nway_restart(&dev->mii);
923
924 return 0;
925out2:
926 kfree(buf);
927out1:
928 return ret;
929}
930
931static struct ethtool_ops ax88772_ethtool_ops = {
932 .get_drvinfo = ax8817x_get_drvinfo,
933 .get_link = ethtool_op_get_link,
934 .get_msglevel = usbnet_get_msglevel,
935 .set_msglevel = usbnet_set_msglevel,
936 .get_wol = ax8817x_get_wol,
937 .set_wol = ax8817x_set_wol,
938 .get_eeprom_len = ax8817x_get_eeprom_len,
939 .get_eeprom = ax8817x_get_eeprom,
940 .get_settings = ax8817x_get_settings,
941 .set_settings = ax8817x_set_settings,
942};
943
944static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
945{
946 int ret;
947 void *buf;
948
949 get_endpoints(dev,intf);
950
951 buf = kmalloc(6, GFP_KERNEL);
952 if(!buf) {
953 dbg ("Cannot allocate memory for buffer");
954 ret = -ENOMEM;
955 goto out1;
956 }
957
958 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
959 0x00B0, 0, 0, buf)) < 0)
960 goto out2;
961
962 msleep(5);
963 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SW_PHY_SELECT, 0x0001, 0, 0, buf)) < 0) {
964 dbg("Select PHY #1 failed: %d", ret);
965 goto out2;
966 }
967
968 if ((ret =
969 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPPD, 0, 0, buf)) < 0) {
970 dbg("Failed to power down internal PHY: %d", ret);
971 goto out2;
972 }
973
974 msleep(150);
975 if ((ret =
976 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_CLEAR, 0, 0, buf)) < 0) {
977 dbg("Failed to perform software reset: %d", ret);
978 goto out2;
979 }
980
981 msleep(150);
982 if ((ret =
983 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
984 dbg("Failed to set Internal/External PHY reset control: %d", ret);
985 goto out2;
986 }
987
988 msleep(150);
989 if ((ret =
990 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0000, 0, 0,
991 buf)) < 0) {
992 dbg("Failed to reset RX_CTL: %d", ret);
993 goto out2;
994 }
995
996 /* Get the MAC address */
997 memset(buf, 0, ETH_ALEN);
998 if ((ret = ax8817x_read_cmd(dev, AX88772_CMD_READ_NODE_ID, 0, 0, ETH_ALEN, buf)) < 0) {
999 dbg("Failed to read MAC address: %d", ret);
1000 goto out2;
1001 }
1002 memcpy(dev->net->dev_addr, buf, ETH_ALEN);
1003
1004 if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, buf)) < 0) {
1005 dbg("Enabling software MII failed: %d", ret);
1006 goto out2;
1007 }
1008
1009 if (((ret =
1010 ax8817x_read_cmd(dev, AX_CMD_READ_MII_REG, 0x0010, 2, 2, buf)) < 0)
1011 || (*((u16 *)buf) != 0x003b)) {
1012 dbg("Read PHY register 2 must be 0x3b00: %d", ret);
1013 goto out2;
1014 }
1015
1016 /* Initialize MII structure */
1017 dev->mii.dev = dev->net;
1018 dev->mii.mdio_read = ax8817x_mdio_read;
1019 dev->mii.mdio_write = ax8817x_mdio_write;
1020 dev->mii.phy_id_mask = 0xff;
1021 dev->mii.reg_num_mask = 0xff;
1022
1023 /* Get the PHY id */
1024 if ((ret = ax8817x_read_cmd(dev, AX_CMD_READ_PHY_ID, 0, 0, 2, buf)) < 0) {
1025 dbg("Error reading PHY ID: %02x", ret);
1026 goto out2;
1027 } else if (ret < 2) {
1028 /* this should always return 2 bytes */
1029 dbg("AX_CMD_READ_PHY_ID returned less than 2 bytes: ret=%02x",
1030 ret);
1031 ret = -EIO;
1032 goto out2;
1033 }
1034 dev->mii.phy_id = *((u8 *)buf + 1);
1035
1036 if ((ret =
1037 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_PRL, 0, 0, buf)) < 0) {
1038 dbg("Set external PHY reset pin level: %d", ret);
1039 goto out2;
1040 }
1041 msleep(150);
1042 if ((ret =
1043 ax8817x_write_cmd(dev, AX_CMD_SW_RESET, AX_SWRESET_IPRL | AX_SWRESET_PRL, 0, 0, buf)) < 0) {
1044 dbg("Set Internal/External PHY reset control: %d", ret);
1045 goto out2;
1046 }
1047 msleep(150);
1048
1049
1050 dev->net->set_multicast_list = ax8817x_set_multicast;
1051 dev->net->ethtool_ops = &ax88772_ethtool_ops;
1052
1053 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR, BMCR_RESET);
1054 ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
1055 ADVERTISE_ALL | ADVERTISE_CSMA);
1056 mii_nway_restart(&dev->mii);
1057
1058 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, AX88772_MEDIUM_DEFAULT, 0, 0, buf)) < 0) {
1059 dbg("Write medium mode register: %d", ret);
1060 goto out2;
1061 }
1062
1063 if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_IPG0, AX88772_IPG0_DEFAULT | AX88772_IPG1_DEFAULT,AX88772_IPG2_DEFAULT, 0, buf)) < 0) {
1064 dbg("Write IPG,IPG1,IPG2 failed: %d", ret);
1065 goto out2;
1066 }
1067 if ((ret =
1068 ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
1069 dbg("Failed to set hardware MII: %02x", ret);
1070 goto out2;
1071 }
1072
1073 /* Set RX_CTL to default values with 2k buffer, and enable cactus */
1074 if ((ret =
1075 ax8817x_write_cmd(dev, AX_CMD_WRITE_RX_CTL, 0x0088, 0, 0,
1076 buf)) < 0) {
1077 dbg("Reset RX_CTL failed: %d", ret);
1078 goto out2;
1079 }
1080
1081 kfree(buf);
1082
1083 return 0;
1084
1085out2:
1086 kfree(buf);
1087out1:
1088 return ret;
1089}
1090
1091static int ax88772_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1092{
1093 u32 *header;
1094 char *packet;
1095 struct sk_buff *ax_skb;
1096 u16 size;
1097
1098 header = (u32 *) skb->data;
1099 le32_to_cpus(header);
1100 packet = (char *)(header + 1);
1101
1102 skb_pull(skb, 4);
1103
1104 while (skb->len > 0) {
1105 if ((short)(*header & 0x0000ffff) !=
1106 ~((short)((*header & 0xffff0000) >> 16))) {
1107 devdbg(dev,"header length data is error");
1108 }
1109 /* get the packet length */
1110 size = (u16) (*header & 0x0000ffff);
1111
1112 if ((skb->len) - ((size + 1) & 0xfffe) == 0)
1113 return 2;
1114 if (size > ETH_FRAME_LEN) {
1115 devdbg(dev,"invalid rx length %d", size);
1116 return 0;
1117 }
1118 ax_skb = skb_clone(skb, GFP_ATOMIC);
1119 if (ax_skb) {
1120 ax_skb->len = size;
1121 ax_skb->data = packet;
1122 ax_skb->tail = packet + size;
1123 skb_return(dev, ax_skb);
1124 } else {
1125 return 0;
1126 }
1127
1128 skb_pull(skb, (size + 1) & 0xfffe);
1129
1130 if (skb->len == 0)
1131 break;
1132
1133 header = (u32 *) skb->data;
1134 le32_to_cpus(header);
1135 packet = (char *)(header + 1);
1136 skb_pull(skb, 4);
1137 }
1138
1139 if (skb->len < 0) {
1140 devdbg(dev,"invalid rx length %d", skb->len);
1141 return 0;
1142 }
1143 return 1;
1144}
1145
1146static struct sk_buff *ax88772_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
1147 int flags)
1148{
1149 int padlen;
1150 int headroom = skb_headroom(skb);
1151 int tailroom = skb_tailroom(skb);
1152 u32 *packet_len;
1153 u32 *padbytes_ptr;
1154
1155 padlen = ((skb->len + 4) % 512) ? 0 : 4;
1156
1157 if ((!skb_cloned(skb))
1158 && ((headroom + tailroom) >= (4 + padlen))) {
1159 if ((headroom < 4) || (tailroom < padlen)) {
1160 skb->data = memmove(skb->head + 4, skb->data, skb->len);
1161 skb->tail = skb->data + skb->len;
1162 }
1163 } else {
1164 struct sk_buff *skb2;
1165 skb2 = skb_copy_expand(skb, 4, padlen, flags);
1166 dev_kfree_skb_any(skb);
1167 skb = skb2;
1168 if (!skb)
1169 return NULL;
1170 }
1171
1172 packet_len = (u32 *) skb_push(skb, 4);
1173
1174 packet_len = (u32 *) skb->data;
1175 *packet_len = (((skb->len - 4) ^ 0x0000ffff) << 16) + (skb->len - 4);
1176
1177 if ((skb->len % 512) == 0) {
1178 padbytes_ptr = (u32 *) skb->tail;
1179 *padbytes_ptr = 0xffff0000;
1180 skb_put(skb, padlen);
1181 }
1182 return skb;
1183}
1184
1185static int ax88772_link_reset(struct usbnet *dev)
1186{
1187 u16 lpa;
1188 u16 mode;
1189
1190 mode = AX88772_MEDIUM_DEFAULT;
1191 lpa = ax8817x_mdio_read(dev->net, dev->mii.phy_id, MII_LPA);
1192
1193 if ((lpa & LPA_DUPLEX) == 0)
1194 mode &= ~AX88772_MEDIUM_FULL_DUPLEX;
1195 if ((lpa & LPA_100) == 0)
1196 mode &= ~AX88772_MEDIUM_100MB;
1197 ax8817x_write_cmd(dev, AX_CMD_WRITE_MEDIUM_MODE, mode, 0, 0, NULL);
1198
1199 return 0;
1200}
1201
1202static const struct driver_info ax8817x_info = {
1203 .description = "ASIX AX8817x USB 2.0 Ethernet",
1204 .bind = ax8817x_bind,
1205 .status = ax8817x_status,
1206 .link_reset = ax88172_link_reset,
1207 .reset = ax88172_link_reset,
1208 .flags = FLAG_ETHER,
1209 .data = 0x00130103,
1210};
1211
1212static const struct driver_info dlink_dub_e100_info = {
1213 .description = "DLink DUB-E100 USB Ethernet",
1214 .bind = ax8817x_bind,
1215 .status = ax8817x_status,
1216 .link_reset = ax88172_link_reset,
1217 .reset = ax88172_link_reset,
1218 .flags = FLAG_ETHER,
1219 .data = 0x009f9d9f,
1220};
1221
1222static const struct driver_info netgear_fa120_info = {
1223 .description = "Netgear FA-120 USB Ethernet",
1224 .bind = ax8817x_bind,
1225 .status = ax8817x_status,
1226 .link_reset = ax88172_link_reset,
1227 .reset = ax88172_link_reset,
1228 .flags = FLAG_ETHER,
1229 .data = 0x00130103,
1230};
1231
1232static const struct driver_info hawking_uf200_info = {
1233 .description = "Hawking UF200 USB Ethernet",
1234 .bind = ax8817x_bind,
1235 .status = ax8817x_status,
1236 .link_reset = ax88172_link_reset,
1237 .reset = ax88172_link_reset,
1238 .flags = FLAG_ETHER,
1239 .data = 0x001f1d1f,
1240};
1241
1242static const struct driver_info ax88772_info = {
1243 .description = "ASIX AX88772 USB 2.0 Ethernet",
1244 .bind = ax88772_bind,
1245 .status = ax8817x_status,
1246 .link_reset = ax88772_link_reset,
1247 .reset = ax88772_link_reset,
1248 .flags = FLAG_ETHER | FLAG_FRAMING_AX,
1249 .rx_fixup = ax88772_rx_fixup,
1250 .tx_fixup = ax88772_tx_fixup,
1251 .data = 0x00130103,
1252};
1253
1254#endif /* CONFIG_USB_AX8817X */
1255
1256
1257
1258#ifdef CONFIG_USB_BELKIN
1259#define HAVE_HARDWARE
1260
1261/*-------------------------------------------------------------------------
1262 *
1263 * Belkin F5U104 ... two NetChip 2280 devices + Atmel microcontroller
1264 *
1265 * ... also two eTEK designs, including one sold as "Advance USBNET"
1266 *
1267 *-------------------------------------------------------------------------*/
1268
1269static const struct driver_info belkin_info = {
1270 .description = "Belkin, eTEK, or compatible",
1271};
1272
1273#endif /* CONFIG_USB_BELKIN */
1274
1275
1276
1277/*-------------------------------------------------------------------------
1278 *
1279 * Communications Device Class declarations.
1280 * Used by CDC Ethernet, and some CDC variants
1281 *
1282 *-------------------------------------------------------------------------*/
1283
1284#ifdef CONFIG_USB_CDCETHER
1285#define NEED_GENERIC_CDC
1286#endif
1287
1288#ifdef CONFIG_USB_ZAURUS
1289/* Ethernet variant uses funky framing, broken ethernet addressing */
1290#define NEED_GENERIC_CDC
1291#endif
1292
1293#ifdef CONFIG_USB_RNDIS
1294/* ACM variant uses even funkier framing, complex control RPC scheme */
1295#define NEED_GENERIC_CDC
1296#endif
1297
1298
1299#ifdef NEED_GENERIC_CDC
1300
1301#include <linux/usb_cdc.h>
1302
1303struct cdc_state {
1304 struct usb_cdc_header_desc *header;
1305 struct usb_cdc_union_desc *u;
1306 struct usb_cdc_ether_desc *ether;
1307 struct usb_interface *control;
1308 struct usb_interface *data;
1309};
1310
1311static struct usb_driver usbnet_driver;
1312
1313/*
1314 * probes control interface, claims data interface, collects the bulk
1315 * endpoints, activates data interface (if needed), maybe sets MTU.
1316 * all pure cdc, except for certain firmware workarounds.
1317 */
1318static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1319{
1320 u8 *buf = intf->cur_altsetting->extra;
1321 int len = intf->cur_altsetting->extralen;
1322 struct usb_interface_descriptor *d;
1323 struct cdc_state *info = (void *) &dev->data;
1324 int status;
1325 int rndis;
1326
1327 if (sizeof dev->data < sizeof *info)
1328 return -EDOM;
1329
1330 /* expect strict spec conformance for the descriptors, but
1331 * cope with firmware which stores them in the wrong place
1332 */
1333 if (len == 0 && dev->udev->actconfig->extralen) {
1334 /* Motorola SB4100 (and others: Brad Hards says it's
1335 * from a Broadcom design) put CDC descriptors here
1336 */
1337 buf = dev->udev->actconfig->extra;
1338 len = dev->udev->actconfig->extralen;
1339 if (len)
1340 dev_dbg (&intf->dev,
1341 "CDC descriptors on config\n");
1342 }
1343
1344 /* this assumes that if there's a non-RNDIS vendor variant
1345 * of cdc-acm, it'll fail RNDIS requests cleanly.
1346 */
1347 rndis = (intf->cur_altsetting->desc.bInterfaceProtocol == 0xff);
1348
1349 memset (info, 0, sizeof *info);
1350 info->control = intf;
1351 while (len > 3) {
1352 if (buf [1] != USB_DT_CS_INTERFACE)
1353 goto next_desc;
1354
1355 /* use bDescriptorSubType to identify the CDC descriptors.
1356 * We expect devices with CDC header and union descriptors.
1357 * For CDC Ethernet we need the ethernet descriptor.
1358 * For RNDIS, ignore two (pointless) CDC modem descriptors
1359 * in favor of a complicated OID-based RPC scheme doing what
1360 * CDC Ethernet achieves with a simple descriptor.
1361 */
1362 switch (buf [2]) {
1363 case USB_CDC_HEADER_TYPE:
1364 if (info->header) {
1365 dev_dbg (&intf->dev, "extra CDC header\n");
1366 goto bad_desc;
1367 }
1368 info->header = (void *) buf;
1369 if (info->header->bLength != sizeof *info->header) {
1370 dev_dbg (&intf->dev, "CDC header len %u\n",
1371 info->header->bLength);
1372 goto bad_desc;
1373 }
1374 break;
1375 case USB_CDC_UNION_TYPE:
1376 if (info->u) {
1377 dev_dbg (&intf->dev, "extra CDC union\n");
1378 goto bad_desc;
1379 }
1380 info->u = (void *) buf;
1381 if (info->u->bLength != sizeof *info->u) {
1382 dev_dbg (&intf->dev, "CDC union len %u\n",
1383 info->u->bLength);
1384 goto bad_desc;
1385 }
1386
1387 /* we need a master/control interface (what we're
1388 * probed with) and a slave/data interface; union
1389 * descriptors sort this all out.
1390 */
1391 info->control = usb_ifnum_to_if(dev->udev,
1392 info->u->bMasterInterface0);
1393 info->data = usb_ifnum_to_if(dev->udev,
1394 info->u->bSlaveInterface0);
1395 if (!info->control || !info->data) {
1396 dev_dbg (&intf->dev,
1397 "master #%u/%p slave #%u/%p\n",
1398 info->u->bMasterInterface0,
1399 info->control,
1400 info->u->bSlaveInterface0,
1401 info->data);
1402 goto bad_desc;
1403 }
1404 if (info->control != intf) {
1405 dev_dbg (&intf->dev, "bogus CDC Union\n");
1406 /* Ambit USB Cable Modem (and maybe others)
1407 * interchanges master and slave interface.
1408 */
1409 if (info->data == intf) {
1410 info->data = info->control;
1411 info->control = intf;
1412 } else
1413 goto bad_desc;
1414 }
1415
1416 /* a data interface altsetting does the real i/o */
1417 d = &info->data->cur_altsetting->desc;
1418 if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
1419 dev_dbg (&intf->dev, "slave class %u\n",
1420 d->bInterfaceClass);
1421 goto bad_desc;
1422 }
1423 break;
1424 case USB_CDC_ETHERNET_TYPE:
1425 if (info->ether) {
1426 dev_dbg (&intf->dev, "extra CDC ether\n");
1427 goto bad_desc;
1428 }
1429 info->ether = (void *) buf;
1430 if (info->ether->bLength != sizeof *info->ether) {
1431 dev_dbg (&intf->dev, "CDC ether len %u\n",
1432 info->ether->bLength);
1433 goto bad_desc;
1434 }
1435 dev->net->mtu = le16_to_cpup (
1436 &info->ether->wMaxSegmentSize)
1437 - ETH_HLEN;
1438 /* because of Zaurus, we may be ignoring the host
1439 * side link address we were given.
1440 */
1441 break;
1442 }
1443next_desc:
1444 len -= buf [0]; /* bLength */
1445 buf += buf [0];
1446 }
1447
1448 if (!info->header || !info->u || (!rndis && !info->ether)) {
1449 dev_dbg (&intf->dev, "missing cdc %s%s%sdescriptor\n",
1450 info->header ? "" : "header ",
1451 info->u ? "" : "union ",
1452 info->ether ? "" : "ether ");
1453 goto bad_desc;
1454 }
1455
1456 /* claim data interface and set it up ... with side effects.
1457 * network traffic can't flow until an altsetting is enabled.
1458 */
1459 status = usb_driver_claim_interface (&usbnet_driver, info->data, dev);
1460 if (status < 0)
1461 return status;
1462 status = get_endpoints (dev, info->data);
1463 if (status < 0) {
1464 /* ensure immediate exit from usbnet_disconnect */
1465 usb_set_intfdata(info->data, NULL);
1466 usb_driver_release_interface (&usbnet_driver, info->data);
1467 return status;
1468 }
1469
1470 /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
1471 dev->status = NULL;
1472 if (info->control->cur_altsetting->desc.bNumEndpoints == 1) {
1473 struct usb_endpoint_descriptor *desc;
1474
1475 dev->status = &info->control->cur_altsetting->endpoint [0];
1476 desc = &dev->status->desc;
1477 if (desc->bmAttributes != USB_ENDPOINT_XFER_INT
1478 || !(desc->bEndpointAddress & USB_DIR_IN)
1479 || (le16_to_cpu(desc->wMaxPacketSize)
1480 < sizeof (struct usb_cdc_notification))
1481 || !desc->bInterval) {
1482 dev_dbg (&intf->dev, "bad notification endpoint\n");
1483 dev->status = NULL;
1484 }
1485 }
1486 if (rndis && !dev->status) {
1487 dev_dbg (&intf->dev, "missing RNDIS status endpoint\n");
1488 usb_set_intfdata(info->data, NULL);
1489 usb_driver_release_interface (&usbnet_driver, info->data);
1490 return -ENODEV;
1491 }
1492 return 0;
1493
1494bad_desc:
1495 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
1496 return -ENODEV;
1497}
1498
1499static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
1500{
1501 struct cdc_state *info = (void *) &dev->data;
1502
1503 /* disconnect master --> disconnect slave */
1504 if (intf == info->control && info->data) {
1505 /* ensure immediate exit from usbnet_disconnect */
1506 usb_set_intfdata(info->data, NULL);
1507 usb_driver_release_interface (&usbnet_driver, info->data);
1508 info->data = NULL;
1509 }
1510
1511 /* and vice versa (just in case) */
1512 else if (intf == info->data && info->control) {
1513 /* ensure immediate exit from usbnet_disconnect */
1514 usb_set_intfdata(info->control, NULL);
1515 usb_driver_release_interface (&usbnet_driver, info->control);
1516 info->control = NULL;
1517 }
1518}
1519
1520#endif /* NEED_GENERIC_CDC */
1521
1522
1523#ifdef CONFIG_USB_CDCETHER
1524#define HAVE_HARDWARE
1525
1526/*-------------------------------------------------------------------------
1527 *
1528 * Communications Device Class, Ethernet Control model
1529 *
1530 * Takes two interfaces. The DATA interface is inactive till an altsetting
1531 * is selected. Configuration data includes class descriptors.
1532 *
1533 * This should interop with whatever the 2.4 "CDCEther.c" driver
1534 * (by Brad Hards) talked with.
1535 *
1536 *-------------------------------------------------------------------------*/
1537
1538#include <linux/ctype.h>
1539
1540
1541static void dumpspeed (struct usbnet *dev, __le32 *speeds)
1542{
1543 if (netif_msg_timer (dev))
1544 devinfo (dev, "link speeds: %u kbps up, %u kbps down",
1545 __le32_to_cpu(speeds[0]) / 1000,
1546 __le32_to_cpu(speeds[1]) / 1000);
1547}
1548
1549static void cdc_status (struct usbnet *dev, struct urb *urb)
1550{
1551 struct usb_cdc_notification *event;
1552
1553 if (urb->actual_length < sizeof *event)
1554 return;
1555
1556 /* SPEED_CHANGE can get split into two 8-byte packets */
1557 if (test_and_clear_bit (EVENT_STS_SPLIT, &dev->flags)) {
1558 dumpspeed (dev, (__le32 *) urb->transfer_buffer);
1559 return;
1560 }
1561
1562 event = urb->transfer_buffer;
1563 switch (event->bNotificationType) {
1564 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
1565 if (netif_msg_timer (dev))
1566 devdbg (dev, "CDC: carrier %s",
1567 event->wValue ? "on" : "off");
1568 if (event->wValue)
1569 netif_carrier_on(dev->net);
1570 else
1571 netif_carrier_off(dev->net);
1572 break;
1573 case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */
1574 if (netif_msg_timer (dev))
1575 devdbg (dev, "CDC: speed change (len %d)",
1576 urb->actual_length);
1577 if (urb->actual_length != (sizeof *event + 8))
1578 set_bit (EVENT_STS_SPLIT, &dev->flags);
1579 else
1580 dumpspeed (dev, (__le32 *) &event[1]);
1581 break;
1582 // case USB_CDC_NOTIFY_RESPONSE_AVAILABLE: /* RNDIS; or unsolicited */
1583 default:
1584 deverr (dev, "CDC: unexpected notification %02x!",
1585 event->bNotificationType);
1586 break;
1587 }
1588}
1589
1590static u8 nibble (unsigned char c)
1591{
1592 if (likely (isdigit (c)))
1593 return c - '0';
1594 c = toupper (c);
1595 if (likely (isxdigit (c)))
1596 return 10 + c - 'A';
1597 return 0;
1598}
1599
1600static inline int
1601get_ethernet_addr (struct usbnet *dev, struct usb_cdc_ether_desc *e)
1602{
1603 int tmp, i;
1604 unsigned char buf [13];
1605
1606 tmp = usb_string (dev->udev, e->iMACAddress, buf, sizeof buf);
1607 if (tmp != 12) {
1608 dev_dbg (&dev->udev->dev,
1609 "bad MAC string %d fetch, %d\n", e->iMACAddress, tmp);
1610 if (tmp >= 0)
1611 tmp = -EINVAL;
1612 return tmp;
1613 }
1614 for (i = tmp = 0; i < 6; i++, tmp += 2)
1615 dev->net->dev_addr [i] =
1616 (nibble (buf [tmp]) << 4) + nibble (buf [tmp + 1]);
1617 return 0;
1618}
1619
1620static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
1621{
1622 int status;
1623 struct cdc_state *info = (void *) &dev->data;
1624
1625 status = generic_cdc_bind (dev, intf);
1626 if (status < 0)
1627 return status;
1628
1629 status = get_ethernet_addr (dev, info->ether);
1630 if (status < 0) {
1631 usb_set_intfdata(info->data, NULL);
1632 usb_driver_release_interface (&usbnet_driver, info->data);
1633 return status;
1634 }
1635
1636 /* FIXME cdc-ether has some multicast code too, though it complains
1637 * in routine cases. info->ether describes the multicast support.
1638 */
1639 return 0;
1640}
1641
1642static const struct driver_info cdc_info = {
1643 .description = "CDC Ethernet Device",
1644 .flags = FLAG_ETHER,
1645 // .check_connect = cdc_check_connect,
1646 .bind = cdc_bind,
1647 .unbind = cdc_unbind,
1648 .status = cdc_status,
1649};
1650
1651#endif /* CONFIG_USB_CDCETHER */
1652
1653
1654
1655#ifdef CONFIG_USB_EPSON2888
1656#define HAVE_HARDWARE
1657
1658/*-------------------------------------------------------------------------
1659 *
1660 * EPSON USB clients
1661 *
1662 * This is the same idea as Linux PDAs (below) except the firmware in the
1663 * device might not be Tux-powered. Epson provides reference firmware that
1664 * implements this interface. Product developers can reuse or modify that
1665 * code, such as by using their own product and vendor codes.
1666 *
1667 * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
1668 *
1669 *-------------------------------------------------------------------------*/
1670
1671static const struct driver_info epson2888_info = {
1672 .description = "Epson USB Device",
1673 .check_connect = always_connected,
1674
1675 .in = 4, .out = 3,
1676};
1677
1678#endif /* CONFIG_USB_EPSON2888 */
1679
1680
1681#ifdef CONFIG_USB_GENESYS
1682#define HAVE_HARDWARE
1683
1684/*-------------------------------------------------------------------------
1685 *
1686 * GeneSys GL620USB-A (www.genesyslogic.com.tw)
1687 *
1688 * ... should partially interop with the Win32 driver for this hardware
1689 * The GeneSys docs imply there's some NDIS issue motivating this framing.
1690 *
1691 * Some info from GeneSys:
1692 * - GL620USB-A is full duplex; GL620USB is only half duplex for bulk.
1693 * (Some cables, like the BAFO-100c, use the half duplex version.)
1694 * - For the full duplex model, the low bit of the version code says
1695 * which side is which ("left/right").
1696 * - For the half duplex type, a control/interrupt handshake settles
1697 * the transfer direction. (That's disabled here, partially coded.)
1698 * A control URB would block until other side writes an interrupt.
1699 *
1700 * Original code from Jiun-Jie Huang <huangjj@genesyslogic.com.tw>
1701 * and merged into "usbnet" by Stanislav Brabec <utx@penguin.cz>.
1702 *
1703 *-------------------------------------------------------------------------*/
1704
1705// control msg write command
1706#define GENELINK_CONNECT_WRITE 0xF0
1707// interrupt pipe index
1708#define GENELINK_INTERRUPT_PIPE 0x03
1709// interrupt read buffer size
1710#define INTERRUPT_BUFSIZE 0x08
1711// interrupt pipe interval value
1712#define GENELINK_INTERRUPT_INTERVAL 0x10
1713// max transmit packet number per transmit
1714#define GL_MAX_TRANSMIT_PACKETS 32
1715// max packet length
1716#define GL_MAX_PACKET_LEN 1514
1717// max receive buffer size
1718#define GL_RCV_BUF_SIZE \
1719 (((GL_MAX_PACKET_LEN + 4) * GL_MAX_TRANSMIT_PACKETS) + 4)
1720
1721struct gl_packet {
1722 u32 packet_length;
1723 char packet_data [1];
1724};
1725
1726struct gl_header {
1727 u32 packet_count;
1728 struct gl_packet packets;
1729};
1730
1731#ifdef GENELINK_ACK
1732
1733// FIXME: this code is incomplete, not debugged; it doesn't
1734// handle interrupts correctly. interrupts should be generic
1735// code like all other device I/O, anyway.
1736
1737struct gl_priv {
1738 struct urb *irq_urb;
1739 char irq_buf [INTERRUPT_BUFSIZE];
1740};
1741
1742static inline int gl_control_write (struct usbnet *dev, u8 request, u16 value)
1743{
1744 int retval;
1745
1746 retval = usb_control_msg (dev->udev,
1747 usb_sndctrlpipe (dev->udev, 0),
1748 request,
1749 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1750 value,
1751 0, // index
1752 0, // data buffer
1753 0, // size
1754 CONTROL_TIMEOUT_MS);
1755 return retval;
1756}
1757
1758static void gl_interrupt_complete (struct urb *urb, struct pt_regs *regs)
1759{
1760 int status = urb->status;
1761
1762 switch (status) {
1763 case 0:
1764 /* success */
1765 break;
1766 case -ECONNRESET:
1767 case -ENOENT:
1768 case -ESHUTDOWN:
1769 /* this urb is terminated, clean up */
1770 dbg("%s - urb shutting down with status: %d",
1771 __FUNCTION__, status);
1772 return;
1773 default:
1774 dbg("%s - nonzero urb status received: %d",
1775 __FUNCTION__, urb->status);
1776 }
1777
1778 status = usb_submit_urb (urb, GFP_ATOMIC);
1779 if (status)
1780 err ("%s - usb_submit_urb failed with result %d",
1781 __FUNCTION__, status);
1782}
1783
1784static int gl_interrupt_read (struct usbnet *dev)
1785{
1786 struct gl_priv *priv = dev->priv_data;
1787 int retval;
1788
1789 // issue usb interrupt read
1790 if (priv && priv->irq_urb) {
1791 // submit urb
1792 if ((retval = usb_submit_urb (priv->irq_urb, GFP_KERNEL)) != 0)
1793 dbg ("gl_interrupt_read: submit fail - %X...", retval);
1794 else
1795 dbg ("gl_interrupt_read: submit success...");
1796 }
1797
1798 return 0;
1799}
1800
1801// check whether another side is connected
1802static int genelink_check_connect (struct usbnet *dev)
1803{
1804 int retval;
1805
1806 dbg ("genelink_check_connect...");
1807
1808 // detect whether another side is connected
1809 if ((retval = gl_control_write (dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
1810 dbg ("%s: genelink_check_connect write fail - %X",
1811 dev->net->name, retval);
1812 return retval;
1813 }
1814
1815 // usb interrupt read to ack another side
1816 if ((retval = gl_interrupt_read (dev)) != 0) {
1817 dbg ("%s: genelink_check_connect read fail - %X",
1818 dev->net->name, retval);
1819 return retval;
1820 }
1821
1822 dbg ("%s: genelink_check_connect read success", dev->net->name);
1823 return 0;
1824}
1825
1826// allocate and initialize the private data for genelink
1827static int genelink_init (struct usbnet *dev)
1828{
1829 struct gl_priv *priv;
1830
1831 // allocate the private data structure
1832 if ((priv = kmalloc (sizeof *priv, GFP_KERNEL)) == 0) {
1833 dbg ("%s: cannot allocate private data per device",
1834 dev->net->name);
1835 return -ENOMEM;
1836 }
1837
1838 // allocate irq urb
1839 if ((priv->irq_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
1840 dbg ("%s: cannot allocate private irq urb per device",
1841 dev->net->name);
1842 kfree (priv);
1843 return -ENOMEM;
1844 }
1845
1846 // fill irq urb
1847 usb_fill_int_urb (priv->irq_urb, dev->udev,
1848 usb_rcvintpipe (dev->udev, GENELINK_INTERRUPT_PIPE),
1849 priv->irq_buf, INTERRUPT_BUFSIZE,
1850 gl_interrupt_complete, 0,
1851 GENELINK_INTERRUPT_INTERVAL);
1852
1853 // set private data pointer
1854 dev->priv_data = priv;
1855
1856 return 0;
1857}
1858
1859// release the private data
1860static int genelink_free (struct usbnet *dev)
1861{
1862 struct gl_priv *priv = dev->priv_data;
1863
1864 if (!priv)
1865 return 0;
1866
1867// FIXME: can't cancel here; it's synchronous, and
1868// should have happened earlier in any case (interrupt
1869// handling needs to be generic)
1870
1871 // cancel irq urb first
1872 usb_kill_urb (priv->irq_urb);
1873
1874 // free irq urb
1875 usb_free_urb (priv->irq_urb);
1876
1877 // free the private data structure
1878 kfree (priv);
1879
1880 return 0;
1881}
1882
1883#endif
1884
1885static int genelink_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
1886{
1887 struct gl_header *header;
1888 struct gl_packet *packet;
1889 struct sk_buff *gl_skb;
1890 u32 size;
1891
1892 header = (struct gl_header *) skb->data;
1893
1894 // get the packet count of the received skb
1895 le32_to_cpus (&header->packet_count);
1896 if ((header->packet_count > GL_MAX_TRANSMIT_PACKETS)
1897 || (header->packet_count < 0)) {
1898 dbg ("genelink: invalid received packet count %d",
1899 header->packet_count);
1900 return 0;
1901 }
1902
1903 // set the current packet pointer to the first packet
1904 packet = &header->packets;
1905
1906 // decrement the length for the packet count size 4 bytes
1907 skb_pull (skb, 4);
1908
1909 while (header->packet_count > 1) {
1910 // get the packet length
1911 size = packet->packet_length;
1912
1913 // this may be a broken packet
1914 if (size > GL_MAX_PACKET_LEN) {
1915 dbg ("genelink: invalid rx length %d", size);
1916 return 0;
1917 }
1918
1919 // allocate the skb for the individual packet
1920 gl_skb = alloc_skb (size, GFP_ATOMIC);
1921 if (gl_skb) {
1922
1923 // copy the packet data to the new skb
1924 memcpy(skb_put(gl_skb, size), packet->packet_data, size);
1925 skb_return (dev, gl_skb);
1926 }
1927
1928 // advance to the next packet
1929 packet = (struct gl_packet *)
1930 &packet->packet_data [size];
1931 header->packet_count--;
1932
1933 // shift the data pointer to the next gl_packet
1934 skb_pull (skb, size + 4);
1935 }
1936
1937 // skip the packet length field 4 bytes
1938 skb_pull (skb, 4);
1939
1940 if (skb->len > GL_MAX_PACKET_LEN) {
1941 dbg ("genelink: invalid rx length %d", skb->len);
1942 return 0;
1943 }
1944 return 1;
1945}
1946
1947static struct sk_buff *
1948genelink_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
1949{
1950 int padlen;
1951 int length = skb->len;
1952 int headroom = skb_headroom (skb);
1953 int tailroom = skb_tailroom (skb);
1954 u32 *packet_count;
1955 u32 *packet_len;
1956
1957 // FIXME: magic numbers, bleech
1958 padlen = ((skb->len + (4 + 4*1)) % 64) ? 0 : 1;
1959
1960 if ((!skb_cloned (skb))
1961 && ((headroom + tailroom) >= (padlen + (4 + 4*1)))) {
1962 if ((headroom < (4 + 4*1)) || (tailroom < padlen)) {
1963 skb->data = memmove (skb->head + (4 + 4*1),
1964 skb->data, skb->len);
1965 skb->tail = skb->data + skb->len;
1966 }
1967 } else {
1968 struct sk_buff *skb2;
1969 skb2 = skb_copy_expand (skb, (4 + 4*1) , padlen, flags);
1970 dev_kfree_skb_any (skb);
1971 skb = skb2;
1972 if (!skb)
1973 return NULL;
1974 }
1975
1976 // attach the packet count to the header
1977 packet_count = (u32 *) skb_push (skb, (4 + 4*1));
1978 packet_len = packet_count + 1;
1979
1980 // FIXME little endian?
1981 *packet_count = 1;
1982 *packet_len = length;
1983
1984 // add padding byte
1985 if ((skb->len % dev->maxpacket) == 0)
1986 skb_put (skb, 1);
1987
1988 return skb;
1989}
1990
1991static const struct driver_info genelink_info = {
1992 .description = "Genesys GeneLink",
1993 .flags = FLAG_FRAMING_GL | FLAG_NO_SETINT,
1994 .rx_fixup = genelink_rx_fixup,
1995 .tx_fixup = genelink_tx_fixup,
1996
1997 .in = 1, .out = 2,
1998
1999#ifdef GENELINK_ACK
2000 .check_connect =genelink_check_connect,
2001#endif
2002};
2003
2004#endif /* CONFIG_USB_GENESYS */
2005
2006
2007
2008#ifdef CONFIG_USB_NET1080
2009#define HAVE_HARDWARE
2010
2011/*-------------------------------------------------------------------------
2012 *
2013 * Netchip 1080 driver ... http://www.netchip.com
2014 * Used in LapLink cables
2015 *
2016 *-------------------------------------------------------------------------*/
2017
2018#define dev_packet_id data[0]
2019#define frame_errors data[1]
2020
2021/*
2022 * NetChip framing of ethernet packets, supporting additional error
2023 * checks for links that may drop bulk packets from inside messages.
2024 * Odd USB length == always short read for last usb packet.
2025 * - nc_header
2026 * - Ethernet header (14 bytes)
2027 * - payload
2028 * - (optional padding byte, if needed so length becomes odd)
2029 * - nc_trailer
2030 *
2031 * This framing is to be avoided for non-NetChip devices.
2032 */
2033
2034struct nc_header { // packed:
2035 __le16 hdr_len; // sizeof nc_header (LE, all)
2036 __le16 packet_len; // payload size (including ethhdr)
2037 __le16 packet_id; // detects dropped packets
2038#define MIN_HEADER 6
2039
2040 // all else is optional, and must start with:
2041 // u16 vendorId; // from usb-if
2042 // u16 productId;
2043} __attribute__((__packed__));
2044
2045#define PAD_BYTE ((unsigned char)0xAC)
2046
2047struct nc_trailer {
2048 __le16 packet_id;
2049} __attribute__((__packed__));
2050
2051// packets may use FLAG_FRAMING_NC and optional pad
2052#define FRAMED_SIZE(mtu) (sizeof (struct nc_header) \
2053 + sizeof (struct ethhdr) \
2054 + (mtu) \
2055 + 1 \
2056 + sizeof (struct nc_trailer))
2057
2058#define MIN_FRAMED FRAMED_SIZE(0)
2059
2060
2061/*
2062 * Zero means no timeout; else, how long a 64 byte bulk packet may be queued
2063 * before the hardware drops it. If that's done, the driver will need to
2064 * frame network packets to guard against the dropped USB packets. The win32
2065 * driver sets this for both sides of the link.
2066 */
2067#define NC_READ_TTL_MS ((u8)255) // ms
2068
2069/*
2070 * We ignore most registers and EEPROM contents.
2071 */
2072#define REG_USBCTL ((u8)0x04)
2073#define REG_TTL ((u8)0x10)
2074#define REG_STATUS ((u8)0x11)
2075
2076/*
2077 * Vendor specific requests to read/write data
2078 */
2079#define REQUEST_REGISTER ((u8)0x10)
2080#define REQUEST_EEPROM ((u8)0x11)
2081
2082static int
2083nc_vendor_read (struct usbnet *dev, u8 req, u8 regnum, u16 *retval_ptr)
2084{
2085 int status = usb_control_msg (dev->udev,
2086 usb_rcvctrlpipe (dev->udev, 0),
2087 req,
2088 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2089 0, regnum,
2090 retval_ptr, sizeof *retval_ptr,
2091 CONTROL_TIMEOUT_MS);
2092 if (status > 0)
2093 status = 0;
2094 if (!status)
2095 le16_to_cpus (retval_ptr);
2096 return status;
2097}
2098
2099static inline int
2100nc_register_read (struct usbnet *dev, u8 regnum, u16 *retval_ptr)
2101{
2102 return nc_vendor_read (dev, REQUEST_REGISTER, regnum, retval_ptr);
2103}
2104
2105// no retval ... can become async, usable in_interrupt()
2106static void
2107nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
2108{
2109 usb_control_msg (dev->udev,
2110 usb_sndctrlpipe (dev->udev, 0),
2111 req,
2112 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2113 value, regnum,
2114 NULL, 0, // data is in setup packet
2115 CONTROL_TIMEOUT_MS);
2116}
2117
2118static inline void
2119nc_register_write (struct usbnet *dev, u8 regnum, u16 value)
2120{
2121 nc_vendor_write (dev, REQUEST_REGISTER, regnum, value);
2122}
2123
2124
2125#if 0
2126static void nc_dump_registers (struct usbnet *dev)
2127{
2128 u8 reg;
2129 u16 *vp = kmalloc (sizeof (u16));
2130
2131 if (!vp) {
2132 dbg ("no memory?");
2133 return;
2134 }
2135
2136 dbg ("%s registers:", dev->net->name);
2137 for (reg = 0; reg < 0x20; reg++) {
2138 int retval;
2139
2140 // reading some registers is trouble
2141 if (reg >= 0x08 && reg <= 0xf)
2142 continue;
2143 if (reg >= 0x12 && reg <= 0x1e)
2144 continue;
2145
2146 retval = nc_register_read (dev, reg, vp);
2147 if (retval < 0)
2148 dbg ("%s reg [0x%x] ==> error %d",
2149 dev->net->name, reg, retval);
2150 else
2151 dbg ("%s reg [0x%x] = 0x%x",
2152 dev->net->name, reg, *vp);
2153 }
2154 kfree (vp);
2155}
2156#endif
2157
2158
2159/*-------------------------------------------------------------------------*/
2160
2161/*
2162 * Control register
2163 */
2164
2165#define USBCTL_WRITABLE_MASK 0x1f0f
2166// bits 15-13 reserved, r/o
2167#define USBCTL_ENABLE_LANG (1 << 12)
2168#define USBCTL_ENABLE_MFGR (1 << 11)
2169#define USBCTL_ENABLE_PROD (1 << 10)
2170#define USBCTL_ENABLE_SERIAL (1 << 9)
2171#define USBCTL_ENABLE_DEFAULTS (1 << 8)
2172// bits 7-4 reserved, r/o
2173#define USBCTL_FLUSH_OTHER (1 << 3)
2174#define USBCTL_FLUSH_THIS (1 << 2)
2175#define USBCTL_DISCONN_OTHER (1 << 1)
2176#define USBCTL_DISCONN_THIS (1 << 0)
2177
2178static inline void nc_dump_usbctl (struct usbnet *dev, u16 usbctl)
2179{
2180 if (!netif_msg_link (dev))
2181 return;
2182 devdbg (dev, "net1080 %s-%s usbctl 0x%x:%s%s%s%s%s;"
2183 " this%s%s;"
2184 " other%s%s; r/o 0x%x",
2185 dev->udev->bus->bus_name, dev->udev->devpath,
2186 usbctl,
2187 (usbctl & USBCTL_ENABLE_LANG) ? " lang" : "",
2188 (usbctl & USBCTL_ENABLE_MFGR) ? " mfgr" : "",
2189 (usbctl & USBCTL_ENABLE_PROD) ? " prod" : "",
2190 (usbctl & USBCTL_ENABLE_SERIAL) ? " serial" : "",
2191 (usbctl & USBCTL_ENABLE_DEFAULTS) ? " defaults" : "",
2192
2193 (usbctl & USBCTL_FLUSH_OTHER) ? " FLUSH" : "",
2194 (usbctl & USBCTL_DISCONN_OTHER) ? " DIS" : "",
2195 (usbctl & USBCTL_FLUSH_THIS) ? " FLUSH" : "",
2196 (usbctl & USBCTL_DISCONN_THIS) ? " DIS" : "",
2197 usbctl & ~USBCTL_WRITABLE_MASK
2198 );
2199}
2200
2201/*-------------------------------------------------------------------------*/
2202
2203/*
2204 * Status register
2205 */
2206
2207#define STATUS_PORT_A (1 << 15)
2208
2209#define STATUS_CONN_OTHER (1 << 14)
2210#define STATUS_SUSPEND_OTHER (1 << 13)
2211#define STATUS_MAILBOX_OTHER (1 << 12)
2212#define STATUS_PACKETS_OTHER(n) (((n) >> 8) && 0x03)
2213
2214#define STATUS_CONN_THIS (1 << 6)
2215#define STATUS_SUSPEND_THIS (1 << 5)
2216#define STATUS_MAILBOX_THIS (1 << 4)
2217#define STATUS_PACKETS_THIS(n) (((n) >> 0) && 0x03)
2218
2219#define STATUS_UNSPEC_MASK 0x0c8c
2220#define STATUS_NOISE_MASK ((u16)~(0x0303|STATUS_UNSPEC_MASK))
2221
2222
2223static inline void nc_dump_status (struct usbnet *dev, u16 status)
2224{
2225 if (!netif_msg_link (dev))
2226 return;
2227 devdbg (dev, "net1080 %s-%s status 0x%x:"
2228 " this (%c) PKT=%d%s%s%s;"
2229 " other PKT=%d%s%s%s; unspec 0x%x",
2230 dev->udev->bus->bus_name, dev->udev->devpath,
2231 status,
2232
2233 // XXX the packet counts don't seem right
2234 // (1 at reset, not 0); maybe UNSPEC too
2235
2236 (status & STATUS_PORT_A) ? 'A' : 'B',
2237 STATUS_PACKETS_THIS (status),
2238 (status & STATUS_CONN_THIS) ? " CON" : "",
2239 (status & STATUS_SUSPEND_THIS) ? " SUS" : "",
2240 (status & STATUS_MAILBOX_THIS) ? " MBOX" : "",
2241
2242 STATUS_PACKETS_OTHER (status),
2243 (status & STATUS_CONN_OTHER) ? " CON" : "",
2244 (status & STATUS_SUSPEND_OTHER) ? " SUS" : "",
2245 (status & STATUS_MAILBOX_OTHER) ? " MBOX" : "",
2246
2247 status & STATUS_UNSPEC_MASK
2248 );
2249}
2250
2251/*-------------------------------------------------------------------------*/
2252
2253/*
2254 * TTL register
2255 */
2256
2257#define TTL_THIS(ttl) (0x00ff & ttl)
2258#define TTL_OTHER(ttl) (0x00ff & (ttl >> 8))
2259#define MK_TTL(this,other) ((u16)(((other)<<8)|(0x00ff&(this))))
2260
2261static inline void nc_dump_ttl (struct usbnet *dev, u16 ttl)
2262{
2263 if (netif_msg_link (dev))
2264 devdbg (dev, "net1080 %s-%s ttl 0x%x this = %d, other = %d",
2265 dev->udev->bus->bus_name, dev->udev->devpath,
2266 ttl, TTL_THIS (ttl), TTL_OTHER (ttl));
2267}
2268
2269/*-------------------------------------------------------------------------*/
2270
2271static int net1080_reset (struct usbnet *dev)
2272{
2273 u16 usbctl, status, ttl;
2274 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
2275 int retval;
2276
2277 if (!vp)
2278 return -ENOMEM;
2279
2280 // nc_dump_registers (dev);
2281
2282 if ((retval = nc_register_read (dev, REG_STATUS, vp)) < 0) {
2283 dbg ("can't read %s-%s status: %d",
2284 dev->udev->bus->bus_name, dev->udev->devpath, retval);
2285 goto done;
2286 }
2287 status = *vp;
2288 nc_dump_status (dev, status);
2289
2290 if ((retval = nc_register_read (dev, REG_USBCTL, vp)) < 0) {
2291 dbg ("can't read USBCTL, %d", retval);
2292 goto done;
2293 }
2294 usbctl = *vp;
2295 nc_dump_usbctl (dev, usbctl);
2296
2297 nc_register_write (dev, REG_USBCTL,
2298 USBCTL_FLUSH_THIS | USBCTL_FLUSH_OTHER);
2299
2300 if ((retval = nc_register_read (dev, REG_TTL, vp)) < 0) {
2301 dbg ("can't read TTL, %d", retval);
2302 goto done;
2303 }
2304 ttl = *vp;
2305 // nc_dump_ttl (dev, ttl);
2306
2307 nc_register_write (dev, REG_TTL,
2308 MK_TTL (NC_READ_TTL_MS, TTL_OTHER (ttl)) );
2309 dbg ("%s: assigned TTL, %d ms", dev->net->name, NC_READ_TTL_MS);
2310
2311 if (netif_msg_link (dev))
2312 devinfo (dev, "port %c, peer %sconnected",
2313 (status & STATUS_PORT_A) ? 'A' : 'B',
2314 (status & STATUS_CONN_OTHER) ? "" : "dis"
2315 );
2316 retval = 0;
2317
2318done:
2319 kfree (vp);
2320 return retval;
2321}
2322
2323static int net1080_check_connect (struct usbnet *dev)
2324{
2325 int retval;
2326 u16 status;
2327 u16 *vp = kmalloc (sizeof (u16), GFP_KERNEL);
2328
2329 if (!vp)
2330 return -ENOMEM;
2331 retval = nc_register_read (dev, REG_STATUS, vp);
2332 status = *vp;
2333 kfree (vp);
2334 if (retval != 0) {
2335 dbg ("%s net1080_check_conn read - %d", dev->net->name, retval);
2336 return retval;
2337 }
2338 if ((status & STATUS_CONN_OTHER) != STATUS_CONN_OTHER)
2339 return -ENOLINK;
2340 return 0;
2341}
2342
2343static void nc_flush_complete (struct urb *urb, struct pt_regs *regs)
2344{
2345 kfree (urb->context);
2346 usb_free_urb(urb);
2347}
2348
2349static void nc_ensure_sync (struct usbnet *dev)
2350{
2351 dev->frame_errors++;
2352 if (dev->frame_errors > 5) {
2353 struct urb *urb;
2354 struct usb_ctrlrequest *req;
2355 int status;
2356
2357 /* Send a flush */
2358 urb = usb_alloc_urb (0, SLAB_ATOMIC);
2359 if (!urb)
2360 return;
2361
2362 req = kmalloc (sizeof *req, GFP_ATOMIC);
2363 if (!req) {
2364 usb_free_urb (urb);
2365 return;
2366 }
2367
2368 req->bRequestType = USB_DIR_OUT
2369 | USB_TYPE_VENDOR
2370 | USB_RECIP_DEVICE;
2371 req->bRequest = REQUEST_REGISTER;
2372 req->wValue = cpu_to_le16 (USBCTL_FLUSH_THIS
2373 | USBCTL_FLUSH_OTHER);
2374 req->wIndex = cpu_to_le16 (REG_USBCTL);
2375 req->wLength = cpu_to_le16 (0);
2376
2377 /* queue an async control request, we don't need
2378 * to do anything when it finishes except clean up.
2379 */
2380 usb_fill_control_urb (urb, dev->udev,
2381 usb_sndctrlpipe (dev->udev, 0),
2382 (unsigned char *) req,
2383 NULL, 0,
2384 nc_flush_complete, req);
2385 status = usb_submit_urb (urb, GFP_ATOMIC);
2386 if (status) {
2387 kfree (req);
2388 usb_free_urb (urb);
2389 return;
2390 }
2391
2392 if (netif_msg_rx_err (dev))
2393 devdbg (dev, "flush net1080; too many framing errors");
2394 dev->frame_errors = 0;
2395 }
2396}
2397
2398static int net1080_rx_fixup (struct usbnet *dev, struct sk_buff *skb)
2399{
2400 struct nc_header *header;
2401 struct nc_trailer *trailer;
2402 u16 hdr_len, packet_len;
2403
2404 if (!(skb->len & 0x01)
2405 || MIN_FRAMED > skb->len
2406 || skb->len > FRAMED_SIZE (dev->net->mtu)) {
2407 dev->stats.rx_frame_errors++;
2408 dbg ("rx framesize %d range %d..%d mtu %d", skb->len,
2409 (int)MIN_FRAMED, (int)FRAMED_SIZE (dev->net->mtu),
2410 dev->net->mtu);
2411 nc_ensure_sync (dev);
2412 return 0;
2413 }
2414
2415 header = (struct nc_header *) skb->data;
2416 hdr_len = le16_to_cpup (&header->hdr_len);
2417 packet_len = le16_to_cpup (&header->packet_len);
2418 if (FRAMED_SIZE (packet_len) > MAX_PACKET) {
2419 dev->stats.rx_frame_errors++;
2420 dbg ("packet too big, %d", packet_len);
2421 nc_ensure_sync (dev);
2422 return 0;
2423 } else if (hdr_len < MIN_HEADER) {
2424 dev->stats.rx_frame_errors++;
2425 dbg ("header too short, %d", hdr_len);
2426 nc_ensure_sync (dev);
2427 return 0;
2428 } else if (hdr_len > MIN_HEADER) {
2429 // out of band data for us?
2430 dbg ("header OOB, %d bytes", hdr_len - MIN_HEADER);
2431 nc_ensure_sync (dev);
2432 // switch (vendor/product ids) { ... }
2433 }
2434 skb_pull (skb, hdr_len);
2435
2436 trailer = (struct nc_trailer *)
2437 (skb->data + skb->len - sizeof *trailer);
2438 skb_trim (skb, skb->len - sizeof *trailer);
2439
2440 if ((packet_len & 0x01) == 0) {
2441 if (skb->data [packet_len] != PAD_BYTE) {
2442 dev->stats.rx_frame_errors++;
2443 dbg ("bad pad");
2444 return 0;
2445 }
2446 skb_trim (skb, skb->len - 1);
2447 }
2448 if (skb->len != packet_len) {
2449 dev->stats.rx_frame_errors++;
2450 dbg ("bad packet len %d (expected %d)",
2451 skb->len, packet_len);
2452 nc_ensure_sync (dev);
2453 return 0;
2454 }
2455 if (header->packet_id != get_unaligned (&trailer->packet_id)) {
2456 dev->stats.rx_fifo_errors++;
2457 dbg ("(2+ dropped) rx packet_id mismatch 0x%x 0x%x",
2458 le16_to_cpu (header->packet_id),
2459 le16_to_cpu (trailer->packet_id));
2460 return 0;
2461 }
2462#if 0
2463 devdbg (dev, "frame <rx h %d p %d id %d", header->hdr_len,
2464 header->packet_len, header->packet_id);
2465#endif
2466 dev->frame_errors = 0;
2467 return 1;
2468}
2469
2470static struct sk_buff *
2471net1080_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2472{
2473 int padlen;
2474 struct sk_buff *skb2;
2475
2476 padlen = ((skb->len + sizeof (struct nc_header)
2477 + sizeof (struct nc_trailer)) & 0x01) ? 0 : 1;
2478 if (!skb_cloned (skb)) {
2479 int headroom = skb_headroom (skb);
2480 int tailroom = skb_tailroom (skb);
2481
2482 if ((padlen + sizeof (struct nc_trailer)) <= tailroom
2483 && sizeof (struct nc_header) <= headroom)
2484 /* There's enough head and tail room */
2485 return skb;
2486
2487 if ((sizeof (struct nc_header) + padlen
2488 + sizeof (struct nc_trailer)) <
2489 (headroom + tailroom)) {
2490 /* There's enough total room, so just readjust */
2491 skb->data = memmove (skb->head
2492 + sizeof (struct nc_header),
2493 skb->data, skb->len);
2494 skb->tail = skb->data + skb->len;
2495 return skb;
2496 }
2497 }
2498
2499 /* Create a new skb to use with the correct size */
2500 skb2 = skb_copy_expand (skb,
2501 sizeof (struct nc_header),
2502 sizeof (struct nc_trailer) + padlen,
2503 flags);
2504 dev_kfree_skb_any (skb);
2505 return skb2;
2506}
2507
2508static const struct driver_info net1080_info = {
2509 .description = "NetChip TurboCONNECT",
2510 .flags = FLAG_FRAMING_NC,
2511 .reset = net1080_reset,
2512 .check_connect =net1080_check_connect,
2513 .rx_fixup = net1080_rx_fixup,
2514 .tx_fixup = net1080_tx_fixup,
2515};
2516
2517#endif /* CONFIG_USB_NET1080 */
2518
2519
2520
2521#ifdef CONFIG_USB_PL2301
2522#define HAVE_HARDWARE
2523
2524/*-------------------------------------------------------------------------
2525 *
2526 * Prolific PL-2301/PL-2302 driver ... http://www.prolifictech.com
2527 *
2528 * The protocol and handshaking used here should be bug-compatible
2529 * with the Linux 2.2 "plusb" driver, by Deti Fliegl.
2530 *
2531 *-------------------------------------------------------------------------*/
2532
2533/*
2534 * Bits 0-4 can be used for software handshaking; they're set from
2535 * one end, cleared from the other, "read" with the interrupt byte.
2536 */
2537#define PL_S_EN (1<<7) /* (feature only) suspend enable */
2538/* reserved bit -- rx ready (6) ? */
2539#define PL_TX_READY (1<<5) /* (interrupt only) transmit ready */
2540#define PL_RESET_OUT (1<<4) /* reset output pipe */
2541#define PL_RESET_IN (1<<3) /* reset input pipe */
2542#define PL_TX_C (1<<2) /* transmission complete */
2543#define PL_TX_REQ (1<<1) /* transmission received */
2544#define PL_PEER_E (1<<0) /* peer exists */
2545
2546static inline int
2547pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
2548{
2549 return usb_control_msg (dev->udev,
2550 usb_rcvctrlpipe (dev->udev, 0),
2551 req,
2552 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2553 val, index,
2554 NULL, 0,
2555 CONTROL_TIMEOUT_MS);
2556}
2557
2558static inline int
2559pl_clear_QuickLink_features (struct usbnet *dev, int val)
2560{
2561 return pl_vendor_req (dev, 1, (u8) val, 0);
2562}
2563
2564static inline int
2565pl_set_QuickLink_features (struct usbnet *dev, int val)
2566{
2567 return pl_vendor_req (dev, 3, (u8) val, 0);
2568}
2569
2570/*-------------------------------------------------------------------------*/
2571
2572static int pl_reset (struct usbnet *dev)
2573{
2574 /* some units seem to need this reset, others reject it utterly.
2575 * FIXME be more like "naplink" or windows drivers.
2576 */
2577 (void) pl_set_QuickLink_features (dev,
2578 PL_S_EN|PL_RESET_OUT|PL_RESET_IN|PL_PEER_E);
2579 return 0;
2580}
2581
2582static const struct driver_info prolific_info = {
2583 .description = "Prolific PL-2301/PL-2302",
2584 .flags = FLAG_NO_SETINT,
2585 /* some PL-2302 versions seem to fail usb_set_interface() */
2586 .reset = pl_reset,
2587};
2588
2589#endif /* CONFIG_USB_PL2301 */
2590
2591
2592#ifdef CONFIG_USB_KC2190
2593#define HAVE_HARDWARE
2594static const struct driver_info kc2190_info = {
2595 .description = "KC Technology KC-190",
2596};
2597#endif /* CONFIG_USB_KC2190 */
2598
2599
2600#ifdef CONFIG_USB_ARMLINUX
2601#define HAVE_HARDWARE
2602
2603/*-------------------------------------------------------------------------
2604 *
2605 * Intel's SA-1100 chip integrates basic USB support, and is used
2606 * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
2607 * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
2608 * network using minimal USB framing data.
2609 *
2610 * This describes the driver currently in standard ARM Linux kernels.
2611 * The Zaurus uses a different driver (see later).
2612 *
2613 * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
2614 * and different USB endpoint numbering than the SA1100 devices. The
2615 * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
2616 * so we rely on the endpoint descriptors.
2617 *
2618 *-------------------------------------------------------------------------*/
2619
2620static const struct driver_info linuxdev_info = {
2621 .description = "Linux Device",
2622 .check_connect = always_connected,
2623};
2624
2625static const struct driver_info yopy_info = {
2626 .description = "Yopy",
2627 .check_connect = always_connected,
2628};
2629
2630static const struct driver_info blob_info = {
2631 .description = "Boot Loader OBject",
2632 .check_connect = always_connected,
2633};
2634
2635#endif /* CONFIG_USB_ARMLINUX */
2636
2637
2638#ifdef CONFIG_USB_ZAURUS
2639#define HAVE_HARDWARE
2640
2641#include <linux/crc32.h>
2642
2643/*-------------------------------------------------------------------------
2644 *
2645 * Zaurus is also a SA-1110 based PDA, but one using a different driver
2646 * (and framing) for its USB slave/gadget controller than the case above.
2647 *
2648 * For the current version of that driver, the main way that framing is
2649 * nonstandard (also from perspective of the CDC ethernet model!) is a
2650 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
2651 * haven't been fully worked around. Also, all Zaurii use the same
2652 * default Ethernet address.
2653 *
2654 * PXA based models use the same framing, and also can't implement
2655 * set_interface properly.
2656 *
2657 * All known Zaurii lie about their standards conformance. Most lie by
2658 * saying they support CDC Ethernet. Some lie and say they support CDC
2659 * MDLM (as if for access to cell phone modems). Someone, please beat
2660 * on Sharp (and other such vendors) for a while with a cluestick.
2661 *
2662 *-------------------------------------------------------------------------*/
2663
2664static struct sk_buff *
2665zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, int flags)
2666{
2667 int padlen;
2668 struct sk_buff *skb2;
2669
2670 padlen = 2;
2671 if (!skb_cloned (skb)) {
2672 int tailroom = skb_tailroom (skb);
2673 if ((padlen + 4) <= tailroom)
2674 goto done;
2675 }
2676 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
2677 dev_kfree_skb_any (skb);
2678 skb = skb2;
2679 if (skb) {
2680 u32 fcs;
2681done:
2682 fcs = crc32_le (~0, skb->data, skb->len);
2683 fcs = ~fcs;
2684
2685 *skb_put (skb, 1) = fcs & 0xff;
2686 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
2687 *skb_put (skb, 1) = (fcs>>16) & 0xff;
2688 *skb_put (skb, 1) = (fcs>>24) & 0xff;
2689 }
2690 return skb;
2691}
2692
2693static const struct driver_info zaurus_sl5x00_info = {
2694 .description = "Sharp Zaurus SL-5x00",
2695 .flags = FLAG_FRAMING_Z,
2696 .check_connect = always_connected,
2697 .bind = generic_cdc_bind,
2698 .unbind = cdc_unbind,
2699 .tx_fixup = zaurus_tx_fixup,
2700};
2701#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
2702
2703static const struct driver_info zaurus_pxa_info = {
2704 .description = "Sharp Zaurus, PXA-2xx based",
2705 .flags = FLAG_FRAMING_Z,
2706 .check_connect = always_connected,
2707 .bind = generic_cdc_bind,
2708 .unbind = cdc_unbind,
2709 .tx_fixup = zaurus_tx_fixup,
2710};
2711#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
2712
2713static const struct driver_info olympus_mxl_info = {
2714 .description = "Olympus R1000",
2715 .flags = FLAG_FRAMING_Z,
2716 .check_connect = always_connected,
2717 .bind = generic_cdc_bind,
2718 .unbind = cdc_unbind,
2719 .tx_fixup = zaurus_tx_fixup,
2720};
2721#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
2722
2723
2724/* Some more recent products using Lineo/Belcarra code will wrongly claim
2725 * CDC MDLM conformance. They aren't conformant: data endpoints live
2726 * in the control interface, there's no data interface, and it's not used
2727 * to talk to a cell phone radio. But at least we can detect these two
2728 * pseudo-classes, rather than growing this product list with entries for
2729 * each new nonconformant product (sigh).
2730 */
2731static const u8 safe_guid[16] = {
2732 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
2733 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
2734};
2735static const u8 blan_guid[16] = {
2736 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
2737 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
2738};
2739
2740static int blan_mdlm_bind (struct usbnet *dev, struct usb_interface *intf)
2741{
2742 u8 *buf = intf->cur_altsetting->extra;
2743 int len = intf->cur_altsetting->extralen;
2744 struct usb_cdc_mdlm_desc *desc = NULL;
2745 struct usb_cdc_mdlm_detail_desc *detail = NULL;
2746
2747 while (len > 3) {
2748 if (buf [1] != USB_DT_CS_INTERFACE)
2749 goto next_desc;
2750
2751 /* use bDescriptorSubType, and just verify that we get a
2752 * "BLAN" (or "SAFE") descriptor.
2753 */
2754 switch (buf [2]) {
2755 case USB_CDC_MDLM_TYPE:
2756 if (desc) {
2757 dev_dbg (&intf->dev, "extra MDLM\n");
2758 goto bad_desc;
2759 }
2760 desc = (void *) buf;
2761 if (desc->bLength != sizeof *desc) {
2762 dev_dbg (&intf->dev, "MDLM len %u\n",
2763 desc->bLength);
2764 goto bad_desc;
2765 }
2766 /* expect bcdVersion 1.0, ignore */
2767 if (memcmp(&desc->bGUID, blan_guid, 16)
2768 && memcmp(&desc->bGUID, safe_guid, 16) ) {
2769 /* hey, this one might _really_ be MDLM! */
2770 dev_dbg (&intf->dev, "MDLM guid\n");
2771 goto bad_desc;
2772 }
2773 break;
2774 case USB_CDC_MDLM_DETAIL_TYPE:
2775 if (detail) {
2776 dev_dbg (&intf->dev, "extra MDLM detail\n");
2777 goto bad_desc;
2778 }
2779 detail = (void *) buf;
2780 switch (detail->bGuidDescriptorType) {
2781 case 0: /* "SAFE" */
2782 if (detail->bLength != (sizeof *detail + 2))
2783 goto bad_detail;
2784 break;
2785 case 1: /* "BLAN" */
2786 if (detail->bLength != (sizeof *detail + 3))
2787 goto bad_detail;
2788 break;
2789 default:
2790 goto bad_detail;
2791 }
2792
2793 /* assuming we either noticed BLAN already, or will
2794 * find it soon, there are some data bytes here:
2795 * - bmNetworkCapabilities (unused)
2796 * - bmDataCapabilities (bits, see below)
2797 * - bPad (ignored, for PADAFTER -- BLAN-only)
2798 * bits are:
2799 * - 0x01 -- Zaurus framing (add CRC)
2800 * - 0x02 -- PADBEFORE (CRC includes some padding)
2801 * - 0x04 -- PADAFTER (some padding after CRC)
2802 * - 0x08 -- "fermat" packet mangling (for hw bugs)
2803 * the PADBEFORE appears not to matter; we interop
2804 * with devices that use it and those that don't.
2805 */
2806 if ((detail->bDetailData[1] & ~02) != 0x01) {
2807 /* bmDataCapabilites == 0 would be fine too,
2808 * but framing is minidriver-coupled for now.
2809 */
2810bad_detail:
2811 dev_dbg (&intf->dev,
2812 "bad MDLM detail, %d %d %d\n",
2813 detail->bLength,
2814 detail->bDetailData[0],
2815 detail->bDetailData[2]);
2816 goto bad_desc;
2817 }
2818 break;
2819 }
2820next_desc:
2821 len -= buf [0]; /* bLength */
2822 buf += buf [0];
2823 }
2824
2825 if (!desc || !detail) {
2826 dev_dbg (&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
2827 desc ? "" : "func ",
2828 detail ? "" : "detail ");
2829 goto bad_desc;
2830 }
2831
2832 /* There's probably a CDC Ethernet descriptor there, but we can't
2833 * rely on the Ethernet address it provides since not all vendors
2834 * bother to make it unique. Likewise there's no point in tracking
2835 * of the CDC event notifications.
2836 */
2837 return get_endpoints (dev, intf);
2838
2839bad_desc:
2840 dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n");
2841 return -ENODEV;
2842}
2843
2844static const struct driver_info bogus_mdlm_info = {
2845 .description = "pseudo-MDLM (BLAN) device",
2846 .flags = FLAG_FRAMING_Z,
2847 .check_connect = always_connected,
2848 .tx_fixup = zaurus_tx_fixup,
2849 .bind = blan_mdlm_bind,
2850};
2851
2852#else
2853
2854/* blacklist all those devices */
2855#define ZAURUS_STRONGARM_INFO 0
2856#define ZAURUS_PXA_INFO 0
2857#define OLYMPUS_MXL_INFO 0
2858
2859#endif
2860 222
2861 223
2862/*------------------------------------------------------------------------- 224/*-------------------------------------------------------------------------
@@ -2868,22 +230,12 @@ static const struct driver_info bogus_mdlm_info = {
2868static int usbnet_change_mtu (struct net_device *net, int new_mtu) 230static int usbnet_change_mtu (struct net_device *net, int new_mtu)
2869{ 231{
2870 struct usbnet *dev = netdev_priv(net); 232 struct usbnet *dev = netdev_priv(net);
233 int ll_mtu = new_mtu + net->hard_header_len;
2871 234
2872 if (new_mtu <= MIN_PACKET || new_mtu > MAX_PACKET) 235 if (new_mtu <= 0 || ll_mtu > dev->hard_mtu)
2873 return -EINVAL; 236 return -EINVAL;
2874#ifdef CONFIG_USB_NET1080
2875 if (((dev->driver_info->flags) & FLAG_FRAMING_NC)) {
2876 if (FRAMED_SIZE (new_mtu) > MAX_PACKET)
2877 return -EINVAL;
2878 }
2879#endif
2880#ifdef CONFIG_USB_GENESYS
2881 if (((dev->driver_info->flags) & FLAG_FRAMING_GL)
2882 && new_mtu > GL_MAX_PACKET_LEN)
2883 return -EINVAL;
2884#endif
2885 // no second zero-length packet read wanted after mtu-sized packets 237 // no second zero-length packet read wanted after mtu-sized packets
2886 if (((new_mtu + sizeof (struct ethhdr)) % dev->maxpacket) == 0) 238 if ((ll_mtu % dev->maxpacket) == 0)
2887 return -EDOM; 239 return -EDOM;
2888 net->mtu = new_mtu; 240 net->mtu = new_mtu;
2889 return 0; 241 return 0;
@@ -2922,7 +274,7 @@ static void defer_bh(struct usbnet *dev, struct sk_buff *skb, struct sk_buff_hea
2922 * NOTE: annoying asymmetry: if it's active, schedule_work() fails, 274 * NOTE: annoying asymmetry: if it's active, schedule_work() fails,
2923 * but tasklet_schedule() doesn't. hope the failure is rare. 275 * but tasklet_schedule() doesn't. hope the failure is rare.
2924 */ 276 */
2925static void defer_kevent (struct usbnet *dev, int work) 277void usbnet_defer_kevent (struct usbnet *dev, int work)
2926{ 278{
2927 set_bit (work, &dev->flags); 279 set_bit (work, &dev->flags);
2928 if (!schedule_work (&dev->kevent)) 280 if (!schedule_work (&dev->kevent))
@@ -2930,50 +282,24 @@ static void defer_kevent (struct usbnet *dev, int work)
2930 else 282 else
2931 devdbg (dev, "kevent %d scheduled", work); 283 devdbg (dev, "kevent %d scheduled", work);
2932} 284}
285EXPORT_SYMBOL_GPL(usbnet_defer_kevent);
2933 286
2934/*-------------------------------------------------------------------------*/ 287/*-------------------------------------------------------------------------*/
2935 288
2936static void rx_complete (struct urb *urb, struct pt_regs *regs); 289static void rx_complete (struct urb *urb, struct pt_regs *regs);
2937 290
2938static void rx_submit (struct usbnet *dev, struct urb *urb, int flags) 291static void rx_submit (struct usbnet *dev, struct urb *urb, unsigned flags)
2939{ 292{
2940 struct sk_buff *skb; 293 struct sk_buff *skb;
2941 struct skb_data *entry; 294 struct skb_data *entry;
2942 int retval = 0; 295 int retval = 0;
2943 unsigned long lockflags; 296 unsigned long lockflags;
2944 size_t size; 297 size_t size = dev->rx_urb_size;
2945
2946#ifdef CONFIG_USB_NET1080
2947 if (dev->driver_info->flags & FLAG_FRAMING_NC)
2948 size = FRAMED_SIZE (dev->net->mtu);
2949 else
2950#endif
2951#ifdef CONFIG_USB_GENESYS
2952 if (dev->driver_info->flags & FLAG_FRAMING_GL)
2953 size = GL_RCV_BUF_SIZE;
2954 else
2955#endif
2956#ifdef CONFIG_USB_ZAURUS
2957 if (dev->driver_info->flags & FLAG_FRAMING_Z)
2958 size = 6 + (sizeof (struct ethhdr) + dev->net->mtu);
2959 else
2960#endif
2961#ifdef CONFIG_USB_RNDIS
2962 if (dev->driver_info->flags & FLAG_FRAMING_RN)
2963 size = RNDIS_MAX_TRANSFER;
2964 else
2965#endif
2966#ifdef CONFIG_USB_AX8817X
2967 if (dev->driver_info->flags & FLAG_FRAMING_AX)
2968 size = 2048;
2969 else
2970#endif
2971 size = (sizeof (struct ethhdr) + dev->net->mtu);
2972 298
2973 if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) { 299 if ((skb = alloc_skb (size + NET_IP_ALIGN, flags)) == NULL) {
2974 if (netif_msg_rx_err (dev)) 300 if (netif_msg_rx_err (dev))
2975 devdbg (dev, "no rx skb"); 301 devdbg (dev, "no rx skb");
2976 defer_kevent (dev, EVENT_RX_MEMORY); 302 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
2977 usb_free_urb (urb); 303 usb_free_urb (urb);
2978 return; 304 return;
2979 } 305 }
@@ -2987,7 +313,6 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
2987 313
2988 usb_fill_bulk_urb (urb, dev->udev, dev->in, 314 usb_fill_bulk_urb (urb, dev->udev, dev->in,
2989 skb->data, size, rx_complete, skb); 315 skb->data, size, rx_complete, skb);
2990 urb->transfer_flags |= URB_ASYNC_UNLINK;
2991 316
2992 spin_lock_irqsave (&dev->rxq.lock, lockflags); 317 spin_lock_irqsave (&dev->rxq.lock, lockflags);
2993 318
@@ -2996,10 +321,10 @@ static void rx_submit (struct usbnet *dev, struct urb *urb, int flags)
2996 && !test_bit (EVENT_RX_HALT, &dev->flags)) { 321 && !test_bit (EVENT_RX_HALT, &dev->flags)) {
2997 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){ 322 switch (retval = usb_submit_urb (urb, GFP_ATOMIC)){
2998 case -EPIPE: 323 case -EPIPE:
2999 defer_kevent (dev, EVENT_RX_HALT); 324 usbnet_defer_kevent (dev, EVENT_RX_HALT);
3000 break; 325 break;
3001 case -ENOMEM: 326 case -ENOMEM:
3002 defer_kevent (dev, EVENT_RX_MEMORY); 327 usbnet_defer_kevent (dev, EVENT_RX_MEMORY);
3003 break; 328 break;
3004 case -ENODEV: 329 case -ENODEV:
3005 if (netif_msg_ifdown (dev)) 330 if (netif_msg_ifdown (dev))
@@ -3037,7 +362,7 @@ static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
3037 // else network stack removes extra byte if we forced a short packet 362 // else network stack removes extra byte if we forced a short packet
3038 363
3039 if (skb->len) 364 if (skb->len)
3040 skb_return (dev, skb); 365 usbnet_skb_return (dev, skb);
3041 else { 366 else {
3042 if (netif_msg_rx_err (dev)) 367 if (netif_msg_rx_err (dev))
3043 devdbg (dev, "drop"); 368 devdbg (dev, "drop");
@@ -3063,7 +388,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs)
3063 switch (urb_status) { 388 switch (urb_status) {
3064 // success 389 // success
3065 case 0: 390 case 0:
3066 if (MIN_PACKET > skb->len || skb->len > MAX_PACKET) { 391 if (skb->len < dev->net->hard_header_len) {
3067 entry->state = rx_cleanup; 392 entry->state = rx_cleanup;
3068 dev->stats.rx_errors++; 393 dev->stats.rx_errors++;
3069 dev->stats.rx_length_errors++; 394 dev->stats.rx_length_errors++;
@@ -3078,7 +403,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs)
3078 // storm, recovering as needed. 403 // storm, recovering as needed.
3079 case -EPIPE: 404 case -EPIPE:
3080 dev->stats.rx_errors++; 405 dev->stats.rx_errors++;
3081 defer_kevent (dev, EVENT_RX_HALT); 406 usbnet_defer_kevent (dev, EVENT_RX_HALT);
3082 // FALLTHROUGH 407 // FALLTHROUGH
3083 408
3084 // software-driven interface shutdown 409 // software-driven interface shutdown
@@ -3320,55 +645,58 @@ done:
3320 645
3321/*-------------------------------------------------------------------------*/ 646/*-------------------------------------------------------------------------*/
3322 647
3323static void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info) 648/* ethtool methods; minidrivers may need to add some more, but
649 * they'll probably want to use this base set.
650 */
651
652void usbnet_get_drvinfo (struct net_device *net, struct ethtool_drvinfo *info)
3324{ 653{
3325 struct usbnet *dev = netdev_priv(net); 654 struct usbnet *dev = netdev_priv(net);
3326 655
656 /* REVISIT don't always return "usbnet" */
3327 strncpy (info->driver, driver_name, sizeof info->driver); 657 strncpy (info->driver, driver_name, sizeof info->driver);
3328 strncpy (info->version, DRIVER_VERSION, sizeof info->version); 658 strncpy (info->version, DRIVER_VERSION, sizeof info->version);
3329 strncpy (info->fw_version, dev->driver_info->description, 659 strncpy (info->fw_version, dev->driver_info->description,
3330 sizeof info->fw_version); 660 sizeof info->fw_version);
3331 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info); 661 usb_make_path (dev->udev, info->bus_info, sizeof info->bus_info);
3332} 662}
663EXPORT_SYMBOL_GPL(usbnet_get_drvinfo);
3333 664
3334static u32 usbnet_get_link (struct net_device *net) 665static u32 usbnet_get_link (struct net_device *net)
3335{ 666{
3336 struct usbnet *dev = netdev_priv(net); 667 struct usbnet *dev = netdev_priv(net);
3337 668
3338 /* If a check_connect is defined, return it's results */ 669 /* If a check_connect is defined, return its result */
3339 if (dev->driver_info->check_connect) 670 if (dev->driver_info->check_connect)
3340 return dev->driver_info->check_connect (dev) == 0; 671 return dev->driver_info->check_connect (dev) == 0;
3341 672
3342 /* Otherwise, we're up to avoid breaking scripts */ 673 /* Otherwise, say we're up (to avoid breaking scripts) */
3343 return 1; 674 return 1;
3344} 675}
3345 676
3346static u32 usbnet_get_msglevel (struct net_device *net) 677u32 usbnet_get_msglevel (struct net_device *net)
3347{ 678{
3348 struct usbnet *dev = netdev_priv(net); 679 struct usbnet *dev = netdev_priv(net);
3349 680
3350 return dev->msg_enable; 681 return dev->msg_enable;
3351} 682}
683EXPORT_SYMBOL_GPL(usbnet_get_msglevel);
3352 684
3353static void usbnet_set_msglevel (struct net_device *net, u32 level) 685void usbnet_set_msglevel (struct net_device *net, u32 level)
3354{ 686{
3355 struct usbnet *dev = netdev_priv(net); 687 struct usbnet *dev = netdev_priv(net);
3356 688
3357 dev->msg_enable = level; 689 dev->msg_enable = level;
3358} 690}
691EXPORT_SYMBOL_GPL(usbnet_set_msglevel);
3359 692
3360static int usbnet_ioctl (struct net_device *net, struct ifreq *rq, int cmd) 693/* drivers may override default ethtool_ops in their bind() routine */
3361{ 694static struct ethtool_ops usbnet_ethtool_ops = {
3362#ifdef NEED_MII 695 .get_drvinfo = usbnet_get_drvinfo,
3363 { 696 .get_link = usbnet_get_link,
3364 struct usbnet *dev = netdev_priv(net); 697 .get_msglevel = usbnet_get_msglevel,
3365 698 .set_msglevel = usbnet_set_msglevel,
3366 if (dev->mii.mdio_read != NULL && dev->mii.mdio_write != NULL) 699};
3367 return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
3368 }
3369#endif
3370 return -EOPNOTSUPP;
3371}
3372 700
3373/*-------------------------------------------------------------------------*/ 701/*-------------------------------------------------------------------------*/
3374 702
@@ -3387,19 +715,24 @@ kevent (void *data)
3387 if (test_bit (EVENT_TX_HALT, &dev->flags)) { 715 if (test_bit (EVENT_TX_HALT, &dev->flags)) {
3388 unlink_urbs (dev, &dev->txq); 716 unlink_urbs (dev, &dev->txq);
3389 status = usb_clear_halt (dev->udev, dev->out); 717 status = usb_clear_halt (dev->udev, dev->out);
3390 if (status < 0 && status != -EPIPE) { 718 if (status < 0
719 && status != -EPIPE
720 && status != -ESHUTDOWN) {
3391 if (netif_msg_tx_err (dev)) 721 if (netif_msg_tx_err (dev))
3392 deverr (dev, "can't clear tx halt, status %d", 722 deverr (dev, "can't clear tx halt, status %d",
3393 status); 723 status);
3394 } else { 724 } else {
3395 clear_bit (EVENT_TX_HALT, &dev->flags); 725 clear_bit (EVENT_TX_HALT, &dev->flags);
3396 netif_wake_queue (dev->net); 726 if (status != -ESHUTDOWN)
727 netif_wake_queue (dev->net);
3397 } 728 }
3398 } 729 }
3399 if (test_bit (EVENT_RX_HALT, &dev->flags)) { 730 if (test_bit (EVENT_RX_HALT, &dev->flags)) {
3400 unlink_urbs (dev, &dev->rxq); 731 unlink_urbs (dev, &dev->rxq);
3401 status = usb_clear_halt (dev->udev, dev->in); 732 status = usb_clear_halt (dev->udev, dev->in);
3402 if (status < 0 && status != -EPIPE) { 733 if (status < 0
734 && status != -EPIPE
735 && status != -ESHUTDOWN) {
3403 if (netif_msg_rx_err (dev)) 736 if (netif_msg_rx_err (dev))
3404 deverr (dev, "can't clear rx halt, status %d", 737 deverr (dev, "can't clear rx halt, status %d",
3405 status); 738 status);
@@ -3458,7 +791,7 @@ static void tx_complete (struct urb *urb, struct pt_regs *regs)
3458 791
3459 switch (urb->status) { 792 switch (urb->status) {
3460 case -EPIPE: 793 case -EPIPE:
3461 defer_kevent (dev, EVENT_TX_HALT); 794 usbnet_defer_kevent (dev, EVENT_TX_HALT);
3462 break; 795 break;
3463 796
3464 /* software-driven interface shutdown */ 797 /* software-driven interface shutdown */
@@ -3515,10 +848,6 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
3515 struct skb_data *entry; 848 struct skb_data *entry;
3516 struct driver_info *info = dev->driver_info; 849 struct driver_info *info = dev->driver_info;
3517 unsigned long flags; 850 unsigned long flags;
3518#ifdef CONFIG_USB_NET1080
3519 struct nc_header *header = NULL;
3520 struct nc_trailer *trailer = NULL;
3521#endif /* CONFIG_USB_NET1080 */
3522 851
3523 // some devices want funky USB-level framing, for 852 // some devices want funky USB-level framing, for
3524 // win32 driver (usually) and/or hardware quirks 853 // win32 driver (usually) and/or hardware quirks
@@ -3544,24 +873,8 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
3544 entry->state = tx_start; 873 entry->state = tx_start;
3545 entry->length = length; 874 entry->length = length;
3546 875
3547 // FIXME: reorganize a bit, so that fixup() fills out NetChip
3548 // framing too. (Packet ID update needs the spinlock...)
3549 // [ BETTER: we already own net->xmit_lock, that's enough ]
3550
3551#ifdef CONFIG_USB_NET1080
3552 if (info->flags & FLAG_FRAMING_NC) {
3553 header = (struct nc_header *) skb_push (skb, sizeof *header);
3554 header->hdr_len = cpu_to_le16 (sizeof (*header));
3555 header->packet_len = cpu_to_le16 (length);
3556 if (!((skb->len + sizeof *trailer) & 0x01))
3557 *skb_put (skb, 1) = PAD_BYTE;
3558 trailer = (struct nc_trailer *) skb_put (skb, sizeof *trailer);
3559 }
3560#endif /* CONFIG_USB_NET1080 */
3561
3562 usb_fill_bulk_urb (urb, dev->udev, dev->out, 876 usb_fill_bulk_urb (urb, dev->udev, dev->out,
3563 skb->data, skb->len, tx_complete, skb); 877 skb->data, skb->len, tx_complete, skb);
3564 urb->transfer_flags |= URB_ASYNC_UNLINK;
3565 878
3566 /* don't assume the hardware handles USB_ZERO_PACKET 879 /* don't assume the hardware handles USB_ZERO_PACKET
3567 * NOTE: strictly conforming cdc-ether devices should expect 880 * NOTE: strictly conforming cdc-ether devices should expect
@@ -3574,22 +887,10 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
3574 887
3575 spin_lock_irqsave (&dev->txq.lock, flags); 888 spin_lock_irqsave (&dev->txq.lock, flags);
3576 889
3577#ifdef CONFIG_USB_NET1080
3578 if (info->flags & FLAG_FRAMING_NC) {
3579 header->packet_id = cpu_to_le16 ((u16)dev->dev_packet_id++);
3580 put_unaligned (header->packet_id, &trailer->packet_id);
3581#if 0
3582 devdbg (dev, "frame >tx h %d p %d id %d",
3583 header->hdr_len, header->packet_len,
3584 header->packet_id);
3585#endif
3586 }
3587#endif /* CONFIG_USB_NET1080 */
3588
3589 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) { 890 switch ((retval = usb_submit_urb (urb, GFP_ATOMIC))) {
3590 case -EPIPE: 891 case -EPIPE:
3591 netif_stop_queue (net); 892 netif_stop_queue (net);
3592 defer_kevent (dev, EVENT_TX_HALT); 893 usbnet_defer_kevent (dev, EVENT_TX_HALT);
3593 break; 894 break;
3594 default: 895 default:
3595 if (netif_msg_tx_err (dev)) 896 if (netif_msg_tx_err (dev))
@@ -3692,7 +993,7 @@ static void usbnet_bh (unsigned long param)
3692 993
3693// precondition: never called in_interrupt 994// precondition: never called in_interrupt
3694 995
3695static void usbnet_disconnect (struct usb_interface *intf) 996void usbnet_disconnect (struct usb_interface *intf)
3696{ 997{
3697 struct usbnet *dev; 998 struct usbnet *dev;
3698 struct usb_device *xdev; 999 struct usb_device *xdev;
@@ -3706,7 +1007,8 @@ static void usbnet_disconnect (struct usb_interface *intf)
3706 xdev = interface_to_usbdev (intf); 1007 xdev = interface_to_usbdev (intf);
3707 1008
3708 if (netif_msg_probe (dev)) 1009 if (netif_msg_probe (dev))
3709 devinfo (dev, "unregister usbnet usb-%s-%s, %s", 1010 devinfo (dev, "unregister '%s' usb-%s-%s, %s",
1011 intf->dev.driver->name,
3710 xdev->bus->bus_name, xdev->devpath, 1012 xdev->bus->bus_name, xdev->devpath,
3711 dev->driver_info->description); 1013 dev->driver_info->description);
3712 1014
@@ -3722,15 +1024,14 @@ static void usbnet_disconnect (struct usb_interface *intf)
3722 free_netdev(net); 1024 free_netdev(net);
3723 usb_put_dev (xdev); 1025 usb_put_dev (xdev);
3724} 1026}
1027EXPORT_SYMBOL_GPL(usbnet_disconnect);
3725 1028
3726 1029
3727/*-------------------------------------------------------------------------*/ 1030/*-------------------------------------------------------------------------*/
3728 1031
3729static struct ethtool_ops usbnet_ethtool_ops;
3730
3731// precondition: never called in_interrupt 1032// precondition: never called in_interrupt
3732 1033
3733static int 1034int
3734usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) 1035usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3735{ 1036{
3736 struct usbnet *dev; 1037 struct usbnet *dev;
@@ -3779,6 +1080,10 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3779 strcpy (net->name, "usb%d"); 1080 strcpy (net->name, "usb%d");
3780 memcpy (net->dev_addr, node_id, sizeof node_id); 1081 memcpy (net->dev_addr, node_id, sizeof node_id);
3781 1082
1083 /* rx and tx sides can use different message sizes;
1084 * bind() should set rx_urb_size in that case.
1085 */
1086 dev->hard_mtu = net->mtu + net->hard_header_len;
3782#if 0 1087#if 0
3783// dma_supported() is deeply broken on almost all architectures 1088// dma_supported() is deeply broken on almost all architectures
3784 // possible with some EHCI controllers 1089 // possible with some EHCI controllers
@@ -3793,7 +1098,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3793 net->stop = usbnet_stop; 1098 net->stop = usbnet_stop;
3794 net->watchdog_timeo = TX_TIMEOUT_JIFFIES; 1099 net->watchdog_timeo = TX_TIMEOUT_JIFFIES;
3795 net->tx_timeout = usbnet_tx_timeout; 1100 net->tx_timeout = usbnet_tx_timeout;
3796 net->do_ioctl = usbnet_ioctl;
3797 net->ethtool_ops = &usbnet_ethtool_ops; 1101 net->ethtool_ops = &usbnet_ethtool_ops;
3798 1102
3799 // allow device-specific bind/init procedures 1103 // allow device-specific bind/init procedures
@@ -3806,8 +1110,12 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3806 if ((dev->driver_info->flags & FLAG_ETHER) != 0 1110 if ((dev->driver_info->flags & FLAG_ETHER) != 0
3807 && (net->dev_addr [0] & 0x02) == 0) 1111 && (net->dev_addr [0] & 0x02) == 0)
3808 strcpy (net->name, "eth%d"); 1112 strcpy (net->name, "eth%d");
3809 } else if (!info->in || info->out) 1113
3810 status = get_endpoints (dev, udev); 1114 /* maybe the remote can't receive an Ethernet MTU */
1115 if (net->mtu > (dev->hard_mtu - net->hard_header_len))
1116 net->mtu = dev->hard_mtu - net->hard_header_len;
1117 } else if (!info->in || !info->out)
1118 status = usbnet_get_endpoints (dev, udev);
3811 else { 1119 else {
3812 dev->in = usb_rcvbulkpipe (xdev, info->in); 1120 dev->in = usb_rcvbulkpipe (xdev, info->in);
3813 dev->out = usb_sndbulkpipe (xdev, info->out); 1121 dev->out = usb_sndbulkpipe (xdev, info->out);
@@ -3819,12 +1127,13 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3819 status = 0; 1127 status = 0;
3820 1128
3821 } 1129 }
3822
3823 if (status == 0 && dev->status) 1130 if (status == 0 && dev->status)
3824 status = init_status (dev, udev); 1131 status = init_status (dev, udev);
3825 if (status < 0) 1132 if (status < 0)
3826 goto out1; 1133 goto out1;
3827 1134
1135 if (!dev->rx_urb_size)
1136 dev->rx_urb_size = dev->hard_mtu;
3828 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); 1137 dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1);
3829 1138
3830 SET_NETDEV_DEV(net, &udev->dev); 1139 SET_NETDEV_DEV(net, &udev->dev);
@@ -3832,8 +1141,9 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
3832 if (status) 1141 if (status)
3833 goto out3; 1142 goto out3;
3834 if (netif_msg_probe (dev)) 1143 if (netif_msg_probe (dev))
3835 devinfo (dev, "register usbnet at usb-%s-%s, %s, " 1144 devinfo (dev, "register '%s' at usb-%s-%s, %s, "
3836 "%02x:%02x:%02x:%02x:%02x:%02x", 1145 "%02x:%02x:%02x:%02x:%02x:%02x",
1146 udev->dev.driver->name,
3837 xdev->bus->bus_name, xdev->devpath, 1147 xdev->bus->bus_name, xdev->devpath,
3838 dev->driver_info->description, 1148 dev->driver_info->description,
3839 net->dev_addr [0], net->dev_addr [1], 1149 net->dev_addr [0], net->dev_addr [1],
@@ -3857,12 +1167,15 @@ out:
3857 usb_put_dev(xdev); 1167 usb_put_dev(xdev);
3858 return status; 1168 return status;
3859} 1169}
1170EXPORT_SYMBOL_GPL(usbnet_probe);
3860 1171
3861/*-------------------------------------------------------------------------*/ 1172/*-------------------------------------------------------------------------*/
3862 1173
3863#ifdef CONFIG_PM 1174/* FIXME these suspend/resume methods assume non-CDC style
1175 * devices, with only one interface.
1176 */
3864 1177
3865static int usbnet_suspend (struct usb_interface *intf, pm_message_t message) 1178int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
3866{ 1179{
3867 struct usbnet *dev = usb_get_intfdata(intf); 1180 struct usbnet *dev = usb_get_intfdata(intf);
3868 1181
@@ -3875,8 +1188,9 @@ static int usbnet_suspend (struct usb_interface *intf, pm_message_t message)
3875 intf->dev.power.power_state = PMSG_SUSPEND; 1188 intf->dev.power.power_state = PMSG_SUSPEND;
3876 return 0; 1189 return 0;
3877} 1190}
1191EXPORT_SYMBOL_GPL(usbnet_suspend);
3878 1192
3879static int usbnet_resume (struct usb_interface *intf) 1193int usbnet_resume (struct usb_interface *intf)
3880{ 1194{
3881 struct usbnet *dev = usb_get_intfdata(intf); 1195 struct usbnet *dev = usb_get_intfdata(intf);
3882 1196
@@ -3885,357 +1199,27 @@ static int usbnet_resume (struct usb_interface *intf)
3885 tasklet_schedule (&dev->bh); 1199 tasklet_schedule (&dev->bh);
3886 return 0; 1200 return 0;
3887} 1201}
1202EXPORT_SYMBOL_GPL(usbnet_resume);
3888 1203
3889#else /* !CONFIG_PM */
3890
3891#define usbnet_suspend NULL
3892#define usbnet_resume NULL
3893
3894#endif /* CONFIG_PM */
3895
3896/*-------------------------------------------------------------------------*/
3897
3898#ifndef HAVE_HARDWARE
3899#error You need to configure some hardware for this driver
3900#endif
3901
3902/*
3903 * chip vendor names won't normally be on the cables, and
3904 * may not be on the device.
3905 */
3906
3907static const struct usb_device_id products [] = {
3908
3909#ifdef CONFIG_USB_ALI_M5632
3910{
3911 USB_DEVICE (0x0402, 0x5632), // ALi defaults
3912 .driver_info = (unsigned long) &ali_m5632_info,
3913},
3914#endif
3915
3916#ifdef CONFIG_USB_AN2720
3917{
3918 USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
3919 .driver_info = (unsigned long) &an2720_info,
3920}, {
3921 USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
3922 .driver_info = (unsigned long) &an2720_info,
3923},
3924#endif
3925
3926#ifdef CONFIG_USB_BELKIN
3927{
3928 USB_DEVICE (0x050d, 0x0004), // Belkin
3929 .driver_info = (unsigned long) &belkin_info,
3930}, {
3931 USB_DEVICE (0x056c, 0x8100), // eTEK
3932 .driver_info = (unsigned long) &belkin_info,
3933}, {
3934 USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
3935 .driver_info = (unsigned long) &belkin_info,
3936},
3937#endif
3938
3939#ifdef CONFIG_USB_AX8817X
3940{
3941 // Linksys USB200M
3942 USB_DEVICE (0x077b, 0x2226),
3943 .driver_info = (unsigned long) &ax8817x_info,
3944}, {
3945 // Netgear FA120
3946 USB_DEVICE (0x0846, 0x1040),
3947 .driver_info = (unsigned long) &netgear_fa120_info,
3948}, {
3949 // DLink DUB-E100
3950 USB_DEVICE (0x2001, 0x1a00),
3951 .driver_info = (unsigned long) &dlink_dub_e100_info,
3952}, {
3953 // Intellinet, ST Lab USB Ethernet
3954 USB_DEVICE (0x0b95, 0x1720),
3955 .driver_info = (unsigned long) &ax8817x_info,
3956}, {
3957 // Hawking UF200, TrendNet TU2-ET100
3958 USB_DEVICE (0x07b8, 0x420a),
3959 .driver_info = (unsigned long) &hawking_uf200_info,
3960}, {
3961 // Billionton Systems, USB2AR
3962 USB_DEVICE (0x08dd, 0x90ff),
3963 .driver_info = (unsigned long) &ax8817x_info,
3964}, {
3965 // ATEN UC210T
3966 USB_DEVICE (0x0557, 0x2009),
3967 .driver_info = (unsigned long) &ax8817x_info,
3968}, {
3969 // Buffalo LUA-U2-KTX
3970 USB_DEVICE (0x0411, 0x003d),
3971 .driver_info = (unsigned long) &ax8817x_info,
3972}, {
3973 // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
3974 USB_DEVICE (0x6189, 0x182d),
3975 .driver_info = (unsigned long) &ax8817x_info,
3976}, {
3977 // corega FEther USB2-TX
3978 USB_DEVICE (0x07aa, 0x0017),
3979 .driver_info = (unsigned long) &ax8817x_info,
3980}, {
3981 // Surecom EP-1427X-2
3982 USB_DEVICE (0x1189, 0x0893),
3983 .driver_info = (unsigned long) &ax8817x_info,
3984}, {
3985 // goodway corp usb gwusb2e
3986 USB_DEVICE (0x1631, 0x6200),
3987 .driver_info = (unsigned long) &ax8817x_info,
3988}, {
3989 // ASIX AX88772 10/100
3990 USB_DEVICE (0x0b95, 0x7720),
3991 .driver_info = (unsigned long) &ax88772_info,
3992},
3993#endif
3994
3995#ifdef CONFIG_USB_EPSON2888
3996{
3997 USB_DEVICE (0x0525, 0x2888), // EPSON USB client
3998 .driver_info = (unsigned long) &epson2888_info,
3999},
4000#endif
4001
4002#ifdef CONFIG_USB_GENESYS
4003{
4004 USB_DEVICE (0x05e3, 0x0502), // GL620USB-A
4005 .driver_info = (unsigned long) &genelink_info,
4006},
4007 /* NOT: USB_DEVICE (0x05e3, 0x0501), // GL620USB
4008 * that's half duplex, not currently supported
4009 */
4010#endif
4011
4012#ifdef CONFIG_USB_NET1080
4013{
4014 USB_DEVICE (0x0525, 0x1080), // NetChip ref design
4015 .driver_info = (unsigned long) &net1080_info,
4016}, {
4017 USB_DEVICE (0x06D0, 0x0622), // Laplink Gold
4018 .driver_info = (unsigned long) &net1080_info,
4019},
4020#endif
4021
4022#ifdef CONFIG_USB_PL2301
4023{
4024 USB_DEVICE (0x067b, 0x0000), // PL-2301
4025 .driver_info = (unsigned long) &prolific_info,
4026}, {
4027 USB_DEVICE (0x067b, 0x0001), // PL-2302
4028 .driver_info = (unsigned long) &prolific_info,
4029},
4030#endif
4031
4032#ifdef CONFIG_USB_KC2190
4033{
4034 USB_DEVICE (0x050f, 0x0190), // KC-190
4035 .driver_info = (unsigned long) &kc2190_info,
4036},
4037#endif
4038
4039#ifdef CONFIG_USB_RNDIS
4040{
4041 /* RNDIS is MSFT's un-official variant of CDC ACM */
4042 USB_INTERFACE_INFO (USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
4043 .driver_info = (unsigned long) &rndis_info,
4044},
4045#endif
4046
4047#ifdef CONFIG_USB_ARMLINUX
4048/*
4049 * SA-1100 using standard ARM Linux kernels, or compatible.
4050 * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
4051 * The sa-1100 "usb-eth" driver handles the basic framing.
4052 *
4053 * PXA25x or PXA210 ... these use a "usb-eth" driver much like
4054 * the sa1100 one, but hardware uses different endpoint numbers.
4055 *
4056 * Or the Linux "Ethernet" gadget on hardware that can't talk
4057 * CDC Ethernet (e.g., no altsettings), in either of two modes:
4058 * - acting just like the old "usb-eth" firmware, though
4059 * the implementation is different
4060 * - supporting RNDIS as the first/default configuration for
4061 * MS-Windows interop; Linux needs to use the other config
4062 */
4063{
4064 // 1183 = 0x049F, both used as hex values?
4065 // Compaq "Itsy" vendor/product id
4066 USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
4067 .driver_info = (unsigned long) &linuxdev_info,
4068}, {
4069 USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
4070 .driver_info = (unsigned long) &yopy_info,
4071}, {
4072 USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
4073 .driver_info = (unsigned long) &blob_info,
4074}, {
4075 // Linux Ethernet/RNDIS gadget on pxa210/25x/26x
4076 // e.g. Gumstix, current OpenZaurus, ...
4077 USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
4078 .driver_info = (unsigned long) &linuxdev_info,
4079},
4080#endif
4081
4082#if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
4083/*
4084 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
4085 * Same idea as above, but different framing.
4086 *
4087 * PXA-2xx based models are also lying-about-cdc.
4088 * Some models don't even tell the same lies ...
4089 *
4090 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
4091 * unlike the older ones with 2.4 "embedix" kernels.
4092 *
4093 * NOTE: These entries do double-duty, serving as blacklist entries
4094 * whenever Zaurus support isn't enabled, but CDC Ethernet is.
4095 */
4096#define ZAURUS_MASTER_INTERFACE \
4097 .bInterfaceClass = USB_CLASS_COMM, \
4098 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
4099 .bInterfaceProtocol = USB_CDC_PROTO_NONE
4100{
4101 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4102 | USB_DEVICE_ID_MATCH_DEVICE,
4103 .idVendor = 0x04DD,
4104 .idProduct = 0x8004,
4105 ZAURUS_MASTER_INTERFACE,
4106 .driver_info = ZAURUS_STRONGARM_INFO,
4107}, {
4108 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4109 | USB_DEVICE_ID_MATCH_DEVICE,
4110 .idVendor = 0x04DD,
4111 .idProduct = 0x8005, /* A-300 */
4112 ZAURUS_MASTER_INTERFACE,
4113 .driver_info = ZAURUS_PXA_INFO,
4114}, {
4115 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4116 | USB_DEVICE_ID_MATCH_DEVICE,
4117 .idVendor = 0x04DD,
4118 .idProduct = 0x8006, /* B-500/SL-5600 */
4119 ZAURUS_MASTER_INTERFACE,
4120 .driver_info = ZAURUS_PXA_INFO,
4121}, {
4122 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4123 | USB_DEVICE_ID_MATCH_DEVICE,
4124 .idVendor = 0x04DD,
4125 .idProduct = 0x8007, /* C-700 */
4126 ZAURUS_MASTER_INTERFACE,
4127 .driver_info = ZAURUS_PXA_INFO,
4128}, {
4129 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4130 | USB_DEVICE_ID_MATCH_DEVICE,
4131 .idVendor = 0x04DD,
4132 .idProduct = 0x9031, /* C-750 C-760 */
4133 ZAURUS_MASTER_INTERFACE,
4134 .driver_info = ZAURUS_PXA_INFO,
4135}, {
4136 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4137 | USB_DEVICE_ID_MATCH_DEVICE,
4138 .idVendor = 0x04DD,
4139 .idProduct = 0x9032, /* SL-6000 */
4140 ZAURUS_MASTER_INTERFACE,
4141 .driver_info = ZAURUS_PXA_INFO,
4142}, {
4143 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4144 | USB_DEVICE_ID_MATCH_DEVICE,
4145 .idVendor = 0x04DD,
4146 /* reported with some C860 units */
4147 .idProduct = 0x9050, /* C-860 */
4148 ZAURUS_MASTER_INTERFACE,
4149 .driver_info = ZAURUS_PXA_INFO,
4150},
4151
4152#ifdef CONFIG_USB_ZAURUS
4153 /* At least some (reports vary) PXA units have very different lies
4154 * about their standards support: they claim to be cell phones with
4155 * direct access to their radios. (They don't conform to CDC MDLM.)
4156 */
4157{
4158 USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
4159 USB_CDC_PROTO_NONE),
4160 .driver_info = (unsigned long) &bogus_mdlm_info,
4161},
4162#endif
4163
4164/* Olympus has some models with a Zaurus-compatible option.
4165 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
4166 */
4167{
4168 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
4169 | USB_DEVICE_ID_MATCH_DEVICE,
4170 .idVendor = 0x07B4,
4171 .idProduct = 0x0F02, /* R-1000 */
4172 ZAURUS_MASTER_INTERFACE,
4173 .driver_info = OLYMPUS_MXL_INFO,
4174},
4175#endif
4176
4177#ifdef CONFIG_USB_CDCETHER
4178{
4179 /* CDC Ether uses two interfaces, not necessarily consecutive.
4180 * We match the main interface, ignoring the optional device
4181 * class so we could handle devices that aren't exclusively
4182 * CDC ether.
4183 *
4184 * NOTE: this match must come AFTER entries working around
4185 * bugs/quirks in a given product (like Zaurus, above).
4186 */
4187 USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
4188 USB_CDC_PROTO_NONE),
4189 .driver_info = (unsigned long) &cdc_info,
4190},
4191#endif
4192
4193 { }, // END
4194};
4195MODULE_DEVICE_TABLE (usb, products);
4196
4197static struct usb_driver usbnet_driver = {
4198 .owner = THIS_MODULE,
4199 .name = driver_name,
4200 .id_table = products,
4201 .probe = usbnet_probe,
4202 .disconnect = usbnet_disconnect,
4203 .suspend = usbnet_suspend,
4204 .resume = usbnet_resume,
4205};
4206
4207/* Default ethtool_ops assigned. Devices can override in their bind() routine */
4208static struct ethtool_ops usbnet_ethtool_ops = {
4209 .get_drvinfo = usbnet_get_drvinfo,
4210 .get_link = usbnet_get_link,
4211 .get_msglevel = usbnet_get_msglevel,
4212 .set_msglevel = usbnet_set_msglevel,
4213};
4214 1204
4215/*-------------------------------------------------------------------------*/ 1205/*-------------------------------------------------------------------------*/
4216 1206
4217static int __init usbnet_init (void) 1207static int __init usbnet_init(void)
4218{ 1208{
4219 // compiler should optimize these out 1209 /* compiler should optimize this out */
4220 BUG_ON (sizeof (((struct sk_buff *)0)->cb) 1210 BUG_ON (sizeof (((struct sk_buff *)0)->cb)
4221 < sizeof (struct skb_data)); 1211 < sizeof (struct skb_data));
4222#ifdef CONFIG_USB_CDCETHER
4223 BUG_ON ((sizeof (((struct usbnet *)0)->data)
4224 < sizeof (struct cdc_state)));
4225#endif
4226 1212
4227 random_ether_addr(node_id); 1213 random_ether_addr(node_id);
4228 1214 return 0;
4229 return usb_register(&usbnet_driver);
4230} 1215}
4231module_init (usbnet_init); 1216module_init(usbnet_init);
4232 1217
4233static void __exit usbnet_exit (void) 1218static void __exit usbnet_exit(void)
4234{ 1219{
4235 usb_deregister (&usbnet_driver);
4236} 1220}
4237module_exit (usbnet_exit); 1221module_exit(usbnet_exit);
4238 1222
4239MODULE_AUTHOR ("David Brownell <dbrownell@users.sourceforge.net>"); 1223MODULE_AUTHOR("David Brownell");
4240MODULE_DESCRIPTION ("USB Host-to-Host Link Drivers (numerous vendors)"); 1224MODULE_DESCRIPTION("USB network driver framework");
4241MODULE_LICENSE ("GPL"); 1225MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h
new file mode 100644
index 000000000000..7aa0abd1a9bd
--- /dev/null
+++ b/drivers/usb/net/usbnet.h
@@ -0,0 +1,193 @@
1/*
2 * USB Networking Link Interface
3 *
4 * Copyright (C) 2000-2005 by David Brownell <dbrownell@users.sourceforge.net>
5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22
23#ifndef __USBNET_H
24#define __USBNET_H
25
26
27/* interface from usbnet core to each USB networking link we handle */
28struct usbnet {
29 /* housekeeping */
30 struct usb_device *udev;
31 struct driver_info *driver_info;
32 wait_queue_head_t *wait;
33
34 /* i/o info: pipes etc */
35 unsigned in, out;
36 struct usb_host_endpoint *status;
37 unsigned maxpacket;
38 struct timer_list delay;
39
40 /* protocol/interface state */
41 struct net_device *net;
42 struct net_device_stats stats;
43 int msg_enable;
44 unsigned long data [5];
45 u32 xid;
46 u32 hard_mtu; /* count any extra framing */
47 size_t rx_urb_size; /* size for rx urbs */
48 struct mii_if_info mii;
49
50 /* various kinds of pending driver work */
51 struct sk_buff_head rxq;
52 struct sk_buff_head txq;
53 struct sk_buff_head done;
54 struct urb *interrupt;
55 struct tasklet_struct bh;
56
57 struct work_struct kevent;
58 unsigned long flags;
59# define EVENT_TX_HALT 0
60# define EVENT_RX_HALT 1
61# define EVENT_RX_MEMORY 2
62# define EVENT_STS_SPLIT 3
63# define EVENT_LINK_RESET 4
64};
65
66static inline struct usb_driver *driver_of(struct usb_interface *intf)
67{
68 return to_usb_driver(intf->dev.driver);
69}
70
71/* interface from the device/framing level "minidriver" to core */
72struct driver_info {
73 char *description;
74
75 int flags;
76/* framing is CDC Ethernet, not writing ZLPs (hw issues), or optionally: */
77#define FLAG_FRAMING_NC 0x0001 /* guard against device dropouts */
78#define FLAG_FRAMING_GL 0x0002 /* genelink batches packets */
79#define FLAG_FRAMING_Z 0x0004 /* zaurus adds a trailer */
80#define FLAG_FRAMING_RN 0x0008 /* RNDIS batches, plus huge header */
81
82#define FLAG_NO_SETINT 0x0010 /* device can't set_interface() */
83#define FLAG_ETHER 0x0020 /* maybe use "eth%d" names */
84
85#define FLAG_FRAMING_AX 0x0040 /* AX88772/178 packets */
86
87 /* init device ... can sleep, or cause probe() failure */
88 int (*bind)(struct usbnet *, struct usb_interface *);
89
90 /* cleanup device ... can sleep, but can't fail */
91 void (*unbind)(struct usbnet *, struct usb_interface *);
92
93 /* reset device ... can sleep */
94 int (*reset)(struct usbnet *);
95
96 /* see if peer is connected ... can sleep */
97 int (*check_connect)(struct usbnet *);
98
99 /* for status polling */
100 void (*status)(struct usbnet *, struct urb *);
101
102 /* link reset handling, called from defer_kevent */
103 int (*link_reset)(struct usbnet *);
104
105 /* fixup rx packet (strip framing) */
106 int (*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
107
108 /* fixup tx packet (add framing) */
109 struct sk_buff *(*tx_fixup)(struct usbnet *dev,
110 struct sk_buff *skb, unsigned flags);
111
112 /* for new devices, use the descriptor-reading code instead */
113 int in; /* rx endpoint */
114 int out; /* tx endpoint */
115
116 unsigned long data; /* Misc driver specific data */
117};
118
119/* Minidrivers are just drivers using the "usbnet" core as a powerful
120 * network-specific subroutine library ... that happens to do pretty
121 * much everything except custom framing and chip-specific stuff.
122 */
123extern int usbnet_probe(struct usb_interface *, const struct usb_device_id *);
124extern int usbnet_suspend (struct usb_interface *, pm_message_t );
125extern int usbnet_resume (struct usb_interface *);
126extern void usbnet_disconnect(struct usb_interface *);
127
128
129/* Drivers that reuse some of the standard USB CDC infrastructure
130 * (notably, using multiple interfaces according to the the CDC
131 * union descriptor) get some helper code.
132 */
133struct cdc_state {
134 struct usb_cdc_header_desc *header;
135 struct usb_cdc_union_desc *u;
136 struct usb_cdc_ether_desc *ether;
137 struct usb_interface *control;
138 struct usb_interface *data;
139};
140
141extern int usbnet_generic_cdc_bind (struct usbnet *, struct usb_interface *);
142extern void usbnet_cdc_unbind (struct usbnet *, struct usb_interface *);
143
144/* CDC and RNDIS support the same host-chosen packet filters for IN transfers */
145#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
146 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
147 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
148 |USB_CDC_PACKET_TYPE_DIRECTED)
149
150
151/* we record the state for each of our queued skbs */
152enum skb_state {
153 illegal = 0,
154 tx_start, tx_done,
155 rx_start, rx_done, rx_cleanup
156};
157
158struct skb_data { /* skb->cb is one of these */
159 struct urb *urb;
160 struct usbnet *dev;
161 enum skb_state state;
162 size_t length;
163};
164
165
166extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *);
167extern void usbnet_defer_kevent (struct usbnet *, int);
168extern void usbnet_skb_return (struct usbnet *, struct sk_buff *);
169
170extern u32 usbnet_get_msglevel (struct net_device *);
171extern void usbnet_set_msglevel (struct net_device *, u32);
172extern void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *);
173
174/* messaging support includes the interface name, so it must not be
175 * used before it has one ... notably, in minidriver bind() calls.
176 */
177#ifdef DEBUG
178#define devdbg(usbnet, fmt, arg...) \
179 printk(KERN_DEBUG "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
180#else
181#define devdbg(usbnet, fmt, arg...) do {} while(0)
182#endif
183
184#define deverr(usbnet, fmt, arg...) \
185 printk(KERN_ERR "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
186#define devwarn(usbnet, fmt, arg...) \
187 printk(KERN_WARNING "%s: " fmt "\n" , (usbnet)->net->name , ## arg)
188
189#define devinfo(usbnet, fmt, arg...) \
190 printk(KERN_INFO "%s: " fmt "\n" , (usbnet)->net->name , ## arg); \
191
192
193#endif /* __USBNET_H */
diff --git a/drivers/usb/net/zaurus.c b/drivers/usb/net/zaurus.c
new file mode 100644
index 000000000000..ee3b892aeabc
--- /dev/null
+++ b/drivers/usb/net/zaurus.c
@@ -0,0 +1,386 @@
1/*
2 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
3 * Copyright (C) 2002-2005 by David Brownell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// #define DEBUG // error path messages, extra info
21// #define VERBOSE // more; success messages
22
23#include <linux/config.h>
24#ifdef CONFIG_USB_DEBUG
25# define DEBUG
26#endif
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <linux/init.h>
30#include <linux/netdevice.h>
31#include <linux/ethtool.h>
32#include <linux/workqueue.h>
33#include <linux/mii.h>
34#include <linux/crc32.h>
35#include <linux/usb.h>
36#include <linux/usb_cdc.h>
37
38#include "usbnet.h"
39
40
41/*
42 * All known Zaurii lie about their standards conformance. At least
43 * the earliest SA-1100 models lie by saying they support CDC Ethernet.
44 * Some later models (especially PXA-25x and PXA-27x based ones) lie
45 * and say they support CDC MDLM (for access to cell phone modems).
46 *
47 * There are non-Zaurus products that use these same protocols too.
48 *
49 * The annoying thing is that at the same time Sharp was developing
50 * that annoying standards-breaking software, the Linux community had
51 * a simple "CDC Subset" working reliably on the same SA-1100 hardware.
52 * That is, the same functionality but not violating standards.
53 *
54 * The CDC Ethernet nonconformance points are troublesome to hosts
55 * with a true CDC Ethernet implementation:
56 * - Framing appends a CRC, which the spec says drivers "must not" do;
57 * - Transfers data in altsetting zero, instead of altsetting 1;
58 * - All these peripherals use the same ethernet address.
59 *
60 * The CDC MDLM nonconformance is less immediately troublesome, since all
61 * MDLM implementations are quasi-proprietary anyway.
62 */
63
64static struct sk_buff *
65zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags)
66{
67 int padlen;
68 struct sk_buff *skb2;
69
70 padlen = 2;
71 if (!skb_cloned(skb)) {
72 int tailroom = skb_tailroom(skb);
73 if ((padlen + 4) <= tailroom)
74 goto done;
75 }
76 skb2 = skb_copy_expand(skb, 0, 4 + padlen, flags);
77 dev_kfree_skb_any(skb);
78 skb = skb2;
79 if (skb) {
80 u32 fcs;
81done:
82 fcs = crc32_le(~0, skb->data, skb->len);
83 fcs = ~fcs;
84
85 *skb_put (skb, 1) = fcs & 0xff;
86 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
87 *skb_put (skb, 1) = (fcs>>16) & 0xff;
88 *skb_put (skb, 1) = (fcs>>24) & 0xff;
89 }
90 return skb;
91}
92
93static int zaurus_bind(struct usbnet *dev, struct usb_interface *intf)
94{
95 /* Belcarra's funky framing has other options; mostly
96 * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
97 */
98 dev->net->hard_header_len += 6;
99 dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
100 return usbnet_generic_cdc_bind(dev, intf);
101}
102
103/* PDA style devices are always connected if present */
104static int always_connected (struct usbnet *dev)
105{
106 return 0;
107}
108
109static const struct driver_info zaurus_sl5x00_info = {
110 .description = "Sharp Zaurus SL-5x00",
111 .flags = FLAG_FRAMING_Z,
112 .check_connect = always_connected,
113 .bind = zaurus_bind,
114 .unbind = usbnet_cdc_unbind,
115 .tx_fixup = zaurus_tx_fixup,
116};
117#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
118
119static const struct driver_info zaurus_pxa_info = {
120 .description = "Sharp Zaurus, PXA-2xx based",
121 .flags = FLAG_FRAMING_Z,
122 .check_connect = always_connected,
123 .bind = zaurus_bind,
124 .unbind = usbnet_cdc_unbind,
125 .tx_fixup = zaurus_tx_fixup,
126};
127#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
128
129static const struct driver_info olympus_mxl_info = {
130 .description = "Olympus R1000",
131 .flags = FLAG_FRAMING_Z,
132 .check_connect = always_connected,
133 .bind = zaurus_bind,
134 .unbind = usbnet_cdc_unbind,
135 .tx_fixup = zaurus_tx_fixup,
136};
137#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
138
139
140/* Some more recent products using Lineo/Belcarra code will wrongly claim
141 * CDC MDLM conformance. They aren't conformant: data endpoints live
142 * in the control interface, there's no data interface, and it's not used
143 * to talk to a cell phone radio. But at least we can detect these two
144 * pseudo-classes, rather than growing this product list with entries for
145 * each new nonconformant product (sigh).
146 */
147static const u8 safe_guid[16] = {
148 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
149 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
150};
151static const u8 blan_guid[16] = {
152 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
153 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
154};
155
156static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf)
157{
158 u8 *buf = intf->cur_altsetting->extra;
159 int len = intf->cur_altsetting->extralen;
160 struct usb_cdc_mdlm_desc *desc = NULL;
161 struct usb_cdc_mdlm_detail_desc *detail = NULL;
162
163 while (len > 3) {
164 if (buf [1] != USB_DT_CS_INTERFACE)
165 goto next_desc;
166
167 /* use bDescriptorSubType, and just verify that we get a
168 * "BLAN" (or "SAFE") descriptor.
169 */
170 switch (buf [2]) {
171 case USB_CDC_MDLM_TYPE:
172 if (desc) {
173 dev_dbg(&intf->dev, "extra MDLM\n");
174 goto bad_desc;
175 }
176 desc = (void *) buf;
177 if (desc->bLength != sizeof *desc) {
178 dev_dbg(&intf->dev, "MDLM len %u\n",
179 desc->bLength);
180 goto bad_desc;
181 }
182 /* expect bcdVersion 1.0, ignore */
183 if (memcmp(&desc->bGUID, blan_guid, 16)
184 && memcmp(&desc->bGUID, safe_guid, 16) ) {
185 /* hey, this one might _really_ be MDLM! */
186 dev_dbg(&intf->dev, "MDLM guid\n");
187 goto bad_desc;
188 }
189 break;
190 case USB_CDC_MDLM_DETAIL_TYPE:
191 if (detail) {
192 dev_dbg(&intf->dev, "extra MDLM detail\n");
193 goto bad_desc;
194 }
195 detail = (void *) buf;
196 switch (detail->bGuidDescriptorType) {
197 case 0: /* "SAFE" */
198 if (detail->bLength != (sizeof *detail + 2))
199 goto bad_detail;
200 break;
201 case 1: /* "BLAN" */
202 if (detail->bLength != (sizeof *detail + 3))
203 goto bad_detail;
204 break;
205 default:
206 goto bad_detail;
207 }
208
209 /* assuming we either noticed BLAN already, or will
210 * find it soon, there are some data bytes here:
211 * - bmNetworkCapabilities (unused)
212 * - bmDataCapabilities (bits, see below)
213 * - bPad (ignored, for PADAFTER -- BLAN-only)
214 * bits are:
215 * - 0x01 -- Zaurus framing (add CRC)
216 * - 0x02 -- PADBEFORE (CRC includes some padding)
217 * - 0x04 -- PADAFTER (some padding after CRC)
218 * - 0x08 -- "fermat" packet mangling (for hw bugs)
219 * the PADBEFORE appears not to matter; we interop
220 * with devices that use it and those that don't.
221 */
222 if ((detail->bDetailData[1] & ~0x02) != 0x01) {
223 /* bmDataCapabilites == 0 would be fine too,
224 * but framing is minidriver-coupled for now.
225 */
226bad_detail:
227 dev_dbg(&intf->dev,
228 "bad MDLM detail, %d %d %d\n",
229 detail->bLength,
230 detail->bDetailData[0],
231 detail->bDetailData[2]);
232 goto bad_desc;
233 }
234 break;
235 }
236next_desc:
237 len -= buf [0]; /* bLength */
238 buf += buf [0];
239 }
240
241 if (!desc || !detail) {
242 dev_dbg(&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
243 desc ? "" : "func ",
244 detail ? "" : "detail ");
245 goto bad_desc;
246 }
247
248 /* There's probably a CDC Ethernet descriptor there, but we can't
249 * rely on the Ethernet address it provides since not all vendors
250 * bother to make it unique. Likewise there's no point in tracking
251 * of the CDC event notifications.
252 */
253 return usbnet_get_endpoints(dev, intf);
254
255bad_desc:
256 dev_info(&dev->udev->dev, "unsupported MDLM descriptors\n");
257 return -ENODEV;
258}
259
260static const struct driver_info bogus_mdlm_info = {
261 .description = "pseudo-MDLM (BLAN) device",
262 .flags = FLAG_FRAMING_Z,
263 .check_connect = always_connected,
264 .tx_fixup = zaurus_tx_fixup,
265 .bind = blan_mdlm_bind,
266};
267
268static const struct usb_device_id products [] = {
269#define ZAURUS_MASTER_INTERFACE \
270 .bInterfaceClass = USB_CLASS_COMM, \
271 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
272 .bInterfaceProtocol = USB_CDC_PROTO_NONE
273
274/* SA-1100 based Sharp Zaurus ("collie"), or compatible. */
275{
276 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
277 | USB_DEVICE_ID_MATCH_DEVICE,
278 .idVendor = 0x04DD,
279 .idProduct = 0x8004,
280 ZAURUS_MASTER_INTERFACE,
281 .driver_info = ZAURUS_STRONGARM_INFO,
282},
283
284/* PXA-2xx based models are also lying-about-cdc. If you add any
285 * more devices that claim to be CDC Ethernet, make sure they get
286 * added to the blacklist in cdc_ether too.
287 *
288 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
289 * unlike the older ones with 2.4 "embedix" kernels.
290 */
291{
292 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
293 | USB_DEVICE_ID_MATCH_DEVICE,
294 .idVendor = 0x04DD,
295 .idProduct = 0x8005, /* A-300 */
296 ZAURUS_MASTER_INTERFACE,
297 .driver_info = ZAURUS_PXA_INFO,
298}, {
299 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
300 | USB_DEVICE_ID_MATCH_DEVICE,
301 .idVendor = 0x04DD,
302 .idProduct = 0x8006, /* B-500/SL-5600 */
303 ZAURUS_MASTER_INTERFACE,
304 .driver_info = ZAURUS_PXA_INFO,
305}, {
306 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
307 | USB_DEVICE_ID_MATCH_DEVICE,
308 .idVendor = 0x04DD,
309 .idProduct = 0x8007, /* C-700 */
310 ZAURUS_MASTER_INTERFACE,
311 .driver_info = ZAURUS_PXA_INFO,
312}, {
313 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
314 | USB_DEVICE_ID_MATCH_DEVICE,
315 .idVendor = 0x04DD,
316 .idProduct = 0x9031, /* C-750 C-760 */
317 ZAURUS_MASTER_INTERFACE,
318 .driver_info = ZAURUS_PXA_INFO,
319}, {
320 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
321 | USB_DEVICE_ID_MATCH_DEVICE,
322 .idVendor = 0x04DD,
323 .idProduct = 0x9032, /* SL-6000 */
324 ZAURUS_MASTER_INTERFACE,
325 .driver_info = ZAURUS_PXA_INFO,
326}, {
327 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
328 | USB_DEVICE_ID_MATCH_DEVICE,
329 .idVendor = 0x04DD,
330 /* reported with some C860 units */
331 .idProduct = 0x9050, /* C-860 */
332 ZAURUS_MASTER_INTERFACE,
333 .driver_info = ZAURUS_PXA_INFO,
334},
335
336
337/* At least some of the newest PXA units have very different lies about
338 * their standards support: they claim to be cell phones offering
339 * direct access to their radios! (No, they don't conform to CDC MDLM.)
340 */
341{
342 USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
343 USB_CDC_PROTO_NONE),
344 .driver_info = (unsigned long) &bogus_mdlm_info,
345},
346
347/* Olympus has some models with a Zaurus-compatible option.
348 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
349 */
350{
351 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
352 | USB_DEVICE_ID_MATCH_DEVICE,
353 .idVendor = 0x07B4,
354 .idProduct = 0x0F02, /* R-1000 */
355 ZAURUS_MASTER_INTERFACE,
356 .driver_info = OLYMPUS_MXL_INFO,
357},
358 { }, // END
359};
360MODULE_DEVICE_TABLE(usb, products);
361
362static struct usb_driver zaurus_driver = {
363 .owner = THIS_MODULE,
364 .name = "zaurus",
365 .id_table = products,
366 .probe = usbnet_probe,
367 .disconnect = usbnet_disconnect,
368 .suspend = usbnet_suspend,
369 .resume = usbnet_resume,
370};
371
372static int __init zaurus_init(void)
373{
374 return usb_register(&zaurus_driver);
375}
376module_init(zaurus_init);
377
378static void __exit zaurus_exit(void)
379{
380 usb_deregister(&zaurus_driver);
381}
382module_exit(zaurus_exit);
383
384MODULE_AUTHOR("Pavel Machek, David Brownell");
385MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products");
386MODULE_LICENSE("GPL");
diff --git a/drivers/usb/net/zd1201.c b/drivers/usb/net/zd1201.c
index fc013978837e..c4e479ee926a 100644
--- a/drivers/usb/net/zd1201.c
+++ b/drivers/usb/net/zd1201.c
@@ -847,7 +847,6 @@ static void zd1201_tx_timeout(struct net_device *dev)
847 return; 847 return;
848 dev_warn(&zd->usb->dev, "%s: TX timeout, shooting down urb\n", 848 dev_warn(&zd->usb->dev, "%s: TX timeout, shooting down urb\n",
849 dev->name); 849 dev->name);
850 zd->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
851 usb_unlink_urb(zd->tx_urb); 850 usb_unlink_urb(zd->tx_urb);
852 zd->stats.tx_errors++; 851 zd->stats.tx_errors++;
853 /* Restart the timeout to quiet the watchdog: */ 852 /* Restart the timeout to quiet the watchdog: */
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 4ace9964fc6b..97c78c21e8d1 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -32,7 +32,7 @@
32/* 32/*
33 * Version Information 33 * Version Information
34 */ 34 */
35#define DRIVER_VERSION "v0.04" 35#define DRIVER_VERSION "v0.05"
36#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" 36#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver"
37 37
38/* 38/*
@@ -54,8 +54,11 @@ static void cp2101_shutdown(struct usb_serial*);
54static int debug; 54static int debug;
55 55
56static struct usb_device_id id_table [] = { 56static struct usb_device_id id_table [] = {
57 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
57 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 58 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
58 { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */ 59 { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */
60 { USB_DEVICE(0x10C4, 0x80F6) }, /* Suunto sports instrument */
61 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
59 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ 62 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
60 { } /* Terminating Entry */ 63 { } /* Terminating Entry */
61}; 64};
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 012e63e05806..9ee1aaff2fcd 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -453,8 +453,8 @@ static int generic_startup (struct usb_serial *serial)
453 priv->cbr_mask = B300; 453 priv->cbr_mask = B300;
454 usb_set_serial_port_data(serial->port[0], priv); 454 usb_set_serial_port_data(serial->port[0], priv);
455 455
456 return (0); 456 return 0;
457} 457}
458 458
459 459
460static int cypress_earthmate_startup (struct usb_serial *serial) 460static int cypress_earthmate_startup (struct usb_serial *serial)
@@ -464,14 +464,15 @@ static int cypress_earthmate_startup (struct usb_serial *serial)
464 dbg("%s", __FUNCTION__); 464 dbg("%s", __FUNCTION__);
465 465
466 if (generic_startup(serial)) { 466 if (generic_startup(serial)) {
467 dbg("%s - Failed setting up port %d", __FUNCTION__, serial->port[0]->number); 467 dbg("%s - Failed setting up port %d", __FUNCTION__,
468 serial->port[0]->number);
468 return 1; 469 return 1;
469 } 470 }
470 471
471 priv = usb_get_serial_port_data(serial->port[0]); 472 priv = usb_get_serial_port_data(serial->port[0]);
472 priv->chiptype = CT_EARTHMATE; 473 priv->chiptype = CT_EARTHMATE;
473 474
474 return (0); 475 return 0;
475} /* cypress_earthmate_startup */ 476} /* cypress_earthmate_startup */
476 477
477 478
@@ -482,14 +483,15 @@ static int cypress_hidcom_startup (struct usb_serial *serial)
482 dbg("%s", __FUNCTION__); 483 dbg("%s", __FUNCTION__);
483 484
484 if (generic_startup(serial)) { 485 if (generic_startup(serial)) {
485 dbg("%s - Failed setting up port %d", __FUNCTION__, serial->port[0]->number); 486 dbg("%s - Failed setting up port %d", __FUNCTION__,
487 serial->port[0]->number);
486 return 1; 488 return 1;
487 } 489 }
488 490
489 priv = usb_get_serial_port_data(serial->port[0]); 491 priv = usb_get_serial_port_data(serial->port[0]);
490 priv->chiptype = CT_CYPHIDCOM; 492 priv->chiptype = CT_CYPHIDCOM;
491 493
492 return (0); 494 return 0;
493} /* cypress_hidcom_startup */ 495} /* cypress_hidcom_startup */
494 496
495 497
@@ -608,8 +610,7 @@ static void cypress_close(struct usb_serial_port *port, struct file * filp)
608 timeout = max((HZ*2560)/bps,HZ/10); 610 timeout = max((HZ*2560)/bps,HZ/10);
609 else 611 else
610 timeout = 2*HZ; 612 timeout = 2*HZ;
611 set_current_state(TASK_INTERRUPTIBLE); 613 schedule_timeout_interruptible(timeout);
612 schedule_timeout(timeout);
613 614
614 dbg("%s - stopping urbs", __FUNCTION__); 615 dbg("%s - stopping urbs", __FUNCTION__);
615 usb_kill_urb (port->interrupt_in_urb); 616 usb_kill_urb (port->interrupt_in_urb);
@@ -909,7 +910,8 @@ static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsi
909} /* cypress_ioctl */ 910} /* cypress_ioctl */
910 911
911 912
912static void cypress_set_termios (struct usb_serial_port *port, struct termios *old_termios) 913static void cypress_set_termios (struct usb_serial_port *port,
914 struct termios *old_termios)
913{ 915{
914 struct cypress_private *priv = usb_get_serial_port_data(port); 916 struct cypress_private *priv = usb_get_serial_port_data(port);
915 struct tty_struct *tty; 917 struct tty_struct *tty;
@@ -918,7 +920,7 @@ static void cypress_set_termios (struct usb_serial_port *port, struct termios *o
918 unsigned long flags; 920 unsigned long flags;
919 __u8 oldlines; 921 __u8 oldlines;
920 int linechange = 0; 922 int linechange = 0;
921 923
922 dbg("%s - port %d", __FUNCTION__, port->number); 924 dbg("%s - port %d", __FUNCTION__, port->number);
923 925
924 tty = port->tty; 926 tty = port->tty;
@@ -931,10 +933,12 @@ static void cypress_set_termios (struct usb_serial_port *port, struct termios *o
931 if (!priv->termios_initialized) { 933 if (!priv->termios_initialized) {
932 if (priv->chiptype == CT_EARTHMATE) { 934 if (priv->chiptype == CT_EARTHMATE) {
933 *(tty->termios) = tty_std_termios; 935 *(tty->termios) = tty_std_termios;
934 tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL | CLOCAL; 936 tty->termios->c_cflag = B4800 | CS8 | CREAD | HUPCL |
937 CLOCAL;
935 } else if (priv->chiptype == CT_CYPHIDCOM) { 938 } else if (priv->chiptype == CT_CYPHIDCOM) {
936 *(tty->termios) = tty_std_termios; 939 *(tty->termios) = tty_std_termios;
937 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 940 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL |
941 CLOCAL;
938 } 942 }
939 priv->termios_initialized = 1; 943 priv->termios_initialized = 1;
940 } 944 }
@@ -946,12 +950,15 @@ static void cypress_set_termios (struct usb_serial_port *port, struct termios *o
946 /* check if there are new settings */ 950 /* check if there are new settings */
947 if (old_termios) { 951 if (old_termios) {
948 if ((cflag != old_termios->c_cflag) || 952 if ((cflag != old_termios->c_cflag) ||
949 (RELEVANT_IFLAG(iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) { 953 (RELEVANT_IFLAG(iflag) !=
950 dbg("%s - attempting to set new termios settings", __FUNCTION__); 954 RELEVANT_IFLAG(old_termios->c_iflag))) {
951 /* should make a copy of this in case something goes wrong in the function, we can restore it */ 955 dbg("%s - attempting to set new termios settings",
956 __FUNCTION__);
957 /* should make a copy of this in case something goes
958 * wrong in the function, we can restore it */
952 spin_lock_irqsave(&priv->lock, flags); 959 spin_lock_irqsave(&priv->lock, flags);
953 priv->tmp_termios = *(tty->termios); 960 priv->tmp_termios = *(tty->termios);
954 spin_unlock_irqrestore(&priv->lock, flags); 961 spin_unlock_irqrestore(&priv->lock, flags);
955 } else { 962 } else {
956 dbg("%s - nothing to do, exiting", __FUNCTION__); 963 dbg("%s - nothing to do, exiting", __FUNCTION__);
957 return; 964 return;
@@ -962,21 +969,34 @@ static void cypress_set_termios (struct usb_serial_port *port, struct termios *o
962 /* set number of data bits, parity, stop bits */ 969 /* set number of data bits, parity, stop bits */
963 /* when parity is disabled the parity type bit is ignored */ 970 /* when parity is disabled the parity type bit is ignored */
964 971
965 stop_bits = cflag & CSTOPB ? 1 : 0; /* 1 means 2 stop bits, 0 means 1 stop bit */ 972 /* 1 means 2 stop bits, 0 means 1 stop bit */
966 973 stop_bits = cflag & CSTOPB ? 1 : 0;
974
967 if (cflag & PARENB) { 975 if (cflag & PARENB) {
968 parity_enable = 1; 976 parity_enable = 1;
969 parity_type = cflag & PARODD ? 1 : 0; /* 1 means odd parity, 0 means even parity */ 977 /* 1 means odd parity, 0 means even parity */
978 parity_type = cflag & PARODD ? 1 : 0;
970 } else 979 } else
971 parity_enable = parity_type = 0; 980 parity_enable = parity_type = 0;
972 981
973 if (cflag & CSIZE) { 982 if (cflag & CSIZE) {
974 switch (cflag & CSIZE) { 983 switch (cflag & CSIZE) {
975 case CS5: data_bits = 0; break; 984 case CS5:
976 case CS6: data_bits = 1; break; 985 data_bits = 0;
977 case CS7: data_bits = 2; break; 986 break;
978 case CS8: data_bits = 3; break; 987 case CS6:
979 default: err("%s - CSIZE was set, but not CS5-CS8", __FUNCTION__); data_bits = 3; 988 data_bits = 1;
989 break;
990 case CS7:
991 data_bits = 2;
992 break;
993 case CS8:
994 data_bits = 3;
995 break;
996 default:
997 err("%s - CSIZE was set, but not CS5-CS8",
998 __FUNCTION__);
999 data_bits = 3;
980 } 1000 }
981 } else 1001 } else
982 data_bits = 3; 1002 data_bits = 3;
@@ -991,63 +1011,85 @@ static void cypress_set_termios (struct usb_serial_port *port, struct termios *o
991 } else { 1011 } else {
992 baud_mask = (cflag & CBAUD); 1012 baud_mask = (cflag & CBAUD);
993 switch(baud_mask) { 1013 switch(baud_mask) {
994 case B300: dbg("%s - setting baud 300bps", __FUNCTION__); break; 1014 case B300:
995 case B600: dbg("%s - setting baud 600bps", __FUNCTION__); break; 1015 dbg("%s - setting baud 300bps", __FUNCTION__);
996 case B1200: dbg("%s - setting baud 1200bps", __FUNCTION__); break; 1016 break;
997 case B2400: dbg("%s - setting baud 2400bps", __FUNCTION__); break; 1017 case B600:
998 case B4800: dbg("%s - setting baud 4800bps", __FUNCTION__); break; 1018 dbg("%s - setting baud 600bps", __FUNCTION__);
999 case B9600: dbg("%s - setting baud 9600bps", __FUNCTION__); break; 1019 break;
1000 case B19200: dbg("%s - setting baud 19200bps", __FUNCTION__); break; 1020 case B1200:
1001 case B38400: dbg("%s - setting baud 38400bps", __FUNCTION__); break; 1021 dbg("%s - setting baud 1200bps", __FUNCTION__);
1002 case B57600: dbg("%s - setting baud 57600bps", __FUNCTION__); break; 1022 break;
1003 case B115200: dbg("%s - setting baud 115200bps", __FUNCTION__); break; 1023 case B2400:
1004 default: dbg("%s - unknown masked baud rate", __FUNCTION__); 1024 dbg("%s - setting baud 2400bps", __FUNCTION__);
1025 break;
1026 case B4800:
1027 dbg("%s - setting baud 4800bps", __FUNCTION__);
1028 break;
1029 case B9600:
1030 dbg("%s - setting baud 9600bps", __FUNCTION__);
1031 break;
1032 case B19200:
1033 dbg("%s - setting baud 19200bps", __FUNCTION__);
1034 break;
1035 case B38400:
1036 dbg("%s - setting baud 38400bps", __FUNCTION__);
1037 break;
1038 case B57600:
1039 dbg("%s - setting baud 57600bps", __FUNCTION__);
1040 break;
1041 case B115200:
1042 dbg("%s - setting baud 115200bps", __FUNCTION__);
1043 break;
1044 default:
1045 dbg("%s - unknown masked baud rate", __FUNCTION__);
1005 } 1046 }
1006 priv->line_control = (CONTROL_DTR | CONTROL_RTS); 1047 priv->line_control = (CONTROL_DTR | CONTROL_RTS);
1007 } 1048 }
1008 spin_unlock_irqrestore(&priv->lock, flags); 1049 spin_unlock_irqrestore(&priv->lock, flags);
1009
1010 dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, %d data_bits (+5)", __FUNCTION__,
1011 stop_bits, parity_enable, parity_type, data_bits);
1012 1050
1013 cypress_serial_control(port, baud_mask, data_bits, stop_bits, parity_enable, 1051 dbg("%s - sending %d stop_bits, %d parity_enable, %d parity_type, "
1014 parity_type, 0, CYPRESS_SET_CONFIG); 1052 "%d data_bits (+5)", __FUNCTION__, stop_bits,
1053 parity_enable, parity_type, data_bits);
1054
1055 cypress_serial_control(port, baud_mask, data_bits, stop_bits,
1056 parity_enable, parity_type, 0, CYPRESS_SET_CONFIG);
1015 1057
1016 /* we perform a CYPRESS_GET_CONFIG so that the current settings are filled into the private structure 1058 /* we perform a CYPRESS_GET_CONFIG so that the current settings are
1017 * this should confirm that all is working if it returns what we just set */ 1059 * filled into the private structure this should confirm that all is
1060 * working if it returns what we just set */
1018 cypress_serial_control(port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG); 1061 cypress_serial_control(port, 0, 0, 0, 0, 0, 0, CYPRESS_GET_CONFIG);
1019 1062
1020 /* Here we can define custom tty settings for devices 1063 /* Here we can define custom tty settings for devices; the main tty
1021 * 1064 * termios flag base comes from empeg.c */
1022 * the main tty termios flag base comes from empeg.c
1023 */
1024 1065
1025 spin_lock_irqsave(&priv->lock, flags); 1066 spin_lock_irqsave(&priv->lock, flags);
1026 if ( (priv->chiptype == CT_EARTHMATE) && (priv->baud_rate == 4800) ) { 1067 if ( (priv->chiptype == CT_EARTHMATE) && (priv->baud_rate == 4800) ) {
1027 1068 dbg("Using custom termios settings for a baud rate of "
1028 dbg("Using custom termios settings for a baud rate of 4800bps."); 1069 "4800bps.");
1029 /* define custom termios settings for NMEA protocol */ 1070 /* define custom termios settings for NMEA protocol */
1030 1071
1031 tty->termios->c_iflag /* input modes - */ 1072 tty->termios->c_iflag /* input modes - */
1032 &= ~(IGNBRK /* disable ignore break */ 1073 &= ~(IGNBRK /* disable ignore break */
1033 | BRKINT /* disable break causes interrupt */ 1074 | BRKINT /* disable break causes interrupt */
1034 | PARMRK /* disable mark parity errors */ 1075 | PARMRK /* disable mark parity errors */
1035 | ISTRIP /* disable clear high bit of input characters */ 1076 | ISTRIP /* disable clear high bit of input char */
1036 | INLCR /* disable translate NL to CR */ 1077 | INLCR /* disable translate NL to CR */
1037 | IGNCR /* disable ignore CR */ 1078 | IGNCR /* disable ignore CR */
1038 | ICRNL /* disable translate CR to NL */ 1079 | ICRNL /* disable translate CR to NL */
1039 | IXON); /* disable enable XON/XOFF flow control */ 1080 | IXON); /* disable enable XON/XOFF flow control */
1040 1081
1041 tty->termios->c_oflag /* output modes */ 1082 tty->termios->c_oflag /* output modes */
1042 &= ~OPOST; /* disable postprocess output characters */ 1083 &= ~OPOST; /* disable postprocess output char */
1043
1044 tty->termios->c_lflag /* line discipline modes */
1045 &= ~(ECHO /* disable echo input characters */
1046 | ECHONL /* disable echo new line */
1047 | ICANON /* disable erase, kill, werase, and rprnt special characters */
1048 | ISIG /* disable interrupt, quit, and suspend special characters */
1049 | IEXTEN); /* disable non-POSIX special characters */
1050 1084
1085 tty->termios->c_lflag /* line discipline modes */
1086 &= ~(ECHO /* disable echo input characters */
1087 | ECHONL /* disable echo new line */
1088 | ICANON /* disable erase, kill, werase, and rprnt
1089 special characters */
1090 | ISIG /* disable interrupt, quit, and suspend
1091 special characters */
1092 | IEXTEN); /* disable non-POSIX special characters */
1051 } /* CT_CYPHIDCOM: Application should handle this for device */ 1093 } /* CT_CYPHIDCOM: Application should handle this for device */
1052 1094
1053 linechange = (priv->line_control != oldlines); 1095 linechange = (priv->line_control != oldlines);
@@ -1060,7 +1102,7 @@ static void cypress_set_termios (struct usb_serial_port *port, struct termios *o
1060 } 1102 }
1061} /* cypress_set_termios */ 1103} /* cypress_set_termios */
1062 1104
1063 1105
1064/* returns amount of data still left in soft buffer */ 1106/* returns amount of data still left in soft buffer */
1065static int cypress_chars_in_buffer(struct usb_serial_port *port) 1107static int cypress_chars_in_buffer(struct usb_serial_port *port)
1066{ 1108{
@@ -1088,7 +1130,7 @@ static void cypress_throttle (struct usb_serial_port *port)
1088 1130
1089 spin_lock_irqsave(&priv->lock, flags); 1131 spin_lock_irqsave(&priv->lock, flags);
1090 priv->rx_flags = THROTTLED; 1132 priv->rx_flags = THROTTLED;
1091 spin_unlock_irqrestore(&priv->lock, flags); 1133 spin_unlock_irqrestore(&priv->lock, flags);
1092} 1134}
1093 1135
1094 1136
@@ -1110,7 +1152,8 @@ static void cypress_unthrottle (struct usb_serial_port *port)
1110 1152
1111 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1153 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1112 if (result) 1154 if (result)
1113 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result); 1155 dev_err(&port->dev, "%s - failed submitting read urb, "
1156 "error %d\n", __FUNCTION__, result);
1114 } 1157 }
1115} 1158}
1116 1159
@@ -1122,7 +1165,7 @@ static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs)
1122 struct tty_struct *tty; 1165 struct tty_struct *tty;
1123 unsigned char *data = urb->transfer_buffer; 1166 unsigned char *data = urb->transfer_buffer;
1124 unsigned long flags; 1167 unsigned long flags;
1125 char tty_flag = TTY_NORMAL; 1168 char tty_flag = TTY_NORMAL;
1126 int havedata = 0; 1169 int havedata = 0;
1127 int bytes = 0; 1170 int bytes = 0;
1128 int result; 1171 int result;
@@ -1131,7 +1174,8 @@ static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs)
1131 dbg("%s - port %d", __FUNCTION__, port->number); 1174 dbg("%s - port %d", __FUNCTION__, port->number);
1132 1175
1133 if (urb->status) { 1176 if (urb->status) {
1134 dbg("%s - nonzero read status received: %d", __FUNCTION__, urb->status); 1177 dbg("%s - nonzero read status received: %d", __FUNCTION__,
1178 urb->status);
1135 return; 1179 return;
1136 } 1180 }
1137 1181
@@ -1155,51 +1199,55 @@ static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs)
1155 case 32: 1199 case 32:
1156 /* This is for the CY7C64013... */ 1200 /* This is for the CY7C64013... */
1157 priv->current_status = data[0] & 0xF8; 1201 priv->current_status = data[0] & 0xF8;
1158 bytes = data[1]+2; 1202 bytes = data[1] + 2;
1159 i=2; 1203 i = 2;
1160 if (bytes > 2) 1204 if (bytes > 2)
1161 havedata = 1; 1205 havedata = 1;
1162 break; 1206 break;
1163 case 8: 1207 case 8:
1164 /* This is for the CY7C63743... */ 1208 /* This is for the CY7C63743... */
1165 priv->current_status = data[0] & 0xF8; 1209 priv->current_status = data[0] & 0xF8;
1166 bytes = (data[0] & 0x07)+1; 1210 bytes = (data[0] & 0x07) + 1;
1167 i=1; 1211 i = 1;
1168 if (bytes > 1) 1212 if (bytes > 1)
1169 havedata = 1; 1213 havedata = 1;
1170 break; 1214 break;
1171 default: 1215 default:
1172 dbg("%s - wrong packet size - received %d bytes", __FUNCTION__, urb->actual_length); 1216 dbg("%s - wrong packet size - received %d bytes",
1217 __FUNCTION__, urb->actual_length);
1173 spin_unlock_irqrestore(&priv->lock, flags); 1218 spin_unlock_irqrestore(&priv->lock, flags);
1174 goto continue_read; 1219 goto continue_read;
1175 } 1220 }
1176 spin_unlock_irqrestore(&priv->lock, flags); 1221 spin_unlock_irqrestore(&priv->lock, flags);
1177 1222
1178 usb_serial_debug_data (debug, &port->dev, __FUNCTION__, urb->actual_length, data); 1223 usb_serial_debug_data (debug, &port->dev, __FUNCTION__,
1224 urb->actual_length, data);
1179 1225
1180 spin_lock_irqsave(&priv->lock, flags); 1226 spin_lock_irqsave(&priv->lock, flags);
1181 /* check to see if status has changed */ 1227 /* check to see if status has changed */
1182 if (priv != NULL) { 1228 if (priv != NULL) {
1183 if (priv->current_status != priv->prev_status) { 1229 if (priv->current_status != priv->prev_status) {
1184 priv->diff_status |= priv->current_status ^ priv->prev_status; 1230 priv->diff_status |= priv->current_status ^
1231 priv->prev_status;
1185 wake_up_interruptible(&priv->delta_msr_wait); 1232 wake_up_interruptible(&priv->delta_msr_wait);
1186 priv->prev_status = priv->current_status; 1233 priv->prev_status = priv->current_status;
1187 } 1234 }
1188 } 1235 }
1189 spin_unlock_irqrestore(&priv->lock, flags); 1236 spin_unlock_irqrestore(&priv->lock, flags);
1190 1237
1191 /* hangup, as defined in acm.c... this might be a bad place for it though */ 1238 /* hangup, as defined in acm.c... this might be a bad place for it
1192 if (tty && !(tty->termios->c_cflag & CLOCAL) && !(priv->current_status & UART_CD)) { 1239 * though */
1240 if (tty && !(tty->termios->c_cflag & CLOCAL) &&
1241 !(priv->current_status & UART_CD)) {
1193 dbg("%s - calling hangup", __FUNCTION__); 1242 dbg("%s - calling hangup", __FUNCTION__);
1194 tty_hangup(tty); 1243 tty_hangup(tty);
1195 goto continue_read; 1244 goto continue_read;
1196 } 1245 }
1197 1246
1198 /* There is one error bit... I'm assuming it is a parity error indicator 1247 /* There is one error bit... I'm assuming it is a parity error
1199 * as the generic firmware will set this bit to 1 if a parity error occurs. 1248 * indicator as the generic firmware will set this bit to 1 if a
1200 * I can not find reference to any other error events. 1249 * parity error occurs.
1201 * 1250 * I can not find reference to any other error events. */
1202 */
1203 spin_lock_irqsave(&priv->lock, flags); 1251 spin_lock_irqsave(&priv->lock, flags);
1204 if (priv->current_status & CYP_ERROR) { 1252 if (priv->current_status & CYP_ERROR) {
1205 spin_unlock_irqrestore(&priv->lock, flags); 1253 spin_unlock_irqrestore(&priv->lock, flags);
@@ -1211,7 +1259,8 @@ static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs)
1211 /* process read if there is data other than line status */ 1259 /* process read if there is data other than line status */
1212 if (tty && (bytes > i)) { 1260 if (tty && (bytes > i)) {
1213 for (; i < bytes ; ++i) { 1261 for (; i < bytes ; ++i) {
1214 dbg("pushing byte number %d - %d - %c",i,data[i],data[i]); 1262 dbg("pushing byte number %d - %d - %c", i, data[i],
1263 data[i]);
1215 if(tty->flip.count >= TTY_FLIPBUF_SIZE) { 1264 if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
1216 tty_flip_buffer_push(tty); 1265 tty_flip_buffer_push(tty);
1217 } 1266 }
@@ -1221,25 +1270,28 @@ static void cypress_read_int_callback(struct urb *urb, struct pt_regs *regs)
1221 } 1270 }
1222 1271
1223 spin_lock_irqsave(&priv->lock, flags); 1272 spin_lock_irqsave(&priv->lock, flags);
1224 priv->bytes_in += bytes; /* control and status byte(s) are also counted */ 1273 /* control and status byte(s) are also counted */
1274 priv->bytes_in += bytes;
1225 spin_unlock_irqrestore(&priv->lock, flags); 1275 spin_unlock_irqrestore(&priv->lock, flags);
1226 1276
1227continue_read: 1277continue_read:
1228 1278
1229 /* Continue trying to always read... unless the port has closed. */ 1279 /* Continue trying to always read... unless the port has closed. */
1230 1280
1231 if (port->open_count > 0) { 1281 if (port->open_count > 0) {
1232 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, 1282 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
1233 usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress), 1283 usb_rcvintpipe(port->serial->dev,
1234 port->interrupt_in_urb->transfer_buffer, 1284 port->interrupt_in_endpointAddress),
1235 port->interrupt_in_urb->transfer_buffer_length, 1285 port->interrupt_in_urb->transfer_buffer,
1236 cypress_read_int_callback, port, 1286 port->interrupt_in_urb->transfer_buffer_length,
1237 interval); 1287 cypress_read_int_callback, port, interval);
1238 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1288 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1239 if (result) 1289 if (result)
1240 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); 1290 dev_err(&urb->dev->dev, "%s - failed resubmitting "
1291 "read urb, error %d\n", __FUNCTION__,
1292 result);
1241 } 1293 }
1242 1294
1243 return; 1295 return;
1244} /* cypress_read_int_callback */ 1296} /* cypress_read_int_callback */
1245 1297
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index d1964a0c4168..4e434cb10bb1 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -269,6 +269,8 @@
269#define DRIVER_DESC "USB FTDI Serial Converters Driver" 269#define DRIVER_DESC "USB FTDI Serial Converters Driver"
270 270
271static int debug; 271static int debug;
272static __u16 vendor = FTDI_VID;
273static __u16 product;
272 274
273/* struct ftdi_sio_quirk is used by devices requiring special attention. */ 275/* struct ftdi_sio_quirk is used by devices requiring special attention. */
274struct ftdi_sio_quirk { 276struct ftdi_sio_quirk {
@@ -407,6 +409,34 @@ static struct usb_device_id id_table_combined [] = {
407 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88F_PID) }, 409 { USB_DEVICE(FTDI_VID, FTDI_GUDEADS_E88F_PID) },
408 { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) }, 410 { USB_DEVICE(FTDI_VID, FTDI_ELV_UO100_PID) },
409 { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) }, 411 { USB_DEVICE(FTDI_VID, FTDI_ELV_UM100_PID) },
412 { USB_DEVICE(FTDI_VID, FTDI_ELV_UR100_PID) },
413 { USB_DEVICE(FTDI_VID, FTDI_ELV_ALC8500_PID) },
414 /*
415 * These will probably use user-space drivers. Uncomment them if
416 * you need them or use the user-specified vendor/product module
417 * parameters (see ftdi_sio.h for the numbers). Make a fuss if
418 * you think the driver should recognize any of them by default.
419 */
420 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) }, */
421 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) }, */
422 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) }, */
423 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDF77_PID) }, */
424 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UIO88_PID) }, */
425 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UAD8_PID) }, */
426 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_UDA7_PID) }, */
427 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_USI2_PID) }, */
428 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_T1100_PID) }, */
429 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCD200_PID) }, */
430 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_ULA200_PID) }, */
431 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1000PC_PID) }, */
432 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_CSI8_PID) }, */
433 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1000DL_PID) }, */
434 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, */
435 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) }, */
436 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) }, */
437 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) }, */
438 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) }, */
439 /* { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) }, */
410 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) }, 440 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
411 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) }, 441 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
412 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) }, 442 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
@@ -418,6 +448,7 @@ static struct usb_device_id id_table_combined [] = {
418 { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) }, 448 { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) },
419 { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) }, 449 { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) },
420 { USB_DEVICE(FALCOM_VID, FALCOM_TWIST_PID) }, 450 { USB_DEVICE(FALCOM_VID, FALCOM_TWIST_PID) },
451 { USB_DEVICE(FALCOM_VID, FALCOM_SAMBA_PID) },
421 { USB_DEVICE(FTDI_VID, FTDI_SUUNTO_SPORTS_PID) }, 452 { USB_DEVICE(FTDI_VID, FTDI_SUUNTO_SPORTS_PID) },
422 { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) }, 453 { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) },
423 { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) }, 454 { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) },
@@ -427,12 +458,21 @@ static struct usb_device_id id_table_combined [] = {
427 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_0_PID) }, 458 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_0_PID) },
428 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) }, 459 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) },
429 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) }, 460 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
461 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_0_PID) },
462 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_1_PID) },
463 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_2_PID) },
464 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_3_PID) },
465 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_4_PID) },
466 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_5_PID) },
467 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_6_PID) },
468 { USB_DEVICE(FTDI_VID, XSENS_CONVERTER_7_PID) },
430 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) }, 469 { USB_DEVICE(MOBILITY_VID, MOBILITY_USB_SERIAL_PID) },
431 { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) }, 470 { USB_DEVICE(FTDI_VID, FTDI_ACTIVE_ROBOTS_PID) },
432 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) }, 471 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y6_PID) },
433 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) }, 472 { USB_DEVICE(FTDI_VID, FTDI_MHAM_Y8_PID) },
434 { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) }, 473 { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) },
435 { } /* Terminating entry */ 474 { }, /* Optional parameter entry */
475 { } /* Terminating entry */
436}; 476};
437 477
438MODULE_DEVICE_TABLE (usb, id_table_combined); 478MODULE_DEVICE_TABLE (usb, id_table_combined);
@@ -874,7 +914,7 @@ static void ftdi_determine_type(struct usb_serial_port *port)
874 unsigned interfaces; 914 unsigned interfaces;
875 915
876 /* Assume it is not the original SIO device for now. */ 916 /* Assume it is not the original SIO device for now. */
877 priv->baud_base = 48000000 / 16; 917 priv->baud_base = 48000000 / 2;
878 priv->write_offset = 0; 918 priv->write_offset = 0;
879 919
880 version = le16_to_cpu(udev->descriptor.bcdDevice); 920 version = le16_to_cpu(udev->descriptor.bcdDevice);
@@ -2030,6 +2070,15 @@ static int __init ftdi_init (void)
2030 int retval; 2070 int retval;
2031 2071
2032 dbg("%s", __FUNCTION__); 2072 dbg("%s", __FUNCTION__);
2073 if (vendor > 0 && product > 0) {
2074 /* Add user specified VID/PID to reserved element of table. */
2075 int i;
2076 for (i = 0; id_table_combined[i].idVendor; i++)
2077 ;
2078 id_table_combined[i].match_flags = USB_DEVICE_ID_MATCH_DEVICE;
2079 id_table_combined[i].idVendor = vendor;
2080 id_table_combined[i].idProduct = product;
2081 }
2033 retval = usb_serial_register(&ftdi_sio_device); 2082 retval = usb_serial_register(&ftdi_sio_device);
2034 if (retval) 2083 if (retval)
2035 goto failed_sio_register; 2084 goto failed_sio_register;
@@ -2066,4 +2115,9 @@ MODULE_LICENSE("GPL");
2066 2115
2067module_param(debug, bool, S_IRUGO | S_IWUSR); 2116module_param(debug, bool, S_IRUGO | S_IWUSR);
2068MODULE_PARM_DESC(debug, "Debug enabled or not"); 2117MODULE_PARM_DESC(debug, "Debug enabled or not");
2118module_param(vendor, ushort, 0);
2119MODULE_PARM_DESC(vendor, "User specified vendor ID (default="
2120 __MODULE_STRING(FTDI_VID)")");
2121module_param(product, ushort, 0);
2122MODULE_PARM_DESC(vendor, "User specified product ID");
2069 2123
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 9f4342093e8b..2c35d74cc6d6 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -142,10 +142,43 @@
142/* http://home.earthlink.net/~jrhees/USBUIRT/index.htm */ 142/* http://home.earthlink.net/~jrhees/USBUIRT/index.htm */
143#define FTDI_USB_UIRT_PID 0xF850 /* Product Id */ 143#define FTDI_USB_UIRT_PID 0xF850 /* Product Id */
144 144
145/* ELV USB Module UO100 (PID sent by Stefan Frings) */ 145/*
146#define FTDI_ELV_UO100_PID 0xFB58 /* Product Id */ 146 * ELV USB devices submitted by Christian Abt of ELV (www.elv.de).
147/* ELV USB Module UM100 (PID sent by Arnim Laeuger) */ 147 * All of these devices use FTDI's vendor ID (0x0403).
148#define FTDI_ELV_UM100_PID 0xFB5A /* Product Id */ 148 *
149 * The previously included PID for the UO 100 module was incorrect.
150 * In fact, that PID was for ELV's UR 100 USB-RS232 converter (0xFB58).
151 *
152 * Armin Laeuger originally sent the PID for the UM 100 module.
153 */
154#define FTDI_ELV_UR100_PID 0xFB58 /* USB-RS232-Umsetzer (UR 100) */
155#define FTDI_ELV_UM100_PID 0xFB5A /* USB-Modul UM 100 */
156#define FTDI_ELV_UO100_PID 0xFB5B /* USB-Modul UO 100 */
157#define FTDI_ELV_ALC8500_PID 0xF06E /* ALC 8500 Expert */
158/* Additional ELV PIDs that default to using the FTDI D2XX drivers on
159 * MS Windows, rather than the FTDI Virtual Com Port drivers.
160 * Maybe these will be easier to use with the libftdi/libusb user-space
161 * drivers, or possibly the Comedi drivers in some cases. */
162#define FTDI_ELV_CLI7000_PID 0xFB59 /* Computer-Light-Interface (CLI 7000) */
163#define FTDI_ELV_PPS7330_PID 0xFB5C /* Processor-Power-Supply (PPS 7330) */
164#define FTDI_ELV_TFM100_PID 0xFB5D /* Temperartur-Feuchte Messgeraet (TFM 100) */
165#define FTDI_ELV_UDF77_PID 0xFB5E /* USB DCF Funkurh (UDF 77) */
166#define FTDI_ELV_UIO88_PID 0xFB5F /* USB-I/O Interface (UIO 88) */
167#define FTDI_ELV_UAD8_PID 0xF068 /* USB-AD-Wandler (UAD 8) */
168#define FTDI_ELV_UDA7_PID 0xF069 /* USB-DA-Wandler (UDA 7) */
169#define FTDI_ELV_USI2_PID 0xF06A /* USB-Schrittmotoren-Interface (USI 2) */
170#define FTDI_ELV_T1100_PID 0xF06B /* Thermometer (T 1100) */
171#define FTDI_ELV_PCD200_PID 0xF06C /* PC-Datenlogger (PCD 200) */
172#define FTDI_ELV_ULA200_PID 0xF06D /* USB-LCD-Ansteuerung (ULA 200) */
173#define FTDI_ELV_FHZ1000PC_PID 0xF06F /* FHZ 1000 PC */
174#define FTDI_ELV_CSI8_PID 0xE0F0 /* Computer-Schalt-Interface (CSI 8) */
175#define FTDI_ELV_EM1000DL_PID 0xE0F1 /* PC-Datenlogger fuer Energiemonitor (EM 1000 DL) */
176#define FTDI_ELV_PCK100_PID 0xE0F2 /* PC-Kabeltester (PCK 100) */
177#define FTDI_ELV_RFP500_PID 0xE0F3 /* HF-Leistungsmesser (RFP 500) */
178#define FTDI_ELV_FS20SIG_PID 0xE0F4 /* Signalgeber (FS 20 SIG) */
179#define FTDI_ELV_WS300PC_PID 0xE0F6 /* PC-Wetterstation (WS 300 PC) */
180#define FTDI_ELV_FHZ1300PC_PID 0xE0E8 /* FHZ 1300 PC */
181#define FTDI_ELV_WS500_PID 0xE0E9 /* PC-Wetterstation (WS 500) */
149 182
150/* 183/*
151 * Definitions for ID TECH (www.idt-net.com) devices 184 * Definitions for ID TECH (www.idt-net.com) devices
@@ -222,6 +255,7 @@
222 */ 255 */
223#define FALCOM_VID 0x0F94 /* Vendor Id */ 256#define FALCOM_VID 0x0F94 /* Vendor Id */
224#define FALCOM_TWIST_PID 0x0001 /* Falcom Twist USB GPRS modem */ 257#define FALCOM_TWIST_PID 0x0001 /* Falcom Twist USB GPRS modem */
258#define FALCOM_SAMBA_PID 0x0005 /* Falcom Samba USB GPRS modem */
225 259
226/* 260/*
227 * SUUNTO product ids 261 * SUUNTO product ids
@@ -277,6 +311,18 @@
277#define FTDI_ACTIVE_ROBOTS_PID 0xE548 /* USB comms board */ 311#define FTDI_ACTIVE_ROBOTS_PID 0xE548 /* USB comms board */
278 312
279/* 313/*
314 * Xsens Technologies BV products (http://www.xsens.com).
315 */
316#define XSENS_CONVERTER_0_PID 0xD388
317#define XSENS_CONVERTER_1_PID 0xD389
318#define XSENS_CONVERTER_2_PID 0xD38A
319#define XSENS_CONVERTER_3_PID 0xD38B
320#define XSENS_CONVERTER_4_PID 0xD38C
321#define XSENS_CONVERTER_5_PID 0xD38D
322#define XSENS_CONVERTER_6_PID 0xD38E
323#define XSENS_CONVERTER_7_PID 0xD38F
324
325/*
280 * Evolution Robotics products (http://www.evolution.com/). 326 * Evolution Robotics products (http://www.evolution.com/).
281 * Submitted by Shawn M. Lavelle. 327 * Submitted by Shawn M. Lavelle.
282 */ 328 */
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index fb0926292228..3b958e60f5e8 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -383,11 +383,8 @@ static int keyspan_write(struct usb_serial_port *port,
383 dbg("%s - endpoint %d flip %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), flip); 383 dbg("%s - endpoint %d flip %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), flip);
384 384
385 if (this_urb->status == -EINPROGRESS) { 385 if (this_urb->status == -EINPROGRESS) {
386 if (this_urb->transfer_flags & URB_ASYNC_UNLINK)
387 break;
388 if (time_before(jiffies, p_priv->tx_start_time[flip] + 10 * HZ)) 386 if (time_before(jiffies, p_priv->tx_start_time[flip] + 10 * HZ))
389 break; 387 break;
390 this_urb->transfer_flags |= URB_ASYNC_UNLINK;
391 usb_unlink_urb(this_urb); 388 usb_unlink_urb(this_urb);
392 break; 389 break;
393 } 390 }
@@ -402,7 +399,6 @@ static int keyspan_write(struct usb_serial_port *port,
402 /* send the data out the bulk port */ 399 /* send the data out the bulk port */
403 this_urb->transfer_buffer_length = todo + dataOffset; 400 this_urb->transfer_buffer_length = todo + dataOffset;
404 401
405 this_urb->transfer_flags &= ~URB_ASYNC_UNLINK;
406 this_urb->dev = port->serial->dev; 402 this_urb->dev = port->serial->dev;
407 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) { 403 if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
408 dbg("usb_submit_urb(write bulk) failed (%d)", err); 404 dbg("usb_submit_urb(write bulk) failed (%d)", err);
@@ -1119,10 +1115,8 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
1119 1115
1120static inline void stop_urb(struct urb *urb) 1116static inline void stop_urb(struct urb *urb)
1121{ 1117{
1122 if (urb && urb->status == -EINPROGRESS) { 1118 if (urb && urb->status == -EINPROGRESS)
1123 urb->transfer_flags &= ~URB_ASYNC_UNLINK;
1124 usb_kill_urb(urb); 1119 usb_kill_urb(urb);
1125 }
1126} 1120}
1127 1121
1128static void keyspan_close(struct usb_serial_port *port, struct file *filp) 1122static void keyspan_close(struct usb_serial_port *port, struct file *filp)
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index e9256408757f..92d0f925d053 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -45,29 +45,29 @@
45#include "usb-serial.h" 45#include "usb-serial.h"
46 46
47/* Function prototypes */ 47/* Function prototypes */
48static int option_open (struct usb_serial_port *port, struct file *filp); 48static int option_open(struct usb_serial_port *port, struct file *filp);
49static void option_close (struct usb_serial_port *port, struct file *filp); 49static void option_close(struct usb_serial_port *port, struct file *filp);
50static int option_startup (struct usb_serial *serial); 50static int option_startup(struct usb_serial *serial);
51static void option_shutdown (struct usb_serial *serial); 51static void option_shutdown(struct usb_serial *serial);
52static void option_rx_throttle (struct usb_serial_port *port); 52static void option_rx_throttle(struct usb_serial_port *port);
53static void option_rx_unthrottle (struct usb_serial_port *port); 53static void option_rx_unthrottle(struct usb_serial_port *port);
54static int option_write_room (struct usb_serial_port *port); 54static int option_write_room(struct usb_serial_port *port);
55 55
56static void option_instat_callback(struct urb *urb, struct pt_regs *regs); 56static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
57 57
58static int option_write (struct usb_serial_port *port, 58static int option_write(struct usb_serial_port *port,
59 const unsigned char *buf, int count); 59 const unsigned char *buf, int count);
60 60
61static int option_chars_in_buffer (struct usb_serial_port *port); 61static int option_chars_in_buffer(struct usb_serial_port *port);
62static int option_ioctl (struct usb_serial_port *port, struct file *file, 62static int option_ioctl(struct usb_serial_port *port, struct file *file,
63 unsigned int cmd, unsigned long arg); 63 unsigned int cmd, unsigned long arg);
64static void option_set_termios (struct usb_serial_port *port, 64static void option_set_termios(struct usb_serial_port *port,
65 struct termios *old); 65 struct termios *old);
66static void option_break_ctl (struct usb_serial_port *port, int break_state); 66static void option_break_ctl(struct usb_serial_port *port, int break_state);
67static int option_tiocmget (struct usb_serial_port *port, struct file *file); 67static int option_tiocmget(struct usb_serial_port *port, struct file *file);
68static int option_tiocmset (struct usb_serial_port *port, struct file *file, 68static int option_tiocmset(struct usb_serial_port *port, struct file *file,
69 unsigned int set, unsigned int clear); 69 unsigned int set, unsigned int clear);
70static int option_send_setup (struct usb_serial_port *port); 70static int option_send_setup(struct usb_serial_port *port);
71 71
72/* Vendor and product IDs */ 72/* Vendor and product IDs */
73#define OPTION_VENDOR_ID 0x0AF0 73#define OPTION_VENDOR_ID 0x0AF0
@@ -76,7 +76,6 @@ static int option_send_setup (struct usb_serial_port *port);
76#define OPTION_PRODUCT_FUSION 0x6000 76#define OPTION_PRODUCT_FUSION 0x6000
77#define OPTION_PRODUCT_FUSION2 0x6300 77#define OPTION_PRODUCT_FUSION2 0x6300
78 78
79
80static struct usb_device_id option_ids[] = { 79static struct usb_device_id option_ids[] = {
81 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) }, 80 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
82 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) }, 81 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
@@ -129,7 +128,6 @@ static int debug;
129#define debug 0 128#define debug 0
130#endif 129#endif
131 130
132
133/* per port private data */ 131/* per port private data */
134 132
135#define N_IN_URB 4 133#define N_IN_URB 4
@@ -156,10 +154,8 @@ struct option_port_private {
156 unsigned long tx_start_time[N_OUT_URB]; 154 unsigned long tx_start_time[N_OUT_URB];
157}; 155};
158 156
159
160/* Functions used by new usb-serial code. */ 157/* Functions used by new usb-serial code. */
161static int __init 158static int __init option_init(void)
162option_init (void)
163{ 159{
164 int retval; 160 int retval;
165 retval = usb_serial_register(&option_3port_device); 161 retval = usb_serial_register(&option_3port_device);
@@ -179,8 +175,7 @@ failed_3port_device_register:
179 return retval; 175 return retval;
180} 176}
181 177
182static void __exit 178static void __exit option_exit(void)
183option_exit (void)
184{ 179{
185 usb_deregister (&option_driver); 180 usb_deregister (&option_driver);
186 usb_serial_deregister (&option_3port_device); 181 usb_serial_deregister (&option_3port_device);
@@ -189,39 +184,31 @@ option_exit (void)
189module_init(option_init); 184module_init(option_init);
190module_exit(option_exit); 185module_exit(option_exit);
191 186
192static void 187static void option_rx_throttle(struct usb_serial_port *port)
193option_rx_throttle (struct usb_serial_port *port)
194{ 188{
195 dbg("%s", __FUNCTION__); 189 dbg("%s", __FUNCTION__);
196} 190}
197 191
198 192static void option_rx_unthrottle(struct usb_serial_port *port)
199static void
200option_rx_unthrottle (struct usb_serial_port *port)
201{ 193{
202 dbg("%s", __FUNCTION__); 194 dbg("%s", __FUNCTION__);
203} 195}
204 196
205 197static void option_break_ctl(struct usb_serial_port *port, int break_state)
206static void
207option_break_ctl (struct usb_serial_port *port, int break_state)
208{ 198{
209 /* Unfortunately, I don't know how to send a break */ 199 /* Unfortunately, I don't know how to send a break */
210 dbg("%s", __FUNCTION__); 200 dbg("%s", __FUNCTION__);
211} 201}
212 202
213 203static void option_set_termios(struct usb_serial_port *port,
214static void 204 struct termios *old_termios)
215option_set_termios (struct usb_serial_port *port,
216 struct termios *old_termios)
217{ 205{
218 dbg("%s", __FUNCTION__); 206 dbg("%s", __FUNCTION__);
219 207
220 option_send_setup(port); 208 option_send_setup(port);
221} 209}
222 210
223static int 211static int option_tiocmget(struct usb_serial_port *port, struct file *file)
224option_tiocmget (struct usb_serial_port *port, struct file *file)
225{ 212{
226 unsigned int value; 213 unsigned int value;
227 struct option_port_private *portdata; 214 struct option_port_private *portdata;
@@ -238,9 +225,8 @@ option_tiocmget (struct usb_serial_port *port, struct file *file)
238 return value; 225 return value;
239} 226}
240 227
241static int 228static int option_tiocmset(struct usb_serial_port *port, struct file *file,
242option_tiocmset (struct usb_serial_port *port, struct file *file, 229 unsigned int set, unsigned int clear)
243 unsigned int set, unsigned int clear)
244{ 230{
245 struct option_port_private *portdata; 231 struct option_port_private *portdata;
246 232
@@ -258,17 +244,15 @@ option_tiocmset (struct usb_serial_port *port, struct file *file,
258 return option_send_setup(port); 244 return option_send_setup(port);
259} 245}
260 246
261static int 247static int option_ioctl(struct usb_serial_port *port, struct file *file,
262option_ioctl (struct usb_serial_port *port, struct file *file, 248 unsigned int cmd, unsigned long arg)
263 unsigned int cmd, unsigned long arg)
264{ 249{
265 return -ENOIOCTLCMD; 250 return -ENOIOCTLCMD;
266} 251}
267 252
268/* Write */ 253/* Write */
269static int 254static int option_write(struct usb_serial_port *port,
270option_write (struct usb_serial_port *port, 255 const unsigned char *buf, int count)
271 const unsigned char *buf, int count)
272{ 256{
273 struct option_port_private *portdata; 257 struct option_port_private *portdata;
274 int i; 258 int i;
@@ -289,28 +273,29 @@ option_write (struct usb_serial_port *port,
289 273
290 this_urb = portdata->out_urbs[i]; 274 this_urb = portdata->out_urbs[i];
291 if (this_urb->status == -EINPROGRESS) { 275 if (this_urb->status == -EINPROGRESS) {
292 if (this_urb->transfer_flags & URB_ASYNC_UNLINK) 276 if (time_before(jiffies,
293 continue; 277 portdata->tx_start_time[i] + 10 * HZ))
294 if (time_before(jiffies, portdata->tx_start_time[i] + 10 * HZ))
295 continue; 278 continue;
296 this_urb->transfer_flags |= URB_ASYNC_UNLINK;
297 usb_unlink_urb(this_urb); 279 usb_unlink_urb(this_urb);
298 continue; 280 continue;
299 } 281 }
300 if (this_urb->status != 0) 282 if (this_urb->status != 0)
301 dbg("usb_write %p failed (err=%d)", this_urb, this_urb->status); 283 dbg("usb_write %p failed (err=%d)",
284 this_urb, this_urb->status);
302 285
303 dbg("%s: endpoint %d buf %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), i); 286 dbg("%s: endpoint %d buf %d", __FUNCTION__,
287 usb_pipeendpoint(this_urb->pipe), i);
304 288
305 /* send the data */ 289 /* send the data */
306 memcpy (this_urb->transfer_buffer, buf, todo); 290 memcpy (this_urb->transfer_buffer, buf, todo);
307 this_urb->transfer_buffer_length = todo; 291 this_urb->transfer_buffer_length = todo;
308 292
309 this_urb->transfer_flags &= ~URB_ASYNC_UNLINK;
310 this_urb->dev = port->serial->dev; 293 this_urb->dev = port->serial->dev;
311 err = usb_submit_urb(this_urb, GFP_ATOMIC); 294 err = usb_submit_urb(this_urb, GFP_ATOMIC);
312 if (err) { 295 if (err) {
313 dbg("usb_submit_urb %p (write bulk) failed (%d, has %d)", this_urb, err, this_urb->status); 296 dbg("usb_submit_urb %p (write bulk) failed "
297 "(%d, has %d)", this_urb,
298 err, this_urb->status);
314 continue; 299 continue;
315 } 300 }
316 portdata->tx_start_time[i] = jiffies; 301 portdata->tx_start_time[i] = jiffies;
@@ -323,8 +308,7 @@ option_write (struct usb_serial_port *port,
323 return count; 308 return count;
324} 309}
325 310
326static void 311static void option_indat_callback(struct urb *urb, struct pt_regs *regs)
327option_indat_callback (struct urb *urb, struct pt_regs *regs)
328{ 312{
329 int i, err; 313 int i, err;
330 int endpoint; 314 int endpoint;
@@ -357,14 +341,14 @@ option_indat_callback (struct urb *urb, struct pt_regs *regs)
357 if (port->open_count && urb->status != -ESHUTDOWN) { 341 if (port->open_count && urb->status != -ESHUTDOWN) {
358 err = usb_submit_urb(urb, GFP_ATOMIC); 342 err = usb_submit_urb(urb, GFP_ATOMIC);
359 if (err) 343 if (err)
360 printk(KERN_ERR "%s: resubmit read urb failed. (%d)", __FUNCTION__, err); 344 printk(KERN_ERR "%s: resubmit read urb failed. "
345 "(%d)", __FUNCTION__, err);
361 } 346 }
362 } 347 }
363 return; 348 return;
364} 349}
365 350
366static void 351static void option_outdat_callback(struct urb *urb, struct pt_regs *regs)
367option_outdat_callback (struct urb *urb, struct pt_regs *regs)
368{ 352{
369 struct usb_serial_port *port; 353 struct usb_serial_port *port;
370 354
@@ -376,8 +360,7 @@ option_outdat_callback (struct urb *urb, struct pt_regs *regs)
376 schedule_work(&port->work); 360 schedule_work(&port->work);
377} 361}
378 362
379static void 363static void option_instat_callback(struct urb *urb, struct pt_regs *regs)
380option_instat_callback (struct urb *urb, struct pt_regs *regs)
381{ 364{
382 int err; 365 int err;
383 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 366 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
@@ -395,10 +378,12 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
395 dbg("%s: NULL req_pkt\n", __FUNCTION__); 378 dbg("%s: NULL req_pkt\n", __FUNCTION__);
396 return; 379 return;
397 } 380 }
398 if ((req_pkt->bRequestType == 0xA1) && (req_pkt->bRequest == 0x20)) { 381 if ((req_pkt->bRequestType == 0xA1) &&
382 (req_pkt->bRequest == 0x20)) {
399 int old_dcd_state; 383 int old_dcd_state;
400 unsigned char signals = *((unsigned char *) 384 unsigned char signals = *((unsigned char *)
401 urb->transfer_buffer + sizeof(struct usb_ctrlrequest)); 385 urb->transfer_buffer +
386 sizeof(struct usb_ctrlrequest));
402 387
403 dbg("%s: signal x%x", __FUNCTION__, signals); 388 dbg("%s: signal x%x", __FUNCTION__, signals);
404 389
@@ -408,12 +393,13 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
408 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 393 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
409 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 394 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
410 395
411 if (port->tty && !C_CLOCAL(port->tty) 396 if (port->tty && !C_CLOCAL(port->tty) &&
412 && old_dcd_state && !portdata->dcd_state) { 397 old_dcd_state && !portdata->dcd_state)
413 tty_hangup(port->tty); 398 tty_hangup(port->tty);
414 } 399 } else {
415 } else 400 dbg("%s: type %x req %x", __FUNCTION__,
416 dbg("%s: type %x req %x", __FUNCTION__, req_pkt->bRequestType,req_pkt->bRequest); 401 req_pkt->bRequestType,req_pkt->bRequest);
402 }
417 } else 403 } else
418 dbg("%s: error %d", __FUNCTION__, urb->status); 404 dbg("%s: error %d", __FUNCTION__, urb->status);
419 405
@@ -422,13 +408,12 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
422 urb->dev = serial->dev; 408 urb->dev = serial->dev;
423 err = usb_submit_urb(urb, GFP_ATOMIC); 409 err = usb_submit_urb(urb, GFP_ATOMIC);
424 if (err) 410 if (err)
425 dbg("%s: resubmit intr urb failed. (%d)", __FUNCTION__, err); 411 dbg("%s: resubmit intr urb failed. (%d)",
412 __FUNCTION__, err);
426 } 413 }
427} 414}
428 415
429 416static int option_write_room(struct usb_serial_port *port)
430static int
431option_write_room (struct usb_serial_port *port)
432{ 417{
433 struct option_port_private *portdata; 418 struct option_port_private *portdata;
434 int i; 419 int i;
@@ -447,9 +432,7 @@ option_write_room (struct usb_serial_port *port)
447 return data_len; 432 return data_len;
448} 433}
449 434
450 435static int option_chars_in_buffer(struct usb_serial_port *port)
451static int
452option_chars_in_buffer (struct usb_serial_port *port)
453{ 436{
454 struct option_port_private *portdata; 437 struct option_port_private *portdata;
455 int i; 438 int i;
@@ -467,9 +450,7 @@ option_chars_in_buffer (struct usb_serial_port *port)
467 return data_len; 450 return data_len;
468} 451}
469 452
470 453static int option_open(struct usb_serial_port *port, struct file *filp)
471static int
472option_open (struct usb_serial_port *port, struct file *filp)
473{ 454{
474 struct option_port_private *portdata; 455 struct option_port_private *portdata;
475 struct usb_serial *serial = port->serial; 456 struct usb_serial *serial = port->serial;
@@ -490,17 +471,21 @@ option_open (struct usb_serial_port *port, struct file *filp)
490 if (! urb) 471 if (! urb)
491 continue; 472 continue;
492 if (urb->dev != serial->dev) { 473 if (urb->dev != serial->dev) {
493 dbg("%s: dev %p != %p", __FUNCTION__, urb->dev, serial->dev); 474 dbg("%s: dev %p != %p", __FUNCTION__,
475 urb->dev, serial->dev);
494 continue; 476 continue;
495 } 477 }
496 478
497 /* make sure endpoint data toggle is synchronized with the device */ 479 /*
498 480 * make sure endpoint data toggle is synchronized with the
481 * device
482 */
499 usb_clear_halt(urb->dev, urb->pipe); 483 usb_clear_halt(urb->dev, urb->pipe);
500 484
501 err = usb_submit_urb(urb, GFP_KERNEL); 485 err = usb_submit_urb(urb, GFP_KERNEL);
502 if (err) { 486 if (err) {
503 dbg("%s: submit urb %d failed (%d) %d", __FUNCTION__, i, err, 487 dbg("%s: submit urb %d failed (%d) %d",
488 __FUNCTION__, i, err,
504 urb->transfer_buffer_length); 489 urb->transfer_buffer_length);
505 } 490 }
506 } 491 }
@@ -511,7 +496,8 @@ option_open (struct usb_serial_port *port, struct file *filp)
511 if (! urb) 496 if (! urb)
512 continue; 497 continue;
513 urb->dev = serial->dev; 498 urb->dev = serial->dev;
514 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */ 499 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
500 usb_pipeout(urb->pipe), 0); */
515 } 501 }
516 502
517 port->tty->low_latency = 1; 503 port->tty->low_latency = 1;
@@ -521,17 +507,13 @@ option_open (struct usb_serial_port *port, struct file *filp)
521 return (0); 507 return (0);
522} 508}
523 509
524static inline void 510static inline void stop_urb(struct urb *urb)
525stop_urb (struct urb *urb)
526{ 511{
527 if (urb && urb->status == -EINPROGRESS) { 512 if (urb && urb->status == -EINPROGRESS)
528 urb->transfer_flags &= ~URB_ASYNC_UNLINK;
529 usb_kill_urb(urb); 513 usb_kill_urb(urb);
530 }
531} 514}
532 515
533static void 516static void option_close(struct usb_serial_port *port, struct file *filp)
534option_close (struct usb_serial_port *port, struct file *filp)
535{ 517{
536 int i; 518 int i;
537 struct usb_serial *serial = port->serial; 519 struct usb_serial *serial = port->serial;
@@ -555,12 +537,10 @@ option_close (struct usb_serial_port *port, struct file *filp)
555 port->tty = NULL; 537 port->tty = NULL;
556} 538}
557 539
558
559/* Helper functions used by option_setup_urbs */ 540/* Helper functions used by option_setup_urbs */
560static struct urb * 541static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
561option_setup_urb (struct usb_serial *serial, int endpoint, 542 int dir, void *ctx, char *buf, int len,
562 int dir, void *ctx, char *buf, int len, 543 void (*callback)(struct urb *, struct pt_regs *regs))
563 void (*callback)(struct urb *, struct pt_regs *regs))
564{ 544{
565 struct urb *urb; 545 struct urb *urb;
566 546
@@ -582,8 +562,7 @@ option_setup_urb (struct usb_serial *serial, int endpoint,
582} 562}
583 563
584/* Setup urbs */ 564/* Setup urbs */
585static void 565static void option_setup_urbs(struct usb_serial *serial)
586option_setup_urbs (struct usb_serial *serial)
587{ 566{
588 int j; 567 int j;
589 struct usb_serial_port *port; 568 struct usb_serial_port *port;
@@ -609,9 +588,7 @@ option_setup_urbs (struct usb_serial *serial)
609 } 588 }
610} 589}
611 590
612 591static int option_send_setup(struct usb_serial_port *port)
613static int
614option_send_setup (struct usb_serial_port *port)
615{ 592{
616 struct usb_serial *serial = port->serial; 593 struct usb_serial *serial = port->serial;
617 struct option_port_private *portdata; 594 struct option_port_private *portdata;
@@ -627,16 +604,15 @@ option_send_setup (struct usb_serial_port *port)
627 if (portdata->rts_state) 604 if (portdata->rts_state)
628 val |= 0x02; 605 val |= 0x02;
629 606
630 return usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 607 return usb_control_msg(serial->dev,
631 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); 608 usb_rcvctrlpipe(serial->dev, 0),
609 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
632 } 610 }
633 611
634 return 0; 612 return 0;
635} 613}
636 614
637 615static int option_startup(struct usb_serial *serial)
638static int
639option_startup (struct usb_serial *serial)
640{ 616{
641 int i, err; 617 int i, err;
642 struct usb_serial_port *port; 618 struct usb_serial_port *port;
@@ -647,9 +623,10 @@ option_startup (struct usb_serial *serial)
647 /* Now setup per port private data */ 623 /* Now setup per port private data */
648 for (i = 0; i < serial->num_ports; i++) { 624 for (i = 0; i < serial->num_ports; i++) {
649 port = serial->port[i]; 625 port = serial->port[i];
650 portdata = kmalloc(sizeof(struct option_port_private), GFP_KERNEL); 626 portdata = kmalloc(sizeof(*portdata), GFP_KERNEL);
651 if (!portdata) { 627 if (!portdata) {
652 dbg("%s: kmalloc for option_port_private (%d) failed!.", __FUNCTION__, i); 628 dbg("%s: kmalloc for option_port_private (%d) failed!.",
629 __FUNCTION__, i);
653 return (1); 630 return (1);
654 } 631 }
655 memset(portdata, 0, sizeof(struct option_port_private)); 632 memset(portdata, 0, sizeof(struct option_port_private));
@@ -660,7 +637,8 @@ option_startup (struct usb_serial *serial)
660 continue; 637 continue;
661 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 638 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
662 if (err) 639 if (err)
663 dbg("%s: submit irq_in urb failed %d", __FUNCTION__, err); 640 dbg("%s: submit irq_in urb failed %d",
641 __FUNCTION__, err);
664 } 642 }
665 643
666 option_setup_urbs(serial); 644 option_setup_urbs(serial);
@@ -668,8 +646,7 @@ option_startup (struct usb_serial *serial)
668 return (0); 646 return (0);
669} 647}
670 648
671static void 649static void option_shutdown(struct usb_serial *serial)
672option_shutdown (struct usb_serial *serial)
673{ 650{
674 int i, j; 651 int i, j;
675 struct usb_serial_port *port; 652 struct usb_serial_port *port;
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 7eab5d4cf3a8..3cf245bdda54 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -95,6 +95,7 @@ static struct usb_device_id id_table [] = {
95 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_ID) }, 95 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_ID) },
96 { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65) }, 96 { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X65) },
97 { USB_DEVICE(SYNTECH_VENDOR_ID, SYNTECH_PRODUCT_ID) }, 97 { USB_DEVICE(SYNTECH_VENDOR_ID, SYNTECH_PRODUCT_ID) },
98 { USB_DEVICE( NOKIA_CA42_VENDOR_ID, NOKIA_CA42_PRODUCT_ID ) },
98 { } /* Terminating entry */ 99 { } /* Terminating entry */
99}; 100};
100 101
@@ -538,8 +539,10 @@ static int pl2303_open (struct usb_serial_port *port, struct file *filp)
538 539
539 dbg("%s - port %d", __FUNCTION__, port->number); 540 dbg("%s - port %d", __FUNCTION__, port->number);
540 541
541 usb_clear_halt(serial->dev, port->write_urb->pipe); 542 if (priv->type != HX) {
542 usb_clear_halt(serial->dev, port->read_urb->pipe); 543 usb_clear_halt(serial->dev, port->write_urb->pipe);
544 usb_clear_halt(serial->dev, port->read_urb->pipe);
545 }
543 546
544 buf = kmalloc(10, GFP_KERNEL); 547 buf = kmalloc(10, GFP_KERNEL);
545 if (buf==NULL) 548 if (buf==NULL)
@@ -650,8 +653,7 @@ static void pl2303_close (struct usb_serial_port *port, struct file *filp)
650 timeout = max((HZ*2560)/bps,HZ/10); 653 timeout = max((HZ*2560)/bps,HZ/10);
651 else 654 else
652 timeout = 2*HZ; 655 timeout = 2*HZ;
653 set_current_state(TASK_INTERRUPTIBLE); 656 schedule_timeout_interruptible(timeout);
654 schedule_timeout(timeout);
655 657
656 /* shutdown our urbs */ 658 /* shutdown our urbs */
657 dbg("%s - shutting down urbs", __FUNCTION__); 659 dbg("%s - shutting down urbs", __FUNCTION__);
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index b734c4003c5a..7be9644f5a03 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -58,3 +58,7 @@
58 58
59#define SYNTECH_VENDOR_ID 0x0745 59#define SYNTECH_VENDOR_ID 0x0745
60#define SYNTECH_PRODUCT_ID 0x0001 60#define SYNTECH_PRODUCT_ID 0x0001
61
62/* Nokia CA-42 Cable */
63#define NOKIA_CA42_VENDOR_ID 0x078b
64#define NOKIA_CA42_PRODUCT_ID 0x1234
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 0267b26dde18..e77fbdfc782d 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -531,7 +531,7 @@ bailout_kref_put:
531 531
532static void serial_close(struct tty_struct *tty, struct file * filp) 532static void serial_close(struct tty_struct *tty, struct file * filp)
533{ 533{
534 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 534 struct usb_serial_port *port = tty->driver_data;
535 535
536 if (!port) 536 if (!port)
537 return; 537 return;
@@ -561,7 +561,7 @@ static void serial_close(struct tty_struct *tty, struct file * filp)
561 561
562static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count) 562static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count)
563{ 563{
564 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 564 struct usb_serial_port *port = tty->driver_data;
565 int retval = -EINVAL; 565 int retval = -EINVAL;
566 566
567 dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count); 567 dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count);
@@ -580,7 +580,7 @@ exit:
580 580
581static int serial_write_room (struct tty_struct *tty) 581static int serial_write_room (struct tty_struct *tty)
582{ 582{
583 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 583 struct usb_serial_port *port = tty->driver_data;
584 int retval = -EINVAL; 584 int retval = -EINVAL;
585 585
586 dbg("%s - port %d", __FUNCTION__, port->number); 586 dbg("%s - port %d", __FUNCTION__, port->number);
@@ -599,7 +599,7 @@ exit:
599 599
600static int serial_chars_in_buffer (struct tty_struct *tty) 600static int serial_chars_in_buffer (struct tty_struct *tty)
601{ 601{
602 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 602 struct usb_serial_port *port = tty->driver_data;
603 int retval = -EINVAL; 603 int retval = -EINVAL;
604 604
605 dbg("%s = port %d", __FUNCTION__, port->number); 605 dbg("%s = port %d", __FUNCTION__, port->number);
@@ -618,7 +618,7 @@ exit:
618 618
619static void serial_throttle (struct tty_struct * tty) 619static void serial_throttle (struct tty_struct * tty)
620{ 620{
621 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 621 struct usb_serial_port *port = tty->driver_data;
622 622
623 dbg("%s - port %d", __FUNCTION__, port->number); 623 dbg("%s - port %d", __FUNCTION__, port->number);
624 624
@@ -634,7 +634,7 @@ static void serial_throttle (struct tty_struct * tty)
634 634
635static void serial_unthrottle (struct tty_struct * tty) 635static void serial_unthrottle (struct tty_struct * tty)
636{ 636{
637 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 637 struct usb_serial_port *port = tty->driver_data;
638 638
639 dbg("%s - port %d", __FUNCTION__, port->number); 639 dbg("%s - port %d", __FUNCTION__, port->number);
640 640
@@ -650,7 +650,7 @@ static void serial_unthrottle (struct tty_struct * tty)
650 650
651static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) 651static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg)
652{ 652{
653 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 653 struct usb_serial_port *port = tty->driver_data;
654 int retval = -ENODEV; 654 int retval = -ENODEV;
655 655
656 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); 656 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
@@ -672,7 +672,7 @@ exit:
672 672
673static void serial_set_termios (struct tty_struct *tty, struct termios * old) 673static void serial_set_termios (struct tty_struct *tty, struct termios * old)
674{ 674{
675 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 675 struct usb_serial_port *port = tty->driver_data;
676 676
677 dbg("%s - port %d", __FUNCTION__, port->number); 677 dbg("%s - port %d", __FUNCTION__, port->number);
678 678
@@ -688,7 +688,7 @@ static void serial_set_termios (struct tty_struct *tty, struct termios * old)
688 688
689static void serial_break (struct tty_struct *tty, int break_state) 689static void serial_break (struct tty_struct *tty, int break_state)
690{ 690{
691 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 691 struct usb_serial_port *port = tty->driver_data;
692 692
693 dbg("%s - port %d", __FUNCTION__, port->number); 693 dbg("%s - port %d", __FUNCTION__, port->number);
694 694
@@ -749,7 +749,7 @@ done:
749 749
750static int serial_tiocmget (struct tty_struct *tty, struct file *file) 750static int serial_tiocmget (struct tty_struct *tty, struct file *file)
751{ 751{
752 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 752 struct usb_serial_port *port = tty->driver_data;
753 753
754 dbg("%s - port %d", __FUNCTION__, port->number); 754 dbg("%s - port %d", __FUNCTION__, port->number);
755 755
@@ -768,7 +768,7 @@ exit:
768static int serial_tiocmset (struct tty_struct *tty, struct file *file, 768static int serial_tiocmset (struct tty_struct *tty, struct file *file,
769 unsigned int set, unsigned int clear) 769 unsigned int set, unsigned int clear)
770{ 770{
771 struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data; 771 struct usb_serial_port *port = tty->driver_data;
772 772
773 dbg("%s - port %d", __FUNCTION__, port->number); 773 dbg("%s - port %d", __FUNCTION__, port->number);
774 774
@@ -786,7 +786,7 @@ exit:
786 786
787void usb_serial_port_softint(void *private) 787void usb_serial_port_softint(void *private)
788{ 788{
789 struct usb_serial_port *port = (struct usb_serial_port *)private; 789 struct usb_serial_port *port = private;
790 struct tty_struct *tty; 790 struct tty_struct *tty;
791 791
792 dbg("%s - port %d", __FUNCTION__, port->number); 792 dbg("%s - port %d", __FUNCTION__, port->number);
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index f1f1c0608c22..bb9819cc8826 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -111,3 +111,15 @@ config USB_STORAGE_JUMPSHOT
111 Say Y here to include additional code to support the Lexar Jumpshot 111 Say Y here to include additional code to support the Lexar Jumpshot
112 USB CompactFlash reader. 112 USB CompactFlash reader.
113 113
114
115config USB_STORAGE_ONETOUCH
116 bool "Support OneTouch Button on Maxtor Hard Drives (EXPERIMENTAL)"
117 depends on USB_STORAGE && INPUT_EVDEV && EXPERIMENTAL
118 help
119 Say Y here to include additional code to support the Maxtor OneTouch
120 USB hard drive's onetouch button.
121
122 This code registers the button on the front of Maxtor OneTouch USB
123 hard drive's as an input device. An action can be associated with
124 this input in any keybinding software. (e.g. gnome's keyboard short-
125 cuts)
diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile
index 56652ccc2881..44ab8f9978fe 100644
--- a/drivers/usb/storage/Makefile
+++ b/drivers/usb/storage/Makefile
@@ -18,6 +18,7 @@ usb-storage-obj-$(CONFIG_USB_STORAGE_DPCM) += dpcm.o
18usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o 18usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o
19usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o 19usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o
20usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o 20usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o
21usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o
21 22
22usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ 23usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \
23 initializers.o $(usb-storage-obj-y) 24 initializers.o $(usb-storage-obj-y)
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
new file mode 100644
index 000000000000..2c9402dc702b
--- /dev/null
+++ b/drivers/usb/storage/onetouch.c
@@ -0,0 +1,210 @@
1/*
2 * Support for the Maxtor OneTouch USB hard drive's button
3 *
4 * Current development and maintenance by:
5 * Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu>
6 *
7 * Initial work by:
8 * Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se>
9 *
10 * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann)
11 *
12 */
13
14/*
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 */
30
31#include <linux/config.h>
32#include <linux/kernel.h>
33#include <linux/input.h>
34#include <linux/init.h>
35#include <linux/slab.h>
36#include <linux/module.h>
37#include <linux/usb.h>
38#include <linux/usb_ch9.h>
39#include <linux/usb_input.h>
40#include "usb.h"
41#include "onetouch.h"
42#include "debug.h"
43
44void onetouch_release_input(void *onetouch_);
45
46struct usb_onetouch {
47 char name[128];
48 char phys[64];
49 struct input_dev dev; /* input device interface */
50 struct usb_device *udev; /* usb device */
51
52 struct urb *irq; /* urb for interrupt in report */
53 unsigned char *data; /* input data */
54 dma_addr_t data_dma;
55};
56
57static void usb_onetouch_irq(struct urb *urb, struct pt_regs *regs)
58{
59 struct usb_onetouch *onetouch = urb->context;
60 signed char *data = onetouch->data;
61 struct input_dev *dev = &onetouch->dev;
62 int status;
63
64 switch (urb->status) {
65 case 0: /* success */
66 break;
67 case -ECONNRESET: /* unlink */
68 case -ENOENT:
69 case -ESHUTDOWN:
70 return;
71 /* -EPIPE: should clear the halt */
72 default: /* error */
73 goto resubmit;
74 }
75
76 input_regs(dev, regs);
77
78 input_report_key(&onetouch->dev, ONETOUCH_BUTTON,
79 data[0] & 0x02);
80
81 input_sync(dev);
82resubmit:
83 status = usb_submit_urb (urb, SLAB_ATOMIC);
84 if (status)
85 err ("can't resubmit intr, %s-%s/input0, status %d",
86 onetouch->udev->bus->bus_name,
87 onetouch->udev->devpath, status);
88}
89
90static int usb_onetouch_open(struct input_dev *dev)
91{
92 struct usb_onetouch *onetouch = dev->private;
93
94 onetouch->irq->dev = onetouch->udev;
95 if (usb_submit_urb(onetouch->irq, GFP_KERNEL)) {
96 err("usb_submit_urb failed");
97 return -EIO;
98 }
99
100 return 0;
101}
102
103static void usb_onetouch_close(struct input_dev *dev)
104{
105 struct usb_onetouch *onetouch = dev->private;
106
107 usb_kill_urb(onetouch->irq);
108}
109
110int onetouch_connect_input(struct us_data *ss)
111{
112 struct usb_device *udev = ss->pusb_dev;
113 struct usb_host_interface *interface;
114 struct usb_endpoint_descriptor *endpoint;
115 struct usb_onetouch *onetouch;
116 int pipe, maxp;
117 char path[64];
118
119 interface = ss->pusb_intf->cur_altsetting;
120
121 if (interface->desc.bNumEndpoints != 3)
122 return -ENODEV;
123
124 endpoint = &interface->endpoint[2].desc;
125 if(!(endpoint->bEndpointAddress & USB_DIR_IN))
126 return -ENODEV;
127 if((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
128 != USB_ENDPOINT_XFER_INT)
129 return -ENODEV;
130
131 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
132 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
133
134 if (!(onetouch = kcalloc(1, sizeof(struct usb_onetouch), GFP_KERNEL)))
135 return -ENOMEM;
136
137 onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN,
138 SLAB_ATOMIC, &onetouch->data_dma);
139 if (!onetouch->data){
140 kfree(onetouch);
141 return -ENOMEM;
142 }
143
144 onetouch->irq = usb_alloc_urb(0, GFP_KERNEL);
145 if (!onetouch->irq){
146 kfree(onetouch);
147 usb_buffer_free(udev, ONETOUCH_PKT_LEN,
148 onetouch->data, onetouch->data_dma);
149 return -ENODEV;
150 }
151
152
153 onetouch->udev = udev;
154
155 set_bit(EV_KEY, onetouch->dev.evbit);
156 set_bit(ONETOUCH_BUTTON, onetouch->dev.keybit);
157 clear_bit(0, onetouch->dev.keybit);
158
159 onetouch->dev.private = onetouch;
160 onetouch->dev.open = usb_onetouch_open;
161 onetouch->dev.close = usb_onetouch_close;
162
163 usb_make_path(udev, path, sizeof(path));
164 sprintf(onetouch->phys, "%s/input0", path);
165
166 onetouch->dev.name = onetouch->name;
167 onetouch->dev.phys = onetouch->phys;
168
169 usb_to_input_id(udev, &onetouch->dev.id);
170
171 onetouch->dev.dev = &udev->dev;
172
173 if (udev->manufacturer)
174 strcat(onetouch->name, udev->manufacturer);
175 if (udev->product)
176 sprintf(onetouch->name, "%s %s", onetouch->name,
177 udev->product);
178 if (!strlen(onetouch->name))
179 sprintf(onetouch->name, "Maxtor Onetouch %04x:%04x",
180 onetouch->dev.id.vendor, onetouch->dev.id.product);
181
182 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data,
183 (maxp > 8 ? 8 : maxp),
184 usb_onetouch_irq, onetouch, endpoint->bInterval);
185 onetouch->irq->transfer_dma = onetouch->data_dma;
186 onetouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
187
188 ss->extra_destructor = onetouch_release_input;
189 ss->extra = onetouch;
190
191 input_register_device(&onetouch->dev);
192 printk(KERN_INFO "usb-input: %s on %s\n", onetouch->dev.name, path);
193
194 return 0;
195}
196
197void onetouch_release_input(void *onetouch_)
198{
199 struct usb_onetouch *onetouch = (struct usb_onetouch *) onetouch_;
200
201 if (onetouch) {
202 usb_kill_urb(onetouch->irq);
203 input_unregister_device(&onetouch->dev);
204 usb_free_urb(onetouch->irq);
205 usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN,
206 onetouch->data, onetouch->data_dma);
207 printk(KERN_INFO "usb-input: deregistering %s\n",
208 onetouch->dev.name);
209 }
210}
diff --git a/drivers/usb/storage/onetouch.h b/drivers/usb/storage/onetouch.h
new file mode 100644
index 000000000000..41c7aa8f0446
--- /dev/null
+++ b/drivers/usb/storage/onetouch.h
@@ -0,0 +1,9 @@
1#ifndef _ONETOUCH_H_
2#define _ONETOUCH_H_
3
4#define ONETOUCH_PKT_LEN 0x02
5#define ONETOUCH_BUTTON KEY_PROG1
6
7int onetouch_connect_input(struct us_data *ss);
8
9#endif
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index af294bb68c35..4837524eada7 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -156,6 +156,14 @@ static int slave_configure(struct scsi_device *sdev)
156 if (us->flags & US_FL_FIX_CAPACITY) 156 if (us->flags & US_FL_FIX_CAPACITY)
157 sdev->fix_capacity = 1; 157 sdev->fix_capacity = 1;
158 158
159 /* Some devices report a SCSI revision level above 2 but are
160 * unable to handle the REPORT LUNS command (for which
161 * support is mandatory at level 3). Since we already have
162 * a Get-Max-LUN request, we won't lose much by setting the
163 * revision level down to 2. The only devices that would be
164 * affected are those with sparse LUNs. */
165 sdev->scsi_level = SCSI_2;
166
159 /* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable 167 /* USB-IDE bridges tend to report SK = 0x04 (Non-recoverable
160 * Hardware Error) when any low-level error occurs, 168 * Hardware Error) when any low-level error occurs,
161 * recoverable or not. Setting this flag tells the SCSI 169 * recoverable or not. Setting this flag tells the SCSI
@@ -219,42 +227,42 @@ static int queuecommand(struct scsi_cmnd *srb,
219 ***********************************************************************/ 227 ***********************************************************************/
220 228
221/* Command timeout and abort */ 229/* Command timeout and abort */
222/* This is always called with scsi_lock(host) held */
223static int command_abort(struct scsi_cmnd *srb) 230static int command_abort(struct scsi_cmnd *srb)
224{ 231{
225 struct us_data *us = host_to_us(srb->device->host); 232 struct us_data *us = host_to_us(srb->device->host);
226 233
227 US_DEBUGP("%s called\n", __FUNCTION__); 234 US_DEBUGP("%s called\n", __FUNCTION__);
228 235
236 /* us->srb together with the TIMED_OUT, RESETTING, and ABORTING
237 * bits are protected by the host lock. */
238 scsi_lock(us_to_host(us));
239
229 /* Is this command still active? */ 240 /* Is this command still active? */
230 if (us->srb != srb) { 241 if (us->srb != srb) {
242 scsi_unlock(us_to_host(us));
231 US_DEBUGP ("-- nothing to abort\n"); 243 US_DEBUGP ("-- nothing to abort\n");
232 return FAILED; 244 return FAILED;
233 } 245 }
234 246
235 /* Set the TIMED_OUT bit. Also set the ABORTING bit, but only if 247 /* Set the TIMED_OUT bit. Also set the ABORTING bit, but only if
236 * a device reset isn't already in progress (to avoid interfering 248 * a device reset isn't already in progress (to avoid interfering
237 * with the reset). To prevent races with auto-reset, we must 249 * with the reset). Note that we must retain the host lock while
238 * stop any ongoing USB transfers while still holding the host 250 * calling usb_stor_stop_transport(); otherwise it might interfere
239 * lock. */ 251 * with an auto-reset that begins as soon as we release the lock. */
240 set_bit(US_FLIDX_TIMED_OUT, &us->flags); 252 set_bit(US_FLIDX_TIMED_OUT, &us->flags);
241 if (!test_bit(US_FLIDX_RESETTING, &us->flags)) { 253 if (!test_bit(US_FLIDX_RESETTING, &us->flags)) {
242 set_bit(US_FLIDX_ABORTING, &us->flags); 254 set_bit(US_FLIDX_ABORTING, &us->flags);
243 usb_stor_stop_transport(us); 255 usb_stor_stop_transport(us);
244 } 256 }
257 scsi_unlock(us_to_host(us));
245 258
246 /* Wait for the aborted command to finish */ 259 /* Wait for the aborted command to finish */
247 wait_for_completion(&us->notify); 260 wait_for_completion(&us->notify);
248
249 /* Reacquire the lock and allow USB transfers to resume */
250 clear_bit(US_FLIDX_ABORTING, &us->flags);
251 clear_bit(US_FLIDX_TIMED_OUT, &us->flags);
252 return SUCCESS; 261 return SUCCESS;
253} 262}
254 263
255/* This invokes the transport reset mechanism to reset the state of the 264/* This invokes the transport reset mechanism to reset the state of the
256 * device */ 265 * device */
257/* This is always called with scsi_lock(host) held */
258static int device_reset(struct scsi_cmnd *srb) 266static int device_reset(struct scsi_cmnd *srb)
259{ 267{
260 struct us_data *us = host_to_us(srb->device->host); 268 struct us_data *us = host_to_us(srb->device->host);
@@ -271,7 +279,6 @@ static int device_reset(struct scsi_cmnd *srb)
271} 279}
272 280
273/* Simulate a SCSI bus reset by resetting the device's USB port. */ 281/* Simulate a SCSI bus reset by resetting the device's USB port. */
274/* This is always called with scsi_lock(host) held */
275static int bus_reset(struct scsi_cmnd *srb) 282static int bus_reset(struct scsi_cmnd *srb)
276{ 283{
277 struct us_data *us = host_to_us(srb->device->host); 284 struct us_data *us = host_to_us(srb->device->host);
@@ -283,7 +290,6 @@ static int bus_reset(struct scsi_cmnd *srb)
283 result = usb_stor_port_reset(us); 290 result = usb_stor_port_reset(us);
284 up(&(us->dev_semaphore)); 291 up(&(us->dev_semaphore));
285 292
286 /* lock the host for the return */
287 return result < 0 ? FAILED : SUCCESS; 293 return result < 0 ? FAILED : SUCCESS;
288} 294}
289 295
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index f3b60288696c..356342c6e7a2 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -839,34 +839,31 @@ static int usbat_identify_device(struct us_data *us,
839 rc = usbat_device_reset(us); 839 rc = usbat_device_reset(us);
840 if (rc != USB_STOR_TRANSPORT_GOOD) 840 if (rc != USB_STOR_TRANSPORT_GOOD)
841 return rc; 841 return rc;
842 msleep(25);
842 843
843 /* 844 /*
844 * By examining the device signature after a reset, we can identify 845 * In attempt to distinguish between HP CDRW's and Flash readers, we now
845 * whether the device supports the ATAPI packet interface. 846 * execute the IDENTIFY PACKET DEVICE command. On ATA devices (i.e. flash
846 * The flash-devices do not support this, whereas the HP CDRW's obviously 847 * readers), this command should fail with error. On ATAPI devices (i.e.
847 * do. 848 * CDROM drives), it should succeed.
848 *
849 * This method is not ideal, but works because no other devices have been
850 * produced based on the USBAT/USBAT02.
851 *
852 * Section 9.1 of the ATAPI-4 spec states (amongst other things) that
853 * after a device reset, a Cylinder low of 0x14 indicates that the device
854 * does support packet commands.
855 */ 849 */
856 rc = usbat_read(us, USBAT_ATA, USBAT_ATA_LBA_ME, &status); 850 rc = usbat_write(us, USBAT_ATA, USBAT_ATA_CMD, 0xA1);
857 if (rc != USB_STOR_XFER_GOOD) 851 if (rc != USB_STOR_XFER_GOOD)
858 return USB_STOR_TRANSPORT_ERROR; 852 return USB_STOR_TRANSPORT_ERROR;
859 853
860 US_DEBUGP("usbat_identify_device: Cylinder low is %02X\n", status); 854 rc = usbat_get_status(us, &status);
855 if (rc != USB_STOR_XFER_GOOD)
856 return USB_STOR_TRANSPORT_ERROR;
861 857
862 if (status == 0x14) { 858 // Check for error bit
859 if (status & 0x01) {
860 // Device is a CompactFlash reader/writer
861 US_DEBUGP("usbat_identify_device: Detected Flash reader/writer\n");
862 info->devicetype = USBAT_DEV_FLASH;
863 } else {
863 // Device is HP 8200 864 // Device is HP 8200
864 US_DEBUGP("usbat_identify_device: Detected HP8200 CDRW\n"); 865 US_DEBUGP("usbat_identify_device: Detected HP8200 CDRW\n");
865 info->devicetype = USBAT_DEV_HP8200; 866 info->devicetype = USBAT_DEV_HP8200;
866 } else {
867 // Device is a CompactFlash reader/writer
868 US_DEBUGP("usbat_identify_device: Detected Flash reader/writer\n");
869 info->devicetype = USBAT_DEV_FLASH;
870 } 867 }
871 868
872 return USB_STOR_TRANSPORT_GOOD; 869 return USB_STOR_TRANSPORT_GOOD;
@@ -1239,16 +1236,10 @@ static int usbat_select_and_test_registers(struct us_data *us)
1239{ 1236{
1240 int selector; 1237 int selector;
1241 unsigned char *status = us->iobuf; 1238 unsigned char *status = us->iobuf;
1242 unsigned char max_selector = 0xB0;
1243 if (usbat_get_device_type(us) == USBAT_DEV_FLASH)
1244 max_selector = 0xA0;
1245 1239
1246 // try device = master, then device = slave. 1240 // try device = master, then device = slave.
1247 1241 for (selector = 0xA0; selector <= 0xB0; selector += 0x10) {
1248 for (selector = 0xA0; selector <= max_selector; selector += 0x10) { 1242 if (usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) !=
1249
1250 if (usbat_get_device_type(us) == USBAT_DEV_HP8200 &&
1251 usbat_write(us, USBAT_ATA, USBAT_ATA_DEVICE, selector) !=
1252 USB_STOR_XFER_GOOD) 1243 USB_STOR_XFER_GOOD)
1253 return USB_STOR_TRANSPORT_ERROR; 1244 return USB_STOR_TRANSPORT_ERROR;
1254 1245
@@ -1334,60 +1325,30 @@ int init_usbat(struct us_data *us)
1334 1325
1335 US_DEBUGP("INIT 3\n"); 1326 US_DEBUGP("INIT 3\n");
1336 1327
1337 // At this point, we need to detect which device we are using
1338 if (usbat_set_transport(us, info))
1339 return USB_STOR_TRANSPORT_ERROR;
1340
1341 US_DEBUGP("INIT 4\n");
1342
1343 if (usbat_get_device_type(us) == USBAT_DEV_HP8200) {
1344 msleep(250);
1345
1346 // Write 0x80 to ISA port 0x3F
1347 rc = usbat_write(us, USBAT_ISA, 0x3F, 0x80);
1348 if (rc != USB_STOR_XFER_GOOD)
1349 return USB_STOR_TRANSPORT_ERROR;
1350
1351 US_DEBUGP("INIT 5\n");
1352
1353 // Read ISA port 0x27
1354 rc = usbat_read(us, USBAT_ISA, 0x27, status);
1355 if (rc != USB_STOR_XFER_GOOD)
1356 return USB_STOR_TRANSPORT_ERROR;
1357
1358 US_DEBUGP("INIT 6\n");
1359
1360 rc = usbat_read_user_io(us, status);
1361 if (rc != USB_STOR_XFER_GOOD)
1362 return USB_STOR_TRANSPORT_ERROR;
1363
1364 US_DEBUGP("INIT 7\n");
1365 }
1366
1367 rc = usbat_select_and_test_registers(us); 1328 rc = usbat_select_and_test_registers(us);
1368 if (rc != USB_STOR_TRANSPORT_GOOD) 1329 if (rc != USB_STOR_TRANSPORT_GOOD)
1369 return rc; 1330 return rc;
1370 1331
1371 US_DEBUGP("INIT 8\n"); 1332 US_DEBUGP("INIT 4\n");
1372 1333
1373 rc = usbat_read_user_io(us, status); 1334 rc = usbat_read_user_io(us, status);
1374 if (rc != USB_STOR_XFER_GOOD) 1335 if (rc != USB_STOR_XFER_GOOD)
1375 return USB_STOR_TRANSPORT_ERROR; 1336 return USB_STOR_TRANSPORT_ERROR;
1376 1337
1377 US_DEBUGP("INIT 9\n"); 1338 US_DEBUGP("INIT 5\n");
1378 1339
1379 // Enable peripheral control signals and card detect 1340 // Enable peripheral control signals and card detect
1380 rc = usbat_device_enable_cdt(us); 1341 rc = usbat_device_enable_cdt(us);
1381 if (rc != USB_STOR_TRANSPORT_GOOD) 1342 if (rc != USB_STOR_TRANSPORT_GOOD)
1382 return rc; 1343 return rc;
1383 1344
1384 US_DEBUGP("INIT 10\n"); 1345 US_DEBUGP("INIT 6\n");
1385 1346
1386 rc = usbat_read_user_io(us, status); 1347 rc = usbat_read_user_io(us, status);
1387 if (rc != USB_STOR_XFER_GOOD) 1348 if (rc != USB_STOR_XFER_GOOD)
1388 return USB_STOR_TRANSPORT_ERROR; 1349 return USB_STOR_TRANSPORT_ERROR;
1389 1350
1390 US_DEBUGP("INIT 11\n"); 1351 US_DEBUGP("INIT 7\n");
1391 1352
1392 msleep(1400); 1353 msleep(1400);
1393 1354
@@ -1395,13 +1356,19 @@ int init_usbat(struct us_data *us)
1395 if (rc != USB_STOR_XFER_GOOD) 1356 if (rc != USB_STOR_XFER_GOOD)
1396 return USB_STOR_TRANSPORT_ERROR; 1357 return USB_STOR_TRANSPORT_ERROR;
1397 1358
1398 US_DEBUGP("INIT 12\n"); 1359 US_DEBUGP("INIT 8\n");
1399 1360
1400 rc = usbat_select_and_test_registers(us); 1361 rc = usbat_select_and_test_registers(us);
1401 if (rc != USB_STOR_TRANSPORT_GOOD) 1362 if (rc != USB_STOR_TRANSPORT_GOOD)
1402 return rc; 1363 return rc;
1403 1364
1404 US_DEBUGP("INIT 13\n"); 1365 US_DEBUGP("INIT 9\n");
1366
1367 // At this point, we need to detect which device we are using
1368 if (usbat_set_transport(us, info))
1369 return USB_STOR_TRANSPORT_ERROR;
1370
1371 US_DEBUGP("INIT 10\n");
1405 1372
1406 if (usbat_get_device_type(us) == USBAT_DEV_FLASH) { 1373 if (usbat_get_device_type(us) == USBAT_DEV_FLASH) {
1407 subcountH = 0x02; 1374 subcountH = 0x02;
@@ -1412,7 +1379,7 @@ int init_usbat(struct us_data *us)
1412 if (rc != USB_STOR_XFER_GOOD) 1379 if (rc != USB_STOR_XFER_GOOD)
1413 return USB_STOR_TRANSPORT_ERROR; 1380 return USB_STOR_TRANSPORT_ERROR;
1414 1381
1415 US_DEBUGP("INIT 14\n"); 1382 US_DEBUGP("INIT 11\n");
1416 1383
1417 return USB_STOR_TRANSPORT_GOOD; 1384 return USB_STOR_TRANSPORT_GOOD;
1418} 1385}
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index e6b1c6cf07f2..c1ba5301ebfc 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -96,8 +96,8 @@
96 * or before the URB_ACTIVE bit was set. If so, it's essential to cancel 96 * or before the URB_ACTIVE bit was set. If so, it's essential to cancel
97 * the URB if it hasn't been cancelled already (i.e., if the URB_ACTIVE bit 97 * the URB if it hasn't been cancelled already (i.e., if the URB_ACTIVE bit
98 * is still set). Either way, the function must then wait for the URB to 98 * is still set). Either way, the function must then wait for the URB to
99 * finish. Note that because the URB_ASYNC_UNLINK flag is set, the URB can 99 * finish. Note that the URB can still be in progress even after a call to
100 * still be in progress even after a call to usb_unlink_urb() returns. 100 * usb_unlink_urb() returns.
101 * 101 *
102 * The idea is that (1) once the ABORTING or DISCONNECTING bit is set, 102 * The idea is that (1) once the ABORTING or DISCONNECTING bit is set,
103 * either the stop_transport() function or the submitting function 103 * either the stop_transport() function or the submitting function
@@ -158,8 +158,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
158 * hasn't been mapped for DMA. Yes, this is clunky, but it's 158 * hasn't been mapped for DMA. Yes, this is clunky, but it's
159 * easier than always having the caller tell us whether the 159 * easier than always having the caller tell us whether the
160 * transfer buffer has already been mapped. */ 160 * transfer buffer has already been mapped. */
161 us->current_urb->transfer_flags = 161 us->current_urb->transfer_flags = URB_NO_SETUP_DMA_MAP;
162 URB_ASYNC_UNLINK | URB_NO_SETUP_DMA_MAP;
163 if (us->current_urb->transfer_buffer == us->iobuf) 162 if (us->current_urb->transfer_buffer == us->iobuf)
164 us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 163 us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
165 us->current_urb->transfer_dma = us->iobuf_dma; 164 us->current_urb->transfer_dma = us->iobuf_dma;
@@ -611,7 +610,6 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
611 unsigned char old_sc_data_direction; 610 unsigned char old_sc_data_direction;
612 unsigned char old_cmd_len; 611 unsigned char old_cmd_len;
613 unsigned char old_cmnd[MAX_COMMAND_SIZE]; 612 unsigned char old_cmnd[MAX_COMMAND_SIZE];
614 unsigned long old_serial_number;
615 int old_resid; 613 int old_resid;
616 614
617 US_DEBUGP("Issuing auto-REQUEST_SENSE\n"); 615 US_DEBUGP("Issuing auto-REQUEST_SENSE\n");
@@ -648,10 +646,6 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
648 old_sg = srb->use_sg; 646 old_sg = srb->use_sg;
649 srb->use_sg = 0; 647 srb->use_sg = 0;
650 648
651 /* change the serial number -- toggle the high bit*/
652 old_serial_number = srb->serial_number;
653 srb->serial_number ^= 0x80000000;
654
655 /* issue the auto-sense command */ 649 /* issue the auto-sense command */
656 old_resid = srb->resid; 650 old_resid = srb->resid;
657 srb->resid = 0; 651 srb->resid = 0;
@@ -662,7 +656,6 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
662 srb->request_buffer = old_request_buffer; 656 srb->request_buffer = old_request_buffer;
663 srb->request_bufflen = old_request_bufflen; 657 srb->request_bufflen = old_request_bufflen;
664 srb->use_sg = old_sg; 658 srb->use_sg = old_sg;
665 srb->serial_number = old_serial_number;
666 srb->sc_data_direction = old_sc_data_direction; 659 srb->sc_data_direction = old_sc_data_direction;
667 srb->cmd_len = old_cmd_len; 660 srb->cmd_len = old_cmd_len;
668 memcpy(srb->cmnd, old_cmnd, MAX_COMMAND_SIZE); 661 memcpy(srb->cmnd, old_cmnd, MAX_COMMAND_SIZE);
@@ -985,7 +978,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
985 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 978 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
986 bcb->DataTransferLength = cpu_to_le32(transfer_length); 979 bcb->DataTransferLength = cpu_to_le32(transfer_length);
987 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0; 980 bcb->Flags = srb->sc_data_direction == DMA_FROM_DEVICE ? 1 << 7 : 0;
988 bcb->Tag = srb->serial_number; 981 bcb->Tag = ++us->tag;
989 bcb->Lun = srb->device->lun; 982 bcb->Lun = srb->device->lun;
990 if (us->flags & US_FL_SCM_MULT_TARG) 983 if (us->flags & US_FL_SCM_MULT_TARG)
991 bcb->Lun |= srb->device->id << 4; 984 bcb->Lun |= srb->device->id << 4;
@@ -1074,7 +1067,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1074 US_DEBUGP("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", 1067 US_DEBUGP("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
1075 le32_to_cpu(bcs->Signature), bcs->Tag, 1068 le32_to_cpu(bcs->Signature), bcs->Tag,
1076 residue, bcs->Status); 1069 residue, bcs->Status);
1077 if (bcs->Tag != srb->serial_number || bcs->Status > US_BULK_STAT_PHASE) { 1070 if (bcs->Tag != us->tag || bcs->Status > US_BULK_STAT_PHASE) {
1078 US_DEBUGP("Bulk logical error\n"); 1071 US_DEBUGP("Bulk logical error\n");
1079 return USB_STOR_TRANSPORT_ERROR; 1072 return USB_STOR_TRANSPORT_ERROR;
1080 } 1073 }
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index bd0ab3039bdd..b79dad1b598c 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -79,6 +79,23 @@ UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
79 US_SC_8070, US_PR_SCM_ATAPI, init_usbat, 0), 79 US_SC_8070, US_PR_SCM_ATAPI, init_usbat, 0),
80#endif 80#endif
81 81
82/* Patch submitted by Mihnea-Costin Grigore <mihnea@zulu.ro> */
83UNUSUAL_DEV( 0x040d, 0x6205, 0x0003, 0x0003,
84 "VIA Technologies Inc.",
85 "USB 2.0 Card Reader",
86 US_SC_DEVICE, US_PR_DEVICE, NULL,
87 US_FL_IGNORE_RESIDUE ),
88
89/* Reported by Sebastian Kapfer <sebastian_kapfer@gmx.net>
90 * and Olaf Hering <olh@suse.de> (different bcd's, same vendor/product)
91 * for USB floppies that need the SINGLE_LUN enforcement.
92 */
93UNUSUAL_DEV( 0x0409, 0x0040, 0x0000, 0x9999,
94 "NEC",
95 "NEC USB UF000x",
96 US_SC_DEVICE, US_PR_DEVICE, NULL,
97 US_FL_SINGLE_LUN ),
98
82/* Deduced by Jonathan Woithe <jwoithe@physics.adelaide.edu.au> 99/* Deduced by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
83 * Entry needed for flags: US_FL_FIX_INQUIRY because initial inquiry message 100 * Entry needed for flags: US_FL_FIX_INQUIRY because initial inquiry message
84 * always fails and confuses drive. 101 * always fails and confuses drive.
@@ -89,6 +106,13 @@ UNUSUAL_DEV( 0x0411, 0x001c, 0x0113, 0x0113,
89 US_SC_DEVICE, US_PR_DEVICE, NULL, 106 US_SC_DEVICE, US_PR_DEVICE, NULL,
90 US_FL_FIX_INQUIRY ), 107 US_FL_FIX_INQUIRY ),
91 108
109/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */
110UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
111 "SMSC",
112 "FDC GOLD-2.30",
113 US_SC_DEVICE, US_PR_DEVICE, NULL,
114 US_FL_SINGLE_LUN ),
115
92#ifdef CONFIG_USB_STORAGE_DPCM 116#ifdef CONFIG_USB_STORAGE_DPCM
93UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, 117UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
94 "Microtech", 118 "Microtech",
@@ -96,6 +120,24 @@ UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
96 US_SC_SCSI, US_PR_DPCM_USB, NULL, 0 ), 120 US_SC_SCSI, US_PR_DPCM_USB, NULL, 0 ),
97#endif 121#endif
98 122
123/*
124 * Pete Zaitcev <zaitcev@yahoo.com>, from Patrick C. F. Ernzer, bz#162559.
125 * The key does not actually break, but it returns zero sense which
126 * makes our SCSI stack to print confusing messages.
127 */
128UNUSUAL_DEV( 0x0457, 0x0150, 0x0100, 0x0100,
129 "USBest Technology", /* sold by Transcend */
130 "USB Mass Storage Device",
131 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ),
132
133/* Patch submitted by Daniel Drake <dsd@gentoo.org>
134 * Device reports nonsense bInterfaceProtocol 6 when connected over USB2 */
135UNUSUAL_DEV( 0x0451, 0x5416, 0x0100, 0x0100,
136 "Neuros Audio",
137 "USB 2.0 HD 2.5",
138 US_SC_DEVICE, US_PR_BULK, NULL,
139 US_FL_NEED_OVERRIDE ),
140
99/* Patch submitted by Philipp Friedrich <philipp@void.at> */ 141/* Patch submitted by Philipp Friedrich <philipp@void.at> */
100UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100, 142UNUSUAL_DEV( 0x0482, 0x0100, 0x0100, 0x0100,
101 "Kyocera", 143 "Kyocera",
@@ -929,6 +971,18 @@ UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff,
929 US_FL_SINGLE_LUN ), 971 US_FL_SINGLE_LUN ),
930#endif 972#endif
931 973
974/* Submitted by: Nick Sillik <n.sillik@temple.edu>
975 * Needed for OneTouch extension to usb-storage
976 *
977 */
978#ifdef CONFIG_USB_STORAGE_ONETOUCH
979 UNUSUAL_DEV( 0x0d49, 0x7010, 0x0000, 0x9999,
980 "Maxtor",
981 "OneTouch External Harddrive",
982 US_SC_DEVICE, US_PR_DEVICE, onetouch_connect_input,
983 0),
984#endif
985
932/* Submitted by Joris Struyve <joris@struyve.be> */ 986/* Submitted by Joris Struyve <joris@struyve.be> */
933UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff, 987UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff,
934 "Medion", 988 "Medion",
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 77e7fc258aa2..f9a9bfa1aef5 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -90,7 +90,9 @@
90#ifdef CONFIG_USB_STORAGE_JUMPSHOT 90#ifdef CONFIG_USB_STORAGE_JUMPSHOT
91#include "jumpshot.h" 91#include "jumpshot.h"
92#endif 92#endif
93 93#ifdef CONFIG_USB_STORAGE_ONETOUCH
94#include "onetouch.h"
95#endif
94 96
95/* Some informational data */ 97/* Some informational data */
96MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>"); 98MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
@@ -390,11 +392,16 @@ SkipForAbort:
390 /* If an abort request was received we need to signal that 392 /* If an abort request was received we need to signal that
391 * the abort has finished. The proper test for this is 393 * the abort has finished. The proper test for this is
392 * the TIMED_OUT flag, not srb->result == DID_ABORT, because 394 * the TIMED_OUT flag, not srb->result == DID_ABORT, because
393 * a timeout/abort request might be received after all the 395 * the timeout might have occurred after the command had
394 * USB processing was complete. */ 396 * already completed with a different result code. */
395 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) 397 if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
396 complete(&(us->notify)); 398 complete(&(us->notify));
397 399
400 /* Allow USB transfers to resume */
401 clear_bit(US_FLIDX_ABORTING, &us->flags);
402 clear_bit(US_FLIDX_TIMED_OUT, &us->flags);
403 }
404
398 /* finished working on this command */ 405 /* finished working on this command */
399 us->srb = NULL; 406 us->srb = NULL;
400 scsi_unlock(host); 407 scsi_unlock(host);
@@ -786,6 +793,7 @@ static void usb_stor_release_resources(struct us_data *us)
786 * any more commands. 793 * any more commands.
787 */ 794 */
788 US_DEBUGP("-- sending exit command to thread\n"); 795 US_DEBUGP("-- sending exit command to thread\n");
796 set_bit(US_FLIDX_DISCONNECTING, &us->flags);
789 up(&us->sema); 797 up(&us->sema);
790 798
791 /* Call the destructor routine, if it exists */ 799 /* Call the destructor routine, if it exists */
@@ -816,6 +824,49 @@ static void dissociate_dev(struct us_data *us)
816 usb_set_intfdata(us->pusb_intf, NULL); 824 usb_set_intfdata(us->pusb_intf, NULL);
817} 825}
818 826
827/* First stage of disconnect processing: stop all commands and remove
828 * the host */
829static void quiesce_and_remove_host(struct us_data *us)
830{
831 /* Prevent new USB transfers, stop the current command, and
832 * interrupt a SCSI-scan or device-reset delay */
833 set_bit(US_FLIDX_DISCONNECTING, &us->flags);
834 usb_stor_stop_transport(us);
835 wake_up(&us->delay_wait);
836
837 /* It doesn't matter if the SCSI-scanning thread is still running.
838 * The thread will exit when it sees the DISCONNECTING flag. */
839
840 /* Wait for the current command to finish, then remove the host */
841 down(&us->dev_semaphore);
842 up(&us->dev_semaphore);
843
844 /* queuecommand won't accept any new commands and the control
845 * thread won't execute a previously-queued command. If there
846 * is such a command pending, complete it with an error. */
847 if (us->srb) {
848 us->srb->result = DID_NO_CONNECT << 16;
849 scsi_lock(us_to_host(us));
850 us->srb->scsi_done(us->srb);
851 us->srb = NULL;
852 scsi_unlock(us_to_host(us));
853 }
854
855 /* Now we own no commands so it's safe to remove the SCSI host */
856 scsi_remove_host(us_to_host(us));
857}
858
859/* Second stage of disconnect processing: deallocate all resources */
860static void release_everything(struct us_data *us)
861{
862 usb_stor_release_resources(us);
863 dissociate_dev(us);
864
865 /* Drop our reference to the host; the SCSI core will free it
866 * (and "us" along with it) when the refcount becomes 0. */
867 scsi_host_put(us_to_host(us));
868}
869
819/* Thread to carry out delayed SCSI-device scanning */ 870/* Thread to carry out delayed SCSI-device scanning */
820static int usb_stor_scan_thread(void * __us) 871static int usb_stor_scan_thread(void * __us)
821{ 872{
@@ -956,7 +1007,7 @@ static int storage_probe(struct usb_interface *intf,
956 if (result < 0) { 1007 if (result < 0) {
957 printk(KERN_WARNING USB_STORAGE 1008 printk(KERN_WARNING USB_STORAGE
958 "Unable to start the device-scanning thread\n"); 1009 "Unable to start the device-scanning thread\n");
959 scsi_remove_host(host); 1010 quiesce_and_remove_host(us);
960 goto BadDevice; 1011 goto BadDevice;
961 } 1012 }
962 atomic_inc(&total_threads); 1013 atomic_inc(&total_threads);
@@ -969,10 +1020,7 @@ static int storage_probe(struct usb_interface *intf,
969 /* We come here if there are any problems */ 1020 /* We come here if there are any problems */
970BadDevice: 1021BadDevice:
971 US_DEBUGP("storage_probe() failed\n"); 1022 US_DEBUGP("storage_probe() failed\n");
972 set_bit(US_FLIDX_DISCONNECTING, &us->flags); 1023 release_everything(us);
973 usb_stor_release_resources(us);
974 dissociate_dev(us);
975 scsi_host_put(host);
976 return result; 1024 return result;
977} 1025}
978 1026
@@ -982,28 +1030,8 @@ static void storage_disconnect(struct usb_interface *intf)
982 struct us_data *us = usb_get_intfdata(intf); 1030 struct us_data *us = usb_get_intfdata(intf);
983 1031
984 US_DEBUGP("storage_disconnect() called\n"); 1032 US_DEBUGP("storage_disconnect() called\n");
985 1033 quiesce_and_remove_host(us);
986 /* Prevent new USB transfers, stop the current command, and 1034 release_everything(us);
987 * interrupt a SCSI-scan or device-reset delay */
988 set_bit(US_FLIDX_DISCONNECTING, &us->flags);
989 usb_stor_stop_transport(us);
990 wake_up(&us->delay_wait);
991
992 /* It doesn't matter if the SCSI-scanning thread is still running.
993 * The thread will exit when it sees the DISCONNECTING flag. */
994
995 /* Wait for the current command to finish, then remove the host */
996 down(&us->dev_semaphore);
997 up(&us->dev_semaphore);
998 scsi_remove_host(us_to_host(us));
999
1000 /* Wait for everything to become idle and release all our resources */
1001 usb_stor_release_resources(us);
1002 dissociate_dev(us);
1003
1004 /* Drop our reference to the host; the SCSI core will free it
1005 * (and "us" along with it) when the refcount becomes 0. */
1006 scsi_host_put(us_to_host(us));
1007} 1035}
1008 1036
1009/*********************************************************************** 1037/***********************************************************************
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 625b7aa98074..a195adae57b6 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -158,6 +158,7 @@ struct us_data {
158 158
159 /* SCSI interfaces */ 159 /* SCSI interfaces */
160 struct scsi_cmnd *srb; /* current srb */ 160 struct scsi_cmnd *srb; /* current srb */
161 unsigned int tag; /* current dCBWTag */
161 162
162 /* thread information */ 163 /* thread information */
163 int pid; /* control thread */ 164 int pid; /* control thread */