Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 1 | /* |
Anssi Hannula | 5edc41ee | 2007-09-19 16:13:20 +0200 | [diff] [blame] | 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 " |
Al Viro | d36b691 | 2011-12-29 17:09:01 -0500 | [diff] [blame] | 12 | * - tested with König Gaming gamepad |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 13 | * |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 14 | * 0e8f:0003 "GASIA USB Gamepad" |
Al Viro | d36b691 | 2011-12-29 17:09:01 -0500 | [diff] [blame] | 15 | * - another version of the König gamepad |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 16 | * |
Michael Karcher | aaca9cc | 2013-01-17 11:06:09 +0100 | [diff] [blame] | 17 | * 0f30:0111 "Saitek Color Rumble Pad" |
| 18 | * |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 19 | * Copyright (c) 2007, 2009 Anssi Hannula <anssi.hannula@gmail.com> |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 20 | */ |
| 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 Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 44 | #include <linux/slab.h> |
Paul Gortmaker | 8f86a2c | 2011-07-03 13:39:48 -0400 | [diff] [blame] | 45 | #include <linux/module.h> |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 46 | #include <linux/usb.h> |
| 47 | #include <linux/hid.h> |
Jiri Slaby | 5f02229 | 2008-09-18 19:43:32 +0200 | [diff] [blame] | 48 | |
| 49 | #include "hid-ids.h" |
| 50 | |
| 51 | #ifdef CONFIG_PANTHERLORD_FF |
| 52 | #include "usbhid/usbhid.h" |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 53 | |
| 54 | struct plff_device { |
| 55 | struct hid_report *report; |
Michael Karcher | aaca9cc | 2013-01-17 11:06:09 +0100 | [diff] [blame] | 56 | s32 maxval; |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 57 | s32 *strong; |
| 58 | s32 *weak; |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | static int hid_plff_play(struct input_dev *dev, void *data, |
| 62 | struct ff_effect *effect) |
| 63 | { |
Dmitry Torokhov | e071298 | 2007-05-09 10:17:31 +0200 | [diff] [blame] | 64 | struct hid_device *hid = input_get_drvdata(dev); |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 65 | struct plff_device *plff = data; |
| 66 | int left, right; |
| 67 | |
| 68 | left = effect->u.rumble.strong_magnitude; |
| 69 | right = effect->u.rumble.weak_magnitude; |
| 70 | debug("called with 0x%04x 0x%04x", left, right); |
| 71 | |
Michael Karcher | aaca9cc | 2013-01-17 11:06:09 +0100 | [diff] [blame] | 72 | left = left * plff->maxval / 0xffff; |
| 73 | right = right * plff->maxval / 0xffff; |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 74 | |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 75 | *plff->strong = left; |
| 76 | *plff->weak = right; |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 77 | debug("running with 0x%02x 0x%02x", left, right); |
| 78 | usbhid_submit_report(hid, plff->report, USB_DIR_OUT); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Jiri Slaby | 5f02229 | 2008-09-18 19:43:32 +0200 | [diff] [blame] | 83 | static int plff_init(struct hid_device *hid) |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 84 | { |
| 85 | struct plff_device *plff; |
| 86 | struct hid_report *report; |
| 87 | struct hid_input *hidinput; |
| 88 | struct list_head *report_list = |
| 89 | &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 90 | struct list_head *report_ptr = report_list; |
| 91 | struct input_dev *dev; |
| 92 | int error; |
Michael Karcher | aaca9cc | 2013-01-17 11:06:09 +0100 | [diff] [blame] | 93 | s32 maxval; |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 94 | s32 *strong; |
| 95 | s32 *weak; |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 96 | |
Anssi Hannula | 5edc41ee | 2007-09-19 16:13:20 +0200 | [diff] [blame] | 97 | /* The device contains one output report per physical device, all |
| 98 | containing 1 field, which contains 4 ff00.0002 usages and 4 16bit |
| 99 | absolute values. |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 100 | |
Anssi Hannula | 5edc41ee | 2007-09-19 16:13:20 +0200 | [diff] [blame] | 101 | The input reports also contain a field which contains |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 102 | 8 ff00.0001 usages and 8 boolean values. Their meaning is |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 103 | currently unknown. |
| 104 | |
| 105 | A version of the 0e8f:0003 exists that has all the values in |
| 106 | separate fields and misses the extra input field, thus resembling |
| 107 | Zeroplus (hid-zpff) devices. |
| 108 | */ |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 109 | |
| 110 | if (list_empty(report_list)) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 111 | hid_err(hid, "no output reports found\n"); |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 112 | return -ENODEV; |
| 113 | } |
| 114 | |
| 115 | list_for_each_entry(hidinput, &hid->inputs, list) { |
| 116 | |
| 117 | report_ptr = report_ptr->next; |
| 118 | |
| 119 | if (report_ptr == report_list) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 120 | hid_err(hid, "required output report is missing\n"); |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 121 | return -ENODEV; |
| 122 | } |
| 123 | |
| 124 | report = list_entry(report_ptr, struct hid_report, list); |
| 125 | if (report->maxfield < 1) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 126 | hid_err(hid, "no fields in the report\n"); |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 127 | return -ENODEV; |
| 128 | } |
| 129 | |
Michael Karcher | aaca9cc | 2013-01-17 11:06:09 +0100 | [diff] [blame] | 130 | maxval = 0x7f; |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 131 | if (report->field[0]->report_count >= 4) { |
| 132 | report->field[0]->value[0] = 0x00; |
| 133 | report->field[0]->value[1] = 0x00; |
| 134 | strong = &report->field[0]->value[2]; |
| 135 | weak = &report->field[0]->value[3]; |
| 136 | debug("detected single-field device"); |
| 137 | } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 && |
| 138 | report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) { |
| 139 | report->field[0]->value[0] = 0x00; |
| 140 | report->field[1]->value[0] = 0x00; |
| 141 | strong = &report->field[2]->value[0]; |
| 142 | weak = &report->field[3]->value[0]; |
Michael Karcher | aaca9cc | 2013-01-17 11:06:09 +0100 | [diff] [blame] | 143 | if (hid->vendor == USB_VENDOR_ID_JESS2) |
| 144 | maxval = 0xff; |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 145 | debug("detected 4-field device"); |
| 146 | } else { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 147 | hid_err(hid, "not enough fields or values\n"); |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 148 | return -ENODEV; |
| 149 | } |
| 150 | |
| 151 | plff = kzalloc(sizeof(struct plff_device), GFP_KERNEL); |
| 152 | if (!plff) |
| 153 | return -ENOMEM; |
| 154 | |
| 155 | dev = hidinput->input; |
| 156 | |
| 157 | set_bit(FF_RUMBLE, dev->ffbit); |
| 158 | |
| 159 | error = input_ff_create_memless(dev, plff, hid_plff_play); |
| 160 | if (error) { |
| 161 | kfree(plff); |
| 162 | return error; |
| 163 | } |
| 164 | |
| 165 | plff->report = report; |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 166 | plff->strong = strong; |
| 167 | plff->weak = weak; |
Michael Karcher | aaca9cc | 2013-01-17 11:06:09 +0100 | [diff] [blame] | 168 | plff->maxval = maxval; |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 169 | |
| 170 | *strong = 0x00; |
| 171 | *weak = 0x00; |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 172 | usbhid_submit_report(hid, plff->report, USB_DIR_OUT); |
| 173 | } |
| 174 | |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 175 | hid_info(hid, "Force feedback for PantherLord/GreenAsia devices by Anssi Hannula <anssi.hannula@gmail.com>\n"); |
Anssi Hannula | 20eb127 | 2007-01-11 16:51:18 +0200 | [diff] [blame] | 176 | |
| 177 | return 0; |
| 178 | } |
Jiri Slaby | 5f02229 | 2008-09-18 19:43:32 +0200 | [diff] [blame] | 179 | #else |
| 180 | static inline int plff_init(struct hid_device *hid) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
| 184 | #endif |
| 185 | |
| 186 | static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 187 | { |
| 188 | int ret; |
| 189 | |
| 190 | if (id->driver_data) |
| 191 | hdev->quirks |= HID_QUIRK_MULTI_INPUT; |
| 192 | |
| 193 | ret = hid_parse(hdev); |
| 194 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 195 | hid_err(hdev, "parse failed\n"); |
Jiri Slaby | 5f02229 | 2008-09-18 19:43:32 +0200 | [diff] [blame] | 196 | goto err; |
| 197 | } |
| 198 | |
| 199 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); |
| 200 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 201 | hid_err(hdev, "hw start failed\n"); |
Jiri Slaby | 5f02229 | 2008-09-18 19:43:32 +0200 | [diff] [blame] | 202 | goto err; |
| 203 | } |
| 204 | |
| 205 | plff_init(hdev); |
| 206 | |
| 207 | return 0; |
| 208 | err: |
| 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | static const struct hid_device_id pl_devices[] = { |
| 213 | { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR), |
| 214 | .driver_data = 1 }, /* Twin USB Joystick */ |
Jiri Kosina | 578f3a3 | 2008-11-20 15:55:38 +0100 | [diff] [blame] | 215 | { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR), |
| 216 | .driver_data = 1 }, /* Twin USB Joystick */ |
Anssi Hannula | 27a9c17 | 2009-02-27 23:47:00 +0200 | [diff] [blame] | 217 | { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), }, |
Michael Karcher | aaca9cc | 2013-01-17 11:06:09 +0100 | [diff] [blame] | 218 | { HID_USB_DEVICE(USB_VENDOR_ID_JESS2, USB_DEVICE_ID_JESS2_COLOR_RUMBLE_PAD), }, |
Jiri Slaby | 5f02229 | 2008-09-18 19:43:32 +0200 | [diff] [blame] | 219 | { } |
| 220 | }; |
| 221 | MODULE_DEVICE_TABLE(hid, pl_devices); |
| 222 | |
| 223 | static struct hid_driver pl_driver = { |
| 224 | .name = "pantherlord", |
| 225 | .id_table = pl_devices, |
| 226 | .probe = pl_probe, |
| 227 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 228 | module_hid_driver(pl_driver); |
Jiri Slaby | 5f02229 | 2008-09-18 19:43:32 +0200 | [diff] [blame] | 229 | |
Jiri Slaby | 5f02229 | 2008-09-18 19:43:32 +0200 | [diff] [blame] | 230 | MODULE_LICENSE("GPL"); |