1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Force feedback support for ACRUX game controllers
5 * From what I have gathered, these devices are mass produced in China
6 * by several vendors. They often share the same design as the original
9 * 1a34:0802 "ACRUX USB GAMEPAD 8116"
10 * - tested with an EXEQ EQ-PCU-02090 game controller.
18 #include <linux/input.h>
19 #include <linux/slab.h>
20 #include <linux/hid.h>
21 #include <linux/module.h>
25 #ifdef CONFIG_HID_ACRUX_FF
28 struct hid_report *report;
31 static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
33 struct hid_device *hid = input_get_drvdata(dev);
34 struct axff_device *axff = data;
35 struct hid_report *report = axff->report;
40 left = effect->u.rumble.strong_magnitude;
41 right = effect->u.rumble.weak_magnitude;
43 dbg_hid("called with 0x%04x 0x%04x", left, right);
45 left = left * 0xff / 0xffff;
46 right = right * 0xff / 0xffff;
48 for (i = 0; i < report->maxfield; i++) {
49 for (j = 0; j < report->field[i]->report_count; j++) {
50 report->field[i]->value[j] =
51 field_count % 2 ? right : left;
56 dbg_hid("running with 0x%02x 0x%02x", left, right);
57 hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT);
62 static int axff_init(struct hid_device *hid)
64 struct axff_device *axff;
65 struct hid_report *report;
66 struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
67 struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list;
68 struct input_dev *dev = hidinput->input;
73 if (list_empty(report_list)) {
74 hid_err(hid, "no output reports found\n");
78 report = list_first_entry(report_list, struct hid_report, list);
79 for (i = 0; i < report->maxfield; i++) {
80 for (j = 0; j < report->field[i]->report_count; j++) {
81 report->field[i]->value[j] = 0x00;
86 if (field_count < 4 && hid->product != 0xf705) {
87 hid_err(hid, "not enough fields in the report: %d\n",
92 axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
96 set_bit(FF_RUMBLE, dev->ffbit);
98 error = input_ff_create_memless(dev, axff, axff_play);
102 axff->report = report;
103 hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT);
105 hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun <
[email protected]>\n");
114 static inline int axff_init(struct hid_device *hid)
120 static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
124 dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n");
126 error = hid_parse(hdev);
128 hid_err(hdev, "parse failed\n");
132 error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
134 hid_err(hdev, "hw start failed\n");
138 error = axff_init(hdev);
141 * Do not fail device initialization completely as device
142 * may still be partially operable, just warn.
145 "Failed to enable force feedback support, error: %d\n",
150 * We need to start polling device right away, otherwise
151 * it will go into a coma.
153 error = hid_hw_open(hdev);
155 dev_err(&hdev->dev, "hw open failed\n");
163 static void ax_remove(struct hid_device *hdev)
169 static const struct hid_device_id ax_devices[] = {
170 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), },
171 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705), },
174 MODULE_DEVICE_TABLE(hid, ax_devices);
176 static struct hid_driver ax_driver = {
178 .id_table = ax_devices,
182 module_hid_driver(ax_driver);
184 MODULE_AUTHOR("Sergei Kolzun");
185 MODULE_DESCRIPTION("Force feedback support for ACRUX game controllers");
186 MODULE_LICENSE("GPL");