blob: cce2574203885412b9c5f742405928f74fb0ae3b [file] [log] [blame]
Greg Ungerer33a21262009-04-30 16:22:24 +10001/*
Greg Ungererf2154be2009-05-19 14:38:08 +10002 * intc.c -- support for the old ColdFire interrupt controller
Greg Ungerer33a21262009-04-30 16:22:24 +10003 *
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>
15#include <linux/irq.h>
16#include <linux/io.h>
17#include <asm/traps.h>
18#include <asm/coldfire.h>
19#include <asm/mcfsim.h>
20
Greg Ungerer51879952009-05-19 14:08:47 +100021/*
Greg Ungerer39f0fb62009-05-22 13:33:35 +100022 * The mapping of irq number to a mask register bit is not one-to-one.
23 * The irq numbers are either based on "level" of interrupt or fixed
24 * for an autovector-able interrupt. So we keep a local data structure
25 * that maps from irq to mask register. Not all interrupts will have
26 * an IMR bit.
27 */
28unsigned char mcf_irq2imr[NR_IRQS];
29
30/*
31 * Define the miniumun and maximum external interrupt numbers.
32 * This is also used as the "level" interrupt numbers.
Greg Ungerer51879952009-05-19 14:08:47 +100033 */
34#define EIRQ1 25
35#define EIRQ7 31
36
37/*
Greg Ungererf2154be2009-05-19 14:38:08 +100038 * In the early version 2 core ColdFire parts the IMR register was 16 bits
39 * in size. Version 3 (and later version 2) core parts have a 32 bit
Lucas De Marchi25985ed2011-03-30 22:57:33 -030040 * sized IMR register. Provide some size independent methods to access the
Greg Ungererf2154be2009-05-19 14:38:08 +100041 * IMR register.
42 */
43#ifdef MCFSIM_IMR_IS_16BITS
44
45void mcf_setimr(int index)
46{
Greg Ungerer39f0fb62009-05-22 13:33:35 +100047 u16 imr;
Greg Ungerer6a3a7862012-07-15 21:42:47 +100048 imr = __raw_readw(MCFSIM_IMR);
49 __raw_writew(imr | (0x1 << index), MCFSIM_IMR);
Greg Ungererf2154be2009-05-19 14:38:08 +100050}
51
52void mcf_clrimr(int index)
53{
Greg Ungerer39f0fb62009-05-22 13:33:35 +100054 u16 imr;
Greg Ungerer6a3a7862012-07-15 21:42:47 +100055 imr = __raw_readw(MCFSIM_IMR);
56 __raw_writew(imr & ~(0x1 << index), MCFSIM_IMR);
Greg Ungererf2154be2009-05-19 14:38:08 +100057}
58
59void mcf_maskimr(unsigned int mask)
60{
61 u16 imr;
Greg Ungerer6a3a7862012-07-15 21:42:47 +100062 imr = __raw_readw(MCFSIM_IMR);
Greg Ungererf2154be2009-05-19 14:38:08 +100063 imr |= mask;
Greg Ungerer6a3a7862012-07-15 21:42:47 +100064 __raw_writew(imr, MCFSIM_IMR);
Greg Ungererf2154be2009-05-19 14:38:08 +100065}
66
67#else
68
69void mcf_setimr(int index)
70{
Greg Ungerer39f0fb62009-05-22 13:33:35 +100071 u32 imr;
Greg Ungerer6a3a7862012-07-15 21:42:47 +100072 imr = __raw_readl(MCFSIM_IMR);
73 __raw_writel(imr | (0x1 << index), MCFSIM_IMR);
Greg Ungererf2154be2009-05-19 14:38:08 +100074}
75
76void mcf_clrimr(int index)
77{
Greg Ungerer39f0fb62009-05-22 13:33:35 +100078 u32 imr;
Greg Ungerer6a3a7862012-07-15 21:42:47 +100079 imr = __raw_readl(MCFSIM_IMR);
80 __raw_writel(imr & ~(0x1 << index), MCFSIM_IMR);
Greg Ungererf2154be2009-05-19 14:38:08 +100081}
82
83void mcf_maskimr(unsigned int mask)
84{
85 u32 imr;
Greg Ungerer6a3a7862012-07-15 21:42:47 +100086 imr = __raw_readl(MCFSIM_IMR);
Greg Ungererf2154be2009-05-19 14:38:08 +100087 imr |= mask;
Greg Ungerer6a3a7862012-07-15 21:42:47 +100088 __raw_writel(imr, MCFSIM_IMR);
Greg Ungererf2154be2009-05-19 14:38:08 +100089}
90
91#endif
92
93/*
Greg Ungerer51879952009-05-19 14:08:47 +100094 * Interrupts can be "vectored" on the ColdFire cores that support this old
95 * interrupt controller. That is, the device raising the interrupt can also
96 * supply the vector number to interrupt through. The AVR register of the
97 * interrupt controller enables or disables this for each external interrupt,
98 * so provide generic support for this. Setting this up is out-of-band for
99 * the interrupt system API's, and needs to be done by the driver that
100 * supports this device. Very few devices actually use this.
101 */
102void mcf_autovector(int irq)
103{
Greg Ungerer39f0fb62009-05-22 13:33:35 +1000104#ifdef MCFSIM_AVR
Greg Ungerer51879952009-05-19 14:08:47 +1000105 if ((irq >= EIRQ1) && (irq <= EIRQ7)) {
106 u8 avec;
Greg Ungerer6a3a7862012-07-15 21:42:47 +1000107 avec = __raw_readb(MCFSIM_AVR);
Greg Ungerer51879952009-05-19 14:08:47 +1000108 avec |= (0x1 << (irq - EIRQ1 + 1));
Greg Ungerer6a3a7862012-07-15 21:42:47 +1000109 __raw_writeb(avec, MCFSIM_AVR);
Greg Ungerer51879952009-05-19 14:08:47 +1000110 }
Greg Ungerer39f0fb62009-05-22 13:33:35 +1000111#endif
Greg Ungerer51879952009-05-19 14:08:47 +1000112}
113
Thomas Gleixnerc2ff7c72011-02-06 23:39:14 +0000114static void intc_irq_mask(struct irq_data *d)
Greg Ungerer33a21262009-04-30 16:22:24 +1000115{
Thomas Gleixnerc2ff7c72011-02-06 23:39:14 +0000116 if (mcf_irq2imr[d->irq])
117 mcf_setimr(mcf_irq2imr[d->irq]);
Greg Ungerer33a21262009-04-30 16:22:24 +1000118}
119
Thomas Gleixnerc2ff7c72011-02-06 23:39:14 +0000120static void intc_irq_unmask(struct irq_data *d)
Greg Ungerer33a21262009-04-30 16:22:24 +1000121{
Thomas Gleixnerc2ff7c72011-02-06 23:39:14 +0000122 if (mcf_irq2imr[d->irq])
123 mcf_clrimr(mcf_irq2imr[d->irq]);
Greg Ungerer33a21262009-04-30 16:22:24 +1000124}
125
Thomas Gleixnerc2ff7c72011-02-06 23:39:14 +0000126static int intc_irq_set_type(struct irq_data *d, unsigned int type)
Greg Ungerer33a21262009-04-30 16:22:24 +1000127{
128 return 0;
129}
130
131static struct irq_chip intc_irq_chip = {
132 .name = "CF-INTC",
Thomas Gleixnerc2ff7c72011-02-06 23:39:14 +0000133 .irq_mask = intc_irq_mask,
134 .irq_unmask = intc_irq_unmask,
135 .irq_set_type = intc_irq_set_type,
Greg Ungerer33a21262009-04-30 16:22:24 +1000136};
137
138void __init init_IRQ(void)
139{
140 int irq;
141
Greg Ungererf2154be2009-05-19 14:38:08 +1000142 mcf_maskimr(0xffffffff);
Greg Ungerer33a21262009-04-30 16:22:24 +1000143
144 for (irq = 0; (irq < NR_IRQS); irq++) {
Thomas Gleixner0b98b162011-03-28 13:31:17 +0200145 irq_set_chip(irq, &intc_irq_chip);
146 irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
147 irq_set_handler(irq, handle_level_irq);
Greg Ungerer33a21262009-04-30 16:22:24 +1000148 }
149}
150