Merge tag 'mmc-v4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc
[cascardo/linux.git] / drivers / pci / host / pci-exynos.c
index 2e2d7f0..f1c544b 100644 (file)
 #define to_exynos_pcie(x)      container_of(x, struct exynos_pcie, pp)
 
 struct exynos_pcie {
-       void __iomem            *elbi_base;
-       void __iomem            *phy_base;
-       void __iomem            *block_base;
+       struct pcie_port        pp;
+       void __iomem            *elbi_base;     /* DT 0th resource */
+       void __iomem            *phy_base;      /* DT 1st resource */
+       void __iomem            *block_base;    /* DT 2nd resource */
        int                     reset_gpio;
        struct clk              *clk;
        struct clk              *bus_clk;
-       struct pcie_port        pp;
 };
 
 /* PCIe ELBI registers */
@@ -102,40 +102,40 @@ struct exynos_pcie {
 #define PCIE_PHY_TRSV3_PD_TSV          (0x1 << 7)
 #define PCIE_PHY_TRSV3_LVCC            0x31c
 
-static inline void exynos_elb_writel(struct exynos_pcie *pcie, u32 val, u32 reg)
+static void exynos_elb_writel(struct exynos_pcie *exynos_pcie, u32 val, u32 reg)
 {
-       writel(val, pcie->elbi_base + reg);
+       writel(val, exynos_pcie->elbi_base + reg);
 }
 
-static inline u32 exynos_elb_readl(struct exynos_pcie *pcie, u32 reg)
+static u32 exynos_elb_readl(struct exynos_pcie *exynos_pcie, u32 reg)
 {
-       return readl(pcie->elbi_base + reg);
+       return readl(exynos_pcie->elbi_base + reg);
 }
 
-static inline void exynos_phy_writel(struct exynos_pcie *pcie, u32 val, u32 reg)
+static void exynos_phy_writel(struct exynos_pcie *exynos_pcie, u32 val, u32 reg)
 {
-       writel(val, pcie->phy_base + reg);
+       writel(val, exynos_pcie->phy_base + reg);
 }
 
-static inline u32 exynos_phy_readl(struct exynos_pcie *pcie, u32 reg)
+static u32 exynos_phy_readl(struct exynos_pcie *exynos_pcie, u32 reg)
 {
-       return readl(pcie->phy_base + reg);
+       return readl(exynos_pcie->phy_base + reg);
 }
 
-static inline void exynos_blk_writel(struct exynos_pcie *pcie, u32 val, u32 reg)
+static void exynos_blk_writel(struct exynos_pcie *exynos_pcie, u32 val, u32 reg)
 {
-       writel(val, pcie->block_base + reg);
+       writel(val, exynos_pcie->block_base + reg);
 }
 
-static inline u32 exynos_blk_readl(struct exynos_pcie *pcie, u32 reg)
+static u32 exynos_blk_readl(struct exynos_pcie *exynos_pcie, u32 reg)
 {
-       return readl(pcie->block_base + reg);
+       return readl(exynos_pcie->block_base + reg);
 }
 
-static void exynos_pcie_sideband_dbi_w_mode(struct pcie_port *pp, bool on)
+static void exynos_pcie_sideband_dbi_w_mode(struct exynos_pcie *exynos_pcie,
+                                           bool on)
 {
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        if (on) {
                val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_SLV_AWMISC);
@@ -148,10 +148,10 @@ static void exynos_pcie_sideband_dbi_w_mode(struct pcie_port *pp, bool on)
        }
 }
 
-static void exynos_pcie_sideband_dbi_r_mode(struct pcie_port *pp, bool on)
+static void exynos_pcie_sideband_dbi_r_mode(struct exynos_pcie *exynos_pcie,
+                                           bool on)
 {
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        if (on) {
                val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_SLV_ARMISC);
@@ -164,10 +164,9 @@ static void exynos_pcie_sideband_dbi_r_mode(struct pcie_port *pp, bool on)
        }
 }
 
-static void exynos_pcie_assert_core_reset(struct pcie_port *pp)
+static void exynos_pcie_assert_core_reset(struct exynos_pcie *exynos_pcie)
 {
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        val = exynos_elb_readl(exynos_pcie, PCIE_CORE_RESET);
        val &= ~PCIE_CORE_RESET_ENABLE;
@@ -177,10 +176,9 @@ static void exynos_pcie_assert_core_reset(struct pcie_port *pp)
        exynos_elb_writel(exynos_pcie, 0, PCIE_NONSTICKY_RESET);
 }
 
-static void exynos_pcie_deassert_core_reset(struct pcie_port *pp)
+static void exynos_pcie_deassert_core_reset(struct exynos_pcie *exynos_pcie)
 {
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        val = exynos_elb_readl(exynos_pcie, PCIE_CORE_RESET);
        val |= PCIE_CORE_RESET_ENABLE;
@@ -193,18 +191,14 @@ static void exynos_pcie_deassert_core_reset(struct pcie_port *pp)
        exynos_blk_writel(exynos_pcie, 1, PCIE_PHY_MAC_RESET);
 }
 
-static void exynos_pcie_assert_phy_reset(struct pcie_port *pp)
+static void exynos_pcie_assert_phy_reset(struct exynos_pcie *exynos_pcie)
 {
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
-
        exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_MAC_RESET);
        exynos_blk_writel(exynos_pcie, 1, PCIE_PHY_GLOBAL_RESET);
 }
 
-static void exynos_pcie_deassert_phy_reset(struct pcie_port *pp)
+static void exynos_pcie_deassert_phy_reset(struct exynos_pcie *exynos_pcie)
 {
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
-
        exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_GLOBAL_RESET);
        exynos_elb_writel(exynos_pcie, 1, PCIE_PWR_RESET);
        exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_COMMON_RESET);
@@ -213,10 +207,9 @@ static void exynos_pcie_deassert_phy_reset(struct pcie_port *pp)
        exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_TRSV_RESET);
 }
 
-static void exynos_pcie_power_on_phy(struct pcie_port *pp)
+static void exynos_pcie_power_on_phy(struct exynos_pcie *exynos_pcie)
 {
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        val = exynos_phy_readl(exynos_pcie, PCIE_PHY_COMMON_POWER);
        val &= ~PCIE_PHY_COMMON_PD_CMN;
@@ -239,10 +232,9 @@ static void exynos_pcie_power_on_phy(struct pcie_port *pp)
        exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV3_POWER);
 }
 
-static void exynos_pcie_power_off_phy(struct pcie_port *pp)
+static void exynos_pcie_power_off_phy(struct exynos_pcie *exynos_pcie)
 {
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        val = exynos_phy_readl(exynos_pcie, PCIE_PHY_COMMON_POWER);
        val |= PCIE_PHY_COMMON_PD_CMN;
@@ -265,10 +257,8 @@ static void exynos_pcie_power_off_phy(struct pcie_port *pp)
        exynos_phy_writel(exynos_pcie, val, PCIE_PHY_TRSV3_POWER);
 }
 
-static void exynos_pcie_init_phy(struct pcie_port *pp)
+static void exynos_pcie_init_phy(struct exynos_pcie *exynos_pcie)
 {
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
-
        /* DCC feedback control off */
        exynos_phy_writel(exynos_pcie, 0x29, PCIE_PHY_DCC_FEEDBACK);
 
@@ -305,51 +295,41 @@ static void exynos_pcie_init_phy(struct pcie_port *pp)
        exynos_phy_writel(exynos_pcie, 0xa0, PCIE_PHY_TRSV3_LVCC);
 }
 
-static void exynos_pcie_assert_reset(struct pcie_port *pp)
+static void exynos_pcie_assert_reset(struct exynos_pcie *exynos_pcie)
 {
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
+       struct pcie_port *pp = &exynos_pcie->pp;
+       struct device *dev = pp->dev;
 
        if (exynos_pcie->reset_gpio >= 0)
-               devm_gpio_request_one(pp->dev, exynos_pcie->reset_gpio,
+               devm_gpio_request_one(dev, exynos_pcie->reset_gpio,
                                GPIOF_OUT_INIT_HIGH, "RESET");
 }
 
-static int exynos_pcie_establish_link(struct pcie_port *pp)
+static int exynos_pcie_establish_link(struct exynos_pcie *exynos_pcie)
 {
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
+       struct pcie_port *pp = &exynos_pcie->pp;
+       struct device *dev = pp->dev;
        u32 val;
 
        if (dw_pcie_link_up(pp)) {
-               dev_err(pp->dev, "Link already up\n");
+               dev_err(dev, "Link already up\n");
                return 0;
        }
 
-       /* assert reset signals */
-       exynos_pcie_assert_core_reset(pp);
-       exynos_pcie_assert_phy_reset(pp);
-
-       /* de-assert phy reset */
-       exynos_pcie_deassert_phy_reset(pp);
-
-       /* power on phy */
-       exynos_pcie_power_on_phy(pp);
-
-       /* initialize phy */
-       exynos_pcie_init_phy(pp);
+       exynos_pcie_assert_core_reset(exynos_pcie);
+       exynos_pcie_assert_phy_reset(exynos_pcie);
+       exynos_pcie_deassert_phy_reset(exynos_pcie);
+       exynos_pcie_power_on_phy(exynos_pcie);
+       exynos_pcie_init_phy(exynos_pcie);
 
        /* pulse for common reset */
        exynos_blk_writel(exynos_pcie, 1, PCIE_PHY_COMMON_RESET);
        udelay(500);
        exynos_blk_writel(exynos_pcie, 0, PCIE_PHY_COMMON_RESET);
 
-       /* de-assert core reset */
-       exynos_pcie_deassert_core_reset(pp);
-
-       /* setup root complex */
+       exynos_pcie_deassert_core_reset(exynos_pcie);
        dw_pcie_setup_rc(pp);
-
-       /* assert reset signal */
-       exynos_pcie_assert_reset(pp);
+       exynos_pcie_assert_reset(exynos_pcie);
 
        /* assert LTSSM enable */
        exynos_elb_writel(exynos_pcie, PCIE_ELBI_LTSSM_ENABLE,
@@ -361,27 +341,23 @@ static int exynos_pcie_establish_link(struct pcie_port *pp)
 
        while (exynos_phy_readl(exynos_pcie, PCIE_PHY_PLL_LOCKED) == 0) {
                val = exynos_blk_readl(exynos_pcie, PCIE_PHY_PLL_LOCKED);
-               dev_info(pp->dev, "PLL Locked: 0x%x\n", val);
+               dev_info(dev, "PLL Locked: 0x%x\n", val);
        }
-       /* power off phy */
-       exynos_pcie_power_off_phy(pp);
-
+       exynos_pcie_power_off_phy(exynos_pcie);
        return -ETIMEDOUT;
 }
 
-static void exynos_pcie_clear_irq_pulse(struct pcie_port *pp)
+static void exynos_pcie_clear_irq_pulse(struct exynos_pcie *exynos_pcie)
 {
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        val = exynos_elb_readl(exynos_pcie, PCIE_IRQ_PULSE);
        exynos_elb_writel(exynos_pcie, val, PCIE_IRQ_PULSE);
 }
 
-static void exynos_pcie_enable_irq_pulse(struct pcie_port *pp)
+static void exynos_pcie_enable_irq_pulse(struct exynos_pcie *exynos_pcie)
 {
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        /* enable INTX interrupt */
        val = IRQ_INTA_ASSERT | IRQ_INTB_ASSERT |
@@ -391,23 +367,24 @@ static void exynos_pcie_enable_irq_pulse(struct pcie_port *pp)
 
 static irqreturn_t exynos_pcie_irq_handler(int irq, void *arg)
 {
-       struct pcie_port *pp = arg;
+       struct exynos_pcie *exynos_pcie = arg;
 
-       exynos_pcie_clear_irq_pulse(pp);
+       exynos_pcie_clear_irq_pulse(exynos_pcie);
        return IRQ_HANDLED;
 }
 
 static irqreturn_t exynos_pcie_msi_irq_handler(int irq, void *arg)
 {
-       struct pcie_port *pp = arg;
+       struct exynos_pcie *exynos_pcie = arg;
+       struct pcie_port *pp = &exynos_pcie->pp;
 
        return dw_handle_msi_irq(pp);
 }
 
-static void exynos_pcie_msi_init(struct pcie_port *pp)
+static void exynos_pcie_msi_init(struct exynos_pcie *exynos_pcie)
 {
+       struct pcie_port *pp = &exynos_pcie->pp;
        u32 val;
-       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
 
        dw_pcie_msi_init(pp);
 
@@ -417,60 +394,64 @@ static void exynos_pcie_msi_init(struct pcie_port *pp)
        exynos_elb_writel(exynos_pcie, val, PCIE_IRQ_EN_LEVEL);
 }
 
-static void exynos_pcie_enable_interrupts(struct pcie_port *pp)
+static void exynos_pcie_enable_interrupts(struct exynos_pcie *exynos_pcie)
 {
-       exynos_pcie_enable_irq_pulse(pp);
+       exynos_pcie_enable_irq_pulse(exynos_pcie);
 
        if (IS_ENABLED(CONFIG_PCI_MSI))
-               exynos_pcie_msi_init(pp);
+               exynos_pcie_msi_init(exynos_pcie);
 }
 
-static inline u32 exynos_pcie_readl_rc(struct pcie_port *pp,
-                                      void __iomem *dbi_base)
+static u32 exynos_pcie_readl_rc(struct pcie_port *pp, u32 reg)
 {
+       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
        u32 val;
 
-       exynos_pcie_sideband_dbi_r_mode(pp, true);
-       val = readl(dbi_base);
-       exynos_pcie_sideband_dbi_r_mode(pp, false);
+       exynos_pcie_sideband_dbi_r_mode(exynos_pcie, true);
+       val = readl(pp->dbi_base + reg);
+       exynos_pcie_sideband_dbi_r_mode(exynos_pcie, false);
        return val;
 }
 
-static inline void exynos_pcie_writel_rc(struct pcie_port *pp,
-                                       u32 val, void __iomem *dbi_base)
+static void exynos_pcie_writel_rc(struct pcie_port *pp, u32 reg, u32 val)
 {
-       exynos_pcie_sideband_dbi_w_mode(pp, true);
-       writel(val, dbi_base);
-       exynos_pcie_sideband_dbi_w_mode(pp, false);
+       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
+
+       exynos_pcie_sideband_dbi_w_mode(exynos_pcie, true);
+       writel(val, pp->dbi_base + reg);
+       exynos_pcie_sideband_dbi_w_mode(exynos_pcie, false);
 }
 
 static int exynos_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
                                u32 *val)
 {
+       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
        int ret;
 
-       exynos_pcie_sideband_dbi_r_mode(pp, true);
+       exynos_pcie_sideband_dbi_r_mode(exynos_pcie, true);
        ret = dw_pcie_cfg_read(pp->dbi_base + where, size, val);
-       exynos_pcie_sideband_dbi_r_mode(pp, false);
+       exynos_pcie_sideband_dbi_r_mode(exynos_pcie, false);
        return ret;
 }
 
 static int exynos_pcie_wr_own_conf(struct pcie_port *pp, int where, int size,
                                u32 val)
 {
+       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
        int ret;
 
-       exynos_pcie_sideband_dbi_w_mode(pp, true);
+       exynos_pcie_sideband_dbi_w_mode(exynos_pcie, true);
        ret = dw_pcie_cfg_write(pp->dbi_base + where, size, val);
-       exynos_pcie_sideband_dbi_w_mode(pp, false);
+       exynos_pcie_sideband_dbi_w_mode(exynos_pcie, false);
        return ret;
 }
 
 static int exynos_pcie_link_up(struct pcie_port *pp)
 {
        struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
-       u32 val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_RDLH_LINKUP);
+       u32 val;
 
+       val = exynos_elb_readl(exynos_pcie, PCIE_ELBI_RDLH_LINKUP);
        if (val == PCIE_ELBI_LTSSM_ENABLE)
                return 1;
 
@@ -479,8 +460,10 @@ static int exynos_pcie_link_up(struct pcie_port *pp)
 
 static void exynos_pcie_host_init(struct pcie_port *pp)
 {
-       exynos_pcie_establish_link(pp);
-       exynos_pcie_enable_interrupts(pp);
+       struct exynos_pcie *exynos_pcie = to_exynos_pcie(pp);
+
+       exynos_pcie_establish_link(exynos_pcie);
+       exynos_pcie_enable_interrupts(exynos_pcie);
 }
 
 static struct pcie_host_ops exynos_pcie_host_ops = {
@@ -492,36 +475,38 @@ static struct pcie_host_ops exynos_pcie_host_ops = {
        .host_init = exynos_pcie_host_init,
 };
 
-static int __init exynos_add_pcie_port(struct pcie_port *pp,
+static int __init exynos_add_pcie_port(struct exynos_pcie *exynos_pcie,
                                       struct platform_device *pdev)
 {
+       struct pcie_port *pp = &exynos_pcie->pp;
+       struct device *dev = pp->dev;
        int ret;
 
        pp->irq = platform_get_irq(pdev, 1);
        if (!pp->irq) {
-               dev_err(&pdev->dev, "failed to get irq\n");
+               dev_err(dev, "failed to get irq\n");
                return -ENODEV;
        }
-       ret = devm_request_irq(&pdev->dev, pp->irq, exynos_pcie_irq_handler,
-                               IRQF_SHARED, "exynos-pcie", pp);
+       ret = devm_request_irq(dev, pp->irq, exynos_pcie_irq_handler,
+                               IRQF_SHARED, "exynos-pcie", exynos_pcie);
        if (ret) {
-               dev_err(&pdev->dev, "failed to request irq\n");
+               dev_err(dev, "failed to request irq\n");
                return ret;
        }
 
        if (IS_ENABLED(CONFIG_PCI_MSI)) {
                pp->msi_irq = platform_get_irq(pdev, 0);
                if (!pp->msi_irq) {
-                       dev_err(&pdev->dev, "failed to get msi irq\n");
+                       dev_err(dev, "failed to get msi irq\n");
                        return -ENODEV;
                }
 
-               ret = devm_request_irq(&pdev->dev, pp->msi_irq,
+               ret = devm_request_irq(dev, pp->msi_irq,
                                        exynos_pcie_msi_irq_handler,
                                        IRQF_SHARED | IRQF_NO_THREAD,
-                                       "exynos-pcie", pp);
+                                       "exynos-pcie", exynos_pcie);
                if (ret) {
-                       dev_err(&pdev->dev, "failed to request msi irq\n");
+                       dev_err(dev, "failed to request msi irq\n");
                        return ret;
                }
        }
@@ -531,7 +516,7 @@ static int __init exynos_add_pcie_port(struct pcie_port *pp,
 
        ret = dw_pcie_host_init(pp);
        if (ret) {
-               dev_err(&pdev->dev, "failed to initialize host\n");
+               dev_err(dev, "failed to initialize host\n");
                return ret;
        }
 
@@ -540,37 +525,36 @@ static int __init exynos_add_pcie_port(struct pcie_port *pp,
 
 static int __init exynos_pcie_probe(struct platform_device *pdev)
 {
+       struct device *dev = &pdev->dev;
        struct exynos_pcie *exynos_pcie;
        struct pcie_port *pp;
-       struct device_node *np = pdev->dev.of_node;
+       struct device_node *np = dev->of_node;
        struct resource *elbi_base;
        struct resource *phy_base;
        struct resource *block_base;
        int ret;
 
-       exynos_pcie = devm_kzalloc(&pdev->dev, sizeof(*exynos_pcie),
-                               GFP_KERNEL);
+       exynos_pcie = devm_kzalloc(dev, sizeof(*exynos_pcie), GFP_KERNEL);
        if (!exynos_pcie)
                return -ENOMEM;
 
        pp = &exynos_pcie->pp;
-
-       pp->dev = &pdev->dev;
+       pp->dev = dev;
 
        exynos_pcie->reset_gpio = of_get_named_gpio(np, "reset-gpio", 0);
 
-       exynos_pcie->clk = devm_clk_get(&pdev->dev, "pcie");
+       exynos_pcie->clk = devm_clk_get(dev, "pcie");
        if (IS_ERR(exynos_pcie->clk)) {
-               dev_err(&pdev->dev, "Failed to get pcie rc clock\n");
+               dev_err(dev, "Failed to get pcie rc clock\n");
                return PTR_ERR(exynos_pcie->clk);
        }
        ret = clk_prepare_enable(exynos_pcie->clk);
        if (ret)
                return ret;
 
-       exynos_pcie->bus_clk = devm_clk_get(&pdev->dev, "pcie_bus");
+       exynos_pcie->bus_clk = devm_clk_get(dev, "pcie_bus");
        if (IS_ERR(exynos_pcie->bus_clk)) {
-               dev_err(&pdev->dev, "Failed to get pcie bus clock\n");
+               dev_err(dev, "Failed to get pcie bus clock\n");
                ret = PTR_ERR(exynos_pcie->bus_clk);
                goto fail_clk;
        }
@@ -579,27 +563,27 @@ static int __init exynos_pcie_probe(struct platform_device *pdev)
                goto fail_clk;
 
        elbi_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       exynos_pcie->elbi_base = devm_ioremap_resource(&pdev->dev, elbi_base);
+       exynos_pcie->elbi_base = devm_ioremap_resource(dev, elbi_base);
        if (IS_ERR(exynos_pcie->elbi_base)) {
                ret = PTR_ERR(exynos_pcie->elbi_base);
                goto fail_bus_clk;
        }
 
        phy_base = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-       exynos_pcie->phy_base = devm_ioremap_resource(&pdev->dev, phy_base);
+       exynos_pcie->phy_base = devm_ioremap_resource(dev, phy_base);
        if (IS_ERR(exynos_pcie->phy_base)) {
                ret = PTR_ERR(exynos_pcie->phy_base);
                goto fail_bus_clk;
        }
 
        block_base = platform_get_resource(pdev, IORESOURCE_MEM, 2);
-       exynos_pcie->block_base = devm_ioremap_resource(&pdev->dev, block_base);
+       exynos_pcie->block_base = devm_ioremap_resource(dev, block_base);
        if (IS_ERR(exynos_pcie->block_base)) {
                ret = PTR_ERR(exynos_pcie->block_base);
                goto fail_bus_clk;
        }
 
-       ret = exynos_add_pcie_port(pp, pdev);
+       ret = exynos_add_pcie_port(exynos_pcie, pdev);
        if (ret < 0)
                goto fail_bus_clk;