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 <6348_map_part.h>
39 #include <6348_intr.h>
40 #include <bcm_map_part.h>
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;
57 if (isrNumber == 32) {
61 if (pendingIrqs & irqBit) {
62 PERF->IrqMask &= ~irqBit; // mask
63 do_IRQ(isrNumber + INTERNAL_ISR_TABLE_OFFSET);
69 static void irq_dispatch_ext(uint32 irq)
71 if (!(PERF->ExtIrqCfg & (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT)))) {
72 printk("**** Ext IRQ mask. Should not dispatch ****\n");
74 /* disable and clear interrupt in the controller */
75 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT));
76 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
81 extern void brcm_timer_interrupt(struct pt_regs *regs);
83 asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
86 while((cause = (read_c0_cause()& CAUSEF_IP))) {
87 if (cause & CAUSEF_IP7)
88 brcm_timer_interrupt(regs);
89 else if (cause & CAUSEF_IP2)
90 irq_dispatch_int(regs);
91 else if (cause & CAUSEF_IP3)
92 irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_0);
93 else if (cause & CAUSEF_IP4)
94 irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_1);
95 else if (cause & CAUSEF_IP5)
96 irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_2);
97 else if (cause & CAUSEF_IP6)
98 irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_3);
104 void enable_brcm_irq(unsigned int irq)
108 local_irq_save(flags);
109 if( irq >= INTERNAL_ISR_TABLE_OFFSET ) {
110 PERF->IrqMask |= (1 << (irq - INTERNAL_ISR_TABLE_OFFSET));
112 else if (irq >= INTERRUPT_ID_EXTERNAL_0 && irq <= INTERRUPT_ID_EXTERNAL_3) {
113 /* enable and clear interrupt in the controller */
114 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT));
115 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
117 local_irq_restore(flags);
120 void disable_brcm_irq(unsigned int irq)
124 local_irq_save(flags);
125 if( irq >= INTERNAL_ISR_TABLE_OFFSET ) {
126 PERF->IrqMask &= ~(1 << (irq - INTERNAL_ISR_TABLE_OFFSET));
128 else if (irq >= INTERRUPT_ID_EXTERNAL_0 && irq <= INTERRUPT_ID_EXTERNAL_3) {
129 /* disable interrupt in the controller */
130 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
132 local_irq_restore(flags);
135 void ack_brcm_irq(unsigned int irq)
137 /* Already done in brcm_irq_dispatch */
140 unsigned int startup_brcm_irq(unsigned int irq)
142 enable_brcm_irq(irq);
144 return 0; /* never anything pending */
147 unsigned int startup_brcm_none(unsigned int irq)
152 void end_brcm_irq(unsigned int irq)
154 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
155 enable_brcm_irq(irq);
158 void end_brcm_none(unsigned int irq)
162 static struct hw_interrupt_type brcm_irq_type = {
164 .startup = startup_brcm_irq,
165 .shutdown = disable_brcm_irq,
166 .enable = enable_brcm_irq,
167 .disable = disable_brcm_irq,
173 static struct hw_interrupt_type brcm_irq_no_end_type = {
175 .startup = startup_brcm_none,
176 .shutdown = disable_brcm_irq,
177 .enable = enable_brcm_irq,
178 .disable = disable_brcm_irq,
180 .end = end_brcm_none,
184 void __init arch_init_irq(void)
188 clear_c0_status(ST0_BEV);
189 change_c0_status(ST0_IM, (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4));
191 for (i = 0; i < NR_IRQS; i++) {
192 irq_desc[i].status = IRQ_DISABLED;
193 irq_desc[i].action = 0;
194 irq_desc[i].depth = 1;
195 irq_desc[i].chip = &brcm_irq_type;
199 int request_external_irq(unsigned int irq,
201 unsigned long irqflags,
202 const char * devname,
207 local_irq_save(flags);
209 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT)); // Clear
210 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT)); // Mask
211 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_INSENS_SHFT)); // Edge insesnsitive
212 PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_LEVEL_SHFT)); // Level triggered
213 PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_SENSE_SHFT)); // Low level
215 local_irq_restore(flags);
217 return( request_irq(irq, handler, irqflags, devname, dev_id) );
220 /* VxWorks compatibility function(s). */
222 unsigned int BcmHalMapInterrupt(FN_HANDLER pfunc, unsigned int param,
223 unsigned int interruptId)
228 devname = kmalloc(16, GFP_KERNEL);
230 sprintf( devname, "brcm_%d", interruptId );
232 /* Set the IRQ description to not automatically enable the interrupt at
233 * the end of an ISR. The driver that handles the interrupt must
234 * explicitly call BcmHalInterruptEnable or enable_brcm_irq. This behavior
235 * is consistent with interrupt handling on VxWorks.
237 irq_desc[interruptId].chip = &brcm_irq_no_end_type;
239 if( interruptId >= INTERNAL_ISR_TABLE_OFFSET )
241 printk("BcmHalMapInterrupt : internal IRQ\n");
242 nRet = request_irq( interruptId, pfunc, SA_SAMPLE_RANDOM | SA_INTERRUPT, devname, (void *) param );
244 else if (interruptId >= INTERRUPT_ID_EXTERNAL_0 && interruptId <= INTERRUPT_ID_EXTERNAL_3)
246 printk("BcmHalMapInterrupt : external IRQ\n");
247 nRet = request_external_irq( interruptId, pfunc, SA_SAMPLE_RANDOM | SA_INTERRUPT, devname, (void *) param );
254 EXPORT_SYMBOL(enable_brcm_irq);
255 EXPORT_SYMBOL(disable_brcm_irq);
256 EXPORT_SYMBOL(request_external_irq);
257 EXPORT_SYMBOL(BcmHalMapInterrupt);