From patchwork Thu Apr 1 21:21:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12179599 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=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 C88D2C433ED for ; Thu, 1 Apr 2021 21:32:12 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 3CE23610FB for ; Thu, 1 Apr 2021 21:32:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CE23610FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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=desiato.20200630; 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=c5+oO3EGoE3ZGWwXTK2yjMA8du7ua7c0s0X+3Ok+4wk=; b=ikNyzz/dCL5v7JyNnq+pOgVc7F e0lgJs9ni6/Kr7315PeQwYDpqHl4Yf2e7/4i3Abw71sg3qYMTCGeuj8J8+C2cDnHhbM/ylYu+BBDe 0CSSHkaSZZXK+0LD/AjoPPWvFMpA6YJGplfVlJ/aUUiUAkYKiKlCNLLajnChD1EBHqQ0H3riShc/u EpEkVv0rFIBtH+x/S4bU9lfSYorllXwAPx5oj+IXavcmQOEAbYr5C77mQXhzqeQxkpgKt0Y0QuPI3 2+jpUce9aDMt9cMExUKBwX4wy11+VxBr1isQw0kxb3a84gNXgVwxfR31zEX0RnieiPB3fO3s/Z94X 1GrU7nUA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lS4sH-00B3sj-CD; Thu, 01 Apr 2021 21:29:11 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lS4lQ-00B35R-1b; Thu, 01 Apr 2021 21:22:53 +0000 Received: by mail-pf1-x433.google.com with SMTP id m11so2323290pfc.11; Thu, 01 Apr 2021 14:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3Svmj4M57E9UEJUPztxJxLaD+qDYLkSPzt9oL2QtC44=; b=QdAOl64swAv8QPAkhS3LmoBMm77A/m1F7ZHnm2l6hl7zkTCmQRw6maRV9rcYq2IQYS SDu+c5Ia41SWN6rSBDaNecTwacaO+Pq9gHj+ium+lNYkeyUi1Pa4c7ff6LrA8/qJWaHk MTXBeFEmdYgSWt2MzNBAj5utjpdWkdVtqlj4HrFWm4NdYESeDlxCx4eNMS3J0hU0fc+L lR6YldvvVtve8TN2mJ//NKZ4zSHIUrF6pqjG08HFHz4491EgU9U+OBLy4hhOLEDL2O8w wYcHFxaWkSM04kEfVEJk9SncgCAO0nj6LoYJ7s3jvM3bkkO8dmx95pQdycDKCxAKTlNh lc0w== 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=3Svmj4M57E9UEJUPztxJxLaD+qDYLkSPzt9oL2QtC44=; b=BY9BdmCj8pt0LnC5wltCt2XUtvSqpcTYVlw1u4v35T+Y61K+PfnHvNlwBXn8HWTgwT QNefdbADXUO6Jy/Np0HGZD3JR11rSJYMkk1AERX8ZJ9JAQGRDTCL6Tid3P5rk1HGQ6+m 3HSCbL01lxI/hUXVp25o8Ss+l5fn+CysaH2RPM9Qk8prkSBLUNiXUnz85dd4mH7eoy/W oDGfOrwJtrzhIP3QiG8gTZEnrATRzpmvhHu0x2yzH52irBG/6AVZRgL/9qKPItTYpfo9 3q/nwHxHOcmHn8HosG0sqC/qdhOVU4f7Da3fA/a/0aNSinYAqiMIfZ8xzA64GGr6uBR9 gUUQ== X-Gm-Message-State: AOAM5313Uuku03G6A1TpWyi2l7fFPSKLb9UpGnH6wvbD1ELBzEghaZdV 1eATojhLOCCCLtW0+eGDiDk= X-Google-Smtp-Source: ABdhPJwi3QBpg+AUACKEeirWBOo7RVmBvkFoAwhc7TIv+cKY68bgc16eXAS34emUMg33TpkYzsMKDQ== X-Received: by 2002:aa7:9478:0:b029:1fd:1fc1:bdfe with SMTP id t24-20020aa794780000b02901fd1fc1bdfemr9225842pfq.57.1617312122653; Thu, 01 Apr 2021 14:22:02 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.231.250]) by smtp.gmail.com with ESMTPSA id q5sm5926707pfk.219.2021.04.01.14.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 14:22:02 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Lorenzo Pieralisi , Bjorn Helgaas , Florian Fainelli , 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 v4 4/6] PCI: brcmstb: Do not turn off regulators if EP can wake up Date: Thu, 1 Apr 2021 17:21:44 -0400 Message-Id: <20210401212148.47033-5-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210401212148.47033-1-jim2101024@gmail.com> References: <20210401212148.47033-1-jim2101024@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210401_222249_689928_0F72E341 X-CRM114-Status: GOOD ( 19.23 ) 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 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 1b0de0c7da60..4c79aff66de7 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_generic(struct brcm_pcie *pcie, static inline void brcm_pcie_perst_set_4908(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); static const char * const supplies[] = { "vpcie12v-supply", @@ -304,22 +305,65 @@ struct brcm_pcie { void (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val); struct regulator_bulk_data supplies[PCIE_BRCM_MAX_EP_REGULATORS]; unsigned int num_supplies; + bool ep_wakeup_capable; }; -static int 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 regulators 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 int 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 (!pcie->num_supplies) return 0; - 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 0; + } + } 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 0; + } + } + + if (how == TURN_ON) ret = regulator_bulk_enable(pcie->num_supplies, pcie->supplies); else ret = regulator_bulk_disable(pcie->num_supplies, pcie->supplies); if (ret) dev_err(dev, "failed to %s EP regulators\n", - on ? "enable" : "disable"); + how == TURN_ON ? "enable" : "disable"); return ret; } @@ -1206,7 +1250,7 @@ static int brcm_pcie_suspend(struct device *dev) brcm_phy_stop(pcie); clk_disable_unprepare(pcie->clk); - return brcm_set_regulators(pcie, false); + return brcm_set_regulators(pcie, TURN_OFF); } static int brcm_pcie_resume(struct device *dev) @@ -1221,7 +1265,7 @@ static int brcm_pcie_resume(struct device *dev) if (ret) return ret; - ret = brcm_set_regulators(pcie, true); + ret = brcm_set_regulators(pcie, TURN_ON); if (ret) return ret; @@ -1261,7 +1305,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) @@ -1360,7 +1404,7 @@ static int brcm_pcie_probe(struct platform_device *pdev) goto fail; } - ret = brcm_set_regulators(pcie, true); + ret = brcm_set_regulators(pcie, TURN_ON); if (ret) goto fail;