PCI: imx6: refine codes and add the error propagation
Subsystems (4)
v12 cover PCI: imx6: refine codes and add the error propagation
From: Bjorn Helgaas <[email protected]>
This is a v12 of Richard's series with this description:
Quoted 7 lines
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 fromhost_initand 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 andclk_enable. BTW, this series are verified on i.MX8MM EVK board when one NVME is used.
Main changes from v11 to v12:
- Add four intro patches to move code around to collect similar things (PHY management, reset management) together. This makes the first diff to collect clock enables simpler because it's not cluttered with unrelated things that didn't actually change.
- Factor out ref clock disables so the disable function structure matches the enable structure.
- Drop unused "ret" from "Reduce resume time ..." to avoid bisection hole, then add it back in "Do not hide phy driver ..." where we start using it again.
- Add patch to make imx6_pcie_clk_disable() symmetric with imx6_pcie_clk_enable() in terms of enable/disable ordering.
Quoted 65 lines
Main changes from v10 to v11:
No code changes, just do the following operations refer to Bjorn's comments.
- Split #6 patch into two patches.
- Rebase to v5.19-rc1 based on for-next branch of Shawn's git.Main changes from v9 to v10:
- Add the "Reviewed-by: Lucas Stach <[email protected]>" 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.
- Move theregualtor_disableinto suspend, turn off the regulator when bus is powered off and system in suspend mode.
- Let the driver probe successfully, return zero inimx6_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 andclk_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 placesMain changes from v7 to v8:
Regarding Bjorn's review comments.
- Align the format of thedev_infomessage and refine commit log of #6/7/8 patches.
- Rename theerr_reset_phylabel, since there is no PHY reset in the outMain 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 theregulator_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 newhost_exit()callback intodw_pcie_host_ops, then it could be invoked to handle the unbalance issue in the error handling afterhost_init()function when link is down.
- Add a newhost_exit()callback for i.MX PCIe driver to handle this case in the error handling afterhost_init.
Quoted 10 lines
Main changes from v1 to v2:
Regarding Lucas' comments.
- Move the placement of the newimx6_pcie_clk_enable()to avoid the forward declarition.
- Seperate the second patch of v1 patch-set to three patches.
- Use themodule_paramto 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.
Bjorn Helgaas (5):
PCI: imx6: Move imx6_pcie_grp_offset(), imx6_pcie_configure_type()
earlier
PCI: imx6: Move PHY management functions together
PCI: imx6: Move imx6_pcie_enable_ref_clk() earlier
PCI: imx6: Factor out ref clock disable to match enable
PCI: imx6: Disable clocks in reverse order of enable
Richard Zhu (8):
PCI: imx6: Move imx6_pcie_clk_disable() earlier
PCI: imx6: Collect clock enables in imx6_pcie_clk_enable()
PCI: imx6: Propagate .host_init() errors to caller
PCI: imx6: Disable i.MX6QDL clock when disabling ref clocks
PCI: imx6: Turn off regulator when system is in suspend mode
PCI: imx6: Mark the link down as non-fatal error
PCI: imx6: Reduce resume time by only starting link if it was up
before suspend
PCI: imx6: Do not hide phy driver callbacks and refine the error
handling
drivers/pci/controller/dwc/pci-imx6.c | 606 +++++++++++++++----------- 1 file changed, 342 insertions(+), 264 deletions(-)
Signature · 1 line
2.25.1
PATCH v12 1/13 PCI: imx6: Move imx6_pcie_grp_offset(), imx6_pcie_configure_type() earlier
From: Bjorn Helgaas <[email protected]>
Move imx6_pcie_grp_offset() and imx6_pcie_configure_type() earlier in the file since they depend on nothing and are used by several other functions that will be moved earlier. No functional change intended.
--- drivers/pci/controller/dwc/pci-imx6.c | 50 +++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +25 -25
@@ -146,6 +146,31 @@ struct imx6_pcie {#define PHY_RX_OVRD_IN_LO_RX_DATA_EN BIT(5)#define PHY_RX_OVRD_IN_LO_RX_PLL_EN BIT(3) +static unsigned int imx6_pcie_grp_offset (const struct imx6_pcie *imx6_pcie) +{ +WARN_ON (imx6_pcie->drvdata->variant !=IMX8MQ && + imx6_pcie->drvdata->variant !=IMX8MM ); +return imx6_pcie->controller_id ==1 ?IOMUXC_GPR16 :IOMUXC_GPR14 ; +} + +static void imx6_pcie_configure_type (struct imx6_pcie *imx6_pcie) +{ +unsigned int mask, val; + +if (imx6_pcie->drvdata->variant ==IMX8MQ && + imx6_pcie->controller_id ==1 ) { + mask =IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE ; + val =FIELD_PREP (IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE , +PCI_EXP_TYPE_ROOT_PORT ); + }else { + mask =IMX6Q_GPR12_DEVICE_TYPE ; + val =FIELD_PREP (IMX6Q_GPR12_DEVICE_TYPE , +PCI_EXP_TYPE_ROOT_PORT ); + } + +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , mask, val); +} +static int pcie_phy_poll_ack (struct imx6_pcie *imx6_pcie,bool exp_val) {struct dw_pcie *pci = imx6_pcie->pci;
@@ -415,13 +440,6 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) imx6_pcie->gpio_active_high); } -static unsigned int imx6_pcie_grp_offset (const struct imx6_pcie *imx6_pcie) -{ -WARN_ON (imx6_pcie->drvdata->variant !=IMX8MQ && - imx6_pcie->drvdata->variant !=IMX8MM ); -return imx6_pcie->controller_id ==1 ?IOMUXC_GPR16 :IOMUXC_GPR14 ; -} -static int imx6_pcie_enable_ref_clk (struct imx6_pcie *imx6_pcie) {struct dw_pcie *pci = imx6_pcie->pci;
@@ -617,24 +635,6 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) } } -static void imx6_pcie_configure_type (struct imx6_pcie *imx6_pcie) -{ -unsigned int mask, val; - -if (imx6_pcie->drvdata->variant ==IMX8MQ && - imx6_pcie->controller_id ==1 ) { - mask =IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE ; - val =FIELD_PREP (IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE , -PCI_EXP_TYPE_ROOT_PORT ); - }else { - mask =IMX6Q_GPR12_DEVICE_TYPE ; - val =FIELD_PREP (IMX6Q_GPR12_DEVICE_TYPE , -PCI_EXP_TYPE_ROOT_PORT ); - } - -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , mask, val); -} -static void imx6_pcie_init_phy (struct imx6_pcie *imx6_pcie) {switch (imx6_pcie->drvdata->variant) {
Signature · 1 line
2.25.1
RE: [PATCH v12 01/13] PCI: imx6: Move imx6_pcie_grp_offset(), imx6_pcie_configure_type() earlier
Quoted 15 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 7:16
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: [PATCH v12 01/13] PCI: imx6: Moveimx6_pcie_grp_offset(),imx6_pcie_configure_type()earlier
Quoted 7 lines
From: Bjorn Helgaas <[email protected]>
Move
imx6_pcie_grp_offset()andimx6_pcie_configure_type()earlier in the file since they depend on nothing and are used by several other functions that will be moved earlier. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>
Best Regards
Richard Zhu
Quoted 80 lines
--- drivers/pci/controller/dwc/pci-imx6.c | 50 +++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +22
-25@@ -146,6 +146,31 @@ struct imx6_pcie {#define PHY_RX_OVRD_IN_LO_RX_DATA_EN BIT(5)#define PHY_RX_OVRD_IN_LO_RX_PLL_EN BIT(3) +static unsigned int imx6_pcie_grp_offset (const struct imx6_pcie +*imx6_pcie) { +WARN_ON (imx6_pcie->drvdata->variant !=IMX8MQ && + imx6_pcie->drvdata->variant !=IMX8MM ); +return imx6_pcie->controller_id ==1 ?IOMUXC_GPR16 :IOMUXC_GPR14 ; } + +static void imx6_pcie_configure_type (struct imx6_pcie *imx6_pcie) { +unsigned int mask, val; + +if (imx6_pcie->drvdata->variant ==IMX8MQ && + imx6_pcie->controller_id ==1 ) { + mask =IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE ; + val =FIELD_PREP (IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE , +PCI_EXP_TYPE_ROOT_PORT ); + }else { + mask =IMX6Q_GPR12_DEVICE_TYPE ; + val =FIELD_PREP (IMX6Q_GPR12_DEVICE_TYPE , +PCI_EXP_TYPE_ROOT_PORT ); + } + +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , mask, val); } +static int pcie_phy_poll_ack (struct imx6_pcie *imx6_pcie,bool exp_val) {struct dw_pcie *pci = imx6_pcie->pci;@@ -415,13 +440,6 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) imx6_pcie->gpio_active_high); } -static unsigned int imx6_pcie_grp_offset (const struct imx6_pcie *imx6_pcie) -{ -WARN_ON (imx6_pcie->drvdata->variant !=IMX8MQ && - imx6_pcie->drvdata->variant !=IMX8MM ); -return imx6_pcie->controller_id ==1 ?IOMUXC_GPR16 :IOMUXC_GPR14 ; -} -static int imx6_pcie_enable_ref_clk (struct imx6_pcie *imx6_pcie) {struct dw_pcie *pci = imx6_pcie->pci;@@ -617,24 +635,6 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) } } -static void imx6_pcie_configure_type(struct imx6_pcie *imx6_pcie) -{ -unsigned int mask, val; - -if (imx6_pcie->drvdata->variant ==IMX8MQ && - imx6_pcie->controller_id ==1 ) { - mask =IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE ; - val =FIELD_PREP (IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE , -PCI_EXP_TYPE_ROOT_PORT ); - }else { - mask =IMX6Q_GPR12_DEVICE_TYPE ; - val =FIELD_PREP (IMX6Q_GPR12_DEVICE_TYPE , -PCI_EXP_TYPE_ROOT_PORT ); - } - -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , mask, val); -} -static void imx6_pcie_init_phy (struct imx6_pcie *imx6_pcie) {switch (imx6_pcie->drvdata->variant) { --2.25.1
PATCH v12 2/13 PCI: imx6: Move PHY management functions together
In reply to Bjorn HelgaasFrom: Bjorn Helgaas <[email protected]>
Collect imx6_pcie_init_phy(), imx7d_pcie_wait_for_phy_pll_lock(), and imx6_setup_phy_mpll() earlier with other PHY-related code. No functional change intended.
--- drivers/pci/controller/dwc/pci-imx6.c | 256 +++++++++++++------------- 1 file changed, 128 insertions(+), 128 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +128 -128
@@ -296,6 +296,134 @@ static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, u16 data)return 0 ; } +static void imx6_pcie_init_phy (struct imx6_pcie *imx6_pcie) +{ +switch (imx6_pcie->drvdata->variant) { +case IMX8MM : +/* +* The PHY initialization had been done in the PHY +* driver, break here directly. +*/ +break ; +case IMX8MQ : +/* +* TODO: Currently this code assumes external +* oscillator is being used +*/ +regmap_update_bits (imx6_pcie->iomuxc_gpr, +imx6_pcie_grp_offset (imx6_pcie), +IMX8MQ_GPR_PCIE_REF_USE_PAD , +IMX8MQ_GPR_PCIE_REF_USE_PAD ); +/* +* Regarding the datasheet, the PCIE_VPH is suggested +* to be 1.8V. If the PCIE_VPH is supplied by 3.3V, the +* VREG_BYPASS should be cleared to zero. +*/ +if (imx6_pcie->vph && +regulator_get_voltage (imx6_pcie->vph) >3000000 ) +regmap_update_bits (imx6_pcie->iomuxc_gpr, +imx6_pcie_grp_offset (imx6_pcie), +IMX8MQ_GPR_PCIE_VREG_BYPASS , +0 ); +break ; +case IMX7D : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX7D_GPR12_PCIE_PHY_REFCLK_SEL ,0 ); +break ; +case IMX6SX : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX6SX_GPR12_PCIE_RX_EQ_MASK , +IMX6SX_GPR12_PCIE_RX_EQ_2 ); + fallthrough; +default : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX6Q_GPR12_PCIE_CTL_2 ,0 <<10 ); + +/* configure constant input signal to the pcie ctrl and phy */ +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX6Q_GPR12_LOS_LEVEL ,9 <<4 ); + +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_DEEMPH_GEN1 , + imx6_pcie->tx_deemph_gen1 <<0 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB , + imx6_pcie->tx_deemph_gen2_3p5db <<6 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB , + imx6_pcie->tx_deemph_gen2_6db <<12 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_SWING_FULL , + imx6_pcie->tx_swing_full <<18 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_SWING_LOW , + imx6_pcie->tx_swing_low <<25 ); +break ; + } + +imx6_pcie_configure_type (imx6_pcie); +} + +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 int imx6_setup_phy_mpll (struct imx6_pcie *imx6_pcie) +{ +unsigned long phy_rate =clk_get_rate (imx6_pcie->pcie_phy); +int mult, div; +u16 val; + +if (!(imx6_pcie->drvdata->flags &IMX6_PCIE_FLAG_IMX6_PHY )) +return 0 ; + +switch (phy_rate) { +case 125000000 : +/* +* The default settings of the MPLL are for a 125MHz input +* clock, so no need to reconfigure anything in that case. +*/ +return 0 ; +case 100000000 : + mult =25 ; + div =0 ; +break ; +case 200000000 : + mult =25 ; + div =1 ; +break ; +default : +dev_err (imx6_pcie->pci->dev, +"Unsupported PHY reference clock rate %lu\n" , phy_rate); +return -EINVAL ; + } + +pcie_phy_read (imx6_pcie,PCIE_PHY_MPLL_OVRD_IN_LO , &val); + val &= ~(PCIE_PHY_MPLL_MULTIPLIER_MASK << +PCIE_PHY_MPLL_MULTIPLIER_SHIFT ); + val |= mult <<PCIE_PHY_MPLL_MULTIPLIER_SHIFT ; + val |=PCIE_PHY_MPLL_MULTIPLIER_OVRD ; +pcie_phy_write (imx6_pcie,PCIE_PHY_MPLL_OVRD_IN_LO , val); + +pcie_phy_read (imx6_pcie,PCIE_PHY_ATEOVRD , &val); + val &= ~(PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK << +PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT ); + val |= div <<PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT ; + val |=PCIE_PHY_ATEOVRD_EN ; +pcie_phy_write (imx6_pcie,PCIE_PHY_ATEOVRD , val); + +return 0 ; +} +static void imx6_pcie_reset_phy (struct imx6_pcie *imx6_pcie) {u16 tmp;
@@ -500,19 +628,6 @@ 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) {struct dw_pcie *pci = imx6_pcie->pci;
@@ -635,121 +750,6 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) } } -static void imx6_pcie_init_phy (struct imx6_pcie *imx6_pcie) -{ -switch (imx6_pcie->drvdata->variant) { -case IMX8MM : -/* -* The PHY initialization had been done in the PHY -* driver, break here directly. -*/ -break ; -case IMX8MQ : -/* -* TODO: Currently this code assumes external -* oscillator is being used -*/ -regmap_update_bits (imx6_pcie->iomuxc_gpr, -imx6_pcie_grp_offset (imx6_pcie), -IMX8MQ_GPR_PCIE_REF_USE_PAD , -IMX8MQ_GPR_PCIE_REF_USE_PAD ); -/* -* Regarding the datasheet, the PCIE_VPH is suggested -* to be 1.8V. If the PCIE_VPH is supplied by 3.3V, the -* VREG_BYPASS should be cleared to zero. -*/ -if (imx6_pcie->vph && -regulator_get_voltage (imx6_pcie->vph) >3000000 ) -regmap_update_bits (imx6_pcie->iomuxc_gpr, -imx6_pcie_grp_offset (imx6_pcie), -IMX8MQ_GPR_PCIE_VREG_BYPASS , -0 ); -break ; -case IMX7D : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX7D_GPR12_PCIE_PHY_REFCLK_SEL ,0 ); -break ; -case IMX6SX : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX6SX_GPR12_PCIE_RX_EQ_MASK , -IMX6SX_GPR12_PCIE_RX_EQ_2 ); - fallthrough; -default : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX6Q_GPR12_PCIE_CTL_2 ,0 <<10 ); - -/* configure constant input signal to the pcie ctrl and phy */ -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX6Q_GPR12_LOS_LEVEL ,9 <<4 ); - -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_DEEMPH_GEN1 , - imx6_pcie->tx_deemph_gen1 <<0 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB , - imx6_pcie->tx_deemph_gen2_3p5db <<6 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB , - imx6_pcie->tx_deemph_gen2_6db <<12 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_SWING_FULL , - imx6_pcie->tx_swing_full <<18 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_SWING_LOW , - imx6_pcie->tx_swing_low <<25 ); -break ; - } - -imx6_pcie_configure_type (imx6_pcie); -} - -static int imx6_setup_phy_mpll (struct imx6_pcie *imx6_pcie) -{ -unsigned long phy_rate =clk_get_rate (imx6_pcie->pcie_phy); -int mult, div; -u16 val; - -if (!(imx6_pcie->drvdata->flags &IMX6_PCIE_FLAG_IMX6_PHY )) -return 0 ; - -switch (phy_rate) { -case 125000000 : -/* -* The default settings of the MPLL are for a 125MHz input -* clock, so no need to reconfigure anything in that case. -*/ -return 0 ; -case 100000000 : - mult =25 ; - div =0 ; -break ; -case 200000000 : - mult =25 ; - div =1 ; -break ; -default : -dev_err (imx6_pcie->pci->dev, -"Unsupported PHY reference clock rate %lu\n" , phy_rate); -return -EINVAL ; - } - -pcie_phy_read (imx6_pcie,PCIE_PHY_MPLL_OVRD_IN_LO , &val); - val &= ~(PCIE_PHY_MPLL_MULTIPLIER_MASK << -PCIE_PHY_MPLL_MULTIPLIER_SHIFT ); - val |= mult <<PCIE_PHY_MPLL_MULTIPLIER_SHIFT ; - val |=PCIE_PHY_MPLL_MULTIPLIER_OVRD ; -pcie_phy_write (imx6_pcie,PCIE_PHY_MPLL_OVRD_IN_LO , val); - -pcie_phy_read (imx6_pcie,PCIE_PHY_ATEOVRD , &val); - val &= ~(PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK << -PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT ); - val |= div <<PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT ; - val |=PCIE_PHY_ATEOVRD_EN ; -pcie_phy_write (imx6_pcie,PCIE_PHY_ATEOVRD , val); - -return 0 ; -} -static int imx6_pcie_wait_for_speed_change (struct imx6_pcie *imx6_pcie) {struct dw_pcie *pci = imx6_pcie->pci;
Signature · 1 line
2.25.1
RE: [PATCH v12 02/13] PCI: imx6: Move PHY management functions together
Quoted 14 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 7:16
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: [PATCH v12 02/13] PCI: imx6: Move PHY management functions together
Quoted 7 lines
From: Bjorn Helgaas <[email protected]>
Collect
imx6_pcie_init_phy(),imx7d_pcie_wait_for_phy_pll_lock(), andimx6_setup_phy_mpll()earlier with other PHY-related code. No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>
Best Regards
Richard Zhu
Quoted 282 lines
--- drivers/pci/controller/dwc/pci-imx6.c | 256 +++++++++++++------------- 1 file changed, 128 insertions(+), 128 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +125
-126@@ -296,6 +296,134 @@ static int pcie_phy_write(struct imx6_pcie *imx6_pcie, int addr, u16 data)return 0 ; } +static void imx6_pcie_init_phy (struct imx6_pcie *imx6_pcie) { +switch (imx6_pcie->drvdata->variant) { +case IMX8MM : +/* +* The PHY initialization had been done in the PHY +* driver, break here directly. +*/ +break ; +case IMX8MQ : +/* +* TODO: Currently this code assumes external +* oscillator is being used +*/ +regmap_update_bits (imx6_pcie->iomuxc_gpr, +imx6_pcie_grp_offset (imx6_pcie), +IMX8MQ_GPR_PCIE_REF_USE_PAD , +IMX8MQ_GPR_PCIE_REF_USE_PAD ); +/* +* Regarding the datasheet, the PCIE_VPH is suggested +* to be 1.8V. If the PCIE_VPH is supplied by 3.3V, the +* VREG_BYPASS should be cleared to zero. +*/ +if (imx6_pcie->vph && +regulator_get_voltage (imx6_pcie->vph) >3000000 ) +regmap_update_bits (imx6_pcie->iomuxc_gpr, +imx6_pcie_grp_offset (imx6_pcie), +IMX8MQ_GPR_PCIE_VREG_BYPASS , +0 ); +break ; +case IMX7D : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX7D_GPR12_PCIE_PHY_REFCLK_SEL ,0 ); +break ; +case IMX6SX : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX6SX_GPR12_PCIE_RX_EQ_MASK , +IMX6SX_GPR12_PCIE_RX_EQ_2 ); + fallthrough; +default : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX6Q_GPR12_PCIE_CTL_2 ,0 <<10 ); + +/* configure constant input signal to the pcie ctrl and phy */ +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX6Q_GPR12_LOS_LEVEL ,9 <<4 ); + +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_DEEMPH_GEN1 , + imx6_pcie->tx_deemph_gen1 <<0 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB , + imx6_pcie->tx_deemph_gen2_3p5db <<6 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB , + imx6_pcie->tx_deemph_gen2_6db <<12 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_SWING_FULL , + imx6_pcie->tx_swing_full <<18 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , +IMX6Q_GPR8_TX_SWING_LOW , + imx6_pcie->tx_swing_low <<25 ); +break ; + } + +imx6_pcie_configure_type (imx6_pcie); +} + +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 int imx6_setup_phy_mpll (struct imx6_pcie *imx6_pcie) { +unsigned long phy_rate =clk_get_rate (imx6_pcie->pcie_phy); +int mult, div; +u16 val; + +if (!(imx6_pcie->drvdata->flags &IMX6_PCIE_FLAG_IMX6_PHY )) +return 0 ; + +switch (phy_rate) { +case 125000000 : +/* +* The default settings of the MPLL are for a 125MHz input +* clock, so no need to reconfigure anything in that case. +*/ +return 0 ; +case 100000000 : + mult =25 ; + div =0 ; +break ; +case 200000000 : + mult =25 ; + div =1 ; +break ; +default : +dev_err (imx6_pcie->pci->dev, +"Unsupported PHY reference clock rate %lu\n" , phy_rate); +return -EINVAL ; + } + +pcie_phy_read (imx6_pcie,PCIE_PHY_MPLL_OVRD_IN_LO , &val); + val &= ~(PCIE_PHY_MPLL_MULTIPLIER_MASK << +PCIE_PHY_MPLL_MULTIPLIER_SHIFT ); + val |= mult <<PCIE_PHY_MPLL_MULTIPLIER_SHIFT ; + val |=PCIE_PHY_MPLL_MULTIPLIER_OVRD ; +pcie_phy_write (imx6_pcie,PCIE_PHY_MPLL_OVRD_IN_LO , val); + +pcie_phy_read (imx6_pcie,PCIE_PHY_ATEOVRD , &val); + val &= ~(PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK << +PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT ); + val |= div <<PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT ; + val |=PCIE_PHY_ATEOVRD_EN ; +pcie_phy_write (imx6_pcie,PCIE_PHY_ATEOVRD , val); + +return 0 ; +} +static void imx6_pcie_reset_phy (struct imx6_pcie *imx6_pcie) {u16 tmp;@@ -500,19 +628,6 @@ 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) {struct dw_pcie *pci = imx6_pcie->pci;@@ -635,121 +750,6 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) } } -static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie) -{ -switch (imx6_pcie->drvdata->variant) { -case IMX8MM : -/* -* The PHY initialization had been done in the PHY -* driver, break here directly. -*/ -break ; -case IMX8MQ : -/* -* TODO: Currently this code assumes external -* oscillator is being used -*/ -regmap_update_bits (imx6_pcie->iomuxc_gpr, -imx6_pcie_grp_offset (imx6_pcie), -IMX8MQ_GPR_PCIE_REF_USE_PAD , -IMX8MQ_GPR_PCIE_REF_USE_PAD ); -/* -* Regarding the datasheet, the PCIE_VPH is suggested -* to be 1.8V. If the PCIE_VPH is supplied by 3.3V, the -* VREG_BYPASS should be cleared to zero. -*/ -if (imx6_pcie->vph && -regulator_get_voltage (imx6_pcie->vph) >3000000 ) -regmap_update_bits (imx6_pcie->iomuxc_gpr, -imx6_pcie_grp_offset (imx6_pcie), -IMX8MQ_GPR_PCIE_VREG_BYPASS , -0 ); -break ; -case IMX7D : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX7D_GPR12_PCIE_PHY_REFCLK_SEL ,0 ); -break ; -case IMX6SX : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX6SX_GPR12_PCIE_RX_EQ_MASK , -IMX6SX_GPR12_PCIE_RX_EQ_2 ); - fallthrough; -default : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX6Q_GPR12_PCIE_CTL_2 ,0 <<10 ); - -/* configure constant input signal to the pcie ctrl and phy */ -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX6Q_GPR12_LOS_LEVEL ,9 <<4 ); - -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_DEEMPH_GEN1 , - imx6_pcie->tx_deemph_gen1 <<0 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_DEEMPH_GEN2_3P5DB , - imx6_pcie->tx_deemph_gen2_3p5db <<6 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_DEEMPH_GEN2_6DB , - imx6_pcie->tx_deemph_gen2_6db <<12 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_SWING_FULL , - imx6_pcie->tx_swing_full <<18 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR8 , -IMX6Q_GPR8_TX_SWING_LOW , - imx6_pcie->tx_swing_low <<25 ); -break ; - } - -imx6_pcie_configure_type (imx6_pcie); -} - -static int imx6_setup_phy_mpll(struct imx6_pcie *imx6_pcie) -{ -unsigned long phy_rate =clk_get_rate (imx6_pcie->pcie_phy); -int mult, div; -u16 val; - -if (!(imx6_pcie->drvdata->flags &IMX6_PCIE_FLAG_IMX6_PHY )) -return 0 ; - -switch (phy_rate) { -case 125000000 : -/* -* The default settings of the MPLL are for a 125MHz input -* clock, so no need to reconfigure anything in that case. -*/ -return 0 ; -case 100000000 : - mult =25 ; - div =0 ; -break ; -case 200000000 : - mult =25 ; - div =1 ; -break ; -default : -dev_err (imx6_pcie->pci->dev, -"Unsupported PHY reference clock rate %lu\n" , phy_rate); -return -EINVAL ; - } - -pcie_phy_read (imx6_pcie,PCIE_PHY_MPLL_OVRD_IN_LO , &val); - val &= ~(PCIE_PHY_MPLL_MULTIPLIER_MASK << -PCIE_PHY_MPLL_MULTIPLIER_SHIFT ); - val |= mult <<PCIE_PHY_MPLL_MULTIPLIER_SHIFT ; - val |=PCIE_PHY_MPLL_MULTIPLIER_OVRD ; -pcie_phy_write (imx6_pcie,PCIE_PHY_MPLL_OVRD_IN_LO , val); - -pcie_phy_read (imx6_pcie,PCIE_PHY_ATEOVRD , &val); - val &= ~(PCIE_PHY_ATEOVRD_REF_CLKDIV_MASK << -PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT ); - val |= div <<PCIE_PHY_ATEOVRD_REF_CLKDIV_SHIFT ; - val |=PCIE_PHY_ATEOVRD_EN ; -pcie_phy_write (imx6_pcie,PCIE_PHY_ATEOVRD , val); - -return 0 ; -} -static int imx6_pcie_wait_for_speed_change (struct imx6_pcie *imx6_pcie) {struct dw_pcie *pci = imx6_pcie->pci; --2.25.1
PATCH v12 3/13 PCI: imx6: Move imx6_pcie_enable_ref_clk() earlier
In reply to Bjorn HelgaasFrom: Bjorn Helgaas <[email protected]>
Move imx6_pcie_enable_ref_clk() earlier so it's not in the middle between imx6_pcie_assert_core_reset() and imx6_pcie_deassert_core_reset(). No functional change intended.
--- drivers/pci/controller/dwc/pci-imx6.c | 96 +++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +48 -48
@@ -520,54 +520,6 @@ static int imx6_pcie_attach_pd(struct device *dev)return 0 ; } -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 : -reset_control_assert (imx6_pcie->pciephy_reset); - fallthrough; -case IMX8MM : -reset_control_assert (imx6_pcie->apps_reset); -break ; -case IMX6SX : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX6SX_GPR12_PCIE_TEST_POWERDOWN , -IMX6SX_GPR12_PCIE_TEST_POWERDOWN ); -/* Force PCIe PHY reset */ -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR5 , -IMX6SX_GPR5_PCIE_BTNRST_RESET , -IMX6SX_GPR5_PCIE_BTNRST_RESET ); -break ; -case IMX6QP : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , -IMX6Q_GPR1_PCIE_SW_RST , -IMX6Q_GPR1_PCIE_SW_RST ); -break ; -case IMX6Q : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , -IMX6Q_GPR1_PCIE_TEST_PD ,1 <<18 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , -IMX6Q_GPR1_PCIE_REF_CLK_EN ,0 <<16 ); -break ; - } - -if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { -int ret =regulator_disable (imx6_pcie->vpcie); - -if (ret) -dev_err (dev,"failed to disable vpcie regulator: %d\n" , - ret); - } - -/* Some boards don't have PCIe reset GPIO. */ -if (gpio_is_valid (imx6_pcie->reset_gpio)) -gpio_set_value_cansleep (imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high); -} -static int imx6_pcie_enable_ref_clk (struct imx6_pcie *imx6_pcie) {struct dw_pcie *pci = imx6_pcie->pci;
@@ -628,6 +580,54 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)return ret; } +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 : +reset_control_assert (imx6_pcie->pciephy_reset); + fallthrough; +case IMX8MM : +reset_control_assert (imx6_pcie->apps_reset); +break ; +case IMX6SX : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX6SX_GPR12_PCIE_TEST_POWERDOWN , +IMX6SX_GPR12_PCIE_TEST_POWERDOWN ); +/* Force PCIe PHY reset */ +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR5 , +IMX6SX_GPR5_PCIE_BTNRST_RESET , +IMX6SX_GPR5_PCIE_BTNRST_RESET ); +break ; +case IMX6QP : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , +IMX6Q_GPR1_PCIE_SW_RST , +IMX6Q_GPR1_PCIE_SW_RST ); +break ; +case IMX6Q : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , +IMX6Q_GPR1_PCIE_TEST_PD ,1 <<18 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , +IMX6Q_GPR1_PCIE_REF_CLK_EN ,0 <<16 ); +break ; + } + +if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { +int ret =regulator_disable (imx6_pcie->vpcie); + +if (ret) +dev_err (dev,"failed to disable vpcie regulator: %d\n" , + ret); + } + +/* Some boards don't have PCIe reset GPIO. */ +if (gpio_is_valid (imx6_pcie->reset_gpio)) +gpio_set_value_cansleep (imx6_pcie->reset_gpio, + imx6_pcie->gpio_active_high); +} +static void imx6_pcie_deassert_core_reset (struct imx6_pcie *imx6_pcie) {struct dw_pcie *pci = imx6_pcie->pci;
Signature · 1 line
2.25.1
RE: [PATCH v12 03/13] PCI: imx6: Move imx6_pcie_enable_ref_clk() earlier
Quoted 14 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 7:16
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: [PATCH v12 03/13] PCI: imx6: Moveimx6_pcie_enable_ref_clk()earlier
Quoted 7 lines
From: Bjorn Helgaas <[email protected]>
Move
imx6_pcie_enable_ref_clk()earlier so it's not in the middle betweenimx6_pcie_assert_core_reset()andimx6_pcie_deassert_core_reset(). No functional change intended.Signed-off-by Bjorn Helgaas <[email protected]>
Best Regards
Richard Zhu
Quoted 118 lines
--- drivers/pci/controller/dwc/pci-imx6.c | 96 +++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +47
-48@@ -520,54 +520,6 @@ static int imx6_pcie_attach_pd(struct device *dev)return 0 ; } -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 : -reset_control_assert (imx6_pcie->pciephy_reset); - fallthrough; -case IMX8MM : -reset_control_assert (imx6_pcie->apps_reset); -break ; -case IMX6SX : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , -IMX6SX_GPR12_PCIE_TEST_POWERDOWN , -IMX6SX_GPR12_PCIE_TEST_POWERDOWN ); -/* Force PCIe PHY reset */ -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR5 , -IMX6SX_GPR5_PCIE_BTNRST_RESET , -IMX6SX_GPR5_PCIE_BTNRST_RESET ); -break ; -case IMX6QP : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , -IMX6Q_GPR1_PCIE_SW_RST , -IMX6Q_GPR1_PCIE_SW_RST ); -break ; -case IMX6Q : -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , -IMX6Q_GPR1_PCIE_TEST_PD ,1 <<18 ); -regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , -IMX6Q_GPR1_PCIE_REF_CLK_EN ,0 <<16 ); -break ; - } - -if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { -int ret =regulator_disable (imx6_pcie->vpcie); - -if (ret) -dev_err (dev,"failed to disable vpcie regulator: %d\n" , - ret); - } - -/* Some boards don't have PCIe reset GPIO. */ -if (gpio_is_valid (imx6_pcie->reset_gpio)) -gpio_set_value_cansleep (imx6_pcie->reset_gpio, - imx6_pcie->gpio_active_high); -} -static int imx6_pcie_enable_ref_clk (struct imx6_pcie *imx6_pcie) {struct dw_pcie *pci = imx6_pcie->pci;@@ -628,6 +580,54 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)return ret; } +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 : +reset_control_assert (imx6_pcie->pciephy_reset); + fallthrough; +case IMX8MM : +reset_control_assert (imx6_pcie->apps_reset); +break ; +case IMX6SX : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR12 , +IMX6SX_GPR12_PCIE_TEST_POWERDOWN , +IMX6SX_GPR12_PCIE_TEST_POWERDOWN ); +/* Force PCIe PHY reset */ +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR5 , +IMX6SX_GPR5_PCIE_BTNRST_RESET , +IMX6SX_GPR5_PCIE_BTNRST_RESET ); +break ; +case IMX6QP : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , +IMX6Q_GPR1_PCIE_SW_RST , +IMX6Q_GPR1_PCIE_SW_RST ); +break ; +case IMX6Q : +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , +IMX6Q_GPR1_PCIE_TEST_PD ,1 <<18 ); +regmap_update_bits (imx6_pcie->iomuxc_gpr,IOMUXC_GPR1 , +IMX6Q_GPR1_PCIE_REF_CLK_EN ,0 <<16 ); +break ; + } + +if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { +int ret =regulator_disable (imx6_pcie->vpcie); + +if (ret) +dev_err (dev,"failed to disable vpcie regulator: %d\n" , + ret); + } + +/* Some boards don't have PCIe reset GPIO. */ +if (gpio_is_valid (imx6_pcie->reset_gpio)) +gpio_set_value_cansleep (imx6_pcie->reset_gpio, + imx6_pcie->gpio_active_high); +} +static void imx6_pcie_deassert_core_reset (struct imx6_pcie *imx6_pcie) {struct dw_pcie *pci = imx6_pcie->pci; --2.25.1
PATCH v12 4/13 PCI: imx6: Move imx6_pcie_clk_disable() earlier
In reply to Bjorn HelgaasFrom: Richard Zhu <[email protected]>
Move imx6_pcie_clk_disable() earlier to be near other clock-related functions. No functional change intended.
--- drivers/pci/controller/dwc/pci-imx6.c | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +24 -24
@@ -580,6 +580,30 @@ static int imx6_pcie_enable_ref_clk(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 imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie) {struct device *dev = imx6_pcie->pci->dev;
@@ -941,30 +965,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);
Signature · 1 line
2.25.1
PATCH v12 5/13 PCI: imx6: Factor out ref clock disable to match enable
In reply to Bjorn HelgaasFrom: Bjorn Helgaas <[email protected]>
The PCIe ref clocks are specific to different variants. The enables are already split out into imx6_pcie_enable_ref_clk(), but the disables were combined with the more generic bus/phy/pcie clock disables in imx6_pcie_clk_disable().
Split out the variant-specific disables into imx6_pcie_disable_ref_clk() to match imx6_pcie_enable_ref_clk().
No functional change intended.
--- drivers/pci/controller/dwc/pci-imx6.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +10 -6
@@ -580,12 +580,8 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)return ret; } -static void imx6_pcie_clk_disable (struct imx6_pcie *imx6_pcie) +static void imx6_pcie_disable_ref_clk (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);
@@ -595,8 +591,8 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)IMX7D_GPR12_PCIE_PHY_REFCLK_SEL , IMX7D_GPR12_PCIE_PHY_REFCLK_SEL);break ; -case IMX8MQ :case IMX8MM : +case IMX8MQ :clk_disable_unprepare (imx6_pcie->pcie_aux);break ;default :
@@ -604,6 +600,14 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie) } } +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); +imx6_pcie_disable_ref_clk (imx6_pcie); +} +static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie) {struct device *dev = imx6_pcie->pci->dev;
Signature · 1 line
2.25.1
RE: [PATCH v12 05/13] PCI: imx6: Factor out ref clock disable to match enable
Quoted 20 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 7:16
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: [PATCH v12 05/13] PCI: imx6: Factor out ref clock disable to match enableFrom: Bjorn Helgaas <[email protected]>
The PCIe ref clocks are specific to different variants. The enables are already split out into
imx6_pcie_enable_ref_clk(), but the disables were combined with the more generic bus/phy/pcie clock disables inimx6_pcie_clk_disable().
Quoted 6 lines
Split out the variant-specific disables into
imx6_pcie_disable_ref_clk()to matchimx6_pcie_enable_ref_clk().No functional change intended.
Signed-off-by Bjorn Helgaas <[email protected]>
Best Regards
Richard Zhu
Quoted 51 lines
--- drivers/pci/controller/dwc/pci-imx6.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +1
-5@@ -580,12 +580,8 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)return ret; } -static void imx6_pcie_clk_disable (struct imx6_pcie *imx6_pcie) +static void imx6_pcie_disable_ref_clk (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 :drivers/pci/controller/dwc/pci-imx6.c +1
-1clk_disable_unprepare (imx6_pcie->pcie_inbound_axi);@@ -595,8 +591,8 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)IMX7D_GPR12_PCIE_PHY_REFCLK_SEL , IMX7D_GPR12_PCIE_PHY_REFCLK_SEL);break ; -case IMX8MQ :case IMX8MM : +case IMX8MQ :clk_disable_unprepare (imx6_pcie->pcie_aux);break ;drivers/pci/controller/dwc/pci-imx6.c +7
-1default :@@ -604,6 +600,14 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie) } } +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); +imx6_pcie_disable_ref_clk (imx6_pcie); +} +static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie) {struct device *dev = imx6_pcie->pci->dev; --2.25.1
PATCH v12 6/13 PCI: imx6: Collect clock enables in imx6_pcie_clk_enable()
In reply to Bjorn HelgaasFrom: Richard Zhu <[email protected]>
Encapsulate the i.MX PCIe clock enable operations into one standalone function, imx6_pcie_clk_enable(). No functional change intended.
--- drivers/pci/controller/dwc/pci-imx6.c | 98 ++++++++++++++++----------- 1 file changed, 58 insertions(+), 40 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +58 -40
@@ -600,6 +600,58 @@ static void imx6_pcie_disable_ref_clk(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; + + ret =clk_prepare_enable (imx6_pcie->pcie_phy); +if (ret) { +dev_err (dev,"unable to enable pcie_phy clock\n" ); +return ret; + } + + ret =clk_prepare_enable (imx6_pcie->pcie_bus); +if (ret) { +dev_err (dev,"unable to enable pcie_bus clock\n" ); + goto err_pcie_bus; + } + + ret =clk_prepare_enable (imx6_pcie->pcie); +if (ret) { +dev_err (dev,"unable to enable pcie clock\n" ); + goto err_pcie; + } + + ret =imx6_pcie_enable_ref_clk (imx6_pcie); +if (ret) { +dev_err (dev,"unable to enable pcie ref clock\n" ); + 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 ; + +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 imx6_pcie_clk_disable (struct imx6_pcie *imx6_pcie) {clk_disable_unprepare (imx6_pcie->pcie);
@@ -660,7 +712,7 @@ 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; +int ret, err;if (imx6_pcie->vpcie && !regulator_is_enabled (imx6_pcie->vpcie)) { ret =regulator_enable (imx6_pcie->vpcie);
@@ -671,40 +723,12 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) } } - ret =clk_prepare_enable (imx6_pcie->pcie_phy); -if (ret) { -dev_err (dev,"unable to enable pcie_phy clock\n" ); - goto err_pcie_phy; + err =imx6_pcie_clk_enable (imx6_pcie); +if (err) { +dev_err (dev,"unable to enable pcie clocks: %d\n" , err); + goto err_clks; } - ret =clk_prepare_enable (imx6_pcie->pcie_bus); -if (ret) { -dev_err (dev,"unable to enable pcie_bus clock\n" ); - goto err_pcie_bus; - } - - ret =clk_prepare_enable (imx6_pcie->pcie); -if (ret) { -dev_err (dev,"unable to enable pcie clock\n" ); - goto err_pcie; - } - - ret =imx6_pcie_enable_ref_clk (imx6_pcie); -if (ret) { -dev_err (dev,"unable to enable pcie ref clock\n" ); - 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 );switch (imx6_pcie->drvdata->variant) {case IMX8MQ :
@@ -763,13 +787,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 &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { ret =regulator_disable (imx6_pcie->vpcie);if (ret)
Signature · 1 line
2.25.1
PATCH v12 7/13 PCI: imx6: Propagate .host_init() errors to caller
In reply to Bjorn HelgaasFrom: Richard Zhu <[email protected]>
Since dw_pcie_host_init() checks for errors from ops->host_init(), check for errors when enabling power regulators and clocks and return them.
--- drivers/pci/controller/dwc/pci-imx6.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +12 -4
@@ -708,7 +708,7 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) imx6_pcie->gpio_active_high); } -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;
@@ -719,7 +719,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)if (ret) {dev_err (dev,"failed to enable vpcie regulator: %d\n" , ret); -return ; +return ret; } }
@@ -785,7 +785,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)msleep (100 ); } -return ; +return 0 ; err_clks:if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) {
@@ -794,6 +794,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 int imx6_pcie_wait_for_speed_change (struct imx6_pcie *imx6_pcie)
@@ -912,11 +913,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 ;
Signature · 1 line
2.25.1
PATCH v12 8/13 PCI: imx6: Disable i.MX6QDL clock when disabling ref clocks
In reply to Bjorn HelgaasFrom: Richard Zhu <[email protected]>
When disabling PCIe clocks, disable i.MX6QDL ref clock too.
--- drivers/pci/controller/dwc/pci-imx6.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/pci/controller/dwc/pci-imx6.c +8 -0
@@ -586,6 +586,14 @@ static void imx6_pcie_disable_ref_clk(struct imx6_pcie *imx6_pcie)case IMX6SX :clk_disable_unprepare (imx6_pcie->pcie_inbound_axi);break ; +case IMX6QP : +case IMX6Q : +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 IMX7D : regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, IMX7D_GPR12_PCIE_PHY_REFCLK_SEL,
Signature · 1 line
2.25.1
PATCH v12 9/13 PCI: imx6: Turn off regulator when system is in suspend mode
In reply to Bjorn HelgaasFrom: Richard Zhu <[email protected]>
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.
--- drivers/pci/controller/dwc/pci-imx6.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +7 -12
@@ -670,8 +670,6 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie) { -struct device *dev = imx6_pcie->pci->dev; -switch (imx6_pcie->drvdata->variant) {case IMX7D :case IMX8MQ :
@@ -702,14 +700,6 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)break ; } -if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { -int ret =regulator_disable (imx6_pcie->vpcie); - -if (ret) -dev_err (dev,"failed to disable vpcie regulator: %d\n" , - ret); - } -/* Some boards don't have PCIe reset GPIO. */ if (gpio_is_valid (imx6_pcie->reset_gpio)) gpio_set_value_cansleep(imx6_pcie->reset_gpio,
@@ -722,7 +712,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)struct device *dev = pci->dev;int ret, 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",
@@ -796,7 +786,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)return 0 ; err_clks: -if (imx6_pcie->vpcie &®ulator_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",
@@ -1023,6 +1013,9 @@ static int imx6_pcie_suspend_noirq(struct device *dev)break ; } +if (imx6_pcie->vpcie) +regulator_disable (imx6_pcie->vpcie); +return 0 ; }
@@ -1269,6 +1262,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[] = {
Signature · 1 line
2.25.1
Re: [PATCH v12 09/13] PCI: imx6: Turn off regulator when system is in suspend mode
Quoted 66 lines · Bjorn Helgaas
From: Richard Zhu <[email protected]>
The driver should undo any enables it did itself. The regulator disable shouldn't be basing decisions on
regulator_is_enabled().Move the
regulator_disableto 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]>Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/pci/controller/dwc/pci-imx6.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +2
-12@@ -670,8 +670,6 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie) { -struct device *dev = imx6_pcie->pci->dev; -switch (imx6_pcie->drvdata->variant) {case IMX7D :case IMX8MQ :@@ -702,14 +700,6 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie)break ; } -if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { -int ret =regulator_disable (imx6_pcie->vpcie); - -if (ret) -dev_err (dev,"failed to disable vpcie regulator: %d\n" , - ret); - } -/* Some boards don't have PCIe reset GPIO. */ if (gpio_is_valid (imx6_pcie->reset_gpio)) gpio_set_value_cansleep(imx6_pcie->reset_gpio,@@ -722,7 +712,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)struct device *dev = pci->dev;int ret, 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",@@ -796,7 +786,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)return 0 ; err_clks: -if (imx6_pcie->vpcie &®ulator_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",
drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_suspend_noirq(struct device *dev) · line 1017
Quoted 5 lines
drivers/pci/controller/dwc/pci-imx6.c +2
-0@@ -1023,6 +1013,9 @@ static int imx6_pcie_suspend_noirq(struct device *dev)break ; } +if (imx6_pcie->vpcie) +regulator_disable (imx6_pcie->vpcie);
This is a little bit ugly because imx6_pcie_suspend_noirq() and imx6_pcie_resume_noirq() are not symmetric.
We call regulator_disable() directly here in imx6_pcie_suspend_noirq(), but the corresponding regulator_enable() is buried in imx6_pcie_deassert_core_reset().
It would be nicer if the suspend and resume paths looked more similar, as rockchip_pcie_suspend_noirq() and rockchip_pcie_resume_noirq() do, for example.
Quoted 20 lines
drivers/pci/controller/dwc/pci-imx6.c +2
-0return 0 ; }@@ -1269,6 +1262,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[] = {Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hongxing Zhu
maintainerRE: [PATCH v12 09/13] PCI: imx6: Turn off regulator when system is in suspend mode
Quoted 113 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 7:31
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: Re: [PATCH v12 09/13] PCI: imx6: Turn off regulator when system is in suspend modeQuoted 8 lines · Bjorn Helgaas
From: Richard Zhu <[email protected]>
The driver should undo any enables it did itself. The regulator disable shouldn't be basing decisions on
regulator_is_enabled().Move the
regulator_disableto the suspend function, turn off regulator when the system is in suspend mode.Quoted 6 lines
To keep the balance of the regulator usage counter, disable the regulator in shutdown.
Link:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fr%2F1655189942-12678-6-git-send-email-hongxing.z&dat
Quoted 1 line
a=05%7C01%7Chongxing.zhu%40nxp.com%7C8dea46d908d34cb4825808da4 f270eaf%
Quoted 1 line
7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6379093264156415 35%7CUnkn
Quoted 1 line
own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1 haWwi
Quoted 1 line
LCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=tqzlcCmtSkUNxNzJ0Fr5o CR3X2CTH
drivers/pci/controller/dwc/pci-imx6.c static void imx6_pcie_assert_core_reset(struct
Quoted 24 lines
4dwUJS4NXt5KRc%3D&reserved=0
[email protected]Signed-off-by Richard Zhu <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/pci/controller/dwc/pci-imx6.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +0
-2@@ -670,8 +670,6 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie) { -struct device *dev = imx6_pcie->pci->dev; -switch (imx6_pcie->drvdata->variant) {case IMX7D :drivers/pci/controller/dwc/pci-imx6.c +0
-0case IMX8MQ :@@ -702,14 +700,6 @@ static void imx6_pcie_assert_core_reset(struct
imx6_pcie*imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct
Quoted 15 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-8break ; } -if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { -int ret =regulator_disable (imx6_pcie->vpcie); - -if (ret) -dev_err (dev,"failed to disable vpcie regulator: %d\n" , - ret); - } -/* Some boards don't have PCIe reset GPIO. */ if (gpio_is_valid (imx6_pcie->reset_gpio)) gpio_set_value_cansleep(imx6_pcie->reset_gpio,@@ -722,7 +712,7 @@ static int imx6_pcie_deassert_core_reset(struct
imx6_pcie*imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
Quoted 8 lines
drivers/pci/controller/dwc/pci-imx6.c +1
-1struct 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", @@-796,7
Quoted 1 line
+786,7 @@ static int imx6_pcie_deassert_core_reset(struct
imx6_pcie
*imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
Quoted 8 lines
drivers/pci/controller/dwc/pci-imx6.c +1
-1return 0 ; err_clks: -if (imx6_pcie->vpcie &®ulator_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", @@-1023,6
drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_suspend_noirq(struct device *dev) · line 1017
Quoted 6 lines
+1013,9 @@ static int
imx6_pcie_suspend_noirq(struct device *dev)drivers/pci/controller/dwc/pci-imx6.c +2
-0break ; } +if (imx6_pcie->vpcie) +regulator_disable (imx6_pcie->vpcie);This is a little bit ugly because
imx6_pcie_suspend_noirq()andimx6_pcie_resume_noirq()are not symmetric.
Quoted 6 lines
We call
regulator_disable()directly here inimx6_pcie_suspend_noirq(), but the correspondingregulator_enable()is buried inimx6_pcie_deassert_core_reset().It would be nicer if the suspend and resume paths looked more similar, as
rockchip_pcie_suspend_noirq()androckchip_pcie_resume_noirq()do, for example.
Yes, it is. The regulator_disable()/regulator_enable() are not invoked
symmetrically.
In the original codes, the regulator_disable() is contained in imx6_pcie_assert_core_reset() and with _eanbled() check. And regulator_enable() is embedded in imx6_pcie_deassert_core_reset(). Both the regulator disable and enable are invoked in resume before. I move the regulator_disable to suspend mode refer to Lucas' comments.
Refer to the current situation, how about to move the regulator_disable()
out of imx6_pcie_deassert_core_reset() too?
Best Regards
Richard Zhu
Quoted 37 lines
Quoted 18 lines
drivers/pci/controller/dwc/pci-imx6.c +2
-0return 0 ; }@@ -1269,6 +1262,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_drvdatadrvdata[] = {
--
2.25.1Quoted 5 lines
_______________________________________________
linux-arm-kernel mailing list [email protected]
https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists
.infradead.org%2Fmailman%2Flistinfo%2Flinux-arm-kernel&data=05%7C0
Quoted 1 line
1%7Chongxing.zhu%40nxp.com%7C8dea46d908d34cb4825808da4f270eaf%7 C686ea1
Quoted 1 line
d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C637909326415641535%7CUnk nown%7CTW
Quoted 1 line
FpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXV CI6
Quoted 1 line
Mn0%3D%7C3000%7C%7C%7C&sdata=xjn3jX7ub9%2BX%2BAJQ7YPecV5 ujkzLAPXkY
Quoted 1 line
hcieKs%2BKqg%3D&reserved=0
Re: [PATCH v12 09/13] PCI: imx6: Turn off regulator when system is in suspend mode
Quoted 122 lines · Hongxing Zhu
Quoted 113 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 7:31
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: Re: [PATCH v12 09/13] PCI: imx6: Turn off regulator when system is in suspend modeQuoted 8 lines · Bjorn Helgaas
From: Richard Zhu <[email protected]>
The driver should undo any enables it did itself. The regulator disable shouldn't be basing decisions on
regulator_is_enabled().Move the
regulator_disableto the suspend function, turn off regulator when the system is in suspend mode.Quoted 6 lines
To keep the balance of the regulator usage counter, disable the regulator in shutdown.
Link:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore
.kernel.org%2Fr%2F1655189942-12678-6-git-send-email-hongxing.z&dat
Quoted 1 line
a=05%7C01%7Chongxing.zhu%40nxp.com%7C8dea46d908d34cb4825808da4 f270eaf%
Quoted 1 line
7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6379093264156415 35%7CUnkn
Quoted 1 line
own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1 haWwi
Quoted 1 line
LCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=tqzlcCmtSkUNxNzJ0Fr5o CR3X2CTH
drivers/pci/controller/dwc/pci-imx6.c static void imx6_pcie_assert_core_reset(struct
Quoted 24 lines
4dwUJS4NXt5KRc%3D&reserved=0
[email protected]Signed-off-by Richard Zhu <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/pci/controller/dwc/pci-imx6.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +0
-2@@ -670,8 +670,6 @@ static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie)static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie) { -struct device *dev = imx6_pcie->pci->dev; -switch (imx6_pcie->drvdata->variant) {case IMX7D :drivers/pci/controller/dwc/pci-imx6.c +0
-0case IMX8MQ :@@ -702,14 +700,6 @@ static void imx6_pcie_assert_core_reset(struct
imx6_pcie*imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct
Quoted 15 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-8break ; } -if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ) { -int ret =regulator_disable (imx6_pcie->vpcie); - -if (ret) -dev_err (dev,"failed to disable vpcie regulator: %d\n" , - ret); - } -/* Some boards don't have PCIe reset GPIO. */ if (gpio_is_valid (imx6_pcie->reset_gpio)) gpio_set_value_cansleep(imx6_pcie->reset_gpio,@@ -722,7 +712,7 @@ static int imx6_pcie_deassert_core_reset(struct
imx6_pcie*imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
Quoted 8 lines
drivers/pci/controller/dwc/pci-imx6.c +1
-1struct 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", @@-796,7
Quoted 1 line
+786,7 @@ static int imx6_pcie_deassert_core_reset(struct
imx6_pcie
*imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
Quoted 8 lines
drivers/pci/controller/dwc/pci-imx6.c +1
-1return 0 ; err_clks: -if (imx6_pcie->vpcie &®ulator_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", @@-1023,6
drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_suspend_noirq(struct device *dev) · line 1017
Quoted 6 lines
+1013,9 @@ static int
imx6_pcie_suspend_noirq(struct device *dev)drivers/pci/controller/dwc/pci-imx6.c +2
-0break ; } +if (imx6_pcie->vpcie) +regulator_disable (imx6_pcie->vpcie);This is a little bit ugly because
imx6_pcie_suspend_noirq()andimx6_pcie_resume_noirq()are not symmetric.Quoted 6 lines
We call
regulator_disable()directly here inimx6_pcie_suspend_noirq(), but the correspondingregulator_enable()is buried inimx6_pcie_deassert_core_reset().It would be nicer if the suspend and resume paths looked more similar, as
rockchip_pcie_suspend_noirq()androckchip_pcie_resume_noirq()do, for example.Yes, it is. The regulator_disable()/regulator_enable() are not invoked
symmetrically.
Quoted 8 lines
In the original codes, the
regulator_disable()is contained inimx6_pcie_assert_core_reset()and with_eanbled()check. Andregulator_enable()is embedded inimx6_pcie_deassert_core_reset(). Both the regulator disable and enable are invoked in resume before. I move theregulator_disableto suspend mode refer to Lucas' comments.Refer to the current situation, how about to move the
regulator_disable()
out ofimx6_pcie_deassert_core_reset()too?
I think it's important to tweak this closer to the pattern of other drivers like exynos and rockchip.
exynos_pcie_resume_noirq() calls exynos_pcie_host_init(). imx6_pcie_resume_noirq() is VERY similar to imx6_pcie_host_init(), and I think it should call imx6_pcie_host_init() instead of duplicating that code. The only real difference is that imx6_pcie_host_init() calls imx6_setup_phy_mpll() while imx6_pcie_resume_noirq() does not. I suspect that's a bug.
I don't think "regulator_enable(imx6_pcie->vpcie)" really has anything to do with imx6_pcie_deassert_core_reset() and it should be moved out. The typical pattern is to enable regulators in *_probe() and *_resume_noirq() and disable them in *_remove() and *_suspend_noirq(). I think you should do the same unless there's some reason you can't.
Can you give this a try, starting with this v12 posting?
Bjorn
Hongxing Zhu
maintainerRE: [PATCH v12 09/13] PCI: imx6: Turn off regulator when system is in suspend mode
Quoted 171 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 23:56
To: Hongxing Zhu <[email protected]>
Cc: Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: Re: [PATCH v12 09/13] PCI: imx6: Turn off regulator when system is in suspend modeQuoted 23 lines · Hongxing Zhu
Quoted 23 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 7:31
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: Re: [PATCH v12 09/13] PCI: imx6: Turn off regulator when system is in suspend modeQuoted 8 lines · Bjorn Helgaas
From: Richard Zhu <[email protected]>
The driver should undo any enables it did itself. The regulator disable shouldn't be basing decisions on
regulator_is_enabled().Move the
regulator_disableto the suspend function, turn off regulator when the system is in suspend mode.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
To keep the balance of the regulator usage counter, disable the regulator in shutdown.
Link:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2F
lore .kernel.org%2Fr%2F1655189942-12678-6-git-send-email-hongxing.z&
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
;d
at
Quoted 1 line
a=05%7C01%7Chongxing.zhu%40nxp.com%7C8dea46d908d34cb4825808da4
Quoted 3 lines
Quoted 3 lines
f270eaf%
Quoted 1 line
7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6379093264156415
Quoted 3 lines
Quoted 3 lines
35%7CUnkn
Quoted 1 line
own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1
Quoted 3 lines
Quoted 3 lines
haWwi
Quoted 1 line
LCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=tqzlcCmtSkUNxNzJ0Fr5o
Quoted 28 lines
Quoted 28 lines
CR3X2CTH
Quoted 25 lines
4dwUJS4NXt5KRc%3D&reserved=0
[email protected]Signed-off-by Richard Zhu <[email protected]>Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/pci/controller/dwc/pci-imx6.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +0
-0@@ -670,8 +670,6 @@ static void imx6_pcie_clk_disable(struct
imx6_pcie*imx6_pcie)static void imx6_pcie_assert_core_reset(struct
imx6_pcie*imx6_pcie) {drivers/pci/controller/dwc/pci-imx6.c +0
-2-struct device *dev = imx6_pcie->pci->dev; -switch (imx6_pcie->drvdata->variant) {case IMX7D :case IMX8MQ :@@ -702,14 +700,6 @@ static voidQuoted 1 line
imx6_pcie_assert_core_reset(struct
imx6_pcie*imx6_pcie)Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/dwc/pci-imx6.c
Quoted 4 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-1break ; } -if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ){
Quoted 22 lines
Quoted 22 lines
Quoted 11 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-7-int ret =regulator_disable (imx6_pcie->vpcie); - -if (ret) -dev_err (dev,"failed to disable vpcie regulator: %d\n" , - ret); - } -/* Some boards don't have PCIe reset GPIO. */ if (gpio_is_valid (imx6_pcie->reset_gpio)) gpio_set_value_cansleep(imx6_pcie->reset_gpio,@@ -722,7 +712,7 @@ static intQuoted 1 line
imx6_pcie_deassert_core_reset(struct
imx6_pcie*imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
Quoted 8 lines
drivers/pci/controller/dwc/pci-imx6.c +1
-1struct 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", @@-796,7
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
+786,7 @@ static int imx6_pcie_deassert_core_reset(struct +imx6_pcie
*imx6_pcie)drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
Quoted 4 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-1return 0 ; err_clks: -if (imx6_pcie->vpcie &®ulator_is_enabled (imx6_pcie->vpcie) >0 ){
Quoted 9 lines
Quoted 9 lines
drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
Quoted 4 lines
drivers/pci/controller/dwc/pci-imx6.c +1
-0+if (imx6_pcie->vpcie) { ret =regulator_disable (imx6_pcie->vpcie);if (ret) dev_err(dev, "failed to disable vpcie regulator: %d\n", @@-1023,6
Quoted 4 lines
+1013,9 @@ static int
imx6_pcie_suspend_noirq(struct device *dev)drivers/pci/controller/dwc/pci-imx6.c +0
-0break ; }Quoted 8 lines
Quoted 8 lines
drivers/pci/controller/dwc/pci-imx6.c
Quoted 2 lines
drivers/pci/controller/dwc/pci-imx6.c +2
-0+if (imx6_pcie->vpcie) +regulator_disable (imx6_pcie->vpcie);This is a little bit ugly because
imx6_pcie_suspend_noirq()andimx6_pcie_resume_noirq()are not symmetric.We call
regulator_disable()directly here inimx6_pcie_suspend_noirq(), but the correspondingregulator_enable()isburied in
imx6_pcie_deassert_core_reset().Quoted 8 lines
Quoted 5 lines
It would be nicer if the suspend and resume paths looked more similar, as
rockchip_pcie_suspend_noirq()androckchip_pcie_resume_noirq()do, for example.Yes, it is. The regulator_disable()/regulator_enable() are not invoked symmetrically.
Quoted 8 lines
In the original codes, the
regulator_disable()is contained inimx6_pcie_assert_core_reset()and with_eanbled()check. Andregulator_enable()is embedded inimx6_pcie_deassert_core_reset(). Both the regulator disable and enable are invoked in resume before. I move theregulator_disableto suspend mode refer to Lucas' comments.Refer to the current situation, how about to move the
regulator_disable()out ofimx6_pcie_deassert_core_reset()too?I think it's important to tweak this closer to the pattern of other drivers like exynos and rockchip.
exynos_pcie_resume_noirq()callsexynos_pcie_host_init().imx6_pcie_resume_noirq()is VERY similar toimx6_pcie_host_init(), and I think it should callimx6_pcie_host_init()instead of duplicating that code. The only real difference is thatimx6_pcie_host_init()callsimx6_setup_phy_mpll()whileimx6_pcie_resume_noirq()does not.
I suspect that's a bug.
Quoted 7 lines
I don't think "
regulator_enable(imx6_pcie->vpcie)" really has anything to do withimx6_pcie_deassert_core_reset()and it should be moved out. The typical pattern is to enable regulators in*_probe()and*_resume_noirq()and disable them in*_remove()and*_suspend_noirq(). I think you should do the same unless there's some reason you can't.Can you give this a try, starting with this v12 posting?
Thanks a lot for your inspiration.
Exactly, these codes are almost same. The host_init can be invoked directly
in resume. I would re-change the #12/13 of v12, and send the v13 later.
Best Regards
Richard Zhu
Quoted 2 lines
Bjorn
PATCH v12 10/13 PCI: imx6: Mark the link down as non-fatal error
In reply to Bjorn HelgaasFrom: Richard Zhu <[email protected]>
Let the driver probe successfully, return zero in imx6_pcie_start_link() when PCIe link is down.
--- drivers/pci/controller/dwc/pci-imx6.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +7 -3
@@ -855,7 +855,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. */
@@ -891,7 +893,9 @@ 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" ); }
@@ -905,7 +909,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)
Signature · 1 line
2.25.1
PATCH v12 11/13 PCI: imx6: Reduce resume time by only starting link if it was up before suspend
In reply to Bjorn HelgaasFrom: Richard Zhu <[email protected]>
Because i.MX PCIe doesn't support hot-plug feature. In the 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.
--- drivers/pci/controller/dwc/pci-imx6.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +4 -5
@@ -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;
@@ -900,6 +901,7 @@ static int imx6_pcie_start_link(struct dw_pcie *pci)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 ;
@@ -1025,7 +1027,6 @@ static int imx6_pcie_suspend_noirq(struct device *dev)static int imx6_pcie_resume_noirq (struct device *dev) { -int ret;struct imx6_pcie *imx6_pcie =dev_get_drvdata (dev);struct pcie_port *pp = &imx6_pcie->pci->pp;
@@ -1036,10 +1037,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 ; }
Signature · 1 line
2.25.1
PATCH v12 12/13 PCI: imx6: Do not hide phy driver callbacks and refine the error handling
In reply to Bjorn HelgaasFrom: Richard Zhu <[email protected]>
- 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.
--- drivers/pci/controller/dwc/pci-imx6.c | 70 +++++++++++++++++++++------ 1 file changed, 56 insertions(+), 14 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +56 -14
@@ -639,14 +639,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 ;
@@ -733,10 +725,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);
@@ -772,6 +760,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 ; }
@@ -923,15 +912,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 = {
@@ -1029,18 +1042,47 @@ static int imx6_pcie_resume_noirq(struct device *dev) {struct imx6_pcie *imx6_pcie =dev_get_drvdata (dev);struct pcie_port *pp = &imx6_pcie->pci->pp; +int ret;if (!(imx6_pcie->drvdata->flags &IMX6_PCIE_FLAG_SUPPORTS_SUSPEND ))return 0 ;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
Signature · 1 line
2.25.1
PATCH v12 13/13 PCI: imx6: Disable clocks in reverse order of enable
In reply to Bjorn HelgaasFrom: Bjorn Helgaas <[email protected]>
imx6_pcie_clk_enable() enables clocks in the order:
pcie_phy
pcie_bus
pcie
imx6_pcie_enable_ref_clk
Change imx6_pcie_clk_disable() to disable them in the reverse order.
--- drivers/pci/controller/dwc/pci-imx6.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pci-imx6.c +3 -3
@@ -655,10 +655,10 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie)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);imx6_pcie_disable_ref_clk (imx6_pcie); +clk_disable_unprepare (imx6_pcie->pcie); +clk_disable_unprepare (imx6_pcie->pcie_bus); +clk_disable_unprepare (imx6_pcie->pcie_phy); }static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie)
Signature · 1 line
2.25.1
Re: [PATCH v12 13/13] PCI: imx6: Disable clocks in reverse order of enable
Quoted 21 lines · Bjorn Helgaas
From: Bjorn Helgaas <[email protected]>
imx6_pcie_clk_enable()enables clocks in the order:
pcie_phy
pcie_bus
pcie
imx6_pcie_enable_ref_clkChange
imx6_pcie_clk_disable()to disable them in the reverse order.Signed-off-by Bjorn Helgaas <[email protected]>--- drivers/pci/controller/dwc/pci-imx6.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +0
-0
drivers/pci/controller/dwc/pci-imx6.c static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie) · line 661
Quoted 10 lines
drivers/pci/controller/dwc/pci-imx6.c +3
-3@@ -655,10 +655,10 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie)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);imx6_pcie_disable_ref_clk (imx6_pcie); +clk_disable_unprepare (imx6_pcie->pcie); +clk_disable_unprepare (imx6_pcie->pcie_bus); +clk_disable_unprepare (imx6_pcie->pcie_phy);
Please comment on this. I have no actual information that this is the right thing, but normally we disable things in the reverse order that we enabled them.
And the error path of imx6_pcie_deassert_core_reset() definitely disables pcie, pcie_bus, pcie_phy in that order, so it seems reasonable to do the same here.
Quoted 11 lines
drivers/pci/controller/dwc/pci-imx6.c +0
-0}static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie)Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RE: [PATCH v12 13/13] PCI: imx6: Disable clocks in reverse order of enable
In reply to Bjorn HelgaasQuoted 17 lines
-----Original Message-----
From: Bjorn Helgaas <[email protected]>
Sent: 2022年6月16日 7:16
To: Hongxing Zhu <[email protected]>; Lucas Stach <[email protected]>; Rob Herring <[email protected]>; Mark Brown <[email protected]>; Lorenzo Pieralisi <[email protected]>; Fabio Estevam <[email protected]>; Francesco Dolcini <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Bjorn Helgaas <[email protected]>
Subject: [PATCH v12 13/13] PCI: imx6: Disable clocks in reverse order of enableFrom: Bjorn Helgaas <[email protected]>
imx6_pcie_clk_enable()enables clocks in the order:
Quoted 8 lines
pcie_phy
pcie_bus
pcie
imx6_pcie_enable_ref_clkChange
imx6_pcie_clk_disable()to disable them in the reverse order.Signed-off-by Bjorn Helgaas <[email protected]>
Best Regards
Richard Zhu
Quoted 25 lines
--- drivers/pci/controller/dwc/pci-imx6.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/pci/controller/dwc/pci-imx6.c +3
-4@@ -655,10 +655,10 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie)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);imx6_pcie_disable_ref_clk (imx6_pcie); +clk_disable_unprepare (imx6_pcie->pcie); +clk_disable_unprepare (imx6_pcie->pcie_bus); +clk_disable_unprepare (imx6_pcie->pcie_phy); }static void imx6_pcie_assert_core_reset (struct imx6_pcie *imx6_pcie) --2.25.1