This source file includes following definitions.
- ixp4xx_set_irq_type
- ixp4xx_irq_mask
- ixp4xx_irq_unmask
- ixp4xx_handle_irq
- ixp4xx_irq_domain_translate
- ixp4xx_irq_domain_alloc
- ixp4xx_get_irq_domain
- ixp4xx_irq_setup
- ixp4xx_irq_init
- ixp4xx_of_init_irq
1
2
3
4
5
6
7
8
9
10
11 #include <linux/bitops.h>
12 #include <linux/gpio/driver.h>
13 #include <linux/irq.h>
14 #include <linux/io.h>
15 #include <linux/irqchip.h>
16 #include <linux/irqchip/irq-ixp4xx.h>
17 #include <linux/irqdomain.h>
18 #include <linux/of.h>
19 #include <linux/of_address.h>
20 #include <linux/of_irq.h>
21 #include <linux/platform_device.h>
22 #include <linux/cpu.h>
23
24 #include <asm/exception.h>
25 #include <asm/mach/irq.h>
26
27 #define IXP4XX_ICPR 0x00
28 #define IXP4XX_ICMR 0x04
29 #define IXP4XX_ICLR 0x08
30 #define IXP4XX_ICIP 0x0C
31 #define IXP4XX_ICFP 0x10
32 #define IXP4XX_ICHR 0x14
33 #define IXP4XX_ICIH 0x18
34 #define IXP4XX_ICFH 0x1C
35
36
37 #define IXP4XX_ICPR2 0x20
38 #define IXP4XX_ICMR2 0x24
39 #define IXP4XX_ICLR2 0x28
40 #define IXP4XX_ICIP2 0x2C
41 #define IXP4XX_ICFP2 0x30
42 #define IXP4XX_ICEEN 0x34
43
44
45
46
47
48
49
50
51 struct ixp4xx_irq {
52 void __iomem *irqbase;
53 bool is_356;
54 struct irq_chip irqchip;
55 struct irq_domain *domain;
56 };
57
58
59 static struct ixp4xx_irq ixirq;
60
61
62 #define IXP4XX_GPIO_CLK_0 14
63 #define IXP4XX_GPIO_CLK_1 15
64
65 static int ixp4xx_set_irq_type(struct irq_data *d, unsigned int type)
66 {
67
68 if (type != IRQ_TYPE_LEVEL_HIGH)
69 return -EINVAL;
70 return 0;
71 }
72
73 static void ixp4xx_irq_mask(struct irq_data *d)
74 {
75 struct ixp4xx_irq *ixi = irq_data_get_irq_chip_data(d);
76 u32 val;
77
78 if (ixi->is_356 && d->hwirq >= 32) {
79 val = __raw_readl(ixi->irqbase + IXP4XX_ICMR2);
80 val &= ~BIT(d->hwirq - 32);
81 __raw_writel(val, ixi->irqbase + IXP4XX_ICMR2);
82 } else {
83 val = __raw_readl(ixi->irqbase + IXP4XX_ICMR);
84 val &= ~BIT(d->hwirq);
85 __raw_writel(val, ixi->irqbase + IXP4XX_ICMR);
86 }
87 }
88
89
90
91
92
93 static void ixp4xx_irq_unmask(struct irq_data *d)
94 {
95 struct ixp4xx_irq *ixi = irq_data_get_irq_chip_data(d);
96 u32 val;
97
98 if (ixi->is_356 && d->hwirq >= 32) {
99 val = __raw_readl(ixi->irqbase + IXP4XX_ICMR2);
100 val |= BIT(d->hwirq - 32);
101 __raw_writel(val, ixi->irqbase + IXP4XX_ICMR2);
102 } else {
103 val = __raw_readl(ixi->irqbase + IXP4XX_ICMR);
104 val |= BIT(d->hwirq);
105 __raw_writel(val, ixi->irqbase + IXP4XX_ICMR);
106 }
107 }
108
109 asmlinkage void __exception_irq_entry ixp4xx_handle_irq(struct pt_regs *regs)
110 {
111 struct ixp4xx_irq *ixi = &ixirq;
112 unsigned long status;
113 int i;
114
115 status = __raw_readl(ixi->irqbase + IXP4XX_ICIP);
116 for_each_set_bit(i, &status, 32)
117 handle_domain_irq(ixi->domain, i, regs);
118
119
120
121
122 if (ixi->is_356) {
123 status = __raw_readl(ixi->irqbase + IXP4XX_ICIP2);
124 for_each_set_bit(i, &status, 32)
125 handle_domain_irq(ixi->domain, i + 32, regs);
126 }
127 }
128
129 static int ixp4xx_irq_domain_translate(struct irq_domain *domain,
130 struct irq_fwspec *fwspec,
131 unsigned long *hwirq,
132 unsigned int *type)
133 {
134
135 if (is_of_node(fwspec->fwnode) && fwspec->param_count == 2) {
136 *hwirq = fwspec->param[0];
137 *type = fwspec->param[1];
138 return 0;
139 }
140
141 if (is_fwnode_irqchip(fwspec->fwnode)) {
142 if (fwspec->param_count != 2)
143 return -EINVAL;
144 *hwirq = fwspec->param[0];
145 *type = fwspec->param[1];
146 WARN_ON(*type == IRQ_TYPE_NONE);
147 return 0;
148 }
149
150 return -EINVAL;
151 }
152
153 static int ixp4xx_irq_domain_alloc(struct irq_domain *d,
154 unsigned int irq, unsigned int nr_irqs,
155 void *data)
156 {
157 struct ixp4xx_irq *ixi = d->host_data;
158 irq_hw_number_t hwirq;
159 unsigned int type = IRQ_TYPE_NONE;
160 struct irq_fwspec *fwspec = data;
161 int ret;
162 int i;
163
164 ret = ixp4xx_irq_domain_translate(d, fwspec, &hwirq, &type);
165 if (ret)
166 return ret;
167
168 for (i = 0; i < nr_irqs; i++) {
169
170
171
172
173
174
175 irq_domain_set_info(d,
176 irq + i,
177 hwirq + i,
178 &ixi->irqchip,
179 ixi,
180 handle_level_irq,
181 NULL, NULL);
182 irq_set_probe(irq + i);
183 }
184
185 return 0;
186 }
187
188
189
190
191
192 static const struct irq_domain_ops ixp4xx_irqdomain_ops = {
193 .translate = ixp4xx_irq_domain_translate,
194 .alloc = ixp4xx_irq_domain_alloc,
195 .free = irq_domain_free_irqs_common,
196 };
197
198
199
200
201
202
203 struct irq_domain *ixp4xx_get_irq_domain(void)
204 {
205 struct ixp4xx_irq *ixi = &ixirq;
206
207 return ixi->domain;
208 }
209 EXPORT_SYMBOL_GPL(ixp4xx_get_irq_domain);
210
211
212
213
214
215
216
217
218 struct ixp4xx_irq_chunk {
219 int irq;
220 int hwirq;
221 int nr_irqs;
222 };
223
224 static const struct ixp4xx_irq_chunk ixp4xx_irq_chunks[] = {
225 {
226 .irq = 16,
227 .hwirq = 0,
228 .nr_irqs = 6,
229 },
230 {
231 .irq = 24,
232 .hwirq = 8,
233 .nr_irqs = 11,
234 },
235 {
236 .irq = 46,
237 .hwirq = 30,
238 .nr_irqs = 2,
239 },
240
241 {
242 .irq = 48,
243 .hwirq = 32,
244 .nr_irqs = 10,
245 },
246 };
247
248
249
250
251
252
253
254
255 static int __init ixp4xx_irq_setup(struct ixp4xx_irq *ixi,
256 void __iomem *irqbase,
257 struct fwnode_handle *fwnode,
258 bool is_356)
259 {
260 int nr_irqs;
261
262 ixi->irqbase = irqbase;
263 ixi->is_356 = is_356;
264
265
266 __raw_writel(0x0, ixi->irqbase + IXP4XX_ICLR);
267
268
269 __raw_writel(0x0, ixi->irqbase + IXP4XX_ICMR);
270
271 if (is_356) {
272
273 __raw_writel(0x0, ixi->irqbase + IXP4XX_ICLR2);
274
275
276 __raw_writel(0x0, ixi->irqbase + IXP4XX_ICMR2);
277
278 nr_irqs = 64;
279 } else {
280 nr_irqs = 32;
281 }
282
283 ixi->irqchip.name = "IXP4xx";
284 ixi->irqchip.irq_mask = ixp4xx_irq_mask;
285 ixi->irqchip.irq_unmask = ixp4xx_irq_unmask;
286 ixi->irqchip.irq_set_type = ixp4xx_set_irq_type;
287
288 ixi->domain = irq_domain_create_linear(fwnode, nr_irqs,
289 &ixp4xx_irqdomain_ops,
290 ixi);
291 if (!ixi->domain) {
292 pr_crit("IXP4XX: can not add primary irqdomain\n");
293 return -ENODEV;
294 }
295
296 set_handle_irq(ixp4xx_handle_irq);
297
298 return 0;
299 }
300
301
302
303
304
305
306 void __init ixp4xx_irq_init(resource_size_t irqbase,
307 bool is_356)
308 {
309 struct ixp4xx_irq *ixi = &ixirq;
310 void __iomem *base;
311 struct fwnode_handle *fwnode;
312 struct irq_fwspec fwspec;
313 int nr_chunks;
314 int ret;
315 int i;
316
317 base = ioremap(irqbase, 0x100);
318 if (!base) {
319 pr_crit("IXP4XX: could not ioremap interrupt controller\n");
320 return;
321 }
322 fwnode = irq_domain_alloc_fwnode(&irqbase);
323 if (!fwnode) {
324 pr_crit("IXP4XX: no domain handle\n");
325 return;
326 }
327 ret = ixp4xx_irq_setup(ixi, base, fwnode, is_356);
328 if (ret) {
329 pr_crit("IXP4XX: failed to set up irqchip\n");
330 irq_domain_free_fwnode(fwnode);
331 }
332
333 nr_chunks = ARRAY_SIZE(ixp4xx_irq_chunks);
334 if (!is_356)
335 nr_chunks--;
336
337
338
339
340
341 for (i = 0; i < nr_chunks; i++) {
342 const struct ixp4xx_irq_chunk *chunk = &ixp4xx_irq_chunks[i];
343
344 pr_info("Allocate Linux IRQs %d..%d HW IRQs %d..%d\n",
345 chunk->irq, chunk->irq + chunk->nr_irqs - 1,
346 chunk->hwirq, chunk->hwirq + chunk->nr_irqs - 1);
347 fwspec.fwnode = fwnode;
348 fwspec.param[0] = chunk->hwirq;
349 fwspec.param[1] = IRQ_TYPE_LEVEL_HIGH;
350 fwspec.param_count = 2;
351 ret = __irq_domain_alloc_irqs(ixi->domain,
352 chunk->irq,
353 chunk->nr_irqs,
354 NUMA_NO_NODE,
355 &fwspec,
356 false,
357 NULL);
358 if (ret < 0) {
359 pr_crit("IXP4XX: can not allocate irqs in hierarchy %d\n",
360 ret);
361 return;
362 }
363 }
364 }
365 EXPORT_SYMBOL_GPL(ixp4xx_irq_init);
366
367 #ifdef CONFIG_OF
368 int __init ixp4xx_of_init_irq(struct device_node *np,
369 struct device_node *parent)
370 {
371 struct ixp4xx_irq *ixi = &ixirq;
372 void __iomem *base;
373 struct fwnode_handle *fwnode;
374 bool is_356;
375 int ret;
376
377 base = of_iomap(np, 0);
378 if (!base) {
379 pr_crit("IXP4XX: could not ioremap interrupt controller\n");
380 return -ENODEV;
381 }
382 fwnode = of_node_to_fwnode(np);
383
384
385 is_356 = of_device_is_compatible(np, "intel,ixp43x-interrupt") ||
386 of_device_is_compatible(np, "intel,ixp45x-interrupt") ||
387 of_device_is_compatible(np, "intel,ixp46x-interrupt");
388
389 ret = ixp4xx_irq_setup(ixi, base, fwnode, is_356);
390 if (ret)
391 pr_crit("IXP4XX: failed to set up irqchip\n");
392
393 return ret;
394 }
395 IRQCHIP_DECLARE(ixp42x, "intel,ixp42x-interrupt",
396 ixp4xx_of_init_irq);
397 IRQCHIP_DECLARE(ixp43x, "intel,ixp43x-interrupt",
398 ixp4xx_of_init_irq);
399 IRQCHIP_DECLARE(ixp45x, "intel,ixp45x-interrupt",
400 ixp4xx_of_init_irq);
401 IRQCHIP_DECLARE(ixp46x, "intel,ixp46x-interrupt",
402 ixp4xx_of_init_irq);
403 #endif