2 * Force feedback support for PantherLord/GreenAsia based devices
4 * The devices are distributed under various names and the same USB device ID
5 * can be used in both adapters and actual game controllers.
7 * 0810:0001 "Twin USB Joystick"
8 * - tested with PantherLord USB/PS2 2in1 Adapter
9 * - contains two reports, one for each port (HID_QUIRK_MULTI_INPUT)
11 * 0e8f:0003 "GreenAsia Inc. USB Joystick "
12 * - tested with Köng Gaming gamepad
14 * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #define debug(format, arg...) pr_debug("hid-plff: " format "\n" , ## arg)
38 #include <linux/input.h>
39 #include <linux/usb.h>
40 #include <linux/hid.h>
44 struct hid_report *report;
47 static int hid_plff_play(struct input_dev *dev, void *data,
48 struct ff_effect *effect)
50 struct hid_device *hid = input_get_drvdata(dev);
51 struct plff_device *plff = data;
54 left = effect->u.rumble.strong_magnitude;
55 right = effect->u.rumble.weak_magnitude;
56 debug("called with 0x%04x 0x%04x", left, right);
58 left = left * 0x7f / 0xffff;
59 right = right * 0x7f / 0xffff;
61 plff->report->field[0]->value[2] = left;
62 plff->report->field[0]->value[3] = right;
63 debug("running with 0x%02x 0x%02x", left, right);
64 usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
69 int hid_plff_init(struct hid_device *hid)
71 struct plff_device *plff;
72 struct hid_report *report;
73 struct hid_input *hidinput;
74 struct list_head *report_list =
75 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
76 struct list_head *report_ptr = report_list;
77 struct input_dev *dev;
80 /* The device contains one output report per physical device, all
81 containing 1 field, which contains 4 ff00.0002 usages and 4 16bit
84 The input reports also contain a field which contains
85 8 ff00.0001 usages and 8 boolean values. Their meaning is
88 if (list_empty(report_list)) {
89 printk(KERN_ERR "hid-plff: no output reports found\n");
93 list_for_each_entry(hidinput, &hid->inputs, list) {
95 report_ptr = report_ptr->next;
97 if (report_ptr == report_list) {
98 printk(KERN_ERR "hid-plff: required output report is missing\n");
102 report = list_entry(report_ptr, struct hid_report, list);
103 if (report->maxfield < 1) {
104 printk(KERN_ERR "hid-plff: no fields in the report\n");
108 if (report->field[0]->report_count < 4) {
109 printk(KERN_ERR "hid-plff: not enough values in the field\n");
113 plff = kzalloc(sizeof(struct plff_device), GFP_KERNEL);
117 dev = hidinput->input;
119 set_bit(FF_RUMBLE, dev->ffbit);
121 error = input_ff_create_memless(dev, plff, hid_plff_play);
127 plff->report = report;
128 plff->report->field[0]->value[0] = 0x00;
129 plff->report->field[0]->value[1] = 0x00;
130 plff->report->field[0]->value[2] = 0x00;
131 plff->report->field[0]->value[3] = 0x00;
132 usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
135 printk(KERN_INFO "hid-plff: Force feedback for PantherLord/GreenAsia "
136 "devices by Anssi Hannula <anssi.hannula@gmail.com>\n");