Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Force feedback support for GreenAsia (Product ID 0x12) based devices |
| 3 | * |
| 4 | * The devices are distributed under various names and the same USB device ID |
| 5 | * can be used in many game controllers. |
| 6 | * |
| 7 | * |
| 8 | * 0e8f:0012 "GreenAsia Inc. USB Joystick " |
| 9 | * - tested with MANTA Warior MM816 and SpeedLink Strike2 SL-6635. |
| 10 | * |
| 11 | * Copyright (c) 2008 Lukasz Lubojanski <lukasz@lubojanski.info> |
| 12 | */ |
| 13 | |
| 14 | /* |
| 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. |
| 19 | * |
| 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. |
| 24 | * |
| 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 |
| 28 | */ |
| 29 | |
| 30 | #include <linux/input.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 32 | #include <linux/hid.h> |
Paul Gortmaker | 8f86a2c | 2011-07-03 13:39:48 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 34 | #include "hid-ids.h" |
Jiri Kosina | 0f6f431 | 2009-05-15 15:46:44 +0200 | [diff] [blame] | 35 | |
| 36 | #ifdef CONFIG_GREENASIA_FF |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 37 | |
| 38 | struct gaff_device { |
| 39 | struct hid_report *report; |
| 40 | }; |
| 41 | |
| 42 | static int hid_gaff_play(struct input_dev *dev, void *data, |
| 43 | struct ff_effect *effect) |
| 44 | { |
| 45 | struct hid_device *hid = input_get_drvdata(dev); |
| 46 | struct gaff_device *gaff = data; |
| 47 | int left, right; |
| 48 | |
| 49 | left = effect->u.rumble.strong_magnitude; |
| 50 | right = effect->u.rumble.weak_magnitude; |
| 51 | |
| 52 | dbg_hid("called with 0x%04x 0x%04x", left, right); |
| 53 | |
| 54 | left = left * 0xfe / 0xffff; |
| 55 | right = right * 0xfe / 0xffff; |
| 56 | |
| 57 | gaff->report->field[0]->value[0] = 0x51; |
| 58 | gaff->report->field[0]->value[1] = 0x0; |
| 59 | gaff->report->field[0]->value[2] = right; |
| 60 | gaff->report->field[0]->value[3] = 0; |
| 61 | gaff->report->field[0]->value[4] = left; |
| 62 | gaff->report->field[0]->value[5] = 0; |
| 63 | dbg_hid("running with 0x%02x 0x%02x", left, right); |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 64 | hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 65 | |
| 66 | gaff->report->field[0]->value[0] = 0xfa; |
| 67 | gaff->report->field[0]->value[1] = 0xfe; |
| 68 | gaff->report->field[0]->value[2] = 0x0; |
| 69 | gaff->report->field[0]->value[4] = 0x0; |
| 70 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 71 | hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static int gaff_init(struct hid_device *hid) |
| 77 | { |
| 78 | struct gaff_device *gaff; |
| 79 | struct hid_report *report; |
Alan Stern | 7b5e3ad | 2019-10-03 14:53:59 -0400 | [diff] [blame] | 80 | struct hid_input *hidinput; |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 81 | struct list_head *report_list = |
| 82 | &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 83 | struct list_head *report_ptr = report_list; |
Alan Stern | 7b5e3ad | 2019-10-03 14:53:59 -0400 | [diff] [blame] | 84 | struct input_dev *dev; |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 85 | int error; |
| 86 | |
Alan Stern | 7b5e3ad | 2019-10-03 14:53:59 -0400 | [diff] [blame] | 87 | if (list_empty(&hid->inputs)) { |
| 88 | hid_err(hid, "no inputs found\n"); |
| 89 | return -ENODEV; |
| 90 | } |
| 91 | hidinput = list_entry(hid->inputs.next, struct hid_input, list); |
| 92 | dev = hidinput->input; |
| 93 | |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 94 | if (list_empty(report_list)) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 95 | hid_err(hid, "no output reports found\n"); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 96 | return -ENODEV; |
| 97 | } |
| 98 | |
| 99 | report_ptr = report_ptr->next; |
| 100 | |
| 101 | report = list_entry(report_ptr, struct hid_report, list); |
| 102 | if (report->maxfield < 1) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 103 | hid_err(hid, "no fields in the report\n"); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 104 | return -ENODEV; |
| 105 | } |
| 106 | |
| 107 | if (report->field[0]->report_count < 6) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 108 | hid_err(hid, "not enough values in the field\n"); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 109 | return -ENODEV; |
| 110 | } |
| 111 | |
| 112 | gaff = kzalloc(sizeof(struct gaff_device), GFP_KERNEL); |
| 113 | if (!gaff) |
| 114 | return -ENOMEM; |
| 115 | |
| 116 | set_bit(FF_RUMBLE, dev->ffbit); |
| 117 | |
| 118 | error = input_ff_create_memless(dev, gaff, hid_gaff_play); |
| 119 | if (error) { |
| 120 | kfree(gaff); |
| 121 | return error; |
| 122 | } |
| 123 | |
| 124 | gaff->report = report; |
| 125 | gaff->report->field[0]->value[0] = 0x51; |
| 126 | gaff->report->field[0]->value[1] = 0x00; |
| 127 | gaff->report->field[0]->value[2] = 0x00; |
| 128 | gaff->report->field[0]->value[3] = 0x00; |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 129 | hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 130 | |
| 131 | gaff->report->field[0]->value[0] = 0xfa; |
| 132 | gaff->report->field[0]->value[1] = 0xfe; |
| 133 | |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 134 | hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 135 | |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 136 | hid_info(hid, "Force Feedback for GreenAsia 0x12 devices by Lukasz Lubojanski <lukasz@lubojanski.info>\n"); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 137 | |
| 138 | return 0; |
| 139 | } |
Jiri Kosina | 0f6f431 | 2009-05-15 15:46:44 +0200 | [diff] [blame] | 140 | #else |
| 141 | static inline int gaff_init(struct hid_device *hdev) |
| 142 | { |
| 143 | return 0; |
| 144 | } |
| 145 | #endif |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 146 | |
| 147 | static int ga_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 148 | { |
| 149 | int ret; |
| 150 | |
| 151 | dev_dbg(&hdev->dev, "Greenasia HID hardware probe..."); |
| 152 | |
| 153 | ret = hid_parse(hdev); |
| 154 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 155 | hid_err(hdev, "parse failed\n"); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 156 | goto err; |
| 157 | } |
| 158 | |
| 159 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); |
| 160 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 161 | hid_err(hdev, "hw start failed\n"); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 162 | goto err; |
| 163 | } |
| 164 | |
| 165 | gaff_init(hdev); |
| 166 | |
| 167 | return 0; |
| 168 | err: |
| 169 | return ret; |
| 170 | } |
| 171 | |
| 172 | static const struct hid_device_id ga_devices[] = { |
| 173 | { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012), }, |
| 174 | { } |
| 175 | }; |
| 176 | MODULE_DEVICE_TABLE(hid, ga_devices); |
| 177 | |
| 178 | static struct hid_driver ga_driver = { |
| 179 | .name = "greenasia", |
| 180 | .id_table = ga_devices, |
| 181 | .probe = ga_probe, |
| 182 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 183 | module_hid_driver(ga_driver); |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 184 | |
Lukasz Lubojanski | 42859e0 | 2008-12-11 22:07:59 +0100 | [diff] [blame] | 185 | MODULE_LICENSE("GPL"); |