platform/x86: asus-wmi: fix screenpad brightness/power management
Denis Benato
maintainercover platform/x86: asus-wmi: fix screenpad brightness/power management
Fix up some inconsistent behaviour involving the screenpad on some ASUS laptops. This fixes:
- illogical screen off control (0/1 flipped depending on WMI state)
- bad brightness depending on the last screenpad power state
- incorrect brightness scaling
Changelog:
- v1
- Initial submission
- v2
- Split patch in two
- Remove a redundant variable copy
Denis Benato (2):
platform/x86: asus-wmi: adjust screenpad power/brightness handling platform/x86: asus-wmi: fix screenpad brightness scaling
drivers/platform/x86/asus-wmi.c | 50 +++++++++++++-------------------- 1 file changed, 19 insertions(+), 31 deletions(-)
Signature · 1 line
2.53.0
Denis Benato
maintainerPATCH 1/2 platform/x86: asus-wmi: adjust screenpad power/brightness handling
Fix illogical screen off control by hardcoding 0 and 1 depending on the requested brightness and also do not rely on the last screenpad power state to issue screen brightness commands.
--- drivers/platform/x86/asus-wmi.c | 34 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 21 deletions(-)
drivers/platform/x86/asus-wmi.c +13 -21
@@ -4254,32 +4254,24 @@ static int read_screenpad_brightness(struct backlight_device *bd)static int update_screenpad_bl_status (struct backlight_device *bd) { -struct asus_wmi *asus =bl_get_data (bd); -int power, err =0 ; -u32 ctrl_param; +int err =0 ; +u32 ctrl_param = bd->props.brightness; - power =read_screenpad_backlight_power (asus); -if (power <0 ) -return power; +if (ctrl_param >=0 && bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL ); +if (err <0 ) +return err; -if (bd->props.power != power) { -if (power !=BACKLIGHT_POWER_ON ) { -/* Only brightness > 0 can power it back on */ - ctrl_param = asus->driver->screenpad_brightness -ASUS_SCREENPAD_BRIGHT_MIN ; - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , - ctrl_param,NULL ); - }else { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); - } - }else if (power ==BACKLIGHT_POWER_ON ) { -/* Only set brightness if powered on or we get invalid/unsync state */ - ctrl_param = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL ); +if (err <0 ) +return err; } -/* Ensure brightness is stored to turn back on with */ -if (err ==0 ) - asus->driver->screenpad_brightness = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; +if (!bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); +if (err <0 ) +return err; + }return err; }
Signature · 1 line
2.53.0
Ilpo Järvinen
maintainerRe: [PATCH 1/2] platform/x86: asus-wmi: adjust screenpad power/brightness handling
Quoted 3 lines · Denis Benato
Fix illogical screen off control by hardcoding 0 and 1 depending on the requested brightness and also do not rely on the last screenpad power state to issue screen brightness commands.
Should this have a Fixes tag?
Quoted 11 lines
Signed-off-by Denis Benato <[email protected]>Signed-off-by Luke Jones <[email protected]>--- drivers/platform/x86/asus-wmi.c | 34 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 21 deletions(-)drivers/platform/x86/asus-wmi.c +0
-0
drivers/platform/x86/asus-wmi.c static int read_screenpad_brightness(struct backlight_device *bd) · line 4258
Quoted 8 lines
drivers/platform/x86/asus-wmi.c +2
-3@@ -4254,32 +4254,24 @@ static int read_screenpad_brightness(struct backlight_device *bd)static int update_screenpad_bl_status (struct backlight_device *bd) { -struct asus_wmi *asus =bl_get_data (bd); -int power, err =0 ; -u32 ctrl_param; +int err =0 ; +u32 ctrl_param = bd->props.brightness;
Please retain reverse xmas-tree order.
Quoted 38 lines
drivers/platform/x86/asus-wmi.c +11
-18- power =read_screenpad_backlight_power (asus); -if (power <0 ) -return power; +if (ctrl_param >=0 && bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL ); +if (err <0 ) +return err; -if (bd->props.power != power) { -if (power !=BACKLIGHT_POWER_ON ) { -/* Only brightness > 0 can power it back on */ - ctrl_param = asus->driver->screenpad_brightness -ASUS_SCREENPAD_BRIGHT_MIN ; - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , - ctrl_param,NULL ); - }else { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); - } - }else if (power ==BACKLIGHT_POWER_ON ) { -/* Only set brightness if powered on or we get invalid/unsync state */ - ctrl_param = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL ); +if (err <0 ) +return err; } -/* Ensure brightness is stored to turn back on with */ -if (err ==0 ) - asus->driver->screenpad_brightness = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; +if (!bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); +if (err <0 ) +return err; + }return err; }
Signature · 1 line
i.
Denis Benato
maintainerRe: [PATCH 1/2] platform/x86: asus-wmi: adjust screenpad power/brightness handling
Quoted 7 lines · Ilpo Järvinen
Quoted 3 lines · Denis Benato
Fix illogical screen off control by hardcoding 0 and 1 depending on the requested brightness and also do not rely on the last screenpad power state to issue screen brightness commands.
Should this have a Fixes tag?
Same for the other patch: I am not sure.
What I know for certain is that Luke had an asus DUO to test this patch with and most certainly it was because someone contacted him about these bugs.
I split up commits found int the previous version of this patch:
https://lore.kernel.org/all/[email protected]/
I changed nothing else beside removing a redundant variable assignment.
Quoted 59 lines
Quoted 11 lines
Signed-off-by Denis Benato <[email protected]>Signed-off-by Luke Jones <[email protected]>--- drivers/platform/x86/asus-wmi.c | 34 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 21 deletions(-)drivers/platform/x86/asus-wmi.c +0
-0drivers/platform/x86/asus-wmi.c static int read_screenpad_brightness(struct backlight_device *bd) · line 4258
Quoted 8 lines
drivers/platform/x86/asus-wmi.c +2
-3@@ -4254,32 +4254,24 @@ static int read_screenpad_brightness(struct backlight_device *bd)static int update_screenpad_bl_status (struct backlight_device *bd) { -struct asus_wmi *asus =bl_get_data (bd); -int power, err =0 ; -u32 ctrl_param; +int err =0 ; +u32 ctrl_param = bd->props.brightness;Please retain reverse xmas-tree order.
Quoted 38 lines
drivers/platform/x86/asus-wmi.c +11
-18- power =read_screenpad_backlight_power (asus); -if (power <0 ) -return power; +if (ctrl_param >=0 && bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL ); +if (err <0 ) +return err; -if (bd->props.power != power) { -if (power !=BACKLIGHT_POWER_ON ) { -/* Only brightness > 0 can power it back on */ - ctrl_param = asus->driver->screenpad_brightness -ASUS_SCREENPAD_BRIGHT_MIN ; - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , - ctrl_param,NULL ); - }else { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); - } - }else if (power ==BACKLIGHT_POWER_ON ) { -/* Only set brightness if powered on or we get invalid/unsync state */ - ctrl_param = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL ); +if (err <0 ) +return err; } -/* Ensure brightness is stored to turn back on with */ -if (err ==0 ) - asus->driver->screenpad_brightness = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; +if (!bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); +if (err <0 ) +return err; + }return err; }
[email protected]
maintainerRe: [PATCH 1/2] platform/x86: asus-wmi: adjust screenpad power/brightness handling
Quoted 13 lines · Denis Benato
Quoted 7 lines · Ilpo Järvinen
Quoted 3 lines · Denis Benato
Fix illogical screen off control by hardcoding 0 and 1 depending on the requested brightness and also do not rely on the last screenpad power state to issue screen brightness commands.
Should this have a Fixes tag?
Same for the other patch: I am not sure.
It probably should be a fixes tag. Though there is no reference bug report or other relating to it - only my discovery that the previously written code was in fact not right.
I had written the initial version that is in the kernel based on some limited testing feedback from a user who was not able to clearly articulate what the issues were and was happy with the final result.
I was able to get my hands on a Zenbook Duo and fully test this, which is how I discovered the issues.
Quoted 5 lines
What I know for certain is that Luke had an asus DUO to test this patch with and most certainly it was because someone contacted him about these bugs.
I split up commits found int the previous version of this patch:
https://lore.kernel.org/all/[email protected]/
Thanks for doing this. I just have not had any time to do it myself, very low on the priority list but I would wager getting this all fixed correctly will enable both Older and newer models to function how they should.
Quoted 60 lines
I changed nothing else beside removing a redundant variable assignment.
Quoted 59 lines
Quoted 11 lines
Signed-off-by Denis Benato <[email protected]>Signed-off-by Luke Jones <[email protected]>---
drivers/platform/x86/asus-wmi.c| 34 +++++++++++++--------------------1 file changed, 13 insertions(+), 21 deletions(-)drivers/platform/x86/asus-wmi.c +0
-0drivers/platform/x86/asus-wmi.c static int read_screenpad_brightness(struct backlight_device *bd) · line 4258
Quoted 8 lines
drivers/platform/x86/asus-wmi.c +2
-3@@ -4254,32 +4254,24 @@ static int read_screenpad_brightness(struct backlight_device *bd)static int update_screenpad_bl_status (struct backlight_device *bd) { -struct asus_wmi *asus =bl_get_data (bd); -int power, err =0 ; -u32 ctrl_param; +int err =0 ; +u32 ctrl_param = bd->props.brightness;Please retain reverse xmas-tree order.
Quoted 38 lines
drivers/platform/x86/asus-wmi.c +11
-18- power =read_screenpad_backlight_power (asus); -if (power <0 ) -return power; +if (ctrl_param >=0 && bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL ); +if (err <0 ) +return err; -if (bd->props.power != power) { -if (power !=BACKLIGHT_POWER_ON ) { -/* Only brightness > 0 can power it back on */ - ctrl_param = asus->driver->screenpad_brightness -ASUS_SCREENPAD_BRIGHT_MIN ; - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , - ctrl_param,NULL ); - }else { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); - } - }else if (power ==BACKLIGHT_POWER_ON ) { -/* Only set brightness if powered on or we get invalid/unsync state */ - ctrl_param = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL ); +if (err <0 ) +return err; } -/* Ensure brightness is stored to turn back on with */ -if (err ==0 ) - asus->driver->screenpad_brightness = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; +if (!bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); +if (err <0 ) +return err; + }return err; }
Denis Benato
maintainerRe: [PATCH 1/2] platform/x86: asus-wmi: adjust screenpad power/brightness handling
Quoted 16 lines · On 2/24/26 05:15, [email protected] wrote:
Quoted 12 lines · Denis Benato
Quoted 7 lines · Ilpo Järvinen
Quoted 3 lines · Denis Benato
Fix illogical screen off control by hardcoding 0 and 1 depending on the requested brightness and also do not rely on the last screenpad power state to issue screen brightness commands.
Should this have a Fixes tag?
Same for the other patch: I am not sure.
It probably should be a fixes tag. Though there is no reference bug report or other relating to it - only my discovery that the previously written code was in fact not right.
Quoted 6 lines
I had written the initial version that is in the kernel based on some limited testing feedback from a user who was not able to clearly articulate what the issues were and was happy with the final result.
I was able to get my hands on a Zenbook Duo and fully test this, which is how I discovered the issues.
Actually... my bad. I confused "Closes" with "Fixes". Ilpo meant to reference the original commit.
Sorry for the noise. I will dig those two tags.
Quoted 68 lines
Quoted 5 lines
What I know for certain is that Luke had an asus DUO to test this patch with and most certainly it was because someone contacted him about these bugs.
I split up commits found int the previous version of this patch:
https://lore.kernel.org/all/[email protected]/Thanks for doing this. I just have not had any time to do it myself, very low on the priority list but I would wager getting this all fixed correctly will enable both Older and newer models to function how they should.
Quoted 59 lines
I changed nothing else beside removing a redundant variable assignment.
Quoted 58 lines
Quoted 11 lines
Signed-off-by Denis Benato <[email protected]>Signed-off-by Luke Jones <[email protected]>---
drivers/platform/x86/asus-wmi.c| 34 +++++++++++++--------------------1 file changed, 13 insertions(+), 21 deletions(-)drivers/platform/x86/asus-wmi.c +0
-0drivers/platform/x86/asus-wmi.c static int read_screenpad_brightness(struct backlight_device *bd) · line 4258
Quoted 8 lines
drivers/platform/x86/asus-wmi.c +2
-3@@ -4254,32 +4254,24 @@ static int read_screenpad_brightness(struct backlight_device *bd)static int update_screenpad_bl_status (struct backlight_device *bd) { -struct asus_wmi *asus =bl_get_data (bd); -int power, err =0 ; -u32 ctrl_param; +int err =0 ; +u32 ctrl_param = bd->props.brightness;Please retain reverse xmas-tree order.
Quoted 37 lines
drivers/platform/x86/asus-wmi.c +11
-18- power =read_screenpad_backlight_power (asus); -if (power <0 ) -return power; +if (ctrl_param >=0 && bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL ); +if (err <0 ) +return err; -if (bd->props.power != power) { -if (power !=BACKLIGHT_POWER_ON ) { -/* Only brightness > 0 can power it back on */ - ctrl_param = asus->driver->screenpad_brightness -ASUS_SCREENPAD_BRIGHT_MIN ; - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , - ctrl_param,NULL ); - }else { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); - } - }else if (power ==BACKLIGHT_POWER_ON ) { -/* Only set brightness if powered on or we get invalid/unsync state */ - ctrl_param = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL ); +if (err <0 ) +return err; } -/* Ensure brightness is stored to turn back on with */ -if (err ==0 ) - asus->driver->screenpad_brightness = bd->props.brightness +ASUS_SCREENPAD_BRIGHT_MIN ; +if (!bd->props.power) { + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); +if (err <0 ) +return err; + }return err; }
Denis Benato
maintainerPATCH 2/2 platform/x86: asus-wmi: fix screenpad brightness scaling
In reply to Denis BenatoFix incorrect brightness scaling by removing the inconsistent use of an arbitrary minimum.
--- drivers/platform/x86/asus-wmi.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/platform/x86/asus-wmi.c +6 -10
@@ -125,7 +125,6 @@ module_param(fnlock_default, bool, 0444);#define NVIDIA_TEMP_MIN 75#define NVIDIA_TEMP_MAX 87 -#define ASUS_SCREENPAD_BRIGHT_MIN 20#define ASUS_SCREENPAD_BRIGHT_MAX 255#define ASUS_SCREENPAD_BRIGHT_DEFAULT 60
@@ -4243,13 +4242,13 @@ static int read_screenpad_brightness(struct backlight_device *bd)return err;/* The device brightness can only be read if powered, so return stored */ if (err ==BACKLIGHT_POWER_OFF ) -return asus->driver->screenpad_brightness -ASUS_SCREENPAD_BRIGHT_MIN ; +return bd->props.brightness; err =asus_wmi_get_devstate (asus,ASUS_WMI_DEVID_SCREENPAD_LIGHT , &retval);if (err <0 )return err; -return (retval &ASUS_WMI_DSTS_BRIGHTNESS_MASK ) -ASUS_SCREENPAD_BRIGHT_MIN ; +return (retval &ASUS_WMI_DSTS_BRIGHTNESS_MASK ); }static int update_screenpad_bl_status (struct backlight_device *bd)
@@ -4289,22 +4288,19 @@ static int asus_screenpad_init(struct asus_wmi *asus)int err, power;int brightness =0 ; - power =read_screenpad_backlight_power (asus); + power =asus_wmi_get_devstate_simple (asus,ASUS_WMI_DEVID_SCREENPAD_POWER );if (power <0 )return power; -if (power !=BACKLIGHT_POWER_OFF ) { +if (power) { err =asus_wmi_get_devstate (asus,ASUS_WMI_DEVID_SCREENPAD_LIGHT , &brightness);if (err <0 )return err; } -/* default to an acceptable min brightness on boot if too low */ -if (brightness <ASUS_SCREENPAD_BRIGHT_MIN ) - brightness =ASUS_SCREENPAD_BRIGHT_DEFAULT ;memset (&props,0 ,sizeof (struct backlight_properties )); props.type =BACKLIGHT_RAW ;/* ensure this bd is last to be picked */ - props.max_brightness =ASUS_SCREENPAD_BRIGHT_MAX -ASUS_SCREENPAD_BRIGHT_MIN ; + props.max_brightness =ASUS_SCREENPAD_BRIGHT_MAX ; bd =backlight_device_register ("asus_screenpad" , &asus->platform_device->dev, asus, &asus_screenpad_bl_ops, &props);
@@ -4315,7 +4311,7 @@ static int asus_screenpad_init(struct asus_wmi *asus) asus->screenpad_backlight_device = bd; asus->driver->screenpad_brightness = brightness; - bd->props.brightness = brightness -ASUS_SCREENPAD_BRIGHT_MIN ; + bd->props.brightness = brightness; bd->props.power = power;backlight_update_status (bd);
Signature · 1 line
2.53.0
Ilpo Järvinen
maintainerRe: [PATCH 2/2] platform/x86: asus-wmi: fix screenpad brightness scaling
Quoted 5 lines · Denis Benato
Fix incorrect brightness scaling by removing the inconsistent use of an arbitrary minimum.
Signed-off-by Denis Benato <[email protected]>Signed-off-by Luke Jones <[email protected]>
Should this have a Fixes tag?
Quoted 40 lines
--- drivers/platform/x86/asus-wmi.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)drivers/platform/x86/asus-wmi.c +3
-4@@ -125,7 +125,6 @@ module_param(fnlock_default, bool, 0444);#define NVIDIA_TEMP_MIN 75#define NVIDIA_TEMP_MAX 87 -#define ASUS_SCREENPAD_BRIGHT_MIN 20#define ASUS_SCREENPAD_BRIGHT_MAX 255#define ASUS_SCREENPAD_BRIGHT_DEFAULT 60@@ -4243,13 +4242,13 @@ static int read_screenpad_brightness(struct backlight_device *bd)return err;/* The device brightness can only be read if powered, so return stored */ if (err ==BACKLIGHT_POWER_OFF ) -return asus->driver->screenpad_brightness -ASUS_SCREENPAD_BRIGHT_MIN ; +return bd->props.brightness; err =asus_wmi_get_devstate (asus,ASUS_WMI_DEVID_SCREENPAD_LIGHT , &retval);if (err <0 )return err; -return (retval &ASUS_WMI_DSTS_BRIGHTNESS_MASK ) -ASUS_SCREENPAD_BRIGHT_MIN ; +return (retval &ASUS_WMI_DSTS_BRIGHTNESS_MASK ); }static int update_screenpad_bl_status (struct backlight_device *bd)@@ -4289,22 +4288,19 @@ static int asus_screenpad_init(struct asus_wmi *asus)int err, power;int brightness =0 ; - power =read_screenpad_backlight_power (asus); + power =asus_wmi_get_devstate_simple (asus,ASUS_WMI_DEVID_SCREENPAD_POWER );if (power <0 )return power;
drivers/platform/x86/asus-wmi.c static int asus_screenpad_init(struct asus_wmi *asus) · line 4303
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +1
-4-if (power !=BACKLIGHT_POWER_OFF ) { +if (power) { err =asus_wmi_get_devstate (asus,ASUS_WMI_DEVID_SCREENPAD_LIGHT , &brightness);if (err <0 )return err; } -/* default to an acceptable min brightness on boot if too low */ -if (brightness <ASUS_SCREENPAD_BRIGHT_MIN ) - brightness =ASUS_SCREENPAD_BRIGHT_DEFAULT ;
This doesn't seem to be related to the scaling but looks a lowerbound? Probably removing it would warrant own patch + justification, IMO.
Quoted 9 lines
drivers/platform/x86/asus-wmi.c +1
-1memset (&props,0 ,sizeof (struct backlight_properties )); props.type =BACKLIGHT_RAW ;/* ensure this bd is last to be picked */ - props.max_brightness =ASUS_SCREENPAD_BRIGHT_MAX -ASUS_SCREENPAD_BRIGHT_MIN ; + props.max_brightness =ASUS_SCREENPAD_BRIGHT_MAX ; bd =backlight_device_register ("asus_screenpad" , &asus->platform_device->dev, asus, &asus_screenpad_bl_ops, &props);
drivers/platform/x86/asus-wmi.c static int asus_screenpad_init(struct asus_wmi *asus) · line 4317
Quoted 8 lines
drivers/platform/x86/asus-wmi.c +1
-1@@ -4315,7 +4311,7 @@ static int asus_screenpad_init(struct asus_wmi *asus) asus->screenpad_backlight_device = bd; asus->driver->screenpad_brightness = brightness; - bd->props.brightness = brightness -ASUS_SCREENPAD_BRIGHT_MIN ; + bd->props.brightness = brightness; bd->props.power = power;backlight_update_status (bd);
--
i.