From patchwork Sat Jul 16 22:24:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12920310 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 184C0C43334 for ; Sat, 16 Jul 2022 22:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LD4ZNiHWsakHQtOMs8FTn5TRMzGMPkqJrxd8Tbltois=; b=NwWuwDrHwAGDWk 7xfbKFsrRxlgNj/NQpakIZRw0tSMDZafMwHamlG5tKHCGoAR8lOLSmeHMVzuRnUrhNWQrUDBN42B8 Vw7D8r1L/hOGqQ33jjcieqtSMoZu58p9VIdtmj2zL5kqFoN9N1moI4mF2y1Ydhy4Hc3b86+UUsinN De9WZZmIHyCMXfj9FjSQAHh2II24ussMObvuaZciTgzW7svNZm7SVdYsnztWrAse9atAibP+FZm/s o7vMPcwFOFf8maaa2pea/ns2CXfenhNF/8T1el+Y3nPfo9cjY8Jv2M6ik6FutAQEnCG0RaSmeyDUc Mz5xYeewPZzUP1bfm8Ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCqEz-000xxV-7q; Sat, 16 Jul 2022 22:26:25 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oCqDt-000xST-RJ; Sat, 16 Jul 2022 22:25:19 +0000 Received: by mail-pj1-x102c.google.com with SMTP id cp18-20020a17090afb9200b001ef79e8484aso10206882pjb.1; Sat, 16 Jul 2022 15:25:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HeZBaSe2b0OdhqH1Akhrcs1GY2Xz94hdQRqqwnsXn8k=; b=X63dXK3oXI9/A7LLN4VeFHqJdv5ssf8srCUQDCtmm9vqeQcEob+XIwVHfJymyawNvQ Dd3427QaH8Ql4rLsQkHBZrpJsBtuMP1LzAwyGSppm05rNbwrFwRBdt0OFgBskl/mU2F0 m321DUYtIcTGmqgyk8YtsNYlbxwljCxQHkRcPUlvOmT12dj9MKTELbK6FfocRtMLPbUA MfZXxOdcT7zjD8MDgAwGnLYK5zz1MOv5GoDsuQtQAOXgGxybP9x2AGNcG4IcEnB/Et+O p2kQWVCtR7oqMroZpK+TBx+ahUfKXi+78aR2YkzNgJsG1zRO+VW6Kb5yAEAMmJ3SD+Aq U2+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HeZBaSe2b0OdhqH1Akhrcs1GY2Xz94hdQRqqwnsXn8k=; b=hufEg/OZs/3oOPnOcsLB4xeMMKn1F4bfd6/zt+k/b6h4Er7IEGBmjUBct5ITKeEz7c irXgAdiq3V9DSJAyIQoNwRPoYZA1cfHHGFKv3uRgOAseqySBJkk/es/WExL1CqYoWqWM cPXLC6fr0/N14OFFczYoS4tZT+I1ZHYtXMXWZGp7efbqOPT2legszZ5C1sOd04WOVEqp NMpjGDzPc+/9KIMyRn+I52aZopZWY7kPWzn6ydhl0V0gdhH08m7/Ceqy4Ymyemqzlxoq qE82xhpfnvwLMZjTFZrYsPl7SgRyGMuuNiuUkTklriBYsi366aG2loIRsaiaZCbHfchi NNzA== X-Gm-Message-State: AJIora9sj+f1deKjCaw0CMliwoT0m6ybCoJ75+S8UdbkL4XUg2dt56Hk 07ZhLKpPBiboAQDTyU9mjvQ= X-Google-Smtp-Source: AGRyM1uGmPxUgdybb+yGepSh9vUg1gbQESh8TvcQKrkppQEGDwrJuzFtyujlBWx1CzxylLxgmBywDA== X-Received: by 2002:a17:90a:f2d7:b0:1ef:8859:d61 with SMTP id gt23-20020a17090af2d700b001ef88590d61mr30585783pjb.215.1658010316742; Sat, 16 Jul 2022 15:25:16 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id y12-20020aa78f2c000000b00528c149fe97sm6318662pfr.89.2022.07.16.15.25.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jul 2022 15:25:16 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Bjorn Helgaas , Lorenzo Pieralisi , Cyril Brulebois , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Philipp Zabel , linux-rpi-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-arm-kernel@lists.infradead.org (moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 6/6] PCI: brcmstb: Do not turn off WOL regulators on suspend Date: Sat, 16 Jul 2022 18:24:53 -0400 Message-Id: <20220716222454.29914-7-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220716222454.29914-1-jim2101024@gmail.com> References: <20220716222454.29914-1-jim2101024@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220716_152517_917649_1C19A624 X-CRM114-Status: GOOD ( 17.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If any downstream device can be a wakeup device, do not turn off the regulators as the device will need them on. Link: https://lore.kernel.org/r/20220106160332.2143-8-jim2101024@gmail.com Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 54 ++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 88339fde0df7..570c98594d47 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -264,6 +264,7 @@ struct brcm_pcie { bool refusal_mode; bool regulator_oops; struct subdev_regulators *sr; + bool ep_wakeup_capable; }; static inline bool is_bmips(const struct brcm_pcie *pcie) @@ -1301,9 +1302,21 @@ static void brcm_pcie_turn_off(struct brcm_pcie *pcie) pcie->bridge_sw_init_set(pcie, 1); } +static int pci_dev_may_wakeup(struct pci_dev *dev, void *data) +{ + bool *ret = data; + + if (device_may_wakeup(&dev->dev)) { + *ret = true; + dev_info(&dev->dev, "disable cancelled for wake-up device\n"); + } + return (int) *ret; +} + static int brcm_pcie_suspend_noirq(struct device *dev) { struct brcm_pcie *pcie = dev_get_drvdata(dev); + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); int ret; brcm_pcie_turn_off(pcie); @@ -1322,11 +1335,22 @@ static int brcm_pcie_suspend_noirq(struct device *dev) } if (pcie->sr) { - ret = regulator_bulk_disable(pcie->sr->num_supplies, pcie->sr->supplies); - if (ret) { - dev_err(dev, "Could not turn off regulators\n"); - reset_control_reset(pcie->rescal); - return ret; + /* + * Now turn off the regulators, but if at least one + * downstream device is enabled as a wake-up source, do not + * turn off regulators. + */ + pcie->ep_wakeup_capable = false; + pci_walk_bus(bridge->bus, pci_dev_may_wakeup, + &pcie->ep_wakeup_capable); + if (!pcie->ep_wakeup_capable) { + ret = regulator_bulk_disable(pcie->sr->num_supplies, + pcie->sr->supplies); + if (ret) { + dev_err(dev, "Could not turn off regulators\n"); + reset_control_reset(pcie->rescal); + return ret; + } } } clk_disable_unprepare(pcie->clk); @@ -1371,11 +1395,21 @@ static int brcm_pcie_resume_noirq(struct device *dev) goto err_reset; if (pcie->sr) { - ret = regulator_bulk_enable(pcie->sr->num_supplies, - pcie->sr->supplies); - if (ret) { - dev_err(dev, "Could not turn on regulators\n"); - goto err_reset; + if (pcie->ep_wakeup_capable) { + /* + * We are resuming from a suspend. In the suspend we + * did not disable the power supplies, so there is + * no need to enable them (and falsely increase their + * usage count). + */ + pcie->ep_wakeup_capable = false; + } else { + ret = regulator_bulk_enable(pcie->sr->num_supplies, + pcie->sr->supplies); + if (ret) { + dev_err(dev, "Could not turn on regulators\n"); + goto err_reset; + } } }