hid-glorious.c 2.1 KB

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