lantiq: copy target to kernel 5.4
[oweals/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 @@ -18,6 +18,9 @@
4  #include <linux/pci_regs.h>
5  #include <linux/module.h>
6  
7 +#include <linux/of_gpio.h>
8 +#include <linux/of_platform.h>
9 +
10  #include "ifxmips_pcie.h"
11  #include "ifxmips_pcie_reg.h"
12  
13 @@ -40,6 +43,7 @@
14  static DEFINE_SPINLOCK(ifx_pcie_lock);
15  
16  u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
17 +static int pcie_reset_gpio;
18  
19  static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
20      {
21 @@ -82,6 +86,22 @@ void ifx_pcie_debug(const char *fmt, ...
22         printk("%s", buf);
23  }
24  
25 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
26 +{
27 +       gpio_direction_output(pcie_reset_gpio, 1);
28 +       gpio_set_value(pcie_reset_gpio, 1);
29 +}
30 +
31 +static inline void pcie_device_rst_assert(int pcie_port)
32 +{
33 +       gpio_set_value(pcie_reset_gpio, 0);
34 +}
35 +
36 +static inline void pcie_device_rst_deassert(int pcie_port)
37 +{
38 +       mdelay(100);
39 +       gpio_direction_output(pcie_reset_gpio, 1);
40 +}
41  
42  static inline int pcie_ltssm_enable(int pcie_port)
43  {
44 @@ -1045,17 +1065,52 @@ pcie_rc_initialize(int pcie_port)
45         return 0;
46  }
47  
48 -static int __init ifx_pcie_bios_init(void)
49 +static int ifx_pcie_bios_probe(struct platform_device *pdev)
50  {
51 +    struct device_node *node = pdev->dev.of_node;
52      void __iomem *io_map_base;
53      int pcie_port;
54      int startup_port;
55  
56 +    struct device_node *np;
57 +    struct pci_bus *bus;
58 +
59 +    /*
60 +     * In case a PCI device is physical present, the Lantiq PCI driver need
61 +     * to be loaded prior to the Lantiq PCIe driver. Otherwise none of them
62 +     * will work.
63 +     *
64 +     * In case the lantiq PCI driver is enabled in the device tree, check if
65 +     * a PCI bus (hopefully the one of the Lantiq PCI driver one) is already
66 +     * registered.
67 +     *
68 +     * It will fail if there is another PCI controller, this controller is
69 +     * registered before the Lantiq PCIe driver is probe and the lantiq PCI
70 +     */
71 +    np = of_find_compatible_node(NULL, NULL, "lantiq,pci-xway");
72 +
73 +    if (of_device_is_available(np)) {
74 +        bus = pci_find_next_bus(bus);
75 +
76 +        if (!bus)
77 +            return -EPROBE_DEFER;
78 +    }
79 +
80      /* Enable AHB Master/ Slave */
81      pcie_ahb_pmu_setup();
82  
83      startup_port = IFX_PCIE_PORT0;
84 -    
85 +
86 +    pcie_reset_gpio = of_get_named_gpio(node, "gpio-reset", 0);
87 +    if (gpio_is_valid(pcie_reset_gpio)) {
88 +        int ret = devm_gpio_request(&pdev->dev, pcie_reset_gpio, "pcie-reset");
89 +        if (ret) {
90 +            dev_err(&pdev->dev, "failed to request gpio %d\n", pcie_reset_gpio);
91 +            return ret;
92 +        }
93 +        gpio_direction_output(pcie_reset_gpio, 1);
94 +    }
95 +
96      for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
97         if (pcie_rc_initialize(pcie_port) == 0) {
98             IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: ifx_pcie_cfg_base 0x%p\n", 
99 @@ -1067,6 +1122,7 @@ static int __init ifx_pcie_bios_init(voi
100                  return -ENOMEM;
101              }
102              ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
103 +            pci_load_of_ranges(&ifx_pcie_controller[pcie_port].pcic, node);
104  
105              register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
106              /* XXX, clear error status */
107 @@ -1083,6 +1139,30 @@ static int __init ifx_pcie_bios_init(voi
108  
109      return 0;
110  }
111 +
112 +static const struct of_device_id ifxmips_pcie_match[] = {
113 +        { .compatible = "lantiq,pcie-xrx200" },
114 +        {},
115 +};
116 +MODULE_DEVICE_TABLE(of, ifxmips_pcie_match);
117 +
118 +static struct platform_driver ltq_pci_driver = {
119 +        .probe = ifx_pcie_bios_probe,
120 +        .driver = {
121 +                .name = "pcie-xrx200",
122 +                .owner = THIS_MODULE,
123 +                .of_match_table = ifxmips_pcie_match,
124 +        },
125 +};
126 +
127 +int __init ifx_pcie_bios_init(void)
128 +{
129 +        int ret = platform_driver_register(&ltq_pci_driver);
130 +        if (ret)
131 +                pr_info("pcie-xrx200: Error registering platform driver!");
132 +        return ret;
133 +}
134 +
135  arch_initcall(ifx_pcie_bios_init);
136  
137  MODULE_LICENSE("GPL");
138 --- a/arch/mips/pci/ifxmips_pcie_vr9.h
139 +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
140 @@ -22,8 +22,6 @@
141  #include <linux/gpio.h>
142  #include <lantiq_soc.h>
143  
144 -#define IFX_PCIE_GPIO_RESET  494
145 -
146  #define IFX_REG_R32    ltq_r32
147  #define IFX_REG_W32    ltq_w32
148  #define CONFIG_IFX_PCIE_HW_SWAP
149 @@ -53,21 +51,6 @@
150  #define OUT                    ((volatile u32*)(IFX_GPIO + 0x0070))
151  
152  
153 -static inline void pcie_ep_gpio_rst_init(int pcie_port)
154 -{
155 -
156 -       gpio_request(IFX_PCIE_GPIO_RESET, "pcie-reset");
157 -       gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
158 -       gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
159 -
160 -/*    ifx_gpio_pin_reserve(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
161 -    ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
162 -    ifx_gpio_dir_out_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
163 -    ifx_gpio_altsel0_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
164 -    ifx_gpio_altsel1_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
165 -    ifx_gpio_open_drain_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);*/
166 -}
167 -
168  static inline void pcie_ahb_pmu_setup(void) 
169  {
170         /* Enable AHB bus master/slave */
171 @@ -180,20 +163,6 @@ static inline void pcie_phy_rst_deassert
172      IFX_REG_W32(reg, IFX_RCU_RST_REQ);
173  }
174  
175 -static inline void pcie_device_rst_assert(int pcie_port)
176 -{
177 -       gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
178 -//    ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
179 -}
180 -
181 -static inline void pcie_device_rst_deassert(int pcie_port)
182 -{
183 -    mdelay(100);
184 -       gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
185 -//    gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
186 -    //ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
187 -}
188 -
189  static inline void pcie_core_pmu_setup(int pcie_port)
190  {
191         struct clk *clk;