From patchwork Fri Oct 22 14:06:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12577915 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 818AFC433FE for ; Fri, 22 Oct 2021 14:11:27 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4C4526124A for ; Fri, 22 Oct 2021 14:11:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4C4526124A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=Cb1pWMaIp8kFIfLG16wx8citIKiANCfdOTaSNSClZxs=; b=AjuJtwK8nI44Cy nvlFbiOwlWqbbalvSwnlByLy5VQKUpWGsTlck4+X3yoLvF+J+qg+T5nV0npbxAjlonVKgZy5oDiWX ywdBWBldOHksWwFpyAE0g0wsVteRgzKqeydyYNMEFMDEbO1j/Bj8QyOKX4n/ylRksNbHdm4pBQS49 YwxkdSgMjv8ZMfr7QK4Tkxl/AYPT3HL2IOdxxxGE+H+gZLJljd7xqvdoV9vMl3whd+LQsCw55YpNx VJn+YXuMlO8DkWMaOdEQ30jrUPx/vWq5zO1PiItqbG0H82afKc8Danfoi3MZ3TETzYY8h6gAn9Krg YgRSvy+sM0dmV00xy81Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdvDa-00BC9I-84; Fri, 22 Oct 2021 14:08:22 +0000 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdvCp-00BBrc-DK; Fri, 22 Oct 2021 14:07:37 +0000 Received: by mail-pg1-x52b.google.com with SMTP id q5so3415864pgr.7; Fri, 22 Oct 2021 07:07:35 -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=1OFqIrT+18a19n7objTdvw3Haq7UJKXHt+0jk9CGrew=; b=NhSB2bAHDpM6mMF01d5U0eL/0XiFzhOfpiCYIEyHu+ctod2WCJ9m/yRZ4wVCwUmO08 0xqarR1YZzFPtvT3Xk7EkOJ4TEvsgOfcFuyWHiyVucvPmSkiL5ZHihtqLjmF+Yr7hWhf R5YSYZt28A6h6iiu+QvFR2wrIZfspQX+msQbm7JQUB2C29zyCtJSb+fPTMdwZbI5OIXd leWMTdvIUbW7+kWg7KVNEtpKewqWRh+NciaP8z5psOfS0h5/C5yOaU4ab7jlA8p6POqQ LJdFPtmYSFbUaIcq6gATySfTseWlujhUPLBxNKRDHt8d51FgyDPb1d8c+4DaeJU5y67o rIsA== 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=1OFqIrT+18a19n7objTdvw3Haq7UJKXHt+0jk9CGrew=; b=OrspByeYeBg+jGqgiYxtQ3g3GYqdJTjJ9yEapWB1+DIYCCax+97c3isV0ILsBOhUSd p0Q8tjCaCvCRO9QtB4t2akxZjy0eoTsw24MKJjCs3I0NFJzablWqYX1/DXXr+bPZ0Cif CG4ajYWIlTiqa4EfJqaLNesZwD5PIscJ4ZnofSCzZ26xkGAoWkwVh/40hLiQIoyaTSEE koOGtlY8QXNKuv/y89GEJ+/1HbCNQOBXUUs74AdJM7xEK8B0k3M0sVY56R/ZLaCvVysW 98Fya44rMANfkeOb4DV6iKdKjQSeBYfG+CPSFkbcxUBjuvhJUZM7bVZcEIGEwmPnCJIX ENhQ== X-Gm-Message-State: AOAM533VzeG19MLerOMnAnxfTFE787eg+Sp7itELMPPUzq2YhbZvD5HW Mlv3uStPs3BnsQby0AnCMN/kZ3UZgAwE8A== X-Google-Smtp-Source: ABdhPJxGxUjF1hom1kgQ2Wlvy0rCVgLkb5Yatk+nFFmu0vYBaqDoZMn4pg6f+ZsIfDDNpcsrdMSL2g== X-Received: by 2002:a05:6a00:2484:b0:44d:ce87:3627 with SMTP id c4-20020a056a00248400b0044dce873627mr258943pfv.48.1634911654640; Fri, 22 Oct 2021 07:07:34 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id e12sm9482990pfl.67.2021.10.22.07.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 07:07:34 -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: Florian Fainelli , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Bjorn Helgaas , 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 v5 5/6] PCI: brcmstb: Do not turn off regulators if EP can wake up Date: Fri, 22 Oct 2021 10:06:58 -0400 Message-Id: <20211022140714.28767-6-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022140714.28767-1-jim2101024@gmail.com> References: <20211022140714.28767-1-jim2101024@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211022_070735_497730_331E60D2 X-CRM114-Status: GOOD ( 18.78 ) 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 | 59 +++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 35924af1c3aa..505f74bd1a51 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -192,6 +192,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[] = { "vpcie3v3-supply", @@ -305,22 +306,65 @@ struct brcm_pcie { void (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val); struct regulator_bulk_data supplies[ARRAY_SIZE(supplies)]; 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; } @@ -1234,7 +1278,7 @@ static int brcm_pcie_suspend(struct device *dev) reset_control_rearm(pcie->rescal); 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) @@ -1250,7 +1294,8 @@ static int brcm_pcie_resume(struct device *dev) ret = reset_control_reset(pcie->rescal); if (ret) goto err_disable_clk; - ret = brcm_set_regulators(pcie, true); + + ret = brcm_set_regulators(pcie, TURN_ON); if (ret) goto err_reset; @@ -1297,7 +1342,7 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie) reset_control_rearm(pcie->rescal); clk_disable_unprepare(pcie->clk); if (pcie->num_supplies) { - (void)brcm_set_regulators(pcie, false); + (void)brcm_set_regulators(pcie, TURN_OFF_ALWAYS); regulator_bulk_free(pcie->num_supplies, pcie->supplies); } } @@ -1348,7 +1393,7 @@ static int brcm_pcie_pci_subdev_prepare(bool query, struct pci_bus *bus, int dev return ret; } - ret = brcm_set_regulators(pcie, true); + ret = brcm_set_regulators(pcie, TURN_ON); if (ret) goto err_out0;