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 * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
31 * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm.
33 static void sa1100_mask_irq(struct irq_data
*d
)
35 ICMR
&= ~BIT(d
->hwirq
);
38 static void sa1100_unmask_irq(struct irq_data
*d
)
40 ICMR
|= BIT(d
->hwirq
);
44 * Apart form GPIOs, only the RTC alarm can be a wakeup event.
46 static int sa1100_set_wake(struct irq_data
*d
, unsigned int on
)
48 if (BIT(d
->hwirq
) == IC_RTCAlrm
) {
58 static struct irq_chip sa1100_normal_chip
= {
60 .irq_ack
= sa1100_mask_irq
,
61 .irq_mask
= sa1100_mask_irq
,
62 .irq_unmask
= sa1100_unmask_irq
,
63 .irq_set_wake
= sa1100_set_wake
,
66 static int sa1100_normal_irqdomain_map(struct irq_domain
*d
,
67 unsigned int irq
, irq_hw_number_t hwirq
)
69 irq_set_chip_and_handler(irq
, &sa1100_normal_chip
,
71 set_irq_flags(irq
, IRQF_VALID
);
76 static struct irq_domain_ops sa1100_normal_irqdomain_ops
= {
77 .map
= sa1100_normal_irqdomain_map
,
78 .xlate
= irq_domain_xlate_onetwocell
,
81 static struct irq_domain
*sa1100_normal_irqdomain
;
84 * SA1100 GPIO edge detection for IRQs:
85 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
86 * Use this instead of directly setting GRER/GFER.
88 static int GPIO_IRQ_rising_edge
;
89 static int GPIO_IRQ_falling_edge
;
90 static int GPIO_IRQ_mask
;
92 static int sa1100_gpio_type(struct irq_data
*d
, unsigned int type
)
98 if (type
== IRQ_TYPE_PROBE
) {
99 if ((GPIO_IRQ_rising_edge
| GPIO_IRQ_falling_edge
) & mask
)
101 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
104 if (type
& IRQ_TYPE_EDGE_RISING
) {
105 GPIO_IRQ_rising_edge
|= mask
;
107 GPIO_IRQ_rising_edge
&= ~mask
;
108 if (type
& IRQ_TYPE_EDGE_FALLING
) {
109 GPIO_IRQ_falling_edge
|= mask
;
111 GPIO_IRQ_falling_edge
&= ~mask
;
113 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
114 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
120 * GPIO IRQs must be acknowledged.
122 static void sa1100_gpio_ack(struct irq_data
*d
)
124 GEDR
= BIT(d
->hwirq
);
127 static void sa1100_gpio_mask(struct irq_data
*d
)
129 unsigned int mask
= BIT(d
->hwirq
);
131 GPIO_IRQ_mask
&= ~mask
;
137 static void sa1100_gpio_unmask(struct irq_data
*d
)
139 unsigned int mask
= BIT(d
->hwirq
);
141 GPIO_IRQ_mask
|= mask
;
143 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
144 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
147 static int sa1100_gpio_wake(struct irq_data
*d
, unsigned int on
)
150 PWER
|= BIT(d
->hwirq
);
152 PWER
&= ~BIT(d
->hwirq
);
157 * This is for IRQs from 0 to 10.
159 static struct irq_chip sa1100_low_gpio_chip
= {
161 .irq_ack
= sa1100_gpio_ack
,
162 .irq_mask
= sa1100_gpio_mask
,
163 .irq_unmask
= sa1100_gpio_unmask
,
164 .irq_set_type
= sa1100_gpio_type
,
165 .irq_set_wake
= sa1100_gpio_wake
,
168 static int sa1100_low_gpio_irqdomain_map(struct irq_domain
*d
,
169 unsigned int irq
, irq_hw_number_t hwirq
)
171 irq_set_chip_and_handler(irq
, &sa1100_low_gpio_chip
,
173 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
178 static struct irq_domain_ops sa1100_low_gpio_irqdomain_ops
= {
179 .map
= sa1100_low_gpio_irqdomain_map
,
180 .xlate
= irq_domain_xlate_onetwocell
,
183 static struct irq_domain
*sa1100_low_gpio_irqdomain
;
186 * IRQ 0-11 (GPIO) handler. We enter here with the
187 * irq_controller_lock held, and IRQs disabled. Decode the IRQ
188 * and call the handler.
191 sa1100_gpio_handler(unsigned int irq
, struct irq_desc
*desc
)
198 * clear down all currently active IRQ sources.
199 * We will be processing them all.
206 generic_handle_irq(irq
);
216 * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
217 * In addition, the IRQs are all collected up into one bit in the
218 * interrupt controller registers.
220 static struct irq_chip sa1100_high_gpio_chip
= {
222 .irq_ack
= sa1100_gpio_ack
,
223 .irq_mask
= sa1100_gpio_mask
,
224 .irq_unmask
= sa1100_gpio_unmask
,
225 .irq_set_type
= sa1100_gpio_type
,
226 .irq_set_wake
= sa1100_gpio_wake
,
229 static int sa1100_high_gpio_irqdomain_map(struct irq_domain
*d
,
230 unsigned int irq
, irq_hw_number_t hwirq
)
232 irq_set_chip_and_handler(irq
, &sa1100_high_gpio_chip
,
234 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
239 static struct irq_domain_ops sa1100_high_gpio_irqdomain_ops
= {
240 .map
= sa1100_high_gpio_irqdomain_map
,
241 .xlate
= irq_domain_xlate_onetwocell
,
244 static struct irq_domain
*sa1100_high_gpio_irqdomain
;
246 static struct resource irq_resource
=
247 DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K
, "irqs");
249 static struct sa1100irq_state
{
256 static int sa1100irq_suspend(void)
258 struct sa1100irq_state
*st
= &sa1100irq_state
;
266 * Disable all GPIO-based interrupts.
268 ICMR
&= ~(IC_GPIO11_27
|IC_GPIO10
|IC_GPIO9
|IC_GPIO8
|IC_GPIO7
|
269 IC_GPIO6
|IC_GPIO5
|IC_GPIO4
|IC_GPIO3
|IC_GPIO2
|
273 * Set the appropriate edges for wakeup.
275 GRER
= PWER
& GPIO_IRQ_rising_edge
;
276 GFER
= PWER
& GPIO_IRQ_falling_edge
;
279 * Clear any pending GPIO interrupts.
286 static void sa1100irq_resume(void)
288 struct sa1100irq_state
*st
= &sa1100irq_state
;
294 GRER
= GPIO_IRQ_rising_edge
& GPIO_IRQ_mask
;
295 GFER
= GPIO_IRQ_falling_edge
& GPIO_IRQ_mask
;
301 static struct syscore_ops sa1100irq_syscore_ops
= {
302 .suspend
= sa1100irq_suspend
,
303 .resume
= sa1100irq_resume
,
306 static int __init
sa1100irq_init_devicefs(void)
308 register_syscore_ops(&sa1100irq_syscore_ops
);
312 device_initcall(sa1100irq_init_devicefs
);
314 static asmlinkage
void __exception_irq_entry
315 sa1100_handle_irq(struct pt_regs
*regs
)
317 uint32_t icip
, icmr
, mask
;
327 handle_IRQ(ffs(mask
) - 1 + IRQ_GPIO0_SC
, regs
);
331 void __init
sa1100_init_irq(void)
333 request_resource(&iomem_resource
, &irq_resource
);
335 /* disable all IRQs */
338 /* all IRQs are IRQ, not FIQ */
341 /* clear all GPIO edge detects */
347 * Whatever the doc says, this has to be set for the wait-on-irq
348 * instruction to work... on a SA1100 rev 9 at least.
352 sa1100_normal_irqdomain
= irq_domain_add_legacy(NULL
,
354 &sa1100_normal_irqdomain_ops
, NULL
);
356 sa1100_low_gpio_irqdomain
= irq_domain_add_legacy(NULL
,
358 &sa1100_low_gpio_irqdomain_ops
, NULL
);
360 sa1100_high_gpio_irqdomain
= irq_domain_add_legacy(NULL
,
362 &sa1100_high_gpio_irqdomain_ops
, NULL
);
365 * Install handlers for GPIO 0-10 edge detect interrupts
367 irq_set_chained_handler(IRQ_GPIO0_SC
, sa1100_gpio_handler
);
368 irq_set_chained_handler(IRQ_GPIO1_SC
, sa1100_gpio_handler
);
369 irq_set_chained_handler(IRQ_GPIO2_SC
, sa1100_gpio_handler
);
370 irq_set_chained_handler(IRQ_GPIO3_SC
, sa1100_gpio_handler
);
371 irq_set_chained_handler(IRQ_GPIO4_SC
, sa1100_gpio_handler
);
372 irq_set_chained_handler(IRQ_GPIO5_SC
, sa1100_gpio_handler
);
373 irq_set_chained_handler(IRQ_GPIO6_SC
, sa1100_gpio_handler
);
374 irq_set_chained_handler(IRQ_GPIO7_SC
, sa1100_gpio_handler
);
375 irq_set_chained_handler(IRQ_GPIO8_SC
, sa1100_gpio_handler
);
376 irq_set_chained_handler(IRQ_GPIO9_SC
, sa1100_gpio_handler
);
377 irq_set_chained_handler(IRQ_GPIO10_SC
, sa1100_gpio_handler
);
379 * Install handler for GPIO 11-27 edge detect interrupts
381 irq_set_chained_handler(IRQ_GPIO11_27
, sa1100_gpio_handler
);
383 set_handle_irq(sa1100_handle_irq
);