MLK-16074 PCI: imx: correct some bits configiration of hsio
authorRichard Zhu <hongxing.zhu@nxp.com>
Mon, 14 Jan 2019 08:48:05 +0000 (14:18 +0530)
committerLeonard Crestez <leonard.crestez@nxp.com>
Wed, 17 Apr 2019 23:51:34 +0000 (02:51 +0300)
- Both APB_RST_0 and APB_RST_1 should be asserted, when PHYX2
is used.
Otherwise, PHYX2 can't finish calibration.
- Correct the PCIEB(PHYX2_1) TX PLL locked check.
- The clear check of the reset should be done after
clks are enabled

Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
rebase on v4.19
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
drivers/pci/controller/dwc/pci-imx6.c

index 780f7db..5ae87f3 100644 (file)
@@ -550,8 +550,10 @@ static int imx8_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie)
                        regmap_read(imx6_pcie->iomuxc_gpr,
                                        IMX8QM_CSR_PHYX2_OFFSET + 0x4,
                                        &tmp);
-                       orig = IMX8QM_STTS0_LANE0_TX_PLL_LOCK;
-                       orig |= IMX8QM_STTS0_LANE1_TX_PLL_LOCK;
+                       if (imx6_pcie->ctrl_id == 0) /* pciea 1 lanes */
+                               orig = IMX8QM_STTS0_LANE0_TX_PLL_LOCK;
+                       else /* pcieb 1 lanes */
+                               orig = IMX8QM_STTS0_LANE1_TX_PLL_LOCK;
                        tmp &= orig;
                        if (tmp == orig) {
                                regmap_update_bits(imx6_pcie->iomuxc_gpr,
@@ -612,8 +614,8 @@ 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;
-       u32 val;
+       int ret, i;
+       u32 val, tmp;
 
        if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) {
                ret = regulator_enable(imx6_pcie->vpcie);
@@ -735,6 +737,21 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
                        ret = -ENODEV;
                break;
        case IMX8QM:
+               /* bit19 PM_REQ_CORE_RST of pciex#_stts0 should be cleared. */
+               for (i = 0; i < 100; i++) {
+                       val = IMX8QM_CSR_PCIEA_OFFSET
+                               + imx6_pcie->ctrl_id * SZ_64K;
+                       regmap_read(imx6_pcie->iomuxc_gpr,
+                                       val + IMX8QM_CSR_PCIE_STTS0_OFFSET,
+                                       &tmp);
+                       if ((tmp & IMX8QM_CTRL_STTS0_PM_REQ_CORE_RST) == 0)
+                               break;
+                       udelay(10);
+               }
+
+               if ((tmp & IMX8QM_CTRL_STTS0_PM_REQ_CORE_RST) != 0)
+                       pr_err("ERROR PM_REQ_CORE_RST is still set.\n");
+
                /* wait for phy pll lock firstly. */
                if (imx8_pcie_wait_for_phy_pll_lock(imx6_pcie))
                        ret = -ENODEV;
@@ -883,7 +900,7 @@ static void imx6_pcie_phy_pwr_dn(struct imx6_pcie *imx6_pcie)
 static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
 {
        u32 tmp, val;
-       int i, ret;
+       int ret;
 
        if (imx6_pcie->variant == IMX8QM) {
                switch (imx6_pcie->hsio_cfg) {
@@ -910,10 +927,8 @@ static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
                        break;
 
                case PCIEAX1PCIEBX1SATA:
-                       if (imx6_pcie->ctrl_id)
-                               tmp = IMX8QM_PHY_APB_RSTN_1;
-                       else
-                               tmp = IMX8QM_PHY_APB_RSTN_0;
+                       tmp = IMX8QM_PHY_APB_RSTN_1;
+                       tmp |= IMX8QM_PHY_APB_RSTN_0;
                        regmap_update_bits(imx6_pcie->iomuxc_gpr,
                                IMX8QM_CSR_PHYX2_OFFSET,
                                IMX8QM_PHYX2_CTRL0_APB_MASK, tmp);
@@ -984,19 +999,6 @@ static void imx6_pcie_init_phy(struct imx6_pcie *imx6_pcie)
                                | IMX8QM_CSR_MISC_IOB_A_0_M1M0_2);
                }
 
-               /* bit19 PM_REQ_CORE_RST of pciex2_stts0 should be cleared. */
-               for (i = 0; i < 100; i++) {
-                       val = IMX8QM_CSR_PCIEA_OFFSET
-                               + imx6_pcie->ctrl_id * SZ_64K;
-                       regmap_read(imx6_pcie->iomuxc_gpr,
-                                       val + IMX8QM_CSR_PCIE_STTS0_OFFSET,
-                                       &tmp);
-                       if ((tmp & IMX8QM_CTRL_STTS0_PM_REQ_CORE_RST) == 0)
-                               break;
-                       udelay(10);
-               }
-               if ((tmp & IMX8QM_CTRL_STTS0_PM_REQ_CORE_RST) != 0)
-                       pr_err("ERROR PM_REQ_CORE_RST is still set.\n");
        } else if (imx6_pcie->variant == IMX8MQ) {
                imx6_pcie_phy_pwr_up(imx6_pcie);