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