aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/input/hid-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/input/hid-core.c')
-rw-r--r--drivers/usb/input/hid-core.c158
1 files changed, 113 insertions, 45 deletions
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index a6738a83ff5b..a49644b7c58e 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -270,7 +270,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
270 * Read data value from item. 270 * Read data value from item.
271 */ 271 */
272 272
273static __inline__ __u32 item_udata(struct hid_item *item) 273static u32 item_udata(struct hid_item *item)
274{ 274{
275 switch (item->size) { 275 switch (item->size) {
276 case 1: return item->data.u8; 276 case 1: return item->data.u8;
@@ -280,7 +280,7 @@ static __inline__ __u32 item_udata(struct hid_item *item)
280 return 0; 280 return 0;
281} 281}
282 282
283static __inline__ __s32 item_sdata(struct hid_item *item) 283static s32 item_sdata(struct hid_item *item)
284{ 284{
285 switch (item->size) { 285 switch (item->size) {
286 case 1: return item->data.s8; 286 case 1: return item->data.s8;
@@ -727,7 +727,7 @@ static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
727 * done by hand. 727 * done by hand.
728 */ 728 */
729 729
730static __inline__ __s32 snto32(__u32 value, unsigned n) 730static s32 snto32(__u32 value, unsigned n)
731{ 731{
732 switch (n) { 732 switch (n) {
733 case 8: return ((__s8)value); 733 case 8: return ((__s8)value);
@@ -741,30 +741,65 @@ static __inline__ __s32 snto32(__u32 value, unsigned n)
741 * Convert a signed 32-bit integer to a signed n-bit integer. 741 * Convert a signed 32-bit integer to a signed n-bit integer.
742 */ 742 */
743 743
744static __inline__ __u32 s32ton(__s32 value, unsigned n) 744static u32 s32ton(__s32 value, unsigned n)
745{ 745{
746 __s32 a = value >> (n - 1); 746 s32 a = value >> (n - 1);
747 if (a && a != -1) 747 if (a && a != -1)
748 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1; 748 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
749 return value & ((1 << n) - 1); 749 return value & ((1 << n) - 1);
750} 750}
751 751
752/* 752/*
753 * Extract/implement a data field from/to a report. 753 * Extract/implement a data field from/to a little endian report (bit array).
754 *
755 * Code sort-of follows HID spec:
756 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
757 *
758 * While the USB HID spec allows unlimited length bit fields in "report
759 * descriptors", most devices never use more than 16 bits.
760 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
761 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
754 */ 762 */
755 763
756static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n) 764static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
757{ 765{
758 report += (offset >> 5) << 2; offset &= 31; 766 u64 x;
759 return (le64_to_cpu(get_unaligned((__le64*)report)) >> offset) & ((1ULL << n) - 1); 767
768 WARN_ON(n > 32);
769
770 report += offset >> 3; /* adjust byte index */
771 offset &= 7; /* now only need bit offset into one byte */
772 x = get_unaligned((u64 *) report);
773 x = le64_to_cpu(x);
774 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
775 return (u32) x;
760} 776}
761 777
778/*
779 * "implement" : set bits in a little endian bit stream.
780 * Same concepts as "extract" (see comments above).
781 * The data mangled in the bit stream remains in little endian
782 * order the whole time. It make more sense to talk about
783 * endianness of register values by considering a register
784 * a "cached" copy of the little endiad bit stream.
785 */
762static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) 786static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
763{ 787{
764 report += (offset >> 5) << 2; offset &= 31; 788 u64 x;
765 put_unaligned((get_unaligned((__le64*)report) 789 u64 m = (1ULL << n) - 1;
766 & cpu_to_le64(~((((__u64) 1 << n) - 1) << offset))) 790
767 | cpu_to_le64((__u64)value << offset), (__le64*)report); 791 WARN_ON(n > 32);
792
793 WARN_ON(value > m);
794 value &= m;
795
796 report += offset >> 3;
797 offset &= 7;
798
799 x = get_unaligned((u64 *)report);
800 x &= cpu_to_le64(~(m << offset));
801 x |= cpu_to_le64(((u64) value) << offset);
802 put_unaligned(x, (u64 *) report);
768} 803}
769 804
770/* 805/*
@@ -933,20 +968,29 @@ static void hid_retry_timeout(unsigned long _hid)
933 hid_io_error(hid); 968 hid_io_error(hid);
934} 969}
935 970
936/* Workqueue routine to reset the device */ 971/* Workqueue routine to reset the device or clear a halt */
937static void hid_reset(void *_hid) 972static void hid_reset(void *_hid)
938{ 973{
939 struct hid_device *hid = (struct hid_device *) _hid; 974 struct hid_device *hid = (struct hid_device *) _hid;
940 int rc_lock, rc; 975 int rc_lock, rc = 0;
941 976
942 dev_dbg(&hid->intf->dev, "resetting device\n"); 977 if (test_bit(HID_CLEAR_HALT, &hid->iofl)) {
943 rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf); 978 dev_dbg(&hid->intf->dev, "clear halt\n");
944 if (rc_lock >= 0) { 979 rc = usb_clear_halt(hid->dev, hid->urbin->pipe);
945 rc = usb_reset_composite_device(hid->dev, hid->intf); 980 clear_bit(HID_CLEAR_HALT, &hid->iofl);
946 if (rc_lock) 981 hid_start_in(hid);
947 usb_unlock_device(hid->dev); 982 }
983
984 else if (test_bit(HID_RESET_PENDING, &hid->iofl)) {
985 dev_dbg(&hid->intf->dev, "resetting device\n");
986 rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf);
987 if (rc_lock >= 0) {
988 rc = usb_reset_composite_device(hid->dev, hid->intf);
989 if (rc_lock)
990 usb_unlock_device(hid->dev);
991 }
992 clear_bit(HID_RESET_PENDING, &hid->iofl);
948 } 993 }
949 clear_bit(HID_RESET_PENDING, &hid->iofl);
950 994
951 switch (rc) { 995 switch (rc) {
952 case 0: 996 case 0:
@@ -988,9 +1032,8 @@ static void hid_io_error(struct hid_device *hid)
988 1032
989 /* Retries failed, so do a port reset */ 1033 /* Retries failed, so do a port reset */
990 if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) { 1034 if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) {
991 if (schedule_work(&hid->reset_work)) 1035 schedule_work(&hid->reset_work);
992 goto done; 1036 goto done;
993 clear_bit(HID_RESET_PENDING, &hid->iofl);
994 } 1037 }
995 } 1038 }
996 1039
@@ -1014,6 +1057,11 @@ static void hid_irq_in(struct urb *urb)
1014 hid->retry_delay = 0; 1057 hid->retry_delay = 0;
1015 hid_input_report(HID_INPUT_REPORT, urb, 1); 1058 hid_input_report(HID_INPUT_REPORT, urb, 1);
1016 break; 1059 break;
1060 case -EPIPE: /* stall */
1061 clear_bit(HID_IN_RUNNING, &hid->iofl);
1062 set_bit(HID_CLEAR_HALT, &hid->iofl);
1063 schedule_work(&hid->reset_work);
1064 return;
1017 case -ECONNRESET: /* unlink */ 1065 case -ECONNRESET: /* unlink */
1018 case -ENOENT: 1066 case -ENOENT:
1019 case -ESHUTDOWN: /* unplug */ 1067 case -ESHUTDOWN: /* unplug */
@@ -1381,6 +1429,9 @@ void hid_close(struct hid_device *hid)
1381 1429
1382#define USB_VENDOR_ID_PANJIT 0x134c 1430#define USB_VENDOR_ID_PANJIT 0x134c
1383 1431
1432#define USB_VENDOR_ID_TURBOX 0x062a
1433#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
1434
1384/* 1435/*
1385 * Initialize all reports 1436 * Initialize all reports
1386 */ 1437 */
@@ -1589,6 +1640,19 @@ void hid_init_reports(struct hid_device *hid)
1589 1640
1590#define USB_VENDOR_ID_APPLE 0x05ac 1641#define USB_VENDOR_ID_APPLE 0x05ac
1591#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304 1642#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
1643#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e
1644#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f
1645#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
1646#define USB_DEVICE_ID_APPLE_GEYSER_ISO 0x0215
1647#define USB_DEVICE_ID_APPLE_GEYSER_JIS 0x0216
1648#define USB_DEVICE_ID_APPLE_GEYSER3_ANSI 0x0217
1649#define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218
1650#define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219
1651#define USB_DEVICE_ID_APPLE_GEYSER4_ANSI 0x021a
1652#define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b
1653#define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c
1654#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
1655#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
1592 1656
1593#define USB_VENDOR_ID_CHERRY 0x046a 1657#define USB_VENDOR_ID_CHERRY 0x046a
1594#define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023 1658#define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023
@@ -1602,6 +1666,9 @@ void hid_init_reports(struct hid_device *hid)
1602#define USB_VENDOR_ID_SUN 0x0430 1666#define USB_VENDOR_ID_SUN 0x0430
1603#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab 1667#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
1604 1668
1669#define USB_VENDOR_ID_AIRCABLE 0x16CA
1670#define USB_DEVICE_ID_AIRCABLE1 0x1502
1671
1605/* 1672/*
1606 * Alphabetically sorted blacklist by quirk type. 1673 * Alphabetically sorted blacklist by quirk type.
1607 */ 1674 */
@@ -1619,6 +1686,7 @@ static const struct hid_blacklist {
1619 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE }, 1686 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE },
1620 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE }, 1687 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE },
1621 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE }, 1688 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE },
1689 { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE },
1622 { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE }, 1690 { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE },
1623 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE }, 1691 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE },
1624 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE }, 1692 { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE },
@@ -1752,22 +1820,27 @@ static const struct hid_blacklist {
1752 1820
1753 { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION }, 1821 { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_CYMOTION },
1754 1822
1755 { USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN }, 1823 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
1756 { USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN }, 1824 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO, HID_QUIRK_POWERBOOK_HAS_FN },
1757 { USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN }, 1825 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
1758 { USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN }, 1826 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
1759 { USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN }, 1827 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
1760 { USB_VENDOR_ID_APPLE, 0x0217, HID_QUIRK_POWERBOOK_HAS_FN }, 1828 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
1761 { USB_VENDOR_ID_APPLE, 0x0218, HID_QUIRK_POWERBOOK_HAS_FN }, 1829 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
1762 { USB_VENDOR_ID_APPLE, 0x0219, HID_QUIRK_POWERBOOK_HAS_FN }, 1830 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
1763 { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN }, 1831 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN },
1764 { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN }, 1832 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN },
1833 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN },
1834 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
1835 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN },
1765 1836
1766 { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE }, 1837 { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE },
1767 { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE }, 1838 { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE },
1768 { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE }, 1839 { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE },
1769 { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE }, 1840 { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE },
1770 1841
1842 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
1843
1771 { 0, 0 } 1844 { 0, 0 }
1772}; 1845};
1773 1846
@@ -1940,7 +2013,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1940 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) 2013 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
1941 interval = hid_mousepoll_interval; 2014 interval = hid_mousepoll_interval;
1942 2015
1943 if (endpoint->bEndpointAddress & USB_DIR_IN) { 2016 if (usb_endpoint_dir_in(endpoint)) {
1944 if (hid->urbin) 2017 if (hid->urbin)
1945 continue; 2018 continue;
1946 if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL))) 2019 if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
@@ -2022,13 +2095,9 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
2022 return hid; 2095 return hid;
2023 2096
2024fail: 2097fail:
2025 2098 usb_free_urb(hid->urbin);
2026 if (hid->urbin) 2099 usb_free_urb(hid->urbout);
2027 usb_free_urb(hid->urbin); 2100 usb_free_urb(hid->urbctrl);
2028 if (hid->urbout)
2029 usb_free_urb(hid->urbout);
2030 if (hid->urbctrl)
2031 usb_free_urb(hid->urbctrl);
2032 hid_free_buffers(dev, hid); 2101 hid_free_buffers(dev, hid);
2033 hid_free_device(hid); 2102 hid_free_device(hid);
2034 2103
@@ -2059,8 +2128,7 @@ static void hid_disconnect(struct usb_interface *intf)
2059 2128
2060 usb_free_urb(hid->urbin); 2129 usb_free_urb(hid->urbin);
2061 usb_free_urb(hid->urbctrl); 2130 usb_free_urb(hid->urbctrl);
2062 if (hid->urbout) 2131 usb_free_urb(hid->urbout);
2063 usb_free_urb(hid->urbout);
2064 2132
2065 hid_free_buffers(hid->dev, hid); 2133 hid_free_buffers(hid->dev, hid);
2066 hid_free_device(hid); 2134 hid_free_device(hid);