From patchwork Thu Dec 9 21:14:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12695530 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 6597CC433F5 for ; Thu, 9 Dec 2021 21:17:21 +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=pltub6LTkZRc6CSTGQbkFjiS3ggLUAVwQG0uXM3eiPQ=; b=c5LYrOnnfkddjR c48vCOPZlHe4daBSmpFXdZQtjCx1uNgMkLD6EoBIwws81Nrkq/dHvDXwPkO4OOCRpNAEdnfupnuRu gbpsDFZaD3vz1kUyfUpLaWuhuq+L6COs+mU+GgWHbXI2/t79sQkSgKqgBywfMOI1hi9yRjSIe4BJI ixfLC8JuBvg32Cwu+0zLCqyUK5tiXeF9ucl6VdRRMgAb99dZJ8UXF1w8D4BXnQbRxanfL6LGcrMSL /Usv34t99e0qAMRD3WRrgVZkYGJRFG8dfjx+YbxEgbIxZTvzYcO8efUmMXtSOGBqG81mQfTM7FttI FvHDQzNM6mHwijKk+Zsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvQlS-0001LI-VT; Thu, 09 Dec 2021 21:15:43 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvQkM-0000sS-Ob; Thu, 09 Dec 2021 21:14:36 +0000 Received: by mail-pf1-x432.google.com with SMTP id k26so6544456pfp.10; Thu, 09 Dec 2021 13:14:34 -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=1ejdtBcGu/O1Cxw2YS57FB14hxKmb2vB0wySR/Hf7zE=; b=P+EaI414dlrKAt2SUJZUawDH5u9Hkall7tbv2f8N1argny6SjHkSNzI5i3O20hxLPw 7vbSf9pIQxNiHm+ecRl1DIH5aWTMOBsg2NTzk+wu4M3M3stfw0p46uX2TS9ZdvP55JGU eaWrj4a4LjdqNQoFgx1JxCYpSzE4CcAtZwKS3T9NMrZkBgvsuzW0npOmunQuOhihBd+S iAJ+rq5D60kg8F8DqUBnaI4GjvhpwOPB3jxaMLLXPO0Z8XIPi0R33v7/bJGNTqA4T42G jGqp1NaoD7LLePmrRchsCmM6yACSj9Zc1tYX8cMoNauLXNIlmiDj/sDT6JOkSwNzcufL KssA== 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=1ejdtBcGu/O1Cxw2YS57FB14hxKmb2vB0wySR/Hf7zE=; b=Sq2cN31p1oixr1cFHi2jBVdiXz72PYmtj9ZhStCOMB2imODXBBs0tjR0gSMJOcL8Uv dw8LErqOfwOJi7/Uvcdbkdbel+bh51lyv2zD6WN8/t7gDn96yaqg7RjypkUsIY9WKVHm ceQS039UqgW0T1/ZKp5n62trK350UvVxbYotM+6XaFqVnICI7AG9dKq9AAa7Q9pU6TcK pcmZXwQc/KnUoA7Nl43uM+Zn0CuG3b7krCihOrUkYxY+jRzEya1E4Bmp0uNDSV6GVzlZ o6RYDjo65x2pcgPCLTtOgGqpArHBNL1/luxOWu4cbvN0nH37eXFD9XqssVUB54g262BQ w9VA== X-Gm-Message-State: AOAM530omR6BDMieKhY/4dDC8qfigrxFtuIH/7buJs+V1CtPwzOeTkxX BRekArRvkA3AI2kgLGrmBr0= X-Google-Smtp-Source: ABdhPJwyhlwJggiRgi7BqXbJk7CM8QL1w7vHCs91o46x2lSJhd/S8prWb7v2FHaHQ4pEeoXNclYBiw== X-Received: by 2002:a05:6a00:244b:b0:4ad:5852:f41d with SMTP id d11-20020a056a00244b00b004ad5852f41dmr14392033pfj.29.1639084473656; Thu, 09 Dec 2021 13:14:33 -0800 (PST) Received: from stbsrv-and-01.and.broadcom.net ([192.19.11.250]) by smtp.gmail.com with ESMTPSA id y4sm617800pfi.178.2021.12.09.13.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 13:14:32 -0800 (PST) From: Jim Quinlan To: linux-pci@vger.kernel.org, Bjorn Helgaas , 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?= , 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 v10 7/7] PCI: brcmstb: Do not turn off WOL regulators on suspend Date: Thu, 9 Dec 2021 16:14:05 -0500 Message-Id: <20211209211407.8102-8-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211209211407.8102-1-jim2101024@gmail.com> References: <20211209211407.8102-1-jim2101024@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211209_131434_837945_75522880 X-CRM114-Status: GOOD ( 17.71 ) 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 9b4df253e79a..8e5cbf6850cd 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -298,6 +298,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; }; /* @@ -1166,9 +1167,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); @@ -1187,11 +1200,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); @@ -1212,10 +1236,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; + } } }