Lines Matching +full:assigned +full:- +full:resolution +full:- +full:bits

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2000-2001 Vojtech Pavlik
4 * Copyright (c) 2006-2010 Jiri Kosina
12 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
21 #include <linux/hid-debug.h>
23 #include "hid-ids.h"
49 } hid_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1…
62 * hid-input will convert this list into priorities:
67 * hid-input will then shift the priority by 8 bits to leave some space
71 * defined in the next 8 bits (defined by 0xff - slot).
73 * If drivers want to add fields before those, hid-input will
74 * leave out the first 8 bits of the priority value.
110 return (usage->hid & (HID_USAGE_PAGE | HID_USAGE)) == scancode; in match_scancode()
119 return (usage->type == EV_KEY && usage->code == keycode); in match_keycode()
141 list_for_each_entry(report, &hid->report_enum[k].report_list, list) { in hidinput_find_key()
142 for (i = 0; i < report->maxfield; i++) { in hidinput_find_key()
143 for (j = 0; j < report->field[i]->maxusage; j++) { in hidinput_find_key()
144 usage = report->field[i]->usage + j; in hidinput_find_key()
145 if (usage->type == EV_KEY || usage->type == 0) { in hidinput_find_key()
167 if (ke->flags & INPUT_KEYMAP_BY_INDEX) in hidinput_locate_usage()
168 usage = hidinput_find_key(hid, match_index, ke->index, index); in hidinput_locate_usage()
186 ke->keycode = usage->type == EV_KEY ? in hidinput_getkeycode()
187 usage->code : KEY_RESERVED; in hidinput_getkeycode()
188 ke->index = index; in hidinput_getkeycode()
189 scancode = usage->hid & (HID_USAGE_PAGE | HID_USAGE); in hidinput_getkeycode()
190 ke->len = sizeof(scancode); in hidinput_getkeycode()
191 memcpy(ke->scancode, &scancode, sizeof(scancode)); in hidinput_getkeycode()
195 return -EINVAL; in hidinput_getkeycode()
207 *old_keycode = usage->type == EV_KEY ? in hidinput_setkeycode()
208 usage->code : KEY_RESERVED; in hidinput_setkeycode()
209 usage->type = EV_KEY; in hidinput_setkeycode()
210 usage->code = ke->keycode; in hidinput_setkeycode()
212 clear_bit(*old_keycode, dev->keybit); in hidinput_setkeycode()
213 set_bit(usage->code, dev->keybit); in hidinput_setkeycode()
214 dbg_hid("Assigned keycode %d to HID usage code %x\n", in hidinput_setkeycode()
215 usage->code, usage->hid); in hidinput_setkeycode()
222 set_bit(*old_keycode, dev->keybit); in hidinput_setkeycode()
227 return -EINVAL; in hidinput_setkeycode()
232 * hidinput_calc_abs_res - calculate an absolute axis resolution
233 * @field: the HID report field to calculate resolution for
237 * (logical_maximum - logical_minimum)
238 * resolution = ----------------------------------------------------------
239 * (physical_maximum - physical_minimum) * 10 ^ unit_exponent
248 __s32 unit_exponent = field->unit_exponent; in hidinput_calc_abs_res()
249 __s32 logical_extents = field->logical_maximum - in hidinput_calc_abs_res()
250 field->logical_minimum; in hidinput_calc_abs_res()
251 __s32 physical_extents = field->physical_maximum - in hidinput_calc_abs_res()
252 field->physical_minimum; in hidinput_calc_abs_res()
273 if (field->unit == 0x11) { /* If centimeters */ in hidinput_calc_abs_res()
276 } else if (field->unit == 0x13) { /* If inches */ in hidinput_calc_abs_res()
282 unit_exponent -= 1; in hidinput_calc_abs_res()
294 if (field->unit == 0x14) { /* If degrees */ in hidinput_calc_abs_res()
301 } else if (field->unit != 0x12) { /* If not radians */ in hidinput_calc_abs_res()
318 for (; unit_exponent > 0; unit_exponent--) { in hidinput_calc_abs_res()
325 /* Calculate resolution */ in hidinput_calc_abs_res()
389 * Elan I2C-HID touchscreens seem to all report a non present battery,
390 * set HID_BATTERY_QUIRK_IGNORE for all Elan I2C-HID devices.
403 quirks = match->driver_data; in find_battery_quirk()
411 if (dev->battery_min < dev->battery_max && in hidinput_scale_battery_capacity()
412 value >= dev->battery_min && value <= dev->battery_max) in hidinput_scale_battery_capacity()
413 value = ((value - dev->battery_min) * 100) / in hidinput_scale_battery_capacity()
414 (dev->battery_max - dev->battery_min); in hidinput_scale_battery_capacity()
426 return -ENOMEM; in hidinput_query_battery_capacity()
428 ret = hid_hw_raw_request(dev, dev->battery_report_id, buf, 4, in hidinput_query_battery_capacity()
429 dev->battery_report_type, HID_REQ_GET_REPORT); in hidinput_query_battery_capacity()
432 return -ENODATA; in hidinput_query_battery_capacity()
451 val->intval = 1; in hidinput_get_battery_property()
455 if (dev->battery_status != HID_BATTERY_REPORTED && in hidinput_get_battery_property()
456 !dev->battery_avoid_query) { in hidinput_get_battery_property()
461 value = dev->battery_capacity; in hidinput_get_battery_property()
464 val->intval = value; in hidinput_get_battery_property()
468 val->strval = dev->name; in hidinput_get_battery_property()
472 if (dev->battery_status != HID_BATTERY_REPORTED && in hidinput_get_battery_property()
473 !dev->battery_avoid_query) { in hidinput_get_battery_property()
478 dev->battery_capacity = value; in hidinput_get_battery_property()
479 dev->battery_status = HID_BATTERY_QUERIED; in hidinput_get_battery_property()
482 if (dev->battery_status == HID_BATTERY_UNKNOWN) in hidinput_get_battery_property()
483 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in hidinput_get_battery_property()
485 val->intval = dev->battery_charge_status; in hidinput_get_battery_property()
489 val->intval = POWER_SUPPLY_SCOPE_DEVICE; in hidinput_get_battery_property()
493 ret = -EINVAL; in hidinput_get_battery_property()
509 if (dev->battery) in hidinput_setup_battery()
515 dev->bus, dev->vendor, dev->product, dev->version, quirks); in hidinput_setup_battery()
522 return -ENOMEM; in hidinput_setup_battery()
524 psy_desc->name = kasprintf(GFP_KERNEL, "hid-%s-battery", in hidinput_setup_battery()
525 strlen(dev->uniq) ? in hidinput_setup_battery()
526 dev->uniq : dev_name(&dev->dev)); in hidinput_setup_battery()
527 if (!psy_desc->name) { in hidinput_setup_battery()
528 error = -ENOMEM; in hidinput_setup_battery()
532 psy_desc->type = POWER_SUPPLY_TYPE_BATTERY; in hidinput_setup_battery()
533 psy_desc->properties = hidinput_battery_props; in hidinput_setup_battery()
534 psy_desc->num_properties = ARRAY_SIZE(hidinput_battery_props); in hidinput_setup_battery()
535 psy_desc->use_for_apm = 0; in hidinput_setup_battery()
536 psy_desc->get_property = hidinput_get_battery_property; in hidinput_setup_battery()
538 min = field->logical_minimum; in hidinput_setup_battery()
539 max = field->logical_maximum; in hidinput_setup_battery()
549 dev->battery_min = min; in hidinput_setup_battery()
550 dev->battery_max = max; in hidinput_setup_battery()
551 dev->battery_report_type = report_type; in hidinput_setup_battery()
552 dev->battery_report_id = field->report->id; in hidinput_setup_battery()
553 dev->battery_charge_status = POWER_SUPPLY_STATUS_DISCHARGING; in hidinput_setup_battery()
560 dev->battery_avoid_query = report_type == HID_INPUT_REPORT && in hidinput_setup_battery()
561 field->physical == HID_DG_STYLUS; in hidinput_setup_battery()
564 dev->battery_avoid_query = true; in hidinput_setup_battery()
566 dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg); in hidinput_setup_battery()
567 if (IS_ERR(dev->battery)) { in hidinput_setup_battery()
568 error = PTR_ERR(dev->battery); in hidinput_setup_battery()
573 power_supply_powers(dev->battery, &dev->dev); in hidinput_setup_battery()
577 kfree(psy_desc->name); in hidinput_setup_battery()
580 dev->battery = NULL; in hidinput_setup_battery()
588 if (!dev->battery) in hidinput_cleanup_battery()
591 psy_desc = dev->battery->desc; in hidinput_cleanup_battery()
592 power_supply_unregister(dev->battery); in hidinput_cleanup_battery()
593 kfree(psy_desc->name); in hidinput_cleanup_battery()
595 dev->battery = NULL; in hidinput_cleanup_battery()
602 if (!dev->battery) in hidinput_update_battery()
605 if (value == 0 || value < dev->battery_min || value > dev->battery_max) in hidinput_update_battery()
610 if (dev->battery_status != HID_BATTERY_REPORTED || in hidinput_update_battery()
611 capacity != dev->battery_capacity || in hidinput_update_battery()
612 ktime_after(ktime_get_coarse(), dev->battery_ratelimit_time)) { in hidinput_update_battery()
613 dev->battery_capacity = capacity; in hidinput_update_battery()
614 dev->battery_status = HID_BATTERY_REPORTED; in hidinput_update_battery()
615 dev->battery_ratelimit_time = in hidinput_update_battery()
617 power_supply_changed(dev->battery); in hidinput_update_battery()
626 dev->battery_charge_status = value ? in hidinput_set_battery_charge_status()
661 collection = &device->collection[field->usage->collection_index]; in hidinput_field_in_collection()
663 return collection->type == type && collection->usage == usage; in hidinput_field_in_collection()
669 struct input_dev *input = hidinput->input; in hidinput_configure_usage()
676 field->hidinput = hidinput; in hidinput_configure_usage()
678 if (field->flags & HID_MAIN_ITEM_CONSTANT) in hidinput_configure_usage()
682 if (field->report_count < 1) in hidinput_configure_usage()
686 if (field->report_type == HID_OUTPUT_REPORT && in hidinput_configure_usage()
687 (usage->hid & HID_USAGE_PAGE) != HID_UP_LED) { in hidinput_configure_usage()
693 if (usage->hid == hidinput_usages_priorities[i].usage) { in hidinput_configure_usage()
696 field->usages_priorities[usage_index] = in hidinput_configure_usage()
697 (ARRAY_SIZE(hidinput_usages_priorities) - i) << 8; in hidinput_configure_usage()
706 if (usage_priority && usage_priority->global) in hidinput_configure_usage()
707 field->usages_priorities[usage_index] |= in hidinput_configure_usage()
708 usage_priority->slot_overwrite; in hidinput_configure_usage()
710 field->usages_priorities[usage_index] |= in hidinput_configure_usage()
711 (0xff - field->slot_idx) << 16; in hidinput_configure_usage()
713 if (device->driver->input_mapping) { in hidinput_configure_usage()
714 int ret = device->driver->input_mapping(device, hidinput, field, in hidinput_configure_usage()
722 switch (usage->hid & HID_USAGE_PAGE) { in hidinput_configure_usage()
727 set_bit(EV_REP, input->evbit); in hidinput_configure_usage()
729 if ((usage->hid & HID_USAGE) < 256) { in hidinput_configure_usage()
730 if (!hid_keyboard[usage->hid & HID_USAGE]) goto ignore; in hidinput_configure_usage()
731 map_key_clear(hid_keyboard[usage->hid & HID_USAGE]); in hidinput_configure_usage()
738 code = ((usage->hid - 1) & HID_USAGE); in hidinput_configure_usage()
740 switch (field->application) { in hidinput_configure_usage()
747 code += BTN_TRIGGER_HAPPY - 0x10; in hidinput_configure_usage()
753 code += BTN_TRIGGER_HAPPY - 0x10; in hidinput_configure_usage()
762 code += BTN_TRIGGER_HAPPY - 0x1e; in hidinput_configure_usage()
767 switch (field->physical) { in hidinput_configure_usage()
780 switch (usage->hid & 0xffff) { in hidinput_configure_usage()
791 if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */ in hidinput_configure_usage()
792 switch (usage->hid & 0xf) { in hidinput_configure_usage()
813 if ((usage->hid & 0xf0) == 0x90) { /* SystemControl*/ in hidinput_configure_usage()
814 switch (usage->hid & 0xf) { in hidinput_configure_usage()
821 if ((usage->hid & 0xf0) == 0xa0) { /* SystemControl */ in hidinput_configure_usage()
822 switch (usage->hid & 0xf) { in hidinput_configure_usage()
830 if ((usage->hid & 0xf0) == 0xb0) { /* SC - Display */ in hidinput_configure_usage()
831 switch (usage->hid & 0xf) { in hidinput_configure_usage()
844 if (field->application == HID_GD_SYSTEM_CONTROL) in hidinput_configure_usage()
847 if ((usage->hid & 0xf0) == 0x90) { /* D-pad */ in hidinput_configure_usage()
848 switch (usage->hid) { in hidinput_configure_usage()
849 case HID_GD_UP: usage->hat_dir = 1; break; in hidinput_configure_usage()
850 case HID_GD_DOWN: usage->hat_dir = 5; break; in hidinput_configure_usage()
851 case HID_GD_RIGHT: usage->hat_dir = 3; break; in hidinput_configure_usage()
852 case HID_GD_LEFT: usage->hat_dir = 7; break; in hidinput_configure_usage()
855 if (field->dpad) { in hidinput_configure_usage()
856 map_abs(field->dpad); in hidinput_configure_usage()
863 switch (usage->hid) { in hidinput_configure_usage()
867 if (field->flags & HID_MAIN_ITEM_RELATIVE) in hidinput_configure_usage()
868 map_rel(usage->hid & 0xf); in hidinput_configure_usage()
870 map_abs_clear(usage->hid & 0xf); in hidinput_configure_usage()
874 if (field->flags & HID_MAIN_ITEM_RELATIVE) { in hidinput_configure_usage()
875 set_bit(REL_WHEEL, input->relbit); in hidinput_configure_usage()
878 map_abs(usage->hid & 0xf); in hidinput_configure_usage()
882 if (field->flags & HID_MAIN_ITEM_RELATIVE) in hidinput_configure_usage()
883 map_rel(usage->hid & 0xf); in hidinput_configure_usage()
885 map_abs(usage->hid & 0xf); in hidinput_configure_usage()
889 usage->hat_min = field->logical_minimum; in hidinput_configure_usage()
890 usage->hat_max = field->logical_maximum; in hidinput_configure_usage()
899 if (field->application == HID_GD_WIRELESS_RADIO_CTLS) { in hidinput_configure_usage()
902 field->flags |= HID_MAIN_ITEM_RELATIVE; in hidinput_configure_usage()
913 switch (usage->hid & 0xffff) { /* HID-Value: */ in hidinput_configure_usage()
919 case 0x27: map_led (LED_SLEEP); break; /* "Stand-By" */ in hidinput_configure_usage()
931 if ((field->application & 0xff) == 0x01) /* Digitizer */ in hidinput_configure_usage()
932 __set_bit(INPUT_PROP_POINTER, input->propbit); in hidinput_configure_usage()
933 else if ((field->application & 0xff) == 0x02) /* Pen */ in hidinput_configure_usage()
934 __set_bit(INPUT_PROP_DIRECT, input->propbit); in hidinput_configure_usage()
936 switch (usage->hid & 0xff) { in hidinput_configure_usage()
941 if (!test_bit(BTN_TOUCH, input->keybit)) { in hidinput_configure_usage()
942 device->quirks |= HID_QUIRK_NOTOUCH; in hidinput_configure_usage()
943 set_bit(EV_KEY, input->evbit); in hidinput_configure_usage()
944 set_bit(BTN_TOUCH, input->keybit); in hidinput_configure_usage()
950 switch (field->physical) { in hidinput_configure_usage()
962 if (!field->physical) { in hidinput_configure_usage()
963 switch (field->application) { in hidinput_configure_usage()
980 usage->type = EV_PWR; in hidinput_configure_usage()
984 device->quirks &= ~HID_QUIRK_NOINVERT; in hidinput_configure_usage()
999 device->quirks &= ~HID_QUIRK_NOTOUCH; in hidinput_configure_usage()
1013 if (!test_bit(BTN_TOOL_RUBBER, input->keybit)) { in hidinput_configure_usage()
1014 device->quirks |= HID_QUIRK_NOINVERT; in hidinput_configure_usage()
1015 set_bit(BTN_TOOL_RUBBER, input->keybit); in hidinput_configure_usage()
1035 switch (usage->hid & HID_USAGE) { in hidinput_configure_usage()
1057 case HID_UP_CONSUMER: /* USB HUT v1.12, pages 75-84 */ in hidinput_configure_usage()
1058 switch (usage->hid & HID_USAGE) { in hidinput_configure_usage()
1221 set_bit(REL_HWHEEL, input->relbit); in hidinput_configure_usage()
1252 switch (usage->hid) { in hidinput_configure_usage()
1255 usage->type = EV_PWR; in hidinput_configure_usage()
1261 switch (usage->hid) { in hidinput_configure_usage()
1264 usage->type = EV_PWR; in hidinput_configure_usage()
1267 usage->type = EV_PWR; in hidinput_configure_usage()
1272 switch (usage->hid & HID_USAGE) { in hidinput_configure_usage()
1283 set_bit(EV_REP, input->evbit); in hidinput_configure_usage()
1284 switch (usage->hid & HID_USAGE) { in hidinput_configure_usage()
1302 set_bit(EV_REP, input->evbit); in hidinput_configure_usage()
1303 switch (usage->hid & HID_USAGE) { in hidinput_configure_usage()
1315 set_bit(EV_REP, input->evbit); in hidinput_configure_usage()
1326 switch (usage->hid & HID_USAGE) { in hidinput_configure_usage()
1334 if (field->report_size == 1) { in hidinput_configure_usage()
1335 if (field->report->type == HID_OUTPUT_REPORT) { in hidinput_configure_usage()
1342 if (field->flags & HID_MAIN_ITEM_RELATIVE) { in hidinput_configure_usage()
1355 if (device->driver->input_mapped && in hidinput_configure_usage()
1356 device->driver->input_mapped(device, hidinput, field, usage, in hidinput_configure_usage()
1365 set_bit(usage->type, input->evbit); in hidinput_configure_usage()
1369 * - HID aims at being generic so we should do our best to export in hidinput_configure_usage()
1371 * - HID describes what events are, so there is no reason for ABS_X in hidinput_configure_usage()
1373 * - HID is using *_MISC+N as a default value, but nothing prevents in hidinput_configure_usage()
1382 while (usage->code <= max && test_and_set_bit(usage->code, bit)) { in hidinput_configure_usage()
1383 if (device->quirks & HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE) { in hidinput_configure_usage()
1384 usage->code = find_next_zero_bit(bit, in hidinput_configure_usage()
1386 usage->code); in hidinput_configure_usage()
1388 device->status |= HID_STAT_DUP_DETECTED; in hidinput_configure_usage()
1393 if (usage->code > max) in hidinput_configure_usage()
1396 if (usage->type == EV_ABS) { in hidinput_configure_usage()
1398 int a = field->logical_minimum; in hidinput_configure_usage()
1399 int b = field->logical_maximum; in hidinput_configure_usage()
1401 if ((device->quirks & HID_QUIRK_BADPAD) && (usage->code == ABS_X || usage->code == ABS_Y)) { in hidinput_configure_usage()
1402 a = field->logical_minimum = 0; in hidinput_configure_usage()
1403 b = field->logical_maximum = 255; in hidinput_configure_usage()
1406 if (field->application == HID_GD_GAMEPAD || field->application == HID_GD_JOYSTICK) in hidinput_configure_usage()
1407 input_set_abs_params(input, usage->code, a, b, (b - a) >> 8, (b - a) >> 4); in hidinput_configure_usage()
1408 else input_set_abs_params(input, usage->code, a, b, 0, 0); in hidinput_configure_usage()
1410 input_abs_set_res(input, usage->code, in hidinput_configure_usage()
1411 hidinput_calc_abs_res(field, usage->code)); in hidinput_configure_usage()
1414 if (usage->code == ABS_MT_POSITION_X && input->hint_events_per_packet == 0) in hidinput_configure_usage()
1418 if (usage->type == EV_ABS && in hidinput_configure_usage()
1419 (usage->hat_min < usage->hat_max || usage->hat_dir)) { in hidinput_configure_usage()
1421 for (i = usage->code; i < usage->code + 2 && i <= max; i++) { in hidinput_configure_usage()
1422 input_set_abs_params(input, i, -1, 1, 0, 0); in hidinput_configure_usage()
1423 set_bit(i, input->absbit); in hidinput_configure_usage()
1425 if (usage->hat_dir && !field->dpad) in hidinput_configure_usage()
1426 field->dpad = usage->code; in hidinput_configure_usage()
1433 if ((usage->type == EV_ABS) && (field->flags & HID_MAIN_ITEM_RELATIVE) && in hidinput_configure_usage()
1434 (usage->code == ABS_VOLUME)) { in hidinput_configure_usage()
1435 set_bit(KEY_VOLUMEUP, input->keybit); in hidinput_configure_usage()
1436 set_bit(KEY_VOLUMEDOWN, input->keybit); in hidinput_configure_usage()
1439 if (usage->type == EV_KEY) { in hidinput_configure_usage()
1440 set_bit(EV_MSC, input->evbit); in hidinput_configure_usage()
1441 set_bit(MSC_SCAN, input->mscbit); in hidinput_configure_usage()
1447 usage->type = 0; in hidinput_configure_usage()
1448 usage->code = 0; in hidinput_configure_usage()
1461 if (usage->code == REL_WHEEL_HI_RES) in hidinput_handle_scroll()
1467 * Windows reports one wheel click as value 120. Where a high-res in hidinput_handle_scroll()
1472 hi_res = value * 120/usage->resolution_multiplier; in hidinput_handle_scroll()
1474 usage->wheel_accumulated += hi_res; in hidinput_handle_scroll()
1475 lo_res = usage->wheel_accumulated/120; in hidinput_handle_scroll()
1477 usage->wheel_accumulated -= lo_res * 120; in hidinput_handle_scroll()
1480 input_event(input, EV_REL, usage->code, hi_res); in hidinput_handle_scroll()
1487 if (!test_bit(tool, input->key)) in hid_report_release_tool()
1498 report->tool = 0; in hid_report_release_tool()
1504 if (report->tool != new_tool) in hid_report_set_tool()
1505 hid_report_release_tool(report, input, report->tool); in hid_report_set_tool()
1508 report->tool = new_tool; in hid_report_set_tool()
1514 struct hid_report *report = field->report; in hidinput_hid_event()
1515 unsigned *quirks = &hid->quirks; in hidinput_hid_event()
1517 if (!usage->type) in hidinput_hid_event()
1520 if (usage->type == EV_PWR) { in hidinput_hid_event()
1521 bool handled = hidinput_set_battery_charge_status(hid, usage->hid, value); in hidinput_hid_event()
1529 if (!field->hidinput) in hidinput_hid_event()
1532 input = field->hidinput->input; in hidinput_hid_event()
1534 if (usage->hat_min < usage->hat_max || usage->hat_dir) { in hidinput_hid_event()
1535 int hat_dir = usage->hat_dir; in hidinput_hid_event()
1537 hat_dir = (value - usage->hat_min) * 8 / (usage->hat_max - usage->hat_min + 1) + 1; in hidinput_hid_event()
1539 input_event(input, usage->type, usage->code , hid_hat_to_axis[hat_dir].x); in hidinput_hid_event()
1540 input_event(input, usage->type, usage->code + 1, hid_hat_to_axis[hat_dir].y); in hidinput_hid_event()
1545 * Ignore out-of-range values as per HID specification, in hidinput_hid_event()
1549 * https://msdn.microsoft.com/en-us/library/windows/hardware/dn672278(v=vs.85).asp in hidinput_hid_event()
1555 if ((field->flags & HID_MAIN_ITEM_VARIABLE) && in hidinput_hid_event()
1556 field->logical_minimum < field->logical_maximum) { in hidinput_hid_event()
1557 if (field->flags & HID_MAIN_ITEM_NULL_STATE && in hidinput_hid_event()
1558 (value < field->logical_minimum || in hidinput_hid_event()
1559 value > field->logical_maximum)) { in hidinput_hid_event()
1560 dbg_hid("Ignoring out-of-range value %x\n", value); in hidinput_hid_event()
1564 field->logical_minimum, in hidinput_hid_event()
1565 field->logical_maximum); in hidinput_hid_event()
1568 switch (usage->hid) { in hidinput_hid_event()
1570 report->tool_active |= !!value; in hidinput_hid_event()
1578 else if (report->tool != BTN_TOOL_RUBBER) in hidinput_hid_event()
1582 !test_bit(BTN_TOUCH, input->key)) { in hidinput_hid_event()
1591 /* let hid-input set BTN_TOUCH */ in hidinput_hid_event()
1595 report->tool_active |= !!value; in hidinput_hid_event()
1602 else if (!report->tool_active) in hidinput_hid_event()
1610 report->tool_active |= !!value; in hidinput_hid_event()
1612 if (report->tool_active) { in hidinput_hid_event()
1617 if (!report->tool) in hidinput_hid_event()
1618 report->tool = usage->code; in hidinput_hid_event()
1621 hid_report_set_tool(report, input, report->tool); in hidinput_hid_event()
1623 hid_report_release_tool(report, input, usage->code); in hidinput_hid_event()
1627 report->tool_active = false; in hidinput_hid_event()
1633 report->tool_active |= !!value; in hidinput_hid_event()
1636 if (report->tool == BTN_TOOL_RUBBER) in hidinput_hid_event()
1643 int a = field->logical_minimum; in hidinput_hid_event()
1644 int b = field->logical_maximum; in hidinput_hid_event()
1646 if (value > a + ((b - a) >> 3)) { in hidinput_hid_event()
1648 report->tool_active = true; in hidinput_hid_event()
1654 dbg_hid("Maximum Effects - %d\n",value); in hidinput_hid_event()
1662 switch (usage->type) { in hidinput_hid_event()
1664 if (usage->code == 0) /* Key 0 is "unassigned", not KEY_UNKNOWN */ in hidinput_hid_event()
1669 if (usage->code == REL_WHEEL_HI_RES || in hidinput_hid_event()
1670 usage->code == REL_HWHEEL_HI_RES) { in hidinput_hid_event()
1677 if ((field->flags & HID_MAIN_ITEM_RELATIVE) && in hidinput_hid_event()
1678 usage->code == ABS_VOLUME) { in hidinput_hid_event()
1691 } else if (((*quirks & HID_QUIRK_X_INVERT) && usage->code == ABS_X) || in hidinput_hid_event()
1692 ((*quirks & HID_QUIRK_Y_INVERT) && usage->code == ABS_Y)) in hidinput_hid_event()
1693 value = field->logical_maximum - value; in hidinput_hid_event()
1707 if (!(field->flags & (HID_MAIN_ITEM_RELATIVE | in hidinput_hid_event()
1709 (field->flags & HID_MAIN_ITEM_VARIABLE) && in hidinput_hid_event()
1710 usage->usage_index < field->maxusage && in hidinput_hid_event()
1711 value == field->value[usage->usage_index]) in hidinput_hid_event()
1715 if (usage->type == EV_KEY && in hidinput_hid_event()
1716 (!test_bit(usage->code, input->key)) == value) in hidinput_hid_event()
1717 input_event(input, EV_MSC, MSC_SCAN, usage->hid); in hidinput_hid_event()
1719 input_event(input, usage->type, usage->code, value); in hidinput_hid_event()
1721 if ((field->flags & HID_MAIN_ITEM_RELATIVE) && in hidinput_hid_event()
1722 usage->type == EV_KEY && value) { in hidinput_hid_event()
1724 input_event(input, usage->type, usage->code, 0); in hidinput_hid_event()
1732 if (hid->quirks & HID_QUIRK_NO_INPUT_SYNC) in hidinput_report_event()
1735 list_for_each_entry(hidinput, &hid->inputs, list) in hidinput_report_event()
1736 input_sync(hidinput->input); in hidinput_report_event()
1746 list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) { in hidinput_find_field()
1747 for (i = 0; i < report->maxfield; i++) { in hidinput_find_field()
1748 *field = report->field[i]; in hidinput_find_field()
1749 for (j = 0; j < (*field)->maxusage; j++) in hidinput_find_field()
1750 if ((*field)->usage[j].type == type && (*field)->usage[j].code == code) in hidinput_find_field()
1754 return -1; in hidinput_find_field()
1764 &hid->report_enum[HID_OUTPUT_REPORT].report_list, in hidinput_get_led_field()
1766 for (i = 0; i < report->maxfield; i++) { in hidinput_get_led_field()
1767 field = report->field[i]; in hidinput_get_led_field()
1768 for (j = 0; j < field->maxusage; j++) in hidinput_get_led_field()
1769 if (field->usage[j].type == EV_LED) in hidinput_get_led_field()
1785 &hid->report_enum[HID_OUTPUT_REPORT].report_list, in hidinput_count_leds()
1787 for (i = 0; i < report->maxfield; i++) { in hidinput_count_leds()
1788 field = report->field[i]; in hidinput_count_leds()
1789 for (j = 0; j < field->maxusage; j++) in hidinput_count_leds()
1790 if (field->usage[j].type == EV_LED && in hidinput_count_leds()
1791 field->value[j]) in hidinput_count_leds()
1814 * field->report is accessed unlocked regarding HID core. So there might in hidinput_led_worker()
1815 * be another incoming SET-LED request from user-space, which changes in hidinput_led_worker()
1822 * for every SET-LED request so the following worker will send the in hidinput_led_worker()
1826 report = field->report; in hidinput_led_worker()
1829 if (hid->ll_driver->request) in hidinput_led_worker()
1830 return hid->ll_driver->request(hid, report, HID_REQ_SET_REPORT); in hidinput_led_worker()
1832 /* fall back to generic raw-output-report */ in hidinput_led_worker()
1841 if (ret == -ENOSYS) in hidinput_led_worker()
1842 hid_hw_raw_request(hid, report->id, buf, len, HID_OUTPUT_REPORT, in hidinput_led_worker()
1858 return -1; in hidinput_input_event()
1860 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) { in hidinput_input_event()
1862 return -1; in hidinput_input_event()
1867 schedule_work(&hid->led_work); in hidinput_input_event()
1893 if (report->maxfield == 0) in __hidinput_change_resolution_multipliers()
1896 for (i = 0; i < report->maxfield; i++) { in __hidinput_change_resolution_multipliers()
1898 report->field[i]->logical_maximum : in __hidinput_change_resolution_multipliers()
1899 report->field[i]->logical_minimum; in __hidinput_change_resolution_multipliers()
1901 /* There is no good reason for a Resolution in __hidinput_change_resolution_multipliers()
1905 if (report->field[i]->report_count != 1) in __hidinput_change_resolution_multipliers()
1908 for (j = 0; j < report->field[i]->maxusage; j++) { in __hidinput_change_resolution_multipliers()
1909 usage = &report->field[i]->usage[j]; in __hidinput_change_resolution_multipliers()
1911 if (usage->hid != HID_GD_RESOLUTION_MULTIPLIER) in __hidinput_change_resolution_multipliers()
1916 * report we need to fill in the bits from the in __hidinput_change_resolution_multipliers()
1918 * Resolution Multiplier. in __hidinput_change_resolution_multipliers()
1924 if (!get_report_completed && report->maxfield > 1) { in __hidinput_change_resolution_multipliers()
1925 if (hid->quirks & HID_QUIRK_NO_INIT_REPORTS) in __hidinput_change_resolution_multipliers()
1933 report->field[i]->value[j] = value; in __hidinput_change_resolution_multipliers()
1947 rep_enum = &hid->report_enum[HID_FEATURE_REPORT]; in hidinput_change_resolution_multipliers()
1948 list_for_each_entry(rep, &rep_enum->report_list, list) { in hidinput_change_resolution_multipliers()
1968 struct hid_driver *drv = hid->driver; in report_features()
1974 rep_enum = &hid->report_enum[HID_FEATURE_REPORT]; in report_features()
1975 list_for_each_entry(rep, &rep_enum->report_list, list) in report_features()
1976 for (i = 0; i < rep->maxfield; i++) { in report_features()
1978 if (rep->field[i]->report_count < 1) in report_features()
1981 for (j = 0; j < rep->field[i]->maxusage; j++) { in report_features()
1982 usage = &rep->field[i]->usage[j]; in report_features()
1985 if (usage->hid == HID_DC_BATTERYSTRENGTH) in report_features()
1987 rep->field[i], false); in report_features()
1989 if (drv->feature_mapping) in report_features()
1990 drv->feature_mapping(hid, rep->field[i], usage); in report_features()
2006 if ((hid->quirks & HID_QUIRK_INPUT_PER_APP) && in hidinput_allocate()
2007 hid->maxapplication > 1) { in hidinput_allocate()
2021 * DG_PEN -> "Stylus" in hidinput_allocate()
2022 * DG_STYLUS -> "Pen" in hidinput_allocate()
2055 name_len = strlen(hid->name); in hidinput_allocate()
2058 strcmp(hid->name + name_len - suffix_len, suffix)) { in hidinput_allocate()
2059 hidinput->name = kasprintf(GFP_KERNEL, "%s %s", in hidinput_allocate()
2060 hid->name, suffix); in hidinput_allocate()
2061 if (!hidinput->name) in hidinput_allocate()
2067 input_dev->event = hidinput_input_event; in hidinput_allocate()
2068 input_dev->open = hidinput_open; in hidinput_allocate()
2069 input_dev->close = hidinput_close; in hidinput_allocate()
2070 input_dev->setkeycode = hidinput_setkeycode; in hidinput_allocate()
2071 input_dev->getkeycode = hidinput_getkeycode; in hidinput_allocate()
2073 input_dev->name = hidinput->name ? hidinput->name : hid->name; in hidinput_allocate()
2074 input_dev->phys = hid->phys; in hidinput_allocate()
2075 input_dev->uniq = hid->uniq; in hidinput_allocate()
2076 input_dev->id.bustype = hid->bus; in hidinput_allocate()
2077 input_dev->id.vendor = hid->vendor; in hidinput_allocate()
2078 input_dev->id.product = hid->product; in hidinput_allocate()
2079 input_dev->id.version = hid->version; in hidinput_allocate()
2080 input_dev->dev.parent = &hid->dev; in hidinput_allocate()
2082 hidinput->input = input_dev; in hidinput_allocate()
2083 hidinput->application = application; in hidinput_allocate()
2084 list_add_tail(&hidinput->list, &hid->inputs); in hidinput_allocate()
2086 INIT_LIST_HEAD(&hidinput->reports); in hidinput_allocate()
2103 r |= hidinput->input->evbit[i]; in hidinput_has_been_populated()
2106 r |= hidinput->input->keybit[i]; in hidinput_has_been_populated()
2109 r |= hidinput->input->relbit[i]; in hidinput_has_been_populated()
2112 r |= hidinput->input->absbit[i]; in hidinput_has_been_populated()
2115 r |= hidinput->input->mscbit[i]; in hidinput_has_been_populated()
2118 r |= hidinput->input->ledbit[i]; in hidinput_has_been_populated()
2121 r |= hidinput->input->sndbit[i]; in hidinput_has_been_populated()
2124 r |= hidinput->input->ffbit[i]; in hidinput_has_been_populated()
2127 r |= hidinput->input->swbit[i]; in hidinput_has_been_populated()
2138 list_del(&hidinput->list); in hidinput_cleanup_hidinput()
2139 input_free_device(hidinput->input); in hidinput_cleanup_hidinput()
2140 kfree(hidinput->name); in hidinput_cleanup_hidinput()
2144 hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS) in hidinput_cleanup_hidinput()
2147 list_for_each_entry(report, &hid->report_enum[k].report_list, in hidinput_cleanup_hidinput()
2150 for (i = 0; i < report->maxfield; i++) in hidinput_cleanup_hidinput()
2151 if (report->field[i]->hidinput == hidinput) in hidinput_cleanup_hidinput()
2152 report->field[i]->hidinput = NULL; in hidinput_cleanup_hidinput()
2161 struct hid_device *hid = report->device; in hidinput_match()
2164 list_for_each_entry(hidinput, &hid->inputs, list) { in hidinput_match()
2165 if (hidinput->report && in hidinput_match()
2166 hidinput->report->id == report->id) in hidinput_match()
2175 struct hid_device *hid = report->device; in hidinput_match_application()
2178 list_for_each_entry(hidinput, &hid->inputs, list) { in hidinput_match_application()
2179 if (hidinput->application == report->application) in hidinput_match_application()
2186 if ((report->application == HID_GD_SYSTEM_CONTROL || in hidinput_match_application()
2187 report->application == HID_CP_CONSUMER_CONTROL) && in hidinput_match_application()
2188 hidinput->application == HID_GD_KEYBOARD) { in hidinput_match_application()
2201 int slot_collection_index = -1; in hidinput_configure_usages()
2202 int prev_collection_index = -1; in hidinput_configure_usages()
2210 for (i = 0; i < report->maxfield; i++) { in hidinput_configure_usages()
2211 field = report->field[i]; in hidinput_configure_usages()
2214 if (field->maxusage < 1) in hidinput_configure_usages()
2220 if (prev_collection_index != field->usage->collection_index) { in hidinput_configure_usages()
2221 prev_collection_index = field->usage->collection_index; in hidinput_configure_usages()
2229 if (slot_collection_index == field->usage->collection_index) { in hidinput_configure_usages()
2230 field->slot_idx = slot_idx; in hidinput_configure_usages()
2235 for (j = 0; j < field->maxusage; j++) { in hidinput_configure_usages()
2236 if (field->usage[j].hid == HID_DG_CONTACTID) { in hidinput_configure_usages()
2237 slot_collection_index = field->usage->collection_index; in hidinput_configure_usages()
2245 report->field[k]->slot_idx = slot_idx; in hidinput_configure_usages()
2251 for (i = 0; i < report->maxfield; i++) in hidinput_configure_usages()
2252 for (j = 0; j < report->field[i]->maxusage; j++) in hidinput_configure_usages()
2253 hidinput_configure_usage(hidinput, report->field[i], in hidinput_configure_usages()
2254 report->field[i]->usage + j, in hidinput_configure_usages()
2266 struct hid_driver *drv = hid->driver; in hidinput_connect()
2272 INIT_LIST_HEAD(&hid->inputs); in hidinput_connect()
2273 INIT_WORK(&hid->led_work, hidinput_led_worker); in hidinput_connect()
2275 hid->status &= ~HID_STAT_DUP_DETECTED; in hidinput_connect()
2278 for (i = 0; i < hid->maxcollection; i++) { in hidinput_connect()
2279 struct hid_collection *col = &hid->collection[i]; in hidinput_connect()
2280 if (col->type == HID_COLLECTION_APPLICATION || in hidinput_connect()
2281 col->type == HID_COLLECTION_PHYSICAL) in hidinput_connect()
2282 if (IS_INPUT_APPLICATION(col->usage)) in hidinput_connect()
2286 if (i == hid->maxcollection) in hidinput_connect()
2287 return -1; in hidinput_connect()
2294 hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS) in hidinput_connect()
2297 list_for_each_entry(report, &hid->report_enum[k].report_list, list) { in hidinput_connect()
2299 if (!report->maxfield) in hidinput_connect()
2302 application = report->application; in hidinput_connect()
2308 if (hid->quirks & HID_QUIRK_MULTI_INPUT) in hidinput_connect()
2310 else if (hid->maxapplication > 1 && in hidinput_connect()
2311 (hid->quirks & HID_QUIRK_INPUT_PER_APP)) in hidinput_connect()
2322 if (hid->quirks & HID_QUIRK_MULTI_INPUT) in hidinput_connect()
2323 hidinput->report = report; in hidinput_connect()
2325 list_add_tail(&report->hidinput_list, in hidinput_connect()
2326 &hidinput->reports); in hidinput_connect()
2332 list_for_each_entry_safe(hidinput, next, &hid->inputs, list) { in hidinput_connect()
2333 if (drv->input_configured && in hidinput_connect()
2334 drv->input_configured(hid, hidinput)) in hidinput_connect()
2343 if (input_register_device(hidinput->input)) in hidinput_connect()
2345 hidinput->registered = true; in hidinput_connect()
2348 if (list_empty(&hid->inputs)) { in hidinput_connect()
2353 if (hid->status & HID_STAT_DUP_DETECTED) in hidinput_connect()
2363 return -1; in hidinput_connect()
2373 list_for_each_entry_safe(hidinput, next, &hid->inputs, list) { in hidinput_disconnect()
2374 list_del(&hidinput->list); in hidinput_disconnect()
2375 if (hidinput->registered) in hidinput_disconnect()
2376 input_unregister_device(hidinput->input); in hidinput_disconnect()
2378 input_free_device(hidinput->input); in hidinput_disconnect()
2379 kfree(hidinput->name); in hidinput_disconnect()
2387 cancel_work_sync(&hid->led_work); in hidinput_disconnect()
2392 #include "hid-input-test.c"