Skip to content

Commit

Permalink
hid-xpadneo, quirks: We need to carry a quirk for Linux button mappings
Browse files Browse the repository at this point in the history
There are controllers which are not 100% compatible with Xbox One S
because they are not switching to Linux mode when connected to Linux.
We can detect such devices at HID parse time and set a flag when we
detect Linux mode.

With this commit, we no longer shift the button bits when we detect a
controller in native Windows mode.

Fixes: atar-axis#228
Signed-off-by: Kai Krakow <kai@kaishome.de>
  • Loading branch information
kakra committed Jul 12, 2020
1 parent 1000f44 commit 83ad155
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ MODULE_PARM_DESC(gamepad_compliance,
#define XPADNEO_QUIRK_NO_TRIGGER_RUMBLE 2
#define XPADNEO_QUIRK_NO_MOTOR_MASK 4
#define XPADNEO_QUIRK_USE_HW_PROFILES 8
#define XPADNEO_QUIRK_LINUX_BUTTONS 16

static struct {
char *args[17];
Expand All @@ -92,7 +93,8 @@ MODULE_PARM_DESC(quirks,
", no pulse parameters = " __stringify(XPADNEO_QUIRK_NO_PULSE)
", no trigger rumble = " __stringify(XPADNEO_QUIRK_NO_TRIGGER_RUMBLE)
", no motor masking = " __stringify(XPADNEO_QUIRK_NO_MOTOR_MASK)
", hardware profile switch = " __stringify(XPADNEO_QUIRK_USE_HW_PROFILES));
", hardware profile switch = " __stringify(XPADNEO_QUIRK_USE_HW_PROFILES)
", use Linux button mappings = " __stringify(XPADNEO_QUIRK_LINUX_BUTTONS));

static DEFINE_IDA(xpadneo_device_id_allocator);

Expand Down Expand Up @@ -836,7 +838,9 @@ static u8 *xpadneo_report_fixup(struct hid_device *hdev, u8 *rdesc, unsigned int
rdesc[144] == 0x29 && rdesc[145] == 0x0F &&
rdesc[152] == 0x95 && rdesc[153] == 0x0F &&
rdesc[162] == 0x95 && rdesc[163] == 0x01) {
struct xpadneo_devdata *xdata = hid_get_drvdata(hdev);
hid_notice(hdev, "fixing up button mapping\n");
xdata->quirks |= XPADNEO_QUIRK_LINUX_BUTTONS;
rdesc[145] = 0x0B; /* 15 buttons -> 11 buttons */
rdesc[153] = 0x0B; /* 15 bits -> 11 bits buttons */
rdesc[163] = 0x05; /* 1 bit -> 5 bits constants */
Expand Down Expand Up @@ -870,7 +874,7 @@ static int xpadneo_raw_event(struct hid_device *hdev, struct hid_report *report,
}

/* correct button mapping of Xbox controllers in Linux mode */
if (report->id == 1 && (reportsize == 17 || reportsize == 39 || reportsize == 55)) {
if ((xdata->quirks & XPADNEO_QUIRK_LINUX_BUTTONS) && report->id == 1 && reportsize >= 17) {
u16 bits = 0;

bits |= (data[14] & (BIT(0) | BIT(1))) >> 0; /* A, B */
Expand Down Expand Up @@ -1137,7 +1141,7 @@ static int xpadneo_probe(struct hid_device *hdev, const struct hid_device_id *id
return ret;
}

xdata->quirks = id->driver_data;
xdata->quirks |= id->driver_data;
ret = xpadneo_init_hw(hdev);
if (ret) {
hid_err(hdev, "hw init failed: %d\n", ret);
Expand Down

0 comments on commit 83ad155

Please sign in to comment.