Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp161981lqe; Fri, 5 Apr 2024 17:02:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5hqygjJOL9KOFW3NB+bmlAcOpblIdfuwrc9My3pg7tdJXDdtu7RAo8a6sMe1ap7Qe/pFNOXeKVznNGuWaImbRnGvbLjLlPwOL51fKRg== X-Google-Smtp-Source: AGHT+IGVLJtIl0rqlmchw+6WpFmKnkoOrlFQ5IIzIZ4uyWY1Rf8hcCNJ0J4ayx8mhdZmoZSy5zi8 X-Received: by 2002:a2e:a496:0:b0:2d6:994f:1c9f with SMTP id h22-20020a2ea496000000b002d6994f1c9fmr1902691lji.53.1712361729203; Fri, 05 Apr 2024 17:02:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712361729; cv=pass; d=google.com; s=arc-20160816; b=zf9xCHM8y7D2i6JU8mPmHX/QMru8w2llumocky3GaGNa7acoYLF55wWj+6nmZJkkw5 W32jxbdrQfhKxeQXT4SuUoA2oFVVaSldBdf8+yh/CnPs8izgCS2KCXpO8BaRJvna3yoN QBZ9hyV3S+GxAclYOADyfoi+Mb5IlEAzPxFsM+KUjCjP8L3i+shh7zYROgS5REsFMT6/ OZrpBhsrWfkpDLfgfaBWoIxVzzG3d41xxfsEuKLJTlc5w0GekE2DcVV2R2xD9LwyJChz 3KacNTO7ONI+PPgwH0Kam+4MDdH7OMgK0mifcZxbDorLR/LGJkKKpe0PwyhcVeh6bhZh O+bg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Md9bALEuT8A1ve8IYXqoKqZmj7Zwlv00o+9BG5ryyJI=; fh=6ItT6a40bb2SjcEub3w2uacgTqy3t+UXXWJueNXo/1w=; b=uwN93iWyn6S+l+3n3vV+bHqRulOnpDcQu3xzCwOug2Dpffs0siz1OPVy7mDfkdHvV4 1hUj0FBXnhmpD9thkO0727EQ5VMIlILOoM4Xlqs2f7cVjfcF3stCO3/n2OxX0S0UhcCs UEuuGzLjCK6dxjN+ZW/1HCktKirlMvdSdcZeBVcw9LwYXOqcyi7KOARjABB7uDWH+mE/ ocefkFHDD+m7x32wz3gB+dI0tKrOI2a+Qmjv1q+XiqsC+wAUSJYayWVGkQw019r0821G pvmpl35JZu3vOeMoiJ8lksLhMqmLQG0oLCJtSERbRlFDrtWteDd8yJnVBggrWSNVqrCR 0e0w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=irl.hu dmarc=pass fromdomain=irl.hu); spf=pass (google.com: domain of linux-kernel+bounces-133724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=irl.hu Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n21-20020a05640205d500b0056c53a533easi1170703edx.17.2024.04.05.17.02.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 17:02:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=irl.hu dmarc=pass fromdomain=irl.hu); spf=pass (google.com: domain of linux-kernel+bounces-133724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=irl.hu Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A7DF31F23666 for ; Sat, 6 Apr 2024 00:02:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF7963611F; Sat, 6 Apr 2024 00:01:51 +0000 (UTC) Received: from irl.hu (irl.hu [95.85.9.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8A47374EB; Sat, 6 Apr 2024 00:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.85.9.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361711; cv=none; b=kANSs4+q4maCFbfkz0hyhcPNOPVhPjHWmCP/usHIE2p5g4+8baNn3T2UwtMAAZjw82U5WO1V3TlFtXhaREDlgXiy/z5q9YGIkNC61POF11rQf3qBs5dU1Um4u0Mzb4Bfrj9KXMDS0b+caRRlKd/pSDrspUG6a+hldISZP8HK1gM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712361711; c=relaxed/simple; bh=jDfFOIqdI4WU8ZptpCWpiWScAHZGn68u/HHOO16s4Rk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Mime-Version:Content-Type; b=YX3NVUgTFipjg4dPxOZOu4WUANBDvCi0aRktz7ZpxExPRA1X9MwVpIXctlOyZoXJ0R+PwpReIKKmpEsmRP/bnsYgsi26J8vzR7CuF9tVjZOMPrELhmTM59tiNKZCFiXpwyfcKEb6njrrcNtpubHDzvnyKt6QyDE++ZGWY9kqPgQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=irl.hu; spf=pass smtp.mailfrom=irl.hu; arc=none smtp.client-ip=95.85.9.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=irl.hu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=irl.hu Received: from fedori.lan (51b69f53.dsl.pool.telekom.hu [::ffff:81.182.159.83]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 000000000006F99A.00000000661090EB.0025D55B; Sat, 06 Apr 2024 02:01:47 +0200 From: Gergo Koteles To: "Rafael J. Wysocki" , Len Brown , Ike Panhc , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Henrique de Moraes Holschuh , Daniel Lezcano , =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Cc: linux-acpi@vger.kernel.org, ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Gergo Koteles Subject: [PATCH v5 1/3] ACPI: platform-profile: add platform_profile_cycle() Date: Sat, 6 Apr 2024 02:01:31 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Mime-Autoconverted: from 8bit to 7bit by courier 1.0 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 --- 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))) { + 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_*/ -- 2.44.0