hid-holtek-mouse.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * HID driver for Holtek gaming mice
  3. * Copyright (c) 2013 Christian Ohm
  4. * Heavily inspired by various other HID drivers that adjust the report
  5. * descriptor.
  6. */
  7. /*
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. */
  13. #include <linux/hid.h>
  14. #include <linux/module.h>
  15. #include <linux/usb.h>
  16. #include "hid-ids.h"
  17. /*
  18. * The report descriptor of some Holtek based gaming mice specifies an
  19. * excessively large number of consumer usages (2^15), which is more than
  20. * HID_MAX_USAGES. This prevents proper parsing of the report descriptor.
  21. *
  22. * This driver fixes the report descriptor for:
  23. * - USB ID 04d9:a067, sold as Sharkoon Drakonia and Perixx MX-2000
  24. * - USB ID 04d9:a04a, sold as Tracer Sniper TRM-503, NOVA Gaming Slider X200
  25. * and Zalman ZM-GM1
  26. * - USB ID 04d9:a081, sold as SHARKOON DarkGlider Gaming mouse
  27. * - USB ID 04d9:a072, sold as LEETGION Hellion Gaming Mouse
  28. * - USB ID 04d9:a0c2, sold as ETEKCITY Scroll T-140 Gaming Mouse
  29. */
  30. static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  31. unsigned int *rsize)
  32. {
  33. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  34. if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
  35. /* Change usage maximum and logical maximum from 0x7fff to
  36. * 0x2fff, so they don't exceed HID_MAX_USAGES */
  37. switch (hdev->product) {
  38. case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067:
  39. case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072:
  40. case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2:
  41. if (*rsize >= 122 && rdesc[115] == 0xff && rdesc[116] == 0x7f
  42. && rdesc[120] == 0xff && rdesc[121] == 0x7f) {
  43. hid_info(hdev, "Fixing up report descriptor\n");
  44. rdesc[116] = rdesc[121] = 0x2f;
  45. }
  46. break;
  47. case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A:
  48. case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070:
  49. case USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081:
  50. if (*rsize >= 113 && rdesc[106] == 0xff && rdesc[107] == 0x7f
  51. && rdesc[111] == 0xff && rdesc[112] == 0x7f) {
  52. hid_info(hdev, "Fixing up report descriptor\n");
  53. rdesc[107] = rdesc[112] = 0x2f;
  54. }
  55. break;
  56. }
  57. }
  58. return rdesc;
  59. }
  60. static const struct hid_device_id holtek_mouse_devices[] = {
  61. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
  62. USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
  63. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
  64. USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A070) },
  65. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
  66. USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A04A) },
  67. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
  68. USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A072) },
  69. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
  70. USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A081) },
  71. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
  72. USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A0C2) },
  73. { }
  74. };
  75. MODULE_DEVICE_TABLE(hid, holtek_mouse_devices);
  76. static struct hid_driver holtek_mouse_driver = {
  77. .name = "holtek_mouse",
  78. .id_table = holtek_mouse_devices,
  79. .report_fixup = holtek_mouse_report_fixup,
  80. };
  81. module_hid_driver(holtek_mouse_driver);
  82. MODULE_LICENSE("GPL");