hid-vrc2.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * HID driver for VRC-2 2-axis Car controller
  4. *
  5. * Copyright (C) 2022 Marcus Folkesson <[email protected]>
  6. */
  7. #include <linux/device.h>
  8. #include <linux/hid.h>
  9. #include <linux/module.h>
  10. /*
  11. * VID/PID are probably "borrowed", so keep them locally and
  12. * do not populate hid-ids.h with those.
  13. */
  14. #define USB_VENDOR_ID_VRC2 (0x07c0)
  15. #define USB_DEVICE_ID_VRC2 (0x1125)
  16. static __u8 vrc2_rdesc_fixed[] = {
  17. 0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
  18. 0x09, 0x04, // Usage (Joystick)
  19. 0xA1, 0x01, // Collection (Application)
  20. 0x09, 0x01, // Usage (Pointer)
  21. 0xA1, 0x00, // Collection (Physical)
  22. 0x09, 0x30, // Usage (X)
  23. 0x09, 0x31, // Usage (Y)
  24. 0x15, 0x00, // Logical Minimum (0)
  25. 0x26, 0xFF, 0x07, // Logical Maximum (2047)
  26. 0x35, 0x00, // Physical Minimum (0)
  27. 0x46, 0xFF, 0x00, // Physical Maximum (255)
  28. 0x75, 0x10, // Report Size (16)
  29. 0x95, 0x02, // Report Count (2)
  30. 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
  31. 0xC0, // End Collection
  32. 0x75, 0x08, // Report Size (8)
  33. 0x95, 0x03, // Report Count (3)
  34. 0x81, 0x03, // Input (Cnst,Var,Abs)
  35. 0xC0, // End Collection
  36. };
  37. static __u8 *vrc2_report_fixup(struct hid_device *hdev, __u8 *rdesc,
  38. unsigned int *rsize)
  39. {
  40. hid_info(hdev, "fixing up VRC-2 report descriptor\n");
  41. *rsize = sizeof(vrc2_rdesc_fixed);
  42. return vrc2_rdesc_fixed;
  43. }
  44. static int vrc2_probe(struct hid_device *hdev, const struct hid_device_id *id)
  45. {
  46. int ret;
  47. /*
  48. * The device gives us 2 separate USB endpoints.
  49. * One of those (the one with report descriptor size of 23) is just bogus so ignore it
  50. */
  51. if (hdev->dev_rsize == 23)
  52. return -ENODEV;
  53. ret = hid_parse(hdev);
  54. if (ret) {
  55. hid_err(hdev, "parse failed\n");
  56. return ret;
  57. }
  58. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  59. if (ret) {
  60. hid_err(hdev, "hw start failed\n");
  61. return ret;
  62. }
  63. return 0;
  64. }
  65. static const struct hid_device_id vrc2_devices[] = {
  66. { HID_USB_DEVICE(USB_VENDOR_ID_VRC2, USB_DEVICE_ID_VRC2) },
  67. { /* sentinel */ }
  68. };
  69. MODULE_DEVICE_TABLE(hid, vrc2_devices);
  70. static struct hid_driver vrc2_driver = {
  71. .name = "vrc2",
  72. .id_table = vrc2_devices,
  73. .report_fixup = vrc2_report_fixup,
  74. .probe = vrc2_probe,
  75. };
  76. module_hid_driver(vrc2_driver);
  77. MODULE_AUTHOR("Marcus Folkesson <[email protected]>");
  78. MODULE_DESCRIPTION("HID driver for VRC-2 2-axis Car controller");
  79. MODULE_LICENSE("GPL");