diff mbox series

[v10,5/7] PCI: imx6: Turn off regulator when the system is in suspend mode

Message ID 1655110538-10914-6-git-send-email-hongxing.zhu@nxp.com (mailing list archive)
State New, archived
Headers show
Series PCI: imx6: refine codes and add the error propagation | expand

Commit Message

Hongxing Zhu June 13, 2022, 8:55 a.m. UTC
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.

Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
---
 drivers/pci/controller/dwc/pci-imx6.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

Comments

Francesco Dolcini June 13, 2022, 10:17 a.m. UTC | #1
On Mon, Jun 13, 2022 at 04:55:36PM +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.

According to the documentation:

  vpcie-supply:
    description: Should specify the regulator in charge of PCIe port power.
      The regulator will be enabled when initializing the PCIe host and
      disabled either as part of the init process or when shutting down
      the host (optional required).

Is this really what we want to do (remove power in suspend, enable
it on resume)? On our boards this powers a PCIe device connected to the host
port, that sound fair according to the binding documentation for it.
Am I wrong?

We do have issues with PCIe not working anymore after suspend/resume,
wondering (I did not have time to properly dig into it) if this is the
root cause.

Francesco
Hongxing Zhu June 14, 2022, 12:58 a.m. UTC | #2
> -----Original Message-----
> From: Francesco Dolcini <francesco.dolcini@toradex.com>
> Sent: 2022年6月13日 18:17
> To: Hongxing Zhu <hongxing.zhu@nxp.com>; l.stach@pengutronix.de;
> bhelgaas@google.com; robh@kernel.org
> Cc: 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; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is
> in suspend mode
> 
> On Mon, Jun 13, 2022 at 04:55:36PM +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.
> 
> According to the documentation:
> 
>   vpcie-supply:
>     description: Should specify the regulator in charge of PCIe port power.
>       The regulator will be enabled when initializing the PCIe host and
>       disabled either as part of the init process or when shutting down
>       the host (optional required).
> 
> Is this really what we want to do (remove power in suspend, enable it on
> resume)? On our boards this powers a PCIe device connected to the host port,
> that sound fair according to the binding documentation for it.
> Am I wrong?
> 
> We do have issues with PCIe not working anymore after suspend/resume,
> wondering (I did not have time to properly dig into it) if this is the root cause.
> 
Hi Francesco:
Yes, you're right. This regulator is used to powered up the port. It's
 reasonable to move the disable to suspend refer to Lucas' review comments.
BTW, I suspect that your PCIe failure after suspend/resume is caused by the
 MSI_ADDR missing. Can you make a double check on it?
I used found that the MSI_ADDR should be re-configured again during resume on
 some platforms. But I didn't issue that fix patch in time. Sorry about that.

Best Regards
Richard Zhu

> Francesco
diff mbox series

Patch

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 8002d98036e8..c02748393aac 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -369,8 +369,6 @@  static int imx6_pcie_attach_pd(struct device *dev)
 
 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:
@@ -400,14 +398,6 @@  static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)
 				   IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16);
 		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);
-	}
 }
 
 static unsigned int imx6_pcie_grp_offset(const struct imx6_pcie *imx6_pcie)
@@ -580,7 +570,7 @@  static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 	struct device *dev = pci->dev;
 	int ret, err;
 
-	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",
@@ -653,7 +643,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",
@@ -1013,6 +1003,9 @@  static int imx6_pcie_suspend_noirq(struct device *dev)
 		break;
 	}
 
+	if (imx6_pcie->vpcie)
+		regulator_disable(imx6_pcie->vpcie);
+
 	return 0;
 }
 
@@ -1259,6 +1252,8 @@  static void imx6_pcie_shutdown(struct platform_device *pdev)
 
 	/* bring down link, so bootloader gets clean state in case of reboot */
 	imx6_pcie_assert_core_reset(imx6_pcie);
+	if (imx6_pcie->vpcie)
+		regulator_disable(imx6_pcie->vpcie);
 }
 
 static const struct imx6_pcie_drvdata drvdata[] = {