Path: blob/master/arch/m68k/platform/coldfire/intc-simr.c
10819 views
/*1* intc-simr.c2*3* Interrupt controller code for the ColdFire 5208, 5207 & 532x parts.4*5* (C) Copyright 2009-2011, Greg Ungerer <[email protected]>6*7* This file is subject to the terms and conditions of the GNU General Public8* License. See the file COPYING in the main directory of this archive9* for more details.10*/1112#include <linux/types.h>13#include <linux/init.h>14#include <linux/kernel.h>15#include <linux/interrupt.h>16#include <linux/irq.h>17#include <linux/io.h>18#include <asm/coldfire.h>19#include <asm/mcfsim.h>20#include <asm/traps.h>2122/*23* The EDGE Port interrupts are the fixed 7 external interrupts.24* They need some special treatment, for example they need to be acked.25*/26#ifdef CONFIG_M520x27/*28* The 520x parts only support a limited range of these external29* interrupts, only 1, 4 and 7 (as interrupts 65, 66 and 67).30*/31#define EINT0 64 /* Is not actually used, but spot reserved for it */32#define EINT1 65 /* EDGE Port interrupt 1 */33#define EINT4 66 /* EDGE Port interrupt 4 */34#define EINT7 67 /* EDGE Port interrupt 7 */3536static unsigned int irqebitmap[] = { 0, 1, 4, 7 };37static unsigned int inline irq2ebit(unsigned int irq)38{39return irqebitmap[irq - EINT0];40}4142#else4344/*45* Most of the ColdFire parts with the EDGE Port module just have46* a strait direct mapping of the 7 external interrupts. Although47* there is a bit reserved for 0, it is not used.48*/49#define EINT0 64 /* Is not actually used, but spot reserved for it */50#define EINT1 65 /* EDGE Port interrupt 1 */51#define EINT7 71 /* EDGE Port interrupt 7 */5253static unsigned int inline irq2ebit(unsigned int irq)54{55return irq - EINT0;56}5758#endif5960/*61* There maybe one or two interrupt control units, each has 6462* interrupts. If there is no second unit then MCFINTC1_* defines63* will be 0 (and code for them optimized away).64*/6566static void intc_irq_mask(struct irq_data *d)67{68unsigned int irq = d->irq - MCFINT_VECBASE;6970if (MCFINTC1_SIMR && (irq > 64))71__raw_writeb(irq - 64, MCFINTC1_SIMR);72else73__raw_writeb(irq, MCFINTC0_SIMR);74}7576static void intc_irq_unmask(struct irq_data *d)77{78unsigned int irq = d->irq - MCFINT_VECBASE;7980if (MCFINTC1_CIMR && (irq > 64))81__raw_writeb(irq - 64, MCFINTC1_CIMR);82else83__raw_writeb(irq, MCFINTC0_CIMR);84}8586static void intc_irq_ack(struct irq_data *d)87{88unsigned int ebit = irq2ebit(d->irq);8990__raw_writeb(0x1 << ebit, MCFEPORT_EPFR);91}9293static unsigned int intc_irq_startup(struct irq_data *d)94{95unsigned int irq = d->irq;9697if ((irq >= EINT1) && (irq <= EINT7)) {98unsigned int ebit = irq2ebit(irq);99u8 v;100101/* Set EPORT line as input */102v = __raw_readb(MCFEPORT_EPDDR);103__raw_writeb(v & ~(0x1 << ebit), MCFEPORT_EPDDR);104105/* Set EPORT line as interrupt source */106v = __raw_readb(MCFEPORT_EPIER);107__raw_writeb(v | (0x1 << ebit), MCFEPORT_EPIER);108}109110irq -= MCFINT_VECBASE;111if (MCFINTC1_ICR0 && (irq > 64))112__raw_writeb(5, MCFINTC1_ICR0 + irq - 64);113else114__raw_writeb(5, MCFINTC0_ICR0 + irq);115116117intc_irq_unmask(d);118return 0;119}120121static int intc_irq_set_type(struct irq_data *d, unsigned int type)122{123unsigned int ebit, irq = d->irq;124u16 pa, tb;125126switch (type) {127case IRQ_TYPE_EDGE_RISING:128tb = 0x1;129break;130case IRQ_TYPE_EDGE_FALLING:131tb = 0x2;132break;133case IRQ_TYPE_EDGE_BOTH:134tb = 0x3;135break;136default:137/* Level triggered */138tb = 0;139break;140}141142if (tb)143irq_set_handler(irq, handle_edge_irq);144145ebit = irq2ebit(irq) * 2;146pa = __raw_readw(MCFEPORT_EPPAR);147pa = (pa & ~(0x3 << ebit)) | (tb << ebit);148__raw_writew(pa, MCFEPORT_EPPAR);149150return 0;151}152153static struct irq_chip intc_irq_chip = {154.name = "CF-INTC",155.irq_startup = intc_irq_startup,156.irq_mask = intc_irq_mask,157.irq_unmask = intc_irq_unmask,158};159160static struct irq_chip intc_irq_chip_edge_port = {161.name = "CF-INTC-EP",162.irq_startup = intc_irq_startup,163.irq_mask = intc_irq_mask,164.irq_unmask = intc_irq_unmask,165.irq_ack = intc_irq_ack,166.irq_set_type = intc_irq_set_type,167};168169void __init init_IRQ(void)170{171int irq, eirq;172173init_vectors();174175/* Mask all interrupt sources */176__raw_writeb(0xff, MCFINTC0_SIMR);177if (MCFINTC1_SIMR)178__raw_writeb(0xff, MCFINTC1_SIMR);179180eirq = MCFINT_VECBASE + 64 + (MCFINTC1_ICR0 ? 64 : 0);181for (irq = MCFINT_VECBASE; (irq < eirq); irq++) {182if ((irq >= EINT1) && (irq <= EINT7))183irq_set_chip(irq, &intc_irq_chip_edge_port);184else185irq_set_chip(irq, &intc_irq_chip);186irq_set_irq_type(irq, IRQ_TYPE_LEVEL_HIGH);187irq_set_handler(irq, handle_level_irq);188}189}190191192193