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