Lines Matching full:hid
3 * HID support for Linux
31 #include <linux/hid.h>
33 #include <linux/hid-debug.h>
36 #include "hid-ids.h"
42 #define DRIVER_DESC "HID core driver"
318 field->usage[i].hid = parser->local.usage[j]; in hid_add_field()
423 * nibble due to the common misunderstanding of HID in hid_parser_global()
707 struct hid_device *hid = container_of(ref, struct hid_device, ref); in hiddev_free() local
709 hid_close_report(hid); in hiddev_free()
710 kfree(hid->dev_rdesc); in hiddev_free()
711 kfree(hid); in hiddev_free()
716 struct hid_device *hid = to_hid_device(dev); in hid_device_release() local
718 kref_put(&hid->ref, hiddev_free); in hid_device_release()
790 struct hid_device *hid = parser->device; in hid_scan_input_usage() local
793 hid->group = HID_GROUP_MULTITOUCH; in hid_scan_input_usage()
809 struct hid_device *hid = parser->device; in hid_scan_collection() local
815 hid->group = HID_GROUP_SENSOR_HUB; in hid_scan_collection()
817 if (hid->vendor == USB_VENDOR_ID_MICROSOFT && in hid_scan_collection()
818 hid->product == USB_DEVICE_ID_MS_POWER_COVER && in hid_scan_collection()
819 hid->group == HID_GROUP_MULTITOUCH) in hid_scan_collection()
820 hid->group = HID_GROUP_GENERIC; in hid_scan_collection()
854 /* ignore constant inputs, they will be ignored by hid-input */ in hid_scan_main()
879 static int hid_scan_report(struct hid_device *hid) in hid_scan_report() argument
883 __u8 *start = hid->dev_rdesc; in hid_scan_report()
884 __u8 *end = start + hid->dev_rsize; in hid_scan_report()
897 parser->device = hid; in hid_scan_report()
898 hid->group = HID_GROUP_GENERIC; in hid_scan_report()
902 * be robust against hid errors. Those errors will be raised by in hid_scan_report()
912 (hid->group == HID_GROUP_MULTITOUCH)) in hid_scan_report()
913 hid->group = HID_GROUP_MULTITOUCH_WIN_8; in hid_scan_report()
918 switch (hid->vendor) { in hid_scan_report()
920 hid->group = HID_GROUP_WACOM; in hid_scan_report()
923 if (hid->group == HID_GROUP_GENERIC) in hid_scan_report()
927 * hid-rmi should take care of them, in hid_scan_report()
928 * not hid-generic in hid_scan_report()
930 hid->group = HID_GROUP_RMI; in hid_scan_report()
942 * @hid: hid device
949 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size) in hid_parse_report() argument
951 hid->dev_rdesc = kmemdup(start, size, GFP_KERNEL); in hid_parse_report()
952 if (!hid->dev_rdesc) in hid_parse_report()
954 hid->dev_rsize = size; in hid_parse_report()
967 * @hid: hid device
976 struct hid_report *hid_validate_values(struct hid_device *hid, in hid_validate_values() argument
984 hid_err(hid, "invalid HID report type %u\n", type); in hid_validate_values()
989 hid_err(hid, "invalid HID report id %u\n", id); in hid_validate_values()
1004 &hid->report_enum[type].report_list, in hid_validate_values()
1007 report = hid->report_enum[type].report_id_hash[id]; in hid_validate_values()
1010 hid_err(hid, "missing %s %u\n", hid_report_names[type], id); in hid_validate_values()
1014 hid_err(hid, "not enough fields in %s %u\n", in hid_validate_values()
1019 hid_err(hid, "not enough values in %s %u field %u\n", in hid_validate_values()
1027 static int hid_calculate_multiplier(struct hid_device *hid, in hid_calculate_multiplier() argument
1042 * HID Usage Table, v1.12, Section 4.3.1, p31 in hid_calculate_multiplier()
1052 hid_warn(hid, in hid_calculate_multiplier()
1059 hid_warn(hid, "unsupported Resolution Multiplier %d\n", m); in hid_calculate_multiplier()
1066 static void hid_apply_multiplier_to_field(struct hid_device *hid, in hid_apply_multiplier_to_field() argument
1084 collection = &hid->collection[usage->collection_index]; in hid_apply_multiplier_to_field()
1087 collection = &hid->collection[collection->parent_idx]; in hid_apply_multiplier_to_field()
1096 static void hid_apply_multiplier(struct hid_device *hid, in hid_apply_multiplier() argument
1115 * HID Usage Table, v1.12, Section 4.3.1, p30 in hid_apply_multiplier()
1124 multiplier_collection = &hid->collection[multiplier->usage->collection_index]; in hid_apply_multiplier()
1127 multiplier_collection = &hid->collection[multiplier_collection->parent_idx]; in hid_apply_multiplier()
1129 effective_multiplier = hid_calculate_multiplier(hid, multiplier); in hid_apply_multiplier()
1131 rep_enum = &hid->report_enum[HID_INPUT_REPORT]; in hid_apply_multiplier()
1135 hid_apply_multiplier_to_field(hid, field, in hid_apply_multiplier()
1145 * @device: hid device
1165 void hid_setup_resolution_multiplier(struct hid_device *hid) in hid_setup_resolution_multiplier() argument
1172 rep_enum = &hid->report_enum[HID_FEATURE_REPORT]; in hid_setup_resolution_multiplier()
1181 if (usage->hid == HID_GD_RESOLUTION_MULTIPLIER) in hid_setup_resolution_multiplier()
1182 hid_apply_multiplier(hid, in hid_setup_resolution_multiplier()
1193 * @device: hid device
1361 * Code sort-of follows HID spec:
1364 * While the USB HID spec allows unlimited length bit fields in "report
1367 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
1391 u32 hid_field_extract(const struct hid_device *hid, u8 *report, in hid_field_extract() argument
1395 hid_warn_once(hid, "%s() called with n (%d) > 32! (%s)\n", in hid_field_extract()
1437 static void implement(const struct hid_device *hid, u8 *report, in implement() argument
1441 hid_warn(hid, "%s() called with n (%d) > 32! (%s)\n", in implement()
1448 hid_warn(hid, in implement()
1475 * @hid: hid device
1476 * @report: hid report to match against
1478 * compare hid->driver->report_table->report_type to report->type
1480 static int hid_match_report(struct hid_device *hid, struct hid_report *report) in hid_match_report() argument
1482 const struct hid_report_id *id = hid->driver->report_table; in hid_match_report()
1497 * @hid: hid device
1500 * compare hid->driver->usage_table->usage_{type,code} to
1503 static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage) in hid_match_usage() argument
1505 const struct hid_usage_id *id = hid->driver->usage_table; in hid_match_usage()
1512 id->usage_hid == usage->hid) && in hid_match_usage()
1521 static void hid_process_event(struct hid_device *hid, struct hid_field *field, in hid_process_event() argument
1524 struct hid_driver *hdrv = hid->driver; in hid_process_event()
1527 if (!list_empty(&hid->debug_list)) in hid_process_event()
1528 hid_dump_input(hid, usage, value); in hid_process_event()
1530 if (hdrv && hdrv->event && hid_match_usage(hid, usage)) { in hid_process_event()
1531 ret = hdrv->event(hid, field, usage, value); in hid_process_event()
1534 hid_err(hid, "%s's event failed with %d\n", in hid_process_event()
1540 if (hid->claimed & HID_CLAIMED_INPUT) in hid_process_event()
1541 hidinput_hid_event(hid, field, usage, value); in hid_process_event()
1542 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) in hid_process_event()
1543 hid->hiddev_hid_event(hid, field, usage, value); in hid_process_event()
1568 static void hid_input_fetch_field(struct hid_device *hid, in hid_input_fetch_field() argument
1586 snto32(hid_field_extract(hid, data, offset + n * size, in hid_input_fetch_field()
1588 hid_field_extract(hid, data, offset + n * size, size); in hid_input_fetch_field()
1593 field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1) { in hid_input_fetch_field()
1604 static void hid_input_var_field(struct hid_device *hid, in hid_input_var_field() argument
1613 hid_process_event(hid, in hid_input_var_field()
1627 static void hid_input_array_field(struct hid_device *hid, in hid_input_array_field() argument
1645 hid_process_event(hid, in hid_input_array_field()
1653 hid_process_event(hid, in hid_input_array_field()
1668 static void hid_process_report(struct hid_device *hid, in hid_process_report() argument
1679 hid_input_fetch_field(hid, report->field[a], data); in hid_process_report()
1689 hid_process_event(hid, in hid_process_report()
1695 hid_input_array_field(hid, field, interrupt); in hid_process_report()
1712 hid_input_var_field(hid, field, interrupt); in hid_process_report()
1714 hid_input_array_field(hid, field, interrupt); in hid_process_report()
1726 static void __hid_insert_field_entry(struct hid_device *hid, in __hid_insert_field_entry() argument
1756 static void hid_report_process_ordering(struct hid_device *hid, in hid_report_process_ordering() argument
1794 __hid_insert_field_entry(hid, report, in hid_report_process_ordering()
1800 __hid_insert_field_entry(hid, report, &entries[usages], in hid_report_process_ordering()
1807 static void hid_process_ordering(struct hid_device *hid) in hid_process_ordering() argument
1810 struct hid_report_enum *report_enum = &hid->report_enum[HID_INPUT_REPORT]; in hid_process_ordering()
1813 hid_report_process_ordering(hid, report); in hid_process_ordering()
1820 static void hid_output_field(const struct hid_device *hid, in hid_output_field() argument
1830 implement(hid, data, offset + n * size, size, in hid_output_field()
1833 implement(hid, data, offset + n * size, size, in hid_output_field()
1935 * DO NOT USE in hid drivers directly, but through hid_hw_request instead.
1937 int __hid_request(struct hid_device *hid, struct hid_report *report, in __hid_request() argument
1953 ret = hid->ll_driver->raw_request(hid, report->id, buf, len, in __hid_request()
1961 hid_input_report(hid, report->type, buf, ret, 0); in __hid_request()
1971 int hid_report_raw_event(struct hid_device *hid, enum hid_report_type type, u8 *data, u32 size, in hid_report_raw_event() argument
1974 struct hid_report_enum *report_enum = hid->report_enum + type; in hid_report_raw_event()
1993 if (hid->ll_driver->max_buffer_size) in hid_report_raw_event()
1994 max_buffer_size = hid->ll_driver->max_buffer_size; in hid_report_raw_event()
2007 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) in hid_report_raw_event()
2008 hid->hiddev_report_event(hid, report); in hid_report_raw_event()
2009 if (hid->claimed & HID_CLAIMED_HIDRAW) { in hid_report_raw_event()
2010 ret = hidraw_report_event(hid, data, size); in hid_report_raw_event()
2015 if (hid->claimed != HID_CLAIMED_HIDRAW && report->maxfield) { in hid_report_raw_event()
2016 hid_process_report(hid, report, cdata, interrupt); in hid_report_raw_event()
2017 hdrv = hid->driver; in hid_report_raw_event()
2019 hdrv->report(hid, report); in hid_report_raw_event()
2022 if (hid->claimed & HID_CLAIMED_INPUT) in hid_report_raw_event()
2023 hidinput_report_event(hid, report); in hid_report_raw_event()
2032 * @hid: hid device
2033 * @type: HID report type (HID_*_REPORT)
2040 int hid_input_report(struct hid_device *hid, enum hid_report_type type, u8 *data, u32 size, in hid_input_report() argument
2048 if (!hid) in hid_input_report()
2051 if (down_trylock(&hid->driver_input_lock)) in hid_input_report()
2054 if (!hid->driver) { in hid_input_report()
2058 report_enum = hid->report_enum + type; in hid_input_report()
2059 hdrv = hid->driver; in hid_input_report()
2061 data = dispatch_hid_bpf_device_event(hid, type, data, &size, interrupt); in hid_input_report()
2074 if (!list_empty(&hid->debug_list)) in hid_input_report()
2075 hid_dump_report(hid, type, data, size); in hid_input_report()
2084 if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) { in hid_input_report()
2085 ret = hdrv->raw_event(hid, report, data, size); in hid_input_report()
2090 ret = hid_report_raw_event(hid, type, data, size, interrupt); in hid_input_report()
2093 up(&hid->driver_input_lock); in hid_input_report()
2268 hid_info(hdev, "%s: %s HID v%x.%02x %s [%s] on %s\n", in hid_connect()
2293 * @hdev: hid device
2322 * @hdev: hid device
2336 * @hdev: hid device
2364 * @hdev: hid device
2382 * @hdev: hid device
2384 * @reqtype: hid request type
2399 * @hdev: hid device
2403 * @rtype: HID report type
2430 * @hdev: hid device
2488 * new_id_store - add a new HID device ID to this driver and re-probe devices
2493 * Adds a new dynamic hid device ID to this driver,
2576 * @hdev_a: hid device
2577 * @hdev_b: hid device
2609 * hid-generic implements .match(), so we must be dealing with a in hid_check_device_match()
2610 * different HID driver here, and can simply check if in hid_check_device_match()
2709 return scnprintf(buf, PAGE_SIZE, "hid:b%04Xg%04Xv%08Xp%08X\n", in modalias_show()
2745 if (add_uevent_var(env, "MODALIAS=hid:b%04Xg%04Xv%08Xp%08X", in hid_uevent()
2753 .name = "hid",
2827 * hid_allocate_device - allocate new hid device descriptor
2829 * Allocate and initialize hid device, so that hid_destroy_device might be
2879 * @hdev: hid device
2955 int hid_check_keys_pressed(struct hid_device *hid) in hid_check_keys_pressed() argument
2960 if (!(hid->claimed & HID_CLAIMED_INPUT)) in hid_check_keys_pressed()
2963 list_for_each_entry(hidinput, &hid->inputs, list) { in hid_check_keys_pressed()
2988 pr_err("can't register hid bus\n"); in hid_init()