[ALSA] ice1712, ice1724 - Code clean up
[linux-2.6/btrfs-unstable.git] / arch / arm / mach-pxa / irq.c
blob07acb45b16ea83ac26be925293943a1f14def698
1 /*
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>
20 #include <asm/irq.h>
21 #include <asm/mach/irq.h>
22 #include <asm/arch/pxa-regs.h>
24 #include "generic.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);
36 static void pxa_unmask_low_irq(unsigned int irq)
38 ICMR |= (1 << irq);
41 static struct irq_chip pxa_internal_chip_low = {
42 .name = "SC",
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)
50 int irq;
52 /* disable all IRQs */
53 ICMR = 0;
55 /* all IRQs are IRQ, not FIQ */
56 ICLR = 0;
58 /* only unmasked interrupts kick us out of idle */
59 ICCR = 1;
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 = {
85 .name = "SC-hi",
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)
93 int irq;
95 ICMR2 = 0;
96 ICLR2 = 0;
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);
104 #endif
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)
118 int gpio, idx;
120 gpio = IRQ_TO_GPIO(irq);
121 idx = gpio >> 5;
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)) &
127 GPIO_bit(gpio))
128 return 0;
129 if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2)))
130 return 0;
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);
141 } else {
142 __clear_bit (gpio, GPIO_IRQ_rising_edge);
145 if (type & __IRQT_FALEDGE) {
146 /* printk("falling "); */
147 __set_bit (gpio, GPIO_IRQ_falling_edge);
148 } else {
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];
156 return 0;
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 = {
169 .name = "GPIO-l",
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)
182 unsigned int mask;
183 int loop;
185 do {
186 loop = 0;
188 mask = GEDR0 & GPIO_IRQ_mask[0] & ~3;
189 if (mask) {
190 GEDR0 = mask;
191 irq = IRQ_GPIO(2);
192 desc = irq_desc + irq;
193 mask >>= 2;
194 do {
195 if (mask & 1)
196 desc_handle_irq(irq, desc);
197 irq++;
198 desc++;
199 mask >>= 1;
200 } while (mask);
201 loop = 1;
204 mask = GEDR1 & GPIO_IRQ_mask[1];
205 if (mask) {
206 GEDR1 = mask;
207 irq = IRQ_GPIO(32);
208 desc = irq_desc + irq;
209 do {
210 if (mask & 1)
211 desc_handle_irq(irq, desc);
212 irq++;
213 desc++;
214 mask >>= 1;
215 } while (mask);
216 loop = 1;
219 mask = GEDR2 & GPIO_IRQ_mask[2];
220 if (mask) {
221 GEDR2 = mask;
222 irq = IRQ_GPIO(64);
223 desc = irq_desc + irq;
224 do {
225 if (mask & 1)
226 desc_handle_irq(irq, desc);
227 irq++;
228 desc++;
229 mask >>= 1;
230 } while (mask);
231 loop = 1;
234 mask = GEDR3 & GPIO_IRQ_mask[3];
235 if (mask) {
236 GEDR3 = mask;
237 irq = IRQ_GPIO(96);
238 desc = irq_desc + irq;
239 do {
240 if (mask & 1)
241 desc_handle_irq(irq, desc);
242 irq++;
243 desc++;
244 mask >>= 1;
245 } while (mask);
246 loop = 1;
248 } while (loop);
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;
268 int idx = gpio >> 5;
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 = {
275 .name = "GPIO",
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)
284 int irq, i;
286 pxa_last_gpio = gpio_nr - 1;
288 /* clear all GPIO edge detects */
289 for (i = 0; i < gpio_nr; i += 32) {
290 GFER(i) = 0;
291 GRER(i) = 0;
292 GEDR(i) = GEDR(i);
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;
318 #ifdef CONFIG_PXA27x
319 pxa_internal_chip_high.set_wake = set_wake;
320 #endif
321 pxa_low_gpio_chip.set_wake = set_wake;
322 pxa_muxed_gpio_chip.set_wake = set_wake;