2022-05-09 05:26:52

by Richard Zhu

[permalink] [raw]
Subject: [PATCH v9 0/8] PCI: imx6: refine codes and add compliance tests mode support

This series patches refine pci-imx6 driver and do the following main changes.
- Encapsulate the clock enable into one standalone function
- Add the error propagation from host_init
- Disable the regulators and clocks when link never comes up
- Add the compliance tests mode support
- Move the phy driver callbacks to the proper places

Main changes from v8 to v9:
- Don't change pcie-designware codes, and do the error exit process only in
pci-imx6 driver internally.
- Move the phy driver callbacks to the proper places

Main changes from v7 to v8:
Regarding Bjorn's review comments.
- Align the format of the dev_info message and refine commit log of
#6/7/8 patches.
- Rename the err_reset_phy label, since there is no PHY reset in the out

Main changes from v6 to v7:
- Keep the regulator usage counter balance in the #5 patch of v6 series.

Main changes from v5 to v6:
- Refer to the following discussion with Fabio, fix the dump by his patch.
https://patchwork.kernel.org/project/linux-pci/patch/[email protected]/
Refine and rebase this patch-set after Fabio' dump fix patch is merged.
- Add one new #4 patch to disable i.MX6QDL REF clock too when disable clocks
- Split the regulator refine codes into one standalone patch #5 in this version.

Main changes from v4 to v5:
- Since i.MX8MM PCIe support had been merged. Based on Lorenzo's git repos,
resend the patch-set after rebase.

Main changes from v3 to v4:
- Regarding Mark's comments, delete the regulator_is_enabled() check.
- Squash #3 and #6 of v3 patch into #5 patch of v4 set.

Main changes from v2 to v3:
- Add "Reviewed-by: Lucas Stach <[email protected]>" tag into
first two patches.
- Add a Fixes tag into #3 patch.
- Split the #4 of v2 to two patches, one is clock disable codes move,
the other one is the acutal clock unbalance fix.
- Add a new host_exit() callback into dw_pcie_host_ops, then it could be
invoked to handle the unbalance issue in the error handling after
host_init() function when link is down.
- Add a new host_exit() callback for i.MX PCIe driver to handle this case
in the error handling after host_init.

Main changes from v1 to v2:
Regarding Lucas' comments.
- Move the placement of the new imx6_pcie_clk_enable() to avoid the
forward declarition.
- Seperate the second patch of v1 patch-set to three patches.
- Use the module_param to replace the kernel command line.
Regarding Bjorn's comments:
- Use the cover-letter for a multi-patch series.
- Correct the subject line, and refine the commit logs. For example,
remove the timestamp of the logs.

drivers/pci/controller/dwc/pci-imx6.c | 277 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 188 insertions(+), 89 deletions(-)

[PATCH v9 1/8] PCI: imx6: Encapsulate the clock enable into one
[PATCH v9 2/8] PCI: imx6: Add the error propagation from host_init
[PATCH v9 3/8] PCI: imx6: Move imx6_pcie_clk_disable() earlier
[PATCH v9 4/8] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable
[PATCH v9 5/8] PCI: imx6: Refine the regulator usage
[PATCH v9 6/8] PCI: imx6: Disable clocks and regulators after link is
[PATCH v9 7/8] PCI: imx6: Move the phy driver callbacks to the proper
[PATCH v9 8/8] PCI: imx6: Add compliance tests mode support


2022-05-09 05:40:39

by Richard Zhu

[permalink] [raw]
Subject: [PATCH v9 2/8] PCI: imx6: Add the error propagation from host_init

Since there is error return check of the host_init callback, add error
check to imx6_pcie_deassert_core_reset() function, and change the
function type accordingly.

Signed-off-by: Richard Zhu <[email protected]>
Reviewed-by: Lucas Stach <[email protected]>
---
drivers/pci/controller/dwc/pci-imx6.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index d3ef0e94ab26..1d3a8a7cafc2 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -542,24 +542,24 @@ static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie)
dev_err(dev, "PCIe PLL lock timeout\n");
}

-static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
+static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
{
struct dw_pcie *pci = imx6_pcie->pci;
struct device *dev = pci->dev;
- int ret;
+ int ret, err;

if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) {
ret = regulator_enable(imx6_pcie->vpcie);
if (ret) {
dev_err(dev, "failed to enable vpcie regulator: %d\n",
ret);
- return;
+ return ret;
}
}

- ret = imx6_pcie_clk_enable(imx6_pcie);
- if (ret) {
- dev_err(dev, "unable to enable pcie clocks\n");
+ err = imx6_pcie_clk_enable(imx6_pcie);
+ if (err) {
+ dev_err(dev, "unable to enable pcie clocks: %d\n", err);
goto err_clks;
}

@@ -618,7 +618,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
break;
}

- return;
+ return 0;

err_clks:
if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) {
@@ -627,6 +627,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
dev_err(dev, "failed to disable vpcie regulator: %d\n",
ret);
}
+ return err;
}

static void imx6_pcie_configure_type(struct imx6_pcie *imx6_pcie)
@@ -878,11 +879,18 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
static int imx6_pcie_host_init(struct pcie_port *pp)
{
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
+ struct device *dev = pci->dev;
struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci);
+ int ret;

imx6_pcie_assert_core_reset(imx6_pcie);
imx6_pcie_init_phy(imx6_pcie);
- imx6_pcie_deassert_core_reset(imx6_pcie);
+ ret = imx6_pcie_deassert_core_reset(imx6_pcie);
+ if (ret < 0) {
+ dev_err(dev, "pcie host init failed: %d.\n", ret);
+ return ret;
+ }
+
imx6_setup_phy_mpll(imx6_pcie);

return 0;
--
2.25.1


2022-05-09 06:03:39

by Richard Zhu

[permalink] [raw]
Subject: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

The driver should undo any enables it did itself. The regulator disable
shouldn't be basing decisions on regulator_is_enabled().

To keep the balance of the regulator usage counter, disable the regulator
just behind of imx6_pcie_assert_core_reset() in resume and 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 7005a7910003..3ce3993d5797 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",
@@ -1026,6 +1016,9 @@ static int imx6_pcie_resume_noirq(struct device *dev)
return 0;

imx6_pcie_assert_core_reset(imx6_pcie);
+ if (imx6_pcie->vpcie)
+ regulator_disable(imx6_pcie->vpcie);
+
imx6_pcie_init_phy(imx6_pcie);
imx6_pcie_deassert_core_reset(imx6_pcie);
dw_pcie_setup_rc(pp);
@@ -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-08 08:43:09

by Lucas Stach

[permalink] [raw]
Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

Am Freitag, dem 06.05.2022 um 09:47 +0800 schrieb Richard Zhu:
> The driver should undo any enables it did itself. The regulator disable
> shouldn't be basing decisions on regulator_is_enabled().
>
> To keep the balance of the regulator usage counter, disable the regulator
> just behind of imx6_pcie_assert_core_reset() in resume and 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 7005a7910003..3ce3993d5797 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",
> @@ -1026,6 +1016,9 @@ static int imx6_pcie_resume_noirq(struct device *dev)
> return 0;
>
> imx6_pcie_assert_core_reset(imx6_pcie);
> + if (imx6_pcie->vpcie)
> + regulator_disable(imx6_pcie->vpcie);
> +
This one looks misplaced. Surely you want the regulator to be on when
resuming the PCIe subsystem. Isn't this just papering over a wrong
usage count here, because there is no regulator_disable in
imx6_pcie_suspend_noirq, where I would expect this to happen?

Regards,
Lucas

> imx6_pcie_init_phy(imx6_pcie);
> imx6_pcie_deassert_core_reset(imx6_pcie);
> dw_pcie_setup_rc(pp);
> @@ -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[] = {


2022-06-08 19:03:20

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

On Fri, May 06, 2022 at 09:47:06AM +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().
>
> To keep the balance of the regulator usage counter, disable the regulator
> just behind of imx6_pcie_assert_core_reset() in resume and shutdown.

In subject, "Refine" doesn't tell me anything about what's happening
here.

2022-06-08 19:03:39

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v9 2/8] PCI: imx6: Add the error propagation from host_init

On Fri, May 06, 2022 at 09:47:03AM +0800, Richard Zhu wrote:
> Since there is error return check of the host_init callback, add error
> check to imx6_pcie_deassert_core_reset() function, and change the
> function type accordingly.

> @@ -878,11 +879,18 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
> static int imx6_pcie_host_init(struct pcie_port *pp)
> {
> struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> + struct device *dev = pci->dev;
> struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci);
> + int ret;
>
> imx6_pcie_assert_core_reset(imx6_pcie);
> imx6_pcie_init_phy(imx6_pcie);
> - imx6_pcie_deassert_core_reset(imx6_pcie);
> + ret = imx6_pcie_deassert_core_reset(imx6_pcie);
> + if (ret < 0) {
> + dev_err(dev, "pcie host init failed: %d.\n", ret);

Other messages from this driver do not include a trailing period.

2022-06-09 06:35:20

by Richard Zhu

[permalink] [raw]
Subject: RE: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

> -----Original Message-----
> From: Lucas Stach <[email protected]>
> Sent: 2022年6月8日 15:27
> To: Hongxing Zhu <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]
> Cc: [email protected]; [email protected];
> [email protected]; [email protected]; dl-linux-imx
> <[email protected]>
> Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage
>
> Am Freitag, dem 06.05.2022 um 09:47 +0800 schrieb Richard Zhu:
> > The driver should undo any enables it did itself. The regulator
> > disable shouldn't be basing decisions on regulator_is_enabled().
> >
> > To keep the balance of the regulator usage counter, disable the
> > regulator just behind of imx6_pcie_assert_core_reset() in resume and
> 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 7005a7910003..3ce3993d5797 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", @@
> -1026,6
> > +1016,9 @@ static int imx6_pcie_resume_noirq(struct device *dev)
> > return 0;
> >
> > imx6_pcie_assert_core_reset(imx6_pcie);
> > + if (imx6_pcie->vpcie)
> > + regulator_disable(imx6_pcie->vpcie);
> > +
> This one looks misplaced. Surely you want the regulator to be on when
> resuming the PCIe subsystem. Isn't this just papering over a wrong usage count
> here, because there is no regulator_disable in imx6_pcie_suspend_noirq,
> where I would expect this to happen?
>
Hi Lucas:
Thanks for your comments.
There was one regulator_disable() operation at the end of the
imx6_pcie_assert_core_reset() function before.
When create the 5/8 patch, I follow the same behavior to disable the
regulator just behind the imx6_pcie_assert_core_reset() function.

Yes, it is. Imx6_pcie_suspend_noirq doesn't have the regulator_disable.
The regulaor_enable is contained in imx6_pcie_deassert_core_reset().
Both of the regulator_disable and regulator_enabe are invoked once in
imx6_pcie_resume_noirq.
So, the regulator is on and has a balanced usage count after resume.
Best Regards
Richard Zhu

> Regards,
> Lucas
>
> > imx6_pcie_init_phy(imx6_pcie);
> > imx6_pcie_deassert_core_reset(imx6_pcie);
> > dw_pcie_setup_rc(pp);
> > @@ -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[] = {
>

2022-06-09 06:38:59

by Richard Zhu

[permalink] [raw]
Subject: RE: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

> -----Original Message-----
> From: Bjorn Helgaas <[email protected]>
> Sent: 2022??6??9?? 2:55
> To: Hongxing Zhu <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]; dl-linux-imx
> <[email protected]>
> Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage
>
> On Fri, May 06, 2022 at 09:47:06AM +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().
> >
> > To keep the balance of the regulator usage counter, disable the
> > regulator just behind of imx6_pcie_assert_core_reset() in resume and
> shutdown.
>
> In subject, "Refine" doesn't tell me anything about what's happening here.
Thanks for your comments.
How about the following one?
PCI: imx6: Do regulator disable without the regulator_is_enabled check

Best Regards
Richard Zhu

2022-06-09 06:51:27

by Richard Zhu

[permalink] [raw]
Subject: RE: [PATCH v9 2/8] PCI: imx6: Add the error propagation from host_init

> -----Original Message-----
> From: Bjorn Helgaas <[email protected]>
> Sent: 2022??6??9?? 2:53
> To: Hongxing Zhu <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]; dl-linux-imx
> <[email protected]>
> Subject: Re: [PATCH v9 2/8] PCI: imx6: Add the error propagation from
> host_init
>
> On Fri, May 06, 2022 at 09:47:03AM +0800, Richard Zhu wrote:
> > Since there is error return check of the host_init callback, add error
> > check to imx6_pcie_deassert_core_reset() function, and change the
> > function type accordingly.
>
> > @@ -878,11 +879,18 @@ static int imx6_pcie_start_link(struct dw_pcie
> > *pci) static int imx6_pcie_host_init(struct pcie_port *pp) {
> > struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
> > + struct device *dev = pci->dev;
> > struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci);
> > + int ret;
> >
> > imx6_pcie_assert_core_reset(imx6_pcie);
> > imx6_pcie_init_phy(imx6_pcie);
> > - imx6_pcie_deassert_core_reset(imx6_pcie);
> > + ret = imx6_pcie_deassert_core_reset(imx6_pcie);
> > + if (ret < 0) {
> > + dev_err(dev, "pcie host init failed: %d.\n", ret);
>
> Other messages from this driver do not include a trailing period.
Okay, to keep alignment, would remove the trailing period.
Thanks.

Best Regards
Richard Zhu

2022-06-09 08:03:34

by Lucas Stach

[permalink] [raw]
Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

Am Donnerstag, dem 09.06.2022 um 06:17 +0000 schrieb Hongxing Zhu:
> > -----Original Message-----
> > From: Lucas Stach <[email protected]>
> > Sent: 2022年6月8日 15:27
> > To: Hongxing Zhu <[email protected]>; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected];
> > [email protected]
> > Cc: [email protected];
> > [email protected];
> > [email protected]; [email protected]; dl-linux-imx
> > <[email protected]>
> > Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage
> >
> > Am Freitag, dem 06.05.2022 um 09:47 +0800 schrieb Richard Zhu:
> > > The driver should undo any enables it did itself. The regulator
> > > disable shouldn't be basing decisions on regulator_is_enabled().
> > >
> > > To keep the balance of the regulator usage counter, disable the
> > > regulator just behind of imx6_pcie_assert_core_reset() in resume
> > > and
> > 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 7005a7910003..3ce3993d5797 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", @@
> > -1026,6
> > > +1016,9 @@ static int imx6_pcie_resume_noirq(struct device *dev)
> > >   return 0;
> > >
> > >   imx6_pcie_assert_core_reset(imx6_pcie);
> > > + if (imx6_pcie->vpcie)
> > > + regulator_disable(imx6_pcie->vpcie);
> > > +
> > This one looks misplaced. Surely you want the regulator to be on
> > when
> > resuming the PCIe subsystem. Isn't this just papering over a wrong
> > usage count
> > here, because there is no regulator_disable in
> > imx6_pcie_suspend_noirq,
> > where I would expect this to happen?
> >
> Hi Lucas:
> Thanks for your comments.
> There was one regulator_disable() operation at the end of the
>  imx6_pcie_assert_core_reset() function before.
> When create the 5/8 patch, I follow the same behavior to disable the
> regulator just behind the imx6_pcie_assert_core_reset() function.
>
> Yes, it is. Imx6_pcie_suspend_noirq doesn't have the
> regulator_disable.
> The regulaor_enable is contained in imx6_pcie_deassert_core_reset().
> Both of the regulator_disable and regulator_enabe are invoked once in
>  imx6_pcie_resume_noirq.
> So, the regulator is on and has a balanced usage count after resume.
>

Yea, my argument is that when we are moving around the regulator
handling anyways, we should move the regulator_disable into the suspend
function. It's the right thing to do: we don't want the bus to be
powered when the system is in suspend and while the use-count is
correct, it's confusing to read the resume function otherwise.

Regards,
Lucas

2022-06-09 09:16:05

by Richard Zhu

[permalink] [raw]
Subject: RE: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

> -----Original Message-----
> From: Lucas Stach <[email protected]>
> Sent: 2022年6月9日 15:47
> To: Hongxing Zhu <[email protected]>; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]
> Cc: [email protected]; [email protected];
> [email protected]; [email protected]; dl-linux-imx
> <[email protected]>
> Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage
>
> Am Donnerstag, dem 09.06.2022 um 06:17 +0000 schrieb Hongxing Zhu:
> > > -----Original Message-----
> > > From: Lucas Stach <[email protected]>
> > > Sent: 2022年6月8日 15:27
> > > To: Hongxing Zhu <[email protected]>; [email protected];
> > > [email protected]; [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > [email protected]
> > > Cc: [email protected];
> > > [email protected];
> > > [email protected]; [email protected]; dl-linux-imx
> > > <[email protected]>
> > > Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage
> > >
> > > Am Freitag, dem 06.05.2022 um 09:47 +0800 schrieb Richard Zhu:
> > > > The driver should undo any enables it did itself. The regulator
> > > > disable shouldn't be basing decisions on regulator_is_enabled().
> > > >
> > > > To keep the balance of the regulator usage counter, disable the
> > > > regulator just behind of imx6_pcie_assert_core_reset() in resume
> > > > and
> > > 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 7005a7910003..3ce3993d5797 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", @@
> > > -1026,6
> > > > +1016,9 @@ static int imx6_pcie_resume_noirq(struct device *dev)
> > > >   return 0;
> > > >
> > > >   imx6_pcie_assert_core_reset(imx6_pcie);
> > > > + if (imx6_pcie->vpcie)
> > > > + regulator_disable(imx6_pcie->vpcie);
> > > > +
> > > This one looks misplaced. Surely you want the regulator to be on
> > > when resuming the PCIe subsystem. Isn't this just papering over a
> > > wrong usage count here, because there is no regulator_disable in
> > > imx6_pcie_suspend_noirq, where I would expect this to happen?
> > >
> > Hi Lucas:
> > Thanks for your comments.
> > There was one regulator_disable() operation at the end of the
> >  imx6_pcie_assert_core_reset() function before.
> > When create the 5/8 patch, I follow the same behavior to disable the
> > regulator just behind the imx6_pcie_assert_core_reset() function.
> >
> > Yes, it is. Imx6_pcie_suspend_noirq doesn't have the
> > regulator_disable.
> > The regulaor_enable is contained in imx6_pcie_deassert_core_reset().
> > Both of the regulator_disable and regulator_enabe are invoked once in
> >  imx6_pcie_resume_noirq.
> > So, the regulator is on and has a balanced usage count after resume.
> >
>
> Yea, my argument is that when we are moving around the regulator handling
> anyways, we should move the regulator_disable into the suspend function. It's
> the right thing to do: we don't want the bus to be powered when the system is
> in suspend and while the use-count is correct, it's confusing to read the resume
> function otherwise.
>
Thanks for your quick reply.
Understand. I would move the regulator_disable at the end of the suspend
function if you're fine with it.

Best Regards
Richard Zhu

> Regards,
> Lucas

2022-06-09 18:19:33

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

On Thu, Jun 09, 2022 at 06:19:47AM +0000, Hongxing Zhu wrote:
> > -----Original Message-----
> > From: Bjorn Helgaas <[email protected]>
> > Sent: 2022年6月9日 2:55
> > To: Hongxing Zhu <[email protected]>
> > Cc: [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected]; [email protected];
> > [email protected]; [email protected];
> > [email protected]; [email protected];
> > [email protected]; [email protected]; dl-linux-imx
> > <[email protected]>
> > Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage
> >
> > On Fri, May 06, 2022 at 09:47:06AM +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().

The driver should disable things if an error occurs after it has
enabled something, or if it enabled something during probe and we're
now detaching the driver. That doesn't look like the case here.

> > > To keep the balance of the regulator usage counter, disable the
> > > regulator just behind of imx6_pcie_assert_core_reset() in resume and
> > > shutdown.
> >
> > In subject, "Refine" doesn't tell me anything about what's happening here.
>
> Thanks for your comments.
> How about the following one?
> PCI: imx6: Do regulator disable without the regulator_is_enabled check

That's too low-level, like describing the C code line by line.
I'm hoping for something about the purpose for the patch so
"git log --oneline" can tell a coherent story.

Apparently this is about disabling the power regulator when the slot
isn't being used, so maybe it could say something about that.

$ git grep -Ep "regulator_(en|dis)able" drivers/pci/controller/

shows that in other drivers, this being done in
probe/remove/suspend/resume-type paths. imx6 should be similar.

Bjorn

2022-06-10 07:46:54

by Richard Zhu

[permalink] [raw]
Subject: RE: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage

> -----Original Message-----
> From: Bjorn Helgaas <[email protected]>
> Sent: 2022年6月10日 1:20
> To: Hongxing Zhu <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]; dl-linux-imx
> <[email protected]>
> Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage
>
> On Thu, Jun 09, 2022 at 06:19:47AM +0000, Hongxing Zhu wrote:
> > > -----Original Message-----
> > > From: Bjorn Helgaas <[email protected]>
> > > Sent: 2022年6月9日 2:55
> > > To: Hongxing Zhu <[email protected]>
> > > Cc: [email protected]; [email protected]; [email protected];
> > > [email protected]; [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > [email protected]; [email protected];
> > > [email protected]; [email protected]; dl-linux-imx
> > > <[email protected]>
> > > Subject: Re: [PATCH v9 5/8] PCI: imx6: Refine the regulator usage
> > >
> > > On Fri, May 06, 2022 at 09:47:06AM +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().
>
> The driver should disable things if an error occurs after it has enabled
> something, or if it enabled something during probe and we're now detaching
> the driver. That doesn't look like the case here.
>
> > > > To keep the balance of the regulator usage counter, disable the
> > > > regulator just behind of imx6_pcie_assert_core_reset() in resume
> > > > and shutdown.
> > >
> > > In subject, "Refine" doesn't tell me anything about what's happening here.
> >
> > Thanks for your comments.
> > How about the following one?
> > PCI: imx6: Do regulator disable without the regulator_is_enabled check
>
> That's too low-level, like describing the C code line by line.
> I'm hoping for something about the purpose for the patch so "git log --oneline"
> can tell a coherent story.
>
> Apparently this is about disabling the power regulator when the slot isn't being
> used, so maybe it could say something about that.
>
> $ git grep -Ep "regulator_(en|dis)able" drivers/pci/controller/
>
> shows that in other drivers, this being done in
> probe/remove/suspend/resume-type paths. imx6 should be similar.
>
Got that, thanks a lot.

Best Regards
Richard Zhu

> Bjorn