blob: d1e2fbad327cecaa4c785e4b270177a6c030cbb5 [file] [log] [blame]
Greg Ungerer90752162009-07-07 09:39:11 +10001/*
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 Ungerera405f832010-10-13 13:42:22 +100015#include <linux/kernel_stat.h>
Greg Ungerer90752162009-07-07 09:39:11 +100016#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 Ungerera405f832010-10-13 13:42:22 +100033 *
34 * Note that the external interrupts are edge triggered (unlike the
35 * internal interrupt sources which are level triggered). Which means
Lucas De Marchi25985ed2011-03-30 22:57:33 -030036 * they also need acknowledging via acknowledge bits.
Greg Ungerer90752162009-07-07 09:39:11 +100037 */
38struct irqmap {
Greg Ungererecb6bdc2014-08-28 14:39:45 +100039 unsigned int icr;
Greg Ungerer90752162009-07-07 09:39:11 +100040 unsigned char index;
41 unsigned char ack;
42};
43
44static 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 Ungerera405f832010-10-13 13:42:22 +100076/*
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 */
Thomas Gleixner27301582011-02-06 23:39:28 +000081static void intc_irq_mask(struct irq_data *d)
Greg Ungerer90752162009-07-07 09:39:11 +100082{
Thomas Gleixner27301582011-02-06 23:39:28 +000083 unsigned int irq = d->irq;
84
Greg Ungerer90752162009-07-07 09:39:11 +100085 if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) {
86 u32 v;
87 irq -= MCFINT_VECBASE;
88 v = 0x8 << intc_irqmap[irq].index;
Greg Ungererc986a3d2012-08-17 16:48:16 +100089 writel(v, intc_irqmap[irq].icr);
Greg Ungerer90752162009-07-07 09:39:11 +100090 }
91}
92
Thomas Gleixner27301582011-02-06 23:39:28 +000093static void intc_irq_unmask(struct irq_data *d)
Greg Ungerer90752162009-07-07 09:39:11 +100094{
Thomas Gleixner27301582011-02-06 23:39:28 +000095 unsigned int irq = d->irq;
96
Greg Ungerer90752162009-07-07 09:39:11 +100097 if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) {
98 u32 v;
99 irq -= MCFINT_VECBASE;
100 v = 0xd << intc_irqmap[irq].index;
Greg Ungererc986a3d2012-08-17 16:48:16 +1000101 writel(v, intc_irqmap[irq].icr);
Greg Ungerer90752162009-07-07 09:39:11 +1000102 }
103}
104
Thomas Gleixner27301582011-02-06 23:39:28 +0000105static void intc_irq_ack(struct irq_data *d)
Greg Ungerer90752162009-07-07 09:39:11 +1000106{
Thomas Gleixner27301582011-02-06 23:39:28 +0000107 unsigned int irq = d->irq;
108
Greg Ungerer90752162009-07-07 09:39:11 +1000109 /* Only external interrupts are acked */
110 if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) {
111 irq -= MCFINT_VECBASE;
112 if (intc_irqmap[irq].ack) {
113 u32 v;
Greg Ungererc986a3d2012-08-17 16:48:16 +1000114 v = readl(intc_irqmap[irq].icr);
Greg Ungerera405f832010-10-13 13:42:22 +1000115 v &= (0x7 << intc_irqmap[irq].index);
116 v |= (0x8 << intc_irqmap[irq].index);
Greg Ungererc986a3d2012-08-17 16:48:16 +1000117 writel(v, intc_irqmap[irq].icr);
Greg Ungerer90752162009-07-07 09:39:11 +1000118 }
119 }
120}
121
Thomas Gleixner27301582011-02-06 23:39:28 +0000122static int intc_irq_set_type(struct irq_data *d, unsigned int type)
Greg Ungerer90752162009-07-07 09:39:11 +1000123{
Thomas Gleixner27301582011-02-06 23:39:28 +0000124 unsigned int irq = d->irq;
125
Greg Ungerera405f832010-10-13 13:42:22 +1000126 if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX)) {
127 irq -= MCFINT_VECBASE;
128 if (intc_irqmap[irq].ack) {
129 u32 v;
Greg Ungererc986a3d2012-08-17 16:48:16 +1000130 v = readl(MCFSIM_PITR);
Greg Ungerera405f832010-10-13 13:42:22 +1000131 if (type == IRQ_TYPE_EDGE_FALLING)
132 v &= ~(0x1 << (32 - irq));
133 else
134 v |= (0x1 << (32 - irq));
Greg Ungererc986a3d2012-08-17 16:48:16 +1000135 writel(v, MCFSIM_PITR);
Greg Ungerera405f832010-10-13 13:42:22 +1000136 }
137 }
Greg Ungerer90752162009-07-07 09:39:11 +1000138 return 0;
139}
140
Greg Ungerera405f832010-10-13 13:42:22 +1000141/*
142 * Simple flow handler to deal with the external edge triggered interrupts.
143 * We need to be careful with the masking/acking due to the side effects
144 * of masking an interrupt.
145 */
146static void intc_external_irq(unsigned int irq, struct irq_desc *desc)
147{
Thomas Gleixner0b98b162011-03-28 13:31:17 +0200148 irq_desc_get_chip(desc)->irq_ack(&desc->irq_data);
Thomas Gleixnere6988f22011-02-06 23:39:14 +0000149 handle_simple_irq(irq, desc);
Greg Ungerera405f832010-10-13 13:42:22 +1000150}
151
Greg Ungerer90752162009-07-07 09:39:11 +1000152static struct irq_chip intc_irq_chip = {
153 .name = "CF-INTC",
Thomas Gleixner27301582011-02-06 23:39:28 +0000154 .irq_mask = intc_irq_mask,
155 .irq_unmask = intc_irq_unmask,
156 .irq_mask_ack = intc_irq_mask,
157 .irq_ack = intc_irq_ack,
158 .irq_set_type = intc_irq_set_type,
Greg Ungerer90752162009-07-07 09:39:11 +1000159};
160
161void __init init_IRQ(void)
162{
Greg Ungerera405f832010-10-13 13:42:22 +1000163 int irq, edge;
Greg Ungerer90752162009-07-07 09:39:11 +1000164
Greg Ungerer90752162009-07-07 09:39:11 +1000165 /* Mask all interrupt sources */
Greg Ungererc986a3d2012-08-17 16:48:16 +1000166 writel(0x88888888, MCFSIM_ICR1);
167 writel(0x88888888, MCFSIM_ICR2);
168 writel(0x88888888, MCFSIM_ICR3);
169 writel(0x88888888, MCFSIM_ICR4);
Greg Ungerer90752162009-07-07 09:39:11 +1000170
171 for (irq = 0; (irq < NR_IRQS); irq++) {
Thomas Gleixner0b98b162011-03-28 13:31:17 +0200172 irq_set_chip(irq, &intc_irq_chip);
Greg Ungerera405f832010-10-13 13:42:22 +1000173 edge = 0;
174 if ((irq >= MCFINT_VECBASE) && (irq <= MCFINT_VECMAX))
175 edge = intc_irqmap[irq - MCFINT_VECBASE].ack;
176 if (edge) {
Thomas Gleixner0b98b162011-03-28 13:31:17 +0200177 irq_set_irq_type(irq, IRQ_TYPE_EDGE_RISING);
178 irq_set_handler(irq, intc_external_irq);
Greg Ungerera405f832010-10-13 13:42:22 +1000179 } else {
Thomas Gleixner0b98b162011-03-28 13:31:17 +0200180 irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
181 irq_set_handler(irq, handle_level_irq);
Greg Ungerera405f832010-10-13 13:42:22 +1000182 }
Greg Ungerer90752162009-07-07 09:39:11 +1000183 }
184}
185