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