From patchwork Thu Feb 25 17:40:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 12104601 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A817CC433E0 for ; Thu, 25 Feb 2021 17:41:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61F7C64F20 for ; Thu, 25 Feb 2021 17:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbhBYRlo (ORCPT ); Thu, 25 Feb 2021 12:41:44 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:45787 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229613AbhBYRlo (ORCPT ); Thu, 25 Feb 2021 12:41:44 -0500 Received: from 1-171-225-221.dynamic-ip.hinet.net ([1.171.225.221] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lFKdJ-0007hu-1X; Thu, 25 Feb 2021 17:41:01 +0000 From: Kai-Heng Feng To: bhelgaas@google.com Cc: Kai-Heng Feng , Aaron Ma , Arnd Bergmann , linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list), linux-arch@vger.kernel.org (open list:GENERIC INCLUDE/ASM HEADER FILES) Subject: [PATCH 1/3] PCI: Introduce quirk hook after driver shutdown callback Date: Fri, 26 Feb 2021 01:40:38 +0800 Message-Id: <20210225174041.405739-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org It can be useful to apply quirk after device shutdown callback, like putting device into a different power state. This will be used by later patches. Signed-off-by: Aaron Ma Signed-off-by: Kai-Heng Feng --- drivers/pci/pci-driver.c | 2 ++ drivers/pci/quirks.c | 7 +++++++ include/asm-generic/vmlinux.lds.h | 3 +++ include/linux/pci.h | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index ec44a79e951a..7941f6190815 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -498,6 +498,8 @@ static void pci_device_shutdown(struct device *dev) */ if (kexec_in_progress && (pci_dev->current_state <= PCI_D3hot)) pci_clear_master(pci_dev); + + pci_fixup_device(pci_fixup_shutdown, pci_dev); } #ifdef CONFIG_PM diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 653660e3ba9e..1f94fafc6920 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -93,6 +93,8 @@ extern struct pci_fixup __start_pci_fixups_suspend[]; extern struct pci_fixup __end_pci_fixups_suspend[]; extern struct pci_fixup __start_pci_fixups_suspend_late[]; extern struct pci_fixup __end_pci_fixups_suspend_late[]; +extern struct pci_fixup __start_pci_fixups_shutdown[]; +extern struct pci_fixup __end_pci_fixups_shutdown[]; static bool pci_apply_fixup_final_quirks; @@ -143,6 +145,11 @@ void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) end = __end_pci_fixups_suspend_late; break; + case pci_fixup_shutdown: + start = __start_pci_fixups_shutdown; + end = __end_pci_fixups_shutdown; + break; + default: /* stupid compiler warning, you would think with an enum... */ return; diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index c54adce8f6f6..aba43fc2f7b1 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -472,6 +472,9 @@ __start_pci_fixups_suspend_late = .; \ KEEP(*(.pci_fixup_suspend_late)) \ __end_pci_fixups_suspend_late = .; \ + __start_pci_fixups_shutdown = .; \ + KEEP(*(.pci_fixup_shutdown)) \ + __end_pci_fixups_shutdown = .; \ } \ \ /* Built-in firmware blobs */ \ diff --git a/include/linux/pci.h b/include/linux/pci.h index 86c799c97b77..7cbe9b21e049 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1923,6 +1923,7 @@ enum pci_fixup_pass { pci_fixup_suspend, /* pci_device_suspend() */ pci_fixup_resume_early, /* pci_device_resume_early() */ pci_fixup_suspend_late, /* pci_device_suspend_late() */ + pci_fixup_shutdown, /* pci_device_shutdown() */ }; #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS @@ -2028,6 +2029,9 @@ enum pci_fixup_pass { #define DECLARE_PCI_FIXUP_SUSPEND_LATE(vendor, device, hook) \ DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend_late, \ suspend_late##hook, vendor, device, PCI_ANY_ID, 0, hook) +#define DECLARE_PCI_FIXUP_SHUTDOWN(vendor, device, hook) \ + DECLARE_PCI_FIXUP_SECTION(.pci_fixup_shutdown, \ + shutdown##hook, vendor, device, PCI_ANY_ID, 0, hook) #ifdef CONFIG_PCI_QUIRKS void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev); From patchwork Thu Feb 25 17:40:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 12104603 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1E64C433E6 for ; Thu, 25 Feb 2021 17:42:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DC6364F1A for ; Thu, 25 Feb 2021 17:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232086AbhBYRls (ORCPT ); Thu, 25 Feb 2021 12:41:48 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:45792 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbhBYRlq (ORCPT ); Thu, 25 Feb 2021 12:41:46 -0500 Received: from 1-171-225-221.dynamic-ip.hinet.net ([1.171.225.221] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lFKdM-0007iZ-VY; Thu, 25 Feb 2021 17:41:05 +0000 From: Kai-Heng Feng To: bhelgaas@google.com Cc: Aaron Ma , Kai-Heng Feng , linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 2/3] PCI: Set AMD Renoir USB controller to D3 when shutdown Date: Fri, 26 Feb 2021 01:40:39 +0800 Message-Id: <20210225174041.405739-2-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210225174041.405739-1-kai.heng.feng@canonical.com> References: <20210225174041.405739-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Aaron Ma On AMD Renoir/Cezanne platforms, when set "Always on USB" to "On" in BIOS, USB controller will consume more power than 0.03w. Set it to D3cold when shutdown, S5 power consumption will be 0.03w lower. The USB can charge other devices as before. USB controller works fine after power on and reboot. Signed-off-by: Aaron Ma Signed-off-by: Kai-Heng Feng --- drivers/pci/quirks.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 1f94fafc6920..0a848ef0b7db 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -28,6 +28,7 @@ #include #include #include +#include #include /* isa_dma_bridge_buggy */ #include "pci.h" @@ -5619,3 +5620,10 @@ static void apex_pci_fixup_class(struct pci_dev *pdev) } DECLARE_PCI_FIXUP_CLASS_HEADER(0x1ac1, 0x089a, PCI_CLASS_NOT_DEFINED, 8, apex_pci_fixup_class); + +static void pci_fixup_shutdown_d3(struct pci_dev *pdev) +{ + if (!kexec_in_progress) + pci_set_power_state(pdev, PCI_D3cold); +} +DECLARE_PCI_FIXUP_SHUTDOWN(PCI_VENDOR_ID_AMD, 0x1639, pci_fixup_shutdown_d3); From patchwork Thu Feb 25 17:40:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai-Heng Feng X-Patchwork-Id: 12104605 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A315C433E0 for ; Thu, 25 Feb 2021 17:42:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D275764F1A for ; Thu, 25 Feb 2021 17:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232014AbhBYRl6 (ORCPT ); Thu, 25 Feb 2021 12:41:58 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:45801 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232103AbhBYRlz (ORCPT ); Thu, 25 Feb 2021 12:41:55 -0500 Received: from 1-171-225-221.dynamic-ip.hinet.net ([1.171.225.221] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lFKdQ-0007iq-Oa; Thu, 25 Feb 2021 17:41:09 +0000 From: Kai-Heng Feng To: bhelgaas@google.com Cc: Kai-Heng Feng , Yan-Hsuan Chuang , Kalle Valo , "David S. Miller" , Jakub Kicinski , linux-wireless@vger.kernel.org (open list:REALTEK WIRELESS DRIVER (rtw88)), netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list), linux-pci@vger.kernel.org (open list:PCI SUBSYSTEM) Subject: [PATCH 3/3] PCI: Convert rtw88 power cycle quirk to shutdown quirk Date: Fri, 26 Feb 2021 01:40:40 +0800 Message-Id: <20210225174041.405739-3-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210225174041.405739-1-kai.heng.feng@canonical.com> References: <20210225174041.405739-1-kai.heng.feng@canonical.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Now we have a generic D3 shutdown quirk, so convert the original approach to a PCI quirk. Signed-off-by: Kai-Heng Feng Acked-by: Kalle Valo --- drivers/net/wireless/realtek/rtw88/pci.c | 2 -- drivers/pci/quirks.c | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c index 786a48649946..cddc9b09bb1f 100644 --- a/drivers/net/wireless/realtek/rtw88/pci.c +++ b/drivers/net/wireless/realtek/rtw88/pci.c @@ -1709,8 +1709,6 @@ void rtw_pci_shutdown(struct pci_dev *pdev) if (chip->ops->shutdown) chip->ops->shutdown(rtwdev); - - pci_set_power_state(pdev, PCI_D3hot); } EXPORT_SYMBOL(rtw_pci_shutdown); diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 0a848ef0b7db..dfb8746e3b72 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -5627,3 +5627,9 @@ static void pci_fixup_shutdown_d3(struct pci_dev *pdev) pci_set_power_state(pdev, PCI_D3cold); } DECLARE_PCI_FIXUP_SHUTDOWN(PCI_VENDOR_ID_AMD, 0x1639, pci_fixup_shutdown_d3); +DECLARE_PCI_FIXUP_SHUTDOWN(PCI_VENDOR_ID_REALTEK, 0xd723, pci_fixup_shutdown_d3); +DECLARE_PCI_FIXUP_SHUTDOWN(PCI_VENDOR_ID_REALTEK, 0xc821, pci_fixup_shutdown_d3); +DECLARE_PCI_FIXUP_SHUTDOWN(PCI_VENDOR_ID_REALTEK, 0xb822, pci_fixup_shutdown_d3); +DECLARE_PCI_FIXUP_SHUTDOWN(PCI_VENDOR_ID_REALTEK, 0xb822, pci_fixup_shutdown_d3); +DECLARE_PCI_FIXUP_SHUTDOWN(PCI_VENDOR_ID_REALTEK, 0xc822, pci_fixup_shutdown_d3); +DECLARE_PCI_FIXUP_SHUTDOWN(PCI_VENDOR_ID_REALTEK, 0xc82f, pci_fixup_shutdown_d3);