platform/x86 acer-wmi: Improve platform profile handling
Subsystems (2)
v3 cover platform/x86 acer-wmi: Improve platform profile handling
This patch improves the platform profile handling for laptops using the Acer Predator interface by making the following changes -
1) Using WMI calls to fetch the current platform profile instead of directly accessing it from the EC. A new helper function is introduced for this purpose.
2) Simplifying the cycling of platform profiles by making use of platform_profile_cycle()
3) Using an ACPI bitmap to dynamically set platform_profile_choices to better reflect the supported profiles.
The last patch also adds support for the Acer Nitro AN515-58 by adding it to the quirk list.
---v1->v2:
[1/3]
- Fixed enum member alignment and reordered them
[2/3]
- Made use of test_bit to check bitmap values
- Replaced magic numbers with proper variables
Link to v1: https://lore.kernel.org/platform-driver-x86/[email protected]/
v2->v3:
[1/5]
- Removed a line which was supposed to be in another patch
[3/5]
- Moved checking of max performance profile to [4/5]
- Restored code in profile_set which updates last_non_turbo_profile
Moved the supported profiles patch closer to the end of the series
Link to v2: https://lore.kernel.org/r/[email protected]
---
Hridesh MG (5):
platform/x86: acer-wmi: use WMI calls for platform profile handling platform/x86: acer-wmi: use new helper function for setting overclocks platform/x86: acer-wmi: simplify platform profile cycling platform/x86: acer-wmi: use an ACPI bitmap to set the platform profile choices platform/x86: acer-wmi: add support for Acer Nitro AN515-58
drivers/platform/x86/acer-wmi.c | 301 +++++++++++++++++++++++++--------------- 1 file changed, 188 insertions(+), 113 deletions(-)
---
base-commit: 8155b4ef3466f0e289e8fcc9e6e62f3f4dceeac2
change-id: 20250102-platform_profile-fc1e0aaf2900
Best regards,
Signature · 1 line
Hridesh MG <[email protected]>
PATCH v3 1/5 platform/x86: acer-wmi: use WMI calls for platform profile handling
Improve the platform profile handling by using WMI calls to fetch the current platform profile instead of directly accessing it from the EC. This is beneficial because the EC address differs for certain laptops.
--- drivers/platform/x86/acer-wmi.c | 185 ++++++++++++++++++++++++++++------------ 1 file changed, 129 insertions(+), 56 deletions(-)
drivers/platform/x86/acer-wmi.c +129 -56
@@ -31,6 +31,7 @@#include <acpi/video.h> #include <linux/hwmon.h> #include <linux/units.h> +#include <linux/unaligned.h> #include <linux/bitfield.h> MODULE_AUTHOR ("Carlos Corbacho" );
@@ -68,8 +69,11 @@ MODULE_LICENSE("GPL");#define ACER_WMID_GET_GAMING_SYS_INFO_METHODID 5#define ACER_WMID_SET_GAMING_FAN_BEHAVIOR 14#define ACER_WMID_SET_GAMING_MISC_SETTING_METHODID 22 +#define ACER_WMID_GET_GAMING_MISC_SETTING_METHODID 23 -#define ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET 0x54 +#define ACER_GAMING_MISC_SETTING_STATUS_MASK GENMASK_ULL(7, 0) +#define ACER_GAMING_MISC_SETTING_INDEX_MASK GENMASK_ULL(7, 0) +#define ACER_GAMING_MISC_SETTING_VALUE_MASK GENMASK_ULL(15, 8)#define ACER_PREDATOR_V4_RETURN_STATUS_BIT_MASK GENMASK_ULL(7, 0)#define ACER_PREDATOR_V4_SENSOR_INDEX_BIT_MASK GENMASK_ULL(15, 8)
@@ -115,6 +119,10 @@ enum acer_wmi_predator_v4_sensor_id { ACER_WMID_SENSOR_GPU_TEMPERATURE = 0x0A, }; +enum acer_wmi_gaming_misc_setting { +ACER_WMID_MISC_SETTING_PLATFORM_PROFILE =0x000B , +}; +static const struct key_entry acer_wmi_keymap[]__initconst = { {KE_KEY ,0x01 , {KEY_WLAN } },/* WiFi */ {KE_KEY ,0x03 , {KEY_WLAN } },/* WiFi */
@@ -751,20 +759,12 @@ static bool platform_profile_support;*/ static int last_non_turbo_profile; -enum acer_predator_v4_thermal_profile_ec { -ACER_PREDATOR_V4_THERMAL_PROFILE_ECO =0x04 , -ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO =0x03 , -ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE =0x02 , -ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET =0x01 , -ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED =0x00 , -}; - -enum acer_predator_v4_thermal_profile_wmi { -ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI =0x060B , -ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI =0x050B , -ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI =0x040B , -ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI =0x0B , -ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI =0x010B , +enum acer_predator_v4_thermal_profile { +ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET =0x00 , +ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED =0x01 , +ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE =0x04 , +ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO =0x05 , +ACER_PREDATOR_V4_THERMAL_PROFILE_ECO =0x06 , };/* Find which quirks are needed for a particular vendor/ model pair */
@@ -1477,6 +1477,45 @@ WMI_gaming_execute_u64(u32 method_id, u64 in, u64 *out)return status; } +static int WMI_gaming_execute_u32_u64 (u32 method_id,u32 in,u64 *out) +{ +struct acpi_buffer result = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer input = { + .length =sizeof (in), + .pointer = &in, + }; +union acpi_object *obj; +acpi_status status; +int ret =0 ; + + status =wmi_evaluate_method (WMID_GUID4 ,0 , method_id, &input, &result); +if (ACPI_FAILURE (status)) +return -EIO ; + + obj = result.pointer; +if (obj && out) { +switch (obj->type) { +case ACPI_TYPE_INTEGER : + *out = obj->integer.value; +break ; +case ACPI_TYPE_BUFFER : +if (obj->buffer.length <sizeof (*out)) + ret = -ENOMSG ; +else + *out =get_unaligned_le64 (obj->buffer.pointer); + +break ; +default : + ret = -ENOMSG ; +break ; + } + } + +kfree (obj); + +return ret; +} +static acpi_status WMID_gaming_set_u64 (u64 value,u32 cap) {u32 method_id =0 ;
@@ -1565,6 +1604,48 @@ static void WMID_gaming_set_fan_mode(u8 fan_mode)WMID_gaming_set_u64 (gpu_fan_config2 | gpu_fan_config1 <<16 ,ACER_CAP_TURBO_FAN ); } +static int WMID_gaming_set_misc_setting (enum acer_wmi_gaming_misc_setting setting,u8 value) +{ +acpi_status status; +u64 input =0 ; +u64 result; + + input |=FIELD_PREP (ACER_GAMING_MISC_SETTING_INDEX_MASK , setting); + input |=FIELD_PREP (ACER_GAMING_MISC_SETTING_VALUE_MASK , value); + + status =WMI_gaming_execute_u64 (ACER_WMID_SET_GAMING_MISC_SETTING_METHODID , input, &result); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* The return status must be zero for the operation to have succeeded */ +if (FIELD_GET (ACER_GAMING_MISC_SETTING_STATUS_MASK , result)) +return -EIO ; + +return 0 ; +} + +static int WMID_gaming_get_misc_setting (enum acer_wmi_gaming_misc_setting setting,u8 *value) +{ +u64 input =0 ; +u64 result; +int ret; + + input |=FIELD_PREP (ACER_GAMING_MISC_SETTING_INDEX_MASK , setting); + + ret =WMI_gaming_execute_u32_u64 (ACER_WMID_GET_GAMING_MISC_SETTING_METHODID , input, + &result); +if (ret <0 ) +return ret; + +/* The return status must be zero for the operation to have succeeded */ +if (FIELD_GET (ACER_GAMING_MISC_SETTING_STATUS_MASK , result)) +return -EIO ; + + *value =FIELD_GET (ACER_GAMING_MISC_SETTING_VALUE_MASK , result); + +return 0 ; +} +/* * Generic Device (interface-independent) */
@@ -1833,9 +1914,8 @@ acer_predator_v4_platform_profile_get(struct platform_profile_handler *pprof,u8 tp;int err; - err =ec_read (ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET , &tp); - -if (err <0 ) + err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , &tp); +if (err)return err;switch (tp) {
@@ -1865,36 +1945,33 @@ static int acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, enum platform_profile_option profile) { - int tp; -acpi_status status; + int err, tp;switch (profile) {case PLATFORM_PROFILE_PERFORMANCE : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;case PLATFORM_PROFILE_BALANCED_PERFORMANCE : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE ;break ;case PLATFORM_PROFILE_BALANCED : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;break ;case PLATFORM_PROFILE_QUIET : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET ;break ;case PLATFORM_PROFILE_LOW_POWER : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ;break ;default :return -EOPNOTSUPP ; } - status =WMI_gaming_execute_u64 ( -ACER_WMID_SET_GAMING_MISC_SETTING_METHODID , tp,NULL ); - -if (ACPI_FAILURE (status)) -return -EIO ; + err =WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , tp); +if (err) +return err; -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ) +if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) last_non_turbo_profile = tp;return 0 ;
@@ -1931,7 +2008,7 @@ static int acer_platform_profile_setup(struct platform_device *device)/* Set default non-turbo profile */ last_non_turbo_profile = -ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; +ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; }return 0 ; }
@@ -1946,12 +2023,10 @@ static int acer_thermal_profile_change(void)u8 current_tp;int tp, err;u64 on_AC; -acpi_status status; - - err =ec_read (ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET , - ¤t_tp); -if (err <0 ) + err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , + ¤t_tp); +if (err)return err;/* Check power source */
@@ -1962,54 +2037,52 @@ static int acer_thermal_profile_change(void)switch (current_tp) {case ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ;else tp = last_non_turbo_profile;break ;case ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;case ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ;else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE ;else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;case ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;case ACER_PREDATOR_V4_THERMAL_PROFILE_ECO :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET ;else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;default :return -EOPNOTSUPP ; } - status =WMI_gaming_execute_u64 ( -ACER_WMID_SET_GAMING_MISC_SETTING_METHODID , tp,NULL ); - -if (ACPI_FAILURE (status)) -return -EIO ; + err =WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , tp); +if (err) +return err;/* Store non-turbo profile for turbo mode toggle*/ -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ) +if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) last_non_turbo_profile = tp;platform_profile_notify (&platform_profile_handler);
Signature · 1 line
2.47.1
PATCH v3 2/5 platform/x86: acer-wmi: use new helper function for setting overclocks
In reply to Hridesh MGMigrate the OC handling in acer_toggle_turbo() to the new helper function for issuing the SetGamingMiscSetting WMI call.
--- drivers/platform/x86/acer-wmi.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/platform/x86/acer-wmi.c +19 -7
@@ -119,7 +119,14 @@ enum acer_wmi_predator_v4_sensor_id { ACER_WMID_SENSOR_GPU_TEMPERATURE = 0x0A, }; +enum acer_wmi_predator_v4_oc { +ACER_WMID_OC_NORMAL =0x0000 , +ACER_WMID_OC_TURBO =0x0002 , +}; +enum acer_wmi_gaming_misc_setting { +ACER_WMID_MISC_SETTING_OC_1 =0x0005 , +ACER_WMID_MISC_SETTING_OC_2 =0x0007 ,ACER_WMID_MISC_SETTING_PLATFORM_PROFILE =0x000B , };
@@ -1530,9 +1537,6 @@ static acpi_status WMID_gaming_set_u64(u64 value, u32 cap)case ACER_CAP_TURBO_FAN : method_id =ACER_WMID_SET_GAMING_FAN_BEHAVIOR ;break ; -case ACER_CAP_TURBO_OC : - method_id =ACER_WMID_SET_GAMING_MISC_SETTING_METHODID ; -break ;default :return AE_BAD_PARAMETER ; }
@@ -1891,8 +1895,12 @@ static int acer_toggle_turbo(void)WMID_gaming_set_fan_mode (0x1 );/* Set OC to normal */ -WMID_gaming_set_u64 (0x5 ,ACER_CAP_TURBO_OC ); -WMID_gaming_set_u64 (0x7 ,ACER_CAP_TURBO_OC ); +if (has_cap (ACER_CAP_TURBO_OC )) { +WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_OC_1 , +ACER_WMID_OC_NORMAL ); +WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_OC_2 , +ACER_WMID_OC_NORMAL ); + } }else {/* Turn on turbo led */ WMID_gaming_set_u64 (0x10001 ,ACER_CAP_TURBO_LED );
@@ -1901,8 +1909,12 @@ static int acer_toggle_turbo(void)WMID_gaming_set_fan_mode (0x2 );/* Set OC to turbo mode */ -WMID_gaming_set_u64 (0x205 ,ACER_CAP_TURBO_OC ); -WMID_gaming_set_u64 (0x207 ,ACER_CAP_TURBO_OC ); +if (has_cap (ACER_CAP_TURBO_OC )) { +WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_OC_1 , +ACER_WMID_OC_TURBO ); +WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_OC_2 , +ACER_WMID_OC_TURBO ); + } }return turbo_led_state; }
Signature · 1 line
2.47.1
PATCH v3 3/5 platform/x86: acer-wmi: simplify platform profile cycling
In reply to Hridesh MGMake use of platform_profile_cycle() to simplify the logic used for cycling through the different platform profiles. Also remove the unnecessary handling for AC power, as the hardware accepts different profiles regardless of whether AC is plugged in.
--- drivers/platform/x86/acer-wmi.c | 80 ++++++++++------------------------------- 1 file changed, 19 insertions(+), 61 deletions(-)
drivers/platform/x86/acer-wmi.c +19 -61
@@ -2028,76 +2028,34 @@ static int acer_platform_profile_setup(struct platform_device *device)static int acer_thermal_profile_change (void ) {/* -* This mode key can rotate each mode or toggle turbo mode. -* On battery, only ECO and BALANCED mode are available. +* This mode key will either cycle through each mode or toggle the turbo profile. */ if (quirks->predator_v4) {u8 current_tp; -int tp, err; -u64 on_AC; +int err, tp; - err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , - ¤t_tp); -if (err) -return err; - -/* Check power source */ - err =WMID_gaming_get_sys_info (ACER_WMID_CMD_GET_PREDATOR_V4_BAT_STATUS , &on_AC); -if (err <0 ) -return err; +if (cycle_gaming_thermal_profile) { +platform_profile_cycle (); + }else { + err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , + ¤t_tp); +if (err) +return err; -switch (current_tp) { -case ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ; -else +if (current_tp ==ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) { tp = last_non_turbo_profile; -break ; -case ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else + }else { + last_non_turbo_profile = current_tp; tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; -break ; -case ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ; -else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE ; -else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; -break ; -case ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; -break ; -case ACER_PREDATOR_V4_THERMAL_PROFILE_ECO : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET ; -else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; -break ; -default : -return -EOPNOTSUPP ; - } - - err =WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , tp); -if (err) -return err; + } -/* Store non-turbo profile for turbo mode toggle*/ -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) - last_non_turbo_profile = tp; + err =WMID_gaming_set_misc_setting ( +ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , tp); +if (err) +return err; -platform_profile_notify (&platform_profile_handler); +platform_profile_notify (&platform_profile_handler); + } }return 0 ;
Signature · 1 line
2.47.1
PATCH v3 4/5 platform/x86: acer-wmi: use an ACPI bitmap to set the platform profile choices
In reply to Hridesh MGCurrently the choices for the platform profile are hardcoded. There is an ACPI bitmap accessible via WMI that specifies the supported profiles, use this bitmap to dynamically set the choices for the platform profile.
--- drivers/platform/x86/acer-wmi.c | 55 +++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-)
drivers/platform/x86/acer-wmi.c +39 -16
@@ -33,6 +33,7 @@#include <linux/units.h> #include <linux/unaligned.h> #include <linux/bitfield.h> +#include <linux/bitmap.h> MODULE_AUTHOR ("Carlos Corbacho" );MODULE_DESCRIPTION ("Acer Laptop WMI Extras Driver" );
@@ -127,6 +128,7 @@ enum acer_wmi_predator_v4_oc {enum acer_wmi_gaming_misc_setting {ACER_WMID_MISC_SETTING_OC_1 =0x0005 ,ACER_WMID_MISC_SETTING_OC_2 =0x0007 , +ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES =0x000A ,ACER_WMID_MISC_SETTING_PLATFORM_PROFILE =0x000B , };
@@ -1957,7 +1959,7 @@ static int acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, enum platform_profile_option profile) { - int err, tp; + int max_perf, err, tp;switch (profile) {case PLATFORM_PROFILE_PERFORMANCE :
@@ -1983,7 +1985,10 @@ acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,if (err)return err; -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) + max_perf =find_last_bit (platform_profile_handler.choices, +PLATFORM_PROFILE_LAST ); + +if (tp != max_perf) last_non_turbo_profile = tp;return 0 ;
@@ -1992,6 +1997,7 @@ acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,static int acer_platform_profile_setup (struct platform_device *device) {if (quirks->predator_v4) { +unsigned long supported_profiles;int err; platform_profile_handler.name ="acer-wmi" ;
@@ -2001,16 +2007,30 @@ static int acer_platform_profile_setup(struct platform_device *device) platform_profile_handler.profile_set = acer_predator_v4_platform_profile_set; -set_bit (PLATFORM_PROFILE_PERFORMANCE , - platform_profile_handler.choices); -set_bit (PLATFORM_PROFILE_BALANCED_PERFORMANCE , - platform_profile_handler.choices); -set_bit (PLATFORM_PROFILE_BALANCED , - platform_profile_handler.choices); -set_bit (PLATFORM_PROFILE_QUIET , - platform_profile_handler.choices); -set_bit (PLATFORM_PROFILE_LOW_POWER , - platform_profile_handler.choices); + err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES , + (u8 *)&supported_profiles); +if (err) +return err; + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET , &supported_profiles)) +set_bit (PLATFORM_PROFILE_QUIET , + platform_profile_handler.choices); + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED , &supported_profiles)) +set_bit (PLATFORM_PROFILE_BALANCED , + platform_profile_handler.choices); + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE , &supported_profiles)) +set_bit (PLATFORM_PROFILE_BALANCED_PERFORMANCE , + platform_profile_handler.choices); + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO , &supported_profiles)) +set_bit (PLATFORM_PROFILE_PERFORMANCE , + platform_profile_handler.choices); + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_ECO , &supported_profiles)) +set_bit (PLATFORM_PROFILE_LOW_POWER , + platform_profile_handler.choices); err =platform_profile_register (&platform_profile_handler);if (err)
@@ -2028,11 +2048,11 @@ static int acer_platform_profile_setup(struct platform_device *device)static int acer_thermal_profile_change (void ) {/* -* This mode key will either cycle through each mode or toggle the turbo profile. +* This mode key will either cycle through each mode or toggle the most performant profile. */ if (quirks->predator_v4) {u8 current_tp; -int err, tp; +int max_perf, err, tp;if (cycle_gaming_thermal_profile) {platform_profile_cycle ();
@@ -2042,11 +2062,14 @@ static int acer_thermal_profile_change(void)if (err)return err; -if (current_tp ==ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) { + max_perf =find_last_bit (platform_profile_handler.choices, +PLATFORM_PROFILE_LAST ); + +if (current_tp == max_perf) { tp = last_non_turbo_profile; }else { last_non_turbo_profile = current_tp; - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; + tp = max_perf; } err = WMID_gaming_set_misc_setting(
Signature · 1 line
2.47.1
PATCH v3 5/5 platform/x86: acer-wmi: add support for Acer Nitro AN515-58
In reply to Hridesh MGAdd predator_v4 quirk for the Acer Nitro AN515-58 to enable fan speed monitoring and platform_profile handling.
--- drivers/platform/x86/acer-wmi.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/platform/x86/acer-wmi.c +9 -0
@@ -601,6 +601,15 @@ static const struct dmi_system_id acer_quirks[] __initconst = { }, .driver_data = &quirk_acer_travelmate_2490, }, + { + .callback = dmi_matched, + .ident = "Acer Nitro AN515-58", + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), + DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN515-58"), + }, + .driver_data = &quirk_acer_predator_v4, + }, { .callback = dmi_matched, .ident = "Acer Predator PH315-53",
Signature · 1 line
2.47.1
Re: [PATCH v3 1/5] platform/x86: acer-wmi: use WMI calls for platform profile handling
In reply to Hridesh MGQuoted 8 lines · Hridesh MG
Improve the platform profile handling by using WMI calls to fetch the current platform profile instead of directly accessing it from the EC. This is beneficial because the EC address differs for certain laptops.
Co-developed-by Armin Wolf <[email protected]>Signed-off-by Armin Wolf <[email protected]>Signed-off-by Hridesh MG <[email protected]>
Quoted 318 lines
--- drivers/platform/x86/acer-wmi.c | 185 ++++++++++++++++++++++++++++------------ 1 file changed, 129 insertions(+), 56 deletions(-)drivers/platform/x86/acer-wmi.c +129
-56@@ -31,6 +31,7 @@#include <acpi/video.h> #include <linux/hwmon.h> #include <linux/units.h> +#include <linux/unaligned.h> #include <linux/bitfield.h> MODULE_AUTHOR ("Carlos Corbacho" );@@ -68,8 +69,11 @@ MODULE_LICENSE("GPL");#define ACER_WMID_GET_GAMING_SYS_INFO_METHODID 5#define ACER_WMID_SET_GAMING_FAN_BEHAVIOR 14#define ACER_WMID_SET_GAMING_MISC_SETTING_METHODID 22 +#define ACER_WMID_GET_GAMING_MISC_SETTING_METHODID 23 -#define ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET 0x54 +#define ACER_GAMING_MISC_SETTING_STATUS_MASK GENMASK_ULL(7, 0) +#define ACER_GAMING_MISC_SETTING_INDEX_MASK GENMASK_ULL(7, 0) +#define ACER_GAMING_MISC_SETTING_VALUE_MASK GENMASK_ULL(15, 8)#define ACER_PREDATOR_V4_RETURN_STATUS_BIT_MASK GENMASK_ULL(7, 0)#define ACER_PREDATOR_V4_SENSOR_INDEX_BIT_MASK GENMASK_ULL(15, 8)@@ -115,6 +119,10 @@ enum acer_wmi_predator_v4_sensor_id { ACER_WMID_SENSOR_GPU_TEMPERATURE = 0x0A, }; +enum acer_wmi_gaming_misc_setting { +ACER_WMID_MISC_SETTING_PLATFORM_PROFILE =0x000B , +}; +static const struct key_entry acer_wmi_keymap[]__initconst = { {KE_KEY ,0x01 , {KEY_WLAN } },/* WiFi */ {KE_KEY ,0x03 , {KEY_WLAN } },/* WiFi */ @@ -751,20 +759,12 @@ static bool platform_profile_support;*/ static int last_non_turbo_profile; -enum acer_predator_v4_thermal_profile_ec { -ACER_PREDATOR_V4_THERMAL_PROFILE_ECO =0x04 , -ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO =0x03 , -ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE =0x02 , -ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET =0x01 , -ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED =0x00 , -}; - -enum acer_predator_v4_thermal_profile_wmi { -ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI =0x060B , -ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI =0x050B , -ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI =0x040B , -ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI =0x0B , -ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI =0x010B , +enum acer_predator_v4_thermal_profile { +ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET =0x00 , +ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED =0x01 , +ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE =0x04 , +ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO =0x05 , +ACER_PREDATOR_V4_THERMAL_PROFILE_ECO =0x06 , };/* Find which quirks are needed for a particular vendor/ model pair */ @@ -1477,6 +1477,45 @@ WMI_gaming_execute_u64(u32 method_id, u64 in, u64 *out)return status; } +static int WMI_gaming_execute_u32_u64 (u32 method_id,u32 in,u64 *out) +{ +struct acpi_buffer result = {ACPI_ALLOCATE_BUFFER ,NULL }; +struct acpi_buffer input = { + .length =sizeof (in), + .pointer = &in, + }; +union acpi_object *obj; +acpi_status status; +int ret =0 ; + + status =wmi_evaluate_method (WMID_GUID4 ,0 , method_id, &input, &result); +if (ACPI_FAILURE (status)) +return -EIO ; + + obj = result.pointer; +if (obj && out) { +switch (obj->type) { +case ACPI_TYPE_INTEGER : + *out = obj->integer.value; +break ; +case ACPI_TYPE_BUFFER : +if (obj->buffer.length <sizeof (*out)) + ret = -ENOMSG ; +else + *out =get_unaligned_le64 (obj->buffer.pointer); + +break ; +default : + ret = -ENOMSG ; +break ; + } + } + +kfree (obj); + +return ret; +} +static acpi_status WMID_gaming_set_u64 (u64 value,u32 cap) {u32 method_id =0 ;@@ -1565,6 +1604,48 @@ static void WMID_gaming_set_fan_mode(u8 fan_mode)WMID_gaming_set_u64 (gpu_fan_config2 | gpu_fan_config1 <<16 ,ACER_CAP_TURBO_FAN ); } +static int WMID_gaming_set_misc_setting (enum acer_wmi_gaming_misc_setting setting,u8 value) +{ +acpi_status status; +u64 input =0 ; +u64 result; + + input |=FIELD_PREP (ACER_GAMING_MISC_SETTING_INDEX_MASK , setting); + input |=FIELD_PREP (ACER_GAMING_MISC_SETTING_VALUE_MASK , value); + + status =WMI_gaming_execute_u64 (ACER_WMID_SET_GAMING_MISC_SETTING_METHODID , input, &result); +if (ACPI_FAILURE (status)) +return -EIO ; + +/* The return status must be zero for the operation to have succeeded */ +if (FIELD_GET (ACER_GAMING_MISC_SETTING_STATUS_MASK , result)) +return -EIO ; + +return 0 ; +} + +static int WMID_gaming_get_misc_setting (enum acer_wmi_gaming_misc_setting setting,u8 *value) +{ +u64 input =0 ; +u64 result; +int ret; + + input |=FIELD_PREP (ACER_GAMING_MISC_SETTING_INDEX_MASK , setting); + + ret =WMI_gaming_execute_u32_u64 (ACER_WMID_GET_GAMING_MISC_SETTING_METHODID , input, + &result); +if (ret <0 ) +return ret; + +/* The return status must be zero for the operation to have succeeded */ +if (FIELD_GET (ACER_GAMING_MISC_SETTING_STATUS_MASK , result)) +return -EIO ; + + *value =FIELD_GET (ACER_GAMING_MISC_SETTING_VALUE_MASK , result); + +return 0 ; +} +/* * Generic Device (interface-independent) */ @@ -1833,9 +1914,8 @@ acer_predator_v4_platform_profile_get(struct platform_profile_handler *pprof,u8 tp;int err; - err =ec_read (ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET , &tp); - -if (err <0 ) + err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , &tp); +if (err)return err;switch (tp) {@@ -1865,36 +1945,33 @@ static int acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, enum platform_profile_option profile) { - int tp; -acpi_status status; + int err, tp;switch (profile) {case PLATFORM_PROFILE_PERFORMANCE : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;case PLATFORM_PROFILE_BALANCED_PERFORMANCE : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE ;break ;case PLATFORM_PROFILE_BALANCED : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;break ;case PLATFORM_PROFILE_QUIET : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET ;break ;case PLATFORM_PROFILE_LOW_POWER : - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ;break ;default :return -EOPNOTSUPP ; } - status =WMI_gaming_execute_u64 ( -ACER_WMID_SET_GAMING_MISC_SETTING_METHODID , tp,NULL ); - -if (ACPI_FAILURE (status)) -return -EIO ; + err =WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , tp); +if (err) +return err; -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ) +if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) last_non_turbo_profile = tp;return 0 ;@@ -1931,7 +2008,7 @@ static int acer_platform_profile_setup(struct platform_device *device)/* Set default non-turbo profile */ last_non_turbo_profile = -ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; +ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; }return 0 ; }@@ -1946,12 +2023,10 @@ static int acer_thermal_profile_change(void)u8 current_tp;int tp, err;u64 on_AC; -acpi_status status; - - err =ec_read (ACER_PREDATOR_V4_THERMAL_PROFILE_EC_OFFSET , - ¤t_tp); -if (err <0 ) + err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , + ¤t_tp); +if (err)return err;/* Check power source */ @@ -1962,54 +2037,52 @@ static int acer_thermal_profile_change(void)switch (current_tp) {case ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ;else tp = last_non_turbo_profile;break ;case ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;case ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ;else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE ;else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;case ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;case ACER_PREDATOR_V4_THERMAL_PROFILE_ECO :if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ;else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET ;else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ; + tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ;break ;default :return -EOPNOTSUPP ; } - status =WMI_gaming_execute_u64 ( -ACER_WMID_SET_GAMING_MISC_SETTING_METHODID , tp,NULL ); - -if (ACPI_FAILURE (status)) -return -EIO ; + err =WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , tp); +if (err) +return err;/* Store non-turbo profile for turbo mode toggle*/ -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO_WMI ) +if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) last_non_turbo_profile = tp;platform_profile_notify (&platform_profile_handler);
Re: [PATCH v3 2/5] platform/x86: acer-wmi: use new helper function for setting overclocks
In reply to Hridesh MGQuoted 4 lines · Hridesh MG
Migrate the OC handling in
acer_toggle_turbo()to the new helper function for issuing the SetGamingMiscSetting WMI call.Signed-off-by Hridesh MG <[email protected]>
Quoted 63 lines
--- drivers/platform/x86/acer-wmi.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)drivers/platform/x86/acer-wmi.c +19
-7@@ -119,7 +119,14 @@ enum acer_wmi_predator_v4_sensor_id { ACER_WMID_SENSOR_GPU_TEMPERATURE = 0x0A, }; +enum acer_wmi_predator_v4_oc { +ACER_WMID_OC_NORMAL =0x0000 , +ACER_WMID_OC_TURBO =0x0002 , +}; +enum acer_wmi_gaming_misc_setting { +ACER_WMID_MISC_SETTING_OC_1 =0x0005 , +ACER_WMID_MISC_SETTING_OC_2 =0x0007 ,ACER_WMID_MISC_SETTING_PLATFORM_PROFILE =0x000B , };@@ -1530,9 +1537,6 @@ static acpi_status WMID_gaming_set_u64(u64 value, u32 cap)case ACER_CAP_TURBO_FAN : method_id =ACER_WMID_SET_GAMING_FAN_BEHAVIOR ;break ; -case ACER_CAP_TURBO_OC : - method_id =ACER_WMID_SET_GAMING_MISC_SETTING_METHODID ; -break ;default :return AE_BAD_PARAMETER ; }@@ -1891,8 +1895,12 @@ static int acer_toggle_turbo(void)WMID_gaming_set_fan_mode (0x1 );/* Set OC to normal */ -WMID_gaming_set_u64 (0x5 ,ACER_CAP_TURBO_OC ); -WMID_gaming_set_u64 (0x7 ,ACER_CAP_TURBO_OC ); +if (has_cap (ACER_CAP_TURBO_OC )) { +WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_OC_1 , +ACER_WMID_OC_NORMAL ); +WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_OC_2 , +ACER_WMID_OC_NORMAL ); + } }else {/* Turn on turbo led */ WMID_gaming_set_u64 (0x10001 ,ACER_CAP_TURBO_LED );@@ -1901,8 +1909,12 @@ static int acer_toggle_turbo(void)WMID_gaming_set_fan_mode (0x2 );/* Set OC to turbo mode */ -WMID_gaming_set_u64 (0x205 ,ACER_CAP_TURBO_OC ); -WMID_gaming_set_u64 (0x207 ,ACER_CAP_TURBO_OC ); +if (has_cap (ACER_CAP_TURBO_OC )) { +WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_OC_1 , +ACER_WMID_OC_TURBO ); +WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_OC_2 , +ACER_WMID_OC_TURBO ); + } }return turbo_led_state; }
Re: [PATCH v3 3/5] platform/x86: acer-wmi: simplify platform profile cycling
In reply to Hridesh MGQuoted 32 lines · Hridesh MG
Make use of
platform_profile_cycle()to simplify the logic used for cycling through the different platform profiles. Also remove the unnecessary handling for AC power, as the hardware accepts different profiles regardless of whether AC is plugged in.Signed-off-by Hridesh MG <[email protected]>--- drivers/platform/x86/acer-wmi.c | 80 ++++++++++------------------------------- 1 file changed, 19 insertions(+), 61 deletions(-)drivers/platform/x86/acer-wmi.c +2
-7@@ -2028,76 +2028,34 @@ static int acer_platform_profile_setup(struct platform_device *device)static int acer_thermal_profile_change (void ) {/* -* This mode key can rotate each mode or toggle turbo mode. -* On battery, only ECO and BALANCED mode are available. +* This mode key will either cycle through each mode or toggle the turbo profile. */ if (quirks->predator_v4) {u8 current_tp; -int tp, err; -u64 on_AC; +int err, tp; - err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , - ¤t_tp); -if (err)
drivers/platform/x86/acer-wmi.c static int acer_platform_profile_setup(struct platform_device *device) · line 2040
Quoted 10 lines
drivers/platform/x86/acer-wmi.c +4
-6-return err; - -/* Check power source */ - err =WMID_gaming_get_sys_info (ACER_WMID_CMD_GET_PREDATOR_V4_BAT_STATUS , &on_AC); -if (err <0 ) -return err; +if (cycle_gaming_thermal_profile) { +platform_profile_cycle (); + }else { + err = WMID_gaming_get_misc_setting(ACER_WMID_MISC_SETTING_PLATFORM_PROFILE,
nit: Break this line like you did bellow.
Quoted 10 lines
drivers/platform/x86/acer-wmi.c +3
-6+ ¤t_tp); +if (err) +return err; -switch (current_tp) { -case ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ;
drivers/platform/x86/acer-wmi.c static int acer_platform_profile_setup(struct platform_device *device) · line 2048
Quoted 10 lines
drivers/platform/x86/acer-wmi.c +3
-6-else +if (current_tp ==ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) { tp = last_non_turbo_profile; -break ; -case ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else + }else { + last_non_turbo_profile = current_tp;
WMID_gaming_set_misc_setting() may fail, so I think you should set last_non_turbo_profile after call has succeeded.
~ Kurt
Quoted 49 lines
drivers/platform/x86/acer-wmi.c +7
-36tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; -break ; -case ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_ECO ; -else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE ; -else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; -break ; -case ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; -break ; -case ACER_PREDATOR_V4_THERMAL_PROFILE_ECO : -if (!on_AC) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED ; -else if (cycle_gaming_thermal_profile) - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET ; -else - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; -break ; -default : -return -EOPNOTSUPP ; - } - - err =WMID_gaming_set_misc_setting (ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , tp); -if (err) -return err; + } -/* Store non-turbo profile for turbo mode toggle*/ -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) - last_non_turbo_profile = tp; + err =WMID_gaming_set_misc_setting ( +ACER_WMID_MISC_SETTING_PLATFORM_PROFILE , tp); +if (err) +return err; -platform_profile_notify (&platform_profile_handler); +platform_profile_notify (&platform_profile_handler); + } }return 0 ;
Re: [PATCH v3 4/5] platform/x86: acer-wmi: use an ACPI bitmap to set the platform profile choices
In reply to Hridesh MGQuoted 40 lines · Hridesh MG
Currently the choices for the platform profile are hardcoded. There is an ACPI bitmap accessible via WMI that specifies the supported profiles, use this bitmap to dynamically set the choices for the platform profile.
Signed-off-by Hridesh MG <[email protected]>--- drivers/platform/x86/acer-wmi.c | 55 +++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-)drivers/platform/x86/acer-wmi.c +3
-1@@ -33,6 +33,7 @@#include <linux/units.h> #include <linux/unaligned.h> #include <linux/bitfield.h> +#include <linux/bitmap.h> MODULE_AUTHOR ("Carlos Corbacho" );MODULE_DESCRIPTION ("Acer Laptop WMI Extras Driver" );@@ -127,6 +128,7 @@ enum acer_wmi_predator_v4_oc {enum acer_wmi_gaming_misc_setting {ACER_WMID_MISC_SETTING_OC_1 =0x0005 ,ACER_WMID_MISC_SETTING_OC_2 =0x0007 , +ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES =0x000A ,ACER_WMID_MISC_SETTING_PLATFORM_PROFILE =0x000B , };@@ -1957,7 +1959,7 @@ static int acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, enum platform_profile_option profile) { - int err, tp; + int max_perf, err, tp;switch (profile) {case PLATFORM_PROFILE_PERFORMANCE :
drivers/platform/x86/acer-wmi.c acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, · line 1991
Quoted 8 lines
drivers/platform/x86/acer-wmi.c +4
-1@@ -1983,7 +1985,10 @@ acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,if (err)return err; -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) + max_perf =find_last_bit (platform_profile_handler.choices, +PLATFORM_PROFILE_LAST ); + +if (tp != max_perf)
You can't directly compare tp and max_perf. ACER_PREDATOR_V4 values may not match PLATFORM_PROFILE ones.
It does in the case of PERFORMANCE and TURBO, but it does not in the case of QUIET and BALANCED.
I suggest you store the actual ACER_PREDATOR_V4 max_perf when setting up the platform_profile.
Quoted 67 lines
drivers/platform/x86/acer-wmi.c +27
-12last_non_turbo_profile = tp;return 0 ;@@ -1992,6 +1997,7 @@ acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,static int acer_platform_profile_setup (struct platform_device *device) {if (quirks->predator_v4) { +unsigned long supported_profiles;int err; platform_profile_handler.name ="acer-wmi" ;@@ -2001,16 +2007,30 @@ static int acer_platform_profile_setup(struct platform_device *device) platform_profile_handler.profile_set = acer_predator_v4_platform_profile_set; -set_bit (PLATFORM_PROFILE_PERFORMANCE , - platform_profile_handler.choices); -set_bit (PLATFORM_PROFILE_BALANCED_PERFORMANCE , - platform_profile_handler.choices); -set_bit (PLATFORM_PROFILE_BALANCED , - platform_profile_handler.choices); -set_bit (PLATFORM_PROFILE_QUIET , - platform_profile_handler.choices); -set_bit (PLATFORM_PROFILE_LOW_POWER , - platform_profile_handler.choices); + err =WMID_gaming_get_misc_setting (ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES , + (u8 *)&supported_profiles); +if (err) +return err; + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET , &supported_profiles)) +set_bit (PLATFORM_PROFILE_QUIET , + platform_profile_handler.choices); + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED , &supported_profiles)) +set_bit (PLATFORM_PROFILE_BALANCED , + platform_profile_handler.choices); + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE , &supported_profiles)) +set_bit (PLATFORM_PROFILE_BALANCED_PERFORMANCE , + platform_profile_handler.choices); + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO , &supported_profiles)) +set_bit (PLATFORM_PROFILE_PERFORMANCE , + platform_profile_handler.choices); + +if (test_bit (ACER_PREDATOR_V4_THERMAL_PROFILE_ECO , &supported_profiles)) +set_bit (PLATFORM_PROFILE_LOW_POWER , + platform_profile_handler.choices); err =platform_profile_register (&platform_profile_handler);if (err)@@ -2028,11 +2048,11 @@ static int acer_platform_profile_setup(struct platform_device *device)static int acer_thermal_profile_change (void ) {/* -* This mode key will either cycle through each mode or toggle the turbo profile. +* This mode key will either cycle through each mode or toggle the most performant profile. */ if (quirks->predator_v4) {u8 current_tp; -int err, tp; +int max_perf, err, tp;if (cycle_gaming_thermal_profile) {platform_profile_cycle ();
drivers/platform/x86/acer-wmi.c static int acer_thermal_profile_change(void) · line 2068
Quoted 8 lines
drivers/platform/x86/acer-wmi.c +4
-1@@ -2042,11 +2062,14 @@ static int acer_thermal_profile_change(void)if (err)return err; -if (current_tp ==ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) { + max_perf =find_last_bit (platform_profile_handler.choices, +PLATFORM_PROFILE_LAST ); + +if (current_tp == max_perf) {
Same as above.
~ Kurt
Quoted 8 lines
drivers/platform/x86/acer-wmi.c +1
-1tp = last_non_turbo_profile; }else { last_non_turbo_profile = current_tp; - tp =ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ; + tp = max_perf; } err = WMID_gaming_set_misc_setting(
Re: [PATCH v3 4/5] platform/x86: acer-wmi: use an ACPI bitmap to set the platform profile choices
Quoted 54 lines · Kurt Borja
Quoted 40 lines · Hridesh MG
Currently the choices for the platform profile are hardcoded. There is an ACPI bitmap accessible via WMI that specifies the supported profiles, use this bitmap to dynamically set the choices for the platform profile.
Signed-off-by Hridesh MG <[email protected]>--- drivers/platform/x86/acer-wmi.c | 55 +++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-)drivers/platform/x86/acer-wmi.c +3
-1@@ -33,6 +33,7 @@#include <linux/units.h> #include <linux/unaligned.h> #include <linux/bitfield.h> +#include <linux/bitmap.h> MODULE_AUTHOR ("Carlos Corbacho" );MODULE_DESCRIPTION ("Acer Laptop WMI Extras Driver" );@@ -127,6 +128,7 @@ enum acer_wmi_predator_v4_oc {enum acer_wmi_gaming_misc_setting {ACER_WMID_MISC_SETTING_OC_1 =0x0005 ,ACER_WMID_MISC_SETTING_OC_2 =0x0007 , +ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES =0x000A ,ACER_WMID_MISC_SETTING_PLATFORM_PROFILE =0x000B , };@@ -1957,7 +1959,7 @@ static int acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, enum platform_profile_option profile) { - int err, tp; + int max_perf, err, tp;switch (profile) {case PLATFORM_PROFILE_PERFORMANCE :drivers/platform/x86/acer-wmi.c acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, · line 1991
Quoted 8 lines
drivers/platform/x86/acer-wmi.c +4
-1@@ -1983,7 +1985,10 @@ acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,if (err)return err; -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) + max_perf =find_last_bit (platform_profile_handler.choices, +PLATFORM_PROFILE_LAST ); + +if (tp != max_perf)You can't directly compare
tpandmax_perf.ACER_PREDATOR_V4values may not matchPLATFORM_PROFILEones.
Quoted 5 lines
It does in the case of PERFORMANCE and TURBO, but it does not in the case of QUIET and BALANCED.
I suggest you store the actual
ACER_PREDATOR_V4max_perfwhen setting up theplatform_profile.
Ah this was quite a stupid mistake. I'm not sure why I even assumed both were equivalent. I have one doubt though, if i set it during profile setup, the code becomes quite verbose -
/* Iterate through supported profiles in order of increasing
performance */
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_ECO,
&supported_profiles)) {
set_bit(PLATFORM_PROFILE_LOW_POWER,
platform_profile_handler.choices);
max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
}
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET,
&supported_profiles)) {
set_bit(PLATFORM_PROFILE_QUIET,
platform_profile_handler.choices);
max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
}
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED,
&supported_profiles)) {
set_bit(PLATFORM_PROFILE_BALANCED,
platform_profile_handler.choices);
max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
}
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE,
&supported_profiles)) {
set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE,
platform_profile_handler.choices);
max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
}
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO,
&supported_profiles)) {
set_bit(PLATFORM_PROFILE_PERFORMANCE,
platform_profile_handler.choices);
max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
}Is this fine? Maybe for readability's sake, I could lift it up into a different function, like what you did in the RFC patch. Btw, thanks a lot for the detailed reviews so far—they’ve been very helpful!
--
Thanks,
Hridesh MG
Re: [PATCH v3 4/5] platform/x86: acer-wmi: use an ACPI bitmap to set the platform profile choices
Quoted 92 lines · Hridesh MG
Quoted 54 lines · Kurt Borja
Quoted 40 lines · Hridesh MG
Currently the choices for the platform profile are hardcoded. There is an ACPI bitmap accessible via WMI that specifies the supported profiles, use this bitmap to dynamically set the choices for the platform profile.
Signed-off-by Hridesh MG <[email protected]>--- drivers/platform/x86/acer-wmi.c | 55 +++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-)drivers/platform/x86/acer-wmi.c +3
-1@@ -33,6 +33,7 @@#include <linux/units.h> #include <linux/unaligned.h> #include <linux/bitfield.h> +#include <linux/bitmap.h> MODULE_AUTHOR ("Carlos Corbacho" );MODULE_DESCRIPTION ("Acer Laptop WMI Extras Driver" );@@ -127,6 +128,7 @@ enum acer_wmi_predator_v4_oc {enum acer_wmi_gaming_misc_setting {ACER_WMID_MISC_SETTING_OC_1 =0x0005 ,ACER_WMID_MISC_SETTING_OC_2 =0x0007 , +ACER_WMID_MISC_SETTING_SUPPORTED_PROFILES =0x000A ,ACER_WMID_MISC_SETTING_PLATFORM_PROFILE =0x000B , };@@ -1957,7 +1959,7 @@ static int acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, enum platform_profile_option profile) { - int err, tp; + int max_perf, err, tp;switch (profile) {case PLATFORM_PROFILE_PERFORMANCE :drivers/platform/x86/acer-wmi.c acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof, · line 1991
Quoted 8 lines
drivers/platform/x86/acer-wmi.c +4
-1@@ -1983,7 +1985,10 @@ acer_predator_v4_platform_profile_set(struct platform_profile_handler *pprof,if (err)return err; -if (tp !=ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO ) + max_perf =find_last_bit (platform_profile_handler.choices, +PLATFORM_PROFILE_LAST ); + +if (tp != max_perf)You can't directly compare
tpandmax_perf.ACER_PREDATOR_V4values may not matchPLATFORM_PROFILEones.Quoted 5 lines
It does in the case of PERFORMANCE and TURBO, but it does not in the case of QUIET and BALANCED.
I suggest you store the actual
ACER_PREDATOR_V4max_perfwhen setting up theplatform_profile.Ah this was quite a stupid mistake. I'm not sure why I even assumed both were equivalent. I have one doubt though, if i set it during profile setup, the code becomes quite verbose -
/* Iterate through supported profiles in order of increasing performance */ if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_ECO, &supported_profiles)) { set_bit(PLATFORM_PROFILE_LOW_POWER, platform_profile_handler.choices); max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO; } if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET, &supported_profiles)) { set_bit(PLATFORM_PROFILE_QUIET, platform_profile_handler.choices); max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET; } if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED, &supported_profiles)) { set_bit(PLATFORM_PROFILE_BALANCED, platform_profile_handler.choices); max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED; } if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE, &supported_profiles)) { set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, platform_profile_handler.choices); max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
Quoted 8 lines
}
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO,
&supported_profiles)) {
set_bit(PLATFORM_PROFILE_PERFORMANCE,
platform_profile_handler.choices);
max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
}Hi Hridesh,
It looks a bit verbose, but for me it's fine, it even caches the value. If max_perf is a global variable now, rename it to something like acer_predator_v4_max_perf.
Quoted 4 lines
Is this fine? Maybe for readability's sake, I could lift it up into a different function, like what you did in the RFC patch. Btw, thanks a lot for the detailed reviews so far—they’ve been very helpful!
Glad I can help :)
~ Kurt
Quoted 4 lines
--
Thanks,
Hridesh MG