diff options
author | Jiri Slaby <jirislaby@gmail.com> | 2008-09-18 13:43:32 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2008-10-14 17:51:00 -0400 |
commit | 5f022298aab58ddff9bccdb28b82a59109789da9 (patch) | |
tree | 08d87903b7a15c465a0b21cb7bdb7a30e9226cf3 /drivers/hid/hid-pl.c | |
parent | 2b107d629dc0c35de606bb7b010b829cd247a93a (diff) |
HID: move pantherlord FF processing
Move the force feedback processing into a separate module.
[jkosina@suse.cz: fix Kconfig texts a little bit]
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-pl.c')
-rw-r--r-- | drivers/hid/hid-pl.c | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c new file mode 100644 index 000000000000..a1d1fb9da125 --- /dev/null +++ b/drivers/hid/hid-pl.c | |||
@@ -0,0 +1,205 @@ | |||
1 | /* | ||
2 | * Force feedback support for PantherLord/GreenAsia based devices | ||
3 | * | ||
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. | ||
6 | * | ||
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) | ||
10 | * | ||
11 | * 0e8f:0003 "GreenAsia Inc. USB Joystick " | ||
12 | * - tested with K??ng Gaming gamepad | ||
13 | * | ||
14 | * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com> | ||
15 | */ | ||
16 | |||
17 | /* | ||
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. | ||
22 | * | ||
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. | ||
27 | * | ||
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 | ||
31 | */ | ||
32 | |||
33 | |||
34 | /* #define DEBUG */ | ||
35 | |||
36 | #define debug(format, arg...) pr_debug("hid-plff: " format "\n" , ## arg) | ||
37 | |||
38 | #include <linux/input.h> | ||
39 | #include <linux/usb.h> | ||
40 | #include <linux/hid.h> | ||
41 | |||
42 | #include "hid-ids.h" | ||
43 | |||
44 | #ifdef CONFIG_PANTHERLORD_FF | ||
45 | #include "usbhid/usbhid.h" | ||
46 | |||
47 | struct plff_device { | ||
48 | struct hid_report *report; | ||
49 | }; | ||
50 | |||
51 | static int hid_plff_play(struct input_dev *dev, void *data, | ||
52 | struct ff_effect *effect) | ||
53 | { | ||
54 | struct hid_device *hid = input_get_drvdata(dev); | ||
55 | struct plff_device *plff = data; | ||
56 | int left, right; | ||
57 | |||
58 | left = effect->u.rumble.strong_magnitude; | ||
59 | right = effect->u.rumble.weak_magnitude; | ||
60 | debug("called with 0x%04x 0x%04x", left, right); | ||
61 | |||
62 | left = left * 0x7f / 0xffff; | ||
63 | right = right * 0x7f / 0xffff; | ||
64 | |||
65 | plff->report->field[0]->value[2] = left; | ||
66 | plff->report->field[0]->value[3] = right; | ||
67 | debug("running with 0x%02x 0x%02x", left, right); | ||
68 | usbhid_submit_report(hid, plff->report, USB_DIR_OUT); | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | static int plff_init(struct hid_device *hid) | ||
74 | { | ||
75 | struct plff_device *plff; | ||
76 | struct hid_report *report; | ||
77 | struct hid_input *hidinput; | ||
78 | struct list_head *report_list = | ||
79 | &hid->report_enum[HID_OUTPUT_REPORT].report_list; | ||
80 | struct list_head *report_ptr = report_list; | ||
81 | struct input_dev *dev; | ||
82 | int error; | ||
83 | |||
84 | /* The device contains one output report per physical device, all | ||
85 | containing 1 field, which contains 4 ff00.0002 usages and 4 16bit | ||
86 | absolute values. | ||
87 | |||
88 | The input reports also contain a field which contains | ||
89 | 8 ff00.0001 usages and 8 boolean values. Their meaning is | ||
90 | currently unknown. */ | ||
91 | |||
92 | if (list_empty(report_list)) { | ||
93 | printk(KERN_ERR "hid-plff: no output reports found\n"); | ||
94 | return -ENODEV; | ||
95 | } | ||
96 | |||
97 | list_for_each_entry(hidinput, &hid->inputs, list) { | ||
98 | |||
99 | report_ptr = report_ptr->next; | ||
100 | |||
101 | if (report_ptr == report_list) { | ||
102 | printk(KERN_ERR "hid-plff: required output report is missing\n"); | ||
103 | return -ENODEV; | ||
104 | } | ||
105 | |||
106 | report = list_entry(report_ptr, struct hid_report, list); | ||
107 | if (report->maxfield < 1) { | ||
108 | printk(KERN_ERR "hid-plff: no fields in the report\n"); | ||
109 | return -ENODEV; | ||
110 | } | ||
111 | |||
112 | if (report->field[0]->report_count < 4) { | ||
113 | printk(KERN_ERR "hid-plff: not enough values in the field\n"); | ||
114 | return -ENODEV; | ||
115 | } | ||
116 | |||
117 | plff = kzalloc(sizeof(struct plff_device), GFP_KERNEL); | ||
118 | if (!plff) | ||
119 | return -ENOMEM; | ||
120 | |||
121 | dev = hidinput->input; | ||
122 | |||
123 | set_bit(FF_RUMBLE, dev->ffbit); | ||
124 | |||
125 | error = input_ff_create_memless(dev, plff, hid_plff_play); | ||
126 | if (error) { | ||
127 | kfree(plff); | ||
128 | return error; | ||
129 | } | ||
130 | |||
131 | plff->report = report; | ||
132 | plff->report->field[0]->value[0] = 0x00; | ||
133 | plff->report->field[0]->value[1] = 0x00; | ||
134 | plff->report->field[0]->value[2] = 0x00; | ||
135 | plff->report->field[0]->value[3] = 0x00; | ||
136 | usbhid_submit_report(hid, plff->report, USB_DIR_OUT); | ||
137 | } | ||
138 | |||
139 | printk(KERN_INFO "hid-plff: Force feedback for PantherLord/GreenAsia " | ||
140 | "devices by Anssi Hannula <anssi.hannula@gmail.com>\n"); | ||
141 | |||
142 | return 0; | ||
143 | } | ||
144 | #else | ||
145 | static inline int plff_init(struct hid_device *hid) | ||
146 | { | ||
147 | return 0; | ||
148 | } | ||
149 | #endif | ||
150 | |||
151 | static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
152 | { | ||
153 | int ret; | ||
154 | |||
155 | if (id->driver_data) | ||
156 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; | ||
157 | |||
158 | ret = hid_parse(hdev); | ||
159 | if (ret) { | ||
160 | dev_err(&hdev->dev, "parse failed\n"); | ||
161 | goto err; | ||
162 | } | ||
163 | |||
164 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); | ||
165 | if (ret) { | ||
166 | dev_err(&hdev->dev, "hw start failed\n"); | ||
167 | goto err; | ||
168 | } | ||
169 | |||
170 | plff_init(hdev); | ||
171 | |||
172 | return 0; | ||
173 | err: | ||
174 | return ret; | ||
175 | } | ||
176 | |||
177 | static const struct hid_device_id pl_devices[] = { | ||
178 | { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR), | ||
179 | .driver_data = 1 }, /* Twin USB Joystick */ | ||
180 | { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), }, /* GreenAsia Inc. USB Joystick */ | ||
181 | { } | ||
182 | }; | ||
183 | MODULE_DEVICE_TABLE(hid, pl_devices); | ||
184 | |||
185 | static struct hid_driver pl_driver = { | ||
186 | .name = "pantherlord", | ||
187 | .id_table = pl_devices, | ||
188 | .probe = pl_probe, | ||
189 | }; | ||
190 | |||
191 | static int pl_init(void) | ||
192 | { | ||
193 | return hid_register_driver(&pl_driver); | ||
194 | } | ||
195 | |||
196 | static void pl_exit(void) | ||
197 | { | ||
198 | hid_unregister_driver(&pl_driver); | ||
199 | } | ||
200 | |||
201 | module_init(pl_init); | ||
202 | module_exit(pl_exit); | ||
203 | MODULE_LICENSE("GPL"); | ||
204 | |||
205 | HID_COMPAT_LOAD_DRIVER(pantherlord); | ||