From nobody Sat Apr 11 09:20:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF04AC19F2D for ; Sat, 13 Aug 2022 09:27:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238763AbiHMJ0m (ORCPT ); Sat, 13 Aug 2022 05:26:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiHMJ0k (ORCPT ); Sat, 13 Aug 2022 05:26:40 -0400 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3777B2A426; Sat, 13 Aug 2022 02:26:39 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 80E5D320089C; Sat, 13 Aug 2022 05:26:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 13 Aug 2022 05:26:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ljones.dev; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm2; t=1660382796; x=1660469196; bh=pFfuz6Pb6zgmosFpm3ocdnQBX HnpsxKhbqrD48iXvy4=; b=QI6AEJfqPwOzR0T5Vh3RjziHNFjdPDijkb+G94d6h NG4Lbgf6QienSYE3KVs6F2AG0q8y7MeS3ty6IlGQFSoec1LJ3pW24JJqdALGbGX3 7bHNdIkODuVShrujgZ5EksmM2/9oRY4YG68wo4aP7K14b7Glh1Np9iYGggw2BzOw xAawOGC9/SBkUIzh3hQVtBWKnjwX7p7J5rQhMscrDhW3Mys222cHxEpOSToY9xQp CQq2KDy/MjlXwKgrtH8T4sX1JPBqBuHnbCNCjo6yw+FH3RP9gUcs2ATE4CV9YCVG Bhbym9Qv1vyX8Vhd6gozonZ+dAXwUvbqN9iq35TiMEkUQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1660382796; x=1660469196; bh=pFfuz6Pb6zgmosFpm3ocdnQBXHnpsxKhbqr D48iXvy4=; b=bvG4M1xt1T2kiHn0ml98B/B8FnF9yzL88lhrlB/8k/AgG1u1RuJ Tq+1xLOnUU8/X22AuNdWVP6DJU3TawlM01cqWxvLWf2QPHpHyntVAwmJg4QvMw1y 4poh74GMVOBPH8Xpl2wllGNQzrJuhqrm7omcm0OinomYKSDJIuVzW9xuqTU0z/g+ jekVOjrGoovBd5csiEdinogIUjsGCPiayskTXrSVmDz8OHTZ6EUBLMMCcL9I6HmS irBmDASHJgYgJ4vKubnjmSY7o2nf1j3tSXaxye+FoUzRdFeBar/ZCQuPyfhHjU6x FL+gZVVOVIi62EAodmRWpgAXDQXbuxXX+hA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdegkedgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffoggfgsedtkeertd ertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehljhho nhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfdujedthfduudekffefkeeiffdttd dvhfegudduueffuefhfefggeefteevvdegnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 13 Aug 2022 05:26:32 -0400 (EDT) From: "Luke D. Jones" To: hdegoede@redhat.com Cc: markgross@kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, "Luke D. Jones" Subject: [PATCH] asus-wmi: Support the hardware GPU MUX on some laptops Date: Sat, 13 Aug 2022 21:26:24 +1200 Message-Id: <20220813092624.6228-1-luke@ljones.dev> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Support the hardware GPU MUX switch available on some models. This switch can toggle the MUX between: - 0, Dedicated mode - 1, Optimus mode Optimus mode is the regular iGPU + dGPU available, while dedicated mode switches the system to have only the dGPU available. Signed-off-by: Luke D. Jones --- .../ABI/testing/sysfs-platform-asus-wmi | 11 ++++ drivers/platform/x86/asus-wmi.c | 62 +++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 + 3 files changed, 76 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi b/Documentat= ion/ABI/testing/sysfs-platform-asus-wmi index 574b5170a37d..03124eab7f01 100644 --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi @@ -58,6 +58,17 @@ Description: * 1 - overboost, * 2 - silent =20 +What: /sys/devices/platform//gpu_mux_mode +Date: Aug 2022 +KernelVersion: 6.1 +Contact: "Luke Jones" +Description: + Switch the GPU hardware MUX mode. Laptops with this feature= can + can be toggled to boot with only the dGPU (discrete mode) or in + standard Optimus/Hybrid mode. On switch a reboot is required: + * 0 - Discrete GPU, + * 1 - Optimus/Hybrid, + What: /sys/devices/platform//dgpu_disable Date: Aug 2022 KernelVersion: 5.17 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wm= i.c index e2b51b5550e8..0421ffb81927 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -230,6 +230,7 @@ struct asus_wmi { =20 bool egpu_enable_available; bool dgpu_disable_available; + bool gpu_mux_mode_available; =20 bool throttle_thermal_policy_available; u8 throttle_thermal_policy_mode; @@ -668,6 +669,59 @@ static ssize_t egpu_enable_store(struct device *dev, } static DEVICE_ATTR_RW(egpu_enable); =20 +/* gpu mux switch ********************************************************= *****/ +static int gpu_mux_mode_check_present(struct asus_wmi *asus) +{ + asus->gpu_mux_mode_available =3D asus_wmi_dev_is_present(asus, ASUS_WMI_D= EVID_GPU_MUX); + + return 0; +} + +static ssize_t gpu_mux_mode_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct asus_wmi *asus =3D dev_get_drvdata(dev); + int result; + + result =3D asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPU_MUX); + if (result < 0) + return result; + + return sysfs_emit(buf, "%d\n", result); +} + +static ssize_t gpu_mux_mode_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct asus_wmi *asus =3D dev_get_drvdata(dev); + int result, err; + u32 optimus; + + err =3D kstrtou32(buf, 10, &optimus); + if (err) + return err; + + if (optimus > 1) + return -EINVAL; + + err =3D asus_wmi_set_devstate(ASUS_WMI_DEVID_GPU_MUX, optimus, &result); + if (err) { + dev_err(dev, "Failed to set GPU MUX mode: %d\n", err); + return err; + } + /* !1 is considered a fail by ASUS */ + if (result !=3D 1) { + dev_warn(dev, "Failed to set GPU MUX mode (result): 0x%x\n", result); + return -EIO; + } + + sysfs_notify(&asus->platform_device->dev.kobj, NULL, "gpu_mux_mode"); + + return count; +} +static DEVICE_ATTR_RW(gpu_mux_mode); + /* Battery ***************************************************************= *****/ =20 /* The battery maximum charging percentage */ @@ -3165,6 +3219,7 @@ static struct attribute *platform_attributes[] =3D { &dev_attr_touchpad.attr, &dev_attr_egpu_enable.attr, &dev_attr_dgpu_disable.attr, + &dev_attr_gpu_mux_mode.attr, &dev_attr_lid_resume.attr, &dev_attr_als_enable.attr, &dev_attr_fan_boost_mode.attr, @@ -3195,6 +3250,8 @@ static umode_t asus_sysfs_is_visible(struct kobject *= kobj, ok =3D asus->egpu_enable_available; else if (attr =3D=3D &dev_attr_dgpu_disable.attr) ok =3D asus->dgpu_disable_available; + else if (attr =3D=3D &dev_attr_gpu_mux_mode.attr) + ok =3D asus->gpu_mux_mode_available; else if (attr =3D=3D &dev_attr_fan_boost_mode.attr) ok =3D asus->fan_boost_mode_available; else if (attr =3D=3D &dev_attr_throttle_thermal_policy.attr) @@ -3464,6 +3521,10 @@ static int asus_wmi_add(struct platform_device *pdev) if (err) goto fail_dgpu_disable; =20 + err =3D gpu_mux_mode_check_present(asus); + if (err) + goto fail_gpu_mux_mode; + err =3D fan_boost_mode_check_present(asus); if (err) goto fail_fan_boost_mode; @@ -3578,6 +3639,7 @@ static int asus_wmi_add(struct platform_device *pdev) fail_fan_boost_mode: fail_egpu_enable: fail_dgpu_disable: +fail_gpu_mux_mode: fail_platform: fail_panel_od: kfree(asus); diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index a571b47ff362..c023332842a2 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -98,6 +98,9 @@ /* dgpu on/off */ #define ASUS_WMI_DEVID_DGPU 0x00090020 =20 +/* gpu mux switch, 0 =3D dGPU, 1 =3D Optimus */ +#define ASUS_WMI_DEVID_GPU_MUX 0x00090016 + /* DSTS masks */ #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001 #define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002 --=20 2.37.1