Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 1 | /* |
| 2 | * intc.c -- interrupt controller or ColdFire 5272 SoC |
| 3 | * |
| 4 | * (C) Copyright 2009, Greg Ungerer <gerg@snapgear.com> |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file COPYING in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/interrupt.h> |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 15 | #include <linux/kernel_stat.h> |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 16 | #include <linux/irq.h> |
| 17 | #include <linux/io.h> |
| 18 | #include <asm/coldfire.h> |
| 19 | #include <asm/mcfsim.h> |
| 20 | #include <asm/traps.h> |
| 21 | |
| 22 | /* |
| 23 | * The 5272 ColdFire interrupt controller is nothing like any other |
| 24 | * ColdFire interrupt controller - it truly is completely different. |
| 25 | * Given its age it is unlikely to be used on any other ColdFire CPU. |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * The masking and priproty setting of interrupts on the 5272 is done |
| 30 | * via a set of 4 "Interrupt Controller Registers" (ICR). There is a |
| 31 | * loose mapping of vector number to register and internal bits, but |
| 32 | * a table is the easiest and quickest way to map them. |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 33 | * |
| 34 | * Note that the external interrupts are edge triggered (unlike the |
| 35 | * internal interrupt sources which are level triggered). Which means |
| 36 | * they also need acknowledgeing via acknowledge bits. |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 37 | */ |
| 38 | struct irqmap { |
| 39 | unsigned char icr; |
| 40 | unsigned char index; |
| 41 | unsigned char ack; |
| 42 | }; |
| 43 | |
| 44 | static struct irqmap intc_irqmap[MCFINT_VECMAX - MCFINT_VECBASE] = { |
| 45 | /*MCF_IRQ_SPURIOUS*/ { .icr = 0, .index = 0, .ack = 0, }, |
| 46 | /*MCF_IRQ_EINT1*/ { .icr = MCFSIM_ICR1, .index = 28, .ack = 1, }, |
| 47 | /*MCF_IRQ_EINT2*/ { .icr = MCFSIM_ICR1, .index = 24, .ack = 1, }, |
| 48 | /*MCF_IRQ_EINT3*/ { .icr = MCFSIM_ICR1, .index = 20, .ack = 1, }, |
| 49 | /*MCF_IRQ_EINT4*/ { .icr = MCFSIM_ICR1, .index = 16, .ack = 1, }, |
| 50 | /*MCF_IRQ_TIMER1*/ { .icr = MCFSIM_ICR1, .index = 12, .ack = 0, }, |
| 51 | /*MCF_IRQ_TIMER2*/ { .icr = MCFSIM_ICR1, .index = 8, .ack = 0, }, |
| 52 | /*MCF_IRQ_TIMER3*/ { .icr = MCFSIM_ICR1, .index = 4, .ack = 0, }, |
| 53 | /*MCF_IRQ_TIMER4*/ { .icr = MCFSIM_ICR1, .index = 0, .ack = 0, }, |
| 54 | /*MCF_IRQ_UART1*/ { .icr = MCFSIM_ICR2, .index = 28, .ack = 0, }, |
| 55 | /*MCF_IRQ_UART2*/ { .icr = MCFSIM_ICR2, .index = 24, .ack = 0, }, |
| 56 | /*MCF_IRQ_PLIP*/ { .icr = MCFSIM_ICR2, .index = 20, .ack = 0, }, |
| 57 | /*MCF_IRQ_PLIA*/ { .icr = MCFSIM_ICR2, .index = 16, .ack = 0, }, |
| 58 | /*MCF_IRQ_USB0*/ { .icr = MCFSIM_ICR2, .index = 12, .ack = 0, }, |
| 59 | /*MCF_IRQ_USB1*/ { .icr = MCFSIM_ICR2, .index = 8, .ack = 0, }, |
| 60 | /*MCF_IRQ_USB2*/ { .icr = MCFSIM_ICR2, .index = 4, .ack = 0, }, |
| 61 | /*MCF_IRQ_USB3*/ { .icr = MCFSIM_ICR2, .index = 0, .ack = 0, }, |
| 62 | /*MCF_IRQ_USB4*/ { .icr = MCFSIM_ICR3, .index = 28, .ack = 0, }, |
| 63 | /*MCF_IRQ_USB5*/ { .icr = MCFSIM_ICR3, .index = 24, .ack = 0, }, |
| 64 | /*MCF_IRQ_USB6*/ { .icr = MCFSIM_ICR3, .index = 20, .ack = 0, }, |
| 65 | /*MCF_IRQ_USB7*/ { .icr = MCFSIM_ICR3, .index = 16, .ack = 0, }, |
| 66 | /*MCF_IRQ_DMA*/ { .icr = MCFSIM_ICR3, .index = 12, .ack = 0, }, |
| 67 | /*MCF_IRQ_ERX*/ { .icr = MCFSIM_ICR3, .index = 8, .ack = 0, }, |
| 68 | /*MCF_IRQ_ETX*/ { .icr = MCFSIM_ICR3, .index = 4, .ack = 0, }, |
| 69 | /*MCF_IRQ_ENTC*/ { .icr = MCFSIM_ICR3, .index = 0, .ack = 0, }, |
| 70 | /*MCF_IRQ_QSPI*/ { .icr = MCFSIM_ICR4, .index = 28, .ack = 0, }, |
| 71 | /*MCF_IRQ_EINT5*/ { .icr = MCFSIM_ICR4, .index = 24, .ack = 1, }, |
| 72 | /*MCF_IRQ_EINT6*/ { .icr = MCFSIM_ICR4, .index = 20, .ack = 1, }, |
| 73 | /*MCF_IRQ_SWTO*/ { .icr = MCFSIM_ICR4, .index = 16, .ack = 0, }, |
| 74 | }; |
| 75 | |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 76 | /* |
| 77 | * The act of masking the interrupt also has a side effect of 'ack'ing |
| 78 | * an interrupt on this irq (for the external irqs). So this mask function |
| 79 | * is also an ack_mask function. |
| 80 | */ |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 81 | static void intc_irq_mask(unsigned int irq) |
| 82 | { |
| 83 | if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) { |
| 84 | u32 v; |
| 85 | irq -= MCFINT_VECBASE; |
| 86 | v = 0x8 << intc_irqmap[irq].index; |
| 87 | writel(v, MCF_MBAR + intc_irqmap[irq].icr); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static void intc_irq_unmask(unsigned int irq) |
| 92 | { |
| 93 | if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) { |
| 94 | u32 v; |
| 95 | irq -= MCFINT_VECBASE; |
| 96 | v = 0xd << intc_irqmap[irq].index; |
| 97 | writel(v, MCF_MBAR + intc_irqmap[irq].icr); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | static void intc_irq_ack(unsigned int irq) |
| 102 | { |
| 103 | /* Only external interrupts are acked */ |
| 104 | if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) { |
| 105 | irq -= MCFINT_VECBASE; |
| 106 | if (intc_irqmap[irq].ack) { |
| 107 | u32 v; |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 108 | v = readl(MCF_MBAR + intc_irqmap[irq].icr); |
| 109 | v &= (0x7 << intc_irqmap[irq].index); |
| 110 | v |= (0x8 << intc_irqmap[irq].index); |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 111 | writel(v, MCF_MBAR + intc_irqmap[irq].icr); |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | static int intc_irq_set_type(unsigned int irq, unsigned int type) |
| 117 | { |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 118 | if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) { |
| 119 | irq -= MCFINT_VECBASE; |
| 120 | if (intc_irqmap[irq].ack) { |
| 121 | u32 v; |
| 122 | v = readl(MCF_MBAR + MCFSIM_PITR); |
| 123 | if (type == IRQ_TYPE_EDGE_FALLING) |
| 124 | v &= ~(0x1 << (32 - irq)); |
| 125 | else |
| 126 | v |= (0x1 << (32 - irq)); |
| 127 | writel(v, MCF_MBAR + MCFSIM_PITR); |
| 128 | } |
| 129 | } |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 133 | /* |
| 134 | * Simple flow handler to deal with the external edge triggered interrupts. |
| 135 | * We need to be careful with the masking/acking due to the side effects |
| 136 | * of masking an interrupt. |
| 137 | */ |
| 138 | static void intc_external_irq(unsigned int irq, struct irq_desc *desc) |
| 139 | { |
| 140 | kstat_incr_irqs_this_cpu(irq, desc); |
| 141 | desc->status |= IRQ_INPROGRESS; |
| 142 | desc->chip->ack(irq); |
| 143 | handle_IRQ_event(irq, desc->action); |
| 144 | desc->status &= ~IRQ_INPROGRESS; |
| 145 | } |
| 146 | |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 147 | static struct irq_chip intc_irq_chip = { |
| 148 | .name = "CF-INTC", |
| 149 | .mask = intc_irq_mask, |
| 150 | .unmask = intc_irq_unmask, |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 151 | .mask_ack = intc_irq_mask, |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 152 | .ack = intc_irq_ack, |
| 153 | .set_type = intc_irq_set_type, |
| 154 | }; |
| 155 | |
| 156 | void __init init_IRQ(void) |
| 157 | { |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 158 | int irq, edge; |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 159 | |
| 160 | init_vectors(); |
| 161 | |
| 162 | /* Mask all interrupt sources */ |
| 163 | writel(0x88888888, MCF_MBAR + MCFSIM_ICR1); |
| 164 | writel(0x88888888, MCF_MBAR + MCFSIM_ICR2); |
| 165 | writel(0x88888888, MCF_MBAR + MCFSIM_ICR3); |
| 166 | writel(0x88888888, MCF_MBAR + MCFSIM_ICR4); |
| 167 | |
| 168 | for (irq = 0; (irq < NR_IRQS); irq++) { |
Greg Ungerer | 04570b4 | 2010-09-09 17:12:53 +1000 | [diff] [blame] | 169 | set_irq_chip(irq, &intc_irq_chip); |
Greg Ungerer | a405f83 | 2010-10-13 13:42:22 +1000 | [diff] [blame] | 170 | edge = 0; |
| 171 | if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) |
| 172 | edge = intc_irqmap[irq - MCFINT_VECBASE].ack; |
| 173 | if (edge) { |
| 174 | set_irq_type(irq, IRQ_TYPE_EDGE_RISING); |
| 175 | set_irq_handler(irq, intc_external_irq); |
| 176 | } else { |
| 177 | set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH); |
| 178 | set_irq_handler(irq, handle_level_irq); |
| 179 | } |
Greg Ungerer | 9075216 | 2009-07-07 09:39:11 +1000 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |