Skip to content

Commit

Permalink
xpadneo: Revert fixups on device removal
Browse files Browse the repository at this point in the history
Later kernels seem to cache devices when removed from a driver. This
commit undoes our fixups so we can properly detect and reapply them
when we see the device again, even if the device itself was never
removed from the kernel.

Fixes: #340
Maybe-fixes: #347
Maybe-fixes: #343
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed Apr 16, 2022
1 parent 4fd620c commit b6c0708
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
32 changes: 23 additions & 9 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,6 @@ static int xpadneo_probe(struct hid_device *hdev, const struct hid_device_id *id
{
int ret;
struct xpadneo_devdata *xdata;
u16 product;
u32 version;

xdata = devm_kzalloc(&hdev->dev, sizeof(*xdata), GFP_KERNEL);
if (xdata == NULL)
Expand Down Expand Up @@ -1166,9 +1164,9 @@ static int xpadneo_probe(struct hid_device *hdev, const struct hid_device_id *id
* still detect our driver as the correct model. Currently this
* maps all controllers to the same model.
*/
product = hdev->product;
version = hdev->version;
switch (product) {
xdata->original_product = hdev->product;
xdata->original_version = hdev->version;
switch (xdata->original_product) {
case 0x02E0:
hdev->version = 0x00000903;
break;
Expand All @@ -1183,16 +1181,16 @@ static int xpadneo_probe(struct hid_device *hdev, const struct hid_device_id *id
break;
}

if (hdev->product != product)
if (hdev->product != xdata->original_product)
hid_info(hdev,
"pretending XB1S Windows wireless mode "
"(changed PID from 0x%04X to 0x%04X)\n", product,
"(changed PID from 0x%04X to 0x%04X)\n", xdata->original_product,
hdev->product);

if (hdev->version != version)
if (hdev->version != xdata->original_version)
hid_info(hdev,
"working around wrong SDL2 mappings "
"(changed version from 0x%08X to 0x%08X)\n", version,
"(changed version from 0x%08X to 0x%08X)\n", xdata->original_version,
hdev->version);

ret = hid_parse(hdev);
Expand Down Expand Up @@ -1241,6 +1239,22 @@ static void xpadneo_remove(struct hid_device *hdev)

hid_hw_close(hdev);

if (hdev->version != xdata->original_version) {
hid_info(hdev,
"reverting to original version "
"(changed version from 0x%08X to 0x%08X)\n",
hdev->version, xdata->original_version);
hdev->version = xdata->original_version;
}

if (hdev->product != xdata->original_product) {
hid_info(hdev,
"reverting to original product "
"(changed PID from 0x%04X to 0x%04X)\n",
hdev->product, xdata->original_product);
hdev->product = xdata->original_product;
}

cancel_delayed_work_sync(&xdata->ff_worker);

kfree(xdata->battery.name);
Expand Down
4 changes: 4 additions & 0 deletions hid-xpadneo/src/xpadneo.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ struct xpadneo_devdata {
struct input_dev *consumer, *gamepad, *keyboard;
short int missing_reported;

/* revert fixups on removal */
u16 original_product;
u32 original_version;

/* quirk flags */
unsigned int original_rsize;
u32 quirks;
Expand Down

0 comments on commit b6c0708

Please sign in to comment.