Skip to contentSkip to conversation

platform/x86: ideapad-laptop: switch platform profiles using thermal management key

PATCH Superseded Gergo Koteles 1 participant 1 message Apr 3, 2024 x86 platform drivers

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 platform/x86: ideapad-laptop: switch platform profiles using thermal management key

Ideapad laptops have thermal management or performance mode switch key (Fn + Q). Now it sends KEY_PROG4.

If supported, switch platform profiles instead.

Tested on Yoga7 14ARB7.

---
Changes in v2:
- only switch platform profiles if supported, otherwise keep the behavior.

[1]: https://lore.kernel.org/all/85254ce8e87570c05e7f04d6507701bef954ed75.1712149429.git.soyer@irl.hu/

---
 drivers/platform/x86/ideapad-laptop.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/platform/x86/ideapad-laptop.c +25 -2
index 901849810ce2..dba43c2d244b 100644
@@ -1181,8 +1181,31 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv)
 		switch (bit) {
 		case 6:	/* Z570 */
 		case 0:	/* Z580 */
-			/* Thermal Management button */
-			ideapad_input_report(priv, 65);
+			/* Thermal Management / Performance Mode button */
+			if (!priv->dytc) {
+				ideapad_input_report(priv, 65);
+				break;
+			}
+			switch (priv->dytc->current_profile) {
+			case PLATFORM_PROFILE_LOW_POWER:
+				dytc_profile_set(&priv->dytc->pprof,
+						 PLATFORM_PROFILE_BALANCED);
+				break;
+			case PLATFORM_PROFILE_BALANCED:
+				dytc_profile_set(&priv->dytc->pprof,
+						 PLATFORM_PROFILE_PERFORMANCE);
+				break;
+			case PLATFORM_PROFILE_PERFORMANCE:
+				dytc_profile_set(&priv->dytc->pprof,
+						 PLATFORM_PROFILE_LOW_POWER);
+				break;
+			default:
+				dev_warn(&priv->platform_device->dev,
+					 "Unexpected platform profile %d",
+					 priv->dytc->current_profile);
+			}
+			/* Notify user space the profile changed */
+			platform_profile_notify();
 			break;
 		case 1:
 			/* OneKey Theater button */

base-commit: 39cd87c4eb2b893354f3b850f916353f2658ae6f

Signature · 1 line
2.44.0