blob: 558eb08c19ef9da28b233e4418353a32b0172260 [file] [log] [blame]
Samuel Čavoj77a36a32020-03-13 03:12:38 +01001// 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.
5 *
6 * Copyright (c) 2020 Samuel Čavoj <sammko@sammserver.com>
7 */
8
9/*
10 */
11
12#include <linux/hid.h>
13#include <linux/module.h>
14
15#include "hid-ids.h"
16
17MODULE_AUTHOR("Samuel Čavoj <sammko@sammserver.com>");
18MODULE_DESCRIPTION("HID driver for Glorious PC Gaming Race mice");
19
20/*
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.
24 */
25static __u8 *glorious_report_fixup(struct hid_device *hdev, __u8 *rdesc,
26 unsigned int *rsize)
27{
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;
34 }
35 return rdesc;
36}
37
38static void glorious_update_name(struct hid_device *hdev)
39{
40 const char *model = "Device";
41
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;
47 }
48
49 snprintf(hdev->name, sizeof(hdev->name), "%s %s", "Glorious", model);
50}
51
52static int glorious_probe(struct hid_device *hdev,
53 const struct hid_device_id *id)
54{
55 int ret;
56
57 hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
58
59 ret = hid_parse(hdev);
60 if (ret)
61 return ret;
62
63 glorious_update_name(hdev);
64
65 return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
66}
67
68static 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 { }
74};
75MODULE_DEVICE_TABLE(hid, glorious_devices);
76
77static struct hid_driver glorious_driver = {
78 .name = "glorious",
79 .id_table = glorious_devices,
80 .probe = glorious_probe,
81 .report_fixup = glorious_report_fixup
82};
83
84module_hid_driver(glorious_driver);
85
86MODULE_LICENSE("GPL");