blob: e0ca59171022fb8f2cee7a488cc2ee622c238384 [file] [log] [blame]
SAN People73a59c12006-01-09 17:05:41 +00001/*
Andrew Victor9d041262007-02-05 11:42:07 +01002 * linux/arch/arm/mach-at91/irq.c
SAN People73a59c12006-01-09 17:05:41 +00003 *
4 * Copyright (C) 2004 SAN People
5 * Copyright (C) 2004 ATMEL
6 * Copyright (C) Rick Bronson
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
SAN People73a59c12006-01-09 17:05:41 +000023#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/mm.h>
Ludovic Desrochesc4b68522012-05-30 10:01:09 +020026#include <linux/bitmap.h>
SAN People73a59c12006-01-09 17:05:41 +000027#include <linux/types.h>
Nicolas Ferree2615012011-11-22 22:26:09 +010028#include <linux/irq.h>
29#include <linux/of.h>
30#include <linux/of_address.h>
31#include <linux/of_irq.h>
32#include <linux/irqdomain.h>
33#include <linux/err.h>
Ludovic Desrochesf8a073e2012-06-20 16:13:30 +020034#include <linux/slab.h>
SAN People73a59c12006-01-09 17:05:41 +000035
Russell Kinga09e64f2008-08-05 16:14:15 +010036#include <mach/hardware.h>
SAN People73a59c12006-01-09 17:05:41 +000037#include <asm/irq.h>
SAN People73a59c12006-01-09 17:05:41 +000038#include <asm/setup.h>
39
Ludovic Desroches3e135462012-06-11 15:38:03 +020040#include <asm/exception.h>
SAN People73a59c12006-01-09 17:05:41 +000041#include <asm/mach/arch.h>
42#include <asm/mach/irq.h>
43#include <asm/mach/map.h>
44
Jean-Christophe PLAGNIOL-VILLARDa510b9b2012-10-30 06:41:28 +080045#include "at91_aic.h"
Ludovic Desroches8fe82a52012-06-21 14:47:27 +020046
Jean-Christophe PLAGNIOL-VILLARDbe6d4322011-11-03 01:12:50 +080047void __iomem *at91_aic_base;
Nicolas Ferree2615012011-11-22 22:26:09 +010048static struct irq_domain *at91_aic_domain;
49static struct device_node *at91_aic_np;
Ludovic Desrochesc4b68522012-05-30 10:01:09 +020050static unsigned int n_irqs = NR_AIC_IRQS;
51static unsigned long at91_aic_caps = 0;
SAN People73a59c12006-01-09 17:05:41 +000052
Ludovic Desrochesc4b68522012-05-30 10:01:09 +020053/* AIC5 introduces a Source Select Register */
54#define AT91_AIC_CAP_AIC5 (1 << 0)
55#define has_aic5() (at91_aic_caps & AT91_AIC_CAP_AIC5)
56
57#ifdef CONFIG_PM
58
59static unsigned long *wakeups;
60static unsigned long *backups;
61
62#define set_backup(bit) set_bit(bit, backups)
63#define clear_backup(bit) clear_bit(bit, backups)
64
65static int at91_aic_pm_init(void)
66{
67 backups = kzalloc(BITS_TO_LONGS(n_irqs) * sizeof(*backups), GFP_KERNEL);
68 if (!backups)
69 return -ENOMEM;
70
71 wakeups = kzalloc(BITS_TO_LONGS(n_irqs) * sizeof(*backups), GFP_KERNEL);
72 if (!wakeups) {
73 kfree(backups);
74 return -ENOMEM;
75 }
76
77 return 0;
78}
79
80static int at91_aic_set_wake(struct irq_data *d, unsigned value)
81{
82 if (unlikely(d->hwirq >= n_irqs))
83 return -EINVAL;
84
85 if (value)
86 set_bit(d->hwirq, wakeups);
87 else
88 clear_bit(d->hwirq, wakeups);
89
90 return 0;
91}
92
93void at91_irq_suspend(void)
94{
Ludovic Desroches0ed66be2013-03-08 16:13:57 +010095 int bit = -1;
Ludovic Desrochesc4b68522012-05-30 10:01:09 +020096
97 if (has_aic5()) {
98 /* disable enabled irqs */
Ludovic Desroches0ed66be2013-03-08 16:13:57 +010099 while ((bit = find_next_bit(backups, n_irqs, bit + 1)) < n_irqs) {
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200100 at91_aic_write(AT91_AIC5_SSR,
101 bit & AT91_AIC5_INTSEL_MSK);
102 at91_aic_write(AT91_AIC5_IDCR, 1);
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200103 }
104 /* enable wakeup irqs */
Ludovic Desroches0ed66be2013-03-08 16:13:57 +0100105 bit = -1;
106 while ((bit = find_next_bit(wakeups, n_irqs, bit + 1)) < n_irqs) {
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200107 at91_aic_write(AT91_AIC5_SSR,
108 bit & AT91_AIC5_INTSEL_MSK);
109 at91_aic_write(AT91_AIC5_IECR, 1);
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200110 }
111 } else {
112 at91_aic_write(AT91_AIC_IDCR, *backups);
113 at91_aic_write(AT91_AIC_IECR, *wakeups);
114 }
115}
116
117void at91_irq_resume(void)
118{
Ludovic Desroches0ed66be2013-03-08 16:13:57 +0100119 int bit = -1;
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200120
121 if (has_aic5()) {
122 /* disable wakeup irqs */
Ludovic Desroches0ed66be2013-03-08 16:13:57 +0100123 while ((bit = find_next_bit(wakeups, n_irqs, bit + 1)) < n_irqs) {
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200124 at91_aic_write(AT91_AIC5_SSR,
125 bit & AT91_AIC5_INTSEL_MSK);
126 at91_aic_write(AT91_AIC5_IDCR, 1);
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200127 }
128 /* enable irqs disabled for suspend */
Ludovic Desroches0ed66be2013-03-08 16:13:57 +0100129 bit = -1;
130 while ((bit = find_next_bit(backups, n_irqs, bit + 1)) < n_irqs) {
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200131 at91_aic_write(AT91_AIC5_SSR,
132 bit & AT91_AIC5_INTSEL_MSK);
133 at91_aic_write(AT91_AIC5_IECR, 1);
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200134 }
135 } else {
136 at91_aic_write(AT91_AIC_IDCR, *wakeups);
137 at91_aic_write(AT91_AIC_IECR, *backups);
138 }
139}
140
141#else
142static inline int at91_aic_pm_init(void)
143{
144 return 0;
145}
146
147#define set_backup(bit)
148#define clear_backup(bit)
149#define at91_aic_set_wake NULL
150
151#endif /* CONFIG_PM */
152
153asmlinkage void __exception_irq_entry
154at91_aic_handle_irq(struct pt_regs *regs)
Ludovic Desroches3e135462012-06-11 15:38:03 +0200155{
156 u32 irqnr;
157 u32 irqstat;
158
159 irqnr = at91_aic_read(AT91_AIC_IVR);
160 irqstat = at91_aic_read(AT91_AIC_ISR);
161
162 /*
163 * ISR value is 0 when there is no current interrupt or when there is
164 * a spurious interrupt
165 */
166 if (!irqstat)
167 at91_aic_write(AT91_AIC_EOICR, 0);
168 else
169 handle_IRQ(irqnr, regs);
170}
171
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200172asmlinkage void __exception_irq_entry
173at91_aic5_handle_irq(struct pt_regs *regs)
174{
175 u32 irqnr;
176 u32 irqstat;
177
178 irqnr = at91_aic_read(AT91_AIC5_IVR);
179 irqstat = at91_aic_read(AT91_AIC5_ISR);
180
181 if (!irqstat)
182 at91_aic_write(AT91_AIC5_EOICR, 0);
183 else
184 handle_IRQ(irqnr, regs);
185}
186
Lennert Buytenhekda0f9402010-11-29 10:26:19 +0100187static void at91_aic_mask_irq(struct irq_data *d)
SAN People73a59c12006-01-09 17:05:41 +0000188{
189 /* Disable interrupt on AIC */
Nicolas Ferree2615012011-11-22 22:26:09 +0100190 at91_aic_write(AT91_AIC_IDCR, 1 << d->hwirq);
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200191 /* Update ISR cache */
192 clear_backup(d->hwirq);
193}
194
195static void __maybe_unused at91_aic5_mask_irq(struct irq_data *d)
196{
197 /* Disable interrupt on AIC5 */
198 at91_aic_write(AT91_AIC5_SSR, d->hwirq & AT91_AIC5_INTSEL_MSK);
199 at91_aic_write(AT91_AIC5_IDCR, 1);
200 /* Update ISR cache */
201 clear_backup(d->hwirq);
SAN People73a59c12006-01-09 17:05:41 +0000202}
203
Lennert Buytenhekda0f9402010-11-29 10:26:19 +0100204static void at91_aic_unmask_irq(struct irq_data *d)
SAN People73a59c12006-01-09 17:05:41 +0000205{
206 /* Enable interrupt on AIC */
Nicolas Ferree2615012011-11-22 22:26:09 +0100207 at91_aic_write(AT91_AIC_IECR, 1 << d->hwirq);
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200208 /* Update ISR cache */
209 set_backup(d->hwirq);
210}
211
212static void __maybe_unused at91_aic5_unmask_irq(struct irq_data *d)
213{
214 /* Enable interrupt on AIC5 */
215 at91_aic_write(AT91_AIC5_SSR, d->hwirq & AT91_AIC5_INTSEL_MSK);
216 at91_aic_write(AT91_AIC5_IECR, 1);
217 /* Update ISR cache */
218 set_backup(d->hwirq);
SAN People73a59c12006-01-09 17:05:41 +0000219}
220
Ludovic Desroches42a859d2012-05-25 14:11:51 +0200221static void at91_aic_eoi(struct irq_data *d)
222{
223 /*
224 * Mark end-of-interrupt on AIC, the controller doesn't care about
225 * the value written. Moreover it's a write-only register.
226 */
227 at91_aic_write(AT91_AIC_EOICR, 0);
228}
229
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200230static void __maybe_unused at91_aic5_eoi(struct irq_data *d)
SAN People73a59c12006-01-09 17:05:41 +0000231{
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200232 at91_aic_write(AT91_AIC5_EOICR, 0);
233}
234
235unsigned long *at91_extern_irq;
236
237#define is_extern_irq(hwirq) test_bit(hwirq, at91_extern_irq)
238
239static int at91_aic_compute_srctype(struct irq_data *d, unsigned type)
240{
241 int srctype;
SAN People73a59c12006-01-09 17:05:41 +0000242
SAN People73a59c12006-01-09 17:05:41 +0000243 switch (type) {
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100244 case IRQ_TYPE_LEVEL_HIGH:
SAN People73a59c12006-01-09 17:05:41 +0000245 srctype = AT91_AIC_SRCTYPE_HIGH;
246 break;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100247 case IRQ_TYPE_EDGE_RISING:
SAN People73a59c12006-01-09 17:05:41 +0000248 srctype = AT91_AIC_SRCTYPE_RISING;
249 break;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100250 case IRQ_TYPE_LEVEL_LOW:
Nicolas Ferree2615012011-11-22 22:26:09 +0100251 if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */
Andrew Victor1f4fd0a2006-11-30 10:01:47 +0100252 srctype = AT91_AIC_SRCTYPE_LOW;
253 else
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200254 srctype = -EINVAL;
SAN People73a59c12006-01-09 17:05:41 +0000255 break;
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100256 case IRQ_TYPE_EDGE_FALLING:
Nicolas Ferree2615012011-11-22 22:26:09 +0100257 if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */
Andrew Victor1f4fd0a2006-11-30 10:01:47 +0100258 srctype = AT91_AIC_SRCTYPE_FALLING;
259 else
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200260 srctype = -EINVAL;
SAN People73a59c12006-01-09 17:05:41 +0000261 break;
262 default:
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200263 srctype = -EINVAL;
SAN People73a59c12006-01-09 17:05:41 +0000264 }
265
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200266 return srctype;
SAN People73a59c12006-01-09 17:05:41 +0000267}
268
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200269static int at91_aic_set_type(struct irq_data *d, unsigned type)
Andrew Victor683c66b2006-06-19 15:26:53 +0100270{
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200271 unsigned int smr;
272 int srctype;
Andrew Victor683c66b2006-06-19 15:26:53 +0100273
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200274 srctype = at91_aic_compute_srctype(d, type);
275 if (srctype < 0)
276 return srctype;
277
278 if (has_aic5()) {
279 at91_aic_write(AT91_AIC5_SSR,
280 d->hwirq & AT91_AIC5_INTSEL_MSK);
281 smr = at91_aic_read(AT91_AIC5_SMR) & ~AT91_AIC_SRCTYPE;
282 at91_aic_write(AT91_AIC5_SMR, smr | srctype);
283 } else {
284 smr = at91_aic_read(AT91_AIC_SMR(d->hwirq))
285 & ~AT91_AIC_SRCTYPE;
286 at91_aic_write(AT91_AIC_SMR(d->hwirq), smr | srctype);
287 }
Andrew Victor683c66b2006-06-19 15:26:53 +0100288
289 return 0;
290}
291
David Brownell38c677c2006-08-01 22:26:25 +0100292static struct irq_chip at91_aic_chip = {
293 .name = "AIC",
Lennert Buytenhekda0f9402010-11-29 10:26:19 +0100294 .irq_mask = at91_aic_mask_irq,
295 .irq_unmask = at91_aic_unmask_irq,
296 .irq_set_type = at91_aic_set_type,
297 .irq_set_wake = at91_aic_set_wake,
Ludovic Desroches42a859d2012-05-25 14:11:51 +0200298 .irq_eoi = at91_aic_eoi,
SAN People73a59c12006-01-09 17:05:41 +0000299};
300
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100301static void __init at91_aic_hw_init(unsigned int spu_vector)
302{
303 int i;
304
305 /*
306 * Perform 8 End Of Interrupt Command to make sure AIC
307 * will not Lock out nIRQ
308 */
309 for (i = 0; i < 8; i++)
310 at91_aic_write(AT91_AIC_EOICR, 0);
311
312 /*
313 * Spurious Interrupt ID in Spurious Vector Register.
314 * When there is no current interrupt, the IRQ Vector Register
315 * reads the value stored in AIC_SPU
316 */
317 at91_aic_write(AT91_AIC_SPU, spu_vector);
318
319 /* No debugging in AIC: Debug (Protect) Control Register */
320 at91_aic_write(AT91_AIC_DCR, 0);
321
322 /* Disable and clear all interrupts initially */
323 at91_aic_write(AT91_AIC_IDCR, 0xFFFFFFFF);
324 at91_aic_write(AT91_AIC_ICCR, 0xFFFFFFFF);
325}
326
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200327static void __init __maybe_unused at91_aic5_hw_init(unsigned int spu_vector)
328{
329 int i;
330
331 /*
332 * Perform 8 End Of Interrupt Command to make sure AIC
333 * will not Lock out nIRQ
334 */
335 for (i = 0; i < 8; i++)
336 at91_aic_write(AT91_AIC5_EOICR, 0);
337
338 /*
339 * Spurious Interrupt ID in Spurious Vector Register.
340 * When there is no current interrupt, the IRQ Vector Register
341 * reads the value stored in AIC_SPU
342 */
343 at91_aic_write(AT91_AIC5_SPU, spu_vector);
344
345 /* No debugging in AIC: Debug (Protect) Control Register */
346 at91_aic_write(AT91_AIC5_DCR, 0);
347
348 /* Disable and clear all interrupts initially */
349 for (i = 0; i < n_irqs; i++) {
350 at91_aic_write(AT91_AIC5_SSR, i & AT91_AIC5_INTSEL_MSK);
351 at91_aic_write(AT91_AIC5_IDCR, 1);
352 at91_aic_write(AT91_AIC5_ICCR, 1);
353 }
354}
355
Nicolas Ferree2615012011-11-22 22:26:09 +0100356#if defined(CONFIG_OF)
Arnd Bergmann14070ad2012-07-04 07:45:16 +0000357static unsigned int *at91_aic_irq_priorities;
358
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100359static int at91_aic_irq_map(struct irq_domain *h, unsigned int virq,
360 irq_hw_number_t hw)
361{
362 /* Put virq number in Source Vector Register */
363 at91_aic_write(AT91_AIC_SVR(hw), virq);
364
Ludovic Desrochesf8a073e2012-06-20 16:13:30 +0200365 /* Active Low interrupt, with priority */
366 at91_aic_write(AT91_AIC_SMR(hw),
367 AT91_AIC_SRCTYPE_LOW | at91_aic_irq_priorities[hw]);
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100368
Ludovic Desroches42a859d2012-05-25 14:11:51 +0200369 irq_set_chip_and_handler(virq, &at91_aic_chip, handle_fasteoi_irq);
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100370 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
371
372 return 0;
373}
374
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200375static int at91_aic5_irq_map(struct irq_domain *h, unsigned int virq,
376 irq_hw_number_t hw)
377{
378 at91_aic_write(AT91_AIC5_SSR, hw & AT91_AIC5_INTSEL_MSK);
379
380 /* Put virq number in Source Vector Register */
381 at91_aic_write(AT91_AIC5_SVR, virq);
382
383 /* Active Low interrupt, with priority */
384 at91_aic_write(AT91_AIC5_SMR,
385 AT91_AIC_SRCTYPE_LOW | at91_aic_irq_priorities[hw]);
386
387 irq_set_chip_and_handler(virq, &at91_aic_chip, handle_fasteoi_irq);
388 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
389
390 return 0;
391}
392
Ludovic Desrochesf8a073e2012-06-20 16:13:30 +0200393static int at91_aic_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr,
394 const u32 *intspec, unsigned int intsize,
395 irq_hw_number_t *out_hwirq, unsigned int *out_type)
396{
397 if (WARN_ON(intsize < 3))
398 return -EINVAL;
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200399 if (WARN_ON(intspec[0] >= n_irqs))
Ludovic Desrochesf8a073e2012-06-20 16:13:30 +0200400 return -EINVAL;
401 if (WARN_ON((intspec[2] < AT91_AIC_IRQ_MIN_PRIORITY)
402 || (intspec[2] > AT91_AIC_IRQ_MAX_PRIORITY)))
403 return -EINVAL;
404
405 *out_hwirq = intspec[0];
406 *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
407 at91_aic_irq_priorities[*out_hwirq] = intspec[2];
408
409 return 0;
410}
411
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100412static struct irq_domain_ops at91_aic_irq_ops = {
413 .map = at91_aic_irq_map,
Ludovic Desrochesf8a073e2012-06-20 16:13:30 +0200414 .xlate = at91_aic_irq_domain_xlate,
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100415};
416
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200417int __init at91_aic_of_common_init(struct device_node *node,
418 struct device_node *parent)
Nicolas Ferree2615012011-11-22 22:26:09 +0100419{
Jean-Christophe PLAGNIOL-VILLARDc6573942012-04-09 19:36:36 +0800420 struct property *prop;
421 const __be32 *p;
422 u32 val;
423
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200424 at91_extern_irq = kzalloc(BITS_TO_LONGS(n_irqs)
425 * sizeof(*at91_extern_irq), GFP_KERNEL);
426 if (!at91_extern_irq)
427 return -ENOMEM;
428
429 if (at91_aic_pm_init()) {
430 kfree(at91_extern_irq);
431 return -ENOMEM;
432 }
433
434 at91_aic_irq_priorities = kzalloc(n_irqs
Ludovic Desrochesf8a073e2012-06-20 16:13:30 +0200435 * sizeof(*at91_aic_irq_priorities),
436 GFP_KERNEL);
437 if (!at91_aic_irq_priorities)
438 return -ENOMEM;
439
Nicolas Ferree2615012011-11-22 22:26:09 +0100440 at91_aic_base = of_iomap(node, 0);
441 at91_aic_np = node;
442
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200443 at91_aic_domain = irq_domain_add_linear(at91_aic_np, n_irqs,
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100444 &at91_aic_irq_ops, NULL);
445 if (!at91_aic_domain)
446 panic("Unable to add AIC irq domain (DT)\n");
447
Jean-Christophe PLAGNIOL-VILLARDc6573942012-04-09 19:36:36 +0800448 of_property_for_each_u32(node, "atmel,external-irqs", prop, p, val) {
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200449 if (val >= n_irqs)
450 pr_warn("AIC: external irq %d >= %d skip it\n",
451 val, n_irqs);
Jean-Christophe PLAGNIOL-VILLARDc6573942012-04-09 19:36:36 +0800452 else
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200453 set_bit(val, at91_extern_irq);
Jean-Christophe PLAGNIOL-VILLARDc6573942012-04-09 19:36:36 +0800454 }
455
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100456 irq_set_default_host(at91_aic_domain);
457
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200458 return 0;
459}
460
461int __init at91_aic_of_init(struct device_node *node,
462 struct device_node *parent)
463{
464 int err;
465
466 err = at91_aic_of_common_init(node, parent);
467 if (err)
468 return err;
469
470 at91_aic_hw_init(n_irqs);
471
472 return 0;
473}
474
475int __init at91_aic5_of_init(struct device_node *node,
476 struct device_node *parent)
477{
478 int err;
479
480 at91_aic_caps |= AT91_AIC_CAP_AIC5;
481 n_irqs = NR_AIC5_IRQS;
482 at91_aic_chip.irq_ack = at91_aic5_mask_irq;
483 at91_aic_chip.irq_mask = at91_aic5_mask_irq;
484 at91_aic_chip.irq_unmask = at91_aic5_unmask_irq;
485 at91_aic_chip.irq_eoi = at91_aic5_eoi;
486 at91_aic_irq_ops.map = at91_aic5_irq_map;
487
488 err = at91_aic_of_common_init(node, parent);
489 if (err)
490 return err;
491
492 at91_aic5_hw_init(n_irqs);
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100493
Nicolas Ferree2615012011-11-22 22:26:09 +0100494 return 0;
495}
Nicolas Ferree2615012011-11-22 22:26:09 +0100496#endif
497
SAN People73a59c12006-01-09 17:05:41 +0000498/*
499 * Initialize the AIC interrupt controller.
500 */
Nicolas Ferre738a0fd2012-10-24 16:09:57 +0200501void __init at91_aic_init(unsigned int *priority, unsigned int ext_irq_mask)
SAN People73a59c12006-01-09 17:05:41 +0000502{
503 unsigned int i;
Nicolas Ferree2615012011-11-22 22:26:09 +0100504 int irq_base;
SAN People73a59c12006-01-09 17:05:41 +0000505
Nicolas Ferre738a0fd2012-10-24 16:09:57 +0200506 at91_extern_irq = kzalloc(BITS_TO_LONGS(n_irqs)
507 * sizeof(*at91_extern_irq), GFP_KERNEL);
508
509 if (at91_aic_pm_init() || at91_extern_irq == NULL)
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200510 panic("Unable to allocate bit maps\n");
511
Nicolas Ferre738a0fd2012-10-24 16:09:57 +0200512 *at91_extern_irq = ext_irq_mask;
513
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100514 at91_aic_base = ioremap(AT91_AIC, 512);
Jean-Christophe PLAGNIOL-VILLARDbe6d4322011-11-03 01:12:50 +0800515 if (!at91_aic_base)
Nicolas Ferree2615012011-11-22 22:26:09 +0100516 panic("Unable to ioremap AIC registers\n");
517
518 /* Add irq domain for AIC */
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200519 irq_base = irq_alloc_descs(-1, 0, n_irqs, 0);
Nicolas Ferree2615012011-11-22 22:26:09 +0100520 if (irq_base < 0) {
521 WARN(1, "Cannot allocate irq_descs, assuming pre-allocated\n");
522 irq_base = 0;
523 }
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200524 at91_aic_domain = irq_domain_add_legacy(at91_aic_np, n_irqs,
Nicolas Ferree2615012011-11-22 22:26:09 +0100525 irq_base, 0,
526 &irq_domain_simple_ops, NULL);
527
528 if (!at91_aic_domain)
529 panic("Unable to add AIC irq domain\n");
Jean-Christophe PLAGNIOL-VILLARDbe6d4322011-11-03 01:12:50 +0800530
Nicolas Ferre8014d6f2012-02-14 18:08:14 +0100531 irq_set_default_host(at91_aic_domain);
532
SAN People73a59c12006-01-09 17:05:41 +0000533 /*
534 * The IVR is used by macro get_irqnr_and_base to read and verify.
535 * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
536 */
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200537 for (i = 0; i < n_irqs; i++) {
Nicolas Ferree2615012011-11-22 22:26:09 +0100538 /* Put hardware irq number in Source Vector Register: */
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200539 at91_aic_write(AT91_AIC_SVR(i), NR_IRQS_LEGACY + i);
Andrew Victorba854e12006-07-05 17:22:52 +0100540 /* Active Low interrupt, with the specified priority */
Jean-Christophe PLAGNIOL-VILLARDbe6d4322011-11-03 01:12:50 +0800541 at91_aic_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);
Ludovic Desroches8fe82a52012-06-21 14:47:27 +0200542 irq_set_chip_and_handler(NR_IRQS_LEGACY + i, &at91_aic_chip, handle_fasteoi_irq);
SAN People73a59c12006-01-09 17:05:41 +0000543 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
SAN People73a59c12006-01-09 17:05:41 +0000544 }
545
Ludovic Desrochesc4b68522012-05-30 10:01:09 +0200546 at91_aic_hw_init(n_irqs);
SAN People73a59c12006-01-09 17:05:41 +0000547}