blob: b4554288de00bee40adb14d3318df8d4aa3c97b8 [file] [log] [blame]
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +02001/*
2 * Force feedback support for ACRUX game controllers
3 *
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
6 * Xbox 360 controller.
7 *
8 * 1a34:0802 "ACRUX USB GAMEPAD 8116"
9 * - tested with a EXEQ EQ-PCU-02090 game controller.
10 *
11 * Copyright (c) 2010 Sergei Kolzun <x0r@dv-life.ru>
12 */
13
14/*
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.
19 *
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.
24 *
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
28 */
29
30#include <linux/input.h>
31#include <linux/slab.h>
32#include <linux/usb.h>
33#include <linux/hid.h>
34
35#include "hid-ids.h"
Dmitry Torokhov0ae43812011-03-11 00:27:34 -080036
37#ifdef CONFIG_HID_ACRUX_FF
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +020038#include "usbhid/usbhid.h"
39
40struct axff_device {
41 struct hid_report *report;
42};
43
44static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
45{
46 struct hid_device *hid = input_get_drvdata(dev);
47 struct axff_device *axff = data;
48 int left, right;
49
50 left = effect->u.rumble.strong_magnitude;
51 right = effect->u.rumble.weak_magnitude;
52
53 dbg_hid("called with 0x%04x 0x%04x", left, right);
54
55 left = left * 0xff / 0xffff;
56 right = right * 0xff / 0xffff;
57
58 axff->report->field[0]->value[0] = left;
59 axff->report->field[1]->value[0] = right;
60 axff->report->field[2]->value[0] = left;
61 axff->report->field[3]->value[0] = right;
62 dbg_hid("running with 0x%02x 0x%02x", left, right);
63 usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
64
65 return 0;
66}
67
68static int axff_init(struct hid_device *hid)
69{
70 struct axff_device *axff;
71 struct hid_report *report;
72 struct hid_input *hidinput = list_first_entry(&hid->inputs, struct hid_input, list);
73 struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list;
74 struct input_dev *dev = hidinput->input;
75 int error;
76
77 if (list_empty(report_list)) {
Joe Perches4291ee32010-12-09 19:29:03 -080078 hid_err(hid, "no output reports found\n");
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +020079 return -ENODEV;
80 }
81
82 report = list_first_entry(report_list, struct hid_report, list);
83
84 if (report->maxfield < 4) {
Joe Perches4291ee32010-12-09 19:29:03 -080085 hid_err(hid, "no fields in the report: %d\n", report->maxfield);
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +020086 return -ENODEV;
87 }
88
89 axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL);
90 if (!axff)
91 return -ENOMEM;
92
93 set_bit(FF_RUMBLE, dev->ffbit);
94
95 error = input_ff_create_memless(dev, axff, axff_play);
96 if (error)
97 goto err_free_mem;
98
99 axff->report = report;
100 axff->report->field[0]->value[0] = 0x00;
101 axff->report->field[1]->value[0] = 0x00;
102 axff->report->field[2]->value[0] = 0x00;
103 axff->report->field[3]->value[0] = 0x00;
104 usbhid_submit_report(hid, axff->report, USB_DIR_OUT);
105
Joe Perches4291ee32010-12-09 19:29:03 -0800106 hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun<x0r@dv-life.ru>\n");
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200107
108 return 0;
109
110err_free_mem:
111 kfree(axff);
112 return error;
113}
Dmitry Torokhov0ae43812011-03-11 00:27:34 -0800114#else
115static inline int axff_init(struct hid_device *hid)
116{
117 return 0;
118}
119#endif
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200120
121static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id)
122{
123 int error;
124
Joe Perches4291ee32010-12-09 19:29:03 -0800125 dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n");
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200126
127 error = hid_parse(hdev);
128 if (error) {
Joe Perches4291ee32010-12-09 19:29:03 -0800129 hid_err(hdev, "parse failed\n");
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200130 return error;
131 }
132
133 error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
134 if (error) {
Joe Perches4291ee32010-12-09 19:29:03 -0800135 hid_err(hdev, "hw start failed\n");
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200136 return error;
137 }
138
139 error = axff_init(hdev);
140 if (error) {
141 /*
142 * Do not fail device initialization completely as device
143 * may still be partially operable, just warn.
144 */
Joe Perches4291ee32010-12-09 19:29:03 -0800145 hid_warn(hdev,
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200146 "Failed to enable force feedback support, error: %d\n",
147 error);
148 }
149
Dmitry Torokhov0ae43812011-03-11 00:27:34 -0800150 /*
151 * We need to start polling device right away, otherwise
152 * it will go into a coma.
153 */
154 error = hid_hw_open(hdev);
155 if (error) {
156 dev_err(&hdev->dev, "hw open failed\n");
157 return error;
158 }
159
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200160 return 0;
161}
162
Dmitry Torokhov0ae43812011-03-11 00:27:34 -0800163static void ax_remove(struct hid_device *hdev)
164{
165 hid_hw_close(hdev);
166 hid_hw_stop(hdev);
167}
168
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200169static const struct hid_device_id ax_devices[] = {
170 { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), },
171 { }
172};
173MODULE_DEVICE_TABLE(hid, ax_devices);
174
175static struct hid_driver ax_driver = {
Dmitry Torokhov0ae43812011-03-11 00:27:34 -0800176 .name = "acrux",
177 .id_table = ax_devices,
178 .probe = ax_probe,
179 .remove = ax_remove,
Sergei Kolzunc0dbcc32010-07-19 12:13:23 +0200180};
181
182static int __init ax_init(void)
183{
184 return hid_register_driver(&ax_driver);
185}
186
187static void __exit ax_exit(void)
188{
189 hid_unregister_driver(&ax_driver);
190}
191
192module_init(ax_init);
193module_exit(ax_exit);
194
195MODULE_AUTHOR("Sergei Kolzun");
196MODULE_DESCRIPTION("Force feedback support for ACRUX game controllers");
197MODULE_LICENSE("GPL");