2 * linux/arch/arm/mach-sa1100/irq.c
4 * Copyright (C) 1999-2001 Nicolas Pitre
6 * Generic IRQ handling for the SA11x0, GPIO 11-27 IRQ demultiplexing.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/sched.h>
15 #include <linux/interrupt.h>
16 #include <linux/ioport.h>
17 #include <linux/ptrace.h>
18 #include <linux/list.h>
19 #include <linux/timer.h>
21 #include <asm/hardware.h>
23 #include <asm/mach/irq.h>
24 #include <asm/arch/irq.h>
30 * SA1100 GPIO edge detection for IRQs:
31 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
32 * This must be called *before* the appropriate IRQ is registered.
33 * Use this instead of directly setting GRER/GFER.
35 static int GPIO_IRQ_rising_edge;
36 static int GPIO_IRQ_falling_edge;
37 static int GPIO_IRQ_mask = (1 << 11) - 1;
39 void set_GPIO_IRQ_edge(int gpio_mask, int edge)
44 gpio_mask &= 0x0fffffff;
45 local_irq_save(flags);
46 if (edge & GPIO_FALLING_EDGE)
47 GPIO_IRQ_falling_edge |= gpio_mask;
49 GPIO_IRQ_falling_edge &= ~gpio_mask;
50 if (edge & GPIO_RISING_EDGE)
51 GPIO_IRQ_rising_edge |= gpio_mask;
53 GPIO_IRQ_rising_edge &= ~gpio_mask;
56 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
57 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
62 irq_desc[irq].valid = 1;
66 local_irq_restore(flags);
69 EXPORT_SYMBOL(set_GPIO_IRQ_edge);
73 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
74 * this is for internal IRQs i.e. from 11 to 31.
77 static void sa1100_mask_irq(unsigned int irq)
82 static void sa1100_unmask_irq(unsigned int irq)
88 * GPIO IRQs must be acknoledged. This is for IRQs from 0 to 10.
91 static void sa1100_mask_and_ack_GPIO0_10_irq(unsigned int irq)
93 unsigned int mask = 1 << irq;
99 static void sa1100_mask_GPIO0_10_irq(unsigned int irq)
104 static void sa1100_unmask_GPIO0_10_irq(unsigned int irq)
110 * Install handler for GPIO 11-27 edge detect interrupts
113 static int GPIO_11_27_spurious; /* GPIOs that triggered when masked */
115 static void sa1100_GPIO11_27_demux(int irq, void *dev_id,
116 struct pt_regs *regs)
120 while ((irq = (GEDR & 0xfffff800))) {
122 * We don't want to clear GRER/GFER when the corresponding
123 * IRQ is masked because we could miss a level transition
124 * i.e. an IRQ which need servicing as soon as it is
125 * unmasked. However, such situation should happen only
126 * during the loop below. Thus all IRQs which aren't
127 * enabled at this point are considered spurious. Those
128 * are cleared but only de-activated if they happen twice.
130 spurious = irq & ~GPIO_IRQ_mask;
133 GRER &= ~(spurious & GPIO_11_27_spurious);
134 GFER &= ~(spurious & GPIO_11_27_spurious);
135 GPIO_11_27_spurious |= spurious;
140 for (i = 11; i <= 27; ++i) {
142 do_IRQ(IRQ_GPIO11 + i - 11, regs);
148 static struct irqaction GPIO11_27_irq = {
149 .name = "GPIO 11-27",
150 .handler = sa1100_GPIO11_27_demux,
151 .flags = SA_INTERRUPT
154 static void sa1100_mask_and_ack_GPIO11_27_irq(unsigned int irq)
156 unsigned int mask = (1 << GPIO_11_27_IRQ(irq));
157 GPIO_11_27_spurious &= ~mask;
158 GPIO_IRQ_mask &= ~mask;
162 static void sa1100_mask_GPIO11_27_irq(unsigned int irq)
164 unsigned int mask = (1 << GPIO_11_27_IRQ(irq));
165 GPIO_11_27_spurious &= ~mask;
166 GPIO_IRQ_mask &= ~mask;
169 static void sa1100_unmask_GPIO11_27_irq(unsigned int irq)
171 unsigned int mask = (1 << GPIO_11_27_IRQ(irq));
172 if (GPIO_11_27_spurious & mask) {
174 * We don't want to miss an interrupt that would have occurred
175 * while it was masked. Simulate it if it is the case.
178 if (((state & GPIO_IRQ_rising_edge) |
179 (~state & GPIO_IRQ_falling_edge)) & mask)
181 /* just in case it gets referenced: */
182 struct pt_regs dummy;
184 memzero(&dummy, sizeof(dummy));
187 /* we are being called recursively from do_IRQ() */
192 GPIO_IRQ_mask |= mask;
194 GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
195 GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
198 static struct resource irq_resource = {
204 void __init sa1100_init_irq(void)
208 request_resource(&iomem_resource, &irq_resource);
210 /* disable all IRQs */
213 /* all IRQs are IRQ, not FIQ */
216 /* clear all GPIO edge detects */
222 * Whatever the doc says, this has to be set for the wait-on-irq
223 * instruction to work... on a SA1100 rev 9 at least.
228 * Note: GPIO IRQs are initially invalid until at least one call
229 * to set_GPIO_IRQ_edge() is performed.
232 for (irq = 0; irq <= 10; irq++) {
233 irq_desc[irq].valid = 0;
234 irq_desc[irq].probe_ok = 1;
235 irq_desc[irq].mask_ack = sa1100_mask_and_ack_GPIO0_10_irq;
236 irq_desc[irq].mask = sa1100_mask_GPIO0_10_irq;
237 irq_desc[irq].unmask = sa1100_unmask_GPIO0_10_irq;
240 for (irq = 11; irq <= 31; irq++) {
241 irq_desc[irq].valid = 1;
242 irq_desc[irq].probe_ok = 0;
243 irq_desc[irq].mask_ack = sa1100_mask_irq;
244 irq_desc[irq].mask = sa1100_mask_irq;
245 irq_desc[irq].unmask = sa1100_unmask_irq;
248 for (irq = 32; irq <= 48; irq++) {
249 irq_desc[irq].valid = 0;
250 irq_desc[irq].probe_ok = 1;
251 irq_desc[irq].mask_ack = sa1100_mask_and_ack_GPIO11_27_irq;
252 irq_desc[irq].mask = sa1100_mask_GPIO11_27_irq;
253 irq_desc[irq].unmask = sa1100_unmask_GPIO11_27_irq;
255 setup_arm_irq( IRQ_GPIO11_27, &GPIO11_27_irq );