xref: /linux/drivers/hid/hid-ite.c (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f1918be1SHans de Goede /*
3f1918be1SHans de Goede  * HID driver for some ITE "special" devices
4f1918be1SHans de Goede  * Copyright (c) 2017 Hans de Goede <hdegoede@redhat.com>
5f1918be1SHans de Goede  */
6f1918be1SHans de Goede 
7f1918be1SHans de Goede #include <linux/device.h>
8f1918be1SHans de Goede #include <linux/input.h>
9f1918be1SHans de Goede #include <linux/hid.h>
10f1918be1SHans de Goede #include <linux/module.h>
11f1918be1SHans de Goede 
12f1918be1SHans de Goede #include "hid-ids.h"
13f1918be1SHans de Goede 
143c785a06SHans de Goede #define QUIRK_TOUCHPAD_ON_OFF_REPORT		BIT(0)
153c785a06SHans de Goede 
ite_report_fixup(struct hid_device * hdev,__u8 * rdesc,unsigned int * rsize)16*fe73965dSThomas Weißschuh static const __u8 *ite_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize)
173c785a06SHans de Goede {
183c785a06SHans de Goede 	unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
193c785a06SHans de Goede 
203c785a06SHans de Goede 	if (quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) {
21c961facbSHans de Goede 		/* For Acer Aspire Switch 10 SW5-012 keyboard-dock */
223c785a06SHans de Goede 		if (*rsize == 188 && rdesc[162] == 0x81 && rdesc[163] == 0x02) {
23c961facbSHans de Goede 			hid_info(hdev, "Fixing up Acer Sw5-012 ITE keyboard report descriptor\n");
243c785a06SHans de Goede 			rdesc[163] = HID_MAIN_ITEM_RELATIVE;
253c785a06SHans de Goede 		}
26b7c20f38SHans de Goede 		/* For Acer One S1002/S1003 keyboard-dock */
27c961facbSHans de Goede 		if (*rsize == 188 && rdesc[185] == 0x81 && rdesc[186] == 0x02) {
28b7c20f38SHans de Goede 			hid_info(hdev, "Fixing up Acer S1002/S1003 ITE keyboard report descriptor\n");
29c961facbSHans de Goede 			rdesc[186] = HID_MAIN_ITEM_RELATIVE;
30c961facbSHans de Goede 		}
31b7c20f38SHans de Goede 		/* For Acer Aspire Switch 10E (SW3-016) keyboard-dock */
32b7c20f38SHans de Goede 		if (*rsize == 210 && rdesc[184] == 0x81 && rdesc[185] == 0x02) {
33b7c20f38SHans de Goede 			hid_info(hdev, "Fixing up Acer Aspire Switch 10E (SW3-016) ITE keyboard report descriptor\n");
34b7c20f38SHans de Goede 			rdesc[185] = HID_MAIN_ITEM_RELATIVE;
35b7c20f38SHans de Goede 		}
363c785a06SHans de Goede 	}
373c785a06SHans de Goede 
383c785a06SHans de Goede 	return rdesc;
393c785a06SHans de Goede }
403c785a06SHans de Goede 
ite_input_mapping(struct hid_device * hdev,struct hid_input * hi,struct hid_field * field,struct hid_usage * usage,unsigned long ** bit,int * max)413c785a06SHans de Goede static int ite_input_mapping(struct hid_device *hdev,
423c785a06SHans de Goede 		struct hid_input *hi, struct hid_field *field,
433c785a06SHans de Goede 		struct hid_usage *usage, unsigned long **bit,
443c785a06SHans de Goede 		int *max)
453c785a06SHans de Goede {
463c785a06SHans de Goede 
473c785a06SHans de Goede 	unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
483c785a06SHans de Goede 
493c785a06SHans de Goede 	if ((quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) &&
503c785a06SHans de Goede 	    (usage->hid & HID_USAGE_PAGE) == 0x00880000) {
513c785a06SHans de Goede 		if (usage->hid == 0x00880078) {
523c785a06SHans de Goede 			/* Touchpad on, userspace expects F22 for this */
533c785a06SHans de Goede 			hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F22);
543c785a06SHans de Goede 			return 1;
553c785a06SHans de Goede 		}
563c785a06SHans de Goede 		if (usage->hid == 0x00880079) {
573c785a06SHans de Goede 			/* Touchpad off, userspace expects F23 for this */
583c785a06SHans de Goede 			hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F23);
593c785a06SHans de Goede 			return 1;
603c785a06SHans de Goede 		}
613c785a06SHans de Goede 		return -1;
623c785a06SHans de Goede 	}
633c785a06SHans de Goede 
643c785a06SHans de Goede 	return 0;
653c785a06SHans de Goede }
663c785a06SHans de Goede 
ite_event(struct hid_device * hdev,struct hid_field * field,struct hid_usage * usage,__s32 value)67f1918be1SHans de Goede static int ite_event(struct hid_device *hdev, struct hid_field *field,
68f1918be1SHans de Goede 		     struct hid_usage *usage, __s32 value)
69f1918be1SHans de Goede {
70f1918be1SHans de Goede 	struct input_dev *input;
71f1918be1SHans de Goede 
72f1918be1SHans de Goede 	if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
73f1918be1SHans de Goede 		return 0;
74f1918be1SHans de Goede 
75f1918be1SHans de Goede 	input = field->hidinput->input;
76f1918be1SHans de Goede 
77f1918be1SHans de Goede 	/*
78f1918be1SHans de Goede 	 * The ITE8595 always reports 0 as value for the rfkill button. Luckily
79f1918be1SHans de Goede 	 * it is the only button in its report, and it sends a report on
80f1918be1SHans de Goede 	 * release only, so receiving a report means the button was pressed.
81f1918be1SHans de Goede 	 */
82f1918be1SHans de Goede 	if (usage->hid == HID_GD_RFKILL_BTN) {
83f1918be1SHans de Goede 		input_event(input, EV_KEY, KEY_RFKILL, 1);
84f1918be1SHans de Goede 		input_sync(input);
85f1918be1SHans de Goede 		input_event(input, EV_KEY, KEY_RFKILL, 0);
86f1918be1SHans de Goede 		input_sync(input);
87f1918be1SHans de Goede 		return 1;
88f1918be1SHans de Goede 	}
89f1918be1SHans de Goede 
90f1918be1SHans de Goede 	return 0;
91f1918be1SHans de Goede }
92f1918be1SHans de Goede 
ite_probe(struct hid_device * hdev,const struct hid_device_id * id)933c785a06SHans de Goede static int ite_probe(struct hid_device *hdev, const struct hid_device_id *id)
943c785a06SHans de Goede {
953c785a06SHans de Goede 	int ret;
963c785a06SHans de Goede 
973c785a06SHans de Goede 	hid_set_drvdata(hdev, (void *)id->driver_data);
983c785a06SHans de Goede 
993c785a06SHans de Goede 	ret = hid_open_report(hdev);
1003c785a06SHans de Goede 	if (ret)
1013c785a06SHans de Goede 		return ret;
1023c785a06SHans de Goede 
1033c785a06SHans de Goede 	return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1043c785a06SHans de Goede }
1053c785a06SHans de Goede 
106f1918be1SHans de Goede static const struct hid_device_id ite_devices[] = {
107f1918be1SHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE8595) },
10840502074SHans de Goede 	{ HID_USB_DEVICE(USB_VENDOR_ID_258A, USB_DEVICE_ID_258A_6A88) },
1098f18eca9SHans de Goede 	/* ITE8595 USB kbd ctlr, with Synaptics touchpad connected to it. */
110beae5619SHans de Goede 	{ HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
111beae5619SHans de Goede 		     USB_VENDOR_ID_SYNAPTICS,
1123c785a06SHans de Goede 		     USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_012),
1133c785a06SHans de Goede 	  .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT },
1145bf2f2f3SHans de Goede 	/* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */
1155bf2f2f3SHans de Goede 	{ HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
1165bf2f2f3SHans de Goede 		     USB_VENDOR_ID_SYNAPTICS,
117c961facbSHans de Goede 		     USB_DEVICE_ID_SYNAPTICS_ACER_ONE_S1002),
118c961facbSHans de Goede 	  .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT },
119c961facbSHans de Goede 	/* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */
120c961facbSHans de Goede 	{ HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
121c961facbSHans de Goede 		     USB_VENDOR_ID_SYNAPTICS,
122b7c20f38SHans de Goede 		     USB_DEVICE_ID_SYNAPTICS_ACER_ONE_S1003),
123b7c20f38SHans de Goede 	  .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT },
1249ad6645aSHans de Goede 	/* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */
1259ad6645aSHans de Goede 	{ HID_DEVICE(BUS_USB, HID_GROUP_GENERIC,
1269ad6645aSHans de Goede 		     USB_VENDOR_ID_SYNAPTICS,
1279ad6645aSHans de Goede 		     USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_017),
1289ad6645aSHans de Goede 	  .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT },
129f1918be1SHans de Goede 	{ }
130f1918be1SHans de Goede };
131f1918be1SHans de Goede MODULE_DEVICE_TABLE(hid, ite_devices);
132f1918be1SHans de Goede 
133f1918be1SHans de Goede static struct hid_driver ite_driver = {
134f1918be1SHans de Goede 	.name = "itetech",
135f1918be1SHans de Goede 	.id_table = ite_devices,
1363c785a06SHans de Goede 	.probe = ite_probe,
1373c785a06SHans de Goede 	.report_fixup = ite_report_fixup,
1383c785a06SHans de Goede 	.input_mapping = ite_input_mapping,
139f1918be1SHans de Goede 	.event = ite_event,
140f1918be1SHans de Goede };
141f1918be1SHans de Goede module_hid_driver(ite_driver);
142f1918be1SHans de Goede 
143b413c59eSHans de Goede MODULE_AUTHOR("Hans de Goede <hdegoede@redhat.com>");
1445bd8d707SJeff Johnson MODULE_DESCRIPTION("HID driver for some ITE \"special\" devices");
145f1918be1SHans de Goede MODULE_LICENSE("GPL");
146