Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Force feedback support for SmartJoy PLUS PS2->USB adapter |
| 3 | * |
| 4 | * Copyright (c) 2009 Jussi Kivilinna <jussi.kivilinna@mbnet.fi> |
| 5 | * |
| 6 | * Based of hid-pl.c and hid-gaff.c |
| 7 | * Copyright (c) 2007, 2009 Anssi Hannula <anssi.hannula@gmail.com> |
| 8 | * Copyright (c) 2008 Lukasz Lubojanski <lukasz@lubojanski.info> |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | /* #define DEBUG */ |
| 28 | |
| 29 | #include <linux/input.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 31 | #include <linux/hid.h> |
Paul Gortmaker | 8f86a2c | 2011-07-03 13:39:48 -0400 | [diff] [blame] | 32 | #include <linux/module.h> |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 33 | #include "hid-ids.h" |
| 34 | |
| 35 | #ifdef CONFIG_SMARTJOYPLUS_FF |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 36 | |
| 37 | struct sjoyff_device { |
| 38 | struct hid_report *report; |
| 39 | }; |
| 40 | |
| 41 | static int hid_sjoyff_play(struct input_dev *dev, void *data, |
| 42 | struct ff_effect *effect) |
| 43 | { |
| 44 | struct hid_device *hid = input_get_drvdata(dev); |
| 45 | struct sjoyff_device *sjoyff = data; |
| 46 | u32 left, right; |
| 47 | |
| 48 | left = effect->u.rumble.strong_magnitude; |
| 49 | right = effect->u.rumble.weak_magnitude; |
| 50 | dev_dbg(&dev->dev, "called with 0x%08x 0x%08x\n", left, right); |
| 51 | |
| 52 | left = left * 0xff / 0xffff; |
| 53 | right = (right != 0); /* on/off only */ |
| 54 | |
| 55 | sjoyff->report->field[0]->value[1] = right; |
| 56 | sjoyff->report->field[0]->value[2] = left; |
| 57 | dev_dbg(&dev->dev, "running with 0x%02x 0x%02x\n", left, right); |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 58 | hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT); |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static int sjoyff_init(struct hid_device *hid) |
| 64 | { |
| 65 | struct sjoyff_device *sjoyff; |
| 66 | struct hid_report *report; |
Sean Young | ad395cc | 2011-08-14 20:42:05 +0100 | [diff] [blame] | 67 | struct hid_input *hidinput; |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 68 | struct list_head *report_list = |
| 69 | &hid->report_enum[HID_OUTPUT_REPORT].report_list; |
| 70 | struct list_head *report_ptr = report_list; |
| 71 | struct input_dev *dev; |
| 72 | int error; |
| 73 | |
| 74 | if (list_empty(report_list)) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 75 | hid_err(hid, "no output reports found\n"); |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 76 | return -ENODEV; |
| 77 | } |
| 78 | |
Sean Young | ad395cc | 2011-08-14 20:42:05 +0100 | [diff] [blame] | 79 | list_for_each_entry(hidinput, &hid->inputs, list) { |
| 80 | report_ptr = report_ptr->next; |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 81 | |
Sean Young | ad395cc | 2011-08-14 20:42:05 +0100 | [diff] [blame] | 82 | if (report_ptr == report_list) { |
| 83 | hid_err(hid, "required output report is missing\n"); |
| 84 | return -ENODEV; |
| 85 | } |
| 86 | |
| 87 | report = list_entry(report_ptr, struct hid_report, list); |
| 88 | if (report->maxfield < 1) { |
| 89 | hid_err(hid, "no fields in the report\n"); |
| 90 | return -ENODEV; |
| 91 | } |
| 92 | |
| 93 | if (report->field[0]->report_count < 3) { |
| 94 | hid_err(hid, "not enough values in the field\n"); |
| 95 | return -ENODEV; |
| 96 | } |
| 97 | |
| 98 | sjoyff = kzalloc(sizeof(struct sjoyff_device), GFP_KERNEL); |
| 99 | if (!sjoyff) |
| 100 | return -ENOMEM; |
| 101 | |
| 102 | dev = hidinput->input; |
| 103 | |
| 104 | set_bit(FF_RUMBLE, dev->ffbit); |
| 105 | |
| 106 | error = input_ff_create_memless(dev, sjoyff, hid_sjoyff_play); |
| 107 | if (error) { |
| 108 | kfree(sjoyff); |
| 109 | return error; |
| 110 | } |
| 111 | |
| 112 | sjoyff->report = report; |
| 113 | sjoyff->report->field[0]->value[0] = 0x01; |
| 114 | sjoyff->report->field[0]->value[1] = 0x00; |
| 115 | sjoyff->report->field[0]->value[2] = 0x00; |
Benjamin Tissoires | d8814272 | 2013-02-25 11:31:46 +0100 | [diff] [blame] | 116 | hid_hw_request(hid, sjoyff->report, HID_REQ_SET_REPORT); |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 117 | } |
| 118 | |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 119 | hid_info(hid, "Force feedback for SmartJoy PLUS PS2/USB adapter\n"); |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | #else |
| 124 | static inline int sjoyff_init(struct hid_device *hid) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | #endif |
| 129 | |
| 130 | static int sjoy_probe(struct hid_device *hdev, const struct hid_device_id *id) |
| 131 | { |
| 132 | int ret; |
| 133 | |
Sean Young | ad395cc | 2011-08-14 20:42:05 +0100 | [diff] [blame] | 134 | hdev->quirks |= id->driver_data; |
| 135 | |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 136 | ret = hid_parse(hdev); |
| 137 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 138 | hid_err(hdev, "parse failed\n"); |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 139 | goto err; |
| 140 | } |
| 141 | |
| 142 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); |
| 143 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 144 | hid_err(hdev, "hw start failed\n"); |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 145 | goto err; |
| 146 | } |
| 147 | |
| 148 | sjoyff_init(hdev); |
| 149 | |
| 150 | return 0; |
| 151 | err: |
| 152 | return ret; |
| 153 | } |
| 154 | |
| 155 | static const struct hid_device_id sjoy_devices[] = { |
Sean Young | 42fc04e | 2012-02-18 12:53:44 +0000 | [diff] [blame] | 156 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO), |
| 157 | .driver_data = HID_QUIRK_NOGET }, |
Sean Young | 1bcc206 | 2011-10-20 21:26:21 +0100 | [diff] [blame] | 158 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_DUAL_BOX_PRO), |
| 159 | .driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET | |
| 160 | HID_QUIRK_SKIP_OUTPUT_REPORTS }, |
| 161 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_5_PRO), |
| 162 | .driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET | |
| 163 | HID_QUIRK_SKIP_OUTPUT_REPORTS }, |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 164 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) }, |
Sean Young | 42fc04e | 2012-02-18 12:53:44 +0000 | [diff] [blame] | 165 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SUPER_JOY_BOX_3) }, |
Sean Young | ad395cc | 2011-08-14 20:42:05 +0100 | [diff] [blame] | 166 | { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD), |
Sean Young | 42fc04e | 2012-02-18 12:53:44 +0000 | [diff] [blame] | 167 | .driver_data = HID_QUIRK_MULTI_INPUT | |
Sean Young | ad395cc | 2011-08-14 20:42:05 +0100 | [diff] [blame] | 168 | HID_QUIRK_SKIP_OUTPUT_REPORTS }, |
Sean Young | 6e5e9a0 | 2015-05-06 21:38:42 +0100 | [diff] [blame] | 169 | { HID_USB_DEVICE(USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII), |
| 170 | .driver_data = HID_QUIRK_MULTI_INPUT | |
| 171 | HID_QUIRK_SKIP_OUTPUT_REPORTS }, |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 172 | { } |
| 173 | }; |
| 174 | MODULE_DEVICE_TABLE(hid, sjoy_devices); |
| 175 | |
| 176 | static struct hid_driver sjoy_driver = { |
| 177 | .name = "smartjoyplus", |
| 178 | .id_table = sjoy_devices, |
| 179 | .probe = sjoy_probe, |
| 180 | }; |
H Hartley Sweeten | f425458 | 2012-12-17 15:28:26 -0700 | [diff] [blame] | 181 | module_hid_driver(sjoy_driver); |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 182 | |
Jussi Kivilinna | fac733f | 2009-05-13 11:54:38 +0300 | [diff] [blame] | 183 | MODULE_LICENSE("GPL"); |
| 184 | MODULE_AUTHOR("Jussi Kivilinna"); |
| 185 | |