1 --- a/arch/mips/pci/ifxmips_pcie.c
2 +++ b/arch/mips/pci/ifxmips_pcie.c
4 #include <asm/paccess.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>
13 +#include <linux/of_gpio.h>
14 +#include <linux/of_platform.h>
16 #include "ifxmips_pcie.h"
17 #include "ifxmips_pcie_reg.h"
20 static DEFINE_SPINLOCK(ifx_pcie_lock);
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;
28 static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
30 @@ -82,6 +93,22 @@ void ifx_pcie_debug(const char *fmt, ...
34 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
36 + gpio_direction_output(pcie_reset_gpio, 1);
37 + gpio_set_value(pcie_reset_gpio, 1);
40 +static inline void pcie_device_rst_assert(int pcie_port)
42 + gpio_set_value(pcie_reset_gpio, 0);
45 +static inline void pcie_device_rst_deassert(int pcie_port)
48 + gpio_direction_output(pcie_reset_gpio, 1);
51 static inline int pcie_ltssm_enable(int pcie_port)
53 @@ -988,10 +1015,22 @@ int ifx_pcie_bios_plat_dev_init(struct
55 pcie_rc_initialize(int pcie_port)
59 #define IFX_PCIE_PHY_LOOP_CNT 5
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);
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);
69 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_PCIE_S,
73 + regmap_update_bits(ltq_rcu_regmap, 0x4c, IFX_RCU_AHB_BE_XBAR_M,
76 pcie_ep_gpio_rst_init(pcie_port);
78 @@ -1000,26 +1039,21 @@ pcie_rc_initialize(int pcie_port)
79 * reset PCIe PHY will solve this issue
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);
85 - pcie_phy_rst_assert(pcie_port);
86 - pcie_phy_rst_deassert(pcie_port);
88 - /* Make sure PHY PLL is stable */
91 - /* PCIe Core reset enabled, low active, sw programmed */
92 - pcie_core_rst_assert(pcie_port);
93 + ret = phy_init(ltq_pcie_phy);
97 /* Put PCIe EP in reset status */
98 pcie_device_rst_assert(pcie_port);
100 - /* PCI PHY & Core reset disabled, high active, sw programmed */
101 - pcie_core_rst_deassert(pcie_port);
103 + reset_control_deassert(ltq_pcie_reset);
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);
109 + phy_exit(ltq_pcie_phy);
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)
120 + phy_power_off(ltq_pcie_phy);
121 + reset_control_assert(ltq_pcie_reset);
122 + phy_exit(ltq_pcie_phy);
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)
130 -static int __init ifx_pcie_bios_init(void)
131 +static int ifx_pcie_bios_probe(struct platform_device *pdev)
133 + struct device_node *node = pdev->dev.of_node;
134 void __iomem *io_map_base;
137 + struct device_node *np;
138 + struct pci_bus *bus;
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
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
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
152 + np = of_find_compatible_node(NULL, NULL, "lantiq,pci-xway");
154 + if (of_device_is_available(np)) {
155 + bus = pci_find_next_bus(bus);
158 + return -EPROBE_DEFER;
161 /* Enable AHB Master/ Slave */
162 pcie_ahb_pmu_setup();
164 startup_port = IFX_PCIE_PORT0;
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);
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);
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);
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");
187 + dev_err(&pdev->dev, "failed to request gpio %d\n", pcie_reset_gpio);
190 + gpio_direction_output(pcie_reset_gpio, 1);
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
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);
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
209 +static const struct of_device_id ifxmips_pcie_match[] = {
210 + { .compatible = "lantiq,pcie-xrx200" },
213 +MODULE_DEVICE_TABLE(of, ifxmips_pcie_match);
215 +static struct platform_driver ltq_pci_driver = {
216 + .probe = ifx_pcie_bios_probe,
218 + .name = "pcie-xrx200",
219 + .owner = THIS_MODULE,
220 + .of_match_table = ifxmips_pcie_match,
224 +int __init ifx_pcie_bios_init(void)
226 + int ret = platform_driver_register(<q_pci_driver);
228 + pr_info("pcie-xrx200: Error registering platform driver!");
232 arch_initcall(ifx_pcie_bios_init);
234 MODULE_LICENSE("GPL");
235 --- a/arch/mips/pci/ifxmips_pcie_vr9.h
236 +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
238 #include <linux/gpio.h>
239 #include <lantiq_soc.h>
241 -#define IFX_PCIE_GPIO_RESET 494
243 #define IFX_REG_R32 ltq_r32
244 #define IFX_REG_W32 ltq_w32
245 #define CONFIG_IFX_PCIE_HW_SWAP
247 #define OUT ((volatile u32*)(IFX_GPIO + 0x0070))
250 -static inline void pcie_ep_gpio_rst_init(int pcie_port)
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);
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);*/
265 static inline void pcie_ahb_pmu_setup(void)
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);
272 -static inline void pcie_rcu_endian_setup(int pcie_port)
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;
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));
290 static inline void pcie_phy_pmu_enable(int pcie_port)
293 @@ -115,17 +80,6 @@ static inline void pcie_phy_pmu_disable(
294 // PCIE_PHY_PMU_SETUP(IFX_PMU_DISABLE);
297 -static inline void pcie_pdi_big_endian(int pcie_port)
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);
308 static inline void pcie_pdi_pmu_enable(int pcie_port)
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);
315 -static inline void pcie_core_rst_assert(int pcie_port)
319 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
321 - /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
323 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
326 -static inline void pcie_core_rst_deassert(int pcie_port)
330 - /* Make sure one micro-second delay */
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);
339 -static inline void pcie_phy_rst_assert(int pcie_port)
343 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
344 - reg |= 0x00001000; /* Bit 12 */
345 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
348 -static inline void pcie_phy_rst_deassert(int pcie_port)
352 - /* Make sure one micro-second delay */
355 - reg = IFX_REG_R32(IFX_RCU_RST_REQ);
356 - reg &= ~0x00001000; /* Bit 12 */
357 - IFX_REG_W32(reg, IFX_RCU_RST_REQ);
360 -static inline void pcie_device_rst_assert(int pcie_port)
362 - gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
363 -// ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
366 -static inline void pcie_device_rst_deassert(int pcie_port)
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);
374 static inline void pcie_core_pmu_setup(int pcie_port)
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