Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-btrfs-devel.git] / drivers / hid / hid-sjoy.c
blob670da9109f86fa2b5aba02951eda62593a4e7d33
1 /*
2 * Force feedback support for SmartJoy PLUS PS2->USB adapter
4 * Copyright (c) 2009 Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
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 */
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.
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.
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
27 /* #define DEBUG */
29 #include <linux/input.h>
30 #include <linux/slab.h>
31 #include <linux/usb.h>
32 #include <linux/hid.h>
33 #include "hid-ids.h"
35 #ifdef CONFIG_SMARTJOYPLUS_FF
36 #include "usbhid/usbhid.h"
38 struct sjoyff_device {
39 struct hid_report *report;
42 static int hid_sjoyff_play(struct input_dev *dev, void *data,
43 struct ff_effect *effect)
45 struct hid_device *hid = input_get_drvdata(dev);
46 struct sjoyff_device *sjoyff = data;
47 u32 left, right;
49 left = effect->u.rumble.strong_magnitude;
50 right = effect->u.rumble.weak_magnitude;
51 dev_dbg(&dev->dev, "called with 0x%08x 0x%08x\n", left, right);
53 left = left * 0xff / 0xffff;
54 right = (right != 0); /* on/off only */
56 sjoyff->report->field[0]->value[1] = right;
57 sjoyff->report->field[0]->value[2] = left;
58 dev_dbg(&dev->dev, "running with 0x%02x 0x%02x\n", left, right);
59 usbhid_submit_report(hid, sjoyff->report, USB_DIR_OUT);
61 return 0;
64 static int sjoyff_init(struct hid_device *hid)
66 struct sjoyff_device *sjoyff;
67 struct hid_report *report;
68 struct hid_input *hidinput;
69 struct list_head *report_list =
70 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
71 struct list_head *report_ptr = report_list;
72 struct input_dev *dev;
73 int error;
75 if (list_empty(report_list)) {
76 hid_err(hid, "no output reports found\n");
77 return -ENODEV;
80 list_for_each_entry(hidinput, &hid->inputs, list) {
81 report_ptr = report_ptr->next;
83 if (report_ptr == report_list) {
84 hid_err(hid, "required output report is missing\n");
85 return -ENODEV;
88 report = list_entry(report_ptr, struct hid_report, list);
89 if (report->maxfield < 1) {
90 hid_err(hid, "no fields in the report\n");
91 return -ENODEV;
94 if (report->field[0]->report_count < 3) {
95 hid_err(hid, "not enough values in the field\n");
96 return -ENODEV;
99 sjoyff = kzalloc(sizeof(struct sjoyff_device), GFP_KERNEL);
100 if (!sjoyff)
101 return -ENOMEM;
103 dev = hidinput->input;
105 set_bit(FF_RUMBLE, dev->ffbit);
107 error = input_ff_create_memless(dev, sjoyff, hid_sjoyff_play);
108 if (error) {
109 kfree(sjoyff);
110 return error;
113 sjoyff->report = report;
114 sjoyff->report->field[0]->value[0] = 0x01;
115 sjoyff->report->field[0]->value[1] = 0x00;
116 sjoyff->report->field[0]->value[2] = 0x00;
117 usbhid_submit_report(hid, sjoyff->report, USB_DIR_OUT);
120 hid_info(hid, "Force feedback for SmartJoy PLUS PS2/USB adapter\n");
122 return 0;
124 #else
125 static inline int sjoyff_init(struct hid_device *hid)
127 return 0;
129 #endif
131 static int sjoy_probe(struct hid_device *hdev, const struct hid_device_id *id)
133 int ret;
135 hdev->quirks |= id->driver_data;
137 ret = hid_parse(hdev);
138 if (ret) {
139 hid_err(hdev, "parse failed\n");
140 goto err;
143 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
144 if (ret) {
145 hid_err(hdev, "hw start failed\n");
146 goto err;
149 sjoyff_init(hdev);
151 return 0;
152 err:
153 return ret;
156 static const struct hid_device_id sjoy_devices[] = {
157 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SUPER_JOY_BOX_3_PRO) },
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 },
164 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) },
165 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD),
166 .driver_data = HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET |
167 HID_QUIRK_SKIP_OUTPUT_REPORTS },
170 MODULE_DEVICE_TABLE(hid, sjoy_devices);
172 static struct hid_driver sjoy_driver = {
173 .name = "smartjoyplus",
174 .id_table = sjoy_devices,
175 .probe = sjoy_probe,
178 static int __init sjoy_init(void)
180 return hid_register_driver(&sjoy_driver);
183 static void __exit sjoy_exit(void)
185 hid_unregister_driver(&sjoy_driver);
188 module_init(sjoy_init);
189 module_exit(sjoy_exit);
190 MODULE_LICENSE("GPL");
191 MODULE_AUTHOR("Jussi Kivilinna");