SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 1 | /* |
Andrew Victor | 9d04126 | 2007-02-05 11:42:07 +0100 | [diff] [blame] | 2 | * linux/arch/arm/mach-at91/irq.c |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2004 SAN People |
| 5 | * Copyright (C) 2004 ATMEL |
| 6 | * Copyright (C) Rick Bronson |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/mm.h> |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 26 | #include <linux/bitmap.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 27 | #include <linux/types.h> |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 28 | #include <linux/irq.h> |
| 29 | #include <linux/of.h> |
| 30 | #include <linux/of_address.h> |
| 31 | #include <linux/of_irq.h> |
| 32 | #include <linux/irqdomain.h> |
| 33 | #include <linux/err.h> |
Ludovic Desroches | f8a073e | 2012-06-20 16:13:30 +0200 | [diff] [blame] | 34 | #include <linux/slab.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 35 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 36 | #include <mach/hardware.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 37 | #include <asm/irq.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 38 | #include <asm/setup.h> |
| 39 | |
Ludovic Desroches | 3e13546 | 2012-06-11 15:38:03 +0200 | [diff] [blame] | 40 | #include <asm/exception.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 41 | #include <asm/mach/arch.h> |
| 42 | #include <asm/mach/irq.h> |
| 43 | #include <asm/mach/map.h> |
| 44 | |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 45 | #include <mach/at91_aic.h> |
| 46 | |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 47 | void __iomem *at91_aic_base; |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 48 | static struct irq_domain *at91_aic_domain; |
| 49 | static struct device_node *at91_aic_np; |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 50 | static unsigned int n_irqs = NR_AIC_IRQS; |
| 51 | static unsigned long at91_aic_caps = 0; |
Ludovic Desroches | f8a073e | 2012-06-20 16:13:30 +0200 | [diff] [blame] | 52 | static unsigned int *at91_aic_irq_priorities; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 53 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 54 | /* AIC5 introduces a Source Select Register */ |
| 55 | #define AT91_AIC_CAP_AIC5 (1 << 0) |
| 56 | #define has_aic5() (at91_aic_caps & AT91_AIC_CAP_AIC5) |
| 57 | |
| 58 | #ifdef CONFIG_PM |
| 59 | |
| 60 | static unsigned long *wakeups; |
| 61 | static unsigned long *backups; |
| 62 | |
| 63 | #define set_backup(bit) set_bit(bit, backups) |
| 64 | #define clear_backup(bit) clear_bit(bit, backups) |
| 65 | |
| 66 | static int at91_aic_pm_init(void) |
| 67 | { |
| 68 | backups = kzalloc(BITS_TO_LONGS(n_irqs) * sizeof(*backups), GFP_KERNEL); |
| 69 | if (!backups) |
| 70 | return -ENOMEM; |
| 71 | |
| 72 | wakeups = kzalloc(BITS_TO_LONGS(n_irqs) * sizeof(*backups), GFP_KERNEL); |
| 73 | if (!wakeups) { |
| 74 | kfree(backups); |
| 75 | return -ENOMEM; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int at91_aic_set_wake(struct irq_data *d, unsigned value) |
| 82 | { |
| 83 | if (unlikely(d->hwirq >= n_irqs)) |
| 84 | return -EINVAL; |
| 85 | |
| 86 | if (value) |
| 87 | set_bit(d->hwirq, wakeups); |
| 88 | else |
| 89 | clear_bit(d->hwirq, wakeups); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | void at91_irq_suspend(void) |
| 95 | { |
| 96 | int i = 0, bit; |
| 97 | |
| 98 | if (has_aic5()) { |
| 99 | /* disable enabled irqs */ |
| 100 | while ((bit = find_next_bit(backups, n_irqs, i)) < n_irqs) { |
| 101 | at91_aic_write(AT91_AIC5_SSR, |
| 102 | bit & AT91_AIC5_INTSEL_MSK); |
| 103 | at91_aic_write(AT91_AIC5_IDCR, 1); |
| 104 | i = bit; |
| 105 | } |
| 106 | /* enable wakeup irqs */ |
| 107 | i = 0; |
| 108 | while ((bit = find_next_bit(wakeups, n_irqs, i)) < n_irqs) { |
| 109 | at91_aic_write(AT91_AIC5_SSR, |
| 110 | bit & AT91_AIC5_INTSEL_MSK); |
| 111 | at91_aic_write(AT91_AIC5_IECR, 1); |
| 112 | i = bit; |
| 113 | } |
| 114 | } else { |
| 115 | at91_aic_write(AT91_AIC_IDCR, *backups); |
| 116 | at91_aic_write(AT91_AIC_IECR, *wakeups); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void at91_irq_resume(void) |
| 121 | { |
| 122 | int i = 0, bit; |
| 123 | |
| 124 | if (has_aic5()) { |
| 125 | /* disable wakeup irqs */ |
| 126 | while ((bit = find_next_bit(wakeups, n_irqs, i)) < n_irqs) { |
| 127 | at91_aic_write(AT91_AIC5_SSR, |
| 128 | bit & AT91_AIC5_INTSEL_MSK); |
| 129 | at91_aic_write(AT91_AIC5_IDCR, 1); |
| 130 | i = bit; |
| 131 | } |
| 132 | /* enable irqs disabled for suspend */ |
| 133 | i = 0; |
| 134 | while ((bit = find_next_bit(backups, n_irqs, i)) < n_irqs) { |
| 135 | at91_aic_write(AT91_AIC5_SSR, |
| 136 | bit & AT91_AIC5_INTSEL_MSK); |
| 137 | at91_aic_write(AT91_AIC5_IECR, 1); |
| 138 | i = bit; |
| 139 | } |
| 140 | } else { |
| 141 | at91_aic_write(AT91_AIC_IDCR, *wakeups); |
| 142 | at91_aic_write(AT91_AIC_IECR, *backups); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | #else |
| 147 | static inline int at91_aic_pm_init(void) |
| 148 | { |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | #define set_backup(bit) |
| 153 | #define clear_backup(bit) |
| 154 | #define at91_aic_set_wake NULL |
| 155 | |
| 156 | #endif /* CONFIG_PM */ |
| 157 | |
| 158 | asmlinkage void __exception_irq_entry |
| 159 | at91_aic_handle_irq(struct pt_regs *regs) |
Ludovic Desroches | 3e13546 | 2012-06-11 15:38:03 +0200 | [diff] [blame] | 160 | { |
| 161 | u32 irqnr; |
| 162 | u32 irqstat; |
| 163 | |
| 164 | irqnr = at91_aic_read(AT91_AIC_IVR); |
| 165 | irqstat = at91_aic_read(AT91_AIC_ISR); |
| 166 | |
| 167 | /* |
| 168 | * ISR value is 0 when there is no current interrupt or when there is |
| 169 | * a spurious interrupt |
| 170 | */ |
| 171 | if (!irqstat) |
| 172 | at91_aic_write(AT91_AIC_EOICR, 0); |
| 173 | else |
| 174 | handle_IRQ(irqnr, regs); |
| 175 | } |
| 176 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 177 | asmlinkage void __exception_irq_entry |
| 178 | at91_aic5_handle_irq(struct pt_regs *regs) |
| 179 | { |
| 180 | u32 irqnr; |
| 181 | u32 irqstat; |
| 182 | |
| 183 | irqnr = at91_aic_read(AT91_AIC5_IVR); |
| 184 | irqstat = at91_aic_read(AT91_AIC5_ISR); |
| 185 | |
| 186 | if (!irqstat) |
| 187 | at91_aic_write(AT91_AIC5_EOICR, 0); |
| 188 | else |
| 189 | handle_IRQ(irqnr, regs); |
| 190 | } |
| 191 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 192 | static void at91_aic_mask_irq(struct irq_data *d) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 193 | { |
| 194 | /* Disable interrupt on AIC */ |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 195 | at91_aic_write(AT91_AIC_IDCR, 1 << d->hwirq); |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 196 | /* Update ISR cache */ |
| 197 | clear_backup(d->hwirq); |
| 198 | } |
| 199 | |
| 200 | static void __maybe_unused at91_aic5_mask_irq(struct irq_data *d) |
| 201 | { |
| 202 | /* Disable interrupt on AIC5 */ |
| 203 | at91_aic_write(AT91_AIC5_SSR, d->hwirq & AT91_AIC5_INTSEL_MSK); |
| 204 | at91_aic_write(AT91_AIC5_IDCR, 1); |
| 205 | /* Update ISR cache */ |
| 206 | clear_backup(d->hwirq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 209 | static void at91_aic_unmask_irq(struct irq_data *d) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 210 | { |
| 211 | /* Enable interrupt on AIC */ |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 212 | at91_aic_write(AT91_AIC_IECR, 1 << d->hwirq); |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 213 | /* Update ISR cache */ |
| 214 | set_backup(d->hwirq); |
| 215 | } |
| 216 | |
| 217 | static void __maybe_unused at91_aic5_unmask_irq(struct irq_data *d) |
| 218 | { |
| 219 | /* Enable interrupt on AIC5 */ |
| 220 | at91_aic_write(AT91_AIC5_SSR, d->hwirq & AT91_AIC5_INTSEL_MSK); |
| 221 | at91_aic_write(AT91_AIC5_IECR, 1); |
| 222 | /* Update ISR cache */ |
| 223 | set_backup(d->hwirq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Ludovic Desroches | 42a859d | 2012-05-25 14:11:51 +0200 | [diff] [blame] | 226 | static void at91_aic_eoi(struct irq_data *d) |
| 227 | { |
| 228 | /* |
| 229 | * Mark end-of-interrupt on AIC, the controller doesn't care about |
| 230 | * the value written. Moreover it's a write-only register. |
| 231 | */ |
| 232 | at91_aic_write(AT91_AIC_EOICR, 0); |
| 233 | } |
| 234 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 235 | static void __maybe_unused at91_aic5_eoi(struct irq_data *d) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 236 | { |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 237 | at91_aic_write(AT91_AIC5_EOICR, 0); |
| 238 | } |
| 239 | |
| 240 | unsigned long *at91_extern_irq; |
| 241 | |
| 242 | #define is_extern_irq(hwirq) test_bit(hwirq, at91_extern_irq) |
| 243 | |
| 244 | static int at91_aic_compute_srctype(struct irq_data *d, unsigned type) |
| 245 | { |
| 246 | int srctype; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 247 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 248 | switch (type) { |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 249 | case IRQ_TYPE_LEVEL_HIGH: |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 250 | srctype = AT91_AIC_SRCTYPE_HIGH; |
| 251 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 252 | case IRQ_TYPE_EDGE_RISING: |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 253 | srctype = AT91_AIC_SRCTYPE_RISING; |
| 254 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 255 | case IRQ_TYPE_LEVEL_LOW: |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 256 | if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */ |
Andrew Victor | 1f4fd0a | 2006-11-30 10:01:47 +0100 | [diff] [blame] | 257 | srctype = AT91_AIC_SRCTYPE_LOW; |
| 258 | else |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 259 | srctype = -EINVAL; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 260 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 261 | case IRQ_TYPE_EDGE_FALLING: |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 262 | if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */ |
Andrew Victor | 1f4fd0a | 2006-11-30 10:01:47 +0100 | [diff] [blame] | 263 | srctype = AT91_AIC_SRCTYPE_FALLING; |
| 264 | else |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 265 | srctype = -EINVAL; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 266 | break; |
| 267 | default: |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 268 | srctype = -EINVAL; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 271 | return srctype; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 274 | static int at91_aic_set_type(struct irq_data *d, unsigned type) |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 275 | { |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 276 | unsigned int smr; |
| 277 | int srctype; |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 278 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 279 | srctype = at91_aic_compute_srctype(d, type); |
| 280 | if (srctype < 0) |
| 281 | return srctype; |
| 282 | |
| 283 | if (has_aic5()) { |
| 284 | at91_aic_write(AT91_AIC5_SSR, |
| 285 | d->hwirq & AT91_AIC5_INTSEL_MSK); |
| 286 | smr = at91_aic_read(AT91_AIC5_SMR) & ~AT91_AIC_SRCTYPE; |
| 287 | at91_aic_write(AT91_AIC5_SMR, smr | srctype); |
| 288 | } else { |
| 289 | smr = at91_aic_read(AT91_AIC_SMR(d->hwirq)) |
| 290 | & ~AT91_AIC_SRCTYPE; |
| 291 | at91_aic_write(AT91_AIC_SMR(d->hwirq), smr | srctype); |
| 292 | } |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 297 | static struct irq_chip at91_aic_chip = { |
| 298 | .name = "AIC", |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 299 | .irq_mask = at91_aic_mask_irq, |
| 300 | .irq_unmask = at91_aic_unmask_irq, |
| 301 | .irq_set_type = at91_aic_set_type, |
| 302 | .irq_set_wake = at91_aic_set_wake, |
Ludovic Desroches | 42a859d | 2012-05-25 14:11:51 +0200 | [diff] [blame] | 303 | .irq_eoi = at91_aic_eoi, |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 304 | }; |
| 305 | |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 306 | static void __init at91_aic_hw_init(unsigned int spu_vector) |
| 307 | { |
| 308 | int i; |
| 309 | |
| 310 | /* |
| 311 | * Perform 8 End Of Interrupt Command to make sure AIC |
| 312 | * will not Lock out nIRQ |
| 313 | */ |
| 314 | for (i = 0; i < 8; i++) |
| 315 | at91_aic_write(AT91_AIC_EOICR, 0); |
| 316 | |
| 317 | /* |
| 318 | * Spurious Interrupt ID in Spurious Vector Register. |
| 319 | * When there is no current interrupt, the IRQ Vector Register |
| 320 | * reads the value stored in AIC_SPU |
| 321 | */ |
| 322 | at91_aic_write(AT91_AIC_SPU, spu_vector); |
| 323 | |
| 324 | /* No debugging in AIC: Debug (Protect) Control Register */ |
| 325 | at91_aic_write(AT91_AIC_DCR, 0); |
| 326 | |
| 327 | /* Disable and clear all interrupts initially */ |
| 328 | at91_aic_write(AT91_AIC_IDCR, 0xFFFFFFFF); |
| 329 | at91_aic_write(AT91_AIC_ICCR, 0xFFFFFFFF); |
| 330 | } |
| 331 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 332 | static void __init __maybe_unused at91_aic5_hw_init(unsigned int spu_vector) |
| 333 | { |
| 334 | int i; |
| 335 | |
| 336 | /* |
| 337 | * Perform 8 End Of Interrupt Command to make sure AIC |
| 338 | * will not Lock out nIRQ |
| 339 | */ |
| 340 | for (i = 0; i < 8; i++) |
| 341 | at91_aic_write(AT91_AIC5_EOICR, 0); |
| 342 | |
| 343 | /* |
| 344 | * Spurious Interrupt ID in Spurious Vector Register. |
| 345 | * When there is no current interrupt, the IRQ Vector Register |
| 346 | * reads the value stored in AIC_SPU |
| 347 | */ |
| 348 | at91_aic_write(AT91_AIC5_SPU, spu_vector); |
| 349 | |
| 350 | /* No debugging in AIC: Debug (Protect) Control Register */ |
| 351 | at91_aic_write(AT91_AIC5_DCR, 0); |
| 352 | |
| 353 | /* Disable and clear all interrupts initially */ |
| 354 | for (i = 0; i < n_irqs; i++) { |
| 355 | at91_aic_write(AT91_AIC5_SSR, i & AT91_AIC5_INTSEL_MSK); |
| 356 | at91_aic_write(AT91_AIC5_IDCR, 1); |
| 357 | at91_aic_write(AT91_AIC5_ICCR, 1); |
| 358 | } |
| 359 | } |
| 360 | |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 361 | #if defined(CONFIG_OF) |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 362 | static int at91_aic_irq_map(struct irq_domain *h, unsigned int virq, |
| 363 | irq_hw_number_t hw) |
| 364 | { |
| 365 | /* Put virq number in Source Vector Register */ |
| 366 | at91_aic_write(AT91_AIC_SVR(hw), virq); |
| 367 | |
Ludovic Desroches | f8a073e | 2012-06-20 16:13:30 +0200 | [diff] [blame] | 368 | /* Active Low interrupt, with priority */ |
| 369 | at91_aic_write(AT91_AIC_SMR(hw), |
| 370 | AT91_AIC_SRCTYPE_LOW | at91_aic_irq_priorities[hw]); |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 371 | |
Ludovic Desroches | 42a859d | 2012-05-25 14:11:51 +0200 | [diff] [blame] | 372 | irq_set_chip_and_handler(virq, &at91_aic_chip, handle_fasteoi_irq); |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 373 | set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); |
| 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 378 | static int at91_aic5_irq_map(struct irq_domain *h, unsigned int virq, |
| 379 | irq_hw_number_t hw) |
| 380 | { |
| 381 | at91_aic_write(AT91_AIC5_SSR, hw & AT91_AIC5_INTSEL_MSK); |
| 382 | |
| 383 | /* Put virq number in Source Vector Register */ |
| 384 | at91_aic_write(AT91_AIC5_SVR, virq); |
| 385 | |
| 386 | /* Active Low interrupt, with priority */ |
| 387 | at91_aic_write(AT91_AIC5_SMR, |
| 388 | AT91_AIC_SRCTYPE_LOW | at91_aic_irq_priorities[hw]); |
| 389 | |
| 390 | irq_set_chip_and_handler(virq, &at91_aic_chip, handle_fasteoi_irq); |
| 391 | set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
Ludovic Desroches | f8a073e | 2012-06-20 16:13:30 +0200 | [diff] [blame] | 396 | static int at91_aic_irq_domain_xlate(struct irq_domain *d, struct device_node *ctrlr, |
| 397 | const u32 *intspec, unsigned int intsize, |
| 398 | irq_hw_number_t *out_hwirq, unsigned int *out_type) |
| 399 | { |
| 400 | if (WARN_ON(intsize < 3)) |
| 401 | return -EINVAL; |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 402 | if (WARN_ON(intspec[0] >= n_irqs)) |
Ludovic Desroches | f8a073e | 2012-06-20 16:13:30 +0200 | [diff] [blame] | 403 | return -EINVAL; |
| 404 | if (WARN_ON((intspec[2] < AT91_AIC_IRQ_MIN_PRIORITY) |
| 405 | || (intspec[2] > AT91_AIC_IRQ_MAX_PRIORITY))) |
| 406 | return -EINVAL; |
| 407 | |
| 408 | *out_hwirq = intspec[0]; |
| 409 | *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK; |
| 410 | at91_aic_irq_priorities[*out_hwirq] = intspec[2]; |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 415 | static struct irq_domain_ops at91_aic_irq_ops = { |
| 416 | .map = at91_aic_irq_map, |
Ludovic Desroches | f8a073e | 2012-06-20 16:13:30 +0200 | [diff] [blame] | 417 | .xlate = at91_aic_irq_domain_xlate, |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 418 | }; |
| 419 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 420 | int __init at91_aic_of_common_init(struct device_node *node, |
| 421 | struct device_node *parent) |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 422 | { |
Jean-Christophe PLAGNIOL-VILLARD | c657394 | 2012-04-09 19:36:36 +0800 | [diff] [blame] | 423 | struct property *prop; |
| 424 | const __be32 *p; |
| 425 | u32 val; |
| 426 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 427 | at91_extern_irq = kzalloc(BITS_TO_LONGS(n_irqs) |
| 428 | * sizeof(*at91_extern_irq), GFP_KERNEL); |
| 429 | if (!at91_extern_irq) |
| 430 | return -ENOMEM; |
| 431 | |
| 432 | if (at91_aic_pm_init()) { |
| 433 | kfree(at91_extern_irq); |
| 434 | return -ENOMEM; |
| 435 | } |
| 436 | |
| 437 | at91_aic_irq_priorities = kzalloc(n_irqs |
Ludovic Desroches | f8a073e | 2012-06-20 16:13:30 +0200 | [diff] [blame] | 438 | * sizeof(*at91_aic_irq_priorities), |
| 439 | GFP_KERNEL); |
| 440 | if (!at91_aic_irq_priorities) |
| 441 | return -ENOMEM; |
| 442 | |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 443 | at91_aic_base = of_iomap(node, 0); |
| 444 | at91_aic_np = node; |
| 445 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 446 | at91_aic_domain = irq_domain_add_linear(at91_aic_np, n_irqs, |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 447 | &at91_aic_irq_ops, NULL); |
| 448 | if (!at91_aic_domain) |
| 449 | panic("Unable to add AIC irq domain (DT)\n"); |
| 450 | |
Jean-Christophe PLAGNIOL-VILLARD | c657394 | 2012-04-09 19:36:36 +0800 | [diff] [blame] | 451 | of_property_for_each_u32(node, "atmel,external-irqs", prop, p, val) { |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 452 | if (val >= n_irqs) |
| 453 | pr_warn("AIC: external irq %d >= %d skip it\n", |
| 454 | val, n_irqs); |
Jean-Christophe PLAGNIOL-VILLARD | c657394 | 2012-04-09 19:36:36 +0800 | [diff] [blame] | 455 | else |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 456 | set_bit(val, at91_extern_irq); |
Jean-Christophe PLAGNIOL-VILLARD | c657394 | 2012-04-09 19:36:36 +0800 | [diff] [blame] | 457 | } |
| 458 | |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 459 | irq_set_default_host(at91_aic_domain); |
| 460 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | int __init at91_aic_of_init(struct device_node *node, |
| 465 | struct device_node *parent) |
| 466 | { |
| 467 | int err; |
| 468 | |
| 469 | err = at91_aic_of_common_init(node, parent); |
| 470 | if (err) |
| 471 | return err; |
| 472 | |
| 473 | at91_aic_hw_init(n_irqs); |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | int __init at91_aic5_of_init(struct device_node *node, |
| 479 | struct device_node *parent) |
| 480 | { |
| 481 | int err; |
| 482 | |
| 483 | at91_aic_caps |= AT91_AIC_CAP_AIC5; |
| 484 | n_irqs = NR_AIC5_IRQS; |
| 485 | at91_aic_chip.irq_ack = at91_aic5_mask_irq; |
| 486 | at91_aic_chip.irq_mask = at91_aic5_mask_irq; |
| 487 | at91_aic_chip.irq_unmask = at91_aic5_unmask_irq; |
| 488 | at91_aic_chip.irq_eoi = at91_aic5_eoi; |
| 489 | at91_aic_irq_ops.map = at91_aic5_irq_map; |
| 490 | |
| 491 | err = at91_aic_of_common_init(node, parent); |
| 492 | if (err) |
| 493 | return err; |
| 494 | |
| 495 | at91_aic5_hw_init(n_irqs); |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 496 | |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 497 | return 0; |
| 498 | } |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 499 | #endif |
| 500 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 501 | /* |
| 502 | * Initialize the AIC interrupt controller. |
| 503 | */ |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 504 | void __init at91_aic_init(unsigned int *priority) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 505 | { |
| 506 | unsigned int i; |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 507 | int irq_base; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 508 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 509 | if (at91_aic_pm_init()) |
| 510 | panic("Unable to allocate bit maps\n"); |
| 511 | |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 512 | at91_aic_base = ioremap(AT91_AIC, 512); |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 513 | if (!at91_aic_base) |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 514 | panic("Unable to ioremap AIC registers\n"); |
| 515 | |
| 516 | /* Add irq domain for AIC */ |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 517 | irq_base = irq_alloc_descs(-1, 0, n_irqs, 0); |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 518 | if (irq_base < 0) { |
| 519 | WARN(1, "Cannot allocate irq_descs, assuming pre-allocated\n"); |
| 520 | irq_base = 0; |
| 521 | } |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 522 | at91_aic_domain = irq_domain_add_legacy(at91_aic_np, n_irqs, |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 523 | irq_base, 0, |
| 524 | &irq_domain_simple_ops, NULL); |
| 525 | |
| 526 | if (!at91_aic_domain) |
| 527 | panic("Unable to add AIC irq domain\n"); |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 528 | |
Nicolas Ferre | 8014d6f4 | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 529 | irq_set_default_host(at91_aic_domain); |
| 530 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 531 | /* |
| 532 | * The IVR is used by macro get_irqnr_and_base to read and verify. |
| 533 | * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred. |
| 534 | */ |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 535 | for (i = 0; i < n_irqs; i++) { |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 536 | /* Put hardware irq number in Source Vector Register: */ |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 537 | at91_aic_write(AT91_AIC_SVR(i), NR_IRQS_LEGACY + i); |
Andrew Victor | ba854e1 | 2006-07-05 17:22:52 +0100 | [diff] [blame] | 538 | /* Active Low interrupt, with the specified priority */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 539 | at91_aic_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]); |
Ludovic Desroches | 8fe82a5 | 2012-06-21 14:47:27 +0200 | [diff] [blame] | 540 | irq_set_chip_and_handler(NR_IRQS_LEGACY + i, &at91_aic_chip, handle_fasteoi_irq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 541 | set_irq_flags(i, IRQF_VALID | IRQF_PROBE); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Ludovic Desroches | c4b6852 | 2012-05-30 10:01:09 +0200 | [diff] [blame^] | 544 | at91_aic_hw_init(n_irqs); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 545 | } |