Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-pxa/irq.c |
| 3 | * |
| 4 | * Generic PXA IRQ handling, GPIO IRQ demultiplexing, etc. |
| 5 | * |
| 6 | * Author: Nicolas Pitre |
| 7 | * Created: Jun 15, 2001 |
| 8 | * Copyright: MontaVista Software Inc. |
| 9 | * |
| 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. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include <asm/hardware.h> |
| 20 | #include <asm/irq.h> |
| 21 | #include <asm/mach/irq.h> |
| 22 | #include <asm/arch/pxa-regs.h> |
| 23 | |
| 24 | #include "generic.h" |
| 25 | |
| 26 | |
| 27 | /* |
| 28 | * This is for peripheral IRQs internal to the PXA chip. |
| 29 | */ |
| 30 | |
| 31 | static void pxa_mask_low_irq(unsigned int irq) |
| 32 | { |
Eric Miao | 486c955 | 2007-06-06 06:22:20 +0100 | [diff] [blame] | 33 | ICMR &= ~(1 << irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static void pxa_unmask_low_irq(unsigned int irq) |
| 37 | { |
Eric Miao | 486c955 | 2007-06-06 06:22:20 +0100 | [diff] [blame] | 38 | ICMR |= (1 << irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } |
| 40 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 41 | static struct irq_chip pxa_internal_chip_low = { |
| 42 | .name = "SC", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | .ack = pxa_mask_low_irq, |
| 44 | .mask = pxa_mask_low_irq, |
| 45 | .unmask = pxa_unmask_low_irq, |
| 46 | }; |
| 47 | |
Eric Miao | 53665a5 | 2007-06-06 06:36:04 +0100 | [diff] [blame] | 48 | void __init pxa_init_irq_low(void) |
| 49 | { |
| 50 | int irq; |
| 51 | |
| 52 | /* disable all IRQs */ |
| 53 | ICMR = 0; |
| 54 | |
| 55 | /* all IRQs are IRQ, not FIQ */ |
| 56 | ICLR = 0; |
| 57 | |
| 58 | /* only unmasked interrupts kick us out of idle */ |
| 59 | ICCR = 1; |
| 60 | |
| 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); |
| 65 | } |
| 66 | } |
| 67 | |
Eric Miao | c08b7b3 | 2007-06-06 06:32:38 +0100 | [diff] [blame] | 68 | #ifdef CONFIG_PXA27x |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * This is for the second set of internal IRQs as found on the PXA27x. |
| 72 | */ |
| 73 | |
| 74 | static void pxa_mask_high_irq(unsigned int irq) |
| 75 | { |
Eric Miao | 486c955 | 2007-06-06 06:22:20 +0100 | [diff] [blame] | 76 | ICMR2 &= ~(1 << (irq - 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static void pxa_unmask_high_irq(unsigned int irq) |
| 80 | { |
Eric Miao | 486c955 | 2007-06-06 06:22:20 +0100 | [diff] [blame] | 81 | ICMR2 |= (1 << (irq - 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 84 | static struct irq_chip pxa_internal_chip_high = { |
| 85 | .name = "SC-hi", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | .ack = pxa_mask_high_irq, |
| 87 | .mask = pxa_mask_high_irq, |
| 88 | .unmask = pxa_unmask_high_irq, |
| 89 | }; |
| 90 | |
Eric Miao | c08b7b3 | 2007-06-06 06:32:38 +0100 | [diff] [blame] | 91 | void __init pxa_init_irq_high(void) |
| 92 | { |
| 93 | int irq; |
| 94 | |
| 95 | ICMR2 = 0; |
| 96 | ICLR2 = 0; |
| 97 | |
| 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); |
| 102 | } |
| 103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | #endif |
| 105 | |
| 106 | /* |
| 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. |
| 110 | */ |
| 111 | |
| 112 | static long GPIO_IRQ_rising_edge[4]; |
| 113 | static long GPIO_IRQ_falling_edge[4]; |
| 114 | static long GPIO_IRQ_mask[4]; |
| 115 | |
| 116 | static int pxa_gpio_irq_type(unsigned int irq, unsigned int type) |
| 117 | { |
| 118 | int gpio, idx; |
| 119 | |
| 120 | gpio = IRQ_TO_GPIO(irq); |
| 121 | idx = gpio >> 5; |
| 122 | |
| 123 | if (type == IRQT_PROBE) { |
| 124 | /* Don't mess with enabled GPIOs using preconfigured edges or |
Guennadi Liakhovetski | e033108 | 2006-06-28 16:42:02 +0100 | [diff] [blame] | 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)) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | GPIO_bit(gpio)) |
| 128 | return 0; |
| 129 | if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2))) |
| 130 | return 0; |
| 131 | type = __IRQT_RISEDGE | __IRQT_FALEDGE; |
| 132 | } |
| 133 | |
| 134 | /* printk(KERN_DEBUG "IRQ%d (GPIO%d): ", irq, gpio); */ |
| 135 | |
| 136 | pxa_gpio_mode(gpio | GPIO_IN); |
| 137 | |
| 138 | if (type & __IRQT_RISEDGE) { |
| 139 | /* printk("rising "); */ |
| 140 | __set_bit (gpio, GPIO_IRQ_rising_edge); |
Philipp Zabel | 4fe4a2b | 2007-02-26 01:44:57 +0100 | [diff] [blame] | 141 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | __clear_bit (gpio, GPIO_IRQ_rising_edge); |
Philipp Zabel | 4fe4a2b | 2007-02-26 01:44:57 +0100 | [diff] [blame] | 143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | if (type & __IRQT_FALEDGE) { |
| 146 | /* printk("falling "); */ |
| 147 | __set_bit (gpio, GPIO_IRQ_falling_edge); |
Philipp Zabel | 4fe4a2b | 2007-02-26 01:44:57 +0100 | [diff] [blame] | 148 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | __clear_bit (gpio, GPIO_IRQ_falling_edge); |
Philipp Zabel | 4fe4a2b | 2007-02-26 01:44:57 +0100 | [diff] [blame] | 150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
| 152 | /* printk("edges\n"); */ |
| 153 | |
| 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; |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * GPIO IRQs must be acknowledged. This is for GPIO 0 and 1. |
| 161 | */ |
| 162 | |
| 163 | static void pxa_ack_low_gpio(unsigned int irq) |
| 164 | { |
| 165 | GEDR0 = (1 << (irq - IRQ_GPIO0)); |
| 166 | } |
| 167 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 168 | static struct irq_chip pxa_low_gpio_chip = { |
| 169 | .name = "GPIO-l", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | .ack = pxa_ack_low_gpio, |
| 171 | .mask = pxa_mask_low_irq, |
| 172 | .unmask = pxa_unmask_low_irq, |
Russell King | 7801907 | 2005-09-04 19:43:13 +0100 | [diff] [blame] | 173 | .set_type = pxa_gpio_irq_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | /* |
| 177 | * Demux handler for GPIO>=2 edge detect interrupts |
| 178 | */ |
| 179 | |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 180 | static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
| 182 | unsigned int mask; |
| 183 | int loop; |
| 184 | |
| 185 | do { |
| 186 | loop = 0; |
| 187 | |
Eric Miao | 4a3dcd3 | 2007-06-06 06:45:18 +0100 | [diff] [blame] | 188 | mask = GEDR0 & GPIO_IRQ_mask[0] & ~3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 196 | desc_handle_irq(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | irq++; |
| 198 | desc++; |
| 199 | mask >>= 1; |
| 200 | } while (mask); |
| 201 | loop = 1; |
| 202 | } |
| 203 | |
Eric Miao | 4a3dcd3 | 2007-06-06 06:45:18 +0100 | [diff] [blame] | 204 | mask = GEDR1 & GPIO_IRQ_mask[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | if (mask) { |
| 206 | GEDR1 = mask; |
| 207 | irq = IRQ_GPIO(32); |
| 208 | desc = irq_desc + irq; |
| 209 | do { |
| 210 | if (mask & 1) |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 211 | desc_handle_irq(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | irq++; |
| 213 | desc++; |
| 214 | mask >>= 1; |
| 215 | } while (mask); |
| 216 | loop = 1; |
| 217 | } |
| 218 | |
Eric Miao | 4a3dcd3 | 2007-06-06 06:45:18 +0100 | [diff] [blame] | 219 | mask = GEDR2 & GPIO_IRQ_mask[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | if (mask) { |
| 221 | GEDR2 = mask; |
| 222 | irq = IRQ_GPIO(64); |
| 223 | desc = irq_desc + irq; |
| 224 | do { |
| 225 | if (mask & 1) |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 226 | desc_handle_irq(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | irq++; |
| 228 | desc++; |
| 229 | mask >>= 1; |
| 230 | } while (mask); |
| 231 | loop = 1; |
| 232 | } |
| 233 | |
Eric Miao | 4a3dcd3 | 2007-06-06 06:45:18 +0100 | [diff] [blame] | 234 | mask = GEDR3 & GPIO_IRQ_mask[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | if (mask) { |
| 236 | GEDR3 = mask; |
| 237 | irq = IRQ_GPIO(96); |
| 238 | desc = irq_desc + irq; |
| 239 | do { |
| 240 | if (mask & 1) |
Linus Torvalds | 0cd61b6 | 2006-10-06 10:53:39 -0700 | [diff] [blame] | 241 | desc_handle_irq(irq, desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | irq++; |
| 243 | desc++; |
| 244 | mask >>= 1; |
| 245 | } while (mask); |
| 246 | loop = 1; |
| 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } while (loop); |
| 249 | } |
| 250 | |
| 251 | static void pxa_ack_muxed_gpio(unsigned int irq) |
| 252 | { |
| 253 | int gpio = irq - IRQ_GPIO(2) + 2; |
| 254 | GEDR(gpio) = GPIO_bit(gpio); |
| 255 | } |
| 256 | |
| 257 | static void pxa_mask_muxed_gpio(unsigned int irq) |
| 258 | { |
| 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); |
| 263 | } |
| 264 | |
| 265 | static void pxa_unmask_muxed_gpio(unsigned int irq) |
| 266 | { |
| 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]; |
| 272 | } |
| 273 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 274 | static struct irq_chip pxa_muxed_gpio_chip = { |
| 275 | .name = "GPIO", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | .ack = pxa_ack_muxed_gpio, |
| 277 | .mask = pxa_mask_muxed_gpio, |
| 278 | .unmask = pxa_unmask_muxed_gpio, |
Russell King | 7801907 | 2005-09-04 19:43:13 +0100 | [diff] [blame] | 279 | .set_type = pxa_gpio_irq_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | }; |
| 281 | |
Eric Miao | 348f2e3 | 2007-06-06 06:37:15 +0100 | [diff] [blame] | 282 | void __init pxa_init_irq_gpio(int gpio_nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
Eric Miao | 348f2e3 | 2007-06-06 06:37:15 +0100 | [diff] [blame] | 284 | int irq, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
eric miao | 30f0b40 | 2007-08-29 10:18:47 +0100 | [diff] [blame] | 286 | pxa_last_gpio = gpio_nr - 1; |
| 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | /* clear all GPIO edge detects */ |
Eric Miao | 348f2e3 | 2007-06-06 06:37:15 +0100 | [diff] [blame] | 289 | for (i = 0; i < gpio_nr; i += 32) { |
| 290 | GFER(i) = 0; |
| 291 | GRER(i) = 0; |
| 292 | GEDR(i) = GEDR(i); |
| 293 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | /* GPIO 0 and 1 must have their mask bit always set */ |
| 296 | GPIO_IRQ_mask[0] = 3; |
| 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) { |
| 299 | set_irq_chip(irq, &pxa_low_gpio_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 300 | set_irq_handler(irq, handle_edge_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 302 | } |
| 303 | |
Samuel | fd51bcc | 2007-08-28 19:56:34 +0100 | [diff] [blame] | 304 | for (irq = IRQ_GPIO(2); irq < IRQ_GPIO(gpio_nr); irq++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | set_irq_chip(irq, &pxa_muxed_gpio_chip); |
Russell King | 10dd5ce | 2006-11-23 11:41:32 +0000 | [diff] [blame] | 306 | set_irq_handler(irq, handle_edge_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 308 | } |
| 309 | |
| 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); |
| 313 | } |
eric miao | c95530c | 2007-08-29 10:22:17 +0100 | [diff] [blame^] | 314 | |
| 315 | void __init pxa_init_irq_set_wake(int (*set_wake)(unsigned int, unsigned int)) |
| 316 | { |
| 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; |
| 323 | } |