2 * Common tx4927 irq handler
4 * Author: MontaVista Software, Inc.
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
12 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
14 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
15 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
16 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
17 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
18 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
19 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
20 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/errno.h>
27 #include <linux/init.h>
28 #include <linux/kernel_stat.h>
29 #include <linux/module.h>
30 #include <linux/signal.h>
31 #include <linux/sched.h>
32 #include <linux/types.h>
33 #include <linux/interrupt.h>
34 #include <linux/ioport.h>
35 #include <linux/timex.h>
36 #include <linux/slab.h>
37 #include <linux/random.h>
38 #include <linux/irq.h>
39 #include <linux/bitops.h>
40 #include <asm/bootinfo.h>
43 #include <asm/mipsregs.h>
44 #include <asm/system.h>
45 #include <asm/tx4927/tx4927.h>
46 #ifdef CONFIG_TOSHIBA_RBTX4927
47 #include <asm/tx4927/toshiba_rbtx4927.h>
54 #undef TX4927_IRQ_DEBUG
56 #ifdef TX4927_IRQ_DEBUG
57 #define TX4927_IRQ_NONE 0x00000000
59 #define TX4927_IRQ_INFO ( 1 << 0 )
60 #define TX4927_IRQ_WARN ( 1 << 1 )
61 #define TX4927_IRQ_EROR ( 1 << 2 )
63 #define TX4927_IRQ_INIT ( 1 << 5 )
64 #define TX4927_IRQ_NEST1 ( 1 << 6 )
65 #define TX4927_IRQ_NEST2 ( 1 << 7 )
66 #define TX4927_IRQ_NEST3 ( 1 << 8 )
67 #define TX4927_IRQ_NEST4 ( 1 << 9 )
69 #define TX4927_IRQ_CP0_INIT ( 1 << 10 )
70 #define TX4927_IRQ_CP0_ENABLE ( 1 << 13 )
71 #define TX4927_IRQ_CP0_DISABLE ( 1 << 14 )
73 #define TX4927_IRQ_PIC_INIT ( 1 << 20 )
74 #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
75 #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
77 #define TX4927_IRQ_ALL 0xffffffff
80 #ifdef TX4927_IRQ_DEBUG
81 static const u32 tx4927_irq_debug_flag = (TX4927_IRQ_NONE
83 | TX4927_IRQ_WARN | TX4927_IRQ_EROR
84 // | TX4927_IRQ_CP0_INIT
85 // | TX4927_IRQ_CP0_ENABLE
86 // | TX4927_IRQ_CP0_ENDIRQ
87 // | TX4927_IRQ_PIC_INIT
88 // | TX4927_IRQ_PIC_ENABLE
89 // | TX4927_IRQ_PIC_DISABLE
98 #ifdef TX4927_IRQ_DEBUG
99 #define TX4927_IRQ_DPRINTK(flag,str...) \
100 if ( (tx4927_irq_debug_flag) & (flag) ) \
103 sprintf( tmp, str ); \
104 printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
107 #define TX4927_IRQ_DPRINTK(flag,str...)
111 * Forwad definitions for all pic's
114 static void tx4927_irq_cp0_enable(unsigned int irq);
115 static void tx4927_irq_cp0_disable(unsigned int irq);
117 static void tx4927_irq_pic_enable(unsigned int irq);
118 static void tx4927_irq_pic_disable(unsigned int irq);
121 * Kernel structs for all pic's
124 #define TX4927_CP0_NAME "TX4927-CP0"
125 static struct irq_chip tx4927_irq_cp0_type = {
126 .name = TX4927_CP0_NAME,
127 .ack = tx4927_irq_cp0_disable,
128 .mask = tx4927_irq_cp0_disable,
129 .mask_ack = tx4927_irq_cp0_disable,
130 .unmask = tx4927_irq_cp0_enable,
133 #define TX4927_PIC_NAME "TX4927-PIC"
134 static struct irq_chip tx4927_irq_pic_type = {
135 .name = TX4927_PIC_NAME,
136 .ack = tx4927_irq_pic_disable,
137 .mask = tx4927_irq_pic_disable,
138 .mask_ack = tx4927_irq_pic_disable,
139 .unmask = tx4927_irq_pic_enable,
142 #define TX4927_PIC_ACTION(s) { no_action, 0, CPU_MASK_NONE, s, NULL, NULL }
143 static struct irqaction tx4927_irq_pic_action =
144 TX4927_PIC_ACTION(TX4927_PIC_NAME);
146 #define CCP0_STATUS 12
147 #define CCP0_CAUSE 13
153 #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
156 tx4927_irq_cp0_modify(unsigned cp0_reg, unsigned clr_bits, unsigned set_bits)
158 unsigned long val = 0;
162 val = read_c0_status();
166 val = read_c0_cause();
176 write_c0_status(val);
186 static void __init tx4927_irq_cp0_init(void)
190 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT, "beg=%d end=%d\n",
191 TX4927_IRQ_CP0_BEG, TX4927_IRQ_CP0_END);
193 for (i = TX4927_IRQ_CP0_BEG; i <= TX4927_IRQ_CP0_END; i++)
194 set_irq_chip_and_handler(i, &tx4927_irq_cp0_type,
198 static void tx4927_irq_cp0_enable(unsigned int irq)
200 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE, "irq=%d \n", irq);
202 tx4927_irq_cp0_modify(CCP0_STATUS, 0, tx4927_irq_cp0_mask(irq));
205 static void tx4927_irq_cp0_disable(unsigned int irq)
207 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE, "irq=%d \n", irq);
209 tx4927_irq_cp0_modify(CCP0_STATUS, tx4927_irq_cp0_mask(irq), 0);
215 u32 tx4927_irq_pic_addr(int irq)
217 /* MVMCP -- need to formulize this */
218 irq -= TX4927_IRQ_PIC_BEG;
272 u32 tx4927_irq_pic_mask(int irq)
274 /* MVMCP -- need to formulize this */
275 irq -= TX4927_IRQ_PIC_BEG;
321 static void tx4927_irq_pic_modify(unsigned pic_reg, unsigned clr_bits,
324 unsigned long val = 0;
326 val = TX4927_RD(pic_reg);
329 TX4927_WR(pic_reg, val);
332 static void __init tx4927_irq_pic_init(void)
336 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT, "beg=%d end=%d\n",
337 TX4927_IRQ_PIC_BEG, TX4927_IRQ_PIC_END);
339 for (i = TX4927_IRQ_PIC_BEG; i <= TX4927_IRQ_PIC_END; i++)
340 set_irq_chip_and_handler(i, &tx4927_irq_pic_type,
343 setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0, &tx4927_irq_pic_action);
345 TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
346 TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
349 static void tx4927_irq_pic_enable(unsigned int irq)
351 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE, "irq=%d\n", irq);
353 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq), 0,
354 tx4927_irq_pic_mask(irq));
357 static void tx4927_irq_pic_disable(unsigned int irq)
359 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE, "irq=%d\n", irq);
361 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq),
362 tx4927_irq_pic_mask(irq), 0);
366 * Main init functions
368 void __init tx4927_irq_init(void)
370 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "-\n");
372 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_cp0_init()\n");
373 tx4927_irq_cp0_init();
375 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_pic_init()\n");
376 tx4927_irq_pic_init();
378 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "+\n");
381 static int tx4927_irq_nested(void)
386 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "-\n");
388 level2 = TX4927_RD(0xff1ff6a0);
389 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=level2a=0x%x\n", level2);
391 if ((level2 & 0x10000) == 0) {
393 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=level2b=0x%x\n", level2);
395 sw_irq = TX4927_IRQ_PIC_BEG + level2;
396 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=sw_irq=%d\n", sw_irq);
399 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq-%d\n",
402 #ifdef CONFIG_TOSHIBA_RBTX4927
404 sw_irq = toshiba_rbtx4927_irq_nested(sw_irq);
408 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq+%d\n",
413 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=sw_irq=%d\n", sw_irq);
415 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "+\n");
420 asmlinkage void plat_irq_dispatch(void)
422 unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
424 if (pending & STATUSF_IP7) /* cpu timer */
425 do_IRQ(TX4927_IRQ_CPU_TIMER);
426 else if (pending & STATUSF_IP2) { /* tx4927 pic */
427 unsigned int irq = tx4927_irq_nested();
429 if (unlikely(irq == 0)) {
430 spurious_interrupt();
434 } else if (pending & STATUSF_IP0) /* user line 0 */
435 do_IRQ(TX4927_IRQ_USER0);
436 else if (pending & STATUSF_IP1) /* user line 1 */
437 do_IRQ(TX4927_IRQ_USER1);
439 spurious_interrupt();