X86 platform drivers
 help / color / mirror / Atom feed
From: Mohamed Ghanmi <mohamed.ghanmi@supcom.tn>
To: Joshua Leivenzon <hacker1024@users.sourceforge.net>
Cc: platform-driver-x86@vger.kernel.org,
	Corentin Chary <corentin.chary@gmail.com>,
	"Luke D . Jones" <luke@ljones.dev>
Subject: Re: [PATCH 1/1] platform/x86: asus-wmi: Add lite thermal policy support
Date: Wed, 31 Jul 2024 12:54:33 +0100	[thread overview]
Message-ID: <Zqoln_jQlfP5yzS6@meddabeast> (raw)
In-Reply-To: <ME3P282MB300372C60091A735770D94B1A4B12@ME3P282MB3003.AUSP282.PROD.OUTLOOK.COM>

Hi, 

On Wed, Jul 31, 2024 at 09:35:07PM +1000, Joshua Leivenzon wrote:
> Some ASUS laptops, such as the Zenbook Duo 2024 (UX8406), use a different WMI
> device ID to set the thermal policy.
> 
> These devices tend to lack support for custom fan curve management, hence the
> "lite" designation.
> 
> Signed-off-by: Joshua Leivenzon <hacker1024@users.sourceforge.net>
> ---
>  drivers/platform/x86/asus-wmi.c            | 102 +++++++++++++++------
>  include/linux/platform_data/x86/asus-wmi.h |   1 +
>  2 files changed, 76 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index cc735931f97b..a89cbc063a3f 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -93,9 +93,13 @@ module_param(fnlock_default, bool, 0444);
>  #define ASUS_FAN_BOOST_MODE_SILENT_MASK		0x02
>  #define ASUS_FAN_BOOST_MODES_MASK		0x03
>  
> +#define ASUS_THROTTLE_THERMAL_POLICY_COUNT 3
>  #define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT	0
>  #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST	1
>  #define ASUS_THROTTLE_THERMAL_POLICY_SILENT	2
> +#define ASUS_THROTTLE_THERMAL_POLICY_LITE_DEFAULT 0
> +#define ASUS_THROTTLE_THERMAL_POLICY_LITE_OVERBOOST 2
> +#define ASUS_THROTTLE_THERMAL_POLICY_LITE_SILENT 1
>  
>  #define USB_INTEL_XUSB2PR		0xD0
>  #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI	0x9c31
> @@ -287,6 +291,7 @@ struct asus_wmi {
>  	bool kbd_rgb_state_available;
>  
>  	bool throttle_thermal_policy_available;
> +	bool throttle_thermal_policy_lite;
>  	u8 throttle_thermal_policy_mode;
>  
>  	bool cpu_fan_curve_available;
> @@ -3639,6 +3644,14 @@ static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
>  	err = asus_wmi_get_devstate(asus,
>  				    ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
>  				    &result);
> +	if (err == -ENODEV) {
> +		err = asus_wmi_get_devstate(asus,
> +						ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_LITE,
> +						&result);
> +		asus->throttle_thermal_policy_lite = true;
> +	} else {
> +		asus->throttle_thermal_policy_lite = false;
> +	}
>  	if (err) {
>  		if (err == -ENODEV)
>  			return 0;
> @@ -3659,7 +3672,10 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
>  
>  	value = asus->throttle_thermal_policy_mode;
>  
> -	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
> +	err = asus_wmi_set_devstate(
> +					asus->throttle_thermal_policy_lite
> +						? ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_LITE
> +						: ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
>  				    value, &retval);
>  
>  	sysfs_notify(&asus->platform_device->dev.kobj, NULL,
> @@ -3701,7 +3717,7 @@ static int throttle_thermal_policy_switch_next(struct asus_wmi *asus)
>  	u8 new_mode = asus->throttle_thermal_policy_mode + 1;
>  	int err;
>  
> -	if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT)
> +	if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_COUNT - 1)
>  		new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
>  
>  	asus->throttle_thermal_policy_mode = new_mode;
> @@ -3740,7 +3756,7 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
>  	if (result < 0)
>  		return result;
>  
> -	if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_SILENT)
> +	if (new_mode > ASUS_THROTTLE_THERMAL_POLICY_COUNT - 1)
>  		return -EINVAL;
>  
>  	asus->throttle_thermal_policy_mode = new_mode;
> @@ -3771,18 +3787,34 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
>  
>  	tp = asus->throttle_thermal_policy_mode;
>  
> -	switch (tp) {
> -	case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
> -		*profile = PLATFORM_PROFILE_BALANCED;
> -		break;
> -	case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
> -		*profile = PLATFORM_PROFILE_PERFORMANCE;
> -		break;
> -	case ASUS_THROTTLE_THERMAL_POLICY_SILENT:
> -		*profile = PLATFORM_PROFILE_QUIET;
> -		break;
> -	default:
> -		return -EINVAL;
> +	if (!asus->throttle_thermal_policy_lite) {
> +		switch (tp) {
> +		case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
> +			*profile = PLATFORM_PROFILE_BALANCED;
> +			break;
> +		case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
> +			*profile = PLATFORM_PROFILE_PERFORMANCE;
> +			break;
> +		case ASUS_THROTTLE_THERMAL_POLICY_SILENT:
> +			*profile = PLATFORM_PROFILE_QUIET;
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
> +	} else {
> +		switch (tp) {
> +		case ASUS_THROTTLE_THERMAL_POLICY_LITE_DEFAULT:
> +			*profile = PLATFORM_PROFILE_BALANCED;
> +			break;
> +		case ASUS_THROTTLE_THERMAL_POLICY_LITE_OVERBOOST:
> +			*profile = PLATFORM_PROFILE_PERFORMANCE;
> +			break;
> +		case ASUS_THROTTLE_THERMAL_POLICY_LITE_SILENT:
> +			*profile = PLATFORM_PROFILE_QUIET;
> +			break;
> +		default:
> +			return -EINVAL;
> +		}
>  	}
>  
>  	return 0;
> @@ -3796,18 +3828,34 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
>  
>  	asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
>  
> -	switch (profile) {
> -	case PLATFORM_PROFILE_PERFORMANCE:
> -		tp = ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST;
> -		break;
> -	case PLATFORM_PROFILE_BALANCED:
> -		tp = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
> -		break;
> -	case PLATFORM_PROFILE_QUIET:
> -		tp = ASUS_THROTTLE_THERMAL_POLICY_SILENT;
> -		break;
> -	default:
> -		return -EOPNOTSUPP;
> +	if (!asus->throttle_thermal_policy_lite) {
> +		switch (profile) {
> +		case PLATFORM_PROFILE_PERFORMANCE:
> +			tp = ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST;
> +			break;
> +		case PLATFORM_PROFILE_BALANCED:
> +			tp = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
> +			break;
> +		case PLATFORM_PROFILE_QUIET:
> +			tp = ASUS_THROTTLE_THERMAL_POLICY_SILENT;
> +			break;
> +		default:
> +			return -EOPNOTSUPP;
> +		}
> +	} else {
> +		switch (profile) {
> +		case PLATFORM_PROFILE_PERFORMANCE:
> +			tp = ASUS_THROTTLE_THERMAL_POLICY_LITE_OVERBOOST;
> +			break;
> +		case PLATFORM_PROFILE_BALANCED:
> +			tp = ASUS_THROTTLE_THERMAL_POLICY_LITE_DEFAULT;
> +			break;
> +		case PLATFORM_PROFILE_QUIET:
> +			tp = ASUS_THROTTLE_THERMAL_POLICY_LITE_SILENT;
> +			break;
> +		default:
> +			return -EOPNOTSUPP;
> +		}
>  	}
>  
>  	asus->throttle_thermal_policy_mode = tp;
> diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h
> index 0aeeae1c1943..f37e34ea36a5 100644
> --- a/include/linux/platform_data/x86/asus-wmi.h
> +++ b/include/linux/platform_data/x86/asus-wmi.h
> @@ -68,6 +68,7 @@
>  #define ASUS_WMI_DEVID_SCREENPAD_LIGHT	0x00050032
>  #define ASUS_WMI_DEVID_FAN_BOOST_MODE	0x00110018
>  #define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY 0x00120075
> +#define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_LITE 0x00110019

A patch already exists that fixes this issue but still not upstream
It adds support for modern vivobook laptops and some newer zenbooks
and uses platform profiles

https://lore.kernel.org/platform-driver-x86/20240609144849.2532-2-mohamed.ghanmi@supcom.tn/

>  
>  /* Misc */
>  #define ASUS_WMI_DEVID_PANEL_OD		0x00050019
> -- 
> 2.45.2
> 

  reply	other threads:[~2024-07-31 11:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240731113507.178929-1-hacker1024@users.sourceforge.net>
2024-07-31 11:35 ` [PATCH 1/1] platform/x86: asus-wmi: Add lite thermal policy support Joshua Leivenzon
2024-07-31 11:54   ` Mohamed Ghanmi [this message]
2024-08-01 14:05     ` Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zqoln_jQlfP5yzS6@meddabeast \
    --to=mohamed.ghanmi@supcom.tn \
    --cc=corentin.chary@gmail.com \
    --cc=hacker1024@users.sourceforge.net \
    --cc=luke@ljones.dev \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox