mbox series

[v5,0/3] switch platform profiles with Lenovo laptops

Message ID cover.1712360639.git.soyer@irl.hu
Headers show
Series switch platform profiles with Lenovo laptops | expand

Message

Gergo Koteles April 6, 2024, 12:01 a.m. UTC
Hi All,

This patch series adds a platform_profile_cycle function to the platform 
profile module, which allows modules to easily switch between the 
enabled profiles.

Use it in ideapad-laptop and thinkpad-acpi modules.

Best regards,
Gergo

Changes in v5:
 - use find_next_bit_wrap function to find the next enabled profile 
 instead of multiple ffs calls

Changes in v4:
 - move the cycle to the platform profile module where it can switch 
 between the enabled profiles
 - add a patch to use it in the thinkpad-acpi module

Changes in v3:
 - add dytc_profile_cycle function

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

[4]: https://lore.kernel.org/all/cover.1712282976.git.soyer@irl.hu/
[3]: https://lore.kernel.org/all/7c358ad8dd6de7889fa887954145a181501ac362.1712236099.git.soyer@irl.hu/
[2]: https://lore.kernel.org/all/797884d8cab030d3a2b656dba67f3c423cc58be7.1712174794.git.soyer@irl.hu/
[1]: https://lore.kernel.org/all/85254ce8e87570c05e7f04d6507701bef954ed75.1712149429.git.soyer@irl.hu/


Gergo Koteles (3):
  ACPI: platform-profile: add platform_profile_cycle()
  platform/x86: ideapad-laptop: switch platform profiles using thermal
    management key
  platform/x86: thinkpad_acpi: use platform_profile_cycle()

 drivers/acpi/platform_profile.c       | 39 +++++++++++++++++++++++++++
 drivers/platform/x86/ideapad-laptop.c |  7 +++--
 drivers/platform/x86/thinkpad_acpi.c  | 19 ++-----------
 include/linux/platform_profile.h      |  1 +
 4 files changed, 47 insertions(+), 19 deletions(-)


base-commit: 39cd87c4eb2b893354f3b850f916353f2658ae6f

Comments

Hans de Goede April 8, 2024, 4:41 p.m. UTC | #1
Hi Gergo,

On 4/6/24 2:01 AM, Gergo Koteles wrote:
> Some laptops have a key to switch platform profiles.
> 
> Add a platform_profile_cycle() function to cycle between the enabled
> profiles.
> 
> Signed-off-by: Gergo Koteles <soyer@irl.hu>

Thank you for your patch, 1 small remark below,
otherwise this looks good to me.

Rafael, may I have your Ack for merging this through the pdx86 tree
together with the rest of the series once my remark has been addressed ?


> ---
>  drivers/acpi/platform_profile.c  | 39 ++++++++++++++++++++++++++++++++
>  include/linux/platform_profile.h |  1 +
>  2 files changed, 40 insertions(+)
> 
> diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
> index d418462ab791..acc606af812a 100644
> --- a/drivers/acpi/platform_profile.c
> +++ b/drivers/acpi/platform_profile.c
> @@ -136,6 +136,45 @@ void platform_profile_notify(void)
>  }
>  EXPORT_SYMBOL_GPL(platform_profile_notify);
>  
> +int platform_profile_cycle(void)
> +{
> +	enum platform_profile_option profile;
> +	enum platform_profile_option next;
> +	int err;
> +
> +	err = mutex_lock_interruptible(&profile_lock);
> +	if (err)
> +		return err;
> +
> +	if (!cur_profile) {
> +		mutex_unlock(&profile_lock);
> +		return -ENODEV;
> +	}
> +
> +	err = cur_profile->profile_get(cur_profile, &profile);
> +	if (err) {
> +		mutex_unlock(&profile_lock);
> +		return err;
> +	}
> +
> +	next = find_next_bit_wrap(cur_profile->choices,
> +				  ARRAY_SIZE(profile_names), profile + 1);
> +
> +	if (WARN_ON(next == ARRAY_SIZE(profile_names))) {

Other code in drivers/acpi/platform_profile.c uses PLATFORM_PROFILE_LAST
instead of ARRAY_SIZE(profile_names) (these are guaranteed to be equal)
please switch to using PLATFORM_PROFILE_LAST for consistency.

Regards,

Hans





> +		mutex_unlock(&profile_lock);
> +		return -EINVAL;
> +	}
> +
> +	err = cur_profile->profile_set(cur_profile, next);
> +	mutex_unlock(&profile_lock);
> +
> +	if (!err)
> +		sysfs_notify(acpi_kobj, NULL, "platform_profile");
> +
> +	return err;
> +}
> +EXPORT_SYMBOL_GPL(platform_profile_cycle);
> +
>  int platform_profile_register(struct platform_profile_handler *pprof)
>  {
>  	int err;
> diff --git a/include/linux/platform_profile.h b/include/linux/platform_profile.h
> index e5cbb6841f3a..f5492ed413f3 100644
> --- a/include/linux/platform_profile.h
> +++ b/include/linux/platform_profile.h
> @@ -36,6 +36,7 @@ struct platform_profile_handler {
>  
>  int platform_profile_register(struct platform_profile_handler *pprof);
>  int platform_profile_remove(void);
> +int platform_profile_cycle(void);
>  void platform_profile_notify(void);
>  
>  #endif  /*_PLATFORM_PROFILE_H_*/
Rafael J. Wysocki April 8, 2024, 5:04 p.m. UTC | #2
On Mon, Apr 8, 2024 at 6:41 PM Hans de Goede <hdegoede@redhat.com> wrote:
>
> Hi Gergo,
>
> On 4/6/24 2:01 AM, Gergo Koteles wrote:
> > Some laptops have a key to switch platform profiles.
> >
> > Add a platform_profile_cycle() function to cycle between the enabled
> > profiles.
> >
> > Signed-off-by: Gergo Koteles <soyer@irl.hu>
>
> Thank you for your patch, 1 small remark below,
> otherwise this looks good to me.
>
> Rafael, may I have your Ack for merging this through the pdx86 tree
> together with the rest of the series once my remark has been addressed ?

Sure, please feel free to add

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

to this patch.  Thanks!

> > ---
> >  drivers/acpi/platform_profile.c  | 39 ++++++++++++++++++++++++++++++++
> >  include/linux/platform_profile.h |  1 +
> >  2 files changed, 40 insertions(+)
> >
> > diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
> > index d418462ab791..acc606af812a 100644
> > --- a/drivers/acpi/platform_profile.c
> > +++ b/drivers/acpi/platform_profile.c
> > @@ -136,6 +136,45 @@ void platform_profile_notify(void)
> >  }
> >  EXPORT_SYMBOL_GPL(platform_profile_notify);
> >
> > +int platform_profile_cycle(void)
> > +{
> > +     enum platform_profile_option profile;
> > +     enum platform_profile_option next;
> > +     int err;
> > +
> > +     err = mutex_lock_interruptible(&profile_lock);
> > +     if (err)
> > +             return err;
> > +
> > +     if (!cur_profile) {
> > +             mutex_unlock(&profile_lock);
> > +             return -ENODEV;
> > +     }
> > +
> > +     err = cur_profile->profile_get(cur_profile, &profile);
> > +     if (err) {
> > +             mutex_unlock(&profile_lock);
> > +             return err;
> > +     }
> > +
> > +     next = find_next_bit_wrap(cur_profile->choices,
> > +                               ARRAY_SIZE(profile_names), profile + 1);
> > +
> > +     if (WARN_ON(next == ARRAY_SIZE(profile_names))) {
>
> Other code in drivers/acpi/platform_profile.c uses PLATFORM_PROFILE_LAST
> instead of ARRAY_SIZE(profile_names) (these are guaranteed to be equal)
> please switch to using PLATFORM_PROFILE_LAST for consistency.
>
> Regards,
>
> Hans
>
>
>
>
>
> > +             mutex_unlock(&profile_lock);
> > +             return -EINVAL;
> > +     }
> > +
> > +     err = cur_profile->profile_set(cur_profile, next);
> > +     mutex_unlock(&profile_lock);
> > +
> > +     if (!err)
> > +             sysfs_notify(acpi_kobj, NULL, "platform_profile");
> > +
> > +     return err;
> > +}
> > +EXPORT_SYMBOL_GPL(platform_profile_cycle);
> > +
> >  int platform_profile_register(struct platform_profile_handler *pprof)
> >  {
> >       int err;
> > diff --git a/include/linux/platform_profile.h b/include/linux/platform_profile.h
> > index e5cbb6841f3a..f5492ed413f3 100644
> > --- a/include/linux/platform_profile.h
> > +++ b/include/linux/platform_profile.h
> > @@ -36,6 +36,7 @@ struct platform_profile_handler {
> >
> >  int platform_profile_register(struct platform_profile_handler *pprof);
> >  int platform_profile_remove(void);
> > +int platform_profile_cycle(void);
> >  void platform_profile_notify(void);
> >
> >  #endif  /*_PLATFORM_PROFILE_H_*/
>
Gergo Koteles April 8, 2024, 8:13 p.m. UTC | #3
Hi Hans,

On Mon, 2024-04-08 at 18:41 +0200, Hans de Goede wrote:
> > +	next = find_next_bit_wrap(cur_profile->choices,
> > +				  ARRAY_SIZE(profile_names), profile + 1);
> > +
> > +	if (WARN_ON(next == ARRAY_SIZE(profile_names))) {
> 
> Other code in drivers/acpi/platform_profile.c uses PLATFORM_PROFILE_LAST
> instead of ARRAY_SIZE(profile_names) (these are guaranteed to be equal)
> please switch to using PLATFORM_PROFILE_LAST for consistency.
> 

Thanks for the review. I changed these in v6.


Best regards,
Gergo