Path: blob/master/arch/m68k/platform/coldfire/intc.c
10819 views
/*1* intc.c -- support for the old ColdFire interrupt controller2*3* (C) Copyright 2009, Greg Ungerer <[email protected]>4*5* This file is subject to the terms and conditions of the GNU General Public6* License. See the file COPYING in the main directory of this archive7* for more details.8*/910#include <linux/types.h>11#include <linux/init.h>12#include <linux/kernel.h>13#include <linux/interrupt.h>14#include <linux/irq.h>15#include <linux/io.h>16#include <asm/traps.h>17#include <asm/coldfire.h>18#include <asm/mcfsim.h>1920/*21* The mapping of irq number to a mask register bit is not one-to-one.22* The irq numbers are either based on "level" of interrupt or fixed23* for an autovector-able interrupt. So we keep a local data structure24* that maps from irq to mask register. Not all interrupts will have25* an IMR bit.26*/27unsigned char mcf_irq2imr[NR_IRQS];2829/*30* Define the miniumun and maximum external interrupt numbers.31* This is also used as the "level" interrupt numbers.32*/33#define EIRQ1 2534#define EIRQ7 313536/*37* In the early version 2 core ColdFire parts the IMR register was 16 bits38* in size. Version 3 (and later version 2) core parts have a 32 bit39* sized IMR register. Provide some size independent methods to access the40* IMR register.41*/42#ifdef MCFSIM_IMR_IS_16BITS4344void mcf_setimr(int index)45{46u16 imr;47imr = __raw_readw(MCF_MBAR + MCFSIM_IMR);48__raw_writew(imr | (0x1 << index), MCF_MBAR + MCFSIM_IMR);49}5051void mcf_clrimr(int index)52{53u16 imr;54imr = __raw_readw(MCF_MBAR + MCFSIM_IMR);55__raw_writew(imr & ~(0x1 << index), MCF_MBAR + MCFSIM_IMR);56}5758void mcf_maskimr(unsigned int mask)59{60u16 imr;61imr = __raw_readw(MCF_MBAR + MCFSIM_IMR);62imr |= mask;63__raw_writew(imr, MCF_MBAR + MCFSIM_IMR);64}6566#else6768void mcf_setimr(int index)69{70u32 imr;71imr = __raw_readl(MCF_MBAR + MCFSIM_IMR);72__raw_writel(imr | (0x1 << index), MCF_MBAR + MCFSIM_IMR);73}7475void mcf_clrimr(int index)76{77u32 imr;78imr = __raw_readl(MCF_MBAR + MCFSIM_IMR);79__raw_writel(imr & ~(0x1 << index), MCF_MBAR + MCFSIM_IMR);80}8182void mcf_maskimr(unsigned int mask)83{84u32 imr;85imr = __raw_readl(MCF_MBAR + MCFSIM_IMR);86imr |= mask;87__raw_writel(imr, MCF_MBAR + MCFSIM_IMR);88}8990#endif9192/*93* Interrupts can be "vectored" on the ColdFire cores that support this old94* interrupt controller. That is, the device raising the interrupt can also95* supply the vector number to interrupt through. The AVR register of the96* interrupt controller enables or disables this for each external interrupt,97* so provide generic support for this. Setting this up is out-of-band for98* the interrupt system API's, and needs to be done by the driver that99* supports this device. Very few devices actually use this.100*/101void mcf_autovector(int irq)102{103#ifdef MCFSIM_AVR104if ((irq >= EIRQ1) && (irq <= EIRQ7)) {105u8 avec;106avec = __raw_readb(MCF_MBAR + MCFSIM_AVR);107avec |= (0x1 << (irq - EIRQ1 + 1));108__raw_writeb(avec, MCF_MBAR + MCFSIM_AVR);109}110#endif111}112113static void intc_irq_mask(struct irq_data *d)114{115if (mcf_irq2imr[d->irq])116mcf_setimr(mcf_irq2imr[d->irq]);117}118119static void intc_irq_unmask(struct irq_data *d)120{121if (mcf_irq2imr[d->irq])122mcf_clrimr(mcf_irq2imr[d->irq]);123}124125static int intc_irq_set_type(struct irq_data *d, unsigned int type)126{127return 0;128}129130static struct irq_chip intc_irq_chip = {131.name = "CF-INTC",132.irq_mask = intc_irq_mask,133.irq_unmask = intc_irq_unmask,134.irq_set_type = intc_irq_set_type,135};136137void __init init_IRQ(void)138{139int irq;140141init_vectors();142mcf_maskimr(0xffffffff);143144for (irq = 0; (irq < NR_IRQS); irq++) {145irq_set_chip(irq, &intc_irq_chip);146irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);147irq_set_handler(irq, handle_level_irq);148}149}150151152153