* [PATCH] HID: playstation: Center initial joystick axes to prevent spurious events
@ 2025-11-11 23:38 Siarhei Vishniakou
2025-11-11 23:40 ` Siarhei Vishniakou
0 siblings, 1 reply; 2+ messages in thread
From: Siarhei Vishniakou @ 2025-11-11 23:38 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires, Roderick Colenbrander,
linux-input, linux-kernel
Cc: Siarhei Vishniakou
When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
the input subsystem sets the default value for its absolute axes (e.g.,
ABS_X, ABS_Y) to 0.
However, the hardware's actual neutral/resting state for these joysticks
is 128 (0x80). This creates a mismatch.
When the first HID report arrives from the device, the driver sees the
resting value of 128. The kernel compares this to its initial state of 0
and incorrectly interprets this as a delta (0 -> 128). Consequently, it
generates EV_ABS events for this initial, non-existent movement.
This behavior can fail userspace 'sanity check' tests (e.g., in
Android CTS) that correctly assert no motion events should be generated
from a device that is already at rest.
This patch fixes the issue by explicitly setting the initial value of the
main joystick axes (e.g., ABS_X, ABS_Y, ABS_RX, ABS_RY) to 128 (0x80)
in the common ps_gamepad_create() function.
This aligns the kernel's initial state with the hardware's expected
neutral state, ensuring that the first report (at 128) produces no
delta and thus, no spurious event.
Signed-off-by: Siarhei Vishniakou <svv@google.com>
---
drivers/hid/hid-playstation.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 1468fb11e39d..fd9d3c901743 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -718,12 +718,19 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,
if (IS_ERR(gamepad))
return ERR_CAST(gamepad);
+ /* Set initial resting state for joysticks to 128 (center) */
input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_X].value = 128;
input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_Y].value = 128;
input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_Z].value = 128;
input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_RX].value = 128;
input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_RY].value = 128;
input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0);
+ gamepad->absinfo[ABS_RZ].value = 128;
input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0);
input_set_abs_params(gamepad, ABS_HAT0Y, -1, 1, 0, 0);
--
2.51.0.536.g15c5d4f767-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] HID: playstation: Center initial joystick axes to prevent spurious events
2025-11-11 23:38 [PATCH] HID: playstation: Center initial joystick axes to prevent spurious events Siarhei Vishniakou
@ 2025-11-11 23:40 ` Siarhei Vishniakou
0 siblings, 0 replies; 2+ messages in thread
From: Siarhei Vishniakou @ 2025-11-11 23:40 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires, Roderick Colenbrander,
linux-input, linux-kernel
вт, 11 нояб. 2025 г. в 15:38, Siarhei Vishniakou <svv@google.com>:
>
> When a new PlayStation gamepad (DualShock 4 or DualSense) is initialized,
> the input subsystem sets the default value for its absolute axes (e.g.,
> ABS_X, ABS_Y) to 0.
>
> However, the hardware's actual neutral/resting state for these joysticks
> is 128 (0x80). This creates a mismatch.
>
> When the first HID report arrives from the device, the driver sees the
> resting value of 128. The kernel compares this to its initial state of 0
> and incorrectly interprets this as a delta (0 -> 128). Consequently, it
> generates EV_ABS events for this initial, non-existent movement.
>
> This behavior can fail userspace 'sanity check' tests (e.g., in
> Android CTS) that correctly assert no motion events should be generated
> from a device that is already at rest.
>
> This patch fixes the issue by explicitly setting the initial value of the
> main joystick axes (e.g., ABS_X, ABS_Y, ABS_RX, ABS_RY) to 128 (0x80)
> in the common ps_gamepad_create() function.
>
> This aligns the kernel's initial state with the hardware's expected
> neutral state, ensuring that the first report (at 128) produces no
> delta and thus, no spurious event.
>
> Signed-off-by: Siarhei Vishniakou <svv@google.com>
> ---
> drivers/hid/hid-playstation.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> index 1468fb11e39d..fd9d3c901743 100644
> --- a/drivers/hid/hid-playstation.c
> +++ b/drivers/hid/hid-playstation.c
> @@ -718,12 +718,19 @@ static struct input_dev *ps_gamepad_create(struct hid_device *hdev,
> if (IS_ERR(gamepad))
> return ERR_CAST(gamepad);
>
> + /* Set initial resting state for joysticks to 128 (center) */
> input_set_abs_params(gamepad, ABS_X, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_X].value = 128;
> input_set_abs_params(gamepad, ABS_Y, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_Y].value = 128;
> input_set_abs_params(gamepad, ABS_Z, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_Z].value = 128;
> input_set_abs_params(gamepad, ABS_RX, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RX].value = 128;
> input_set_abs_params(gamepad, ABS_RY, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RY].value = 128;
> input_set_abs_params(gamepad, ABS_RZ, 0, 255, 0, 0);
> + gamepad->absinfo[ABS_RZ].value = 128;
>
> input_set_abs_params(gamepad, ABS_HAT0X, -1, 1, 0, 0);
> input_set_abs_params(gamepad, ABS_HAT0Y, -1, 1, 0, 0);
> --
> 2.51.0.536.g15c5d4f767-goog
>
My apologies, I sent the wrong version of this patch. The values for
Z, RZ should not have changed. I will resend.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-11 23:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-11 23:38 [PATCH] HID: playstation: Center initial joystick axes to prevent spurious events Siarhei Vishniakou
2025-11-11 23:40 ` Siarhei Vishniakou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).