Skip to contentSkip to conversation

platform/x86: asus-wmi: add support for vivobook fan profiles

PATCH In review Mohamed Ghanmi 3 participants 8 messages Jun 9, 2024 – Aug 1, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v4 cover platform/x86: asus-wmi: add support for vivobook fan profiles

Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK to adjust power limits.

These fan profiles have a different device id than the ROG series and different order. This reorders the existing modes.

As part of keeping the patch clean the throttle_thermal_policy_available boolean stored in the driver struct is removed and throttle_thermal_policy_dev is used in place (as on init it is zeroed).

Changelog:
- V1
- fixes grammar in description
- reorders macros
- adds throttle_thermal_policy_max_mode() helper function
- V2
- removes unnecessary braces in throttle_thermal_policy_max_mode()
- V3
- fixes a use before declaration compilation error caused by reordering of local variables in throttle_thermal_policy_store() function
- V4
- removes the fullspeed mode
- moves the remapping from throttle thermal policy to Platform profiles

 drivers/platform/x86/asus-wmi.c            | 125 ++++++++++++---------
 include/linux/platform_data/x86/asus-wmi.h |   1 +
 2 files changed, 76 insertions(+), 50 deletions(-)
Signature · 1 line
2.44.0
#1 lore raw

PATCH v4 1/1 platform/x86: asus-wmi: add support for vivobook fan profiles

Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK to adjust power limits.

These fan profiles have a different device id than the ROG series and different order. This reorders the existing modes.

As part of keeping the patch clean the throttle_thermal_policy_available boolean stored in the driver struct is removed and throttle_thermal_policy_dev is used in place (as on init it is zeroed).

---
 drivers/platform/x86/asus-wmi.c            | 125 ++++++++++++---------
 include/linux/platform_data/x86/asus-wmi.h |   1 +
 2 files changed, 76 insertions(+), 50 deletions(-)
drivers/platform/x86/asus-wmi.c +75 -50
index 3c61d75a3..2e3d8d8fb 100644
@@ -97,6 +97,12 @@ module_param(fnlock_default, bool, 0444);
 #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST	1
 #define ASUS_THROTTLE_THERMAL_POLICY_SILENT	2
 
+#define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO	0
+#define ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO	1
+#define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO	2
+
+#define PLATFORM_PROFILE_MAX 2
+
 #define USB_INTEL_XUSB2PR		0xD0
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI	0x9c31
 
@@ -293,8 +299,8 @@ struct asus_wmi {
 	u32 kbd_rgb_dev;
 	bool kbd_rgb_state_available;
 
-	bool throttle_thermal_policy_available;
 	u8 throttle_thermal_policy_mode;
+	u32 throttle_thermal_policy_dev;
 
 	bool cpu_fan_curve_available;
 	bool gpu_fan_curve_available;
@@ -3152,7 +3158,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)
 	int err, fan_idx;
 	u8 mode = 0;
 
-	if (asus->throttle_thermal_policy_available)
+	if (asus->throttle_thermal_policy_dev)
 		mode = asus->throttle_thermal_policy_mode;
 	/* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
 	if (mode == 2)
@@ -3359,7 +3365,7 @@ static ssize_t fan_curve_enable_store(struct device *dev,
 		 * For machines with throttle this is the only way to reset fans
 		 * to default mode of operation (does not erase curve data).
 		 */
-		if (asus->throttle_thermal_policy_available) {
+		if (asus->throttle_thermal_policy_dev) {
 			err = throttle_thermal_policy_write(asus);
 			if (err)
 				return err;
@@ -3576,8 +3582,8 @@ static const struct attribute_group asus_fan_curve_attr_group = {
 __ATTRIBUTE_GROUPS(asus_fan_curve_attr);
 
 /*
- * Must be initialised after throttle_thermal_policy_check_present() as
- * we check the status of throttle_thermal_policy_available during init.
+ * Must be initialised after throttle_thermal_policy_dev is set as
+ * we check the status of throttle_thermal_policy_dev during init.
  */
 static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 {
@@ -3618,38 +3624,13 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 }
 
 /* Throttle thermal policy ****************************************************/
-
-static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
-{
-	u32 result;
-	int err;
-
-	asus->throttle_thermal_policy_available = false;
-
-	err = asus_wmi_get_devstate(asus,
-				    ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
-				    &result);
-	if (err) {
-		if (err == -ENODEV)
-			return 0;
-		return err;
-	}
-
-	if (result & ASUS_WMI_DSTS_PRESENCE_BIT)
-		asus->throttle_thermal_policy_available = true;
-
-	return 0;
-}
-
 static int throttle_thermal_policy_write(struct asus_wmi *asus)
 {
-	int err;
-	u8 value;
+	u8 value = asus->throttle_thermal_policy_mode;
 	u32 retval;
+	int err;
 
-	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_dev,
 				    value, &retval);
 
 	sysfs_notify(&asus->platform_device->dev.kobj, NULL,
@@ -3679,7 +3660,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
 
 static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
 {
-	if (!asus->throttle_thermal_policy_available)
+	if (!asus->throttle_thermal_policy_dev)
 		return 0;
 
 	asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
@@ -3691,7 +3672,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 > PLATFORM_PROFILE_MAX)
 		new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
 
 	asus->throttle_thermal_policy_mode = new_mode;
@@ -3730,7 +3711,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 > PLATFORM_PROFILE_MAX)
 		return -EINVAL;
 
 	asus->throttle_thermal_policy_mode = new_mode;
@@ -3747,10 +3728,56 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
 	return count;
 }
 
-// Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+/*
+ * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+ */
 static DEVICE_ATTR_RW(throttle_thermal_policy);
 
 /* Platform profile ***********************************************************/
+static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus,
+						  int mode)
+{
+	bool vivo;
+
+	vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+	if (vivo) {
+		switch (mode) {
+		case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
+			return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO;
+		case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
+			return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO;
+		case ASUS_THROTTLE_THERMAL_POLICY_SILENT:
+			return ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO;
+		}
+	}
+
+	return mode;
+
+}
+
+static int asus_wmi_platform_profile_mode_from_vivo(struct asus_wmi *asus,
+						  int mode)
+{
+	bool vivo;
+
+	vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+	if (vivo) {
+		switch (mode) {
+		case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO:
+			return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
+		case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO:
+			return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST;
+		case ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO:
+			return ASUS_THROTTLE_THERMAL_POLICY_SILENT;
+		}
+	}
+
+	return mode;
+
+}
+
 static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 					enum platform_profile_option *profile)
 {
@@ -3758,10 +3785,9 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 	int tp;
 
 	asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
-
 	tp = asus->throttle_thermal_policy_mode;
 
-	switch (tp) {
+	switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) {
 	case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
 		*profile = PLATFORM_PROFILE_BALANCED;
 		break;
@@ -3775,6 +3801,7 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 		return -EINVAL;
 	}
 
+
 	return 0;
 }
 
@@ -3800,7 +3827,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
 		return -EOPNOTSUPP;
 	}
 
-	asus->throttle_thermal_policy_mode = tp;
+	asus->throttle_thermal_policy_mode = asus_wmi_platform_profile_to_vivo(asus, tp);
 	return throttle_thermal_policy_write(asus);
 }
 
@@ -3813,7 +3840,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 	 * Not an error if a component platform_profile relies on is unavailable
 	 * so early return, skipping the setup of platform_profile.
 	 */
-	if (!asus->throttle_thermal_policy_available)
+	if (!asus->throttle_thermal_policy_dev)
 		return 0;
 
 	dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n");
@@ -4228,7 +4255,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
 	if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) {
 		if (asus->fan_boost_mode_available)
 			fan_boost_mode_switch_next(asus);
-		if (asus->throttle_thermal_policy_available)
+		if (asus->throttle_thermal_policy_dev)
 			throttle_thermal_policy_switch_next(asus);
 		return;
 
@@ -4436,7 +4463,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
 	else if (attr == &dev_attr_fan_boost_mode.attr)
 		ok = asus->fan_boost_mode_available;
 	else if (attr == &dev_attr_throttle_thermal_policy.attr)
-		ok = asus->throttle_thermal_policy_available;
+		ok = asus->throttle_thermal_policy_dev != 0;
 	else if (attr == &dev_attr_ppt_pl2_sppt.attr)
 		devid = ASUS_WMI_DEVID_PPT_PL2_SPPT;
 	else if (attr == &dev_attr_ppt_pl1_spl.attr)
@@ -4745,16 +4772,15 @@ static int asus_wmi_add(struct platform_device *pdev)
 	else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2))
 		asus->kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2;
 
+	if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY))
+		asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY;
+	else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO))
+		asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
 	err = fan_boost_mode_check_present(asus);
 	if (err)
 		goto fail_fan_boost_mode;
 
-	err = throttle_thermal_policy_check_present(asus);
-	if (err)
-		goto fail_throttle_thermal_policy;
-	else
-		throttle_thermal_policy_set_default(asus);
-
 	err = platform_profile_setup(asus);
 	if (err)
 		goto fail_platform_profile_setup;
@@ -4849,7 +4875,6 @@ static int asus_wmi_add(struct platform_device *pdev)
 fail_input:
 	asus_wmi_sysfs_exit(asus->platform_device);
 fail_sysfs:
-fail_throttle_thermal_policy:
 fail_custom_fan_curve:
 fail_platform_profile_setup:
 	if (asus->platform_profile_support)
include/linux/platform_data/x86/asus-wmi.h +1 -0
index 3eb5cd677..982a63774 100644
@@ -64,6 +64,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_VIVO 0x00110019
 
 /* Misc */
 #define ASUS_WMI_DEVID_PANEL_OD		0x00050019
Signature · 1 line
2.44.0
maintainer
#2 lore raw
Quoted 146 lines · Mohamed Ghanmi

Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK to adjust power limits.

These fan profiles have a different device id than the ROG series and different order. This reorders the existing modes.

As part of keeping the patch clean the throttle_thermal_policy_available boolean stored in the driver struct is removed and throttle_thermal_policy_dev is used in place (as on init it is zeroed).

---
drivers/platform/x86/asus-wmi.c | 125 ++++++++++++---------
include/linux/platform_data/x86/asus-wmi.h | 1 +

2 files changed, 76 insertions(+), 50 deletions(-)
drivers/platform/x86/asus-wmi.c +17 -36
index 3c61d75a3..2e3d8d8fb 100644
@@ -97,6 +97,12 @@ module_param(fnlock_default, bool, 0444);
 #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1
 #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2
 
+#define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO 0
+#define ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO 1
+#define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO 2
+
+#define PLATFORM_PROFILE_MAX 2
+
 #define USB_INTEL_XUSB2PR 0xD0
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
 
@@ -293,8 +299,8 @@ struct asus_wmi {
 u32 kbd_rgb_dev;
 bool kbd_rgb_state_available;
 
- bool throttle_thermal_policy_available;
 u8 throttle_thermal_policy_mode;
+ u32 throttle_thermal_policy_dev;
 
 bool cpu_fan_curve_available;
 bool gpu_fan_curve_available;
@@ -3152,7 +3158,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)
 int err, fan_idx;
 u8 mode = 0;
 
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 mode = asus->throttle_thermal_policy_mode;
 /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
 if (mode == 2)
@@ -3359,7 +3365,7 @@ static ssize_t fan_curve_enable_store(struct device *dev,
 * For machines with throttle this is the only way to reset fans
 * to default mode of operation (does not erase curve data).
 */
- if (asus->throttle_thermal_policy_available) {
+ if (asus->throttle_thermal_policy_dev) {
 err = throttle_thermal_policy_write(asus);
 if (err)
 return err;
@@ -3576,8 +3582,8 @@ static const struct attribute_group asus_fan_curve_attr_group = {
 __ATTRIBUTE_GROUPS(asus_fan_curve_attr);
 
 /*
- * Must be initialised after throttle_thermal_policy_check_present() as
- * we check the status of throttle_thermal_policy_available during init.
+ * Must be initialised after throttle_thermal_policy_dev is set as
+ * we check the status of throttle_thermal_policy_dev during init.
  */
 static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 {
@@ -3618,38 +3624,13 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 }
 
 /* Throttle thermal policy ****************************************************/
-
-static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
-{
- u32 result;
- int err;
-
- asus->throttle_thermal_policy_available = false;
-
- err = asus_wmi_get_devstate(asus,
-     ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
-     &result);
- if (err) {
- if (err == -ENODEV)
- return 0;
- return err;
- }
-
- if (result & ASUS_WMI_DSTS_PRESENCE_BIT)
- asus->throttle_thermal_policy_available = true;
-
- return 0;
-}
-
 static int throttle_thermal_policy_write(struct asus_wmi *asus)
 {
- int err;
- u8 value;
+ u8 value = asus->throttle_thermal_policy_mode;
 u32 retval;
+ int err;
 
- 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_dev,
    value, &retval);
 
 sysfs_notify(&asus->platform_device->dev.kobj, NULL,
@@ -3679,7 +3660,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
 
 static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
 {
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
@@ -3691,7 +3672,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 > PLATFORM_PROFILE_MAX)
 new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3730,7 +3711,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 > PLATFORM_PROFILE_MAX)
 return -EINVAL;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3747,10 +3728,56 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
 return count;
 }

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3738

Quoted 10 lines
drivers/platform/x86/asus-wmi.c +5 -1
 
-// Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+/*
+ * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+ */
 static DEVICE_ATTR_RW(throttle_thermal_policy);
 
 /* Platform profile ***********************************************************/
+static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus,
+   int mode)

Given the internals of this function I'm still not sure if this naming makes sense. Perhaps "maybe_platform_profile_to_vivo()"

Quoted 12 lines
drivers/platform/x86/asus-wmi.c +12 -0
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT:

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3760

Quoted 10 lines
drivers/platform/x86/asus-wmi.c +10 -0
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO;
+ }
+ }
+
+ return mode;
+
+}
+
+static int asus_wmi_platform_profile_mode_from_vivo(struct asus_wmi *asus,
+   int mode)

Same as the last function.

Quoted 124 lines
drivers/platform/x86/asus-wmi.c +21 -2
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT;
+ }
+ }
+
+ return mode;
+
+}
+
 static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 enum platform_profile_option *profile)
 {
@@ -3758,10 +3785,9 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 int tp;
 
 asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
-
 tp = asus->throttle_thermal_policy_mode;
 
- switch (tp) {
+ switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) {

case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
*profile = PLATFORM_PROFILE_BALANCED;
break;

drivers/platform/x86/asus-wmi.c +10 -10
@@ -3775,6 +3801,7 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 return -EINVAL;
 }
 
+
 return 0;
 }
 
@@ -3800,7 +3827,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
 return -EOPNOTSUPP;
 }
 
- asus->throttle_thermal_policy_mode = tp;
+ asus->throttle_thermal_policy_mode = asus_wmi_platform_profile_to_vivo(asus, tp);
 return throttle_thermal_policy_write(asus);
 }
 
@@ -3813,7 +3840,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 * Not an error if a component platform_profile relies on is unavailable
 * so early return, skipping the setup of platform_profile.
 */
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n");
@@ -4228,7 +4255,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
 if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) {
 if (asus->fan_boost_mode_available)
 fan_boost_mode_switch_next(asus);
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 throttle_thermal_policy_switch_next(asus);
 return;
 
@@ -4436,7 +4463,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
 else if (attr == &dev_attr_fan_boost_mode.attr)
 ok = asus->fan_boost_mode_available;
 else if (attr == &dev_attr_throttle_thermal_policy.attr)
- ok = asus->throttle_thermal_policy_available;
+ ok = asus->throttle_thermal_policy_dev != 0;
 else if (attr == &dev_attr_ppt_pl2_sppt.attr)
 devid = ASUS_WMI_DEVID_PPT_PL2_SPPT;
 else if (attr == &dev_attr_ppt_pl1_spl.attr)
@@ -4745,16 +4772,15 @@ static int asus_wmi_add(struct platform_device *pdev)
 else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2))
 asus->kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2;
 
+ if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY;
+ else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
 err = fan_boost_mode_check_present(asus);
 if (err)
 goto fail_fan_boost_mode;
 
- err = throttle_thermal_policy_check_present(asus);
- if (err)
- goto fail_throttle_thermal_policy;
- else
- throttle_thermal_policy_set_default(asus);
-
 err = platform_profile_setup(asus);
 if (err)
 goto fail_platform_profile_setup;
@@ -4849,7 +4875,6 @@ static int asus_wmi_add(struct platform_device *pdev)

fail_input:
asus_wmi_sysfs_exit(asus->platform_device);
fail_sysfs:
-fail_throttle_thermal_policy:
fail_custom_fan_curve:
fail_platform_profile_setup:
if (asus->platform_profile_support)

include/linux/platform_data/x86/asus-wmi.h +1 -0
index 3eb5cd677..982a63774 100644
@@ -64,6 +64,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_VIVO 0x00110019
 
 /* Misc */
 #define ASUS_WMI_DEVID_PANEL_OD 0x00050019
Signature · 1 line
2.44.0

If Hans and Ilpo don't have any requirements then:

#3 lore raw
Quoted 156 lines · Luke Jones
Quoted 153 lines · Mohamed Ghanmi

Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK to adjust power limits.

These fan profiles have a different device id than the ROG series and different order. This reorders the existing modes.

As part of keeping the patch clean the throttle_thermal_policy_available boolean stored in the driver struct is removed and throttle_thermal_policy_dev is used in place (as on init it is zeroed).

---
drivers/platform/x86/asus-wmi.c | 125 ++++++++++++---------
include/linux/platform_data/x86/asus-wmi.h | 1 +

2 files changed, 76 insertions(+), 50 deletions(-)
drivers/platform/x86/asus-wmi.c +20 -37
index 3c61d75a3..2e3d8d8fb 100644
@@ -97,6 +97,12 @@ module_param(fnlock_default, bool, 0444);
 #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1
 #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2
 
+#define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO 0
+#define ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO 1
+#define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO 2
+
+#define PLATFORM_PROFILE_MAX 2
+
 #define USB_INTEL_XUSB2PR 0xD0
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
 
@@ -293,8 +299,8 @@ struct asus_wmi {
 u32 kbd_rgb_dev;
 bool kbd_rgb_state_available;
 
- bool throttle_thermal_policy_available;
 u8 throttle_thermal_policy_mode;
+ u32 throttle_thermal_policy_dev;
 
 bool cpu_fan_curve_available;
 bool gpu_fan_curve_available;
@@ -3152,7 +3158,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)
 int err, fan_idx;
 u8 mode = 0;
 
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 mode = asus->throttle_thermal_policy_mode;
 /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
 if (mode == 2)
@@ -3359,7 +3365,7 @@ static ssize_t fan_curve_enable_store(struct device *dev,
 * For machines with throttle this is the only way to reset fans
 * to default mode of operation (does not erase curve data).
 */
- if (asus->throttle_thermal_policy_available) {
+ if (asus->throttle_thermal_policy_dev) {
 err = throttle_thermal_policy_write(asus);
 if (err)
 return err;
@@ -3576,8 +3582,8 @@ static const struct attribute_group asus_fan_curve_attr_group = {
 __ATTRIBUTE_GROUPS(asus_fan_curve_attr);
 
 /*
- * Must be initialised after throttle_thermal_policy_check_present() as
- * we check the status of throttle_thermal_policy_available during init.
+ * Must be initialised after throttle_thermal_policy_dev is set as
+ * we check the status of throttle_thermal_policy_dev during init.
  */
 static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 {
@@ -3618,38 +3624,13 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 }
 
 /* Throttle thermal policy ****************************************************/
-
-static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
-{
- u32 result;
- int err;
-
- asus->throttle_thermal_policy_available = false;
-
- err = asus_wmi_get_devstate(asus,
-     ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
-     &result);
- if (err) {
- if (err == -ENODEV)
- return 0;
- return err;
- }
-
- if (result & ASUS_WMI_DSTS_PRESENCE_BIT)
- asus->throttle_thermal_policy_available = true;
-
- return 0;
-}
-
 static int throttle_thermal_policy_write(struct asus_wmi *asus)
 {
- int err;
- u8 value;
+ u8 value = asus->throttle_thermal_policy_mode;
 u32 retval;
+ int err;
 
- 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_dev,
    value, &retval);
 
 sysfs_notify(&asus->platform_device->dev.kobj, NULL,
@@ -3679,7 +3660,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
 
 static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
 {
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
@@ -3691,7 +3672,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 > PLATFORM_PROFILE_MAX)
 new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3730,7 +3711,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 > PLATFORM_PROFILE_MAX)
 return -EINVAL;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3747,10 +3728,56 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
 return count;
 }
 
-// Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+/*
+ * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+ */
 static DEVICE_ATTR_RW(throttle_thermal_policy);
 
Quoted 6 lines

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3738

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +2 -0
 /* Platform profile ***********************************************************/
+static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus,
+   int mode)

Given the internals of this function I'm still not sure if this naming makes sense. Perhaps "maybe_platform_profile_to_vivo()"

you're right. this function doesn't only remap to vivo but if the laptop is a not a vivo (in our case a ROG) it doesn't change the mapping.

The way I see it is that there is a logical mapping (the ROG mode mapping) which is stored in the asus_wmi struct and a physical mapping that is used when writing to the acpi device (the vivo in this case). so maybe naming them asus_wmi_platform_profile_from_logical_mapping() and asus_wmi_platform_profile_to_logical_mapping() is a better naming. in the future there will be other device ids for different laptops.

sorry for the late reply

Quoted 16 lines
Quoted 16 lines
drivers/platform/x86/asus-wmi.c +16 -0
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO;
+ }
+ }
+
Quoted 9 lines

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3760

Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6 -0
+ return mode;
+
+}
+
+static int asus_wmi_platform_profile_mode_from_vivo(struct asus_wmi *asus,
+   int mode)

Same as the last function.

same as the above

Quoted 129 lines
Quoted 124 lines
drivers/platform/x86/asus-wmi.c +21 -2
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT;
+ }
+ }
+
+ return mode;
+
+}
+
 static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 enum platform_profile_option *profile)
 {
@@ -3758,10 +3785,9 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 int tp;
 
 asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
-
 tp = asus->throttle_thermal_policy_mode;
 
- switch (tp) {
+ switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) {

case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
*profile = PLATFORM_PROFILE_BALANCED;
break;

drivers/platform/x86/asus-wmi.c +10 -10
@@ -3775,6 +3801,7 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 return -EINVAL;
 }
 
+
 return 0;
 }
 
@@ -3800,7 +3827,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
 return -EOPNOTSUPP;
 }
 
- asus->throttle_thermal_policy_mode = tp;
+ asus->throttle_thermal_policy_mode = asus_wmi_platform_profile_to_vivo(asus, tp);
 return throttle_thermal_policy_write(asus);
 }
 
@@ -3813,7 +3840,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 * Not an error if a component platform_profile relies on is unavailable
 * so early return, skipping the setup of platform_profile.
 */
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n");
@@ -4228,7 +4255,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
 if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) {
 if (asus->fan_boost_mode_available)
 fan_boost_mode_switch_next(asus);
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 throttle_thermal_policy_switch_next(asus);
 return;
 
@@ -4436,7 +4463,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
 else if (attr == &dev_attr_fan_boost_mode.attr)
 ok = asus->fan_boost_mode_available;
 else if (attr == &dev_attr_throttle_thermal_policy.attr)
- ok = asus->throttle_thermal_policy_available;
+ ok = asus->throttle_thermal_policy_dev != 0;
 else if (attr == &dev_attr_ppt_pl2_sppt.attr)
 devid = ASUS_WMI_DEVID_PPT_PL2_SPPT;
 else if (attr == &dev_attr_ppt_pl1_spl.attr)
@@ -4745,16 +4772,15 @@ static int asus_wmi_add(struct platform_device *pdev)
 else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2))
 asus->kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2;
 
+ if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY;
+ else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
 err = fan_boost_mode_check_present(asus);
 if (err)
 goto fail_fan_boost_mode;
 
- err = throttle_thermal_policy_check_present(asus);
- if (err)
- goto fail_throttle_thermal_policy;
- else
- throttle_thermal_policy_set_default(asus);
-
 err = platform_profile_setup(asus);
 if (err)
 goto fail_platform_profile_setup;
@@ -4849,7 +4875,6 @@ static int asus_wmi_add(struct platform_device *pdev)

fail_input:
asus_wmi_sysfs_exit(asus->platform_device);
fail_sysfs:
-fail_throttle_thermal_policy:
fail_custom_fan_curve:
fail_platform_profile_setup:
if (asus->platform_profile_support)

include/linux/platform_data/x86/asus-wmi.h +1 -0
index 3eb5cd677..982a63774 100644
@@ -64,6 +64,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_VIVO 0x00110019
 
 /* Misc */
 #define ASUS_WMI_DEVID_PANEL_OD 0x00050019
Signature · 1 line
2.44.0

If Hans and Ilpo don't have any requirements then:

maintainer
#4 lore raw
Quoted 166 lines · Mohamed Ghanmi
Quoted 156 lines · Luke Jones
Quoted 153 lines · Mohamed Ghanmi

Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK to adjust power limits.

These fan profiles have a different device id than the ROG series and different order. This reorders the existing modes.

As part of keeping the patch clean the throttle_thermal_policy_available boolean stored in the driver struct is removed and throttle_thermal_policy_dev is used in place (as on init it is zeroed).

---
drivers/platform/x86/asus-wmi.c | 125 ++++++++++++---------
include/linux/platform_data/x86/asus-wmi.h | 1 +

2 files changed, 76 insertions(+), 50 deletions(-)
drivers/platform/x86/asus-wmi.c +20 -37
index 3c61d75a3..2e3d8d8fb 100644
@@ -97,6 +97,12 @@ module_param(fnlock_default, bool, 0444);
 #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1
 #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2
 
+#define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO 0
+#define ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO 1
+#define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO 2
+
+#define PLATFORM_PROFILE_MAX 2
+
 #define USB_INTEL_XUSB2PR 0xD0
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
 
@@ -293,8 +299,8 @@ struct asus_wmi {
 u32 kbd_rgb_dev;
 bool kbd_rgb_state_available;
 
- bool throttle_thermal_policy_available;
 u8 throttle_thermal_policy_mode;
+ u32 throttle_thermal_policy_dev;
 
 bool cpu_fan_curve_available;
 bool gpu_fan_curve_available;
@@ -3152,7 +3158,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)
 int err, fan_idx;
 u8 mode = 0;
 
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 mode = asus->throttle_thermal_policy_mode;
 /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
 if (mode == 2)
@@ -3359,7 +3365,7 @@ static ssize_t fan_curve_enable_store(struct device *dev,
 * For machines with throttle this is the only way to reset fans
 * to default mode of operation (does not erase curve data).
 */
- if (asus->throttle_thermal_policy_available) {
+ if (asus->throttle_thermal_policy_dev) {
 err = throttle_thermal_policy_write(asus);
 if (err)
 return err;
@@ -3576,8 +3582,8 @@ static const struct attribute_group asus_fan_curve_attr_group = {
 __ATTRIBUTE_GROUPS(asus_fan_curve_attr);
 
 /*
- * Must be initialised after throttle_thermal_policy_check_present() as
- * we check the status of throttle_thermal_policy_available during init.
+ * Must be initialised after throttle_thermal_policy_dev is set as
+ * we check the status of throttle_thermal_policy_dev during init.
  */
 static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 {
@@ -3618,38 +3624,13 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 }
 
 /* Throttle thermal policy ****************************************************/
-
-static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
-{
- u32 result;
- int err;
-
- asus->throttle_thermal_policy_available = false;
-
- err = asus_wmi_get_devstate(asus,
-     ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
-     &result);
- if (err) {
- if (err == -ENODEV)
- return 0;
- return err;
- }
-
- if (result & ASUS_WMI_DSTS_PRESENCE_BIT)
- asus->throttle_thermal_policy_available = true;
-
- return 0;
-}
-
 static int throttle_thermal_policy_write(struct asus_wmi *asus)
 {
- int err;
- u8 value;
+ u8 value = asus->throttle_thermal_policy_mode;
 u32 retval;
+ int err;
 
- 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_dev,
    value, &retval);
 
 sysfs_notify(&asus->platform_device->dev.kobj, NULL,
@@ -3679,7 +3660,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
 
 static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
 {
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
@@ -3691,7 +3672,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 > PLATFORM_PROFILE_MAX)
 new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3730,7 +3711,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 > PLATFORM_PROFILE_MAX)
 return -EINVAL;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3747,10 +3728,56 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
 return count;
 }
 
-// Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+/*
+ * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+ */
 static DEVICE_ATTR_RW(throttle_thermal_policy);
 
Quoted 6 lines

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3738

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +2 -0
 /* Platform profile ***********************************************************/
+static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus,
+   int mode)

Given the internals of this function I'm still not sure if this naming makes sense. Perhaps "maybe_platform_profile_to_vivo()"

you're right. this function doesn't only remap to vivo but if the laptop is a not a vivo (in our case a ROG) it doesn't change the mapping.

Quoted 6 lines

The way I see it is that there is a logical mapping (the ROG mode mapping) which is stored in the asus_wmi struct and a physical mapping that is used when writing to the acpi device (the vivo in this case). so maybe naming them asus_wmi_platform_profile_from_logical_mapping() and asus_wmi_platform_profile_to_logical_mapping() is a better naming. in the future there will be other device ids for different laptops.

If we go ahead with a function name change it should be shorter, and add a oneline comment to describe what you just did here.

Perhaps "asus_wmi_map_<to/from>_platform_profile()".

Quoted 157 lines

sorry for the late reply

Quoted 16 lines
Quoted 16 lines
drivers/platform/x86/asus-wmi.c +16 -0
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO;
+ }
+ }
+
Quoted 9 lines

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3760

Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6 -0
+ return mode;
+
+}
+
+static int asus_wmi_platform_profile_mode_from_vivo(struct asus_wmi *asus,
+   int mode)

Same as the last function.

same as the above

Quoted 129 lines
Quoted 124 lines
drivers/platform/x86/asus-wmi.c +21 -2
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT;
+ }
+ }
+
+ return mode;
+
+}
+
 static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 enum platform_profile_option *profile)
 {
@@ -3758,10 +3785,9 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 int tp;
 
 asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
-
 tp = asus->throttle_thermal_policy_mode;
 
- switch (tp) {
+ switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) {

case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
*profile = PLATFORM_PROFILE_BALANCED;
break;

drivers/platform/x86/asus-wmi.c +10 -10
@@ -3775,6 +3801,7 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 return -EINVAL;
 }
 
+
 return 0;
 }
 
@@ -3800,7 +3827,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
 return -EOPNOTSUPP;
 }
 
- asus->throttle_thermal_policy_mode = tp;
+ asus->throttle_thermal_policy_mode = asus_wmi_platform_profile_to_vivo(asus, tp);
 return throttle_thermal_policy_write(asus);
 }
 
@@ -3813,7 +3840,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 * Not an error if a component platform_profile relies on is unavailable
 * so early return, skipping the setup of platform_profile.
 */
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n");
@@ -4228,7 +4255,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
 if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) {
 if (asus->fan_boost_mode_available)
 fan_boost_mode_switch_next(asus);
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 throttle_thermal_policy_switch_next(asus);
 return;
 
@@ -4436,7 +4463,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
 else if (attr == &dev_attr_fan_boost_mode.attr)
 ok = asus->fan_boost_mode_available;
 else if (attr == &dev_attr_throttle_thermal_policy.attr)
- ok = asus->throttle_thermal_policy_available;
+ ok = asus->throttle_thermal_policy_dev != 0;
 else if (attr == &dev_attr_ppt_pl2_sppt.attr)
 devid = ASUS_WMI_DEVID_PPT_PL2_SPPT;
 else if (attr == &dev_attr_ppt_pl1_spl.attr)
@@ -4745,16 +4772,15 @@ static int asus_wmi_add(struct platform_device *pdev)
 else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2))
 asus->kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2;
 
+ if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY;
+ else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
 err = fan_boost_mode_check_present(asus);
 if (err)
 goto fail_fan_boost_mode;
 
- err = throttle_thermal_policy_check_present(asus);
- if (err)
- goto fail_throttle_thermal_policy;
- else
- throttle_thermal_policy_set_default(asus);
-
 err = platform_profile_setup(asus);
 if (err)
 goto fail_platform_profile_setup;
@@ -4849,7 +4875,6 @@ static int asus_wmi_add(struct platform_device *pdev)

fail_input:
asus_wmi_sysfs_exit(asus->platform_device);
fail_sysfs:
-fail_throttle_thermal_policy:
fail_custom_fan_curve:
fail_platform_profile_setup:
if (asus->platform_profile_support)

include/linux/platform_data/x86/asus-wmi.h +1 -0
index 3eb5cd677..982a63774 100644
@@ -64,6 +64,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_VIVO 0x00110019
 
 /* Misc */
 #define ASUS_WMI_DEVID_PANEL_OD 0x00050019
Signature · 1 line
2.44.0

If Hans and Ilpo don't have any requirements then:

#5 lore raw

Hi,

Quoted 174 lines · Luke Jones
Quoted 166 lines · Mohamed Ghanmi
Quoted 156 lines · Luke Jones
Quoted 153 lines · Mohamed Ghanmi

Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK to adjust power limits.

These fan profiles have a different device id than the ROG series and different order. This reorders the existing modes.

As part of keeping the patch clean the throttle_thermal_policy_available boolean stored in the driver struct is removed and throttle_thermal_policy_dev is used in place (as on init it is zeroed).

---
drivers/platform/x86/asus-wmi.c | 125 ++++++++++++---------
include/linux/platform_data/x86/asus-wmi.h | 1 +

2 files changed, 76 insertions(+), 50 deletions(-)
drivers/platform/x86/asus-wmi.c +20 -37
index 3c61d75a3..2e3d8d8fb 100644
@@ -97,6 +97,12 @@ module_param(fnlock_default, bool, 0444);
 #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1
 #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2
 
+#define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO 0
+#define ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO 1
+#define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO 2
+
+#define PLATFORM_PROFILE_MAX 2
+
 #define USB_INTEL_XUSB2PR 0xD0
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
 
@@ -293,8 +299,8 @@ struct asus_wmi {
 u32 kbd_rgb_dev;
 bool kbd_rgb_state_available;
 
- bool throttle_thermal_policy_available;
 u8 throttle_thermal_policy_mode;
+ u32 throttle_thermal_policy_dev;
 
 bool cpu_fan_curve_available;
 bool gpu_fan_curve_available;
@@ -3152,7 +3158,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)
 int err, fan_idx;
 u8 mode = 0;
 
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 mode = asus->throttle_thermal_policy_mode;
 /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
 if (mode == 2)
@@ -3359,7 +3365,7 @@ static ssize_t fan_curve_enable_store(struct device *dev,
 * For machines with throttle this is the only way to reset fans
 * to default mode of operation (does not erase curve data).
 */
- if (asus->throttle_thermal_policy_available) {
+ if (asus->throttle_thermal_policy_dev) {
 err = throttle_thermal_policy_write(asus);
 if (err)
 return err;
@@ -3576,8 +3582,8 @@ static const struct attribute_group asus_fan_curve_attr_group = {
 __ATTRIBUTE_GROUPS(asus_fan_curve_attr);
 
 /*
- * Must be initialised after throttle_thermal_policy_check_present() as
- * we check the status of throttle_thermal_policy_available during init.
+ * Must be initialised after throttle_thermal_policy_dev is set as
+ * we check the status of throttle_thermal_policy_dev during init.
  */
 static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 {
@@ -3618,38 +3624,13 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 }
 
 /* Throttle thermal policy ****************************************************/
-
-static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
-{
- u32 result;
- int err;
-
- asus->throttle_thermal_policy_available = false;
-
- err = asus_wmi_get_devstate(asus,
-     ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
-     &result);
- if (err) {
- if (err == -ENODEV)
- return 0;
- return err;
- }
-
- if (result & ASUS_WMI_DSTS_PRESENCE_BIT)
- asus->throttle_thermal_policy_available = true;
-
- return 0;
-}
-
 static int throttle_thermal_policy_write(struct asus_wmi *asus)
 {
- int err;
- u8 value;
+ u8 value = asus->throttle_thermal_policy_mode;
 u32 retval;
+ int err;
 
- 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_dev,
    value, &retval);
 
 sysfs_notify(&asus->platform_device->dev.kobj, NULL,
@@ -3679,7 +3660,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
 
 static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
 {
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
@@ -3691,7 +3672,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 > PLATFORM_PROFILE_MAX)
 new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3730,7 +3711,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 > PLATFORM_PROFILE_MAX)
 return -EINVAL;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3747,10 +3728,56 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
 return count;
 }
 
-// Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+/*
+ * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+ */
 static DEVICE_ATTR_RW(throttle_thermal_policy);
 
Quoted 6 lines

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3738

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +2 -0
 /* Platform profile ***********************************************************/
+static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus,
+   int mode)

Given the internals of this function I'm still not sure if this naming makes sense. Perhaps "maybe_platform_profile_to_vivo()"

you're right. this function doesn't only remap to vivo but if the laptop is a not a vivo (in our case a ROG) it doesn't change the mapping.

Quoted 6 lines

The way I see it is that there is a logical mapping (the ROG mode mapping) which is stored in the asus_wmi struct and a physical mapping that is used when writing to the acpi device (the vivo in this case). so maybe naming them asus_wmi_platform_profile_from_logical_mapping() and asus_wmi_platform_profile_to_logical_mapping() is a better naming. in the future there will be other device ids for different laptops.

Quoted 3 lines

If we go ahead with a function name change it should be shorter, and add a oneline comment to describe what you just did here.

Perhaps "asus_wmi_map_<to/from>_platform_profile()".

I would like to know the status on this patch ?
should we go ahead with a name change ?
I’d like to hear your thoughts on this

Quoted 158 lines
Quoted 158 lines

sorry for the late reply

Quoted 16 lines
Quoted 16 lines
drivers/platform/x86/asus-wmi.c +16 -0
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO;
+ }
+ }
+
Quoted 9 lines

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3760

Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6 -0
+ return mode;
+
+}
+
+static int asus_wmi_platform_profile_mode_from_vivo(struct asus_wmi *asus,
+   int mode)

Same as the last function.

same as the above

Quoted 129 lines
Quoted 124 lines
drivers/platform/x86/asus-wmi.c +21 -2
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT;
+ }
+ }
+
+ return mode;
+
+}
+
 static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 enum platform_profile_option *profile)
 {
@@ -3758,10 +3785,9 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 int tp;
 
 asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
-
 tp = asus->throttle_thermal_policy_mode;
 
- switch (tp) {
+ switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) {

case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
*profile = PLATFORM_PROFILE_BALANCED;
break;

drivers/platform/x86/asus-wmi.c +10 -10
@@ -3775,6 +3801,7 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 return -EINVAL;
 }
 
+
 return 0;
 }
 
@@ -3800,7 +3827,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
 return -EOPNOTSUPP;
 }
 
- asus->throttle_thermal_policy_mode = tp;
+ asus->throttle_thermal_policy_mode = asus_wmi_platform_profile_to_vivo(asus, tp);
 return throttle_thermal_policy_write(asus);
 }
 
@@ -3813,7 +3840,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 * Not an error if a component platform_profile relies on is unavailable
 * so early return, skipping the setup of platform_profile.
 */
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n");
@@ -4228,7 +4255,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
 if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) {
 if (asus->fan_boost_mode_available)
 fan_boost_mode_switch_next(asus);
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 throttle_thermal_policy_switch_next(asus);
 return;
 
@@ -4436,7 +4463,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
 else if (attr == &dev_attr_fan_boost_mode.attr)
 ok = asus->fan_boost_mode_available;
 else if (attr == &dev_attr_throttle_thermal_policy.attr)
- ok = asus->throttle_thermal_policy_available;
+ ok = asus->throttle_thermal_policy_dev != 0;
 else if (attr == &dev_attr_ppt_pl2_sppt.attr)
 devid = ASUS_WMI_DEVID_PPT_PL2_SPPT;
 else if (attr == &dev_attr_ppt_pl1_spl.attr)
@@ -4745,16 +4772,15 @@ static int asus_wmi_add(struct platform_device *pdev)
 else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2))
 asus->kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2;
 
+ if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY;
+ else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
 err = fan_boost_mode_check_present(asus);
 if (err)
 goto fail_fan_boost_mode;
 
- err = throttle_thermal_policy_check_present(asus);
- if (err)
- goto fail_throttle_thermal_policy;
- else
- throttle_thermal_policy_set_default(asus);
-
 err = platform_profile_setup(asus);
 if (err)
 goto fail_platform_profile_setup;
@@ -4849,7 +4875,6 @@ static int asus_wmi_add(struct platform_device *pdev)

fail_input:
asus_wmi_sysfs_exit(asus->platform_device);
fail_sysfs:
-fail_throttle_thermal_policy:
fail_custom_fan_curve:
fail_platform_profile_setup:
if (asus->platform_profile_support)

include/linux/platform_data/x86/asus-wmi.h +1 -0
index 3eb5cd677..982a63774 100644
@@ -64,6 +64,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_VIVO 0x00110019
 
 /* Misc */
 #define ASUS_WMI_DEVID_PANEL_OD 0x00050019
Signature · 1 line
2.44.0

If Hans and Ilpo don't have any requirements then:

maintainer
#6 lore raw
Quoted 178 lines

Hi,

Quoted 174 lines · Luke Jones
Quoted 172 lines · Mohamed Ghanmi
Quoted 156 lines · Luke Jones
Quoted 153 lines · Mohamed Ghanmi

Add support for vivobook fan profiles wmi call on the ASUS VIVOBOOK to adjust power limits.

These fan profiles have a different device id than the ROG series and different order. This reorders the existing modes.

As part of keeping the patch clean the throttle_thermal_policy_available boolean stored in the driver struct is removed and throttle_thermal_policy_dev is used in place (as on init it is zeroed).

---
drivers/platform/x86/asus-wmi.c | 125 ++++++++++++---------
include/linux/platform_data/x86/asus-wmi.h | 1 +

2 files changed, 76 insertions(+), 50 deletions(-)
drivers/platform/x86/asus-wmi.c +20 -37
index 3c61d75a3..2e3d8d8fb 100644
@@ -97,6 +97,12 @@ module_param(fnlock_default, bool, 0444);
 #define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST 1
 #define ASUS_THROTTLE_THERMAL_POLICY_SILENT 2
 
+#define ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO 0
+#define ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO 1
+#define ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO 2
+
+#define PLATFORM_PROFILE_MAX 2
+
 #define USB_INTEL_XUSB2PR 0xD0
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31
 
@@ -293,8 +299,8 @@ struct asus_wmi {
 u32 kbd_rgb_dev;
 bool kbd_rgb_state_available;
 
- bool throttle_thermal_policy_available;
 u8 throttle_thermal_policy_mode;
+ u32 throttle_thermal_policy_dev;
 
 bool cpu_fan_curve_available;
 bool gpu_fan_curve_available;
@@ -3152,7 +3158,7 @@ static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)
 int err, fan_idx;
 u8 mode = 0;
 
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 mode = asus->throttle_thermal_policy_mode;
 /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
 if (mode == 2)
@@ -3359,7 +3365,7 @@ static ssize_t fan_curve_enable_store(struct device *dev,
 * For machines with throttle this is the only way to reset fans
 * to default mode of operation (does not erase curve data).
 */
- if (asus->throttle_thermal_policy_available) {
+ if (asus->throttle_thermal_policy_dev) {
 err = throttle_thermal_policy_write(asus);
 if (err)
 return err;
@@ -3576,8 +3582,8 @@ static const struct attribute_group asus_fan_curve_attr_group = {
 __ATTRIBUTE_GROUPS(asus_fan_curve_attr);
 
 /*
- * Must be initialised after throttle_thermal_policy_check_present() as
- * we check the status of throttle_thermal_policy_available during init.
+ * Must be initialised after throttle_thermal_policy_dev is set as
+ * we check the status of throttle_thermal_policy_dev during init.
  */
 static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 {
@@ -3618,38 +3624,13 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus)
 }
 
 /* Throttle thermal policy ****************************************************/
-
-static int throttle_thermal_policy_check_present(struct asus_wmi *asus)
-{
- u32 result;
- int err;
-
- asus->throttle_thermal_policy_available = false;
-
- err = asus_wmi_get_devstate(asus,
-     ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
-     &result);
- if (err) {
- if (err == -ENODEV)
- return 0;
- return err;
- }
-
- if (result & ASUS_WMI_DSTS_PRESENCE_BIT)
- asus->throttle_thermal_policy_available = true;
-
- return 0;
-}
-
 static int throttle_thermal_policy_write(struct asus_wmi *asus)
 {
- int err;
- u8 value;
+ u8 value = asus->throttle_thermal_policy_mode;
 u32 retval;
+ int err;
 
- 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_dev,
    value, &retval);
 
 sysfs_notify(&asus->platform_device->dev.kobj, NULL,
@@ -3679,7 +3660,7 @@ static int throttle_thermal_policy_write(struct asus_wmi *asus)
 
 static int throttle_thermal_policy_set_default(struct asus_wmi *asus)
 {
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 asus->throttle_thermal_policy_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
@@ -3691,7 +3672,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 > PLATFORM_PROFILE_MAX)
 new_mode = ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3730,7 +3711,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 > PLATFORM_PROFILE_MAX)
 return -EINVAL;
 
 asus->throttle_thermal_policy_mode = new_mode;
@@ -3747,10 +3728,56 @@ static ssize_t throttle_thermal_policy_store(struct device *dev,
 return count;
 }
 
-// Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+/*
+ * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent
+ */
 static DEVICE_ATTR_RW(throttle_thermal_policy);
 
Quoted 6 lines

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3738

Quoted 3 lines
drivers/platform/x86/asus-wmi.c +2 -0
 /* Platform profile ***********************************************************/
+static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus,
+   int mode)

Given the internals of this function I'm still not sure if this naming makes sense. Perhaps "maybe_platform_profile_to_vivo()"

you're right. this function doesn't only remap to vivo but if the laptop is a not a vivo (in our case a ROG) it doesn't change the mapping.

The way I see it is that there is a logical mapping (the ROG mode mapping) which is stored in the asus_wmi struct and a physical mapping that is used when writing to the acpi device (the vivo in this case). so maybe naming them asus_wmi_platform_profile_from_logical_mapping() and asus_wmi_platform_profile_to_logical_mapping() is a better naming. in the future there will be other device ids for different laptops.

Quoted 164 lines
Quoted 3 lines

If we go ahead with a function name change it should be shorter, and add a oneline comment to describe what you just did here.

Perhaps "asus_wmi_map_<to/from>_platform_profile()".

I would like to know the status on this patch ?
should we go ahead with a name change ?
I’d like to hear your thoughts on this

Quoted 156 lines
Quoted 156 lines

sorry for the late reply

Quoted 16 lines
Quoted 16 lines
drivers/platform/x86/asus-wmi.c +16 -0
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO;
+ }
+ }
+
Quoted 9 lines

drivers/platform/x86/asus-wmi.c static ssize_t throttle_thermal_policy_store(struct device *dev, · line 3760

Quoted 6 lines
drivers/platform/x86/asus-wmi.c +6 -0
+ return mode;
+
+}
+
+static int asus_wmi_platform_profile_mode_from_vivo(struct asus_wmi *asus,
+   int mode)

Same as the last function.

same as the above

Quoted 128 lines
Quoted 124 lines
drivers/platform/x86/asus-wmi.c +21 -2
+{
+ bool vivo;
+
+ vivo = asus->throttle_thermal_policy_dev == ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
+ if (vivo) {
+ switch (mode) {
+ case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_DEFAULT;
+ case ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_OVERBOOST;
+ case ASUS_THROTTLE_THERMAL_POLICY_SILENT_VIVO:
+ return ASUS_THROTTLE_THERMAL_POLICY_SILENT;
+ }
+ }
+
+ return mode;
+
+}
+
 static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 enum platform_profile_option *profile)
 {
@@ -3758,10 +3785,9 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 int tp;
 
 asus = container_of(pprof, struct asus_wmi, platform_profile_handler);
-
 tp = asus->throttle_thermal_policy_mode;
 
- switch (tp) {
+ switch (asus_wmi_platform_profile_mode_from_vivo(asus, tp)) {

case ASUS_THROTTLE_THERMAL_POLICY_DEFAULT:
*profile = PLATFORM_PROFILE_BALANCED;
break;

drivers/platform/x86/asus-wmi.c +10 -10
@@ -3775,6 +3801,7 @@ static int asus_wmi_platform_profile_get(struct platform_profile_handler *pprof,
 return -EINVAL;
 }
 
+
 return 0;
 }
 
@@ -3800,7 +3827,7 @@ static int asus_wmi_platform_profile_set(struct platform_profile_handler *pprof,
 return -EOPNOTSUPP;
 }
 
- asus->throttle_thermal_policy_mode = tp;
+ asus->throttle_thermal_policy_mode = asus_wmi_platform_profile_to_vivo(asus, tp);
 return throttle_thermal_policy_write(asus);
 }
 
@@ -3813,7 +3840,7 @@ static int platform_profile_setup(struct asus_wmi *asus)
 * Not an error if a component platform_profile relies on is unavailable
 * so early return, skipping the setup of platform_profile.
 */
- if (!asus->throttle_thermal_policy_available)
+ if (!asus->throttle_thermal_policy_dev)
 return 0;
 
 dev_info(dev, "Using throttle_thermal_policy for platform_profile support\n");
@@ -4228,7 +4255,7 @@ static void asus_wmi_handle_event_code(int code, struct asus_wmi *asus)
 if (code == NOTIFY_KBD_FBM || code == NOTIFY_KBD_TTP) {
 if (asus->fan_boost_mode_available)
 fan_boost_mode_switch_next(asus);
- if (asus->throttle_thermal_policy_available)
+ if (asus->throttle_thermal_policy_dev)
 throttle_thermal_policy_switch_next(asus);
 return;
 
@@ -4436,7 +4463,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj,
 else if (attr == &dev_attr_fan_boost_mode.attr)
 ok = asus->fan_boost_mode_available;
 else if (attr == &dev_attr_throttle_thermal_policy.attr)
- ok = asus->throttle_thermal_policy_available;
+ ok = asus->throttle_thermal_policy_dev != 0;
 else if (attr == &dev_attr_ppt_pl2_sppt.attr)
 devid = ASUS_WMI_DEVID_PPT_PL2_SPPT;
 else if (attr == &dev_attr_ppt_pl1_spl.attr)
@@ -4745,16 +4772,15 @@ static int asus_wmi_add(struct platform_device *pdev)
 else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2))
 asus->kbd_rgb_dev = ASUS_WMI_DEVID_TUF_RGB_MODE2;
 
+ if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY;
+ else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO))
+ asus->throttle_thermal_policy_dev = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO;
+
 err = fan_boost_mode_check_present(asus);
 if (err)
 goto fail_fan_boost_mode;
 
- err = throttle_thermal_policy_check_present(asus);
- if (err)
- goto fail_throttle_thermal_policy;
- else
- throttle_thermal_policy_set_default(asus);
-
 err = platform_profile_setup(asus);
 if (err)
 goto fail_platform_profile_setup;
@@ -4849,7 +4875,6 @@ static int asus_wmi_add(struct platform_device *pdev)

fail_input:
asus_wmi_sysfs_exit(asus->platform_device);
fail_sysfs:
-fail_throttle_thermal_policy:
fail_custom_fan_curve:
fail_platform_profile_setup:
if (asus->platform_profile_support)

include/linux/platform_data/x86/asus-wmi.h +1 -0
index 3eb5cd677..982a63774 100644
@@ -64,6 +64,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_VIVO 0x00110019
 
 /* Misc */
 #define ASUS_WMI_DEVID_PANEL_OD 0x00050019
Signature · 1 line
2.44.0

If Hans and Ilpo don't have any requirements then:

I have no issues with this patch and it needs to be merged before I submit a stream of work. My signed-off tag is above.

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Reviewed-by
#7 lore raw

Hi,

On 7/31/24 11:06 PM, Luke Jones wrote:

...

Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

If Hans and Ilpo don't have any requirements then:

I have no issues with this patch and it needs to be merged before I submit a stream of work. My signed-off tag is above.

Reading back the comments about the function names I believe that the asus_wmi_platform_profile_mode_[to|from]_vivo() names are fine.

And the rest of the patch looks good to me to:

I have merged this into my review-hans branch now with one small change, both asus_wmi_platform_profile_mode_[to|from]_vivo() ended in:

       return mode;

}

I have dropped the empty line after the return mode; statement (in both functions) while merging this.

I've also dropped a spurious whitespace change (extra empty line) added to asus_wmi_platform_profile_get().

Luke, please base your coming work on top of pdx86/review-hans.

Regards,

Hans

p.s.

One thing which I noticed while reviewing is this:

static int fan_curve_get_factory_default(struct asus_wmi *asus, u32 fan_dev)

{
        struct fan_curve_data *curves;
        u8 buf[FAN_CURVE_BUF_LEN];
        int err, fan_idx;
        u8 mode = 0;

        if (asus->throttle_thermal_policy_dev)
                mode = asus->throttle_thermal_policy_mode;
        /* DEVID_<C/G>PU_FAN_CURVE is switched for OVERBOOST vs SILENT */
        if (mode == 2)
                mode = 1;
        else if (mode == 1)
                mode = 2;

        err = asus_wmi_evaluate_method_buf(asus->dsts_id, fan_dev, mode, buf,
                                           FAN_CURVE_BUF_LEN);

Since asus->throttle_thermal_policy_mode stores the raw mode, which has silent/overboost swapped for vivo notebooks I wonder if we should still do the mode 1/2 swapping here when on a vivo notebook ?

I have a feeling the swapping here should not be done when one a vivo notebook but I'm not sure.

If the swapping here should be skipped on Vivobooks please submit a separate follow-up patch for that.

Regards,

Hans