ACPI: platform-profile: add platform_profile_cycle()
authorGergo Koteles <soyer@irl.hu>
Mon, 8 Apr 2024 17:35:10 +0000 (19:35 +0200)
committerHans de Goede <hdegoede@redhat.com>
Mon, 15 Apr 2024 13:46:56 +0000 (15:46 +0200)
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>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/5a97deddf72aa5e764d881eb39a7ba35c01a903e.1712597199.git.soyer@irl.hu
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/acpi/platform_profile.c
include/linux/platform_profile.h

index d418462ab7919210f95e6092ff860a3dd8263371..4a9704730224ad3623795fd337817cb89bf23c91 100644 (file)
@@ -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, PLATFORM_PROFILE_LAST,
+                                 profile + 1);
+
+       if (WARN_ON(next == PLATFORM_PROFILE_LAST)) {
+               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;
index e5cbb6841f3ac949a7750f47e746121545461cc0..f5492ed413f363ee80272f2d44a68a1ad7158f51 100644 (file)
@@ -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_*/