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 | |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 367 | #if !defined(CONFIG_BF54x) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 368 | |
| 369 | static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)]; |
| 370 | static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)]; |
| 371 | |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 372 | extern void bfin_gpio_irq_prepare(unsigned gpio); |
Michael Hennerich | 6fce6a8 | 2007-12-24 16:56:12 +0800 | [diff] [blame] | 373 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 374 | static void bfin_gpio_ack_irq(unsigned int irq) |
| 375 | { |
| 376 | u16 gpionr = irq - IRQ_PF0; |
| 377 | |
| 378 | if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) { |
| 379 | set_gpio_data(gpionr, 0); |
| 380 | SSYNC(); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | static void bfin_gpio_mask_ack_irq(unsigned int irq) |
| 385 | { |
| 386 | u16 gpionr = irq - IRQ_PF0; |
| 387 | |
| 388 | if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) { |
| 389 | set_gpio_data(gpionr, 0); |
| 390 | SSYNC(); |
| 391 | } |
| 392 | |
| 393 | set_gpio_maska(gpionr, 0); |
| 394 | SSYNC(); |
| 395 | } |
| 396 | |
| 397 | static void bfin_gpio_mask_irq(unsigned int irq) |
| 398 | { |
| 399 | set_gpio_maska(irq - IRQ_PF0, 0); |
| 400 | SSYNC(); |
| 401 | } |
| 402 | |
| 403 | static void bfin_gpio_unmask_irq(unsigned int irq) |
| 404 | { |
| 405 | set_gpio_maska(irq - IRQ_PF0, 1); |
| 406 | SSYNC(); |
| 407 | } |
| 408 | |
| 409 | static unsigned int bfin_gpio_irq_startup(unsigned int irq) |
| 410 | { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 411 | u16 gpionr = irq - IRQ_PF0; |
| 412 | |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 413 | if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) |
| 414 | bfin_gpio_irq_prepare(gpionr); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 415 | |
| 416 | gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr); |
| 417 | bfin_gpio_unmask_irq(irq); |
| 418 | |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 419 | return 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static void bfin_gpio_irq_shutdown(unsigned int irq) |
| 423 | { |
| 424 | bfin_gpio_mask_irq(irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 425 | gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0); |
| 426 | } |
| 427 | |
| 428 | static int bfin_gpio_irq_type(unsigned int irq, unsigned int type) |
| 429 | { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 430 | u16 gpionr = irq - IRQ_PF0; |
| 431 | |
| 432 | if (type == IRQ_TYPE_PROBE) { |
| 433 | /* only probe unenabled GPIO interrupt lines */ |
| 434 | if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)) |
| 435 | return 0; |
| 436 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; |
| 437 | } |
| 438 | |
| 439 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 440 | IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 441 | if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) |
| 442 | bfin_gpio_irq_prepare(gpionr); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 443 | |
| 444 | gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr); |
| 445 | } else { |
| 446 | gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr); |
| 447 | return 0; |
| 448 | } |
| 449 | |
Michael Hennerich | f1bceb4 | 2008-02-02 16:17:52 +0800 | [diff] [blame] | 450 | set_gpio_inen(gpionr, 0); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 451 | set_gpio_dir(gpionr, 0); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 452 | |
| 453 | if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) |
| 454 | == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) |
| 455 | set_gpio_both(gpionr, 1); |
| 456 | else |
| 457 | set_gpio_both(gpionr, 0); |
| 458 | |
| 459 | if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW))) |
| 460 | set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */ |
| 461 | else |
| 462 | set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */ |
| 463 | |
Michael Hennerich | f1bceb4 | 2008-02-02 16:17:52 +0800 | [diff] [blame] | 464 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) { |
| 465 | set_gpio_edge(gpionr, 1); |
| 466 | set_gpio_inen(gpionr, 1); |
| 467 | gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr); |
| 468 | set_gpio_data(gpionr, 0); |
| 469 | |
| 470 | } else { |
| 471 | set_gpio_edge(gpionr, 0); |
| 472 | gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr); |
| 473 | set_gpio_inen(gpionr, 1); |
| 474 | } |
| 475 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 476 | SSYNC(); |
| 477 | |
| 478 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) |
| 479 | set_irq_handler(irq, handle_edge_irq); |
| 480 | else |
| 481 | set_irq_handler(irq, handle_level_irq); |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 486 | #ifdef CONFIG_PM |
| 487 | int bfin_gpio_set_wake(unsigned int irq, unsigned int state) |
| 488 | { |
| 489 | unsigned gpio = irq_to_gpio(irq); |
| 490 | |
| 491 | if (state) |
| 492 | gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE); |
| 493 | else |
| 494 | gpio_pm_wakeup_free(gpio); |
| 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | #endif |
| 499 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 500 | static struct irq_chip bfin_gpio_irqchip = { |
Graf Yang | 763e63c | 2008-10-08 17:08:15 +0800 | [diff] [blame^] | 501 | .name = "GPIO", |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 502 | .ack = bfin_gpio_ack_irq, |
| 503 | .mask = bfin_gpio_mask_irq, |
| 504 | .mask_ack = bfin_gpio_mask_ack_irq, |
| 505 | .unmask = bfin_gpio_unmask_irq, |
Michael Hennerich | 1f2d186 | 2008-07-14 16:31:22 +0800 | [diff] [blame] | 506 | .disable = bfin_gpio_mask_irq, |
| 507 | .enable = bfin_gpio_unmask_irq, |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 508 | .set_type = bfin_gpio_irq_type, |
| 509 | .startup = bfin_gpio_irq_startup, |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 510 | .shutdown = bfin_gpio_irq_shutdown, |
| 511 | #ifdef CONFIG_PM |
| 512 | .set_wake = bfin_gpio_set_wake, |
| 513 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 514 | }; |
| 515 | |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 516 | static void bfin_demux_gpio_irq(unsigned int inta_irq, |
| 517 | struct irq_desc *desc) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 518 | { |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 519 | unsigned int i, gpio, mask, irq, search = 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 520 | |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 521 | switch (inta_irq) { |
| 522 | #if defined(CONFIG_BF53x) |
| 523 | case IRQ_PROG_INTA: |
| 524 | irq = IRQ_PF0; |
| 525 | search = 1; |
| 526 | break; |
| 527 | # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)) |
| 528 | case IRQ_MAC_RX: |
| 529 | irq = IRQ_PH0; |
| 530 | break; |
| 531 | # endif |
| 532 | #elif defined(CONFIG_BF52x) |
| 533 | case IRQ_PORTF_INTA: |
| 534 | irq = IRQ_PF0; |
| 535 | break; |
| 536 | case IRQ_PORTG_INTA: |
| 537 | irq = IRQ_PG0; |
| 538 | break; |
| 539 | case IRQ_PORTH_INTA: |
| 540 | irq = IRQ_PH0; |
| 541 | break; |
| 542 | #elif defined(CONFIG_BF561) |
| 543 | case IRQ_PROG0_INTA: |
| 544 | irq = IRQ_PF0; |
| 545 | break; |
| 546 | case IRQ_PROG1_INTA: |
| 547 | irq = IRQ_PF16; |
| 548 | break; |
| 549 | case IRQ_PROG2_INTA: |
| 550 | irq = IRQ_PF32; |
| 551 | break; |
| 552 | #endif |
| 553 | default: |
| 554 | BUG(); |
| 555 | return; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 556 | } |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 557 | |
| 558 | if (search) { |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 559 | for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) { |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 560 | irq += i; |
| 561 | |
| 562 | mask = get_gpiop_data(i) & |
| 563 | (gpio_enabled[gpio_bank(i)] & |
| 564 | get_gpiop_maska(i)); |
| 565 | |
| 566 | while (mask) { |
| 567 | if (mask & 1) { |
| 568 | desc = irq_desc + irq; |
| 569 | desc->handle_irq(irq, desc); |
| 570 | } |
| 571 | irq++; |
| 572 | mask >>= 1; |
| 573 | } |
| 574 | } |
| 575 | } else { |
| 576 | gpio = irq_to_gpio(irq); |
| 577 | mask = get_gpiop_data(gpio) & |
| 578 | (gpio_enabled[gpio_bank(gpio)] & |
| 579 | get_gpiop_maska(gpio)); |
| 580 | |
| 581 | do { |
| 582 | if (mask & 1) { |
| 583 | desc = irq_desc + irq; |
| 584 | desc->handle_irq(irq, desc); |
| 585 | } |
| 586 | irq++; |
| 587 | mask >>= 1; |
| 588 | } while (mask); |
| 589 | } |
| 590 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 593 | #else /* CONFIG_BF54x */ |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 594 | |
| 595 | #define NR_PINT_SYS_IRQS 4 |
| 596 | #define NR_PINT_BITS 32 |
| 597 | #define NR_PINTS 160 |
| 598 | #define IRQ_NOT_AVAIL 0xFF |
| 599 | |
| 600 | #define PINT_2_BANK(x) ((x) >> 5) |
| 601 | #define PINT_2_BIT(x) ((x) & 0x1F) |
| 602 | #define PINT_BIT(x) (1 << (PINT_2_BIT(x))) |
| 603 | |
| 604 | static unsigned char irq2pint_lut[NR_PINTS]; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 605 | static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS]; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 606 | |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 607 | static unsigned int gpio_both_edge_triggered[NR_PINT_SYS_IRQS]; |
| 608 | static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)]; |
| 609 | |
| 610 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 611 | struct pin_int_t { |
| 612 | unsigned int mask_set; |
| 613 | unsigned int mask_clear; |
| 614 | unsigned int request; |
| 615 | unsigned int assign; |
| 616 | unsigned int edge_set; |
| 617 | unsigned int edge_clear; |
| 618 | unsigned int invert_set; |
| 619 | unsigned int invert_clear; |
| 620 | unsigned int pinstate; |
| 621 | unsigned int latch; |
| 622 | }; |
| 623 | |
| 624 | static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = { |
| 625 | (struct pin_int_t *)PINT0_MASK_SET, |
| 626 | (struct pin_int_t *)PINT1_MASK_SET, |
| 627 | (struct pin_int_t *)PINT2_MASK_SET, |
| 628 | (struct pin_int_t *)PINT3_MASK_SET, |
| 629 | }; |
| 630 | |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 631 | extern void bfin_gpio_irq_prepare(unsigned gpio); |
| 632 | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 633 | inline unsigned short get_irq_base(u8 bank, u8 bmap) |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 634 | { |
| 635 | |
| 636 | u16 irq_base; |
| 637 | |
| 638 | if (bank < 2) { /*PA-PB */ |
| 639 | irq_base = IRQ_PA0 + bmap * 16; |
| 640 | } else { /*PC-PJ */ |
| 641 | irq_base = IRQ_PC0 + bmap * 16; |
| 642 | } |
| 643 | |
| 644 | return irq_base; |
| 645 | |
| 646 | } |
| 647 | |
| 648 | /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */ |
| 649 | void init_pint_lut(void) |
| 650 | { |
| 651 | u16 bank, bit, irq_base, bit_pos; |
| 652 | u32 pint_assign; |
| 653 | u8 bmap; |
| 654 | |
| 655 | memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut)); |
| 656 | |
| 657 | for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) { |
| 658 | |
| 659 | pint_assign = pint[bank]->assign; |
| 660 | |
| 661 | for (bit = 0; bit < NR_PINT_BITS; bit++) { |
| 662 | |
| 663 | bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF; |
| 664 | |
| 665 | irq_base = get_irq_base(bank, bmap); |
| 666 | |
| 667 | irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0); |
| 668 | bit_pos = bit + bank * NR_PINT_BITS; |
| 669 | |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 670 | pint2irq_lut[bit_pos] = irq_base - SYS_IRQS; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 671 | irq2pint_lut[irq_base - SYS_IRQS] = bit_pos; |
| 672 | |
| 673 | } |
| 674 | |
| 675 | } |
| 676 | |
| 677 | } |
| 678 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 679 | static void bfin_gpio_ack_irq(unsigned int irq) |
| 680 | { |
| 681 | u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 682 | u32 pintbit = PINT_BIT(pint_val); |
| 683 | u8 bank = PINT_2_BANK(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 684 | |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 685 | if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) { |
| 686 | if (pint[bank]->invert_set & pintbit) |
| 687 | pint[bank]->invert_clear = pintbit; |
| 688 | else |
| 689 | pint[bank]->invert_set = pintbit; |
| 690 | } |
| 691 | pint[bank]->request = pintbit; |
| 692 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 693 | SSYNC(); |
| 694 | } |
| 695 | |
| 696 | static void bfin_gpio_mask_ack_irq(unsigned int irq) |
| 697 | { |
| 698 | u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 699 | u32 pintbit = PINT_BIT(pint_val); |
| 700 | u8 bank = PINT_2_BANK(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 701 | |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 702 | if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) { |
| 703 | if (pint[bank]->invert_set & pintbit) |
| 704 | pint[bank]->invert_clear = pintbit; |
| 705 | else |
| 706 | pint[bank]->invert_set = pintbit; |
| 707 | } |
| 708 | |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 709 | pint[bank]->request = pintbit; |
| 710 | pint[bank]->mask_clear = pintbit; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 711 | SSYNC(); |
| 712 | } |
| 713 | |
| 714 | static void bfin_gpio_mask_irq(unsigned int irq) |
| 715 | { |
| 716 | u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
| 717 | |
| 718 | pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val); |
| 719 | SSYNC(); |
| 720 | } |
| 721 | |
| 722 | static void bfin_gpio_unmask_irq(unsigned int irq) |
| 723 | { |
| 724 | u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 725 | u32 pintbit = PINT_BIT(pint_val); |
| 726 | u8 bank = PINT_2_BANK(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 727 | |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 728 | pint[bank]->request = pintbit; |
| 729 | pint[bank]->mask_set = pintbit; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 730 | SSYNC(); |
| 731 | } |
| 732 | |
| 733 | static unsigned int bfin_gpio_irq_startup(unsigned int irq) |
| 734 | { |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 735 | u16 gpionr = irq_to_gpio(irq); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 736 | u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
| 737 | |
Michael Hennerich | 50e163c | 2007-07-24 16:17:28 +0800 | [diff] [blame] | 738 | if (pint_val == IRQ_NOT_AVAIL) { |
| 739 | printk(KERN_ERR |
| 740 | "GPIO IRQ %d :Not in PINT Assign table " |
| 741 | "Reconfigure Interrupt to Port Assignemt\n", irq); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 742 | return -ENODEV; |
Michael Hennerich | 50e163c | 2007-07-24 16:17:28 +0800 | [diff] [blame] | 743 | } |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 744 | |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 745 | if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) |
| 746 | bfin_gpio_irq_prepare(gpionr); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 747 | |
| 748 | gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr); |
| 749 | bfin_gpio_unmask_irq(irq); |
| 750 | |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 751 | return 0; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | static void bfin_gpio_irq_shutdown(unsigned int irq) |
| 755 | { |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 756 | u16 gpionr = irq_to_gpio(irq); |
| 757 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 758 | bfin_gpio_mask_irq(irq); |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 759 | gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static int bfin_gpio_irq_type(unsigned int irq, unsigned int type) |
| 763 | { |
| 764 | |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 765 | u16 gpionr = irq_to_gpio(irq); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 766 | u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 767 | u32 pintbit = PINT_BIT(pint_val); |
| 768 | u8 bank = PINT_2_BANK(pint_val); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 769 | |
| 770 | if (pint_val == IRQ_NOT_AVAIL) |
| 771 | return -ENODEV; |
| 772 | |
| 773 | if (type == IRQ_TYPE_PROBE) { |
| 774 | /* only probe unenabled GPIO interrupt lines */ |
| 775 | if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)) |
| 776 | return 0; |
| 777 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; |
| 778 | } |
| 779 | |
| 780 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | |
| 781 | IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { |
Michael Hennerich | affee2b | 2008-04-24 08:10:10 +0800 | [diff] [blame] | 782 | if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) |
| 783 | bfin_gpio_irq_prepare(gpionr); |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 784 | |
| 785 | gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr); |
| 786 | } else { |
| 787 | gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr); |
| 788 | return 0; |
| 789 | } |
| 790 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 791 | if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW))) |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 792 | pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */ |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 793 | else |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 794 | pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */ |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 795 | |
Michael Hennerich | 8baf560 | 2007-12-24 18:51:34 +0800 | [diff] [blame] | 796 | if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) |
| 797 | == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) { |
| 798 | |
| 799 | gpio_both_edge_triggered[bank] |= pintbit; |
| 800 | |
| 801 | if (gpio_get_value(gpionr)) |
| 802 | pint[bank]->invert_set = pintbit; |
| 803 | else |
| 804 | pint[bank]->invert_clear = pintbit; |
| 805 | } else { |
| 806 | gpio_both_edge_triggered[bank] &= ~pintbit; |
| 807 | } |
| 808 | |
| 809 | if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) { |
| 810 | pint[bank]->edge_set = pintbit; |
| 811 | set_irq_handler(irq, handle_edge_irq); |
| 812 | } else { |
| 813 | pint[bank]->edge_clear = pintbit; |
| 814 | set_irq_handler(irq, handle_level_irq); |
| 815 | } |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 816 | |
| 817 | SSYNC(); |
| 818 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 819 | return 0; |
| 820 | } |
| 821 | |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 822 | #ifdef CONFIG_PM |
| 823 | u32 pint_saved_masks[NR_PINT_SYS_IRQS]; |
| 824 | u32 pint_wakeup_masks[NR_PINT_SYS_IRQS]; |
| 825 | |
| 826 | int bfin_gpio_set_wake(unsigned int irq, unsigned int state) |
| 827 | { |
| 828 | u32 pint_irq; |
| 829 | u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; |
| 830 | u32 bank = PINT_2_BANK(pint_val); |
| 831 | u32 pintbit = PINT_BIT(pint_val); |
| 832 | |
| 833 | switch (bank) { |
| 834 | case 0: |
| 835 | pint_irq = IRQ_PINT0; |
| 836 | break; |
| 837 | case 2: |
| 838 | pint_irq = IRQ_PINT2; |
| 839 | break; |
| 840 | case 3: |
| 841 | pint_irq = IRQ_PINT3; |
| 842 | break; |
| 843 | case 1: |
| 844 | pint_irq = IRQ_PINT1; |
| 845 | break; |
| 846 | default: |
| 847 | return -EINVAL; |
| 848 | } |
| 849 | |
| 850 | bfin_internal_set_wake(pint_irq, state); |
| 851 | |
| 852 | if (state) |
| 853 | pint_wakeup_masks[bank] |= pintbit; |
| 854 | else |
| 855 | pint_wakeup_masks[bank] &= ~pintbit; |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | u32 bfin_pm_setup(void) |
| 861 | { |
| 862 | u32 val, i; |
| 863 | |
| 864 | for (i = 0; i < NR_PINT_SYS_IRQS; i++) { |
| 865 | val = pint[i]->mask_clear; |
| 866 | pint_saved_masks[i] = val; |
| 867 | if (val ^ pint_wakeup_masks[i]) { |
| 868 | pint[i]->mask_clear = val; |
| 869 | pint[i]->mask_set = pint_wakeup_masks[i]; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | void bfin_pm_restore(void) |
| 877 | { |
| 878 | u32 i, val; |
| 879 | |
| 880 | for (i = 0; i < NR_PINT_SYS_IRQS; i++) { |
| 881 | val = pint_saved_masks[i]; |
| 882 | if (val ^ pint_wakeup_masks[i]) { |
| 883 | pint[i]->mask_clear = pint[i]->mask_clear; |
| 884 | pint[i]->mask_set = val; |
| 885 | } |
| 886 | } |
| 887 | } |
| 888 | #endif |
| 889 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 890 | static struct irq_chip bfin_gpio_irqchip = { |
Graf Yang | 763e63c | 2008-10-08 17:08:15 +0800 | [diff] [blame^] | 891 | .name = "GPIO", |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 892 | .ack = bfin_gpio_ack_irq, |
| 893 | .mask = bfin_gpio_mask_irq, |
| 894 | .mask_ack = bfin_gpio_mask_ack_irq, |
| 895 | .unmask = bfin_gpio_unmask_irq, |
Michael Hennerich | 1f2d186 | 2008-07-14 16:31:22 +0800 | [diff] [blame] | 896 | .disable = bfin_gpio_mask_irq, |
| 897 | .enable = bfin_gpio_unmask_irq, |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 898 | .set_type = bfin_gpio_irq_type, |
| 899 | .startup = bfin_gpio_irq_startup, |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 900 | .shutdown = bfin_gpio_irq_shutdown, |
| 901 | #ifdef CONFIG_PM |
| 902 | .set_wake = bfin_gpio_set_wake, |
| 903 | #endif |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 904 | }; |
| 905 | |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 906 | static void bfin_demux_gpio_irq(unsigned int inta_irq, |
| 907 | struct irq_desc *desc) |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 908 | { |
| 909 | u8 bank, pint_val; |
| 910 | u32 request, irq; |
| 911 | |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 912 | switch (inta_irq) { |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 913 | case IRQ_PINT0: |
| 914 | bank = 0; |
| 915 | break; |
| 916 | case IRQ_PINT2: |
| 917 | bank = 2; |
| 918 | break; |
| 919 | case IRQ_PINT3: |
| 920 | bank = 3; |
| 921 | break; |
| 922 | case IRQ_PINT1: |
| 923 | bank = 1; |
| 924 | break; |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 925 | default: |
| 926 | return; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | pint_val = bank * NR_PINT_BITS; |
| 930 | |
| 931 | request = pint[bank]->request; |
| 932 | |
| 933 | while (request) { |
| 934 | if (request & 1) { |
Michael Hennerich | e3f2300 | 2007-07-12 16:39:29 +0800 | [diff] [blame] | 935 | irq = pint2irq_lut[pint_val] + SYS_IRQS; |
| 936 | desc = irq_desc + irq; |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 937 | desc->handle_irq(irq, desc); |
| 938 | } |
| 939 | pint_val++; |
| 940 | request >>= 1; |
| 941 | } |
| 942 | |
| 943 | } |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 944 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 945 | |
Bernd Schmidt | 8be80ed | 2007-07-25 14:44:49 +0800 | [diff] [blame] | 946 | void __init init_exception_vectors(void) |
| 947 | { |
| 948 | SSYNC(); |
| 949 | |
Mike Frysinger | f0b5d12 | 2007-08-05 17:03:59 +0800 | [diff] [blame] | 950 | /* cannot program in software: |
| 951 | * evt0 - emulation (jtag) |
| 952 | * evt1 - reset |
| 953 | */ |
| 954 | bfin_write_EVT2(evt_nmi); |
Bernd Schmidt | 8be80ed | 2007-07-25 14:44:49 +0800 | [diff] [blame] | 955 | bfin_write_EVT3(trap); |
| 956 | bfin_write_EVT5(evt_ivhw); |
| 957 | bfin_write_EVT6(evt_timer); |
| 958 | bfin_write_EVT7(evt_evt7); |
| 959 | bfin_write_EVT8(evt_evt8); |
| 960 | bfin_write_EVT9(evt_evt9); |
| 961 | bfin_write_EVT10(evt_evt10); |
| 962 | bfin_write_EVT11(evt_evt11); |
| 963 | bfin_write_EVT12(evt_evt12); |
| 964 | bfin_write_EVT13(evt_evt13); |
| 965 | bfin_write_EVT14(evt14_softirq); |
| 966 | bfin_write_EVT15(evt_system_call); |
| 967 | CSYNC(); |
| 968 | } |
| 969 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 970 | /* |
| 971 | * This function should be called during kernel startup to initialize |
| 972 | * the BFin IRQ handling routines. |
| 973 | */ |
| 974 | int __init init_arch_irq(void) |
| 975 | { |
| 976 | int irq; |
| 977 | unsigned long ilat = 0; |
| 978 | /* Disable all the peripheral intrs - page 4-29 HW Ref manual */ |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 979 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 980 | bfin_write_SIC_IMASK0(SIC_UNMASK_ALL); |
| 981 | bfin_write_SIC_IMASK1(SIC_UNMASK_ALL); |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 982 | # ifdef CONFIG_BF54x |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 983 | bfin_write_SIC_IMASK2(SIC_UNMASK_ALL); |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 984 | # endif |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 985 | #else |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 986 | bfin_write_SIC_IMASK(SIC_UNMASK_ALL); |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 987 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 988 | |
| 989 | local_irq_disable(); |
| 990 | |
Mike Frysinger | d70536e | 2008-08-25 17:37:35 +0800 | [diff] [blame] | 991 | #if (defined(CONFIG_BF537) || defined(CONFIG_BF536)) |
Mike Frysinger | 95a86b5 | 2008-08-14 15:05:01 +0800 | [diff] [blame] | 992 | /* Clear EMAC Interrupt Status bits so we can demux it later */ |
| 993 | bfin_write_EMAC_SYSTAT(-1); |
| 994 | #endif |
| 995 | |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 996 | #ifdef CONFIG_BF54x |
| 997 | # ifdef CONFIG_PINTx_REASSIGN |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 998 | pint[0]->assign = CONFIG_PINT0_ASSIGN; |
| 999 | pint[1]->assign = CONFIG_PINT1_ASSIGN; |
| 1000 | pint[2]->assign = CONFIG_PINT2_ASSIGN; |
| 1001 | pint[3]->assign = CONFIG_PINT3_ASSIGN; |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 1002 | # endif |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 1003 | /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */ |
| 1004 | init_pint_lut(); |
| 1005 | #endif |
| 1006 | |
| 1007 | for (irq = 0; irq <= SYS_IRQS; irq++) { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1008 | if (irq <= IRQ_CORETMR) |
| 1009 | set_irq_chip(irq, &bfin_core_irqchip); |
| 1010 | else |
| 1011 | set_irq_chip(irq, &bfin_internal_irqchip); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1012 | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1013 | switch (irq) { |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1014 | #if defined(CONFIG_BF53x) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1015 | case IRQ_PROG_INTA: |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 1016 | # 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] | 1017 | case IRQ_MAC_RX: |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 1018 | # endif |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1019 | #elif defined(CONFIG_BF54x) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1020 | case IRQ_PINT0: |
| 1021 | case IRQ_PINT1: |
| 1022 | case IRQ_PINT2: |
| 1023 | case IRQ_PINT3: |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1024 | #elif defined(CONFIG_BF52x) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1025 | case IRQ_PORTF_INTA: |
| 1026 | case IRQ_PORTG_INTA: |
| 1027 | case IRQ_PORTH_INTA: |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 1028 | #elif defined(CONFIG_BF561) |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1029 | case IRQ_PROG0_INTA: |
| 1030 | case IRQ_PROG1_INTA: |
| 1031 | case IRQ_PROG2_INTA: |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1032 | #endif |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1033 | set_irq_chained_handler(irq, |
| 1034 | bfin_demux_gpio_irq); |
| 1035 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1036 | #ifdef BF537_GENERIC_ERROR_INT_DEMUX |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1037 | case IRQ_GENERIC_ERROR: |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1038 | set_irq_handler(irq, bfin_demux_error_irq); |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1039 | |
| 1040 | break; |
| 1041 | #endif |
| 1042 | default: |
| 1043 | set_irq_handler(irq, handle_simple_irq); |
| 1044 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1045 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1046 | } |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1047 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1048 | #ifdef BF537_GENERIC_ERROR_INT_DEMUX |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1049 | for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++) |
| 1050 | set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip, |
| 1051 | handle_level_irq); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1052 | #endif |
| 1053 | |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1054 | /* if configured as edge, then will be changed to do_edge_IRQ */ |
| 1055 | for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++) |
| 1056 | set_irq_chip_and_handler(irq, &bfin_gpio_irqchip, |
| 1057 | handle_level_irq); |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 1058 | |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 1059 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1060 | bfin_write_IMASK(0); |
| 1061 | CSYNC(); |
| 1062 | ilat = bfin_read_ILAT(); |
| 1063 | CSYNC(); |
| 1064 | bfin_write_ILAT(ilat); |
| 1065 | CSYNC(); |
| 1066 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 1067 | printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1068 | /* IMASK=xxx is equivalent to STI xx or irq_flags=xx, |
| 1069 | * local_irq_enable() |
| 1070 | */ |
| 1071 | program_IAR(); |
| 1072 | /* Therefore it's better to setup IARs before interrupts enabled */ |
| 1073 | search_IAR(); |
| 1074 | |
| 1075 | /* Enable interrupts IVG7-15 */ |
| 1076 | irq_flags = irq_flags | IMASK_IVG15 | |
| 1077 | IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 | |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 1078 | IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1079 | |
Michael Hennerich | fe9ec9b | 2008-02-25 12:04:57 +0800 | [diff] [blame] | 1080 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) |
Michael Hennerich | 56f5f59 | 2008-08-06 17:55:32 +0800 | [diff] [blame] | 1081 | bfin_write_SIC_IWR0(IWR_DISABLE_ALL); |
Michael Hennerich | 55546ac | 2008-08-13 17:41:13 +0800 | [diff] [blame] | 1082 | #if defined(CONFIG_BF52x) |
| 1083 | /* BF52x system reset does not properly reset SIC_IWR1 which |
| 1084 | * will screw up the bootrom as it relies on MDMA0/1 waking it |
| 1085 | * up from IDLE instructions. See this report for more info: |
| 1086 | * http://blackfin.uclinux.org/gf/tracker/4323 |
| 1087 | */ |
| 1088 | bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11)); |
| 1089 | #else |
Michael Hennerich | 56f5f59 | 2008-08-06 17:55:32 +0800 | [diff] [blame] | 1090 | bfin_write_SIC_IWR1(IWR_DISABLE_ALL); |
Michael Hennerich | 55546ac | 2008-08-13 17:41:13 +0800 | [diff] [blame] | 1091 | #endif |
Michael Hennerich | fe9ec9b | 2008-02-25 12:04:57 +0800 | [diff] [blame] | 1092 | # ifdef CONFIG_BF54x |
Michael Hennerich | 56f5f59 | 2008-08-06 17:55:32 +0800 | [diff] [blame] | 1093 | bfin_write_SIC_IWR2(IWR_DISABLE_ALL); |
Michael Hennerich | fe9ec9b | 2008-02-25 12:04:57 +0800 | [diff] [blame] | 1094 | # endif |
| 1095 | #else |
Michael Hennerich | 56f5f59 | 2008-08-06 17:55:32 +0800 | [diff] [blame] | 1096 | bfin_write_SIC_IWR(IWR_DISABLE_ALL); |
Michael Hennerich | fe9ec9b | 2008-02-25 12:04:57 +0800 | [diff] [blame] | 1097 | #endif |
| 1098 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | #ifdef CONFIG_DO_IRQ_L1 |
Mike Frysinger | a055b2b | 2007-11-15 21:12:32 +0800 | [diff] [blame] | 1103 | __attribute__((l1_text)) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1104 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1105 | void do_irq(int vec, struct pt_regs *fp) |
| 1106 | { |
| 1107 | if (vec == EVT_IVTMR_P) { |
| 1108 | vec = IRQ_CORETMR; |
| 1109 | } else { |
| 1110 | struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst; |
| 1111 | struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop; |
Michael Hennerich | 2c4f829 | 2008-02-09 04:11:14 +0800 | [diff] [blame] | 1112 | #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 1113 | unsigned long sic_status[3]; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1114 | |
Michael Hennerich | 4fb4524 | 2007-10-21 16:53:53 +0800 | [diff] [blame] | 1115 | sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0(); |
| 1116 | sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1(); |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1117 | #ifdef CONFIG_BF54x |
Michael Hennerich | 4fb4524 | 2007-10-21 16:53:53 +0800 | [diff] [blame] | 1118 | sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2(); |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1119 | #endif |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 1120 | for (;; ivg++) { |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 1121 | if (ivg >= ivg_stop) { |
| 1122 | atomic_inc(&num_spurious); |
| 1123 | return; |
| 1124 | } |
Michael Hennerich | 34e0fc8 | 2007-07-12 16:17:18 +0800 | [diff] [blame] | 1125 | if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag) |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 1126 | break; |
| 1127 | } |
| 1128 | #else |
| 1129 | unsigned long sic_status; |
Michael Hennerich | 464abc5 | 2008-02-25 13:50:20 +0800 | [diff] [blame] | 1130 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1131 | sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR(); |
| 1132 | |
| 1133 | for (;; ivg++) { |
| 1134 | if (ivg >= ivg_stop) { |
| 1135 | atomic_inc(&num_spurious); |
| 1136 | return; |
| 1137 | } else if (sic_status & ivg->isrflag) |
| 1138 | break; |
| 1139 | } |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 1140 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1141 | vec = ivg->irqno; |
| 1142 | } |
| 1143 | asm_do_IRQ(vec, fp); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1144 | } |