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