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