From patchwork Thu Jan 6 16:03:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12705525 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 21B1EC433EF for ; Thu, 6 Jan 2022 16:07:02 +0000 (UTC) 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=nnrh4OVBiAnfNP/D+ywQs75c2PYsX+3rCuLvKYg6He8=; b=Km/uRjicMdEOP7 YiDtA4dUXSNj3Is8+ubrTXpXxVP/v988zs44gW5mc0XcApHZz5ltbbQYvJbEVqXd/SKPjSZcJ5unM hphCSY6MNt7c97Gl04hFBD8WrRcI5Ir1NvyFnQwA3gQo4mVh8rNj6TneoG/ecT089tL1r4IASzNiz ROYr4Q7VVmRaTKXMz2ayK9kpaAV6CyyKjyv/3fLuC8MxP4ROM6VtzGXQUitP0/q0V9HajeL5+8f8t NA0ausvu3lQDDAmUmlwSPbZWlW6Dl/KAdPj24SihgwXK6yKPpA17Ij/NHpdmJhqWv3kOf0rwVR2j6 XYuE3jFUMbQPyuR0WFCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5VGe-000Xrv-PP; Thu, 06 Jan 2022 16:05:34 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n5VFA-000XA1-8l; Thu, 06 Jan 2022 16:04:01 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 59-20020a17090a09c100b001b34a13745eso1762011pjo.5; Thu, 06 Jan 2022 08:03:59 -0800 (PST) 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=UHomRXytyYgyL9vtpaE63/zjvL/tbxiA4ouQRYYuZNM=; b=c5EaoEwe0k4Y+kQIV5nbnpVpnij3u8gmP/HYggIXoYlNSEvMPLnJC2YgPb+PeLhYoT 8UadcBboJznJOT1R9M3EfhTqcV6yUGz5bFxz5+EDQOknZ+UdlZCzqnb3rFnotQuUDUAk CBU8emUqfl/XtO5E3i5RMpAaaaKOFS9xMYCsDjzf/Q29aWqp09nbgZXGxoQmGsh8Yh1B pto/5wpZLodO0Ia4hUclXeiSILBIAaUAMUZPet147zwswHA3gAMCGnx5pdIBQ8eqj5Dn P05OgdMsdVUT1C+iseGBwrBYLgP5aNnFgtN7ia+2+bK10VwGX5bhMhT2wxQ1VIeoV2da iLlw== 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=UHomRXytyYgyL9vtpaE63/zjvL/tbxiA4ouQRYYuZNM=; b=3pCcVXGeU4vkYgPhddZzYnuYoqDaAVVaERci5FOh5Xw2+SdzK10f/2uqsFbS+j0UdU ovbK8wClKJrqfwUYzFZFEK+0y/hMFvIGijRkJwRgoCgUB06t2E71w7wgaLH+NnTHEuyq x4nhPhcp8jmuhESqZfM79zzc4+mjzmSkeRPuv+GbOJHa70PZV18J8+tgSeH7cO8KCZKu fHRkJogbF+a7iEBhlTMWo3EW3qoM36vaQtTCCkl1BCE/iqSVCmsOFAai0+v2VhvA6avM lbNdEB8WfL/zAll+ZhmpYO9X1oBRJeXzD9d8WpEg1Oi7OLwzBKFxyfXAdeUyd1kl+pyX +tLQ== X-Gm-Message-State: AOAM530JYdt/peVYvuX0e/SU/IqPUYj/C/9gVGpzGyHl4ESSe66DNbNr UYZdNChcWgcp0/VtcPVEFYhFacYfYbw= X-Google-Smtp-Source: ABdhPJx6++vXFv73cMhMbu7dLZ1FYH3JW6xuu7wKmHwNUI65WS5IwVZh0B82ylv7LxL5ZzRpeFIaHA== X-Received: by 2002:a17:902:c401:b0:149:7451:2200 with SMTP id k1-20020a170902c40100b0014974512200mr51383018plk.14.1641485039575; Thu, 06 Jan 2022 08:03:59 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id q19sm2376316pgb.77.2022.01.06.08.03.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 08:03:59 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , Nicolas Saenz Julienne , Lorenzo Pieralisi , Rob Herring , Mark Brown , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Philipp Zabel , 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 v11 7/7] PCI: brcmstb: Do not turn off WOL regulators on suspend Date: Thu, 6 Jan 2022 11:03:30 -0500 Message-Id: <20220106160332.2143-8-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220106160332.2143-1-jim2101024@gmail.com> References: <20220106160332.2143-1-jim2101024@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220106_080400_333842_E6B8D596 X-CRM114-Status: GOOD ( 18.08 ) 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 can be awoken do not turn off the regulators as the device will need them on. Signed-off-by: Jim Quinlan --- drivers/pci/controller/pcie-brcmstb.c | 53 ++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c index 3c1b2fefe7e1..8a3321314b74 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -308,6 +308,7 @@ struct brcm_pcie { void (*bridge_sw_init_set)(struct brcm_pcie *pcie, u32 val); bool refusal_mode; struct subdev_regulators *sr; + bool ep_wakeup_capable; }; /* @@ -1269,9 +1270,21 @@ static void brcm_pcie_turn_off(struct brcm_pcie *pcie) pcie->bridge_sw_init_set(pcie, 1); } +static int pci_dev_may_wakeup(struct pci_dev *dev, void *data) +{ + bool *ret = data; + + if (device_may_wakeup(&dev->dev)) { + *ret = true; + dev_info(&dev->dev, "disable cancelled for wake-up device\n"); + } + return (int) *ret; +} + static int brcm_pcie_suspend(struct device *dev) { struct brcm_pcie *pcie = dev_get_drvdata(dev); + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); int ret; brcm_pcie_turn_off(pcie); @@ -1290,11 +1303,22 @@ static int brcm_pcie_suspend(struct device *dev) } if (pcie->sr) { - ret = regulator_bulk_disable(pcie->sr->num_supplies, pcie->sr->supplies); - if (ret) { - dev_err(dev, "Could not turn off regulators\n"); - reset_control_reset(pcie->rescal); - return ret; + /* + * Now turn off the regulators, but if at least one + * downstream device is enabled as a wake-up source, do not + * turn off regulators. + */ + pcie->ep_wakeup_capable = false; + pci_walk_bus(bridge->bus, pci_dev_may_wakeup, + &pcie->ep_wakeup_capable); + if (!pcie->ep_wakeup_capable) { + ret = regulator_bulk_disable(pcie->sr->num_supplies, + pcie->sr->supplies); + if (ret) { + dev_err(dev, "Could not turn off regulators\n"); + reset_control_reset(pcie->rescal); + return ret; + } } } clk_disable_unprepare(pcie->clk); @@ -1315,10 +1339,21 @@ static int brcm_pcie_resume(struct device *dev) return ret; if (pcie->sr) { - ret = regulator_bulk_enable(pcie->sr->num_supplies, pcie->sr->supplies); - if (ret) { - dev_err(dev, "Could not turn on regulators\n"); - goto err_disable_clk; + if (pcie->ep_wakeup_capable) { + /* + * We are resuming from a suspend. In the 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; + } else { + ret = regulator_bulk_enable(pcie->sr->num_supplies, + pcie->sr->supplies); + if (ret) { + dev_err(dev, "Could not turn on regulators\n"); + goto err_disable_clk; + } } }