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/wbflush.h>
34 #include <asm/tx4938/rbtx4938.h>
36 /**********************************************************************************/
37 /* Forwad definitions for all pic's */
38 /**********************************************************************************/
40 static unsigned int tx4938_irq_cp0_startup(unsigned int irq);
41 static void tx4938_irq_cp0_shutdown(unsigned int irq);
42 static void tx4938_irq_cp0_enable(unsigned int irq);
43 static void tx4938_irq_cp0_disable(unsigned int irq);
44 static void tx4938_irq_cp0_mask_and_ack(unsigned int irq);
45 static void tx4938_irq_cp0_end(unsigned int irq);
47 static unsigned int tx4938_irq_pic_startup(unsigned int irq);
48 static void tx4938_irq_pic_shutdown(unsigned int irq);
49 static void tx4938_irq_pic_enable(unsigned int irq);
50 static void tx4938_irq_pic_disable(unsigned int irq);
51 static void tx4938_irq_pic_mask_and_ack(unsigned int irq);
52 static void tx4938_irq_pic_end(unsigned int irq);
54 /**********************************************************************************/
55 /* Kernel structs for all pic's */
56 /**********************************************************************************/
57 DEFINE_SPINLOCK(tx4938_cp0_lock);
58 DEFINE_SPINLOCK(tx4938_pic_lock);
60 #define TX4938_CP0_NAME "TX4938-CP0"
61 static struct irq_chip tx4938_irq_cp0_type = {
62 .typename = TX4938_CP0_NAME,
63 .startup = tx4938_irq_cp0_startup,
64 .shutdown = tx4938_irq_cp0_shutdown,
65 .enable = tx4938_irq_cp0_enable,
66 .disable = tx4938_irq_cp0_disable,
67 .ack = tx4938_irq_cp0_mask_and_ack,
68 .end = tx4938_irq_cp0_end,
72 #define TX4938_PIC_NAME "TX4938-PIC"
73 static struct irq_chip tx4938_irq_pic_type = {
74 .typename = TX4938_PIC_NAME,
75 .startup = tx4938_irq_pic_startup,
76 .shutdown = tx4938_irq_pic_shutdown,
77 .enable = tx4938_irq_pic_enable,
78 .disable = tx4938_irq_pic_disable,
79 .ack = tx4938_irq_pic_mask_and_ack,
80 .end = tx4938_irq_pic_end,
84 static struct irqaction tx4938_irq_pic_action = {
87 .mask = CPU_MASK_NONE,
88 .name = TX4938_PIC_NAME
91 /**********************************************************************************/
92 /* Functions for cp0 */
93 /**********************************************************************************/
95 #define tx4938_irq_cp0_mask(irq) ( 1 << ( irq-TX4938_IRQ_CP0_BEG+8 ) )
98 tx4938_irq_cp0_init(void)
102 for (i = TX4938_IRQ_CP0_BEG; i <= TX4938_IRQ_CP0_END; i++) {
103 irq_desc[i].status = IRQ_DISABLED;
104 irq_desc[i].action = 0;
105 irq_desc[i].depth = 1;
106 irq_desc[i].chip = &tx4938_irq_cp0_type;
111 tx4938_irq_cp0_startup(unsigned int irq)
113 tx4938_irq_cp0_enable(irq);
119 tx4938_irq_cp0_shutdown(unsigned int irq)
121 tx4938_irq_cp0_disable(irq);
125 tx4938_irq_cp0_enable(unsigned int irq)
129 spin_lock_irqsave(&tx4938_cp0_lock, flags);
131 set_c0_status(tx4938_irq_cp0_mask(irq));
133 spin_unlock_irqrestore(&tx4938_cp0_lock, flags);
137 tx4938_irq_cp0_disable(unsigned int irq)
141 spin_lock_irqsave(&tx4938_cp0_lock, flags);
143 clear_c0_status(tx4938_irq_cp0_mask(irq));
145 spin_unlock_irqrestore(&tx4938_cp0_lock, flags);
149 tx4938_irq_cp0_mask_and_ack(unsigned int irq)
151 tx4938_irq_cp0_disable(irq);
155 tx4938_irq_cp0_end(unsigned int irq)
157 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
158 tx4938_irq_cp0_enable(irq);
162 /**********************************************************************************/
163 /* Functions for pic */
164 /**********************************************************************************/
167 tx4938_irq_pic_addr(int irq)
169 /* MVMCP -- need to formulize this */
170 irq -= TX4938_IRQ_PIC_BEG;
177 return (TX4938_MKA(TX4938_IRC_IRLVL0));
183 return (TX4938_MKA(TX4938_IRC_IRLVL1));
189 return (TX4938_MKA(TX4938_IRC_IRLVL2));
195 return (TX4938_MKA(TX4938_IRC_IRLVL3));
201 return (TX4938_MKA(TX4938_IRC_IRLVL4));
207 return (TX4938_MKA(TX4938_IRC_IRLVL5));
213 return (TX4938_MKA(TX4938_IRC_IRLVL6));
219 return (TX4938_MKA(TX4938_IRC_IRLVL7));
227 tx4938_irq_pic_mask(int irq)
229 /* MVMCP -- need to formulize this */
230 irq -= TX4938_IRQ_PIC_BEG;
278 tx4938_irq_pic_modify(unsigned pic_reg, unsigned clr_bits, unsigned set_bits)
280 unsigned long val = 0;
282 val = TX4938_RD(pic_reg);
285 TX4938_WR(pic_reg, val);
291 tx4938_irq_pic_init(void)
296 for (i = TX4938_IRQ_PIC_BEG; i <= TX4938_IRQ_PIC_END; i++) {
297 irq_desc[i].status = IRQ_DISABLED;
298 irq_desc[i].action = 0;
299 irq_desc[i].depth = 2;
300 irq_desc[i].chip = &tx4938_irq_pic_type;
303 setup_irq(TX4938_IRQ_NEST_PIC_ON_CP0, &tx4938_irq_pic_action);
305 spin_lock_irqsave(&tx4938_pic_lock, flags);
307 TX4938_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
308 TX4938_WR(0xff1ff600, TX4938_RD(0xff1ff600) | 0x1); /* irq enable */
310 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
314 tx4938_irq_pic_startup(unsigned int irq)
316 tx4938_irq_pic_enable(irq);
322 tx4938_irq_pic_shutdown(unsigned int irq)
324 tx4938_irq_pic_disable(irq);
328 tx4938_irq_pic_enable(unsigned int irq)
332 spin_lock_irqsave(&tx4938_pic_lock, flags);
334 tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq), 0,
335 tx4938_irq_pic_mask(irq));
337 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
341 tx4938_irq_pic_disable(unsigned int irq)
345 spin_lock_irqsave(&tx4938_pic_lock, flags);
347 tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq),
348 tx4938_irq_pic_mask(irq), 0);
350 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
354 tx4938_irq_pic_mask_and_ack(unsigned int irq)
356 tx4938_irq_pic_disable(irq);
360 tx4938_irq_pic_end(unsigned int irq)
362 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
363 tx4938_irq_pic_enable(irq);
367 /**********************************************************************************/
368 /* Main init functions */
369 /**********************************************************************************/
372 tx4938_irq_init(void)
374 tx4938_irq_cp0_init();
375 tx4938_irq_pic_init();
379 tx4938_irq_nested(void)
384 level2 = TX4938_RD(0xff1ff6a0);
385 if ((level2 & 0x10000) == 0) {
387 sw_irq = TX4938_IRQ_PIC_BEG + level2;
390 extern int toshiba_rbtx4938_irq_nested(int sw_irq);
391 sw_irq = toshiba_rbtx4938_irq_nested(sw_irq);
400 asmlinkage void plat_irq_dispatch(void)
402 unsigned int pending = read_c0_cause() & read_c0_status();
404 if (pending & STATUSF_IP7)
405 do_IRQ(TX4938_IRQ_CPU_TIMER);
406 else if (pending & STATUSF_IP2) {
407 int irq = tx4938_irq_nested();
411 spurious_interrupt();
412 } else if (pending & STATUSF_IP1)
413 do_IRQ(TX4938_IRQ_USER1);
414 else if (pending & STATUSF_IP0)
415 do_IRQ(TX4938_IRQ_USER0);