diff mbox series

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

Message ID 7c358ad8dd6de7889fa887954145a181501ac362.1712236099.git.soyer@irl.hu (mailing list archive)
State Superseded, archived
Headers show
Series [v3] platform/x86: ideapad-laptop: switch platform profiles using thermal management key | expand

Commit Message

Gergo Koteles April 4, 2024, 1:10 p.m. UTC
Ideapad laptops have thermal management or performance mode switch key
(Fn + Q). They report KEY_PROG4.

If supported, cycle platform profiles instead.

Tested on Yoga7 14ARB7.

Signed-off-by: Gergo Koteles <soyer@irl.hu>
---
Changes in v3:
 - add dytc_profile_cycle function
Changes in v2:
 - only switch platform profiles if supported, otherwise keep the 
   behavior.

[2]: https://lore.kernel.org/all/797884d8cab030d3a2b656dba67f3c423cc58be7.1712174794.git.soyer@irl.hu/
[1]: https://lore.kernel.org/all/85254ce8e87570c05e7f04d6507701bef954ed75.1712149429.git.soyer@irl.hu/
---
 drivers/platform/x86/ideapad-laptop.c | 31 +++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)


base-commit: 39cd87c4eb2b893354f3b850f916353f2658ae6f

Comments

Daniel Lezcano April 4, 2024, 1:27 p.m. UTC | #1
On 04/04/2024 15:10, Gergo Koteles wrote:
> Ideapad laptops have thermal management or performance mode switch key
> (Fn + Q). They report KEY_PROG4.
> 
> If supported, cycle platform profiles instead.
> 
> Tested on Yoga7 14ARB7.
> 
> Signed-off-by: Gergo Koteles <soyer@irl.hu>
> ---
> Changes in v3:
>   - add dytc_profile_cycle function
> Changes in v2:
>   - only switch platform profiles if supported, otherwise keep the
>     behavior.
> 
> [2]: https://lore.kernel.org/all/797884d8cab030d3a2b656dba67f3c423cc58be7.1712174794.git.soyer@irl.hu/
> [1]: https://lore.kernel.org/all/85254ce8e87570c05e7f04d6507701bef954ed75.1712149429.git.soyer@irl.hu/
> ---
>   drivers/platform/x86/ideapad-laptop.c | 31 +++++++++++++++++++++++++--
>   1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
> index 901849810ce2..c7ea3ed14aba 100644
> --- a/drivers/platform/x86/ideapad-laptop.c
> +++ b/drivers/platform/x86/ideapad-laptop.c
> @@ -858,6 +858,30 @@ static void dytc_profile_refresh(struct ideapad_private *priv)
>   	}
>   }
>   
> +static void dytc_profile_cycle(struct ideapad_private *priv)
> +{
> +	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();
> +}

Cycling is done through modulo.

Quick and dirty example:

static int profiles[] = {
	PLATFORM_PROFILE_LOW_POWER,
	PLATFORM_PROFILE_BALANCED,
	PLATFORM_PROFILE_PERFORMANCE
};

static int current_profile_index = 0;

static void dytc_profile_cycle(struct ideapad_private *priv)
{
	current_profile_index++

	current_profile_index =
		current_profile_index % ARRAY_SIZE(profiles);

	dytc_profile_set(&priv->dytc->pprof,
			profiles[current_profile_index]);

	platform_profile_notify();
}


>   static const struct dmi_system_id ideapad_dytc_v4_allow_table[] = {
>   	{
>   		/* Ideapad 5 Pro 16ACH6 */
> @@ -1181,8 +1205,11 @@ 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)
> +				dytc_profile_cycle(priv);
> +			else
> +				ideapad_input_report(priv, 65);
>   			break;
>   		case 1:
>   			/* OneKey Theater button */
> 
> base-commit: 39cd87c4eb2b893354f3b850f916353f2658ae6f
Gergo Koteles April 4, 2024, 3:05 p.m. UTC | #2
Hi Daniel,

On Thu, 2024-04-04 at 15:27 +0200, Daniel Lezcano wrote:
> > Cycling is done through modulo.
> > 
> > Quick and dirty example:
> > 
> > static int profiles[] = {
> > 	PLATFORM_PROFILE_LOW_POWER,
> > 	PLATFORM_PROFILE_BALANCED,
> > 	PLATFORM_PROFILE_PERFORMANCE
> > };
> > 
> > static int current_profile_index = 0;
> > 
> > static void dytc_profile_cycle(struct ideapad_private *priv)
> > {
> > 	current_profile_index++
> > 
> > 	current_profile_index =
> > 		current_profile_index % ARRAY_SIZE(profiles);
> > 
> > 	dytc_profile_set(&priv->dytc->pprof,
> > 			profiles[current_profile_index]);
> > 
> > 	platform_profile_notify();
> > }
> > 

Thanks for your suggestions. I thought about it.
It would make this module complicated, but something like this fits
well in the platform_profile module.
I will implement the cycle there in v4.

Best regards,
Gergo
diff mbox series

Patch

diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index 901849810ce2..c7ea3ed14aba 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -858,6 +858,30 @@  static void dytc_profile_refresh(struct ideapad_private *priv)
 	}
 }
 
+static void dytc_profile_cycle(struct ideapad_private *priv)
+{
+	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();
+}
+
 static const struct dmi_system_id ideapad_dytc_v4_allow_table[] = {
 	{
 		/* Ideapad 5 Pro 16ACH6 */
@@ -1181,8 +1205,11 @@  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)
+				dytc_profile_cycle(priv);
+			else
+				ideapad_input_report(priv, 65);
 			break;
 		case 1:
 			/* OneKey Theater button */