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 | |
| 58 | /* PCIe Purple registers */ |
| 59 | #define PCIE_PHY_GLOBAL_RESET 0x000 |
| 60 | #define PCIE_PHY_COMMON_RESET 0x004 |
| 61 | #define PCIE_PHY_CMN_REG 0x008 |
| 62 | #define PCIE_PHY_MAC_RESET 0x00c |
| 63 | #define PCIE_PHY_PLL_LOCKED 0x010 |
| 64 | #define PCIE_PHY_TRSVREG_RESET 0x020 |
| 65 | #define PCIE_PHY_TRSV_RESET 0x024 |
| 66 | |
| 67 | /* PCIe PHY registers */ |
| 68 | #define PCIE_PHY_IMPEDANCE 0x004 |
| 69 | #define PCIE_PHY_PLL_DIV_0 0x008 |
| 70 | #define PCIE_PHY_PLL_BIAS 0x00c |
| 71 | #define PCIE_PHY_DCC_FEEDBACK 0x014 |
| 72 | #define PCIE_PHY_PLL_DIV_1 0x05c |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 73 | #define PCIE_PHY_COMMON_POWER 0x064 |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 74 | #define PCIE_PHY_COMMON_PD_CMN BIT(3) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 75 | #define PCIE_PHY_TRSV0_EMP_LVL 0x084 |
| 76 | #define PCIE_PHY_TRSV0_DRV_LVL 0x088 |
| 77 | #define PCIE_PHY_TRSV0_RXCDR 0x0ac |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 78 | #define PCIE_PHY_TRSV0_POWER 0x0c4 |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 79 | #define PCIE_PHY_TRSV0_PD_TSV BIT(7) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 80 | #define PCIE_PHY_TRSV0_LVCC 0x0dc |
| 81 | #define PCIE_PHY_TRSV1_EMP_LVL 0x144 |
| 82 | #define PCIE_PHY_TRSV1_RXCDR 0x16c |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 83 | #define PCIE_PHY_TRSV1_POWER 0x184 |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 84 | #define PCIE_PHY_TRSV1_PD_TSV BIT(7) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 85 | #define PCIE_PHY_TRSV1_LVCC 0x19c |
| 86 | #define PCIE_PHY_TRSV2_EMP_LVL 0x204 |
| 87 | #define PCIE_PHY_TRSV2_RXCDR 0x22c |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 88 | #define PCIE_PHY_TRSV2_POWER 0x244 |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 89 | #define PCIE_PHY_TRSV2_PD_TSV BIT(7) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 90 | #define PCIE_PHY_TRSV2_LVCC 0x25c |
| 91 | #define PCIE_PHY_TRSV3_EMP_LVL 0x2c4 |
| 92 | #define PCIE_PHY_TRSV3_RXCDR 0x2ec |
Jingoo Han | f62b878 | 2013-09-06 17:21:45 +0900 | [diff] [blame] | 93 | #define PCIE_PHY_TRSV3_POWER 0x304 |
Jaehoon Chung | 2681c0e | 2017-01-16 15:31:37 +0900 | [diff] [blame] | 94 | #define PCIE_PHY_TRSV3_PD_TSV BIT(7) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 95 | #define PCIE_PHY_TRSV3_LVCC 0x31c |
| 96 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 97 | struct exynos_pcie_mem_res { |
| 98 | void __iomem *elbi_base; /* DT 0th resource: PCIe CTRL */ |
| 99 | void __iomem *phy_base; /* DT 1st resource: PHY CTRL */ |
| 100 | void __iomem *block_base; /* DT 2nd resource: PHY ADDITIONAL CTRL */ |
| 101 | }; |
| 102 | |
| 103 | struct exynos_pcie_clk_res { |
| 104 | struct clk *clk; |
| 105 | struct clk *bus_clk; |
| 106 | }; |
| 107 | |
| 108 | struct exynos_pcie { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 109 | struct dw_pcie *pci; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 110 | struct exynos_pcie_mem_res *mem_res; |
| 111 | struct exynos_pcie_clk_res *clk_res; |
| 112 | const struct exynos_pcie_ops *ops; |
| 113 | int reset_gpio; |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 114 | |
| 115 | /* For Generic PHY Framework */ |
| 116 | bool using_phy; |
| 117 | struct phy *phy; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | struct exynos_pcie_ops { |
| 121 | int (*get_mem_resources)(struct platform_device *pdev, |
| 122 | struct exynos_pcie *ep); |
| 123 | int (*get_clk_resources)(struct exynos_pcie *ep); |
| 124 | int (*init_clk_resources)(struct exynos_pcie *ep); |
| 125 | void (*deinit_clk_resources)(struct exynos_pcie *ep); |
| 126 | }; |
| 127 | |
| 128 | static int exynos5440_pcie_get_mem_resources(struct platform_device *pdev, |
| 129 | struct exynos_pcie *ep) |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 130 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 131 | struct dw_pcie *pci = ep->pci; |
| 132 | struct device *dev = pci->dev; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 133 | struct resource *res; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 134 | |
| 135 | ep->mem_res = devm_kzalloc(dev, sizeof(*ep->mem_res), GFP_KERNEL); |
| 136 | if (!ep->mem_res) |
| 137 | return -ENOMEM; |
| 138 | |
| 139 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 140 | ep->mem_res->elbi_base = devm_ioremap_resource(dev, res); |
| 141 | if (IS_ERR(ep->mem_res->elbi_base)) |
| 142 | return PTR_ERR(ep->mem_res->elbi_base); |
| 143 | |
Jaehoon Chung | 544714d | 2017-03-07 19:54:05 +0900 | [diff] [blame] | 144 | /* If using the PHY framework, doesn't need to get other resource */ |
| 145 | if (ep->using_phy) |
| 146 | return 0; |
| 147 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 148 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 149 | ep->mem_res->phy_base = devm_ioremap_resource(dev, res); |
| 150 | if (IS_ERR(ep->mem_res->phy_base)) |
| 151 | return PTR_ERR(ep->mem_res->phy_base); |
| 152 | |
| 153 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); |
| 154 | ep->mem_res->block_base = devm_ioremap_resource(dev, res); |
| 155 | if (IS_ERR(ep->mem_res->block_base)) |
| 156 | return PTR_ERR(ep->mem_res->block_base); |
| 157 | |
| 158 | return 0; |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 159 | } |
| 160 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 161 | static int exynos5440_pcie_get_clk_resources(struct exynos_pcie *ep) |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 162 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 163 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 164 | struct device *dev = pci->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 165 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 166 | ep->clk_res = devm_kzalloc(dev, sizeof(*ep->clk_res), GFP_KERNEL); |
| 167 | if (!ep->clk_res) |
| 168 | return -ENOMEM; |
| 169 | |
| 170 | ep->clk_res->clk = devm_clk_get(dev, "pcie"); |
| 171 | if (IS_ERR(ep->clk_res->clk)) { |
| 172 | dev_err(dev, "Failed to get pcie rc clock\n"); |
| 173 | return PTR_ERR(ep->clk_res->clk); |
| 174 | } |
| 175 | |
| 176 | ep->clk_res->bus_clk = devm_clk_get(dev, "pcie_bus"); |
| 177 | if (IS_ERR(ep->clk_res->bus_clk)) { |
| 178 | dev_err(dev, "Failed to get pcie bus clock\n"); |
| 179 | return PTR_ERR(ep->clk_res->bus_clk); |
| 180 | } |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static int exynos5440_pcie_init_clk_resources(struct exynos_pcie *ep) |
| 186 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 187 | struct dw_pcie *pci = ep->pci; |
| 188 | struct device *dev = pci->dev; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 189 | int ret; |
| 190 | |
| 191 | ret = clk_prepare_enable(ep->clk_res->clk); |
| 192 | if (ret) { |
| 193 | dev_err(dev, "cannot enable pcie rc clock"); |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | ret = clk_prepare_enable(ep->clk_res->bus_clk); |
| 198 | if (ret) { |
| 199 | dev_err(dev, "cannot enable pcie bus clock"); |
| 200 | goto err_bus_clk; |
| 201 | } |
| 202 | |
| 203 | return 0; |
| 204 | |
| 205 | err_bus_clk: |
| 206 | clk_disable_unprepare(ep->clk_res->clk); |
| 207 | |
| 208 | return ret; |
| 209 | } |
| 210 | |
| 211 | static void exynos5440_pcie_deinit_clk_resources(struct exynos_pcie *ep) |
| 212 | { |
| 213 | clk_disable_unprepare(ep->clk_res->bus_clk); |
| 214 | clk_disable_unprepare(ep->clk_res->clk); |
| 215 | } |
| 216 | |
| 217 | static const struct exynos_pcie_ops exynos5440_pcie_ops = { |
| 218 | .get_mem_resources = exynos5440_pcie_get_mem_resources, |
| 219 | .get_clk_resources = exynos5440_pcie_get_clk_resources, |
| 220 | .init_clk_resources = exynos5440_pcie_init_clk_resources, |
| 221 | .deinit_clk_resources = exynos5440_pcie_deinit_clk_resources, |
| 222 | }; |
| 223 | |
Jaehoon Chung | d6da7d9 | 2017-01-16 15:31:35 +0900 | [diff] [blame] | 224 | static void exynos_pcie_writel(void __iomem *base, u32 val, u32 reg) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 225 | { |
Jaehoon Chung | d6da7d9 | 2017-01-16 15:31:35 +0900 | [diff] [blame] | 226 | writel(val, base + reg); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 227 | } |
| 228 | |
Jaehoon Chung | d6da7d9 | 2017-01-16 15:31:35 +0900 | [diff] [blame] | 229 | static u32 exynos_pcie_readl(void __iomem *base, u32 reg) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 230 | { |
Jaehoon Chung | d6da7d9 | 2017-01-16 15:31:35 +0900 | [diff] [blame] | 231 | return readl(base + reg); |
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 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] | 235 | { |
| 236 | u32 val; |
| 237 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 238 | 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] | 239 | if (on) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 240 | val |= PCIE_ELBI_SLV_DBI_ENABLE; |
Jaehoon Chung | 92004a06 | 2017-01-16 15:31:38 +0900 | [diff] [blame] | 241 | else |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 242 | val &= ~PCIE_ELBI_SLV_DBI_ENABLE; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 243 | 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] | 244 | } |
| 245 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 246 | 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] | 247 | { |
| 248 | u32 val; |
| 249 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 250 | 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] | 251 | if (on) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 252 | val |= PCIE_ELBI_SLV_DBI_ENABLE; |
Jaehoon Chung | 92004a06 | 2017-01-16 15:31:38 +0900 | [diff] [blame] | 253 | else |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 254 | val &= ~PCIE_ELBI_SLV_DBI_ENABLE; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 255 | 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] | 256 | } |
| 257 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 258 | static void exynos_pcie_assert_core_reset(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 259 | { |
| 260 | u32 val; |
| 261 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 262 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_CORE_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 263 | val &= ~PCIE_CORE_RESET_ENABLE; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 264 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_CORE_RESET); |
| 265 | exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_PWR_RESET); |
| 266 | exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_STICKY_RESET); |
| 267 | exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_NONSTICKY_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 268 | } |
| 269 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 270 | static void exynos_pcie_deassert_core_reset(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 271 | { |
| 272 | u32 val; |
| 273 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 274 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_CORE_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 275 | val |= PCIE_CORE_RESET_ENABLE; |
| 276 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 277 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_CORE_RESET); |
| 278 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_STICKY_RESET); |
| 279 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_NONSTICKY_RESET); |
| 280 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_APP_INIT_RESET); |
| 281 | exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_APP_INIT_RESET); |
| 282 | exynos_pcie_writel(ep->mem_res->block_base, 1, PCIE_PHY_MAC_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 283 | } |
| 284 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 285 | static void exynos_pcie_assert_phy_reset(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 286 | { |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 287 | exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_MAC_RESET); |
| 288 | exynos_pcie_writel(ep->mem_res->block_base, 1, PCIE_PHY_GLOBAL_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 289 | } |
| 290 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 291 | static void exynos_pcie_deassert_phy_reset(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 292 | { |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 293 | exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_GLOBAL_RESET); |
| 294 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_PWR_RESET); |
| 295 | exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_COMMON_RESET); |
| 296 | exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_CMN_REG); |
| 297 | exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_TRSVREG_RESET); |
| 298 | exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_TRSV_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 299 | } |
| 300 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 301 | static void exynos_pcie_power_on_phy(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 302 | { |
| 303 | u32 val; |
| 304 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 305 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_COMMON_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 306 | val &= ~PCIE_PHY_COMMON_PD_CMN; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 307 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_COMMON_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 308 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 309 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV0_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 310 | val &= ~PCIE_PHY_TRSV0_PD_TSV; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 311 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV0_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 312 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 313 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV1_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 314 | val &= ~PCIE_PHY_TRSV1_PD_TSV; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 315 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV1_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 316 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 317 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV2_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 318 | val &= ~PCIE_PHY_TRSV2_PD_TSV; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 319 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV2_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 320 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 321 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV3_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 322 | val &= ~PCIE_PHY_TRSV3_PD_TSV; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 323 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV3_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 324 | } |
| 325 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 326 | static void exynos_pcie_power_off_phy(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 327 | { |
| 328 | u32 val; |
| 329 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 330 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_COMMON_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 331 | val |= PCIE_PHY_COMMON_PD_CMN; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 332 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_COMMON_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 333 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 334 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV0_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 335 | val |= PCIE_PHY_TRSV0_PD_TSV; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 336 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV0_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 337 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 338 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV1_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 339 | val |= PCIE_PHY_TRSV1_PD_TSV; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 340 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV1_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 341 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 342 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV2_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 343 | val |= PCIE_PHY_TRSV2_PD_TSV; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 344 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV2_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 345 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 346 | val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV3_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 347 | val |= PCIE_PHY_TRSV3_PD_TSV; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 348 | exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV3_POWER); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 349 | } |
| 350 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 351 | static void exynos_pcie_init_phy(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 352 | { |
| 353 | /* DCC feedback control off */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 354 | exynos_pcie_writel(ep->mem_res->phy_base, 0x29, PCIE_PHY_DCC_FEEDBACK); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 355 | |
| 356 | /* set TX/RX impedance */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 357 | exynos_pcie_writel(ep->mem_res->phy_base, 0xd5, PCIE_PHY_IMPEDANCE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 358 | |
| 359 | /* set 50Mhz PHY clock */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 360 | exynos_pcie_writel(ep->mem_res->phy_base, 0x14, PCIE_PHY_PLL_DIV_0); |
| 361 | exynos_pcie_writel(ep->mem_res->phy_base, 0x12, PCIE_PHY_PLL_DIV_1); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 362 | |
| 363 | /* set TX Differential output for lane 0 */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 364 | exynos_pcie_writel(ep->mem_res->phy_base, 0x7f, PCIE_PHY_TRSV0_DRV_LVL); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 365 | |
| 366 | /* set TX Pre-emphasis Level Control for lane 0 to minimum */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 367 | exynos_pcie_writel(ep->mem_res->phy_base, 0x0, PCIE_PHY_TRSV0_EMP_LVL); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 368 | |
| 369 | /* set RX clock and data recovery bandwidth */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 370 | exynos_pcie_writel(ep->mem_res->phy_base, 0xe7, PCIE_PHY_PLL_BIAS); |
| 371 | exynos_pcie_writel(ep->mem_res->phy_base, 0x82, PCIE_PHY_TRSV0_RXCDR); |
| 372 | exynos_pcie_writel(ep->mem_res->phy_base, 0x82, PCIE_PHY_TRSV1_RXCDR); |
| 373 | exynos_pcie_writel(ep->mem_res->phy_base, 0x82, PCIE_PHY_TRSV2_RXCDR); |
| 374 | exynos_pcie_writel(ep->mem_res->phy_base, 0x82, PCIE_PHY_TRSV3_RXCDR); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 375 | |
| 376 | /* change TX Pre-emphasis Level Control for lanes */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 377 | exynos_pcie_writel(ep->mem_res->phy_base, 0x39, PCIE_PHY_TRSV0_EMP_LVL); |
| 378 | exynos_pcie_writel(ep->mem_res->phy_base, 0x39, PCIE_PHY_TRSV1_EMP_LVL); |
| 379 | exynos_pcie_writel(ep->mem_res->phy_base, 0x39, PCIE_PHY_TRSV2_EMP_LVL); |
| 380 | exynos_pcie_writel(ep->mem_res->phy_base, 0x39, PCIE_PHY_TRSV3_EMP_LVL); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 381 | |
| 382 | /* set LVCC */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 383 | exynos_pcie_writel(ep->mem_res->phy_base, 0x20, PCIE_PHY_TRSV0_LVCC); |
| 384 | exynos_pcie_writel(ep->mem_res->phy_base, 0xa0, PCIE_PHY_TRSV1_LVCC); |
| 385 | exynos_pcie_writel(ep->mem_res->phy_base, 0xa0, PCIE_PHY_TRSV2_LVCC); |
| 386 | exynos_pcie_writel(ep->mem_res->phy_base, 0xa0, PCIE_PHY_TRSV3_LVCC); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 387 | } |
| 388 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 389 | static void exynos_pcie_assert_reset(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 390 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 391 | struct dw_pcie *pci = ep->pci; |
| 392 | struct device *dev = pci->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 393 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 394 | if (ep->reset_gpio >= 0) |
| 395 | devm_gpio_request_one(dev, ep->reset_gpio, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 396 | GPIOF_OUT_INIT_HIGH, "RESET"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 397 | } |
| 398 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 399 | static int exynos_pcie_establish_link(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 400 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 401 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 402 | struct pcie_port *pp = &pci->pp; |
| 403 | struct device *dev = pci->dev; |
Bjorn Helgaas | 6cbb247 | 2015-06-02 16:47:17 -0500 | [diff] [blame] | 404 | u32 val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 405 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 406 | if (dw_pcie_link_up(pci)) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 407 | dev_err(dev, "Link already up\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 408 | return 0; |
| 409 | } |
| 410 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 411 | exynos_pcie_assert_core_reset(ep); |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 412 | |
| 413 | if (ep->using_phy) { |
| 414 | phy_reset(ep->phy); |
| 415 | |
| 416 | exynos_pcie_writel(ep->mem_res->elbi_base, 1, |
| 417 | PCIE_PWR_RESET); |
| 418 | |
| 419 | phy_power_on(ep->phy); |
| 420 | phy_init(ep->phy); |
| 421 | } else { |
| 422 | exynos_pcie_assert_phy_reset(ep); |
| 423 | exynos_pcie_deassert_phy_reset(ep); |
| 424 | exynos_pcie_power_on_phy(ep); |
| 425 | exynos_pcie_init_phy(ep); |
| 426 | |
| 427 | /* pulse for common reset */ |
| 428 | exynos_pcie_writel(ep->mem_res->block_base, 1, |
| 429 | PCIE_PHY_COMMON_RESET); |
| 430 | udelay(500); |
| 431 | exynos_pcie_writel(ep->mem_res->block_base, 0, |
| 432 | PCIE_PHY_COMMON_RESET); |
| 433 | } |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 434 | |
| 435 | /* pulse for common reset */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 436 | exynos_pcie_writel(ep->mem_res->block_base, 1, PCIE_PHY_COMMON_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 437 | udelay(500); |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 438 | exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_COMMON_RESET); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 439 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 440 | exynos_pcie_deassert_core_reset(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 441 | dw_pcie_setup_rc(pp); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 442 | exynos_pcie_assert_reset(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 443 | |
| 444 | /* assert LTSSM enable */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 445 | exynos_pcie_writel(ep->mem_res->elbi_base, PCIE_ELBI_LTSSM_ENABLE, |
Seungwon Jeon | 058dd01 | 2013-08-29 21:35:56 +0900 | [diff] [blame] | 446 | PCIE_APP_LTSSM_ENABLE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 447 | |
| 448 | /* check if the link is up or not */ |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 449 | if (!dw_pcie_wait_for_link(pci)) |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 450 | return 0; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 451 | |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 452 | if (ep->using_phy) { |
| 453 | phy_power_off(ep->phy); |
| 454 | return -ETIMEDOUT; |
| 455 | } |
| 456 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 457 | while (exynos_pcie_readl(ep->mem_res->phy_base, |
| 458 | PCIE_PHY_PLL_LOCKED) == 0) { |
| 459 | val = exynos_pcie_readl(ep->mem_res->block_base, |
| 460 | PCIE_PHY_PLL_LOCKED); |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 461 | dev_info(dev, "PLL Locked: 0x%x\n", val); |
Bjorn Helgaas | 6cbb247 | 2015-06-02 16:47:17 -0500 | [diff] [blame] | 462 | } |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 463 | exynos_pcie_power_off_phy(ep); |
Joao Pinto | 886bc5c | 2016-03-10 14:44:35 -0600 | [diff] [blame] | 464 | return -ETIMEDOUT; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 465 | } |
| 466 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 467 | static void exynos_pcie_clear_irq_pulse(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 468 | { |
| 469 | u32 val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 470 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 471 | val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_IRQ_PULSE); |
| 472 | exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_IRQ_PULSE); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 473 | } |
| 474 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 475 | static void exynos_pcie_enable_irq_pulse(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 476 | { |
| 477 | u32 val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 478 | |
| 479 | /* enable INTX interrupt */ |
| 480 | val = IRQ_INTA_ASSERT | IRQ_INTB_ASSERT | |
Jaehoon Chung | 01d06a9 | 2015-03-25 14:13:12 +0900 | [diff] [blame] | 481 | IRQ_INTC_ASSERT | IRQ_INTD_ASSERT; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 482 | 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] | 483 | } |
| 484 | |
| 485 | static irqreturn_t exynos_pcie_irq_handler(int irq, void *arg) |
| 486 | { |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 487 | struct exynos_pcie *ep = arg; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 488 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 489 | exynos_pcie_clear_irq_pulse(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 490 | return IRQ_HANDLED; |
| 491 | } |
| 492 | |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 493 | static irqreturn_t exynos_pcie_msi_irq_handler(int irq, void *arg) |
| 494 | { |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 495 | struct exynos_pcie *ep = arg; |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 496 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 497 | struct pcie_port *pp = &pci->pp; |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 498 | |
Lucas Stach | 7f4f16e | 2014-03-28 17:52:58 +0100 | [diff] [blame] | 499 | return dw_handle_msi_irq(pp); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 500 | } |
| 501 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 502 | static void exynos_pcie_msi_init(struct exynos_pcie *ep) |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 503 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 504 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 505 | struct pcie_port *pp = &pci->pp; |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 506 | u32 val; |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 507 | |
| 508 | dw_pcie_msi_init(pp); |
| 509 | |
| 510 | /* enable MSI interrupt */ |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 511 | 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] | 512 | val |= IRQ_MSI_ENABLE; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 513 | 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] | 514 | } |
| 515 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 516 | static void exynos_pcie_enable_interrupts(struct exynos_pcie *ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 517 | { |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 518 | exynos_pcie_enable_irq_pulse(ep); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 519 | |
| 520 | if (IS_ENABLED(CONFIG_PCI_MSI)) |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 521 | exynos_pcie_msi_init(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 522 | } |
| 523 | |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 524 | static u32 exynos_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base, |
| 525 | u32 reg, size_t size) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 526 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 527 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Bjorn Helgaas | 446fc23 | 2016-08-17 14:17:58 -0500 | [diff] [blame] | 528 | u32 val; |
| 529 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 530 | exynos_pcie_sideband_dbi_r_mode(ep, true); |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 531 | dw_pcie_read(base + reg, size, &val); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 532 | exynos_pcie_sideband_dbi_r_mode(ep, false); |
Bjorn Helgaas | 446fc23 | 2016-08-17 14:17:58 -0500 | [diff] [blame] | 533 | return val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 534 | } |
| 535 | |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 536 | static void exynos_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base, |
| 537 | u32 reg, size_t size, u32 val) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 538 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 539 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Bjorn Helgaas | cc08e82 | 2016-10-06 13:33:39 -0500 | [diff] [blame] | 540 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 541 | exynos_pcie_sideband_dbi_w_mode(ep, true); |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 542 | dw_pcie_write(base + reg, size, val); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 543 | exynos_pcie_sideband_dbi_w_mode(ep, false); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static int exynos_pcie_rd_own_conf(struct pcie_port *pp, int where, int size, |
| 547 | u32 *val) |
| 548 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 549 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 550 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 551 | int ret; |
| 552 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 553 | exynos_pcie_sideband_dbi_r_mode(ep, true); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 554 | ret = dw_pcie_read(pci->dbi_base + where, size, val); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 555 | exynos_pcie_sideband_dbi_r_mode(ep, false); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | static int exynos_pcie_wr_own_conf(struct pcie_port *pp, int where, int size, |
| 560 | u32 val) |
| 561 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 562 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 563 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 564 | int ret; |
| 565 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 566 | exynos_pcie_sideband_dbi_w_mode(ep, true); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 567 | ret = dw_pcie_write(pci->dbi_base + where, size, val); |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 568 | exynos_pcie_sideband_dbi_w_mode(ep, false); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 569 | return ret; |
| 570 | } |
| 571 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 572 | static int exynos_pcie_link_up(struct dw_pcie *pci) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 573 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 574 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Bjorn Helgaas | cc08e82 | 2016-10-06 13:33:39 -0500 | [diff] [blame] | 575 | u32 val; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 576 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 577 | 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] | 578 | if (val == PCIE_ELBI_LTSSM_ENABLE) |
| 579 | return 1; |
| 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 584 | static int exynos_pcie_host_init(struct pcie_port *pp) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 585 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 586 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 587 | struct exynos_pcie *ep = to_exynos_pcie(pci); |
Bjorn Helgaas | cc08e82 | 2016-10-06 13:33:39 -0500 | [diff] [blame] | 588 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 589 | exynos_pcie_establish_link(ep); |
| 590 | exynos_pcie_enable_interrupts(ep); |
Bjorn Andersson | 4a30176 | 2017-07-15 23:39:45 -0700 | [diff] [blame] | 591 | |
| 592 | return 0; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 593 | } |
| 594 | |
Jisheng Zhang | 4ab2e7c | 2017-06-05 16:53:46 +0800 | [diff] [blame] | 595 | static const struct dw_pcie_host_ops exynos_pcie_host_ops = { |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 596 | .rd_own_conf = exynos_pcie_rd_own_conf, |
| 597 | .wr_own_conf = exynos_pcie_wr_own_conf, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 598 | .host_init = exynos_pcie_host_init, |
| 599 | }; |
| 600 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 601 | static int __init exynos_add_pcie_port(struct exynos_pcie *ep, |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 602 | struct platform_device *pdev) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 603 | { |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 604 | struct dw_pcie *pci = ep->pci; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 605 | struct pcie_port *pp = &pci->pp; |
| 606 | struct device *dev = &pdev->dev; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 607 | int ret; |
| 608 | |
| 609 | pp->irq = platform_get_irq(pdev, 1); |
Fabio Estevam | 1df5a48 | 2017-08-31 14:52:01 -0300 | [diff] [blame] | 610 | if (pp->irq < 0) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 611 | dev_err(dev, "failed to get irq\n"); |
Fabio Estevam | 1df5a48 | 2017-08-31 14:52:01 -0300 | [diff] [blame] | 612 | return pp->irq; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 613 | } |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 614 | ret = devm_request_irq(dev, pp->irq, exynos_pcie_irq_handler, |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 615 | IRQF_SHARED, "exynos-pcie", ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 616 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 617 | dev_err(dev, "failed to request irq\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 618 | return ret; |
| 619 | } |
| 620 | |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 621 | if (IS_ENABLED(CONFIG_PCI_MSI)) { |
| 622 | pp->msi_irq = platform_get_irq(pdev, 0); |
Fabio Estevam | 1df5a48 | 2017-08-31 14:52:01 -0300 | [diff] [blame] | 623 | if (pp->msi_irq < 0) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 624 | dev_err(dev, "failed to get msi irq\n"); |
Fabio Estevam | 1df5a48 | 2017-08-31 14:52:01 -0300 | [diff] [blame] | 625 | return pp->msi_irq; |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 626 | } |
| 627 | |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 628 | ret = devm_request_irq(dev, pp->msi_irq, |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 629 | exynos_pcie_msi_irq_handler, |
Grygorii Strashko | 8ff0ef9 | 2015-12-10 21:18:20 +0200 | [diff] [blame] | 630 | IRQF_SHARED | IRQF_NO_THREAD, |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 631 | "exynos-pcie", ep); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 632 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 633 | dev_err(dev, "failed to request msi irq\n"); |
Jingoo Han | f342d94 | 2013-09-06 15:54:59 +0900 | [diff] [blame] | 634 | return ret; |
| 635 | } |
| 636 | } |
| 637 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 638 | pp->root_bus_nr = -1; |
| 639 | pp->ops = &exynos_pcie_host_ops; |
| 640 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 641 | ret = dw_pcie_host_init(pp); |
| 642 | if (ret) { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 643 | dev_err(dev, "failed to initialize host\n"); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 644 | return ret; |
| 645 | } |
| 646 | |
| 647 | return 0; |
| 648 | } |
| 649 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 650 | static const struct dw_pcie_ops dw_pcie_ops = { |
Kishon Vijay Abraham I | a509d7d | 2017-03-13 19:13:26 +0530 | [diff] [blame] | 651 | .read_dbi = exynos_pcie_read_dbi, |
| 652 | .write_dbi = exynos_pcie_write_dbi, |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 653 | .link_up = exynos_pcie_link_up, |
| 654 | }; |
| 655 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 656 | static int __init exynos_pcie_probe(struct platform_device *pdev) |
| 657 | { |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 658 | struct device *dev = &pdev->dev; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 659 | struct dw_pcie *pci; |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 660 | struct exynos_pcie *ep; |
Bjorn Helgaas | fae68d6 | 2016-10-06 13:33:41 -0500 | [diff] [blame] | 661 | struct device_node *np = dev->of_node; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 662 | int ret; |
| 663 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 664 | ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL); |
| 665 | if (!ep) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 666 | return -ENOMEM; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 667 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 668 | pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); |
| 669 | if (!pci) |
| 670 | return -ENOMEM; |
| 671 | |
| 672 | pci->dev = dev; |
| 673 | pci->ops = &dw_pcie_ops; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 674 | |
Guenter Roeck | c046406 | 2017-02-25 02:08:12 -0800 | [diff] [blame] | 675 | ep->pci = pci; |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 676 | ep->ops = (const struct exynos_pcie_ops *) |
| 677 | of_device_get_match_data(dev); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 678 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 679 | ep->reset_gpio = of_get_named_gpio(np, "reset-gpio", 0); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 680 | |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 681 | /* Assume that controller doesn't use the PHY framework */ |
| 682 | ep->using_phy = false; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 683 | |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 684 | ep->phy = devm_of_phy_get(dev, np, NULL); |
| 685 | if (IS_ERR(ep->phy)) { |
| 686 | if (PTR_ERR(ep->phy) == -EPROBE_DEFER) |
| 687 | return PTR_ERR(ep->phy); |
| 688 | dev_warn(dev, "Use the 'phy' property. Current DT of pci-exynos was deprecated!!\n"); |
| 689 | } else |
| 690 | ep->using_phy = true; |
| 691 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 692 | if (ep->ops && ep->ops->get_mem_resources) { |
| 693 | ret = ep->ops->get_mem_resources(pdev, ep); |
| 694 | if (ret) |
| 695 | return ret; |
Wei Yongjun | f8db3c9 | 2013-09-29 10:29:11 +0800 | [diff] [blame] | 696 | } |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 697 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 698 | if (ep->ops && ep->ops->get_clk_resources) { |
| 699 | ret = ep->ops->get_clk_resources(ep); |
| 700 | if (ret) |
| 701 | return ret; |
| 702 | ret = ep->ops->init_clk_resources(ep); |
| 703 | if (ret) |
| 704 | return ret; |
Wei Yongjun | f8db3c9 | 2013-09-29 10:29:11 +0800 | [diff] [blame] | 705 | } |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 706 | |
Bjorn Helgaas | b2e6d30 | 2017-02-21 15:13:30 -0600 | [diff] [blame] | 707 | platform_set_drvdata(pdev, ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 708 | |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 709 | ret = exynos_add_pcie_port(ep, pdev); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 710 | if (ret < 0) |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 711 | goto fail_probe; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 712 | |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 713 | return 0; |
| 714 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 715 | fail_probe: |
Jaehoon Chung | e7cd7ef | 2017-02-13 17:26:13 +0900 | [diff] [blame] | 716 | if (ep->using_phy) |
| 717 | phy_exit(ep->phy); |
| 718 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 719 | if (ep->ops && ep->ops->deinit_clk_resources) |
| 720 | ep->ops->deinit_clk_resources(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 721 | return ret; |
| 722 | } |
| 723 | |
| 724 | static int __exit exynos_pcie_remove(struct platform_device *pdev) |
| 725 | { |
Jaehoon Chung | 4e0a90b38 | 2017-01-16 15:31:34 +0900 | [diff] [blame] | 726 | struct exynos_pcie *ep = platform_get_drvdata(pdev); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 727 | |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 728 | if (ep->ops && ep->ops->deinit_clk_resources) |
| 729 | ep->ops->deinit_clk_resources(ep); |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | static const struct of_device_id exynos_pcie_of_match[] = { |
Niyas Ahmed S T | 3278478 | 2017-02-01 10:13:06 +0530 | [diff] [blame] | 735 | { |
| 736 | .compatible = "samsung,exynos5440-pcie", |
| 737 | .data = &exynos5440_pcie_ops |
| 738 | }, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 739 | {}, |
| 740 | }; |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 741 | |
| 742 | static struct platform_driver exynos_pcie_driver = { |
| 743 | .remove = __exit_p(exynos_pcie_remove), |
| 744 | .driver = { |
| 745 | .name = "exynos-pcie", |
Sachin Kamat | eb36309 | 2013-10-21 14:36:43 +0530 | [diff] [blame] | 746 | .of_match_table = exynos_pcie_of_match, |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 747 | }, |
| 748 | }; |
| 749 | |
| 750 | /* Exynos PCIe driver does not allow module unload */ |
| 751 | |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 752 | static int __init exynos_pcie_init(void) |
Jingoo Han | 4b1ced8 | 2013-07-31 17:14:10 +0900 | [diff] [blame] | 753 | { |
| 754 | return platform_driver_probe(&exynos_pcie_driver, exynos_pcie_probe); |
| 755 | } |
Jingoo Han | 70b3e89 | 2014-10-22 13:58:49 +0900 | [diff] [blame] | 756 | subsys_initcall(exynos_pcie_init); |