kernel: backport an upstream fix for ath10k splat
[openwrt/staging/xback.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 @@ -25,11 +32,6 @@
43 #define IFX_PCIE_ERROR_INT
44 #define IFX_PCIE_IO_32BIT
45
46 -#define IFX_PCIE_IR (INT_NUM_IM4_IRL0 + 25)
47 -#define IFX_PCIE_INTA (INT_NUM_IM4_IRL0 + 8)
48 -#define IFX_PCIE_INTB (INT_NUM_IM4_IRL0 + 9)
49 -#define IFX_PCIE_INTC (INT_NUM_IM4_IRL0 + 10)
50 -#define IFX_PCIE_INTD (INT_NUM_IM4_IRL0 + 11)
51 #define MS(_v, _f) (((_v) & (_f)) >> _f##_S)
52 #define SM(_v, _f) (((_v) << _f##_S) & (_f))
53 #define IFX_REG_SET_BIT(_f, _r) \
54 @@ -40,30 +42,30 @@
55 static DEFINE_SPINLOCK(ifx_pcie_lock);
56
57 u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
58 +static int pcie_reset_gpio;
59 +static struct phy *ltq_pcie_phy;
60 +static struct reset_control *ltq_pcie_reset;
61 +static struct regmap *ltq_rcu_regmap;
62 +static bool switch_pcie_endianess;
63
64 static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
65 {
66 .ir_irq = {
67 - .irq = IFX_PCIE_IR,
68 .name = "ifx_pcie_rc0",
69 },
70
71 .legacy_irq = {
72 {
73 .irq_bit = PCIE_IRN_INTA,
74 - .irq = IFX_PCIE_INTA,
75 },
76 {
77 .irq_bit = PCIE_IRN_INTB,
78 - .irq = IFX_PCIE_INTB,
79 },
80 {
81 .irq_bit = PCIE_IRN_INTC,
82 - .irq = IFX_PCIE_INTC,
83 },
84 {
85 .irq_bit = PCIE_IRN_INTD,
86 - .irq = IFX_PCIE_INTD,
87 },
88 },
89 },
90 @@ -82,6 +84,22 @@ void ifx_pcie_debug(const char *fmt, ...
91 printk("%s", buf);
92 }
93
94 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
95 +{
96 + gpio_direction_output(pcie_reset_gpio, 1);
97 + gpio_set_value(pcie_reset_gpio, 1);
98 +}
99 +
100 +static inline void pcie_device_rst_assert(int pcie_port)
101 +{
102 + gpio_set_value(pcie_reset_gpio, 0);
103 +}
104 +
105 +static inline void pcie_device_rst_deassert(int pcie_port)
106 +{
107 + mdelay(100);
108 + gpio_direction_output(pcie_reset_gpio, 1);
109 +}
110
111 static inline int pcie_ltssm_enable(int pcie_port)
112 {
113 @@ -857,7 +875,8 @@ pcie_rc_core_int_init(int pcie_port)
114 ret = request_irq(pcie_irqs[pcie_port].ir_irq.irq, pcie_rc_core_isr, 0,
115 pcie_irqs[pcie_port].ir_irq.name, &ifx_pcie_controller[pcie_port]);
116 if (ret)
117 - printk(KERN_ERR "%s request irq %d failed\n", __func__, IFX_PCIE_IR);
118 + printk(KERN_ERR "%s request irq %d failed\n", __func__,
119 + pcie_irqs[pcie_port].ir_irq.irq);
120
121 return ret;
122 }
123 @@ -988,10 +1007,26 @@ int ifx_pcie_bios_plat_dev_init(struct
124 static int
125 pcie_rc_initialize(int pcie_port)
126 {
127 - int i;
128 + int i, ret;
129 #define IFX_PCIE_PHY_LOOP_CNT 5
130
131 - pcie_rcu_endian_setup(pcie_port);
132 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_M,
133 + IFX_RCU_AHB_BE_PCIE_M);
134 +
135 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
136 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
137 + IFX_RCU_AHB_BE_PCIE_S);
138 + if (switch_pcie_endianess) {
139 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_S,
140 + IFX_RCU_AHB_BE_XBAR_S);
141 + }
142 +#else
143 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
144 + 0x0);
145 +#endif
146 +
147 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_M,
148 + 0x0);
149
150 pcie_ep_gpio_rst_init(pcie_port);
151
152 @@ -1000,26 +1035,21 @@ pcie_rc_initialize(int pcie_port)
153 * reset PCIe PHY will solve this issue
154 */
155 for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
156 - /* Disable PCIe PHY Analog part for sanity check */
157 - pcie_phy_pmu_disable(pcie_port);
158 -
159 - pcie_phy_rst_assert(pcie_port);
160 - pcie_phy_rst_deassert(pcie_port);
161 -
162 - /* Make sure PHY PLL is stable */
163 - udelay(20);
164 -
165 - /* PCIe Core reset enabled, low active, sw programmed */
166 - pcie_core_rst_assert(pcie_port);
167 + ret = phy_init(ltq_pcie_phy);
168 + if (ret)
169 + continue;
170
171 /* Put PCIe EP in reset status */
172 pcie_device_rst_assert(pcie_port);
173
174 - /* PCI PHY & Core reset disabled, high active, sw programmed */
175 - pcie_core_rst_deassert(pcie_port);
176 + udelay(1);
177 + reset_control_deassert(ltq_pcie_reset);
178
179 - /* Already in a quiet state, program PLL, enable PHY, check ready bit */
180 - pcie_phy_clock_mode_setup(pcie_port);
181 + ret = phy_power_on(ltq_pcie_phy);
182 + if (ret) {
183 + phy_exit(ltq_pcie_phy);
184 + continue;
185 + }
186
187 /* Enable PCIe PHY and Clock */
188 pcie_core_pmu_setup(pcie_port);
189 @@ -1035,6 +1065,10 @@ pcie_rc_initialize(int pcie_port)
190 /* Once link is up, break out */
191 if (pcie_app_loigc_setup(pcie_port) == 0)
192 break;
193 +
194 + phy_power_off(ltq_pcie_phy);
195 + reset_control_assert(ltq_pcie_reset);
196 + phy_exit(ltq_pcie_phy);
197 }
198 if (i >= IFX_PCIE_PHY_LOOP_CNT) {
199 printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
200 @@ -1045,17 +1079,73 @@ pcie_rc_initialize(int pcie_port)
201 return 0;
202 }
203
204 -static int __init ifx_pcie_bios_init(void)
205 +static int ifx_pcie_bios_probe(struct platform_device *pdev)
206 {
207 + struct device_node *node = pdev->dev.of_node;
208 void __iomem *io_map_base;
209 int pcie_port;
210 int startup_port;
211 + struct device_node *np;
212 + struct pci_bus *bus;
213 +
214 + /*
215 + * In case a PCI device is physical present, the Lantiq PCI driver need
216 + * to be loaded prior to the Lantiq PCIe driver. Otherwise none of them
217 + * will work.
218 + *
219 + * In case the lantiq PCI driver is enabled in the device tree, check if
220 + * a PCI bus (hopefully the one of the Lantiq PCI driver one) is already
221 + * registered.
222 + *
223 + * It will fail if there is another PCI controller, this controller is
224 + * registered before the Lantiq PCIe driver is probe and the lantiq PCI
225 + */
226 + np = of_find_compatible_node(NULL, NULL, "lantiq,pci-xway");
227 +
228 + if (of_device_is_available(np)) {
229 + bus = pci_find_next_bus(bus);
230 +
231 + if (!bus)
232 + return -EPROBE_DEFER;
233 + }
234
235 /* Enable AHB Master/ Slave */
236 pcie_ahb_pmu_setup();
237
238 startup_port = IFX_PCIE_PORT0;
239 -
240 +
241 + ltq_pcie_phy = devm_phy_get(&pdev->dev, "pcie");
242 + if (IS_ERR(ltq_pcie_phy))
243 + return dev_err_probe(&pdev->dev, PTR_ERR(ltq_pcie_phy),
244 + "failed to get the PCIe PHY\n");
245 +
246 + ltq_pcie_reset = devm_reset_control_get_shared(&pdev->dev, NULL);
247 + if (IS_ERR(ltq_pcie_reset)) {
248 + dev_err(&pdev->dev, "failed to get the PCIe reset line\n");
249 + return PTR_ERR(ltq_pcie_reset);
250 + }
251 +
252 + if (of_property_read_bool(node, "lantiq,switch-pcie-endianess")) {
253 + switch_pcie_endianess = true;
254 + dev_info(&pdev->dev, "switch pcie endianess requested\n");
255 + } else {
256 + switch_pcie_endianess = false;
257 + }
258 +
259 + ltq_rcu_regmap = syscon_regmap_lookup_by_phandle(node, "lantiq,rcu");
260 + if (IS_ERR(ltq_rcu_regmap))
261 + return PTR_ERR(ltq_rcu_regmap);
262 +
263 + pcie_reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
264 + if (gpio_is_valid(pcie_reset_gpio)) {
265 + int ret = devm_gpio_request(&pdev->dev, pcie_reset_gpio, "pcie-reset");
266 + if (ret) {
267 + dev_err(&pdev->dev, "failed to request gpio %d\n", pcie_reset_gpio);
268 + return ret;
269 + }
270 + gpio_direction_output(pcie_reset_gpio, 1);
271 + }
272 +
273 for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
274 if (pcie_rc_initialize(pcie_port) == 0) {
275 IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: ifx_pcie_cfg_base 0x%p\n",
276 @@ -1066,7 +1156,19 @@ static int __init ifx_pcie_bios_init(voi
277 IFX_PCIE_PRINT(PCIE_MSG_ERR, "%s io space ioremap failed\n", __func__);
278 return -ENOMEM;
279 }
280 + pcie_irqs[pcie_port].ir_irq.irq = platform_get_irq(pdev, 0);
281 + if (pcie_irqs[pcie_port].ir_irq.irq < 0)
282 + return pcie_irqs[pcie_port].ir_irq.irq;
283 +
284 + for (int i = 0; i <= 3; i++){
285 + pcie_irqs[pcie_port].legacy_irq[i].irq = platform_get_irq(pdev, i + 1);
286 +
287 + if (pcie_irqs[pcie_port].legacy_irq[i].irq < 0)
288 + return pcie_irqs[pcie_port].legacy_irq[i].irq;
289 + }
290 +
291 ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
292 + pci_load_of_ranges(&ifx_pcie_controller[pcie_port].pcic, node);
293
294 register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
295 /* XXX, clear error status */
296 @@ -1083,6 +1185,30 @@ static int __init ifx_pcie_bios_init(voi
297
298 return 0;
299 }
300 +
301 +static const struct of_device_id ifxmips_pcie_match[] = {
302 + { .compatible = "lantiq,pcie-xrx200" },
303 + {},
304 +};
305 +MODULE_DEVICE_TABLE(of, ifxmips_pcie_match);
306 +
307 +static struct platform_driver ltq_pci_driver = {
308 + .probe = ifx_pcie_bios_probe,
309 + .driver = {
310 + .name = "pcie-xrx200",
311 + .owner = THIS_MODULE,
312 + .of_match_table = ifxmips_pcie_match,
313 + },
314 +};
315 +
316 +int __init ifx_pcie_bios_init(void)
317 +{
318 + int ret = platform_driver_register(&ltq_pci_driver);
319 + if (ret)
320 + pr_info("pcie-xrx200: Error registering platform driver!");
321 + return ret;
322 +}
323 +
324 arch_initcall(ifx_pcie_bios_init);
325
326 MODULE_LICENSE("GPL");
327 --- a/arch/mips/pci/ifxmips_pcie_vr9.h
328 +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
329 @@ -22,8 +22,6 @@
330 #include <linux/gpio.h>
331 #include <lantiq_soc.h>
332
333 -#define IFX_PCIE_GPIO_RESET 494
334 -
335 #define IFX_REG_R32 ltq_r32
336 #define IFX_REG_W32 ltq_w32
337 #define CONFIG_IFX_PCIE_HW_SWAP
338 @@ -54,21 +52,6 @@
339 #define OUT ((volatile u32*)(IFX_GPIO + 0x0070))
340
341
342 -static inline void pcie_ep_gpio_rst_init(int pcie_port)
343 -{
344 -
345 - gpio_request(IFX_PCIE_GPIO_RESET, "pcie-reset");
346 - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
347 - gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
348 -
349 -/* ifx_gpio_pin_reserve(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
350 - ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
351 - ifx_gpio_dir_out_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
352 - ifx_gpio_altsel0_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
353 - ifx_gpio_altsel1_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
354 - ifx_gpio_open_drain_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);*/
355 -}
356 -
357 static inline void pcie_ahb_pmu_setup(void)
358 {
359 /* Enable AHB bus master/slave */
360 @@ -80,24 +63,6 @@ static inline void pcie_ahb_pmu_setup(vo
361 //AHBS_PMU_SETUP(IFX_PMU_ENABLE);
362 }
363
364 -static inline void pcie_rcu_endian_setup(int pcie_port)
365 -{
366 - u32 reg;
367 -
368 - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
369 -#ifdef CONFIG_IFX_PCIE_HW_SWAP
370 - reg |= IFX_RCU_AHB_BE_PCIE_M;
371 - reg |= IFX_RCU_AHB_BE_PCIE_S;
372 - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
373 -#else
374 - reg |= IFX_RCU_AHB_BE_PCIE_M;
375 - reg &= ~IFX_RCU_AHB_BE_PCIE_S;
376 - reg &= ~IFX_RCU_AHB_BE_XBAR_M;
377 -#endif /* CONFIG_IFX_PCIE_HW_SWAP */
378 - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
379 - IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
380 -}
381 -
382 static inline void pcie_phy_pmu_enable(int pcie_port)
383 {
384 struct clk *clk;
385 @@ -116,17 +81,6 @@ static inline void pcie_phy_pmu_disable(
386 // PCIE_PHY_PMU_SETUP(IFX_PMU_DISABLE);
387 }
388
389 -static inline void pcie_pdi_big_endian(int pcie_port)
390 -{
391 - u32 reg;
392 -
393 - /* SRAM2PDI endianness control. */
394 - reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
395 - /* Config AHB->PCIe and PDI endianness */
396 - reg |= IFX_RCU_AHB_BE_PCIE_PDI;
397 - IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
398 -}
399 -
400 static inline void pcie_pdi_pmu_enable(int pcie_port)
401 {
402 /* Enable PDI to access PCIe PHY register */
403 @@ -136,65 +90,6 @@ static inline void pcie_pdi_pmu_enable(i
404 //PDI_PMU_SETUP(IFX_PMU_ENABLE);
405 }
406
407 -static inline void pcie_core_rst_assert(int pcie_port)
408 -{
409 - u32 reg;
410 -
411 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
412 -
413 - /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
414 - reg |= 0x00400000;
415 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
416 -}
417 -
418 -static inline void pcie_core_rst_deassert(int pcie_port)
419 -{
420 - u32 reg;
421 -
422 - /* Make sure one micro-second delay */
423 - udelay(1);
424 -
425 - /* Reset PCIe PHY & Core, bit 22 */
426 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
427 - reg &= ~0x00400000;
428 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
429 -}
430 -
431 -static inline void pcie_phy_rst_assert(int pcie_port)
432 -{
433 - u32 reg;
434 -
435 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
436 - reg |= 0x00001000; /* Bit 12 */
437 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
438 -}
439 -
440 -static inline void pcie_phy_rst_deassert(int pcie_port)
441 -{
442 - u32 reg;
443 -
444 - /* Make sure one micro-second delay */
445 - udelay(1);
446 -
447 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
448 - reg &= ~0x00001000; /* Bit 12 */
449 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
450 -}
451 -
452 -static inline void pcie_device_rst_assert(int pcie_port)
453 -{
454 - gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
455 -// ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
456 -}
457 -
458 -static inline void pcie_device_rst_deassert(int pcie_port)
459 -{
460 - mdelay(100);
461 - gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
462 -// gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
463 - //ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
464 -}
465 -
466 static inline void pcie_core_pmu_setup(int pcie_port)
467 {
468 struct clk *clk;
469 --- a/arch/mips/pci/ifxmips_pcie.h
470 +++ b/arch/mips/pci/ifxmips_pcie.h
471 @@ -96,13 +96,13 @@ struct ifx_pci_controller {
472 };
473
474 typedef struct ifx_pcie_ir_irq {
475 - const unsigned int irq;
476 + unsigned int irq;
477 const char name[16];
478 }ifx_pcie_ir_irq_t;
479
480 typedef struct ifx_pcie_legacy_irq{
481 const u32 irq_bit;
482 - const int irq;
483 + int irq;
484 }ifx_pcie_legacy_irq_t;
485
486 typedef struct ifx_pcie_irq {