From patchwork Sun Sep 22 17:22:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13809161 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9958D2AEFC; Sun, 22 Sep 2024 17:24:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025873; cv=none; b=XPj2OTVOfM/Y89m0+XBs3hL/LoS5mlzSV+MxZRaFwC3AOu6ESi5H+1N7NtkvIdanVsfYoH/wz9QYKXpLjABJtrQmNB06Mvbwepkb2GlynCwa3wZ5bf5n1CfPb8J3I6Eo4gO+w2JPZVyH2OV7Ph47sCYbEYAcglgWPTEDWAcbODs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025873; c=relaxed/simple; bh=nBKbezGU8tCj+w5KktCCaXSUYra/fTFZnmGI3X7dqYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E1E4eqSK4ofxu3n5bxbVycEbt/nEzbJ7vMPKGp2MplphVyu9xVyXXXXXi4j/XC0RkUeJ7umpvQlNUxo3zmw++xSRw8a/f4QnKGYi4PxsYtHvt+hVH1YHJRhF5OU2AgF6uafz9jBoZJj0QD6yj83F/aGB88+fiBNyKwCK16R4vvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=WlvJjWun; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="WlvJjWun" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 3B10E2E096FD; Sun, 22 Sep 2024 20:24:26 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1727025867; bh=iWGWg+HqOzVyWBplL1Ejrl1AsmTfFMNkEylcKF88Ny4=; h=From:To:Subject; b=WlvJjWunpd7xINvl5r1mGCtvbIdtnbvYmGUyCGx5xOKjC3kMyGNH+xLQgb0G5vtqd Gr+/XJb5ZBYX9IOEl19+ORUzujlSehhFQ6BjCJSlgg8cQNkxW5w8E+PtGeusCW/1ga 6D+f2Qy9PuwDSnPjy/+yTSd1enxgGA6mCTE+NzTE= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-pm@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org, Mario Limonciello , luke@ljones.dev, me@kylegospodneti.ch, Denis Benato , Antheas Kapenekakis Subject: [PATCH v2 1/5] acpi/x86: s2idle: add support for Display Off and Display On callbacks Date: Sun, 22 Sep 2024 19:22:54 +0200 Message-ID: <20240922172258.48435-2-lkml@antheas.dev> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240922172258.48435-1-lkml@antheas.dev> References: <20240922172258.48435-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <172702586706.19493.3873523492503629555@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean The Display Off and Display On firmware notifications are meant to signify the system entering a state where the user is not actively interacting with it (i.e., in Windows this state is called "Screen Off" and the system enters it once it turns the screen off e.g., due to inactivity). Currently, these functions are called within the suspend sequence, which causes issues when these notifications interact with e.g., a USB device and makes them unable to be called as part of the screen turning off. This patch adds a set of callbacks to allow calling the Display On/Off notifications outside of the suspend/resume path. Co-developed-by: Mario Limonciello Signed-off-by: Antheas Kapenekakis --- include/linux/suspend.h | 5 +++++ kernel/power/suspend.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index da6ebca3ff77..8f33249cc067 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -132,6 +132,7 @@ struct platform_suspend_ops { }; struct platform_s2idle_ops { + int (*display_off)(void); int (*begin)(void); int (*prepare)(void); int (*prepare_late)(void); @@ -140,6 +141,7 @@ struct platform_s2idle_ops { void (*restore_early)(void); void (*restore)(void); void (*end)(void); + int (*display_on)(void); }; #ifdef CONFIG_SUSPEND @@ -160,6 +162,9 @@ extern unsigned int pm_suspend_global_flags; #define PM_SUSPEND_FLAG_FW_RESUME BIT(1) #define PM_SUSPEND_FLAG_NO_PLATFORM BIT(2) +int platform_suspend_display_off(void); +int platform_suspend_display_on(void); + static inline void pm_suspend_clear_flags(void) { pm_suspend_global_flags = 0; diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index 09f8397bae15..c527dc0ae5ae 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -254,6 +254,18 @@ static bool sleep_state_supported(suspend_state_t state) (valid_state(state) && !cxl_mem_active()); } +int platform_suspend_display_off(void) +{ + return s2idle_ops && s2idle_ops->display_off ? s2idle_ops->display_off() : 0; +} +EXPORT_SYMBOL_GPL(platform_suspend_display_off); + +int platform_suspend_display_on(void) +{ + return s2idle_ops && s2idle_ops->display_on ? s2idle_ops->display_on() : 0; +} +EXPORT_SYMBOL_GPL(platform_suspend_display_on); + static int platform_suspend_prepare(suspend_state_t state) { return state != PM_SUSPEND_TO_IDLE && suspend_ops->prepare ? From patchwork Sun Sep 22 17:22:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13809163 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF38EEED6; Sun, 22 Sep 2024 17:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025874; cv=none; b=tXlnk/ZJKSuDQQJ9AXqxH5TSBbHtvsOGie4Xnt+enf/Gj0pC6M6q+6CNVNlVAnaMHIF2d+qilDFOCTQWC0iW+Yqoo4zgcX25PEnYKBp4buctEdjmZ5PJ4rmFZYMhMSR7fpsGyqKM5kvRJko4fDhLb9kLw5Bn3Ne5GjvXLiWtPQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025874; c=relaxed/simple; bh=pbGp2Upa1tQfV5lGSqqMjjJH0EyD9UJ0tLujZepVKxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MCh9Cqbf1yr71lYt9CqKA1+H25TVXxwSUk2AxeYyKYcf0S0DTWjdXT8R+g0StRFtxhuaBE322patrK7UQNWPU5C5azHp5sxCH1Az44z9bhSDv3QhN2oGr17xyJz6s+19XXO6YJ0H9vcJsct/VktMMzi2dkcwYAWOXmCPdqqDAVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=zgRT4K3t; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="zgRT4K3t" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 6BA512E096FE; Sun, 22 Sep 2024 20:24:27 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1727025868; bh=PYi9JePA/C7PKQyom8rQqDAAGKRyFKQnDmgNqq6n+Ro=; h=From:To:Subject; b=zgRT4K3tSoy8ud67EFbuSr1gzZUJ7YOFdctMI4cYRp1A511GiGUCWH0PXLovc337M fyvArEsP0KXs1Pew1iXlEvRLQVanV2A18JcQ2sjDuucfhviLh3ba4En58lMds2Ekg+ 5UONPjKWwZswcnA7qT12ZBftJND69MOj2qCsVrbQ= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-pm@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org, Mario Limonciello , luke@ljones.dev, me@kylegospodneti.ch, Denis Benato , Antheas Kapenekakis Subject: [PATCH v2 2/5] acpi/x86: s2idle: handle Display On/Off calls outside of suspend sequence Date: Sun, 22 Sep 2024 19:22:55 +0200 Message-ID: <20240922172258.48435-3-lkml@antheas.dev> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240922172258.48435-1-lkml@antheas.dev> References: <20240922172258.48435-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <172702586826.19559.10852927881081473431@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Currently, the Display On/Off calls are handled within the suspend sequence, which is a deviation from Windows. This causes issues with certain devices, where the notification interacts with a USB device that expects the kernel to be fully awake. This patch calls the Display On/Off callbacks before entering the suspend sequence, which fixes this issue. In addition, it opens the possibility of modelling a state such as "Screen Off" that mirrors Windows, as the callbacks will be accessible and validated to work outside of the suspend sequence. Suggested-by: Mario Limonciello Signed-off-by: Antheas Kapenekakis --- kernel/power/suspend.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index c527dc0ae5ae..610f8ecaeebd 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -589,6 +589,13 @@ static int enter_state(suspend_state_t state) if (state == PM_SUSPEND_TO_IDLE) s2idle_begin(); + /* + * Linux does not have the concept of a "Screen Off" state, so call + * the platform functions for Display On/Off prior to the suspend + * sequence, mirroring Windows which calls them outside of it as well. + */ + platform_suspend_display_off(); + if (sync_on_suspend_enabled) { trace_suspend_resume(TPS("sync_filesystems"), 0, true); ksys_sync_helper(); @@ -616,6 +623,8 @@ static int enter_state(suspend_state_t state) suspend_finish(); Unlock: mutex_unlock(&system_transition_mutex); + + platform_suspend_display_on(); return error; } From patchwork Sun Sep 22 17:22:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13809164 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2CE11A276; Sun, 22 Sep 2024 17:24:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025875; cv=none; b=BVldZqZ5i62h1dSMG3giNLrpiTWwRwJVKAtTceScozuThXfWBuq3RqrCTc/Eb7fY84Uq28+Bphi/tCjVyHRTVhvxNUsvQix6YtWjRnmCDPj88xs6LKnX0UKhMJjvrEJA7j45LpRETrXKYqyFo8kigJ5Zvv5ffTTybBIDy55ZDhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025875; c=relaxed/simple; bh=/q6XQlUZwLuDa/LRHCtcLcdUytwC2i3gD3uQ+jnxVM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EIhlXyWHSKUml8b+H17EROo9wq8xAzLtbfYfd5WZk7a+8CnD/94TbFExIeJkMTGoHIeoraa6BPie209A8Hwdz6AlKmHp3zQzlY6TGEM/+YB3XlqMnqKBR5PxfpYUqaCAajyfH/kdBN7RO65zHA47o9KA9d2D2Vr9NbNK4Aj6RMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=YMV90tWM; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="YMV90tWM" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id A3C982E096FB; Sun, 22 Sep 2024 20:24:28 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1727025869; bh=4xg+XiBJrHP9fSaSSoDTSxVBoNzDqUeh30zv1W614Vc=; h=From:To:Subject; b=YMV90tWMB6AKpvEhYLVWmakwqaWNx4cVqbi4ZlD7y5Pc35WtdpKmMFpuJTrr/D+wx qWGYuq90smSSDsqmX+wuu7PxGBjeUETnj7nwCUs7bmt4QmEXOqrs1hmuVDIZk5XFdv msV3xITT75w2PEheOXtY3k51ZiBCnV7wf5VkJkso= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-pm@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org, Mario Limonciello , luke@ljones.dev, me@kylegospodneti.ch, Denis Benato , Antheas Kapenekakis Subject: [PATCH v2 3/5] acpi/x86: s2idle: add quirk table for modern standby delays Date: Sun, 22 Sep 2024 19:22:56 +0200 Message-ID: <20240922172258.48435-4-lkml@antheas.dev> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240922172258.48435-1-lkml@antheas.dev> References: <20240922172258.48435-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <172702586953.19607.1922514203249411979@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Unfortunately, some modern standby systems, including the ROG Ally, rely on a delay between modern standby transitions. Add a quirk table for introducing delays between modern standby transitions, and quirk the ROG Ally on "Display Off", which needs a bit of time to turn off its controllers prior to suspending (i.e., entering DRIPS). Reported-by: Denis Benato Signed-off-by: Antheas Kapenekakis --- include/linux/suspend.h | 5 +++++ kernel/power/suspend.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 8f33249cc067..d7e2a4d8ab0c 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -144,6 +144,11 @@ struct platform_s2idle_ops { int (*display_on)(void); }; +struct platform_s2idle_quirks { + int delay_display_off; + int delay_display_on; +}; + #ifdef CONFIG_SUSPEND extern suspend_state_t pm_suspend_target_state; extern suspend_state_t mem_sleep_current; diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index 610f8ecaeebd..af2abdd2f8c3 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -61,6 +62,30 @@ static DECLARE_SWAIT_QUEUE_HEAD(s2idle_wait_head); enum s2idle_states __read_mostly s2idle_state; static DEFINE_RAW_SPINLOCK(s2idle_lock); +// The ROG Ally series disconnects its controllers on Display Off, without +// holding a lock, introducing a race condition. Add a delay to allow the +// controller to disconnect cleanly prior to suspend. +static const struct platform_s2idle_quirks rog_ally_quirks = { + .delay_display_off = 500, +}; + +static const struct dmi_system_id platform_s2idle_quirks[] = { + { + .matches = { + DMI_MATCH(DMI_BOARD_NAME, "RC71L"), + }, + .driver_data = (void *)&rog_ally_quirks + }, + { + .matches = { + DMI_MATCH(DMI_BOARD_NAME, "RC72L"), + }, + .driver_data = (void *)&rog_ally_quirks + }, + {} +}; + + /** * pm_suspend_default_s2idle - Check if suspend-to-idle is the default suspend. * @@ -589,12 +614,26 @@ static int enter_state(suspend_state_t state) if (state == PM_SUSPEND_TO_IDLE) s2idle_begin(); + /* + * Windows transitions between Modern Standby states slowly, over multiple + * seconds. Certain manufacturers may rely on this, introducing race + * conditions. Until Linux can support modern standby, add the relevant + * delays between transitions here. + */ + const struct dmi_system_id *s2idle_sysid = dmi_first_match( + platform_s2idle_quirks + ); + const struct platform_s2idle_quirks *s2idle_quirks = s2idle_sysid ? + s2idle_sysid->driver_data : NULL; + /* * Linux does not have the concept of a "Screen Off" state, so call * the platform functions for Display On/Off prior to the suspend * sequence, mirroring Windows which calls them outside of it as well. */ platform_suspend_display_off(); + if (s2idle_quirks && s2idle_quirks->delay_display_off) + msleep(s2idle_quirks->delay_display_off); if (sync_on_suspend_enabled) { trace_suspend_resume(TPS("sync_filesystems"), 0, true); @@ -624,6 +663,8 @@ static int enter_state(suspend_state_t state) Unlock: mutex_unlock(&system_transition_mutex); + if (s2idle_quirks && s2idle_quirks->delay_display_on) + msleep(s2idle_quirks->delay_display_on); platform_suspend_display_on(); return error; } From patchwork Sun Sep 22 17:22:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13809165 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06A7E2B9A1; Sun, 22 Sep 2024 17:24:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025875; cv=none; b=AvWuoV5ec0V8FIjUgZvkbJi/Hs0FCqGrwoy5KXqx8Ooz7f4i0L8wHS5r+0jLA4Ui7xpl9gpiykFVoSWEMOhHLHBVy5FdPLqBnDRs4U42qDPaeI3/oiUJmPQNIijHzIjr+YAgj4/gY6yXYdgsMlqY8IAMzfCBZvs6bajZ4sbTZdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025875; c=relaxed/simple; bh=hdYiVrfxrtBaACQtrGawG/G1F0oam/9gpUa3/Msk+H0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U16itiI5ygSpZzy9ir0UjgyFCNteS8MB8HB2EQifYIaBVe9jbCWYb2mbnH+P9ozGFRHLNMqFiz4LZjc87GhhxTMyfixcjAG6netXLB8S7ln5cLwQ1WOj/A+gV2QE9WwI8j+q5+LRuZnaoLmMaWsLCqdjXXqXtF3H3j1YHmUi+W0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=zh2atIWe; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="zh2atIWe" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id E77A92E09702; Sun, 22 Sep 2024 20:24:29 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1727025870; bh=WEaCrXuILAhyNJftzE1NUauNPw6HjX292SCxgFJUUak=; h=From:To:Subject; b=zh2atIWeZA6zALTnAcOlW/zp2ddwYpX6n4TwWGvH9Z9mQHzRtahOJmTaLy+fut9IX j72TAqb/2PNF9FiqHGEZMFNQTvGNeWMh2L/paFr5m3hZctk0LjLWTeMNdOs1kN/wRz p1LHXDCCZxD2pUuKbQ1FsZ4axLeTQzDTn2CG6LgU= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-pm@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org, Mario Limonciello , luke@ljones.dev, me@kylegospodneti.ch, Denis Benato , Antheas Kapenekakis Subject: [PATCH v2 4/5] acpi/x86: s2idle: call Display On/Off as part of callbacks and rename Date: Sun, 22 Sep 2024 19:22:57 +0200 Message-ID: <20240922172258.48435-5-lkml@antheas.dev> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240922172258.48435-1-lkml@antheas.dev> References: <20240922172258.48435-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <172702587079.19655.3616447128571825577@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean Move the Display On/Off notifications into dedicated callbacks that gate the ACPI mutex, so they can be called outside of the suspend path. This fixes issues on certain devices that expect kernel drivers to be fully active during the calls, and allows for the flexibility of calling them as part of a more elaborate userspace suspend sequence (such as with "Screen Off" in Windows Modern Standby). In addition, rename the notifications from "screen_" to "display_", as there is no documentation referring to them as screen, either by Intel or Microsoft. Co-developed-by: Mario Limonciello Signed-off-by: Antheas Kapenekakis --- drivers/acpi/x86/s2idle.c | 89 +++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c index dd0b40b9bbe8..a17e28b91326 100644 --- a/drivers/acpi/x86/s2idle.c +++ b/drivers/acpi/x86/s2idle.c @@ -39,8 +39,8 @@ static const struct acpi_device_id lps0_device_ids[] = { #define ACPI_LPS0_DSM_UUID "c4eb40a0-6cd2-11e2-bcfd-0800200c9a66" #define ACPI_LPS0_GET_DEVICE_CONSTRAINTS 1 -#define ACPI_LPS0_SCREEN_OFF 3 -#define ACPI_LPS0_SCREEN_ON 4 +#define ACPI_LPS0_DISPLAY_OFF 3 +#define ACPI_LPS0_DISPLAY_ON 4 #define ACPI_LPS0_ENTRY 5 #define ACPI_LPS0_EXIT 6 #define ACPI_LPS0_MS_ENTRY 7 @@ -50,8 +50,8 @@ static const struct acpi_device_id lps0_device_ids[] = { #define ACPI_LPS0_DSM_UUID_AMD "e3f32452-febc-43ce-9039-932122d37721" #define ACPI_LPS0_ENTRY_AMD 2 #define ACPI_LPS0_EXIT_AMD 3 -#define ACPI_LPS0_SCREEN_OFF_AMD 4 -#define ACPI_LPS0_SCREEN_ON_AMD 5 +#define ACPI_LPS0_DISPLAY_OFF_AMD 4 +#define ACPI_LPS0_DISPLAY_ON_AMD 5 static acpi_handle lps0_device_handle; static guid_t lps0_dsm_guid; @@ -60,6 +60,7 @@ static int lps0_dsm_func_mask; static guid_t lps0_dsm_guid_microsoft; static int lps0_dsm_func_mask_microsoft; static int lps0_dsm_state; +static bool lsp0_dsm_in_display_off; /* Device constraint entry structure */ struct lpi_device_info { @@ -361,9 +362,9 @@ static const char *acpi_sleep_dsm_state_to_str(unsigned int state) { if (lps0_dsm_func_mask_microsoft || !acpi_s2idle_vendor_amd()) { switch (state) { - case ACPI_LPS0_SCREEN_OFF: + case ACPI_LPS0_DISPLAY_OFF: return "screen off"; - case ACPI_LPS0_SCREEN_ON: + case ACPI_LPS0_DISPLAY_ON: return "screen on"; case ACPI_LPS0_ENTRY: return "lps0 entry"; @@ -376,9 +377,9 @@ static const char *acpi_sleep_dsm_state_to_str(unsigned int state) } } else { switch (state) { - case ACPI_LPS0_SCREEN_ON_AMD: + case ACPI_LPS0_DISPLAY_ON_AMD: return "screen on"; - case ACPI_LPS0_SCREEN_OFF_AMD: + case ACPI_LPS0_DISPLAY_OFF_AMD: return "screen off"; case ACPI_LPS0_ENTRY_AMD: return "lps0 entry"; @@ -539,27 +540,69 @@ static struct acpi_scan_handler lps0_handler = { .attach = lps0_device_attach, }; -int acpi_s2idle_prepare_late(void) +static int acpi_s2idle_display_off(void) { - struct acpi_s2idle_dev_ops *handler; - if (!lps0_device_handle || sleep_no_lps0) return 0; - if (pm_debug_messages_on) - lpi_check_constraints(); + if (unlikely(WARN_ON(lsp0_dsm_in_display_off))) + return -EINVAL; + + lsp0_dsm_in_display_off = true; + acpi_scan_lock_acquire(); - /* Screen off */ + /* Display off */ if (lps0_dsm_func_mask > 0) acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ? - ACPI_LPS0_SCREEN_OFF_AMD : - ACPI_LPS0_SCREEN_OFF, + ACPI_LPS0_DISPLAY_OFF_AMD : + ACPI_LPS0_DISPLAY_OFF, lps0_dsm_func_mask, lps0_dsm_guid); if (lps0_dsm_func_mask_microsoft > 0) - acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_OFF, + acpi_sleep_run_lps0_dsm(ACPI_LPS0_DISPLAY_OFF, lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); + acpi_scan_lock_release(); + + return 0; +} + +static int acpi_s2idle_display_on(void) +{ + if (!lps0_device_handle || sleep_no_lps0) + return 0; + + if (unlikely(WARN_ON(!lsp0_dsm_in_display_off))) + return -EINVAL; + + lsp0_dsm_in_display_off = false; + acpi_scan_lock_acquire(); + + /* Display on */ + if (lps0_dsm_func_mask_microsoft > 0) + acpi_sleep_run_lps0_dsm(ACPI_LPS0_DISPLAY_ON, + lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); + if (lps0_dsm_func_mask > 0) + acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ? + ACPI_LPS0_DISPLAY_ON_AMD : + ACPI_LPS0_DISPLAY_ON, + lps0_dsm_func_mask, lps0_dsm_guid); + + acpi_scan_lock_release(); + + return 0; +} + +int acpi_s2idle_prepare_late(void) +{ + struct acpi_s2idle_dev_ops *handler; + + if (!lps0_device_handle || sleep_no_lps0) + return 0; + + if (pm_debug_messages_on) + lpi_check_constraints(); + /* LPS0 entry */ if (lps0_dsm_func_mask > 0 && acpi_s2idle_vendor_amd()) acpi_sleep_run_lps0_dsm(ACPI_LPS0_ENTRY_AMD, @@ -623,19 +666,10 @@ void acpi_s2idle_restore_early(void) acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT, lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); } - - /* Screen on */ - if (lps0_dsm_func_mask_microsoft > 0) - acpi_sleep_run_lps0_dsm(ACPI_LPS0_SCREEN_ON, - lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); - if (lps0_dsm_func_mask > 0) - acpi_sleep_run_lps0_dsm(acpi_s2idle_vendor_amd() ? - ACPI_LPS0_SCREEN_ON_AMD : - ACPI_LPS0_SCREEN_ON, - lps0_dsm_func_mask, lps0_dsm_guid); } static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = { + .display_off = acpi_s2idle_display_off, .begin = acpi_s2idle_begin, .prepare = acpi_s2idle_prepare, .prepare_late = acpi_s2idle_prepare_late, @@ -644,6 +678,7 @@ static const struct platform_s2idle_ops acpi_s2idle_ops_lps0 = { .restore_early = acpi_s2idle_restore_early, .restore = acpi_s2idle_restore, .end = acpi_s2idle_end, + .display_on = acpi_s2idle_display_on, }; void __init acpi_s2idle_setup(void) From patchwork Sun Sep 22 17:22:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antheas Kapenekakis X-Patchwork-Id: 13809166 Received: from linux1587.grserver.gr (linux1587.grserver.gr [185.138.42.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5949C3C092; Sun, 22 Sep 2024 17:24:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.138.42.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025877; cv=none; b=P1HzX/9m06qVu6rHJqpoirg3MjE5Kn+5YeOfZzlXOWVLBzKJzu8QdRMTBp/mgWHta77yycOOq0/WOOuUi88pkID6msSmBPIINS8NTsUP63NNuOwHKkzrSgDmceYfl+sohZo5Jmzyj2Rk3tGosuRNFFa9ag0zvBcxaC+bTrd9Ank= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727025877; c=relaxed/simple; bh=xUPaNyKOYRw1XkLMhyngzDzY7C1vZMPdKSdizUoRUIU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LqjISZN8U48W+ASlYpcHUiFQC0FHaY+1gA1ZgDtPe7gCSYWuTicJZd7nvhmaGyrBtGM4dmp78nmQpgcZfdVVjavdyLDeQQy8EEErTfJJiv12lCqmVVE8vAX8jdb5pIouPvDb0pdtj1ICE+3uR5lPQCORLmBkj1FktnuGH35H540= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev; spf=pass smtp.mailfrom=antheas.dev; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b=sAhl8EiJ; arc=none smtp.client-ip=185.138.42.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=antheas.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antheas.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antheas.dev header.i=@antheas.dev header.b="sAhl8EiJ" Received: from localhost.localdomain (unknown [IPv6:2a05:f6c2:511b:0:cbc0:999f:73ad:33bd]) by linux1587.grserver.gr (Postfix) with ESMTPSA id 353A82E09700; Sun, 22 Sep 2024 20:24:31 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antheas.dev; s=default; t=1727025872; bh=2mLOpsI3OZHKEiKQT5M4Jl+h+Wp5+sbyyU/iexK8+Io=; h=From:To:Subject; b=sAhl8EiJEUfwdtlOXTvMhDuYTGutk5EfrpEkxEmowGYGXnKyHefticVs5sbk8nE5R LLkM0YM71HoPHMd00vhoGq6EBOdE1G1cW+95YIrxZhDN0KJ0rx0brPdKB6FpAAFa+l d9rLufkzJUwFhiWAQN2rqrX/b4h1+TjnejOefcDg= Authentication-Results: linux1587.grserver.gr; spf=pass (sender IP is 2a05:f6c2:511b:0:cbc0:999f:73ad:33bd) smtp.mailfrom=lkml@antheas.dev smtp.helo=localhost.localdomain Received-SPF: pass (linux1587.grserver.gr: connection is authenticated) From: Antheas Kapenekakis To: linux-pm@vger.kernel.org Cc: platform-driver-x86@vger.kernel.org, Mario Limonciello , luke@ljones.dev, me@kylegospodneti.ch, Denis Benato , Antheas Kapenekakis Subject: [PATCH v2 5/5] platform/x86: asus-wmi: remove Ally (1st gen) and Ally X suspend quirk Date: Sun, 22 Sep 2024 19:22:58 +0200 Message-ID: <20240922172258.48435-6-lkml@antheas.dev> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240922172258.48435-1-lkml@antheas.dev> References: <20240922172258.48435-1-lkml@antheas.dev> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-PPP-Message-ID: <172702587209.19708.13018070105160490087@linux1587.grserver.gr> X-PPP-Vhost: antheas.dev X-Virus-Scanned: clamav-milter 0.103.11 at linux1587.grserver.gr X-Virus-Status: Clean By moving the Display On/Off calls outside of the suspend sequence and introducing a slight delay after Display Off, the ROG Ally controller functions exactly as it does in Windows. Therefore, remove the quirk that fixed the controller only when the mcu_powersave attribute was disabled, while adding a large amount of delay to the suspend and wake process. Reviewed-by: Mario Limonciello Signed-off-by: Antheas Kapenekakis --- drivers/platform/x86/asus-wmi.c | 54 --------------------------------- 1 file changed, 54 deletions(-) diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c index 37636e5a38e3..2c9656e0afda 100644 --- a/drivers/platform/x86/asus-wmi.c +++ b/drivers/platform/x86/asus-wmi.c @@ -137,29 +137,10 @@ module_param(fnlock_default, bool, 0444); #define ASUS_MINI_LED_2024_STRONG 0x01 #define ASUS_MINI_LED_2024_OFF 0x02 -/* 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 1500 - static const char * const ashs_ids[] = { "ATK4001", "ATK4002", NULL }; static int throttle_thermal_policy_write(struct asus_wmi *); -static const struct dmi_system_id asus_ally_mcu_quirk[] = { - { - .matches = { - DMI_MATCH(DMI_BOARD_NAME, "RC71L"), - }, - }, - { - .matches = { - DMI_MATCH(DMI_BOARD_NAME, "RC72L"), - }, - }, - { }, -}; - static bool ashs_present(void) { int i = 0; @@ -269,9 +250,6 @@ struct asus_wmi { u32 tablet_switch_dev_id; bool tablet_switch_inverted; - /* The ROG Ally device requires the MCU USB device be disconnected before suspend */ - bool ally_mcu_usb_switch; - enum fan_type fan_type; enum fan_type gpu_fan_type; enum fan_type mid_fan_type; @@ -4698,8 +4676,6 @@ static int asus_wmi_add(struct platform_device *pdev) 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); - asus->ally_mcu_usb_switch = acpi_has_method(NULL, ASUS_USB0_PWR_EC0_CSEE) - && dmi_check_system(asus_ally_mcu_quirk); if (asus_wmi_dev_is_present(asus, ASUS_WMI_DEVID_MINI_LED_MODE)) asus->mini_led_dev_id = ASUS_WMI_DEVID_MINI_LED_MODE; @@ -4892,34 +4868,6 @@ static int asus_hotk_resume(struct device *device) return 0; } -static int asus_hotk_resume_early(struct device *device) -{ - struct asus_wmi *asus = dev_get_drvdata(device); - - if (asus->ally_mcu_usb_switch) { - /* sleep required to prevent USB0 being yanked then reappearing rapidly */ - 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 = dev_get_drvdata(device); - - if (asus->ally_mcu_usb_switch) { - /* 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; -} - static int asus_hotk_restore(struct device *device) { struct asus_wmi *asus = dev_get_drvdata(device); @@ -4964,8 +4912,6 @@ static const struct dev_pm_ops asus_pm_ops = { .thaw = asus_hotk_thaw, .restore = asus_hotk_restore, .resume = asus_hotk_resume, - .resume_early = asus_hotk_resume_early, - .prepare = asus_hotk_prepare, }; /* Registration ***************************************************************/