From nobody Thu Nov 28 18:28:54 2024 Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (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 699783BB24; Mon, 30 Sep 2024 00:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654462; cv=none; b=TzAJmC+SLYkw35mZiFH3WK0YlCuQeo4WfMsesaDD2lAf0+OXgd3MXLHeczjTezNxNHs3Xh5rhW0ABPgS9Tznp0ZWzFps3gGJJxp8ITwmjCIkgAJhkfisHOzH4KjozoI5nHXSRYFfajc4YzkyXk9hrv1OmOL5qjvQhQDXH7LJMe8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654462; c=relaxed/simple; bh=DLQDS9gcy6U1XM5MIluSlORbovD5evV7jFxCDR0aVR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IQCBxEovGRuwpV5wYEmaKG3Qpmi3u6thqHNvlXc6Lf6PcXjw1wGvAQPXbfao0YCU+WRx65I2oP2LtsZJsHPr/hHWpulCo8dG8d/PhMYx+YW4rirC0z9eZSKXk4aWVD+GJBicQOzmOLczgYKmrYFBjSr5bXnpWQIuXvd1IMdqHog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=dSEytDzr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bzHBHH66; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="dSEytDzr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bzHBHH66" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id 75F3C1380211; Sun, 29 Sep 2024 20:00:59 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Sun, 29 Sep 2024 20:00:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1727654459; x= 1727740859; bh=VxlV172xyHrTQ/zpqQqtA1Dtnt/AvJVJ15KyMVETlaY=; b=d SEytDzrm5B+51Cb44sxX6uyKyxF0joydoG5s9jZ6nGkGP+8Us+00o6FvX6emsgAt ue8sqNdBhoe81YTLztIwVT7f3P5z4Vqn3SYA9z0NItE7Rg2kfqajkNRAUGyqDyI+ vLng7LkV3qBiHIId7J11YKAVn6GfMdsOHqPSDE/hZTtZNk/CpZcuIUtJigvEi6MX yuE6x8iEYR9fEBFNPDWziszsPvi7cvXaJerCE9PrS6IR1HP08uj7rT9X5+GalA4b PSstdUrNA9dW6eDFtbjdeMyCd0n5oDBolpy6MAAsPVYo6z5+0JRaf80kYQv7kVnj Og4/Lk5OPouAwq8/vIfwg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654459; x= 1727740859; bh=VxlV172xyHrTQ/zpqQqtA1Dtnt/AvJVJ15KyMVETlaY=; b=b zHBHH66aSVhEtitd3T73Js7xBC/cFp17UG1I62j5jVUiPmMLrTTeOuKOY4xhrBGx cgPsBfE7s486KfF0O5fxxaN11sHpGbLcjeA1WmCQFM4RGnFLMx/Y3w4YXtzSSEhB hTvh/O1x4oETabMYMKejmcT9eqjVqNDDVIsSaAXHwRpxvw7Vq8WOqgZ39183pPWu cNWfzEvKT6PZQsHOHExRXvK4TwPWGt5RgjDG5Wa9BKDG7oVPUvWdRLRX2mTi6U7+ yxE8Sv3cKnhjLtrqOrbSjtE9WllIRzjGsPfV3x5vHALSTVzQeMTLbpvvXj9IslxT u7ubDpZDPqTAGFoQkYOLA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhjohhnvghsrd guvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugffgleeltedv veethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghvpdhnsggprhgtphhtthho pedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqihhnphhu thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjihhkohhssehkvghrnh gvlhdrohhrghdprhgtphhtthhopehplhgrthhfohhrmhdqughrihhvvghrqdigkeeisehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihhlphhordhjrghrvhhinhgvnh eslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehhuggvghhovgguvgesrhgv ughhrghtrdgtohhmpdhrtghpthhtoheptghorhgvnhhtihhnrdgthhgrrhihsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhuphgvrhhmudeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:00:55 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" , Mario Limonciello Subject: [PATCH v6 1/9] platform/x86: asus-wmi: export symbols used for read/write WMI Date: Mon, 30 Sep 2024 13:00:38 +1300 Message-ID: <20240930000046.51388-2-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Export some rather helpful read/write WMI symbols using a namespace. These are DEVS and DSTS only, or require the arg0 input. Also does a slight refactor of internals of these functions. Signed-off-by: Luke D. Jones Reviewed-by: Mario Limonciello --- drivers/platform/x86/asus-wmi.c | 51 ++++++++++++++++++++-- include/linux/platform_data/x86/asus-wmi.h | 10 +++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wm= i.c index 6725a27df62f..0a5221d65130 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -385,7 +385,7 @@ int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u= 32 arg1, u32 *retval) { return asus_wmi_evaluate_method3(method_id, arg0, arg1, 0, retval); } -EXPORT_SYMBOL_GPL(asus_wmi_evaluate_method); +EXPORT_SYMBOL_NS_GPL(asus_wmi_evaluate_method, ASUS_WMI); =20 static int asus_wmi_evaluate_method5(u32 method_id, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 arg4, u32 *retval) @@ -549,12 +549,57 @@ static int asus_wmi_get_devstate(struct asus_wmi *asu= s, u32 dev_id, u32 *retval) return 0; } =20 -static int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, - u32 *retval) +/** + * asus_wmi_get_devstate_dsts() - Get the WMI function state. + * @dev_id: The WMI function to call. + * @retval: A pointer to where to store the value returned from WMI. + * + * The returned WMI function state can also be used to determine if the WMI + * function is supported by checking if the asus_wmi_get_devstate_dsts() + * returns an error. + * + * On success the return value is 0, and the retval is a valid value retur= ned + * by the successful WMI function call. An error value is returned only if= the + * WMI function failed, or if it returns "unsupported" which is typically = a 0 + * (no return, and no 'supported' bit set), or a 0xFFFFFFFE (~1) which if = not + * caught here can result in unexpected behaviour later. + */ +int asus_wmi_get_devstate_dsts(u32 dev_id, u32 *retval) +{ + int err; + + err =3D asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, dev_id, 0, retva= l); + if (err) + return err; + + *retval &=3D ~ASUS_WMI_DSTS_PRESENCE_BIT; + if (*retval =3D=3D ASUS_WMI_UNSUPPORTED_METHOD) + return -ENODEV; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(asus_wmi_get_devstate_dsts, ASUS_WMI); + +/** + * asus_wmi_set_devstate() - Set the WMI function state. + * @dev_id: The WMI function to call. + * @ctrl_param: The argument to be used for this WMI function. + * @retval: A pointer to where to store the value returned from WMI. + * + * The returned WMI function state if not checked here for error as + * asus_wmi_set_devstate() is not called unless first paired with a call to + * asus_wmi_get_devstate_dsts() to check that the WMI function is supporte= d. + * + * On success the return value is 0, and the retval is a valid value retur= ned + * by the successful WMI function call. An error value is returned only if= the + * WMI function failed. + */ +int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval) { return asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS, dev_id, ctrl_param, retval); } +EXPORT_SYMBOL_NS_GPL(asus_wmi_set_devstate, ASUS_WMI); =20 /* Helper for special devices with magic return codes */ static int asus_wmi_get_devstate_bits(struct asus_wmi *asus, diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index 365e119bebaa..6ea4dedfb85e 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -158,8 +158,18 @@ #define ASUS_WMI_DSTS_LIGHTBAR_MASK 0x0000000F =20 #if IS_REACHABLE(CONFIG_ASUS_WMI) +int asus_wmi_get_devstate_dsts(u32 dev_id, u32 *retval); +int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *retval); int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1, u32 *retva= l); #else +static inline int asus_wmi_get_devstate_dsts(u32 dev_id, u32 *retval) +{ + return -ENODEV; +} +static inline int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param, u32 *r= etval) +{ + return -ENODEV; +} static inline int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 ar= g1, u32 *retval) { --=20 2.46.1 From nobody Thu Nov 28 18:28:54 2024 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 AB3D020E3; Mon, 30 Sep 2024 00:01:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654466; cv=none; b=T+OCtJfVD4xTBChISz0L5hK3uJnZuORCvnrT+TgmnG9+EXle2cwEmttSdpFr0DAmMkXIvyfn2eXKIsi0N49cwIxRJ3kvnzdFtiGrE7JCKqA60MF8+b8d4+gUhGOpOwwmoSNITxKsIonMG1mseb3nOoSK5zJzsGV5bwFwImIJMQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654466; c=relaxed/simple; bh=F5nsnUF/LLwYv5OebTo/vk+KTkqsA+0WiBF9qachlAA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxzgnnJdnYYLrlxLKYSwIvM02TWi0ODaGjYAfARuNAW1OajY+vnHtPGtE+BWIybqYeK227E70PDBr6azslgcTP3kM59rErZGT5Z7gcDbQvWwhBbDjDZOOy4+R8Vc4zkmbj4U9lu+GhJZpg/mwKndPztZ0UokG1c64t8udfac+no= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=Hc2i/2C6; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nP6vNVzk; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="Hc2i/2C6"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nP6vNVzk" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id C2095114013C; Sun, 29 Sep 2024 20:01:03 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Sun, 29 Sep 2024 20:01:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1727654463; x= 1727740863; bh=8G22bI9F/1QDb/B0ZgWZNzwOEjpuSyGQlONf6x/zq7Y=; b=H c2i/2C67zEvRvfgPnvGoXN4rBgEbs1yVJxh8BT2aUAFqoYLk+dMwvzAQ5Dlo0u6I /b6f4zTgiJLZf7B+c7VgLG3JCYB1seOPKu+RnPDqQ1HzLHbf5Xt3poCF1MBi6QO1 Lz2sPtn+uOKmMWJJL9XzCOG4+onXi8d9bVQtGqvqane9tHCuvbLRHGEhGhZ2xMMv wTjbW9YV3guwrWMxr8/tVaIIYaTyMSpIpjnA02y8qytbbccq2ryu4l5wDEIwhKYa WRFWmFG6qH2Cecy6pFwPslh0SP0iXnfN4V0GQpbbQykHusAauTvOiLR6oJkYU0Zm Rh5b+A2yZSH6xsMSNUR7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654463; x= 1727740863; bh=8G22bI9F/1QDb/B0ZgWZNzwOEjpuSyGQlONf6x/zq7Y=; b=n P6vNVzkwjItU4FQttsTSLAOtTlCq9Wjusr9Wk6mmuSMJ+mALKitbPx5R+QdUsWYP WfJ7/b5zpME5R8Iwn3xcgt45EtUlbXuvxo4/cwoGlkC2Z6xWr9uR+VgaMx+gyawc xK9NzgxJ+Dki11HbTOVd5ATLjMh762l3A8fmdHHa6G0KjePxrCK+dVjKGZpOBgWk btx1vyZUA2AlsOz6PVb5XTwx00iiu3T3CDC5ZX42KsYSRFjShsqMNXeVB8CRgi/x Y8M6o9nWflmQ6j92nXemdjJoz2/fUPY7Ce9G00Ivh13YNDbhNrJxv3qJibB6Bkd9 GyndTNHIMHh0qKbN2ynQQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhjohhnvghsrd guvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugffgleeltedv veethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghvpdhnsggprhgtphhtthho pedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqihhnphhu thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjihhkohhssehkvghrnh gvlhdrohhrghdprhgtphhtthhopehplhgrthhfohhrmhdqughrihhvvghrqdigkeeisehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihhlphhordhjrghrvhhinhgvnh eslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehhuggvghhovgguvgesrhgv ughhrghtrdgtohhmpdhrtghpthhtoheptghorhgvnhhtihhnrdgthhgrrhihsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhuphgvrhhmudeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:00:59 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" , Jiri Kosina Subject: [PATCH v6 2/9] hid-asus: Add MODULE_IMPORT_NS(ASUS_WMI) Date: Mon, 30 Sep 2024 13:00:39 +1300 Message-ID: <20240930000046.51388-3-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A small change to asus_wmi_evaluate_method() was introduced during asus-armoury driver development to put the exports behind a namespace. Import that namespace here. Signed-off-by: Luke D. Jones Acked-by: Jiri Kosina --- drivers/hid/hid-asus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index a4b47319ad8e..9540e3e19cce 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -1301,4 +1301,5 @@ static struct hid_driver asus_driver =3D { }; module_hid_driver(asus_driver); =20 +MODULE_IMPORT_NS(ASUS_WMI); MODULE_LICENSE("GPL"); --=20 2.46.1 From nobody Thu Nov 28 18:28:54 2024 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 274DE168488; Mon, 30 Sep 2024 00:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654471; cv=none; b=RnESirc9/NksYU+681gqF4FUdbrC5mIQylX5JTOidOO+wylNktWZ5YTfXdQP97DV065KM2bqcMprHpM9lDH6du6dKvxI4Pp0h6M7mTBHGEy/hZ4qdIiWKNHRkiNmHyhRJQzFqJnFUpDudJG7XXYHc9YnwZ+qHwvo1HT2aaWxDjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654471; c=relaxed/simple; bh=GVFI1Z898RRKFB82y+I+SzEn5HPNeRlTZCgFnxFsIJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hBHLpeUa5s1Z1ftnler269GihAEYHToYTPWytAdOGyPureivNJGkekP09dLuxG2t/2W57Q4RVt3sFtbcZx3fW2taRXuRNFikY0hwHpq/VGj2ET9RJdDrPslhyM8P1zfJZtNp9Ao/Za8cgmIbVT3mAcMMocC+lowjCLk1a3qFv7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=rUROmBcW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Sldzx6Vz; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="rUROmBcW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Sldzx6Vz" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id 32A7911400B2; Sun, 29 Sep 2024 20:01:08 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Sun, 29 Sep 2024 20:01:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1727654468; x=1727740868; bh=J3kg83uc0tCA/s6xaif5CHqeXlR4HeKrXOxhVGnsc08=; b= rUROmBcWRb7blFT3vgWcxY0SwEGqqfyevs5wjrqKNl5/l72Gfs3XkvYDa9cUjzU4 f7kep2+0Kv0nzz91dmuSj5AO6AScE2K3UuXQ9TRG9ety5yfpP/WH1GLGyC5uUfhp tpnoewto91Ft10IjOJ3oRWsCVwO3+KJgwgLfNd0wjISFg+EdUTjmOIdV+IlOBveW fjdHBAodjQvc0AuIdoWHbTkZ4AhAp3JVYyDnl5TK4f0/4geVk2JyC3JUh9p6cpe6 w5ow9aOAm+Pr1Lomzv8s+zB6BxljAN8GhdW1yZ3RtnMazPNdJHw9TmB7tDsuDlyt wUvsJMs/qgQA2aO1gN7oGQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654468; x= 1727740868; bh=J3kg83uc0tCA/s6xaif5CHqeXlR4HeKrXOxhVGnsc08=; b=S ldzx6VzuGGhiabiDHTkUZq89ZVszgijOcNkhn7BIo8LzmY9R6KYMd3fw52+Txq5X np81EA3mOJyAs/ffimu5DVB+LSir7zaU5twxvRWobPWThjav9EeVwZ1R4O9iU3VT mFhkLZGLFsaXMIDM07I/Ue5XWXgwkJXK4lq1OBgCd8uCZrnkx4Kr3G2tm/AYI835 v8JAfkauO9Aw7KTZ8JHhcsafaIvg0Sd4rvu8/7URuc7foN5zdJ9LZNgVhwlDqTP4 nTywtcaiSBe6JR7iZvXX6y2uI0TB/5ySwIlQguSTqKauEaIOjbsQZp6F+i+++0xg p7fIcXzASCqK0/v+/7jIQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevuf ffkffojghfgggtgfesthekredtredtjeenucfhrhhomhepfdfnuhhkvgcuffdrucflohhn vghsfdcuoehluhhkvgeslhhjohhnvghsrdguvghvqeenucggtffrrghtthgvrhhnpeduud etudehiedvvdevveelhfegkeefffdvfeetuefgveefgffgffeiffeitdelieenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehluhhkvgeslhhjoh hnvghsrdguvghvpdhnsggprhgtphhtthhopeelpdhmohguvgepshhmthhpohhuthdprhgt phhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprh gtphhtthhopehlihhnuhigqdhinhhpuhhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhr tghpthhtohepjhhikhhosheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphhlrghtfh horhhmqdgurhhivhgvrhdqgiekieesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphht thhopehilhhpohdrjhgrrhhvihhnvghnsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtg hpthhtohephhguvghgohgvuggvsehrvgguhhgrthdrtghomhdprhgtphhtthhopegtohhr vghnthhinhdrtghhrghrhiesghhmrghilhdrtghomhdprhgtphhtthhopehsuhhpvghrmh dusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehluhhkvgeslhhjohhnvghsrdguvghv X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:01:04 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" Subject: [PATCH v6 3/9] platform/x86: asus-armoury: move existing tunings to asus-armoury module Date: Mon, 30 Sep 2024 13:00:40 +1300 Message-ID: <20240930000046.51388-4-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> 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 The fw_attributes_class provides a much cleaner interface to all of the attributes introduced to asus-wmi. This patch moves all of these extra attributes over to fw_attributes_class, and shifts the bulk of these definitions to a new kernel module to reduce the clutter of asus-wmi with the intention of deprecating the asus-wmi attributes in future. The work applies only to WMI methods which don't have a clearly defined place within the sysfs and as a result ended up lumped together in /sys/devices/platform/asus-nb-wmi/ with no standard API. Where possible the fw attrs now implement defaults, min, max, scalar, choices, etc. As en example dgpu_disable becomes: /sys/class/firmware-attributes/asus-armoury/attributes/dgpu_disable/ =E2=94=9C=E2=94=80=E2=94=80 current_value =E2=94=9C=E2=94=80=E2=94=80 display_name =E2=94=9C=E2=94=80=E2=94=80 possible_values =E2=94=94=E2=94=80=E2=94=80 type as do other attributes. The ppt_* based attributes are removed in this initial patch as the implementation is somewhat broken due to the WMI methods requiring a set of limits on the values accepted (which is not provided by WMI). Signed-off-by: Luke D. Jones Reviewed-by: Mario Limonciello --- drivers/platform/x86/Kconfig | 12 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/asus-armoury.c | 593 +++++++++++++++++++++ drivers/platform/x86/asus-armoury.h | 146 +++++ drivers/platform/x86/asus-wmi.c | 4 - include/linux/platform_data/x86/asus-wmi.h | 3 + 6 files changed, 755 insertions(+), 4 deletions(-) create mode 100644 drivers/platform/x86/asus-armoury.c create mode 100644 drivers/platform/x86/asus-armoury.h diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 3875abba5a79..80ec8b45022d 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -265,6 +265,18 @@ config ASUS_WIRELESS If you choose to compile this driver as a module the module will be called asus-wireless. =20 +config ASUS_ARMOURY + tristate "ASUS Armoury driver" + depends on ASUS_WMI + select FW_ATTR_CLASS + help + Say Y here if you have a WMI aware Asus machine and would like to use t= he + firmware_attributes API to control various settings typically exposed in + the ASUS Armoury Crate application available on Windows. + + To compile this driver as a module, choose M here: the module will + be called asus-armoury. + config ASUS_WMI tristate "ASUS WMI Driver" depends on ACPI_WMI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index e1b142947067..fe3e7e7dede8 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_APPLE_GMUX) +=3D apple-gmux.o # ASUS obj-$(CONFIG_ASUS_LAPTOP) +=3D asus-laptop.o obj-$(CONFIG_ASUS_WIRELESS) +=3D asus-wireless.o +obj-$(CONFIG_ASUS_ARMOURY) +=3D asus-armoury.o obj-$(CONFIG_ASUS_WMI) +=3D asus-wmi.o obj-$(CONFIG_ASUS_NB_WMI) +=3D asus-nb-wmi.o obj-$(CONFIG_ASUS_TF103C_DOCK) +=3D asus-tf103c-dock.o diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asu= s-armoury.c new file mode 100644 index 000000000000..0085f1b112ab --- /dev/null +++ b/drivers/platform/x86/asus-armoury.c @@ -0,0 +1,593 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Asus Armoury (WMI) attributes driver. This driver uses the fw_attributes + * class to expose the various WMI functions that many gaming and some + * non-gaming ASUS laptops have available. + * These typically don't fit anywhere else in the sysfs such as under LED = class, + * hwmon or other, and are set in Windows using the ASUS Armoury Crate too= l. + * + * Copyright(C) 2010 Intel Corporation. + * Copyright(C) 2024-2024 Luke Jones + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "asus-armoury.h" +#include "firmware_attributes_class.h" + +#define ASUS_NB_WMI_EVENT_GUID "0B3CBB35-E3C2-45ED-91C2-4C5A6D195D1C" + +#define ASUS_MINI_LED_MODE_MASK 0x03 +/* Standard modes for devices with only on/off */ +#define ASUS_MINI_LED_OFF 0x00 +#define ASUS_MINI_LED_ON 0x01 +/* Like "on" but the effect is more vibrant or brighter */ +#define ASUS_MINI_LED_STRONG_MODE 0x02 +/* New modes for devices with 3 mini-led mode types */ +#define ASUS_MINI_LED_2024_WEAK 0x00 +#define ASUS_MINI_LED_2024_STRONG 0x01 +#define ASUS_MINI_LED_2024_OFF 0x02 + +/* Default limits for tunables available on ASUS ROG laptops */ +#define NVIDIA_BOOST_MIN 5 +#define NVIDIA_BOOST_MAX 25 +#define NVIDIA_TEMP_MIN 75 +#define NVIDIA_TEMP_MAX 87 +#define PPT_CPU_LIMIT_MIN 5 +#define PPT_CPU_LIMIT_MAX 150 +#define PPT_CPU_LIMIT_DEFAULT 80 +#define PPT_PLATFORM_MIN 5 +#define PPT_PLATFORM_MAX 100 +#define PPT_PLATFORM_DEFAULT 80 + +static const struct class *fw_attr_class; + +struct asus_armoury_priv { + struct device *fw_attr_dev; + struct kset *fw_attr_kset; + + u32 mini_led_dev_id; + u32 gpu_mux_dev_id; + + struct mutex mutex; +}; + +static struct asus_armoury_priv asus_armoury =3D { .mutex =3D __MUTEX_INIT= IALIZER( + asus_armoury.mutex) }; + +struct fw_attrs_group { + bool pending_reboot; +}; + +static struct fw_attrs_group fw_attrs =3D { + .pending_reboot =3D false, +}; + +struct asus_attr_group { + const struct attribute_group *attr_group; + u32 wmi_devid; +}; + +static bool asus_wmi_is_present(u32 dev_id) +{ + u32 retval; + int status; + + status =3D asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, dev_id, 0, &r= etval); + pr_debug("%s called (0x%08x), retval: 0x%08x\n", __func__, dev_id, retval= ); + + return status =3D=3D 0 && (retval & ASUS_WMI_DSTS_PRESENCE_BIT); +} + +static void asus_set_reboot_and_signal_event(void) +{ + fw_attrs.pending_reboot =3D true; + kobject_uevent(&asus_armoury.fw_attr_dev->kobj, KOBJ_CHANGE); +} + +static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attri= bute *attr, char *buf) +{ + return sysfs_emit(buf, "%d\n", fw_attrs.pending_reboot); +} + +static struct kobj_attribute pending_reboot =3D __ATTR_RO(pending_reboot); + +static bool asus_bios_requires_reboot(struct kobj_attribute *attr) +{ + return !strcmp(attr->attr.name, "gpu_mux_mode"); +} + +/** + * attr_int_store() - Generic store function for use with most WMI functio= ns. + * @kobj: Pointer to the driver object. + * @kobj_attribute: Pointer to the attribute calling this function. + * @buf: The buffer to read from, this is parsed to `int` type. + * @count: Required by sysfs attribute macros, pass in from the callee att= r. + * @min: Minimum accepted value. Below this returns -EINVAL. + * @max: Maximum accepted value. Above this returns -EINVAL. + * @store_value: Pointer to where the parsed value should be stored. + * @wmi_dev: The WMI function ID to use. + * + * The WMI functions available on most ASUS laptops return a 1 as "success= ", and + * a 0 as failed. However some functions can return n > 1 for additional e= rrors. + * The function currently treats all values which are not 1 as errors, ign= oring + * the possible differences in WMI error returns. + * + * Returns: Either count, or an error. + */ +static ssize_t attr_int_store(struct kobject *kobj, struct kobj_attribute = *attr, const char *buf, + size_t count, u32 min, u32 max, u32 *store_value, u32 wmi_dev) +{ + u32 result, value; + int err; + + err =3D kstrtouint(buf, 10, &value); + if (err) + return err; + + if (value < min || value > max) + return -EINVAL; + + mutex_lock(&asus_armoury.mutex); + err =3D asus_wmi_set_devstate(wmi_dev, value, &result); + mutex_unlock(&asus_armoury.mutex); + if (err) { + pr_err("Failed to set %s: %d\n", attr->attr.name, err); + return err; + } + + if (result !=3D 1) { + pr_err("Failed to set %s (result): 0x%x\n", attr->attr.name, result); + return -EIO; + } + + if (store_value !=3D NULL) + *store_value =3D value; + sysfs_notify(kobj, NULL, attr->attr.name); + + if (asus_bios_requires_reboot(attr)) + asus_set_reboot_and_signal_event(); + + return count; +} + +/* Mini-LED mode *********************************************************= *****/ +static ssize_t mini_led_mode_current_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + u32 value; + int err; + + err =3D asus_wmi_get_devstate_dsts(asus_armoury.mini_led_dev_id, &value); + if (err) + return err; + + value &=3D ASUS_MINI_LED_MODE_MASK; + + /* + * Remap the mode values to match previous generation mini-LED. The last = gen + * WMI 0 =3D=3D off, while on this version WMI 2 =3D=3D off (flipped). + */ + if (asus_armoury.mini_led_dev_id =3D=3D ASUS_WMI_DEVID_MINI_LED_MODE2) { + switch (value) { + case ASUS_MINI_LED_2024_WEAK: + value =3D ASUS_MINI_LED_ON; + break; + case ASUS_MINI_LED_2024_STRONG: + value =3D ASUS_MINI_LED_STRONG_MODE; + break; + case ASUS_MINI_LED_2024_OFF: + value =3D ASUS_MINI_LED_OFF; + break; + } + } + + return sysfs_emit(buf, "%u\n", value); +} + +static ssize_t mini_led_mode_current_value_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, + size_t count) +{ + int result, err; + u32 mode; + + err =3D kstrtou32(buf, 10, &mode); + if (err) + return err; + + if (asus_armoury.mini_led_dev_id =3D=3D ASUS_WMI_DEVID_MINI_LED_MODE && + mode > ASUS_MINI_LED_ON) + return -EINVAL; + if (asus_armoury.mini_led_dev_id =3D=3D ASUS_WMI_DEVID_MINI_LED_MODE2 && + mode > ASUS_MINI_LED_STRONG_MODE) + return -EINVAL; + + /* + * Remap the mode values so expected behaviour is the same as the last + * generation of mini-LED with 0 =3D=3D off, 1 =3D=3D on. + */ + if (asus_armoury.mini_led_dev_id =3D=3D ASUS_WMI_DEVID_MINI_LED_MODE2) { + switch (mode) { + case ASUS_MINI_LED_OFF: + mode =3D ASUS_MINI_LED_2024_OFF; + break; + case ASUS_MINI_LED_ON: + mode =3D ASUS_MINI_LED_2024_WEAK; + break; + case ASUS_MINI_LED_STRONG_MODE: + mode =3D ASUS_MINI_LED_2024_STRONG; + break; + } + } + + mutex_lock(&asus_armoury.mutex); + err =3D asus_wmi_set_devstate(asus_armoury.mini_led_dev_id, mode, &result= ); + mutex_unlock(&asus_armoury.mutex); + if (err) { + pr_warn("Failed to set mini-LED: %d\n", err); + return err; + } + + if (result !=3D 1) { + pr_warn("Failed to set mini-LED mode (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(kobj, NULL, attr->attr.name); + + return count; +} + +static ssize_t mini_led_mode_possible_values_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + switch (asus_armoury.mini_led_dev_id) { + case ASUS_WMI_DEVID_MINI_LED_MODE: + return sysfs_emit(buf, "0;1\n"); + case ASUS_WMI_DEVID_MINI_LED_MODE2: + return sysfs_emit(buf, "0;1;2\n"); + } + + return sysfs_emit(buf, "0\n"); +} + +ATTR_GROUP_ENUM_CUSTOM(mini_led_mode, "mini_led_mode", "Set the mini-LED b= acklight mode"); + +static ssize_t gpu_mux_mode_current_value_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, + size_t count) +{ + int result, err; + u32 optimus; + + err =3D kstrtou32(buf, 10, &optimus); + if (err) + return err; + + if (optimus > 1) + return -EINVAL; + + if (asus_wmi_is_present(ASUS_WMI_DEVID_DGPU)) { + err =3D asus_wmi_get_devstate_dsts(ASUS_WMI_DEVID_DGPU, &result); + if (err) + return err; + if (result && !optimus) { + err =3D -ENODEV; + pr_warn("Can not switch MUX to dGPU mode when dGPU is disabled: %02X %0= 2X %d\n", + result, optimus, err); + return err; + } + } + + if (asus_wmi_is_present(ASUS_WMI_DEVID_EGPU)) { + err =3D asus_wmi_get_devstate_dsts(ASUS_WMI_DEVID_EGPU, &result); + if (err) + return err; + if (result && !optimus) { + err =3D -ENODEV; + pr_warn("Can not switch MUX to dGPU mode when eGPU is enabled: %d\n", + err); + return err; + } + } + + mutex_lock(&asus_armoury.mutex); + err =3D asus_wmi_set_devstate(asus_armoury.gpu_mux_dev_id, optimus, &resu= lt); + mutex_unlock(&asus_armoury.mutex); + if (err) { + pr_err("Failed to set GPU MUX mode: %d\n", err); + return err; + } + /* !1 is considered a fail by ASUS */ + if (result !=3D 1) { + pr_warn("Failed to set GPU MUX mode (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(kobj, NULL, attr->attr.name); + asus_set_reboot_and_signal_event(); + + return count; +} +WMI_SHOW_INT(gpu_mux_mode_current_value, "%d\n", asus_armoury.gpu_mux_dev_= id); +ATTR_GROUP_BOOL_CUSTOM(gpu_mux_mode, "gpu_mux_mode", "Set the GPU display = MUX mode"); + +/* + * A user may be required to store the value twice, typical store first, t= hen + * rescan PCI bus to activate power, then store a second time to save corr= ectly. + * The reason for this is that an extra code path in the ACPI is enabled w= hen + * the device and bus are powered. + */ +static ssize_t dgpu_disable_current_value_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, + size_t count) +{ + int result, err; + u32 disable; + + err =3D kstrtou32(buf, 10, &disable); + if (err) + return err; + + if (disable > 1) + return -EINVAL; + + if (asus_armoury.gpu_mux_dev_id) { + err =3D asus_wmi_get_devstate_dsts(asus_armoury.gpu_mux_dev_id, &result); + if (err) + return err; + if (!result && disable) { + err =3D -ENODEV; + pr_warn("Can not disable dGPU when the MUX is in dGPU mode: %d\n", err); + return err; + } + } + + mutex_lock(&asus_armoury.mutex); + err =3D asus_wmi_set_devstate(ASUS_WMI_DEVID_DGPU, disable, &result); + mutex_unlock(&asus_armoury.mutex); + if (err) { + pr_warn("Failed to set dGPU disable: %d\n", err); + return err; + } + + if (result !=3D 1) { + pr_warn("Failed to set dGPU disable (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(kobj, NULL, attr->attr.name); + + return count; +} +WMI_SHOW_INT(dgpu_disable_current_value, "%d\n", ASUS_WMI_DEVID_DGPU); +ATTR_GROUP_BOOL_CUSTOM(dgpu_disable, "dgpu_disable", "Disable the dGPU"); + +/* The ACPI call to enable the eGPU also disables the internal dGPU */ +static ssize_t egpu_enable_current_value_store(struct kobject *kobj, struc= t kobj_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 enable; + + err =3D kstrtou32(buf, 10, &enable); + if (err) + return err; + + if (enable > 1) + return -EINVAL; + + err =3D asus_wmi_get_devstate_dsts(ASUS_WMI_DEVID_EGPU_CONNECTED, &result= ); + if (err) { + pr_warn("Failed to get eGPU connection status: %d\n", err); + return err; + } + + if (asus_armoury.gpu_mux_dev_id) { + err =3D asus_wmi_get_devstate_dsts(asus_armoury.gpu_mux_dev_id, &result); + if (err) { + pr_warn("Failed to get GPU MUX status: %d\n", result); + return result; + } + if (!result && enable) { + err =3D -ENODEV; + pr_warn("Can not enable eGPU when the MUX is in dGPU mode: %d\n", err); + return err; + } + } + + mutex_lock(&asus_armoury.mutex); + err =3D asus_wmi_set_devstate(ASUS_WMI_DEVID_EGPU, enable, &result); + mutex_unlock(&asus_armoury.mutex); + if (err) { + pr_warn("Failed to set eGPU state: %d\n", err); + return err; + } + + if (result !=3D 1) { + pr_warn("Failed to set eGPU state (retval): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(kobj, NULL, attr->attr.name); + + return count; +} +WMI_SHOW_INT(egpu_enable_current_value, "%d\n", ASUS_WMI_DEVID_EGPU); +ATTR_GROUP_BOOL_CUSTOM(egpu_enable, "egpu_enable", "Enable the eGPU (also = disables dGPU)"); + +/* Simple attribute creation */ +ATTR_GROUP_ENUM_INT_RO(charge_mode, "charge_mode", ASUS_WMI_DEVID_CHARGE_M= ODE, "0;1;2", + "Show the current mode of charging"); + +ATTR_GROUP_BOOL_RW(boot_sound, "boot_sound", ASUS_WMI_DEVID_BOOT_SOUND, + "Set the boot POST sound"); +ATTR_GROUP_BOOL_RW(mcu_powersave, "mcu_powersave", ASUS_WMI_DEVID_MCU_POWE= RSAVE, + "Set MCU powersaving mode"); +ATTR_GROUP_BOOL_RW(panel_od, "panel_overdrive", ASUS_WMI_DEVID_PANEL_OD, + "Set the panel refresh overdrive"); +ATTR_GROUP_BOOL_RO(egpu_connected, "egpu_connected", ASUS_WMI_DEVID_EGPU_C= ONNECTED, + "Show the eGPU connection status"); + +/* If an attribute does not require any special case handling add it here = */ +static const struct asus_attr_group armoury_attr_groups[] =3D { + { &egpu_connected_attr_group, ASUS_WMI_DEVID_EGPU_CONNECTED }, + { &egpu_enable_attr_group, ASUS_WMI_DEVID_EGPU }, + { &dgpu_disable_attr_group, ASUS_WMI_DEVID_DGPU }, + + { &charge_mode_attr_group, ASUS_WMI_DEVID_CHARGE_MODE }, + { &boot_sound_attr_group, ASUS_WMI_DEVID_BOOT_SOUND }, + { &mcu_powersave_attr_group, ASUS_WMI_DEVID_MCU_POWERSAVE }, + { &panel_od_attr_group, ASUS_WMI_DEVID_PANEL_OD }, +}; + +static int asus_fw_attr_add(void) +{ + int err, i; + + err =3D fw_attributes_class_get(&fw_attr_class); + if (err) + return err; + + asus_armoury.fw_attr_dev =3D + device_create(fw_attr_class, NULL, MKDEV(0, 0), NULL, "%s", DRIVER_NAME); + + if (IS_ERR(asus_armoury.fw_attr_dev)) { + err =3D PTR_ERR(asus_armoury.fw_attr_dev); + goto fail_class_get; + } + + asus_armoury.fw_attr_kset =3D + kset_create_and_add("attributes", NULL, &asus_armoury.fw_attr_dev->kobj); + if (!asus_armoury.fw_attr_kset) { + err =3D -ENOMEM; + goto err_destroy_classdev; + } + + err =3D sysfs_create_file(&asus_armoury.fw_attr_kset->kobj, &pending_rebo= ot.attr); + if (err) { + pr_err("Failed to create sysfs level attributes\n"); + goto err_destroy_kset; + } + + asus_armoury.mini_led_dev_id =3D 0; + if (asus_wmi_is_present(ASUS_WMI_DEVID_MINI_LED_MODE)) { + asus_armoury.mini_led_dev_id =3D ASUS_WMI_DEVID_MINI_LED_MODE; + err =3D sysfs_create_group(&asus_armoury.fw_attr_kset->kobj, &mini_led_m= ode_attr_group); + } else if (asus_wmi_is_present(ASUS_WMI_DEVID_MINI_LED_MODE2)) { + asus_armoury.mini_led_dev_id =3D ASUS_WMI_DEVID_MINI_LED_MODE2; + err =3D sysfs_create_group(&asus_armoury.fw_attr_kset->kobj, &mini_led_m= ode_attr_group); + } + if (err) { + pr_err("Failed to create sysfs-group for mini_led\n"); + goto err_remove_file; + } + + asus_armoury.gpu_mux_dev_id =3D 0; + if (asus_wmi_is_present(ASUS_WMI_DEVID_GPU_MUX)) { + asus_armoury.gpu_mux_dev_id =3D ASUS_WMI_DEVID_GPU_MUX; + err =3D sysfs_create_group(&asus_armoury.fw_attr_kset->kobj, &gpu_mux_mo= de_attr_group); + } else if (asus_wmi_is_present(ASUS_WMI_DEVID_GPU_MUX_VIVO)) { + asus_armoury.gpu_mux_dev_id =3D ASUS_WMI_DEVID_GPU_MUX_VIVO; + err =3D sysfs_create_group(&asus_armoury.fw_attr_kset->kobj, &gpu_mux_mo= de_attr_group); + } + if (err) { + pr_err("Failed to create sysfs-group for gpu_mux\n"); + goto err_remove_mini_led_group; + } + + for (i =3D 0; i < ARRAY_SIZE(armoury_attr_groups); i++) { + if (!asus_wmi_is_present(armoury_attr_groups[i].wmi_devid)) + continue; + + err =3D sysfs_create_group(&asus_armoury.fw_attr_kset->kobj, + armoury_attr_groups[i].attr_group); + if (err) { + pr_err("Failed to create sysfs-group for %s\n", + armoury_attr_groups[i].attr_group->name); + goto err_remove_groups; + } else { + pr_debug("Created sysfs-group for %s\n", + armoury_attr_groups[i].attr_group->name); + } + } + + return 0; + +err_remove_groups: + while (--i >=3D 0) { + if (asus_wmi_is_present(armoury_attr_groups[i].wmi_devid)) + sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, armoury_attr_group= s[i].attr_group); + } + sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, &gpu_mux_mode_attr_g= roup); +err_remove_mini_led_group: + sysfs_remove_group(&asus_armoury.fw_attr_kset->kobj, &mini_led_mode_attr_= group); +err_remove_file: + sysfs_remove_file(&asus_armoury.fw_attr_kset->kobj, &pending_reboot.attr); +err_destroy_kset: + kset_unregister(asus_armoury.fw_attr_kset); +err_destroy_classdev: + device_destroy(fw_attr_class, MKDEV(0, 0)); +fail_class_get: + fw_attributes_class_put(); + return err; +} + +/* Init / exit ***********************************************************= *****/ + +static int __init asus_fw_init(void) +{ + char *wmi_uid; + int err; + + wmi_uid =3D wmi_get_acpi_device_uid(ASUS_WMI_MGMT_GUID); + if (!wmi_uid) + return -ENODEV; + + /* + * if equal to "ASUSWMI" then it's DCTS that can't be used for this + * driver, DSTS is required. + */ + if (!strcmp(wmi_uid, ASUS_ACPI_UID_ASUSWMI)) + return -ENODEV; + + err =3D asus_fw_attr_add(); + if (err) + return err; + + return 0; +} + +static void __exit asus_fw_exit(void) +{ + mutex_lock(&asus_armoury.mutex); + + sysfs_remove_file(&asus_armoury.fw_attr_kset->kobj, &pending_reboot.attr); + kset_unregister(asus_armoury.fw_attr_kset); + device_destroy(fw_attr_class, MKDEV(0, 0)); + fw_attributes_class_put(); + + mutex_unlock(&asus_armoury.mutex); +} + +module_init(asus_fw_init); +module_exit(asus_fw_exit); + +MODULE_IMPORT_NS(ASUS_WMI); +MODULE_AUTHOR("Luke Jones "); +MODULE_DESCRIPTION("ASUS BIOS Configuration Driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("wmi:" ASUS_NB_WMI_EVENT_GUID); diff --git a/drivers/platform/x86/asus-armoury.h b/drivers/platform/x86/asu= s-armoury.h new file mode 100644 index 000000000000..4d0dd34c52aa --- /dev/null +++ b/drivers/platform/x86/asus-armoury.h @@ -0,0 +1,146 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Definitions for kernel modules using asus-armoury driver + * + * Copyright (c) 2024 Luke Jones + */ + +#ifndef _ASUS_ARMOURY_H_ +#define _ASUS_ARMOURY_H_ + +#include +#include + +#define DRIVER_NAME "asus-armoury" + +static ssize_t attr_int_store(struct kobject *kobj, struct kobj_attribute = *attr, + const char *buf, size_t count, u32 min, u32 max, + u32 *store_value, u32 wmi_dev); + +static ssize_t enum_type_show(struct kobject *kobj, struct kobj_attribute = *attr, + char *buf) +{ + return sysfs_emit(buf, "enumeration\n"); +} + +#define __ASUS_ATTR_RO(_func, _name) \ + { \ + .attr =3D { .name =3D __stringify(_name), .mode =3D 0444 }, \ + .show =3D _func##_##_name##_show, \ + } + +#define __ASUS_ATTR_RO_AS(_name, _show) \ + { \ + .attr =3D { .name =3D __stringify(_name), .mode =3D 0444 }, \ + .show =3D _show, \ + } + +#define __ASUS_ATTR_RW(_func, _name) \ + __ATTR(_name, 0644, _func##_##_name##_show, _func##_##_name##_store) + +#define __WMI_STORE_INT(_attr, _min, _max, _wmi) \ + static ssize_t _attr##_store(struct kobject *kobj, \ + struct kobj_attribute *attr, \ + const char *buf, size_t count) \ + { \ + return attr_int_store(kobj, attr, buf, count, _min, _max, \ + NULL, _wmi); \ + } + +#define WMI_SHOW_INT(_attr, _fmt, _wmi) = \ + static ssize_t _attr##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, char *buf) \ + { \ + u32 result; \ + int err; \ + err =3D asus_wmi_get_devstate_dsts(_wmi, &result); \ + if (err) \ + return err; \ + return sysfs_emit(buf, _fmt, \ + result & ~ASUS_WMI_DSTS_PRESENCE_BIT); \ + } + +/* Create functions and attributes for use in other macros or on their own= */ + +#define __ATTR_CURRENT_INT_RO(_attr, _wmi) \ + WMI_SHOW_INT(_attr##_current_value, "%d\n", _wmi); \ + static struct kobj_attribute attr_##_attr##_current_value =3D \ + __ASUS_ATTR_RO(_attr, current_value) + +#define __ATTR_CURRENT_INT_RW(_attr, _minv, _maxv, _wmi) \ + __WMI_STORE_INT(_attr##_current_value, _minv, _maxv, _wmi); \ + WMI_SHOW_INT(_attr##_current_value, "%d\n", _wmi); \ + static struct kobj_attribute attr_##_attr##_current_value =3D \ + __ASUS_ATTR_RW(_attr, current_value) + +/* Shows a formatted static variable */ +#define __ATTR_SHOW_FMT(_prop, _attrname, _fmt, _val) = \ + static ssize_t _attrname##_##_prop##_show( \ + struct kobject *kobj, struct kobj_attribute *attr, char *buf) \ + { \ + return sysfs_emit(buf, _fmt, _val); \ + } \ + static struct kobj_attribute attr_##_attrname##_##_prop =3D \ + __ASUS_ATTR_RO(_attrname, _prop) + +/* Boolean style enumeration, base macro. Requires adding show/store */ +#define __ATTR_GROUP_ENUM(_attrname, _fsname, _possible, _dispname) \ + __ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ + __ATTR_SHOW_FMT(possible_values, _attrname, "%s\n", _possible); \ + static struct kobj_attribute attr_##_attrname##_type =3D \ + __ASUS_ATTR_RO_AS(type, enum_type_show); \ + static struct attribute *_attrname##_attrs[] =3D { \ + &attr_##_attrname##_current_value.attr, \ + &attr_##_attrname##_display_name.attr, \ + &attr_##_attrname##_possible_values.attr, \ + &attr_##_attrname##_type.attr, \ + NULL \ + }; \ + static const struct attribute_group _attrname##_attr_group =3D { \ + .name =3D _fsname, .attrs =3D _attrname##_attrs \ + } + +#define ATTR_GROUP_BOOL_RO(_attrname, _fsname, _wmi, _dispname) \ + __ATTR_CURRENT_INT_RO(_attrname, _wmi); \ + __ATTR_GROUP_ENUM(_attrname, _fsname, "0;1", _dispname) + +#define ATTR_GROUP_BOOL_RW(_attrname, _fsname, _wmi, _dispname) \ + __ATTR_CURRENT_INT_RW(_attrname, 0, 1, _wmi); \ + __ATTR_GROUP_ENUM(_attrname, _fsname, "0;1", _dispname) + +/* + * Requires _current_value_show(), _current_value_show() + */ +#define ATTR_GROUP_BOOL_CUSTOM(_attrname, _fsname, _dispname) \ + static struct kobj_attribute attr_##_attrname##_current_value =3D \ + __ASUS_ATTR_RW(_attrname, current_value); \ + __ATTR_GROUP_ENUM(_attrname, _fsname, "0;1", _dispname) + +#define ATTR_GROUP_ENUM_INT_RO(_attrname, _fsname, _wmi, _possible, _dispn= ame) \ + __ATTR_CURRENT_INT_RO(_attrname, _wmi); \ + __ATTR_GROUP_ENUM(_attrname, _fsname, _possible, _dispname) + +/* + * Requires _current_value_show(), _current_value_show() + * and _possible_values_show() + */ +#define ATTR_GROUP_ENUM_CUSTOM(_attrname, _fsname, _dispname) \ + __ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ + static struct kobj_attribute attr_##_attrname##_current_value =3D \ + __ASUS_ATTR_RW(_attrname, current_value); \ + static struct kobj_attribute attr_##_attrname##_possible_values =3D \ + __ASUS_ATTR_RO(_attrname, possible_values); \ + static struct kobj_attribute attr_##_attrname##_type =3D \ + __ASUS_ATTR_RO_AS(type, enum_type_show); \ + static struct attribute *_attrname##_attrs[] =3D { \ + &attr_##_attrname##_current_value.attr, \ + &attr_##_attrname##_display_name.attr, \ + &attr_##_attrname##_possible_values.attr, \ + &attr_##_attrname##_type.attr, \ + NULL \ + }; \ + static const struct attribute_group _attrname##_attr_group =3D { \ + .name =3D _fsname, .attrs =3D _attrname##_attrs \ + } + +#endif /* _ASUS_BIOSCFG_H_ */ diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wm= i.c index 0a5221d65130..3c6d774f4453 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -55,8 +55,6 @@ module_param(fnlock_default, bool, 0444); #define to_asus_wmi_driver(pdrv) \ (container_of((pdrv), struct asus_wmi_driver, platform_driver)) =20 -#define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" - #define NOTIFY_BRNUP_MIN 0x11 #define NOTIFY_BRNUP_MAX 0x1f #define NOTIFY_BRNDOWN_MIN 0x20 @@ -105,8 +103,6 @@ module_param(fnlock_default, bool, 0444); #define USB_INTEL_XUSB2PR 0xD0 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI 0x9c31 =20 -#define ASUS_ACPI_UID_ASUSWMI "ASUSWMI" - #define WMI_EVENT_MASK 0xFFFF =20 #define FAN_CURVE_POINTS 8 diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index 6ea4dedfb85e..21313e1eb6c9 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -6,6 +6,9 @@ #include #include =20 +#define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" +#define ASUS_ACPI_UID_ASUSWMI "ASUSWMI" + /* WMI Methods */ #define ASUS_WMI_METHODID_SPEC 0x43455053 /* BIOS SPECification */ #define ASUS_WMI_METHODID_SFBD 0x44424653 /* Set First Boot Device */ --=20 2.46.1 From nobody Thu Nov 28 18:28:54 2024 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 70DEA44384; Mon, 30 Sep 2024 00:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654475; cv=none; b=bZZ58FszQhrqY7WfTItS2JYO4PQolugvUf5MwD71TvM2DMBnZz65i4tEtKBDiCxMHxmkD16j7uaIudl9r0YU9F20WSRS9rH6rdzc7mDwg7uL1UraGOmVv9LyyTS/JX2fnkdCaLUJsFSQcdMH/cu5TQbI2p0AjOQ4C5HeMyNSCmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654475; c=relaxed/simple; bh=82Wqe26Vsx9+J8kEOWKWHyvigGJmH5htw8V3v+3qsmo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AqKzSl9ZEJiLY+oJQLM60MkzOQyt74ETiSsw9puQHc78AlhLyNIZczDVfIoRmrAEGUB8y7D6TEERvWFaEoAhtWXjsz2/0UyVuhP8ndZc4fU9+PcI+6ekaLuMQyb702lWzBLg1BY8HKOm7uZ5Xf5teHv659isQ7zgMsXcvjlBGt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=D8LzJtIt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Q0nfgqTK; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="D8LzJtIt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Q0nfgqTK" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 8F5DE1140146; Sun, 29 Sep 2024 20:01:12 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Sun, 29 Sep 2024 20:01:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1727654472; x= 1727740872; bh=2GYuXj9/jvSk1R9t1rgNi+1KuQU5o8cqDPb0TSdoYw0=; b=D 8LzJtItkIPYVR4mmknIT1FxFzKvOWBaSv5iV9RiWA84nPXxafdYK5zo0gczkcObs QF+eBtlJYv4wA9/60cf0q8CYWEbqjextahQ8o+shn0RrLY2H4TmF3JWXlHXvgjpO VQDRxE09uHD3weOw7fsu0b2E4VP0nJrS8icPUnn4ALKZRtVNIV1C4ga/I9ibUVu1 ntma/Fk+IULTsBMKZogAHm1gCoQQxpT4QHLNSQI/f8i6AS+TvRoVme9/Am6ol3ab /k8qTs8Gl1kaKzHoCOUk94PT/QQWvJ5dF+S1q7zhhPbWWxPCb824NpnqO/KrVJgS P7Aewr+Qa4eW8q75ceSsw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654472; x= 1727740872; bh=2GYuXj9/jvSk1R9t1rgNi+1KuQU5o8cqDPb0TSdoYw0=; b=Q 0nfgqTK6XhIxUhAgY/9GbDQNTQ3ty4to0+nD6b2P2fWZqWOTa5cZ21ev1qcAC6Oi Qc1QOkKd4R/hyi2JscBQg3bQ9jHBi5vhpuqGib8wMVC/Vonh1NTKVwis6a0GEbCx 8qjo7lUaXaT3ZIXaEBqntwoiHTCUwA7DzWn7LjSVQqWcYGTuWI7fUPhsDF/+HfcK AOGfo45cL1/Cjjtn1jKVVL9I4QjbK6YznMHaFC4gT8OXytI0qdM3QRDHK1A51Ivb ypuAJZKSMRGsiC4ZNezMBpO0TdxEVunPWtu/NKBjJWsTu0Tvla2bwA+ZHGJSKSM7 nCDgcJt+Xojkqdra3i9Pw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhjohhnvghsrd guvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugffgleeltedv veethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghvpdhnsggprhgtphhtthho pedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqihhnphhu thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjihhkohhssehkvghrnh gvlhdrohhrghdprhgtphhtthhopehplhgrthhfohhrmhdqughrihhvvghrqdigkeeisehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihhlphhordhjrghrvhhinhgvnh eslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehhuggvghhovgguvgesrhgv ughhrghtrdgtohhmpdhrtghpthhtoheptghorhgvnhhtihhnrdgthhgrrhihsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhuphgvrhhmudeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:01:08 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" , Mario Limonciello Subject: [PATCH v6 4/9] platform/x86: asus-armoury: add panel_hd_mode attribute Date: Mon, 30 Sep 2024 13:00:41 +1300 Message-ID: <20240930000046.51388-5-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add panel_hd_mode to toggle the panel mode between single and high definition modes. Signed-off-by: Luke D. Jones Reviewed-by: Mario Limonciello --- drivers/platform/x86/asus-armoury.c | 6 +++++- include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asu= s-armoury.c index 0085f1b112ab..a4a615dc919b 100644 --- a/drivers/platform/x86/asus-armoury.c +++ b/drivers/platform/x86/asus-armoury.c @@ -106,7 +106,8 @@ static struct kobj_attribute pending_reboot =3D __ATTR_= RO(pending_reboot); =20 static bool asus_bios_requires_reboot(struct kobj_attribute *attr) { - return !strcmp(attr->attr.name, "gpu_mux_mode"); + return !strcmp(attr->attr.name, "gpu_mux_mode") || + !strcmp(attr->attr.name, "panel_hd_mode"); } =20 /** @@ -439,6 +440,8 @@ ATTR_GROUP_BOOL_RW(mcu_powersave, "mcu_powersave", ASUS= _WMI_DEVID_MCU_POWERSAVE, "Set MCU powersaving mode"); ATTR_GROUP_BOOL_RW(panel_od, "panel_overdrive", ASUS_WMI_DEVID_PANEL_OD, "Set the panel refresh overdrive"); +ATTR_GROUP_BOOL_RW(panel_hd_mode, "panel_hd_mode", ASUS_WMI_DEVID_PANEL_HD, + "Set the panel HD mode to UHD<0> or FHD<1>"); ATTR_GROUP_BOOL_RO(egpu_connected, "egpu_connected", ASUS_WMI_DEVID_EGPU_C= ONNECTED, "Show the eGPU connection status"); =20 @@ -452,6 +455,7 @@ static const struct asus_attr_group armoury_attr_groups= [] =3D { { &boot_sound_attr_group, ASUS_WMI_DEVID_BOOT_SOUND }, { &mcu_powersave_attr_group, ASUS_WMI_DEVID_MCU_POWERSAVE }, { &panel_od_attr_group, ASUS_WMI_DEVID_PANEL_OD }, + { &panel_hd_mode_attr_group, ASUS_WMI_DEVID_PANEL_HD }, }; =20 static int asus_fw_attr_add(void) diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index 21313e1eb6c9..a6064995c2cc 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -76,6 +76,7 @@ #define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY_VIVO 0x00110019 =20 /* Misc */ +#define ASUS_WMI_DEVID_PANEL_HD 0x0005001C #define ASUS_WMI_DEVID_PANEL_OD 0x00050019 #define ASUS_WMI_DEVID_CAMERA 0x00060013 #define ASUS_WMI_DEVID_LID_FLIP 0x00060062 --=20 2.46.1 From nobody Thu Nov 28 18:28:54 2024 Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (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 095C217C9B9; Mon, 30 Sep 2024 00:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654480; cv=none; b=kHN1rKHazdCNHIuSsFbvzlSSXJTWOV4HduQSII8Xs7TYazoXFP4QP3+ofe+lCdO3v+8BjWLQv0FTm956gjxNzbxOkRoGynRkUY7gRTc3UoO9dH9iNeL1QNNu376ZuQrNTwDGdnb9N390ZciiWKiobsXkD3wjYpzt6PFeuZ7md+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654480; c=relaxed/simple; bh=su0kdUEJQrLb4YK4prpMn2wOTv7kjfrb9d+D3+oA3Xo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CnvyJmtXH/pr+K64cDh8C2ZqYhONUDUa67nhQ3LetfxhzDbvuQ36L9b4xs106nLqp1a+MVTtpqo9KoDWcczsWU8GZJYJFriEut9zBL5i5WdjTD+yiIjuwg+/4Lp232E3AeJikzP456VcavzbxDDU0L9loRyp7NrPUWgM7j2wFcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=IMx6blrt; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=B5HyY3Ds; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="IMx6blrt"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="B5HyY3Ds" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id 10BBE13800E0; Sun, 29 Sep 2024 20:01:17 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Sun, 29 Sep 2024 20:01:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1727654477; x= 1727740877; bh=rhiAwUxFfMYJ6F7lswNn5sS1IPORUos4cIPRSYH4iTg=; b=I Mx6blrtuwn976cmHvf2XW+w5rQido+eymgSaP7kirGLWqI2KBLFmQBKRd7d2Dl12 UZxrG1B87MrMHOZLiiqGx6pDkIGHIYU+jBeIcnBGdsYmb37o3OataF4xZYhiPvqV dVsBXFApN4VoN4zP6WiRZKIROyfr8yoJBtxNTgHfJsbdcc/5eS+zF7odKGUunn2o bMuWVxbF8HtzRJm13vcMhWj2LEmLO8CyZsixk51SxB9HgMkGIkaD5J/nMbvu2qar BAGfV4OhKn14ZMhSyKyEXF/H7TTCCE1rFUlrWPnfgQSMoc4WYXW+jUxzx/JECbIi TigUqeRIsK/CJtHoAt1+g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654477; x= 1727740877; bh=rhiAwUxFfMYJ6F7lswNn5sS1IPORUos4cIPRSYH4iTg=; b=B 5HyY3Ds8BSk7SyBpuLGy8I/wmdeyAL5ZxVHqVekdAOB2pN3s+4ps9yfErsiZVSZK kgepNqNqGhrgpLZhQQXKDUcK/1EVwPEwudEwhe0zK2T+lzHrWEHc0RDE0B4CpsF9 3DgGDLuK8GvrLeVdbmbVvXra2s6OUiCNhRl+At/z6EsdsoFMZUiySnqkoD65Btcq qo1uRI0b/DBkpk4hjVWtE7eoImIGZSfODSX36WtYiI1fSBLuudl5LTIBPHYDlt8v 3eT0K3rzCl13uU5ZR8Yg4le+0MKiU/YF0nIfbkNWsaGaMLjwXq1phYwdnOfVQYA2 MQKX+1Z0kOt+6GgSr4j8A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhjohhnvghsrd guvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugffgleeltedv veethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmh epmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghvpdhnsggprhgtphhtthho pedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqihhnphhu thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjihhkohhssehkvghrnh gvlhdrohhrghdprhgtphhtthhopehplhgrthhfohhrmhdqughrihhvvghrqdigkeeisehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihhlphhordhjrghrvhhinhgvnh eslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehhuggvghhovgguvgesrhgv ughhrghtrdgtohhmpdhrtghpthhtoheptghorhgvnhhtihhnrdgthhgrrhihsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhuphgvrhhmudeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:01:12 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" , Mario Limonciello Subject: [PATCH v6 5/9] platform/x86: asus-armoury: add the ppt_* and nv_* tuning knobs Date: Mon, 30 Sep 2024 13:00:42 +1300 Message-ID: <20240930000046.51388-6-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds the ppt_* and nv_* tuning knobs that are available via WMI methods and adds proper min/max levels plus defaults. Signed-off-by: Luke D. Jones Reviewed-by: Mario Limonciello --- drivers/platform/x86/asus-armoury.c | 134 ++++++++++++++++++++++++++++ drivers/platform/x86/asus-armoury.h | 65 ++++++++++++++ 2 files changed, 199 insertions(+) diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asu= s-armoury.c index a4a615dc919b..192c60bb1091 100644 --- a/drivers/platform/x86/asus-armoury.c +++ b/drivers/platform/x86/asus-armoury.c @@ -52,12 +52,40 @@ #define PPT_PLATFORM_MAX 100 #define PPT_PLATFORM_DEFAULT 80 =20 +/* Tunables provided by ASUS for gaming laptops */ +struct rog_tunables { + u32 cpu_default; + u32 cpu_min; + u32 cpu_max; + + u32 platform_default; + u32 platform_min; + u32 platform_max; + + u32 ppt_pl1_spl; // cpu + u32 ppt_pl2_sppt; // cpu + u32 ppt_apu_sppt; // plat + u32 ppt_platform_sppt; // plat + u32 ppt_fppt; // cpu + + u32 nv_boost_default; + u32 nv_boost_min; + u32 nv_boost_max; + u32 nv_dynamic_boost; + + u32 nv_temp_default; + u32 nv_temp_min; + u32 nv_temp_max; + u32 nv_temp_target; +}; + static const struct class *fw_attr_class; =20 struct asus_armoury_priv { struct device *fw_attr_dev; struct kset *fw_attr_kset; =20 + struct rog_tunables *rog_tunables; u32 mini_led_dev_id; u32 gpu_mux_dev_id; =20 @@ -431,6 +459,25 @@ WMI_SHOW_INT(egpu_enable_current_value, "%d\n", ASUS_W= MI_DEVID_EGPU); ATTR_GROUP_BOOL_CUSTOM(egpu_enable, "egpu_enable", "Enable the eGPU (also = disables dGPU)"); =20 /* Simple attribute creation */ +ATTR_GROUP_ROG_TUNABLE(ppt_pl1_spl, "ppt_pl1_spl", ASUS_WMI_DEVID_PPT_PL1_= SPL, cpu_default, + cpu_min, cpu_max, 1, "Set the CPU slow package limit"); +ATTR_GROUP_ROG_TUNABLE(ppt_pl2_sppt, "ppt_pl2_sppt", ASUS_WMI_DEVID_PPT_PL= 2_SPPT, cpu_default, + cpu_min, cpu_max, 1, "Set the CPU fast package limit"); +ATTR_GROUP_ROG_TUNABLE(ppt_apu_sppt, "ppt_apu_sppt", ASUS_WMI_DEVID_PPT_AP= U_SPPT, + platform_default, platform_min, platform_max, 1, + "Set the CPU slow package limit"); +ATTR_GROUP_ROG_TUNABLE(ppt_platform_sppt, "ppt_platform_sppt", ASUS_WMI_DE= VID_PPT_PLAT_SPPT, + platform_default, platform_min, platform_max, 1, + "Set the CPU slow package limit"); +ATTR_GROUP_ROG_TUNABLE(ppt_fppt, "ppt_fppt", ASUS_WMI_DEVID_PPT_FPPT, cpu_= default, cpu_min, + cpu_max, 1, "Set the CPU slow package limit"); +ATTR_GROUP_ROG_TUNABLE(nv_dynamic_boost, "nv_dynamic_boost", ASUS_WMI_DEVI= D_NV_DYN_BOOST, + nv_boost_default, nv_boost_min, nv_boost_max, 1, + "Set the Nvidia dynamic boost limit"); +ATTR_GROUP_ROG_TUNABLE(nv_temp_target, "nv_temp_target", ASUS_WMI_DEVID_NV= _THERM_TARGET, + nv_temp_default, nv_boost_min, nv_temp_max, 1, + "Set the Nvidia max thermal limit"); + ATTR_GROUP_ENUM_INT_RO(charge_mode, "charge_mode", ASUS_WMI_DEVID_CHARGE_M= ODE, "0;1;2", "Show the current mode of charging"); =20 @@ -451,6 +498,14 @@ static const struct asus_attr_group armoury_attr_group= s[] =3D { { &egpu_enable_attr_group, ASUS_WMI_DEVID_EGPU }, { &dgpu_disable_attr_group, ASUS_WMI_DEVID_DGPU }, =20 + { &ppt_pl1_spl_attr_group, ASUS_WMI_DEVID_PPT_PL1_SPL }, + { &ppt_pl2_sppt_attr_group, ASUS_WMI_DEVID_PPT_PL2_SPPT }, + { &ppt_apu_sppt_attr_group, ASUS_WMI_DEVID_PPT_APU_SPPT }, + { &ppt_platform_sppt_attr_group, ASUS_WMI_DEVID_PPT_PLAT_SPPT }, + { &ppt_fppt_attr_group, ASUS_WMI_DEVID_PPT_FPPT }, + { &nv_dynamic_boost_attr_group, ASUS_WMI_DEVID_NV_DYN_BOOST }, + { &nv_temp_target_attr_group, ASUS_WMI_DEVID_NV_THERM_TARGET }, + { &charge_mode_attr_group, ASUS_WMI_DEVID_CHARGE_MODE }, { &boot_sound_attr_group, ASUS_WMI_DEVID_BOOT_SOUND }, { &mcu_powersave_attr_group, ASUS_WMI_DEVID_MCU_POWERSAVE }, @@ -552,6 +607,79 @@ static int asus_fw_attr_add(void) =20 /* Init / exit ***********************************************************= *****/ =20 +/* Set up the min/max and defaults for ROG tunables */ +static void init_rog_tunables(struct rog_tunables *rog) +{ + u32 platform_default =3D PPT_PLATFORM_DEFAULT; + u32 cpu_default =3D PPT_CPU_LIMIT_DEFAULT; + u32 platform_max =3D PPT_PLATFORM_MAX; + u32 max_boost =3D NVIDIA_BOOST_MAX; + u32 cpu_max =3D PPT_CPU_LIMIT_MAX; + const char *product; + + /* + * ASUS product_name contains everything required, e.g, + * "ROG Flow X16 GV601VV_GV601VV_00185149B". + * The bulk of these defaults are gained from users reporting what + * ASUS Armoury Crate in Windows provides them. + */ + product =3D dmi_get_system_info(DMI_PRODUCT_NAME); + + if (strstr(product, "GA402R")) { + cpu_default =3D 125; + } else if (strstr(product, "13QY")) { + cpu_max =3D 250; + } else if (strstr(product, "X13")) { + cpu_max =3D 75; + cpu_default =3D 50; + } else if (strstr(product, "RC71") || strstr(product, "RC72")) { + cpu_max =3D 50; + cpu_default =3D 30; + } else if (strstr(product, "G814") || strstr(product, "G614") || + strstr(product, "G834") || strstr(product, "G634")) { + cpu_max =3D 175; + } else if (strstr(product, "GA402X") || strstr(product, "GA403") || + strstr(product, "FA507N") || strstr(product, "FA507X") || + strstr(product, "FA707N") || strstr(product, "FA707X")) { + cpu_max =3D 90; + } else { + pr_notice("Using default CPU limits. Please report if these are not corr= ect.\n"); + } + + if (strstr(product, "GZ301ZE")) + max_boost =3D 5; + else if (strstr(product, "FX507ZC4")) + max_boost =3D 15; + else if (strstr(product, "GU605")) + max_boost =3D 20; + + /* ensure defaults for tunables */ + rog->cpu_default =3D cpu_default; + rog->cpu_min =3D PPT_CPU_LIMIT_MIN; + rog->cpu_max =3D cpu_max; + + rog->platform_default =3D platform_default; + rog->platform_max =3D PPT_PLATFORM_MIN; + rog->platform_max =3D platform_max; + + rog->ppt_pl1_spl =3D cpu_default; + rog->ppt_pl2_sppt =3D cpu_default; + rog->ppt_apu_sppt =3D cpu_default; + + rog->ppt_platform_sppt =3D platform_default; + rog->ppt_fppt =3D cpu_default; + + rog->nv_boost_default =3D NVIDIA_BOOST_MAX; + rog->nv_boost_max =3D NVIDIA_BOOST_MIN; + rog->nv_boost_max =3D max_boost; + rog->nv_dynamic_boost =3D NVIDIA_BOOST_MIN; + + rog->nv_temp_default =3D NVIDIA_TEMP_MAX; + rog->nv_temp_max =3D NVIDIA_TEMP_MIN; + rog->nv_temp_max =3D NVIDIA_TEMP_MAX; + rog->nv_temp_target =3D NVIDIA_TEMP_MIN; +} + static int __init asus_fw_init(void) { char *wmi_uid; @@ -568,6 +696,12 @@ static int __init asus_fw_init(void) if (!strcmp(wmi_uid, ASUS_ACPI_UID_ASUSWMI)) return -ENODEV; =20 + asus_armoury.rog_tunables =3D kzalloc(sizeof(struct rog_tunables), GFP_KE= RNEL); + if (!asus_armoury.rog_tunables) + return -ENOMEM; + + init_rog_tunables(asus_armoury.rog_tunables); + err =3D asus_fw_attr_add(); if (err) return err; diff --git a/drivers/platform/x86/asus-armoury.h b/drivers/platform/x86/asu= s-armoury.h index 4d0dd34c52aa..ca570ed9c8ef 100644 --- a/drivers/platform/x86/asus-armoury.h +++ b/drivers/platform/x86/asus-armoury.h @@ -17,6 +17,12 @@ static ssize_t attr_int_store(struct kobject *kobj, stru= ct kobj_attribute *attr, const char *buf, size_t count, u32 min, u32 max, u32 *store_value, u32 wmi_dev); =20 +static ssize_t int_type_show(struct kobject *kobj, struct kobj_attribute *= attr, + char *buf) +{ + return sysfs_emit(buf, "integer\n"); +} + static ssize_t enum_type_show(struct kobject *kobj, struct kobj_attribute = *attr, char *buf) { @@ -143,4 +149,63 @@ static ssize_t enum_type_show(struct kobject *kobj, st= ruct kobj_attribute *attr, .name =3D _fsname, .attrs =3D _attrname##_attrs \ } =20 +/* + * ROG PPT attributes need a little different in setup as they + * require rog_tunables members. + */ + +#define __ROG_TUNABLE_RW(_attr, _min, _max, _wmi) = \ + static ssize_t _attr##_current_value_store( \ + struct kobject *kobj, struct kobj_attribute *attr, \ + const char *buf, size_t count) \ + { \ + return attr_int_store(kobj, attr, buf, count, \ + asus_armoury.rog_tunables->_min, \ + asus_armoury.rog_tunables->_max, \ + &asus_armoury.rog_tunables->_attr, \ + _wmi); \ + } \ + static ssize_t _attr##_current_value_show( \ + struct kobject *kobj, struct kobj_attribute *attr, char *buf) \ + { \ + return sysfs_emit(buf, "%u\n", \ + asus_armoury.rog_tunables->_attr); \ + } \ + static struct kobj_attribute attr_##_attr##_current_value =3D \ + __ASUS_ATTR_RW(_attr, current_value) + +#define __ROG_TUNABLE_SHOW(_prop, _attrname, _val) = \ + static ssize_t _attrname##_##_prop##_show( \ + struct kobject *kobj, struct kobj_attribute *attr, char *buf) \ + { \ + return sysfs_emit(buf, "%d\n", \ + asus_armoury.rog_tunables->_val); \ + } \ + static struct kobj_attribute attr_##_attrname##_##_prop =3D \ + __ASUS_ATTR_RO(_attrname, _prop) + +#define ATTR_GROUP_ROG_TUNABLE(_attrname, _fsname, _wmi, _default, _min, _= max, \ + _incstep, _dispname) \ + __ROG_TUNABLE_SHOW(default_value, _attrname, _default); \ + __ROG_TUNABLE_RW(_attrname, _min, _max, _wmi); \ + __ROG_TUNABLE_SHOW(min_value, _attrname, _min); \ + __ROG_TUNABLE_SHOW(max_value, _attrname, _max); \ + __ATTR_SHOW_FMT(scalar_increment, _attrname, "%d\n", _incstep); \ + __ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ + static struct kobj_attribute attr_##_attrname##_type =3D \ + __ASUS_ATTR_RO_AS(type, int_type_show); \ + static struct attribute *_attrname##_attrs[] =3D { \ + &attr_##_attrname##_current_value.attr, \ + &attr_##_attrname##_default_value.attr, \ + &attr_##_attrname##_min_value.attr, \ + &attr_##_attrname##_max_value.attr, \ + &attr_##_attrname##_scalar_increment.attr, \ + &attr_##_attrname##_display_name.attr, \ + &attr_##_attrname##_type.attr, \ + NULL \ + }; \ + static const struct attribute_group _attrname##_attr_group =3D { \ + .name =3D _fsname, .attrs =3D _attrname##_attrs \ + } + #endif /* _ASUS_BIOSCFG_H_ */ --=20 2.46.1 From nobody Thu Nov 28 18:28:54 2024 Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (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 21E49183098; Mon, 30 Sep 2024 00:01:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654483; cv=none; b=OKMYffgnbOpd+s6TFy/88T+5kOvAqoyew3DAzo03L4MP3+Q5+vtV0fjBRrpFlEe8Ko9lP0cOAaKGJP2vOeZsEoqEQ8Zi1QLMFV2PYH3Bj6TOlJ309+LfyOxe/Fle5XRBLsRBowlS5R0iGdRFEu9mmV7GKXVFaX/AydeksixS77k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654483; c=relaxed/simple; bh=bDzydaHh8wGaCM4bLuCOFS1cirJD7kfYBAGOYOrkdJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NpnbbT+6ULC1EAomqXAjSYZ/vf7uwn9PWTdhUY8ZRvC3r1eUTctr1IOC3vKSjUPJHNVf200c3GflVrWiOS4mxcF807d7xRtTR0VDAiWljL04FdHq6gKqCyR0F7ScCKGAohHuomghzv+CZTxEwY/wv+fIzeWYRAQoVHtjowD2rS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=GITi4BGq; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=VNiHEwpL; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="GITi4BGq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="VNiHEwpL" Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id 6E41D1380119; Sun, 29 Sep 2024 20:01:21 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-10.internal (MEProxy); Sun, 29 Sep 2024 20:01:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1727654481; x= 1727740881; bh=EnJ2FGuAi1StVRkfpdoYX7bnOKdXXE10ll29GgqAKz0=; b=G ITi4BGqWhwKp+Jw5nuZVPr2l94/RdrS7dgLUtt+RbTwRvYYYpzwFLokQ3q/xB31O mahOVGgrbvPmZns6byRjUpdaBY4TR7aRf/VTsDzw8S4y2tiQHf7Z6Db3Z+j7TcAK gGGzdmpp/QWhDEqUSsNhrZl1lL3V9F7ID/qaKVJko6T/9dXKU7F2h/PhEfpcUpb5 6hSN+IfPmr/AzzSMpf2NjupJgJuhZVBEbVZI0pjD4azUjzyn70Wu7ilGIn/hz820 bak1legmAkaSMoggqqI8tlmG6dOCNm1qYW/tifgkdJ7ksMbSTsNH7yqex19JNKtf cNYUQ1fg/mvRIaC0qxI8w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654481; x= 1727740881; bh=EnJ2FGuAi1StVRkfpdoYX7bnOKdXXE10ll29GgqAKz0=; b=V NiHEwpLxbnEZBEG0LhBf0/rljkYPxB0Y24vcLDMIDxfEqvHWWJQGxJ3c32v11M9/ ZInNXHEasWnNu+ywfUvUpXrt7uELfiYXFPsePmd5BCcethp9bfjV3W+yuvZuBLCB rOPEEA7AOVO+6gVfP+myZxJRbYtJ22brI3B2XDhEO2dKHh5bXnVMas2+BFs4HXyp p2lO7IZoBzpLCWeyC7onNLwnWTHrOhXyRAhO4upcBg4lVOL4oibb6YhCBb1LGgmo c/a9CizFLULSEvxiunffrQdnD541MMhltrBf+y/TsDdkzNbaeUFXy3CzTPfEbi4q oI6r33hXXdaNFBt2ONF8Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhjohhnvghsrd guvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugffgleeltedv veethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmh epmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghvpdhnsggprhgtphhtthho pedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqihhnphhu thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjihhkohhssehkvghrnh gvlhdrohhrghdprhgtphhtthhopehplhgrthhfohhrmhdqughrihhvvghrqdigkeeisehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihhlphhordhjrghrvhhinhgvnh eslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehhuggvghhovgguvgesrhgv ughhrghtrdgtohhmpdhrtghpthhtoheptghorhgvnhhtihhnrdgthhgrrhihsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhuphgvrhhmudeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:01:17 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" , Mario Limonciello Subject: [PATCH v6 6/9] platform/x86: asus-armoury: add dgpu tgp control Date: Mon, 30 Sep 2024 13:00:43 +1300 Message-ID: <20240930000046.51388-7-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the dgpu TGP control under the asus-armoury module using the fw_attributes class. Reviewed-by: Mario Limonciello Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-armoury.c | 21 +++++++++++++++++++++ drivers/platform/x86/asus-armoury.h | 18 ++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 +++ 3 files changed, 42 insertions(+) diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asu= s-armoury.c index 192c60bb1091..ac87b55a17b3 100644 --- a/drivers/platform/x86/asus-armoury.c +++ b/drivers/platform/x86/asus-armoury.c @@ -45,6 +45,9 @@ #define NVIDIA_BOOST_MAX 25 #define NVIDIA_TEMP_MIN 75 #define NVIDIA_TEMP_MAX 87 +#define NVIDIA_POWER_MIN 0 +#define NVIDIA_POWER_MAX 70 +#define NVIDIA_POWER_DEFAULT 70 #define PPT_CPU_LIMIT_MIN 5 #define PPT_CPU_LIMIT_MAX 150 #define PPT_CPU_LIMIT_DEFAULT 80 @@ -77,6 +80,11 @@ struct rog_tunables { u32 nv_temp_min; u32 nv_temp_max; u32 nv_temp_target; + + u32 dgpu_tgp_default; + u32 dgpu_tgp_min; + u32 dgpu_tgp_max; + u32 dgpu_tgp; }; =20 static const struct class *fw_attr_class; @@ -477,6 +485,12 @@ ATTR_GROUP_ROG_TUNABLE(nv_dynamic_boost, "nv_dynamic_b= oost", ASUS_WMI_DEVID_NV_D ATTR_GROUP_ROG_TUNABLE(nv_temp_target, "nv_temp_target", ASUS_WMI_DEVID_NV= _THERM_TARGET, nv_temp_default, nv_boost_min, nv_temp_max, 1, "Set the Nvidia max thermal limit"); +ATTR_GROUP_ROG_TUNABLE(dgpu_tgp, "dgpu_tgp", ASUS_WMI_DEVID_DGPU_SET_TGP, = dgpu_tgp_default, + dgpu_tgp_min, dgpu_tgp_max, 1, + "Set the additional TGP on top of the base TGP"); + +ATTR_GROUP_INT_VALUE_ONLY_RO(dgpu_base_tgp, "dgpu_base_tgp", ASUS_WMI_DEVI= D_DGPU_BASE_TGP, + "Read the base TGP value"); =20 ATTR_GROUP_ENUM_INT_RO(charge_mode, "charge_mode", ASUS_WMI_DEVID_CHARGE_M= ODE, "0;1;2", "Show the current mode of charging"); @@ -505,6 +519,8 @@ static const struct asus_attr_group armoury_attr_groups= [] =3D { { &ppt_fppt_attr_group, ASUS_WMI_DEVID_PPT_FPPT }, { &nv_dynamic_boost_attr_group, ASUS_WMI_DEVID_NV_DYN_BOOST }, { &nv_temp_target_attr_group, ASUS_WMI_DEVID_NV_THERM_TARGET }, + { &dgpu_base_tgp_attr_group, ASUS_WMI_DEVID_DGPU_BASE_TGP }, + { &dgpu_tgp_attr_group, ASUS_WMI_DEVID_DGPU_SET_TGP }, =20 { &charge_mode_attr_group, ASUS_WMI_DEVID_CHARGE_MODE }, { &boot_sound_attr_group, ASUS_WMI_DEVID_BOOT_SOUND }, @@ -678,6 +694,11 @@ static void init_rog_tunables(struct rog_tunables *rog) rog->nv_temp_max =3D NVIDIA_TEMP_MIN; rog->nv_temp_max =3D NVIDIA_TEMP_MAX; rog->nv_temp_target =3D NVIDIA_TEMP_MIN; + + rog->dgpu_tgp_default =3D NVIDIA_POWER_DEFAULT; + rog->dgpu_tgp_min =3D NVIDIA_POWER_MIN; + rog->dgpu_tgp_max =3D NVIDIA_POWER_MAX; + rog->dgpu_tgp =3D NVIDIA_POWER_MAX; } =20 static int __init asus_fw_init(void) diff --git a/drivers/platform/x86/asus-armoury.h b/drivers/platform/x86/asu= s-armoury.h index ca570ed9c8ef..e08459cad942 100644 --- a/drivers/platform/x86/asus-armoury.h +++ b/drivers/platform/x86/asus-armoury.h @@ -89,6 +89,20 @@ static ssize_t enum_type_show(struct kobject *kobj, stru= ct kobj_attribute *attr, static struct kobj_attribute attr_##_attrname##_##_prop =3D \ __ASUS_ATTR_RO(_attrname, _prop) =20 +/* Requires current_value_show */ +#define __ATTR_GROUP_INT_VALUE_ONLY(_attrname, _fsname, _dispname) \ + __ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ + static struct kobj_attribute attr_##_attrname##_type =3D \ + __ASUS_ATTR_RO_AS(type, int_type_show); \ + static struct attribute *_attrname##_attrs[] =3D { \ + &attr_##_attrname##_current_value.attr, \ + &attr_##_attrname##_display_name.attr, \ + &attr_##_attrname##_type.attr, NULL \ + }; \ + static const struct attribute_group _attrname##_attr_group =3D { \ + .name =3D _fsname, .attrs =3D _attrname##_attrs \ + } + /* Boolean style enumeration, base macro. Requires adding show/store */ #define __ATTR_GROUP_ENUM(_attrname, _fsname, _possible, _dispname) \ __ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ @@ -106,6 +120,10 @@ static ssize_t enum_type_show(struct kobject *kobj, st= ruct kobj_attribute *attr, .name =3D _fsname, .attrs =3D _attrname##_attrs \ } =20 +#define ATTR_GROUP_INT_VALUE_ONLY_RO(_attrname, _fsname, _wmi, _dispname) \ + __ATTR_CURRENT_INT_RO(_attrname, _wmi); \ + __ATTR_GROUP_INT_VALUE_ONLY(_attrname, _fsname, _dispname) + #define ATTR_GROUP_BOOL_RO(_attrname, _fsname, _wmi, _dispname) \ __ATTR_CURRENT_INT_RO(_attrname, _wmi); \ __ATTR_GROUP_ENUM(_attrname, _fsname, "0;1", _dispname) diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index a6064995c2cc..8c755799eb60 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -137,6 +137,9 @@ /* dgpu on/off */ #define ASUS_WMI_DEVID_DGPU 0x00090020 =20 +#define ASUS_WMI_DEVID_DGPU_BASE_TGP 0x00120099 +#define ASUS_WMI_DEVID_DGPU_SET_TGP 0x00120098 + /* gpu mux switch, 0 =3D dGPU, 1 =3D Optimus */ #define ASUS_WMI_DEVID_GPU_MUX 0x00090016 #define ASUS_WMI_DEVID_GPU_MUX_VIVO 0x00090026 --=20 2.46.1 From nobody Thu Nov 28 18:28:54 2024 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 A907015CD49; Mon, 30 Sep 2024 00:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654488; cv=none; b=dGqsGZm1QpiDZNmTjZRqRGoo5F5D4bBnToP9rqMnfrER8r22Jf5jGZl/GZp2oT/XS6RvHoIMwU1idTJGKcQ4ubGy8PfMAE90XrWIC1NcLDY8Bq6PMNHpRoZRywt1DnbViOJ95ts3rmiEYFN/T6zKus348MUNveS6V33HOX/vx+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654488; c=relaxed/simple; bh=FKfOLZUelv7OFJ8Jec472jmuOEQZr3iWagIjCP05wB8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t5A1mp1CYeJAYt++GbFQZhdImS3VQ715q3BVW5KircazLdeIwCSA4vYGY+Zq4/1FnWvtzF6aDm/XyyxrM696bxgxf7hkZhRh7jXGRoTcB+V1zLDootDLKA3N4PWzr+aR4qCuQutV29ktiRFeecD672LQ4/t23TilTfRXaunhqF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=LQR4lqgV; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=XZkFAsx0; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="LQR4lqgV"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XZkFAsx0" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id C65D511400B5; Sun, 29 Sep 2024 20:01:25 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Sun, 29 Sep 2024 20:01:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1727654485; x= 1727740885; bh=v96vpS5acrzMZ/XcBZTjpTQAEk0QenkXH0x5I5boXok=; b=L QR4lqgVKnqkjwVzoSVseqYCeJ5NuRDZXCnM46FBMgk7g9SAUaYF+JJQWj4455Hf1 c4qAB7nPxgu0I19J6f3t2uC5iy6mrFvdWO74PGcVxPBG9mU3xuZ51MYLRhf7/Ni+ opLPZxtTPkJSlrbISuaWYO979nD3wPV1iVIZGIzgDtc18covj2luDKNk4wfsqjwX N8JTZTG8kklb0gu0ikOZKGqCMJ/nrTIs9S92Ktzd778XBk1xHSXg6a2EOvUhZJ4b YqqdX/mJRyJs0XbGZmWi06P4JJwet/2qBovO6i0iq1CXxfHz15BJc2U90g2FgdTK gu0PGLSDazC/fWh37lE4g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654485; x= 1727740885; bh=v96vpS5acrzMZ/XcBZTjpTQAEk0QenkXH0x5I5boXok=; b=X ZkFAsx0yIt6wVaXHh+oMTpVaimvRtytDbuw8ffluPuRBE/9YkBN7+MQrhY6i39E9 9g0y1GnL1oTWhkb04X1VdZdf9OlYH9QPBMauu9rKg/RiuNtsqV7Jb9OihkjYhDNc AbD7CPNJ2K9qiPrvjd//ICv4lTkyuqIdxLMxEIu2pzJ5W3XS7CDDmGmjzUutEPDK 7UX4caRSjJn89GJl4JN09JSmSKeGhAdQEKv3zUGvYVXeRagy4tBgzCovsSSavdU4 goKlrhcwBIFOPJK1noG/VFCAo/h9/24XM/4oIDNuYb2BipSQuKGKPyd2h4F92fCC tnjqS3SY5IDqMtceMsn+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhjohhnvghsrd guvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugffgleeltedv veethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghvpdhnsggprhgtphhtthho pedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqihhnphhu thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjihhkohhssehkvghrnh gvlhdrohhrghdprhgtphhtthhopehplhgrthhfohhrmhdqughrihhvvghrqdigkeeisehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihhlphhordhjrghrvhhinhgvnh eslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehhuggvghhovgguvgesrhgv ughhrghtrdgtohhmpdhrtghpthhtoheptghorhgvnhhtihhnrdgthhgrrhihsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhuphgvrhhmudeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:01:21 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" , Mario Limonciello Subject: [PATCH v6 7/9] platform/x86: asus-armoury: add apu-mem control support Date: Mon, 30 Sep 2024 13:00:44 +1300 Message-ID: <20240930000046.51388-8-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the APU memory size control under the asus-armoury module using the fw_attributes class. This allows the APU allocated memory size to be adjusted depending on the users priority. A reboot is required after change. Signed-off-by: Luke D. Jones Reviewed-by: Mario Limonciello --- drivers/platform/x86/asus-armoury.c | 114 +++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 1 + 2 files changed, 115 insertions(+) diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asu= s-armoury.c index ac87b55a17b3..09e0cbf24f25 100644 --- a/drivers/platform/x86/asus-armoury.c +++ b/drivers/platform/x86/asus-armoury.c @@ -466,6 +466,119 @@ static ssize_t egpu_enable_current_value_store(struct= kobject *kobj, struct kobj WMI_SHOW_INT(egpu_enable_current_value, "%d\n", ASUS_WMI_DEVID_EGPU); ATTR_GROUP_BOOL_CUSTOM(egpu_enable, "egpu_enable", "Enable the eGPU (also = disables dGPU)"); =20 +/* Device memory available to APU */ + +static ssize_t apu_mem_current_value_show(struct kobject *kobj, struct kob= j_attribute *attr, + char *buf) +{ + int err; + u32 mem; + + err =3D asus_wmi_get_devstate_dsts(ASUS_WMI_DEVID_APU_MEM, &mem); + if (err) + return err; + + switch (mem) { + case 0x100: + mem =3D 0; + break; + case 0x102: + mem =3D 1; + break; + case 0x103: + mem =3D 2; + break; + case 0x104: + mem =3D 3; + break; + case 0x105: + mem =3D 4; + break; + case 0x106: + /* This is out of order and looks wrong but is correct */ + mem =3D 8; + break; + case 0x107: + mem =3D 5; + break; + case 0x108: + mem =3D 6; + break; + case 0x109: + mem =3D 7; + break; + default: + mem =3D 4; + break; + } + + return sysfs_emit(buf, "%u\n", mem); +} + +static ssize_t apu_mem_current_value_store(struct kobject *kobj, struct ko= bj_attribute *attr, + const char *buf, size_t count) +{ + int result, err; + u32 requested, mem; + + result =3D kstrtou32(buf, 10, &requested); + if (result) + return result; + + switch (requested) { + case 0: + mem =3D 0x000; + break; + case 1: + mem =3D 0x102; + break; + case 2: + mem =3D 0x103; + break; + case 3: + mem =3D 0x104; + break; + case 4: + mem =3D 0x105; + break; + case 5: + mem =3D 0x107; + break; + case 6: + mem =3D 0x108; + break; + case 7: + mem =3D 0x109; + break; + case 8: + /* This is out of order and looks wrong but is correct */ + mem =3D 0x106; + break; + default: + return -EIO; + } + + err =3D asus_wmi_set_devstate(ASUS_WMI_DEVID_APU_MEM, mem, &result); + if (err) { + pr_warn("Failed to set apu_mem: %d\n", err); + return err; + } + + pr_info("APU memory changed to %uGB, reboot required\n", requested); + sysfs_notify(kobj, NULL, attr->attr.name); + + asus_set_reboot_and_signal_event(); + + return count; +} + +static ssize_t apu_mem_possible_values_show(struct kobject *kobj, struct k= obj_attribute *attr, + char *buf) +{ + return sysfs_emit(buf, "0;1;2;3;4;5;6;7;8\n"); +} +ATTR_GROUP_ENUM_CUSTOM(apu_mem, "apu_mem", "Set available system RAM (in G= B) for the APU to use"); + /* Simple attribute creation */ ATTR_GROUP_ROG_TUNABLE(ppt_pl1_spl, "ppt_pl1_spl", ASUS_WMI_DEVID_PPT_PL1_= SPL, cpu_default, cpu_min, cpu_max, 1, "Set the CPU slow package limit"); @@ -521,6 +634,7 @@ static const struct asus_attr_group armoury_attr_groups= [] =3D { { &nv_temp_target_attr_group, ASUS_WMI_DEVID_NV_THERM_TARGET }, { &dgpu_base_tgp_attr_group, ASUS_WMI_DEVID_DGPU_BASE_TGP }, { &dgpu_tgp_attr_group, ASUS_WMI_DEVID_DGPU_SET_TGP }, + { &apu_mem_attr_group, ASUS_WMI_DEVID_APU_MEM }, =20 { &charge_mode_attr_group, ASUS_WMI_DEVID_CHARGE_MODE }, { &boot_sound_attr_group, ASUS_WMI_DEVID_BOOT_SOUND }, diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index 8c755799eb60..88bf250dc8ca 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -139,6 +139,7 @@ =20 #define ASUS_WMI_DEVID_DGPU_BASE_TGP 0x00120099 #define ASUS_WMI_DEVID_DGPU_SET_TGP 0x00120098 +#define ASUS_WMI_DEVID_APU_MEM 0x000600C1 =20 /* gpu mux switch, 0 =3D dGPU, 1 =3D Optimus */ #define ASUS_WMI_DEVID_GPU_MUX 0x00090016 --=20 2.46.1 From nobody Thu Nov 28 18:28:54 2024 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (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 35DA918593C; Mon, 30 Sep 2024 00:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654493; cv=none; b=cdoORjN+/dtMl5ADp/BGu+7LSlMhQfkU5bwHeXqMIZnaXmwtYKt6IK2b0mpURU/Ir2N13Rua50xZqeMMRNJS0mB5J2c4BCPYGuv5LDcNS05MfzlOCi4yX+CFTkhg5qzf7L0zk7+CkGnqpoEb3GLfyQAHQzgiHv6GSzYSVs8OiVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654493; c=relaxed/simple; bh=xXI3PDfVdDtPZL5HC34qUkD1L93LnrcNZ+y5OrszdzQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P+xNA2+XRh/IXxf01/OoVelbVPxfmlzxioqRD/5lmEn16fC+S9agNZ3C/zlGizlx+zS/HleldXR41LcH+7UeYUhx1UxpIsOo02k32tMpCVx/EZ1hf4dNIJIza9VEMtRN+j6OF8n3uatIdUUdFncVuvxFlxtud1LiDQcCvL6B+h8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=wvM/GBTO; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SfxS/aXe; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="wvM/GBTO"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SfxS/aXe" Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 639F2114011F; Sun, 29 Sep 2024 20:01:30 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Sun, 29 Sep 2024 20:01:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1727654490; x= 1727740890; bh=JnLrLTqmj62lRbMnp/ziZZkcRPEozZ3C3ht9DTjWvfI=; b=w vM/GBTOKc16jDnj8bA+BvbjY5o70FWATKibJ5h6wMvKEQQhzT45c5oAJSltuT/lo 4DUNtQ2JkA98LfUHzuF3L/OsECVPYSs6yrgJYj/6rUZ4piTctdgRa0Y3t3GbioAT gJclqtFIuELm3eFMZrxL1Uw0C3hfqe8jpChcr1NXP8Yx5VI8ZxDdp6tOuXRyZj9i YkKYXsuwhff80HmH8n/+tP8wGPl6X8qK+5k7zsSzxF/BiVnAJ9WZ9MSleYNnqY/L QFoOyeP6EPH+ubeQ6ws0S9CvKFh011cIbT9INJ3RnZ0kbJt/PMbTXPYHCmc2Hq5O 1FUJJC71pkNRKHMs2kOhQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654490; x= 1727740890; bh=JnLrLTqmj62lRbMnp/ziZZkcRPEozZ3C3ht9DTjWvfI=; b=S fxS/aXeLcB8XhPV1ydJ2B4MaFQ1oWJGoTfuhoPiNw13tK3DTrbzCuD2dXTtj4/jx ZuBWXP5tpuE9J29NKMKPhFdcgeI0g+cRb/hTKr3omB7xEDmzbpUbadKDntKKtT/o v6VRZIL5Mgwd1J6/i53smmN5nMLfFzw1Q/twvsYtBy/6ISCd9qV2AMMDc8GXl/AX IAuM/yV/XW7DxGWsY9a/Bl1FiPwphDA3Eo1CZSXjD1x6Ol7dp9EZmRKb5xWAlQYV UBjpHw641/KwwR3o7U/YaXLngRX+aUCvlayi8modMsLsCkR3zHN/Ach7GlZgcO17 D2jh+wElrNpyY9GIdtI1Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhjohhnvghsrd guvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugffgleeltedv veethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghvpdhnsggprhgtphhtthho pedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqihhnphhu thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjihhkohhssehkvghrnh gvlhdrohhrghdprhgtphhtthhopehplhgrthhfohhrmhdqughrihhvvghrqdigkeeisehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihhlphhordhjrghrvhhinhgvnh eslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehhuggvghhovgguvgesrhgv ughhrghtrdgtohhmpdhrtghpthhtoheptghorhgvnhhtihhnrdgthhgrrhihsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhuphgvrhhmudeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:01:26 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" , Mario Limonciello Subject: [PATCH v6 8/9] platform/x86: asus-armoury: add core count control Date: Mon, 30 Sep 2024 13:00:45 +1300 Message-ID: <20240930000046.51388-9-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement Intel core enablement under the asus-armoury module using the fw_attributes class. This allows users to enable or disable preformance or efficiency cores depending on their requirements. After change a reboot is required. Signed-off-by: Luke D. Jones Reviewed-by: Mario Limonciello --- drivers/platform/x86/asus-armoury.c | 227 +++++++++++++++++++++ drivers/platform/x86/asus-armoury.h | 28 +++ include/linux/platform_data/x86/asus-wmi.h | 4 + 3 files changed, 259 insertions(+) diff --git a/drivers/platform/x86/asus-armoury.c b/drivers/platform/x86/asu= s-armoury.c index 09e0cbf24f25..caaa55219946 100644 --- a/drivers/platform/x86/asus-armoury.c +++ b/drivers/platform/x86/asus-armoury.c @@ -40,6 +40,24 @@ #define ASUS_MINI_LED_2024_STRONG 0x01 #define ASUS_MINI_LED_2024_OFF 0x02 =20 +#define ASUS_POWER_CORE_MASK GENMASK(15, 8) +#define ASUS_PERF_CORE_MASK GENMASK(7, 0) + +enum cpu_core_type { + CPU_CORE_PERF =3D 0, + CPU_CORE_POWER, +}; + +enum cpu_core_value { + CPU_CORE_DEFAULT =3D 0, + CPU_CORE_MIN, + CPU_CORE_MAX, + CPU_CORE_CURRENT, +}; + +#define CPU_PERF_CORE_COUNT_MIN 4 +#define CPU_POWR_CORE_COUNT_MIN 0 + /* Default limits for tunables available on ASUS ROG laptops */ #define NVIDIA_BOOST_MIN 5 #define NVIDIA_BOOST_MAX 25 @@ -85,6 +103,13 @@ struct rog_tunables { u32 dgpu_tgp_min; u32 dgpu_tgp_max; u32 dgpu_tgp; + + u32 cur_perf_cores; + u32 min_perf_cores; + u32 max_perf_cores; + u32 cur_power_cores; + u32 min_power_cores; + u32 max_power_cores; }; =20 static const struct class *fw_attr_class; @@ -143,6 +168,8 @@ static struct kobj_attribute pending_reboot =3D __ATTR_= RO(pending_reboot); static bool asus_bios_requires_reboot(struct kobj_attribute *attr) { return !strcmp(attr->attr.name, "gpu_mux_mode") || + !strcmp(attr->attr.name, "cores_performance") || + !strcmp(attr->attr.name, "cores_efficiency") || !strcmp(attr->attr.name, "panel_hd_mode"); } =20 @@ -579,6 +606,200 @@ static ssize_t apu_mem_possible_values_show(struct ko= bject *kobj, struct kobj_at } ATTR_GROUP_ENUM_CUSTOM(apu_mem, "apu_mem", "Set available system RAM (in G= B) for the APU to use"); =20 +static int init_max_cpu_cores(void) +{ + u32 cores; + int err; + + if (!asus_wmi_is_present(ASUS_WMI_DEVID_CORES_MAX)) + return 0; + + + err =3D asus_wmi_get_devstate_dsts(ASUS_WMI_DEVID_CORES_MAX, &cores); + if (err) + return err; + + cores &=3D ~ASUS_WMI_DSTS_PRESENCE_BIT; + asus_armoury.rog_tunables->max_power_cores =3D FIELD_GET(ASUS_POWER_CORE_= MASK, cores); + asus_armoury.rog_tunables->max_perf_cores =3D FIELD_GET(ASUS_PERF_CORE_MA= SK, cores); + + cores =3D 0; + err =3D asus_wmi_get_devstate_dsts(ASUS_WMI_DEVID_CORES, &cores); + if (err) { + pr_err("Could not get CPU core count: error %d", err); + return err; + } + + asus_armoury.rog_tunables->cur_perf_cores =3D FIELD_GET(ASUS_PERF_CORE_MA= SK, cores); + asus_armoury.rog_tunables->cur_power_cores =3D FIELD_GET(ASUS_POWER_CORE_= MASK, cores); + + asus_armoury.rog_tunables->min_perf_cores =3D CPU_PERF_CORE_COUNT_MIN; + asus_armoury.rog_tunables->min_power_cores =3D CPU_POWR_CORE_COUNT_MIN; + + return 0; +} + +static ssize_t cores_value_show(struct kobject *kobj, struct kobj_attribut= e *attr, char *buf, + enum cpu_core_type core_type, enum cpu_core_value core_value) +{ + u32 cores; + + switch (core_value) { + case CPU_CORE_DEFAULT: + case CPU_CORE_MAX: + if (core_type =3D=3D CPU_CORE_PERF) + return sysfs_emit(buf, "%d\n", + asus_armoury.rog_tunables->max_perf_cores); + else + return sysfs_emit(buf, "%d\n", + asus_armoury.rog_tunables->max_power_cores); + case CPU_CORE_MIN: + if (core_type =3D=3D CPU_CORE_PERF) + return sysfs_emit(buf, "%d\n", + asus_armoury.rog_tunables->min_perf_cores); + else + return sysfs_emit(buf, "%d\n", + asus_armoury.rog_tunables->min_power_cores); + default: + break; + } + + if (core_type =3D=3D CPU_CORE_PERF) + cores =3D asus_armoury.rog_tunables->cur_perf_cores; + else + cores =3D asus_armoury.rog_tunables->cur_power_cores; + + return sysfs_emit(buf, "%d\n", cores); +} + +static ssize_t cores_current_value_store(struct kobject *kobj, struct kobj= _attribute *attr, + const char *buf, enum cpu_core_type core_type) +{ + int result, err; + u32 new_cores, perf_cores, powr_cores, out_val, min, max; + + result =3D kstrtou32(buf, 10, &new_cores); + if (result) + return result; + + if (core_type =3D=3D CPU_CORE_PERF) { + perf_cores =3D new_cores; + powr_cores =3D out_val =3D asus_armoury.rog_tunables->cur_power_cores; + min =3D asus_armoury.rog_tunables->min_perf_cores; + max =3D asus_armoury.rog_tunables->max_perf_cores; + } else { + perf_cores =3D asus_armoury.rog_tunables->cur_perf_cores; + powr_cores =3D out_val =3D new_cores; + min =3D asus_armoury.rog_tunables->min_power_cores; + max =3D asus_armoury.rog_tunables->max_power_cores; + } + + if (new_cores < min || new_cores > max) + return -EINVAL; + + out_val =3D 0; + out_val |=3D FIELD_PREP(ASUS_PERF_CORE_MASK, perf_cores); + out_val |=3D FIELD_PREP(ASUS_POWER_CORE_MASK, powr_cores); + + mutex_lock(&asus_armoury.mutex); + err =3D asus_wmi_set_devstate(ASUS_WMI_DEVID_CORES, out_val, &result); + mutex_unlock(&asus_armoury.mutex); + + if (err) { + pr_warn("Failed to set CPU core count: %d\n", err); + return err; + } + + if (result > 1) { + pr_warn("Failed to set CPU core count (result): 0x%x\n", result); + return -EIO; + } + + pr_info("CPU core count changed, reboot required\n"); + sysfs_notify(kobj, NULL, attr->attr.name); + asus_set_reboot_and_signal_event(); + + return 0; +} + +static ssize_t cores_performance_min_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return cores_value_show(kobj, attr, buf, CPU_CORE_PERF, CPU_CORE_MIN); +} + +static ssize_t cores_performance_max_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return cores_value_show(kobj, attr, buf, CPU_CORE_PERF, CPU_CORE_MAX); +} + +static ssize_t cores_performance_default_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return cores_value_show(kobj, attr, buf, CPU_CORE_PERF, CPU_CORE_DEFAULT); +} + +static ssize_t cores_performance_current_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return cores_value_show(kobj, attr, buf, CPU_CORE_PERF, CPU_CORE_CURRENT); +} + +static ssize_t cores_performance_current_value_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + + err =3D cores_current_value_store(kobj, attr, buf, CPU_CORE_PERF); + if (err) + return err; + + return count; +} +ATTR_GROUP_CORES_RW(cores_performance, "cores_performance", + "Set the max available performance cores"); + +static ssize_t cores_efficiency_min_value_show(struct kobject *kobj, struc= t kobj_attribute *attr, + char *buf) +{ + return cores_value_show(kobj, attr, buf, CPU_CORE_POWER, CPU_CORE_MIN); +} + +static ssize_t cores_efficiency_max_value_show(struct kobject *kobj, struc= t kobj_attribute *attr, + char *buf) +{ + return cores_value_show(kobj, attr, buf, CPU_CORE_POWER, CPU_CORE_MAX); +} + +static ssize_t cores_efficiency_default_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return cores_value_show(kobj, attr, buf, CPU_CORE_POWER, CPU_CORE_DEFAULT= ); +} + +static ssize_t cores_efficiency_current_value_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return cores_value_show(kobj, attr, buf, CPU_CORE_POWER, CPU_CORE_CURRENT= ); +} + +static ssize_t cores_efficiency_current_value_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, + size_t count) +{ + int err; + + err =3D cores_current_value_store(kobj, attr, buf, CPU_CORE_POWER); + if (err) + return err; + + return count; +} +ATTR_GROUP_CORES_RW(cores_efficiency, "cores_efficiency", + "Set the max available efficiency cores"); + /* Simple attribute creation */ ATTR_GROUP_ROG_TUNABLE(ppt_pl1_spl, "ppt_pl1_spl", ASUS_WMI_DEVID_PPT_PL1_= SPL, cpu_default, cpu_min, cpu_max, 1, "Set the CPU slow package limit"); @@ -635,6 +856,8 @@ static const struct asus_attr_group armoury_attr_groups= [] =3D { { &dgpu_base_tgp_attr_group, ASUS_WMI_DEVID_DGPU_BASE_TGP }, { &dgpu_tgp_attr_group, ASUS_WMI_DEVID_DGPU_SET_TGP }, { &apu_mem_attr_group, ASUS_WMI_DEVID_APU_MEM }, + { &cores_efficiency_attr_group, ASUS_WMI_DEVID_CORES_MAX }, + { &cores_performance_attr_group, ASUS_WMI_DEVID_CORES_MAX }, =20 { &charge_mode_attr_group, ASUS_WMI_DEVID_CHARGE_MODE }, { &boot_sound_attr_group, ASUS_WMI_DEVID_BOOT_SOUND }, @@ -752,6 +975,7 @@ static void init_rog_tunables(struct rog_tunables *rog) * "ROG Flow X16 GV601VV_GV601VV_00185149B". * The bulk of these defaults are gained from users reporting what * ASUS Armoury Crate in Windows provides them. + * This should be turned in to a tabe eventually. */ product =3D dmi_get_system_info(DMI_PRODUCT_NAME); =20 @@ -836,6 +1060,9 @@ static int __init asus_fw_init(void) return -ENOMEM; =20 init_rog_tunables(asus_armoury.rog_tunables); + err =3D init_max_cpu_cores(); + if (err) + return err; =20 err =3D asus_fw_attr_add(); if (err) diff --git a/drivers/platform/x86/asus-armoury.h b/drivers/platform/x86/asu= s-armoury.h index e08459cad942..04b88f7d2421 100644 --- a/drivers/platform/x86/asus-armoury.h +++ b/drivers/platform/x86/asus-armoury.h @@ -167,6 +167,34 @@ static ssize_t enum_type_show(struct kobject *kobj, st= ruct kobj_attribute *attr, .name =3D _fsname, .attrs =3D _attrname##_attrs \ } =20 +/* CPU core attributes need a little different in setup */ +#define ATTR_GROUP_CORES_RW(_attrname, _fsname, _dispname) \ + __ATTR_SHOW_FMT(scalar_increment, _attrname, "%d\n", 1); \ + __ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ + static struct kobj_attribute attr_##_attrname##_current_value =3D \ + __ASUS_ATTR_RW(_attrname, current_value); \ + static struct kobj_attribute attr_##_attrname##_default_value =3D \ + __ASUS_ATTR_RO(_attrname, default_value); \ + static struct kobj_attribute attr_##_attrname##_min_value =3D \ + __ASUS_ATTR_RO(_attrname, min_value); \ + static struct kobj_attribute attr_##_attrname##_max_value =3D \ + __ASUS_ATTR_RO(_attrname, max_value); \ + static struct kobj_attribute attr_##_attrname##_type =3D \ + __ASUS_ATTR_RO_AS(type, int_type_show); \ + static struct attribute *_attrname##_attrs[] =3D { \ + &attr_##_attrname##_current_value.attr, \ + &attr_##_attrname##_default_value.attr, \ + &attr_##_attrname##_min_value.attr, \ + &attr_##_attrname##_max_value.attr, \ + &attr_##_attrname##_scalar_increment.attr, \ + &attr_##_attrname##_display_name.attr, \ + &attr_##_attrname##_type.attr, \ + NULL \ + }; \ + static const struct attribute_group _attrname##_attr_group =3D { \ + .name =3D _fsname, .attrs =3D _attrname##_attrs \ + } + /* * ROG PPT attributes need a little different in setup as they * require rog_tunables members. diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index 88bf250dc8ca..cc21e4272460 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -137,6 +137,10 @@ /* dgpu on/off */ #define ASUS_WMI_DEVID_DGPU 0x00090020 =20 +/* Intel E-core and P-core configuration in a format 0x0[E]0[P] */ +#define ASUS_WMI_DEVID_CORES 0x001200D2 + /* Maximum Intel E-core and P-core availability */ +#define ASUS_WMI_DEVID_CORES_MAX 0x001200D3 #define ASUS_WMI_DEVID_DGPU_BASE_TGP 0x00120099 #define ASUS_WMI_DEVID_DGPU_SET_TGP 0x00120098 #define ASUS_WMI_DEVID_APU_MEM 0x000600C1 --=20 2.46.1 From nobody Thu Nov 28 18:28:54 2024 Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (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 BF9C13C24; Mon, 30 Sep 2024 00:01:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654497; cv=none; b=TxQMYS6srfIXcJIYK8QXxCAfdegbNMP6yJ6xyzwv2/yKjuTJm66jiKTsW47ldSRRccToEYui/Eh1I7zKQwCyIPyCUc9uOcwh0sNevKpcInUG1eVPEW3y9MfYDD+JW9zJM+g7+5lqdodUaFGBgcHYK2gZTYhvrZvBTlIsXeEDZ88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727654497; c=relaxed/simple; bh=46LW8KReDEp2cmxjXriEFh7L2tx+Fn0n84sjnLb4c68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y3SmXYwoWxf+Jo8FFPKnTeDd80XRr38lL4VZxA23vHW3grGXMOkSoQnoSvpLvoXsDfx9Shce0HOXaXpO3ADMPqN7f2yJul29Ype94d0trbIrXWQLB47I/CUvR2ND6ncz+TpS+tAVLCYBqFAFRy2veZXZPqlQi0BzhSeiwE/XZWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev; spf=none smtp.mailfrom=ljones.dev; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b=w0cFeLSz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gFPfTGcf; arc=none smtp.client-ip=103.168.172.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ljones.dev Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ljones.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ljones.dev header.i=@ljones.dev header.b="w0cFeLSz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gFPfTGcf" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id E7E591380145; Sun, 29 Sep 2024 20:01:34 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-08.internal (MEProxy); Sun, 29 Sep 2024 20:01:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1727654494; x= 1727740894; bh=J3pbvIucRMBjm9H2HB4JyEC704gjoDwQ9XdK9WrJ/bQ=; b=w 0cFeLSzB7ttfQdigFl7OGnE8EsAvIGjLIRxtzfqzzyowIRidGBl2jgsPyXsnAfiQ aH6S8y0mb6BIZnP9vBQl3hN1xrvqA37NRkcLM7Rd24Bpb2ul5xHffEZ5GhrnT4gu uhG2QqK3ITIhJaa+dN5kcjAuJ3utughYkSQxuN6eLljyDaVPv1QTuUnonP6QTpmM IO6PlTjPsiGJed2e5kKcALIL0x6x1lgAyU9mufNNHgCRUF1k5qB+sNijkPP8wNMP v35AJF64+h7TaSzkjLKu4vEIbF0Iq5ovPhNM3Fi/yTY/Wz812yT4TYPddewosDfO Ey7iSA8+iLQn2LL1/J+jw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1727654494; x= 1727740894; bh=J3pbvIucRMBjm9H2HB4JyEC704gjoDwQ9XdK9WrJ/bQ=; b=g FPfTGcfnQgOYg1YHg5lwMNqdvtMwoP1qQrZsQ/wI67msIfjkRnIRjmTDG2bzEMX6 54frvLXwqhBrD5Y5xIbp+UiGhWjNqdsysshI6avBhZLRSO2jzMmVEq/ZW7/g44nN s9F3N2NBihpd62C0j0Fy1kqMtPzyaBIqV1Nw3pkG/FqQ2i9swRxgHZnRMhNxq2Pl W/G8Ey3cU9MW/BrV1NMKtnO01j6qO9LDwFfbifxN9pMUvxRpP7+NdGJgnhMnP+sZ eRf8Vkh/KqWbSqHpODviHOTpk7b3eRSND//6TcgJmVbGwli8cypjbCLLVgwqMcDW rPkCU1jwLjpudyzlERXXQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddugedgfeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttden ucfhrhhomhepfdfnuhhkvgcuffdrucflohhnvghsfdcuoehluhhkvgeslhhjohhnvghsrd guvghvqeenucggtffrrghtthgvrhhnpefgteefudfgteduueehteejhfeugffgleeltedv veethfeuueejfedvgeelveehgfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmh epmhgrihhlfhhrohhmpehluhhkvgeslhhjohhnvghsrdguvghvpdhnsggprhgtphhtthho pedutddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqihhnphhu thesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehjihhkohhssehkvghrnh gvlhdrohhrghdprhgtphhtthhopehplhgrthhfohhrmhdqughrihhvvghrqdigkeeisehv ghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihhlphhordhjrghrvhhinhgvnh eslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehhuggvghhovgguvgesrhgv ughhrghtrdgtohhmpdhrtghpthhtoheptghorhgvnhhtihhnrdgthhgrrhihsehgmhgrih hlrdgtohhmpdhrtghpthhtohepshhuphgvrhhmudeskhgvrhhnvghlrdhorhhgpdhrtghp thhtoheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 Sep 2024 20:01:30 -0400 (EDT) From: "Luke D. Jones" To: linux-kernel@vger.kernel.org Cc: linux-input@vger.kernel.org, jikos@kernel.org, platform-driver-x86@vger.kernel.org, ilpo.jarvinen@linux.intel.com, hdegoede@redhat.com, corentin.chary@gmail.com, superm1@kernel.org, "Luke D. Jones" , Mario Limonciello Subject: [PATCH v6 9/9] platform/x86: asus-wmi: deprecate bios features Date: Mon, 30 Sep 2024 13:00:46 +1300 Message-ID: <20240930000046.51388-10-luke@ljones.dev> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930000046.51388-1-luke@ljones.dev> References: <20240930000046.51388-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With the existence of the asus-armoury module the attributes no-longer need to live under the /sys/devices/platform/asus-nb-wmi/ path. Deprecate all those that were implemented in asus-bioscfg with the goal of removing them fully in the next LTS cycle. Signed-off-by: Luke D. Jones Reviewed-by: Mario Limonciello --- .../ABI/testing/sysfs-platform-asus-wmi | 17 +++ drivers/platform/x86/Kconfig | 9 ++ drivers/platform/x86/asus-wmi.c | 134 ++++++++++++++---- 3 files changed, 130 insertions(+), 30 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentat= ion/ABI/testing/sysfs-platform-asus-wmi index 28144371a0f1..765d50b0d9df 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -63,6 +63,7 @@ Date: Aug 2022 KernelVersion: 6.1 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Switch the GPU hardware MUX mode. Laptops with this feature can can be toggled to boot with only the dGPU (discrete mode) or in standard Optimus/Hybrid mode. On switch a reboot is required: @@ -75,6 +76,7 @@ Date: Aug 2022 KernelVersion: 5.17 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Disable discrete GPU: * 0 - Enable dGPU, * 1 - Disable dGPU @@ -84,6 +86,7 @@ Date: Aug 2022 KernelVersion: 5.17 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Enable the external GPU paired with ROG X-Flow laptops. Toggling this setting will also trigger ACPI to disable the dGPU: =20 @@ -95,6 +98,7 @@ Date: Aug 2022 KernelVersion: 5.17 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Enable an LCD response-time boost to reduce or remove ghosting: * 0 - Disable, * 1 - Enable @@ -104,6 +108,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Get the current charging mode being used: * 1 - Barrel connected charger, * 2 - USB-C charging @@ -114,6 +119,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Show if the egpu (XG Mobile) is correctly connected: * 0 - False, * 1 - True @@ -123,6 +129,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Change the mini-LED mode: * 0 - Single-zone, * 1 - Multi-zone @@ -133,6 +140,7 @@ Date: Apr 2024 KernelVersion: 6.10 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON List the available mini-led modes. =20 What: /sys/devices/platform//ppt_pl1_spl @@ -140,6 +148,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set the Package Power Target total of CPU: PL1 on Intel, SPL on AMD. Shown on Intel+Nvidia or AMD+Nvidia based systems: =20 @@ -150,6 +159,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set the Slow Package Power Tracking Limit of CPU: PL2 on Intel, SPPT, on AMD. Shown on Intel+Nvidia or AMD+Nvidia based systems: =20 @@ -160,6 +170,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set the Fast Package Power Tracking Limit of CPU. AMD+Nvidia only: * min=3D5, max=3D250 =20 @@ -168,6 +179,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set the APU SPPT limit. Shown on full AMD systems only: * min=3D5, max=3D130 =20 @@ -176,6 +188,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set the platform SPPT limit. Shown on full AMD systems only: * min=3D5, max=3D130 =20 @@ -184,6 +197,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set the dynamic boost limit of the Nvidia dGPU: * min=3D5, max=3D25 =20 @@ -192,6 +206,7 @@ Date: Jun 2023 KernelVersion: 6.5 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set the target temperature limit of the Nvidia dGPU: * min=3D75, max=3D87 =20 @@ -200,6 +215,7 @@ Date: Apr 2024 KernelVersion: 6.10 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set if the BIOS POST sound is played on boot. * 0 - False, * 1 - True @@ -209,6 +225,7 @@ Date: Apr 2024 KernelVersion: 6.10 Contact: "Luke Jones" Description: + DEPRECATED, WILL BE REMOVED SOON Set if the MCU can go in to low-power mode on system sleep * 0 - False, * 1 - True diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 80ec8b45022d..d0fc68d93f48 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -299,6 +299,15 @@ config ASUS_WMI To compile this driver as a module, choose M here: the module will be called asus-wmi. =20 +config ASUS_WMI_DEPRECATED_ATTRS + bool "BIOS option support in WMI platform (DEPRECATED)" + depends on ASUS_WMI + default y + help + Say Y to expose the configurable BIOS options through the asus-wmi + driver. This can be used with or without the asus-armoury driver which + has the same attributes, but more, and better features. + config ASUS_NB_WMI tristate "Asus Notebook WMI Driver" depends on ASUS_WMI diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wm= i.c index 3c6d774f4453..3b8e04f6c086 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -285,11 +285,12 @@ struct asus_wmi { u8 fan_boost_mode_mask; u8 fan_boost_mode; =20 + + /* Tunables provided by ASUS for gaming laptops */ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) bool egpu_enable_available; bool dgpu_disable_available; u32 gpu_mux_dev; - - /* Tunables provided by ASUS for gaming laptops */ u32 ppt_pl2_sppt; u32 ppt_pl1_spl; u32 ppt_apu_sppt; @@ -297,6 +298,9 @@ struct asus_wmi { u32 ppt_fppt; u32 nv_dynamic_boost; u32 nv_temp_target; + bool panel_overdrive_available; + u32 mini_led_dev_id; +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 u32 kbd_rgb_dev; bool kbd_rgb_state_available; @@ -315,9 +319,6 @@ struct asus_wmi { // The RSOC controls the maximum charging percentage. bool battery_rsoc_available; =20 - bool panel_overdrive_available; - u32 mini_led_dev_id; - struct hotplug_slot hotplug_slot; struct mutex hotplug_lock; struct mutex wmi_lock; @@ -331,6 +332,15 @@ struct asus_wmi { struct asus_wmi_driver *driver; }; =20 +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) +static void asus_wmi_show_deprecated(void) +{ + pr_notice_once("Accessing attributes through /sys/bus/platform/asus_wmi " + "is deprecated and will be removed in a future release. Please " + "switch over to /sys/class/firmware_attributes.\n"); +} +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ + /* WMI *******************************************************************= *****/ =20 static int asus_wmi_evaluate_method3(u32 method_id, @@ -728,6 +738,7 @@ static void asus_wmi_tablet_mode_get_state(struct asus_= wmi *asus) } =20 /* Charging mode, 1=3DBarrel, 2=3DUSB ************************************= ******/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t charge_mode_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -738,12 +749,16 @@ static ssize_t charge_mode_show(struct device *dev, if (result < 0) return result; =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", value & 0xff); } =20 static DEVICE_ATTR_RO(charge_mode); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* dGPU ******************************************************************= **/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t dgpu_disable_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -754,6 +769,8 @@ static ssize_t dgpu_disable_show(struct device *dev, if (result < 0) return result; =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", result); } =20 @@ -807,8 +824,10 @@ static ssize_t dgpu_disable_store(struct device *dev, return count; } static DEVICE_ATTR_RW(dgpu_disable); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* eGPU ******************************************************************= **/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t egpu_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -819,6 +838,8 @@ static ssize_t egpu_enable_show(struct device *dev, if (result < 0) return result; =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", result); } =20 @@ -875,8 +896,10 @@ static ssize_t egpu_enable_store(struct device *dev, return count; } static DEVICE_ATTR_RW(egpu_enable); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* Is eGPU connected? ****************************************************= *****/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t egpu_connected_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -887,12 +910,16 @@ static ssize_t egpu_connected_show(struct device *dev, if (result < 0) return result; =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", result); } =20 static DEVICE_ATTR_RO(egpu_connected); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* gpu mux switch ********************************************************= *****/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t gpu_mux_mode_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -903,6 +930,8 @@ static ssize_t gpu_mux_mode_show(struct device *dev, if (result < 0) return result; =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", result); } =20 @@ -961,6 +990,7 @@ static ssize_t gpu_mux_mode_store(struct device *dev, return count; } static DEVICE_ATTR_RW(gpu_mux_mode); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* TUF Laptop Keyboard RGB Modes *****************************************= *****/ static ssize_t kbd_rgb_mode_store(struct device *dev, @@ -1084,6 +1114,7 @@ static const struct attribute_group *kbd_rgb_mode_gro= ups[] =3D { }; =20 /* Tunable: PPT: Intel=3DPL1, AMD=3DSPPT *********************************= ********/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t ppt_pl2_sppt_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -1122,6 +1153,8 @@ static ssize_t ppt_pl2_sppt_show(struct device *dev, { struct asus_wmi *asus =3D dev_get_drvdata(dev); =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%u\n", asus->ppt_pl2_sppt); } static DEVICE_ATTR_RW(ppt_pl2_sppt); @@ -1164,6 +1197,8 @@ static ssize_t ppt_pl1_spl_show(struct device *dev, { struct asus_wmi *asus =3D dev_get_drvdata(dev); =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%u\n", asus->ppt_pl1_spl); } static DEVICE_ATTR_RW(ppt_pl1_spl); @@ -1207,6 +1242,8 @@ static ssize_t ppt_fppt_show(struct device *dev, { struct asus_wmi *asus =3D dev_get_drvdata(dev); =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%u\n", asus->ppt_fppt); } static DEVICE_ATTR_RW(ppt_fppt); @@ -1250,6 +1287,8 @@ static ssize_t ppt_apu_sppt_show(struct device *dev, { struct asus_wmi *asus =3D dev_get_drvdata(dev); =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%u\n", asus->ppt_apu_sppt); } static DEVICE_ATTR_RW(ppt_apu_sppt); @@ -1293,6 +1332,8 @@ static ssize_t ppt_platform_sppt_show(struct device *= dev, { struct asus_wmi *asus =3D dev_get_drvdata(dev); =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%u\n", asus->ppt_platform_sppt); } static DEVICE_ATTR_RW(ppt_platform_sppt); @@ -1336,6 +1377,8 @@ static ssize_t nv_dynamic_boost_show(struct device *d= ev, { struct asus_wmi *asus =3D dev_get_drvdata(dev); =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%u\n", asus->nv_dynamic_boost); } static DEVICE_ATTR_RW(nv_dynamic_boost); @@ -1379,11 +1422,15 @@ static ssize_t nv_temp_target_show(struct device *d= ev, { struct asus_wmi *asus =3D dev_get_drvdata(dev); =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%u\n", asus->nv_temp_target); } static DEVICE_ATTR_RW(nv_temp_target); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* Ally MCU Powersave ****************************************************= ****/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t mcu_powersave_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1394,6 +1441,8 @@ static ssize_t mcu_powersave_show(struct device *dev, if (result < 0) return result; =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", result); } =20 @@ -1429,6 +1478,7 @@ static ssize_t mcu_powersave_store(struct device *dev, return count; } static DEVICE_ATTR_RW(mcu_powersave); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* Battery ***************************************************************= *****/ =20 @@ -2302,6 +2352,7 @@ static int asus_wmi_rfkill_init(struct asus_wmi *asus) } =20 /* Panel Overdrive *******************************************************= *****/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t panel_od_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -2312,6 +2363,8 @@ static ssize_t panel_od_show(struct device *dev, if (result < 0) return result; =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", result); } =20 @@ -2348,9 +2401,10 @@ static ssize_t panel_od_store(struct device *dev, return count; } static DEVICE_ATTR_RW(panel_od); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* Bootup sound **********************************************************= *****/ - +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t boot_sound_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -2361,6 +2415,8 @@ static ssize_t boot_sound_show(struct device *dev, if (result < 0) return result; =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", result); } =20 @@ -2396,8 +2452,10 @@ static ssize_t boot_sound_store(struct device *dev, return count; } static DEVICE_ATTR_RW(boot_sound); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* Mini-LED mode *********************************************************= *****/ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t mini_led_mode_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -2428,6 +2486,8 @@ static ssize_t mini_led_mode_show(struct device *dev, } } =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "%d\n", value); } =20 @@ -2498,10 +2558,13 @@ static ssize_t available_mini_led_mode_show(struct = device *dev, return sysfs_emit(buf, "0 1 2\n"); } =20 + asus_wmi_show_deprecated(); + return sysfs_emit(buf, "0\n"); } =20 static DEVICE_ATTR_RO(available_mini_led_mode); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* Quirks ****************************************************************= *****/ =20 @@ -3800,6 +3863,7 @@ static int throttle_thermal_policy_switch_next(struct= asus_wmi *asus) return 0; } =20 +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) static ssize_t throttle_thermal_policy_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -3843,6 +3907,7 @@ static ssize_t throttle_thermal_policy_store(struct d= evice *dev, * Throttle thermal policy: 0 - default, 1 - overboost, 2 - silent */ static DEVICE_ATTR_RW(throttle_thermal_policy); +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 /* Platform profile ******************************************************= *****/ static int asus_wmi_platform_profile_to_vivo(struct asus_wmi *asus, int mo= de) @@ -4470,27 +4535,29 @@ static struct attribute *platform_attributes[] =3D { &dev_attr_camera.attr, &dev_attr_cardr.attr, &dev_attr_touchpad.attr, - &dev_attr_charge_mode.attr, - &dev_attr_egpu_enable.attr, - &dev_attr_egpu_connected.attr, - &dev_attr_dgpu_disable.attr, - &dev_attr_gpu_mux_mode.attr, &dev_attr_lid_resume.attr, &dev_attr_als_enable.attr, &dev_attr_fan_boost_mode.attr, - &dev_attr_throttle_thermal_policy.attr, - &dev_attr_ppt_pl2_sppt.attr, - &dev_attr_ppt_pl1_spl.attr, - &dev_attr_ppt_fppt.attr, - &dev_attr_ppt_apu_sppt.attr, - &dev_attr_ppt_platform_sppt.attr, - &dev_attr_nv_dynamic_boost.attr, - &dev_attr_nv_temp_target.attr, - &dev_attr_mcu_powersave.attr, - &dev_attr_boot_sound.attr, - &dev_attr_panel_od.attr, - &dev_attr_mini_led_mode.attr, - &dev_attr_available_mini_led_mode.attr, +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) + &dev_attr_charge_mode.attr, + &dev_attr_egpu_enable.attr, + &dev_attr_egpu_connected.attr, + &dev_attr_dgpu_disable.attr, + &dev_attr_gpu_mux_mode.attr, + &dev_attr_ppt_pl2_sppt.attr, + &dev_attr_ppt_pl1_spl.attr, + &dev_attr_ppt_fppt.attr, + &dev_attr_ppt_apu_sppt.attr, + &dev_attr_ppt_platform_sppt.attr, + &dev_attr_nv_dynamic_boost.attr, + &dev_attr_nv_temp_target.attr, + &dev_attr_mcu_powersave.attr, + &dev_attr_boot_sound.attr, + &dev_attr_panel_od.attr, + &dev_attr_mini_led_mode.attr, + &dev_attr_available_mini_led_mode.attr, + &dev_attr_throttle_thermal_policy.attr, +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ NULL }; =20 @@ -4512,7 +4579,11 @@ static umode_t asus_sysfs_is_visible(struct kobject = *kobj, devid =3D ASUS_WMI_DEVID_LID_RESUME; else if (attr =3D=3D &dev_attr_als_enable.attr) devid =3D ASUS_WMI_DEVID_ALS_ENABLE; - else if (attr =3D=3D &dev_attr_charge_mode.attr) + else if (attr =3D=3D &dev_attr_fan_boost_mode.attr) + ok =3D asus->fan_boost_mode_available; + +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) + if (attr =3D=3D &dev_attr_charge_mode.attr) devid =3D ASUS_WMI_DEVID_CHARGE_MODE; else if (attr =3D=3D &dev_attr_egpu_enable.attr) ok =3D asus->egpu_enable_available; @@ -4550,6 +4621,7 @@ static umode_t asus_sysfs_is_visible(struct kobject *= kobj, ok =3D asus->mini_led_dev_id !=3D 0; else if (attr =3D=3D &dev_attr_available_mini_led_mode.attr) ok =3D asus->mini_led_dev_id !=3D 0; +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 if (devid !=3D -1) { ok =3D !(asus_wmi_get_devstate_simple(asus, devid) < 0); @@ -4790,6 +4862,7 @@ static int asus_wmi_add(struct platform_device *pdev) goto fail_platform; =20 /* ensure defaults for tunables */ +#if IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) asus->ppt_pl2_sppt =3D 5; asus->ppt_pl1_spl =3D 5; asus->ppt_apu_sppt =3D 5; @@ -4813,17 +4886,18 @@ static int asus_wmi_add(struct platform_device *pde= v) asus->gpu_mux_dev =3D ASUS_WMI_DEVID_GPU_MUX; else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_GPU_MUX_VIVO)) asus->gpu_mux_dev =3D ASUS_WMI_DEVID_GPU_MUX_VIVO; - - if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE)) - asus->kbd_rgb_dev =3D ASUS_WMI_DEVID_TUF_RGB_MODE; - else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2)) - asus->kbd_rgb_dev =3D ASUS_WMI_DEVID_TUF_RGB_MODE2; +#endif /* IS_ENABLED(CONFIG_ASUS_WMI_DEPRECATED_ATTRS) */ =20 if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY)) asus->throttle_thermal_policy_dev =3D ASUS_WMI_DEVID_THROTTLE_THERMAL_PO= LICY; else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_THROTTLE_THERMAL_PO= LICY_VIVO)) asus->throttle_thermal_policy_dev =3D ASUS_WMI_DEVID_THROTTLE_THERMAL_PO= LICY_VIVO; =20 + if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE)) + asus->kbd_rgb_dev =3D ASUS_WMI_DEVID_TUF_RGB_MODE; + else if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_MODE2)) + asus->kbd_rgb_dev =3D ASUS_WMI_DEVID_TUF_RGB_MODE2; + err =3D fan_boost_mode_check_present(asus); if (err) goto fail_fan_boost_mode; --=20 2.46.1