Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / hid / hid-glorious.c
blob558eb08c19ef9da28b233e4418353a32b0172260
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * USB HID driver for Glorious PC Gaming Race
4 * Glorious Model O, O- and D mice.
6 * Copyright (c) 2020 Samuel Čavoj <sammko@sammserver.com>
7 */
9 /*
12 #include <linux/hid.h>
13 #include <linux/module.h>
15 #include "hid-ids.h"
17 MODULE_AUTHOR("Samuel Čavoj <sammko@sammserver.com>");
18 MODULE_DESCRIPTION("HID driver for Glorious PC Gaming Race mice");
21 * Glorious Model O and O- specify the const flag in the consumer input
22 * report descriptor, which leads to inputs being ignored. Fix this
23 * by patching the descriptor.
25 static __u8 *glorious_report_fixup(struct hid_device *hdev, __u8 *rdesc,
26 unsigned int *rsize)
28 if (*rsize == 213 &&
29 rdesc[84] == 129 && rdesc[112] == 129 && rdesc[140] == 129 &&
30 rdesc[85] == 3 && rdesc[113] == 3 && rdesc[141] == 3) {
31 hid_info(hdev, "patching Glorious Model O consumer control report descriptor\n");
32 rdesc[85] = rdesc[113] = rdesc[141] = \
33 HID_MAIN_ITEM_VARIABLE | HID_MAIN_ITEM_RELATIVE;
35 return rdesc;
38 static void glorious_update_name(struct hid_device *hdev)
40 const char *model = "Device";
42 switch (hdev->product) {
43 case USB_DEVICE_ID_GLORIOUS_MODEL_O:
44 model = "Model O"; break;
45 case USB_DEVICE_ID_GLORIOUS_MODEL_D:
46 model = "Model D"; break;
49 snprintf(hdev->name, sizeof(hdev->name), "%s %s", "Glorious", model);
52 static int glorious_probe(struct hid_device *hdev,
53 const struct hid_device_id *id)
55 int ret;
57 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
59 ret = hid_parse(hdev);
60 if (ret)
61 return ret;
63 glorious_update_name(hdev);
65 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
68 static const struct hid_device_id glorious_devices[] = {
69 { HID_USB_DEVICE(USB_VENDOR_ID_GLORIOUS,
70 USB_DEVICE_ID_GLORIOUS_MODEL_O) },
71 { HID_USB_DEVICE(USB_VENDOR_ID_GLORIOUS,
72 USB_DEVICE_ID_GLORIOUS_MODEL_D) },
73 { }
75 MODULE_DEVICE_TABLE(hid, glorious_devices);
77 static struct hid_driver glorious_driver = {
78 .name = "glorious",
79 .id_table = glorious_devices,
80 .probe = glorious_probe,
81 .report_fixup = glorious_report_fixup
84 module_hid_driver(glorious_driver);
86 MODULE_LICENSE("GPL");