summaryrefslogtreecommitdiff
path: root/drivers/usb/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor_core@ameritech.net>2006-04-02 00:08:05 -0500
committerDmitry Torokhov <dtor_core@ameritech.net>2006-04-02 00:08:05 -0500
commit95d465fd750897ab32462a6702fbfe1b122cbbc0 (patch)
tree65c38b2f11c51bb6932e44dd6c92f15b0091abfe /drivers/usb/input
parent642fde17dceceb56c7ba2762733ac688666ae657 (diff)
parent683aa4012f53b2ada0f430487e05d37b0d94e90a (diff)
Manual merge with Linus.
Conflicts: arch/powerpc/kernel/setup-common.c drivers/input/keyboard/hil_kbd.c drivers/input/mouse/hil_ptr.c
Diffstat (limited to 'drivers/usb/input')
-rw-r--r--drivers/usb/input/ati_remote.c2
-rw-r--r--drivers/usb/input/hid-core.c177
-rw-r--r--drivers/usb/input/hid-lgff.c6
-rw-r--r--drivers/usb/input/hid-tmff.c3
-rw-r--r--drivers/usb/input/hid.h10
-rw-r--r--drivers/usb/input/hiddev.c6
6 files changed, 157 insertions, 47 deletions
diff --git a/drivers/usb/input/ati_remote.c b/drivers/usb/input/ati_remote.c
index f7bdc506e61..99f986cb6e9 100644
--- a/drivers/usb/input/ati_remote.c
+++ b/drivers/usb/input/ati_remote.c
@@ -159,8 +159,6 @@ static const char accel[] = { 1, 2, 4, 6, 9, 13, 20 };
*/
#define FILTER_TIME (HZ / 20)
-static DECLARE_MUTEX(disconnect_sem);
-
struct ati_remote {
struct input_dev *idev;
struct usb_device *udev;
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 07a012f8877..d4bf1701046 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -66,9 +66,8 @@ static struct hid_report *hid_register_report(struct hid_device *device, unsigne
if (report_enum->report_id_hash[id])
return report_enum->report_id_hash[id];
- if (!(report = kmalloc(sizeof(struct hid_report), GFP_KERNEL)))
+ if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
return NULL;
- memset(report, 0, sizeof(struct hid_report));
if (id != 0)
report_enum->numbered = 1;
@@ -97,12 +96,9 @@ static struct hid_field *hid_register_field(struct hid_report *report, unsigned
return NULL;
}
- if (!(field = kmalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
+ if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
+ values * sizeof(unsigned), GFP_KERNEL))) return NULL;
- memset(field, 0, sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
- + values * sizeof(unsigned));
-
field->index = report->maxfield++;
report->field[field->index] = field;
field->usage = (struct hid_usage *)(field + 1);
@@ -651,17 +647,14 @@ static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
hid_parser_reserved
};
- if (!(device = kmalloc(sizeof(struct hid_device), GFP_KERNEL)))
+ if (!(device = kzalloc(sizeof(struct hid_device), GFP_KERNEL)))
return NULL;
- memset(device, 0, sizeof(struct hid_device));
- if (!(device->collection = kmalloc(sizeof(struct hid_collection) *
+ if (!(device->collection = kzalloc(sizeof(struct hid_collection) *
HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) {
kfree(device);
return NULL;
}
- memset(device->collection, 0, sizeof(struct hid_collection) *
- HID_DEFAULT_NUM_COLLECTIONS);
device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
for (i = 0; i < HID_REPORT_TYPES; i++)
@@ -675,13 +668,12 @@ static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
memcpy(device->rdesc, start, size);
device->rsize = size;
- if (!(parser = kmalloc(sizeof(struct hid_parser), GFP_KERNEL))) {
+ if (!(parser = kzalloc(sizeof(struct hid_parser), GFP_KERNEL))) {
kfree(device->rdesc);
kfree(device->collection);
kfree(device);
return NULL;
}
- memset(parser, 0, sizeof(struct hid_parser));
parser->device = device;
end = start + size;
@@ -911,6 +903,99 @@ static int hid_input_report(int type, struct urb *urb, int interrupt, struct pt_
}
/*
+ * Input submission and I/O error handler.
+ */
+
+static void hid_io_error(struct hid_device *hid);
+
+/* Start up the input URB */
+static int hid_start_in(struct hid_device *hid)
+{
+ unsigned long flags;
+ int rc = 0;
+
+ spin_lock_irqsave(&hid->inlock, flags);
+ if (hid->open > 0 && !test_bit(HID_SUSPENDED, &hid->iofl) &&
+ !test_and_set_bit(HID_IN_RUNNING, &hid->iofl)) {
+ rc = usb_submit_urb(hid->urbin, GFP_ATOMIC);
+ if (rc != 0)
+ clear_bit(HID_IN_RUNNING, &hid->iofl);
+ }
+ spin_unlock_irqrestore(&hid->inlock, flags);
+ return rc;
+}
+
+/* I/O retry timer routine */
+static void hid_retry_timeout(unsigned long _hid)
+{
+ struct hid_device *hid = (struct hid_device *) _hid;
+
+ dev_dbg(&hid->intf->dev, "retrying intr urb\n");
+ if (hid_start_in(hid))
+ hid_io_error(hid);
+}
+
+/* Workqueue routine to reset the device */
+static void hid_reset(void *_hid)
+{
+ struct hid_device *hid = (struct hid_device *) _hid;
+ int rc_lock, rc;
+
+ dev_dbg(&hid->intf->dev, "resetting device\n");
+ rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf);
+ if (rc_lock >= 0) {
+ rc = usb_reset_device(hid->dev);
+ if (rc_lock)
+ usb_unlock_device(hid->dev);
+ }
+ clear_bit(HID_RESET_PENDING, &hid->iofl);
+
+ if (rc == 0) {
+ hid->retry_delay = 0;
+ if (hid_start_in(hid))
+ hid_io_error(hid);
+ } else if (!(rc == -ENODEV || rc == -EHOSTUNREACH || rc == -EINTR))
+ err("can't reset device, %s-%s/input%d, status %d",
+ hid->dev->bus->bus_name,
+ hid->dev->devpath,
+ hid->ifnum, rc);
+}
+
+/* Main I/O error handler */
+static void hid_io_error(struct hid_device *hid)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&hid->inlock, flags);
+
+ /* Stop when disconnected */
+ if (usb_get_intfdata(hid->intf) == NULL)
+ goto done;
+
+ /* When an error occurs, retry at increasing intervals */
+ if (hid->retry_delay == 0) {
+ hid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */
+ hid->stop_retry = jiffies + msecs_to_jiffies(1000);
+ } else if (hid->retry_delay < 100)
+ hid->retry_delay *= 2;
+
+ if (time_after(jiffies, hid->stop_retry)) {
+
+ /* Retries failed, so do a port reset */
+ if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) {
+ if (schedule_work(&hid->reset_work))
+ goto done;
+ clear_bit(HID_RESET_PENDING, &hid->iofl);
+ }
+ }
+
+ mod_timer(&hid->io_retry,
+ jiffies + msecs_to_jiffies(hid->retry_delay));
+done:
+ spin_unlock_irqrestore(&hid->inlock, flags);
+}
+
+/*
* Input interrupt completion handler.
*/
@@ -921,25 +1006,35 @@ static void hid_irq_in(struct urb *urb, struct pt_regs *regs)
switch (urb->status) {
case 0: /* success */
+ hid->retry_delay = 0;
hid_input_report(HID_INPUT_REPORT, urb, 1, regs);
break;
case -ECONNRESET: /* unlink */
case -ENOENT:
- case -EPERM:
case -ESHUTDOWN: /* unplug */
- case -EILSEQ: /* unplug timeout on uhci */
+ clear_bit(HID_IN_RUNNING, &hid->iofl);
return;
+ case -EILSEQ: /* protocol error or unplug */
+ case -EPROTO: /* protocol error or unplug */
case -ETIMEDOUT: /* NAK */
- break;
+ clear_bit(HID_IN_RUNNING, &hid->iofl);
+ hid_io_error(hid);
+ return;
default: /* error */
warn("input irq status %d received", urb->status);
}
status = usb_submit_urb(urb, SLAB_ATOMIC);
- if (status)
- err("can't resubmit intr, %s-%s/input%d, status %d",
- hid->dev->bus->bus_name, hid->dev->devpath,
- hid->ifnum, status);
+ if (status) {
+ clear_bit(HID_IN_RUNNING, &hid->iofl);
+ if (status != -EPERM) {
+ err("can't resubmit intr, %s-%s/input%d, status %d",
+ hid->dev->bus->bus_name,
+ hid->dev->devpath,
+ hid->ifnum, status);
+ hid_io_error(hid);
+ }
+ }
}
/*
@@ -1101,8 +1196,9 @@ static void hid_irq_out(struct urb *urb, struct pt_regs *regs)
case 0: /* success */
break;
case -ESHUTDOWN: /* unplug */
- case -EILSEQ: /* unplug timeout on uhci */
unplug = 1;
+ case -EILSEQ: /* protocol error or unplug */
+ case -EPROTO: /* protocol error or unplug */
case -ECONNRESET: /* unlink */
case -ENOENT:
break;
@@ -1119,7 +1215,7 @@ static void hid_irq_out(struct urb *urb, struct pt_regs *regs)
if (hid->outhead != hid->outtail) {
if (hid_submit_out(hid)) {
- clear_bit(HID_OUT_RUNNING, &hid->iofl);;
+ clear_bit(HID_OUT_RUNNING, &hid->iofl);
wake_up(&hid->wait);
}
spin_unlock_irqrestore(&hid->outlock, flags);
@@ -1149,8 +1245,9 @@ static void hid_ctrl(struct urb *urb, struct pt_regs *regs)
hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0, regs);
break;
case -ESHUTDOWN: /* unplug */
- case -EILSEQ: /* unplug timectrl on uhci */
unplug = 1;
+ case -EILSEQ: /* protocol error or unplug */
+ case -EPROTO: /* protocol error or unplug */
case -ECONNRESET: /* unlink */
case -ENOENT:
case -EPIPE: /* report not available */
@@ -1263,14 +1360,9 @@ static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
int hid_open(struct hid_device *hid)
{
- if (hid->open++)
- return 0;
-
- hid->urbin->dev = hid->dev;
-
- if (usb_submit_urb(hid->urbin, GFP_KERNEL))
- return -EIO;
-
+ ++hid->open;
+ if (hid_start_in(hid))
+ hid_io_error(hid);
return 0;
}
@@ -1460,6 +1552,9 @@ void hid_init_reports(struct hid_device *hid)
#define USB_VENDOR_ID_HP 0x03f0
#define USB_DEVICE_ID_HP_USBHUB_KB 0x020c
+#define USB_VENDOR_ID_CREATIVELABS 0x062a
+#define USB_DEVICE_ID_CREATIVELABS_SILVERCREST 0x0201
+
/*
* Alphabetically sorted blacklist by quirk type.
*/
@@ -1576,6 +1671,7 @@ static const struct hid_blacklist {
{ USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
{ USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_KEYBOARD, HID_QUIRK_NOGET},
{ USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_USBHUB_KB, HID_QUIRK_NOGET},
+ { USB_VENDOR_ID_CREATIVELABS, USB_DEVICE_ID_CREATIVELABS_SILVERCREST, HID_QUIRK_NOGET },
{ USB_VENDOR_ID_HP, USB_DEVICE_ID_HP_USBHUB_KB, HID_QUIRK_NOGET },
{ USB_VENDOR_ID_TANGTOP, USB_DEVICE_ID_TANGTOP_USBPS2, HID_QUIRK_NOGET },
{ USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
@@ -1795,6 +1891,10 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
init_waitqueue_head(&hid->wait);
+ INIT_WORK(&hid->reset_work, hid_reset, hid);
+ setup_timer(&hid->io_retry, hid_retry_timeout, (unsigned long) hid);
+
+ spin_lock_init(&hid->inlock);
spin_lock_init(&hid->outlock);
spin_lock_init(&hid->ctrllock);
@@ -1863,11 +1963,16 @@ static void hid_disconnect(struct usb_interface *intf)
if (!hid)
return;
+ spin_lock_irq(&hid->inlock); /* Sync with error handler */
usb_set_intfdata(intf, NULL);
+ spin_unlock_irq(&hid->inlock);
usb_kill_urb(hid->urbin);
usb_kill_urb(hid->urbout);
usb_kill_urb(hid->urbctrl);
+ del_timer_sync(&hid->io_retry);
+ flush_scheduled_work();
+
if (hid->claimed & HID_CLAIMED_INPUT)
hidinput_disconnect(hid);
if (hid->claimed & HID_CLAIMED_HIDDEV)
@@ -1942,6 +2047,10 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
{
struct hid_device *hid = usb_get_intfdata (intf);
+ spin_lock_irq(&hid->inlock); /* Sync with error handler */
+ set_bit(HID_SUSPENDED, &hid->iofl);
+ spin_unlock_irq(&hid->inlock);
+ del_timer(&hid->io_retry);
usb_kill_urb(hid->urbin);
dev_dbg(&intf->dev, "suspend\n");
return 0;
@@ -1952,10 +2061,8 @@ static int hid_resume(struct usb_interface *intf)
struct hid_device *hid = usb_get_intfdata (intf);
int status;
- if (hid->open)
- status = usb_submit_urb(hid->urbin, GFP_NOIO);
- else
- status = 0;
+ clear_bit(HID_SUSPENDED, &hid->iofl);
+ status = hid_start_in(hid);
dev_dbg(&intf->dev, "resume status %d\n", status);
return status;
}
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index f82c9c9e5d5..f07d44357ff 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -154,10 +154,9 @@ int hid_lgff_init(struct hid_device* hid)
return -1;
}
- private = kmalloc(sizeof(struct lgff_device), GFP_KERNEL);
+ private = kzalloc(sizeof(struct lgff_device), GFP_KERNEL);
if (!private)
return -1;
- memset(private, 0, sizeof(struct lgff_device));
hid->ff_private = private;
/* Input init */
@@ -228,13 +227,12 @@ static struct hid_report* hid_lgff_duplicate_report(struct hid_report* report)
}
*ret->field[0] = *report->field[0];
- ret->field[0]->value = kmalloc(sizeof(s32[8]), GFP_KERNEL);
+ ret->field[0]->value = kzalloc(sizeof(s32[8]), GFP_KERNEL);
if (!ret->field[0]->value) {
kfree(ret->field[0]);
kfree(ret);
return NULL;
}
- memset(ret->field[0]->value, 0, sizeof(s32[8]));
return ret;
}
diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c
index 023fd5ac31c..534425c69c0 100644
--- a/drivers/usb/input/hid-tmff.c
+++ b/drivers/usb/input/hid-tmff.c
@@ -113,11 +113,10 @@ int hid_tmff_init(struct hid_device *hid)
struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
struct input_dev *input_dev = hidinput->input;
- private = kmalloc(sizeof(struct tmff_device), GFP_KERNEL);
+ private = kzalloc(sizeof(struct tmff_device), GFP_KERNEL);
if (!private)
return -ENOMEM;
- memset(private, 0, sizeof(struct tmff_device));
hid->ff_private = private;
/* Find the report to use */
diff --git a/drivers/usb/input/hid.h b/drivers/usb/input/hid.h
index 8b0d4346ce9..4e1b784fe52 100644
--- a/drivers/usb/input/hid.h
+++ b/drivers/usb/input/hid.h
@@ -31,6 +31,8 @@
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/list.h>
+#include <linux/timer.h>
+#include <linux/workqueue.h>
/*
* USB HID (Human Interface Device) interface class code
@@ -370,6 +372,9 @@ struct hid_control_fifo {
#define HID_CTRL_RUNNING 1
#define HID_OUT_RUNNING 2
+#define HID_IN_RUNNING 3
+#define HID_RESET_PENDING 4
+#define HID_SUSPENDED 5
struct hid_input {
struct list_head list;
@@ -393,12 +398,17 @@ struct hid_device { /* device report descriptor */
int ifnum; /* USB interface number */
unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
+ struct timer_list io_retry; /* Retry timer */
+ unsigned long stop_retry; /* Time to give up, in jiffies */
+ unsigned int retry_delay; /* Delay length in ms */
+ struct work_struct reset_work; /* Task context for resets */
unsigned int bufsize; /* URB buffer size */
struct urb *urbin; /* Input URB */
char *inbuf; /* Input buffer */
dma_addr_t inbuf_dma; /* Input buffer dma */
+ spinlock_t inlock; /* Input fifo spinlock */
struct urb *urbctrl; /* Control URB */
struct usb_ctrlrequest *cr; /* Control request struct */
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 925f5aba06f..6dd66669617 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -257,9 +257,8 @@ static int hiddev_open(struct inode * inode, struct file * file) {
if (i >= HIDDEV_MINORS || !hiddev_table[i])
return -ENODEV;
- if (!(list = kmalloc(sizeof(struct hiddev_list), GFP_KERNEL)))
+ if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL)))
return -ENOMEM;
- memset(list, 0, sizeof(struct hiddev_list));
list->hiddev = hiddev_table[i];
list->next = hiddev_table[i]->list;
@@ -754,9 +753,8 @@ int hiddev_connect(struct hid_device *hid)
if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0)
return -1;
- if (!(hiddev = kmalloc(sizeof(struct hiddev), GFP_KERNEL)))
+ if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
return -1;
- memset(hiddev, 0, sizeof(struct hiddev));
retval = usb_register_dev(hid->intf, &hiddev_class);
if (retval) {