Received: by 2002:ab2:5182:0:b0:1f4:61d5:3ad4 with SMTP id x2csp56251lqi; Fri, 5 Apr 2024 09:35:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUyTA4t0Vju3Dx3l99lqbogpyF7/+RdXA8jB2mMkf4cZpEl2ks6ifgjbo870tjkYPC9fATcNqDq7Ogwgn1whu4/SFOf4ufUf26eCNfRsQ== X-Google-Smtp-Source: AGHT+IHvZrN19G+nmpQfdtUIDxZlfglB28CnhXNFqRMjGjMfeqLQcwIQTZTRQRGqW54O/JbRriVz X-Received: by 2002:a17:903:44a:b0:1e2:7717:d34e with SMTP id iw10-20020a170903044a00b001e27717d34emr1964420plb.58.1712334924053; Fri, 05 Apr 2024 09:35:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712334924; cv=pass; d=google.com; s=arc-20160816; b=US7H86AumAdpfreUKvStugLWcaKtC7oUIIMcDszgIyf2L8x42AfMJo4st+RkDgQhQt Y2orG2A9CAgVKLeXhgkx7x+ERLfd2xn0ttgaM7/3MNKgG0xFWZXE72jY4O3+PchI6JXD 1i16SbdIbMN+/sTEPu1rSCvN+gisyb8DFa3dTJTrWJ76rbCzIje6UO4zWb2uCNU0uRKt RZXLSJYk/l+ahrAW+pZIMSeApd6Qv7S5TOYlvkd9nfCJ9ZQ+pyYdJfouI584Aw/quQjF ID/u9URNxXNCe7rtoX6jHftjvmMGieDAws9Cjoa1bHrE5kB21mdCQTIjT/ZgoxYTay2/ ygxw== 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:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=S3WQALqPQkgNA4pAsO5tIwgQszOpcZJAo1yOP3F/ne0=; fh=8dy78hOb4A2RuIO4xrbc489qcEHM5w/PVPuE3B0TMlM=; b=Ha14KpEW8S9eOzvWkrcjmJmeMsfy+hTFT7y3OQcM7ESAb9CHKN69KxxEBVYVLgyT/H FjH5bGwuNc5eBhk0fz84IrMyXurgHiDSVoTkkiS1W/JLtxByMbIIXnszVgo2wSSnwcJd 4eK/gGtIRhXiTa6rBjVMspqjev+yPbGZfdqic9Q/uLgs0wYOn0yJbTkO0ifHt6RP/rv+ OsInXnld1h3RyUSXG1e/ptSMqs5gmZ4ER5CYvp56RFRCRgfyomNEJP123kh4uLM37K3b MBSGVMRXzex1mGhLfcbbsOMzhn8pLat1C9t0YJzKuzkJm/NMe6VOGXYEw1eNw5qU5iOu EZ+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=AIbz7XCx; arc=pass (i=1 spf=pass spfdomain=protonmail.com dkim=pass dkdomain=protonmail.com dmarc=pass fromdomain=protonmail.com); spf=pass (google.com: domain of linux-kernel+bounces-133344-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133344-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id mf15-20020a170902fc8f00b001e23fce8e3dsi1634885plb.125.2024.04.05.09.35.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 09:35:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133344-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=AIbz7XCx; arc=pass (i=1 spf=pass spfdomain=protonmail.com dkim=pass dkdomain=protonmail.com dmarc=pass fromdomain=protonmail.com); spf=pass (google.com: domain of linux-kernel+bounces-133344-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133344-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2539B287597 for ; Fri, 5 Apr 2024 16:35:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF80D171094; Fri, 5 Apr 2024 16:35:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="AIbz7XCx" Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) (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 BADBB2869B for ; Fri, 5 Apr 2024 16:35:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712334912; cv=none; b=NftED30EUk6KlZbBVqq80LybtAVTdMGJaHhe2uKpv1nxJqrwTlgbHJlcEEpaEAyrPKht8SemfyJxCB+5Y9BQnGEevk476brJb43+/x1KDW3ye8AvxQRepE0SNQsBnHa16GroDwzK34F0gvjIf1mt7IzdCWPNAtpnCBlnhev9/oY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712334912; c=relaxed/simple; bh=O+UnvDut8VP1erLUptBy2LRJVciHe8+vp0N0w/zfIa4=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=p5ee74fwqFJ72PybWKR/849h1p/l4rheSeFtfBfExXT4zGBzLSpAbJAhhzpvSJ8k1c9O9rGOw2WUG5HAGxWI57WWxJ0zXSFaNe5+Ju02MIIRUc6C8FRIFZHxCV7lyVXf7FatSYgJuwoUktwkyGmIvlpefeeDT0+/AQ2nx/F964Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=AIbz7XCx; arc=none smtp.client-ip=185.70.40.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1712334901; x=1712594101; bh=S3WQALqPQkgNA4pAsO5tIwgQszOpcZJAo1yOP3F/ne0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=AIbz7XCx1kxCmMrfMHXFnmgxeaXtcWXNZHadfoIuneQnq8ltsXCS45mrqKOztcfmL 82aRIXMWdvr7D5s7S0O2A55FUGTNQDcIDMb95xf1i1vCw8TpEoO/nUgr9BFejmPeSC wun1UzgVf5gQDrt/FScjLqTNc0WQ4SkKKWQVWnjRpVqOxreF3XFQM5r4/Jgr/mZcl9 3X2XkDKMGTlylO4zOrqaEUzCaTgEPWnrjH0SHPc+b02vIJdaGmHwyAcjnHQqQl0mpA rIuVsPwXD+vQbq9Ryd+irQgGunhfbUAcCX83e+S5B/fv8wdVmoFxUPv/LTdWa3LlxQ GFjWbwZN1Qhdw== Date: Fri, 05 Apr 2024 16:34:58 +0000 To: Gergo Koteles From: =?utf-8?Q?Barnab=C3=A1s_P=C5=91cze?= Cc: "Rafael J. Wysocki" , Len Brown , Ike Panhc , Hans de Goede , =?utf-8?Q?Ilpo_J=C3=A4rvinen?= , Henrique de Moraes Holschuh , 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() Message-ID: In-Reply-To: References: Feedback-ID: 20568564:user:proton 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: quoted-printable Hi 2024. =C3=A1prilis 5., p=C3=A9ntek 5:05 keltez=C3=A9ssel, Gergo Koteles =C3=ADrta: > Some laptops have a key to switch platform profiles. >=20 > Add a platform_profile_cycle() function to cycle between the enabled > profiles. >=20 > Signed-off-by: Gergo Koteles > --- > drivers/acpi/platform_profile.c | 42 ++++++++++++++++++++++++++++++++ > include/linux/platform_profile.h | 1 + > 2 files changed, 43 insertions(+) >=20 > diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_prof= ile.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); >=20 > +int platform_profile_cycle(void) > +{ > +=09enum platform_profile_option profile; > +=09enum platform_profile_option next; > +=09int err; > + > +=09err =3D mutex_lock_interruptible(&profile_lock); > +=09if (err) > +=09=09return err; > + > +=09if (!cur_profile) { > +=09=09mutex_unlock(&profile_lock); > +=09=09return -ENODEV; > +=09} > + > +=09err =3D cur_profile->profile_get(cur_profile, &profile); > +=09if (err) { > +=09=09mutex_unlock(&profile_lock); > +=09=09return err; > +=09} > + > +=09next =3D ffs(cur_profile->choices[0] >> (profile + 1)) + profile; > + > +=09/* current profile is the highest, select the lowest */ > +=09if (next =3D=3D profile) > +=09=09next =3D ffs(cur_profile->choices[0]) - 1; I think you can use `find_next_bit()` or similar instead. > + > +=09if (WARN_ON((next < 0) || (next >=3D ARRAY_SIZE(profile_names)))) { > +=09=09mutex_unlock(&profile_lock); > +=09=09return -EINVAL; > +=09} > + > +=09err =3D cur_profile->profile_set(cur_profile, next); > +=09mutex_unlock(&profile_lock); > + > +=09if (!err) > +=09=09sysfs_notify(acpi_kobj, NULL, "platform_profile"); > + > +=09return err; > +} > +EXPORT_SYMBOL_GPL(platform_profile_cycle); > + > int platform_profile_register(struct platform_profile_handler *pprof) > { > =09int err; > diff --git a/include/linux/platform_profile.h b/include/linux/platform_pr= ofile.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 { >=20 > int platform_profile_register(struct platform_profile_handler *pprof); > int platform_profile_remove(void); > +int platform_profile_cycle(void); > void platform_profile_notify(void); >=20 > #endif /*_PLATFORM_PROFILE_H_*/ > -- > 2.44.0 >=20 Regards, Barnab=C3=A1s P=C5=91cze