irqchip: Fix dependencies for archs w/o HAS_IOMEM
[linux/fpc-iii.git] / arch / arm / mach-dove / irq.c
blobbfb3703357c55aba72674827527e0fba68650b3e
1 /*
2 * arch/arm/mach-dove/irq.c
4 * Dove IRQ handling.
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/irq.h>
14 #include <linux/gpio.h>
15 #include <linux/io.h>
16 #include <asm/mach/arch.h>
17 #include <plat/irq.h>
18 #include <asm/mach/irq.h>
19 #include <mach/pm.h>
20 #include <mach/bridge-regs.h>
21 #include <plat/orion-gpio.h>
22 #include "common.h"
24 static void pmu_irq_mask(struct irq_data *d)
26 int pin = irq_to_pmu(d->irq);
27 u32 u;
29 u = readl(PMU_INTERRUPT_MASK);
30 u &= ~(1 << (pin & 31));
31 writel(u, PMU_INTERRUPT_MASK);
34 static void pmu_irq_unmask(struct irq_data *d)
36 int pin = irq_to_pmu(d->irq);
37 u32 u;
39 u = readl(PMU_INTERRUPT_MASK);
40 u |= 1 << (pin & 31);
41 writel(u, PMU_INTERRUPT_MASK);
44 static void pmu_irq_ack(struct irq_data *d)
46 int pin = irq_to_pmu(d->irq);
47 u32 u;
50 * The PMU mask register is not RW0C: it is RW. This means that
51 * the bits take whatever value is written to them; if you write
52 * a '1', you will set the interrupt.
54 * Unfortunately this means there is NO race free way to clear
55 * these interrupts.
57 * So, let's structure the code so that the window is as small as
58 * possible.
60 u = ~(1 << (pin & 31));
61 u &= readl_relaxed(PMU_INTERRUPT_CAUSE);
62 writel_relaxed(u, PMU_INTERRUPT_CAUSE);
65 static struct irq_chip pmu_irq_chip = {
66 .name = "pmu_irq",
67 .irq_mask = pmu_irq_mask,
68 .irq_unmask = pmu_irq_unmask,
69 .irq_ack = pmu_irq_ack,
72 static void pmu_irq_handler(struct irq_desc *desc)
74 unsigned long cause = readl(PMU_INTERRUPT_CAUSE);
75 unsigned int irq;
77 cause &= readl(PMU_INTERRUPT_MASK);
78 if (cause == 0) {
79 do_bad_IRQ(desc);
80 return;
83 for (irq = 0; irq < NR_PMU_IRQS; irq++) {
84 if (!(cause & (1 << irq)))
85 continue;
86 irq = pmu_to_irq(irq);
87 generic_handle_irq(irq);
91 static int __initdata gpio0_irqs[4] = {
92 IRQ_DOVE_GPIO_0_7,
93 IRQ_DOVE_GPIO_8_15,
94 IRQ_DOVE_GPIO_16_23,
95 IRQ_DOVE_GPIO_24_31,
98 static int __initdata gpio1_irqs[4] = {
99 IRQ_DOVE_HIGH_GPIO,
105 static int __initdata gpio2_irqs[4] = {
112 #ifdef CONFIG_MULTI_IRQ_HANDLER
114 * Compiling with both non-DT and DT support enabled, will
115 * break asm irq handler used by non-DT boards. Therefore,
116 * we provide a C-style irq handler even for non-DT boards,
117 * if MULTI_IRQ_HANDLER is set.
120 static void __iomem *dove_irq_base = IRQ_VIRT_BASE;
122 static asmlinkage void
123 __exception_irq_entry dove_legacy_handle_irq(struct pt_regs *regs)
125 u32 stat;
127 stat = readl_relaxed(dove_irq_base + IRQ_CAUSE_LOW_OFF);
128 stat &= readl_relaxed(dove_irq_base + IRQ_MASK_LOW_OFF);
129 if (stat) {
130 unsigned int hwirq = 1 + __fls(stat);
131 handle_IRQ(hwirq, regs);
132 return;
134 stat = readl_relaxed(dove_irq_base + IRQ_CAUSE_HIGH_OFF);
135 stat &= readl_relaxed(dove_irq_base + IRQ_MASK_HIGH_OFF);
136 if (stat) {
137 unsigned int hwirq = 33 + __fls(stat);
138 handle_IRQ(hwirq, regs);
139 return;
142 #endif
144 void __init dove_init_irq(void)
146 int i;
148 orion_irq_init(1, IRQ_VIRT_BASE + IRQ_MASK_LOW_OFF);
149 orion_irq_init(33, IRQ_VIRT_BASE + IRQ_MASK_HIGH_OFF);
151 #ifdef CONFIG_MULTI_IRQ_HANDLER
152 set_handle_irq(dove_legacy_handle_irq);
153 #endif
156 * Initialize gpiolib for GPIOs 0-71.
158 orion_gpio_init(NULL, 0, 32, DOVE_GPIO_LO_VIRT_BASE, 0,
159 IRQ_DOVE_GPIO_START, gpio0_irqs);
161 orion_gpio_init(NULL, 32, 32, DOVE_GPIO_HI_VIRT_BASE, 0,
162 IRQ_DOVE_GPIO_START + 32, gpio1_irqs);
164 orion_gpio_init(NULL, 64, 8, DOVE_GPIO2_VIRT_BASE, 0,
165 IRQ_DOVE_GPIO_START + 64, gpio2_irqs);
168 * Mask and clear PMU interrupts
170 writel(0, PMU_INTERRUPT_MASK);
171 writel(0, PMU_INTERRUPT_CAUSE);
173 for (i = IRQ_DOVE_PMU_START; i < NR_IRQS; i++) {
174 irq_set_chip_and_handler(i, &pmu_irq_chip, handle_level_irq);
175 irq_set_status_flags(i, IRQ_LEVEL);
176 irq_clear_status_flags(i, IRQ_NOREQUEST);
178 irq_set_chained_handler(IRQ_DOVE_PMU, pmu_irq_handler);