Skip to content

Commit 77a36a3

Browse files
sammkoJiri Kosina
authored andcommitted
HID: Add driver fixing Glorious PC Gaming Race mouse report descriptor
The Glorious Model O mice (and also at least the Model O-, which is driver-wise the same mouse) have a bug in the descriptor of HID Report with ID 2. This report is used for Consumer Control buttons, which can be mapped using the provided Windows only software. Here is an excerpt from the original descriptor: INPUT(2)[INPUT] Field(0) Flags( Constant Variable Absolute ) Field(1) Flags( Constant Variable Absolute ) Field(2) Flags( Constant Variable Absolute ) The issue is the Constant flag specified on all 3 fields, which causes the hid driver to ignore changes in these fields and essentialy causes the buttons to not work at all. The submitted driver patches the descriptor to end up with the following: INPUT(2)[INPUT] Field(0) Flags( Variable Relative ) Field(1) Flags( Variable Relative ) Field(2) Flags( Variable Relative ) The Constant bit is reset and the Relative bit has been set in order to prevent repeat events when holding down the button. Additionally, the device name is changed from the hardware-reported "SINOWEALTH Wired Gaming Mouse" to "Glorious Model O" or "Glorious Model D". Signed-off-by: Samuel Čavoj <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent ac309e7 commit 77a36a3

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

drivers/hid/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ config HID_GFRM
362362
---help---
363363
Support for Google Fiber TV Box remote controls
364364

365+
config HID_GLORIOUS
366+
tristate "Glorious PC Gaming Race mice"
367+
depends on HID
368+
help
369+
Support for Glorious PC Gaming Race mice such as
370+
the Glorious Model O, O- and D.
371+
365372
config HID_HOLTEK
366373
tristate "Holtek HID devices"
367374
depends on USB_HID

drivers/hid/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ obj-$(CONFIG_HID_ELO) += hid-elo.o
4848
obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o
4949
obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o
5050
obj-$(CONFIG_HID_GFRM) += hid-gfrm.o
51+
obj-$(CONFIG_HID_GLORIOUS) += hid-glorious.o
5152
obj-$(CONFIG_HID_GOOGLE_HAMMER) += hid-google-hammer.o
5253
obj-$(CONFIG_HID_GT683R) += hid-gt683r.o
5354
obj-$(CONFIG_HID_GYRATION) += hid-gyration.o

drivers/hid/hid-glorious.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.
5+
*
6+
* Copyright (c) 2020 Samuel Čavoj <[email protected]>
7+
*/
8+
9+
/*
10+
*/
11+
12+
#include <linux/hid.h>
13+
#include <linux/module.h>
14+
15+
#include "hid-ids.h"
16+
17+
MODULE_AUTHOR("Samuel Čavoj <[email protected]>");
18+
MODULE_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+
*/
25+
static __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+
38+
static 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+
52+
static 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+
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+
{ }
74+
};
75+
MODULE_DEVICE_TABLE(hid, glorious_devices);
76+
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
82+
};
83+
84+
module_hid_driver(glorious_driver);
85+
86+
MODULE_LICENSE("GPL");

drivers/hid/hid-ids.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@
464464
#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_010A 0x010a
465465
#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PIT_E100 0xe100
466466

467+
#define USB_VENDOR_ID_GLORIOUS 0x258a
468+
#define USB_DEVICE_ID_GLORIOUS_MODEL_D 0x0033
469+
#define USB_DEVICE_ID_GLORIOUS_MODEL_O 0x0036
470+
467471
#define I2C_VENDOR_ID_GOODIX 0x27c6
468472
#define I2C_DEVICE_ID_GOODIX_01F0 0x01f0
469473

0 commit comments

Comments
 (0)