Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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