From patchwork Mon Nov 30 21:11:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 11941313 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=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, T_TVD_MIME_NO_HEADERS,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 5F5A4C63777 for ; Mon, 30 Nov 2020 21:14:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E54802073C for ; Mon, 30 Nov 2020 21:14:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="O0M7tkuz"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="UaTLtG5P" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E54802073C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type:MIME-Version: Cc:List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EKKHW2I80BFbL6i7qy23LHl0JSoWxOSNYANRfAROggA=; b=O0M7tkuzP8qK3BWVg6rtrfe9U hxek+/cCmQjwjnB+ySiwHxj1kIKLeaXKAklQ1WtbTcAAB3TgBz/+fHWExlDKxxAMDPmZxcQ1I38JF F3Shkor6qmvbZYdnk3piU8qvGL7E1dnMcQYNzqyUfpPO7sZo31Bgwns6rSfjmvsSvsvVAMvpJBwuu atcti4STOCV5MerpmDp9TYJPABwZFJJOczX5tKgz8bYN7eNWxVCUCUzYceJwfARo1REPTi0aQNH4J lmDiIGQN84u3dkBrzyeBnEy3fgqCq//FOnfvA8hm02U40B3AyqymVQxITB7LofirciDTZn7dO4aum w7dBvDJRQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjqTN-0003BG-QR; Mon, 30 Nov 2020 21:12:37 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjqSs-00031j-0l for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2020 21:12:07 +0000 Received: by mail-pf1-x442.google.com with SMTP id w202so11229170pff.10 for ; Mon, 30 Nov 2020 13:12:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lRE6nXlSTX/JDIik5RYL7aM0Sq2Cl6+aagZWppbZQ4g=; b=UaTLtG5PnQg/k8Z4297aUG9bKRIW07Glj12KMan6CKpY17KWcwOHvola/AQ5Ivywk4 WfHT14jagjUxAUJ80Oa/A2htiRrnvzJJYzIHxWqJMEyy6UPRpD5B3LX4DZtuqDa7SNFV 2B9Otj8VkMB0qOI/BzH2ABxk4aBceBuEWeHQU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lRE6nXlSTX/JDIik5RYL7aM0Sq2Cl6+aagZWppbZQ4g=; b=WBwbaD3LdFoewMy47oLCmzIjyTBmDOMiBG7d00Q4vxkw3H+bNkNkQgE8yZqfO9EkW0 4/WfUKzBJmzGa3HGcFqn6e+N0s56B3bMW5iW/7fcacezZTcNZ56A/NVvEaTHcDGXCODr 1U8gb9l5/uSu+6Tt0kDCRHOonCrDaTW2UbnREhEqXSNLxSgmF9QZRoTjMGM+kA6JpuC8 Xbv5n+ZtABiOo+01Sdq03pYIXx1Yfo07gzXLixZxQ6y5nPKB7FqV/5s6vJBsJp/CnnJ2 WvBZT5FPW5joZT8ve9MNjoqHLWS383CewWJAws6Hv9mRZbHRaOz4k/ibD9JOXdEO84pz TFxQ== X-Gm-Message-State: AOAM530SlPDGceQRqxJ04XWOUIXJ/PXspnAs9Xh65lWIKMlHV68h93xy W4djp5F1BSb/K8rlqAf+tDahpA== X-Google-Smtp-Source: ABdhPJwMd1CCQvBOAMbqF/0wJd5EeppOZWpk+YTnQgPqG8KZtSB3jjVuH2ZDtwVcb814gD9On3a0lw== X-Received: by 2002:a62:4e15:0:b029:197:98e1:15c4 with SMTP id c21-20020a624e150000b029019798e115c4mr20817960pfb.39.1606770723827; Mon, 30 Nov 2020 13:12:03 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.231.250]) by smtp.gmail.com with ESMTPSA id m7sm18320441pfh.72.2020.11.30.13.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2020 13:12:03 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , broonie@kernel.org, bcm-kernel-feedback-list@broadcom.com, james.quinlan@broadcom.com Subject: [PATCH v2 3/6] PCI: brcmstb: Do not turn off regulators if EP can wake up Date: Mon, 30 Nov 2020 16:11:40 -0500 Message-Id: <20201130211145.3012-4-james.quinlan@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201130211145.3012-1-james.quinlan@broadcom.com> References: <20201130211145.3012-1-james.quinlan@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_161206_121172_CCBA5C0D X-CRM114-Status: GOOD ( 17.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , Lorenzo Pieralisi , open list , Florian Fainelli , "moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" , Bjorn Helgaas , "moderated list:BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE" 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 may wake up during S2/S3 suspend, we do not want to turn off its power when suspending. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 58 +++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 9d4ac42b3bee..cbdb315d4b2f 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -193,6 +193,7 @@ static inline void brcm_pcie_bridge_sw_init_set_7278(struct brcm_pcie *pcie, u32 static inline void brcm_pcie_bridge_sw_init_set_generic(struct brcm_pcie *pcie, u32 val); static inline void brcm_pcie_perst_set_7278(struct brcm_pcie *pcie, u32 val); static inline void brcm_pcie_perst_set_generic(struct brcm_pcie *pcie, u32 val); +static bool brcm_pcie_link_up(struct brcm_pcie *pcie); enum { RGR1_SW_INIT_1, @@ -293,14 +294,57 @@ struct brcm_pcie { void (*perst_set)(struct brcm_pcie *pcie, u32 val); void (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val); struct regulator_bulk_data supplies[ARRAY_SIZE(ep_regulator_names)]; + bool ep_wakeup_capable; }; -static void brcm_set_regulators(struct brcm_pcie *pcie, bool on) +static int pci_dev_may_wakeup(struct pci_dev *dev, void *data) { + bool *ret = data; + + if (device_may_wakeup(&dev->dev)) { + *ret = true; + dev_dbg(&dev->dev, "disable cancelled for wake-up device\n"); + } + return (int) *ret; +} + +enum { + TURN_OFF, /* Turn egulators off, unless an EP is wakeup-capable */ + TURN_OFF_ALWAYS, /* Turn Regulators off, no exceptions */ + TURN_ON, /* Turn regulators on, unless pcie->ep_wakeup_capable */ +}; + +static void brcm_set_regulators(struct brcm_pcie *pcie, int how) +{ + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); struct device *dev = pcie->dev; int ret; - if (on) + if (how == TURN_ON) { + if (pcie->ep_wakeup_capable) { + /* + * We are resuming from a suspend. In the + * previous 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; + return; + } + } else if (how == TURN_OFF) { + /* + * If at least one device on this bus is enabled as a + * wake-up source, do not turn off regulators. + */ + pcie->ep_wakeup_capable = false; + if (bridge->bus && brcm_pcie_link_up(pcie)) { + pci_walk_bus(bridge->bus, pci_dev_may_wakeup, &pcie->ep_wakeup_capable); + if (pcie->ep_wakeup_capable) + return; + } + } + + if (how == TURN_ON) ret = regulator_bulk_enable(ARRAY_SIZE(ep_regulator_names), pcie->supplies); else @@ -308,7 +352,7 @@ static void brcm_set_regulators(struct brcm_pcie *pcie, bool on) pcie->supplies); if (ret) dev_err(dev, "failed to %s EP regulators\n", - on ? "enable" : "disable"); + how == TURN_ON ? "enable" : "disable"); } /* @@ -1161,7 +1205,7 @@ static int brcm_pcie_suspend(struct device *dev) brcm_pcie_turn_off(pcie); ret = brcm_phy_stop(pcie); clk_disable_unprepare(pcie->clk); - brcm_set_regulators(pcie, false); + brcm_set_regulators(pcie, TURN_OFF); return ret; } @@ -1174,7 +1218,7 @@ static int brcm_pcie_resume(struct device *dev) int ret; base = pcie->base; - brcm_set_regulators(pcie, true); + brcm_set_regulators(pcie, TURN_ON); clk_prepare_enable(pcie->clk); ret = brcm_phy_start(pcie); @@ -1213,7 +1257,7 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie) brcm_phy_stop(pcie); reset_control_assert(pcie->rescal); clk_disable_unprepare(pcie->clk); - brcm_set_regulators(pcie, false); + brcm_set_regulators(pcie, TURN_OFF_ALWAYS); } static int brcm_pcie_remove(struct platform_device *pdev) @@ -1308,7 +1352,7 @@ static int brcm_pcie_probe(struct platform_device *pdev) return ret; } - brcm_set_regulators(pcie, true); + brcm_set_regulators(pcie, TURN_ON); ret = brcm_pcie_setup(pcie); if (ret) goto fail;