2 * linux/arch/arm/mach-pxa/irq.c
4 * Generic PXA IRQ handling, GPIO IRQ demultiplexing, etc.
6 * Author: Nicolas Pitre
7 * Created: Jun 15, 2001
8 * Copyright: MontaVista Software Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/interrupt.h>
19 #include <asm/hardware.h>
21 #include <asm/mach/irq.h>
22 #include <asm/arch/pxa-regs.h>
28 * This is for peripheral IRQs internal to the PXA chip.
31 static void pxa_mask_low_irq(unsigned int irq
)
33 ICMR
&= ~(1 << (irq
+ PXA_IRQ_SKIP
));
36 static void pxa_unmask_low_irq(unsigned int irq
)
38 ICMR
|= (1 << (irq
+ PXA_IRQ_SKIP
));
41 static int pxa_set_wake(unsigned int irq
, unsigned int on
)
50 /* REVISIT can handle USBH1, USBH2, USB, MSL, USIM, ... */
62 static struct irq_chip pxa_internal_chip_low
= {
64 .ack
= pxa_mask_low_irq
,
65 .mask
= pxa_mask_low_irq
,
66 .unmask
= pxa_unmask_low_irq
,
67 .set_wake
= pxa_set_wake
,
70 #if PXA_INTERNAL_IRQS > 32
73 * This is for the second set of internal IRQs as found on the PXA27x.
76 static void pxa_mask_high_irq(unsigned int irq
)
78 ICMR2
&= ~(1 << (irq
- 32 + PXA_IRQ_SKIP
));
81 static void pxa_unmask_high_irq(unsigned int irq
)
83 ICMR2
|= (1 << (irq
- 32 + PXA_IRQ_SKIP
));
86 static struct irq_chip pxa_internal_chip_high
= {
88 .ack
= pxa_mask_high_irq
,
89 .mask
= pxa_mask_high_irq
,
90 .unmask
= pxa_unmask_high_irq
,
95 /* Note that if an input/irq line ever gets changed to an output during
96 * suspend, the relevant PWER, PRER, and PFER bits should be cleared.
100 /* PXA27x: Various gpios can issue wakeup events. This logic only
101 * handles the simple cases, not the WEMUX2 and WEMUX3 options
103 #define PXA27x_GPIO_NOWAKE_MASK \
104 ((1 << 8) | (1 << 7) | (1 << 6) | (1 << 5) | (1 << 2))
105 #define WAKEMASK(gpio) \
107 ? ((1 << (gpio)) & ~PXA27x_GPIO_NOWAKE_MASK) \
108 : ((gpio == 35) ? (1 << 24) : 0))
111 /* pxa 210, 250, 255, 26x: gpios 0..15 can issue wakeups */
112 #define WAKEMASK(gpio) (((gpio) <= 15) ? (1 << (gpio)) : 0)
116 * PXA GPIO edge detection for IRQs:
117 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
118 * Use this instead of directly setting GRER/GFER.
121 static long GPIO_IRQ_rising_edge
[4];
122 static long GPIO_IRQ_falling_edge
[4];
123 static long GPIO_IRQ_mask
[4];
125 static int pxa_gpio_irq_type(unsigned int irq
, unsigned int type
)
130 gpio
= IRQ_TO_GPIO(irq
);
132 mask
= WAKEMASK(gpio
);
134 if (type
== IRQT_PROBE
) {
135 /* Don't mess with enabled GPIOs using preconfigured edges or
136 GPIOs set to alternate function or to output during probe */
137 if ((GPIO_IRQ_rising_edge
[idx
] | GPIO_IRQ_falling_edge
[idx
] | GPDR(gpio
)) &
140 if (GAFR(gpio
) & (0x3 << (((gpio
) & 0xf)*2)))
142 type
= __IRQT_RISEDGE
| __IRQT_FALEDGE
;
145 /* printk(KERN_DEBUG "IRQ%d (GPIO%d): ", irq, gpio); */
147 pxa_gpio_mode(gpio
| GPIO_IN
);
149 if (type
& __IRQT_RISEDGE
) {
150 /* printk("rising "); */
151 __set_bit (gpio
, GPIO_IRQ_rising_edge
);
154 __clear_bit (gpio
, GPIO_IRQ_rising_edge
);
158 if (type
& __IRQT_FALEDGE
) {
159 /* printk("falling "); */
160 __set_bit (gpio
, GPIO_IRQ_falling_edge
);
163 __clear_bit (gpio
, GPIO_IRQ_falling_edge
);
167 /* printk("edges\n"); */
169 GRER(gpio
) = GPIO_IRQ_rising_edge
[idx
] & GPIO_IRQ_mask
[idx
];
170 GFER(gpio
) = GPIO_IRQ_falling_edge
[idx
] & GPIO_IRQ_mask
[idx
];
175 * GPIO IRQs must be acknowledged. This is for GPIO 0 and 1.
178 static void pxa_ack_low_gpio(unsigned int irq
)
180 GEDR0
= (1 << (irq
- IRQ_GPIO0
));
183 static int pxa_set_gpio_wake(unsigned int irq
, unsigned int on
)
185 int gpio
= IRQ_TO_GPIO(irq
);
186 u32 mask
= WAKEMASK(gpio
);
199 static struct irq_chip pxa_low_gpio_chip
= {
201 .ack
= pxa_ack_low_gpio
,
202 .mask
= pxa_mask_low_irq
,
203 .unmask
= pxa_unmask_low_irq
,
204 .set_type
= pxa_gpio_irq_type
,
205 .set_wake
= pxa_set_gpio_wake
,
209 * Demux handler for GPIO>=2 edge detect interrupts
212 static void pxa_gpio_demux_handler(unsigned int irq
, struct irq_desc
*desc
)
224 desc
= irq_desc
+ irq
;
228 desc_handle_irq(irq
, desc
);
240 desc
= irq_desc
+ irq
;
243 desc_handle_irq(irq
, desc
);
255 desc
= irq_desc
+ irq
;
258 desc_handle_irq(irq
, desc
);
266 #if PXA_LAST_GPIO >= 96
271 desc
= irq_desc
+ irq
;
274 desc_handle_irq(irq
, desc
);
285 static void pxa_ack_muxed_gpio(unsigned int irq
)
287 int gpio
= irq
- IRQ_GPIO(2) + 2;
288 GEDR(gpio
) = GPIO_bit(gpio
);
291 static void pxa_mask_muxed_gpio(unsigned int irq
)
293 int gpio
= irq
- IRQ_GPIO(2) + 2;
294 __clear_bit(gpio
, GPIO_IRQ_mask
);
295 GRER(gpio
) &= ~GPIO_bit(gpio
);
296 GFER(gpio
) &= ~GPIO_bit(gpio
);
299 static void pxa_unmask_muxed_gpio(unsigned int irq
)
301 int gpio
= irq
- IRQ_GPIO(2) + 2;
303 __set_bit(gpio
, GPIO_IRQ_mask
);
304 GRER(gpio
) = GPIO_IRQ_rising_edge
[idx
] & GPIO_IRQ_mask
[idx
];
305 GFER(gpio
) = GPIO_IRQ_falling_edge
[idx
] & GPIO_IRQ_mask
[idx
];
308 static struct irq_chip pxa_muxed_gpio_chip
= {
310 .ack
= pxa_ack_muxed_gpio
,
311 .mask
= pxa_mask_muxed_gpio
,
312 .unmask
= pxa_unmask_muxed_gpio
,
313 .set_type
= pxa_gpio_irq_type
,
314 .set_wake
= pxa_set_gpio_wake
,
318 void __init
pxa_init_irq(void)
322 /* disable all IRQs */
325 /* all IRQs are IRQ, not FIQ */
328 /* clear all GPIO edge detects */
340 /* And similarly for the extra regs on the PXA27x */
348 /* only unmasked interrupts kick us out of idle */
351 /* GPIO 0 and 1 must have their mask bit always set */
352 GPIO_IRQ_mask
[0] = 3;
354 for (irq
= PXA_IRQ(PXA_IRQ_SKIP
); irq
<= PXA_IRQ(31); irq
++) {
355 set_irq_chip(irq
, &pxa_internal_chip_low
);
356 set_irq_handler(irq
, handle_level_irq
);
357 set_irq_flags(irq
, IRQF_VALID
);
360 #if PXA_INTERNAL_IRQS > 32
361 for (irq
= PXA_IRQ(32); irq
< PXA_IRQ(PXA_INTERNAL_IRQS
); irq
++) {
362 set_irq_chip(irq
, &pxa_internal_chip_high
);
363 set_irq_handler(irq
, handle_level_irq
);
364 set_irq_flags(irq
, IRQF_VALID
);
368 for (irq
= IRQ_GPIO0
; irq
<= IRQ_GPIO1
; irq
++) {
369 set_irq_chip(irq
, &pxa_low_gpio_chip
);
370 set_irq_handler(irq
, handle_edge_irq
);
371 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
374 for (irq
= IRQ_GPIO(2); irq
<= IRQ_GPIO(PXA_LAST_GPIO
); irq
++) {
375 set_irq_chip(irq
, &pxa_muxed_gpio_chip
);
376 set_irq_handler(irq
, handle_edge_irq
);
377 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
380 /* Install handler for GPIO>=2 edge detect interrupts */
381 set_irq_chip(IRQ_GPIO_2_x
, &pxa_internal_chip_low
);
382 set_irq_chained_handler(IRQ_GPIO_2_x
, pxa_gpio_demux_handler
);