From patchwork Wed Nov 3 18:49:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12601483 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 5544AC433F5 for ; Wed, 3 Nov 2021 18:52:54 +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 198D660E78 for ; Wed, 3 Nov 2021 18:52:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 198D660E78 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=QeNBRuOTs0PdB2ULQpvkSQPOcwYYCaPhEM0jtWACevw=; b=eLFgJxYSzcal1T igBIcELuq8h8wH35BMveCtGhZUvL3XOWxWrLNR08264YiHyCBiLiz31JX4sp5GvkpHJEh1eS8m3gD b73gA/PwGFwB9AH1+cHUZdnCgZAJn0uR3gu3u+zJ+I7DhC/OidRwrt9k3oP9BqxB3Hcx7p9sl51rC nEh+wzOXse2XsfqibyfAigARmHnbyToOMt4pTJjU1Q411kdR5LAxt1LCTorG7n26LtJdJrngTEzoT FYA4n62ExqE5+U2TTE4QnmXSRXG/VjNeYHYWZH9Xlj/DZbe0sNr5WMWqSqDCIvBNptQ4cmlrODhXA uDwaP5QMpa90fQUIRT7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1miLM0-006HtG-1A; Wed, 03 Nov 2021 18:51:20 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1miLKm-006HI9-JF; Wed, 03 Nov 2021 18:50:06 +0000 Received: by mail-pj1-x102a.google.com with SMTP id gx15-20020a17090b124f00b001a695f3734aso2117873pjb.0; Wed, 03 Nov 2021 11:50:00 -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=wB1XTHRrUvGXuzH1iZwj1J6GyNltpPCGAayAWSa5LmQ=; b=Jj8wZVtWZX2avHtT6K3bSj2bMG40lbof6al+upIjE7v3prKL0Gs3UxNJozzt8u1SVn qiB3GwgJpsqaYVkk7UAyEGZ5cTHZQwl1Pa2eeY8LKW3uMnVIduLtjV9BsxcaC2Y5xA+N ohXJ0QybXPPWQg4ct6FDvRGTAqwl90ycMiPDNEUqZ4x5zo96VNRGlAVMnpkrdbHLHVmS PrtQiTySChOB2IYY9Eq/7sKmUm9+7mEmLtXjgFHbh4oorXVkDtTnp855HOh3rbg0TMsC OHaVuERpAmLFCLVliDJjGCkRQMM5ZJEWKmTUH9rYGdmuAOVbcSl9q8CPLiJEohehV8/K IPLw== 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=wB1XTHRrUvGXuzH1iZwj1J6GyNltpPCGAayAWSa5LmQ=; b=0zZcQo9c+na6rFRSbfgxA6WGxZ7MvldUwFnzMUy270qjZvpfntLy1/7yo8siRrgdL0 pMGI2//L/ulu5PeSlB/vIowZHJ0T8P9/10PCejnlQRtcSl70VOElojMaxzpXVj+u1oUH E7aXyAbItwfkXQpjCOSzv5rD4P8+XfEGAEif1JS6D4SCl7SiFU+e0cTbuiezsdY6Tnyr 3W3espTLPs0VGBPZ/RXmR5M7M7bjnsd7iduO0rCg8Vhmz+9yNQ5SFNgOFlPJoIWXASzJ YT08Hsfwpwvcn4mn8uwgc+q9vNB7wDpsBA6OOIqs99db41taO8s9YYeqpQ5vbmE8irVG Vl0Q== X-Gm-Message-State: AOAM531nx8deUMIt0RA8SBVOHG0pzqghRcnRL8+VhJgpnHCsWSTCng+7 09jSBEHXjb4TKNwkV32xoZY= X-Google-Smtp-Source: ABdhPJxysJWpo64eRsY6+bwdO1TrGhnH5TPuJXNlA8jir9+FpIYzLpJNg28HsV1AQ62Z5m6fK2zglA== X-Received: by 2002:a17:902:778a:b0:13f:672c:103a with SMTP id o10-20020a170902778a00b0013f672c103amr40891628pll.55.1635965399774; Wed, 03 Nov 2021 11:49:59 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id j6sm2379065pgq.0.2021.11.03.11.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Nov 2021 11:49:59 -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 v7 6/7] PCI: brcmstb: Do not turn off regulators if EP can wake up Date: Wed, 3 Nov 2021 14:49:36 -0400 Message-Id: <20211103184939.45263-7-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211103184939.45263-1-jim2101024@gmail.com> References: <20211103184939.45263-1-jim2101024@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211103_115004_669090_93393B51 X-CRM114-Status: GOOD ( 17.37 ) 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 Reviewed-by: Mark Brown --- drivers/pci/controller/pcie-brcmstb.c | 43 +++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index aaf6a4cbeb78..9aadb0eccfff 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -307,8 +307,20 @@ 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 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; +} + static int brcm_regulators_on(struct brcm_pcie *pcie) { struct device *dev = pcie->dev; @@ -316,6 +328,18 @@ static int brcm_regulators_on(struct brcm_pcie *pcie) if (!pcie->num_supplies) return 0; + + 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; + } + ret = regulator_bulk_enable(pcie->num_supplies, pcie->supplies); if (ret) dev_err(dev, "failed to enable EP regulators\n"); @@ -323,13 +347,28 @@ static int brcm_regulators_on(struct brcm_pcie *pcie) return ret; } -static int brcm_regulators_off(struct brcm_pcie *pcie) +static int brcm_regulators_off(struct brcm_pcie *pcie, bool force) { + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); struct device *dev = pcie->dev; int ret; if (!pcie->num_supplies) return 0; + + pcie->ep_wakeup_capable = false; + + if (!force && bridge->bus && brcm_pcie_link_up(pcie)) { + /* + * If at least one device on this bus is enabled as a + * wake-up source, do not turn off regulators. + */ + pci_walk_bus(bridge->bus, pci_dev_may_wakeup, + &pcie->ep_wakeup_capable); + if (pcie->ep_wakeup_capable) + return 0; + } + ret = regulator_bulk_disable(pcie->num_supplies, pcie->supplies); if (ret) dev_err(dev, "failed to disable EP regulators\n"); @@ -1241,7 +1280,7 @@ static int brcm_pcie_suspend(struct device *dev) reset_control_rearm(pcie->rescal); clk_disable_unprepare(pcie->clk); - return brcm_regulators_off(pcie); + return brcm_regulators_off(pcie, false); } static int brcm_pcie_resume(struct device *dev)