hid-redragon.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * HID driver for Redragon keyboards
  3. *
  4. * Copyright (c) 2017 Robert Munteanu
  5. * SPDX-License-Identifier: GPL-2.0+
  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/device.h>
  14. #include <linux/hid.h>
  15. #include <linux/module.h>
  16. #include "hid-ids.h"
  17. /*
  18. * The Redragon Asura keyboard sends an incorrect HID descriptor.
  19. * At byte 100 it contains
  20. *
  21. * 0x81, 0x00
  22. *
  23. * which is Input (Data, Arr, Abs), but it should be
  24. *
  25. * 0x81, 0x02
  26. *
  27. * which is Input (Data, Var, Abs), which is consistent with the way
  28. * key codes are generated.
  29. */
  30. static __u8 *redragon_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  31. unsigned int *rsize)
  32. {
  33. if (*rsize >= 102 && rdesc[100] == 0x81 && rdesc[101] == 0x00) {
  34. dev_info(&hdev->dev, "Fixing Redragon ASURA report descriptor.\n");
  35. rdesc[101] = 0x02;
  36. }
  37. return rdesc;
  38. }
  39. static const struct hid_device_id redragon_devices[] = {
  40. {HID_USB_DEVICE(USB_VENDOR_ID_JESS, USB_DEVICE_ID_REDRAGON_ASURA)},
  41. {}
  42. };
  43. MODULE_DEVICE_TABLE(hid, redragon_devices);
  44. static struct hid_driver redragon_driver = {
  45. .name = "redragon",
  46. .id_table = redragon_devices,
  47. .report_fixup = redragon_report_fixup
  48. };
  49. module_hid_driver(redragon_driver);
  50. MODULE_LICENSE("GPL");