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 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 void __init pxa_init_irq_low(void)
74 /* disable all IRQs */
77 /* all IRQs are IRQ, not FIQ */
80 /* only unmasked interrupts kick us out of idle */
83 for (irq = PXA_IRQ(0); irq <= PXA_IRQ(31); irq++) {
84 set_irq_chip(irq, &pxa_internal_chip_low);
85 set_irq_handler(irq, handle_level_irq);
86 set_irq_flags(irq, IRQF_VALID);
93 * This is for the second set of internal IRQs as found on the PXA27x.
96 static void pxa_mask_high_irq(unsigned int irq)
98 ICMR2 &= ~(1 << (irq - 32));
101 static void pxa_unmask_high_irq(unsigned int irq)
103 ICMR2 |= (1 << (irq - 32));
106 static struct irq_chip pxa_internal_chip_high = {
108 .ack = pxa_mask_high_irq,
109 .mask = pxa_mask_high_irq,
110 .unmask = pxa_unmask_high_irq,
113 void __init pxa_init_irq_high(void)
120 for (irq = PXA_IRQ(32); irq < PXA_IRQ(64); irq++) {
121 set_irq_chip(irq, &pxa_internal_chip_high);
122 set_irq_handler(irq, handle_level_irq);
123 set_irq_flags(irq, IRQF_VALID);
128 /* Note that if an input/irq line ever gets changed to an output during
129 * suspend, the relevant PWER, PRER, and PFER bits should be cleared.
133 /* PXA27x: Various gpios can issue wakeup events. This logic only
134 * handles the simple cases, not the WEMUX2 and WEMUX3 options
136 #define PXA27x_GPIO_NOWAKE_MASK \
137 ((1 << 8) | (1 << 7) | (1 << 6) | (1 << 5) | (1 << 2))
138 #define WAKEMASK(gpio) \
140 ? ((1 << (gpio)) & ~PXA27x_GPIO_NOWAKE_MASK) \
141 : ((gpio == 35) ? (1 << 24) : 0))
144 /* pxa 210, 250, 255, 26x: gpios 0..15 can issue wakeups */
145 #define WAKEMASK(gpio) (((gpio) <= 15) ? (1 << (gpio)) : 0)
149 * PXA GPIO edge detection for IRQs:
150 * IRQs are generated on Falling-Edge, Rising-Edge, or both.
151 * Use this instead of directly setting GRER/GFER.
154 static long GPIO_IRQ_rising_edge[4];
155 static long GPIO_IRQ_falling_edge[4];
156 static long GPIO_IRQ_mask[4];
158 static int pxa_gpio_irq_type(unsigned int irq, unsigned int type)
163 gpio = IRQ_TO_GPIO(irq);
165 mask = WAKEMASK(gpio);
167 if (type == IRQT_PROBE) {
168 /* Don't mess with enabled GPIOs using preconfigured edges or
169 GPIOs set to alternate function or to output during probe */
170 if ((GPIO_IRQ_rising_edge[idx] | GPIO_IRQ_falling_edge[idx] | GPDR(gpio)) &
173 if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2)))
175 type = __IRQT_RISEDGE | __IRQT_FALEDGE;
178 /* printk(KERN_DEBUG "IRQ%d (GPIO%d): ", irq, gpio); */
180 pxa_gpio_mode(gpio | GPIO_IN);
182 if (type & __IRQT_RISEDGE) {
183 /* printk("rising "); */
184 __set_bit (gpio, GPIO_IRQ_rising_edge);
187 __clear_bit (gpio, GPIO_IRQ_rising_edge);
191 if (type & __IRQT_FALEDGE) {
192 /* printk("falling "); */
193 __set_bit (gpio, GPIO_IRQ_falling_edge);
196 __clear_bit (gpio, GPIO_IRQ_falling_edge);
200 /* printk("edges\n"); */
202 GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
203 GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
208 * GPIO IRQs must be acknowledged. This is for GPIO 0 and 1.
211 static void pxa_ack_low_gpio(unsigned int irq)
213 GEDR0 = (1 << (irq - IRQ_GPIO0));
216 static int pxa_set_gpio_wake(unsigned int irq, unsigned int on)
218 int gpio = IRQ_TO_GPIO(irq);
219 u32 mask = WAKEMASK(gpio);
232 static struct irq_chip pxa_low_gpio_chip = {
234 .ack = pxa_ack_low_gpio,
235 .mask = pxa_mask_low_irq,
236 .unmask = pxa_unmask_low_irq,
237 .set_type = pxa_gpio_irq_type,
238 .set_wake = pxa_set_gpio_wake,
242 * Demux handler for GPIO>=2 edge detect interrupts
245 static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc)
253 mask = GEDR0 & GPIO_IRQ_mask[0] & ~3;
257 desc = irq_desc + irq;
261 desc_handle_irq(irq, desc);
269 mask = GEDR1 & GPIO_IRQ_mask[1];
273 desc = irq_desc + irq;
276 desc_handle_irq(irq, desc);
284 mask = GEDR2 & GPIO_IRQ_mask[2];
288 desc = irq_desc + irq;
291 desc_handle_irq(irq, desc);
299 mask = GEDR3 & GPIO_IRQ_mask[3];
303 desc = irq_desc + irq;
306 desc_handle_irq(irq, desc);
316 static void pxa_ack_muxed_gpio(unsigned int irq)
318 int gpio = irq - IRQ_GPIO(2) + 2;
319 GEDR(gpio) = GPIO_bit(gpio);
322 static void pxa_mask_muxed_gpio(unsigned int irq)
324 int gpio = irq - IRQ_GPIO(2) + 2;
325 __clear_bit(gpio, GPIO_IRQ_mask);
326 GRER(gpio) &= ~GPIO_bit(gpio);
327 GFER(gpio) &= ~GPIO_bit(gpio);
330 static void pxa_unmask_muxed_gpio(unsigned int irq)
332 int gpio = irq - IRQ_GPIO(2) + 2;
334 __set_bit(gpio, GPIO_IRQ_mask);
335 GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
336 GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
339 static struct irq_chip pxa_muxed_gpio_chip = {
341 .ack = pxa_ack_muxed_gpio,
342 .mask = pxa_mask_muxed_gpio,
343 .unmask = pxa_unmask_muxed_gpio,
344 .set_type = pxa_gpio_irq_type,
345 .set_wake = pxa_set_gpio_wake,
348 void __init pxa_init_irq_gpio(int gpio_nr)
352 /* clear all GPIO edge detects */
353 for (i = 0; i < gpio_nr; i += 32) {
359 /* GPIO 0 and 1 must have their mask bit always set */
360 GPIO_IRQ_mask[0] = 3;
362 for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) {
363 set_irq_chip(irq, &pxa_low_gpio_chip);
364 set_irq_handler(irq, handle_edge_irq);
365 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
368 for (irq = IRQ_GPIO(2); irq < IRQ_GPIO(gpio_nr); irq++) {
369 set_irq_chip(irq, &pxa_muxed_gpio_chip);
370 set_irq_handler(irq, handle_edge_irq);
371 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
374 /* Install handler for GPIO>=2 edge detect interrupts */
375 set_irq_chip(IRQ_GPIO_2_x, &pxa_internal_chip_low);
376 set_irq_chained_handler(IRQ_GPIO_2_x, pxa_gpio_demux_handler);