2 * linux/arch/arm/mach-at91/irq.c
4 * Copyright (C) 2004 SAN People
5 * Copyright (C) 2004 ATMEL
6 * Copyright (C) Rick Bronson
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.
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.
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
23 #include <linux/init.h>
24 #include <linux/module.h>
26 #include <linux/types.h>
27 #include <linux/irq.h>
29 #include <linux/of_address.h>
30 #include <linux/of_irq.h>
31 #include <linux/irqdomain.h>
32 #include <linux/err.h>
34 #include <mach/hardware.h>
36 #include <asm/setup.h>
38 #include <asm/mach/arch.h>
39 #include <asm/mach/irq.h>
40 #include <asm/mach/map.h>
42 void __iomem *at91_aic_base;
43 static struct irq_domain *at91_aic_domain;
44 static struct device_node *at91_aic_np;
46 static void at91_aic_mask_irq(struct irq_data *d)
48 /* Disable interrupt on AIC */
49 at91_aic_write(AT91_AIC_IDCR, 1 << d->hwirq);
52 static void at91_aic_unmask_irq(struct irq_data *d)
54 /* Enable interrupt on AIC */
55 at91_aic_write(AT91_AIC_IECR, 1 << d->hwirq);
58 unsigned int at91_extern_irq;
60 #define is_extern_irq(hwirq) ((1 << (hwirq)) & at91_extern_irq)
62 static int at91_aic_set_type(struct irq_data *d, unsigned type)
64 unsigned int smr, srctype;
67 case IRQ_TYPE_LEVEL_HIGH:
68 srctype = AT91_AIC_SRCTYPE_HIGH;
70 case IRQ_TYPE_EDGE_RISING:
71 srctype = AT91_AIC_SRCTYPE_RISING;
73 case IRQ_TYPE_LEVEL_LOW:
74 if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */
75 srctype = AT91_AIC_SRCTYPE_LOW;
79 case IRQ_TYPE_EDGE_FALLING:
80 if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */
81 srctype = AT91_AIC_SRCTYPE_FALLING;
89 smr = at91_aic_read(AT91_AIC_SMR(d->hwirq)) & ~AT91_AIC_SRCTYPE;
90 at91_aic_write(AT91_AIC_SMR(d->hwirq), smr | srctype);
99 static int at91_aic_set_wake(struct irq_data *d, unsigned value)
101 if (unlikely(d->hwirq >= NR_AIC_IRQS))
105 wakeups |= (1 << d->hwirq);
107 wakeups &= ~(1 << d->hwirq);
112 void at91_irq_suspend(void)
114 backups = at91_aic_read(AT91_AIC_IMR);
115 at91_aic_write(AT91_AIC_IDCR, backups);
116 at91_aic_write(AT91_AIC_IECR, wakeups);
119 void at91_irq_resume(void)
121 at91_aic_write(AT91_AIC_IDCR, wakeups);
122 at91_aic_write(AT91_AIC_IECR, backups);
126 #define at91_aic_set_wake NULL
129 static struct irq_chip at91_aic_chip = {
131 .irq_ack = at91_aic_mask_irq,
132 .irq_mask = at91_aic_mask_irq,
133 .irq_unmask = at91_aic_unmask_irq,
134 .irq_set_type = at91_aic_set_type,
135 .irq_set_wake = at91_aic_set_wake,
138 static void __init at91_aic_hw_init(unsigned int spu_vector)
143 * Perform 8 End Of Interrupt Command to make sure AIC
144 * will not Lock out nIRQ
146 for (i = 0; i < 8; i++)
147 at91_aic_write(AT91_AIC_EOICR, 0);
150 * Spurious Interrupt ID in Spurious Vector Register.
151 * When there is no current interrupt, the IRQ Vector Register
152 * reads the value stored in AIC_SPU
154 at91_aic_write(AT91_AIC_SPU, spu_vector);
156 /* No debugging in AIC: Debug (Protect) Control Register */
157 at91_aic_write(AT91_AIC_DCR, 0);
159 /* Disable and clear all interrupts initially */
160 at91_aic_write(AT91_AIC_IDCR, 0xFFFFFFFF);
161 at91_aic_write(AT91_AIC_ICCR, 0xFFFFFFFF);
164 #if defined(CONFIG_OF)
165 static int at91_aic_irq_map(struct irq_domain *h, unsigned int virq,
168 /* Put virq number in Source Vector Register */
169 at91_aic_write(AT91_AIC_SVR(hw), virq);
171 /* Active Low interrupt, without priority */
172 at91_aic_write(AT91_AIC_SMR(hw), AT91_AIC_SRCTYPE_LOW);
174 irq_set_chip_and_handler(virq, &at91_aic_chip, handle_level_irq);
175 set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
180 static struct irq_domain_ops at91_aic_irq_ops = {
181 .map = at91_aic_irq_map,
182 .xlate = irq_domain_xlate_twocell,
185 int __init at91_aic_of_init(struct device_node *node,
186 struct device_node *parent)
188 at91_aic_base = of_iomap(node, 0);
191 at91_aic_domain = irq_domain_add_linear(at91_aic_np, NR_AIC_IRQS,
192 &at91_aic_irq_ops, NULL);
193 if (!at91_aic_domain)
194 panic("Unable to add AIC irq domain (DT)\n");
196 irq_set_default_host(at91_aic_domain);
198 at91_aic_hw_init(NR_AIC_IRQS);
205 * Initialize the AIC interrupt controller.
207 void __init at91_aic_init(unsigned int priority[NR_AIC_IRQS])
212 at91_aic_base = ioremap(AT91_AIC, 512);
214 panic("Unable to ioremap AIC registers\n");
216 /* Add irq domain for AIC */
217 irq_base = irq_alloc_descs(-1, 0, NR_AIC_IRQS, 0);
219 WARN(1, "Cannot allocate irq_descs, assuming pre-allocated\n");
222 at91_aic_domain = irq_domain_add_legacy(at91_aic_np, NR_AIC_IRQS,
224 &irq_domain_simple_ops, NULL);
226 if (!at91_aic_domain)
227 panic("Unable to add AIC irq domain\n");
229 irq_set_default_host(at91_aic_domain);
232 * The IVR is used by macro get_irqnr_and_base to read and verify.
233 * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
235 for (i = 0; i < NR_AIC_IRQS; i++) {
236 /* Put hardware irq number in Source Vector Register: */
237 at91_aic_write(AT91_AIC_SVR(i), i);
238 /* Active Low interrupt, with the specified priority */
239 at91_aic_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);
241 irq_set_chip_and_handler(i, &at91_aic_chip, handle_level_irq);
242 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
245 at91_aic_hw_init(NR_AIC_IRQS);