Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  USB HID driver for Glorious PC Gaming Race
0004  *  Glorious Model O, O- and D mice.
0005  *
0006  *  Copyright (c) 2020 Samuel Čavoj <sammko@sammserver.com>
0007  */
0008 
0009 /*
0010  */
0011 
0012 #include <linux/hid.h>
0013 #include <linux/module.h>
0014 
0015 #include "hid-ids.h"
0016 
0017 MODULE_AUTHOR("Samuel Čavoj <sammko@sammserver.com>");
0018 MODULE_DESCRIPTION("HID driver for Glorious PC Gaming Race mice");
0019 
0020 /*
0021  * Glorious Model O and O- specify the const flag in the consumer input
0022  * report descriptor, which leads to inputs being ignored. Fix this
0023  * by patching the descriptor.
0024  */
0025 static __u8 *glorious_report_fixup(struct hid_device *hdev, __u8 *rdesc,
0026         unsigned int *rsize)
0027 {
0028     if (*rsize == 213 &&
0029         rdesc[84] == 129 && rdesc[112] == 129 && rdesc[140] == 129 &&
0030         rdesc[85] == 3   && rdesc[113] == 3   && rdesc[141] == 3) {
0031         hid_info(hdev, "patching Glorious Model O consumer control report descriptor\n");
0032         rdesc[85] = rdesc[113] = rdesc[141] = \
0033             HID_MAIN_ITEM_VARIABLE | HID_MAIN_ITEM_RELATIVE;
0034     }
0035     return rdesc;
0036 }
0037 
0038 static void glorious_update_name(struct hid_device *hdev)
0039 {
0040     const char *model = "Device";
0041 
0042     switch (hdev->product) {
0043     case USB_DEVICE_ID_GLORIOUS_MODEL_O:
0044         model = "Model O"; break;
0045     case USB_DEVICE_ID_GLORIOUS_MODEL_D:
0046         model = "Model D"; break;
0047     }
0048 
0049     snprintf(hdev->name, sizeof(hdev->name), "%s %s", "Glorious", model);
0050 }
0051 
0052 static int glorious_probe(struct hid_device *hdev,
0053         const struct hid_device_id *id)
0054 {
0055     int ret;
0056 
0057     hdev->quirks |= HID_QUIRK_INPUT_PER_APP;
0058 
0059     ret = hid_parse(hdev);
0060     if (ret)
0061         return ret;
0062 
0063     glorious_update_name(hdev);
0064 
0065     return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
0066 }
0067 
0068 static const struct hid_device_id glorious_devices[] = {
0069     { HID_USB_DEVICE(USB_VENDOR_ID_GLORIOUS,
0070         USB_DEVICE_ID_GLORIOUS_MODEL_O) },
0071     { HID_USB_DEVICE(USB_VENDOR_ID_GLORIOUS,
0072         USB_DEVICE_ID_GLORIOUS_MODEL_D) },
0073     { }
0074 };
0075 MODULE_DEVICE_TABLE(hid, glorious_devices);
0076 
0077 static struct hid_driver glorious_driver = {
0078     .name = "glorious",
0079     .id_table = glorious_devices,
0080     .probe = glorious_probe,
0081     .report_fixup = glorious_report_fixup
0082 };
0083 
0084 module_hid_driver(glorious_driver);
0085 
0086 MODULE_LICENSE("GPL");