intc.c 3.4 KB
Newer Older
1
/*
2
 * intc.c  -- support for the old ColdFire interrupt controller
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * (C) Copyright 2009, Greg Ungerer <gerg@snapgear.com>
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive
 * for more details.
 */

#include <linux/types.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <asm/traps.h>
#include <asm/coldfire.h>
#include <asm/mcfsim.h>

21
/*
22 23 24 25 26 27 28 29 30 31 32
 * The mapping of irq number to a mask register bit is not one-to-one.
 * The irq numbers are either based on "level" of interrupt or fixed
 * for an autovector-able interrupt. So we keep a local data structure
 * that maps from irq to mask register. Not all interrupts will have
 * an IMR bit.
 */
unsigned char mcf_irq2imr[NR_IRQS];

/*
 * Define the miniumun and maximum external interrupt numbers.
 * This is also used as the "level" interrupt numbers.
33 34 35 36
 */
#define	EIRQ1	25
#define	EIRQ7	31

37 38 39
/*
 * In the early version 2 core ColdFire parts the IMR register was 16 bits
 * in size. Version 3 (and later version 2) core parts have a 32 bit
L
Lucas De Marchi 已提交
40
 * sized IMR register. Provide some size independent methods to access the
41 42 43 44 45 46
 * IMR register.
 */
#ifdef MCFSIM_IMR_IS_16BITS

void mcf_setimr(int index)
{
47
	u16 imr;
48 49
	imr = __raw_readw(MCFSIM_IMR);
	__raw_writew(imr | (0x1 << index), MCFSIM_IMR);
50 51 52 53
}

void mcf_clrimr(int index)
{
54
	u16 imr;
55 56
	imr = __raw_readw(MCFSIM_IMR);
	__raw_writew(imr & ~(0x1 << index), MCFSIM_IMR);
57 58 59 60 61
}

void mcf_maskimr(unsigned int mask)
{
	u16 imr;
62
	imr = __raw_readw(MCFSIM_IMR);
63
	imr |= mask;
64
	__raw_writew(imr, MCFSIM_IMR);
65 66 67 68 69 70
}

#else

void mcf_setimr(int index)
{
71
	u32 imr;
72 73
	imr = __raw_readl(MCFSIM_IMR);
	__raw_writel(imr | (0x1 << index), MCFSIM_IMR);
74 75 76 77
}

void mcf_clrimr(int index)
{
78
	u32 imr;
79 80
	imr = __raw_readl(MCFSIM_IMR);
	__raw_writel(imr & ~(0x1 << index), MCFSIM_IMR);
81 82 83 84 85
}

void mcf_maskimr(unsigned int mask)
{
	u32 imr;
86
	imr = __raw_readl(MCFSIM_IMR);
87
	imr |= mask;
88
	__raw_writel(imr, MCFSIM_IMR);
89 90 91 92
}

#endif

93 94 95 96 97 98 99 100 101 102 103
/*
 * Interrupts can be "vectored" on the ColdFire cores that support this old
 * interrupt controller. That is, the device raising the interrupt can also
 * supply the vector number to interrupt through. The AVR register of the
 * interrupt controller enables or disables this for each external interrupt,
 * so provide generic support for this. Setting this up is out-of-band for
 * the interrupt system API's, and needs to be done by the driver that
 * supports this device. Very few devices actually use this.
 */
void mcf_autovector(int irq)
{
104
#ifdef MCFSIM_AVR
105 106
	if ((irq >= EIRQ1) && (irq <= EIRQ7)) {
		u8 avec;
107
		avec = __raw_readb(MCFSIM_AVR);
108
		avec |= (0x1 << (irq - EIRQ1 + 1));
109
		__raw_writeb(avec, MCFSIM_AVR);
110
	}
111
#endif
112 113
}

114
static void intc_irq_mask(struct irq_data *d)
115
{
116 117
	if (mcf_irq2imr[d->irq])
		mcf_setimr(mcf_irq2imr[d->irq]);
118 119
}

120
static void intc_irq_unmask(struct irq_data *d)
121
{
122 123
	if (mcf_irq2imr[d->irq])
		mcf_clrimr(mcf_irq2imr[d->irq]);
124 125
}

126
static int intc_irq_set_type(struct irq_data *d, unsigned int type)
127 128 129 130 131 132
{
	return 0;
}

static struct irq_chip intc_irq_chip = {
	.name		= "CF-INTC",
133 134 135
	.irq_mask	= intc_irq_mask,
	.irq_unmask	= intc_irq_unmask,
	.irq_set_type	= intc_irq_set_type,
136 137 138 139 140 141
};

void __init init_IRQ(void)
{
	int irq;

142
	mcf_maskimr(0xffffffff);
143 144

	for (irq = 0; (irq < NR_IRQS); irq++) {
145 146 147
		irq_set_chip(irq, &intc_irq_chip);
		irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);
		irq_set_handler(irq, handle_level_irq);
148 149 150
	}
}