diff options
Diffstat (limited to 'drivers/usb/input/hid-core.c')
-rw-r--r-- | drivers/usb/input/hid-core.c | 68 |
1 files changed, 56 insertions, 12 deletions
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c index a6738a83ff5b..6daf85c6eeee 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 | ||
273 | static __inline__ __u32 item_udata(struct hid_item *item) | 273 | static 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 | ||
283 | static __inline__ __s32 item_sdata(struct hid_item *item) | 283 | static 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 | ||
730 | static __inline__ __s32 snto32(__u32 value, unsigned n) | 730 | static 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 | ||
744 | static __inline__ __u32 s32ton(__s32 value, unsigned n) | 744 | static 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 | ||
756 | static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n) | 764 | static __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 | */ | ||
762 | static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) | 786 | static __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 | /* |
@@ -1381,6 +1416,9 @@ void hid_close(struct hid_device *hid) | |||
1381 | 1416 | ||
1382 | #define USB_VENDOR_ID_PANJIT 0x134c | 1417 | #define USB_VENDOR_ID_PANJIT 0x134c |
1383 | 1418 | ||
1419 | #define USB_VENDOR_ID_TURBOX 0x062a | ||
1420 | #define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201 | ||
1421 | |||
1384 | /* | 1422 | /* |
1385 | * Initialize all reports | 1423 | * Initialize all reports |
1386 | */ | 1424 | */ |
@@ -1602,6 +1640,9 @@ void hid_init_reports(struct hid_device *hid) | |||
1602 | #define USB_VENDOR_ID_SUN 0x0430 | 1640 | #define USB_VENDOR_ID_SUN 0x0430 |
1603 | #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab | 1641 | #define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab |
1604 | 1642 | ||
1643 | #define USB_VENDOR_ID_AIRCABLE 0x16CA | ||
1644 | #define USB_DEVICE_ID_AIRCABLE1 0x1502 | ||
1645 | |||
1605 | /* | 1646 | /* |
1606 | * Alphabetically sorted blacklist by quirk type. | 1647 | * Alphabetically sorted blacklist by quirk type. |
1607 | */ | 1648 | */ |
@@ -1619,6 +1660,7 @@ static const struct hid_blacklist { | |||
1619 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE }, | 1660 | { 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 }, | 1661 | { 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 }, | 1662 | { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE }, |
1663 | { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE }, | ||
1622 | { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE }, | 1664 | { 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 }, | 1665 | { 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 }, | 1666 | { USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40, HID_QUIRK_IGNORE }, |
@@ -1768,6 +1810,8 @@ static const struct hid_blacklist { | |||
1768 | { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE }, | 1810 | { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE }, |
1769 | { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE }, | 1811 | { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE }, |
1770 | 1812 | ||
1813 | { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, | ||
1814 | |||
1771 | { 0, 0 } | 1815 | { 0, 0 } |
1772 | }; | 1816 | }; |
1773 | 1817 | ||