2 * Force feedback support for ACRUX game controllers
4 * From what I have gathered, these devices are mass produced in China
5 * by several vendors. They often share the same design as the original
8 * 1a34:0802 "ACRUX USB GAMEPAD 8116"
9 * - tested with an EXEQ EQ-PCU-02090 game controller.
11 * Copyright (c) 2010 Sergei Kolzun <x0r@dv-life.ru>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <linux/input.h>
31 #include <linux/slab.h>
32 #include <linux/usb.h>
33 #include <linux/hid.h>
34 #include <linux/module.h>
38 #ifdef CONFIG_HID_ACRUX_FF
39 #include "usbhid/usbhid.h"
42 struct hid_report *report;
45 static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
47 struct hid_device *hid = input_get_drvdata(dev);
48 struct axff_device *axff = data;
49 struct hid_report *report = axff->report;
54 left = effect->u.rumble.strong_magnitude;
55 right = effect->u.rumble.weak_magnitude;
57 dbg_hid("called with 0x%04x 0x%04x", left, right);
59 left = left * 0xff / 0xffff;
60 right = right * 0xff / 0xffff;
62 for (i = 0; i < report->maxfield; i++) {
63 for (j = 0; j < report->field[i]->report_count; j++) {
64 report->field[i]->value[j] =
65 field_count % 2 ? right : left;
70 dbg_hid("running with 0x%02x 0x%02x", left, right);
71 usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
76 static int axff_init(struct hid_device *hid)
78 struct axff_device *axff;
79 struct hid_report *report;
80 struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
81 struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list;
82 struct input_dev *dev = hidinput->input;
87 if (list_empty(report_list)) {
88 hid_err(hid, "no output reports found\n");
92 report = list_first_entry(report_list, struct hid_report, list);
93 for (i = 0; i < report->maxfield; i++) {
94 for (j = 0; j < report->field[i]->report_count; j++) {
95 report->field[i]->value[j] = 0x00;
100 if (field_count < 4) {
101 hid_err(hid, "not enough fields in the report: %d\n",
106 axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
110 set_bit(FF_RUMBLE, dev->ffbit);
112 error = input_ff_create_memless(dev, axff, axff_play);
116 axff->report = report;
117 usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
119 hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun <x0r@dv-life.ru>\n");
128 static inline int axff_init(struct hid_device *hid)
134 static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
138 dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n");
140 error = hid_parse(hdev);
142 hid_err(hdev, "parse failed\n");
146 error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
148 hid_err(hdev, "hw start failed\n");
152 error = axff_init(hdev);
155 * Do not fail device initialization completely as device
156 * may still be partially operable, just warn.
159 "Failed to enable force feedback support, error: %d\n",
164 * We need to start polling device right away, otherwise
165 * it will go into a coma.
167 error = hid_hw_open(hdev);
169 dev_err(&hdev->dev, "hw open failed\n");
177 static void ax_remove(struct hid_device *hdev)
183 static const struct hid_device_id ax_devices[] = {
184 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), },
187 MODULE_DEVICE_TABLE(hid, ax_devices);
189 static struct hid_driver ax_driver = {
191 .id_table = ax_devices,
195 module_hid_driver(ax_driver);
197 MODULE_AUTHOR("Sergei Kolzun");
198 MODULE_DESCRIPTION("Force feedback support for ACRUX game controllers");
199 MODULE_LICENSE("GPL");