From d2ee4dd9a4d68543bddddb69d38cba51b4373e6b Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Tue, 20 Mar 2012 16:01:33 +0200 Subject: HID: waltop: Add support for Sirius tablet Add support for Waltop Sirius Battery Free Tablet. VisTablet Muse and Princeton PTB-S1BK are other possible names of this tablet. Signed-off-by: Nikolai Kondrashov Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/hid-quirks.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/hid/usbhid') diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c index 782c63955f29..0597ee604f6e 100644 --- a/drivers/hid/usbhid/hid-quirks.c +++ b/drivers/hid/usbhid/hid-quirks.c @@ -88,6 +88,7 @@ static const struct hid_blacklist { { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP8060U, HID_QUIRK_MULTI_INPUT }, { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_10_6_INCH, HID_QUIRK_MULTI_INPUT }, { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_MEDIA_TABLET_14_1_INCH, HID_QUIRK_MULTI_INPUT }, + { USB_VENDOR_ID_WALTOP, USB_DEVICE_ID_WALTOP_SIRIUS_BATTERY_FREE_TABLET, HID_QUIRK_MULTI_INPUT }, { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, { USB_VENDOR_ID_WISEGROUP_LTD2, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, -- cgit v1.2.2 From a8c52b662cef520815ed43cb3305f8b45b452694 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Wed, 28 Mar 2012 13:16:19 +0200 Subject: HID: usbhid: fix error handling of not enough bandwidth In case IO cannot be started because there is a lack of bandwidth on the bus, it makes no sense to reset the device. If IO is requested because the device is opened, user space should be notified with an error right away. If the lack of bandwidth arises later, for example after resume, there's no other choice but to retry in the hope that bandwidth will be freed. Signed-off-by: Oliver Neukum Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/hid-core.c | 37 +++++++++++++++++++++++++++---------- drivers/hid/usbhid/usbhid.h | 1 + 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'drivers/hid/usbhid') diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 5bf91dbad59d..c1a1dd54601c 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -86,8 +86,13 @@ static int hid_start_in(struct hid_device *hid) !test_bit(HID_REPORTED_IDLE, &usbhid->iofl) && !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) { rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC); - if (rc != 0) + if (rc != 0) { clear_bit(HID_IN_RUNNING, &usbhid->iofl); + if (rc == -ENOSPC) + set_bit(HID_NO_BANDWIDTH, &usbhid->iofl); + } else { + clear_bit(HID_NO_BANDWIDTH, &usbhid->iofl); + } } spin_unlock_irqrestore(&usbhid->lock, flags); return rc; @@ -173,8 +178,10 @@ static void hid_io_error(struct hid_device *hid) if (time_after(jiffies, usbhid->stop_retry)) { - /* Retries failed, so do a port reset */ - if (!test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) { + /* Retries failed, so do a port reset unless we lack bandwidth*/ + if (test_bit(HID_NO_BANDWIDTH, &usbhid->iofl) + && !test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) { + schedule_work(&usbhid->reset_work); goto done; } @@ -700,7 +707,7 @@ static int hid_get_class_descriptor(struct usb_device *dev, int ifnum, int usbhid_open(struct hid_device *hid) { struct usbhid_device *usbhid = hid->driver_data; - int res; + int res = 0; mutex_lock(&hid_open_mut); if (!hid->open++) { @@ -708,17 +715,27 @@ int usbhid_open(struct hid_device *hid) /* the device must be awake to reliably request remote wakeup */ if (res < 0) { hid->open--; - mutex_unlock(&hid_open_mut); - return -EIO; + res = -EIO; + goto done; } usbhid->intf->needs_remote_wakeup = 1; - if (hid_start_in(hid)) - hid_io_error(hid); - + res = hid_start_in(hid); + if (res) { + if (res != -ENOSPC) { + hid_io_error(hid); + res = 0; + } else { + /* no use opening if resources are insufficient */ + hid->open--; + res = -EBUSY; + usbhid->intf->needs_remote_wakeup = 0; + } + } usb_autopm_put_interface(usbhid->intf); } +done: mutex_unlock(&hid_open_mut); - return 0; + return res; } void usbhid_close(struct hid_device *hid) diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h index cb8f703efde5..1883d7b94870 100644 --- a/drivers/hid/usbhid/usbhid.h +++ b/drivers/hid/usbhid/usbhid.h @@ -55,6 +55,7 @@ struct usb_interface *usbhid_find_interface(int minor); #define HID_STARTED 8 #define HID_REPORTED_IDLE 9 #define HID_KEYS_PRESSED 10 +#define HID_NO_BANDWIDTH 11 /* * USB-specific HID struct, to be pointed to -- cgit v1.2.2 From dc3c78e43469063c5bf4b744214508f94c4129f9 Mon Sep 17 00:00:00 2001 From: Simon Haggett Date: Tue, 3 Apr 2012 16:04:15 +0100 Subject: HID: usbhid: Check HID report descriptor contents after device reset When a USB device reset occurs, usbcore will refetch the device and configuration descriptors and compare them with those retrieved before the reset to ensure that they have not changed. For USB HID devices, this implicitly includes the HID class descriptor (as this is fetched with the configuration descriptor). However, the HID report descriptor is not checked again. Whilst a change in the size of the HID report descriptor will be detected (as this is held in the class descriptor), content changes to the report descriptor which do not result in a change in its size will be missed. If a firmware update were applied to a USB HID device which resulted in such a change to the report descriptor after device reset, then this would not be picked up by usbhid. This patch fixes this issue by allowing usbhid to check the contents of the report descriptor after the device reset, and trigger a rebind of the device if there is a mismatch. Reviewed-by: Toby Gray Signed-off-by: Simon Haggett Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/hid-core.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'drivers/hid/usbhid') diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index c1a1dd54601c..aa1c503a9526 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -1364,7 +1365,34 @@ static int hid_post_reset(struct usb_interface *intf) struct usb_device *dev = interface_to_usbdev (intf); struct hid_device *hid = usb_get_intfdata(intf); struct usbhid_device *usbhid = hid->driver_data; + struct usb_host_interface *interface = intf->cur_altsetting; int status; + char *rdesc; + + /* Fetch and examine the HID report descriptor. If this + * has changed, then rebind. Since usbcore's check of the + * configuration descriptors passed, we already know that + * the size of the HID report descriptor has not changed. + */ + rdesc = kmalloc(hid->rsize, GFP_KERNEL); + if (!rdesc) { + dbg_hid("couldn't allocate rdesc memory (post_reset)\n"); + return 1; + } + status = hid_get_class_descriptor(dev, + interface->desc.bInterfaceNumber, + HID_DT_REPORT, rdesc, hid->rsize); + if (status < 0) { + dbg_hid("reading report descriptor failed (post_reset)\n"); + kfree(rdesc); + return 1; + } + status = memcmp(rdesc, hid->rdesc, hid->rsize); + kfree(rdesc); + if (status != 0) { + dbg_hid("report descriptor changed\n"); + return 1; + } spin_lock_irq(&usbhid->lock); clear_bit(HID_RESET_PENDING, &usbhid->iofl); -- cgit v1.2.2 From d4f0e4daf0d867f80c78ca4f9ac03a562e229e72 Mon Sep 17 00:00:00 2001 From: Havard Skinnemoen Date: Thu, 26 Apr 2012 11:16:00 -0700 Subject: HID: hiddev: Use vzalloc to allocate hiddev_list Everytime a HID device is opened, a new hiddev_list is allocated with kzalloc. This requires 64KB of physically contiguous memory, which could easily push a heavily loaded system over the edge. Allocating the same amount of memory with vmalloc shouldn't be nearly as demanding, so let's do that instead. The memory isn't used for DMA and doesn't look particularly performance sensitive, so this should be safe. Signed-off-by: Havard Skinnemoen Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/hiddev.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'drivers/hid/usbhid') diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c index b1ec0e2aeb57..14599e256791 100644 --- a/drivers/hid/usbhid/hiddev.c +++ b/drivers/hid/usbhid/hiddev.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "usbhid.h" #ifdef CONFIG_USB_DYNAMIC_MINORS @@ -250,13 +251,13 @@ static int hiddev_release(struct inode * inode, struct file * file) } else { mutex_unlock(&list->hiddev->existancelock); kfree(list->hiddev); - kfree(list); + vfree(list); return 0; } } mutex_unlock(&list->hiddev->existancelock); - kfree(list); + vfree(list); return 0; } @@ -278,7 +279,7 @@ static int hiddev_open(struct inode *inode, struct file *file) hid = usb_get_intfdata(intf); hiddev = hid->hiddev; - if (!(list = kzalloc(sizeof(struct hiddev_list), GFP_KERNEL))) + if (!(list = vzalloc(sizeof(struct hiddev_list)))) return -ENOMEM; mutex_init(&list->thread_lock); list->hiddev = hiddev; @@ -322,7 +323,7 @@ bail_unlock: mutex_unlock(&hiddev->existancelock); bail: file->private_data = NULL; - kfree(list); + vfree(list); return res; } -- cgit v1.2.2 From 070748ed0b52399858a5967026a452bbb903a64c Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 23 Apr 2012 12:07:05 +0200 Subject: HID: Create a generic device group Devices that do not have a special driver are handled by the generic driver. This patch does the same thing using device groups; Instead of forcing a particular driver, the appropriate driver is picked up by udev. As a consequence, one can now move a device from generic to specific handling by a simple rebind. By adding a new device id to the generic driver, the same thing can be done in reverse. Signed-off-by: Henrik Rydberg Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/hid-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/hid/usbhid') diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 5bf91dbad59d..9abf718318ca 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -1505,7 +1505,7 @@ static struct usb_driver hid_driver = { }; static const struct hid_device_id hid_usb_table[] = { - { HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) }, + { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, HID_ANY_ID, HID_ANY_ID) }, { } }; -- cgit v1.2.2 From 8215d557e5f3a70e50e07c857d35c250fee62a73 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 23 Apr 2012 12:07:07 +0200 Subject: HID: Create a common generic driver Move the hid drivers of the bus drivers to a common generic hid driver, and make it a proper module. This ought to simplify device handling moving forward. Cc: Gustavo Padovan Signed-off-by: Henrik Rydberg Signed-off-by: Jiri Kosina --- drivers/hid/usbhid/hid-core.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'drivers/hid/usbhid') diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c index 9abf718318ca..9cba5006b5ed 100644 --- a/drivers/hid/usbhid/hid-core.c +++ b/drivers/hid/usbhid/hid-core.c @@ -1504,28 +1504,15 @@ static struct usb_driver hid_driver = { .supports_autosuspend = 1, }; -static const struct hid_device_id hid_usb_table[] = { - { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, HID_ANY_ID, HID_ANY_ID) }, - { } -}; - struct usb_interface *usbhid_find_interface(int minor) { return usb_find_interface(&hid_driver, minor); } -static struct hid_driver hid_usb_driver = { - .name = "generic-usb", - .id_table = hid_usb_table, -}; - static int __init hid_init(void) { int retval = -ENOMEM; - retval = hid_register_driver(&hid_usb_driver); - if (retval) - goto hid_register_fail; retval = usbhid_quirks_init(quirks_param); if (retval) goto usbhid_quirks_init_fail; @@ -1538,8 +1525,6 @@ static int __init hid_init(void) usb_register_fail: usbhid_quirks_exit(); usbhid_quirks_init_fail: - hid_unregister_driver(&hid_usb_driver); -hid_register_fail: return retval; } @@ -1547,7 +1532,6 @@ static void __exit hid_exit(void) { usb_deregister(&hid_driver); usbhid_quirks_exit(); - hid_unregister_driver(&hid_usb_driver); } module_init(hid_init); -- cgit v1.2.2