3 Copyright 2002 Broadcom Corp. All Rights Reserved.
5 This program is free software; you can distribute it and/or modify it
6 under the terms of the GNU General Public License (Version 2) as
7 published by the Free Software Foundation.
9 This program is distributed in the hope it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
20 * Interrupt control functions for Broadcom 963xx MIPS boards
23 #include <asm/atomic.h>
25 #include <linux/delay.h>
26 #include <linux/init.h>
27 #include <linux/ioport.h>
28 #include <linux/irq.h>
29 #include <linux/interrupt.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/module.h>
35 #include <asm/mipsregs.h>
36 #include <asm/addrspace.h>
37 #include <asm/signal.h>
38 #include <bcm_map_part.h>
41 extern asmlinkage unsigned int do_IRQ(int irq, struct pt_regs *regs);
43 static void irq_dispatch_int(struct pt_regs *regs)
45 unsigned int pendingIrqs;
46 static unsigned int irqBit;
47 static unsigned int isrNumber = 31;
49 pendingIrqs = PERF->IrqStatus & PERF->IrqMask;
51 printk("***no pending IRQ***\n");
58 if (isrNumber == 32) {
62 if (pendingIrqs & irqBit) {
63 PERF->IrqMask &= ~irqBit; // mask
64 do_IRQ(isrNumber + INTERNAL_ISR_TABLE_OFFSET, regs);
70 static void irq_dispatch_ext(uint32 irq, struct pt_regs *regs)
72 if (!(PERF->ExtIrqCfg & (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT)))) {
73 printk("**** Ext IRQ mask. Should not dispatch ****\n");
75 /* disable and clear interrupt in the controller */
76 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT));
77 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
81 void brcm_irq_dispatch(struct pt_regs *regs)
84 while((cause = (read_c0_cause()& CAUSEF_IP))) {
85 if (cause & CAUSEF_IP7)
86 do_IRQ(MIPS_TIMER_INT, regs);
87 else if (cause & CAUSEF_IP2)
88 irq_dispatch_int(regs);
89 else if (cause & CAUSEF_IP3)
90 irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_0, regs);
91 else if (cause & CAUSEF_IP4)
92 irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_1, regs);
93 else if (cause & CAUSEF_IP5)
94 irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_2, regs);
95 else if (cause & CAUSEF_IP6)
96 irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_3, regs);
102 void enable_brcm_irq(unsigned int irq)
106 local_irq_save(flags);
107 if( irq >= INTERNAL_ISR_TABLE_OFFSET ) {
108 PERF->IrqMask |= (1 << (irq - INTERNAL_ISR_TABLE_OFFSET));
110 else if (irq >= INTERRUPT_ID_EXTERNAL_0 && irq <= INTERRUPT_ID_EXTERNAL_3) {
111 /* enable and clear interrupt in the controller */
112 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT));
113 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
115 local_irq_restore(flags);
118 void disable_brcm_irq(unsigned int irq)
122 local_irq_save(flags);
123 if( irq >= INTERNAL_ISR_TABLE_OFFSET ) {
124 PERF->IrqMask &= ~(1 << (irq - INTERNAL_ISR_TABLE_OFFSET));
126 else if (irq >= INTERRUPT_ID_EXTERNAL_0 && irq <= INTERRUPT_ID_EXTERNAL_3) {
127 /* disable interrupt in the controller */
128 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
130 local_irq_restore(flags);
133 void ack_brcm_irq(unsigned int irq)
135 /* Already done in brcm_irq_dispatch */
138 unsigned int startup_brcm_irq(unsigned int irq)
140 enable_brcm_irq(irq);
142 return 0; /* never anything pending */
145 unsigned int startup_brcm_none(unsigned int irq)
150 void end_brcm_irq(unsigned int irq)
152 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
153 enable_brcm_irq(irq);
156 void end_brcm_none(unsigned int irq)
160 #define ALLINTS_NOTIMER (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4)
162 static void __init brcm_irq_setup(void)
164 extern asmlinkage void brcmIRQ(void);
166 clear_c0_status(ST0_BEV);
167 set_except_vector(0, brcmIRQ);
168 change_c0_status(ST0_IM, ALLINTS_NOTIMER);
170 #ifdef CONFIG_REMOTE_DEBUG
175 static struct hw_interrupt_type brcm_irq_type = {
177 .startup = startup_brcm_irq,
178 .shutdown = disable_brcm_irq,
179 .enable = enable_brcm_irq,
180 .disable = disable_brcm_irq,
186 static struct hw_interrupt_type brcm_irq_no_end_type = {
188 .startup = startup_brcm_none,
189 .shutdown = disable_brcm_irq,
190 .enable = enable_brcm_irq,
191 .disable = disable_brcm_irq,
193 .end = end_brcm_none,
197 void __init arch_init_irq(void)
201 for (i = 0; i < NR_IRQS; i++) {
202 irq_desc[i].status = IRQ_DISABLED;
203 irq_desc[i].action = 0;
204 irq_desc[i].depth = 1;
205 irq_desc[i].handler = &brcm_irq_type;
211 int request_external_irq(unsigned int irq,
213 unsigned long irqflags,
214 const char * devname,
219 local_irq_save(flags);
221 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT)); // Clear
222 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT)); // Mask
223 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_INSENS_SHFT)); // Edge insesnsitive
224 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_LEVEL_SHFT)); // Level triggered
225 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_SENSE_SHFT)); // Low level
227 local_irq_restore(flags);
229 return( request_irq(irq, handler, irqflags, devname, dev_id) );
232 /* VxWorks compatibility function(s). */
234 unsigned int BcmHalMapInterrupt(FN_HANDLER pfunc, unsigned int param,
235 unsigned int interruptId)
240 devname = kmalloc(16, GFP_KERNEL);
242 sprintf( devname, "brcm_%d", interruptId );
244 /* Set the IRQ description to not automatically enable the interrupt at
245 * the end of an ISR. The driver that handles the interrupt must
246 * explicitly call BcmHalInterruptEnable or enable_brcm_irq. This behavior
247 * is consistent with interrupt handling on VxWorks.
249 irq_desc[interruptId].handler = &brcm_irq_no_end_type;
251 if( interruptId >= INTERNAL_ISR_TABLE_OFFSET )
253 nRet = request_irq( interruptId, pfunc, SA_SAMPLE_RANDOM | SA_INTERRUPT,
254 devname, (void *) param );
256 else if (interruptId >= INTERRUPT_ID_EXTERNAL_0 && interruptId <= INTERRUPT_ID_EXTERNAL_3)
258 nRet = request_external_irq( interruptId, pfunc, SA_SAMPLE_RANDOM | SA_INTERRUPT,
259 devname, (void *) param );
266 /* Debug function. */
268 void dump_intr_regs(void)
270 printk("PERF->ExtIrqCfg [%08x]\n", *(&(PERF->ExtIrqCfg)));
273 EXPORT_SYMBOL(enable_brcm_irq);
274 EXPORT_SYMBOL(disable_brcm_irq);
275 EXPORT_SYMBOL(request_external_irq);
276 EXPORT_SYMBOL(BcmHalMapInterrupt);