diff options
author | Benjamin Tissoires <benjamin.tissoires@redhat.com> | 2013-08-22 08:51:07 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2013-08-27 04:00:00 -0400 |
commit | 3dc8fc083dbfeede7b63a0c07581192e97711365 (patch) | |
tree | 0d3b7b292e7029503f45a9db17a752726c603cb1 /drivers/hid | |
parent | c08d46aa805ba46d501f610c2448d07bea979780 (diff) |
HID: Use hid_parser for pre-scanning the report descriptors
The Win 8 detection is sufficiently complex to warrant use of the full
parser code, in spite of the inferred memory usage. Therefore, we can use
the existing HID parser in hid-core for hid_scan_report() by re-using the
code from hid_open_report(). hid_parser_global, hid_parser_local and
hid_parser_reserved does not have any side effects. We just need to
reimplement the MAIN_ITEM callback to have a proper parsing without side
effects.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Reviewed-by: Henrik Rydberg <rydberg@euromail.se>
Tested-by: Srinivas Pandruvada<srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r-- | drivers/hid/hid-core.c | 102 |
1 files changed, 64 insertions, 38 deletions
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index e39dac68063c..ddd95f3e33c0 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c | |||
@@ -677,12 +677,52 @@ static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item) | |||
677 | return NULL; | 677 | return NULL; |
678 | } | 678 | } |
679 | 679 | ||
680 | static void hid_scan_usage(struct hid_device *hid, u32 usage) | 680 | static void hid_scan_input_usage(struct hid_parser *parser, u32 usage) |
681 | { | 681 | { |
682 | struct hid_device *hid = parser->device; | ||
683 | |||
682 | if (usage == HID_DG_CONTACTID) | 684 | if (usage == HID_DG_CONTACTID) |
683 | hid->group = HID_GROUP_MULTITOUCH; | 685 | hid->group = HID_GROUP_MULTITOUCH; |
684 | } | 686 | } |
685 | 687 | ||
688 | static void hid_scan_collection(struct hid_parser *parser, unsigned type) | ||
689 | { | ||
690 | struct hid_device *hid = parser->device; | ||
691 | |||
692 | if (((parser->global.usage_page << 16) == HID_UP_SENSOR) && | ||
693 | type == HID_COLLECTION_PHYSICAL) | ||
694 | hid->group = HID_GROUP_SENSOR_HUB; | ||
695 | } | ||
696 | |||
697 | static int hid_scan_main(struct hid_parser *parser, struct hid_item *item) | ||
698 | { | ||
699 | __u32 data; | ||
700 | int i; | ||
701 | |||
702 | data = item_udata(item); | ||
703 | |||
704 | switch (item->tag) { | ||
705 | case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: | ||
706 | hid_scan_collection(parser, data & 0xff); | ||
707 | break; | ||
708 | case HID_MAIN_ITEM_TAG_END_COLLECTION: | ||
709 | break; | ||
710 | case HID_MAIN_ITEM_TAG_INPUT: | ||
711 | for (i = 0; i < parser->local.usage_index; i++) | ||
712 | hid_scan_input_usage(parser, parser->local.usage[i]); | ||
713 | break; | ||
714 | case HID_MAIN_ITEM_TAG_OUTPUT: | ||
715 | break; | ||
716 | case HID_MAIN_ITEM_TAG_FEATURE: | ||
717 | break; | ||
718 | } | ||
719 | |||
720 | /* Reset the local parser environment */ | ||
721 | memset(&parser->local, 0, sizeof(parser->local)); | ||
722 | |||
723 | return 0; | ||
724 | } | ||
725 | |||
686 | /* | 726 | /* |
687 | * Scan a report descriptor before the device is added to the bus. | 727 | * Scan a report descriptor before the device is added to the bus. |
688 | * Sets device groups and other properties that determine what driver | 728 | * Sets device groups and other properties that determine what driver |
@@ -690,48 +730,34 @@ static void hid_scan_usage(struct hid_device *hid, u32 usage) | |||
690 | */ | 730 | */ |
691 | static int hid_scan_report(struct hid_device *hid) | 731 | static int hid_scan_report(struct hid_device *hid) |
692 | { | 732 | { |
693 | unsigned int page = 0, delim = 0; | 733 | struct hid_parser *parser; |
734 | struct hid_item item; | ||
694 | __u8 *start = hid->dev_rdesc; | 735 | __u8 *start = hid->dev_rdesc; |
695 | __u8 *end = start + hid->dev_rsize; | 736 | __u8 *end = start + hid->dev_rsize; |
696 | unsigned int u, u_min = 0, u_max = 0; | 737 | static int (*dispatch_type[])(struct hid_parser *parser, |
697 | struct hid_item item; | 738 | struct hid_item *item) = { |
739 | hid_scan_main, | ||
740 | hid_parser_global, | ||
741 | hid_parser_local, | ||
742 | hid_parser_reserved | ||
743 | }; | ||
744 | |||
745 | parser = vzalloc(sizeof(struct hid_parser)); | ||
746 | if (!parser) | ||
747 | return -ENOMEM; | ||
698 | 748 | ||
749 | parser->device = hid; | ||
699 | hid->group = HID_GROUP_GENERIC; | 750 | hid->group = HID_GROUP_GENERIC; |
700 | while ((start = fetch_item(start, end, &item)) != NULL) { | ||
701 | if (item.format != HID_ITEM_FORMAT_SHORT) | ||
702 | return -EINVAL; | ||
703 | if (item.type == HID_ITEM_TYPE_GLOBAL) { | ||
704 | if (item.tag == HID_GLOBAL_ITEM_TAG_USAGE_PAGE) | ||
705 | page = item_udata(&item) << 16; | ||
706 | } else if (item.type == HID_ITEM_TYPE_LOCAL) { | ||
707 | if (delim > 1) | ||
708 | break; | ||
709 | u = item_udata(&item); | ||
710 | if (item.size <= 2) | ||
711 | u += page; | ||
712 | switch (item.tag) { | ||
713 | case HID_LOCAL_ITEM_TAG_DELIMITER: | ||
714 | delim += !!u; | ||
715 | break; | ||
716 | case HID_LOCAL_ITEM_TAG_USAGE: | ||
717 | hid_scan_usage(hid, u); | ||
718 | break; | ||
719 | case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: | ||
720 | u_min = u; | ||
721 | break; | ||
722 | case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: | ||
723 | u_max = u; | ||
724 | for (u = u_min; u <= u_max; u++) | ||
725 | hid_scan_usage(hid, u); | ||
726 | break; | ||
727 | } | ||
728 | } else if (page == HID_UP_SENSOR && | ||
729 | item.type == HID_ITEM_TYPE_MAIN && | ||
730 | item.tag == HID_MAIN_ITEM_TAG_BEGIN_COLLECTION && | ||
731 | (item_udata(&item) & 0xff) == HID_COLLECTION_PHYSICAL) | ||
732 | hid->group = HID_GROUP_SENSOR_HUB; | ||
733 | } | ||
734 | 751 | ||
752 | /* | ||
753 | * The parsing is simpler than the one in hid_open_report() as we should | ||
754 | * be robust against hid errors. Those errors will be raised by | ||
755 | * hid_open_report() anyway. | ||
756 | */ | ||
757 | while ((start = fetch_item(start, end, &item)) != NULL) | ||
758 | dispatch_type[item.type](parser, &item); | ||
759 | |||
760 | vfree(parser); | ||
735 | return 0; | 761 | return 0; |
736 | } | 762 | } |
737 | 763 | ||