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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *  USB HID driver for Glorious PC Gaming Race
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *  Glorious Model O, O- and D mice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *  Copyright (c) 2020 Samuel Čavoj <sammko@sammserver.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) MODULE_AUTHOR("Samuel Čavoj <sammko@sammserver.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) MODULE_DESCRIPTION("HID driver for Glorious PC Gaming Race mice");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)  * Glorious Model O and O- specify the const flag in the consumer input
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)  * report descriptor, which leads to inputs being ignored. Fix this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)  * by patching the descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static __u8 *glorious_report_fixup(struct hid_device *hdev, __u8 *rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 		unsigned int *rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	if (*rsize == 213 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		rdesc[84] == 129 && rdesc[112] == 129 && rdesc[140] == 129 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		rdesc[85] == 3   && rdesc[113] == 3   && rdesc[141] == 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 		hid_info(hdev, "patching Glorious Model O consumer control report descriptor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 		rdesc[85] = rdesc[113] = rdesc[141] = \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 			HID_MAIN_ITEM_VARIABLE | HID_MAIN_ITEM_RELATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	return rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void glorious_update_name(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	const char *model = "Device";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	switch (hdev->product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	case USB_DEVICE_ID_GLORIOUS_MODEL_O:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 		model = "Model O"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	case USB_DEVICE_ID_GLORIOUS_MODEL_D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		model = "Model D"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	snprintf(hdev->name, sizeof(hdev->name), "%s %s", "Glorious", model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static int glorious_probe(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	glorious_update_name(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static const struct hid_device_id glorious_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLORIOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		USB_DEVICE_ID_GLORIOUS_MODEL_O) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	{ HID_USB_DEVICE(USB_VENDOR_ID_GLORIOUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 		USB_DEVICE_ID_GLORIOUS_MODEL_D) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) MODULE_DEVICE_TABLE(hid, glorious_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static struct hid_driver glorious_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	.name = "glorious",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	.id_table = glorious_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	.probe = glorious_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	.report_fixup = glorious_report_fixup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) module_hid_driver(glorious_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) MODULE_LICENSE("GPL");