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/usb.h>
32 #include <linux/hid.h>
35 #include "usbhid/usbhid.h"
38 struct hid_report *report;
41 static int drff_play(struct input_dev *dev, void *data,
42 struct ff_effect *effect)
44 struct hid_device *hid = input_get_drvdata(dev);
45 struct drff_device *drff = data;
48 strong = effect->u.rumble.strong_magnitude;
49 weak = effect->u.rumble.weak_magnitude;
51 dbg_hid("called with 0x%04x 0x%04x", strong, weak);
54 strong = strong * 0xff / 0xffff;
55 weak = weak * 0xff / 0xffff;
57 /* While reverse engineering this device, I found that when
58 this value is set, it causes the strong rumble to function
59 at a near maximum speed, so we'll bypass it. */
63 drff->report->field[0]->value[0] = 0x51;
64 drff->report->field[0]->value[1] = 0x00;
65 drff->report->field[0]->value[2] = weak;
66 drff->report->field[0]->value[4] = strong;
67 usbhid_submit_report(hid, drff->report, USB_DIR_OUT);
69 drff->report->field[0]->value[0] = 0xfa;
70 drff->report->field[0]->value[1] = 0xfe;
72 drff->report->field[0]->value[0] = 0xf3;
73 drff->report->field[0]->value[1] = 0x00;
76 drff->report->field[0]->value[2] = 0x00;
77 drff->report->field[0]->value[4] = 0x00;
78 dbg_hid("running with 0x%02x 0x%02x", strong, weak);
79 usbhid_submit_report(hid, drff->report, USB_DIR_OUT);
84 static int drff_init(struct hid_device *hid)
86 struct drff_device *drff;
87 struct hid_report *report;
88 struct hid_input *hidinput = list_first_entry(&hid->inputs,
89 struct hid_input, list);
90 struct list_head *report_list =
91 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
92 struct input_dev *dev = hidinput->input;
95 if (list_empty(report_list)) {
96 dev_err(&hid->dev, "no output reports found\n");
100 report = list_first_entry(report_list, struct hid_report, list);
101 if (report->maxfield < 1) {
102 dev_err(&hid->dev, "no fields in the report\n");
106 if (report->field[0]->report_count < 7) {
107 dev_err(&hid->dev, "not enough values in the field\n");
111 drff = kzalloc(sizeof(struct drff_device), GFP_KERNEL);
115 set_bit(FF_RUMBLE, dev->ffbit);
117 error = input_ff_create_memless(dev, drff, drff_play);
123 drff->report = report;
124 drff->report->field[0]->value[0] = 0xf3;
125 drff->report->field[0]->value[1] = 0x00;
126 drff->report->field[0]->value[2] = 0x00;
127 drff->report->field[0]->value[3] = 0x00;
128 drff->report->field[0]->value[4] = 0x00;
129 drff->report->field[0]->value[5] = 0x00;
130 drff->report->field[0]->value[6] = 0x00;
131 usbhid_submit_report(hid, drff->report, USB_DIR_OUT);
133 dev_info(&hid->dev, "Force Feedback for DragonRise Inc. game "
134 "controllers by Richard Walmsley <richwalm@gmail.com>\n");
139 static int dr_probe(struct hid_device *hdev, const struct hid_device_id *id)
143 dev_dbg(&hdev->dev, "DragonRise Inc. HID hardware probe...");
145 ret = hid_parse(hdev);
147 dev_err(&hdev->dev, "parse failed\n");
151 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
153 dev_err(&hdev->dev, "hw start failed\n");
164 static const struct hid_device_id dr_devices[] = {
165 { HID_USB_DEVICE(USB_VENDOR_ID_DRAGONRISE, 0x0006), },
168 MODULE_DEVICE_TABLE(hid, dr_devices);
170 static struct hid_driver dr_driver = {
171 .name = "dragonrise",
172 .id_table = dr_devices,
176 static int __init dr_init(void)
178 return hid_register_driver(&dr_driver);
181 static void __exit dr_exit(void)
183 hid_unregister_driver(&dr_driver);
186 module_init(dr_init);
187 module_exit(dr_exit);
188 MODULE_LICENSE("GPL");