From mboxrd@z Thu Jan 1 00:00:00 1970 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 DA413C43334 for ; Thu, 23 Jun 2022 22:21:28 +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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Owner; bh=2F3zyaxXTcmIWDacUx7elUkM2EAFfOQrcnXdYAw85fk=; b=CAmlFOpnb8KQhx x8y453LiOnUlbDOlacYIqoMGZ8LMd80wtJrmboGFl+s5D/r9RpJtNa4bbrOMPVuvEi3+1hGUXHAk/ Xayp2ULuKbNeTqZ7uAqKfhD2wDqMbiHhjSmlj+lmxoKA4XCmV3VENs5/nJO5YgcPVOJNg5k0ylBGd WuBdVFKnvs5n/4/S0GFN+AE5gAwUEezsCXp483sHKu1wyFn3PW8biNs2Rv8MTPNy3SxLj3K3QdBjo H1o4ZHhPEILrJohSgChrVj8WxjleZ9oCAxNsNNQKGML97VFSgJqGWEDXUxIs8qI1OM8G3559RYScX 479m7+QJ+5rlRPFlmn1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4VBG-00Gxrr-8K; Thu, 23 Jun 2022 22:20:06 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o4VBC-00Gxq8-IL for linux-arm-kernel@lists.infradead.org; Thu, 23 Jun 2022 22:20:04 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 371CDCE2478; Thu, 23 Jun 2022 22:19:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19DD0C341C0; Thu, 23 Jun 2022 22:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656022786; bh=QAkJ/pcFV9yqibLp92B+VmLbcqZsNm4Yso6Az/wbnpE=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=hdZKwMzG/HUQuKB2JpKSbsV1P/U/fmb1yFZJi5ycNayyitbPFMrc1/OCwO8LOnZAP vEhiyag4kpzawOkGBP2hb+NuSCEF2ntDugFO319cDBDo0S1sVkDguWARedIoBlkQkb iBnT2Lt89PiCZ9pnhHRg+Id1YH+g8xHlKhLhhGZBdvPMNd1ILrrhQFrgZGCxa/gr+I sPrhtcgvmISqfAuvEuzyS9e2s78Xu8rpNIKD+WljYBWbFlGszTMuENQA3HF++gWa+z 3EEqBMutWiVl5+i/UYIHy9JQpuDPxjqM+SpqFMvnf53QmiSUEdsg3TKSUzMeOBGmj2 MumwRAzI72hbQ== Date: Thu, 23 Jun 2022 17:19:44 -0500 From: Bjorn Helgaas To: Richard Zhu Cc: l.stach@pengutronix.de, bhelgaas@google.com, robh+dt@kernel.org, broonie@kernel.org, lorenzo.pieralisi@arm.com, festevam@gmail.com, francesco.dolcini@toradex.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, linux-imx@nxp.com Subject: Re: [PATCH v13 10/15] PCI: imx6: Turn off regulator when system is in suspend mode Message-ID: <20220623221944.GA1481121@bhelgaas> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1655461874-16908-11-git-send-email-hongxing.zhu@nxp.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220623_152003_027102_A601B4F7 X-CRM114-Status: GOOD ( 24.41 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jun 17, 2022 at 06:31:09PM +0800, Richard Zhu wrote: > The driver should undo any enables it did itself. The regulator disable > shouldn't be basing decisions on regulator_is_enabled(). > > Move the regulator_disable to the suspend function, turn off regulator when > the system is in suspend mode. > > To keep the balance of the regulator usage counter, disable the regulator > in shutdown. > > Link: https://lore.kernel.org/r/1655189942-12678-6-git-send-email-hongxing.z > hu@nxp.com > Signed-off-by: Richard Zhu > Signed-off-by: Bjorn Helgaas > --- > drivers/pci/controller/dwc/pci-imx6.c | 19 +++++++------------ > 1 file changed, 7 insertions(+), 12 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index 2b42c37f1617..f72eb609769b 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -670,8 +670,6 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie) > > static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) > { > - struct device *dev = imx6_pcie->pci->dev; > - > switch (imx6_pcie->drvdata->variant) { > case IMX7D: > case IMX8MQ: > @@ -702,14 +700,6 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) > break; > } > > - if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { > - int ret = regulator_disable(imx6_pcie->vpcie); > - > - if (ret) > - dev_err(dev, "failed to disable vpcie regulator: %d\n", > - ret); > - } > - > /* Some boards don't have PCIe reset GPIO. */ > if (gpio_is_valid(imx6_pcie->reset_gpio)) > gpio_set_value_cansleep(imx6_pcie->reset_gpio, > @@ -722,7 +712,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) > struct device *dev = pci->dev; > int ret; > > - if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) { > + if (imx6_pcie->vpcie) { > ret = regulator_enable(imx6_pcie->vpcie); > if (ret) { > dev_err(dev, "failed to enable vpcie regulator: %d\n", > @@ -795,7 +785,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) > return 0; > > err_clks: > - if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { > + if (imx6_pcie->vpcie) { > ret = regulator_disable(imx6_pcie->vpcie); > if (ret) > dev_err(dev, "failed to disable vpcie regulator: %d\n", > @@ -1022,6 +1012,9 @@ static int imx6_pcie_suspend_noirq(struct device *dev) > break; > } > > + if (imx6_pcie->vpcie) > + regulator_disable(imx6_pcie->vpcie); > + > return 0; > } The suspend and resume methods should be symmetric, and they should *look* symmetric. imx6_pcie_suspend_noirq() disables the regulator, so imx6_pcie_resume_noirq() should enable it. imx6_pcie_suspend_noirq() calls imx6_pcie_clk_disable() to disable several clocks. imx6_pcie_resume_noirq() should call imx6_pcie_clk_enable() to enable them. imx6_pcie_clk_enable() *is* called in the resume path, but it's buried inside imx6_pcie_host_init() and imx6_pcie_deassert_core_reset(). That makes it hard to analyze. We should be able to look at imx6_pcie_suspend_noirq() and imx6_pcie_resume_noirq() and easily see that the resume path resumes everything that was suspended in the suspend path. Bjorn _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel