Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Force feedback support for ACRUX game controllers |
| 3 | * |
| 4 | * From what I have gathered, these devices are mass produced in China |
| 5 | * by several vendors. They often share the same design as the original |
| 6 | * Xbox 360 controller. |
| 7 | * |
| 8 | * 1a34:0802 "ACRUX USB GAMEPAD 8116" |
Sergei Kolzun | b55ebc2 | 2011-08-04 00:25:57 -0700 | [diff] [blame] | 9 | * - tested with an EXEQ EQ-PCU-02090 game controller. |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 10 | * |
| 11 | * Copyright (c) 2010 Sergei Kolzun <x0r@dv-life.ru> |
| 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> |
| 31 | #include <linux/slab.h> |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 32 | #include <linux/hid.h> |
Paul Gortmaker | 8f86a2c | 2011-07-03 13:39:48 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 34 | |
| 35 | #include "hid-ids.h" |
Dmitry Torokhov | 0ae4381 | 2011-03-11 00:27:34 -0800 | [diff] [blame] | 36 | |
| 37 | #ifdef CONFIG_HID_ACRUX_FF |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 38 | |
| 39 | struct axff_device { |
| 40 | struct hid_report *report; |
| 41 | }; |
| 42 | |
| 43 | static int axff_play(struct input_dev *dev, void *data, struct ff_effect *effect) |
| 44 | { |
| 45 | struct hid_device *hid = input_get_drvdata(dev); |
| 46 | struct axff_device *axff = data; |
Sergei Kolzun | b55ebc2 | 2011-08-04 00:25:57 -0700 | [diff] [blame] | 47 | struct hid_report *report = axff->report; |
| 48 | int field_count = 0; |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 49 | int left, right; |
Sergei Kolzun | b55ebc2 | 2011-08-04 00:25:57 -0700 | [diff] [blame] | 50 | int i, j; |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 51 | |
| 52 | left = effect->u.rumble.strong_magnitude; |
| 53 | right = effect->u.rumble.weak_magnitude; |
| 54 | |
| 55 | dbg_hid("called with 0x%04x 0x%04x", left, right); |
| 56 | |
| 57 | left = left * 0xff / 0xffff; |
| 58 | right = right * 0xff / 0xffff; |
| 59 | |
Sergei Kolzun | b55ebc2 | 2011-08-04 00:25:57 -0700 | [diff] [blame] | 60 | for (i = 0; i < report->maxfield; i++) { |
| 61 | for (j = 0; j < report->field[i]->report_count; j++) { |
| 62 | report->field[i]->value[j] = |
| 63 | field_count % 2 ? right : left; |
| 64 | field_count++; |
| 65 | } |
| 66 | } |
| 67 | |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 68 | dbg_hid("running with 0x%02x 0x%02x", left, right); |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 69 | hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static int axff_init(struct hid_device *hid) |
| 75 | { |
| 76 | struct axff_device *axff; |
| 77 | struct hid_report *report; |
Alan Stern | 7b5e3ad | 2019-10-03 14:53:59 -0400 | [diff] [blame] | 78 | struct hid_input *hidinput; |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 79 | struct list_head *report_list =&hid->report_enum[HID_OUTPUT_REPORT].report_list; |
Alan Stern | 7b5e3ad | 2019-10-03 14:53:59 -0400 | [diff] [blame] | 80 | struct input_dev *dev; |
Sergei Kolzun | b55ebc2 | 2011-08-04 00:25:57 -0700 | [diff] [blame] | 81 | int field_count = 0; |
| 82 | int i, j; |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 83 | int error; |
| 84 | |
Alan Stern | 7b5e3ad | 2019-10-03 14:53:59 -0400 | [diff] [blame] | 85 | if (list_empty(&hid->inputs)) { |
| 86 | hid_err(hid, "no inputs found\n"); |
| 87 | return -ENODEV; |
| 88 | } |
| 89 | hidinput = list_first_entry(&hid->inputs, struct hid_input, list); |
| 90 | dev = hidinput->input; |
| 91 | |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 92 | if (list_empty(report_list)) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 93 | hid_err(hid, "no output reports found\n"); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 94 | return -ENODEV; |
| 95 | } |
| 96 | |
| 97 | report = list_first_entry(report_list, struct hid_report, list); |
Sergei Kolzun | b55ebc2 | 2011-08-04 00:25:57 -0700 | [diff] [blame] | 98 | for (i = 0; i < report->maxfield; i++) { |
| 99 | for (j = 0; j < report->field[i]->report_count; j++) { |
| 100 | report->field[i]->value[j] = 0x00; |
| 101 | field_count++; |
| 102 | } |
| 103 | } |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 104 | |
Tristan Rice | e17f5d76 | 2013-11-12 19:06:23 +0100 | [diff] [blame] | 105 | if (field_count < 4 && hid->product != 0xf705) { |
Sergei Kolzun | b55ebc2 | 2011-08-04 00:25:57 -0700 | [diff] [blame] | 106 | hid_err(hid, "not enough fields in the report: %d\n", |
| 107 | field_count); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 108 | return -ENODEV; |
| 109 | } |
| 110 | |
| 111 | axff = kzalloc(sizeof(struct axff_device), GFP_KERNEL); |
| 112 | if (!axff) |
| 113 | return -ENOMEM; |
| 114 | |
| 115 | set_bit(FF_RUMBLE, dev->ffbit); |
| 116 | |
| 117 | error = input_ff_create_memless(dev, axff, axff_play); |
| 118 | if (error) |
| 119 | goto err_free_mem; |
| 120 | |
| 121 | axff->report = report; |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 122 | hid_hw_request(hid, axff->report, HID_REQ_SET_REPORT); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 123 | |
Sergei Kolzun | b55ebc2 | 2011-08-04 00:25:57 -0700 | [diff] [blame] | 124 | hid_info(hid, "Force Feedback for ACRUX game controllers by Sergei Kolzun <x0r@dv-life.ru>\n"); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 125 | |
| 126 | return 0; |
| 127 | |
| 128 | err_free_mem: |
| 129 | kfree(axff); |
| 130 | return error; |
| 131 | } |
Dmitry Torokhov | 0ae4381 | 2011-03-11 00:27:34 -0800 | [diff] [blame] | 132 | #else |
| 133 | static inline int axff_init(struct hid_device *hid) |
| 134 | { |
| 135 | return 0; |
| 136 | } |
| 137 | #endif |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 138 | |
| 139 | static int ax_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 140 | { |
| 141 | int error; |
| 142 | |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 143 | dev_dbg(&hdev->dev, "ACRUX HID hardware probe...\n"); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 144 | |
| 145 | error = hid_parse(hdev); |
| 146 | if (error) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 147 | hid_err(hdev, "parse failed\n"); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 148 | return error; |
| 149 | } |
| 150 | |
| 151 | error = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); |
| 152 | if (error) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 153 | hid_err(hdev, "hw start failed\n"); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 154 | return error; |
| 155 | } |
| 156 | |
| 157 | error = axff_init(hdev); |
| 158 | if (error) { |
| 159 | /* |
| 160 | * Do not fail device initialization completely as device |
| 161 | * may still be partially operable, just warn. |
| 162 | */ |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 163 | hid_warn(hdev, |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 164 | "Failed to enable force feedback support, error: %d\n", |
| 165 | error); |
| 166 | } |
| 167 | |
Dmitry Torokhov | 0ae4381 | 2011-03-11 00:27:34 -0800 | [diff] [blame] | 168 | /* |
| 169 | * We need to start polling device right away, otherwise |
| 170 | * it will go into a coma. |
| 171 | */ |
| 172 | error = hid_hw_open(hdev); |
| 173 | if (error) { |
| 174 | dev_err(&hdev->dev, "hw open failed\n"); |
Axel Lin | b30d89d | 2011-07-14 13:07:51 +0800 | [diff] [blame] | 175 | hid_hw_stop(hdev); |
Dmitry Torokhov | 0ae4381 | 2011-03-11 00:27:34 -0800 | [diff] [blame] | 176 | return error; |
| 177 | } |
| 178 | |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
Dmitry Torokhov | 0ae4381 | 2011-03-11 00:27:34 -0800 | [diff] [blame] | 182 | static void ax_remove(struct hid_device *hdev) |
| 183 | { |
| 184 | hid_hw_close(hdev); |
| 185 | hid_hw_stop(hdev); |
| 186 | } |
| 187 | |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 188 | static const struct hid_device_id ax_devices[] = { |
| 189 | { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0x0802), }, |
Tristan Rice | e17f5d76 | 2013-11-12 19:06:23 +0100 | [diff] [blame] | 190 | { HID_USB_DEVICE(USB_VENDOR_ID_ACRUX, 0xf705), }, |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 191 | { } |
| 192 | }; |
| 193 | MODULE_DEVICE_TABLE(hid, ax_devices); |
| 194 | |
| 195 | static struct hid_driver ax_driver = { |
Dmitry Torokhov | 0ae4381 | 2011-03-11 00:27:34 -0800 | [diff] [blame] | 196 | .name = "acrux", |
| 197 | .id_table = ax_devices, |
| 198 | .probe = ax_probe, |
| 199 | .remove = ax_remove, |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 200 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 201 | module_hid_driver(ax_driver); |
Sergei Kolzun | c0dbcc3 | 2010-07-19 12:13:23 +0200 | [diff] [blame] | 202 | |
| 203 | MODULE_AUTHOR("Sergei Kolzun"); |
| 204 | MODULE_DESCRIPTION("Force feedback support for ACRUX game controllers"); |
| 205 | MODULE_LICENSE("GPL"); |