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