2 * linux/arch/mips/tx4938/common/irq.c
4 * Common tx4938 irq handler
5 * Copyright (C) 2000-2001 Toshiba Corporation
7 * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
8 * terms of the GNU General Public License version 2. This program is
9 * licensed "as is" without any warranty of any kind, whether express
12 * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/kernel_stat.h>
17 #include <linux/module.h>
18 #include <linux/signal.h>
19 #include <linux/sched.h>
20 #include <linux/types.h>
21 #include <linux/interrupt.h>
22 #include <linux/ioport.h>
23 #include <linux/timex.h>
24 #include <linux/slab.h>
25 #include <linux/random.h>
26 #include <linux/irq.h>
27 #include <asm/bitops.h>
28 #include <asm/bootinfo.h>
31 #include <asm/mipsregs.h>
32 #include <asm/system.h>
33 #include <asm/tx4938/rbtx4938.h>
35 /**********************************************************************************/
36 /* Forwad definitions for all pic's */
37 /**********************************************************************************/
39 static unsigned int tx4938_irq_cp0_startup(unsigned int irq);
40 static void tx4938_irq_cp0_shutdown(unsigned int irq);
41 static void tx4938_irq_cp0_enable(unsigned int irq);
42 static void tx4938_irq_cp0_disable(unsigned int irq);
43 static void tx4938_irq_cp0_mask_and_ack(unsigned int irq);
44 static void tx4938_irq_cp0_end(unsigned int irq);
46 static unsigned int tx4938_irq_pic_startup(unsigned int irq);
47 static void tx4938_irq_pic_shutdown(unsigned int irq);
48 static void tx4938_irq_pic_enable(unsigned int irq);
49 static void tx4938_irq_pic_disable(unsigned int irq);
50 static void tx4938_irq_pic_mask_and_ack(unsigned int irq);
51 static void tx4938_irq_pic_end(unsigned int irq);
53 /**********************************************************************************/
54 /* Kernel structs for all pic's */
55 /**********************************************************************************/
56 DEFINE_SPINLOCK(tx4938_cp0_lock);
57 DEFINE_SPINLOCK(tx4938_pic_lock);
59 #define TX4938_CP0_NAME "TX4938-CP0"
60 static struct irq_chip tx4938_irq_cp0_type = {
61 .typename = TX4938_CP0_NAME,
62 .startup = tx4938_irq_cp0_startup,
63 .shutdown = tx4938_irq_cp0_shutdown,
64 .enable = tx4938_irq_cp0_enable,
65 .disable = tx4938_irq_cp0_disable,
66 .ack = tx4938_irq_cp0_mask_and_ack,
67 .end = tx4938_irq_cp0_end,
71 #define TX4938_PIC_NAME "TX4938-PIC"
72 static struct irq_chip tx4938_irq_pic_type = {
73 .typename = TX4938_PIC_NAME,
74 .startup = tx4938_irq_pic_startup,
75 .shutdown = tx4938_irq_pic_shutdown,
76 .enable = tx4938_irq_pic_enable,
77 .disable = tx4938_irq_pic_disable,
78 .ack = tx4938_irq_pic_mask_and_ack,
79 .end = tx4938_irq_pic_end,
83 static struct irqaction tx4938_irq_pic_action = {
86 .mask = CPU_MASK_NONE,
87 .name = TX4938_PIC_NAME
90 /**********************************************************************************/
91 /* Functions for cp0 */
92 /**********************************************************************************/
94 #define tx4938_irq_cp0_mask(irq) ( 1 << ( irq-TX4938_IRQ_CP0_BEG+8 ) )
97 tx4938_irq_cp0_init(void)
101 for (i = TX4938_IRQ_CP0_BEG; i <= TX4938_IRQ_CP0_END; i++) {
102 irq_desc[i].status = IRQ_DISABLED;
103 irq_desc[i].action = 0;
104 irq_desc[i].depth = 1;
105 irq_desc[i].chip = &tx4938_irq_cp0_type;
110 tx4938_irq_cp0_startup(unsigned int irq)
112 tx4938_irq_cp0_enable(irq);
118 tx4938_irq_cp0_shutdown(unsigned int irq)
120 tx4938_irq_cp0_disable(irq);
124 tx4938_irq_cp0_enable(unsigned int irq)
128 spin_lock_irqsave(&tx4938_cp0_lock, flags);
130 set_c0_status(tx4938_irq_cp0_mask(irq));
132 spin_unlock_irqrestore(&tx4938_cp0_lock, flags);
136 tx4938_irq_cp0_disable(unsigned int irq)
140 spin_lock_irqsave(&tx4938_cp0_lock, flags);
142 clear_c0_status(tx4938_irq_cp0_mask(irq));
144 spin_unlock_irqrestore(&tx4938_cp0_lock, flags);
148 tx4938_irq_cp0_mask_and_ack(unsigned int irq)
150 tx4938_irq_cp0_disable(irq);
154 tx4938_irq_cp0_end(unsigned int irq)
156 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
157 tx4938_irq_cp0_enable(irq);
161 /**********************************************************************************/
162 /* Functions for pic */
163 /**********************************************************************************/
166 tx4938_irq_pic_addr(int irq)
168 /* MVMCP -- need to formulize this */
169 irq -= TX4938_IRQ_PIC_BEG;
176 return (TX4938_MKA(TX4938_IRC_IRLVL0));
182 return (TX4938_MKA(TX4938_IRC_IRLVL1));
188 return (TX4938_MKA(TX4938_IRC_IRLVL2));
194 return (TX4938_MKA(TX4938_IRC_IRLVL3));
200 return (TX4938_MKA(TX4938_IRC_IRLVL4));
206 return (TX4938_MKA(TX4938_IRC_IRLVL5));
212 return (TX4938_MKA(TX4938_IRC_IRLVL6));
218 return (TX4938_MKA(TX4938_IRC_IRLVL7));
226 tx4938_irq_pic_mask(int irq)
228 /* MVMCP -- need to formulize this */
229 irq -= TX4938_IRQ_PIC_BEG;
277 tx4938_irq_pic_modify(unsigned pic_reg, unsigned clr_bits, unsigned set_bits)
279 unsigned long val = 0;
281 val = TX4938_RD(pic_reg);
284 TX4938_WR(pic_reg, val);
290 tx4938_irq_pic_init(void)
295 for (i = TX4938_IRQ_PIC_BEG; i <= TX4938_IRQ_PIC_END; i++) {
296 irq_desc[i].status = IRQ_DISABLED;
297 irq_desc[i].action = 0;
298 irq_desc[i].depth = 2;
299 irq_desc[i].chip = &tx4938_irq_pic_type;
302 setup_irq(TX4938_IRQ_NEST_PIC_ON_CP0, &tx4938_irq_pic_action);
304 spin_lock_irqsave(&tx4938_pic_lock, flags);
306 TX4938_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
307 TX4938_WR(0xff1ff600, TX4938_RD(0xff1ff600) | 0x1); /* irq enable */
309 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
313 tx4938_irq_pic_startup(unsigned int irq)
315 tx4938_irq_pic_enable(irq);
321 tx4938_irq_pic_shutdown(unsigned int irq)
323 tx4938_irq_pic_disable(irq);
327 tx4938_irq_pic_enable(unsigned int irq)
331 spin_lock_irqsave(&tx4938_pic_lock, flags);
333 tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq), 0,
334 tx4938_irq_pic_mask(irq));
336 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
340 tx4938_irq_pic_disable(unsigned int irq)
344 spin_lock_irqsave(&tx4938_pic_lock, flags);
346 tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq),
347 tx4938_irq_pic_mask(irq), 0);
349 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
353 tx4938_irq_pic_mask_and_ack(unsigned int irq)
355 tx4938_irq_pic_disable(irq);
359 tx4938_irq_pic_end(unsigned int irq)
361 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
362 tx4938_irq_pic_enable(irq);
366 /**********************************************************************************/
367 /* Main init functions */
368 /**********************************************************************************/
371 tx4938_irq_init(void)
373 tx4938_irq_cp0_init();
374 tx4938_irq_pic_init();
378 tx4938_irq_nested(void)
383 level2 = TX4938_RD(0xff1ff6a0);
384 if ((level2 & 0x10000) == 0) {
386 sw_irq = TX4938_IRQ_PIC_BEG + level2;
389 extern int toshiba_rbtx4938_irq_nested(int sw_irq);
390 sw_irq = toshiba_rbtx4938_irq_nested(sw_irq);
399 asmlinkage void plat_irq_dispatch(void)
401 unsigned int pending = read_c0_cause() & read_c0_status();
403 if (pending & STATUSF_IP7)
404 do_IRQ(TX4938_IRQ_CPU_TIMER);
405 else if (pending & STATUSF_IP2) {
406 int irq = tx4938_irq_nested();
410 spurious_interrupt();
411 } else if (pending & STATUSF_IP1)
412 do_IRQ(TX4938_IRQ_USER1);
413 else if (pending & STATUSF_IP0)
414 do_IRQ(TX4938_IRQ_USER0);