lantiq: add patches headers
[openwrt/staging/jow.git] / target / linux / lantiq / patches-5.15 / 0151-lantiq-ifxmips_pcie-use-of.patch
1 From 1d1885f4a7abd7272f47b835b03d8662fb981d19 Mon Sep 17 00:00:00 2001
2 From: Eddi De Pieri <eddi@depieri.net>
3 Date: Tue, 14 Oct 2014 11:04:00 +0000
4 Subject: [PATCH] MIPS: lantiq: ifxmips_pcie: use of
5
6 Signed-off-by: Eddi De Pieri <eddi@depieri.net>
7 ---
8 arch/mips/pci/Makefile | 2 +-
9 arch/mips/pci/ifxmips_pcie.c | 151 +++++++++++++++++++++++++++----
10 arch/mips/pci/ifxmips_pcie_vr9.h | 105 ---------------------
11 3 files changed, 133 insertions(+), 125 deletions(-)
12
13 --- a/arch/mips/pci/Makefile
14 +++ b/arch/mips/pci/Makefile
15 @@ -43,7 +43,7 @@ obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o
16 obj-$(CONFIG_SOC_MT7620) += pci-mt7620.o
17 obj-$(CONFIG_SOC_RT288X) += pci-rt2880.o
18 obj-$(CONFIG_SOC_RT3883) += pci-rt3883.o
19 -obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie_phy.o ifxmips_pcie.o fixup-lantiq-pcie.o
20 +obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie.o fixup-lantiq-pcie.o
21 obj-$(CONFIG_PCIE_LANTIQ_MSI) += pcie-lantiq-msi.o
22 obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
23 obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
24 --- a/arch/mips/pci/ifxmips_pcie.c
25 +++ b/arch/mips/pci/ifxmips_pcie.c
26 @@ -16,8 +16,15 @@
27 #include <asm/paccess.h>
28 #include <linux/pci.h>
29 #include <linux/pci_regs.h>
30 +#include <linux/phy/phy.h>
31 +#include <linux/regmap.h>
32 +#include <linux/reset.h>
33 +#include <linux/mfd/syscon.h>
34 #include <linux/module.h>
35
36 +#include <linux/of_gpio.h>
37 +#include <linux/of_platform.h>
38 +
39 #include "ifxmips_pcie.h"
40 #include "ifxmips_pcie_reg.h"
41
42 @@ -40,6 +47,10 @@
43 static DEFINE_SPINLOCK(ifx_pcie_lock);
44
45 u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
46 +static int pcie_reset_gpio;
47 +static struct phy *ltq_pcie_phy;
48 +static struct reset_control *ltq_pcie_reset;
49 +static struct regmap *ltq_rcu_regmap;
50
51 static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
52 {
53 @@ -82,6 +93,22 @@ void ifx_pcie_debug(const char *fmt, ...
54 printk("%s", buf);
55 }
56
57 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
58 +{
59 + gpio_direction_output(pcie_reset_gpio, 1);
60 + gpio_set_value(pcie_reset_gpio, 1);
61 +}
62 +
63 +static inline void pcie_device_rst_assert(int pcie_port)
64 +{
65 + gpio_set_value(pcie_reset_gpio, 0);
66 +}
67 +
68 +static inline void pcie_device_rst_deassert(int pcie_port)
69 +{
70 + mdelay(100);
71 + gpio_direction_output(pcie_reset_gpio, 1);
72 +}
73
74 static inline int pcie_ltssm_enable(int pcie_port)
75 {
76 @@ -988,10 +1015,22 @@ int ifx_pcie_bios_plat_dev_init(struct
77 static int
78 pcie_rc_initialize(int pcie_port)
79 {
80 - int i;
81 + int i, ret;
82 #define IFX_PCIE_PHY_LOOP_CNT 5
83
84 - pcie_rcu_endian_setup(pcie_port);
85 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_M,
86 + IFX_RCU_AHB_BE_PCIE_M);
87 +
88 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
89 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
90 + IFX_RCU_AHB_BE_PCIE_S);
91 +#else
92 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
93 + 0x0);
94 +#endif
95 +
96 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_M,
97 + 0x0);
98
99 pcie_ep_gpio_rst_init(pcie_port);
100
101 @@ -1000,26 +1039,21 @@ pcie_rc_initialize(int pcie_port)
102 * reset PCIe PHY will solve this issue
103 */
104 for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
105 - /* Disable PCIe PHY Analog part for sanity check */
106 - pcie_phy_pmu_disable(pcie_port);
107 -
108 - pcie_phy_rst_assert(pcie_port);
109 - pcie_phy_rst_deassert(pcie_port);
110 -
111 - /* Make sure PHY PLL is stable */
112 - udelay(20);
113 -
114 - /* PCIe Core reset enabled, low active, sw programmed */
115 - pcie_core_rst_assert(pcie_port);
116 + ret = phy_init(ltq_pcie_phy);
117 + if (ret)
118 + continue;
119
120 /* Put PCIe EP in reset status */
121 pcie_device_rst_assert(pcie_port);
122
123 - /* PCI PHY & Core reset disabled, high active, sw programmed */
124 - pcie_core_rst_deassert(pcie_port);
125 + udelay(1);
126 + reset_control_deassert(ltq_pcie_reset);
127
128 - /* Already in a quiet state, program PLL, enable PHY, check ready bit */
129 - pcie_phy_clock_mode_setup(pcie_port);
130 + ret = phy_power_on(ltq_pcie_phy);
131 + if (ret) {
132 + phy_exit(ltq_pcie_phy);
133 + continue;
134 + }
135
136 /* Enable PCIe PHY and Clock */
137 pcie_core_pmu_setup(pcie_port);
138 @@ -1035,6 +1069,10 @@ pcie_rc_initialize(int pcie_port)
139 /* Once link is up, break out */
140 if (pcie_app_loigc_setup(pcie_port) == 0)
141 break;
142 +
143 + phy_power_off(ltq_pcie_phy);
144 + reset_control_assert(ltq_pcie_reset);
145 + phy_exit(ltq_pcie_phy);
146 }
147 if (i >= IFX_PCIE_PHY_LOOP_CNT) {
148 printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
149 @@ -1045,17 +1083,67 @@ pcie_rc_initialize(int pcie_port)
150 return 0;
151 }
152
153 -static int __init ifx_pcie_bios_init(void)
154 +static int ifx_pcie_bios_probe(struct platform_device *pdev)
155 {
156 + struct device_node *node = pdev->dev.of_node;
157 void __iomem *io_map_base;
158 int pcie_port;
159 int startup_port;
160 + struct device_node *np;
161 + struct pci_bus *bus;
162 +
163 + /*
164 + * In case a PCI device is physical present, the Lantiq PCI driver need
165 + * to be loaded prior to the Lantiq PCIe driver. Otherwise none of them
166 + * will work.
167 + *
168 + * In case the lantiq PCI driver is enabled in the device tree, check if
169 + * a PCI bus (hopefully the one of the Lantiq PCI driver one) is already
170 + * registered.
171 + *
172 + * It will fail if there is another PCI controller, this controller is
173 + * registered before the Lantiq PCIe driver is probe and the lantiq PCI
174 + */
175 + np = of_find_compatible_node(NULL, NULL, "lantiq,pci-xway");
176 +
177 + if (of_device_is_available(np)) {
178 + bus = pci_find_next_bus(bus);
179 +
180 + if (!bus)
181 + return -EPROBE_DEFER;
182 + }
183
184 /* Enable AHB Master/ Slave */
185 pcie_ahb_pmu_setup();
186
187 startup_port = IFX_PCIE_PORT0;
188 -
189 +
190 + ltq_pcie_phy = devm_phy_get(&pdev->dev, "pcie");
191 + if (IS_ERR(ltq_pcie_phy)) {
192 + dev_err(&pdev->dev, "failed to get the PCIe PHY\n");
193 + return PTR_ERR(ltq_pcie_phy);
194 + }
195 +
196 + ltq_pcie_reset = devm_reset_control_get_shared(&pdev->dev, NULL);
197 + if (IS_ERR(ltq_pcie_reset)) {
198 + dev_err(&pdev->dev, "failed to get the PCIe reset line\n");
199 + return PTR_ERR(ltq_pcie_reset);
200 + }
201 +
202 + ltq_rcu_regmap = syscon_regmap_lookup_by_phandle(node, "lantiq,rcu");
203 + if (IS_ERR(ltq_rcu_regmap))
204 + return PTR_ERR(ltq_rcu_regmap);
205 +
206 + pcie_reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
207 + if (gpio_is_valid(pcie_reset_gpio)) {
208 + int ret = devm_gpio_request(&pdev->dev, pcie_reset_gpio, "pcie-reset");
209 + if (ret) {
210 + dev_err(&pdev->dev, "failed to request gpio %d\n", pcie_reset_gpio);
211 + return ret;
212 + }
213 + gpio_direction_output(pcie_reset_gpio, 1);
214 + }
215 +
216 for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
217 if (pcie_rc_initialize(pcie_port) == 0) {
218 IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: ifx_pcie_cfg_base 0x%p\n",
219 @@ -1067,6 +1155,7 @@ static int __init ifx_pcie_bios_init(voi
220 return -ENOMEM;
221 }
222 ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
223 + pci_load_of_ranges(&ifx_pcie_controller[pcie_port].pcic, node);
224
225 register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
226 /* XXX, clear error status */
227 @@ -1083,6 +1172,30 @@ static int __init ifx_pcie_bios_init(voi
228
229 return 0;
230 }
231 +
232 +static const struct of_device_id ifxmips_pcie_match[] = {
233 + { .compatible = "lantiq,pcie-xrx200" },
234 + {},
235 +};
236 +MODULE_DEVICE_TABLE(of, ifxmips_pcie_match);
237 +
238 +static struct platform_driver ltq_pci_driver = {
239 + .probe = ifx_pcie_bios_probe,
240 + .driver = {
241 + .name = "pcie-xrx200",
242 + .owner = THIS_MODULE,
243 + .of_match_table = ifxmips_pcie_match,
244 + },
245 +};
246 +
247 +int __init ifx_pcie_bios_init(void)
248 +{
249 + int ret = platform_driver_register(&ltq_pci_driver);
250 + if (ret)
251 + pr_info("pcie-xrx200: Error registering platform driver!");
252 + return ret;
253 +}
254 +
255 arch_initcall(ifx_pcie_bios_init);
256
257 MODULE_LICENSE("GPL");
258 --- a/arch/mips/pci/ifxmips_pcie_vr9.h
259 +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
260 @@ -22,8 +22,6 @@
261 #include <linux/gpio.h>
262 #include <lantiq_soc.h>
263
264 -#define IFX_PCIE_GPIO_RESET 494
265 -
266 #define IFX_REG_R32 ltq_r32
267 #define IFX_REG_W32 ltq_w32
268 #define CONFIG_IFX_PCIE_HW_SWAP
269 @@ -53,21 +51,6 @@
270 #define OUT ((volatile u32*)(IFX_GPIO + 0x0070))
271
272
273 -static inline void pcie_ep_gpio_rst_init(int pcie_port)
274 -{
275 -
276 - gpio_request(IFX_PCIE_GPIO_RESET, "pcie-reset");
277 - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
278 - gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
279 -
280 -/* ifx_gpio_pin_reserve(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
281 - ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
282 - ifx_gpio_dir_out_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
283 - ifx_gpio_altsel0_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
284 - ifx_gpio_altsel1_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
285 - ifx_gpio_open_drain_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);*/
286 -}
287 -
288 static inline void pcie_ahb_pmu_setup(void)
289 {
290 /* Enable AHB bus master/slave */
291 @@ -79,24 +62,6 @@ static inline void pcie_ahb_pmu_setup(vo
292 //AHBS_PMU_SETUP(IFX_PMU_ENABLE);
293 }
294
295 -static inline void pcie_rcu_endian_setup(int pcie_port)
296 -{
297 - u32 reg;
298 -
299 - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
300 -#ifdef CONFIG_IFX_PCIE_HW_SWAP
301 - reg |= IFX_RCU_AHB_BE_PCIE_M;
302 - reg |= IFX_RCU_AHB_BE_PCIE_S;
303 - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
304 -#else
305 - reg |= IFX_RCU_AHB_BE_PCIE_M;
306 - reg &= ~IFX_RCU_AHB_BE_PCIE_S;
307 - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
308 -#endif /* CONFIG_IFX_PCIE_HW_SWAP */
309 - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
310 - IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
311 -}
312 -
313 static inline void pcie_phy_pmu_enable(int pcie_port)
314 {
315 struct clk *clk;
316 @@ -115,17 +80,6 @@ static inline void pcie_phy_pmu_disable(
317 // PCIE_PHY_PMU_SETUP(IFX_PMU_DISABLE);
318 }
319
320 -static inline void pcie_pdi_big_endian(int pcie_port)
321 -{
322 - u32 reg;
323 -
324 - /* SRAM2PDI endianness control. */
325 - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
326 - /* Config AHB->PCIe and PDI endianness */
327 - reg |= IFX_RCU_AHB_BE_PCIE_PDI;
328 - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
329 -}
330 -
331 static inline void pcie_pdi_pmu_enable(int pcie_port)
332 {
333 /* Enable PDI to access PCIe PHY register */
334 @@ -135,65 +89,6 @@ static inline void pcie_pdi_pmu_enable(i
335 //PDI_PMU_SETUP(IFX_PMU_ENABLE);
336 }
337
338 -static inline void pcie_core_rst_assert(int pcie_port)
339 -{
340 - u32 reg;
341 -
342 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
343 -
344 - /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
345 - reg |= 0x00400000;
346 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
347 -}
348 -
349 -static inline void pcie_core_rst_deassert(int pcie_port)
350 -{
351 - u32 reg;
352 -
353 - /* Make sure one micro-second delay */
354 - udelay(1);
355 -
356 - /* Reset PCIe PHY & Core, bit 22 */
357 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
358 - reg &= ~0x00400000;
359 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
360 -}
361 -
362 -static inline void pcie_phy_rst_assert(int pcie_port)
363 -{
364 - u32 reg;
365 -
366 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
367 - reg |= 0x00001000; /* Bit 12 */
368 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
369 -}
370 -
371 -static inline void pcie_phy_rst_deassert(int pcie_port)
372 -{
373 - u32 reg;
374 -
375 - /* Make sure one micro-second delay */
376 - udelay(1);
377 -
378 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
379 - reg &= ~0x00001000; /* Bit 12 */
380 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
381 -}
382 -
383 -static inline void pcie_device_rst_assert(int pcie_port)
384 -{
385 - gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
386 -// ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
387 -}
388 -
389 -static inline void pcie_device_rst_deassert(int pcie_port)
390 -{
391 - mdelay(100);
392 - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
393 -// gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
394 - //ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
395 -}
396 -
397 static inline void pcie_core_pmu_setup(int pcie_port)
398 {
399 struct clk *clk;