Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp445319lqp; Thu, 4 Apr 2024 20:06:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTQT819Al9uCIfP2PNARldv1bSQlCDS0TU+H5V72p/+r8BHXHhP7ehRVpHIUg1/r7S3P6rkewdS08D+D5AiwWBaCwMu5fn7iJm+4oXRw== X-Google-Smtp-Source: AGHT+IFCdnIHCUM9zs0JfqsuydFfA8p5zHzwT1wcvLKGI0GLZi4q6kumrZzUBpyyYhT7Fj5fr8CY X-Received: by 2002:a05:6512:484a:b0:516:d26e:ea6f with SMTP id ep10-20020a056512484a00b00516d26eea6fmr123453lfb.35.1712286373454; Thu, 04 Apr 2024 20:06:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712286373; cv=pass; d=google.com; s=arc-20160816; b=Fau6z8RXH526a7OferPFgGqyaQ74fr7bQ8A2yF5ujt/V/4f15KN4U+6hca/8nxJxXz CR8p1bYfer5JGjy2mb99amCpvbJbc82omT/bOSWkXIvJG5XrWgWAF4HiIEd/HCBGndju gYSiQfi0DP5rLxL9hgD6/qYcbXpmdrMvUOQ/RP4rTh2R+UYcdhXz8tjNE4qaffGeU2go +BglfQ8UMLssjUSDuzx+Fj2D0vWmuk/hqunzmTC54L0PcPeR7017Ch8+IGl8tfHFFgT6 r1jNaVRRhH5fTaix7F4/eWQpC2VwB9x093o1USq3bILOzAFbeZdvuIbIhalmLCnyZC+a ww/w== 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=XiLe0UPssdK8j0EMrywuRFQ241FwQi+I+HX4Ag/0ISA=; fh=ZUON8yv4I04w5UsoejLcnuG5t0kXYyjDKRvUhxX89zQ=; b=V8M3Yg4pwDDrUDJkzUyjmvZ0tO7QWFcVKMwEtICTLtD/frQiEcD4OxVxy+w9tONYps TPUwn1ujFDx9f5LlhQJlfkP4k+vPESWhu8Xvx0NC9jaQWdy/VVPldPnO0s3Volfj8OxO 7C7cvi+nxON8kmbdmrNlkHql18nKaoJV4OIDXp8iwLib9FfmDlszLFQXJUZSK3ztqgk9 T39WKz6j3ZuX7rJesCZqd+uwqaKQhkWTtJxGcoHXkULdyqaqWj8QoAD1JRxS4u8zPdGn ++YnBQZbOmAL3dgoq/rCjXdMiY59sR1N9wcUt8RHzDcZB/+KFCrUzY1eiZCoB3FNW2CT OWig==; 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-132359-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132359-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gf4-20020a170906e20400b00a4e7fe79504si255364ejb.67.2024.04.04.20.06.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 20:06:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132359-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-132359-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132359-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 30CA11F22A88 for ; Fri, 5 Apr 2024 03:06:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D0CC1C687; Fri, 5 Apr 2024 03:05:59 +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 EF3E0134A9; Fri, 5 Apr 2024 03:05:56 +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=1712286358; cv=none; b=QRyu1wokWx2Qsf5NznfWpldo53G5zrDKKqaqsbeolS0k0eXYpvmjyMAQ3ZZQTgldkYhZwfpmt2jyzM9wOFYuta1j/LkAtfUGxy9WhIj4v2dC9CWxpSnmMMihxX9Pj9VWFwyk1FaA2t3ERuS8CsxpN7kP3r5XDPTK+4cPI3SKmKw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712286358; c=relaxed/simple; bh=C2VgREdi+4ETlKAR2VZI0tLQIj3vvb+U8c5FeOVWXV4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Mime-Version:Content-Type; b=h3hlfosxyY/dzPbTbKO++kNL3bsF3pzJlvparz7w9M0lBiZYJBttu9MXbhg1jk6caf62HRuHmOwK349X6nRpZzwZi9oDA8EGSpbPEq12yD3DKDnimOSSVtbinFDhulP70kE1LH7L6ZV7flKzfXgyrnODVvCciI1l2cCKST+nf0o= 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 (51b69867.dsl.pool.telekom.hu [::ffff:81.182.152.103]) (AUTH: CRAM-MD5 soyer@irl.hu, ) by irl.hu with ESMTPSA id 000000000006F223.00000000660F6A92.0025A894; Fri, 05 Apr 2024 05:05:54 +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 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 v4 1/3] ACPI: platform-profile: add platform_profile_cycle() Date: Fri, 5 Apr 2024 05:05:28 +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 | 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; + } + + 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