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> |
| 27 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 28 | #include <mach/hardware.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 29 | #include <asm/irq.h> |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 30 | #include <asm/setup.h> |
| 31 | |
| 32 | #include <asm/mach/arch.h> |
| 33 | #include <asm/mach/irq.h> |
| 34 | #include <asm/mach/map.h> |
| 35 | |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 36 | void __iomem *at91_aic_base; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 37 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 38 | static void at91_aic_mask_irq(struct irq_data *d) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 39 | { |
| 40 | /* Disable interrupt on AIC */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 41 | at91_aic_write(AT91_AIC_IDCR, 1 << d->irq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 44 | static void at91_aic_unmask_irq(struct irq_data *d) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 45 | { |
| 46 | /* Enable interrupt on AIC */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 47 | at91_aic_write(AT91_AIC_IECR, 1 << d->irq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Andrew Victor | 1f4fd0a | 2006-11-30 10:01:47 +0100 | [diff] [blame] | 50 | unsigned int at91_extern_irq; |
| 51 | |
| 52 | #define is_extern_irq(irq) ((1 << (irq)) & at91_extern_irq) |
| 53 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 54 | static int at91_aic_set_type(struct irq_data *d, unsigned type) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 55 | { |
| 56 | unsigned int smr, srctype; |
| 57 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 58 | switch (type) { |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 59 | case IRQ_TYPE_LEVEL_HIGH: |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 60 | srctype = AT91_AIC_SRCTYPE_HIGH; |
| 61 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 62 | case IRQ_TYPE_EDGE_RISING: |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 63 | srctype = AT91_AIC_SRCTYPE_RISING; |
| 64 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 65 | case IRQ_TYPE_LEVEL_LOW: |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 66 | if ((d->irq == AT91_ID_FIQ) || is_extern_irq(d->irq)) /* only supported on external interrupts */ |
Andrew Victor | 1f4fd0a | 2006-11-30 10:01:47 +0100 | [diff] [blame] | 67 | srctype = AT91_AIC_SRCTYPE_LOW; |
| 68 | else |
Andrew Victor | 37f2e4b | 2006-06-19 15:26:52 +0100 | [diff] [blame] | 69 | return -EINVAL; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 70 | break; |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 71 | case IRQ_TYPE_EDGE_FALLING: |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 72 | if ((d->irq == AT91_ID_FIQ) || is_extern_irq(d->irq)) /* only supported on external interrupts */ |
Andrew Victor | 1f4fd0a | 2006-11-30 10:01:47 +0100 | [diff] [blame] | 73 | srctype = AT91_AIC_SRCTYPE_FALLING; |
| 74 | else |
Andrew Victor | 37f2e4b | 2006-06-19 15:26:52 +0100 | [diff] [blame] | 75 | return -EINVAL; |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 76 | break; |
| 77 | default: |
| 78 | return -EINVAL; |
| 79 | } |
| 80 | |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 81 | smr = at91_aic_read(AT91_AIC_SMR(d->irq)) & ~AT91_AIC_SRCTYPE; |
| 82 | at91_aic_write(AT91_AIC_SMR(d->irq), smr | srctype); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 86 | #ifdef CONFIG_PM |
| 87 | |
| 88 | static u32 wakeups; |
| 89 | static u32 backups; |
| 90 | |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 91 | static int at91_aic_set_wake(struct irq_data *d, unsigned value) |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 92 | { |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 93 | if (unlikely(d->irq >= 32)) |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 94 | return -EINVAL; |
| 95 | |
| 96 | if (value) |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 97 | wakeups |= (1 << d->irq); |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 98 | else |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 99 | wakeups &= ~(1 << d->irq); |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | void at91_irq_suspend(void) |
| 105 | { |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 106 | backups = at91_aic_read(AT91_AIC_IMR); |
| 107 | at91_aic_write(AT91_AIC_IDCR, backups); |
| 108 | at91_aic_write(AT91_AIC_IECR, wakeups); |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void at91_irq_resume(void) |
| 112 | { |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 113 | at91_aic_write(AT91_AIC_IDCR, wakeups); |
| 114 | at91_aic_write(AT91_AIC_IECR, backups); |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | #else |
Andrew Victor | ba854e1 | 2006-07-05 17:22:52 +0100 | [diff] [blame] | 118 | #define at91_aic_set_wake NULL |
Andrew Victor | 683c66b | 2006-06-19 15:26:53 +0100 | [diff] [blame] | 119 | #endif |
| 120 | |
David Brownell | 38c677c | 2006-08-01 22:26:25 +0100 | [diff] [blame] | 121 | static struct irq_chip at91_aic_chip = { |
| 122 | .name = "AIC", |
Lennert Buytenhek | da0f940 | 2010-11-29 10:26:19 +0100 | [diff] [blame] | 123 | .irq_ack = at91_aic_mask_irq, |
| 124 | .irq_mask = at91_aic_mask_irq, |
| 125 | .irq_unmask = at91_aic_unmask_irq, |
| 126 | .irq_set_type = at91_aic_set_type, |
| 127 | .irq_set_wake = at91_aic_set_wake, |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | /* |
| 131 | * Initialize the AIC interrupt controller. |
| 132 | */ |
Andrew Victor | ba854e1 | 2006-07-05 17:22:52 +0100 | [diff] [blame] | 133 | void __init at91_aic_init(unsigned int priority[NR_AIC_IRQS]) |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 134 | { |
| 135 | unsigned int i; |
| 136 | |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 137 | at91_aic_base = ioremap(AT91_AIC, 512); |
| 138 | |
| 139 | if (!at91_aic_base) |
| 140 | panic("Impossible to ioremap AT91_AIC\n"); |
| 141 | |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 142 | /* |
| 143 | * The IVR is used by macro get_irqnr_and_base to read and verify. |
| 144 | * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred. |
| 145 | */ |
| 146 | for (i = 0; i < NR_AIC_IRQS; i++) { |
| 147 | /* Put irq number in Source Vector Register: */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 148 | at91_aic_write(AT91_AIC_SVR(i), i); |
Andrew Victor | ba854e1 | 2006-07-05 17:22:52 +0100 | [diff] [blame] | 149 | /* Active Low interrupt, with the specified priority */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 150 | 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] | 151 | |
Thomas Gleixner | f38c02f | 2011-03-24 13:35:09 +0100 | [diff] [blame] | 152 | irq_set_chip_and_handler(i, &at91_aic_chip, handle_level_irq); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 153 | set_irq_flags(i, IRQF_VALID | IRQF_PROBE); |
| 154 | |
| 155 | /* Perform 8 End Of Interrupt Command to make sure AIC will not Lock out nIRQ */ |
| 156 | if (i < 8) |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 157 | at91_aic_write(AT91_AIC_EOICR, 0); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* |
| 161 | * Spurious Interrupt ID in Spurious Vector Register is NR_AIC_IRQS |
| 162 | * When there is no current interrupt, the IRQ Vector Register reads the value stored in AIC_SPU |
| 163 | */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 164 | at91_aic_write(AT91_AIC_SPU, NR_AIC_IRQS); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 165 | |
| 166 | /* No debugging in AIC: Debug (Protect) Control Register */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 167 | at91_aic_write(AT91_AIC_DCR, 0); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 168 | |
| 169 | /* Disable and clear all interrupts initially */ |
Jean-Christophe PLAGNIOL-VILLARD | be6d432 | 2011-11-03 01:12:50 +0800 | [diff] [blame^] | 170 | at91_aic_write(AT91_AIC_IDCR, 0xFFFFFFFF); |
| 171 | at91_aic_write(AT91_AIC_ICCR, 0xFFFFFFFF); |
SAN People | 73a59c1 | 2006-01-09 17:05:41 +0000 | [diff] [blame] | 172 | } |