Skip to content

Commit 2c5e8e6

Browse files
marcusfolkessonbentiss
authored andcommitted
HID: Add driver for VRC-2 Car Controller
VRC-2 is 2-axis controller often used in car simulators. Signed-off-by: Marcus Folkesson <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a1f7642 commit 2c5e8e6

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9065,6 +9065,12 @@ F: drivers/hid/hid-sensor-*
90659065
F: drivers/iio/*/hid-*
90669066
F: include/linux/hid-sensor-*
90679067

9068+
HID VRC-2 CAR CONTROLLER DRIVER
9069+
M: Marcus Folkesson <[email protected]>
9070+
9071+
S: Maintained
9072+
F: drivers/hid/hid-vrc2.c
9073+
90689074
HID WACOM DRIVER
90699075
M: Ping Cheng <[email protected]>
90709076
M: Jason Gerecke <[email protected]>

drivers/hid/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ config HID_VIEWSONIC
481481
help
482482
Support for ViewSonic/Signotec PD1011 signature pad.
483483

484+
config HID_VRC2
485+
tristate "VRC-2 Car Controller"
486+
depends on HID
487+
help
488+
Support for VRC-2 which is a 2-axis controller often used in
489+
car simulators.
490+
491+
To compile this driver as a module, choose M here: the
492+
module will be called hid-vrc2.
493+
484494
config HID_XIAOMI
485495
tristate "Xiaomi"
486496
depends on HID

drivers/hid/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ obj-$(CONFIG_HID_XINMO) += hid-xinmo.o
136136
obj-$(CONFIG_HID_ZEROPLUS) += hid-zpff.o
137137
obj-$(CONFIG_HID_ZYDACRON) += hid-zydacron.o
138138
obj-$(CONFIG_HID_VIEWSONIC) += hid-viewsonic.o
139+
obj-$(CONFIG_HID_VRC2) += hid-vrc2.o
139140

140141
wacom-objs := wacom_wac.o wacom_sys.o
141142
obj-$(CONFIG_HID_WACOM) += wacom.o

drivers/hid/hid-vrc2.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
8+
#include <linux/device.h>
9+
#include <linux/hid.h>
10+
#include <linux/module.h>
11+
12+
/*
13+
* VID/PID are probably "borrowed", so keep them locally and
14+
* do not populate hid-ids.h with those.
15+
*/
16+
#define USB_VENDOR_ID_VRC2 (0x07c0)
17+
#define USB_DEVICE_ID_VRC2 (0x1125)
18+
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
39+
};
40+
41+
static __u8 *vrc2_report_fixup(struct hid_device *hdev, __u8 *rdesc,
42+
unsigned int *rsize)
43+
{
44+
hid_info(hdev, "fixing up VRC-2 report descriptor\n");
45+
*rsize = sizeof(vrc2_rdesc_fixed);
46+
return vrc2_rdesc_fixed;
47+
}
48+
49+
static int vrc2_probe(struct hid_device *hdev, const struct hid_device_id *id)
50+
{
51+
int ret;
52+
53+
/*
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
56+
*/
57+
if (hdev->dev_rsize == 23)
58+
return -ENODEV;
59+
60+
ret = hid_parse(hdev);
61+
if (ret) {
62+
hid_err(hdev, "parse failed\n");
63+
return ret;
64+
}
65+
66+
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
67+
if (ret) {
68+
hid_err(hdev, "hw start failed\n");
69+
return ret;
70+
}
71+
72+
return 0;
73+
}
74+
75+
static const struct hid_device_id vrc2_devices[] = {
76+
{ HID_USB_DEVICE(USB_VENDOR_ID_VRC2, USB_DEVICE_ID_VRC2) },
77+
{ /* sentinel */ }
78+
};
79+
MODULE_DEVICE_TABLE(hid, vrc2_devices);
80+
81+
static struct hid_driver vrc2_driver = {
82+
.name = "vrc2",
83+
.id_table = vrc2_devices,
84+
.report_fixup = vrc2_report_fixup,
85+
.probe = vrc2_probe,
86+
};
87+
module_hid_driver(vrc2_driver);
88+
89+
MODULE_AUTHOR("Marcus Folkesson <[email protected]>");
90+
MODULE_DESCRIPTION("HID driver for VRC-2 2-axis Car controller");
91+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)