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