linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation
@ 2022-06-13  8:55 Richard Zhu
  2022-06-13  8:55 ` [PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one standalone function Richard Zhu
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Richard Zhu @ 2022-06-13  8:55 UTC (permalink / raw)
  To: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini
  Cc: hongxing.zhu, linux-pci, linux-arm-kernel, linux-kernel, kernel,
	linux-imx

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 and resume
- Turn off regulator when the system is in suspend mode
- Let the probe successfully when link never comes up
- Do not hide the phy driver callbacks in core reset and clk_enable.
BTW, this series are verified on i.MX8MM EVK board when one NVME is used.

Main changes from v9 to v10:
- Add the "Reviewed-by: Lucas Stach <l.stach@pengutronix.de>" tag into #3
  and #4 patches.
Refer to Bjorn's comments:
- refine the commit of the first patch
- keep alignment of the message format in the second patch
- More specific commit and subject of the #5 and #7 patches.
Refer to Lucas' comments:
- Move the regualtor_disable into suspend, turn off the regulator when bus
  is powered off and system in suspend mode.
- Let the driver probe successfully, return zero in imx6_pcie_start_link()
  when PCIe link is down. 
  In this link down scenario, only start the PCIe link training in resume
  when the link is up before system suspend to avoid the long latency in
  the link training period.
- Don't hide phy driver callbacks in core reset and clk_enable, and refine
  the error handling accordingly.
- Drop the #8 patch of v9 series, since the clocks and powers are not gated
  off anymore when link is down.

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/1641368602-20401-6-git-send-email-hongxing.zhu@nxp.com/
  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 <l.stach@pengutronix.de>" 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 | 241 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 157 insertions(+), 84 deletions(-)

[PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one
[PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init
[PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier
[PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when
[PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in
[PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
[PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one standalone function
  2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
@ 2022-06-13  8:55 ` Richard Zhu
  2022-06-13  8:55 ` [PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init Richard Zhu
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Richard Zhu @ 2022-06-13  8:55 UTC (permalink / raw)
  To: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini
  Cc: hongxing.zhu, linux-pci, linux-arm-kernel, linux-kernel, kernel,
	linux-imx

No function changes, just encapsulate the i.MX PCIe clock enable
operations into one standalone function imx6_pcie_clk_enable().

Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/pci/controller/dwc/pci-imx6.c | 79 ++++++++++++++++-----------
 1 file changed, 48 insertions(+), 31 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 6619e3caffe2..d3ef0e94ab26 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -477,38 +477,16 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
 	return ret;
 }
 
-static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie)
-{
-	u32 val;
-	struct device *dev = imx6_pcie->pci->dev;
-
-	if (regmap_read_poll_timeout(imx6_pcie->iomuxc_gpr,
-				     IOMUXC_GPR22, val,
-				     val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED,
-				     PHY_PLL_LOCK_WAIT_USLEEP_MAX,
-				     PHY_PLL_LOCK_WAIT_TIMEOUT))
-		dev_err(dev, "PCIe PLL lock timeout\n");
-}
-
-static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
+static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie)
 {
 	struct dw_pcie *pci = imx6_pcie->pci;
 	struct device *dev = pci->dev;
 	int ret;
 
-	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;
-		}
-	}
-
 	ret = clk_prepare_enable(imx6_pcie->pcie_phy);
 	if (ret) {
 		dev_err(dev, "unable to enable pcie_phy clock\n");
-		goto err_pcie_phy;
+		return ret;
 	}
 
 	ret = clk_prepare_enable(imx6_pcie->pcie_bus);
@@ -539,6 +517,51 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 	}
 	/* allow the clocks to stabilize */
 	usleep_range(200, 500);
+	return 0;
+
+err_ref_clk:
+	clk_disable_unprepare(imx6_pcie->pcie);
+err_pcie:
+	clk_disable_unprepare(imx6_pcie->pcie_bus);
+err_pcie_bus:
+	clk_disable_unprepare(imx6_pcie->pcie_phy);
+
+	return ret;
+}
+
+static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie)
+{
+	u32 val;
+	struct device *dev = imx6_pcie->pci->dev;
+
+	if (regmap_read_poll_timeout(imx6_pcie->iomuxc_gpr,
+				     IOMUXC_GPR22, val,
+				     val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED,
+				     PHY_PLL_LOCK_WAIT_USLEEP_MAX,
+				     PHY_PLL_LOCK_WAIT_TIMEOUT))
+		dev_err(dev, "PCIe PLL lock timeout\n");
+}
+
+static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
+{
+	struct dw_pcie *pci = imx6_pcie->pci;
+	struct device *dev = pci->dev;
+	int ret;
+
+	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;
+		}
+	}
+
+	ret = imx6_pcie_clk_enable(imx6_pcie);
+	if (ret) {
+		dev_err(dev, "unable to enable pcie clocks\n");
+		goto err_clks;
+	}
 
 	/* Some boards don't have PCIe reset GPIO. */
 	if (gpio_is_valid(imx6_pcie->reset_gpio)) {
@@ -597,13 +620,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 
 	return;
 
-err_ref_clk:
-	clk_disable_unprepare(imx6_pcie->pcie);
-err_pcie:
-	clk_disable_unprepare(imx6_pcie->pcie_bus);
-err_pcie_bus:
-	clk_disable_unprepare(imx6_pcie->pcie_phy);
-err_pcie_phy:
+err_clks:
 	if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) {
 		ret = regulator_disable(imx6_pcie->vpcie);
 		if (ret)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init
  2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
  2022-06-13  8:55 ` [PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one standalone function Richard Zhu
@ 2022-06-13  8:55 ` Richard Zhu
  2022-06-13  8:55 ` [PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier Richard Zhu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Richard Zhu @ 2022-06-13  8:55 UTC (permalink / raw)
  To: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini
  Cc: hongxing.zhu, linux-pci, linux-arm-kernel, linux-kernel, kernel,
	linux-imx

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 <hongxing.zhu@nxp.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
---
 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..e1420409b47f 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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier
  2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
  2022-06-13  8:55 ` [PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one standalone function Richard Zhu
  2022-06-13  8:55 ` [PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init Richard Zhu
@ 2022-06-13  8:55 ` Richard Zhu
  2022-06-13  8:55 ` [PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable PCIe clocks Richard Zhu
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Richard Zhu @ 2022-06-13  8:55 UTC (permalink / raw)
  To: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini
  Cc: hongxing.zhu, linux-pci, linux-arm-kernel, linux-kernel, kernel,
	linux-imx

Just move the imx6_pcie_clk_disable() to an earlier place without function
changes, since it wouldn't be only used in imx6_pcie_suspend_noirq() later.

Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/pci/controller/dwc/pci-imx6.c | 48 +++++++++++++--------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index e1420409b47f..aa5080c2fe5f 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -529,6 +529,30 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie)
 	return ret;
 }
 
+static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)
+{
+	clk_disable_unprepare(imx6_pcie->pcie);
+	clk_disable_unprepare(imx6_pcie->pcie_phy);
+	clk_disable_unprepare(imx6_pcie->pcie_bus);
+
+	switch (imx6_pcie->drvdata->variant) {
+	case IMX6SX:
+		clk_disable_unprepare(imx6_pcie->pcie_inbound_axi);
+		break;
+	case IMX7D:
+		regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
+				   IMX7D_GPR12_PCIE_PHY_REFCLK_SEL,
+				   IMX7D_GPR12_PCIE_PHY_REFCLK_SEL);
+		break;
+	case IMX8MQ:
+	case IMX8MM:
+		clk_disable_unprepare(imx6_pcie->pcie_aux);
+		break;
+	default:
+		break;
+	}
+}
+
 static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie)
 {
 	u32 val;
@@ -961,30 +985,6 @@ static void imx6_pcie_pm_turnoff(struct imx6_pcie *imx6_pcie)
 	usleep_range(1000, 10000);
 }
 
-static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)
-{
-	clk_disable_unprepare(imx6_pcie->pcie);
-	clk_disable_unprepare(imx6_pcie->pcie_phy);
-	clk_disable_unprepare(imx6_pcie->pcie_bus);
-
-	switch (imx6_pcie->drvdata->variant) {
-	case IMX6SX:
-		clk_disable_unprepare(imx6_pcie->pcie_inbound_axi);
-		break;
-	case IMX7D:
-		regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12,
-				   IMX7D_GPR12_PCIE_PHY_REFCLK_SEL,
-				   IMX7D_GPR12_PCIE_PHY_REFCLK_SEL);
-		break;
-	case IMX8MQ:
-	case IMX8MM:
-		clk_disable_unprepare(imx6_pcie->pcie_aux);
-		break;
-	default:
-		break;
-	}
-}
-
 static int imx6_pcie_suspend_noirq(struct device *dev)
 {
 	struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable PCIe clocks
  2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
                   ` (2 preceding siblings ...)
  2022-06-13  8:55 ` [PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier Richard Zhu
@ 2022-06-13  8:55 ` Richard Zhu
  2022-06-13  8:55 ` [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode Richard Zhu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Richard Zhu @ 2022-06-13  8:55 UTC (permalink / raw)
  To: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini
  Cc: hongxing.zhu, linux-pci, linux-arm-kernel, linux-kernel, kernel,
	linux-imx

When disable PCIe clocks, disable i.MX6QDL PCIe REF clock too.

Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
---
 drivers/pci/controller/dwc/pci-imx6.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index aa5080c2fe5f..8002d98036e8 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -536,6 +536,14 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)
 	clk_disable_unprepare(imx6_pcie->pcie_bus);
 
 	switch (imx6_pcie->drvdata->variant) {
+	case IMX6Q:
+	case IMX6QP:
+		regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
+				IMX6Q_GPR1_PCIE_REF_CLK_EN, 0);
+		regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
+				IMX6Q_GPR1_PCIE_TEST_PD,
+				IMX6Q_GPR1_PCIE_TEST_PD);
+		break;
 	case IMX6SX:
 		clk_disable_unprepare(imx6_pcie->pcie_inbound_axi);
 		break;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode
  2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
                   ` (3 preceding siblings ...)
  2022-06-13  8:55 ` [PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable PCIe clocks Richard Zhu
@ 2022-06-13  8:55 ` Richard Zhu
  2022-06-13 10:17   ` Francesco Dolcini
  2022-06-13  8:55 ` [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error Richard Zhu
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Richard Zhu @ 2022-06-13  8:55 UTC (permalink / raw)
  To: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini
  Cc: hongxing.zhu, linux-pci, linux-arm-kernel, linux-kernel, kernel,
	linux-imx

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(-)

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


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
  2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
                   ` (4 preceding siblings ...)
  2022-06-13  8:55 ` [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode Richard Zhu
@ 2022-06-13  8:55 ` Richard Zhu
  2022-06-13 22:21   ` Bjorn Helgaas
  2022-06-13  8:55 ` [PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the error handling Richard Zhu
  2022-06-13 20:41 ` [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Bjorn Helgaas
  7 siblings, 1 reply; 14+ messages in thread
From: Richard Zhu @ 2022-06-13  8:55 UTC (permalink / raw)
  To: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini
  Cc: hongxing.zhu, linux-pci, linux-arm-kernel, linux-kernel, kernel,
	linux-imx

let the driver probe successfully, return zero in imx6_pcie_start_link()
when PCIe link is down.

Because i.MX PCIe doesn't support hot-plug feature.
In this link down scenario, only start the PCIe link training in resume
when the link is up before system suspend to avoid the long latency in
the link training period.

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

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index c02748393aac..ac6ec2d691a0 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -67,6 +67,7 @@ struct imx6_pcie {
 	struct dw_pcie		*pci;
 	int			reset_gpio;
 	bool			gpio_active_high;
+	bool			link_is_up;
 	struct clk		*pcie_bus;
 	struct clk		*pcie_phy;
 	struct clk		*pcie_inbound_axi;
@@ -845,7 +846,9 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
 	/* Start LTSSM. */
 	imx6_pcie_ltssm_enable(dev);
 
-	dw_pcie_wait_for_link(pci);
+	ret = dw_pcie_wait_for_link(pci);
+	if (ret)
+		goto err_reset_phy;
 
 	if (pci->link_gen == 2) {
 		/* Allow Gen2 mode after the link is up. */
@@ -881,11 +884,14 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
 		}
 
 		/* Make sure link training is finished as well! */
-		dw_pcie_wait_for_link(pci);
+		ret = dw_pcie_wait_for_link(pci);
+		if (ret)
+			goto err_reset_phy;
 	} else {
 		dev_info(dev, "Link: Gen2 disabled\n");
 	}
 
+	imx6_pcie->link_is_up = true;
 	tmp = dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKSTA);
 	dev_info(dev, "Link up, Gen%i\n", tmp & PCI_EXP_LNKSTA_CLS);
 	return 0;
@@ -895,7 +901,7 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
 		dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0),
 		dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG1));
 	imx6_pcie_reset_phy(imx6_pcie);
-	return ret;
+	return 0;
 }
 
 static int imx6_pcie_host_init(struct pcie_port *pp)
@@ -1022,10 +1028,8 @@ static int imx6_pcie_resume_noirq(struct device *dev)
 	imx6_pcie_init_phy(imx6_pcie);
 	imx6_pcie_deassert_core_reset(imx6_pcie);
 	dw_pcie_setup_rc(pp);
-
-	ret = imx6_pcie_start_link(imx6_pcie->pci);
-	if (ret < 0)
-		dev_info(dev, "pcie link is down after resume.\n");
+	if (imx6_pcie->link_is_up)
+		imx6_pcie_start_link(imx6_pcie->pci);
 
 	return 0;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the error handling
  2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
                   ` (5 preceding siblings ...)
  2022-06-13  8:55 ` [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error Richard Zhu
@ 2022-06-13  8:55 ` Richard Zhu
  2022-06-13 20:41 ` [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Bjorn Helgaas
  7 siblings, 0 replies; 14+ messages in thread
From: Richard Zhu @ 2022-06-13  8:55 UTC (permalink / raw)
  To: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini
  Cc: hongxing.zhu, linux-pci, linux-arm-kernel, linux-kernel, kernel,
	linux-imx

- Move the phy_power_on() to host_init and resume functions from
  imx6_pcie_clk_enable().
- Move the phy_init() to host_init and resume functions from
  imx6_pcie_deassert_core_reset().

Refine the error handling in imx6_pcie_host_init() and
imx6_pcie_resume_noirq() functions accordingly.

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

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index ac6ec2d691a0..61d9fa0120b4 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -498,14 +498,6 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie)
 		goto err_ref_clk;
 	}
 
-	switch (imx6_pcie->drvdata->variant) {
-	case IMX8MM:
-		if (phy_power_on(imx6_pcie->phy))
-			dev_err(dev, "unable to power on PHY\n");
-		break;
-	default:
-		break;
-	}
 	/* allow the clocks to stabilize */
 	usleep_range(200, 500);
 	return 0;
@@ -599,10 +591,6 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 	case IMX8MQ:
 		reset_control_deassert(imx6_pcie->pciephy_reset);
 		break;
-	case IMX8MM:
-		if (phy_init(imx6_pcie->phy))
-			dev_err(dev, "waiting for phy ready timeout!\n");
-		break;
 	case IMX7D:
 		reset_control_deassert(imx6_pcie->pciephy_reset);
 
@@ -638,6 +626,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 		usleep_range(200, 500);
 		break;
 	case IMX6Q:		/* Nothing to do */
+	case IMX8MM:
 		break;
 	}
 
@@ -913,15 +902,39 @@ static int imx6_pcie_host_init(struct pcie_port *pp)
 
 	imx6_pcie_assert_core_reset(imx6_pcie);
 	imx6_pcie_init_phy(imx6_pcie);
+	if (imx6_pcie->phy) {
+		ret = phy_power_on(imx6_pcie->phy);
+		if (ret) {
+			dev_err(dev, "pcie phy power up failed.\n");
+			return ret;
+		}
+	}
+
 	ret = imx6_pcie_deassert_core_reset(imx6_pcie);
 	if (ret < 0) {
 		dev_err(dev, "pcie host init failed: %d\n", ret);
-		return ret;
+		goto err_phy_off;
+	}
+	if (imx6_pcie->phy) {
+		ret = phy_init(imx6_pcie->phy);
+		if (ret) {
+			dev_err(dev, "waiting for phy ready timeout!\n");
+			goto err_phy_init;
+		}
 	}
 
 	imx6_setup_phy_mpll(imx6_pcie);
 
 	return 0;
+
+err_phy_init:
+	imx6_pcie_clk_disable(imx6_pcie);
+	if (imx6_pcie->vpcie)
+		regulator_disable(imx6_pcie->vpcie);
+err_phy_off:
+	if (imx6_pcie->phy)
+		phy_power_off(imx6_pcie->phy);
+	return ret;
 }
 
 static const struct dw_pcie_host_ops imx6_pcie_host_ops = {
@@ -1026,12 +1039,40 @@ static int imx6_pcie_resume_noirq(struct device *dev)
 
 	imx6_pcie_assert_core_reset(imx6_pcie);
 	imx6_pcie_init_phy(imx6_pcie);
-	imx6_pcie_deassert_core_reset(imx6_pcie);
+	if (imx6_pcie->phy) {
+		ret = phy_power_on(imx6_pcie->phy);
+		if (ret) {
+			dev_err(dev, "pcie phy power up failed.\n");
+			return ret;
+		}
+	}
+
+	ret = imx6_pcie_deassert_core_reset(imx6_pcie);
+	if (ret < 0) {
+		dev_err(dev, "pcie deassert core reset failed: %d.\n", ret);
+		goto err_phy_off;
+	} else if (imx6_pcie->phy) {
+		ret = phy_init(imx6_pcie->phy);
+		if (ret) {
+			dev_err(dev, "pcie phy init failed.\n");
+			goto err_phy_init;
+		}
+	}
+
 	dw_pcie_setup_rc(pp);
 	if (imx6_pcie->link_is_up)
 		imx6_pcie_start_link(imx6_pcie->pci);
 
 	return 0;
+
+err_phy_init:
+	imx6_pcie_clk_disable(imx6_pcie);
+	if (imx6_pcie->vpcie)
+		regulator_disable(imx6_pcie->vpcie);
+err_phy_off:
+	if (imx6_pcie->phy)
+		phy_power_off(imx6_pcie->phy);
+	return ret;
 }
 #endif
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode
  2022-06-13  8:55 ` [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode Richard Zhu
@ 2022-06-13 10:17   ` Francesco Dolcini
  2022-06-14  0:58     ` Hongxing Zhu
  0 siblings, 1 reply; 14+ messages in thread
From: Francesco Dolcini @ 2022-06-13 10:17 UTC (permalink / raw)
  To: Richard Zhu, l.stach, bhelgaas, robh
  Cc: broonie, lorenzo.pieralisi, festevam, francesco.dolcini,
	linux-pci, linux-arm-kernel, linux-kernel, kernel, linux-imx

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation
  2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
                   ` (6 preceding siblings ...)
  2022-06-13  8:55 ` [PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the error handling Richard Zhu
@ 2022-06-13 20:41 ` Bjorn Helgaas
  2022-06-14  1:00   ` Hongxing Zhu
  7 siblings, 1 reply; 14+ messages in thread
From: Bjorn Helgaas @ 2022-06-13 20:41 UTC (permalink / raw)
  To: Richard Zhu
  Cc: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini, linux-pci, linux-arm-kernel, linux-kernel,
	kernel, linux-imx

On Mon, Jun 13, 2022 at 04:55:31PM +0800, Richard Zhu wrote:
> 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 and resume
> - Turn off regulator when the system is in suspend mode
> - Let the probe successfully when link never comes up
> - Do not hide the phy driver callbacks in core reset and clk_enable.

This doesn't apply on v5.19-rc1 for me.  Am I missing something:

  03:38:06 ~/linux (main)$ git checkout -b wip/richard-imx6-power-v10 v5.19-rc1
  Switched to a new branch 'wip/richard-imx6-power-v10'
  03:38:14 ~/linux (wip/richard-imx6-power-v10)$ b4 am -om/ https://lore.kernel.org/r/1655110538-10914-1-git-send-email-hongxing.zhu@nxp.com
  Looking up https://lore.kernel.org/r/1655110538-10914-1-git-send-email-hongxing.zhu%40nxp.com
  Analyzing 9 messages in the thread
  Checking attestation on all messages, may take a moment...
  ---
    [PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one standalone function
    [PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init
    [PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier
    [PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable PCIe clocks
    [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode
    [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
    [PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the error handling
  ---
  Total patches: 7
  ---
  Cover: m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_propagation.cover
   Link: https://lore.kernel.org/r/1655110538-10914-1-git-send-email-hongxing.zhu@nxp.com
   Base: not specified
	 git am m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_propagation.mbx
  03:38:27 ~/linux (wip/richard-imx6-power-v10)$ git am m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_propagation.mbx
  Applying: PCI: imx6: Encapsulate the clock enable into one standalone function
  error: patch failed: drivers/pci/controller/dwc/pci-imx6.c:539
  error: drivers/pci/controller/dwc/pci-imx6.c: patch does not apply
  Patch failed at 0001 PCI: imx6: Encapsulate the clock enable into one standalone function
  hint: Use 'git am --show-current-patch' to see the failed patch
  When you have resolved this problem, run "git am --continue".
  If you prefer to skip this patch, run "git am --skip" instead.
  To restore the original branch and stop patching, run "git am --abort".


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
  2022-06-13  8:55 ` [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error Richard Zhu
@ 2022-06-13 22:21   ` Bjorn Helgaas
  2022-06-14  1:02     ` Hongxing Zhu
  0 siblings, 1 reply; 14+ messages in thread
From: Bjorn Helgaas @ 2022-06-13 22:21 UTC (permalink / raw)
  To: Richard Zhu
  Cc: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini, linux-pci, linux-arm-kernel, linux-kernel,
	kernel, linux-imx

On Mon, Jun 13, 2022 at 04:55:37PM +0800, Richard Zhu wrote:
> let the driver probe successfully, return zero in imx6_pcie_start_link()
> when PCIe link is down.
> 
> Because i.MX PCIe doesn't support hot-plug feature.
> In this link down scenario, only start the PCIe link training in resume
> when the link is up before system suspend to avoid the long latency in
> the link training period.

This looks like two changes that should be separate patches:

  1) Make driver probe successful even if link is down.

  2) Reduce resume time by only starting the link if it was up before
     suspend.

> Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
> ---
>  drivers/pci/controller/dwc/pci-imx6.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index c02748393aac..ac6ec2d691a0 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -67,6 +67,7 @@ struct imx6_pcie {
>  	struct dw_pcie		*pci;
>  	int			reset_gpio;
>  	bool			gpio_active_high;
> +	bool			link_is_up;
>  	struct clk		*pcie_bus;
>  	struct clk		*pcie_phy;
>  	struct clk		*pcie_inbound_axi;
> @@ -845,7 +846,9 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
>  	/* Start LTSSM. */
>  	imx6_pcie_ltssm_enable(dev);
>  
> -	dw_pcie_wait_for_link(pci);
> +	ret = dw_pcie_wait_for_link(pci);
> +	if (ret)
> +		goto err_reset_phy;
>  
>  	if (pci->link_gen == 2) {
>  		/* Allow Gen2 mode after the link is up. */
> @@ -881,11 +884,14 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
>  		}
>  
>  		/* Make sure link training is finished as well! */
> -		dw_pcie_wait_for_link(pci);
> +		ret = dw_pcie_wait_for_link(pci);
> +		if (ret)
> +			goto err_reset_phy;
>  	} else {
>  		dev_info(dev, "Link: Gen2 disabled\n");
>  	}
>  
> +	imx6_pcie->link_is_up = true;
>  	tmp = dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKSTA);
>  	dev_info(dev, "Link up, Gen%i\n", tmp & PCI_EXP_LNKSTA_CLS);
>  	return 0;
> @@ -895,7 +901,7 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
>  		dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0),
>  		dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG1));
>  	imx6_pcie_reset_phy(imx6_pcie);
> -	return ret;
> +	return 0;
>  }
>  
>  static int imx6_pcie_host_init(struct pcie_port *pp)
> @@ -1022,10 +1028,8 @@ static int imx6_pcie_resume_noirq(struct device *dev)
>  	imx6_pcie_init_phy(imx6_pcie);
>  	imx6_pcie_deassert_core_reset(imx6_pcie);
>  	dw_pcie_setup_rc(pp);
> -
> -	ret = imx6_pcie_start_link(imx6_pcie->pci);
> -	if (ret < 0)
> -		dev_info(dev, "pcie link is down after resume.\n");
> +	if (imx6_pcie->link_is_up)
> +		imx6_pcie_start_link(imx6_pcie->pci);
>  
>  	return 0;
>  }
> -- 
> 2.25.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode
  2022-06-13 10:17   ` Francesco Dolcini
@ 2022-06-14  0:58     ` Hongxing Zhu
  0 siblings, 0 replies; 14+ messages in thread
From: Hongxing Zhu @ 2022-06-14  0:58 UTC (permalink / raw)
  To: Francesco Dolcini, l.stach, bhelgaas, robh
  Cc: broonie, lorenzo.pieralisi, festevam, linux-pci,
	linux-arm-kernel, linux-kernel, kernel, dl-linux-imx

> -----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


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation
  2022-06-13 20:41 ` [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Bjorn Helgaas
@ 2022-06-14  1:00   ` Hongxing Zhu
  0 siblings, 0 replies; 14+ messages in thread
From: Hongxing Zhu @ 2022-06-14  1:00 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini, linux-pci, linux-arm-kernel, linux-kernel,
	kernel, dl-linux-imx

> -----Original Message-----
> From: Bjorn Helgaas <helgaas@kernel.org>
> Sent: 2022年6月14日 4:41
> To: Hongxing Zhu <hongxing.zhu@nxp.com>
> 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; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH v10 0/7] PCI: imx6: refine codes and add the error
> propagation
> 
> On Mon, Jun 13, 2022 at 04:55:31PM +0800, Richard Zhu wrote:
> > 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 and resume
> > - Turn off regulator when the system is in suspend mode
> > - Let the probe successfully when link never comes up
> > - Do not hide the phy driver callbacks in core reset and clk_enable.
> 
> This doesn't apply on v5.19-rc1 for me.  Am I missing something:
Hi Bjorn:
The V10 patch based on Shawn's for-next branch.
I would rebased them on v5.19-rc1 later.

Best Regards
Richard Zhu

> 
>   03:38:06 ~/linux (main)$ git checkout -b wip/richard-imx6-power-v10
> v5.19-rc1
>   Switched to a new branch 'wip/richard-imx6-power-v10'
>   03:38:14 ~/linux (wip/richard-imx6-power-v10)$ b4 am -om/
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ker
> nel.org%2Fr%2F1655110538-10914-1-git-send-email-hongxing.zhu%40nxp.co
> m&amp;data=05%7C01%7Chongxing.zhu%40nxp.com%7C5c2dbbe817b94f90
> 919508da4d7d16bb%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> C637907496897306313%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%
> 7C&amp;sdata=bCMhbBxRNV8D0lnVBxURUFRbtMNADUxZJq4wZz47rKY%3D&
> amp;reserved=0
>   Looking up
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ker
> nel.org%2Fr%2F1655110538-10914-1-git-send-email-hongxing.zhu%2540nxp.
> com&amp;data=05%7C01%7Chongxing.zhu%40nxp.com%7C5c2dbbe817b94f
> 90919508da4d7d16bb%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0
> %7C637907496897306313%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj
> AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7
> C%7C&amp;sdata=s3FVLiwJneQlQPV1KKj4cPJ2jD%2FtKudkqP4wd0LACgI%3D
> &amp;reserved=0
>   Analyzing 9 messages in the thread
>   Checking attestation on all messages, may take a moment...
>   ---
>     [PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one
> standalone function
>     [PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init
>     [PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier
>     [PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable
> PCIe clocks
>     [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in
> suspend mode
>     [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
>     [PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the
> error handling
>   ---
>   Total patches: 7
>   ---
>   Cover:
> m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_
> propagation.cover
>    Link:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.ker
> nel.org%2Fr%2F1655110538-10914-1-git-send-email-hongxing.zhu%40nxp.co
> m&amp;data=05%7C01%7Chongxing.zhu%40nxp.com%7C5c2dbbe817b94f90
> 919508da4d7d16bb%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7
> C637907496897306313%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%
> 7C&amp;sdata=bCMhbBxRNV8D0lnVBxURUFRbtMNADUxZJq4wZz47rKY%3D&
> amp;reserved=0
>    Base: not specified
> 	 git am
> m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_
> propagation.mbx
>   03:38:27 ~/linux (wip/richard-imx6-power-v10)$ git am
> m/v10_20220613_hongxing_zhu_pci_imx6_refine_codes_and_add_the_error_
> propagation.mbx
>   Applying: PCI: imx6: Encapsulate the clock enable into one standalone
> function
>   error: patch failed: drivers/pci/controller/dwc/pci-imx6.c:539
>   error: drivers/pci/controller/dwc/pci-imx6.c: patch does not apply
>   Patch failed at 0001 PCI: imx6: Encapsulate the clock enable into one
> standalone function
>   hint: Use 'git am --show-current-patch' to see the failed patch
>   When you have resolved this problem, run "git am --continue".
>   If you prefer to skip this patch, run "git am --skip" instead.
>   To restore the original branch and stop patching, run "git am --abort".


^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
  2022-06-13 22:21   ` Bjorn Helgaas
@ 2022-06-14  1:02     ` Hongxing Zhu
  0 siblings, 0 replies; 14+ messages in thread
From: Hongxing Zhu @ 2022-06-14  1:02 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: l.stach, bhelgaas, robh+dt, broonie, lorenzo.pieralisi, festevam,
	francesco.dolcini, linux-pci, linux-arm-kernel, linux-kernel,
	kernel, dl-linux-imx

> -----Original Message-----
> From: Bjorn Helgaas <helgaas@kernel.org>
> Sent: 2022年6月14日 6:21
> To: Hongxing Zhu <hongxing.zhu@nxp.com>
> 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; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error
> 
> On Mon, Jun 13, 2022 at 04:55:37PM +0800, Richard Zhu wrote:
> > let the driver probe successfully, return zero in
> > imx6_pcie_start_link() when PCIe link is down.
> >
> > Because i.MX PCIe doesn't support hot-plug feature.
> > In this link down scenario, only start the PCIe link training in
> > resume when the link is up before system suspend to avoid the long
> > latency in the link training period.
> 
> This looks like two changes that should be separate patches:
> 
>   1) Make driver probe successful even if link is down.
> 
>   2) Reduce resume time by only starting the link if it was up before
>      suspend.
Yes, you're right.
They are two changes. Would split them into two patches later.
Thanks a lot for your kindly help.

Best Regards
Richard Zhu
> 
> > Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
> > ---
> >  drivers/pci/controller/dwc/pci-imx6.c | 18 +++++++++++-------
> >  1 file changed, 11 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/pci/controller/dwc/pci-imx6.c
> > b/drivers/pci/controller/dwc/pci-imx6.c
> > index c02748393aac..ac6ec2d691a0 100644
> > --- a/drivers/pci/controller/dwc/pci-imx6.c
> > +++ b/drivers/pci/controller/dwc/pci-imx6.c
> > @@ -67,6 +67,7 @@ struct imx6_pcie {
> >  	struct dw_pcie		*pci;
> >  	int			reset_gpio;
> >  	bool			gpio_active_high;
> > +	bool			link_is_up;
> >  	struct clk		*pcie_bus;
> >  	struct clk		*pcie_phy;
> >  	struct clk		*pcie_inbound_axi;
> > @@ -845,7 +846,9 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
> >  	/* Start LTSSM. */
> >  	imx6_pcie_ltssm_enable(dev);
> >
> > -	dw_pcie_wait_for_link(pci);
> > +	ret = dw_pcie_wait_for_link(pci);
> > +	if (ret)
> > +		goto err_reset_phy;
> >
> >  	if (pci->link_gen == 2) {
> >  		/* Allow Gen2 mode after the link is up. */ @@ -881,11 +884,14
> @@
> > static int imx6_pcie_start_link(struct dw_pcie *pci)
> >  		}
> >
> >  		/* Make sure link training is finished as well! */
> > -		dw_pcie_wait_for_link(pci);
> > +		ret = dw_pcie_wait_for_link(pci);
> > +		if (ret)
> > +			goto err_reset_phy;
> >  	} else {
> >  		dev_info(dev, "Link: Gen2 disabled\n");
> >  	}
> >
> > +	imx6_pcie->link_is_up = true;
> >  	tmp = dw_pcie_readw_dbi(pci, offset + PCI_EXP_LNKSTA);
> >  	dev_info(dev, "Link up, Gen%i\n", tmp & PCI_EXP_LNKSTA_CLS);
> >  	return 0;
> > @@ -895,7 +901,7 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)
> >  		dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0),
> >  		dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG1));
> >  	imx6_pcie_reset_phy(imx6_pcie);
> > -	return ret;
> > +	return 0;
> >  }
> >
> >  static int imx6_pcie_host_init(struct pcie_port *pp) @@ -1022,10
> > +1028,8 @@ static int imx6_pcie_resume_noirq(struct device *dev)
> >  	imx6_pcie_init_phy(imx6_pcie);
> >  	imx6_pcie_deassert_core_reset(imx6_pcie);
> >  	dw_pcie_setup_rc(pp);
> > -
> > -	ret = imx6_pcie_start_link(imx6_pcie->pci);
> > -	if (ret < 0)
> > -		dev_info(dev, "pcie link is down after resume.\n");
> > +	if (imx6_pcie->link_is_up)
> > +		imx6_pcie_start_link(imx6_pcie->pci);
> >
> >  	return 0;
> >  }
> > --
> > 2.25.1
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists
> > .infradead.org%2Fmailman%2Flistinfo%2Flinux-arm-kernel&amp;data=05%7
> C0
> >
> 1%7Chongxing.zhu%40nxp.com%7Ce77b8f84d1cf4a0b105808da4d8b0e18%7
> C686ea1
> >
> d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637907556889007090%7CUnk
> nown%7CTW
> >
> FpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXV
> CI6
> >
> Mn0%3D%7C3000%7C%7C%7C&amp;sdata=vd0JWz9d5xDP4MpPNTsq5UG2L
> gmx%2B%2FrNE
> > tnF4UsZKCM%3D&amp;reserved=0

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-06-14  1:02 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-13  8:55 [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Richard Zhu
2022-06-13  8:55 ` [PATCH v10 1/7] PCI: imx6: Encapsulate the clock enable into one standalone function Richard Zhu
2022-06-13  8:55 ` [PATCH v10 2/7] PCI: imx6: Add the error propagation from host_init Richard Zhu
2022-06-13  8:55 ` [PATCH v10 3/7] PCI: imx6: Move imx6_pcie_clk_disable() earlier Richard Zhu
2022-06-13  8:55 ` [PATCH v10 4/7] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable PCIe clocks Richard Zhu
2022-06-13  8:55 ` [PATCH v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode Richard Zhu
2022-06-13 10:17   ` Francesco Dolcini
2022-06-14  0:58     ` Hongxing Zhu
2022-06-13  8:55 ` [PATCH v10 6/7] PCI: imx6: Mark the link down as none fatal error Richard Zhu
2022-06-13 22:21   ` Bjorn Helgaas
2022-06-14  1:02     ` Hongxing Zhu
2022-06-13  8:55 ` [PATCH v10 7/7] PCI: imx6: Do not hide phy driver callbacks and refine the error handling Richard Zhu
2022-06-13 20:41 ` [PATCH v10 0/7] PCI: imx6: refine codes and add the error propagation Bjorn Helgaas
2022-06-14  1:00   ` Hongxing Zhu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).