Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 1 | /* |
| 2 | * PCIe host controller driver for Samsung EXYNOS SoCs |
| 3 | * |
| 4 | * Copyright (C) 2013 Samsung Electronics Co., Ltd. |
| 5 | * http://www.samsung.com |
| 6 | * |
| 7 | * Author: Jingoo Han <jg1.han@samsung.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/clk.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/gpio.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/kernel.h> |
Paul Gortmaker | caf5548 | 2016-08-22 17:59:47 -0400 | [diff] [blame] | 19 | #include <linux/init.h> |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 20 | #include <linux/of_device.h> |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 21 | #include <linux/of_gpio.h> |
| 22 | #include <linux/pci.h> |
| 23 | #include <linux/platform_device.h> |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 24 | #include <linux/phy/phy.h> |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 25 | #include <linux/resource.h> |
| 26 | #include <linux/signal.h> |
| 27 | #include <linux/types.h> |
| 28 | |
| 29 | #include "pcie-designware.h" |
| 30 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 31 | #define to_exynos_pcie(x) dev_get_drvdata((x)->dev) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 32 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 33 | /* PCIe ELBI registers */ |
| 34 | #define PCIE_IRQ_PULSE 0x000 |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 35 | #define IRQ_INTA_ASSERT BIT(0) |
| 36 | #define IRQ_INTB_ASSERT BIT(2) |
| 37 | #define IRQ_INTC_ASSERT BIT(4) |
| 38 | #define IRQ_INTD_ASSERT BIT(6) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 39 | #define PCIE_IRQ_LEVEL 0x004 |
| 40 | #define PCIE_IRQ_SPECIAL 0x008 |
| 41 | #define PCIE_IRQ_EN_PULSE 0x00c |
| 42 | #define PCIE_IRQ_EN_LEVEL 0x010 |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 43 | #define IRQ_MSI_ENABLE BIT(2) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 44 | #define PCIE_IRQ_EN_SPECIAL 0x014 |
| 45 | #define PCIE_PWR_RESET 0x018 |
| 46 | #define PCIE_CORE_RESET 0x01c |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 47 | #define PCIE_CORE_RESET_ENABLE BIT(0) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 48 | #define PCIE_STICKY_RESET 0x020 |
| 49 | #define PCIE_NONSTICKY_RESET 0x024 |
| 50 | #define PCIE_APP_INIT_RESET 0x028 |
| 51 | #define PCIE_APP_LTSSM_ENABLE 0x02c |
| 52 | #define PCIE_ELBI_RDLH_LINKUP 0x064 |
| 53 | #define PCIE_ELBI_LTSSM_ENABLE 0x1 |
| 54 | #define PCIE_ELBI_SLV_AWMISC 0x11c |
| 55 | #define PCIE_ELBI_SLV_ARMISC 0x120 |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 56 | #define PCIE_ELBI_SLV_DBI_ENABLE BIT(21) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 57 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 58 | struct exynos_pcie_mem_res { |
| 59 | void __iomem *elbi_base; /* DT 0th resource: PCIe CTRL */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | struct exynos_pcie_clk_res { |
| 63 | struct clk *clk; |
| 64 | struct clk *bus_clk; |
| 65 | }; |
| 66 | |
| 67 | struct exynos_pcie { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 68 | struct dw_pcie *pci; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 69 | struct exynos_pcie_mem_res *mem_res; |
| 70 | struct exynos_pcie_clk_res *clk_res; |
| 71 | const struct exynos_pcie_ops *ops; |
| 72 | int reset_gpio; |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 73 | |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 74 | struct phy *phy; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | struct exynos_pcie_ops { |
| 78 | int (*get_mem_resources)(struct platform_device *pdev, |
| 79 | struct exynos_pcie *ep); |
| 80 | int (*get_clk_resources)(struct exynos_pcie *ep); |
| 81 | int (*init_clk_resources)(struct exynos_pcie *ep); |
| 82 | void (*deinit_clk_resources)(struct exynos_pcie *ep); |
| 83 | }; |
| 84 | |
| 85 | static int exynos5440_pcie_get_mem_resources(struct platform_device *pdev, |
| 86 | struct exynos_pcie *ep) |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 87 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 88 | struct dw_pcie *pci = ep->pci; |
| 89 | struct device *dev = pci->dev; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 90 | struct resource *res; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 91 | |
| 92 | ep->mem_res = devm_kzalloc(dev, sizeof(*ep->mem_res), GFP_KERNEL); |
| 93 | if (!ep->mem_res) |
| 94 | return -ENOMEM; |
| 95 | |
| 96 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 97 | ep->mem_res->elbi_base = devm_ioremap_resource(dev, res); |
| 98 | if (IS_ERR(ep->mem_res->elbi_base)) |
| 99 | return PTR_ERR(ep->mem_res->elbi_base); |
| 100 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 101 | return 0; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 104 | static int exynos5440_pcie_get_clk_resources(struct exynos_pcie *ep) |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 105 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 106 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 107 | struct device *dev = pci->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 108 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 109 | ep->clk_res = devm_kzalloc(dev, sizeof(*ep->clk_res), GFP_KERNEL); |
| 110 | if (!ep->clk_res) |
| 111 | return -ENOMEM; |
| 112 | |
| 113 | ep->clk_res->clk = devm_clk_get(dev, "pcie"); |
| 114 | if (IS_ERR(ep->clk_res->clk)) { |
| 115 | dev_err(dev, "Failed to get pcie rc clock\n"); |
| 116 | return PTR_ERR(ep->clk_res->clk); |
| 117 | } |
| 118 | |
| 119 | ep->clk_res->bus_clk = devm_clk_get(dev, "pcie_bus"); |
| 120 | if (IS_ERR(ep->clk_res->bus_clk)) { |
| 121 | dev_err(dev, "Failed to get pcie bus clock\n"); |
| 122 | return PTR_ERR(ep->clk_res->bus_clk); |
| 123 | } |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int exynos5440_pcie_init_clk_resources(struct exynos_pcie *ep) |
| 129 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 130 | struct dw_pcie *pci = ep->pci; |
| 131 | struct device *dev = pci->dev; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 132 | int ret; |
| 133 | |
| 134 | ret = clk_prepare_enable(ep->clk_res->clk); |
| 135 | if (ret) { |
| 136 | dev_err(dev, "cannot enable pcie rc clock"); |
| 137 | return ret; |
| 138 | } |
| 139 | |
| 140 | ret = clk_prepare_enable(ep->clk_res->bus_clk); |
| 141 | if (ret) { |
| 142 | dev_err(dev, "cannot enable pcie bus clock"); |
| 143 | goto err_bus_clk; |
| 144 | } |
| 145 | |
| 146 | return 0; |
| 147 | |
| 148 | err_bus_clk: |
| 149 | clk_disable_unprepare(ep->clk_res->clk); |
| 150 | |
| 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | static void exynos5440_pcie_deinit_clk_resources(struct exynos_pcie *ep) |
| 155 | { |
| 156 | clk_disable_unprepare(ep->clk_res->bus_clk); |
| 157 | clk_disable_unprepare(ep->clk_res->clk); |
| 158 | } |
| 159 | |
| 160 | static const struct exynos_pcie_ops exynos5440_pcie_ops = { |
| 161 | .get_mem_resources = exynos5440_pcie_get_mem_resources, |
| 162 | .get_clk_resources = exynos5440_pcie_get_clk_resources, |
| 163 | .init_clk_resources = exynos5440_pcie_init_clk_resources, |
| 164 | .deinit_clk_resources = exynos5440_pcie_deinit_clk_resources, |
| 165 | }; |
| 166 | |
Jaehoon Chung | d6da7d9 | 2017-01-16 15:31:35 +0900 | [diff] [blame] | 167 | static void exynos_pcie_writel(void __iomem *base, u32 val, u32 reg) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 168 | { |
Jaehoon Chung | d6da7d9 | 2017-01-16 15:31:35 +0900 | [diff] [blame] | 169 | writel(val, base + reg); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 170 | } |
| 171 | |
Jaehoon Chung | d6da7d9 | 2017-01-16 15:31:35 +0900 | [diff] [blame] | 172 | static u32 exynos_pcie_readl(void __iomem *base, u32 reg) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 173 | { |
Jaehoon Chung | d6da7d9 | 2017-01-16 15:31:35 +0900 | [diff] [blame] | 174 | return readl(base + reg); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 175 | } |
| 176 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 177 | static void exynos_pcie_sideband_dbi_w_mode(struct exynos_pcie *ep, bool on) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 178 | { |
| 179 | u32 val; |
| 180 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 181 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_ELBI_SLV_AWMISC); |
Jaehoon Chung | 92004a06 | 2017-01-16 15:31:38 +0900 | [diff] [blame] | 182 | if (on) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 183 | val |= PCIE_ELBI_SLV_DBI_ENABLE; |
Jaehoon Chung | 92004a06 | 2017-01-16 15:31:38 +0900 | [diff] [blame] | 184 | else |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 185 | val &= ~PCIE_ELBI_SLV_DBI_ENABLE; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 186 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_ELBI_SLV_AWMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 187 | } |
| 188 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 189 | static void exynos_pcie_sideband_dbi_r_mode(struct exynos_pcie *ep, bool on) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 190 | { |
| 191 | u32 val; |
| 192 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 193 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_ELBI_SLV_ARMISC); |
Jaehoon Chung | 92004a06 | 2017-01-16 15:31:38 +0900 | [diff] [blame] | 194 | if (on) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 195 | val |= PCIE_ELBI_SLV_DBI_ENABLE; |
Jaehoon Chung | 92004a06 | 2017-01-16 15:31:38 +0900 | [diff] [blame] | 196 | else |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 197 | val &= ~PCIE_ELBI_SLV_DBI_ENABLE; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 198 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_ELBI_SLV_ARMISC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 199 | } |
| 200 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 201 | static void exynos_pcie_assert_core_reset(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 202 | { |
| 203 | u32 val; |
| 204 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 205 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_CORE_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 206 | val &= ~PCIE_CORE_RESET_ENABLE; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 207 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_CORE_RESET); |
| 208 | exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_PWR_RESET); |
| 209 | exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_STICKY_RESET); |
| 210 | exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_NONSTICKY_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 211 | } |
| 212 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 213 | static void exynos_pcie_deassert_core_reset(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 214 | { |
| 215 | u32 val; |
| 216 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 217 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_CORE_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 218 | val |= PCIE_CORE_RESET_ENABLE; |
| 219 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 220 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_CORE_RESET); |
| 221 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_STICKY_RESET); |
| 222 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_NONSTICKY_RESET); |
| 223 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_APP_INIT_RESET); |
| 224 | exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_APP_INIT_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 225 | } |
| 226 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 227 | static void exynos_pcie_assert_reset(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 228 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 229 | struct dw_pcie *pci = ep->pci; |
| 230 | struct device *dev = pci->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 231 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 232 | if (ep->reset_gpio >= 0) |
| 233 | devm_gpio_request_one(dev, ep->reset_gpio, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 234 | GPIOF_OUT_INIT_HIGH, "RESET"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 235 | } |
| 236 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 237 | static int exynos_pcie_establish_link(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 238 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 239 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 240 | struct pcie_port *pp = &pci->pp; |
| 241 | struct device *dev = pci->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 242 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 243 | if (dw_pcie_link_up(pci)) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 244 | dev_err(dev, "Link already up\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 245 | return 0; |
| 246 | } |
| 247 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 248 | exynos_pcie_assert_core_reset(ep); |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 249 | |
Jaehoon Chung | 83f4f3f | 2017-12-27 18:43:27 +0900 | [diff] [blame^] | 250 | phy_reset(ep->phy); |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 251 | |
Jaehoon Chung | 83f4f3f | 2017-12-27 18:43:27 +0900 | [diff] [blame^] | 252 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, |
| 253 | PCIE_PWR_RESET); |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 254 | |
Jaehoon Chung | 83f4f3f | 2017-12-27 18:43:27 +0900 | [diff] [blame^] | 255 | phy_power_on(ep->phy); |
| 256 | phy_init(ep->phy); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 257 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 258 | exynos_pcie_deassert_core_reset(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 259 | dw_pcie_setup_rc(pp); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 260 | exynos_pcie_assert_reset(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 261 | |
| 262 | /* assert LTSSM enable */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 263 | exynos_pcie_writel(ep->mem_res->elbi_base, PCIE_ELBI_LTSSM_ENABLE, |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 264 | PCIE_APP_LTSSM_ENABLE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 265 | |
| 266 | /* check if the link is up or not */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 267 | if (!dw_pcie_wait_for_link(pci)) |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 268 | return 0; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 269 | |
Jaehoon Chung | 83f4f3f | 2017-12-27 18:43:27 +0900 | [diff] [blame^] | 270 | phy_power_off(ep->phy); |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 271 | return -ETIMEDOUT; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 272 | } |
| 273 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 274 | static void exynos_pcie_clear_irq_pulse(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 275 | { |
| 276 | u32 val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 277 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 278 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_IRQ_PULSE); |
| 279 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_IRQ_PULSE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 280 | } |
| 281 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 282 | static void exynos_pcie_enable_irq_pulse(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 283 | { |
| 284 | u32 val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 285 | |
| 286 | /* enable INTX interrupt */ |
| 287 | val = IRQ_INTA_ASSERT | IRQ_INTB_ASSERT | |
Jaehoon Chung | 01d06a9 | 2015-03-25 14:13:12 +0900 | [diff] [blame] | 288 | IRQ_INTC_ASSERT | IRQ_INTD_ASSERT; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 289 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_IRQ_EN_PULSE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static irqreturn_t exynos_pcie_irq_handler(int irq, void *arg) |
| 293 | { |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 294 | struct exynos_pcie *ep = arg; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 295 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 296 | exynos_pcie_clear_irq_pulse(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 297 | return IRQ_HANDLED; |
| 298 | } |
| 299 | |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 300 | static irqreturn_t exynos_pcie_msi_irq_handler(int irq, void *arg) |
| 301 | { |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 302 | struct exynos_pcie *ep = arg; |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 303 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 304 | struct pcie_port *pp = &pci->pp; |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 305 | |
Lucas Stach | 7f4f16e | 2014-03-28 17:52:58 +0100 | [diff] [blame] | 306 | return dw_handle_msi_irq(pp); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 307 | } |
| 308 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 309 | static void exynos_pcie_msi_init(struct exynos_pcie *ep) |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 310 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 311 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 312 | struct pcie_port *pp = &pci->pp; |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 313 | u32 val; |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 314 | |
| 315 | dw_pcie_msi_init(pp); |
| 316 | |
| 317 | /* enable MSI interrupt */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 318 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_IRQ_EN_LEVEL); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 319 | val |= IRQ_MSI_ENABLE; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 320 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_IRQ_EN_LEVEL); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 321 | } |
| 322 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 323 | static void exynos_pcie_enable_interrupts(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 324 | { |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 325 | exynos_pcie_enable_irq_pulse(ep); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 326 | |
| 327 | if (IS_ENABLED(CONFIG_PCI_MSI)) |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 328 | exynos_pcie_msi_init(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 329 | } |
| 330 | |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 331 | static u32 exynos_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base, |
| 332 | u32 reg, size_t size) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 333 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 334 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Bjorn Helgaas | 446fc23 | 2016-08-17 14:17:58 -0500 | [diff] [blame] | 335 | u32 val; |
| 336 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 337 | exynos_pcie_sideband_dbi_r_mode(ep, true); |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 338 | dw_pcie_read(base + reg, size, &val); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 339 | exynos_pcie_sideband_dbi_r_mode(ep, false); |
Bjorn Helgaas | 446fc23 | 2016-08-17 14:17:58 -0500 | [diff] [blame] | 340 | return val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 341 | } |
| 342 | |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 343 | static void exynos_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base, |
| 344 | u32 reg, size_t size, u32 val) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 345 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 346 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Bjorn Helgaas | cc08e82 | 2016-10-06 13:33:39 -0500 | [diff] [blame] | 347 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 348 | exynos_pcie_sideband_dbi_w_mode(ep, true); |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 349 | dw_pcie_write(base + reg, size, val); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 350 | exynos_pcie_sideband_dbi_w_mode(ep, false); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static int exynos_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, |
| 354 | u32 *val) |
| 355 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 356 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 357 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 358 | int ret; |
| 359 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 360 | exynos_pcie_sideband_dbi_r_mode(ep, true); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 361 | ret = dw_pcie_read(pci->dbi_base + where, size, val); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 362 | exynos_pcie_sideband_dbi_r_mode(ep, false); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 363 | return ret; |
| 364 | } |
| 365 | |
| 366 | static int exynos_pcie_wr_own_conf(struct pcie_port *pp, int where, int size, |
| 367 | u32 val) |
| 368 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 369 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 370 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 371 | int ret; |
| 372 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 373 | exynos_pcie_sideband_dbi_w_mode(ep, true); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 374 | ret = dw_pcie_write(pci->dbi_base + where, size, val); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 375 | exynos_pcie_sideband_dbi_w_mode(ep, false); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 376 | return ret; |
| 377 | } |
| 378 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 379 | static int exynos_pcie_link_up(struct dw_pcie *pci) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 380 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 381 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Bjorn Helgaas | cc08e82 | 2016-10-06 13:33:39 -0500 | [diff] [blame] | 382 | u32 val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 383 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 384 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_ELBI_RDLH_LINKUP); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 385 | if (val == PCIE_ELBI_LTSSM_ENABLE) |
| 386 | return 1; |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 391 | static int exynos_pcie_host_init(struct pcie_port *pp) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 392 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 393 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 394 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Bjorn Helgaas | cc08e82 | 2016-10-06 13:33:39 -0500 | [diff] [blame] | 395 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 396 | exynos_pcie_establish_link(ep); |
| 397 | exynos_pcie_enable_interrupts(ep); |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 398 | |
| 399 | return 0; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 400 | } |
| 401 | |
Jisheng Zhang | 4ab2e7c | 2017-06-05 16:53:46 +0800 | [diff] [blame] | 402 | static const struct dw_pcie_host_ops exynos_pcie_host_ops = { |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 403 | .rd_own_conf = exynos_pcie_rd_own_conf, |
| 404 | .wr_own_conf = exynos_pcie_wr_own_conf, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 405 | .host_init = exynos_pcie_host_init, |
| 406 | }; |
| 407 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 408 | static int __init exynos_add_pcie_port(struct exynos_pcie *ep, |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 409 | struct platform_device *pdev) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 410 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 411 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 412 | struct pcie_port *pp = &pci->pp; |
| 413 | struct device *dev = &pdev->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 414 | int ret; |
| 415 | |
| 416 | pp->irq = platform_get_irq(pdev, 1); |
Fabio Estevam | 1df5a48 | 2017-08-31 14:52:01 -0300 | [diff] [blame] | 417 | if (pp->irq < 0) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 418 | dev_err(dev, "failed to get irq\n"); |
Fabio Estevam | 1df5a48 | 2017-08-31 14:52:01 -0300 | [diff] [blame] | 419 | return pp->irq; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 420 | } |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 421 | ret = devm_request_irq(dev, pp->irq, exynos_pcie_irq_handler, |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 422 | IRQF_SHARED, "exynos-pcie", ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 423 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 424 | dev_err(dev, "failed to request irq\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 425 | return ret; |
| 426 | } |
| 427 | |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 428 | if (IS_ENABLED(CONFIG_PCI_MSI)) { |
| 429 | pp->msi_irq = platform_get_irq(pdev, 0); |
Fabio Estevam | 1df5a48 | 2017-08-31 14:52:01 -0300 | [diff] [blame] | 430 | if (pp->msi_irq < 0) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 431 | dev_err(dev, "failed to get msi irq\n"); |
Fabio Estevam | 1df5a48 | 2017-08-31 14:52:01 -0300 | [diff] [blame] | 432 | return pp->msi_irq; |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 433 | } |
| 434 | |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 435 | ret = devm_request_irq(dev, pp->msi_irq, |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 436 | exynos_pcie_msi_irq_handler, |
Grygorii Strashko | 8ff0ef9 | 2015-12-10 21:18:20 +0200 | [diff] [blame] | 437 | IRQF_SHARED | IRQF_NO_THREAD, |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 438 | "exynos-pcie", ep); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 439 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 440 | dev_err(dev, "failed to request msi irq\n"); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 441 | return ret; |
| 442 | } |
| 443 | } |
| 444 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 445 | pp->root_bus_nr = -1; |
| 446 | pp->ops = &exynos_pcie_host_ops; |
| 447 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 448 | ret = dw_pcie_host_init(pp); |
| 449 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 450 | dev_err(dev, "failed to initialize host\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 451 | return ret; |
| 452 | } |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 457 | static const struct dw_pcie_ops dw_pcie_ops = { |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 458 | .read_dbi = exynos_pcie_read_dbi, |
| 459 | .write_dbi = exynos_pcie_write_dbi, |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 460 | .link_up = exynos_pcie_link_up, |
| 461 | }; |
| 462 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 463 | static int __init exynos_pcie_probe(struct platform_device *pdev) |
| 464 | { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 465 | struct device *dev = &pdev->dev; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 466 | struct dw_pcie *pci; |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 467 | struct exynos_pcie *ep; |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 468 | struct device_node *np = dev->of_node; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 469 | int ret; |
| 470 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 471 | ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); |
| 472 | if (!ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 473 | return -ENOMEM; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 474 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 475 | pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); |
| 476 | if (!pci) |
| 477 | return -ENOMEM; |
| 478 | |
| 479 | pci->dev = dev; |
| 480 | pci->ops = &dw_pcie_ops; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 481 | |
Guenter Roeck | c046406 | 2017-02-25 02:08:12 -0800 | [diff] [blame] | 482 | ep->pci = pci; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 483 | ep->ops = (const struct exynos_pcie_ops *) |
| 484 | of_device_get_match_data(dev); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 485 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 486 | ep->reset_gpio = of_get_named_gpio(np, "reset-gpio", 0); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 487 | |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 488 | ep->phy = devm_of_phy_get(dev, np, NULL); |
| 489 | if (IS_ERR(ep->phy)) { |
| 490 | if (PTR_ERR(ep->phy) == -EPROBE_DEFER) |
| 491 | return PTR_ERR(ep->phy); |
Jaehoon Chung | 83f4f3f | 2017-12-27 18:43:27 +0900 | [diff] [blame^] | 492 | |
| 493 | ep->phy = NULL; |
| 494 | } |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 495 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 496 | if (ep->ops && ep->ops->get_mem_resources) { |
| 497 | ret = ep->ops->get_mem_resources(pdev, ep); |
| 498 | if (ret) |
| 499 | return ret; |
Wei Yongjun | f8db3c9 | 2013-09-29 10:29:11 +0800 | [diff] [blame] | 500 | } |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 501 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 502 | if (ep->ops && ep->ops->get_clk_resources) { |
| 503 | ret = ep->ops->get_clk_resources(ep); |
| 504 | if (ret) |
| 505 | return ret; |
| 506 | ret = ep->ops->init_clk_resources(ep); |
| 507 | if (ret) |
| 508 | return ret; |
Wei Yongjun | f8db3c9 | 2013-09-29 10:29:11 +0800 | [diff] [blame] | 509 | } |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 510 | |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 511 | platform_set_drvdata(pdev, ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 512 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 513 | ret = exynos_add_pcie_port(ep, pdev); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 514 | if (ret < 0) |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 515 | goto fail_probe; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 516 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 517 | return 0; |
| 518 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 519 | fail_probe: |
Jaehoon Chung | 83f4f3f | 2017-12-27 18:43:27 +0900 | [diff] [blame^] | 520 | phy_exit(ep->phy); |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 521 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 522 | if (ep->ops && ep->ops->deinit_clk_resources) |
| 523 | ep->ops->deinit_clk_resources(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 524 | return ret; |
| 525 | } |
| 526 | |
| 527 | static int __exit exynos_pcie_remove(struct platform_device *pdev) |
| 528 | { |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 529 | struct exynos_pcie *ep = platform_get_drvdata(pdev); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 530 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 531 | if (ep->ops && ep->ops->deinit_clk_resources) |
| 532 | ep->ops->deinit_clk_resources(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | static const struct of_device_id exynos_pcie_of_match[] = { |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 538 | { |
| 539 | .compatible = "samsung,exynos5440-pcie", |
| 540 | .data = &exynos5440_pcie_ops |
| 541 | }, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 542 | {}, |
| 543 | }; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 544 | |
| 545 | static struct platform_driver exynos_pcie_driver = { |
| 546 | .remove = __exit_p(exynos_pcie_remove), |
| 547 | .driver = { |
| 548 | .name = "exynos-pcie", |
Sachin Kamat | eb36309 | 2013-10-21 14:36:43 +0530 | [diff] [blame] | 549 | .of_match_table = exynos_pcie_of_match, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 550 | }, |
| 551 | }; |
| 552 | |
| 553 | /* Exynos PCIe driver does not allow module unload */ |
| 554 | |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 555 | static int __init exynos_pcie_init(void) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 556 | { |
| 557 | return platform_driver_probe(&exynos_pcie_driver, exynos_pcie_probe); |
| 558 | } |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 559 | subsys_initcall(exynos_pcie_init); |