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> |
| 26 | #include <linux/types.h> |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 27 | #include <linux/irq.h> |
| 28 | #include <linux/of.h> |
| 29 | #include <linux/of_address.h> |
| 30 | #include <linux/of_irq.h> |
| 31 | #include <linux/irqdomain.h> |
| 32 | #include <linux/err.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 33 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 34 | #include <mach/hardware.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 35 | #include <asm/irq.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 36 | #include <asm/setup.h> |
| 37 | |
| 38 | #include <asm/mach/arch.h> |
| 39 | #include <asm/mach/irq.h> |
| 40 | #include <asm/mach/map.h> |
| 41 | |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 42 | void __iomem *at91_aic_base; |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 43 | static struct irq_domain *at91_aic_domain; |
| 44 | static struct device_node *at91_aic_np; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 45 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 46 | static void at91_aic_mask_irq(struct irq_data *d) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 47 | { |
| 48 | /* Disable interrupt on AIC */ |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 49 | at91_aic_write(AT91_AIC_IDCR, 1 << d->hwirq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 52 | static void at91_aic_unmask_irq(struct irq_data *d) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 53 | { |
| 54 | /* Enable interrupt on AIC */ |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 55 | at91_aic_write(AT91_AIC_IECR, 1 << d->hwirq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Ludovic Desroches | 42a859d | 2012-05-25 14:11:51 +0200 | [diff] [blame^] | 58 | static void at91_aic_eoi(struct irq_data *d) |
| 59 | { |
| 60 | /* |
| 61 | * Mark end-of-interrupt on AIC, the controller doesn't care about |
| 62 | * the value written. Moreover it's a write-only register. |
| 63 | */ |
| 64 | at91_aic_write(AT91_AIC_EOICR, 0); |
| 65 | } |
| 66 | |
Andrew Victor | 1f4fd0a | 2006-11-30 10:01:47 +0100 | [diff] [blame] | 67 | unsigned int at91_extern_irq; |
| 68 | |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 69 | #define is_extern_irq(hwirq) ((1 << (hwirq)) & at91_extern_irq) |
Andrew Victor | 1f4fd0a | 2006-11-30 10:01:47 +0100 | [diff] [blame] | 70 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 71 | static int at91_aic_set_type(struct irq_data *d, unsigned type) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 72 | { |
| 73 | unsigned int smr, srctype; |
| 74 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 75 | switch (type) { |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 76 | case IRQ_TYPE_LEVEL_HIGH: |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 77 | srctype = AT91_AIC_SRCTYPE_HIGH; |
| 78 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 79 | case IRQ_TYPE_EDGE_RISING: |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 80 | srctype = AT91_AIC_SRCTYPE_RISING; |
| 81 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 82 | case IRQ_TYPE_LEVEL_LOW: |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 83 | 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] | 84 | srctype = AT91_AIC_SRCTYPE_LOW; |
| 85 | else |
Andrew Victor | 37f2e4b | 2006-06-19 15:26:52 +0100 | [diff] [blame] | 86 | return -EINVAL; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 87 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 88 | case IRQ_TYPE_EDGE_FALLING: |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 89 | 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] | 90 | srctype = AT91_AIC_SRCTYPE_FALLING; |
| 91 | else |
Andrew Victor | 37f2e4b | 2006-06-19 15:26:52 +0100 | [diff] [blame] | 92 | return -EINVAL; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 93 | break; |
| 94 | default: |
| 95 | return -EINVAL; |
| 96 | } |
| 97 | |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 98 | smr = at91_aic_read(AT91_AIC_SMR(d->hwirq)) & ~AT91_AIC_SRCTYPE; |
| 99 | at91_aic_write(AT91_AIC_SMR(d->hwirq), smr | srctype); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 103 | #ifdef CONFIG_PM |
| 104 | |
| 105 | static u32 wakeups; |
| 106 | static u32 backups; |
| 107 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 108 | static int at91_aic_set_wake(struct irq_data *d, unsigned value) |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 109 | { |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 110 | if (unlikely(d->hwirq >= NR_AIC_IRQS)) |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 111 | return -EINVAL; |
| 112 | |
| 113 | if (value) |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 114 | wakeups |= (1 << d->hwirq); |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 115 | else |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 116 | wakeups &= ~(1 << d->hwirq); |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | void at91_irq_suspend(void) |
| 122 | { |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 123 | backups = at91_aic_read(AT91_AIC_IMR); |
| 124 | at91_aic_write(AT91_AIC_IDCR, backups); |
| 125 | at91_aic_write(AT91_AIC_IECR, wakeups); |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void at91_irq_resume(void) |
| 129 | { |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 130 | at91_aic_write(AT91_AIC_IDCR, wakeups); |
| 131 | at91_aic_write(AT91_AIC_IECR, backups); |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | #else |
Andrew Victor | ba854e1 | 2006-07-05 17:22:52 +0100 | [diff] [blame] | 135 | #define at91_aic_set_wake NULL |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 136 | #endif |
| 137 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 138 | static struct irq_chip at91_aic_chip = { |
| 139 | .name = "AIC", |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 140 | .irq_mask = at91_aic_mask_irq, |
| 141 | .irq_unmask = at91_aic_unmask_irq, |
| 142 | .irq_set_type = at91_aic_set_type, |
| 143 | .irq_set_wake = at91_aic_set_wake, |
Ludovic Desroches | 42a859d | 2012-05-25 14:11:51 +0200 | [diff] [blame^] | 144 | .irq_eoi = at91_aic_eoi, |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
Nicolas Ferre | 8014d6f | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 147 | static void __init at91_aic_hw_init(unsigned int spu_vector) |
| 148 | { |
| 149 | int i; |
| 150 | |
| 151 | /* |
| 152 | * Perform 8 End Of Interrupt Command to make sure AIC |
| 153 | * will not Lock out nIRQ |
| 154 | */ |
| 155 | for (i = 0; i < 8; i++) |
| 156 | at91_aic_write(AT91_AIC_EOICR, 0); |
| 157 | |
| 158 | /* |
| 159 | * Spurious Interrupt ID in Spurious Vector Register. |
| 160 | * When there is no current interrupt, the IRQ Vector Register |
| 161 | * reads the value stored in AIC_SPU |
| 162 | */ |
| 163 | at91_aic_write(AT91_AIC_SPU, spu_vector); |
| 164 | |
| 165 | /* No debugging in AIC: Debug (Protect) Control Register */ |
| 166 | at91_aic_write(AT91_AIC_DCR, 0); |
| 167 | |
| 168 | /* Disable and clear all interrupts initially */ |
| 169 | at91_aic_write(AT91_AIC_IDCR, 0xFFFFFFFF); |
| 170 | at91_aic_write(AT91_AIC_ICCR, 0xFFFFFFFF); |
| 171 | } |
| 172 | |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 173 | #if defined(CONFIG_OF) |
Nicolas Ferre | 8014d6f | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 174 | static int at91_aic_irq_map(struct irq_domain *h, unsigned int virq, |
| 175 | irq_hw_number_t hw) |
| 176 | { |
| 177 | /* Put virq number in Source Vector Register */ |
| 178 | at91_aic_write(AT91_AIC_SVR(hw), virq); |
| 179 | |
| 180 | /* Active Low interrupt, without priority */ |
| 181 | at91_aic_write(AT91_AIC_SMR(hw), AT91_AIC_SRCTYPE_LOW); |
| 182 | |
Ludovic Desroches | 42a859d | 2012-05-25 14:11:51 +0200 | [diff] [blame^] | 183 | irq_set_chip_and_handler(virq, &at91_aic_chip, handle_fasteoi_irq); |
Nicolas Ferre | 8014d6f | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 184 | set_irq_flags(virq, IRQF_VALID | IRQF_PROBE); |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | static struct irq_domain_ops at91_aic_irq_ops = { |
| 190 | .map = at91_aic_irq_map, |
| 191 | .xlate = irq_domain_xlate_twocell, |
| 192 | }; |
| 193 | |
| 194 | int __init at91_aic_of_init(struct device_node *node, |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 195 | struct device_node *parent) |
| 196 | { |
| 197 | at91_aic_base = of_iomap(node, 0); |
| 198 | at91_aic_np = node; |
| 199 | |
Nicolas Ferre | 8014d6f | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 200 | at91_aic_domain = irq_domain_add_linear(at91_aic_np, NR_AIC_IRQS, |
| 201 | &at91_aic_irq_ops, NULL); |
| 202 | if (!at91_aic_domain) |
| 203 | panic("Unable to add AIC irq domain (DT)\n"); |
| 204 | |
| 205 | irq_set_default_host(at91_aic_domain); |
| 206 | |
| 207 | at91_aic_hw_init(NR_AIC_IRQS); |
| 208 | |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 209 | return 0; |
| 210 | } |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 211 | #endif |
| 212 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 213 | /* |
| 214 | * Initialize the AIC interrupt controller. |
| 215 | */ |
Andrew Victor | ba854e1 | 2006-07-05 17:22:52 +0100 | [diff] [blame] | 216 | void __init at91_aic_init(unsigned int priority[NR_AIC_IRQS]) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 217 | { |
| 218 | unsigned int i; |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 219 | int irq_base; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 220 | |
Nicolas Ferre | 8014d6f | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 221 | at91_aic_base = ioremap(AT91_AIC, 512); |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 222 | if (!at91_aic_base) |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 223 | panic("Unable to ioremap AIC registers\n"); |
| 224 | |
| 225 | /* Add irq domain for AIC */ |
| 226 | irq_base = irq_alloc_descs(-1, 0, NR_AIC_IRQS, 0); |
| 227 | if (irq_base < 0) { |
| 228 | WARN(1, "Cannot allocate irq_descs, assuming pre-allocated\n"); |
| 229 | irq_base = 0; |
| 230 | } |
| 231 | at91_aic_domain = irq_domain_add_legacy(at91_aic_np, NR_AIC_IRQS, |
| 232 | irq_base, 0, |
| 233 | &irq_domain_simple_ops, NULL); |
| 234 | |
| 235 | if (!at91_aic_domain) |
| 236 | panic("Unable to add AIC irq domain\n"); |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 237 | |
Nicolas Ferre | 8014d6f | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 238 | irq_set_default_host(at91_aic_domain); |
| 239 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 240 | /* |
| 241 | * The IVR is used by macro get_irqnr_and_base to read and verify. |
| 242 | * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred. |
| 243 | */ |
| 244 | for (i = 0; i < NR_AIC_IRQS; i++) { |
Nicolas Ferre | e261501 | 2011-11-22 22:26:09 +0100 | [diff] [blame] | 245 | /* Put hardware irq number in Source Vector Register: */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 246 | at91_aic_write(AT91_AIC_SVR(i), i); |
Andrew Victor | ba854e1 | 2006-07-05 17:22:52 +0100 | [diff] [blame] | 247 | /* Active Low interrupt, with the specified priority */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame] | 248 | at91_aic_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 249 | |
Ludovic Desroches | 42a859d | 2012-05-25 14:11:51 +0200 | [diff] [blame^] | 250 | irq_set_chip_and_handler(i, &at91_aic_chip, handle_fasteoi_irq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 251 | set_irq_flags(i, IRQF_VALID | IRQF_PROBE); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Nicolas Ferre | 8014d6f | 2012-02-14 18:08:14 +0100 | [diff] [blame] | 254 | at91_aic_hw_init(NR_AIC_IRQS); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 255 | } |