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