2 * Ralink SoC Interrupt controller routines
4 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/irq.h>
16 #include <linux/bitops.h>
18 #include <asm/irq_cpu.h>
19 #include <asm/mipsregs.h>
21 #include <asm/mach-ralink/common.h>
23 /* INTC register offsets */
24 #define INTC_REG_STATUS0 0x00
25 #define INTC_REG_STATUS1 0x04
26 #define INTC_REG_TYPE 0x20
27 #define INTC_REG_RAW_STATUS 0x30
28 #define INTC_REG_ENABLE 0x34
29 #define INTC_REG_DISABLE 0x38
31 #define INTC_INT_GLOBAL BIT(31)
32 #define INTC_IRQ_COUNT 32
34 static unsigned int ramips_intc_irq_base
;
35 static void __iomem
*ramips_intc_base
;
37 static inline void ramips_intc_wr(u32 val
, unsigned reg
)
39 __raw_writel(val
, ramips_intc_base
+ reg
);
42 static inline u32
ramips_intc_rr(unsigned reg
)
44 return __raw_readl(ramips_intc_base
+ reg
);
47 static void ramips_intc_irq_unmask(struct irq_data
*d
)
49 unsigned int irq
= d
->irq
- ramips_intc_irq_base
;
51 ramips_intc_wr((1 << irq
), INTC_REG_ENABLE
);
54 static void ramips_intc_irq_mask(struct irq_data
*d
)
56 unsigned int irq
= d
->irq
- ramips_intc_irq_base
;
58 ramips_intc_wr((1 << irq
), INTC_REG_DISABLE
);
61 static struct irq_chip ramips_intc_irq_chip
= {
63 .irq_unmask
= ramips_intc_irq_unmask
,
64 .irq_mask
= ramips_intc_irq_mask
,
65 .irq_mask_ack
= ramips_intc_irq_mask
,
68 static struct irqaction ramips_intc_irqaction
= {
70 .name
= "cascade [INTC]",
73 void __init
ramips_intc_irq_init(unsigned intc_base
, unsigned irq
,
78 ramips_intc_base
= ioremap_nocache(intc_base
, PAGE_SIZE
);
79 ramips_intc_irq_base
= irq_base
;
81 /* disable all interrupts */
82 ramips_intc_wr(~0, INTC_REG_DISABLE
);
84 /* route all INTC interrupts to MIPS HW0 interrupt */
85 ramips_intc_wr(0, INTC_REG_TYPE
);
87 for (i
= ramips_intc_irq_base
;
88 i
< ramips_intc_irq_base
+ INTC_IRQ_COUNT
; i
++)
89 irq_set_chip_and_handler(i
, &ramips_intc_irq_chip
,
92 setup_irq(irq
, &ramips_intc_irqaction
);
93 ramips_intc_wr(INTC_INT_GLOBAL
, INTC_REG_ENABLE
);
96 u32
ramips_intc_get_status(void)
98 return ramips_intc_rr(INTC_REG_STATUS0
);