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