platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13
cover platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13
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
Signature · 1 line
2.55.0
PATCH 1/2 platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
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.
--- drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
(quoted diff) +0 -0
/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 8610663b8..f68fd2bcd 100644
drivers/platform/x86/asus-wmi.c +12 -0
@@ -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);
}
Signature · 1 line
2.55.0
Denis Benato
maintainerRe: [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
Quoted 10 lines · Robin Everaars
On some convertibles the lid-flip devstate sets
ASUS_WMI_DSTS_UNKNOWN_BITalongside the state bit while the machine is folded. Measured on an ASUS ProArt PX13 (HN7306EAC),ASUS_WMI_DEVID_LID_FLIP_ROGanswers0x00010000open and0x00010003folded, 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, soasus_wmi_tablet_mode_get_state()discards a perfectly good state sitting in bit 0 andSW_TABLET_MODEnever moves.
Quoted 4 lines
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 ofasus_wmi_get_devstate_simple()is untouched, so the change is confined to the tablet switch.
Hi Robin,
Thanks for looking into this!
Quoted 29 lines
Signed-off-by Robin Everaars <[email protected]>--- drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)(quoted diff) +0
-0/asus-wmi.c
b/drivers/platform/x86/asus-wmi.c
index8610663b8..f68fd2bcd100644drivers/platform/x86/asus-wmi.c +12
-0@@ -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.
+ */drivers/platform/x86/asus-wmi.c +1
-0+static int asus_wmi_tablet_sw_get_state (struct asus_wmi *asus,u32 dev_id)
drivers/platform/x86/asus-wmi.c
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10
-0+{ +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.
drivers/platform/x86/asus-wmi.c
Quoted 2 lines
drivers/platform/x86/asus-wmi.c +2
-0+ +return !!(retval &ASUS_WMI_DSTS_STATUS_BIT );
Same here
Quoted 22 lines
drivers/platform/x86/asus-wmi.c +4
-2+} +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);}
Hans de Goede
maintainerRe: [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
Hi Denis,
Quoted 52 lines · Denis Benato
Quoted 10 lines · Robin Everaars
On some convertibles the lid-flip devstate sets
ASUS_WMI_DSTS_UNKNOWN_BITalongside the state bit while the machine is folded. Measured on an ASUS ProArt PX13 (HN7306EAC),ASUS_WMI_DEVID_LID_FLIP_ROGanswers0x00010000open and0x00010003folded, 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, soasus_wmi_tablet_mode_get_state()discards a perfectly good state sitting in bit 0 andSW_TABLET_MODEnever moves.Quoted 4 lines
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 ofasus_wmi_get_devstate_simple()is untouched, so the change is confined to the tablet switch.Hi Robin,
Thanks for looking into this!
Quoted 33 lines
Signed-off-by Robin Everaars <[email protected]>--- drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)(quoted diff) +0
-0/asus-wmi.c
b/drivers/platform/x86/asus-wmi.c
index8610663b8..f68fd2bcd100644drivers/platform/x86/asus-wmi.c +12
-0@@ -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.
+ */drivers/platform/x86/asus-wmi.c +5
-0+static int asus_wmi_tablet_sw_get_state (struct asus_wmi *asus,u32 dev_id) +{ +u32 retval; +int err; +
Quoted 8 lines
drivers/platform/x86/asus-wmi.c
Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6
-0+ 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_GETand 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
Quoted 25 lines
drivers/platform/x86/asus-wmi.c
Quoted 2 lines
drivers/platform/x86/asus-wmi.c +2
-0+ +return !!(retval &ASUS_WMI_DSTS_STATUS_BIT );Same here
Quoted 22 lines
drivers/platform/x86/asus-wmi.c +4
-2+} +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);}
Denis Benato
maintainerRe: [PATCH 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
Quoted 62 lines · Hans de Goede
Hi Denis,
Quoted 51 lines · Denis Benato
Quoted 10 lines · Robin Everaars
On some convertibles the lid-flip devstate sets
ASUS_WMI_DSTS_UNKNOWN_BITalongside the state bit while the machine is folded. Measured on an ASUS ProArt PX13 (HN7306EAC),ASUS_WMI_DEVID_LID_FLIP_ROGanswers0x00010000open and0x00010003folded, 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, soasus_wmi_tablet_mode_get_state()discards a perfectly good state sitting in bit 0 andSW_TABLET_MODEnever moves.Quoted 4 lines
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 ofasus_wmi_get_devstate_simple()is untouched, so the change is confined to the tablet switch.Hi Robin,
Thanks for looking into this!
Quoted 33 lines
Signed-off-by Robin Everaars <[email protected]>--- drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)(quoted diff) +0
-0/asus-wmi.c
b/drivers/platform/x86/asus-wmi.c
index8610663b8..f68fd2bcd100644drivers/platform/x86/asus-wmi.c +12
-0@@ -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.
+ */drivers/platform/x86/asus-wmi.c +5
-0+static int asus_wmi_tablet_sw_get_state (struct asus_wmi *asus,u32 dev_id) +{ +u32 retval; +int err; +Quoted 8 lines
drivers/platform/x86/asus-wmi.c
Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6
-0+ 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_GETand many more macros to do this, please use those as it makes the code easier to read.
Quoted 7 lines
I appreciate that you are trying to help out with reviewing, but in this case this is not good advice.
Using
FIELD_GETis good advice for new code, but for an existing driver it is more important to be consistent and so far no code inasus-wmi.cis usingFIELD_GETso adding this just makes the whole driver harder to read since now it is mixing 2 styles.
Aaaah, my bad, sorry.
Quoted 31 lines
Regards,
Hans
Quoted 25 lines
drivers/platform/x86/asus-wmi.c
Quoted 2 lines
drivers/platform/x86/asus-wmi.c +2
-0+ +return !!(retval &ASUS_WMI_DSTS_STATUS_BIT );Same here
Quoted 22 lines
drivers/platform/x86/asus-wmi.c +4
-2+} +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);}
PATCH 2/2 platform/x86: asus-wmi: accept either lid-flip notify code
In reply to Robin Everaarsasus-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 <[email protected]>
--- drivers/platform/x86/asus-wmi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +8 -0
@@ -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;
}
Signature · 1 line
2.55.0
Denis Benato
maintainerRe: [PATCH 2/2] platform/x86: asus-wmi: accept either lid-flip notify code
Quoted 39 lines · Robin Everaars
asus-wmi pairs the devid it polls for the tablet switch with the single notify code it listens for, and
tablet_mode_swonly 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_FLIPis frozen at 1 in every pose whileASUS_WMI_DEVID_LID_FLIP_ROGtracks the hinge, yet folding notifies withNOTIFY_LID_FLIPrather thanNOTIFY_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_PROG2in the sparse keymap. Machines with a keyboard-dock switch notify with0x75and are unaffected, and with no switch registered the event code is 0 and the old equality test still runs.Signed-off-by: Robin
Everaars <[email protected]>--- drivers/platform/x86/asus-wmi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/platform/x86/asus-wmi.c +8
-0@@ -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
Quoted 2 lines
ent and both already map to
KEY_PROG2in 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.
Quoted 24 lines
drivers/platform/x86/asus-wmi.c +13
-1+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 ; }
v2 cover platform/x86: asus-wmi: make the tablet switch work on the ProArt PX13
In reply to Robin EveraarsSW_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/bitfield.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/[email protected]/
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: aca39607c1734ed976fdd65deb75b3555a5a0326
Signature · 1 line
2.55.0
PATCH v2 1/2 platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
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.
---
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/platform/x86/asus-wmi.c | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
drivers/platform/x86/asus-wmi.c +9 -0
@@ -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);
}
Signature · 1 line
2.55.0
Hans de Goede
maintainerRe: [PATCH v2 1/2] platform/x86: asus-wmi: keep the lid-flip state when UNKNOWN is set
Hi,
Thank you for your patches!
Quoted 59 lines · Robin Everaars
On some convertibles the lid-flip devstate sets
ASUS_WMI_DSTS_UNKNOWN_BITalongside the state bit while the machine is folded. Measured on an ASUS ProArt PX13 (HN7306EAC),ASUS_WMI_DEVID_LID_FLIP_ROGanswers0x00010000open and0x00010003folded, 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, soasus_wmi_tablet_mode_get_state()discards a perfectly good state sitting in bit 0 andSW_TABLET_MODEnever 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 ofasus_wmi_get_devstate_simple()is untouched, so the change is confined to the tablet switch.Signed-off-by Robin Everaars <[email protected]>---
v2: useFIELD_GET()for both bits and add thelinux/bitfield.hinclude,
per Denis Benato. Drops the !! on the return. No functional change.
drivers/platform/x86/asus-wmi.c| 33 +++++++++++++++++++++++++++++++--1 file changed, 31 insertions(+), 2 deletions(-)drivers/platform/x86/asus-wmi.c +9
-0@@ -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,
+ * soasus_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.
+ */drivers/platform/x86/asus-wmi.c +5
-0+static int asus_wmi_tablet_sw_get_state (struct asus_wmi *asus,u32 dev_id) +{ +u32 retval; +int err; +
drivers/platform/x86/asus-wmi.c
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10
-0+ 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
Quoted 20 lines
static void
asus_wmi_tablet_sw_init(struct asus_wmi *asus, u32 dev_id, int event_code){drivers/platform/x86/asus-wmi.c +2
-2struct 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
In reply to Robin Everaarsasus-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 <[email protected]>
--- drivers/platform/x86/asus-wmi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +8 -0
@@ -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;
}
Signature · 1 line
2.55.0
Hans de Goede
maintainerRe: [PATCH v2 2/2] platform/x86: asus-wmi: accept either lid-flip notify code
Hi Robin,
Quoted 11 lines · Robin Everaars
asus-wmi pairs the devid it polls for the tablet switch with the single notify code it listens for, and
tablet_mode_swonly 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_FLIPis frozen at 1 in every pose whileASUS_WMI_DEVID_LID_FLIP_ROGtracks the hinge, yet folding notifies withNOTIFY_LID_FLIPrather thanNOTIFY_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.
Quoted 8 lines
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_PROG2in the sparse keymap. Machines with a keyboard-dock switch notify with0x75and are unaffected, and with no switch registered the event code is 0 and the old equality test still runs.Signed-off-by: Robin
Everaars <[email protected]>
nitpick: Something went wrong with the S-o-b line here
Quoted 23 lines
--- drivers/platform/x86/asus-wmi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/platform/x86/asus-wmi.c +8
-0@@ -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_PROG2in the sparse keymap.
+ */drivers/platform/x86/asus-wmi.c +1
-0+static bool asus_wmi_is_tablet_switch_code (struct asus_wmi *asus,int code)
drivers/platform/x86/asus-wmi.c
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10
-0+{ +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 ...
drivers/platform/x86/asus-wmi.c static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus) · line 4702
Quoted 9 lines
drivers/platform/x86/asus-wmi.c +1
-1@@ -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