blob: 66d4e47dd8d0f7d41289f12e32c62cf41b5839e8 [file] [log] [blame]
Greg Ungerer2fba4f02009-04-27 15:38:03 +10001/*
Philippe De Muyter03cbc3852010-08-19 19:04:58 +02002 * intc-2.c
3 *
Philippe De Muyter88513382010-09-01 15:23:28 +02004 * General interrupt controller code for the many ColdFire cores that use
5 * interrupt controllers with 63 interrupt sources, organized as 56 fully-
6 * programmable + 7 fixed-level interrupt sources. This includes the 523x
7 * family, the 5270, 5271, 5274, 5275, and the 528x family which have two such
8 * controllers, and the 547x and 548x families which have only one of them.
Greg Ungerer2fba4f02009-04-27 15:38:03 +10009 *
10 * (C) Copyright 2009, Greg Ungerer <gerg@snapgear.com>
11 *
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file COPYING in the main directory of this archive
14 * for more details.
15 */
16
17#include <linux/types.h>
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/interrupt.h>
21#include <linux/irq.h>
22#include <linux/io.h>
23#include <asm/coldfire.h>
24#include <asm/mcfsim.h>
25#include <asm/traps.h>
26
27/*
Philippe De Muyter88513382010-09-01 15:23:28 +020028 * Bit definitions for the ICR family of registers.
Greg Ungerer2fba4f02009-04-27 15:38:03 +100029 */
Philippe De Muyter88513382010-09-01 15:23:28 +020030#define MCFSIM_ICR_LEVEL(l) ((l)<<3) /* Level l intr */
31#define MCFSIM_ICR_PRI(p) (p) /* Priority p intr */
32
Philippe De Muyter88513382010-09-01 15:23:28 +020033#ifdef MCFICM_INTC1
34#define NR_VECS 128
35#else
36#define NR_VECS 64
37#endif
Greg Ungerer2fba4f02009-04-27 15:38:03 +100038
Thomas Gleixner0bc0f3a2011-02-06 23:39:14 +000039static void intc_irq_mask(struct irq_data *d)
Greg Ungerer2fba4f02009-04-27 15:38:03 +100040{
Greg Ungerer49bc6de2011-03-07 17:21:43 +100041 unsigned int irq = d->irq - MCFINT_VECBASE;
42 unsigned long imraddr;
43 u32 val, imrbit;
Thomas Gleixner0bc0f3a2011-02-06 23:39:14 +000044
Philippe De Muyter88513382010-09-01 15:23:28 +020045#ifdef MCFICM_INTC1
Greg Ungerer49bc6de2011-03-07 17:21:43 +100046 imraddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
Philippe De Muyter88513382010-09-01 15:23:28 +020047#else
Greg Ungerer49bc6de2011-03-07 17:21:43 +100048 imraddr = MCFICM_INTC0;
Philippe De Muyter88513382010-09-01 15:23:28 +020049#endif
Greg Ungerer49bc6de2011-03-07 17:21:43 +100050 imraddr += (irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL;
51 imrbit = 0x1 << (irq & 0x1f);
Greg Ungerer2fba4f02009-04-27 15:38:03 +100052
Greg Ungerer49bc6de2011-03-07 17:21:43 +100053 val = __raw_readl(imraddr);
54 __raw_writel(val | imrbit, imraddr);
Greg Ungerer2fba4f02009-04-27 15:38:03 +100055}
56
Thomas Gleixner0bc0f3a2011-02-06 23:39:14 +000057static void intc_irq_unmask(struct irq_data *d)
Greg Ungerer2fba4f02009-04-27 15:38:03 +100058{
Greg Ungerer49bc6de2011-03-07 17:21:43 +100059 unsigned int irq = d->irq - MCFINT_VECBASE;
Greg Ungerer6d0f33f2011-03-07 17:42:28 +100060 unsigned long imraddr;
Greg Ungerer49bc6de2011-03-07 17:21:43 +100061 u32 val, imrbit;
Thomas Gleixner0bc0f3a2011-02-06 23:39:14 +000062
Philippe De Muyter88513382010-09-01 15:23:28 +020063#ifdef MCFICM_INTC1
Greg Ungerer6d0f33f2011-03-07 17:42:28 +100064 imraddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
Philippe De Muyter88513382010-09-01 15:23:28 +020065#else
Greg Ungerer6d0f33f2011-03-07 17:42:28 +100066 imraddr = MCFICM_INTC0;
Philippe De Muyter88513382010-09-01 15:23:28 +020067#endif
Greg Ungerer6d0f33f2011-03-07 17:42:28 +100068 imraddr += ((irq & 0x20) ? MCFINTC_IMRH : MCFINTC_IMRL);
Greg Ungerer49bc6de2011-03-07 17:21:43 +100069 imrbit = 0x1 << (irq & 0x1f);
Greg Ungerer2fba4f02009-04-27 15:38:03 +100070
Greg Ungerer49bc6de2011-03-07 17:21:43 +100071 /* Don't set the "maskall" bit! */
72 if ((irq & 0x20) == 0)
73 imrbit |= 0x1;
Greg Ungerer2fba4f02009-04-27 15:38:03 +100074
Greg Ungerer49bc6de2011-03-07 17:21:43 +100075 val = __raw_readl(imraddr);
76 __raw_writel(val & ~imrbit, imraddr);
Greg Ungerer2fba4f02009-04-27 15:38:03 +100077}
78
Thomas Gleixner0bc0f3a2011-02-06 23:39:14 +000079static int intc_irq_set_type(struct irq_data *d, unsigned int type)
Greg Ungerer04570b42010-09-09 17:12:53 +100080{
81 return 0;
82}
83
Greg Ungerer6d0f33f2011-03-07 17:42:28 +100084/*
85 * Each vector needs a unique priority and level associated with it.
86 * We don't really care so much what they are, we don't rely on the
87 * traditional priority interrupt scheme of the m68k/ColdFire. This
88 * only needs to be set once for an interrupt, and we will never change
89 * these values once we have set them.
90 */
91static u8 intc_intpri = MCFSIM_ICR_LEVEL(6) | MCFSIM_ICR_PRI(6);
92
93static unsigned int intc_irq_startup(struct irq_data *d)
94{
95 unsigned int irq = d->irq - MCFINT_VECBASE;
96 unsigned long icraddr;
97
98#ifdef MCFICM_INTC1
99 icraddr = (irq & 0x40) ? MCFICM_INTC1 : MCFICM_INTC0;
100#else
101 icraddr = MCFICM_INTC0;
102#endif
103 icraddr += MCFINTC_ICR0 + (irq & 0x3f);
104 if (__raw_readb(icraddr) == 0)
105 __raw_writeb(intc_intpri--, icraddr);
106
107 intc_irq_unmask(d);
108 return 0;
109}
110
Greg Ungerer2fba4f02009-04-27 15:38:03 +1000111static struct irq_chip intc_irq_chip = {
112 .name = "CF-INTC",
Greg Ungerer6d0f33f2011-03-07 17:42:28 +1000113 .irq_startup = intc_irq_startup,
Thomas Gleixner0bc0f3a2011-02-06 23:39:14 +0000114 .irq_mask = intc_irq_mask,
115 .irq_unmask = intc_irq_unmask,
116 .irq_set_type = intc_irq_set_type,
Greg Ungerer2fba4f02009-04-27 15:38:03 +1000117};
118
119void __init init_IRQ(void)
120{
121 int irq;
122
123 init_vectors();
124
125 /* Mask all interrupt sources */
Greg Ungerer254eef72011-03-05 22:17:17 +1000126 __raw_writel(0x1, MCFICM_INTC0 + MCFINTC_IMRL);
Philippe De Muyter88513382010-09-01 15:23:28 +0200127#ifdef MCFICM_INTC1
Greg Ungerer254eef72011-03-05 22:17:17 +1000128 __raw_writel(0x1, MCFICM_INTC1 + MCFINTC_IMRL);
Philippe De Muyter88513382010-09-01 15:23:28 +0200129#endif
Greg Ungerer2fba4f02009-04-27 15:38:03 +1000130
Greg Ungerer49bc6de2011-03-07 17:21:43 +1000131 for (irq = MCFINT_VECBASE; (irq < MCFINT_VECBASE + NR_VECS); irq++) {
Greg Ungerer04570b42010-09-09 17:12:53 +1000132 set_irq_chip(irq, &intc_irq_chip);
133 set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
134 set_irq_handler(irq, handle_level_irq);
Greg Ungerer2fba4f02009-04-27 15:38:03 +1000135 }
136}
137