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/interrupt.h>
15 #include <linux/irq.h>
16 #include <linux/ioport.h>
17 #include <linux/sysdev.h>
19 #include <mach/hardware.h>
20 #include <asm/mach/irq.h>
26 * SA1100 GPIO edge detection for IRQs:
27 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
28 * Use this instead of directly setting GRER/GFER.
30 static int GPIO_IRQ_rising_edge
;
31 static int GPIO_IRQ_falling_edge
;
32 static int GPIO_IRQ_mask
= (1 << 11) - 1;
35 * To get the GPIO number from an IRQ number
37 #define GPIO_11_27_IRQ(i) ((i) - 21)
38 #define GPIO11_27_MASK(irq) (1 << GPIO_11_27_IRQ(irq))
40 static int sa1100_gpio_type(unsigned int irq
, unsigned int type
)
47 mask
= GPIO11_27_MASK(irq
);
49 if (type
== IRQ_TYPE_PROBE
) {
50 if ((GPIO_IRQ_rising_edge
| GPIO_IRQ_falling_edge
) & mask
)
52 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
55 if (type
& IRQ_TYPE_EDGE_RISING
) {
56 GPIO_IRQ_rising_edge
|= mask
;
58 GPIO_IRQ_rising_edge
&= ~mask
;
59 if (type
& IRQ_TYPE_EDGE_FALLING
) {
60 GPIO_IRQ_falling_edge
|= mask
;
62 GPIO_IRQ_falling_edge
&= ~mask
;
64 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
65 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
71 * GPIO IRQs must be acknowledged. This is for IRQs from 0 to 10.
73 static void sa1100_low_gpio_ack(unsigned int irq
)
78 static void sa1100_low_gpio_mask(unsigned int irq
)
83 static void sa1100_low_gpio_unmask(unsigned int irq
)
88 static int sa1100_low_gpio_wake(unsigned int irq
, unsigned int on
)
97 static struct irq_chip sa1100_low_gpio_chip
= {
99 .ack
= sa1100_low_gpio_ack
,
100 .mask
= sa1100_low_gpio_mask
,
101 .unmask
= sa1100_low_gpio_unmask
,
102 .set_type
= sa1100_gpio_type
,
103 .set_wake
= sa1100_low_gpio_wake
,
107 * IRQ11 (GPIO11 through 27) handler. We enter here with the
108 * irq_controller_lock held, and IRQs disabled. Decode the IRQ
109 * and call the handler.
112 sa1100_high_gpio_handler(unsigned int irq
, struct irq_desc
*desc
)
116 mask
= GEDR
& 0xfffff800;
119 * clear down all currently active IRQ sources.
120 * We will be processing them all.
125 desc
= irq_desc
+ irq
;
129 desc_handle_irq(irq
, desc
);
135 mask
= GEDR
& 0xfffff800;
140 * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
141 * In addition, the IRQs are all collected up into one bit in the
142 * interrupt controller registers.
144 static void sa1100_high_gpio_ack(unsigned int irq
)
146 unsigned int mask
= GPIO11_27_MASK(irq
);
151 static void sa1100_high_gpio_mask(unsigned int irq
)
153 unsigned int mask
= GPIO11_27_MASK(irq
);
155 GPIO_IRQ_mask
&= ~mask
;
161 static void sa1100_high_gpio_unmask(unsigned int irq
)
163 unsigned int mask
= GPIO11_27_MASK(irq
);
165 GPIO_IRQ_mask
|= mask
;
167 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
168 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
171 static int sa1100_high_gpio_wake(unsigned int irq
, unsigned int on
)
174 PWER
|= GPIO11_27_MASK(irq
);
176 PWER
&= ~GPIO11_27_MASK(irq
);
180 static struct irq_chip sa1100_high_gpio_chip
= {
182 .ack
= sa1100_high_gpio_ack
,
183 .mask
= sa1100_high_gpio_mask
,
184 .unmask
= sa1100_high_gpio_unmask
,
185 .set_type
= sa1100_gpio_type
,
186 .set_wake
= sa1100_high_gpio_wake
,
190 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
191 * this is for internal IRQs i.e. from 11 to 31.
193 static void sa1100_mask_irq(unsigned int irq
)
198 static void sa1100_unmask_irq(unsigned int irq
)
204 * Apart form GPIOs, only the RTC alarm can be a wakeup event.
206 static int sa1100_set_wake(unsigned int irq
, unsigned int on
)
208 if (irq
== IRQ_RTCAlrm
) {
218 static struct irq_chip sa1100_normal_chip
= {
220 .ack
= sa1100_mask_irq
,
221 .mask
= sa1100_mask_irq
,
222 .unmask
= sa1100_unmask_irq
,
223 .set_wake
= sa1100_set_wake
,
226 static struct resource irq_resource
= {
232 static struct sa1100irq_state
{
239 static int sa1100irq_suspend(struct sys_device
*dev
, pm_message_t state
)
241 struct sa1100irq_state
*st
= &sa1100irq_state
;
249 * Disable all GPIO-based interrupts.
251 ICMR
&= ~(IC_GPIO11_27
|IC_GPIO10
|IC_GPIO9
|IC_GPIO8
|IC_GPIO7
|
252 IC_GPIO6
|IC_GPIO5
|IC_GPIO4
|IC_GPIO3
|IC_GPIO2
|
256 * Set the appropriate edges for wakeup.
258 GRER
= PWER
& GPIO_IRQ_rising_edge
;
259 GFER
= PWER
& GPIO_IRQ_falling_edge
;
262 * Clear any pending GPIO interrupts.
269 static int sa1100irq_resume(struct sys_device
*dev
)
271 struct sa1100irq_state
*st
= &sa1100irq_state
;
277 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
278 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
285 static struct sysdev_class sa1100irq_sysclass
= {
286 .name
= "sa11x0-irq",
287 .suspend
= sa1100irq_suspend
,
288 .resume
= sa1100irq_resume
,
291 static struct sys_device sa1100irq_device
= {
293 .cls
= &sa1100irq_sysclass
,
296 static int __init
sa1100irq_init_devicefs(void)
298 sysdev_class_register(&sa1100irq_sysclass
);
299 return sysdev_register(&sa1100irq_device
);
302 device_initcall(sa1100irq_init_devicefs
);
304 void __init
sa1100_init_irq(void)
308 request_resource(&iomem_resource
, &irq_resource
);
310 /* disable all IRQs */
313 /* all IRQs are IRQ, not FIQ */
316 /* clear all GPIO edge detects */
322 * Whatever the doc says, this has to be set for the wait-on-irq
323 * instruction to work... on a SA1100 rev 9 at least.
327 for (irq
= 0; irq
<= 10; irq
++) {
328 set_irq_chip(irq
, &sa1100_low_gpio_chip
);
329 set_irq_handler(irq
, handle_edge_irq
);
330 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
333 for (irq
= 12; irq
<= 31; irq
++) {
334 set_irq_chip(irq
, &sa1100_normal_chip
);
335 set_irq_handler(irq
, handle_level_irq
);
336 set_irq_flags(irq
, IRQF_VALID
);
339 for (irq
= 32; irq
<= 48; irq
++) {
340 set_irq_chip(irq
, &sa1100_high_gpio_chip
);
341 set_irq_handler(irq
, handle_edge_irq
);
342 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
346 * Install handler for GPIO 11-27 edge detect interrupts
348 set_irq_chip(IRQ_GPIO11_27
, &sa1100_normal_chip
);
349 set_irq_chained_handler(IRQ_GPIO11_27
, sa1100_high_gpio_handler
);