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)
36 static void pxa_unmask_low_irq(unsigned int irq)
41 static struct irq_chip pxa_internal_chip_low = {
43 .ack = pxa_mask_low_irq,
44 .mask = pxa_mask_low_irq,
45 .unmask = pxa_unmask_low_irq,
48 void __init pxa_init_irq_low(void)
52 /* disable all IRQs */
55 /* all IRQs are IRQ, not FIQ */
58 /* only unmasked interrupts kick us out of idle */
61 for (irq = PXA_IRQ(0); irq <= PXA_IRQ(31); irq++) {
62 set_irq_chip(irq, &pxa_internal_chip_low);
63 set_irq_handler(irq, handle_level_irq);
64 set_irq_flags(irq, IRQF_VALID);
68 #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
71 * This is for the second set of internal IRQs as found on the PXA27x.
74 static void pxa_mask_high_irq(unsigned int irq)
76 ICMR2 &= ~(1 << (irq - 32));
79 static void pxa_unmask_high_irq(unsigned int irq)
81 ICMR2 |= (1 << (irq - 32));
84 static struct irq_chip pxa_internal_chip_high = {
86 .ack = pxa_mask_high_irq,
87 .mask = pxa_mask_high_irq,
88 .unmask = pxa_unmask_high_irq,
91 void __init pxa_init_irq_high(void)
98 for (irq = PXA_IRQ(32); irq < PXA_IRQ(64); irq++) {
99 set_irq_chip(irq, &pxa_internal_chip_high);
100 set_irq_handler(irq, handle_level_irq);
101 set_irq_flags(irq, IRQF_VALID);
107 * PXA GPIO edge detection for IRQs:
108 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
109 * Use this instead of directly setting GRER/GFER.
112 static long GPIO_IRQ_rising_edge[4];
113 static long GPIO_IRQ_falling_edge[4];
114 static long GPIO_IRQ_mask[4];
116 static int pxa_gpio_irq_type(unsigned int irq, unsigned int type)
120 gpio = IRQ_TO_GPIO(irq);
123 if (type == IRQT_PROBE) {
124 /* Don't mess with enabled GPIOs using preconfigured edges or
125 GPIOs set to alternate function or to output during probe */
126 if ((GPIO_IRQ_rising_edge[idx] | GPIO_IRQ_falling_edge[idx] | GPDR(gpio)) &
129 if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2)))
131 type = __IRQT_RISEDGE | __IRQT_FALEDGE;
134 /* printk(KERN_DEBUG "IRQ%d (GPIO%d): ", irq, gpio); */
136 pxa_gpio_mode(gpio | GPIO_IN);
138 if (type & __IRQT_RISEDGE) {
139 /* printk("rising "); */
140 __set_bit (gpio, GPIO_IRQ_rising_edge);
142 __clear_bit (gpio, GPIO_IRQ_rising_edge);
145 if (type & __IRQT_FALEDGE) {
146 /* printk("falling "); */
147 __set_bit (gpio, GPIO_IRQ_falling_edge);
149 __clear_bit (gpio, GPIO_IRQ_falling_edge);
152 /* printk("edges\n"); */
154 GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
155 GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
160 * GPIO IRQs must be acknowledged. This is for GPIO 0 and 1.
163 static void pxa_ack_low_gpio(unsigned int irq)
165 GEDR0 = (1 << (irq - IRQ_GPIO0));
168 static struct irq_chip pxa_low_gpio_chip = {
170 .ack = pxa_ack_low_gpio,
171 .mask = pxa_mask_low_irq,
172 .unmask = pxa_unmask_low_irq,
173 .set_type = pxa_gpio_irq_type,
177 * Demux handler for GPIO>=2 edge detect interrupts
180 static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc)
188 mask = GEDR0 & GPIO_IRQ_mask[0] & ~3;
192 desc = irq_desc + irq;
196 desc_handle_irq(irq, desc);
204 mask = GEDR1 & GPIO_IRQ_mask[1];
208 desc = irq_desc + irq;
211 desc_handle_irq(irq, desc);
219 mask = GEDR2 & GPIO_IRQ_mask[2];
223 desc = irq_desc + irq;
226 desc_handle_irq(irq, desc);
234 mask = GEDR3 & GPIO_IRQ_mask[3];
238 desc = irq_desc + irq;
241 desc_handle_irq(irq, desc);
251 static void pxa_ack_muxed_gpio(unsigned int irq)
253 int gpio = irq - IRQ_GPIO(2) + 2;
254 GEDR(gpio) = GPIO_bit(gpio);
257 static void pxa_mask_muxed_gpio(unsigned int irq)
259 int gpio = irq - IRQ_GPIO(2) + 2;
260 __clear_bit(gpio, GPIO_IRQ_mask);
261 GRER(gpio) &= ~GPIO_bit(gpio);
262 GFER(gpio) &= ~GPIO_bit(gpio);
265 static void pxa_unmask_muxed_gpio(unsigned int irq)
267 int gpio = irq - IRQ_GPIO(2) + 2;
269 __set_bit(gpio, GPIO_IRQ_mask);
270 GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
271 GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
274 static struct irq_chip pxa_muxed_gpio_chip = {
276 .ack = pxa_ack_muxed_gpio,
277 .mask = pxa_mask_muxed_gpio,
278 .unmask = pxa_unmask_muxed_gpio,
279 .set_type = pxa_gpio_irq_type,
282 void __init pxa_init_irq_gpio(int gpio_nr)
286 pxa_last_gpio = gpio_nr - 1;
288 /* clear all GPIO edge detects */
289 for (i = 0; i < gpio_nr; i += 32) {
295 /* GPIO 0 and 1 must have their mask bit always set */
296 GPIO_IRQ_mask[0] = 3;
298 for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) {
299 set_irq_chip(irq, &pxa_low_gpio_chip);
300 set_irq_handler(irq, handle_edge_irq);
301 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
304 for (irq = IRQ_GPIO(2); irq < IRQ_GPIO(gpio_nr); irq++) {
305 set_irq_chip(irq, &pxa_muxed_gpio_chip);
306 set_irq_handler(irq, handle_edge_irq);
307 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
310 /* Install handler for GPIO>=2 edge detect interrupts */
311 set_irq_chip(IRQ_GPIO_2_x, &pxa_internal_chip_low);
312 set_irq_chained_handler(IRQ_GPIO_2_x, pxa_gpio_demux_handler);
315 void __init pxa_init_irq_set_wake(int (*set_wake)(unsigned int, unsigned int))
317 pxa_internal_chip_low.set_wake = set_wake;
319 pxa_internal_chip_high.set_wake = set_wake;
321 pxa_low_gpio_chip.set_wake = set_wake;
322 pxa_muxed_gpio_chip.set_wake = set_wake;