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>
51 #undef TX4927_IRQ_DEBUG
53 #ifdef TX4927_IRQ_DEBUG
54 #define TX4927_IRQ_NONE 0x00000000
56 #define TX4927_IRQ_INFO ( 1 << 0 )
57 #define TX4927_IRQ_WARN ( 1 << 1 )
58 #define TX4927_IRQ_EROR ( 1 << 2 )
60 #define TX4927_IRQ_INIT ( 1 << 5 )
61 #define TX4927_IRQ_NEST1 ( 1 << 6 )
62 #define TX4927_IRQ_NEST2 ( 1 << 7 )
63 #define TX4927_IRQ_NEST3 ( 1 << 8 )
64 #define TX4927_IRQ_NEST4 ( 1 << 9 )
66 #define TX4927_IRQ_CP0_INIT ( 1 << 10 )
67 #define TX4927_IRQ_CP0_STARTUP ( 1 << 11 )
68 #define TX4927_IRQ_CP0_SHUTDOWN ( 1 << 12 )
69 #define TX4927_IRQ_CP0_ENABLE ( 1 << 13 )
70 #define TX4927_IRQ_CP0_DISABLE ( 1 << 14 )
71 #define TX4927_IRQ_CP0_MASK ( 1 << 15 )
72 #define TX4927_IRQ_CP0_ENDIRQ ( 1 << 16 )
74 #define TX4927_IRQ_PIC_INIT ( 1 << 20 )
75 #define TX4927_IRQ_PIC_STARTUP ( 1 << 21 )
76 #define TX4927_IRQ_PIC_SHUTDOWN ( 1 << 22 )
77 #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
78 #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
79 #define TX4927_IRQ_PIC_MASK ( 1 << 25 )
80 #define TX4927_IRQ_PIC_ENDIRQ ( 1 << 26 )
82 #define TX4927_IRQ_ALL 0xffffffff
85 #ifdef TX4927_IRQ_DEBUG
86 static const u32 tx4927_irq_debug_flag = (TX4927_IRQ_NONE
88 | TX4927_IRQ_WARN | TX4927_IRQ_EROR
89 // | TX4927_IRQ_CP0_INIT
90 // | TX4927_IRQ_CP0_STARTUP
91 // | TX4927_IRQ_CP0_SHUTDOWN
92 // | TX4927_IRQ_CP0_ENABLE
93 // | TX4927_IRQ_CP0_DISABLE
94 // | TX4927_IRQ_CP0_MASK
95 // | TX4927_IRQ_CP0_ENDIRQ
96 // | TX4927_IRQ_PIC_INIT
97 // | TX4927_IRQ_PIC_STARTUP
98 // | TX4927_IRQ_PIC_SHUTDOWN
99 // | TX4927_IRQ_PIC_ENABLE
100 // | TX4927_IRQ_PIC_DISABLE
101 // | TX4927_IRQ_PIC_MASK
102 // | TX4927_IRQ_PIC_ENDIRQ
104 // | TX4927_IRQ_NEST1
105 // | TX4927_IRQ_NEST2
106 // | TX4927_IRQ_NEST3
107 // | TX4927_IRQ_NEST4
111 #ifdef TX4927_IRQ_DEBUG
112 #define TX4927_IRQ_DPRINTK(flag,str...) \
113 if ( (tx4927_irq_debug_flag) & (flag) ) \
116 sprintf( tmp, str ); \
117 printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
120 #define TX4927_IRQ_DPRINTK(flag,str...)
124 * Forwad definitions for all pic's
127 static unsigned int tx4927_irq_cp0_startup(unsigned int irq);
128 static void tx4927_irq_cp0_shutdown(unsigned int irq);
129 static void tx4927_irq_cp0_enable(unsigned int irq);
130 static void tx4927_irq_cp0_disable(unsigned int irq);
131 static void tx4927_irq_cp0_mask_and_ack(unsigned int irq);
132 static void tx4927_irq_cp0_end(unsigned int irq);
134 static unsigned int tx4927_irq_pic_startup(unsigned int irq);
135 static void tx4927_irq_pic_shutdown(unsigned int irq);
136 static void tx4927_irq_pic_enable(unsigned int irq);
137 static void tx4927_irq_pic_disable(unsigned int irq);
138 static void tx4927_irq_pic_mask_and_ack(unsigned int irq);
139 static void tx4927_irq_pic_end(unsigned int irq);
142 * Kernel structs for all pic's
145 static DEFINE_SPINLOCK(tx4927_cp0_lock);
146 static DEFINE_SPINLOCK(tx4927_pic_lock);
148 #define TX4927_CP0_NAME "TX4927-CP0"
149 static struct irq_chip tx4927_irq_cp0_type = {
150 .typename = TX4927_CP0_NAME,
151 .startup = tx4927_irq_cp0_startup,
152 .shutdown = tx4927_irq_cp0_shutdown,
153 .enable = tx4927_irq_cp0_enable,
154 .disable = tx4927_irq_cp0_disable,
155 .ack = tx4927_irq_cp0_mask_and_ack,
156 .end = tx4927_irq_cp0_end,
160 #define TX4927_PIC_NAME "TX4927-PIC"
161 static struct irq_chip tx4927_irq_pic_type = {
162 .typename = TX4927_PIC_NAME,
163 .startup = tx4927_irq_pic_startup,
164 .shutdown = tx4927_irq_pic_shutdown,
165 .enable = tx4927_irq_pic_enable,
166 .disable = tx4927_irq_pic_disable,
167 .ack = tx4927_irq_pic_mask_and_ack,
168 .end = tx4927_irq_pic_end,
172 #define TX4927_PIC_ACTION(s) { no_action, 0, CPU_MASK_NONE, s, NULL, NULL }
173 static struct irqaction tx4927_irq_pic_action =
174 TX4927_PIC_ACTION(TX4927_PIC_NAME);
176 #define CCP0_STATUS 12
177 #define CCP0_CAUSE 13
183 #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
186 tx4927_irq_cp0_modify(unsigned cp0_reg, unsigned clr_bits, unsigned set_bits)
188 unsigned long val = 0;
192 val = read_c0_status();
196 val = read_c0_cause();
206 write_c0_status(val);
218 static void __init tx4927_irq_cp0_init(void)
222 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT, "beg=%d end=%d\n",
223 TX4927_IRQ_CP0_BEG, TX4927_IRQ_CP0_END);
225 for (i = TX4927_IRQ_CP0_BEG; i <= TX4927_IRQ_CP0_END; i++) {
226 irq_desc[i].status = IRQ_DISABLED;
227 irq_desc[i].action = 0;
228 irq_desc[i].depth = 1;
229 irq_desc[i].chip = &tx4927_irq_cp0_type;
235 static unsigned int tx4927_irq_cp0_startup(unsigned int irq)
237 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_STARTUP, "irq=%d \n", irq);
239 tx4927_irq_cp0_enable(irq);
244 static void tx4927_irq_cp0_shutdown(unsigned int irq)
246 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_SHUTDOWN, "irq=%d \n", irq);
248 tx4927_irq_cp0_disable(irq);
253 static void tx4927_irq_cp0_enable(unsigned int irq)
257 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE, "irq=%d \n", irq);
259 spin_lock_irqsave(&tx4927_cp0_lock, flags);
261 tx4927_irq_cp0_modify(CCP0_STATUS, 0, tx4927_irq_cp0_mask(irq));
263 spin_unlock_irqrestore(&tx4927_cp0_lock, flags);
268 static void tx4927_irq_cp0_disable(unsigned int irq)
272 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE, "irq=%d \n", irq);
274 spin_lock_irqsave(&tx4927_cp0_lock, flags);
276 tx4927_irq_cp0_modify(CCP0_STATUS, tx4927_irq_cp0_mask(irq), 0);
278 spin_unlock_irqrestore(&tx4927_cp0_lock, flags);
283 static void tx4927_irq_cp0_mask_and_ack(unsigned int irq)
285 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_MASK, "irq=%d \n", irq);
287 tx4927_irq_cp0_disable(irq);
292 static void tx4927_irq_cp0_end(unsigned int irq)
294 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENDIRQ, "irq=%d \n", irq);
296 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
297 tx4927_irq_cp0_enable(irq);
306 u32 tx4927_irq_pic_addr(int irq)
308 /* MVMCP -- need to formulize this */
309 irq -= TX4927_IRQ_PIC_BEG;
363 u32 tx4927_irq_pic_mask(int irq)
365 /* MVMCP -- need to formulize this */
366 irq -= TX4927_IRQ_PIC_BEG;
412 static void tx4927_irq_pic_modify(unsigned pic_reg, unsigned clr_bits,
415 unsigned long val = 0;
417 val = TX4927_RD(pic_reg);
420 TX4927_WR(pic_reg, val);
425 static void __init tx4927_irq_pic_init(void)
430 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT, "beg=%d end=%d\n",
431 TX4927_IRQ_PIC_BEG, TX4927_IRQ_PIC_END);
433 for (i = TX4927_IRQ_PIC_BEG; i <= TX4927_IRQ_PIC_END; i++) {
434 irq_desc[i].status = IRQ_DISABLED;
435 irq_desc[i].action = 0;
436 irq_desc[i].depth = 2;
437 irq_desc[i].chip = &tx4927_irq_pic_type;
440 setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0, &tx4927_irq_pic_action);
442 spin_lock_irqsave(&tx4927_pic_lock, flags);
444 TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
445 TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
447 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
452 static unsigned int tx4927_irq_pic_startup(unsigned int irq)
454 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_STARTUP, "irq=%d\n", irq);
456 tx4927_irq_pic_enable(irq);
461 static void tx4927_irq_pic_shutdown(unsigned int irq)
463 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_SHUTDOWN, "irq=%d\n", irq);
465 tx4927_irq_pic_disable(irq);
470 static void tx4927_irq_pic_enable(unsigned int irq)
474 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE, "irq=%d\n", irq);
476 spin_lock_irqsave(&tx4927_pic_lock, flags);
478 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq), 0,
479 tx4927_irq_pic_mask(irq));
481 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
486 static void tx4927_irq_pic_disable(unsigned int irq)
490 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE, "irq=%d\n", irq);
492 spin_lock_irqsave(&tx4927_pic_lock, flags);
494 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq),
495 tx4927_irq_pic_mask(irq), 0);
497 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
502 static void tx4927_irq_pic_mask_and_ack(unsigned int irq)
504 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_MASK, "irq=%d\n", irq);
506 tx4927_irq_pic_disable(irq);
511 static void tx4927_irq_pic_end(unsigned int irq)
513 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENDIRQ, "irq=%d\n", irq);
515 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
516 tx4927_irq_pic_enable(irq);
523 * Main init functions
525 void __init tx4927_irq_init(void)
527 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "-\n");
529 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_cp0_init()\n");
530 tx4927_irq_cp0_init();
532 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_pic_init()\n");
533 tx4927_irq_pic_init();
535 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "+\n");
540 static int tx4927_irq_nested(void)
545 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "-\n");
547 level2 = TX4927_RD(0xff1ff6a0);
548 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=level2a=0x%x\n", level2);
550 if ((level2 & 0x10000) == 0) {
552 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=level2b=0x%x\n", level2);
554 sw_irq = TX4927_IRQ_PIC_BEG + level2;
555 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=sw_irq=%d\n", sw_irq);
558 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq-%d\n",
561 #ifdef CONFIG_TOSHIBA_RBTX4927
563 sw_irq = toshiba_rbtx4927_irq_nested(sw_irq);
567 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq+%d\n",
572 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=sw_irq=%d\n", sw_irq);
574 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "+\n");
579 asmlinkage void plat_irq_dispatch(void)
581 unsigned int pending = read_c0_status() & read_c0_cause();
583 if (pending & STATUSF_IP7) /* cpu timer */
584 do_IRQ(TX4927_IRQ_CPU_TIMER);
585 else if (pending & STATUSF_IP2) { /* tx4927 pic */
586 unsigned int irq = tx4927_irq_nested();
588 if (unlikely(irq == 0)) {
589 spurious_interrupt();
593 } else if (pending & STATUSF_IP0) /* user line 0 */
594 do_IRQ(TX4927_IRQ_USER0);
595 else if (pending & STATUSF_IP1) /* user line 1 */
596 do_IRQ(TX4927_IRQ_USER1);
598 spurious_interrupt();