Merge tag 'arm-soc-omap-genpd-5.11' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / drivers / hid / hid-ite.c
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                 /* For Acer Aspire Switch 10 SW5-012 keyboard-dock */
22                 if (*rsize == 188 && rdesc[162] == 0x81 && rdesc[163] == 0x02) {
23                         hid_info(hdev, "Fixing up Acer Sw5-012 ITE keyboard report descriptor\n");
24                         rdesc[163] = HID_MAIN_ITEM_RELATIVE;
25                 }
26                 /* For Acer One S1002 keyboard-dock */
27                 if (*rsize == 188 && rdesc[185] == 0x81 && rdesc[186] == 0x02) {
28                         hid_info(hdev, "Fixing up Acer S1002 ITE keyboard report descriptor\n");
29                         rdesc[186] = HID_MAIN_ITEM_RELATIVE;
30                 }
31         }
32
33         return rdesc;
34 }
35
36 static int ite_input_mapping(struct hid_device *hdev,
37                 struct hid_input *hi, struct hid_field *field,
38                 struct hid_usage *usage, unsigned long **bit,
39                 int *max)
40 {
41
42         unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
43
44         if ((quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) &&
45             (usage->hid & HID_USAGE_PAGE) == 0x00880000) {
46                 if (usage->hid == 0x00880078) {
47                         /* Touchpad on, userspace expects F22 for this */
48                         hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F22);
49                         return 1;
50                 }
51                 if (usage->hid == 0x00880079) {
52                         /* Touchpad off, userspace expects F23 for this */
53                         hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F23);
54                         return 1;
55                 }
56                 return -1;
57         }
58
59         return 0;
60 }
61
62 static int ite_event(struct hid_device *hdev, struct hid_field *field,
63                      struct hid_usage *usage, __s32 value)
64 {
65         struct input_dev *input;
66
67         if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
68                 return 0;
69
70         input = field->hidinput->input;
71
72         /*
73          * The ITE8595 always reports 0 as value for the rfkill button. Luckily
74          * it is the only button in its report, and it sends a report on
75          * release only, so receiving a report means the button was pressed.
76          */
77         if (usage->hid == HID_GD_RFKILL_BTN) {
78                 input_event(input, EV_KEY, KEY_RFKILL, 1);
79                 input_sync(input);
80                 input_event(input, EV_KEY, KEY_RFKILL, 0);
81                 input_sync(input);
82                 return 1;
83         }
84
85         return 0;
86 }
87
88 static int ite_probe(struct hid_device *hdev, const struct hid_device_id *id)
89 {
90         int ret;
91
92         hid_set_drvdata(hdev, (void *)id->driver_data);
93
94         ret = hid_open_report(hdev);
95         if (ret)
96                 return ret;
97
98         return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
99 }
100
101 static const struct hid_device_id ite_devices[] = {
102         { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE8595) },
103         { HID_USB_DEVICE(USB_VENDOR_ID_258A, USB_DEVICE_ID_258A_6A88) },
104         /* ITE8595 USB kbd ctlr, with Synaptics touchpad connected to it. */
105         { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
106                      USB_VENDOR_ID_SYNAPTICS,
107                      USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_012),
108           .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT },
109         /* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */
110         { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
111                      USB_VENDOR_ID_SYNAPTICS,
112                      USB_DEVICE_ID_SYNAPTICS_ACER_ONE_S1002),
113           .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT },
114         /* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */
115         { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
116                      USB_VENDOR_ID_SYNAPTICS,
117                      USB_DEVICE_ID_SYNAPTICS_ACER_ONE_S1003) },
118         { }
119 };
120 MODULE_DEVICE_TABLE(hid, ite_devices);
121
122 static struct hid_driver ite_driver = {
123         .name = "itetech",
124         .id_table = ite_devices,
125         .probe = ite_probe,
126         .report_fixup = ite_report_fixup,
127         .input_mapping = ite_input_mapping,
128         .event = ite_event,
129 };
130 module_hid_driver(ite_driver);
131
132 MODULE_LICENSE("GPL");