]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/pci/host/pcie-rockchip.c
PCI: rockchip: Use normal register bank for config accessors
[karo-tx-linux.git] / drivers / pci / host / pcie-rockchip.c
index c283633181d346f602efb827ea1a0b7845dab825..5acf8694fb23bc41d6000c27ae43c425fe478f8a 100644 (file)
                 PCIE_CORE_INT_CT | PCIE_CORE_INT_UTC | \
                 PCIE_CORE_INT_MMVC)
 
+#define PCIE_RC_CONFIG_NORMAL_BASE     0x800000
 #define PCIE_RC_CONFIG_BASE            0xa00000
 #define PCIE_RC_CONFIG_RID_CCR         (PCIE_RC_CONFIG_BASE + 0x08)
 #define   PCIE_RC_CONFIG_SCC_SHIFT             16
 #define   PCIE_RC_CONFIG_DCR_CSPL_SHIFT                18
 #define   PCIE_RC_CONFIG_DCR_CSPL_LIMIT                0xff
 #define   PCIE_RC_CONFIG_DCR_CPLS_SHIFT                26
+#define PCIE_RC_CONFIG_DCSR            (PCIE_RC_CONFIG_BASE + 0xc8)
+#define   PCIE_RC_CONFIG_DCSR_MPS_MASK         GENMASK(7, 5)
+#define   PCIE_RC_CONFIG_DCSR_MPS_256          (0x1 << 5)
 #define PCIE_RC_CONFIG_LINK_CAP                (PCIE_RC_CONFIG_BASE + 0xcc)
 #define   PCIE_RC_CONFIG_LINK_CAP_L0S          BIT(10)
 #define PCIE_RC_CONFIG_LCS             (PCIE_RC_CONFIG_BASE + 0xd0)
@@ -298,7 +302,9 @@ static int rockchip_pcie_valid_device(struct rockchip_pcie *rockchip,
 static int rockchip_pcie_rd_own_conf(struct rockchip_pcie *rockchip,
                                     int where, int size, u32 *val)
 {
-       void __iomem *addr = rockchip->apb_base + PCIE_RC_CONFIG_BASE + where;
+       void __iomem *addr;
+
+       addr = rockchip->apb_base + PCIE_RC_CONFIG_NORMAL_BASE + where;
 
        if (!IS_ALIGNED((uintptr_t)addr, size)) {
                *val = 0;
@@ -322,11 +328,13 @@ static int rockchip_pcie_wr_own_conf(struct rockchip_pcie *rockchip,
                                     int where, int size, u32 val)
 {
        u32 mask, tmp, offset;
+       void __iomem *addr;
 
        offset = where & ~0x3;
+       addr = rockchip->apb_base + PCIE_RC_CONFIG_NORMAL_BASE + offset;
 
        if (size == 4) {
-               writel(val, rockchip->apb_base + PCIE_RC_CONFIG_BASE + offset);
+               writel(val, addr);
                return PCIBIOS_SUCCESSFUL;
        }
 
@@ -337,9 +345,9 @@ static int rockchip_pcie_wr_own_conf(struct rockchip_pcie *rockchip,
         * corrupt RW1C bits in adjacent registers.  But the hardware
         * doesn't support smaller writes.
         */
-       tmp = readl(rockchip->apb_base + PCIE_RC_CONFIG_BASE + offset) & mask;
+       tmp = readl(addr) & mask;
        tmp |= val << ((where & 0x3) * 8);
-       writel(tmp, rockchip->apb_base + PCIE_RC_CONFIG_BASE + offset);
+       writel(tmp, addr);
 
        return PCIBIOS_SUCCESSFUL;
 }
@@ -701,6 +709,11 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
                rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_LINK_CAP);
        }
 
+       status = rockchip_pcie_read(rockchip, PCIE_RC_CONFIG_DCSR);
+       status &= ~PCIE_RC_CONFIG_DCSR_MPS_MASK;
+       status |= PCIE_RC_CONFIG_DCSR_MPS_256;
+       rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_DCSR);
+
        return 0;
 }
 
@@ -1300,24 +1313,46 @@ static int __maybe_unused rockchip_pcie_resume_noirq(struct device *dev)
                }
        }
 
-       clk_prepare_enable(rockchip->clk_pcie_pm);
-       clk_prepare_enable(rockchip->hclk_pcie);
-       clk_prepare_enable(rockchip->aclk_perf_pcie);
-       clk_prepare_enable(rockchip->aclk_pcie);
+       err = clk_prepare_enable(rockchip->clk_pcie_pm);
+       if (err)
+               goto err_pcie_pm;
+
+       err = clk_prepare_enable(rockchip->hclk_pcie);
+       if (err)
+               goto err_hclk_pcie;
+
+       err = clk_prepare_enable(rockchip->aclk_perf_pcie);
+       if (err)
+               goto err_aclk_perf_pcie;
+
+       err = clk_prepare_enable(rockchip->aclk_pcie);
+       if (err)
+               goto err_aclk_pcie;
 
        err = rockchip_pcie_init_port(rockchip);
        if (err)
-               return err;
+               goto err_pcie_resume;
 
        err = rockchip_pcie_cfg_atu(rockchip);
        if (err)
-               return err;
+               goto err_pcie_resume;
 
        /* Need this to enter L1 again */
        rockchip_pcie_update_txcredit_mui(rockchip);
        rockchip_pcie_enable_interrupts(rockchip);
 
        return 0;
+
+err_pcie_resume:
+       clk_disable_unprepare(rockchip->aclk_pcie);
+err_aclk_pcie:
+       clk_disable_unprepare(rockchip->aclk_perf_pcie);
+err_aclk_perf_pcie:
+       clk_disable_unprepare(rockchip->hclk_pcie);
+err_hclk_pcie:
+       clk_disable_unprepare(rockchip->clk_pcie_pm);
+err_pcie_pm:
+       return err;
 }
 
 static int rockchip_pcie_probe(struct platform_device *pdev)
@@ -1433,15 +1468,14 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
        if (err)
                goto err_free_res;
 
-       rockchip->msg_region = devm_ioremap(rockchip->dev,
-                                           rockchip->msg_bus_addr, SZ_1M);
+       rockchip->msg_region = devm_ioremap(dev, rockchip->msg_bus_addr, SZ_1M);
        if (!rockchip->msg_region) {
                err = -ENOMEM;
                goto err_free_res;
        }
 
        list_splice_init(&res, &bridge->windows);
-       bridge->dev.parent = &pdev->dev;
+       bridge->dev.parent = dev;
        bridge->sysdata = rockchip;
        bridge->busnr = 0;
        bridge->ops = &rockchip_pcie_ops;