Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPI: platform-profile: add platform_profile_cycle()

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>

authored by

Gergo Koteles and committed by
Hans de Goede
ba95eb44 c1ca2311

+40
+39
drivers/acpi/platform_profile.c
··· 136 136 } 137 137 EXPORT_SYMBOL_GPL(platform_profile_notify); 138 138 139 + int platform_profile_cycle(void) 140 + { 141 + enum platform_profile_option profile; 142 + enum platform_profile_option next; 143 + int err; 144 + 145 + err = mutex_lock_interruptible(&profile_lock); 146 + if (err) 147 + return err; 148 + 149 + if (!cur_profile) { 150 + mutex_unlock(&profile_lock); 151 + return -ENODEV; 152 + } 153 + 154 + err = cur_profile->profile_get(cur_profile, &profile); 155 + if (err) { 156 + mutex_unlock(&profile_lock); 157 + return err; 158 + } 159 + 160 + next = find_next_bit_wrap(cur_profile->choices, PLATFORM_PROFILE_LAST, 161 + profile + 1); 162 + 163 + if (WARN_ON(next == PLATFORM_PROFILE_LAST)) { 164 + mutex_unlock(&profile_lock); 165 + return -EINVAL; 166 + } 167 + 168 + err = cur_profile->profile_set(cur_profile, next); 169 + mutex_unlock(&profile_lock); 170 + 171 + if (!err) 172 + sysfs_notify(acpi_kobj, NULL, "platform_profile"); 173 + 174 + return err; 175 + } 176 + EXPORT_SYMBOL_GPL(platform_profile_cycle); 177 + 139 178 int platform_profile_register(struct platform_profile_handler *pprof) 140 179 { 141 180 int err;
+1
include/linux/platform_profile.h
··· 36 36 37 37 int platform_profile_register(struct platform_profile_handler *pprof); 38 38 int platform_profile_remove(void); 39 + int platform_profile_cycle(void); 39 40 void platform_profile_notify(void); 40 41 41 42 #endif /*_PLATFORM_PROFILE_H_*/