4 * Copyright (C) 2006, 2007 OpenWrt.org
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/ioport.h>
26 #include <asm/irq_cpu.h>
27 #include <asm/mipsregs.h>
28 #include <asm/ar7/ar7.h>
30 #define EXCEPT_OFFSET 0x80
31 #define PACE_OFFSET 0xA0
32 #define CHNLS_OFFSET 0x200
34 #define IRQ_NUM(irq) (irq % 40 % 32)
35 #define REG_OFFSET(irq, reg) (((irq) < 40) ? \
36 ((irq) / 32 * 0x4 + reg * 0x10) : \
37 (EXCEPT_OFFSET + reg * 0x8))
38 #define SR_OFFSET(irq) (REG_OFFSET(irq, 0))
39 #define CR_OFFSET(irq) (REG_OFFSET(irq, 1))
40 #define ESR_OFFSET(irq) (REG_OFFSET(irq, 2))
41 #define ECR_OFFSET(irq) (REG_OFFSET(irq, 3))
42 #define PIR_OFFSET (0x40)
43 #define MSR_OFFSET (0x44)
44 #define PM_OFFSET(irq) (REG_OFFSET(irq, 5))
45 #define TM_OFFSET(irq) (REG_OFFSET(irq, 6))
47 #define REG(addr) (*(volatile u32 *)(KSEG1ADDR(AR7_REGS_IRQ) + addr))
49 #define CHNL_OFFSET(chnl) (CHNLS_OFFSET + (chnl * 4))
51 static void ar7_unmask_irq(unsigned int irq_nr);
52 static void ar7_mask_irq(unsigned int irq_nr);
53 static irqreturn_t ar7_cascade(int interrupt, void *dev);
54 void ar7_irq_init(int);
56 static struct irq_chip ar7_irq_type = {
58 .unmask = ar7_unmask_irq,
62 static int ar7_irq_base;
64 static struct irqaction ar7_cascade_action = {
65 .handler = ar7_cascade,
66 .name = "AR7 cascade interrupt"
70 static void ar7_unmask_irq(unsigned int irq)
73 local_irq_save(flags);
74 /* enable the interrupt channel bit */
75 REG(ESR_OFFSET(irq - ar7_irq_base)) = 1 << IRQ_NUM(irq - ar7_irq_base);
76 local_irq_restore(flags);
79 static void ar7_mask_irq(unsigned int irq)
82 local_irq_save(flags);
83 /* disable the interrupt channel bit */
84 REG(ECR_OFFSET(irq - ar7_irq_base)) = 1 << IRQ_NUM(irq - ar7_irq_base);
85 local_irq_restore(flags);
88 void __init arch_init_irq(void) {
93 void __init ar7_irq_init(int base)
97 Disable interrupts and clear pending
99 REG(ECR_OFFSET(0)) = 0xffffffff;
100 REG(ECR_OFFSET(32)) = 0xff;
101 REG(ECR_OFFSET(40)) = 0xffffffff;
102 REG(CR_OFFSET(0)) = 0xffffffff;
103 REG(CR_OFFSET(32)) = 0xff;
104 REG(CR_OFFSET(40)) = 0xffffffff;
106 for(i = 0; i < 40; i++) {
107 REG(CHNL_OFFSET(i)) = i;
109 irq_desc[i + base].status = IRQ_DISABLED;
110 irq_desc[i + base].action = 0;
111 irq_desc[i + base].depth = 1;
112 irq_desc[i + base].chip = &ar7_irq_type;
113 /* Secondary IRQ's */
115 irq_desc[i + base + 40].status = IRQ_DISABLED;
116 irq_desc[i + base + 40].action = 0;
117 irq_desc[i + base + 40].depth = 1;
118 irq_desc[i + base + 40].chip =
124 setup_irq(2, &ar7_cascade_action);
125 set_c0_status(IE_IRQ0);
128 static irqreturn_t ar7_cascade(int interrupt, void *dev)
131 unsigned long status;
133 irq = (REG(PIR_OFFSET) & 0x3F);
134 if (irq == 40) return IRQ_NONE;
136 REG(CR_OFFSET(irq)) = 1 << IRQ_NUM(irq);
138 status = REG(SR_OFFSET(40));
139 for (i = 0; i < 32; i++) {
140 if (status & (i << 1)) {
142 REG(CR_OFFSET(irq)) = 1 << i;
146 REG(CR_OFFSET(0)) = 1;
148 return do_IRQ(irq + ar7_irq_base);
151 asmlinkage void plat_irq_dispatch(void)
153 unsigned int pending = read_c0_status() & read_c0_cause();
154 if (pending & STATUSF_IP7) /* cpu timer */
156 else if (pending & STATUSF_IP2) /* int0 hardware line */
159 spurious_interrupt();