From patchwork Fri Jul 1 16:27:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Quinlan X-Patchwork-Id: 12903590 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 A5938C43334 for ; Fri, 1 Jul 2022 16:29:08 +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=ItjCeIijl1oy+EydhlNjL5kIy9WVqJPOhRjEomalWes=; b=3qw9ClUyYfxV3G FI9UrZlEYnh0/apk3RfOf71QhotPVvqPDiLaH/3ZpAB83ModOksA8Fmt4zr+4/lq769z9fNY/Ijl8 FxOjixdo3PY8+AEyO5CyAtjR3o3iE6P0NIzJq2MjkvOF4KFhgH2Skf/gTfV8oZGk3lkfSvYTeR8Y4 yThNea0tuyJS7JVDHmkzCk03CMV0eISCkA9E3v2D/qqH60e3cXDzlsVGuwtPQHlgU9pBLACp4HBsG eIS7l1rY9hDrEYSaa4JCstKpqP5ZtJICFcbxLgnVX5wdV48P9CKcNM/rywpD/99RsLofUvDgXZ5kK +gtvwNo2E00EDDPsAghA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o7JUr-005yEw-4L; Fri, 01 Jul 2022 16:27:57 +0000 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o7JUX-005y6F-2t; Fri, 01 Jul 2022 16:27:38 +0000 Received: by mail-qk1-x72c.google.com with SMTP id z12so2200040qki.3; Fri, 01 Jul 2022 09:27:34 -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=qiHXGREwuuDLvK36dxnLy6Fvpbb/WnJ2uvPA0Bhu+OY=; b=hrwRgul3paFV+aPBBOjirsiOpDpNDtOkTcPKnmbmbBubKKYjZiNFEcpOT/FN3zT/GX tAvFKbxOPpDmyK7MvGZF+Yew0R1jiFZp7OFdwCzw9/+8ad1hMnhS7rFQcRWE7Cv8YFo9 BhxfmP/BxZMgVGOtk8ReRxJT9MrKQmoZUEti12muZNIpf87iDhhU8A3OgJndqquHgAav 54ly58dF2MyxD4Es2mTKEnDD/cduvc/0WlPGmcjgBB0jKy0KkKCKQ8eCZsLDycrKMZdf KBOqMHEoQjCvO11moMiLChjkpIUmzKit3ly7t5CJcA8N5TBtZ9humOCfO6/CjD9Kw/8W +Yrg== 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=qiHXGREwuuDLvK36dxnLy6Fvpbb/WnJ2uvPA0Bhu+OY=; b=AFm84d6xHv2RPzOP3fhK5xuEW/QA/dF3bNs652aRiHDJQfAhGfKj6iWMN6vG+EnQO3 zqo0KmoVicjkb0rRAeR0e/SYt02O+YuZadBLdcuH/SP8MMp563XXqoprWINWzSf9ujJs EOamBFtpbUesw0YBXLTN/+mdT3dMMvONodM+QsHJ2PXRirBOvUd534q8rjLsdWcy/zJW A7g/WonQUF5ZvAAkkcdV+5bbFpcriJ3L81rJsv21Fc0esuiAHjyPSpy6kpLKpacv1YoF MiJKHoky6gxsc8PZe2hsrmxgpIfsCmFFscEWzZWdHDaqKP10uzFrsGFC1i596mzNfBeD 5iAQ== X-Gm-Message-State: AJIora/fQ+zXVx8ItSxBydX+plcRSOSHsYWbYnNOJRQqZEM3KSSR9PBx H4bVZV6DzRzvTqgX5OnpngE= X-Google-Smtp-Source: AGRyM1s+zwZYRfl9g6C362Ge0wZQLJ2sfPhyquuKbBZNxqNWybgBTk5909rCXeLl0GYE9UAqcRgWXg== X-Received: by 2002:a05:620a:29d0:b0:6af:1bc9:38cc with SMTP id s16-20020a05620a29d000b006af1bc938ccmr10966614qkp.136.1656692853804; Fri, 01 Jul 2022 09:27:33 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.144.250]) by smtp.gmail.com with ESMTPSA id w4-20020a05620a424400b006af08c26774sm17316175qko.47.2022.07.01.09.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 09:27:33 -0700 (PDT) From: Jim Quinlan To: linux-pci@vger.kernel.org, Nicolas Saenz Julienne , Bjorn Helgaas , Lorenzo Pieralisi , Cyril Brulebois , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, james.quinlan@broadcom.com Cc: Florian Fainelli , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=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 v1 4/4] PCI: brcmstb: Do not turn off WOL regulators on suspend Date: Fri, 1 Jul 2022 12:27:25 -0400 Message-Id: <20220701162726.31346-5-jim2101024@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220701162726.31346-1-jim2101024@gmail.com> References: <20220701162726.31346-1-jim2101024@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220701_092737_184596_D52BC265 X-CRM114-Status: GOOD ( 17.55 ) 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 a wakeup device, do not turn off the regulators as the device will need them on. Link: https://lore.kernel.org/r/20220106160332.2143-8-jim2101024@gmail.com 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 a86bf502a265..d417dd366490 100644 --- a/drivers/pci/controller/pcie-brcmstb.c +++ b/drivers/pci/controller/pcie-brcmstb.c @@ -333,6 +333,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; }; static inline bool is_bmips(const struct brcm_pcie *pcie) @@ -1350,9 +1351,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); @@ -1371,11 +1384,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); @@ -1396,10 +1420,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; + } } }