2 * Force feedback support for DragonRise Inc. game controllers
4 * From what I have gathered, these devices are mass produced in China and are
5 * distributed under several vendors. They often share the same design as
6 * the original PlayStation DualShock controller.
8 * 0079:0006 "DragonRise Inc. Generic USB Joystick "
9 * - tested with a Tesun USB-703 game controller.
11 * Copyright (c) 2009 Richard Walmsley <richwalm@gmail.com>
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>
37 #ifdef CONFIG_DRAGONRISE_FF
38 #include "usbhid/usbhid.h"
41 struct hid_report *report;
44 static int drff_play(struct input_dev *dev, void *data,
45 struct ff_effect *effect)
47 struct hid_device *hid = input_get_drvdata(dev);
48 struct drff_device *drff = data;
51 strong = effect->u.rumble.strong_magnitude;
52 weak = effect->u.rumble.weak_magnitude;
54 dbg_hid("called with 0x%04x 0x%04x", strong, weak);
57 strong = strong * 0xff / 0xffff;
58 weak = weak * 0xff / 0xffff;
60 /* While reverse engineering this device, I found that when
61 this value is set, it causes the strong rumble to function
62 at a near maximum speed, so we'll bypass it. */
66 drff->report->field[0]->value[0] = 0x51;
67 drff->report->field[0]->value[1] = 0x00;
68 drff->report->field[0]->value[2] = weak;
69 drff->report->field[0]->value[4] = strong;
70 usbhid_submit_report(hid, drff->report, USB_DIR_OUT);
72 drff->report->field[0]->value[0] = 0xfa;
73 drff->report->field[0]->value[1] = 0xfe;
75 drff->report->field[0]->value[0] = 0xf3;
76 drff->report->field[0]->value[1] = 0x00;
79 drff->report->field[0]->value[2] = 0x00;
80 drff->report->field[0]->value[4] = 0x00;
81 dbg_hid("running with 0x%02x 0x%02x", strong, weak);
82 usbhid_submit_report(hid, drff->report, USB_DIR_OUT);
87 static int drff_init(struct hid_device *hid)
89 struct drff_device *drff;
90 struct hid_report *report;
91 struct hid_input *hidinput = list_first_entry(&hid->inputs,
92 struct hid_input, list);
93 struct list_head *report_list =
94 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
95 struct input_dev *dev = hidinput->input;
98 if (list_empty(report_list)) {
99 hid_err(hid, "no output reports found\n");
103 report = list_first_entry(report_list, struct hid_report, list);
104 if (report->maxfield < 1) {
105 hid_err(hid, "no fields in the report\n");
109 if (report->field[0]->report_count < 7) {
110 hid_err(hid, "not enough values in the field\n");
114 drff = kzalloc(sizeof(struct drff_device), GFP_KERNEL);
118 set_bit(FF_RUMBLE, dev->ffbit);
120 error = input_ff_create_memless(dev, drff, drff_play);
126 drff->report = report;
127 drff->report->field[0]->value[0] = 0xf3;
128 drff->report->field[0]->value[1] = 0x00;
129 drff->report->field[0]->value[2] = 0x00;
130 drff->report->field[0]->value[3] = 0x00;
131 drff->report->field[0]->value[4] = 0x00;
132 drff->report->field[0]->value[5] = 0x00;
133 drff->report->field[0]->value[6] = 0x00;
134 usbhid_submit_report(hid, drff->report, USB_DIR_OUT);
136 hid_info(hid, "Force Feedback for DragonRise Inc. "
137 "game controllers by Richard Walmsley <richwalm@gmail.com>\n");
142 static inline int drff_init(struct hid_device *hid)
149 * The original descriptor of joystick with PID 0x0011, represented by DVTech PC
150 * JS19. It seems both copied from another device and a result of confusion
151 * either about the specification or about the program used to create the
152 * descriptor. In any case, it's a wonder it works on Windows.
154 * Usage Page (Desktop), ; Generic desktop controls (01h)
155 * Usage (Joystik), ; Joystik (04h, application collection)
156 * Collection (Application),
157 * Collection (Logical),
160 * Logical Minimum (0),
161 * Logical Maximum (255),
162 * Physical Minimum (0),
163 * Physical Maximum (255),
164 * Usage (X), ; X (30h, dynamic value)
165 * Usage (X), ; X (30h, dynamic value)
166 * Usage (X), ; X (30h, dynamic value)
167 * Usage (X), ; X (30h, dynamic value)
168 * Usage (Y), ; Y (31h, dynamic value)
172 * Logical Maximum (7),
173 * Physical Maximum (315),
176 * Input (Variable, Null State),
180 * Logical Maximum (1),
181 * Physical Maximum (1),
182 * Usage Page (Button), ; Button (09h)
183 * Usage Minimum (01h),
184 * Usage Maximum (0Ah),
186 * Usage Page (FF00h), ; FF00h, vendor-defined
189 * Logical Maximum (1),
190 * Physical Maximum (1),
194 * Collection (Logical),
197 * Physical Maximum (255),
198 * Logical Maximum (255),
205 /* Size of the original descriptor of the PID 0x0011 joystick */
206 #define PID0011_RDESC_ORIG_SIZE 101
208 /* Fixed report descriptor for PID 0x011 joystick */
209 static __u8 pid0011_rdesc_fixed[] = {
210 0x05, 0x01, /* Usage Page (Desktop), */
211 0x09, 0x04, /* Usage (Joystik), */
212 0xA1, 0x01, /* Collection (Application), */
213 0xA1, 0x02, /* Collection (Logical), */
214 0x14, /* Logical Minimum (0), */
215 0x75, 0x08, /* Report Size (8), */
216 0x95, 0x03, /* Report Count (3), */
217 0x81, 0x01, /* Input (Constant), */
218 0x26, 0xFF, 0x00, /* Logical Maximum (255), */
219 0x95, 0x02, /* Report Count (2), */
220 0x09, 0x30, /* Usage (X), */
221 0x09, 0x31, /* Usage (Y), */
222 0x81, 0x02, /* Input (Variable), */
223 0x75, 0x01, /* Report Size (1), */
224 0x95, 0x04, /* Report Count (4), */
225 0x81, 0x01, /* Input (Constant), */
226 0x25, 0x01, /* Logical Maximum (1), */
227 0x95, 0x0A, /* Report Count (10), */
228 0x05, 0x09, /* Usage Page (Button), */
229 0x19, 0x01, /* Usage Minimum (01h), */
230 0x29, 0x0A, /* Usage Maximum (0Ah), */
231 0x81, 0x02, /* Input (Variable), */
232 0x95, 0x0A, /* Report Count (10), */
233 0x81, 0x01, /* Input (Constant), */
234 0xC0, /* End Collection, */
235 0xC0 /* End Collection */
238 static __u8 *dr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
241 switch (hdev->product) {
243 if (*rsize == PID0011_RDESC_ORIG_SIZE) {
244 rdesc = pid0011_rdesc_fixed;
245 *rsize = sizeof(pid0011_rdesc_fixed);
252 static int dr_probe(struct hid_device *hdev, const struct hid_device_id *id)
256 dev_dbg(&hdev->dev, "DragonRise Inc. HID hardware probe...");
258 ret = hid_parse(hdev);
260 hid_err(hdev, "parse failed\n");
264 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
266 hid_err(hdev, "hw start failed\n");
270 switch (hdev->product) {
272 ret = drff_init(hdev);
274 dev_err(&hdev->dev, "force feedback init failed\n");
286 static const struct hid_device_id dr_devices[] = {
287 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006), },
288 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0011), },
291 MODULE_DEVICE_TABLE(hid, dr_devices);
293 static struct hid_driver dr_driver = {
294 .name = "dragonrise",
295 .id_table = dr_devices,
296 .report_fixup = dr_report_fixup,
300 static int __init dr_init(void)
302 return hid_register_driver(&dr_driver);
305 static void __exit dr_exit(void)
307 hid_unregister_driver(&dr_driver);
310 module_init(dr_init);
311 module_exit(dr_exit);
312 MODULE_LICENSE("GPL");