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