hid-holtek-mouse.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 USB ID 04d9:a067, sold as
  23. * Sharkoon Drakonia and Perixx MX-2000.
  24. */
  25. static __u8 *holtek_mouse_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  26. unsigned int *rsize)
  27. {
  28. struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
  29. if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
  30. /* Change usage maximum and logical maximum from 0x7fff to
  31. * 0x2fff, so they don't exceed HID_MAX_USAGES */
  32. if (*rsize >= 122 && rdesc[115] == 0xff && rdesc[116] == 0x7f
  33. && rdesc[120] == 0xff && rdesc[121] == 0x7f) {
  34. hid_info(hdev, "Fixing up report descriptor\n");
  35. rdesc[116] = rdesc[121] = 0x2f;
  36. }
  37. }
  38. return rdesc;
  39. }
  40. static const struct hid_device_id holtek_mouse_devices[] = {
  41. { HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK_ALT,
  42. USB_DEVICE_ID_HOLTEK_ALT_MOUSE_A067) },
  43. { }
  44. };
  45. MODULE_DEVICE_TABLE(hid, holtek_mouse_devices);
  46. static struct hid_driver holtek_mouse_driver = {
  47. .name = "holtek_mouse",
  48. .id_table = holtek_mouse_devices,
  49. .report_fixup = holtek_mouse_report_fixup,
  50. };
  51. static int __init holtek_mouse_init(void)
  52. {
  53. return hid_register_driver(&holtek_mouse_driver);
  54. }
  55. static void __exit holtek_mouse_exit(void)
  56. {
  57. hid_unregister_driver(&holtek_mouse_driver);
  58. }
  59. module_exit(holtek_mouse_exit);
  60. module_init(holtek_mouse_init);
  61. MODULE_LICENSE("GPL");