drivers/input: add export.h to symbol exporting files.
[linux-block.git] / drivers / hid / hid-gaff.c
CommitLineData
42859e0b
LL
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>
5a0e3ad6 31#include <linux/slab.h>
42859e0b
LL
32#include <linux/usb.h>
33#include <linux/hid.h>
34#include "hid-ids.h"
0f6f4319
JK
35
36#ifdef CONFIG_GREENASIA_FF
42859e0b
LL
37#include "usbhid/usbhid.h"
38
39struct gaff_device {
40 struct hid_report *report;
41};
42
43static int hid_gaff_play(struct input_dev *dev, void *data,
44 struct ff_effect *effect)
45{
46 struct hid_device *hid = input_get_drvdata(dev);
47 struct gaff_device *gaff = data;
48 int left, right;
49
50 left = effect->u.rumble.strong_magnitude;
51 right = effect->u.rumble.weak_magnitude;
52
53 dbg_hid("called with 0x%04x 0x%04x", left, right);
54
55 left = left * 0xfe / 0xffff;
56 right = right * 0xfe / 0xffff;
57
58 gaff->report->field[0]->value[0] = 0x51;
59 gaff->report->field[0]->value[1] = 0x0;
60 gaff->report->field[0]->value[2] = right;
61 gaff->report->field[0]->value[3] = 0;
62 gaff->report->field[0]->value[4] = left;
63 gaff->report->field[0]->value[5] = 0;
64 dbg_hid("running with 0x%02x 0x%02x", left, right);
65 usbhid_submit_report(hid, gaff->report, USB_DIR_OUT);
66
67 gaff->report->field[0]->value[0] = 0xfa;
68 gaff->report->field[0]->value[1] = 0xfe;
69 gaff->report->field[0]->value[2] = 0x0;
70 gaff->report->field[0]->value[4] = 0x0;
71
72 usbhid_submit_report(hid, gaff->report, USB_DIR_OUT);
73
74 return 0;
75}
76
77static int gaff_init(struct hid_device *hid)
78{
79 struct gaff_device *gaff;
80 struct hid_report *report;
81 struct hid_input *hidinput = list_entry(hid->inputs.next,
82 struct hid_input, list);
83 struct list_head *report_list =
84 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
85 struct list_head *report_ptr = report_list;
86 struct input_dev *dev = hidinput->input;
87 int error;
88
89 if (list_empty(report_list)) {
4291ee30 90 hid_err(hid, "no output reports found\n");
42859e0b
LL
91 return -ENODEV;
92 }
93
94 report_ptr = report_ptr->next;
95
96 report = list_entry(report_ptr, struct hid_report, list);
97 if (report->maxfield < 1) {
4291ee30 98 hid_err(hid, "no fields in the report\n");
42859e0b
LL
99 return -ENODEV;
100 }
101
102 if (report->field[0]->report_count < 6) {
4291ee30 103 hid_err(hid, "not enough values in the field\n");
42859e0b
LL
104 return -ENODEV;
105 }
106
107 gaff = kzalloc(sizeof(struct gaff_device), GFP_KERNEL);
108 if (!gaff)
109 return -ENOMEM;
110
111 set_bit(FF_RUMBLE, dev->ffbit);
112
113 error = input_ff_create_memless(dev, gaff, hid_gaff_play);
114 if (error) {
115 kfree(gaff);
116 return error;
117 }
118
119 gaff->report = report;
120 gaff->report->field[0]->value[0] = 0x51;
121 gaff->report->field[0]->value[1] = 0x00;
122 gaff->report->field[0]->value[2] = 0x00;
123 gaff->report->field[0]->value[3] = 0x00;
124 usbhid_submit_report(hid, gaff->report, USB_DIR_OUT);
125
126 gaff->report->field[0]->value[0] = 0xfa;
127 gaff->report->field[0]->value[1] = 0xfe;
128
129 usbhid_submit_report(hid, gaff->report, USB_DIR_OUT);
130
4291ee30 131 hid_info(hid, "Force Feedback for GreenAsia 0x12 devices by Lukasz Lubojanski <lukasz@lubojanski.info>\n");
42859e0b
LL
132
133 return 0;
134}
0f6f4319
JK
135#else
136static inline int gaff_init(struct hid_device *hdev)
137{
138 return 0;
139}
140#endif
42859e0b
LL
141
142static int ga_probe(struct hid_device *hdev, const struct hid_device_id *id)
143{
144 int ret;
145
146 dev_dbg(&hdev->dev, "Greenasia HID hardware probe...");
147
148 ret = hid_parse(hdev);
149 if (ret) {
4291ee30 150 hid_err(hdev, "parse failed\n");
42859e0b
LL
151 goto err;
152 }
153
154 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
155 if (ret) {
4291ee30 156 hid_err(hdev, "hw start failed\n");
42859e0b
LL
157 goto err;
158 }
159
160 gaff_init(hdev);
161
162 return 0;
163err:
164 return ret;
165}
166
167static const struct hid_device_id ga_devices[] = {
168 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012), },
169 { }
170};
171MODULE_DEVICE_TABLE(hid, ga_devices);
172
173static struct hid_driver ga_driver = {
174 .name = "greenasia",
175 .id_table = ga_devices,
176 .probe = ga_probe,
177};
178
179static int __init ga_init(void)
180{
181 return hid_register_driver(&ga_driver);
182}
183
184static void __exit ga_exit(void)
185{
186 hid_unregister_driver(&ga_driver);
187}
188
189module_init(ga_init);
190module_exit(ga_exit);
191MODULE_LICENSE("GPL");