1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * HID driver for some ITE "special" devices 4 * Copyright (c) 2017 Hans de Goede <hdegoede@redhat.com> 5 */ 6 7 #include <linux/device.h> 8 #include <linux/input.h> 9 #include <linux/hid.h> 10 #include <linux/module.h> 11 12 #include "hid-ids.h" 13 14 #define QUIRK_TOUCHPAD_ON_OFF_REPORT BIT(0) 15 16 static __u8 *ite_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) 17 { 18 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); 19 20 if (quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) { 21 if (*rsize == 188 && rdesc[162] == 0x81 && rdesc[163] == 0x02) { 22 hid_info(hdev, "Fixing up ITE keyboard report descriptor\n"); 23 rdesc[163] = HID_MAIN_ITEM_RELATIVE; 24 } 25 } 26 27 return rdesc; 28 } 29 30 static int ite_input_mapping(struct hid_device *hdev, 31 struct hid_input *hi, struct hid_field *field, 32 struct hid_usage *usage, unsigned long **bit, 33 int *max) 34 { 35 36 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); 37 38 if ((quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) && 39 (usage->hid & HID_USAGE_PAGE) == 0x00880000) { 40 if (usage->hid == 0x00880078) { 41 /* Touchpad on, userspace expects F22 for this */ 42 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F22); 43 return 1; 44 } 45 if (usage->hid == 0x00880079) { 46 /* Touchpad off, userspace expects F23 for this */ 47 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F23); 48 return 1; 49 } 50 return -1; 51 } 52 53 return 0; 54 } 55 56 static int ite_event(struct hid_device *hdev, struct hid_field *field, 57 struct hid_usage *usage, __s32 value) 58 { 59 struct input_dev *input; 60 61 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput) 62 return 0; 63 64 input = field->hidinput->input; 65 66 /* 67 * The ITE8595 always reports 0 as value for the rfkill button. Luckily 68 * it is the only button in its report, and it sends a report on 69 * release only, so receiving a report means the button was pressed. 70 */ 71 if (usage->hid == HID_GD_RFKILL_BTN) { 72 input_event(input, EV_KEY, KEY_RFKILL, 1); 73 input_sync(input); 74 input_event(input, EV_KEY, KEY_RFKILL, 0); 75 input_sync(input); 76 return 1; 77 } 78 79 return 0; 80 } 81 82 static int ite_probe(struct hid_device *hdev, const struct hid_device_id *id) 83 { 84 int ret; 85 86 hid_set_drvdata(hdev, (void *)id->driver_data); 87 88 ret = hid_open_report(hdev); 89 if (ret) 90 return ret; 91 92 return hid_hw_start(hdev, HID_CONNECT_DEFAULT); 93 } 94 95 static const struct hid_device_id ite_devices[] = { 96 { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE8595) }, 97 { HID_USB_DEVICE(USB_VENDOR_ID_258A, USB_DEVICE_ID_258A_6A88) }, 98 /* ITE8595 USB kbd ctlr, with Synaptics touchpad connected to it. */ 99 { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, 100 USB_VENDOR_ID_SYNAPTICS, 101 USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_012), 102 .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT }, 103 /* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */ 104 { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, 105 USB_VENDOR_ID_SYNAPTICS, 106 USB_DEVICE_ID_SYNAPTICS_ACER_ONE_S1003) }, 107 { } 108 }; 109 MODULE_DEVICE_TABLE(hid, ite_devices); 110 111 static struct hid_driver ite_driver = { 112 .name = "itetech", 113 .id_table = ite_devices, 114 .probe = ite_probe, 115 .report_fixup = ite_report_fixup, 116 .input_mapping = ite_input_mapping, 117 .event = ite_event, 118 }; 119 module_hid_driver(ite_driver); 120 121 MODULE_LICENSE("GPL"); 122