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