From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: "Gergo Koteles" <soyer@irl.hu>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Len Brown" <lenb@kernel.org>,
"Ike Panhc" <ike.pan@canonical.com>,
"Hans de Goede" <hdegoede@redhat.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Henrique de Moraes Holschuh" <hmh@hmh.eng.br>
Cc: linux-acpi@vger.kernel.org, ibm-acpi-devel@lists.sourceforge.net,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/3] ACPI: platform-profile: add platform_profile_cycle()
Date: Fri, 5 Apr 2024 08:48:38 +0200 [thread overview]
Message-ID: <87d38d4c-14e2-4c64-baba-c9b8bd694339@linaro.org> (raw)
In-Reply-To: <fdc1b0b9f910753967b7a9b1996e4923cc63124f.1712282976.git.soyer@irl.hu>
Hi Gergo,
please Cc people who commented your changes.
see below:
On 05/04/2024 05:05, 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>
> ---
> drivers/acpi/platform_profile.c | 42 ++++++++++++++++++++++++++++++++
> include/linux/platform_profile.h | 1 +
> 2 files changed, 43 insertions(+)
>
> diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
> index d418462ab791..1579f380d469 100644
> --- a/drivers/acpi/platform_profile.c
> +++ b/drivers/acpi/platform_profile.c
> @@ -136,6 +136,48 @@ 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 = ffs(cur_profile->choices[0] >> (profile + 1)) + profile;
> +
> + /* current profile is the highest, select the lowest */
> + if (next == profile)
> + next = ffs(cur_profile->choices[0]) - 1;
> +
> + if (WARN_ON((next < 0) || (next >= ARRAY_SIZE(profile_names)))) {
> + mutex_unlock(&profile_lock);
> + return -EINVAL;
> + }
Why do you need to do this?
That can be simplified by:
[ ... ]
err = cur_profile->profile_get(cur_profile, &profile);
if (err)
goto out;
profile = (profile + 1) % ARRAY_SIZE(profile_names);
err = cur_profile->profile_set(cur_profile, next);
out:
mutex_unlock(&profile_lock);
[ ... ]
> + 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_*/
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
next prev parent reply other threads:[~2024-04-05 6:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-05 3:05 [PATCH v4 0/3] switch platform profiles with Lenovo laptops Gergo Koteles
2024-04-05 3:05 ` [PATCH v4 1/3] ACPI: platform-profile: add platform_profile_cycle() Gergo Koteles
2024-04-05 6:48 ` Daniel Lezcano [this message]
2024-04-05 14:48 ` Gergo Koteles
2024-04-05 16:34 ` Barnabás Pőcze
2024-04-06 0:00 ` Gergo Koteles
2024-04-05 3:05 ` [PATCH v4 2/3] platform/x86: ideapad-laptop: switch platform profiles using thermal management key Gergo Koteles
2024-04-05 3:05 ` [PATCH v4 3/3] platform/x86: thinkpad_acpi: use platform_profile_cycle() Gergo Koteles
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=87d38d4c-14e2-4c64-baba-c9b8bd694339@linaro.org \
--to=daniel.lezcano@linaro.org \
--cc=hdegoede@redhat.com \
--cc=hmh@hmh.eng.br \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=ike.pan@canonical.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=soyer@irl.hu \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®