]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/hid/hid-gaff.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Force feedback support for GreenAsia (Product ID 0x12) based devices
5 * The devices are distributed under various names and the same USB device ID
6 * 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>
17 #include <linux/input.h>
18 #include <linux/slab.h>
19 #include <linux/hid.h>
20 #include <linux/module.h>
23 #ifdef CONFIG_GREENASIA_FF
26 struct hid_report
*report
;
29 static int hid_gaff_play(struct input_dev
*dev
, void *data
,
30 struct ff_effect
*effect
)
32 struct hid_device
*hid
= input_get_drvdata(dev
);
33 struct gaff_device
*gaff
= data
;
36 left
= effect
->u
.rumble
.strong_magnitude
;
37 right
= effect
->u
.rumble
.weak_magnitude
;
39 dbg_hid("called with 0x%04x 0x%04x", left
, right
);
41 left
= left
* 0xfe / 0xffff;
42 right
= right
* 0xfe / 0xffff;
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
);
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;
58 hid_hw_request(hid
, gaff
->report
, HID_REQ_SET_REPORT
);
63 static int gaff_init(struct hid_device
*hid
)
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
;
74 if (list_empty(&hid
->inputs
)) {
75 hid_err(hid
, "no inputs found\n");
78 hidinput
= list_entry(hid
->inputs
.next
, struct hid_input
, list
);
79 dev
= hidinput
->input
;
81 if (list_empty(report_list
)) {
82 hid_err(hid
, "no output reports found\n");
86 report_ptr
= report_ptr
->next
;
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");
94 if (report
->field
[0]->report_count
< 6) {
95 hid_err(hid
, "not enough values in the field\n");
99 gaff
= kzalloc(sizeof(struct gaff_device
), GFP_KERNEL
);
103 set_bit(FF_RUMBLE
, dev
->ffbit
);
105 error
= input_ff_create_memless(dev
, gaff
, hid_gaff_play
);
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
);
118 gaff
->report
->field
[0]->value
[0] = 0xfa;
119 gaff
->report
->field
[0]->value
[1] = 0xfe;
121 hid_hw_request(hid
, gaff
->report
, HID_REQ_SET_REPORT
);
123 hid_info(hid
, "Force Feedback for GreenAsia 0x12 devices by Lukasz Lubojanski <lukasz@lubojanski.info>\n");
128 static inline int gaff_init(struct hid_device
*hdev
)
134 static int ga_probe(struct hid_device
*hdev
, const struct hid_device_id
*id
)
138 dev_dbg(&hdev
->dev
, "Greenasia HID hardware probe...");
140 ret
= hid_parse(hdev
);
142 hid_err(hdev
, "parse failed\n");
146 ret
= hid_hw_start(hdev
, HID_CONNECT_DEFAULT
& ~HID_CONNECT_FF
);
148 hid_err(hdev
, "hw start failed\n");
159 static const struct hid_device_id ga_devices
[] = {
160 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA
, 0x0012), },
163 MODULE_DEVICE_TABLE(hid
, ga_devices
);
165 static struct hid_driver ga_driver
= {
167 .id_table
= ga_devices
,
170 module_hid_driver(ga_driver
);
172 MODULE_LICENSE("GPL");