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>
16 #include <linux/irq.h>
17 #include <linux/irqdomain.h>
18 #include <linux/ioport.h>
19 #include <linux/syscore_ops.h>
21 #include <mach/hardware.h>
22 #include <mach/irqs.h>
23 #include <asm/mach/irq.h>
24 #include <asm/exception.h>
30 * SA1100 GPIO edge detection for IRQs:
31 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
32 * Use this instead of directly setting GRER/GFER.
34 static int GPIO_IRQ_rising_edge
;
35 static int GPIO_IRQ_falling_edge
;
36 static int GPIO_IRQ_mask
= (1 << 11) - 1;
39 * To get the GPIO number from an IRQ number
41 #define GPIO_11_27_IRQ(i) ((i) + 11 - IRQ_GPIO11)
42 #define GPIO11_27_MASK(irq) (1 << GPIO_11_27_IRQ(irq))
44 static int sa1100_gpio_type(struct irq_data
*d
, unsigned int type
)
48 if (d
->irq
<= IRQ_GPIO10
)
51 mask
= GPIO11_27_MASK(d
->irq
);
53 if (type
== IRQ_TYPE_PROBE
) {
54 if ((GPIO_IRQ_rising_edge
| GPIO_IRQ_falling_edge
) & mask
)
56 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
59 if (type
& IRQ_TYPE_EDGE_RISING
) {
60 GPIO_IRQ_rising_edge
|= mask
;
62 GPIO_IRQ_rising_edge
&= ~mask
;
63 if (type
& IRQ_TYPE_EDGE_FALLING
) {
64 GPIO_IRQ_falling_edge
|= mask
;
66 GPIO_IRQ_falling_edge
&= ~mask
;
68 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
69 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
75 * GPIO IRQs must be acknowledged. This is for IRQs from GPIO0 to 10.
77 static void sa1100_low_gpio_ack(struct irq_data
*d
)
82 static void sa1100_low_gpio_mask(struct irq_data
*d
)
84 ICMR
&= ~(1 << d
->irq
);
87 static void sa1100_low_gpio_unmask(struct irq_data
*d
)
92 static int sa1100_low_gpio_wake(struct irq_data
*d
, unsigned int on
)
97 PWER
&= ~(1 << d
->irq
);
101 static struct irq_chip sa1100_low_gpio_chip
= {
103 .irq_ack
= sa1100_low_gpio_ack
,
104 .irq_mask
= sa1100_low_gpio_mask
,
105 .irq_unmask
= sa1100_low_gpio_unmask
,
106 .irq_set_type
= sa1100_gpio_type
,
107 .irq_set_wake
= sa1100_low_gpio_wake
,
110 static int sa1100_low_gpio_irqdomain_map(struct irq_domain
*d
,
111 unsigned int irq
, irq_hw_number_t hwirq
)
113 irq_set_chip_and_handler(irq
, &sa1100_low_gpio_chip
,
115 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
120 static struct irq_domain_ops sa1100_low_gpio_irqdomain_ops
= {
121 .map
= sa1100_low_gpio_irqdomain_map
,
122 .xlate
= irq_domain_xlate_onetwocell
,
125 static struct irq_domain
*sa1100_low_gpio_irqdomain
;
128 * IRQ11 (GPIO11 through 27) handler. We enter here with the
129 * irq_controller_lock held, and IRQs disabled. Decode the IRQ
130 * and call the handler.
133 sa1100_high_gpio_handler(unsigned int irq
, struct irq_desc
*desc
)
137 mask
= GEDR
& 0xfffff800;
140 * clear down all currently active IRQ sources.
141 * We will be processing them all.
149 generic_handle_irq(irq
);
154 mask
= GEDR
& 0xfffff800;
159 * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
160 * In addition, the IRQs are all collected up into one bit in the
161 * interrupt controller registers.
163 static void sa1100_high_gpio_ack(struct irq_data
*d
)
165 unsigned int mask
= GPIO11_27_MASK(d
->irq
);
170 static void sa1100_high_gpio_mask(struct irq_data
*d
)
172 unsigned int mask
= GPIO11_27_MASK(d
->irq
);
174 GPIO_IRQ_mask
&= ~mask
;
180 static void sa1100_high_gpio_unmask(struct irq_data
*d
)
182 unsigned int mask
= GPIO11_27_MASK(d
->irq
);
184 GPIO_IRQ_mask
|= mask
;
186 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
187 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
190 static int sa1100_high_gpio_wake(struct irq_data
*d
, unsigned int on
)
193 PWER
|= GPIO11_27_MASK(d
->irq
);
195 PWER
&= ~GPIO11_27_MASK(d
->irq
);
199 static struct irq_chip sa1100_high_gpio_chip
= {
201 .irq_ack
= sa1100_high_gpio_ack
,
202 .irq_mask
= sa1100_high_gpio_mask
,
203 .irq_unmask
= sa1100_high_gpio_unmask
,
204 .irq_set_type
= sa1100_gpio_type
,
205 .irq_set_wake
= sa1100_high_gpio_wake
,
208 static int sa1100_high_gpio_irqdomain_map(struct irq_domain
*d
,
209 unsigned int irq
, irq_hw_number_t hwirq
)
211 irq_set_chip_and_handler(irq
, &sa1100_high_gpio_chip
,
213 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
218 static struct irq_domain_ops sa1100_high_gpio_irqdomain_ops
= {
219 .map
= sa1100_high_gpio_irqdomain_map
,
220 .xlate
= irq_domain_xlate_onetwocell
,
223 static struct irq_domain
*sa1100_high_gpio_irqdomain
;
226 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
227 * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm.
229 static void sa1100_mask_irq(struct irq_data
*d
)
231 ICMR
&= ~(1 << d
->irq
);
234 static void sa1100_unmask_irq(struct irq_data
*d
)
236 ICMR
|= (1 << d
->irq
);
240 * Apart form GPIOs, only the RTC alarm can be a wakeup event.
242 static int sa1100_set_wake(struct irq_data
*d
, unsigned int on
)
244 if (d
->irq
== IRQ_RTCAlrm
) {
254 static struct irq_chip sa1100_normal_chip
= {
256 .irq_ack
= sa1100_mask_irq
,
257 .irq_mask
= sa1100_mask_irq
,
258 .irq_unmask
= sa1100_unmask_irq
,
259 .irq_set_wake
= sa1100_set_wake
,
262 static int sa1100_normal_irqdomain_map(struct irq_domain
*d
,
263 unsigned int irq
, irq_hw_number_t hwirq
)
265 irq_set_chip_and_handler(irq
, &sa1100_normal_chip
,
267 set_irq_flags(irq
, IRQF_VALID
);
272 static struct irq_domain_ops sa1100_normal_irqdomain_ops
= {
273 .map
= sa1100_normal_irqdomain_map
,
274 .xlate
= irq_domain_xlate_onetwocell
,
277 static struct irq_domain
*sa1100_normal_irqdomain
;
279 static struct resource irq_resource
=
280 DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K
, "irqs");
282 static struct sa1100irq_state
{
289 static int sa1100irq_suspend(void)
291 struct sa1100irq_state
*st
= &sa1100irq_state
;
299 * Disable all GPIO-based interrupts.
301 ICMR
&= ~(IC_GPIO11_27
|IC_GPIO10
|IC_GPIO9
|IC_GPIO8
|IC_GPIO7
|
302 IC_GPIO6
|IC_GPIO5
|IC_GPIO4
|IC_GPIO3
|IC_GPIO2
|
306 * Set the appropriate edges for wakeup.
308 GRER
= PWER
& GPIO_IRQ_rising_edge
;
309 GFER
= PWER
& GPIO_IRQ_falling_edge
;
312 * Clear any pending GPIO interrupts.
319 static void sa1100irq_resume(void)
321 struct sa1100irq_state
*st
= &sa1100irq_state
;
327 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
328 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
334 static struct syscore_ops sa1100irq_syscore_ops
= {
335 .suspend
= sa1100irq_suspend
,
336 .resume
= sa1100irq_resume
,
339 static int __init
sa1100irq_init_devicefs(void)
341 register_syscore_ops(&sa1100irq_syscore_ops
);
345 device_initcall(sa1100irq_init_devicefs
);
347 static asmlinkage
void __exception_irq_entry
348 sa1100_handle_irq(struct pt_regs
*regs
)
350 uint32_t icip
, icmr
, mask
;
360 handle_IRQ(ffs(mask
) - 1 + IRQ_GPIO0
, regs
);
364 void __init
sa1100_init_irq(void)
366 request_resource(&iomem_resource
, &irq_resource
);
368 /* disable all IRQs */
371 /* all IRQs are IRQ, not FIQ */
374 /* clear all GPIO edge detects */
380 * Whatever the doc says, this has to be set for the wait-on-irq
381 * instruction to work... on a SA1100 rev 9 at least.
385 sa1100_low_gpio_irqdomain
= irq_domain_add_legacy(NULL
,
387 &sa1100_low_gpio_irqdomain_ops
, NULL
);
389 sa1100_normal_irqdomain
= irq_domain_add_legacy(NULL
,
391 &sa1100_normal_irqdomain_ops
, NULL
);
393 sa1100_high_gpio_irqdomain
= irq_domain_add_legacy(NULL
,
395 &sa1100_high_gpio_irqdomain_ops
, NULL
);
398 * Install handler for GPIO 11-27 edge detect interrupts
400 irq_set_chip(IRQ_GPIO11_27
, &sa1100_normal_chip
);
401 irq_set_chained_handler(IRQ_GPIO11_27
, sa1100_high_gpio_handler
);
403 set_handle_irq(sa1100_handle_irq
);