]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/mach-omap2/irq.c
Merge current mainline tree into linux-omap tree
[linux-2.6-omap-h63xx.git] / arch / arm / mach-omap2 / irq.c
1 /*
2  * linux/arch/arm/mach-omap2/irq.c
3  *
4  * Interrupt handler for OMAP2 boards.
5  *
6  * Copyright (C) 2005 Nokia Corporation
7  * Author: Paul Mundt <paul.mundt@nokia.com>
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License. See the file "COPYING" in the main directory of this archive
11  * for more details.
12  */
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/interrupt.h>
16 #include <mach/hardware.h>
17 #include <asm/mach/irq.h>
18 #include <linux/io.h>
19
20 /* selected INTC register offsets */
21
22 #define INTC_REVISION           0x0000
23 #define INTC_SYSCONFIG          0x0010
24 #define INTC_SYSSTATUS          0x0014
25 #define INTC_CONTROL            0x0048
26 #define INTC_MIR_CLEAR0         0x0088
27 #define INTC_MIR_SET0           0x008c
28 #define INTC_PENDING_IRQ0       0x0098
29
30 /* Number of IRQ state bits in each MIR register */
31 #define IRQ_BITS_PER_REG        32
32
33 /*
34  * OMAP2 has a number of different interrupt controllers, each interrupt
35  * controller is identified as its own "bank". Register definitions are
36  * fairly consistent for each bank, but not all registers are implemented
37  * for each bank.. when in doubt, consult the TRM.
38  */
39 static struct omap_irq_bank {
40         void __iomem *base_reg;
41         unsigned int nr_irqs;
42 } __attribute__ ((aligned(4))) irq_banks[] = {
43         {
44                 /* MPU INTC */
45                 .base_reg       = 0,
46                 .nr_irqs        = 96,
47         },
48 };
49
50 /* INTC bank register get/set */
51
52 static void intc_bank_write_reg(u32 val, struct omap_irq_bank *bank, u16 reg)
53 {
54         __raw_writel(val, (__force void __iomem *)(bank->base_reg + reg));
55 }
56
57 static u32 intc_bank_read_reg(struct omap_irq_bank *bank, u16 reg)
58 {
59         return __raw_readl((__force void __iomem *)(bank->base_reg + reg));
60 }
61
62 /* XXX: FIQ and additional INTC support (only MPU at the moment) */
63 static void omap_ack_irq(unsigned int irq)
64 {
65         intc_bank_write_reg(0x1, &irq_banks[0], INTC_CONTROL);
66 }
67
68 static void omap_mask_irq(unsigned int irq)
69 {
70         int offset = irq & (~(IRQ_BITS_PER_REG - 1));
71
72         irq &= (IRQ_BITS_PER_REG - 1);
73
74         intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
75 }
76
77 static void omap_unmask_irq(unsigned int irq)
78 {
79         int offset = irq & (~(IRQ_BITS_PER_REG - 1));
80
81         irq &= (IRQ_BITS_PER_REG - 1);
82
83         intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
84 }
85
86 static void omap_mask_ack_irq(unsigned int irq)
87 {
88         omap_mask_irq(irq);
89         omap_ack_irq(irq);
90 }
91
92 static struct irq_chip omap_irq_chip = {
93         .name   = "INTC",
94         .ack    = omap_mask_ack_irq,
95         .mask   = omap_mask_irq,
96         .unmask = omap_unmask_irq,
97 };
98
99 static void __init omap_irq_bank_init_one(struct omap_irq_bank *bank)
100 {
101         unsigned long tmp;
102
103         tmp = intc_bank_read_reg(bank, INTC_REVISION) & 0xff;
104         printk(KERN_INFO "IRQ: Found an INTC at 0x%p "
105                          "(revision %ld.%ld) with %d interrupts\n",
106                          bank->base_reg, tmp >> 4, tmp & 0xf, bank->nr_irqs);
107
108         tmp = intc_bank_read_reg(bank, INTC_SYSCONFIG);
109         tmp |= 1 << 1;  /* soft reset */
110         intc_bank_write_reg(tmp, bank, INTC_SYSCONFIG);
111
112         while (!(intc_bank_read_reg(bank, INTC_SYSSTATUS) & 0x1))
113                 /* Wait for reset to complete */;
114
115         /* Enable autoidle */
116         intc_bank_write_reg(1 << 0, bank, INTC_SYSCONFIG);
117 }
118
119 int omap_irq_pending(void)
120 {
121         int i;
122
123         for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
124                 struct omap_irq_bank *bank = irq_banks + i;
125                 int irq;
126
127                 for (irq = 0; irq < bank->nr_irqs; irq += IRQ_BITS_PER_REG) {
128                         int offset = irq & (~(IRQ_BITS_PER_REG - 1));
129
130                         if (intc_bank_read_reg(bank, (INTC_PENDING_IRQ0 +
131                                                       offset)))
132                                 return 1;
133                 }
134         }
135
136         return 0;
137 }
138
139 void __init omap_init_irq(void)
140 {
141         unsigned long nr_irqs = 0;
142         unsigned int nr_banks = 0;
143         int i;
144
145         for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
146                 struct omap_irq_bank *bank = irq_banks + i;
147
148                 if (cpu_is_omap24xx())
149                         bank->base_reg = OMAP2_IO_ADDRESS(OMAP24XX_IC_BASE);
150                 else if (cpu_is_omap34xx())
151                         bank->base_reg = OMAP2_IO_ADDRESS(OMAP34XX_IC_BASE);
152
153                 omap_irq_bank_init_one(bank);
154
155                 nr_irqs += bank->nr_irqs;
156                 nr_banks++;
157         }
158
159         printk(KERN_INFO "Total of %ld interrupts on %d active controller%s\n",
160                nr_irqs, nr_banks, nr_banks > 1 ? "s" : "");
161
162         for (i = 0; i < nr_irqs; i++) {
163                 set_irq_chip(i, &omap_irq_chip);
164                 set_irq_handler(i, handle_level_irq);
165                 set_irq_flags(i, IRQF_VALID);
166         }
167 }
168