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: 11941329 X-Patchwork-Delegate: lorenzo.pieralisi@arm.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=-20.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_HEADER_CTYPE_ONLY, 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 C3D37C83014 for ; Mon, 30 Nov 2020 21:13:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E0CA206A5 for ; Mon, 30 Nov 2020 21:13:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="FpgGNC2D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387752AbgK3VNR (ORCPT ); Mon, 30 Nov 2020 16:13:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388139AbgK3VNQ (ORCPT ); Mon, 30 Nov 2020 16:13:16 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6845C061A49 for ; Mon, 30 Nov 2020 13:12:04 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id q3so3116366pgr.3 for ; Mon, 30 Nov 2020 13:12:04 -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=oQ9LlkkMxS2nc8KVid/xVdHfjgV0dxv/j2t4oViJb00=; b=FpgGNC2D5cix9E5RrsFlRcPreobJBvPaXkEklEW8f9H0s5BRTCvaugICn1nQz2xzD9 EKHpW8aBfeabdWZNTdyu0FBJvL93FK+Qd41rh7lXGMwRoFTjlKm7pA3wou4jEpr35YPT mXxSrg7Pcqcwo7GKddSgBrGrMgx85ULrA7ou4= 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=oQ9LlkkMxS2nc8KVid/xVdHfjgV0dxv/j2t4oViJb00=; b=cf1Vt7dqJr/JTLYP6FWEqPsGtWis8b5uZxOH3RQUFNtBJJBds24T7hVNvJ8ZqJOktb 5vH/2HosZ7wa4rRrDS/8bYllMr+FWWa1Yzuj87UdcLgx+Y7kcoOgms9LIkJQ5xjSRL+o TVvNYe8bvF01uA/Eu6kGtiVrE+jBtB434Tj7VtWi9xbM/RiAg32Isi4itpctae6IPseM 61DcubQyFK3VQIj6c9onTLORCUvxRWHVUjNt+x1ar/+7dJtCVUm96XsUG1pLTsmEgQhb 4tawdd+VFtlqsCfnQ41n5SaFO9yMQIT+3z3Kf4ognT+mNG191j34Jp2YwpLlHoaIdX98 3HUw== X-Gm-Message-State: AOAM533QdoQOqo+BIuxSEi46DQ4JwBvWHgjjGLt4hrE/tvRe4dbyABtZ F/uy3kUjxe4IsTCXhpbXHonk+eU+M9yYGTon5EegAFIDlLGmZO0bBKWZkiquKvDWsWNPrthnMLR xZ4Uyvs8hzPtQo0+m+bZOmcde5W03N/L+9nBHdOCopD/iG//ZUymoVFSKYwxe5ly7G3wCv//IAX yK8wCS 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 Cc: Lorenzo Pieralisi , Rob Herring , 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 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> Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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;