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.c68
1 files changed, 49 insertions, 19 deletions
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 45f44fe33bfe..6d08a3bcc952 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,9 +741,9 @@ 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);
@@ -751,30 +751,55 @@ static __inline__ __u32 s32ton(__s32 value, unsigned n)
751 751
752/* 752/*
753 * Extract/implement a data field from/to a little endian report (bit array). 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 u32 x; 766 u64 x;
767
768 WARN_ON(n > 32);
759 769
760 report += offset >> 3; /* adjust byte index */ 770 report += offset >> 3; /* adjust byte index */
761 offset &= 8 - 1; 771 offset &= 7; /* now only need bit offset into one byte */
762 x = get_unaligned((u32 *) report); 772 x = get_unaligned((u64 *) report);
763 x = le32_to_cpu(x); 773 x = le64_to_cpu(x);
764 x = (x >> offset) & ((1 << n) - 1); 774 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
765 return x; 775 return (u32) x;
766} 776}
767 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 */
768static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value) 786static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
769{ 787{
770 u32 x; 788 u64 x;
789 u64 m = (1ULL << n) - 1;
790
791 WARN_ON(n > 32);
792
793 WARN_ON(value > m);
794 value &= m;
771 795
772 report += offset >> 3; 796 report += offset >> 3;
773 offset &= 8 - 1; 797 offset &= 7;
774 x = get_unaligned((u32 *)report); 798
775 x &= cpu_to_le32(~((((__u32) 1 << n) - 1) << offset)); 799 x = get_unaligned((u64 *)report);
776 x |= cpu_to_le32(value << offset); 800 x &= cpu_to_le64(~(m << offset));
777 put_unaligned(x,(u32 *)report); 801 x |= cpu_to_le64(((u64) value) << offset);
802 put_unaligned(x, (u64 *) report);
778} 803}
779 804
780/* 805/*
@@ -1615,6 +1640,9 @@ void hid_init_reports(struct hid_device *hid)
1615#define USB_VENDOR_ID_SUN 0x0430 1640#define USB_VENDOR_ID_SUN 0x0430
1616#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab 1641#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
1617 1642
1643#define USB_VENDOR_ID_AIRCABLE 0x16CA
1644#define USB_DEVICE_ID_AIRCABLE1 0x1502
1645
1618/* 1646/*
1619 * Alphabetically sorted blacklist by quirk type. 1647 * Alphabetically sorted blacklist by quirk type.
1620 */ 1648 */
@@ -1632,6 +1660,7 @@ static const struct hid_blacklist {
1632 { 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 },
1633 { 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 },
1634 { 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 },
1635 { 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 },
1636 { 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 },
1637 { 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,11 +1797,12 @@ static const struct hid_blacklist {
1768 { USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN }, 1797 { USB_VENDOR_ID_APPLE, 0x020E, HID_QUIRK_POWERBOOK_HAS_FN },
1769 { USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN }, 1798 { USB_VENDOR_ID_APPLE, 0x020F, HID_QUIRK_POWERBOOK_HAS_FN },
1770 { USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN }, 1799 { USB_VENDOR_ID_APPLE, 0x0214, HID_QUIRK_POWERBOOK_HAS_FN },
1771 { USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN }, 1800 { USB_VENDOR_ID_APPLE, 0x0215, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
1772 { USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN }, 1801 { USB_VENDOR_ID_APPLE, 0x0216, HID_QUIRK_POWERBOOK_HAS_FN },
1773 { USB_VENDOR_ID_APPLE, 0x0217, HID_QUIRK_POWERBOOK_HAS_FN }, 1802 { USB_VENDOR_ID_APPLE, 0x0217, HID_QUIRK_POWERBOOK_HAS_FN },
1774 { USB_VENDOR_ID_APPLE, 0x0218, HID_QUIRK_POWERBOOK_HAS_FN }, 1803 { USB_VENDOR_ID_APPLE, 0x0218, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
1775 { USB_VENDOR_ID_APPLE, 0x0219, HID_QUIRK_POWERBOOK_HAS_FN }, 1804 { USB_VENDOR_ID_APPLE, 0x0219, HID_QUIRK_POWERBOOK_HAS_FN },
1805 { USB_VENDOR_ID_APPLE, 0x021B, HID_QUIRK_POWERBOOK_HAS_FN },
1776 { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN }, 1806 { USB_VENDOR_ID_APPLE, 0x030A, HID_QUIRK_POWERBOOK_HAS_FN },
1777 { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN }, 1807 { USB_VENDOR_ID_APPLE, 0x030B, HID_QUIRK_POWERBOOK_HAS_FN },
1778 1808