1b1479ebbSBoris BREZILLON /*
2b1479ebbSBoris BREZILLON * Atmel AT91 AIC5 (Advanced Interrupt Controller) driver
3b1479ebbSBoris BREZILLON *
4b1479ebbSBoris BREZILLON * Copyright (C) 2004 SAN People
5b1479ebbSBoris BREZILLON * Copyright (C) 2004 ATMEL
6b1479ebbSBoris BREZILLON * Copyright (C) Rick Bronson
7b1479ebbSBoris BREZILLON * Copyright (C) 2014 Free Electrons
8b1479ebbSBoris BREZILLON *
9b1479ebbSBoris BREZILLON * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
10b1479ebbSBoris BREZILLON *
11b1479ebbSBoris BREZILLON * This file is licensed under the terms of the GNU General Public
12b1479ebbSBoris BREZILLON * License version 2. This program is licensed "as is" without any
13b1479ebbSBoris BREZILLON * warranty of any kind, whether express or implied.
14b1479ebbSBoris BREZILLON */
15b1479ebbSBoris BREZILLON
16b1479ebbSBoris BREZILLON #include <linux/init.h>
17b1479ebbSBoris BREZILLON #include <linux/module.h>
18b1479ebbSBoris BREZILLON #include <linux/mm.h>
19b1479ebbSBoris BREZILLON #include <linux/bitmap.h>
20b1479ebbSBoris BREZILLON #include <linux/types.h>
21b1479ebbSBoris BREZILLON #include <linux/irq.h>
2241a83e06SJoel Porquet #include <linux/irqchip.h>
23b1479ebbSBoris BREZILLON #include <linux/of.h>
24b1479ebbSBoris BREZILLON #include <linux/of_address.h>
25b1479ebbSBoris BREZILLON #include <linux/of_irq.h>
26b1479ebbSBoris BREZILLON #include <linux/irqdomain.h>
27b1479ebbSBoris BREZILLON #include <linux/err.h>
28b1479ebbSBoris BREZILLON #include <linux/slab.h>
29b1479ebbSBoris BREZILLON #include <linux/io.h>
30b1479ebbSBoris BREZILLON
31b1479ebbSBoris BREZILLON #include <asm/exception.h>
32b1479ebbSBoris BREZILLON #include <asm/mach/irq.h>
33b1479ebbSBoris BREZILLON
34b1479ebbSBoris BREZILLON #include "irq-atmel-aic-common.h"
35b1479ebbSBoris BREZILLON
36b1479ebbSBoris BREZILLON /* Number of irq lines managed by AIC */
37b1479ebbSBoris BREZILLON #define NR_AIC5_IRQS 128
38b1479ebbSBoris BREZILLON
39b1479ebbSBoris BREZILLON #define AT91_AIC5_SSR 0x0
40b1479ebbSBoris BREZILLON #define AT91_AIC5_INTSEL_MSK (0x7f << 0)
41b1479ebbSBoris BREZILLON
42b1479ebbSBoris BREZILLON #define AT91_AIC5_SMR 0x4
43b1479ebbSBoris BREZILLON
44b1479ebbSBoris BREZILLON #define AT91_AIC5_SVR 0x8
45b1479ebbSBoris BREZILLON #define AT91_AIC5_IVR 0x10
46b1479ebbSBoris BREZILLON #define AT91_AIC5_FVR 0x14
47b1479ebbSBoris BREZILLON #define AT91_AIC5_ISR 0x18
48b1479ebbSBoris BREZILLON
49b1479ebbSBoris BREZILLON #define AT91_AIC5_IPR0 0x20
50b1479ebbSBoris BREZILLON #define AT91_AIC5_IPR1 0x24
51b1479ebbSBoris BREZILLON #define AT91_AIC5_IPR2 0x28
52b1479ebbSBoris BREZILLON #define AT91_AIC5_IPR3 0x2c
53b1479ebbSBoris BREZILLON #define AT91_AIC5_IMR 0x30
54b1479ebbSBoris BREZILLON #define AT91_AIC5_CISR 0x34
55b1479ebbSBoris BREZILLON
56b1479ebbSBoris BREZILLON #define AT91_AIC5_IECR 0x40
57b1479ebbSBoris BREZILLON #define AT91_AIC5_IDCR 0x44
58b1479ebbSBoris BREZILLON #define AT91_AIC5_ICCR 0x48
59b1479ebbSBoris BREZILLON #define AT91_AIC5_ISCR 0x4c
60b1479ebbSBoris BREZILLON #define AT91_AIC5_EOICR 0x38
61b1479ebbSBoris BREZILLON #define AT91_AIC5_SPU 0x3c
62b1479ebbSBoris BREZILLON #define AT91_AIC5_DCR 0x6c
63b1479ebbSBoris BREZILLON
64b1479ebbSBoris BREZILLON #define AT91_AIC5_FFER 0x50
65b1479ebbSBoris BREZILLON #define AT91_AIC5_FFDR 0x54
66b1479ebbSBoris BREZILLON #define AT91_AIC5_FFSR 0x58
67b1479ebbSBoris BREZILLON
68b1479ebbSBoris BREZILLON static struct irq_domain *aic5_domain;
69b1479ebbSBoris BREZILLON
70b1479ebbSBoris BREZILLON static asmlinkage void __exception_irq_entry
aic5_handle(struct pt_regs * regs)71b1479ebbSBoris BREZILLON aic5_handle(struct pt_regs *regs)
72b1479ebbSBoris BREZILLON {
73b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(aic5_domain, 0);
74b1479ebbSBoris BREZILLON u32 irqnr;
75b1479ebbSBoris BREZILLON u32 irqstat;
76b1479ebbSBoris BREZILLON
77414a431aSLudovic Desroches irqnr = irq_reg_readl(bgc, AT91_AIC5_IVR);
78414a431aSLudovic Desroches irqstat = irq_reg_readl(bgc, AT91_AIC5_ISR);
79b1479ebbSBoris BREZILLON
80b1479ebbSBoris BREZILLON if (!irqstat)
81414a431aSLudovic Desroches irq_reg_writel(bgc, 0, AT91_AIC5_EOICR);
82b1479ebbSBoris BREZILLON else
83*0953fb26SMark Rutland generic_handle_domain_irq(aic5_domain, irqnr);
84b1479ebbSBoris BREZILLON }
85b1479ebbSBoris BREZILLON
aic5_mask(struct irq_data * d)86b1479ebbSBoris BREZILLON static void aic5_mask(struct irq_data *d)
87b1479ebbSBoris BREZILLON {
88b1479ebbSBoris BREZILLON struct irq_domain *domain = d->domain;
89b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
90d32dc9aaSLudovic Desroches struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
91b1479ebbSBoris BREZILLON
92d32dc9aaSLudovic Desroches /*
93d32dc9aaSLudovic Desroches * Disable interrupt on AIC5. We always take the lock of the
94d32dc9aaSLudovic Desroches * first irq chip as all chips share the same registers.
95d32dc9aaSLudovic Desroches */
96d32dc9aaSLudovic Desroches irq_gc_lock(bgc);
97332fd7c4SKevin Cernekee irq_reg_writel(gc, d->hwirq, AT91_AIC5_SSR);
98332fd7c4SKevin Cernekee irq_reg_writel(gc, 1, AT91_AIC5_IDCR);
99b1479ebbSBoris BREZILLON gc->mask_cache &= ~d->mask;
100d32dc9aaSLudovic Desroches irq_gc_unlock(bgc);
101b1479ebbSBoris BREZILLON }
102b1479ebbSBoris BREZILLON
aic5_unmask(struct irq_data * d)103b1479ebbSBoris BREZILLON static void aic5_unmask(struct irq_data *d)
104b1479ebbSBoris BREZILLON {
105b1479ebbSBoris BREZILLON struct irq_domain *domain = d->domain;
106b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
107d32dc9aaSLudovic Desroches struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
108b1479ebbSBoris BREZILLON
109d32dc9aaSLudovic Desroches /*
110d32dc9aaSLudovic Desroches * Enable interrupt on AIC5. We always take the lock of the
111d32dc9aaSLudovic Desroches * first irq chip as all chips share the same registers.
112d32dc9aaSLudovic Desroches */
113d32dc9aaSLudovic Desroches irq_gc_lock(bgc);
114332fd7c4SKevin Cernekee irq_reg_writel(gc, d->hwirq, AT91_AIC5_SSR);
115332fd7c4SKevin Cernekee irq_reg_writel(gc, 1, AT91_AIC5_IECR);
116b1479ebbSBoris BREZILLON gc->mask_cache |= d->mask;
117d32dc9aaSLudovic Desroches irq_gc_unlock(bgc);
118b1479ebbSBoris BREZILLON }
119b1479ebbSBoris BREZILLON
aic5_retrigger(struct irq_data * d)120b1479ebbSBoris BREZILLON static int aic5_retrigger(struct irq_data *d)
121b1479ebbSBoris BREZILLON {
122b1479ebbSBoris BREZILLON struct irq_domain *domain = d->domain;
123b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
124b1479ebbSBoris BREZILLON
125b1479ebbSBoris BREZILLON /* Enable interrupt on AIC5 */
126414a431aSLudovic Desroches irq_gc_lock(bgc);
127414a431aSLudovic Desroches irq_reg_writel(bgc, d->hwirq, AT91_AIC5_SSR);
128414a431aSLudovic Desroches irq_reg_writel(bgc, 1, AT91_AIC5_ISCR);
129414a431aSLudovic Desroches irq_gc_unlock(bgc);
130b1479ebbSBoris BREZILLON
1314ddfc459SMarc Zyngier return 1;
132b1479ebbSBoris BREZILLON }
133b1479ebbSBoris BREZILLON
aic5_set_type(struct irq_data * d,unsigned type)134b1479ebbSBoris BREZILLON static int aic5_set_type(struct irq_data *d, unsigned type)
135b1479ebbSBoris BREZILLON {
136b1479ebbSBoris BREZILLON struct irq_domain *domain = d->domain;
137b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
138b1479ebbSBoris BREZILLON unsigned int smr;
139b1479ebbSBoris BREZILLON int ret;
140b1479ebbSBoris BREZILLON
141414a431aSLudovic Desroches irq_gc_lock(bgc);
142414a431aSLudovic Desroches irq_reg_writel(bgc, d->hwirq, AT91_AIC5_SSR);
143414a431aSLudovic Desroches smr = irq_reg_readl(bgc, AT91_AIC5_SMR);
144b1479ebbSBoris BREZILLON ret = aic_common_set_type(d, type, &smr);
145b1479ebbSBoris BREZILLON if (!ret)
146414a431aSLudovic Desroches irq_reg_writel(bgc, smr, AT91_AIC5_SMR);
147414a431aSLudovic Desroches irq_gc_unlock(bgc);
148b1479ebbSBoris BREZILLON
149b1479ebbSBoris BREZILLON return ret;
150b1479ebbSBoris BREZILLON }
151b1479ebbSBoris BREZILLON
152b1479ebbSBoris BREZILLON #ifdef CONFIG_PM
153a50ac562SAlexandre Belloni static u32 *smr_cache;
154a50ac562SAlexandre Belloni
aic5_suspend(struct irq_data * d)155b1479ebbSBoris BREZILLON static void aic5_suspend(struct irq_data *d)
156b1479ebbSBoris BREZILLON {
157b1479ebbSBoris BREZILLON struct irq_domain *domain = d->domain;
158b1479ebbSBoris BREZILLON struct irq_domain_chip_generic *dgc = domain->gc;
159b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
160b1479ebbSBoris BREZILLON struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
161b1479ebbSBoris BREZILLON int i;
162b1479ebbSBoris BREZILLON u32 mask;
163b1479ebbSBoris BREZILLON
164a50ac562SAlexandre Belloni if (smr_cache)
165a50ac562SAlexandre Belloni for (i = 0; i < domain->revmap_size; i++) {
166a50ac562SAlexandre Belloni irq_reg_writel(bgc, i, AT91_AIC5_SSR);
167a50ac562SAlexandre Belloni smr_cache[i] = irq_reg_readl(bgc, AT91_AIC5_SMR);
168a50ac562SAlexandre Belloni }
169a50ac562SAlexandre Belloni
170b1479ebbSBoris BREZILLON irq_gc_lock(bgc);
171b1479ebbSBoris BREZILLON for (i = 0; i < dgc->irqs_per_chip; i++) {
172b1479ebbSBoris BREZILLON mask = 1 << i;
173b1479ebbSBoris BREZILLON if ((mask & gc->mask_cache) == (mask & gc->wake_active))
174b1479ebbSBoris BREZILLON continue;
175b1479ebbSBoris BREZILLON
176332fd7c4SKevin Cernekee irq_reg_writel(bgc, i + gc->irq_base, AT91_AIC5_SSR);
177b1479ebbSBoris BREZILLON if (mask & gc->wake_active)
178332fd7c4SKevin Cernekee irq_reg_writel(bgc, 1, AT91_AIC5_IECR);
179b1479ebbSBoris BREZILLON else
180332fd7c4SKevin Cernekee irq_reg_writel(bgc, 1, AT91_AIC5_IDCR);
181b1479ebbSBoris BREZILLON }
182b1479ebbSBoris BREZILLON irq_gc_unlock(bgc);
183b1479ebbSBoris BREZILLON }
184b1479ebbSBoris BREZILLON
aic5_resume(struct irq_data * d)185b1479ebbSBoris BREZILLON static void aic5_resume(struct irq_data *d)
186b1479ebbSBoris BREZILLON {
187b1479ebbSBoris BREZILLON struct irq_domain *domain = d->domain;
188b1479ebbSBoris BREZILLON struct irq_domain_chip_generic *dgc = domain->gc;
189b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
190b1479ebbSBoris BREZILLON struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
191b1479ebbSBoris BREZILLON int i;
192b1479ebbSBoris BREZILLON u32 mask;
193b1479ebbSBoris BREZILLON
194b1479ebbSBoris BREZILLON irq_gc_lock(bgc);
195a50ac562SAlexandre Belloni
196a50ac562SAlexandre Belloni if (smr_cache) {
197a50ac562SAlexandre Belloni irq_reg_writel(bgc, 0xffffffff, AT91_AIC5_SPU);
198a50ac562SAlexandre Belloni for (i = 0; i < domain->revmap_size; i++) {
199a50ac562SAlexandre Belloni irq_reg_writel(bgc, i, AT91_AIC5_SSR);
200a50ac562SAlexandre Belloni irq_reg_writel(bgc, i, AT91_AIC5_SVR);
201a50ac562SAlexandre Belloni irq_reg_writel(bgc, smr_cache[i], AT91_AIC5_SMR);
202a50ac562SAlexandre Belloni }
203a50ac562SAlexandre Belloni }
204a50ac562SAlexandre Belloni
205b1479ebbSBoris BREZILLON for (i = 0; i < dgc->irqs_per_chip; i++) {
206b1479ebbSBoris BREZILLON mask = 1 << i;
207a50ac562SAlexandre Belloni
208a50ac562SAlexandre Belloni if (!smr_cache &&
209a50ac562SAlexandre Belloni ((mask & gc->mask_cache) == (mask & gc->wake_active)))
210b1479ebbSBoris BREZILLON continue;
211b1479ebbSBoris BREZILLON
212332fd7c4SKevin Cernekee irq_reg_writel(bgc, i + gc->irq_base, AT91_AIC5_SSR);
213b1479ebbSBoris BREZILLON if (mask & gc->mask_cache)
214332fd7c4SKevin Cernekee irq_reg_writel(bgc, 1, AT91_AIC5_IECR);
215b1479ebbSBoris BREZILLON else
216332fd7c4SKevin Cernekee irq_reg_writel(bgc, 1, AT91_AIC5_IDCR);
217b1479ebbSBoris BREZILLON }
218b1479ebbSBoris BREZILLON irq_gc_unlock(bgc);
219b1479ebbSBoris BREZILLON }
220b1479ebbSBoris BREZILLON
aic5_pm_shutdown(struct irq_data * d)221b1479ebbSBoris BREZILLON static void aic5_pm_shutdown(struct irq_data *d)
222b1479ebbSBoris BREZILLON {
223b1479ebbSBoris BREZILLON struct irq_domain *domain = d->domain;
224b1479ebbSBoris BREZILLON struct irq_domain_chip_generic *dgc = domain->gc;
225b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(domain, 0);
226b1479ebbSBoris BREZILLON struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
227b1479ebbSBoris BREZILLON int i;
228b1479ebbSBoris BREZILLON
229b1479ebbSBoris BREZILLON irq_gc_lock(bgc);
230b1479ebbSBoris BREZILLON for (i = 0; i < dgc->irqs_per_chip; i++) {
231332fd7c4SKevin Cernekee irq_reg_writel(bgc, i + gc->irq_base, AT91_AIC5_SSR);
232332fd7c4SKevin Cernekee irq_reg_writel(bgc, 1, AT91_AIC5_IDCR);
233332fd7c4SKevin Cernekee irq_reg_writel(bgc, 1, AT91_AIC5_ICCR);
234b1479ebbSBoris BREZILLON }
235b1479ebbSBoris BREZILLON irq_gc_unlock(bgc);
236b1479ebbSBoris BREZILLON }
237b1479ebbSBoris BREZILLON #else
238b1479ebbSBoris BREZILLON #define aic5_suspend NULL
239b1479ebbSBoris BREZILLON #define aic5_resume NULL
240b1479ebbSBoris BREZILLON #define aic5_pm_shutdown NULL
241b1479ebbSBoris BREZILLON #endif /* CONFIG_PM */
242b1479ebbSBoris BREZILLON
aic5_hw_init(struct irq_domain * domain)243b1479ebbSBoris BREZILLON static void __init aic5_hw_init(struct irq_domain *domain)
244b1479ebbSBoris BREZILLON {
245b1479ebbSBoris BREZILLON struct irq_chip_generic *gc = irq_get_domain_generic_chip(domain, 0);
246b1479ebbSBoris BREZILLON int i;
247b1479ebbSBoris BREZILLON
248b1479ebbSBoris BREZILLON /*
249b1479ebbSBoris BREZILLON * Perform 8 End Of Interrupt Command to make sure AIC
250b1479ebbSBoris BREZILLON * will not Lock out nIRQ
251b1479ebbSBoris BREZILLON */
252b1479ebbSBoris BREZILLON for (i = 0; i < 8; i++)
253332fd7c4SKevin Cernekee irq_reg_writel(gc, 0, AT91_AIC5_EOICR);
254b1479ebbSBoris BREZILLON
255b1479ebbSBoris BREZILLON /*
256b1479ebbSBoris BREZILLON * Spurious Interrupt ID in Spurious Vector Register.
257b1479ebbSBoris BREZILLON * When there is no current interrupt, the IRQ Vector Register
258b1479ebbSBoris BREZILLON * reads the value stored in AIC_SPU
259b1479ebbSBoris BREZILLON */
260332fd7c4SKevin Cernekee irq_reg_writel(gc, 0xffffffff, AT91_AIC5_SPU);
261b1479ebbSBoris BREZILLON
262b1479ebbSBoris BREZILLON /* No debugging in AIC: Debug (Protect) Control Register */
263332fd7c4SKevin Cernekee irq_reg_writel(gc, 0, AT91_AIC5_DCR);
264b1479ebbSBoris BREZILLON
265b1479ebbSBoris BREZILLON /* Disable and clear all interrupts initially */
266b1479ebbSBoris BREZILLON for (i = 0; i < domain->revmap_size; i++) {
267332fd7c4SKevin Cernekee irq_reg_writel(gc, i, AT91_AIC5_SSR);
268332fd7c4SKevin Cernekee irq_reg_writel(gc, i, AT91_AIC5_SVR);
269332fd7c4SKevin Cernekee irq_reg_writel(gc, 1, AT91_AIC5_IDCR);
270332fd7c4SKevin Cernekee irq_reg_writel(gc, 1, AT91_AIC5_ICCR);
271b1479ebbSBoris BREZILLON }
272b1479ebbSBoris BREZILLON }
273b1479ebbSBoris BREZILLON
aic5_irq_domain_xlate(struct irq_domain * d,struct device_node * ctrlr,const u32 * intspec,unsigned int intsize,irq_hw_number_t * out_hwirq,unsigned int * out_type)274b1479ebbSBoris BREZILLON static int aic5_irq_domain_xlate(struct irq_domain *d,
275b1479ebbSBoris BREZILLON struct device_node *ctrlr,
276b1479ebbSBoris BREZILLON const u32 *intspec, unsigned int intsize,
277b1479ebbSBoris BREZILLON irq_hw_number_t *out_hwirq,
278b1479ebbSBoris BREZILLON unsigned int *out_type)
279b1479ebbSBoris BREZILLON {
280b55a3bb8SLudovic Desroches struct irq_chip_generic *bgc = irq_get_domain_generic_chip(d, 0);
2815eb0d6ebSBoris Brezillon unsigned long flags;
282b1479ebbSBoris BREZILLON unsigned smr;
283b1479ebbSBoris BREZILLON int ret;
284b1479ebbSBoris BREZILLON
285b55a3bb8SLudovic Desroches if (!bgc)
286b1479ebbSBoris BREZILLON return -EINVAL;
287b1479ebbSBoris BREZILLON
288b1479ebbSBoris BREZILLON ret = aic_common_irq_domain_xlate(d, ctrlr, intspec, intsize,
289b1479ebbSBoris BREZILLON out_hwirq, out_type);
290b1479ebbSBoris BREZILLON if (ret)
291b1479ebbSBoris BREZILLON return ret;
292b1479ebbSBoris BREZILLON
2935eb0d6ebSBoris Brezillon irq_gc_lock_irqsave(bgc, flags);
294414a431aSLudovic Desroches irq_reg_writel(bgc, *out_hwirq, AT91_AIC5_SSR);
295414a431aSLudovic Desroches smr = irq_reg_readl(bgc, AT91_AIC5_SMR);
2965fd26a0bSMilo Kim aic_common_set_priority(intspec[2], &smr);
2974b5ce20bSMilo Kim irq_reg_writel(bgc, smr, AT91_AIC5_SMR);
2985eb0d6ebSBoris Brezillon irq_gc_unlock_irqrestore(bgc, flags);
299b1479ebbSBoris BREZILLON
300b1479ebbSBoris BREZILLON return ret;
301b1479ebbSBoris BREZILLON }
302b1479ebbSBoris BREZILLON
303b1479ebbSBoris BREZILLON static const struct irq_domain_ops aic5_irq_ops = {
304b1479ebbSBoris BREZILLON .map = irq_map_generic_chip,
305b1479ebbSBoris BREZILLON .xlate = aic5_irq_domain_xlate,
306b1479ebbSBoris BREZILLON };
307b1479ebbSBoris BREZILLON
sama5d3_aic_irq_fixup(void)3080a46230bSBoris Brezillon static void __init sama5d3_aic_irq_fixup(void)
3096704d12dSBoris BREZILLON {
3100a46230bSBoris Brezillon aic_common_rtc_irq_fixup();
3116704d12dSBoris BREZILLON }
3126704d12dSBoris BREZILLON
sam9x60_aic_irq_fixup(void)313293953d6SClaudiu Beznea static void __init sam9x60_aic_irq_fixup(void)
314293953d6SClaudiu Beznea {
315293953d6SClaudiu Beznea aic_common_rtc_irq_fixup();
316293953d6SClaudiu Beznea aic_common_rtt_irq_fixup();
317293953d6SClaudiu Beznea }
318293953d6SClaudiu Beznea
319c376023bSNicolas Pitre static const struct of_device_id aic5_irq_fixups[] __initconst = {
3206704d12dSBoris BREZILLON { .compatible = "atmel,sama5d3", .data = sama5d3_aic_irq_fixup },
32120afdeb8SAlexandre Belloni { .compatible = "atmel,sama5d4", .data = sama5d3_aic_irq_fixup },
322293953d6SClaudiu Beznea { .compatible = "microchip,sam9x60", .data = sam9x60_aic_irq_fixup },
3236704d12dSBoris BREZILLON { /* sentinel */ },
3246704d12dSBoris BREZILLON };
3256704d12dSBoris BREZILLON
aic5_of_init(struct device_node * node,struct device_node * parent,int nirqs)326b1479ebbSBoris BREZILLON static int __init aic5_of_init(struct device_node *node,
327b1479ebbSBoris BREZILLON struct device_node *parent,
328b1479ebbSBoris BREZILLON int nirqs)
329b1479ebbSBoris BREZILLON {
330b1479ebbSBoris BREZILLON struct irq_chip_generic *gc;
331b1479ebbSBoris BREZILLON struct irq_domain *domain;
332b1479ebbSBoris BREZILLON int nchips;
333b1479ebbSBoris BREZILLON int i;
334b1479ebbSBoris BREZILLON
335b1479ebbSBoris BREZILLON if (nirqs > NR_AIC5_IRQS)
336b1479ebbSBoris BREZILLON return -EINVAL;
337b1479ebbSBoris BREZILLON
338b1479ebbSBoris BREZILLON if (aic5_domain)
339b1479ebbSBoris BREZILLON return -EEXIST;
340b1479ebbSBoris BREZILLON
341b1479ebbSBoris BREZILLON domain = aic_common_of_init(node, &aic5_irq_ops, "atmel-aic5",
342dd85c791SMilo Kim nirqs, aic5_irq_fixups);
343b1479ebbSBoris BREZILLON if (IS_ERR(domain))
344b1479ebbSBoris BREZILLON return PTR_ERR(domain);
345b1479ebbSBoris BREZILLON
346b1479ebbSBoris BREZILLON aic5_domain = domain;
347b1479ebbSBoris BREZILLON nchips = aic5_domain->revmap_size / 32;
348b1479ebbSBoris BREZILLON for (i = 0; i < nchips; i++) {
349b1479ebbSBoris BREZILLON gc = irq_get_domain_generic_chip(domain, i * 32);
350b1479ebbSBoris BREZILLON
351b1479ebbSBoris BREZILLON gc->chip_types[0].regs.eoi = AT91_AIC5_EOICR;
352b1479ebbSBoris BREZILLON gc->chip_types[0].chip.irq_mask = aic5_mask;
353b1479ebbSBoris BREZILLON gc->chip_types[0].chip.irq_unmask = aic5_unmask;
354b1479ebbSBoris BREZILLON gc->chip_types[0].chip.irq_retrigger = aic5_retrigger;
355b1479ebbSBoris BREZILLON gc->chip_types[0].chip.irq_set_type = aic5_set_type;
356b1479ebbSBoris BREZILLON gc->chip_types[0].chip.irq_suspend = aic5_suspend;
357b1479ebbSBoris BREZILLON gc->chip_types[0].chip.irq_resume = aic5_resume;
358b1479ebbSBoris BREZILLON gc->chip_types[0].chip.irq_pm_shutdown = aic5_pm_shutdown;
359b1479ebbSBoris BREZILLON }
360b1479ebbSBoris BREZILLON
361b1479ebbSBoris BREZILLON aic5_hw_init(domain);
362b1479ebbSBoris BREZILLON set_handle_irq(aic5_handle);
363b1479ebbSBoris BREZILLON
364b1479ebbSBoris BREZILLON return 0;
365b1479ebbSBoris BREZILLON }
366b1479ebbSBoris BREZILLON
36762a993dfSNicolas Ferre #define NR_SAMA5D2_IRQS 77
36862a993dfSNicolas Ferre
sama5d2_aic5_of_init(struct device_node * node,struct device_node * parent)36962a993dfSNicolas Ferre static int __init sama5d2_aic5_of_init(struct device_node *node,
37062a993dfSNicolas Ferre struct device_node *parent)
37162a993dfSNicolas Ferre {
372a50ac562SAlexandre Belloni #ifdef CONFIG_PM
373a50ac562SAlexandre Belloni smr_cache = kcalloc(DIV_ROUND_UP(NR_SAMA5D2_IRQS, 32) * 32,
374a50ac562SAlexandre Belloni sizeof(*smr_cache), GFP_KERNEL);
375a50ac562SAlexandre Belloni if (!smr_cache)
376a50ac562SAlexandre Belloni return -ENOMEM;
377a50ac562SAlexandre Belloni #endif
378a50ac562SAlexandre Belloni
37962a993dfSNicolas Ferre return aic5_of_init(node, parent, NR_SAMA5D2_IRQS);
38062a993dfSNicolas Ferre }
38162a993dfSNicolas Ferre IRQCHIP_DECLARE(sama5d2_aic5, "atmel,sama5d2-aic", sama5d2_aic5_of_init);
38262a993dfSNicolas Ferre
3830cae165fSAlexandre Belloni #define NR_SAMA5D3_IRQS 48
384b1479ebbSBoris BREZILLON
sama5d3_aic5_of_init(struct device_node * node,struct device_node * parent)385b1479ebbSBoris BREZILLON static int __init sama5d3_aic5_of_init(struct device_node *node,
386b1479ebbSBoris BREZILLON struct device_node *parent)
387b1479ebbSBoris BREZILLON {
388b1479ebbSBoris BREZILLON return aic5_of_init(node, parent, NR_SAMA5D3_IRQS);
389b1479ebbSBoris BREZILLON }
390b1479ebbSBoris BREZILLON IRQCHIP_DECLARE(sama5d3_aic5, "atmel,sama5d3-aic", sama5d3_aic5_of_init);
39120afdeb8SAlexandre Belloni
39220afdeb8SAlexandre Belloni #define NR_SAMA5D4_IRQS 68
39320afdeb8SAlexandre Belloni
sama5d4_aic5_of_init(struct device_node * node,struct device_node * parent)39420afdeb8SAlexandre Belloni static int __init sama5d4_aic5_of_init(struct device_node *node,
39520afdeb8SAlexandre Belloni struct device_node *parent)
39620afdeb8SAlexandre Belloni {
39720afdeb8SAlexandre Belloni return aic5_of_init(node, parent, NR_SAMA5D4_IRQS);
39820afdeb8SAlexandre Belloni }
39920afdeb8SAlexandre Belloni IRQCHIP_DECLARE(sama5d4_aic5, "atmel,sama5d4-aic", sama5d4_aic5_of_init);
400212fbf2cSSandeep Sheriker Mallikarjun
401212fbf2cSSandeep Sheriker Mallikarjun #define NR_SAM9X60_IRQS 50
402212fbf2cSSandeep Sheriker Mallikarjun
sam9x60_aic5_of_init(struct device_node * node,struct device_node * parent)403212fbf2cSSandeep Sheriker Mallikarjun static int __init sam9x60_aic5_of_init(struct device_node *node,
404212fbf2cSSandeep Sheriker Mallikarjun struct device_node *parent)
405212fbf2cSSandeep Sheriker Mallikarjun {
406212fbf2cSSandeep Sheriker Mallikarjun return aic5_of_init(node, parent, NR_SAM9X60_IRQS);
407212fbf2cSSandeep Sheriker Mallikarjun }
408212fbf2cSSandeep Sheriker Mallikarjun IRQCHIP_DECLARE(sam9x60_aic5, "microchip,sam9x60-aic", sam9x60_aic5_of_init);
409