1 /*
2  * Copyright 2000 MontaVista Software Inc.
3  * Author: MontaVista Software, Inc.
4  *         	ppopov@mvista.com or source@mvista.com
5  *
6  * This file was derived from Carsten Langgaard's
7  * arch/mips/mips-boards/atlas/atlas_int.c.
8  *
9  * Carsten Langgaard, carstenl@mips.com
10  * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
11  *
12  *  This program is free software; you can redistribute  it and/or modify it
13  *  under  the terms of  the GNU General  Public License as published by the
14  *  Free Software Foundation;  either version 2 of the  License, or (at your
15  *  option) any later version.
16  *
17  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
18  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
19  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
20  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
21  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
23  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
25  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  *  You should have received a copy of the  GNU General Public License along
29  *  with this program; if not, write  to the Free Software Foundation, Inc.,
30  *  675 Mass Ave, Cambridge, MA 02139, USA.
31  */
32 #include <linux/errno.h>
33 #include <linux/init.h>
34 #include <linux/kernel_stat.h>
35 #include <linux/irq.h>
36 #include <linux/module.h>
37 #include <linux/signal.h>
38 #include <linux/sched.h>
39 #include <linux/types.h>
40 #include <linux/interrupt.h>
41 #include <linux/ioport.h>
42 #include <linux/timex.h>
43 #include <linux/slab.h>
44 #include <linux/random.h>
45 
46 #include <asm/bitops.h>
47 #include <asm/bootinfo.h>
48 #include <asm/io.h>
49 #include <asm/mipsregs.h>
50 #include <asm/system.h>
51 #include <asm/galileo-boards/ev96100int.h>
52 
53 extern void mips_timer_interrupt(int irq, struct pt_regs *regs);
54 extern asmlinkage void ev96100IRQ(void);
55 
disable_ev96100_irq(unsigned int irq_nr)56 static void disable_ev96100_irq(unsigned int irq_nr)
57 {
58 	unsigned long flags;
59 
60 	save_and_cli(flags);
61 	clear_c0_status(0x100 << irq_nr);
62 	restore_flags(flags);
63 }
64 
enable_ev96100_irq(unsigned int irq_nr)65 static inline void enable_ev96100_irq(unsigned int irq_nr)
66 {
67 	unsigned long flags;
68 
69 	save_and_cli(flags);
70 	set_c0_status(0x100 << irq_nr);
71 	restore_flags(flags);
72 }
73 
startup_ev96100_irq(unsigned int irq)74 static unsigned int startup_ev96100_irq(unsigned int irq)
75 {
76 	enable_ev96100_irq(irq);
77 
78 	return 0;	/* never anything pending */
79 }
80 
81 #define shutdown_ev96100_irq		disable_ev96100_irq
82 #define mask_and_ack_ev96100_irq	disable_ev96100_irq
83 
end_ev96100_irq(unsigned int irq)84 static void end_ev96100_irq (unsigned int irq)
85 {
86 	if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
87 		enable_ev96100_irq(irq);
88 }
89 
ffz8(unsigned int word)90 static inline unsigned int ffz8(unsigned int word)
91 {
92 	unsigned long k;
93 
94 	k = 7;
95 	if (word & 0x0fUL) { k -= 4;  word <<= 4;  }
96 	if (word & 0x30UL) { k -= 2;  word <<= 2;  }
97 	if (word & 0x40UL) { k -= 1; }
98 
99 	return k;
100 }
101 
ev96100_cpu_irq(unsigned long cause,struct pt_regs * regs)102 asmlinkage void ev96100_cpu_irq(unsigned long cause, struct pt_regs * regs)
103 {
104 	if (!(cause & 0xff00))
105 		return;
106 
107 	do_IRQ(ffz8((cause >> 8) & 0xff), regs);
108 }
109 
110 static struct hw_interrupt_type ev96100_irq_type = {
111 	"EV96100",
112 	startup_ev96100_irq,
113 	shutdown_ev96100_irq,
114 	enable_ev96100_irq,
115 	disable_ev96100_irq,
116 	mask_and_ack_ev96100_irq,
117 	end_ev96100_irq
118 };
119 
init_IRQ(void)120 void __init init_IRQ(void)
121 {
122 	int i;
123 
124 	set_except_vector(0, ev96100IRQ);
125 	init_generic_irq();
126 
127 	for (i = 0; i < 8; i++) {
128 		irq_desc[i].status	= IRQ_DISABLED;
129 		irq_desc[i].action	= 0;
130 		irq_desc[i].depth	= 1;
131 		irq_desc[i].handler	= &ev96100_irq_type;
132 	}
133 }
134