2 * Interrupt handler for DaVinci boards.
4 * Copyright (C) 2006 Texas Instruments.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
26 #include <mach/hardware.h>
28 #include <asm/mach/irq.h>
30 #define IRQ_BIT(irq) ((irq) & 0x1f)
32 #define FIQ_REG0_OFFSET 0x0000
33 #define FIQ_REG1_OFFSET 0x0004
34 #define IRQ_REG0_OFFSET 0x0008
35 #define IRQ_REG1_OFFSET 0x000C
36 #define IRQ_ENT_REG0_OFFSET 0x0018
37 #define IRQ_ENT_REG1_OFFSET 0x001C
38 #define IRQ_INCTL_REG_OFFSET 0x0020
39 #define IRQ_EABASE_REG_OFFSET 0x0024
40 #define IRQ_INTPRI0_REG_OFFSET 0x0030
41 #define IRQ_INTPRI7_REG_OFFSET 0x004C
43 static inline unsigned int davinci_irq_readl(int offset)
45 return davinci_readl(DAVINCI_ARM_INTC_BASE + offset);
48 static inline void davinci_irq_writel(unsigned long value, int offset)
50 davinci_writel(value, DAVINCI_ARM_INTC_BASE + offset);
53 /* Disable interrupt */
54 static void davinci_mask_irq(unsigned int irq)
59 mask = 1 << IRQ_BIT(irq);
62 l = davinci_irq_readl(IRQ_ENT_REG1_OFFSET);
64 davinci_irq_writel(l, IRQ_ENT_REG1_OFFSET);
66 l = davinci_irq_readl(IRQ_ENT_REG0_OFFSET);
68 davinci_irq_writel(l, IRQ_ENT_REG0_OFFSET);
72 /* Enable interrupt */
73 static void davinci_unmask_irq(unsigned int irq)
78 mask = 1 << IRQ_BIT(irq);
81 l = davinci_irq_readl(IRQ_ENT_REG1_OFFSET);
83 davinci_irq_writel(l, IRQ_ENT_REG1_OFFSET);
85 l = davinci_irq_readl(IRQ_ENT_REG0_OFFSET);
87 davinci_irq_writel(l, IRQ_ENT_REG0_OFFSET);
92 static void davinci_ack_irq(unsigned int irq)
96 mask = 1 << IRQ_BIT(irq);
99 davinci_irq_writel(mask, IRQ_REG1_OFFSET);
101 davinci_irq_writel(mask, IRQ_REG0_OFFSET);
104 static struct irq_chip davinci_irq_chip_0 = {
106 .ack = davinci_ack_irq,
107 .mask = davinci_mask_irq,
108 .unmask = davinci_unmask_irq,
112 /* FIQ are pri 0-1; otherwise 2-7, with 7 lowest priority */
113 static const u8 default_priorities[DAVINCI_N_AINTC_IRQ] __initdata = {
130 [IRQ_CCINT0] = 5, /* dma */
131 [IRQ_CCERRINT] = 5, /* dma */
132 [IRQ_TCERRINT0] = 5, /* dma */
133 [IRQ_TCERRINT] = 5, /* dma */
146 [IRQ_TINT0_TINT12] = 2, /* clockevent */
147 [IRQ_TINT0_TINT34] = 2, /* clocksource */
148 [IRQ_TINT1_TINT12] = 7, /* DSP timer */
149 [IRQ_TINT1_TINT34] = 7, /* system tick */
180 /* ARM Interrupt Controller Initialization */
181 void __init davinci_irq_init(void)
184 const u8 *priority = default_priorities;
186 /* Clear all interrupt requests */
187 davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
188 davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
189 davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
190 davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);
192 /* Disable all interrupts */
193 davinci_irq_writel(0x0, IRQ_ENT_REG0_OFFSET);
194 davinci_irq_writel(0x0, IRQ_ENT_REG1_OFFSET);
196 /* Interrupts disabled immediately, IRQ entry reflects all */
197 davinci_irq_writel(0x0, IRQ_INCTL_REG_OFFSET);
199 /* we don't use the hardware vector table, just its entry addresses */
200 davinci_irq_writel(0, IRQ_EABASE_REG_OFFSET);
202 /* Clear all interrupt requests */
203 davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
204 davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
205 davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
206 davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);
208 for (i = IRQ_INTPRI0_REG_OFFSET; i <= IRQ_INTPRI7_REG_OFFSET; i += 4) {
212 for (j = 0, pri = 0; j < 32; j += 4, priority++)
213 pri |= (*priority & 0x07) << j;
214 davinci_irq_writel(pri, i);
217 /* set up genirq dispatch for ARM INTC */
218 for (i = 0; i < DAVINCI_N_AINTC_IRQ; i++) {
219 set_irq_chip(i, &davinci_irq_chip_0);
220 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
221 if (i != IRQ_TINT1_TINT34)
222 set_irq_handler(i, handle_edge_irq);
224 set_irq_handler(i, handle_level_irq);