7927c1cbf5f87c5540a38be6276000b94b2a1d76
[openwrt/staging/stintel.git] / target / linux / ath79 / patches-5.15 / 313-MIPS-pci-ar724x-convert-to-OF.patch
1 From a522ee0199d5d3ea114ca2e211f6ac398d3e8e0b Mon Sep 17 00:00:00 2001
2 From: John Crispin <john@phrozen.org>
3 Date: Sat, 23 Jun 2018 15:07:37 +0200
4 Subject: [PATCH 20/33] MIPS: pci-ar724x: convert to OF
5
6 With the ath79 target getting converted to pure OF, we can drop all the
7 platform data code and add the missing OF bits to the driver. We also add
8 a irq domain for the PCI/e controllers cascade, thus making it usable from
9 dts files.
10
11 Signed-off-by: John Crispin <john@phrozen.org>
12 ---
13 arch/mips/pci/pci-ar724x.c | 88 ++++++++++++++++++++++------------------------
14 1 file changed, 42 insertions(+), 46 deletions(-)
15
16 --- a/arch/mips/pci/pci-ar724x.c
17 +++ b/arch/mips/pci/pci-ar724x.c
18 @@ -11,8 +11,11 @@
19 #include <linux/init.h>
20 #include <linux/delay.h>
21 #include <linux/platform_device.h>
22 +#include <linux/irqchip/chained_irq.h>
23 #include <asm/mach-ath79/ath79.h>
24 #include <asm/mach-ath79/ar71xx_regs.h>
25 +#include <linux/of_irq.h>
26 +#include <linux/of_pci.h>
27
28 #define AR724X_PCI_REG_APP 0x00
29 #define AR724X_PCI_REG_RESET 0x18
30 @@ -42,17 +45,20 @@ struct ar724x_pci_controller {
31 void __iomem *crp_base;
32
33 int irq;
34 - int irq_base;
35
36 bool link_up;
37 bool bar0_is_cached;
38 u32 bar0_value;
39
40 + struct device_node *np;
41 struct pci_controller pci_controller;
42 + struct irq_domain *domain;
43 struct resource io_res;
44 struct resource mem_res;
45 };
46
47 +static struct irq_chip ar724x_pci_irq_chip;
48 +
49 static inline bool ar724x_pci_check_link(struct ar724x_pci_controller *apc)
50 {
51 u32 reset;
52 @@ -228,35 +234,31 @@ static struct pci_ops ar724x_pci_ops = {
53
54 static void ar724x_pci_irq_handler(struct irq_desc *desc)
55 {
56 - struct ar724x_pci_controller *apc;
57 - void __iomem *base;
58 + struct irq_chip *chip = irq_desc_get_chip(desc);
59 + struct ar724x_pci_controller *apc = irq_desc_get_handler_data(desc);
60 u32 pending;
61
62 - apc = irq_desc_get_handler_data(desc);
63 - base = apc->ctrl_base;
64 -
65 - pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) &
66 - __raw_readl(base + AR724X_PCI_REG_INT_MASK);
67 + chained_irq_enter(chip, desc);
68 + pending = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_INT_STATUS) &
69 + __raw_readl(apc->ctrl_base + AR724X_PCI_REG_INT_MASK);
70
71 if (pending & AR724X_PCI_INT_DEV0)
72 - generic_handle_irq(apc->irq_base + 0);
73 -
74 + generic_handle_irq(irq_linear_revmap(apc->domain, 1));
75 else
76 spurious_interrupt();
77 + chained_irq_exit(chip, desc);
78 }
79
80 static void ar724x_pci_irq_unmask(struct irq_data *d)
81 {
82 struct ar724x_pci_controller *apc;
83 void __iomem *base;
84 - int offset;
85 u32 t;
86
87 apc = irq_data_get_irq_chip_data(d);
88 base = apc->ctrl_base;
89 - offset = apc->irq_base - d->irq;
90
91 - switch (offset) {
92 + switch (irq_linear_revmap(apc->domain, d->irq)) {
93 case 0:
94 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
95 __raw_writel(t | AR724X_PCI_INT_DEV0,
96 @@ -270,14 +272,12 @@ static void ar724x_pci_irq_mask(struct i
97 {
98 struct ar724x_pci_controller *apc;
99 void __iomem *base;
100 - int offset;
101 u32 t;
102
103 apc = irq_data_get_irq_chip_data(d);
104 base = apc->ctrl_base;
105 - offset = apc->irq_base - d->irq;
106
107 - switch (offset) {
108 + switch (irq_linear_revmap(apc->domain, d->irq)) {
109 case 0:
110 t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
111 __raw_writel(t & ~AR724X_PCI_INT_DEV0,
112 @@ -302,26 +302,34 @@ static struct irq_chip ar724x_pci_irq_ch
113 .irq_mask_ack = ar724x_pci_irq_mask,
114 };
115
116 +static int ar724x_pci_irq_map(struct irq_domain *d,
117 + unsigned int irq, irq_hw_number_t hw)
118 +{
119 + struct ar724x_pci_controller *apc = d->host_data;
120 +
121 + irq_set_chip_and_handler(irq, &ar724x_pci_irq_chip, handle_level_irq);
122 + irq_set_chip_data(irq, apc);
123 +
124 + return 0;
125 +}
126 +
127 +static const struct irq_domain_ops ar724x_pci_domain_ops = {
128 + .xlate = irq_domain_xlate_onecell,
129 + .map = ar724x_pci_irq_map,
130 +};
131 +
132 static void ar724x_pci_irq_init(struct ar724x_pci_controller *apc,
133 int id)
134 {
135 void __iomem *base;
136 - int i;
137
138 base = apc->ctrl_base;
139
140 __raw_writel(0, base + AR724X_PCI_REG_INT_MASK);
141 __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS);
142
143 - apc->irq_base = ATH79_PCI_IRQ_BASE + (id * AR724X_PCI_IRQ_COUNT);
144 -
145 - for (i = apc->irq_base;
146 - i < apc->irq_base + AR724X_PCI_IRQ_COUNT; i++) {
147 - irq_set_chip_and_handler(i, &ar724x_pci_irq_chip,
148 - handle_level_irq);
149 - irq_set_chip_data(i, apc);
150 - }
151 -
152 + apc->domain = irq_domain_add_linear(apc->np, 2,
153 + &ar724x_pci_domain_ops, apc);
154 irq_set_chained_handler_and_data(apc->irq, ar724x_pci_irq_handler,
155 apc);
156 }
157 @@ -360,7 +368,6 @@ static void ar724x_pci_hw_init(struct ar
158 static int ar724x_pci_probe(struct platform_device *pdev)
159 {
160 struct ar724x_pci_controller *apc;
161 - struct resource *res;
162 int id;
163
164 id = pdev->id;
165 @@ -388,29 +395,11 @@ static int ar724x_pci_probe(struct platf
166 if (apc->irq < 0)
167 return -EINVAL;
168
169 - res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
170 - if (!res)
171 - return -EINVAL;
172 -
173 - apc->io_res.parent = res;
174 - apc->io_res.name = "PCI IO space";
175 - apc->io_res.start = res->start;
176 - apc->io_res.end = res->end;
177 - apc->io_res.flags = IORESOURCE_IO;
178 -
179 - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
180 - if (!res)
181 - return -EINVAL;
182 -
183 - apc->mem_res.parent = res;
184 - apc->mem_res.name = "PCI memory space";
185 - apc->mem_res.start = res->start;
186 - apc->mem_res.end = res->end;
187 - apc->mem_res.flags = IORESOURCE_MEM;
188 -
189 + apc->np = pdev->dev.of_node;
190 apc->pci_controller.pci_ops = &ar724x_pci_ops;
191 apc->pci_controller.io_resource = &apc->io_res;
192 apc->pci_controller.mem_resource = &apc->mem_res;
193 + pci_load_of_ranges(&apc->pci_controller, pdev->dev.of_node);
194
195 /*
196 * Do the full PCIE Root Complex Initialization Sequence if the PCIe
197 @@ -432,10 +421,16 @@ static int ar724x_pci_probe(struct platf
198 return 0;
199 }
200
201 +static const struct of_device_id ar724x_pci_ids[] = {
202 + { .compatible = "qcom,ar7240-pci" },
203 + {},
204 +};
205 +
206 static struct platform_driver ar724x_pci_driver = {
207 .probe = ar724x_pci_probe,
208 .driver = {
209 .name = "ar724x-pci",
210 + .of_match_table = of_match_ptr(ar724x_pci_ids),
211 },
212 };
213