2022-06-13 09:25:16

by Richard Zhu

[permalink] [raw]
Subject: [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode

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 <[email protected]>
---
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 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[] = {
--
2.25.1


2022-06-14 01:06:00

by Richard Zhu

[permalink] [raw]
Subject: RE: [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode

> -----Original Message-----
> From: Francesco Dolcini <[email protected]>
> Sent: 2022??6??13?? 18:17
> To: Hongxing Zhu <[email protected]>; [email protected];
> [email protected]; [email protected]
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; dl-linux-imx <[email protected]>
> 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