From nobody Wed Dec 17 12:14:40 2025 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 D1DBFC4167B for ; Sun, 26 Nov 2023 23:16:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230348AbjKZXFg (ORCPT ); Sun, 26 Nov 2023 18:05:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjKZXFf (ORCPT ); Sun, 26 Nov 2023 18:05:35 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0C54101; Sun, 26 Nov 2023 15:05:40 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id C678E3200A5A; Sun, 26 Nov 2023 18:05:39 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sun, 26 Nov 2023 18:05:40 -0500 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:sender:subject:subject:to:to; s=fm2; t=1701039939; x= 1701126339; bh=4ijHKfQwA0D4YwrR5eZ/8CFnPujbdPSvz94VXQz+ZtA=; b=S k7GwLxBblNSOcSXNUVwCe69jKm0/A8PUj9vhrZcTXt7GvmBwdGs3WfoL3fDGo/PA mUGifaL7i/yCn5mPBMDKGj3ASV2ZnzCG55U2sTfijgmhtB/r/FyMPecqSONaJnsP SacJQh4FLT+l6Ru92S1CIvuBsaAdJA+ZuPLPCS0uxF5RJ2Mwue+pWd2bLHWVWrcm 7NVuOxAZyJbSUrpP2/0q69XO2LOHViPMecoBkCivR55QSw4dyLh3N1BuqSgTK2md hmVfqiZDxEJ7ZxkQI/L7UsdVOK9DAXefkJRFCqof1YRu2wLQ2+PNvu1HwiuQKAbR +/FWvRU7nckcSMbP4OKug== 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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1701039939; x= 1701126339; bh=4ijHKfQwA0D4YwrR5eZ/8CFnPujbdPSvz94VXQz+ZtA=; b=B O7ruGXsnjK+k0NZM3H11cE02SByuhBpEq4SScrHAUCUkvFqiKZkgqGoUtuqqdOhh QuhrS/4PzVKhfXdHzu1qssb/wKg4Q8WU8qudwNKbDgsTlvlHut4ACJtLR/38oT2w wG2TmpWlueH0WogYRRDeGZIGDYPI6vXrJnhDqgUd32E8q4weFRyQHXFkHNEUNVgc kT8Snb4p+QcGy4LHKzReko+/xG3rrqGIQbMTZMnV1ykXF5DRHcFNn5J0Uv2IH2ct yfdgNXQVITubUtjdqSxox3bWs6jiU8QY/t9jOD3ggbdmlL1ZFQ6eoVmDTMArhg5b VfNabyK4uNFXVuntNuWjg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudeitddgtdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpedfnfhukhgvucffrdculfhonhgvshdfuceolhhukhgvsehl jhhonhgvshdruggvvheqnecuggftrfgrthhtvghrnhepgfetfedugfetudeuheetjefhue fggfelleetvdevtefhueeujeefvdegleevhefgnecuvehluhhsthgvrhfuihiivgeptden ucfrrghrrghmpehmrghilhhfrhhomheplhhukhgvsehljhhonhgvshdruggvvh X-ME-Proxy: Feedback-ID: i5ec1447f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 26 Nov 2023 18:05:36 -0500 (EST) 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 v2 1/1] platform/x86: asus-wmi: disable USB0 hub on ROG Ally before suspend Date: Mon, 27 Nov 2023 12:05:21 +1300 Message-ID: <20231126230521.125708-2-luke@ljones.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231126230521.125708-1-luke@ljones.dev> References: <20231126230521.125708-1-luke@ljones.dev> 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" ASUS have worked around an issue in XInput where it doesn't support USB selective suspend, which causes suspend issues in Windows. They worked around this by adjusting the MCU firmware to disable the USB0 hub when the screen is switched off during the Microsoft DSM suspend path in ACPI. The issue we have with this however is one of timing - the call the tells the MCU to this isn't able to complete before suspend is done so we call this in a prepare() and add a small msleep() to ensure it is done. This must be done before the screen is switched off to prevent a variety of possible races. Further to this the MCU powersave option must also be disabled as it can cause a number of issues such as: - unreliable resume connection of N-Key - complete loss of N-Key if the power is plugged in while suspended Disabling the powersave option prevents this. Without this the MCU is unable to initialise itself correctly on resume. Signed-off-by: Luke D. Jones Reviewed-by: Hans de Goede Tested-by: Philip Mueller --- drivers/platform/x86/asus-wmi.c | 50 ++++++++++++++++++++++ include/linux/platform_data/x86/asus-wmi.h | 3 ++ 2 files changed, 53 insertions(+) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wm= i.c index 6a79f16233ab..4ba33dfebfd4 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -132,6 +133,11 @@ module_param(fnlock_default, bool, 0444); #define ASUS_SCREENPAD_BRIGHT_MAX 255 #define ASUS_SCREENPAD_BRIGHT_DEFAULT 60 =20 +/* Controls the power state of the USB0 hub on ROG Ally which input is on = */ +#define ASUS_USB0_PWR_EC0_CSEE "\\_SB.PCI0.SBRG.EC0.CSEE" +/* 300ms so far seems to produce a reliable result on AC and battery */ +#define ASUS_USB0_PWR_EC0_CSEE_WAIT 300 + static const char * const ashs_ids[] =3D { "ATK4001", "ATK4002", NULL }; =20 static int throttle_thermal_policy_write(struct asus_wmi *); @@ -300,6 +306,9 @@ struct asus_wmi { =20 bool fnlock_locked; =20 + /* The ROG Ally device requires the MCU USB device be disconnected before= suspend */ + bool ally_mcu_usb_switch; + struct asus_wmi_debug debug; =20 struct asus_wmi_driver *driver; @@ -4488,6 +4497,8 @@ static int asus_wmi_add(struct platform_device *pdev) asus->nv_temp_tgt_available =3D asus_wmi_dev_is_present(asus, ASUS_WMI_DE= VID_NV_THERM_TARGET); asus->panel_overdrive_available =3D asus_wmi_dev_is_present(asus, ASUS_WM= I_DEVID_PANEL_OD); asus->mini_led_mode_available =3D asus_wmi_dev_is_present(asus, ASUS_WMI_= DEVID_MINI_LED_MODE); + asus->ally_mcu_usb_switch =3D acpi_has_method(NULL, ASUS_USB0_PWR_EC0_CSE= E) + && dmi_match(DMI_BOARD_NAME, "RC71L"); =20 err =3D fan_boost_mode_check_present(asus); if (err) @@ -4654,6 +4665,43 @@ static int asus_hotk_resume(struct device *device) asus_wmi_fnlock_update(asus); =20 asus_wmi_tablet_mode_get_state(asus); + + return 0; +} + +static int asus_hotk_resume_early(struct device *device) +{ + struct asus_wmi *asus =3D dev_get_drvdata(device); + + if (asus->ally_mcu_usb_switch) { + if (ACPI_FAILURE(acpi_execute_simple_method(NULL, ASUS_USB0_PWR_EC0_CSEE= , 0xB8))) + dev_err(device, "ROG Ally MCU failed to connect USB dev\n"); + else + msleep(ASUS_USB0_PWR_EC0_CSEE_WAIT); + } + return 0; +} + +static int asus_hotk_prepare(struct device *device) +{ + struct asus_wmi *asus =3D dev_get_drvdata(device); + int result, err; + + if (asus->ally_mcu_usb_switch) { + /* When powersave is enabled it causes many issues with resume of USB hu= b */ + result =3D asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_MCU_POWERSA= VE); + if (result =3D=3D 1) { + dev_warn(device, "MCU powersave enabled, disabling to prevent resume is= sues"); + err =3D asus_wmi_set_devstate(ASUS_WMI_DEVID_MCU_POWERSAVE, 0, &result); + if (err || result !=3D 1) + dev_err(device, "Failed to set MCU powersave mode: %d\n", err); + } + /* sleep required to ensure USB0 is disabled before sleep continues */ + if (ACPI_FAILURE(acpi_execute_simple_method(NULL, ASUS_USB0_PWR_EC0_CSEE= , 0xB7))) + dev_err(device, "ROG Ally MCU failed to disconnect USB dev\n"); + else + msleep(ASUS_USB0_PWR_EC0_CSEE_WAIT); + } return 0; } =20 @@ -4701,6 +4749,8 @@ static const struct dev_pm_ops asus_pm_ops =3D { .thaw =3D asus_hotk_thaw, .restore =3D asus_hotk_restore, .resume =3D asus_hotk_resume, + .resume_early =3D asus_hotk_resume_early, + .prepare =3D asus_hotk_prepare, }; =20 /* Registration **********************************************************= *****/ diff --git a/include/linux/platform_data/x86/asus-wmi.h b/include/linux/pla= tform_data/x86/asus-wmi.h index 63e630276499..ab1c7deff118 100644 --- a/include/linux/platform_data/x86/asus-wmi.h +++ b/include/linux/platform_data/x86/asus-wmi.h @@ -114,6 +114,9 @@ /* Charging mode - 1=3DBarrel, 2=3DUSB */ #define ASUS_WMI_DEVID_CHARGE_MODE 0x0012006C =20 +/* MCU powersave mode */ +#define ASUS_WMI_DEVID_MCU_POWERSAVE 0x001200E2 + /* epu is connected? 1 =3D=3D true */ #define ASUS_WMI_DEVID_EGPU_CONNECTED 0x00090018 /* egpu on/off */ --=20 2.43.0