All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gergo Koteles <soyer@irl.hu>
To: "Ike Panhc" <ike.pan@canonical.com>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, Gergo Koteles <soyer@irl.hu>
Subject: [PATCH v2] platform/x86: ideapad-laptop: switch platform profiles using thermal management key
Date: Wed,  3 Apr 2024 22:23:15 +0200	[thread overview]
Message-ID: <797884d8cab030d3a2b656dba67f3c423cc58be7.1712174794.git.soyer@irl.hu> (raw)

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.

Signed-off-by: Gergo Koteles <soyer@irl.hu>
---
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(-)

diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index 901849810ce2..dba43c2d244b 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -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
-- 
2.44.0


                 reply	other threads:[~2024-04-03 20:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=797884d8cab030d3a2b656dba67f3c423cc58be7.1712174794.git.soyer@irl.hu \
    --to=soyer@irl.hu \
    --cc=hdegoede@redhat.com \
    --cc=ike.pan@canonical.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

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

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