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