Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 2 | * File: arch/blackfin/mach-common/ints-priority.c |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Simon Arlott | d2d50aa | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 4 | * Description: Set up the interrupt priorities |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 5 | * |
| 6 | * Modified: |
| 7 | * 1996 Roman Zippel |
| 8 | * 1999 D. Jeff Dionne <jeff@uclinux.org> |
| 9 | * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca> |
| 10 | * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca> |
| 11 | * 2003 Metrowerks/Motorola |
| 12 | * 2003 Bas Vermeulen <bas@buyways.nl> |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 13 | * Copyright 2004-2008 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 14 | * |
| 15 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU General Public License as published by |
| 19 | * the Free Software Foundation; either version 2 of the License, or |
| 20 | * (at your option) any later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, see the file COPYING, or write |
| 29 | * to the Free Software Foundation, Inc., |
| 30 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 31 | */ |
| 32 | |
| 33 | #include <linux/module.h> |
| 34 | #include <linux/kernel_stat.h> |
| 35 | #include <linux/seq_file.h> |
| 36 | #include <linux/irq.h> |
| 37 | #ifdef CONFIG_KGDB |
| 38 | #include <linux/kgdb.h> |
| 39 | #endif |
| 40 | #include <asm/traps.h> |
| 41 | #include <asm/blackfin.h> |
| 42 | #include <asm/gpio.h> |
| 43 | #include <asm/irq_handler.h> |
| 44 | |
| 45 | #ifdef BF537_FAMILY |
| 46 | # define BF537_GENERIC_ERROR_INT_DEMUX |
| 47 | #else |
| 48 | # undef BF537_GENERIC_ERROR_INT_DEMUX |
| 49 | #endif |
| 50 | |
| 51 | /* |
| 52 | * NOTES: |
| 53 | * - we have separated the physical Hardware interrupt from the |
| 54 | * levels that the LINUX kernel sees (see the description in irq.h) |
| 55 | * - |
| 56 | */ |
| 57 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 58 | #ifndef CONFIG_SMP |
Mike Frysinger | a99bbcc | 2007-10-22 00:19:31 +0800 | [diff] [blame] | 59 | /* Initialize this to an actual value to force it into the .data |
| 60 | * section so that we know it is properly initialized at entry into |
| 61 | * the kernel but before bss is initialized to zero (which is where |
| 62 | * it would live otherwise). The 0x1f magic represents the IRQs we |
| 63 | * cannot actually mask out in hardware. |
| 64 | */ |
| 65 | unsigned long irq_flags = 0x1f; |
Mike Frysinger | fe8015c | 2008-10-28 11:07:15 +0800 | [diff] [blame] | 66 | EXPORT_SYMBOL(irq_flags); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 67 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 68 | |
| 69 | /* The number of spurious interrupts */ |
| 70 | atomic_t num_spurious; |
| 71 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 72 | #ifdef CONFIG_PM |
| 73 | unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */ |
Michael Hennerich | 4a88d0c | 2008-08-05 17:38:41 +0800 | [diff] [blame] | 74 | unsigned vr_wakeup; |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 75 | #endif |
| 76 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 77 | struct ivgx { |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 78 | /* irq number for request_irq, available in mach-bf5xx/irq.h */ |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 79 | unsigned int irqno; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 80 | /* corresponding bit in the SIC_ISR register */ |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 81 | unsigned int isrflag; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 82 | } ivg_table[NR_PERI_INTS]; |
| 83 | |
| 84 | struct ivg_slice { |
| 85 | /* position of first irq in ivg_table for given ivg */ |
| 86 | struct ivgx *ifirst; |
| 87 | struct ivgx *istop; |
| 88 | } ivg7_13[IVG13 - IVG7 + 1]; |
| 89 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Search SIC_IAR and fill tables with the irqvalues |
| 93 | * and their positions in the SIC_ISR register. |
| 94 | */ |
| 95 | static void __init search_IAR(void) |
| 96 | { |
| 97 | unsigned ivg, irq_pos = 0; |
| 98 | for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) { |
| 99 | int irqn; |
| 100 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 101 | ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 102 | |
| 103 | for (irqn = 0; irqn < NR_PERI_INTS; irqn++) { |
| 104 | int iar_shift = (irqn & 7) * 4; |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 105 | if (ivg == (0xf & |
Bryan Wu | 2f6f4bc | 2008-11-18 17:48:21 +0800 | [diff] [blame] | 106 | #if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \ |
| 107 | || defined(CONFIG_BF539) || defined(CONFIG_BF51x) |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 108 | bfin_read32((unsigned long *)SIC_IAR0 + |
Michael Hennerich | dc26aec | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 109 | ((irqn % 32) >> 3) + ((irqn / 32) * |
| 110 | ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) { |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 111 | #else |
| 112 | bfin_read32((unsigned long *)SIC_IAR0 + |
Michael Hennerich | dc26aec | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 113 | (irqn >> 3)) >> iar_shift)) { |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 114 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 115 | ivg_table[irq_pos].irqno = IVG7 + irqn; |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 116 | ivg_table[irq_pos].isrflag = 1 << (irqn % 32); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 117 | ivg7_13[ivg].istop++; |
| 118 | irq_pos++; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /* |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 125 | * This is for core internal IRQs |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 126 | */ |
| 127 | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 128 | static void bfin_ack_noop(unsigned int irq) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 129 | { |
| 130 | /* Dummy function. */ |
| 131 | } |
| 132 | |
| 133 | static void bfin_core_mask_irq(unsigned int irq) |
| 134 | { |
| 135 | irq_flags &= ~(1 << irq); |
| 136 | if (!irqs_disabled()) |
| 137 | local_irq_enable(); |
| 138 | } |
| 139 | |
| 140 | static void bfin_core_unmask_irq(unsigned int irq) |
| 141 | { |
| 142 | irq_flags |= 1 << irq; |
| 143 | /* |
| 144 | * If interrupts are enabled, IMASK must contain the same value |
| 145 | * as irq_flags. Make sure that invariant holds. If interrupts |
| 146 | * are currently disabled we need not do anything; one of the |
| 147 | * callers will take care of setting IMASK to the proper value |
| 148 | * when reenabling interrupts. |
| 149 | * local_irq_enable just does "STI irq_flags", so it's exactly |
| 150 | * what we need. |
| 151 | */ |
| 152 | if (!irqs_disabled()) |
| 153 | local_irq_enable(); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | static void bfin_internal_mask_irq(unsigned int irq) |
| 158 | { |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 159 | #ifdef CONFIG_BF53x |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 160 | bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() & |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 161 | ~(1 << SIC_SYSIRQ(irq))); |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 162 | #else |
| 163 | unsigned mask_bank, mask_bit; |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 164 | mask_bank = SIC_SYSIRQ(irq) / 32; |
| 165 | mask_bit = SIC_SYSIRQ(irq) % 32; |
Bryan Wu | c04d66b | 2007-07-12 17:26:31 +0800 | [diff] [blame] | 166 | bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) & |
| 167 | ~(1 << mask_bit)); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 168 | #ifdef CONFIG_SMP |
| 169 | bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) & |
| 170 | ~(1 << mask_bit)); |
| 171 | #endif |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 172 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static void bfin_internal_unmask_irq(unsigned int irq) |
| 176 | { |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 177 | #ifdef CONFIG_BF53x |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 178 | bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 179 | (1 << SIC_SYSIRQ(irq))); |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 180 | #else |
| 181 | unsigned mask_bank, mask_bit; |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 182 | mask_bank = SIC_SYSIRQ(irq) / 32; |
| 183 | mask_bit = SIC_SYSIRQ(irq) % 32; |
Bryan Wu | c04d66b | 2007-07-12 17:26:31 +0800 | [diff] [blame] | 184 | bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) | |
| 185 | (1 << mask_bit)); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 186 | #ifdef CONFIG_SMP |
| 187 | bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) | |
| 188 | (1 << mask_bit)); |
| 189 | #endif |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 190 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 193 | #ifdef CONFIG_PM |
| 194 | int bfin_internal_set_wake(unsigned int irq, unsigned int state) |
| 195 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 196 | u32 bank, bit, wakeup = 0; |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 197 | unsigned long flags; |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 198 | bank = SIC_SYSIRQ(irq) / 32; |
| 199 | bit = SIC_SYSIRQ(irq) % 32; |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 200 | |
Michael Hennerich | 4a88d0c | 2008-08-05 17:38:41 +0800 | [diff] [blame] | 201 | switch (irq) { |
| 202 | #ifdef IRQ_RTC |
| 203 | case IRQ_RTC: |
| 204 | wakeup |= WAKE; |
| 205 | break; |
| 206 | #endif |
| 207 | #ifdef IRQ_CAN0_RX |
| 208 | case IRQ_CAN0_RX: |
| 209 | wakeup |= CANWE; |
| 210 | break; |
| 211 | #endif |
| 212 | #ifdef IRQ_CAN1_RX |
| 213 | case IRQ_CAN1_RX: |
| 214 | wakeup |= CANWE; |
| 215 | break; |
| 216 | #endif |
| 217 | #ifdef IRQ_USB_INT0 |
| 218 | case IRQ_USB_INT0: |
| 219 | wakeup |= USBWE; |
| 220 | break; |
| 221 | #endif |
| 222 | #ifdef IRQ_KEY |
| 223 | case IRQ_KEY: |
| 224 | wakeup |= KPADWE; |
| 225 | break; |
| 226 | #endif |
Michael Hennerich | d310fb4 | 2008-08-28 17:32:01 +0800 | [diff] [blame] | 227 | #ifdef CONFIG_BF54x |
Michael Hennerich | 4a88d0c | 2008-08-05 17:38:41 +0800 | [diff] [blame] | 228 | case IRQ_CNT: |
| 229 | wakeup |= ROTWE; |
| 230 | break; |
| 231 | #endif |
| 232 | default: |
| 233 | break; |
| 234 | } |
| 235 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 236 | local_irq_save(flags); |
| 237 | |
Michael Hennerich | 4a88d0c | 2008-08-05 17:38:41 +0800 | [diff] [blame] | 238 | if (state) { |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 239 | bfin_sic_iwr[bank] |= (1 << bit); |
Michael Hennerich | 4a88d0c | 2008-08-05 17:38:41 +0800 | [diff] [blame] | 240 | vr_wakeup |= wakeup; |
| 241 | |
| 242 | } else { |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 243 | bfin_sic_iwr[bank] &= ~(1 << bit); |
Michael Hennerich | 4a88d0c | 2008-08-05 17:38:41 +0800 | [diff] [blame] | 244 | vr_wakeup &= ~wakeup; |
| 245 | } |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 246 | |
| 247 | local_irq_restore(flags); |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | #endif |
| 252 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 253 | static struct irq_chip bfin_core_irqchip = { |
Graf Yang | 763e63c | 2008-10-08 17:08:15 +0800 | [diff] [blame] | 254 | .name = "CORE", |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 255 | .ack = bfin_ack_noop, |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 256 | .mask = bfin_core_mask_irq, |
| 257 | .unmask = bfin_core_unmask_irq, |
| 258 | }; |
| 259 | |
| 260 | static struct irq_chip bfin_internal_irqchip = { |
Graf Yang | 763e63c | 2008-10-08 17:08:15 +0800 | [diff] [blame] | 261 | .name = "INTN", |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 262 | .ack = bfin_ack_noop, |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 263 | .mask = bfin_internal_mask_irq, |
| 264 | .unmask = bfin_internal_unmask_irq, |
Michael Hennerich | ce3b7bb | 2008-02-25 13:48:47 +0800 | [diff] [blame] | 265 | .mask_ack = bfin_internal_mask_irq, |
| 266 | .disable = bfin_internal_mask_irq, |
| 267 | .enable = bfin_internal_unmask_irq, |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 268 | #ifdef CONFIG_PM |
| 269 | .set_wake = bfin_internal_set_wake, |
| 270 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | #ifdef BF537_GENERIC_ERROR_INT_DEMUX |
| 274 | static int error_int_mask; |
| 275 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 276 | static void bfin_generic_error_mask_irq(unsigned int irq) |
| 277 | { |
| 278 | error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR)); |
| 279 | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 280 | if (!error_int_mask) |
| 281 | bfin_internal_mask_irq(IRQ_GENERIC_ERROR); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static void bfin_generic_error_unmask_irq(unsigned int irq) |
| 285 | { |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 286 | bfin_internal_unmask_irq(IRQ_GENERIC_ERROR); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 287 | error_int_mask |= 1L << (irq - IRQ_PPI_ERROR); |
| 288 | } |
| 289 | |
| 290 | static struct irq_chip bfin_generic_error_irqchip = { |
Graf Yang | 763e63c | 2008-10-08 17:08:15 +0800 | [diff] [blame] | 291 | .name = "ERROR", |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 292 | .ack = bfin_ack_noop, |
| 293 | .mask_ack = bfin_generic_error_mask_irq, |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 294 | .mask = bfin_generic_error_mask_irq, |
| 295 | .unmask = bfin_generic_error_unmask_irq, |
| 296 | }; |
| 297 | |
| 298 | static void bfin_demux_error_irq(unsigned int int_err_irq, |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 299 | struct irq_desc *inta_desc) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 300 | { |
| 301 | int irq = 0; |
| 302 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 303 | #if (defined(CONFIG_BF537) || defined(CONFIG_BF536)) |
| 304 | if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK) |
| 305 | irq = IRQ_MAC_ERROR; |
| 306 | else |
| 307 | #endif |
| 308 | if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK) |
| 309 | irq = IRQ_SPORT0_ERROR; |
| 310 | else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK) |
| 311 | irq = IRQ_SPORT1_ERROR; |
| 312 | else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK) |
| 313 | irq = IRQ_PPI_ERROR; |
| 314 | else if (bfin_read_CAN_GIF() & CAN_ERR_MASK) |
| 315 | irq = IRQ_CAN_ERROR; |
| 316 | else if (bfin_read_SPI_STAT() & SPI_ERR_MASK) |
| 317 | irq = IRQ_SPI_ERROR; |
| 318 | else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) && |
| 319 | (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0)) |
| 320 | irq = IRQ_UART0_ERROR; |
| 321 | else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) && |
| 322 | (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0)) |
| 323 | irq = IRQ_UART1_ERROR; |
| 324 | |
| 325 | if (irq) { |
| 326 | if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) { |
| 327 | struct irq_desc *desc = irq_desc + irq; |
| 328 | desc->handle_irq(irq, desc); |
| 329 | } else { |
| 330 | |
| 331 | switch (irq) { |
| 332 | case IRQ_PPI_ERROR: |
| 333 | bfin_write_PPI_STATUS(PPI_ERR_MASK); |
| 334 | break; |
| 335 | #if (defined(CONFIG_BF537) || defined(CONFIG_BF536)) |
| 336 | case IRQ_MAC_ERROR: |
| 337 | bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK); |
| 338 | break; |
| 339 | #endif |
| 340 | case IRQ_SPORT0_ERROR: |
| 341 | bfin_write_SPORT0_STAT(SPORT_ERR_MASK); |
| 342 | break; |
| 343 | |
| 344 | case IRQ_SPORT1_ERROR: |
| 345 | bfin_write_SPORT1_STAT(SPORT_ERR_MASK); |
| 346 | break; |
| 347 | |
| 348 | case IRQ_CAN_ERROR: |
| 349 | bfin_write_CAN_GIS(CAN_ERR_MASK); |
| 350 | break; |
| 351 | |
| 352 | case IRQ_SPI_ERROR: |
| 353 | bfin_write_SPI_STAT(SPI_ERR_MASK); |
| 354 | break; |
| 355 | |
| 356 | default: |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | pr_debug("IRQ %d:" |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 361 | " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n", |
| 362 | irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 363 | } |
| 364 | } else |
| 365 | printk(KERN_ERR |
| 366 | "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR" |
| 367 | " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n", |
Harvey Harrison | b85d858 | 2008-04-23 09:39:01 +0800 | [diff] [blame] | 368 | __func__, __FILE__, __LINE__); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 369 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 370 | } |
| 371 | #endif /* BF537_GENERIC_ERROR_INT_DEMUX */ |
| 372 | |
Graf Yang | bfd1511 | 2008-10-08 18:02:44 +0800 | [diff] [blame] | 373 | static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle) |
| 374 | { |
| 375 | struct irq_desc *desc = irq_desc + irq; |
| 376 | /* May not call generic set_irq_handler() due to spinlock |
| 377 | recursion. */ |
| 378 | desc->handle_irq = handle; |
| 379 | } |
| 380 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 381 | static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS); |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 382 | extern void bfin_gpio_irq_prepare(unsigned gpio); |
Michael Hennerich | 6fce6a8 | 2007-12-24 16:56:12 +0800 | [diff] [blame] | 383 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 384 | #if !defined(CONFIG_BF54x) |
| 385 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 386 | static void bfin_gpio_ack_irq(unsigned int irq) |
| 387 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 388 | /* AFAIK ack_irq in case mask_ack is provided |
| 389 | * get's only called for edge sense irqs |
| 390 | */ |
| 391 | set_gpio_data(irq_to_gpio(irq), 0); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static void bfin_gpio_mask_ack_irq(unsigned int irq) |
| 395 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 396 | struct irq_desc *desc = irq_desc + irq; |
| 397 | u32 gpionr = irq_to_gpio(irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 398 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 399 | if (desc->handle_irq == handle_edge_irq) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 400 | set_gpio_data(gpionr, 0); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 401 | |
| 402 | set_gpio_maska(gpionr, 0); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | static void bfin_gpio_mask_irq(unsigned int irq) |
| 406 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 407 | set_gpio_maska(irq_to_gpio(irq), 0); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static void bfin_gpio_unmask_irq(unsigned int irq) |
| 411 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 412 | set_gpio_maska(irq_to_gpio(irq), 1); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static unsigned int bfin_gpio_irq_startup(unsigned int irq) |
| 416 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 417 | u32 gpionr = irq_to_gpio(irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 418 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 419 | if (__test_and_set_bit(gpionr, gpio_enabled)) |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 420 | bfin_gpio_irq_prepare(gpionr); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 421 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 422 | bfin_gpio_unmask_irq(irq); |
| 423 | |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 424 | return 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | static void bfin_gpio_irq_shutdown(unsigned int irq) |
| 428 | { |
| 429 | bfin_gpio_mask_irq(irq); |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 430 | __clear_bit(irq_to_gpio(irq), gpio_enabled); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static int bfin_gpio_irq_type(unsigned int irq, unsigned int type) |
| 434 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 435 | u32 gpionr = irq_to_gpio(irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 436 | |
| 437 | if (type == IRQ_TYPE_PROBE) { |
| 438 | /* only probe unenabled GPIO interrupt lines */ |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 439 | if (__test_bit(gpionr, gpio_enabled)) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 440 | return 0; |
| 441 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; |
| 442 | } |
| 443 | |
| 444 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 445 | IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 446 | |
| 447 | if (__test_and_set_bit(gpionr, gpio_enabled)) |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 448 | bfin_gpio_irq_prepare(gpionr); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 449 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 450 | } else { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 451 | __clear_bit(gpionr, gpio_enabled); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 452 | return 0; |
| 453 | } |
| 454 | |
Michael Hennerich | f1bceb4 | 2008-02-02 16:17:52 +0800 | [diff] [blame] | 455 | set_gpio_inen(gpionr, 0); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 456 | set_gpio_dir(gpionr, 0); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 457 | |
| 458 | if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) |
| 459 | == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) |
| 460 | set_gpio_both(gpionr, 1); |
| 461 | else |
| 462 | set_gpio_both(gpionr, 0); |
| 463 | |
| 464 | if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW))) |
| 465 | set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */ |
| 466 | else |
| 467 | set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */ |
| 468 | |
Michael Hennerich | f1bceb4 | 2008-02-02 16:17:52 +0800 | [diff] [blame] | 469 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) { |
| 470 | set_gpio_edge(gpionr, 1); |
| 471 | set_gpio_inen(gpionr, 1); |
Michael Hennerich | f1bceb4 | 2008-02-02 16:17:52 +0800 | [diff] [blame] | 472 | set_gpio_data(gpionr, 0); |
| 473 | |
| 474 | } else { |
| 475 | set_gpio_edge(gpionr, 0); |
Michael Hennerich | f1bceb4 | 2008-02-02 16:17:52 +0800 | [diff] [blame] | 476 | set_gpio_inen(gpionr, 1); |
| 477 | } |
| 478 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 479 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) |
Graf Yang | bfd1511 | 2008-10-08 18:02:44 +0800 | [diff] [blame] | 480 | bfin_set_irq_handler(irq, handle_edge_irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 481 | else |
Graf Yang | bfd1511 | 2008-10-08 18:02:44 +0800 | [diff] [blame] | 482 | bfin_set_irq_handler(irq, handle_level_irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 487 | #ifdef CONFIG_PM |
| 488 | int bfin_gpio_set_wake(unsigned int irq, unsigned int state) |
| 489 | { |
| 490 | unsigned gpio = irq_to_gpio(irq); |
| 491 | |
| 492 | if (state) |
| 493 | gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE); |
| 494 | else |
| 495 | gpio_pm_wakeup_free(gpio); |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | #endif |
| 500 | |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 501 | static void bfin_demux_gpio_irq(unsigned int inta_irq, |
| 502 | struct irq_desc *desc) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 503 | { |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 504 | unsigned int i, gpio, mask, irq, search = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 505 | |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 506 | switch (inta_irq) { |
| 507 | #if defined(CONFIG_BF53x) |
| 508 | case IRQ_PROG_INTA: |
| 509 | irq = IRQ_PF0; |
| 510 | search = 1; |
| 511 | break; |
| 512 | # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)) |
| 513 | case IRQ_MAC_RX: |
| 514 | irq = IRQ_PH0; |
| 515 | break; |
| 516 | # endif |
Michael Hennerich | dc26aec | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 517 | #elif defined(CONFIG_BF538) || defined(CONFIG_BF539) |
| 518 | case IRQ_PORTF_INTA: |
| 519 | irq = IRQ_PF0; |
| 520 | break; |
Bryan Wu | 2f6f4bc | 2008-11-18 17:48:21 +0800 | [diff] [blame] | 521 | #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x) |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 522 | case IRQ_PORTF_INTA: |
| 523 | irq = IRQ_PF0; |
| 524 | break; |
| 525 | case IRQ_PORTG_INTA: |
| 526 | irq = IRQ_PG0; |
| 527 | break; |
| 528 | case IRQ_PORTH_INTA: |
| 529 | irq = IRQ_PH0; |
| 530 | break; |
| 531 | #elif defined(CONFIG_BF561) |
| 532 | case IRQ_PROG0_INTA: |
| 533 | irq = IRQ_PF0; |
| 534 | break; |
| 535 | case IRQ_PROG1_INTA: |
| 536 | irq = IRQ_PF16; |
| 537 | break; |
| 538 | case IRQ_PROG2_INTA: |
| 539 | irq = IRQ_PF32; |
| 540 | break; |
| 541 | #endif |
| 542 | default: |
| 543 | BUG(); |
| 544 | return; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 545 | } |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 546 | |
| 547 | if (search) { |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 548 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 549 | irq += i; |
| 550 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 551 | mask = get_gpiop_data(i) & get_gpiop_maska(i); |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 552 | |
| 553 | while (mask) { |
| 554 | if (mask & 1) { |
| 555 | desc = irq_desc + irq; |
| 556 | desc->handle_irq(irq, desc); |
| 557 | } |
| 558 | irq++; |
| 559 | mask >>= 1; |
| 560 | } |
| 561 | } |
| 562 | } else { |
| 563 | gpio = irq_to_gpio(irq); |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 564 | mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio); |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 565 | |
| 566 | do { |
| 567 | if (mask & 1) { |
| 568 | desc = irq_desc + irq; |
| 569 | desc->handle_irq(irq, desc); |
| 570 | } |
| 571 | irq++; |
| 572 | mask >>= 1; |
| 573 | } while (mask); |
| 574 | } |
| 575 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 578 | #else /* CONFIG_BF54x */ |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 579 | |
| 580 | #define NR_PINT_SYS_IRQS 4 |
| 581 | #define NR_PINT_BITS 32 |
| 582 | #define NR_PINTS 160 |
| 583 | #define IRQ_NOT_AVAIL 0xFF |
| 584 | |
| 585 | #define PINT_2_BANK(x) ((x) >> 5) |
| 586 | #define PINT_2_BIT(x) ((x) & 0x1F) |
| 587 | #define PINT_BIT(x) (1 << (PINT_2_BIT(x))) |
| 588 | |
| 589 | static unsigned char irq2pint_lut[NR_PINTS]; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 590 | static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS]; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 591 | |
| 592 | struct pin_int_t { |
| 593 | unsigned int mask_set; |
| 594 | unsigned int mask_clear; |
| 595 | unsigned int request; |
| 596 | unsigned int assign; |
| 597 | unsigned int edge_set; |
| 598 | unsigned int edge_clear; |
| 599 | unsigned int invert_set; |
| 600 | unsigned int invert_clear; |
| 601 | unsigned int pinstate; |
| 602 | unsigned int latch; |
| 603 | }; |
| 604 | |
| 605 | static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = { |
| 606 | (struct pin_int_t *)PINT0_MASK_SET, |
| 607 | (struct pin_int_t *)PINT1_MASK_SET, |
| 608 | (struct pin_int_t *)PINT2_MASK_SET, |
| 609 | (struct pin_int_t *)PINT3_MASK_SET, |
| 610 | }; |
| 611 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 612 | inline unsigned int get_irq_base(u32 bank, u8 bmap) |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 613 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 614 | unsigned int irq_base; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 615 | |
| 616 | if (bank < 2) { /*PA-PB */ |
| 617 | irq_base = IRQ_PA0 + bmap * 16; |
| 618 | } else { /*PC-PJ */ |
| 619 | irq_base = IRQ_PC0 + bmap * 16; |
| 620 | } |
| 621 | |
| 622 | return irq_base; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */ |
| 626 | void init_pint_lut(void) |
| 627 | { |
| 628 | u16 bank, bit, irq_base, bit_pos; |
| 629 | u32 pint_assign; |
| 630 | u8 bmap; |
| 631 | |
| 632 | memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut)); |
| 633 | |
| 634 | for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) { |
| 635 | |
| 636 | pint_assign = pint[bank]->assign; |
| 637 | |
| 638 | for (bit = 0; bit < NR_PINT_BITS; bit++) { |
| 639 | |
| 640 | bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF; |
| 641 | |
| 642 | irq_base = get_irq_base(bank, bmap); |
| 643 | |
| 644 | irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0); |
| 645 | bit_pos = bit + bank * NR_PINT_BITS; |
| 646 | |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 647 | pint2irq_lut[bit_pos] = irq_base - SYS_IRQS; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 648 | irq2pint_lut[irq_base - SYS_IRQS] = bit_pos; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 649 | } |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 650 | } |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 651 | } |
| 652 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 653 | static void bfin_gpio_ack_irq(unsigned int irq) |
| 654 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 655 | struct irq_desc *desc = irq_desc + irq; |
| 656 | u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 657 | u32 pintbit = PINT_BIT(pint_val); |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 658 | u32 bank = PINT_2_BANK(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 659 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 660 | if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) { |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 661 | if (pint[bank]->invert_set & pintbit) |
| 662 | pint[bank]->invert_clear = pintbit; |
| 663 | else |
| 664 | pint[bank]->invert_set = pintbit; |
| 665 | } |
| 666 | pint[bank]->request = pintbit; |
| 667 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static void bfin_gpio_mask_ack_irq(unsigned int irq) |
| 671 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 672 | struct irq_desc *desc = irq_desc + irq; |
| 673 | u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 674 | u32 pintbit = PINT_BIT(pint_val); |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 675 | u32 bank = PINT_2_BANK(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 676 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 677 | if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) { |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 678 | if (pint[bank]->invert_set & pintbit) |
| 679 | pint[bank]->invert_clear = pintbit; |
| 680 | else |
| 681 | pint[bank]->invert_set = pintbit; |
| 682 | } |
| 683 | |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 684 | pint[bank]->request = pintbit; |
| 685 | pint[bank]->mask_clear = pintbit; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | static void bfin_gpio_mask_irq(unsigned int irq) |
| 689 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 690 | u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 691 | |
| 692 | pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void bfin_gpio_unmask_irq(unsigned int irq) |
| 696 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 697 | u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 698 | u32 pintbit = PINT_BIT(pint_val); |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 699 | u32 bank = PINT_2_BANK(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 700 | |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 701 | pint[bank]->request = pintbit; |
| 702 | pint[bank]->mask_set = pintbit; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | static unsigned int bfin_gpio_irq_startup(unsigned int irq) |
| 706 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 707 | u32 gpionr = irq_to_gpio(irq); |
| 708 | u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 709 | |
Michael Hennerich | 50e163c | 2007-07-24 16:17:28 +0800 | [diff] [blame] | 710 | if (pint_val == IRQ_NOT_AVAIL) { |
| 711 | printk(KERN_ERR |
| 712 | "GPIO IRQ %d :Not in PINT Assign table " |
| 713 | "Reconfigure Interrupt to Port Assignemt\n", irq); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 714 | return -ENODEV; |
Michael Hennerich | 50e163c | 2007-07-24 16:17:28 +0800 | [diff] [blame] | 715 | } |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 716 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 717 | if (__test_and_set_bit(gpionr, gpio_enabled)) |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 718 | bfin_gpio_irq_prepare(gpionr); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 719 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 720 | bfin_gpio_unmask_irq(irq); |
| 721 | |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 722 | return 0; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | static void bfin_gpio_irq_shutdown(unsigned int irq) |
| 726 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 727 | u32 gpionr = irq_to_gpio(irq); |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 728 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 729 | bfin_gpio_mask_irq(irq); |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 730 | __clear_bit(gpionr, gpio_enabled); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | static int bfin_gpio_irq_type(unsigned int irq, unsigned int type) |
| 734 | { |
| 735 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 736 | u32 gpionr = irq_to_gpio(irq); |
| 737 | u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 738 | u32 pintbit = PINT_BIT(pint_val); |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 739 | u32 bank = PINT_2_BANK(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 740 | |
| 741 | if (pint_val == IRQ_NOT_AVAIL) |
| 742 | return -ENODEV; |
| 743 | |
| 744 | if (type == IRQ_TYPE_PROBE) { |
| 745 | /* only probe unenabled GPIO interrupt lines */ |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 746 | if (__test_bit(gpionr, gpio_enabled)) |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 747 | return 0; |
| 748 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; |
| 749 | } |
| 750 | |
| 751 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | |
| 752 | IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 753 | if (__test_and_set_bit(gpionr, gpio_enabled)) |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 754 | bfin_gpio_irq_prepare(gpionr); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 755 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 756 | } else { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 757 | __clear_bit(gpionr, gpio_enabled); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 761 | if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW))) |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 762 | pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */ |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 763 | else |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 764 | pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */ |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 765 | |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 766 | if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) |
| 767 | == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) { |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 768 | if (gpio_get_value(gpionr)) |
| 769 | pint[bank]->invert_set = pintbit; |
| 770 | else |
| 771 | pint[bank]->invert_clear = pintbit; |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) { |
| 775 | pint[bank]->edge_set = pintbit; |
Graf Yang | bfd1511 | 2008-10-08 18:02:44 +0800 | [diff] [blame] | 776 | bfin_set_irq_handler(irq, handle_edge_irq); |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 777 | } else { |
| 778 | pint[bank]->edge_clear = pintbit; |
Graf Yang | bfd1511 | 2008-10-08 18:02:44 +0800 | [diff] [blame] | 779 | bfin_set_irq_handler(irq, handle_level_irq); |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 780 | } |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 781 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 782 | return 0; |
| 783 | } |
| 784 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 785 | #ifdef CONFIG_PM |
| 786 | u32 pint_saved_masks[NR_PINT_SYS_IRQS]; |
| 787 | u32 pint_wakeup_masks[NR_PINT_SYS_IRQS]; |
| 788 | |
| 789 | int bfin_gpio_set_wake(unsigned int irq, unsigned int state) |
| 790 | { |
| 791 | u32 pint_irq; |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 792 | u32 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 793 | u32 bank = PINT_2_BANK(pint_val); |
| 794 | u32 pintbit = PINT_BIT(pint_val); |
| 795 | |
| 796 | switch (bank) { |
| 797 | case 0: |
| 798 | pint_irq = IRQ_PINT0; |
| 799 | break; |
| 800 | case 2: |
| 801 | pint_irq = IRQ_PINT2; |
| 802 | break; |
| 803 | case 3: |
| 804 | pint_irq = IRQ_PINT3; |
| 805 | break; |
| 806 | case 1: |
| 807 | pint_irq = IRQ_PINT1; |
| 808 | break; |
| 809 | default: |
| 810 | return -EINVAL; |
| 811 | } |
| 812 | |
| 813 | bfin_internal_set_wake(pint_irq, state); |
| 814 | |
| 815 | if (state) |
| 816 | pint_wakeup_masks[bank] |= pintbit; |
| 817 | else |
| 818 | pint_wakeup_masks[bank] &= ~pintbit; |
| 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | u32 bfin_pm_setup(void) |
| 824 | { |
| 825 | u32 val, i; |
| 826 | |
| 827 | for (i = 0; i < NR_PINT_SYS_IRQS; i++) { |
| 828 | val = pint[i]->mask_clear; |
| 829 | pint_saved_masks[i] = val; |
| 830 | if (val ^ pint_wakeup_masks[i]) { |
| 831 | pint[i]->mask_clear = val; |
| 832 | pint[i]->mask_set = pint_wakeup_masks[i]; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
| 839 | void bfin_pm_restore(void) |
| 840 | { |
| 841 | u32 i, val; |
| 842 | |
| 843 | for (i = 0; i < NR_PINT_SYS_IRQS; i++) { |
| 844 | val = pint_saved_masks[i]; |
| 845 | if (val ^ pint_wakeup_masks[i]) { |
| 846 | pint[i]->mask_clear = pint[i]->mask_clear; |
| 847 | pint[i]->mask_set = val; |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | #endif |
| 852 | |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 853 | static void bfin_demux_gpio_irq(unsigned int inta_irq, |
| 854 | struct irq_desc *desc) |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 855 | { |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 856 | u32 bank, pint_val; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 857 | u32 request, irq; |
| 858 | |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 859 | switch (inta_irq) { |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 860 | case IRQ_PINT0: |
| 861 | bank = 0; |
| 862 | break; |
| 863 | case IRQ_PINT2: |
| 864 | bank = 2; |
| 865 | break; |
| 866 | case IRQ_PINT3: |
| 867 | bank = 3; |
| 868 | break; |
| 869 | case IRQ_PINT1: |
| 870 | bank = 1; |
| 871 | break; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 872 | default: |
| 873 | return; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | pint_val = bank * NR_PINT_BITS; |
| 877 | |
| 878 | request = pint[bank]->request; |
| 879 | |
| 880 | while (request) { |
| 881 | if (request & 1) { |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 882 | irq = pint2irq_lut[pint_val] + SYS_IRQS; |
| 883 | desc = irq_desc + irq; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 884 | desc->handle_irq(irq, desc); |
| 885 | } |
| 886 | pint_val++; |
| 887 | request >>= 1; |
| 888 | } |
| 889 | |
| 890 | } |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 891 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 892 | |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 893 | static struct irq_chip bfin_gpio_irqchip = { |
| 894 | .name = "GPIO", |
| 895 | .ack = bfin_gpio_ack_irq, |
| 896 | .mask = bfin_gpio_mask_irq, |
| 897 | .mask_ack = bfin_gpio_mask_ack_irq, |
| 898 | .unmask = bfin_gpio_unmask_irq, |
| 899 | .disable = bfin_gpio_mask_irq, |
| 900 | .enable = bfin_gpio_unmask_irq, |
| 901 | .set_type = bfin_gpio_irq_type, |
| 902 | .startup = bfin_gpio_irq_startup, |
| 903 | .shutdown = bfin_gpio_irq_shutdown, |
| 904 | #ifdef CONFIG_PM |
| 905 | .set_wake = bfin_gpio_set_wake, |
| 906 | #endif |
| 907 | }; |
| 908 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 909 | void __cpuinit init_exception_vectors(void) |
Bernd Schmidt | 8be80ed | 2007-07-25 14:44:49 +0800 | [diff] [blame] | 910 | { |
Mike Frysinger | f0b5d12 | 2007-08-05 17:03:59 +0800 | [diff] [blame] | 911 | /* cannot program in software: |
| 912 | * evt0 - emulation (jtag) |
| 913 | * evt1 - reset |
| 914 | */ |
| 915 | bfin_write_EVT2(evt_nmi); |
Bernd Schmidt | 8be80ed | 2007-07-25 14:44:49 +0800 | [diff] [blame] | 916 | bfin_write_EVT3(trap); |
| 917 | bfin_write_EVT5(evt_ivhw); |
| 918 | bfin_write_EVT6(evt_timer); |
| 919 | bfin_write_EVT7(evt_evt7); |
| 920 | bfin_write_EVT8(evt_evt8); |
| 921 | bfin_write_EVT9(evt_evt9); |
| 922 | bfin_write_EVT10(evt_evt10); |
| 923 | bfin_write_EVT11(evt_evt11); |
| 924 | bfin_write_EVT12(evt_evt12); |
| 925 | bfin_write_EVT13(evt_evt13); |
| 926 | bfin_write_EVT14(evt14_softirq); |
| 927 | bfin_write_EVT15(evt_system_call); |
| 928 | CSYNC(); |
| 929 | } |
| 930 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 931 | /* |
| 932 | * This function should be called during kernel startup to initialize |
| 933 | * the BFin IRQ handling routines. |
| 934 | */ |
Michael Hennerich | 8d02237 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 935 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 936 | int __init init_arch_irq(void) |
| 937 | { |
| 938 | int irq; |
| 939 | unsigned long ilat = 0; |
| 940 | /* Disable all the peripheral intrs - page 4-29 HW Ref manual */ |
Bryan Wu | 2f6f4bc | 2008-11-18 17:48:21 +0800 | [diff] [blame] | 941 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \ |
| 942 | || defined(BF538_FAMILY) || defined(CONFIG_BF51x) |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 943 | bfin_write_SIC_IMASK0(SIC_UNMASK_ALL); |
| 944 | bfin_write_SIC_IMASK1(SIC_UNMASK_ALL); |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 945 | # ifdef CONFIG_BF54x |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 946 | bfin_write_SIC_IMASK2(SIC_UNMASK_ALL); |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 947 | # endif |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 948 | # ifdef CONFIG_SMP |
| 949 | bfin_write_SICB_IMASK0(SIC_UNMASK_ALL); |
| 950 | bfin_write_SICB_IMASK1(SIC_UNMASK_ALL); |
| 951 | # endif |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 952 | #else |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 953 | bfin_write_SIC_IMASK(SIC_UNMASK_ALL); |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 954 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 955 | |
| 956 | local_irq_disable(); |
| 957 | |
Mike Frysinger | d70536e | 2008-08-25 17:37:35 +0800 | [diff] [blame] | 958 | #if (defined(CONFIG_BF537) || defined(CONFIG_BF536)) |
Mike Frysinger | 95a86b5 | 2008-08-14 15:05:01 +0800 | [diff] [blame] | 959 | /* Clear EMAC Interrupt Status bits so we can demux it later */ |
| 960 | bfin_write_EMAC_SYSTAT(-1); |
| 961 | #endif |
| 962 | |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 963 | #ifdef CONFIG_BF54x |
| 964 | # ifdef CONFIG_PINTx_REASSIGN |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 965 | pint[0]->assign = CONFIG_PINT0_ASSIGN; |
| 966 | pint[1]->assign = CONFIG_PINT1_ASSIGN; |
| 967 | pint[2]->assign = CONFIG_PINT2_ASSIGN; |
| 968 | pint[3]->assign = CONFIG_PINT3_ASSIGN; |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 969 | # endif |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 970 | /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */ |
| 971 | init_pint_lut(); |
| 972 | #endif |
| 973 | |
| 974 | for (irq = 0; irq <= SYS_IRQS; irq++) { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 975 | if (irq <= IRQ_CORETMR) |
| 976 | set_irq_chip(irq, &bfin_core_irqchip); |
| 977 | else |
| 978 | set_irq_chip(irq, &bfin_internal_irqchip); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 979 | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 980 | switch (irq) { |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 981 | #if defined(CONFIG_BF53x) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 982 | case IRQ_PROG_INTA: |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 983 | # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 984 | case IRQ_MAC_RX: |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 985 | # endif |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 986 | #elif defined(CONFIG_BF54x) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 987 | case IRQ_PINT0: |
| 988 | case IRQ_PINT1: |
| 989 | case IRQ_PINT2: |
| 990 | case IRQ_PINT3: |
Bryan Wu | 2f6f4bc | 2008-11-18 17:48:21 +0800 | [diff] [blame] | 991 | #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 992 | case IRQ_PORTF_INTA: |
| 993 | case IRQ_PORTG_INTA: |
| 994 | case IRQ_PORTH_INTA: |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 995 | #elif defined(CONFIG_BF561) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 996 | case IRQ_PROG0_INTA: |
| 997 | case IRQ_PROG1_INTA: |
| 998 | case IRQ_PROG2_INTA: |
Michael Hennerich | dc26aec | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 999 | #elif defined(CONFIG_BF538) || defined(CONFIG_BF539) |
| 1000 | case IRQ_PORTF_INTA: |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1001 | #endif |
Michael Hennerich | dc26aec | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 1002 | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1003 | set_irq_chained_handler(irq, |
| 1004 | bfin_demux_gpio_irq); |
| 1005 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1006 | #ifdef BF537_GENERIC_ERROR_INT_DEMUX |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1007 | case IRQ_GENERIC_ERROR: |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1008 | set_irq_handler(irq, bfin_demux_error_irq); |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1009 | |
| 1010 | break; |
| 1011 | #endif |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1012 | #ifdef CONFIG_TICK_SOURCE_SYSTMR0 |
| 1013 | case IRQ_TIMER0: |
| 1014 | set_irq_handler(irq, handle_percpu_irq); |
| 1015 | break; |
| 1016 | #endif |
| 1017 | #ifdef CONFIG_SMP |
| 1018 | case IRQ_SUPPLE_0: |
| 1019 | case IRQ_SUPPLE_1: |
| 1020 | set_irq_handler(irq, handle_percpu_irq); |
| 1021 | break; |
| 1022 | #endif |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1023 | default: |
| 1024 | set_irq_handler(irq, handle_simple_irq); |
| 1025 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1026 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1027 | } |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1028 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1029 | #ifdef BF537_GENERIC_ERROR_INT_DEMUX |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1030 | for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++) |
| 1031 | set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip, |
| 1032 | handle_level_irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1033 | #endif |
| 1034 | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1035 | /* if configured as edge, then will be changed to do_edge_IRQ */ |
| 1036 | for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++) |
| 1037 | set_irq_chip_and_handler(irq, &bfin_gpio_irqchip, |
| 1038 | handle_level_irq); |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 1039 | |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 1040 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1041 | bfin_write_IMASK(0); |
| 1042 | CSYNC(); |
| 1043 | ilat = bfin_read_ILAT(); |
| 1044 | CSYNC(); |
| 1045 | bfin_write_ILAT(ilat); |
| 1046 | CSYNC(); |
| 1047 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 1048 | printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1049 | /* IMASK=xxx is equivalent to STI xx or irq_flags=xx, |
| 1050 | * local_irq_enable() |
| 1051 | */ |
| 1052 | program_IAR(); |
| 1053 | /* Therefore it's better to setup IARs before interrupts enabled */ |
| 1054 | search_IAR(); |
| 1055 | |
| 1056 | /* Enable interrupts IVG7-15 */ |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1057 | irq_flags |= IMASK_IVG15 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1058 | IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 1059 | IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1060 | |
Bryan Wu | 2f6f4bc | 2008-11-18 17:48:21 +0800 | [diff] [blame] | 1061 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \ |
| 1062 | || defined(BF538_FAMILY) || defined(CONFIG_BF51x) |
Michael Hennerich | 56f5f59 | 2008-08-06 17:55:32 +0800 | [diff] [blame] | 1063 | bfin_write_SIC_IWR0(IWR_DISABLE_ALL); |
Bryan Wu | 2f6f4bc | 2008-11-18 17:48:21 +0800 | [diff] [blame] | 1064 | #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x) |
| 1065 | /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which |
Michael Hennerich | 55546ac | 2008-08-13 17:41:13 +0800 | [diff] [blame] | 1066 | * will screw up the bootrom as it relies on MDMA0/1 waking it |
| 1067 | * up from IDLE instructions. See this report for more info: |
| 1068 | * http://blackfin.uclinux.org/gf/tracker/4323 |
| 1069 | */ |
| 1070 | bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11)); |
| 1071 | #else |
Michael Hennerich | 56f5f59 | 2008-08-06 17:55:32 +0800 | [diff] [blame] | 1072 | bfin_write_SIC_IWR1(IWR_DISABLE_ALL); |
Michael Hennerich | 55546ac | 2008-08-13 17:41:13 +0800 | [diff] [blame] | 1073 | #endif |
Michael Hennerich | fe9ec9b | 2008-02-25 12:04:57 +0800 | [diff] [blame] | 1074 | # ifdef CONFIG_BF54x |
Michael Hennerich | 56f5f59 | 2008-08-06 17:55:32 +0800 | [diff] [blame] | 1075 | bfin_write_SIC_IWR2(IWR_DISABLE_ALL); |
Michael Hennerich | fe9ec9b | 2008-02-25 12:04:57 +0800 | [diff] [blame] | 1076 | # endif |
| 1077 | #else |
Michael Hennerich | 56f5f59 | 2008-08-06 17:55:32 +0800 | [diff] [blame] | 1078 | bfin_write_SIC_IWR(IWR_DISABLE_ALL); |
Michael Hennerich | fe9ec9b | 2008-02-25 12:04:57 +0800 | [diff] [blame] | 1079 | #endif |
| 1080 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1081 | return 0; |
| 1082 | } |
| 1083 | |
| 1084 | #ifdef CONFIG_DO_IRQ_L1 |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 1085 | __attribute__((l1_text)) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1086 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1087 | void do_irq(int vec, struct pt_regs *fp) |
| 1088 | { |
| 1089 | if (vec == EVT_IVTMR_P) { |
| 1090 | vec = IRQ_CORETMR; |
| 1091 | } else { |
| 1092 | struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst; |
| 1093 | struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop; |
Bryan Wu | 2f6f4bc | 2008-11-18 17:48:21 +0800 | [diff] [blame] | 1094 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \ |
| 1095 | || defined(BF538_FAMILY) || defined(CONFIG_BF51x) |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 1096 | unsigned long sic_status[3]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1097 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 1098 | if (smp_processor_id()) { |
| 1099 | #ifdef CONFIG_SMP |
| 1100 | /* This will be optimized out in UP mode. */ |
| 1101 | sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0(); |
| 1102 | sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1(); |
| 1103 | #endif |
| 1104 | } else { |
| 1105 | sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0(); |
| 1106 | sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1(); |
| 1107 | } |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1108 | #ifdef CONFIG_BF54x |
Michael Hennerich | 4fb4524 | 2007-10-21 16:53:53 +0800 | [diff] [blame] | 1109 | sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2(); |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1110 | #endif |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 1111 | for (;; ivg++) { |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 1112 | if (ivg >= ivg_stop) { |
| 1113 | atomic_inc(&num_spurious); |
| 1114 | return; |
| 1115 | } |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 1116 | if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag) |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 1117 | break; |
| 1118 | } |
| 1119 | #else |
| 1120 | unsigned long sic_status; |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1121 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1122 | sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR(); |
| 1123 | |
| 1124 | for (;; ivg++) { |
| 1125 | if (ivg >= ivg_stop) { |
| 1126 | atomic_inc(&num_spurious); |
| 1127 | return; |
| 1128 | } else if (sic_status & ivg->isrflag) |
| 1129 | break; |
| 1130 | } |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 1131 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1132 | vec = ivg->irqno; |
| 1133 | } |
| 1134 | asm_do_IRQ(vec, fp); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1135 | } |