blob: d29112fa5cd51a86b4c29c31398874cc5a726e3d [file] [log] [blame]
Anssi Hannula20eb1272007-01-11 16:51:18 +02001/*
Anssi Hannula5edc41ee2007-09-19 16:13:20 +02002 * 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 "
Al Virod36b6912011-12-29 17:09:01 -050012 * - tested with König Gaming gamepad
Anssi Hannula20eb1272007-01-11 16:51:18 +020013 *
Anssi Hannula27a9c172009-02-27 23:47:00 +020014 * 0e8f:0003 "GASIA USB Gamepad"
Al Virod36b6912011-12-29 17:09:01 -050015 * - another version of the König gamepad
Anssi Hannula27a9c172009-02-27 23:47:00 +020016 *
Michael Karcheraaca9cc2013-01-17 11:06:09 +010017 * 0f30:0111 "Saitek Color Rumble Pad"
18 *
Anssi Hannula27a9c172009-02-27 23:47:00 +020019 * Copyright (c) 2007, 2009 Anssi Hannula <anssi.hannula@gmail.com>
Anssi Hannula20eb1272007-01-11 16:51:18 +020020 */
21
22/*
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or
26 * (at your option) any later version.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 */
37
38
39/* #define DEBUG */
40
41#define debug(format, arg...) pr_debug("hid-plff: " format "\n" , ## arg)
42
43#include <linux/input.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090044#include <linux/slab.h>
Paul Gortmaker8f86a2c2011-07-03 13:39:48 -040045#include <linux/module.h>
Anssi Hannula20eb1272007-01-11 16:51:18 +020046#include <linux/hid.h>
Jiri Slaby5f022292008-09-18 19:43:32 +020047
48#include "hid-ids.h"
49
50#ifdef CONFIG_PANTHERLORD_FF
Anssi Hannula20eb1272007-01-11 16:51:18 +020051
52struct plff_device {
53 struct hid_report *report;
Michael Karcheraaca9cc2013-01-17 11:06:09 +010054 s32 maxval;
Anssi Hannula27a9c172009-02-27 23:47:00 +020055 s32 *strong;
56 s32 *weak;
Anssi Hannula20eb1272007-01-11 16:51:18 +020057};
58
59static int hid_plff_play(struct input_dev *dev, void *data,
60 struct ff_effect *effect)
61{
Dmitry Torokhove0712982007-05-09 10:17:31 +020062 struct hid_device *hid = input_get_drvdata(dev);
Anssi Hannula20eb1272007-01-11 16:51:18 +020063 struct plff_device *plff = data;
64 int left, right;
65
66 left = effect->u.rumble.strong_magnitude;
67 right = effect->u.rumble.weak_magnitude;
68 debug("called with 0x%04x 0x%04x", left, right);
69
Michael Karcheraaca9cc2013-01-17 11:06:09 +010070 left = left * plff->maxval / 0xffff;
71 right = right * plff->maxval / 0xffff;
Anssi Hannula20eb1272007-01-11 16:51:18 +020072
Anssi Hannula27a9c172009-02-27 23:47:00 +020073 *plff->strong = left;
74 *plff->weak = right;
Anssi Hannula20eb1272007-01-11 16:51:18 +020075 debug("running with 0x%02x 0x%02x", left, right);
Benjamin Tissoiresd88142722013-02-25 11:31:46 +010076 hid_hw_request(hid, plff->report, HID_REQ_SET_REPORT);
Anssi Hannula20eb1272007-01-11 16:51:18 +020077
78 return 0;
79}
80
Jiri Slaby5f022292008-09-18 19:43:32 +020081static int plff_init(struct hid_device *hid)
Anssi Hannula20eb1272007-01-11 16:51:18 +020082{
83 struct plff_device *plff;
84 struct hid_report *report;
85 struct hid_input *hidinput;
86 struct list_head *report_list =
87 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
88 struct list_head *report_ptr = report_list;
89 struct input_dev *dev;
90 int error;
Michael Karcheraaca9cc2013-01-17 11:06:09 +010091 s32 maxval;
Anssi Hannula27a9c172009-02-27 23:47:00 +020092 s32 *strong;
93 s32 *weak;
Anssi Hannula20eb1272007-01-11 16:51:18 +020094
Anssi Hannula5edc41ee2007-09-19 16:13:20 +020095 /* The device contains one output report per physical device, all
96 containing 1 field, which contains 4 ff00.0002 usages and 4 16bit
97 absolute values.
Anssi Hannula20eb1272007-01-11 16:51:18 +020098
Anssi Hannula5edc41ee2007-09-19 16:13:20 +020099 The input reports also contain a field which contains
Anssi Hannula20eb1272007-01-11 16:51:18 +0200100 8 ff00.0001 usages and 8 boolean values. Their meaning is
Anssi Hannula27a9c172009-02-27 23:47:00 +0200101 currently unknown.
102
103 A version of the 0e8f:0003 exists that has all the values in
104 separate fields and misses the extra input field, thus resembling
105 Zeroplus (hid-zpff) devices.
106 */
Anssi Hannula20eb1272007-01-11 16:51:18 +0200107
108 if (list_empty(report_list)) {
Joe Perches4291ee32010-12-09 19:29:03 -0800109 hid_err(hid, "no output reports found\n");
Anssi Hannula20eb1272007-01-11 16:51:18 +0200110 return -ENODEV;
111 }
112
113 list_for_each_entry(hidinput, &hid->inputs, list) {
114
115 report_ptr = report_ptr->next;
116
117 if (report_ptr == report_list) {
Joe Perches4291ee32010-12-09 19:29:03 -0800118 hid_err(hid, "required output report is missing\n");
Anssi Hannula20eb1272007-01-11 16:51:18 +0200119 return -ENODEV;
120 }
121
122 report = list_entry(report_ptr, struct hid_report, list);
123 if (report->maxfield < 1) {
Joe Perches4291ee32010-12-09 19:29:03 -0800124 hid_err(hid, "no fields in the report\n");
Anssi Hannula20eb1272007-01-11 16:51:18 +0200125 return -ENODEV;
126 }
127
Michael Karcheraaca9cc2013-01-17 11:06:09 +0100128 maxval = 0x7f;
Anssi Hannula27a9c172009-02-27 23:47:00 +0200129 if (report->field[0]->report_count >= 4) {
130 report->field[0]->value[0] = 0x00;
131 report->field[0]->value[1] = 0x00;
132 strong = &report->field[0]->value[2];
133 weak = &report->field[0]->value[3];
134 debug("detected single-field device");
135 } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
136 report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
137 report->field[0]->value[0] = 0x00;
138 report->field[1]->value[0] = 0x00;
139 strong = &report->field[2]->value[0];
140 weak = &report->field[3]->value[0];
Michael Karcheraaca9cc2013-01-17 11:06:09 +0100141 if (hid->vendor == USB_VENDOR_ID_JESS2)
142 maxval = 0xff;
Anssi Hannula27a9c172009-02-27 23:47:00 +0200143 debug("detected 4-field device");
144 } else {
Joe Perches4291ee32010-12-09 19:29:03 -0800145 hid_err(hid, "not enough fields or values\n");
Anssi Hannula20eb1272007-01-11 16:51:18 +0200146 return -ENODEV;
147 }
148
149 plff = kzalloc(sizeof(struct plff_device), GFP_KERNEL);
150 if (!plff)
151 return -ENOMEM;
152
153 dev = hidinput->input;
154
155 set_bit(FF_RUMBLE, dev->ffbit);
156
157 error = input_ff_create_memless(dev, plff, hid_plff_play);
158 if (error) {
159 kfree(plff);
160 return error;
161 }
162
163 plff->report = report;
Anssi Hannula27a9c172009-02-27 23:47:00 +0200164 plff->strong = strong;
165 plff->weak = weak;
Michael Karcheraaca9cc2013-01-17 11:06:09 +0100166 plff->maxval = maxval;
Anssi Hannula27a9c172009-02-27 23:47:00 +0200167
168 *strong = 0x00;
169 *weak = 0x00;
Benjamin Tissoiresd88142722013-02-25 11:31:46 +0100170 hid_hw_request(hid, plff->report, HID_REQ_SET_REPORT);
Anssi Hannula20eb1272007-01-11 16:51:18 +0200171 }
172
Joe Perches4291ee32010-12-09 19:29:03 -0800173 hid_info(hid, "Force feedback for PantherLord/GreenAsia devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
Anssi Hannula20eb1272007-01-11 16:51:18 +0200174
175 return 0;
176}
Jiri Slaby5f022292008-09-18 19:43:32 +0200177#else
178static inline int plff_init(struct hid_device *hid)
179{
180 return 0;
181}
182#endif
183
184static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
185{
186 int ret;
187
188 if (id->driver_data)
189 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
190
191 ret = hid_parse(hdev);
192 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800193 hid_err(hdev, "parse failed\n");
Jiri Slaby5f022292008-09-18 19:43:32 +0200194 goto err;
195 }
196
197 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
198 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800199 hid_err(hdev, "hw start failed\n");
Jiri Slaby5f022292008-09-18 19:43:32 +0200200 goto err;
201 }
202
203 plff_init(hdev);
204
205 return 0;
206err:
207 return ret;
208}
209
210static const struct hid_device_id pl_devices[] = {
211 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR),
212 .driver_data = 1 }, /* Twin USB Joystick */
Jiri Kosina578f3a32008-11-20 15:55:38 +0100213 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR),
214 .driver_data = 1 }, /* Twin USB Joystick */
Anssi Hannula27a9c172009-02-27 23:47:00 +0200215 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), },
Michael Karcheraaca9cc2013-01-17 11:06:09 +0100216 { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD), },
Jiri Slaby5f022292008-09-18 19:43:32 +0200217 { }
218};
219MODULE_DEVICE_TABLE(hid, pl_devices);
220
221static struct hid_driver pl_driver = {
222 .name = "pantherlord",
223 .id_table = pl_devices,
224 .probe = pl_probe,
225};
H Hartley Sweetenf4254582012-12-17 15:28:26 -0700226module_hid_driver(pl_driver);
Jiri Slaby5f022292008-09-18 19:43:32 +0200227
Jiri Slaby5f022292008-09-18 19:43:32 +0200228MODULE_LICENSE("GPL");