blob: ab9e67465b9ba669cb74c4a39afab5c1c639a656 [file] [log] [blame]
Jingoo Han4b1ced82013-07-31 17:14:10 +09001/*
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 Gortmakercaf55482016-08-22 17:59:47 -040019#include <linux/init.h>
Niyas Ahmed S T32784782017-02-01 10:13:06 +053020#include <linux/of_device.h>
Jingoo Han4b1ced82013-07-31 17:14:10 +090021#include <linux/of_gpio.h>
22#include <linux/pci.h>
23#include <linux/platform_device.h>
24#include <linux/resource.h>
25#include <linux/signal.h>
26#include <linux/types.h>
27
28#include "pcie-designware.h"
29
30#define to_exynos_pcie(x) container_of(x, struct exynos_pcie, pp)
31
Jingoo Han4b1ced82013-07-31 17:14:10 +090032/* PCIe ELBI registers */
33#define PCIE_IRQ_PULSE 0x000
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090034#define IRQ_INTA_ASSERT BIT(0)
35#define IRQ_INTB_ASSERT BIT(2)
36#define IRQ_INTC_ASSERT BIT(4)
37#define IRQ_INTD_ASSERT BIT(6)
Jingoo Han4b1ced82013-07-31 17:14:10 +090038#define PCIE_IRQ_LEVEL 0x004
39#define PCIE_IRQ_SPECIAL 0x008
40#define PCIE_IRQ_EN_PULSE 0x00c
41#define PCIE_IRQ_EN_LEVEL 0x010
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090042#define IRQ_MSI_ENABLE BIT(2)
Jingoo Han4b1ced82013-07-31 17:14:10 +090043#define PCIE_IRQ_EN_SPECIAL 0x014
44#define PCIE_PWR_RESET 0x018
45#define PCIE_CORE_RESET 0x01c
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090046#define PCIE_CORE_RESET_ENABLE BIT(0)
Jingoo Han4b1ced82013-07-31 17:14:10 +090047#define PCIE_STICKY_RESET 0x020
48#define PCIE_NONSTICKY_RESET 0x024
49#define PCIE_APP_INIT_RESET 0x028
50#define PCIE_APP_LTSSM_ENABLE 0x02c
51#define PCIE_ELBI_RDLH_LINKUP 0x064
52#define PCIE_ELBI_LTSSM_ENABLE 0x1
53#define PCIE_ELBI_SLV_AWMISC 0x11c
54#define PCIE_ELBI_SLV_ARMISC 0x120
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090055#define PCIE_ELBI_SLV_DBI_ENABLE BIT(21)
Jingoo Han4b1ced82013-07-31 17:14:10 +090056
57/* PCIe Purple registers */
58#define PCIE_PHY_GLOBAL_RESET 0x000
59#define PCIE_PHY_COMMON_RESET 0x004
60#define PCIE_PHY_CMN_REG 0x008
61#define PCIE_PHY_MAC_RESET 0x00c
62#define PCIE_PHY_PLL_LOCKED 0x010
63#define PCIE_PHY_TRSVREG_RESET 0x020
64#define PCIE_PHY_TRSV_RESET 0x024
65
66/* PCIe PHY registers */
67#define PCIE_PHY_IMPEDANCE 0x004
68#define PCIE_PHY_PLL_DIV_0 0x008
69#define PCIE_PHY_PLL_BIAS 0x00c
70#define PCIE_PHY_DCC_FEEDBACK 0x014
71#define PCIE_PHY_PLL_DIV_1 0x05c
Jingoo Hanf62b8782013-09-06 17:21:45 +090072#define PCIE_PHY_COMMON_POWER 0x064
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090073#define PCIE_PHY_COMMON_PD_CMN BIT(3)
Jingoo Han4b1ced82013-07-31 17:14:10 +090074#define PCIE_PHY_TRSV0_EMP_LVL 0x084
75#define PCIE_PHY_TRSV0_DRV_LVL 0x088
76#define PCIE_PHY_TRSV0_RXCDR 0x0ac
Jingoo Hanf62b8782013-09-06 17:21:45 +090077#define PCIE_PHY_TRSV0_POWER 0x0c4
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090078#define PCIE_PHY_TRSV0_PD_TSV BIT(7)
Jingoo Han4b1ced82013-07-31 17:14:10 +090079#define PCIE_PHY_TRSV0_LVCC 0x0dc
80#define PCIE_PHY_TRSV1_EMP_LVL 0x144
81#define PCIE_PHY_TRSV1_RXCDR 0x16c
Jingoo Hanf62b8782013-09-06 17:21:45 +090082#define PCIE_PHY_TRSV1_POWER 0x184
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090083#define PCIE_PHY_TRSV1_PD_TSV BIT(7)
Jingoo Han4b1ced82013-07-31 17:14:10 +090084#define PCIE_PHY_TRSV1_LVCC 0x19c
85#define PCIE_PHY_TRSV2_EMP_LVL 0x204
86#define PCIE_PHY_TRSV2_RXCDR 0x22c
Jingoo Hanf62b8782013-09-06 17:21:45 +090087#define PCIE_PHY_TRSV2_POWER 0x244
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090088#define PCIE_PHY_TRSV2_PD_TSV BIT(7)
Jingoo Han4b1ced82013-07-31 17:14:10 +090089#define PCIE_PHY_TRSV2_LVCC 0x25c
90#define PCIE_PHY_TRSV3_EMP_LVL 0x2c4
91#define PCIE_PHY_TRSV3_RXCDR 0x2ec
Jingoo Hanf62b8782013-09-06 17:21:45 +090092#define PCIE_PHY_TRSV3_POWER 0x304
Jaehoon Chung2681c0e2017-01-16 15:31:37 +090093#define PCIE_PHY_TRSV3_PD_TSV BIT(7)
Jingoo Han4b1ced82013-07-31 17:14:10 +090094#define PCIE_PHY_TRSV3_LVCC 0x31c
95
Niyas Ahmed S T32784782017-02-01 10:13:06 +053096struct exynos_pcie_mem_res {
97 void __iomem *elbi_base; /* DT 0th resource: PCIe CTRL */
98 void __iomem *phy_base; /* DT 1st resource: PHY CTRL */
99 void __iomem *block_base; /* DT 2nd resource: PHY ADDITIONAL CTRL */
100};
101
102struct exynos_pcie_clk_res {
103 struct clk *clk;
104 struct clk *bus_clk;
105};
106
107struct exynos_pcie {
108 struct pcie_port pp;
109 struct exynos_pcie_mem_res *mem_res;
110 struct exynos_pcie_clk_res *clk_res;
111 const struct exynos_pcie_ops *ops;
112 int reset_gpio;
113};
114
115struct exynos_pcie_ops {
116 int (*get_mem_resources)(struct platform_device *pdev,
117 struct exynos_pcie *ep);
118 int (*get_clk_resources)(struct exynos_pcie *ep);
119 int (*init_clk_resources)(struct exynos_pcie *ep);
120 void (*deinit_clk_resources)(struct exynos_pcie *ep);
121};
122
123static int exynos5440_pcie_get_mem_resources(struct platform_device *pdev,
124 struct exynos_pcie *ep)
125{
126 struct resource *res;
127 struct device *dev = ep->pp.dev;
128
129 ep->mem_res = devm_kzalloc(dev, sizeof(*ep->mem_res), GFP_KERNEL);
130 if (!ep->mem_res)
131 return -ENOMEM;
132
133 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
134 ep->mem_res->elbi_base = devm_ioremap_resource(dev, res);
135 if (IS_ERR(ep->mem_res->elbi_base))
136 return PTR_ERR(ep->mem_res->elbi_base);
137
138 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
139 ep->mem_res->phy_base = devm_ioremap_resource(dev, res);
140 if (IS_ERR(ep->mem_res->phy_base))
141 return PTR_ERR(ep->mem_res->phy_base);
142
143 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
144 ep->mem_res->block_base = devm_ioremap_resource(dev, res);
145 if (IS_ERR(ep->mem_res->block_base))
146 return PTR_ERR(ep->mem_res->block_base);
147
148 return 0;
149}
150
151static int exynos5440_pcie_get_clk_resources(struct exynos_pcie *ep)
152{
153 struct device *dev = ep->pp.dev;
154
155 ep->clk_res = devm_kzalloc(dev, sizeof(*ep->clk_res), GFP_KERNEL);
156 if (!ep->clk_res)
157 return -ENOMEM;
158
159 ep->clk_res->clk = devm_clk_get(dev, "pcie");
160 if (IS_ERR(ep->clk_res->clk)) {
161 dev_err(dev, "Failed to get pcie rc clock\n");
162 return PTR_ERR(ep->clk_res->clk);
163 }
164
165 ep->clk_res->bus_clk = devm_clk_get(dev, "pcie_bus");
166 if (IS_ERR(ep->clk_res->bus_clk)) {
167 dev_err(dev, "Failed to get pcie bus clock\n");
168 return PTR_ERR(ep->clk_res->bus_clk);
169 }
170
171 return 0;
172}
173
174static int exynos5440_pcie_init_clk_resources(struct exynos_pcie *ep)
175{
176 struct device *dev = ep->pp.dev;
177 int ret;
178
179 ret = clk_prepare_enable(ep->clk_res->clk);
180 if (ret) {
181 dev_err(dev, "cannot enable pcie rc clock");
182 return ret;
183 }
184
185 ret = clk_prepare_enable(ep->clk_res->bus_clk);
186 if (ret) {
187 dev_err(dev, "cannot enable pcie bus clock");
188 goto err_bus_clk;
189 }
190
191 return 0;
192
193err_bus_clk:
194 clk_disable_unprepare(ep->clk_res->clk);
195
196 return ret;
197}
198
199static void exynos5440_pcie_deinit_clk_resources(struct exynos_pcie *ep)
200{
201 clk_disable_unprepare(ep->clk_res->bus_clk);
202 clk_disable_unprepare(ep->clk_res->clk);
203}
204
205static const struct exynos_pcie_ops exynos5440_pcie_ops = {
206 .get_mem_resources = exynos5440_pcie_get_mem_resources,
207 .get_clk_resources = exynos5440_pcie_get_clk_resources,
208 .init_clk_resources = exynos5440_pcie_init_clk_resources,
209 .deinit_clk_resources = exynos5440_pcie_deinit_clk_resources,
210};
211
Jaehoon Chungd6da7d92017-01-16 15:31:35 +0900212static void exynos_pcie_writel(void __iomem *base, u32 val, u32 reg)
Seungwon Jeon058dd012013-08-29 21:35:56 +0900213{
Jaehoon Chungd6da7d92017-01-16 15:31:35 +0900214 writel(val, base + reg);
Seungwon Jeon058dd012013-08-29 21:35:56 +0900215}
216
Jaehoon Chungd6da7d92017-01-16 15:31:35 +0900217static u32 exynos_pcie_readl(void __iomem *base, u32 reg)
Seungwon Jeon058dd012013-08-29 21:35:56 +0900218{
Jaehoon Chungd6da7d92017-01-16 15:31:35 +0900219 return readl(base + reg);
Seungwon Jeon058dd012013-08-29 21:35:56 +0900220}
221
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900222static void exynos_pcie_sideband_dbi_w_mode(struct exynos_pcie *ep, bool on)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900223{
224 u32 val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900225
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530226 val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_ELBI_SLV_AWMISC);
Jaehoon Chung92004a062017-01-16 15:31:38 +0900227 if (on)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900228 val |= PCIE_ELBI_SLV_DBI_ENABLE;
Jaehoon Chung92004a062017-01-16 15:31:38 +0900229 else
Jingoo Han4b1ced82013-07-31 17:14:10 +0900230 val &= ~PCIE_ELBI_SLV_DBI_ENABLE;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530231 exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_ELBI_SLV_AWMISC);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900232}
233
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900234static void exynos_pcie_sideband_dbi_r_mode(struct exynos_pcie *ep, bool on)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900235{
236 u32 val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900237
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530238 val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_ELBI_SLV_ARMISC);
Jaehoon Chung92004a062017-01-16 15:31:38 +0900239 if (on)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900240 val |= PCIE_ELBI_SLV_DBI_ENABLE;
Jaehoon Chung92004a062017-01-16 15:31:38 +0900241 else
Jingoo Han4b1ced82013-07-31 17:14:10 +0900242 val &= ~PCIE_ELBI_SLV_DBI_ENABLE;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530243 exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_ELBI_SLV_ARMISC);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900244}
245
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900246static void exynos_pcie_assert_core_reset(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900247{
248 u32 val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900249
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530250 val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_CORE_RESET);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900251 val &= ~PCIE_CORE_RESET_ENABLE;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530252 exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_CORE_RESET);
253 exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_PWR_RESET);
254 exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_STICKY_RESET);
255 exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_NONSTICKY_RESET);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900256}
257
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900258static void exynos_pcie_deassert_core_reset(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900259{
260 u32 val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900261
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530262 val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_CORE_RESET);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900263 val |= PCIE_CORE_RESET_ENABLE;
Seungwon Jeon058dd012013-08-29 21:35:56 +0900264
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530265 exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_CORE_RESET);
266 exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_STICKY_RESET);
267 exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_NONSTICKY_RESET);
268 exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_APP_INIT_RESET);
269 exynos_pcie_writel(ep->mem_res->elbi_base, 0, PCIE_APP_INIT_RESET);
270 exynos_pcie_writel(ep->mem_res->block_base, 1, PCIE_PHY_MAC_RESET);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900271}
272
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900273static void exynos_pcie_assert_phy_reset(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900274{
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530275 exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_MAC_RESET);
276 exynos_pcie_writel(ep->mem_res->block_base, 1, PCIE_PHY_GLOBAL_RESET);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900277}
278
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900279static void exynos_pcie_deassert_phy_reset(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900280{
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530281 exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_GLOBAL_RESET);
282 exynos_pcie_writel(ep->mem_res->elbi_base, 1, PCIE_PWR_RESET);
283 exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_COMMON_RESET);
284 exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_CMN_REG);
285 exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_TRSVREG_RESET);
286 exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_TRSV_RESET);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900287}
288
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900289static void exynos_pcie_power_on_phy(struct exynos_pcie *ep)
Jingoo Hanf62b8782013-09-06 17:21:45 +0900290{
291 u32 val;
Jingoo Hanf62b8782013-09-06 17:21:45 +0900292
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530293 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_COMMON_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900294 val &= ~PCIE_PHY_COMMON_PD_CMN;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530295 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_COMMON_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900296
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530297 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV0_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900298 val &= ~PCIE_PHY_TRSV0_PD_TSV;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530299 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV0_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900300
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530301 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV1_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900302 val &= ~PCIE_PHY_TRSV1_PD_TSV;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530303 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV1_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900304
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530305 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV2_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900306 val &= ~PCIE_PHY_TRSV2_PD_TSV;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530307 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV2_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900308
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530309 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV3_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900310 val &= ~PCIE_PHY_TRSV3_PD_TSV;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530311 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV3_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900312}
313
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900314static void exynos_pcie_power_off_phy(struct exynos_pcie *ep)
Jingoo Hanf62b8782013-09-06 17:21:45 +0900315{
316 u32 val;
Jingoo Hanf62b8782013-09-06 17:21:45 +0900317
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530318 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_COMMON_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900319 val |= PCIE_PHY_COMMON_PD_CMN;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530320 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_COMMON_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900321
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530322 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV0_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900323 val |= PCIE_PHY_TRSV0_PD_TSV;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530324 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV0_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900325
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530326 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV1_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900327 val |= PCIE_PHY_TRSV1_PD_TSV;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530328 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV1_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900329
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530330 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV2_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900331 val |= PCIE_PHY_TRSV2_PD_TSV;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530332 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV2_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900333
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530334 val = exynos_pcie_readl(ep->mem_res->phy_base, PCIE_PHY_TRSV3_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900335 val |= PCIE_PHY_TRSV3_PD_TSV;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530336 exynos_pcie_writel(ep->mem_res->phy_base, val, PCIE_PHY_TRSV3_POWER);
Jingoo Hanf62b8782013-09-06 17:21:45 +0900337}
338
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900339static void exynos_pcie_init_phy(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900340{
Jingoo Han4b1ced82013-07-31 17:14:10 +0900341 /* DCC feedback control off */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530342 exynos_pcie_writel(ep->mem_res->phy_base, 0x29, PCIE_PHY_DCC_FEEDBACK);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900343
344 /* set TX/RX impedance */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530345 exynos_pcie_writel(ep->mem_res->phy_base, 0xd5, PCIE_PHY_IMPEDANCE);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900346
347 /* set 50Mhz PHY clock */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530348 exynos_pcie_writel(ep->mem_res->phy_base, 0x14, PCIE_PHY_PLL_DIV_0);
349 exynos_pcie_writel(ep->mem_res->phy_base, 0x12, PCIE_PHY_PLL_DIV_1);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900350
351 /* set TX Differential output for lane 0 */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530352 exynos_pcie_writel(ep->mem_res->phy_base, 0x7f, PCIE_PHY_TRSV0_DRV_LVL);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900353
354 /* set TX Pre-emphasis Level Control for lane 0 to minimum */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530355 exynos_pcie_writel(ep->mem_res->phy_base, 0x0, PCIE_PHY_TRSV0_EMP_LVL);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900356
357 /* set RX clock and data recovery bandwidth */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530358 exynos_pcie_writel(ep->mem_res->phy_base, 0xe7, PCIE_PHY_PLL_BIAS);
359 exynos_pcie_writel(ep->mem_res->phy_base, 0x82, PCIE_PHY_TRSV0_RXCDR);
360 exynos_pcie_writel(ep->mem_res->phy_base, 0x82, PCIE_PHY_TRSV1_RXCDR);
361 exynos_pcie_writel(ep->mem_res->phy_base, 0x82, PCIE_PHY_TRSV2_RXCDR);
362 exynos_pcie_writel(ep->mem_res->phy_base, 0x82, PCIE_PHY_TRSV3_RXCDR);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900363
364 /* change TX Pre-emphasis Level Control for lanes */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530365 exynos_pcie_writel(ep->mem_res->phy_base, 0x39, PCIE_PHY_TRSV0_EMP_LVL);
366 exynos_pcie_writel(ep->mem_res->phy_base, 0x39, PCIE_PHY_TRSV1_EMP_LVL);
367 exynos_pcie_writel(ep->mem_res->phy_base, 0x39, PCIE_PHY_TRSV2_EMP_LVL);
368 exynos_pcie_writel(ep->mem_res->phy_base, 0x39, PCIE_PHY_TRSV3_EMP_LVL);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900369
370 /* set LVCC */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530371 exynos_pcie_writel(ep->mem_res->phy_base, 0x20, PCIE_PHY_TRSV0_LVCC);
372 exynos_pcie_writel(ep->mem_res->phy_base, 0xa0, PCIE_PHY_TRSV1_LVCC);
373 exynos_pcie_writel(ep->mem_res->phy_base, 0xa0, PCIE_PHY_TRSV2_LVCC);
374 exynos_pcie_writel(ep->mem_res->phy_base, 0xa0, PCIE_PHY_TRSV3_LVCC);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900375}
376
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900377static void exynos_pcie_assert_reset(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900378{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900379 struct pcie_port *pp = &ep->pp;
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500380 struct device *dev = pp->dev;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900381
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900382 if (ep->reset_gpio >= 0)
383 devm_gpio_request_one(dev, ep->reset_gpio,
Jingoo Han4b1ced82013-07-31 17:14:10 +0900384 GPIOF_OUT_INIT_HIGH, "RESET");
Jingoo Han4b1ced82013-07-31 17:14:10 +0900385}
386
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900387static int exynos_pcie_establish_link(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900388{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900389 struct pcie_port *pp = &ep->pp;
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500390 struct device *dev = pp->dev;
Bjorn Helgaas6cbb2472015-06-02 16:47:17 -0500391 u32 val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900392
393 if (dw_pcie_link_up(pp)) {
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500394 dev_err(dev, "Link already up\n");
Jingoo Han4b1ced82013-07-31 17:14:10 +0900395 return 0;
396 }
397
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900398 exynos_pcie_assert_core_reset(ep);
399 exynos_pcie_assert_phy_reset(ep);
400 exynos_pcie_deassert_phy_reset(ep);
401 exynos_pcie_power_on_phy(ep);
402 exynos_pcie_init_phy(ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900403
404 /* pulse for common reset */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530405 exynos_pcie_writel(ep->mem_res->block_base, 1, PCIE_PHY_COMMON_RESET);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900406 udelay(500);
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530407 exynos_pcie_writel(ep->mem_res->block_base, 0, PCIE_PHY_COMMON_RESET);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900408
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900409 exynos_pcie_deassert_core_reset(ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900410 dw_pcie_setup_rc(pp);
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900411 exynos_pcie_assert_reset(ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900412
413 /* assert LTSSM enable */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530414 exynos_pcie_writel(ep->mem_res->elbi_base, PCIE_ELBI_LTSSM_ENABLE,
Seungwon Jeon058dd012013-08-29 21:35:56 +0900415 PCIE_APP_LTSSM_ENABLE);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900416
417 /* check if the link is up or not */
Joao Pinto886bc5c2016-03-10 14:44:35 -0600418 if (!dw_pcie_wait_for_link(pp))
419 return 0;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900420
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530421 while (exynos_pcie_readl(ep->mem_res->phy_base,
422 PCIE_PHY_PLL_LOCKED) == 0) {
423 val = exynos_pcie_readl(ep->mem_res->block_base,
424 PCIE_PHY_PLL_LOCKED);
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500425 dev_info(dev, "PLL Locked: 0x%x\n", val);
Bjorn Helgaas6cbb2472015-06-02 16:47:17 -0500426 }
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900427 exynos_pcie_power_off_phy(ep);
Joao Pinto886bc5c2016-03-10 14:44:35 -0600428 return -ETIMEDOUT;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900429}
430
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900431static void exynos_pcie_clear_irq_pulse(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900432{
433 u32 val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900434
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530435 val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_IRQ_PULSE);
436 exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_IRQ_PULSE);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900437}
438
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900439static void exynos_pcie_enable_irq_pulse(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900440{
441 u32 val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900442
443 /* enable INTX interrupt */
444 val = IRQ_INTA_ASSERT | IRQ_INTB_ASSERT |
Jaehoon Chung01d06a92015-03-25 14:13:12 +0900445 IRQ_INTC_ASSERT | IRQ_INTD_ASSERT;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530446 exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_IRQ_EN_PULSE);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900447}
448
449static irqreturn_t exynos_pcie_irq_handler(int irq, void *arg)
450{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900451 struct exynos_pcie *ep = arg;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900452
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900453 exynos_pcie_clear_irq_pulse(ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900454 return IRQ_HANDLED;
455}
456
Jingoo Hanf342d942013-09-06 15:54:59 +0900457static irqreturn_t exynos_pcie_msi_irq_handler(int irq, void *arg)
458{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900459 struct exynos_pcie *ep = arg;
460 struct pcie_port *pp = &ep->pp;
Jingoo Hanf342d942013-09-06 15:54:59 +0900461
Lucas Stach7f4f16e2014-03-28 17:52:58 +0100462 return dw_handle_msi_irq(pp);
Jingoo Hanf342d942013-09-06 15:54:59 +0900463}
464
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900465static void exynos_pcie_msi_init(struct exynos_pcie *ep)
Jingoo Hanf342d942013-09-06 15:54:59 +0900466{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900467 struct pcie_port *pp = &ep->pp;
Jingoo Hanf342d942013-09-06 15:54:59 +0900468 u32 val;
Jingoo Hanf342d942013-09-06 15:54:59 +0900469
470 dw_pcie_msi_init(pp);
471
472 /* enable MSI interrupt */
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530473 val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_IRQ_EN_LEVEL);
Jingoo Hanf342d942013-09-06 15:54:59 +0900474 val |= IRQ_MSI_ENABLE;
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530475 exynos_pcie_writel(ep->mem_res->elbi_base, val, PCIE_IRQ_EN_LEVEL);
Jingoo Hanf342d942013-09-06 15:54:59 +0900476}
477
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900478static void exynos_pcie_enable_interrupts(struct exynos_pcie *ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900479{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900480 exynos_pcie_enable_irq_pulse(ep);
Jingoo Hanf342d942013-09-06 15:54:59 +0900481
482 if (IS_ENABLED(CONFIG_PCI_MSI))
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900483 exynos_pcie_msi_init(ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900484}
485
Bjorn Helgaas53e5bff12016-10-10 07:50:07 -0500486static u32 exynos_pcie_readl_rc(struct pcie_port *pp, u32 reg)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900487{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900488 struct exynos_pcie *ep = to_exynos_pcie(pp);
Bjorn Helgaas446fc232016-08-17 14:17:58 -0500489 u32 val;
490
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900491 exynos_pcie_sideband_dbi_r_mode(ep, true);
Bjorn Helgaas7e00dfd2016-10-06 13:25:46 -0500492 val = readl(pp->dbi_base + reg);
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900493 exynos_pcie_sideband_dbi_r_mode(ep, false);
Bjorn Helgaas446fc232016-08-17 14:17:58 -0500494 return val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900495}
496
Bjorn Helgaas53e5bff12016-10-10 07:50:07 -0500497static void exynos_pcie_writel_rc(struct pcie_port *pp, u32 reg, u32 val)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900498{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900499 struct exynos_pcie *ep = to_exynos_pcie(pp);
Bjorn Helgaascc08e822016-10-06 13:33:39 -0500500
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900501 exynos_pcie_sideband_dbi_w_mode(ep, true);
Bjorn Helgaas7e00dfd2016-10-06 13:25:46 -0500502 writel(val, pp->dbi_base + reg);
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900503 exynos_pcie_sideband_dbi_w_mode(ep, false);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900504}
505
506static int exynos_pcie_rd_own_conf(struct pcie_port *pp, int where, int size,
507 u32 *val)
508{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900509 struct exynos_pcie *ep = to_exynos_pcie(pp);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900510 int ret;
511
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900512 exynos_pcie_sideband_dbi_r_mode(ep, true);
Gabriele Paoloni4c458522015-10-08 14:27:48 -0500513 ret = dw_pcie_cfg_read(pp->dbi_base + where, size, val);
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900514 exynos_pcie_sideband_dbi_r_mode(ep, false);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900515 return ret;
516}
517
518static int exynos_pcie_wr_own_conf(struct pcie_port *pp, int where, int size,
519 u32 val)
520{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900521 struct exynos_pcie *ep = to_exynos_pcie(pp);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900522 int ret;
523
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900524 exynos_pcie_sideband_dbi_w_mode(ep, true);
Gabriele Paoloni4c458522015-10-08 14:27:48 -0500525 ret = dw_pcie_cfg_write(pp->dbi_base + where, size, val);
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900526 exynos_pcie_sideband_dbi_w_mode(ep, false);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900527 return ret;
528}
529
530static int exynos_pcie_link_up(struct pcie_port *pp)
531{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900532 struct exynos_pcie *ep = to_exynos_pcie(pp);
Bjorn Helgaascc08e822016-10-06 13:33:39 -0500533 u32 val;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900534
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530535 val = exynos_pcie_readl(ep->mem_res->elbi_base, PCIE_ELBI_RDLH_LINKUP);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900536 if (val == PCIE_ELBI_LTSSM_ENABLE)
537 return 1;
538
539 return 0;
540}
541
542static void exynos_pcie_host_init(struct pcie_port *pp)
543{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900544 struct exynos_pcie *ep = to_exynos_pcie(pp);
Bjorn Helgaascc08e822016-10-06 13:33:39 -0500545
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900546 exynos_pcie_establish_link(ep);
547 exynos_pcie_enable_interrupts(ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900548}
549
550static struct pcie_host_ops exynos_pcie_host_ops = {
551 .readl_rc = exynos_pcie_readl_rc,
552 .writel_rc = exynos_pcie_writel_rc,
553 .rd_own_conf = exynos_pcie_rd_own_conf,
554 .wr_own_conf = exynos_pcie_wr_own_conf,
555 .link_up = exynos_pcie_link_up,
556 .host_init = exynos_pcie_host_init,
557};
558
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900559static int __init exynos_add_pcie_port(struct exynos_pcie *ep,
Jingoo Han70b3e892014-10-22 13:58:49 +0900560 struct platform_device *pdev)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900561{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900562 struct pcie_port *pp = &ep->pp;
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500563 struct device *dev = pp->dev;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900564 int ret;
565
566 pp->irq = platform_get_irq(pdev, 1);
567 if (!pp->irq) {
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500568 dev_err(dev, "failed to get irq\n");
Jingoo Han4b1ced82013-07-31 17:14:10 +0900569 return -ENODEV;
570 }
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500571 ret = devm_request_irq(dev, pp->irq, exynos_pcie_irq_handler,
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900572 IRQF_SHARED, "exynos-pcie", ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900573 if (ret) {
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500574 dev_err(dev, "failed to request irq\n");
Jingoo Han4b1ced82013-07-31 17:14:10 +0900575 return ret;
576 }
577
Jingoo Hanf342d942013-09-06 15:54:59 +0900578 if (IS_ENABLED(CONFIG_PCI_MSI)) {
579 pp->msi_irq = platform_get_irq(pdev, 0);
580 if (!pp->msi_irq) {
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500581 dev_err(dev, "failed to get msi irq\n");
Jingoo Hanf342d942013-09-06 15:54:59 +0900582 return -ENODEV;
583 }
584
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500585 ret = devm_request_irq(dev, pp->msi_irq,
Jingoo Hanf342d942013-09-06 15:54:59 +0900586 exynos_pcie_msi_irq_handler,
Grygorii Strashko8ff0ef92015-12-10 21:18:20 +0200587 IRQF_SHARED | IRQF_NO_THREAD,
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900588 "exynos-pcie", ep);
Jingoo Hanf342d942013-09-06 15:54:59 +0900589 if (ret) {
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500590 dev_err(dev, "failed to request msi irq\n");
Jingoo Hanf342d942013-09-06 15:54:59 +0900591 return ret;
592 }
593 }
594
Jingoo Han4b1ced82013-07-31 17:14:10 +0900595 pp->root_bus_nr = -1;
596 pp->ops = &exynos_pcie_host_ops;
597
Jingoo Han4b1ced82013-07-31 17:14:10 +0900598 ret = dw_pcie_host_init(pp);
599 if (ret) {
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500600 dev_err(dev, "failed to initialize host\n");
Jingoo Han4b1ced82013-07-31 17:14:10 +0900601 return ret;
602 }
603
604 return 0;
605}
606
607static int __init exynos_pcie_probe(struct platform_device *pdev)
608{
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500609 struct device *dev = &pdev->dev;
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900610 struct exynos_pcie *ep;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900611 struct pcie_port *pp;
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500612 struct device_node *np = dev->of_node;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900613 int ret;
614
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900615 ep = devm_kzalloc(dev, sizeof(*ep), GFP_KERNEL);
616 if (!ep)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900617 return -ENOMEM;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900618
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900619 pp = &ep->pp;
Bjorn Helgaasfae68d62016-10-06 13:33:41 -0500620 pp->dev = dev;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900621
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530622 ep->ops = (const struct exynos_pcie_ops *)
623 of_device_get_match_data(dev);
624
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900625 ep->reset_gpio = of_get_named_gpio(np, "reset-gpio", 0);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900626
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530627 if (ep->ops && ep->ops->get_mem_resources) {
628 ret = ep->ops->get_mem_resources(pdev, ep);
629 if (ret)
630 return ret;
Wei Yongjunf8db3c92013-09-29 10:29:11 +0800631 }
Jingoo Han4b1ced82013-07-31 17:14:10 +0900632
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530633 if (ep->ops && ep->ops->get_clk_resources) {
634 ret = ep->ops->get_clk_resources(ep);
635 if (ret)
636 return ret;
637 ret = ep->ops->init_clk_resources(ep);
638 if (ret)
639 return ret;
Wei Yongjunf8db3c92013-09-29 10:29:11 +0800640 }
Jingoo Han4b1ced82013-07-31 17:14:10 +0900641
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900642 ret = exynos_add_pcie_port(ep, pdev);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900643 if (ret < 0)
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530644 goto fail_probe;
Jingoo Han4b1ced82013-07-31 17:14:10 +0900645
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900646 platform_set_drvdata(pdev, ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900647 return 0;
648
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530649fail_probe:
650 if (ep->ops && ep->ops->deinit_clk_resources)
651 ep->ops->deinit_clk_resources(ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900652 return ret;
653}
654
655static int __exit exynos_pcie_remove(struct platform_device *pdev)
656{
Jaehoon Chung4e0a90b382017-01-16 15:31:34 +0900657 struct exynos_pcie *ep = platform_get_drvdata(pdev);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900658
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530659 if (ep->ops && ep->ops->deinit_clk_resources)
660 ep->ops->deinit_clk_resources(ep);
Jingoo Han4b1ced82013-07-31 17:14:10 +0900661
662 return 0;
663}
664
665static const struct of_device_id exynos_pcie_of_match[] = {
Niyas Ahmed S T32784782017-02-01 10:13:06 +0530666 {
667 .compatible = "samsung,exynos5440-pcie",
668 .data = &exynos5440_pcie_ops
669 },
Jingoo Han4b1ced82013-07-31 17:14:10 +0900670 {},
671};
Jingoo Han4b1ced82013-07-31 17:14:10 +0900672
673static struct platform_driver exynos_pcie_driver = {
674 .remove = __exit_p(exynos_pcie_remove),
675 .driver = {
676 .name = "exynos-pcie",
Sachin Kamateb363092013-10-21 14:36:43 +0530677 .of_match_table = exynos_pcie_of_match,
Jingoo Han4b1ced82013-07-31 17:14:10 +0900678 },
679};
680
681/* Exynos PCIe driver does not allow module unload */
682
Jingoo Han70b3e892014-10-22 13:58:49 +0900683static int __init exynos_pcie_init(void)
Jingoo Han4b1ced82013-07-31 17:14:10 +0900684{
685 return platform_driver_probe(&exynos_pcie_driver, exynos_pcie_probe);
686}
Jingoo Han70b3e892014-10-22 13:58:49 +0900687subsys_initcall(exynos_pcie_init);