Skip to content

Commit 931830a

Browse files
bentissJiri Kosina
authored andcommitted
HID: gembird: add new driver to fix Gembird JPD-DualForce 2
This gamepad advertise 5 absolute axis while 4 are actually used. The second Z axis shows some garbage, so it has to be ignored by HID. The first Z axis and the Rz one are actually Rx and Ry. Remap them. We could also just remap and ignore the axis in .input_mapping(). I went ahead with .report_fixup() first, so here it is. Reported-by: Orivej Desh <[email protected]> Tested-by: Orivej Desh <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 7a834ba commit 931830a

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed

drivers/hid/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ config HID_EZKEY
251251
---help---
252252
Support for Ezkey BTC 8193 keyboard.
253253

254+
config HID_GEMBIRD
255+
tristate "Gembird Joypad"
256+
depends on HID
257+
---help---
258+
Support for Gembird JPD-DualForce 2.
259+
254260
config HID_HOLTEK
255261
tristate "Holtek HID devices"
256262
depends on USB_HID

drivers/hid/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ obj-$(CONFIG_HID_EMS_FF) += hid-emsff.o
3636
obj-$(CONFIG_HID_ELECOM) += hid-elecom.o
3737
obj-$(CONFIG_HID_ELO) += hid-elo.o
3838
obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o
39+
obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o
3940
obj-$(CONFIG_HID_GT683R) += hid-gt683r.o
4041
obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
4142
obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o

drivers/hid/hid-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
18231823
{ HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
18241824
{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
18251825
{ HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR) },
1826+
{ HID_USB_DEVICE(USB_VENDOR_ID_GEMBIRD, USB_DEVICE_ID_GEMBIRD_JPD_DUALFORCE2) },
18261827
{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
18271828
{ HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0012) },
18281829
{ HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },

drivers/hid/hid-gembird.c

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* HID driver for Gembird Joypad, "PC Game Controller"
3+
*
4+
* Copyright (c) 2015 Red Hat, Inc
5+
* Copyright (c) 2015 Benjamin Tissoires
6+
*/
7+
8+
/*
9+
* This program is free software; you can redistribute it and/or modify it
10+
* under the terms of the GNU General Public License as published by the Free
11+
* Software Foundation; either version 2 of the License, or (at your option)
12+
* any later version.
13+
*/
14+
15+
#include <linux/device.h>
16+
#include <linux/hid.h>
17+
#include <linux/module.h>
18+
19+
#include "hid-ids.h"
20+
21+
#define GEMBIRD_START_FAULTY_RDESC 8
22+
23+
static const __u8 gembird_jpd_faulty_rdesc[] = {
24+
0x75, 0x08, /* Report Size (8) */
25+
0x95, 0x05, /* Report Count (5) */
26+
0x15, 0x00, /* Logical Minimum (0) */
27+
0x26, 0xff, 0x00, /* Logical Maximum (255) */
28+
0x35, 0x00, /* Physical Minimum (0) */
29+
0x46, 0xff, 0x00, /* Physical Maximum (255) */
30+
0x09, 0x30, /* Usage (X) */
31+
0x09, 0x31, /* Usage (Y) */
32+
0x09, 0x32, /* Usage (Z) */
33+
0x09, 0x32, /* Usage (Z) */
34+
0x09, 0x35, /* Usage (Rz) */
35+
0x81, 0x02, /* Input (Data,Var,Abs) */
36+
};
37+
38+
/*
39+
* we fix the report descriptor by:
40+
* - marking the first Z axis as constant (so it is ignored by HID)
41+
* - assign the original second Z to Rx
42+
* - assign the original Rz to Ry
43+
*/
44+
static const __u8 gembird_jpd_fixed_rdesc[] = {
45+
0x75, 0x08, /* Report Size (8) */
46+
0x95, 0x02, /* Report Count (2) */
47+
0x15, 0x00, /* Logical Minimum (0) */
48+
0x26, 0xff, 0x00, /* Logical Maximum (255) */
49+
0x35, 0x00, /* Physical Minimum (0) */
50+
0x46, 0xff, 0x00, /* Physical Maximum (255) */
51+
0x09, 0x30, /* Usage (X) */
52+
0x09, 0x31, /* Usage (Y) */
53+
0x81, 0x02, /* Input (Data,Var,Abs) */
54+
0x95, 0x01, /* Report Count (1) */
55+
0x09, 0x32, /* Usage (Z) */
56+
0x81, 0x01, /* Input (Cnst,Arr,Abs) */
57+
0x95, 0x02, /* Report Count (2) */
58+
0x09, 0x33, /* Usage (Rx) */
59+
0x09, 0x34, /* Usage (Ry) */
60+
0x81, 0x02, /* Input (Data,Var,Abs) */
61+
};
62+
63+
static __u8 *gembird_report_fixup(struct hid_device *hdev, __u8 *rdesc,
64+
unsigned int *rsize)
65+
{
66+
__u8 *new_rdesc;
67+
/* delta_size is > 0 */
68+
size_t delta_size = sizeof(gembird_jpd_fixed_rdesc) -
69+
sizeof(gembird_jpd_faulty_rdesc);
70+
size_t new_size = *rsize + delta_size;
71+
72+
if (*rsize >= 31 && !memcmp(&rdesc[GEMBIRD_START_FAULTY_RDESC],
73+
gembird_jpd_faulty_rdesc,
74+
sizeof(gembird_jpd_faulty_rdesc))) {
75+
new_rdesc = devm_kzalloc(&hdev->dev, new_size, GFP_KERNEL);
76+
if (new_rdesc == NULL)
77+
return rdesc;
78+
79+
dev_info(&hdev->dev,
80+
"fixing Gembird JPD-DualForce 2 report descriptor.\n");
81+
82+
/* start by copying the end of the rdesc */
83+
memcpy(new_rdesc + delta_size, rdesc, *rsize);
84+
85+
/* add the correct beginning */
86+
memcpy(new_rdesc, rdesc, GEMBIRD_START_FAULTY_RDESC);
87+
88+
/* replace the faulty part with the fixed one */
89+
memcpy(new_rdesc + GEMBIRD_START_FAULTY_RDESC,
90+
gembird_jpd_fixed_rdesc,
91+
sizeof(gembird_jpd_fixed_rdesc));
92+
93+
*rsize = new_size;
94+
rdesc = new_rdesc;
95+
}
96+
97+
return rdesc;
98+
}
99+
100+
static const struct hid_device_id gembird_devices[] = {
101+
{ HID_USB_DEVICE(USB_VENDOR_ID_GEMBIRD,
102+
USB_DEVICE_ID_GEMBIRD_JPD_DUALFORCE2) },
103+
{ }
104+
};
105+
MODULE_DEVICE_TABLE(hid, gembird_devices);
106+
107+
static struct hid_driver gembird_driver = {
108+
.name = "gembird",
109+
.id_table = gembird_devices,
110+
.report_fixup = gembird_report_fixup,
111+
};
112+
module_hid_driver(gembird_driver);
113+
114+
MODULE_AUTHOR("Benjamin Tissoires <[email protected]>");
115+
MODULE_DESCRIPTION("HID Gembird joypad driver");
116+
MODULE_LICENSE("GPL");

drivers/hid/hid-ids.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@
358358
#define USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR 0x0001
359359
#define USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR 0x0002
360360

361+
#define USB_VENDOR_ID_GEMBIRD 0x11ff
362+
#define USB_DEVICE_ID_GEMBIRD_JPD_DUALFORCE2 0x3331
363+
361364
#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc
362365
#define USB_DEVICE_ID_GENERAL_TOUCH_WIN7_TWOFINGERS 0x0003
363366
#define USB_DEVICE_ID_GENERAL_TOUCH_WIN8_PWT_TENFINGERS 0x0100

0 commit comments

Comments
 (0)