hid-topre.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * HID driver for Topre REALFORCE Keyboards
  4. *
  5. * Copyright (c) 2022 Harry Stern <[email protected]>
  6. *
  7. * Based on the hid-macally driver
  8. */
  9. #include <linux/hid.h>
  10. #include <linux/module.h>
  11. #include "hid-ids.h"
  12. MODULE_AUTHOR("Harry Stern <[email protected]>");
  13. MODULE_DESCRIPTION("REALFORCE R2 Keyboard driver");
  14. MODULE_LICENSE("GPL");
  15. /*
  16. * Fix the REALFORCE R2's non-boot interface's report descriptor to match the
  17. * events it's actually sending. It claims to send array events but is instead
  18. * sending variable events.
  19. */
  20. static __u8 *topre_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  21. unsigned int *rsize)
  22. {
  23. if (*rsize >= 119 && rdesc[69] == 0x29 && rdesc[70] == 0xe7 &&
  24. rdesc[71] == 0x81 && rdesc[72] == 0x00) {
  25. hid_info(hdev,
  26. "fixing up Topre REALFORCE keyboard report descriptor\n");
  27. rdesc[72] = 0x02;
  28. }
  29. return rdesc;
  30. }
  31. static const struct hid_device_id topre_id_table[] = {
  32. { HID_USB_DEVICE(USB_VENDOR_ID_TOPRE,
  33. USB_DEVICE_ID_TOPRE_REALFORCE_R2_108) },
  34. { }
  35. };
  36. MODULE_DEVICE_TABLE(hid, topre_id_table);
  37. static struct hid_driver topre_driver = {
  38. .name = "topre",
  39. .id_table = topre_id_table,
  40. .report_fixup = topre_report_fixup,
  41. };
  42. module_hid_driver(topre_driver);