Merge branch 'upstream' of git://lost.foo-projects.org/~ahkok/git/netdev-2.6 into...
[pandora-kernel.git] / arch / mips / ddb5xxx / ddb5477 / irq.c
1 /*
2  * Copyright 2001 MontaVista Software Inc.
3  * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
4  *
5  *  arch/mips/ddb5xxx/ddb5477/irq.c
6  *     The irq setup and misc routines for DDB5476.
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  */
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/irq.h>
16 #include <linux/types.h>
17 #include <linux/ptrace.h>
18
19 #include <asm/i8259.h>
20 #include <asm/system.h>
21 #include <asm/mipsregs.h>
22 #include <asm/debug.h>
23 #include <asm/addrspace.h>
24 #include <asm/bootinfo.h>
25
26 #include <asm/ddb5xxx/ddb5xxx.h>
27
28
29 /*
30  * IRQ mapping
31  *
32  *  0-7: 8 CPU interrupts
33  *      0 -     software interrupt 0
34  *      1 -     software interrupt 1
35  *      2 -     most Vrc5477 interrupts are routed to this pin
36  *      3 -     (optional) some other interrupts routed to this pin for debugg
37  *      4 -     not used
38  *      5 -     not used
39  *      6 -     not used
40  *      7 -     cpu timer (used by default)
41  *
42  *  8-39: 32 Vrc5477 interrupt sources
43  *      (refer to the Vrc5477 manual)
44  */
45
46 #define PCI0                    DDB_INTPPES0
47 #define PCI1                    DDB_INTPPES1
48
49 #define ACTIVE_LOW              1
50 #define ACTIVE_HIGH             0
51
52 #define LEVEL_SENSE             2
53 #define EDGE_TRIGGER            0
54
55 #define INTA                    0
56 #define INTB                    1
57 #define INTC                    2
58 #define INTD                    3
59 #define INTE                    4
60
61 static inline void
62 set_pci_int_attr(u32 pci, u32 intn, u32 active, u32 trigger)
63 {
64         u32 reg_value;
65         u32 reg_bitmask;
66
67         reg_value = ddb_in32(pci);
68         reg_bitmask = 0x3 << (intn * 2);
69
70         reg_value &= ~reg_bitmask;
71         reg_value |= (active | trigger) << (intn * 2);
72         ddb_out32(pci, reg_value);
73 }
74
75 extern void vrc5477_irq_init(u32 base);
76 extern void mips_cpu_irq_init(u32 base);
77 extern int setup_irq(unsigned int irq, struct irqaction *irqaction);
78 static struct irqaction irq_cascade = { no_action, 0, CPU_MASK_NONE, "cascade", NULL, NULL };
79
80 void __init arch_init_irq(void)
81 {
82         /* by default, we disable all interrupts and route all vrc5477
83          * interrupts to pin 0 (irq 2) */
84         ddb_out32(DDB_INTCTRL0, 0);
85         ddb_out32(DDB_INTCTRL1, 0);
86         ddb_out32(DDB_INTCTRL2, 0);
87         ddb_out32(DDB_INTCTRL3, 0);
88
89         clear_c0_status(0xff00);
90         set_c0_status(0x0400);
91
92         /* setup PCI interrupt attributes */
93         set_pci_int_attr(PCI0, INTA, ACTIVE_LOW, LEVEL_SENSE);
94         set_pci_int_attr(PCI0, INTB, ACTIVE_LOW, LEVEL_SENSE);
95         if (mips_machtype == MACH_NEC_ROCKHOPPERII)
96                 set_pci_int_attr(PCI0, INTC, ACTIVE_HIGH, LEVEL_SENSE);
97         else
98                 set_pci_int_attr(PCI0, INTC, ACTIVE_LOW, LEVEL_SENSE);
99         set_pci_int_attr(PCI0, INTD, ACTIVE_LOW, LEVEL_SENSE);
100         set_pci_int_attr(PCI0, INTE, ACTIVE_LOW, LEVEL_SENSE);
101
102         set_pci_int_attr(PCI1, INTA, ACTIVE_LOW, LEVEL_SENSE);
103         set_pci_int_attr(PCI1, INTB, ACTIVE_LOW, LEVEL_SENSE);
104         set_pci_int_attr(PCI1, INTC, ACTIVE_LOW, LEVEL_SENSE);
105         set_pci_int_attr(PCI1, INTD, ACTIVE_LOW, LEVEL_SENSE);
106         set_pci_int_attr(PCI1, INTE, ACTIVE_LOW, LEVEL_SENSE);
107
108         /*
109          * for debugging purpose, we enable several error interrupts
110          * and route them to pin 1. (IP3)
111          */
112         /* cpu parity check - 0 */
113         ll_vrc5477_irq_route(0, 1); ll_vrc5477_irq_enable(0);
114         /* cpu no-target decode - 1 */
115         ll_vrc5477_irq_route(1, 1); ll_vrc5477_irq_enable(1);
116         /* local bus read time-out - 7 */
117         ll_vrc5477_irq_route(7, 1); ll_vrc5477_irq_enable(7);
118         /* PCI SERR# - 14 */
119         ll_vrc5477_irq_route(14, 1); ll_vrc5477_irq_enable(14);
120         /* PCI internal error - 15 */
121         ll_vrc5477_irq_route(15, 1); ll_vrc5477_irq_enable(15);
122         /* IOPCI SERR# - 30 */
123         ll_vrc5477_irq_route(30, 1); ll_vrc5477_irq_enable(30);
124         /* IOPCI internal error - 31 */
125         ll_vrc5477_irq_route(31, 1); ll_vrc5477_irq_enable(31);
126
127         /* init all controllers */
128         init_i8259_irqs();
129         mips_cpu_irq_init(CPU_IRQ_BASE);
130         vrc5477_irq_init(VRC5477_IRQ_BASE);
131
132
133         /* setup cascade interrupts */
134         setup_irq(VRC5477_IRQ_BASE + VRC5477_I8259_CASCADE, &irq_cascade);
135         setup_irq(CPU_IRQ_BASE + CPU_VRC5477_CASCADE, &irq_cascade);
136 }
137
138 u8 i8259_interrupt_ack(void)
139 {
140         u8 irq;
141         u32 reg;
142
143         /* Set window 0 for interrupt acknowledge */
144         reg = ddb_in32(DDB_PCIINIT10);
145
146         ddb_set_pmr(DDB_PCIINIT10, DDB_PCICMD_IACK, 0, DDB_PCI_ACCESS_32);
147         irq = *(volatile u8 *) KSEG1ADDR(DDB_PCI_IACK_BASE);
148         ddb_out32(DDB_PCIINIT10, reg);
149
150         /* i8259.c set the base vector to be 0x0 */
151         return irq + I8259_IRQ_BASE;
152 }
153 /*
154  * the first level int-handler will jump here if it is a vrc5477 irq
155  */
156 #define NUM_5477_IRQS   32
157 static void
158 vrc5477_irq_dispatch(struct pt_regs *regs)
159 {
160         u32 intStatus;
161         u32 bitmask;
162         u32 i;
163
164         db_assert(ddb_in32(DDB_INT2STAT) == 0);
165         db_assert(ddb_in32(DDB_INT3STAT) == 0);
166         db_assert(ddb_in32(DDB_INT4STAT) == 0);
167         db_assert(ddb_in32(DDB_NMISTAT) == 0);
168
169         if (ddb_in32(DDB_INT1STAT) != 0) {
170 #if defined(CONFIG_RUNTIME_DEBUG)
171                 vrc5477_show_int_regs();
172 #endif
173                 panic("error interrupt has happened.");
174         }
175
176         intStatus = ddb_in32(DDB_INT0STAT);
177
178         if (mips_machtype == MACH_NEC_ROCKHOPPERII) {
179                 /* check for i8259 interrupts */
180                 if (intStatus & (1 << VRC5477_I8259_CASCADE)) {
181                         int i8259_irq = i8259_interrupt_ack();
182                         do_IRQ(I8259_IRQ_BASE + i8259_irq, regs);
183                         return;
184                 }
185         }
186
187         for (i=0, bitmask=1; i<= NUM_5477_IRQS; bitmask <<=1, i++) {
188                 /* do we need to "and" with the int mask? */
189                 if (intStatus & bitmask) {
190                         do_IRQ(VRC5477_IRQ_BASE + i, regs);
191                         return;
192                 }
193         }
194 }
195
196 #define VR5477INTS (STATUSF_IP2|STATUSF_IP3|STATUSF_IP4|STATUSF_IP5|STATUSF_IP6)
197
198 asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
199 {
200         unsigned int pending = read_c0_cause() & read_c0_status();
201
202         if (pending & STATUSF_IP7)
203                 do_IRQ(CPU_IRQ_BASE + 7, regs);
204         else if (pending & VR5477INTS)
205                 vrc5477_irq_dispatch(regs);
206         else if (pending & STATUSF_IP0)
207                 do_IRQ(CPU_IRQ_BASE, regs);
208         else if (pending & STATUSF_IP1)
209                 do_IRQ(CPU_IRQ_BASE + 1, regs);
210         else
211                 spurious_interrupt(regs);
212 }