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