The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13
@ 2026-08-05 10:15 Robin Everaars
  2026-08-05 10:15 ` [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Robin Everaars @ 2026-08-05 10:15 UTC (permalink / raw)
  To: hansg, ilpo.jarvinen
  Cc: corentin.chary, luke, denis.benato, platform-driver-x86,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2176 bytes --]

SW_TABLET_MODE never moves on an ASUS ProArt PX13 (HN7306EAC), and no
tablet_mode_sw value fixes it, because two independent things are in the way.

The first is a devstate quirk. The lid-flip devstate on this machine sets
ASUS_WMI_DSTS_UNKNOWN_BIT alongside the state bit while folded, so
ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000 open and 0x00010003 folded.
asus_wmi_get_devstate_simple() reads that bit as "state not known" and fails
with -ENODEV, throwing away a valid state that is sitting in bit 0.

The second is the devid/notify pairing. asus-wmi ties the devid it polls to the
one notify code it listens for, and tablet_mode_sw only offers fixed pairings.
This chassis reads the hinge at LID_FLIP_ROG but notifies with NOTIFY_LID_FLIP,
a combination no value covers: tablet_mode_sw=2 pins the switch on and suspends
the internal keyboard for good, while tablet_mode_sw=3 polls the right devid but
never hears the event.

Patch 1 adds a tablet-specific read that gates on
 the presence bit only, used
from the two tablet-switch paths and leaving every other
asus_wmi_get_devstate_simple() caller alone. Patch 2 accepts either lid-flip
notify code once a lid-flip switch is registered; both are the same "lid flip
action" event and both already map to KEY_PROG2 in the sparse keymap.

Machines with a keyboard-dock switch notify with 0x75 and are unaffected, and
with no switch registered the event code is 0 so the old equality test is what
still runs.

Tested on the one machine I have, an ASUS ProArt PX13 HN7306EAC: six clean
SW_TABLET_MODE transitions over three fold cycles with no stray KEY_PROG2, and
libinput suspends the internal keyboard and touchpad on fold and restores them
on unfold. I do not have another convertible to check the untouched paths on
hardware, so review of the dock case would be welcome.

Robin Everaars (2):
  platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
  platform/x86: asus-wmi: accept either lid-
flip notify code

 drivers/platform/x86/asus-wmi.c | 55 +++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 3 deletions(-)


base-commit: aca39607c1734ed976fdd65deb75b3555a5a0326
-- 
2.55.0


[-- Attachment #1.2: publickey - robineveraars@pm.me - 0x8B6BA132.asc --]
[-- Type: application/pgp-keys, Size: 889 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 322 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
  2026-08-05 10:15 [PATCH 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
@ 2026-08-05 10:15 ` Robin Everaars
  2026-08-05 12:07   ` Denis Benato
  2026-08-05 10:15 ` [PATCH 2/2] platform/x86: asus-wmi: accept either lid-flip notify code Robin Everaars
  2026-08-05 14:11 ` [PATCH v2 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
  2 siblings, 1 reply; 12+ messages in thread
From: Robin Everaars @ 2026-08-05 10:15 UTC (permalink / raw)
  To: hansg, ilpo.jarvinen
  Cc: corentin.chary, luke, denis.benato, platform-driver-x86,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 3066 bytes --]

On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
alongside the state bit while the machine is folded. Measured on an ASUS
ProArt PX13 (HN7306EAC), ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000
open and 0x00010003 folded, that is presence | status | UNKNOWN.

asus_wmi_get_devstate_simple() treats that bit as "the state is not known"
and fails the call with -ENODEV, so asus_wmi_tablet_mode_get_state()
discards a perfectly good state sitting in bit 0 and SW_TABLET_MODE never
moves.

Add asus_wmi_tablet_sw_get_state(), which gates on the presence bit only
and returns the status bit. Use it from the two tablet-switch paths. Every
other caller of asus_wmi_get_devstate_simple() is untouched, so the change
is confined to the tablet switch.

Signed-off-by: Robin Everaars <robineveraars@pm.me>
---
 drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86
/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 8610663b8..f68fd2bcd 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -706,12 +706,40 @@ static void asus_wmi_tablet_sw_report(struct asus_wmi *asus, bool value)
 	input_sync(asus->inputdev);
 }
 
+/*
+ * Read the lid-flip state directly rather than through
+ * asus_wmi_get_devstate_simple().
+ *
+ * On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
+ * alongside the state bit while folded. Measured on an ASUS ProArt PX13
+ * (HN7306EAC), devid ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000 open and
+ * 0x00010003 folded, i.e. presence | state | UNKNOWN. The generic helper reads
+ * that bit as "the state is not known" and rejects the whole call with -ENODEV,
+ * so asus_wmi_tablet_mode_get_state() discards a perfectly good state sitting in
+ * bit 0 and the switch never moves. Only presence gates the value here, which is
+ * safe because this path serves 
the tablet switch alone.
+ */
+static int asus_wmi_tablet_sw_get_state(struct asus_wmi *asus, u32 dev_id)
+{
+	u32 retval;
+	int err;
+
+	err = asus_wmi_get_devstate(asus, dev_id, &retval);
+	if (err < 0)
+		return err;
+
+	if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT))
+		return -ENODEV;
+
+	return !!(retval & ASUS_WMI_DSTS_STATUS_BIT);
+}
+
 static void asus_wmi_tablet_sw_init(struct asus_wmi *asus, u32 dev_id, int event_code)
 {
 	struct device *dev = &asus->platform_device->dev;
 	int result;
 
-	result = asus_wmi_get_devstate_simple(asus, dev_id);
+	result = asus_wmi_tablet_sw_get_state(asus, dev_id);
 	if (result >= 0) {
 		input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE);
 		asus_wmi_tablet_sw_report(asus, result);
@@ -786,7 +814,7 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
 	if (!asus->tablet_switch_dev_id)
 		return;
 
-	result = asus_wmi_get_devstate_simple(asus, asus->tablet_switch_dev_id);
+	result = asus_wmi
_tablet_sw_get_state(asus, asus->tablet_switch_dev_id);
 	if (result >= 0)
 		asus_wmi_tablet_sw_report(asus, result);
 }
-- 
2.55.0


[-- Attachment #1.2: publickey - robineveraars@pm.me - 0x8B6BA132.asc --]
[-- Type: application/pgp-keys, Size: 889 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 322 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/2] platform/x86: asus-wmi: accept either lid-flip notify code
  2026-08-05 10:15 [PATCH 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
  2026-08-05 10:15 ` [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
@ 2026-08-05 10:15 ` Robin Everaars
  2026-08-05 12:11   ` Denis Benato
  2026-08-05 14:11 ` [PATCH v2 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
  2 siblings, 1 reply; 12+ messages in thread
From: Robin Everaars @ 2026-08-05 10:15 UTC (permalink / raw)
  To: hansg, ilpo.jarvinen
  Cc: corentin.chary, luke, denis.benato, platform-driver-x86,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2844 bytes --]

asus-wmi pairs the devid it polls for the tablet switch with the single
notify code it listens for, and tablet_mode_sw only offers those fixed
pairings. Some convertibles read the hinge at one lid-flip devid but
notify with the other, which no value covers.

The ASUS ProArt PX13 (HN7306EAC) is one. ASUS_WMI_DEVID_LID_FLIP is frozen
at 1 in every pose while ASUS_WMI_DEVID_LID_FLIP_ROG tracks the hinge, yet
folding notifies with NOTIFY_LID_FLIP rather than NOTIFY_LID_FLIP_ROG. So
tablet_mode_sw=2 pins the switch on and suspends the internal keyboard for
good, and tablet_mode_sw=3 reads the right devid but never hears the event.

Accept either lid-flip code once a lid-flip switch is registered. Both are
the same "lid flip action" event and both already map to KEY_PROG2 in the
sparse keymap. Machines with a keyboard-dock switch notify with 0x75 and
are unaffected, and with no switch registered the event code is 0 and the
old equality test still runs.

Signed-off-by: Robin 
Everaars <robineveraars@pm.me>
---
 drivers/platform/x86/asus-wmi.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index f68fd2bcd..bcbb98529 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -819,6 +819,27 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
 		asus_wmi_tablet_sw_report(asus, result);
 }
 
+/*
+ * Some convertibles report the hinge at one lid-flip devid while their firmware
+ * notifies with the other lid-flip code, a pairing no tablet_mode_sw value
+ * covers. The ASUS ProArt PX13 (HN7306EAC) is one: ASUS_WMI_DEVID_LID_FLIP is
+ * frozen at 1 in every pose while ASUS_WMI_DEVID_LID_FLIP_ROG tracks the hinge,
+ * yet the fold notifies with NOTIFY_LID_FLIP rather than NOTIFY_LID_FLIP_ROG.
+ * Accept either code once a lid-flip switch is registered; both are the same
+ * "lid flip action" ev
ent and both already map to KEY_PROG2 in the sparse keymap.
+ */
+static bool asus_wmi_is_tablet_switch_code(struct asus_wmi *asus, int code)
+{
+	if (code == asus->tablet_switch_event_code)
+		return true;
+
+	if (asus->tablet_switch_event_code == NOTIFY_LID_FLIP ||
+	    asus->tablet_switch_event_code == NOTIFY_LID_FLIP_ROG)
+		return code == NOTIFY_LID_FLIP || code == NOTIFY_LID_FLIP_ROG;
+
+	return false;
+}
+
 /* Charging mode, 1=Barrel, 2=USB ******************************************/
 #if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS)
 static ssize_t charge_mode_show(struct device *dev,
@@ -4674,7 +4695,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
 		return;
 	}
 
-	if (code == asus->tablet_switch_event_code) {
+	if (asus_wmi_is_tablet_switch_code(asus, code)) {
 		asus_wmi_tablet_mode_get_state(asus);
 		return;
 	}
-- 
2.55.0


[-- Attachment #1.2: publickey - robineveraars@pm.me - 0x8B6BA132.asc --]
[-- Type: application/pgp-keys, Size: 889 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 322 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
  2026-08-05 10:15 ` [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
@ 2026-08-05 12:07   ` Denis Benato
  2026-08-10 13:20     ` Hans de Goede
  0 siblings, 1 reply; 12+ messages in thread
From: Denis Benato @ 2026-08-05 12:07 UTC (permalink / raw)
  To: Robin Everaars, hansg, ilpo.jarvinen
  Cc: corentin.chary, luke, platform-driver-x86, linux-kernel


On 8/5/26 12:15, Robin Everaars wrote:
> On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
> alongside the state bit while the machine is folded. Measured on an ASUS
> ProArt PX13 (HN7306EAC), ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000
> open and 0x00010003 folded, that is presence | status | UNKNOWN.
>
> asus_wmi_get_devstate_simple() treats that bit as "the state is not known"
> and fails the call with -ENODEV, so asus_wmi_tablet_mode_get_state()
> discards a perfectly good state sitting in bit 0 and SW_TABLET_MODE never
> moves.
>
> Add asus_wmi_tablet_sw_get_state(), which gates on the presence bit only
> and returns the status bit. Use it from the two tablet-switch paths. Every
> other caller of asus_wmi_get_devstate_simple() is untouched, so the change
> is confined to the tablet switch.
Hi Robin,

Thanks for looking into this!
> Signed-off-by: Robin Everaars <robineveraars@pm.me>
> ---
>  drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++--
>  1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/x86
> /asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index 8610663b8..f68fd2bcd 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -706,12 +706,40 @@ static void asus_wmi_tablet_sw_report(struct asus_wmi *asus, bool value)
>  	input_sync(asus->inputdev);
>  }
>  
> +/*
> + * Read the lid-flip state directly rather than through
> + * asus_wmi_get_devstate_simple().
> + *
> + * On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
> + * alongside the state bit while folded. Measured on an ASUS ProArt PX13
> + * (HN7306EAC), devid ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000 open and
> + * 0x00010003 folded, i.e. presence | state | UNKNOWN. The generic helper reads
> + * that bit as "the state is not known" and rejects the whole call with -ENODEV,
> + * so asus_wmi_tablet_mode_get_state() discards a perfectly good state sitting in
> + * bit 0 and the switch never moves. Only presence gates the value here, which is
> + * safe because this path serves 
> the tablet switch alone.
> + */
> +static int asus_wmi_tablet_sw_get_state(struct asus_wmi *asus, u32 dev_id)
> +{
> +	u32 retval;
> +	int err;
> +
> +	err = asus_wmi_get_devstate(asus, dev_id, &retval);
> +	if (err < 0)
> +		return err;
> +
> +	if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT))
> +		return -ENODEV;
There are FIELD_GET and many more macros to do this,
please use those as it makes the code easier to read.
> +
> +	return !!(retval & ASUS_WMI_DSTS_STATUS_BIT);
Same here
> +}
> +
>  static void asus_wmi_tablet_sw_init(struct asus_wmi *asus, u32 dev_id, int event_code)
>  {
>  	struct device *dev = &asus->platform_device->dev;
>  	int result;
>  
> -	result = asus_wmi_get_devstate_simple(asus, dev_id);
> +	result = asus_wmi_tablet_sw_get_state(asus, dev_id);
>  	if (result >= 0) {
>  		input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE);
>  		asus_wmi_tablet_sw_report(asus, result);
> @@ -786,7 +814,7 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
>  	if (!asus->tablet_switch_dev_id)
>  		return;
>  
> -	result = asus_wmi_get_devstate_simple(asus, asus->tablet_switch_dev_id);
> +	result = asus_wmi
> _tablet_sw_get_state(asus, asus->tablet_switch_dev_id);
>  	if (result >= 0)
>  		asus_wmi_tablet_sw_report(asus, result);
>  }

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/2] platform/x86: asus-wmi: accept either lid-flip notify code
  2026-08-05 10:15 ` [PATCH 2/2] platform/x86: asus-wmi: accept either lid-flip notify code Robin Everaars
@ 2026-08-05 12:11   ` Denis Benato
  0 siblings, 0 replies; 12+ messages in thread
From: Denis Benato @ 2026-08-05 12:11 UTC (permalink / raw)
  To: Robin Everaars, hansg, ilpo.jarvinen
  Cc: corentin.chary, luke, platform-driver-x86, linux-kernel


On 8/5/26 12:15, Robin Everaars wrote:
> asus-wmi pairs the devid it polls for the tablet switch with the single
> notify code it listens for, and tablet_mode_sw only offers those fixed
> pairings. Some convertibles read the hinge at one lid-flip devid but
> notify with the other, which no value covers.
>
> The ASUS ProArt PX13 (HN7306EAC) is one. ASUS_WMI_DEVID_LID_FLIP is frozen
> at 1 in every pose while ASUS_WMI_DEVID_LID_FLIP_ROG tracks the hinge, yet
> folding notifies with NOTIFY_LID_FLIP rather than NOTIFY_LID_FLIP_ROG. So
> tablet_mode_sw=2 pins the switch on and suspends the internal keyboard for
> good, and tablet_mode_sw=3 reads the right devid but never hears the event.
>
> Accept either lid-flip code once a lid-flip switch is registered. Both are
> the same "lid flip action" event and both already map to KEY_PROG2 in the
> sparse keymap. Machines with a keyboard-dock switch notify with 0x75 and
> are unaffected, and with no switch registered the event code is 0 and the
> old equality test still runs.
>
> Signed-off-by: Robin 
> Everaars <robineveraars@pm.me>
> ---
>  drivers/platform/x86/asus-wmi.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index f68fd2bcd..bcbb98529 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -819,6 +819,27 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
>  		asus_wmi_tablet_sw_report(asus, result);
>  }
>  
> +/*
> + * Some convertibles report the hinge at one lid-flip devid while their firmware
> + * notifies with the other lid-flip code, a pairing no tablet_mode_sw value
> + * covers. The ASUS ProArt PX13 (HN7306EAC) is one: ASUS_WMI_DEVID_LID_FLIP is
> + * frozen at 1 in every pose while ASUS_WMI_DEVID_LID_FLIP_ROG tracks the hinge,
> + * yet the fold notifies with NOTIFY_LID_FLIP rather than NOTIFY_LID_FLIP_ROG.
> + * Accept either code once a lid-flip switch is registered; both are the same
> + * "lid flip action" ev
> ent and both already map to KEY_PROG2 in the sparse keymap.
> + */
You may want to complete this kernel doc blockm adding at the beginning
function_name() - brief

and below the description params and return.
> +static bool asus_wmi_is_tablet_switch_code(struct asus_wmi *asus, int code)
> +{
> +	if (code == asus->tablet_switch_event_code)
> +		return true;
> +
> +	if (asus->tablet_switch_event_code == NOTIFY_LID_FLIP ||
> +	    asus->tablet_switch_event_code == NOTIFY_LID_FLIP_ROG)
> +		return code == NOTIFY_LID_FLIP || code == NOTIFY_LID_FLIP_ROG;
> +
> +	return false;
> +}
> +
>  /* Charging mode, 1=Barrel, 2=USB ******************************************/
>  #if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS)
>  static ssize_t charge_mode_show(struct device *dev,
> @@ -4674,7 +4695,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
>  		return;
>  	}
>  
> -	if (code == asus->tablet_switch_event_code) {
> +	if (asus_wmi_is_tablet_switch_code(asus, code)) {
>  		asus_wmi_tablet_mode_get_state(asus);
>  		return;
>  	}

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13
  2026-08-05 10:15 [PATCH 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
  2026-08-05 10:15 ` [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
  2026-08-05 10:15 ` [PATCH 2/2] platform/x86: asus-wmi: accept either lid-flip notify code Robin Everaars
@ 2026-08-05 14:11 ` Robin Everaars
  2026-08-05 14:11   ` [PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
  2026-08-05 14:11   ` [PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code Robin Everaars
  2 siblings, 2 replies; 12+ messages in thread
From: Robin Everaars @ 2026-08-05 14:11 UTC (permalink / raw)
  To: hansg, ilpo.jarvinen
  Cc: corentin.chary, luke, denis.benato, platform-driver-x86,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2998 bytes --]

SW_TABLET_MODE never moves on an ASUS ProArt PX13 (HN7306EAC), and no
tablet_mode_sw value fixes it, because two independent things are in the way.

The first is a devstate quirk. The lid-flip devstate on this machine sets
ASUS_WMI_DSTS_UNKNOWN_BIT alongside the state bit while folded, so
ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000 open and 0x00010003 folded.
asus_wmi_get_devstate_simple() reads that bit as "state not known" and fails
with -ENODEV, throwing away a valid state that is sitting in bit 0.

The second is the devid/notify pairing. asus-wmi ties the devid it polls to the
one notify code it listens for, and tablet_mode_sw only offers fixed pairings.
This chassis reads the hinge at LID_FLIP_ROG but notifies with NOTIFY_LID_FLIP,
a combination no value covers: tablet_mode_sw=2 pins the switch on and suspends
the internal keyboard for good, while tablet_mode_sw=3 polls the right devid but
never hears the event.

Patch 1 adds a tablet-specific read that gates on
 the presence bit only, used
from the two tablet-switch paths and leaving every other
asus_wmi_get_devstate_simple() caller alone. Patch 2 accepts either lid-flip
notify code once a lid-flip switch is registered; both are the same "lid flip
action" event and both already map to KEY_PROG2 in the sparse keymap.

Machines with a keyboard-dock switch notify with 0x75 and are unaffected, and
with no switch registered the event code is 0 so the old equality test is what
still runs.

Tested on the one machine I have, an ASUS ProArt PX13 HN7306EAC: six clean
SW_TABLET_MODE transitions over three fold cycles with no stray KEY_PROG2, and
libinput suspends the internal keyboard and touchpad on fold and restores them
on unfold. I do not have another convertible to check the untouched paths on
hardware, so review of the dock case would be welcome.

Changes in v2:
 - Patch 1: use FIELD_GET() for the presence and state bits instead of open
   mask-and-test, and add the linux/bitfiel
d.h include it needs. Suggested by
   Denis Benato. This also drops the !! on the return, since FIELD_GET already
   yields 0 or 1. No functional change; re-tested on the same machine.
 - No other changes. Patch 2 is unchanged.

Note that asus-wmi.c had no FIELD_GET() users before this, and the neighbouring
asus_wmi_dev_is_present() still open-codes the same presence test, so the file
is now mixed. Happy to send a separate cleanup converting the remaining
ASUS_WMI_DSTS_* users, and the masks in asus-wmi.h to BIT(), if that is wanted;
it seemed wrong to fold unrelated churn into a fix.

v1: https://lore.kernel.org/platform-driver-x86/20260805101502.235668-1-robineveraars@pm.me/

Robin Everaars (2):
  platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
  platform/x86: asus-wmi: accept either lid-flip notify code

 drivers/platform/x86/asus-wmi.c | 56 +++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 3 deletions(-)


base-commit: aca
39607c1734ed976fdd65deb75b3555a5a0326
-- 
2.55.0


[-- Attachment #1.2: publickey - robineveraars@pm.me - 0x8B6BA132.asc --]
[-- Type: application/pgp-keys, Size: 889 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 322 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
  2026-08-05 14:11 ` [PATCH v2 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
@ 2026-08-05 14:11   ` Robin Everaars
  2026-08-10 13:31     ` Hans de Goede
  2026-08-05 14:11   ` [PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code Robin Everaars
  1 sibling, 1 reply; 12+ messages in thread
From: Robin Everaars @ 2026-08-05 14:11 UTC (permalink / raw)
  To: hansg, ilpo.jarvinen
  Cc: corentin.chary, luke, denis.benato, platform-driver-x86,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 3405 bytes --]

On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
alongside the state bit while the machine is folded. Measured on an ASUS
ProArt PX13 (HN7306EAC), ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000
open and 0x00010003 folded, that is presence | status | UNKNOWN.

asus_wmi_get_devstate_simple() treats that bit as "the state is not known"
and fails the call with -ENODEV, so asus_wmi_tablet_mode_get_state()
discards a perfectly good state sitting in bit 0 and SW_TABLET_MODE never
moves.

Add asus_wmi_tablet_sw_get_state(), which gates on the presence bit only
and returns the status bit. Use it from the two tablet-switch paths. Every
other caller of asus_wmi_get_devstate_simple() is untouched, so the change
is confined to the tablet switch.

Signed-off-by: Robin Everaars <robineveraars@pm.me>
---
v2: use FIELD_GET() for both bits and add the linux/bitfield.h include,
    per Denis Benato. Drops the !! on the return. No functional change.

 drivers/p
latform/x86/asus-wmi.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 8610663..dce4d07 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -15,6 +15,7 @@
 
 #include <linux/acpi.h>
 #include <linux/backlight.h>
+#include <linux/bitfield.h>
 #include <linux/bits.h>
 #include <linux/debugfs.h>
 #include <linux/delay.h>
@@ -706,12 +707,40 @@ static void asus_wmi_tablet_sw_report(struct asus_wmi *asus, bool value)
 	input_sync(asus->inputdev);
 }
 
+/*
+ * Read the lid-flip state directly rather than through
+ * asus_wmi_get_devstate_simple().
+ *
+ * On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
+ * alongside the state bit while folded. Measured on an ASUS ProArt PX13
+ * (HN7306EAC), devid ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000 open and
+ * 0x00010003 folded, i.e. pre
sence | state | UNKNOWN. The generic helper reads
+ * that bit as "the state is not known" and rejects the whole call with -ENODEV,
+ * so asus_wmi_tablet_mode_get_state() discards a perfectly good state sitting in
+ * bit 0 and the switch never moves. Only presence gates the value here, which is
+ * safe because this path serves the tablet switch alone.
+ */
+static int asus_wmi_tablet_sw_get_state(struct asus_wmi *asus, u32 dev_id)
+{
+	u32 retval;
+	int err;
+
+	err = asus_wmi_get_devstate(asus, dev_id, &retval);
+	if (err < 0)
+		return err;
+
+	if (!FIELD_GET(ASUS_WMI_DSTS_PRESENCE_BIT, retval))
+		return -ENODEV;
+
+	return FIELD_GET(ASUS_WMI_DSTS_STATUS_BIT, retval);
+}
+
 static void asus_wmi_tablet_sw_init(struct asus_wmi *asus, u32 dev_id, int event_code)
 {
 	struct device *dev = &asus->platform_device->dev;
 	int result;
 
-	result = asus_wmi_get_devstate_simple(asus, dev_id);
+	result = asus_wmi_tablet_sw_get_state(asus, dev_id);
 	if (result >=
 0) {
 		input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE);
 		asus_wmi_tablet_sw_report(asus, result);
@@ -786,7 +815,7 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
 	if (!asus->tablet_switch_dev_id)
 		return;
 
-	result = asus_wmi_get_devstate_simple(asus, asus->tablet_switch_dev_id);
+	result = asus_wmi_tablet_sw_get_state(asus, asus->tablet_switch_dev_id);
 	if (result >= 0)
 		asus_wmi_tablet_sw_report(asus, result);
 }
-- 
2.55.0


[-- Attachment #1.2: publickey - robineveraars@pm.me - 0x8B6BA132.asc --]
[-- Type: application/pgp-keys, Size: 889 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 322 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code
  2026-08-05 14:11 ` [PATCH v2 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
  2026-08-05 14:11   ` [PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
@ 2026-08-05 14:11   ` Robin Everaars
  2026-08-10 13:37     ` Hans de Goede
  1 sibling, 1 reply; 12+ messages in thread
From: Robin Everaars @ 2026-08-05 14:11 UTC (permalink / raw)
  To: hansg, ilpo.jarvinen
  Cc: corentin.chary, luke, denis.benato, platform-driver-x86,
	linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 2840 bytes --]

asus-wmi pairs the devid it polls for the tablet switch with the single
notify code it listens for, and tablet_mode_sw only offers those fixed
pairings. Some convertibles read the hinge at one lid-flip devid but
notify with the other, which no value covers.

The ASUS ProArt PX13 (HN7306EAC) is one. ASUS_WMI_DEVID_LID_FLIP is frozen
at 1 in every pose while ASUS_WMI_DEVID_LID_FLIP_ROG tracks the hinge, yet
folding notifies with NOTIFY_LID_FLIP rather than NOTIFY_LID_FLIP_ROG. So
tablet_mode_sw=2 pins the switch on and suspends the internal keyboard for
good, and tablet_mode_sw=3 reads the right devid but never hears the event.

Accept either lid-flip code once a lid-flip switch is registered. Both are
the same "lid flip action" event and both already map to KEY_PROG2 in the
sparse keymap. Machines with a keyboard-dock switch notify with 0x75 and
are unaffected, and with no switch registered the event code is 0 and the
old equality test still runs.

Signed-off-by: Robin 
Everaars <robineveraars@pm.me>
---
 drivers/platform/x86/asus-wmi.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index dce4d07..8b63fb4 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -820,6 +820,27 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
 		asus_wmi_tablet_sw_report(asus, result);
 }
 
+/*
+ * Some convertibles report the hinge at one lid-flip devid while their firmware
+ * notifies with the other lid-flip code, a pairing no tablet_mode_sw value
+ * covers. The ASUS ProArt PX13 (HN7306EAC) is one: ASUS_WMI_DEVID_LID_FLIP is
+ * frozen at 1 in every pose while ASUS_WMI_DEVID_LID_FLIP_ROG tracks the hinge,
+ * yet the fold notifies with NOTIFY_LID_FLIP rather than NOTIFY_LID_FLIP_ROG.
+ * Accept either code once a lid-flip switch is registered; both are the same
+ * "lid flip action" event 
and both already map to KEY_PROG2 in the sparse keymap.
+ */
+static bool asus_wmi_is_tablet_switch_code(struct asus_wmi *asus, int code)
+{
+	if (code == asus->tablet_switch_event_code)
+		return true;
+
+	if (asus->tablet_switch_event_code == NOTIFY_LID_FLIP ||
+	    asus->tablet_switch_event_code == NOTIFY_LID_FLIP_ROG)
+		return code == NOTIFY_LID_FLIP || code == NOTIFY_LID_FLIP_ROG;
+
+	return false;
+}
+
 /* Charging mode, 1=Barrel, 2=USB ******************************************/
 #if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS)
 static ssize_t charge_mode_show(struct device *dev,
@@ -4675,7 +4696,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
 		return;
 	}
 
-	if (code == asus->tablet_switch_event_code) {
+	if (asus_wmi_is_tablet_switch_code(asus, code)) {
 		asus_wmi_tablet_mode_get_state(asus);
 		return;
 	}
-- 
2.55.0


[-- Attachment #1.2: publickey - robineveraars@pm.me - 0x8B6BA132.asc --]
[-- Type: application/pgp-keys, Size: 889 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 322 bytes --]

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
  2026-08-05 12:07   ` Denis Benato
@ 2026-08-10 13:20     ` Hans de Goede
  2026-08-10 13:31       ` Denis Benato
  0 siblings, 1 reply; 12+ messages in thread
From: Hans de Goede @ 2026-08-10 13:20 UTC (permalink / raw)
  To: Denis Benato, Robin Everaars, ilpo.jarvinen
  Cc: corentin.chary, luke, platform-driver-x86, linux-kernel

Hi Denis,

On 5-Aug-26 2:07 PM, Denis Benato wrote:
> 
> On 8/5/26 12:15, Robin Everaars wrote:
>> On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
>> alongside the state bit while the machine is folded. Measured on an ASUS
>> ProArt PX13 (HN7306EAC), ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000
>> open and 0x00010003 folded, that is presence | status | UNKNOWN.
>>
>> asus_wmi_get_devstate_simple() treats that bit as "the state is not known"
>> and fails the call with -ENODEV, so asus_wmi_tablet_mode_get_state()
>> discards a perfectly good state sitting in bit 0 and SW_TABLET_MODE never
>> moves.
>>
>> Add asus_wmi_tablet_sw_get_state(), which gates on the presence bit only
>> and returns the status bit. Use it from the two tablet-switch paths. Every
>> other caller of asus_wmi_get_devstate_simple() is untouched, so the change
>> is confined to the tablet switch.
> Hi Robin,
> 
> Thanks for looking into this!
>> Signed-off-by: Robin Everaars <robineveraars@pm.me>
>> ---
>>  drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++--
>>  1 file changed, 30 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/platform/x86
>> /asus-wmi.c b/drivers/platform/x86/asus-wmi.c
>> index 8610663b8..f68fd2bcd 100644
>> --- a/drivers/platform/x86/asus-wmi.c
>> +++ b/drivers/platform/x86/asus-wmi.c
>> @@ -706,12 +706,40 @@ static void asus_wmi_tablet_sw_report(struct asus_wmi *asus, bool value)
>>  	input_sync(asus->inputdev);
>>  }
>>  
>> +/*
>> + * Read the lid-flip state directly rather than through
>> + * asus_wmi_get_devstate_simple().
>> + *
>> + * On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
>> + * alongside the state bit while folded. Measured on an ASUS ProArt PX13
>> + * (HN7306EAC), devid ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000 open and
>> + * 0x00010003 folded, i.e. presence | state | UNKNOWN. The generic helper reads
>> + * that bit as "the state is not known" and rejects the whole call with -ENODEV,
>> + * so asus_wmi_tablet_mode_get_state() discards a perfectly good state sitting in
>> + * bit 0 and the switch never moves. Only presence gates the value here, which is
>> + * safe because this path serves 
>> the tablet switch alone.
>> + */
>> +static int asus_wmi_tablet_sw_get_state(struct asus_wmi *asus, u32 dev_id)
>> +{
>> +	u32 retval;
>> +	int err;
>> +
>> +	err = asus_wmi_get_devstate(asus, dev_id, &retval);
>> +	if (err < 0)
>> +		return err;
>> +
>> +	if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT))
>> +		return -ENODEV;
> There are FIELD_GET and many more macros to do this,
> please use those as it makes the code easier to read.

I appreciate that you are trying to help out with reviewing, but in this case this
is not good advice.

Using FIELD_GET is good advice for new code, but for an existing driver it is
more important to be consistent and so far no code in asus-wmi.c is using
FIELD_GET so adding this just makes the whole driver harder to read since
now it is mixing 2 styles.

Regards,

Hans



>> +
>> +	return !!(retval & ASUS_WMI_DSTS_STATUS_BIT);
> Same here
>> +}
>> +
>>  static void asus_wmi_tablet_sw_init(struct asus_wmi *asus, u32 dev_id, int event_code)
>>  {
>>  	struct device *dev = &asus->platform_device->dev;
>>  	int result;
>>  
>> -	result = asus_wmi_get_devstate_simple(asus, dev_id);
>> +	result = asus_wmi_tablet_sw_get_state(asus, dev_id);
>>  	if (result >= 0) {
>>  		input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE);
>>  		asus_wmi_tablet_sw_report(asus, result);
>> @@ -786,7 +814,7 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
>>  	if (!asus->tablet_switch_dev_id)
>>  		return;
>>  
>> -	result = asus_wmi_get_devstate_simple(asus, asus->tablet_switch_dev_id);
>> +	result = asus_wmi
>> _tablet_sw_get_state(asus, asus->tablet_switch_dev_id);
>>  	if (result >= 0)
>>  		asus_wmi_tablet_sw_report(asus, result);
>>  }


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
  2026-08-10 13:20     ` Hans de Goede
@ 2026-08-10 13:31       ` Denis Benato
  0 siblings, 0 replies; 12+ messages in thread
From: Denis Benato @ 2026-08-10 13:31 UTC (permalink / raw)
  To: Hans de Goede, Robin Everaars, ilpo.jarvinen
  Cc: corentin.chary, luke, platform-driver-x86, linux-kernel


On 8/10/26 15:20, Hans de Goede wrote:
> Hi Denis,
>
> On 5-Aug-26 2:07 PM, Denis Benato wrote:
>> On 8/5/26 12:15, Robin Everaars wrote:
>>> On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
>>> alongside the state bit while the machine is folded. Measured on an ASUS
>>> ProArt PX13 (HN7306EAC), ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000
>>> open and 0x00010003 folded, that is presence | status | UNKNOWN.
>>>
>>> asus_wmi_get_devstate_simple() treats that bit as "the state is not known"
>>> and fails the call with -ENODEV, so asus_wmi_tablet_mode_get_state()
>>> discards a perfectly good state sitting in bit 0 and SW_TABLET_MODE never
>>> moves.
>>>
>>> Add asus_wmi_tablet_sw_get_state(), which gates on the presence bit only
>>> and returns the status bit. Use it from the two tablet-switch paths. Every
>>> other caller of asus_wmi_get_devstate_simple() is untouched, so the change
>>> is confined to the tablet switch.
>> Hi Robin,
>>
>> Thanks for looking into this!
>>> Signed-off-by: Robin Everaars <robineveraars@pm.me>
>>> ---
>>>  drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++--
>>>  1 file changed, 30 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/platform/x86
>>> /asus-wmi.c b/drivers/platform/x86/asus-wmi.c
>>> index 8610663b8..f68fd2bcd 100644
>>> --- a/drivers/platform/x86/asus-wmi.c
>>> +++ b/drivers/platform/x86/asus-wmi.c
>>> @@ -706,12 +706,40 @@ static void asus_wmi_tablet_sw_report(struct asus_wmi *asus, bool value)
>>>  	input_sync(asus->inputdev);
>>>  }
>>>  
>>> +/*
>>> + * Read the lid-flip state directly rather than through
>>> + * asus_wmi_get_devstate_simple().
>>> + *
>>> + * On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
>>> + * alongside the state bit while folded. Measured on an ASUS ProArt PX13
>>> + * (HN7306EAC), devid ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000 open and
>>> + * 0x00010003 folded, i.e. presence | state | UNKNOWN. The generic helper reads
>>> + * that bit as "the state is not known" and rejects the whole call with -ENODEV,
>>> + * so asus_wmi_tablet_mode_get_state() discards a perfectly good state sitting in
>>> + * bit 0 and the switch never moves. Only presence gates the value here, which is
>>> + * safe because this path serves 
>>> the tablet switch alone.
>>> + */
>>> +static int asus_wmi_tablet_sw_get_state(struct asus_wmi *asus, u32 dev_id)
>>> +{
>>> +	u32 retval;
>>> +	int err;
>>> +
>>> +	err = asus_wmi_get_devstate(asus, dev_id, &retval);
>>> +	if (err < 0)
>>> +		return err;
>>> +
>>> +	if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT))
>>> +		return -ENODEV;
>> There are FIELD_GET and many more macros to do this,
>> please use those as it makes the code easier to read.
> I appreciate that you are trying to help out with reviewing, but in this case this
> is not good advice.
>
> Using FIELD_GET is good advice for new code, but for an existing driver it is
> more important to be consistent and so far no code in asus-wmi.c is using
> FIELD_GET so adding this just makes the whole driver harder to read since
> now it is mixing 2 styles.
Aaaah, my bad, sorry.

> Regards,
>
> Hans
>
>
>
>>> +
>>> +	return !!(retval & ASUS_WMI_DSTS_STATUS_BIT);
>> Same here
>>> +}
>>> +
>>>  static void asus_wmi_tablet_sw_init(struct asus_wmi *asus, u32 dev_id, int event_code)
>>>  {
>>>  	struct device *dev = &asus->platform_device->dev;
>>>  	int result;
>>>  
>>> -	result = asus_wmi_get_devstate_simple(asus, dev_id);
>>> +	result = asus_wmi_tablet_sw_get_state(asus, dev_id);
>>>  	if (result >= 0) {
>>>  		input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE);
>>>  		asus_wmi_tablet_sw_report(asus, result);
>>> @@ -786,7 +814,7 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
>>>  	if (!asus->tablet_switch_dev_id)
>>>  		return;
>>>  
>>> -	result = asus_wmi_get_devstate_simple(asus, asus->tablet_switch_dev_id);
>>> +	result = asus_wmi
>>> _tablet_sw_get_state(asus, asus->tablet_switch_dev_id);
>>>  	if (result >= 0)
>>>  		asus_wmi_tablet_sw_report(asus, result);
>>>  }

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
  2026-08-05 14:11   ` [PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
@ 2026-08-10 13:31     ` Hans de Goede
  0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2026-08-10 13:31 UTC (permalink / raw)
  To: Robin Everaars, ilpo.jarvinen
  Cc: corentin.chary, luke, denis.benato, platform-driver-x86,
	linux-kernel

Hi,

Thank you for your patches!

On 5-Aug-26 4:11 PM, Robin Everaars wrote:
> On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
> alongside the state bit while the machine is folded. Measured on an ASUS
> ProArt PX13 (HN7306EAC), ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000
> open and 0x00010003 folded, that is presence | status | UNKNOWN.
> 
> asus_wmi_get_devstate_simple() treats that bit as "the state is not known"
> and fails the call with -ENODEV, so asus_wmi_tablet_mode_get_state()
> discards a perfectly good state sitting in bit 0 and SW_TABLET_MODE never
> moves.
> 
> Add asus_wmi_tablet_sw_get_state(), which gates on the presence bit only
> and returns the status bit. Use it from the two tablet-switch paths. Every
> other caller of asus_wmi_get_devstate_simple() is untouched, so the change
> is confined to the tablet switch.
> 
> Signed-off-by: Robin Everaars <robineveraars@pm.me>
> ---
> v2: use FIELD_GET() for both bits and add the linux/bitfield.h include,
>     per Denis Benato. Drops the !! on the return. No functional change.
> 
>  drivers/p
> latform/x86/asus-wmi.c | 33 +++++++++++++++++++++++++++++++--
>  1 file changed, 31 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index 8610663..dce4d07 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -15,6 +15,7 @@
>  
>  #include <linux/acpi.h>
>  #include <linux/backlight.h>
> +#include <linux/bitfield.h>
>  #include <linux/bits.h>
>  #include <linux/debugfs.h>
>  #include <linux/delay.h>
> @@ -706,12 +707,40 @@ static void asus_wmi_tablet_sw_report(struct asus_wmi *asus, bool value)
>  	input_sync(asus->inputdev);
>  }
>  
> +/*
> + * Read the lid-flip state directly rather than through
> + * asus_wmi_get_devstate_simple().
> + *
> + * On some convertibles the lid-flip devstate sets ASUS_WMI_DSTS_UNKNOWN_BIT
> + * alongside the state bit while folded. Measured on an ASUS ProArt PX13
> + * (HN7306EAC), devid ASUS_WMI_DEVID_LID_FLIP_ROG answers 0x00010000 open and
> + * 0x00010003 folded, i.e. pre
> sence | state | UNKNOWN. The generic helper reads
> + * that bit as "the state is not known" and rejects the whole call with -ENODEV,
> + * so asus_wmi_tablet_mode_get_state() discards a perfectly good state sitting in
> + * bit 0 and the switch never moves. Only presence gates the value here, which is
> + * safe because this path serves the tablet switch alone.
> + */
> +static int asus_wmi_tablet_sw_get_state(struct asus_wmi *asus, u32 dev_id)
> +{
> +	u32 retval;
> +	int err;
> +
> +	err = asus_wmi_get_devstate(asus, dev_id, &retval);
> +	if (err < 0)
> +		return err;
> +
> +	if (!FIELD_GET(ASUS_WMI_DSTS_PRESENCE_BIT, retval))
> +		return -ENODEV;
> +
> +	return FIELD_GET(ASUS_WMI_DSTS_STATUS_BIT, retval);
> +}
> +

Looking at the existing asus_wmi_get_devstate_bits() code (which
asus_wmi_get_devstate_simple() wraps), the special handling of
ASUS_WMI_DSTS_UNKNOWN_BIT is gated behind mask == ASUS_WMI_DSTS_STATUS_BIT.

And the only caller of asus_wmi_get_devstate_bits() with a mask of
ASUS_WMI_DSTS_STATUS_BIT is asus_wmi_get_devstate_simple().

So IMHO rather then introducing a new function, the special handling of
ASUS_WMI_DSTS_UNKNOWN_BIT should be removed from asus_wmi_get_devstate_bits()
and then added to asus_wmi_get_devstate_simple() changing the latter to e.g. :

static int asus_wmi_get_devstate_simple(struct asus_wmi *asus, u32 dev_id)
{
        int ret;

        ret = asus_wmi_get_devstate_bits(asus, dev_id,
                        ASUS_WMI_DSTS_STATUS_BIT | ASUS_WMI_DSTS_UNKNOWN_BIT);
        if (ret < 0)
                return ret;
        if (ret & ASUS_WMI_DSTS_UNKNOWN_BIT)
                return -ENODEV;

        return ret;
}

and then the 2 asus_wmi_get_devstate_simple(asus, asus->tablet_switch_dev_id)
calls can be replaced with:

	result = asus_wmi_get_devstate_bits(asus, dev_id, ASUS_WMI_DSTS_STATUS_BIT);

without needing to introduce a new special helper.

Regards,

Hans






>  static void asus_wmi_tablet_sw_init(struct asus_wmi *asus, u32 dev_id, int event_code)
>  {
>  	struct device *dev = &asus->platform_device->dev;
>  	int result;
>  
> -	result = asus_wmi_get_devstate_simple(asus, dev_id);
> +	result = asus_wmi_tablet_sw_get_state(asus, dev_id);
>  	if (result >=
>  0) {
>  		input_set_capability(asus->inputdev, EV_SW, SW_TABLET_MODE);
>  		asus_wmi_tablet_sw_report(asus, result);
> @@ -786,7 +815,7 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
>  	if (!asus->tablet_switch_dev_id)
>  		return;
>  
> -	result = asus_wmi_get_devstate_simple(asus, asus->tablet_switch_dev_id);
> +	result = asus_wmi_tablet_sw_get_state(asus, asus->tablet_switch_dev_id);
>  	if (result >= 0)
>  		asus_wmi_tablet_sw_report(asus, result);
>  }


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code
  2026-08-05 14:11   ` [PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code Robin Everaars
@ 2026-08-10 13:37     ` Hans de Goede
  0 siblings, 0 replies; 12+ messages in thread
From: Hans de Goede @ 2026-08-10 13:37 UTC (permalink / raw)
  To: Robin Everaars, ilpo.jarvinen
  Cc: corentin.chary, luke, denis.benato, platform-driver-x86,
	linux-kernel

Hi Robin,

On 5-Aug-26 4:11 PM, Robin Everaars wrote:
> asus-wmi pairs the devid it polls for the tablet switch with the single
> notify code it listens for, and tablet_mode_sw only offers those fixed
> pairings. Some convertibles read the hinge at one lid-flip devid but
> notify with the other, which no value covers.
> 
> The ASUS ProArt PX13 (HN7306EAC) is one. ASUS_WMI_DEVID_LID_FLIP is frozen
> at 1 in every pose while ASUS_WMI_DEVID_LID_FLIP_ROG tracks the hinge, yet
> folding notifies with NOTIFY_LID_FLIP rather than NOTIFY_LID_FLIP_ROG. So
> tablet_mode_sw=2 pins the switch on and suspends the internal keyboard for
> good, and tablet_mode_sw=3 reads the right devid but never hears the event.
> 
> Accept either lid-flip code once a lid-flip switch is registered. Both are
> the same "lid flip action" event and both already map to KEY_PROG2 in the
> sparse keymap. Machines with a keyboard-dock switch notify with 0x75 and
> are unaffected, and with no switch registered the event code is 0 and the
> old equality test still runs.
> 
> Signed-off-by: Robin 
> Everaars <robineveraars@pm.me>

nitpick: Something went wrong with the S-o-b line here

> ---
>  drivers/platform/x86/asus-wmi.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index dce4d07..8b63fb4 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -820,6 +820,27 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus)
>  		asus_wmi_tablet_sw_report(asus, result);
>  }
>  
> +/*
> + * Some convertibles report the hinge at one lid-flip devid while their firmware
> + * notifies with the other lid-flip code, a pairing no tablet_mode_sw value
> + * covers. The ASUS ProArt PX13 (HN7306EAC) is one: ASUS_WMI_DEVID_LID_FLIP is
> + * frozen at 1 in every pose while ASUS_WMI_DEVID_LID_FLIP_ROG tracks the hinge,
> + * yet the fold notifies with NOTIFY_LID_FLIP rather than NOTIFY_LID_FLIP_ROG.
> + * Accept either code once a lid-flip switch is registered; both are the same
> + * "lid flip action" event 
> and both already map to KEY_PROG2 in the sparse keymap.
> + */
> +static bool asus_wmi_is_tablet_switch_code(struct asus_wmi *asus, int code)
> +{
> +	if (code == asus->tablet_switch_event_code)
> +		return true;
> +
> +	if (asus->tablet_switch_event_code == NOTIFY_LID_FLIP ||
> +	    asus->tablet_switch_event_code == NOTIFY_LID_FLIP_ROG)
> +		return code == NOTIFY_LID_FLIP || code == NOTIFY_LID_FLIP_ROG;
> +
> +	return false;
> +}
This seems rather complicated, instead if adding this function please dropall usage of tablet_switch_event_code and ...

> @@ -4675,7 +4696,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
>  		return;
>  	}
>  
> -	if (code == asus->tablet_switch_event_code) {
> +	if (asus_wmi_is_tablet_switch_code(asus, code)) {
>  		asus_wmi_tablet_mode_get_state(asus);
>  		return;
>  	}

Replace the code check if condition with:

        if (code == NOTIFY_KBD_DOCK_CHANGE ||
            code == NOTIFY_LID_FLIP ||
            code == NOTIFY_LID_FLIP_ROG) {

and update the commit message to match.

Regards,

Hans



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-08-10 13:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 10:15 [PATCH 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
2026-08-05 10:15 ` [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
2026-08-05 12:07   ` Denis Benato
2026-08-10 13:20     ` Hans de Goede
2026-08-10 13:31       ` Denis Benato
2026-08-05 10:15 ` [PATCH 2/2] platform/x86: asus-wmi: accept either lid-flip notify code Robin Everaars
2026-08-05 12:11   ` Denis Benato
2026-08-05 14:11 ` [PATCH v2 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13 Robin Everaars
2026-08-05 14:11   ` [PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set Robin Everaars
2026-08-10 13:31     ` Hans de Goede
2026-08-05 14:11   ` [PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code Robin Everaars
2026-08-10 13:37     ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox