Linux 5.1.15
[linux/fpc-iii.git] / drivers / hid / hid-gaff.c
blob2d8cead3adcaadf68e30ea9a4f37c7fc21452d50
1 /*
2 * Force feedback support for GreenAsia (Product ID 0x12) based devices
4 * The devices are distributed under various names and the same USB device ID
5 * can be used in many game controllers.
8 * 0e8f:0012 "GreenAsia Inc. USB Joystick "
9 * - tested with MANTA Warior MM816 and SpeedLink Strike2 SL-6635.
11 * Copyright (c) 2008 Lukasz Lubojanski <lukasz@lubojanski.info>
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.
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.
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
30 #include <linux/input.h>
31 #include <linux/slab.h>
32 #include <linux/hid.h>
33 #include <linux/module.h>
34 #include "hid-ids.h"
36 #ifdef CONFIG_GREENASIA_FF
38 struct gaff_device {
39 struct hid_report *report;
42 static int hid_gaff_play(struct input_dev *dev, void *data,
43 struct ff_effect *effect)
45 struct hid_device *hid = input_get_drvdata(dev);
46 struct gaff_device *gaff = data;
47 int left, right;
49 left = effect->u.rumble.strong_magnitude;
50 right = effect->u.rumble.weak_magnitude;
52 dbg_hid("called with 0x%04x 0x%04x", left, right);
54 left = left * 0xfe / 0xffff;
55 right = right * 0xfe / 0xffff;
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);
64 hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
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;
71 hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
73 return 0;
76 static int gaff_init(struct hid_device *hid)
78 struct gaff_device *gaff;
79 struct hid_report *report;
80 struct hid_input *hidinput = list_entry(hid->inputs.next,
81 struct hid_input, list);
82 struct list_head *report_list =
83 &hid->report_enum[HID_OUTPUT_REPORT].report_list;
84 struct list_head *report_ptr = report_list;
85 struct input_dev *dev = hidinput->input;
86 int error;
88 if (list_empty(report_list)) {
89 hid_err(hid, "no output reports found\n");
90 return -ENODEV;
93 report_ptr = report_ptr->next;
95 report = list_entry(report_ptr, struct hid_report, list);
96 if (report->maxfield < 1) {
97 hid_err(hid, "no fields in the report\n");
98 return -ENODEV;
101 if (report->field[0]->report_count < 6) {
102 hid_err(hid, "not enough values in the field\n");
103 return -ENODEV;
106 gaff = kzalloc(sizeof(struct gaff_device), GFP_KERNEL);
107 if (!gaff)
108 return -ENOMEM;
110 set_bit(FF_RUMBLE, dev->ffbit);
112 error = input_ff_create_memless(dev, gaff, hid_gaff_play);
113 if (error) {
114 kfree(gaff);
115 return error;
118 gaff->report = report;
119 gaff->report->field[0]->value[0] = 0x51;
120 gaff->report->field[0]->value[1] = 0x00;
121 gaff->report->field[0]->value[2] = 0x00;
122 gaff->report->field[0]->value[3] = 0x00;
123 hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
125 gaff->report->field[0]->value[0] = 0xfa;
126 gaff->report->field[0]->value[1] = 0xfe;
128 hid_hw_request(hid, gaff->report, HID_REQ_SET_REPORT);
130 hid_info(hid, "Force Feedback for GreenAsia 0x12 devices by Lukasz Lubojanski <lukasz@lubojanski.info>\n");
132 return 0;
134 #else
135 static inline int gaff_init(struct hid_device *hdev)
137 return 0;
139 #endif
141 static int ga_probe(struct hid_device *hdev, const struct hid_device_id *id)
143 int ret;
145 dev_dbg(&hdev->dev, "Greenasia HID hardware probe...");
147 ret = hid_parse(hdev);
148 if (ret) {
149 hid_err(hdev, "parse failed\n");
150 goto err;
153 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
154 if (ret) {
155 hid_err(hdev, "hw start failed\n");
156 goto err;
159 gaff_init(hdev);
161 return 0;
162 err:
163 return ret;
166 static const struct hid_device_id ga_devices[] = {
167 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012), },
170 MODULE_DEVICE_TABLE(hid, ga_devices);
172 static struct hid_driver ga_driver = {
173 .name = "greenasia",
174 .id_table = ga_devices,
175 .probe = ga_probe,
177 module_hid_driver(ga_driver);
179 MODULE_LICENSE("GPL");