From patchwork Tue May 28 01:36:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675981 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 14DFA944F; Tue, 28 May 2024 01:36:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860201; cv=none; b=Z+3K2GjxcQjgSavSW6uop0epO6rzepDBrifn+wFxvhl5kDNV2R9R3twy+j6+Q9uduRpYWyqdFAmOjVtPLDkfD8lSl29OArMM0iarUGRNUY4pdBZgljgH+0CJt7ND+nw7437eUcr2iU7YgZX7b/KjNj8mgki9Vtzmhfo55GpKXmI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860201; c=relaxed/simple; bh=vQyiNakurHrTDQqN8eQP1YeGSIHDA/FV2l9h+0yojcs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N3D9xNjL+uK9MYI8TIj+m0fdVD0NznC0fA/872yiBZ4Tq31h+MF5gBHyNcljZAhD0VeKOWLRHXYHDB3h7a0IpvTw4xWPqWqkL9/nwZf5JbqZ/fw4etxmnIGfE7jNsbKeNWCCGTqN78VVCRdgCHUAZVeFhyvyy5TP+DqiFbIQTPg= 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=oeqW5vCh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=po79+vK6; arc=none smtp.client-ip=103.168.172.145 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="oeqW5vCh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="po79+vK6" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 3041F138013D; Mon, 27 May 2024 21:36:39 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 27 May 2024 21:36:39 -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=fm2; t=1716860199; x= 1716946599; bh=gcXTqMW4+klc8Afnn2worXjcdcJuH4da6dNmIEEsW4A=; b=o eqW5vCh8eBUcyMpseOVdkGD2moSC0uUy63QzscFkXkuK0UvYGFA0+AzjMtd4QRI4 Ttx4gh6dk1L0Eo9XY/i9CV6NhVNj2X0SsSEeeGs+7knZjQR5SFRKsjWemKi4DTLS mdcR15vhW+cNQPkHVCZAPyY+zkksh4EXzxjSZ8bBuZmfot3Ict3Iyfn7fFJ14keQ g3ILQG2NNouipH1hvE73Rx9/AxexhwFW9bCmGXTW9aPfoPxTZhoVKXeozB8/Shw1 y3Y2MWCMIJ8Nbd5buuDBhr7lRRrrOHOyD1LUgsjtev8M6dmaYRc3DHf3G0RpJUsB QllJQJwOqQwBkMa/E3mww== 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=fm1; t=1716860199; x= 1716946599; bh=gcXTqMW4+klc8Afnn2worXjcdcJuH4da6dNmIEEsW4A=; b=p o79+vK68GRoU2qOYorVf8a+pXO/Uo+GPhL7zHTuAmGVW8qO+gppXJypqdskW7PSH 54OO96GjunBZ5qiWln2Sjmbei3FmVq8wNQJvb8RgYN+tkCqz/tOsJRwF0y26I5bc tjIiRlF3ZlKcs+cLFMd54CJohFZSE1RnixtNInJQ7xzxUyrpFDP6bNng2dXoqObW pf49Buno0Gsj3ne2HlXjFMytZ/e6cqo+pM/bKNrGAcACkIvuHWYJnQrbg3gWSnw3 lk9mJBESEu7Dmh8WrCC+PXrNhjnal0JYiI+zpvEOERK2bdLA8AwZMO/eYKN7GZXE AQriEdHB1zqKoabrB5Etw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:36:36 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 1/9] platform/x86: asus-wmi: add debug print in more key places Date: Tue, 28 May 2024 13:36:18 +1200 Message-ID: <20240528013626.14066-2-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add more verbose debug print in the WMI method calls. This helps a lot with debugging various issues working with regular users as the WMI methods can be traced now. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 58 +++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index a58df18a70ad..adc841abbb2a 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -334,20 +334,29 @@ static int asus_wmi_evaluate_method3(u32 method_id, status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 0, method_id, &input, &output); - if (ACPI_FAILURE(status)) + pr_debug("%s called (0x%08x) with args: 0x%08x, 0x%08x, 0x%08x\n", + __func__, method_id, arg0, arg1, arg2); + if (ACPI_FAILURE(status)) { + pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n", + __func__, method_id, arg0, -EIO); return -EIO; + } obj = (union acpi_object *)output.pointer; if (obj && obj->type == ACPI_TYPE_INTEGER) tmp = (u32) obj->integer.value; + pr_debug("Result: 0x%08x\n", tmp); if (retval) *retval = tmp; kfree(obj); - if (tmp == ASUS_WMI_UNSUPPORTED_METHOD) + if (tmp == ASUS_WMI_UNSUPPORTED_METHOD) { + pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n", + __func__, method_id, arg0, -ENODEV); return -ENODEV; + } return 0; } @@ -377,20 +386,29 @@ static int asus_wmi_evaluate_method5(u32 method_id, status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 0, method_id, &input, &output); - if (ACPI_FAILURE(status)) + pr_debug("%s called (0x%08x) with args: 0x%08x, 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", + __func__, method_id, arg0, arg1, arg2, arg3, arg4); + if (ACPI_FAILURE(status)) { + pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n", + __func__, method_id, arg0, -EIO); return -EIO; + } obj = (union acpi_object *)output.pointer; if (obj && obj->type == ACPI_TYPE_INTEGER) tmp = (u32) obj->integer.value; + pr_debug("Result: %x\n", tmp); if (retval) *retval = tmp; kfree(obj); - if (tmp == ASUS_WMI_UNSUPPORTED_METHOD) + if (tmp == ASUS_WMI_UNSUPPORTED_METHOD) { + pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n", + __func__, method_id, arg0, -ENODEV); return -ENODEV; + } return 0; } @@ -416,8 +434,13 @@ static int asus_wmi_evaluate_method_buf(u32 method_id, status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 0, method_id, &input, &output); - if (ACPI_FAILURE(status)) + pr_debug("%s called (0x%08x) with args: 0x%08x, 0x%08x\n", + __func__, method_id, arg0, arg1); + if (ACPI_FAILURE(status)) { + pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n", + __func__, method_id, arg0, -EIO); return -EIO; + } obj = (union acpi_object *)output.pointer; @@ -453,8 +476,11 @@ static int asus_wmi_evaluate_method_buf(u32 method_id, kfree(obj); - if (err) + if (err) { + pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n", + __func__, method_id, arg0, err); return err; + } return 0; } @@ -542,6 +568,7 @@ static bool asus_wmi_dev_is_present(struct asus_wmi *asus, u32 dev_id) { u32 retval; int status = asus_wmi_get_devstate(asus, dev_id, &retval); + pr_debug("%s called (0x%08x), retval: 0x%08x\n", __func__, dev_id, retval); return status == 0 && (retval & ASUS_WMI_DSTS_PRESENCE_BIT); } @@ -3559,18 +3586,27 @@ static int asus_wmi_custom_fan_curve_init(struct asus_wmi *asus) err = fan_curve_check_present(asus, &asus->cpu_fan_curve_available, ASUS_WMI_DEVID_CPU_FAN_CURVE); - if (err) + if (err) { + pr_err("%s, checked 0x%08x, failed: %d\n", + __func__, ASUS_WMI_DEVID_CPU_FAN_CURVE, err); return err; + } err = fan_curve_check_present(asus, &asus->gpu_fan_curve_available, ASUS_WMI_DEVID_GPU_FAN_CURVE); - if (err) + if (err) { + pr_err("%s, checked 0x%08x, failed: %d\n", + __func__, ASUS_WMI_DEVID_GPU_FAN_CURVE, err); return err; + } err = fan_curve_check_present(asus, &asus->mid_fan_curve_available, ASUS_WMI_DEVID_MID_FAN_CURVE); - if (err) + if (err) { + pr_err("%s, checked 0x%08x, failed: %d\n", + __func__, ASUS_WMI_DEVID_MID_FAN_CURVE, err); return err; + } if (!asus->cpu_fan_curve_available && !asus->gpu_fan_curve_available @@ -4398,8 +4434,10 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, else if (attr == &dev_attr_available_mini_led_mode.attr) ok = asus->mini_led_dev_id != 0; - if (devid != -1) + if (devid != -1) { ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0); + pr_debug("%s called 0x%08x, ok: %x\n", __func__, devid, ok); + } return ok ? attr->mode : 0; } From patchwork Tue May 28 01:36:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675982 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 25D00EEDB; Tue, 28 May 2024 01:36:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860204; cv=none; b=ZeU/ucGn4WGavvnOC8LdtCFPil/Td8Kg5wFHGFe9pOOswfD9nkyfrmzHdOFj0mJqYDgqa9LFImIMx1kO+h3u6MnvWW/k2koHqXpN5Ipa2dtLDvT9ur/C7/3Rop6VRbCrQExvle7gKMf3QHZVlqiBm3+JDuKUmBqgo+/64WaW9Vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860204; c=relaxed/simple; bh=6X5qvdGER3UOQsX0hdA2jSbk0AKoPE1PhDLPSdV9aUA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p0mGmSNWyopHRc2APOY86LYjD4G0cSn8XlyVP3Qv5Pfz1seaURtAu3YPCJEpB/YvMiimgcv2FDBkFKlD/sRka+GzeTWWyT6mR2f2tMim/vWTbgNCGadg1rK6GVhxxNeShKNqsz1DNeruj/i//g88HepFW6tdkLUVHIbS+AkIgvo= 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=gh7KSpuM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NSqq02EM; arc=none smtp.client-ip=103.168.172.159 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="gh7KSpuM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NSqq02EM" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3253911400D6; Mon, 27 May 2024 21:36:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 27 May 2024 21:36:42 -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=fm2; t=1716860202; x= 1716946602; bh=3bdXh04xDjc3/ImoEZe1VUNcZWPsiJSevANr5wdAkVo=; b=g h7KSpuM5ArFiDOkpZ3NDlTY8PoNNKCgNr6iYv9RBjxiYUfUJ7pK3+VY4rUmBzXp+ 5B38SRhbPDfYBGkecEOV+UliGNG5GTGICDTo0ij/oNwQtq6JjGn6TOnO2andKoYz KkhCyOWoj4pR5BnaFvEEbiG12iKSRnt9/4Na4EMc+p9URiDB75ssMgHlDroZsCxV GryGlaUngjBQJIWR2+DvZknmsEfOteH7oLbaxXULehOLVkuIXZE3MuCguHHoKs8O gmm9Yye2+ceQipuQFNP3nx66/c6V4JGNoikWk9xg3CT4OpQ5V4ORJoKmGN0LWcep 5hNtsKdzoD0DnVEpXhSLg== 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=fm1; t=1716860202; x= 1716946602; bh=3bdXh04xDjc3/ImoEZe1VUNcZWPsiJSevANr5wdAkVo=; b=N Sqq02EM7QkwCYyabkvCoJ9tuR2ZNr3E8MvnvoSQnvb9IntZ9f3D1CoGcKMnKRNap CWrqqCPYy/M0EzA/EtcB4b4zBI+WRGThnWCVvdVQ4BQzGNScqefa1Je6f6ZuSWCj DVDv0+KOuz8B0q1FLRq9zYtwrZLOw6YzDF+0a8jaKy4PIV96VhNv/RTwtS3tVmHU DCeNnW/xG9jbStcp4EITmlncXPD1Dw0vNzUF8lNEPCjGO//hY55g9bqmf3vs1H8S i8o/hGfsFbBCTCU132vER9umbjVgsI88Wry3/SSKGFiAT2HAfJJZ6ac2zhAlsgl0 4hnz27OOTbLwebz/gzOMA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:36:39 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 2/9] platform/x86: asus-wmi: don't fail if platform_profile already registered Date: Tue, 28 May 2024 13:36:19 +1200 Message-ID: <20240528013626.14066-3-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On some newer laptops it appears that an AMD driver can register a platform_profile handler. If this happens then the asus_wmi driver would error with -EEXIST when trying to register its own handler. We can safely continue loading the driver instead of bombing out. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index adc841abbb2a..999cd658ec8b 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -3836,8 +3836,13 @@ static int platform_profile_setup(struct asus_wmi *asus) asus->platform_profile_handler.choices); err = platform_profile_register(&asus->platform_profile_handler); - if (err) + if (err == -EEXIST) { + pr_warn("%s, a platform_profile handler is already registered\n", __func__); + return 0; + } else if (err) { + pr_err("%s, failed at platform_profile_register: %d\n", __func__, err); return err; + } asus->platform_profile_support = true; return 0; @@ -4713,7 +4718,7 @@ static int asus_wmi_add(struct platform_device *pdev) throttle_thermal_policy_set_default(asus); err = platform_profile_setup(asus); - if (err) + if (err && err != -EEXIST) goto fail_platform_profile_setup; err = asus_wmi_sysfs_init(asus->platform_device); From patchwork Tue May 28 01:36:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675983 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 8A08718039; Tue, 28 May 2024 01:36:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860208; cv=none; b=VUoFJgMsFq4sKxVXRnbUGTM7WIMUum8fVtDKDmFjmiWat6Y6YI5wqdNWYiCxmY1eEbYL33gdwgjrO5FRe+N+zWbq4csRJ27aQf77NBwq1smH5fGwpBAOa68+UhjlI2pUUzS3xulLolomxoaIXIw8E9Tbq3Bj6qZVnzeuMDWa2yI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860208; c=relaxed/simple; bh=Q2rvBjS1MCxee3IOaolZ0vn8pemDfVifNXK1NpgBG0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=it2zJ0pNwvf5D7z6AtyQwdADtSGQprJcCnnQeq7m6G7iMBBTHb1aRmvGNopFfdx8LERE42t8UPbpL8IGkK4aIxqJvfnEj784SFaU53FH2sEKcq36Dzqub64jchKlZitgoEz6UcYbLgC8kj9Cg45iu53pfDbxYGuNNysaHJEWIoA= 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=hkc7nM0k; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Aj+VUFvO; arc=none smtp.client-ip=103.168.172.145 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="hkc7nM0k"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Aj+VUFvO" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 9D515138013A; Mon, 27 May 2024 21:36:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 27 May 2024 21:36:45 -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=fm2; t=1716860205; x= 1716946605; bh=7Aa3sTl039lcsHosnWGLerpiLs/DMEJf6PqKt2C8ti4=; b=h kc7nM0kAw98A+fqQIm9O0WKlXuj0rhymd4xO4s6XwqQvaC2kyYpKqYvaFiwwexm7 OB6hkXJ4y4dK5bFee7wCXcyBeCt3pHE+O+sKUKEiXr4sGZmFD2gOKGh+vo6I8Fq2 S4hq8BLdprd549mDM/MgV3uujZkf6acZXLIazV0eRWTyc88oeFkTVJpw/kkJz3SU ZbBlqZ2Ligwepo7Vm3bPQLmKemJQFE7sKhjk7TePlo+j5NrL0XlGuwZ7R2PPtJQD Z+8w6ZWZW0PbCjg5+zv5tSGJfVfjqpRBewyBy5HShy9JxkFh/Lu/UbXbAZCSBtF1 GslQuR48yQ0JrRFR4iAsQ== 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=fm1; t=1716860205; x= 1716946605; bh=7Aa3sTl039lcsHosnWGLerpiLs/DMEJf6PqKt2C8ti4=; b=A j+VUFvOpJ64mb//Viw777+kg/oBboIJcEi351npiPGG8Ac0/5bBw7iN6KVgPOt+P Vl92ToYghk1HV3wJPKoIZVPc4WWkha+vzy31mesPw29DOpDBwomUQ0T9YKcdxDmN RGh9w19YsR6QvNWPWDcoD+ZkxLpYbqDphfUAjved6hFJNsQpon4yFVJe8oLBSvo0 MRZjM5Ylh0tfmiopKRCRbphBfXUX2IqoVMSReluqcvOyTl+f7mYsHClfRziuv6do OQi9NCJay26tpjyWHCTMNoIVZxFR8wEUtLNntc0rrgJFD9jhJlKVBgZveUgyzCBK DGZFvVxgLdf0hg8Q2uUYA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:36:42 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 3/9] platform/x86: asus-wmi: add macros and expose min/max sysfs for ppt tunables Date: Tue, 28 May 2024 13:36:20 +1200 Message-ID: <20240528013626.14066-4-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In most cases the safe min and max values of the various PPT tunables are known for various ASUS ROG (and other) laptop models. We can match the DMI string for these and expose min/max sysfs points, plus set some sane default values. As part of the addition of the min/max and defaults, to reduce the amount of code copy/paste and introduce some sanity a group of macros were added specific to the PPT and NV tunables. The code becomes much cleaner and easier to read. This makes the PPT functions much more usable and safe. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 23 +- drivers/platform/x86/asus-wmi.c | 561 ++++++++---------- 2 files changed, 245 insertions(+), 339 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 28144371a0f1..984a04f32fd0 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -142,8 +142,8 @@ Contact: "Luke Jones" Description: Set the Package Power Target total of CPU: PL1 on Intel, SPL on AMD. Shown on Intel+Nvidia or AMD+Nvidia based systems: - - * min=5, max=250 + * min/max varies, read *_min/*_max sysfs entries + * -1 resets to default What: /sys/devices/platform//ppt_pl2_sppt Date: Jun 2023 @@ -152,8 +152,8 @@ Contact: "Luke Jones" Description: Set the Slow Package Power Tracking Limit of CPU: PL2 on Intel, SPPT, on AMD. Shown on Intel+Nvidia or AMD+Nvidia based systems: - - * min=5, max=250 + * min/max varies, read *_min/*_max sysfs entries + * -1 resets to default What: /sys/devices/platform//ppt_fppt Date: Jun 2023 @@ -161,7 +161,8 @@ KernelVersion: 6.5 Contact: "Luke Jones" Description: Set the Fast Package Power Tracking Limit of CPU. AMD+Nvidia only: - * min=5, max=250 + * min/max varies, read *_min/*_max sysfs entries + * -1 resets to default What: /sys/devices/platform//ppt_apu_sppt Date: Jun 2023 @@ -169,7 +170,8 @@ KernelVersion: 6.5 Contact: "Luke Jones" Description: Set the APU SPPT limit. Shown on full AMD systems only: - * min=5, max=130 + * min/max varies, read *_min/*_max sysfs entries + * -1 resets to default What: /sys/devices/platform//ppt_platform_sppt Date: Jun 2023 @@ -177,7 +179,8 @@ KernelVersion: 6.5 Contact: "Luke Jones" Description: Set the platform SPPT limit. Shown on full AMD systems only: - * min=5, max=130 + * min/max varies, read *_min/*_max sysfs entries + * -1 resets to default What: /sys/devices/platform//nv_dynamic_boost Date: Jun 2023 @@ -185,7 +188,8 @@ KernelVersion: 6.5 Contact: "Luke Jones" Description: Set the dynamic boost limit of the Nvidia dGPU: - * min=5, max=25 + * min/max varies, read *_min/*_max sysfs entries + * -1 resets to default What: /sys/devices/platform//nv_temp_target Date: Jun 2023 @@ -193,7 +197,8 @@ KernelVersion: 6.5 Contact: "Luke Jones" Description: Set the target temperature limit of the Nvidia dGPU: - * min=75, max=87 + * min/max varies, read *_min/*_max sysfs entries + * -1 resets to default What: /sys/devices/platform//boot_sound Date: Apr 2024 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 999cd658ec8b..d016acb23789 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -112,11 +112,13 @@ module_param(fnlock_default, bool, 0444); /* Mask to determine if setting temperature or percentage */ #define FAN_CURVE_PWM_MASK 0x04 -/* Limits for tunables available on ASUS ROG laptops */ -#define PPT_TOTAL_MIN 5 -#define PPT_TOTAL_MAX 250 -#define PPT_CPU_MIN 5 -#define PPT_CPU_MAX 130 +/* Default limits for tunables available on ASUS ROG laptops */ +#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 #define NVIDIA_BOOST_MIN 5 #define NVIDIA_BOOST_MAX 25 #define NVIDIA_TEMP_MIN 75 @@ -219,6 +221,29 @@ struct fan_curve_data { u8 percents[FAN_CURVE_POINTS]; }; +/* Tunables provided by ASUS for gaming laptops */ +struct rog_tunables { + u32 cpu_default; + u32 cpu_max; + + u32 platform_default; + u32 platform_max; + + u32 ppt_pl1_spl; // total + u32 ppt_pl2_sppt; // total + u32 ppt_apu_sppt; // cpu + u32 ppt_platform_sppt; // cpu + u32 ppt_fppt; // total + + u32 nv_boost_default; + u32 nv_boost_max; + u32 nv_dynamic_boost; + + u32 nv_temp_default; + u32 nv_temp_max; + u32 nv_temp_target; +}; + struct asus_wmi { int dsts_id; int spec; @@ -273,14 +298,7 @@ struct asus_wmi { 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; - u32 ppt_platform_sppt; - u32 ppt_fppt; - u32 nv_dynamic_boost; - u32 nv_temp_target; + struct rog_tunables rog_tunables; u32 kbd_rgb_dev; bool kbd_rgb_state_available; @@ -652,6 +670,98 @@ static void asus_wmi_input_exit(struct asus_wmi *asus) asus->inputdev = NULL; } +/* Helper macros for generalised WMI calls */ + +/* Generic store function for use with many ROG tunables */ +static ssize_t rog_tunable_store(struct asus_wmi *asus, + struct attribute *attr, + const char *buf, size_t count, + u32 min, u32 max, u32 defaultv, + u32 *store_value, u32 wmi_dev) +{ + int result, err, value; + + result = kstrtoint(buf, 10, &value); + if (result) + return result; + + if (value == -1 ) + value = defaultv; + if (value < min || value > max) + return -EINVAL; + + err = asus_wmi_set_devstate(wmi_dev, value, &result); + if (err) { + pr_err("Failed to set %s: %d\n", attr->name, err); + return err; + } + + if (result > 1) { + pr_err("Failed to set %s (result): 0x%x\n", attr->name, result); + return -EIO; + } + + if (store_value != NULL) + *store_value = value; + sysfs_notify(&asus->platform_device->dev.kobj, NULL, attr->name); + + return count; +} + +#define ROG_TUNABLE_STORE(_fname, _min, _max, _default, _wmi) \ +static ssize_t _fname##_store(struct device *dev, \ + struct device_attribute *attr, const char *buf, size_t count) \ +{ \ + struct asus_wmi *asus = dev_get_drvdata(dev); \ + return rog_tunable_store(asus, &attr->attr, buf, count, \ + _min, asus->rog_tunables._max, asus->rog_tunables._default, \ + &asus->rog_tunables._fname, _wmi); \ +} + +#define ROG_TUNABLE_SHOW(_fname) \ +static ssize_t _fname##_show(struct device *dev, struct device_attribute *attr, char *buf) \ +{ \ + struct asus_wmi *asus = dev_get_drvdata(dev); \ + return sysfs_emit(buf, "%u\n", asus->rog_tunables._fname); \ +} + +#define ROG_TUNABLE_MIN_SHOW(_fname, _minv) \ +static ssize_t _fname##_min_show(struct device *dev, struct device_attribute *attr, char *buf) \ +{ \ + return sysfs_emit(buf, "%u\n", _minv); \ +} + +#define ROG_TUNABLE_MAX_SHOW(_fname, _maxv) \ +static ssize_t _fname##_max_show(struct device *dev, struct device_attribute *attr, char *buf) \ +{ \ + struct asus_wmi *asus = dev_get_drvdata(dev); \ + return sysfs_emit(buf, "%u\n", asus->rog_tunables._maxv); \ +} + +#define ROG_ATTR_RW(_fname, _minv, _maxv, _defaultv, _wmi) \ +ROG_TUNABLE_MIN_SHOW(_fname, _minv); \ +ROG_TUNABLE_MAX_SHOW(_fname, _maxv); \ +ROG_TUNABLE_STORE(_fname, _minv, _maxv, _defaultv, _wmi);\ +ROG_TUNABLE_SHOW(_fname); \ +static DEVICE_ATTR_RO(_fname##_min); \ +static DEVICE_ATTR_RO(_fname##_max); \ +static DEVICE_ATTR_RW(_fname) + +ROG_ATTR_RW(ppt_platform_sppt, + PPT_PLATFORM_MIN, platform_max, platform_default, ASUS_WMI_DEVID_PPT_PLAT_SPPT); +ROG_ATTR_RW(ppt_pl2_sppt, + PPT_CPU_LIMIT_MIN, cpu_max, cpu_default, ASUS_WMI_DEVID_PPT_PL2_SPPT); +ROG_ATTR_RW(ppt_apu_sppt, + PPT_PLATFORM_MIN, platform_max, platform_default, ASUS_WMI_DEVID_PPT_APU_SPPT); +ROG_ATTR_RW(ppt_pl1_spl, + PPT_CPU_LIMIT_MIN, cpu_max, cpu_default, ASUS_WMI_DEVID_PPT_PL1_SPL); +ROG_ATTR_RW(ppt_fppt, + PPT_CPU_LIMIT_MIN, cpu_max, cpu_default, ASUS_WMI_DEVID_PPT_FPPT); +ROG_ATTR_RW(nv_dynamic_boost, + NVIDIA_BOOST_MIN, nv_boost_max, nv_boost_default, ASUS_WMI_DEVID_NV_DYN_BOOST); +ROG_ATTR_RW(nv_temp_target, + NVIDIA_TEMP_MIN, nv_temp_max, nv_temp_default, ASUS_WMI_DEVID_NV_THERM_TARGET); + /* Tablet mode ****************************************************************/ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus) @@ -1018,306 +1128,6 @@ static const struct attribute_group *kbd_rgb_mode_groups[] = { NULL, }; -/* Tunable: PPT: Intel=PL1, AMD=SPPT *****************************************/ -static ssize_t ppt_pl2_sppt_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result, err; - u32 value; - - result = kstrtou32(buf, 10, &value); - if (result) - return result; - - if (value < PPT_TOTAL_MIN || value > PPT_TOTAL_MAX) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_PL2_SPPT, value, &result); - if (err) { - pr_warn("Failed to set ppt_pl2_sppt: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set ppt_pl2_sppt (result): 0x%x\n", result); - return -EIO; - } - - asus->ppt_pl2_sppt = value; - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_pl2_sppt"); - - return count; -} - -static ssize_t ppt_pl2_sppt_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - - return sysfs_emit(buf, "%u\n", asus->ppt_pl2_sppt); -} -static DEVICE_ATTR_RW(ppt_pl2_sppt); - -/* Tunable: PPT, Intel=PL1, AMD=SPL ******************************************/ -static ssize_t ppt_pl1_spl_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result, err; - u32 value; - - result = kstrtou32(buf, 10, &value); - if (result) - return result; - - if (value < PPT_TOTAL_MIN || value > PPT_TOTAL_MAX) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_PL1_SPL, value, &result); - if (err) { - pr_warn("Failed to set ppt_pl1_spl: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set ppt_pl1_spl (result): 0x%x\n", result); - return -EIO; - } - - asus->ppt_pl1_spl = value; - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_pl1_spl"); - - return count; -} -static ssize_t ppt_pl1_spl_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - - return sysfs_emit(buf, "%u\n", asus->ppt_pl1_spl); -} -static DEVICE_ATTR_RW(ppt_pl1_spl); - -/* Tunable: PPT APU FPPT ******************************************************/ -static ssize_t ppt_fppt_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result, err; - u32 value; - - result = kstrtou32(buf, 10, &value); - if (result) - return result; - - if (value < PPT_TOTAL_MIN || value > PPT_TOTAL_MAX) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_FPPT, value, &result); - if (err) { - pr_warn("Failed to set ppt_fppt: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set ppt_fppt (result): 0x%x\n", result); - return -EIO; - } - - asus->ppt_fppt = value; - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_fpu_sppt"); - - return count; -} - -static ssize_t ppt_fppt_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - - return sysfs_emit(buf, "%u\n", asus->ppt_fppt); -} -static DEVICE_ATTR_RW(ppt_fppt); - -/* Tunable: PPT APU SPPT *****************************************************/ -static ssize_t ppt_apu_sppt_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result, err; - u32 value; - - result = kstrtou32(buf, 10, &value); - if (result) - return result; - - if (value < PPT_CPU_MIN || value > PPT_CPU_MAX) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_APU_SPPT, value, &result); - if (err) { - pr_warn("Failed to set ppt_apu_sppt: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set ppt_apu_sppt (result): 0x%x\n", result); - return -EIO; - } - - asus->ppt_apu_sppt = value; - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_apu_sppt"); - - return count; -} - -static ssize_t ppt_apu_sppt_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - - return sysfs_emit(buf, "%u\n", asus->ppt_apu_sppt); -} -static DEVICE_ATTR_RW(ppt_apu_sppt); - -/* Tunable: PPT platform SPPT ************************************************/ -static ssize_t ppt_platform_sppt_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result, err; - u32 value; - - result = kstrtou32(buf, 10, &value); - if (result) - return result; - - if (value < PPT_CPU_MIN || value > PPT_CPU_MAX) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PPT_PLAT_SPPT, value, &result); - if (err) { - pr_warn("Failed to set ppt_platform_sppt: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set ppt_platform_sppt (result): 0x%x\n", result); - return -EIO; - } - - asus->ppt_platform_sppt = value; - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "ppt_platform_sppt"); - - return count; -} - -static ssize_t ppt_platform_sppt_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - - return sysfs_emit(buf, "%u\n", asus->ppt_platform_sppt); -} -static DEVICE_ATTR_RW(ppt_platform_sppt); - -/* Tunable: NVIDIA dynamic boost *********************************************/ -static ssize_t nv_dynamic_boost_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result, err; - u32 value; - - result = kstrtou32(buf, 10, &value); - if (result) - return result; - - if (value < NVIDIA_BOOST_MIN || value > NVIDIA_BOOST_MAX) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_NV_DYN_BOOST, value, &result); - if (err) { - pr_warn("Failed to set nv_dynamic_boost: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set nv_dynamic_boost (result): 0x%x\n", result); - return -EIO; - } - - asus->nv_dynamic_boost = value; - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "nv_dynamic_boost"); - - return count; -} - -static ssize_t nv_dynamic_boost_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - - return sysfs_emit(buf, "%u\n", asus->nv_dynamic_boost); -} -static DEVICE_ATTR_RW(nv_dynamic_boost); - -/* Tunable: NVIDIA temperature target ****************************************/ -static ssize_t nv_temp_target_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result, err; - u32 value; - - result = kstrtou32(buf, 10, &value); - if (result) - return result; - - if (value < NVIDIA_TEMP_MIN || value > NVIDIA_TEMP_MAX) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_NV_THERM_TARGET, value, &result); - if (err) { - pr_warn("Failed to set nv_temp_target: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set nv_temp_target (result): 0x%x\n", result); - return -EIO; - } - - asus->nv_temp_target = value; - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "nv_temp_target"); - - return count; -} - -static ssize_t nv_temp_target_show(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - - return sysfs_emit(buf, "%u\n", asus->nv_temp_target); -} -static DEVICE_ATTR_RW(nv_temp_target); - /* Ally MCU Powersave ********************************************************/ static ssize_t mcu_powersave_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -4367,13 +4177,27 @@ static struct attribute *platform_attributes[] = { &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_pl1_spl_min.attr, + &dev_attr_ppt_pl1_spl_max.attr, + &dev_attr_ppt_pl2_sppt.attr, + &dev_attr_ppt_pl2_sppt_min.attr, + &dev_attr_ppt_pl2_sppt_max.attr, &dev_attr_ppt_fppt.attr, + &dev_attr_ppt_fppt_min.attr, + &dev_attr_ppt_fppt_max.attr, &dev_attr_ppt_apu_sppt.attr, + &dev_attr_ppt_apu_sppt_min.attr, + &dev_attr_ppt_apu_sppt_max.attr, &dev_attr_ppt_platform_sppt.attr, + &dev_attr_ppt_platform_sppt_min.attr, + &dev_attr_ppt_platform_sppt_max.attr, &dev_attr_nv_dynamic_boost.attr, + &dev_attr_nv_dynamic_boost_min.attr, + &dev_attr_nv_dynamic_boost_max.attr, &dev_attr_nv_temp_target.attr, + &dev_attr_nv_temp_target_min.attr, + &dev_attr_nv_temp_target_max.attr, &dev_attr_mcu_powersave.attr, &dev_attr_boot_sound.attr, &dev_attr_panel_od.attr, @@ -4414,19 +4238,33 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, ok = asus->fan_boost_mode_available; else if (attr == &dev_attr_throttle_thermal_policy.attr) ok = asus->throttle_thermal_policy_available; - else if (attr == &dev_attr_ppt_pl2_sppt.attr) + else if (attr == &dev_attr_ppt_pl2_sppt.attr + || attr == &dev_attr_ppt_pl2_sppt_min.attr + || attr == &dev_attr_ppt_pl2_sppt_max.attr) devid = ASUS_WMI_DEVID_PPT_PL2_SPPT; - else if (attr == &dev_attr_ppt_pl1_spl.attr) + else if (attr == &dev_attr_ppt_pl1_spl.attr + || attr == &dev_attr_ppt_pl1_spl_min.attr + || attr == &dev_attr_ppt_pl1_spl_max.attr) devid = ASUS_WMI_DEVID_PPT_PL1_SPL; - else if (attr == &dev_attr_ppt_fppt.attr) + else if (attr == &dev_attr_ppt_fppt.attr + || attr == &dev_attr_ppt_fppt_min.attr + || attr == &dev_attr_ppt_fppt_max.attr) devid = ASUS_WMI_DEVID_PPT_FPPT; - else if (attr == &dev_attr_ppt_apu_sppt.attr) + else if (attr == &dev_attr_ppt_apu_sppt.attr + || attr == &dev_attr_ppt_apu_sppt_min.attr + || attr == &dev_attr_ppt_apu_sppt_max.attr) devid = ASUS_WMI_DEVID_PPT_APU_SPPT; - else if (attr == &dev_attr_ppt_platform_sppt.attr) + else if (attr == &dev_attr_ppt_platform_sppt.attr + || attr == &dev_attr_ppt_platform_sppt_min.attr + || attr == &dev_attr_ppt_platform_sppt_max.attr) devid = ASUS_WMI_DEVID_PPT_PLAT_SPPT; - else if (attr == &dev_attr_nv_dynamic_boost.attr) + else if (attr == &dev_attr_nv_dynamic_boost.attr + || attr == &dev_attr_nv_dynamic_boost_min.attr + || attr == &dev_attr_nv_dynamic_boost_max.attr) devid = ASUS_WMI_DEVID_NV_DYN_BOOST; - else if (attr == &dev_attr_nv_temp_target.attr) + else if (attr == &dev_attr_nv_temp_target.attr + || attr == &dev_attr_nv_temp_target_min.attr + || attr == &dev_attr_nv_temp_target_max.attr) devid = ASUS_WMI_DEVID_NV_THERM_TARGET; else if (attr == &dev_attr_mcu_powersave.attr) devid = ASUS_WMI_DEVID_MCU_POWERSAVE; @@ -4652,6 +4490,77 @@ static void asus_wmi_debugfs_init(struct asus_wmi *asus) /* Init / exit ****************************************************************/ +/* Set up the min/max and defaults for ROG tunables */ +static void init_rog_tunables(struct asus_wmi *asus) +{ + const char *product; + u32 max_boost = NVIDIA_BOOST_MAX; + u32 cpu_default = PPT_CPU_LIMIT_DEFAULT; + u32 cpu_max = PPT_CPU_LIMIT_MAX; + u32 platform_default = PPT_PLATFORM_DEFAULT; + u32 platform_max = PPT_PLATFORM_MAX; + + /* + * ASUS product_name contains everything required, e.g, + * "ROG Flow X16 GV601VV_GV601VV_00185149B" + */ + product = dmi_get_system_info(DMI_PRODUCT_NAME); + + if (strstr(product, "GA402R")) { + cpu_default = 125; + } else if (strstr(product, "13QY")) { + cpu_max = 250; + } else if (strstr(product, "X13")) { + cpu_max = 75; + cpu_default = 50; + } else if (strstr(product, "RC71")) { + cpu_max = 50; + cpu_default = 30; + } else if (strstr(product, "G814") + || strstr(product, "G614") + || strstr(product, "G834") + || strstr(product, "G634")) { + cpu_max = 175; + } else if (strstr(product, "GA402X") + || strstr(product, "GA403") + || strstr(product, "FA507N") + || strstr(product, "FA507X") + || strstr(product, "FA707N") + || strstr(product, "FA707X")) { + cpu_max = 90; + } + + if (strstr(product, "GZ301ZE")) + max_boost = 5; + else if (strstr(product, "FX507ZC4")) + max_boost = 15; + else if (strstr(product, "GU605")) + max_boost = 20; + + /* ensure defaults for tunables */ + asus->rog_tunables.cpu_default = cpu_default; + asus->rog_tunables.cpu_max = cpu_max; + + asus->rog_tunables.platform_default = platform_default; + asus->rog_tunables.platform_max = platform_max; + + asus->rog_tunables.ppt_pl1_spl = cpu_default; + asus->rog_tunables.ppt_pl2_sppt = cpu_default; + asus->rog_tunables.ppt_apu_sppt = cpu_default; + + asus->rog_tunables.ppt_platform_sppt = platform_default; + asus->rog_tunables.ppt_fppt = platform_default; + + asus->rog_tunables.nv_boost_default = NVIDIA_BOOST_MAX; + asus->rog_tunables.nv_boost_max = max_boost; + asus->rog_tunables.nv_dynamic_boost = NVIDIA_BOOST_MIN; + + asus->rog_tunables.nv_temp_default = NVIDIA_TEMP_MAX; + asus->rog_tunables.nv_temp_max = NVIDIA_TEMP_MAX; + asus->rog_tunables.nv_temp_target = NVIDIA_TEMP_MIN; + +} + static int asus_wmi_add(struct platform_device *pdev) { struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver); @@ -4677,15 +4586,7 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_platform; - /* ensure defaults for tunables */ - asus->ppt_pl2_sppt = 5; - asus->ppt_pl1_spl = 5; - asus->ppt_apu_sppt = 5; - asus->ppt_platform_sppt = 5; - asus->ppt_fppt = 5; - asus->nv_dynamic_boost = 5; - asus->nv_temp_target = 75; - + init_rog_tunables(asus); asus->egpu_enable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_EGPU); asus->dgpu_disable_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_DGPU); asus->kbd_rgb_state_available = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_TUF_RGB_STATE); From patchwork Tue May 28 01:36:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675984 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 B6BD3EEDB; Tue, 28 May 2024 01:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860211; cv=none; b=ATgJ7I5XaAQrZtXzgYtANTFRWjuH6mFiiWIK33dxznu9gY0T/7L7z42u2WBln3uJC7tuTs6O58NLs/Nhu7ljQ5jSq3ooQRTBZ2huuJmE6LLlV08bliRJk9sigo2J/171yQ2kE3OlIyvCjxPdo/FuIXC08VG6d0ilgYWkCEJyn9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860211; c=relaxed/simple; bh=THpXRT3p/0C4OrepJEXq/5KRR9Y10IEXpmUMdwr0zeM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uMA/+1haE8vw5mGAa5M4LvoMxFvcfuG07OFozWH5Ce9tZMjaTv+ltnUYyLz7n04jLQC6/bQ2aLUx3moknNz25vpH5XM7sbsZVxpEcvRqNjFn8he9oQPUOLYq1wfPTtXzIlyxJiV3Z4dJaeCx2SPN0F3BTgDvKjgjamiWfLmVGUk= 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=BkS7uFZ1; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WN12QDGw; arc=none smtp.client-ip=103.168.172.145 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="BkS7uFZ1"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WN12QDGw" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id BC584138013D; Mon, 27 May 2024 21:36:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 27 May 2024 21:36:48 -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=fm2; t=1716860208; x= 1716946608; bh=1y5ZIKidcSJ1U8GECBO90D6MU52bNNu/qP9jzcpqqYw=; b=B kS7uFZ1iUJMkv1500v7ZpHoA2u9Fmw9+A9GDNL4+Nx5Wv31Od7rr5rnz/cdSIWtg kjdPfphYcdvWkPNFbnWVTVOVPfyn01GMJ8Mc9a4iTmmojXRjiMvG4H3WLlYnws0W 1CIjhs5O61wtNRbCskeMpdjYePr30cvDu0yNKXtigWDM2vjO2oNU+KwDYluRqNRJ SO0E4+ydCYkpeaDvBjnXZUMu3/8TuIFu7/REU7LfWoYfMvQwU72pOyDC1z1bk9h0 qVLlXkim6gCFddyVBRgTrul+iEY4Slzo/JybnvfgOBxL5lEEUCam+JfA2ir4c2ox XCyHuMc/lDgYpOHgavndA== 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=fm1; t=1716860208; x= 1716946608; bh=1y5ZIKidcSJ1U8GECBO90D6MU52bNNu/qP9jzcpqqYw=; b=W N12QDGwO6IEtfEHx76CwupHnm5gqyReJxRohyc7e10bfFrczar71LPQlFTWJh8ca lmWTlIyV5JfZ24T8cR4Hkjmq0hBaCXbqDP46/EmYdraiGb4kgJs1oiOd4dFejpUs bN192GCO7Y+hOqQNhnSCOstqqWAUQgoy8pNbD/OfbWvNXcibXvp/j0PbceD7wJcJ M1smHbRTZJW17QUb1Bl2QT195pgGmfLDYKXZw6THKTRubmZjscSr0bpdKS+VQ7XG w53YInotILCH9fmIfufhe8w/wwpsPOYMhBfA3RewtbNJtEk4iO++0wkmq51RXLXI kAaD0A0WBbTwoz+aQWnmg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepuden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:36:45 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 4/9] platform/x86: asus-wmi: reduce code duplication with macros Date: Tue, 28 May 2024 13:36:21 +1200 Message-ID: <20240528013626.14066-5-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Over time many default patterns have emerged while adding functionality. This patch consolidates those patterns in to a few macros to remove a lot of copy/paste, and make it easier to add more of the same style of features in the future. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 215 ++++++-------------------------- 1 file changed, 38 insertions(+), 177 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index d016acb23789..5c03e28ff252 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -676,7 +676,7 @@ static void asus_wmi_input_exit(struct asus_wmi *asus) static ssize_t rog_tunable_store(struct asus_wmi *asus, struct attribute *attr, const char *buf, size_t count, - u32 min, u32 max, u32 defaultv, + u32 min, u32 max, int defaultv, u32 *store_value, u32 wmi_dev) { int result, err, value; @@ -685,7 +685,7 @@ static ssize_t rog_tunable_store(struct asus_wmi *asus, if (result) return result; - if (value == -1 ) + if (value == -1 && defaultv != -1) value = defaultv; if (value < min || value > max) return -EINVAL; @@ -708,6 +708,36 @@ static ssize_t rog_tunable_store(struct asus_wmi *asus, return count; } +#define WMI_SIMPLE_STORE(_fname, _min, _max, _wmi) \ +static ssize_t _fname##_store(struct device *dev, \ + struct device_attribute *attr, const char *buf, size_t count) \ +{ \ + struct asus_wmi *asus = dev_get_drvdata(dev); \ + return rog_tunable_store(asus, &attr->attr, buf, count, \ + _min, _max, -1, NULL, _wmi); \ +} + +#define WMI_SIMPLE_SHOW(_fname, _fmt, _wmi) \ +static ssize_t _fname##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + struct asus_wmi *asus = dev_get_drvdata(dev); \ + u32 result; \ + asus_wmi_get_devstate(asus, _wmi, &result); \ + if (result < 0) \ + return result; \ + return sysfs_emit(buf, _fmt, result & ~ASUS_WMI_DSTS_PRESENCE_BIT); \ +} + +#define WMI_ATTR_SIMPLE_RW(_fname, _minv, _maxv, _wmi) \ +WMI_SIMPLE_STORE(_fname, _minv, _maxv, _wmi); \ +WMI_SIMPLE_SHOW(_fname, "%d\n", _wmi); \ +static DEVICE_ATTR_RW(_fname) + +#define WMI_ATTR_SIMPLE_RO(_fname, _wmi) \ +WMI_SIMPLE_SHOW(_fname, "%d\n", _wmi); \ +static DEVICE_ATTR_RO(_fname) + #define ROG_TUNABLE_STORE(_fname, _min, _max, _default, _wmi) \ static ssize_t _fname##_store(struct device *dev, \ struct device_attribute *attr, const char *buf, size_t count) \ @@ -761,6 +791,12 @@ ROG_ATTR_RW(nv_dynamic_boost, NVIDIA_BOOST_MIN, nv_boost_max, nv_boost_default, ASUS_WMI_DEVID_NV_DYN_BOOST); ROG_ATTR_RW(nv_temp_target, NVIDIA_TEMP_MIN, nv_temp_max, nv_temp_default, ASUS_WMI_DEVID_NV_THERM_TARGET); +/* Ally MCU Powersave */ +WMI_ATTR_SIMPLE_RW(mcu_powersave, 0, 1, ASUS_WMI_DEVID_MCU_POWERSAVE); +WMI_ATTR_SIMPLE_RO(egpu_connected, ASUS_WMI_DEVID_EGPU_CONNECTED); +WMI_ATTR_SIMPLE_RW(panel_od, 0, 1, ASUS_WMI_DEVID_PANEL_OD); +WMI_ATTR_SIMPLE_RW(boot_sound, 0, 1, ASUS_WMI_DEVID_BOOT_SOUND); +WMI_ATTR_SIMPLE_RO(charge_mode, ASUS_WMI_DEVID_CHARGE_MODE); /* Tablet mode ****************************************************************/ @@ -776,22 +812,6 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus) asus_wmi_tablet_sw_report(asus, result); } -/* Charging mode, 1=Barrel, 2=USB ******************************************/ -static ssize_t charge_mode_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result, value; - - result = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CHARGE_MODE, &value); - if (result < 0) - return result; - - return sysfs_emit(buf, "%d\n", value & 0xff); -} - -static DEVICE_ATTR_RO(charge_mode); - /* dGPU ********************************************************************/ static ssize_t dgpu_disable_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -925,22 +945,6 @@ static ssize_t egpu_enable_store(struct device *dev, } static DEVICE_ATTR_RW(egpu_enable); -/* Is eGPU connected? *********************************************************/ -static ssize_t egpu_connected_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result; - - result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU_CONNECTED); - if (result < 0) - return result; - - return sysfs_emit(buf, "%d\n", result); -} - -static DEVICE_ATTR_RO(egpu_connected); - /* gpu mux switch *************************************************************/ static ssize_t gpu_mux_mode_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -1128,53 +1132,6 @@ static const struct attribute_group *kbd_rgb_mode_groups[] = { NULL, }; -/* Ally MCU Powersave ********************************************************/ -static ssize_t mcu_powersave_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result; - - result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_MCU_POWERSAVE); - if (result < 0) - return result; - - return sysfs_emit(buf, "%d\n", result); -} - -static ssize_t mcu_powersave_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - int result, err; - u32 enable; - - struct asus_wmi *asus = dev_get_drvdata(dev); - - result = kstrtou32(buf, 10, &enable); - if (result) - return result; - - if (enable > 1) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_MCU_POWERSAVE, enable, &result); - if (err) { - pr_warn("Failed to set MCU powersave: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set MCU powersave (result): 0x%x\n", result); - return -EIO; - } - - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "mcu_powersave"); - - return count; -} -static DEVICE_ATTR_RW(mcu_powersave); - /* Battery ********************************************************************/ /* The battery maximum charging percentage */ @@ -2002,102 +1959,6 @@ static int asus_wmi_rfkill_init(struct asus_wmi *asus) return result; } -/* Panel Overdrive ************************************************************/ -static ssize_t panel_od_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result; - - result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_PANEL_OD); - if (result < 0) - return result; - - return sysfs_emit(buf, "%d\n", result); -} - -static ssize_t panel_od_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - int result, err; - u32 overdrive; - - struct asus_wmi *asus = dev_get_drvdata(dev); - - result = kstrtou32(buf, 10, &overdrive); - if (result) - return result; - - if (overdrive > 1) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_PANEL_OD, overdrive, &result); - - if (err) { - pr_warn("Failed to set panel overdrive: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set panel overdrive (result): 0x%x\n", result); - return -EIO; - } - - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "panel_od"); - - return count; -} -static DEVICE_ATTR_RW(panel_od); - -/* Bootup sound ***************************************************************/ - -static ssize_t boot_sound_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result; - - result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_BOOT_SOUND); - if (result < 0) - return result; - - return sysfs_emit(buf, "%d\n", result); -} - -static ssize_t boot_sound_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) -{ - int result, err; - u32 snd; - - struct asus_wmi *asus = dev_get_drvdata(dev); - - result = kstrtou32(buf, 10, &snd); - if (result) - return result; - - if (snd > 1) - return -EINVAL; - - err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BOOT_SOUND, snd, &result); - if (err) { - pr_warn("Failed to set boot sound: %d\n", err); - return err; - } - - if (result > 1) { - pr_warn("Failed to set panel boot sound (result): 0x%x\n", result); - return -EIO; - } - - sysfs_notify(&asus->platform_device->dev.kobj, NULL, "boot_sound"); - - return count; -} -static DEVICE_ATTR_RW(boot_sound); - /* Mini-LED mode **************************************************************/ static ssize_t mini_led_mode_show(struct device *dev, struct device_attribute *attr, char *buf) From patchwork Tue May 28 01:36:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675985 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 B3A9E1BDD5; Tue, 28 May 2024 01:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860214; cv=none; b=cCf0h97pg8ZZ8EwmGnTzYMNNOjGGgtTHSzasRKufmNXnnxi4Jwck2mD8ZCjPF0cAXzeGHyb9zHCMRyildGyD7b517QmNwEMMutWtNPEu/wjuwF0AmZ2Bk7mhvJAy+INGa/Qxb7t3JBkhp69WotIsDdrJx5duYVLTyixFYB++g2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860214; c=relaxed/simple; bh=ItassXh+AUFWJJQOX6KSfktnJt4TTmMNonwiy+/h+Zs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bPAIAQMRcT5R+4EqNKq5ZOZ5XJbAUnbrXUf4BVN6odGq48BLzlNF1gTy+Chwt4qOgSAjY773yodWjMK7mW3U+DrsZHPb9dHiA6QKE0MohGLtgHrjS+ayik7zmbO6XGlBSprK7g1Xs0C16Nw0/9+lV2W/tMc0RIdX+zcIao1bsj4= 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=WFyaHz7J; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dPPNYM2x; arc=none smtp.client-ip=103.168.172.159 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="WFyaHz7J"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dPPNYM2x" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id C79BC11400E2; Mon, 27 May 2024 21:36:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 27 May 2024 21:36:51 -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=fm2; t=1716860211; x= 1716946611; bh=hORT7ngd02w+eotRPxOFI1MpB1jcIPhVVq4sYj5WU7k=; b=W FyaHz7JWJMD+s+0nNy9FpUgBjNpDq7zaDks2ThFjWNpExS2+WzqAMeOn8Znh8ajK 6g8p2CImVwInvl3I4kzGCLWa7M0igS531+MulVccIj0WObZlIP0cqwScTICxEv7K d/aEVL5gRj5WpO2gusK0Yp0UkIvluvwMeLOobuqFKOtqo/FL09DVj3AuZoqIbY9k sS3TIYXKClttUB9HWz5uw9bRqxmr10hGHIz/CSVhueOdXEQWp+EBiRv25/IACYYo XlmrOKz1OFviTWL9KbGLGftR7Goxwk9J7pRVV1+aRA6p+y+kUDIerFreXUrlDiOi jr0mWKSPpGd/32TG8/HyQ== 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=fm1; t=1716860211; x= 1716946611; bh=hORT7ngd02w+eotRPxOFI1MpB1jcIPhVVq4sYj5WU7k=; b=d PPNYM2xIrR6ZZXuIR2JF2EnYEtd3QVywT8LMGydPtO9QWF9/EOOG3+RHq6hZvOZg BIeMvbZOEfBDYzWyOQRdLuFvXwaaNmBRSICNbYpwGj1k6K2yjviVvhliSEc/7N2X D4J4H5bZ4QIKKVHplGJiqOHzJbKdyRqlu1jl3wlWxfqSXwDQJyfT0R+SFp4I1AeP WCTrILLehUKV6OzyLmPL9uWAHRkplYHHBs3qliVbfCtqgu/fG5SS21i9bPnSwnLd iynDFGNkyinymGbM8RRhtv9Pu8CHogFacuwjUUxWLyNVbJ5unTq8S3Zte2+1Ehkn t1EIZ9TFja+YSTWbnt1QA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:36:49 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 5/9] platform/x86: asus-wmi: use WMI_SIMPLE_SHOW in more places Date: Tue, 28 May 2024 13:36:22 +1200 Message-ID: <20240528013626.14066-6-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Further reduce code duplication by using the new macros in a few more places. Signed-off-by: Luke D. Jones --- drivers/platform/x86/asus-wmi.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 5c03e28ff252..260548aa6a42 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -813,19 +813,6 @@ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus) } /* dGPU ********************************************************************/ -static ssize_t dgpu_disable_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result; - - result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_DGPU); - if (result < 0) - return result; - - return sysfs_emit(buf, "%d\n", result); -} - /* * A user may be required to store the value twice, typcial store first, then * rescan PCI bus to activate power, then store a second time to save correctly. @@ -875,22 +862,11 @@ static ssize_t dgpu_disable_store(struct device *dev, return count; } + +WMI_SIMPLE_SHOW(dgpu_disable, "%d\n", ASUS_WMI_DEVID_DGPU); static DEVICE_ATTR_RW(dgpu_disable); /* eGPU ********************************************************************/ -static ssize_t egpu_enable_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct asus_wmi *asus = dev_get_drvdata(dev); - int result; - - result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_EGPU); - if (result < 0) - return result; - - return sysfs_emit(buf, "%d\n", result); -} - /* The ACPI call to enable the eGPU also disables the internal dGPU */ static ssize_t egpu_enable_store(struct device *dev, struct device_attribute *attr, @@ -943,6 +919,8 @@ static ssize_t egpu_enable_store(struct device *dev, return count; } + +WMI_SIMPLE_SHOW(egpu_enable, "%d\n", ASUS_WMI_DEVID_EGPU); static DEVICE_ATTR_RW(egpu_enable); /* gpu mux switch *************************************************************/ From patchwork Tue May 28 01:36:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675986 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 DD31322313; Tue, 28 May 2024 01:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860217; cv=none; b=tzBJOL3RsQ2nEPMD10IhsQ0LxPY5nkgkJ2nkmbRaRYc0Hety5qg8LfnlPUyImwIJA/xQHD5pJi+VJFypSwUVyqy6eqzxc7z4/+i3hFR4mNQfOnjLui2fXYzo0p/soExh5uRFvCMBqaYyeSJStcXXdn6tpVJJbmtSYzesjiPZBTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860217; c=relaxed/simple; bh=zOvd3Ay0azx5vH/QyN7mBktkv8CR/XnOIiqvECdvHVw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=haSzOqB5fOlfBT8+6x8CRZk8CMvqWlPegld8yBNsLAs3WoLs9LMpLyrzz9FNk2ENh5TDwAZCXBbd9wEVEcEV/5QvMsOv0/ZCbcZoYuryig8ekM8kmhnCX855ikgP6Ke89jtH/iPQla1bzRRlGjJxAsXYFdyR8tkire63eVOEq7Q= 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=cHIueFw4; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WjrlEKKt; arc=none smtp.client-ip=103.168.172.145 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="cHIueFw4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WjrlEKKt" Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id F3102138013D; Mon, 27 May 2024 21:36:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 27 May 2024 21:36:54 -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=fm2; t=1716860214; x= 1716946614; bh=kwPWX6tvrCbhVRU7E4dBQZXhLYs4bJ8/JTWq8BfSECA=; b=c HIueFw4tmcsP3Unsn1qs9wdhUSV69yCh9YBw8NqYP+icm9Yx4vVBvAXWagQygkfN jbOqddgkWK59L2J5t2+R0do8+6wUt/XvsCC234S7fY8fHXB16EAENqgBRiRFju9a PvVtapmZNIDlQZvKBEMbtXrdC5+RlIsJL5BIeGiHjJuklCw277cnwvXq0dQkVcJ9 p+JoFOJ0nwdB+OMX6JG6CtZdNN7vdJyyhcIo9vLZj4KnsgbA+7PVBwzerWOu/Wm8 9QtWIbIvRRm0PJmwkl/2n74Ayor7snAcg25KlqEWGb6l7RUhBvIRj1wl9VyZgXJu u6SyI3jRA9z7Ejd/1AJdA== 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=fm1; t=1716860214; x= 1716946614; bh=kwPWX6tvrCbhVRU7E4dBQZXhLYs4bJ8/JTWq8BfSECA=; b=W jrlEKKtC1XHKgRdNBCrRRMX4Nj1ycxd1U7NMrXHdLFGsIUuD+bIpAzGJkUeoJWkn 7kix+L/AIUl2iSpMksXSkvjc3BfG/TEPsKRZlojKCklqxFb7wFOZ/P9mHBvPZxW0 R8u5K1QxxCVBEhc/Rj1Jzv+dGj6hM8gLjWN3HY+BgW39CLamFghtgaa+CXRsLTdm tq4uXM82jdry8+nFXt1W0/QZDnS3GiYas61YqmqXWQMB3846H2s5nonpcVDchqXH 3cmawF/jrkhs5wxL5rD0h7efYJaJMFRpAhAPYuD4PRbTGN8ni15LjJH1S1A5IJN1 UsHA1YeP9ctV+hM0mpScQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepvden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:36:52 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 6/9] platform/x86: asus-wmi: add panel-fhd functionality Date: Tue, 28 May 2024 13:36:23 +1200 Message-ID: <20240528013626.14066-7-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Exposes the FHD panel toggle avavilable on new ASUS Duo laptops. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 9 +++++++++ drivers/platform/x86/asus-wmi.c | 20 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 1 + 3 files changed, 30 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 984a04f32fd0..3b4eeea75b7b 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -217,3 +217,12 @@ Description: Set if the MCU can go in to low-power mode on system sleep * 0 - False, * 1 - True + +What: /sys/devices/platform//panel_fhd +Date: Apr 2024 +KernelVersion: 6.11 +Contact: "Luke Jones" +Description: + Set panel to UHD or FHD mode + * 0 - UHD, + * 1 - FHD diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 260548aa6a42..4b045f1828f1 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -798,6 +798,23 @@ WMI_ATTR_SIMPLE_RW(panel_od, 0, 1, ASUS_WMI_DEVID_PANEL_OD); WMI_ATTR_SIMPLE_RW(boot_sound, 0, 1, ASUS_WMI_DEVID_BOOT_SOUND); WMI_ATTR_SIMPLE_RO(charge_mode, ASUS_WMI_DEVID_CHARGE_MODE); +static ssize_t panel_fhd_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int err; + + err = rog_tunable_store(asus, &attr->attr, buf, count, + 0, 1, -1, NULL, ASUS_WMI_DEVID_PANEL_FHD); + if (err < 0) + return err; + + pr_info("Panel UHD/FHD display mode changed, reboot required\n"); + return count; +} +WMI_SIMPLE_SHOW(panel_fhd, "%d\n", ASUS_WMI_DEVID_PANEL_FHD); +static DEVICE_ATTR_RW(panel_fhd); + /* Tablet mode ****************************************************************/ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus) @@ -4040,6 +4057,7 @@ static struct attribute *platform_attributes[] = { &dev_attr_mcu_powersave.attr, &dev_attr_boot_sound.attr, &dev_attr_panel_od.attr, + &dev_attr_panel_fhd.attr, &dev_attr_mini_led_mode.attr, &dev_attr_available_mini_led_mode.attr, NULL @@ -4111,6 +4129,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, devid = ASUS_WMI_DEVID_BOOT_SOUND; else if (attr == &dev_attr_panel_od.attr) devid = ASUS_WMI_DEVID_PANEL_OD; + else if (attr == &dev_attr_panel_fhd.attr) + devid = ASUS_WMI_DEVID_PANEL_FHD; else if (attr == &dev_attr_mini_led_mode.attr) ok = asus->mini_led_dev_id != 0; else if (attr == &dev_attr_available_mini_led_mode.attr) diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 79a50102440d..6c51d41ffc20 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -72,6 +72,7 @@ #define ASUS_WMI_DEVID_LID_FLIP_ROG 0x00060077 #define ASUS_WMI_DEVID_MINI_LED_MODE 0x0005001E #define ASUS_WMI_DEVID_MINI_LED_MODE2 0x0005002E +#define ASUS_WMI_DEVID_PANEL_FHD 0x0005001C /* Storage */ #define ASUS_WMI_DEVID_CARDREADER 0x00080013 From patchwork Tue May 28 01:36:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675987 Received: from fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 1C3AF2E639; Tue, 28 May 2024 01:36:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.159 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860220; cv=none; b=sVOQjt6tTSNiOjA/Qp9RsOCinBcrmeoCLwOQLfV6B8IF0oAyBHd5YUQcCVqcm+00cUEbogPs+gX3Mi6c9heU/E5eq1uYRDxPwuZC+SgjkfmSx2WI8F4Tt/LZKftbvDjSO+hcZJhkR4U3wKuErQMWQiOnAs2llNsG68kZVqha7RY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860220; c=relaxed/simple; bh=mU1fHPbcvCL79A8RD2hsHX8ghHV0CAXO5Lop4WuvoV4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DauG43eMq7p4tSQJ43gYKpFkARMqlPMJv8RVLUCCAJ0MOyCY/6SEZdC6HKWipILSmoDmXNe9zYTPQLnJugPWniuaPN1JTSLnqhy2qA0LTpSavmbKiZmlqspxr8OS9f385XUP2BlQedMxkPXZOSGHhdOi8AtDe7B95+oj4r+FL6A= 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=Uz6yH8Ar; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=O1e7sOWx; arc=none smtp.client-ip=103.168.172.159 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="Uz6yH8Ar"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="O1e7sOWx" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 2FDFE11400FC; Mon, 27 May 2024 21:36:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 27 May 2024 21:36:58 -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=fm2; t=1716860218; x= 1716946618; bh=LJxcABA35wyl1DVjJ0uvxKmcEBlfef0iX30/mEprlhM=; b=U z6yH8Argq9077FU2VllIpX01taHSLxljS9YkDHQT4FyfwSbXPJdwFdy7MiFI1/S6 i1RLd2VD+IjKGi0vnJ4q3dV1SoarzPln0Ge6+7+AUcM/9Dj5mFI9hvny7s2Njc8f B8xqMA/7PVELmY9+epM1TqP1pCWFWkjydMmKQ3+uM/SeLRqWzln62cP2Ezz1RUe8 SHP1w7bu0sLSslBDyEzt0/HgNB0nNjcuFIcSZboqeTJadGKv0KvUy0cNIQHEvUvy QZV0Pq/Vm7aSd8xNt+bze61Ix3TJbBSjVzAWPJ0bl+bd8DXWcccMnoiPm1g1A17T celugjL80dulkrtVmukZg== 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=fm1; t=1716860218; x= 1716946618; bh=LJxcABA35wyl1DVjJ0uvxKmcEBlfef0iX30/mEprlhM=; b=O 1e7sOWxFFw2YNqu8qiLTvfZRe+ZVOrL4eoqMIyDfYg8uHnV20ypqCv7zA83RgOk2 nBX4Sk8gdsBK3pJ6eMpIErks2Dt34+qxsfL6ohXxDM4huyFezhPadZqXwuYFJt6p 7/YBu+xhRpcnsjP/Khp4oHez/sbpyL+xIpZ+vAieA2PyJuYGMq2Fm517d08oNn5Q JQAjvcZHpNzyjKTKqLt1gj3ahxoHbGr3Ve2UyB0U6x2mRYlFBW/2es2rLhNXBR5S ktzSpTK0PwdKrp2DyZ8gafkNwnvJWk8tgpuyRCgTUZ8+Xh96AN4Ovta1givOfaLj HUuqrfAYEcUzpw4o82yXw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:36:55 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 7/9] platform/x86: asus-wmi: add enable/disable CPU cores Date: Tue, 28 May 2024 13:36:24 +1200 Message-ID: <20240528013626.14066-8-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Exposes the WMI functions for enable/disable of performance and efficiency cores on some laptop models (largely Intel only). Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 19 ++++++++ drivers/platform/x86/asus-wmi.c | 45 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 5 +++ 3 files changed, 69 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index 3b4eeea75b7b..ac881e72e374 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -226,3 +226,22 @@ Description: Set panel to UHD or FHD mode * 0 - UHD, * 1 - FHD + +What: /sys/devices/platform//cores_enabled +Date: Jun 2024 +KernelVersion: 6.11 +Contact: "Luke Jones" +Description: + Enable/disable efficiency and performance cores. The format is + 0x[E][P] where [E] is the efficiency core count, and [P] is + the perfromance core count. If the core count is a single digit + it is preceded by a 0 such as 0x0406; E=4, P=6, 0x1006; E=10, P=6 + +What: /sys/devices/platform//cores_max +Date: Jun 2024 +KernelVersion: 6.11 +Contact: "Luke Jones" +Description: + Show the maximum performance and efficiency core countin format + 0x[E][P] where [E] is the efficiency core count, and [P] is + the perfromance core count. diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 4b045f1828f1..f62a36dfcd4b 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -815,6 +815,46 @@ static ssize_t panel_fhd_store(struct device *dev, WMI_SIMPLE_SHOW(panel_fhd, "%d\n", ASUS_WMI_DEVID_PANEL_FHD); static DEVICE_ATTR_RW(panel_fhd); +/* Efficiency and Performance core control **********************************/ +static ssize_t cores_enabled_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int result, err; + u32 cores, max; + + result = kstrtou32(buf, 16, &cores); + if (result) + return result; + + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_CORES_MAX, &max); + if (err < 0) + return err; + + if (cores > max) { + pr_warn("Core count 0x%x exceeds max: 0x%x\n", cores, max); + return -EIO; + } + + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_CORES_SET, cores, &result); + if (err) { + pr_warn("Failed to set cores_enabled: %d\n", err); + return err; + } + + pr_info("Enabled core count changed, reboot required\n"); + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "cores_enabled"); + + return count; +} + +WMI_SIMPLE_SHOW(cores_enabled, "0x%x\n", ASUS_WMI_DEVID_CORES_SET); +static DEVICE_ATTR_RW(cores_enabled); + +WMI_SIMPLE_SHOW(cores_max, "0x%x\n", ASUS_WMI_DEVID_CORES_MAX); +static DEVICE_ATTR_RO(cores_max); + /* Tablet mode ****************************************************************/ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus) @@ -4058,6 +4098,8 @@ static struct attribute *platform_attributes[] = { &dev_attr_boot_sound.attr, &dev_attr_panel_od.attr, &dev_attr_panel_fhd.attr, + &dev_attr_cores_enabled.attr, + &dev_attr_cores_max.attr, &dev_attr_mini_led_mode.attr, &dev_attr_available_mini_led_mode.attr, NULL @@ -4131,6 +4173,9 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, devid = ASUS_WMI_DEVID_PANEL_OD; else if (attr == &dev_attr_panel_fhd.attr) devid = ASUS_WMI_DEVID_PANEL_FHD; + else if (attr == &dev_attr_cores_enabled.attr + || attr == &dev_attr_cores_max.attr) + ok = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CORES_SET); else if (attr == &dev_attr_mini_led_mode.attr) ok = asus->mini_led_dev_id != 0; else if (attr == &dev_attr_available_mini_led_mode.attr) diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 6c51d41ffc20..5a56e7e97785 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -116,6 +116,11 @@ /* Charging mode - 1=Barrel, 2=USB */ #define ASUS_WMI_DEVID_CHARGE_MODE 0x0012006C +/* Intel E-core and P-core configuration in a format 0x0[E]0[P] */ +#define ASUS_WMI_DEVID_CORES_SET 0x001200D2 + /* Maximum Intel E-core and P-core availability */ +#define ASUS_WMI_DEVID_CORES_MAX 0x001200D3 + /* MCU powersave mode */ #define ASUS_WMI_DEVID_MCU_POWERSAVE 0x001200E2 From patchwork Tue May 28 01:36:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675988 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 EFFEB38384; Tue, 28 May 2024 01:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860223; cv=none; b=TNmPDs5KcwKPV57JAZF1OPPjMdfA2V26ogpoor+598pbZG/Q7AX/HDRLJQ0nwZYGga+pk/2ZlNbWNjlm6ic/+GHGEpoyjxfjEK9NDbRUEDNMS+huU8nhL35yt8SaRYS86iMQbOfpbeVSBvK/kNOFqNJPYhzkEefvjqn9gmigkLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860223; c=relaxed/simple; bh=pnyI+9VMiEw1nDcnYNO2We4ATRr2OD2ScBuTROS++u0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ir/SGLbrU6NTSin1nYyuBalW6771q7jxv8e8FXaKP7jiv1r/CNBxCLF9n7Zh6qKbRC2Eaf2NoqHn/Eqm+x14xX/eMRomJR3g+y+Jz4eZpjsyK7wvxnMp1FWMQGqK3T2ytGD7ZftvQikKqoe0XyjTihcOyiz/Xo4XjacPbBXQTdQ= 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=h11d5Eop; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=K6tNPcWJ; arc=none smtp.client-ip=103.168.172.145 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="h11d5Eop"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="K6tNPcWJ" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id 43765138013A; Mon, 27 May 2024 21:37:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Mon, 27 May 2024 21:37:01 -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=fm2; t=1716860221; x= 1716946621; bh=u5wq2d1siVqqrNhbDvRTA1dC/Z6z6yq6CB526Lgu2e0=; b=h 11d5EopzWbohWYtyK5fve5fE8qdoyHP6jdjHju52mWa+mqby5b9IyG+TZsE71uAR 6YSyJ1mrH4VjQdvCWXqmgxKZtFZdiHjYl466kqeAkH5sjmcplszbfb96+4pnZNwX XgzYhpbsQutoBQauKaj6mrk6gypQiuTWvJ7QmGpCiswg8olFVH+gLvWcUxktBhD7 vjaR1qWVlOkucHZFFzsFjUypAavwT6kWoFl851lO/diYEjeOxfBiEVfPNR39qnuH 2NxIooUCqQndkxTbQlo45V0PoW8of2fu3bcnKB7f+mnDDZPpvCL/wZJLYzFE+WD0 EqlAxc1jes74020XYX6+w== 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=fm1; t=1716860221; x= 1716946621; bh=u5wq2d1siVqqrNhbDvRTA1dC/Z6z6yq6CB526Lgu2e0=; b=K 6tNPcWJLhYGDVEkQ8qeuGKWP4R4w47KxJFSFe6NLl+zPWHaLzANf3zz1ywGsuA9Y l2vAIFqRY8VRjHiaSPDSQdYy2QlrsxSID086yMQBi62rcbmnZMj7XLZ5xc0WNJD2 y1eCLE5GFf04SEdtB/jIr2ut+g9L3TUlnot4FglBMZksXfi4+TvbSW2sGLFuywqt adgJpuoxukhToG/I+6dvMjMvLbaJwX/e+PJwcqaKAe+m0X5t/lvp87adWPBuFokU ex5eCUk63h+dClGUxN5f7GMSQlnXDMBQ4HM2K8yY6Co6MgsbcjzQ+Cye5yeGSkoY 40/nEqjpES7WnGH7cCFmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgepuden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:36:58 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 8/9] platform/x86: asus-wmi: add apu_mem setting Date: Tue, 28 May 2024 13:36:25 +1200 Message-ID: <20240528013626.14066-9-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Exposes the APU memory setting available on a few ASUS models such as the ROG Ally. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 8 ++ drivers/platform/x86/asus-wmi.c | 109 ++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 + 3 files changed, 120 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index ac881e72e374..d221a3bc1a81 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -245,3 +245,11 @@ Description: Show the maximum performance and efficiency core countin format 0x[E][P] where [E] is the efficiency core count, and [P] is the perfromance core count. + +What: /sys/devices/platform//apu_mem +Date: Jun 2024 +KernelVersion: 6.11 +Contact: "Luke Jones" +Description: + Set the maximum available system memory for the APU. + * Min=0, Max=8 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index f62a36dfcd4b..4b5fbae8c563 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -855,6 +855,112 @@ static DEVICE_ATTR_RW(cores_enabled); WMI_SIMPLE_SHOW(cores_max, "0x%x\n", ASUS_WMI_DEVID_CORES_MAX); static DEVICE_ATTR_RO(cores_max); +/* Device memory available to APU */ + +static ssize_t apu_mem_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int err; + u32 mem; + + err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_APU_MEM, &mem); + if (err < 0) + return err; + + switch (mem) { + case 256: + mem = 0; + break; + case 258: + mem = 1; + break; + case 259: + mem = 2; + break; + case 260: + mem = 3; + break; + case 261: + mem = 4; + break; + case 262: + mem = 8; + break; + case 263: + mem = 5; + break; + case 264: + mem = 6; + break; + case 265: + mem = 7; + break; + default: + mem = 4; + break; + } + + return sysfs_emit(buf, "%d\n", mem); +} + +static ssize_t apu_mem_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct asus_wmi *asus = dev_get_drvdata(dev); + int result, err; + u32 mem; + + result = kstrtou32(buf, 10, &mem); + if (result) + return result; + + switch (mem) { + case 0: + mem = 0; + break; + case 1: + mem = 258; + break; + case 2: + mem = 259; + break; + case 3: + mem = 260; + break; + case 4: + mem = 261; + break; + case 5: + mem = 263; + break; + case 6: + mem = 264; + break; + case 7: + mem = 265; + break; + case 8: + mem = 262; + break; + default: + return -EIO; + } + + err = 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, reboot required\n"); + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "apu_mem"); + + return count; +} +static DEVICE_ATTR_RW(apu_mem); + /* Tablet mode ****************************************************************/ static void asus_wmi_tablet_mode_get_state(struct asus_wmi *asus) @@ -4100,6 +4206,7 @@ static struct attribute *platform_attributes[] = { &dev_attr_panel_fhd.attr, &dev_attr_cores_enabled.attr, &dev_attr_cores_max.attr, + &dev_attr_apu_mem.attr, &dev_attr_mini_led_mode.attr, &dev_attr_available_mini_led_mode.attr, NULL @@ -4176,6 +4283,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, else if (attr == &dev_attr_cores_enabled.attr || attr == &dev_attr_cores_max.attr) ok = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CORES_SET); + else if (attr == &dev_attr_apu_mem.attr) + ok = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_APU_MEM); else if (attr == &dev_attr_mini_led_mode.attr) ok = asus->mini_led_dev_id != 0; else if (attr == &dev_attr_available_mini_led_mode.attr) diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index 5a56e7e97785..efe608861e55 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -121,6 +121,9 @@ /* Maximum Intel E-core and P-core availability */ #define ASUS_WMI_DEVID_CORES_MAX 0x001200D3 +/* Set the memory available to the APU */ +#define ASUS_WMI_DEVID_APU_MEM 0x000600C1 + /* MCU powersave mode */ #define ASUS_WMI_DEVID_MCU_POWERSAVE 0x001200E2 From patchwork Tue May 28 01:36:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Jones X-Patchwork-Id: 13675989 Received: from fout2-smtp.messagingengine.com (fout2-smtp.messagingengine.com [103.168.172.145]) (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 6F8523AC16; Tue, 28 May 2024 01:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.145 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860226; cv=none; b=cS7TcyBfbeks+IPMDU1X9XySIJz/OAiPbpB/169chOkaPobsXrqHE0ooKzHRUlJLe7eeWtee+V0xr5nW6kgPnLul6EBdMTOSFE2EzWR3pSRu/B5Kd2U+Lmma+uwinjChzi2dM0AFohKkfu2NniZjbAVeCsx3q5QDvFTk5y/T/Ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716860226; c=relaxed/simple; bh=aIav+5EECdqbJcYjdH5A+4TUj/fYjbell3xkt46zAls=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JWsHyv9FKLhz7CsmbNXTZaWd6KgKtHCCQnrqKw3IkgW3enhE2UtaAXE80b4FF0RgZ3x11KMN6WVS6lIy9b5pi0AslK46COI+AK5tSgBUkZL3JSbK4MD4YoaJlHZincG6wodxnJH+lzYUhCI6PuSISB10lYHpWkOLV4xVGvbG5FI= 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=CMOEec67; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=JD2WTgaR; arc=none smtp.client-ip=103.168.172.145 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="CMOEec67"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JD2WTgaR" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 8F0B51380142; Mon, 27 May 2024 21:37:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 27 May 2024 21:37:04 -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=fm2; t=1716860224; x= 1716946624; bh=oUbMKxb/AnzUhw3GvwikoRj656Q1cIKAuZQGKv+i05A=; b=C MOEec67Cywe9myr1q0v3AhliuPSqC3/HcbZzcCBthK/vUxcUPZKn1HxPv134QkyB U2uCoaV4CXFo0sqUWsvIHRFvecsCrLncBjbtzDRUZDs6xr8u0EiGIovja1Or6RIl U6UjLHlpDkM2WmmS0f7yITJaIDzrFRWeo9ssiP2zEfb6YuaZKM4rZkDSiOKx0fbA G+B0Ff2gllI8coFUEOPcX4VlYcGu9f+dpyU+5arXyqmev4z/dBrqR9ITSrGoEG0K Xp0ANRYFZiPHPlCZce+esI8OrziLxTNCI3CipMM+6oA8DLuWpsKOgwjdTFcY5fX0 V6XJDJ2QLW9Yh3fgxHPEw== 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=fm1; t=1716860224; x= 1716946624; bh=oUbMKxb/AnzUhw3GvwikoRj656Q1cIKAuZQGKv+i05A=; b=J D2WTgaRELGS+RFOX6D/oY41aMTL7Jad52P2wJdGsRLn6dEHjqQ31l3Z3E2Z+JWU5 cJwYbUAbWDzeYLgfPkC4IXObC1100vJyztmMFhE0Dur6A5iI/f1Tdz0BTqvkawWk QMcvljOn32e25Y4y0TTJ35r2PX/VjFwETpxyj1EE0pWtgr/mP7F40zyZoKY6/Tw6 WIr80INf3Cii0KcUfsroMQlFc9doT4bBFIhnJHoCB4GA74hxK+js0hAxavturfYD DFOV2PvBv5KOA5g1wlc/1z+j8BDDhj+tCAGY4J7M4PXQC6FjvcTknYs2L0h+iUzb pgxN8469U+vZ7bl0pi2NA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdejhedggeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 May 2024 21:37:01 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: ilpo.jarvinen@linux.intel.com, corentin.chary@gmail.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH 9/9] platform/x86: asus-wmi: add setting dGPU TGP Date: Tue, 28 May 2024 13:36:26 +1200 Message-ID: <20240528013626.14066-10-luke@ljones.dev> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528013626.14066-1-luke@ljones.dev> References: <20240528013626.14066-1-luke@ljones.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The dGPU TGP can be set on a few ROG laptops. This gnerally needs some extra userspace inference to find the base and limit: - Find max-tgp from nvidia-smi - Find max-boost from nv_dynamic_boost_max (asus_wmi) - (max-tgp - max-boost - initial TGP) = base TGP - (max-tgp - max-boost - base TGP) = max additional TGP On some laptops the dgpu_base_tgp may return 0, in which case the base TGP must be derived as above. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 19 +++++++++++++++++++ drivers/platform/x86/asus-wmi.c | 9 +++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 +++ 3 files changed, 31 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentation/ABI/testing/sysfs-platform-asus-wmi index d221a3bc1a81..46df3452c9da 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -253,3 +253,22 @@ Contact: "Luke Jones" Description: Set the maximum available system memory for the APU. * Min=0, Max=8 + +What: /sys/devices/platform//dgpu_tgp +Date: Jun 2024 +KernelVersion: 6.11 +Contact: "Luke Jones" +Description: + Read and set the extra TGP applied to the dGPU. This is applied on + top of the dgpu_base_tgp. + + If the dGPU maximum power including boost is 175 then we can calculate: + 175 - 25 (dynamic boost) - 70 (initial dgpu_tgp) = 80 (dgpu_base_tgp). + For NVIDIA dGPU the max power can be found with nvidia-smi. + +What: /sys/devices/platform//dgpu_base_tgp +Date: Jun 2024 +KernelVersion: 6.11 +Contact: "Luke Jones" +Description: + Read the absolute base TGP of the dGPU. diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 4b5fbae8c563..4d291429e7a1 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -123,6 +123,7 @@ module_param(fnlock_default, bool, 0444); #define NVIDIA_BOOST_MAX 25 #define NVIDIA_TEMP_MIN 75 #define NVIDIA_TEMP_MAX 87 +#define NVIDIA_GPU_POWER_MAX 70 #define ASUS_SCREENPAD_BRIGHT_MIN 20 #define ASUS_SCREENPAD_BRIGHT_MAX 255 @@ -797,6 +798,8 @@ WMI_ATTR_SIMPLE_RO(egpu_connected, ASUS_WMI_DEVID_EGPU_CONNECTED); WMI_ATTR_SIMPLE_RW(panel_od, 0, 1, ASUS_WMI_DEVID_PANEL_OD); WMI_ATTR_SIMPLE_RW(boot_sound, 0, 1, ASUS_WMI_DEVID_BOOT_SOUND); WMI_ATTR_SIMPLE_RO(charge_mode, ASUS_WMI_DEVID_CHARGE_MODE); +WMI_ATTR_SIMPLE_RO(dgpu_base_tgp, ASUS_WMI_DEVID_DGPU_BASE_TGP); +WMI_ATTR_SIMPLE_RW(dgpu_tgp, 0, NVIDIA_GPU_POWER_MAX, ASUS_WMI_DEVID_DGPU_SET_TGP); static ssize_t panel_fhd_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -4204,6 +4207,8 @@ static struct attribute *platform_attributes[] = { &dev_attr_boot_sound.attr, &dev_attr_panel_od.attr, &dev_attr_panel_fhd.attr, + &dev_attr_dgpu_base_tgp.attr, + &dev_attr_dgpu_tgp.attr, &dev_attr_cores_enabled.attr, &dev_attr_cores_max.attr, &dev_attr_apu_mem.attr, @@ -4280,6 +4285,10 @@ static umode_t asus_sysfs_is_visible(struct kobject *kobj, devid = ASUS_WMI_DEVID_PANEL_OD; else if (attr == &dev_attr_panel_fhd.attr) devid = ASUS_WMI_DEVID_PANEL_FHD; + else if (attr == &dev_attr_dgpu_base_tgp.attr) + devid = ASUS_WMI_DEVID_DGPU_BASE_TGP; + else if (attr == &dev_attr_dgpu_tgp.attr) + ok = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_DGPU_SET_TGP); else if (attr == &dev_attr_cores_enabled.attr || attr == &dev_attr_cores_max.attr) ok = asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_CORES_SET); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/platform_data/x86/asus-wmi.h index efe608861e55..71833bd60f27 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -135,6 +135,9 @@ /* dgpu on/off */ #define ASUS_WMI_DEVID_DGPU 0x00090020 +#define ASUS_WMI_DEVID_DGPU_BASE_TGP 0x00120099 +#define ASUS_WMI_DEVID_DGPU_SET_TGP 0x00120098 + /* gpu mux switch, 0 = dGPU, 1 = Optimus */ #define ASUS_WMI_DEVID_GPU_MUX 0x00090016 #define ASUS_WMI_DEVID_GPU_MUX_VIVO 0x00090026