blob: 742c052b0110af4b2b1666d179dd27b6747b02f5 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Hans de Goedef1918be2017-05-10 17:12:53 +02002/*
3 * HID driver for some ITE "special" devices
4 * Copyright (c) 2017 Hans de Goede <hdegoede@redhat.com>
Hans de Goedef1918be2017-05-10 17:12:53 +02005 */
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
Hans de Goede3c785a02020-10-19 09:48:14 +020014#define QUIRK_TOUCHPAD_ON_OFF_REPORT BIT(0)
15
16static __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
30static 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
Hans de Goedef1918be2017-05-10 17:12:53 +020056static 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
Hans de Goede3c785a02020-10-19 09:48:14 +020082static 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
Hans de Goedef1918be2017-05-10 17:12:53 +020095static const struct hid_device_id ite_devices[] = {
96 { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE8595) },
Hans de Goede40502072018-11-26 11:52:18 +010097 { HID_USB_DEVICE(USB_VENDOR_ID_258A, USB_DEVICE_ID_258A_6A88) },
Hans de Goede8f18eca2019-11-19 15:57:11 +010098 /* ITE8595 USB kbd ctlr, with Synaptics touchpad connected to it. */
Hans de Goedebeae5612020-02-01 12:56:48 +010099 { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
100 USB_VENDOR_ID_SYNAPTICS,
Hans de Goede3c785a02020-10-19 09:48:14 +0200101 USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_012),
102 .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT },
Hans de Goede5bf2f2f2020-09-01 09:56:42 +0200103 /* 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) },
Hans de Goedef1918be2017-05-10 17:12:53 +0200107 { }
108};
109MODULE_DEVICE_TABLE(hid, ite_devices);
110
111static struct hid_driver ite_driver = {
112 .name = "itetech",
113 .id_table = ite_devices,
Hans de Goede3c785a02020-10-19 09:48:14 +0200114 .probe = ite_probe,
115 .report_fixup = ite_report_fixup,
116 .input_mapping = ite_input_mapping,
Hans de Goedef1918be2017-05-10 17:12:53 +0200117 .event = ite_event,
118};
119module_hid_driver(ite_driver);
120
121MODULE_LICENSE("GPL");