[PATCH 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13

Robin Everaars posted 2 patches 1 month, 3 weeks ago
There is a newer version of this series
drivers/platform/x86/asus-wmi.c | 55 +++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 3 deletions(-)
[PATCH 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13
Posted by Robin Everaars 1 month, 3 weeks ago
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

[PATCH v2 0/2] platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13
Posted by Robin Everaars 1 month, 3 weeks ago
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

[PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
Posted by Robin Everaars 1 month, 3 weeks ago
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

Re: [PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
Posted by Hans de Goede 1 month, 3 weeks ago
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);
>  }
[PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code
Posted by Robin Everaars 1 month, 3 weeks ago
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

Re: [PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code
Posted by Hans de Goede 1 month, 3 weeks ago
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