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/config.h>
27 #include <linux/errno.h>
28 #include <linux/init.h>
29 #include <linux/kernel_stat.h>
30 #include <linux/module.h>
31 #include <linux/signal.h>
32 #include <linux/sched.h>
33 #include <linux/types.h>
34 #include <linux/interrupt.h>
35 #include <linux/ioport.h>
36 #include <linux/timex.h>
37 #include <linux/slab.h>
38 #include <linux/random.h>
39 #include <linux/irq.h>
40 #include <linux/bitops.h>
41 #include <asm/bootinfo.h>
44 #include <asm/mipsregs.h>
45 #include <asm/system.h>
46 #include <asm/tx4927/tx4927.h>
52 #undef TX4927_IRQ_DEBUG
54 #ifdef TX4927_IRQ_DEBUG
55 #define TX4927_IRQ_NONE 0x00000000
57 #define TX4927_IRQ_INFO ( 1 << 0 )
58 #define TX4927_IRQ_WARN ( 1 << 1 )
59 #define TX4927_IRQ_EROR ( 1 << 2 )
61 #define TX4927_IRQ_INIT ( 1 << 5 )
62 #define TX4927_IRQ_NEST1 ( 1 << 6 )
63 #define TX4927_IRQ_NEST2 ( 1 << 7 )
64 #define TX4927_IRQ_NEST3 ( 1 << 8 )
65 #define TX4927_IRQ_NEST4 ( 1 << 9 )
67 #define TX4927_IRQ_CP0_INIT ( 1 << 10 )
68 #define TX4927_IRQ_CP0_STARTUP ( 1 << 11 )
69 #define TX4927_IRQ_CP0_SHUTDOWN ( 1 << 12 )
70 #define TX4927_IRQ_CP0_ENABLE ( 1 << 13 )
71 #define TX4927_IRQ_CP0_DISABLE ( 1 << 14 )
72 #define TX4927_IRQ_CP0_MASK ( 1 << 15 )
73 #define TX4927_IRQ_CP0_ENDIRQ ( 1 << 16 )
75 #define TX4927_IRQ_PIC_INIT ( 1 << 20 )
76 #define TX4927_IRQ_PIC_STARTUP ( 1 << 21 )
77 #define TX4927_IRQ_PIC_SHUTDOWN ( 1 << 22 )
78 #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
79 #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
80 #define TX4927_IRQ_PIC_MASK ( 1 << 25 )
81 #define TX4927_IRQ_PIC_ENDIRQ ( 1 << 26 )
83 #define TX4927_IRQ_ALL 0xffffffff
86 #ifdef TX4927_IRQ_DEBUG
87 static const u32 tx4927_irq_debug_flag = (TX4927_IRQ_NONE
89 | TX4927_IRQ_WARN | TX4927_IRQ_EROR
90 // | TX4927_IRQ_CP0_INIT
91 // | TX4927_IRQ_CP0_STARTUP
92 // | TX4927_IRQ_CP0_SHUTDOWN
93 // | TX4927_IRQ_CP0_ENABLE
94 // | TX4927_IRQ_CP0_DISABLE
95 // | TX4927_IRQ_CP0_MASK
96 // | TX4927_IRQ_CP0_ENDIRQ
97 // | TX4927_IRQ_PIC_INIT
98 // | TX4927_IRQ_PIC_STARTUP
99 // | TX4927_IRQ_PIC_SHUTDOWN
100 // | TX4927_IRQ_PIC_ENABLE
101 // | TX4927_IRQ_PIC_DISABLE
102 // | TX4927_IRQ_PIC_MASK
103 // | TX4927_IRQ_PIC_ENDIRQ
105 // | TX4927_IRQ_NEST1
106 // | TX4927_IRQ_NEST2
107 // | TX4927_IRQ_NEST3
108 // | TX4927_IRQ_NEST4
112 #ifdef TX4927_IRQ_DEBUG
113 #define TX4927_IRQ_DPRINTK(flag,str...) \
114 if ( (tx4927_irq_debug_flag) & (flag) ) \
117 sprintf( tmp, str ); \
118 printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
121 #define TX4927_IRQ_DPRINTK(flag,str...)
125 * Forwad definitions for all pic's
128 static unsigned int tx4927_irq_cp0_startup(unsigned int irq);
129 static void tx4927_irq_cp0_shutdown(unsigned int irq);
130 static void tx4927_irq_cp0_enable(unsigned int irq);
131 static void tx4927_irq_cp0_disable(unsigned int irq);
132 static void tx4927_irq_cp0_mask_and_ack(unsigned int irq);
133 static void tx4927_irq_cp0_end(unsigned int irq);
135 static unsigned int tx4927_irq_pic_startup(unsigned int irq);
136 static void tx4927_irq_pic_shutdown(unsigned int irq);
137 static void tx4927_irq_pic_enable(unsigned int irq);
138 static void tx4927_irq_pic_disable(unsigned int irq);
139 static void tx4927_irq_pic_mask_and_ack(unsigned int irq);
140 static void tx4927_irq_pic_end(unsigned int irq);
143 * Kernel structs for all pic's
146 static DEFINE_SPINLOCK(tx4927_cp0_lock);
147 static DEFINE_SPINLOCK(tx4927_pic_lock);
149 #define TX4927_CP0_NAME "TX4927-CP0"
150 static struct hw_interrupt_type tx4927_irq_cp0_type = {
151 .typename = TX4927_CP0_NAME,
152 .startup = tx4927_irq_cp0_startup,
153 .shutdown = tx4927_irq_cp0_shutdown,
154 .enable = tx4927_irq_cp0_enable,
155 .disable = tx4927_irq_cp0_disable,
156 .ack = tx4927_irq_cp0_mask_and_ack,
157 .end = tx4927_irq_cp0_end,
161 #define TX4927_PIC_NAME "TX4927-PIC"
162 static struct hw_interrupt_type tx4927_irq_pic_type = {
163 .typename = TX4927_PIC_NAME,
164 .startup = tx4927_irq_pic_startup,
165 .shutdown = tx4927_irq_pic_shutdown,
166 .enable = tx4927_irq_pic_enable,
167 .disable = tx4927_irq_pic_disable,
168 .ack = tx4927_irq_pic_mask_and_ack,
169 .end = tx4927_irq_pic_end,
173 #define TX4927_PIC_ACTION(s) { no_action, 0, CPU_MASK_NONE, s, NULL, NULL }
174 static struct irqaction tx4927_irq_pic_action =
175 TX4927_PIC_ACTION(TX4927_PIC_NAME);
177 #define CCP0_STATUS 12
178 #define CCP0_CAUSE 13
184 #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
187 tx4927_irq_cp0_modify(unsigned cp0_reg, unsigned clr_bits, unsigned set_bits)
189 unsigned long val = 0;
193 val = read_c0_status();
197 val = read_c0_cause();
207 write_c0_status(val);
219 static void __init tx4927_irq_cp0_init(void)
223 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT, "beg=%d end=%d\n",
224 TX4927_IRQ_CP0_BEG, TX4927_IRQ_CP0_END);
226 for (i = TX4927_IRQ_CP0_BEG; i <= TX4927_IRQ_CP0_END; i++) {
227 irq_desc[i].status = IRQ_DISABLED;
228 irq_desc[i].action = 0;
229 irq_desc[i].depth = 1;
230 irq_desc[i].handler = &tx4927_irq_cp0_type;
236 static unsigned int tx4927_irq_cp0_startup(unsigned int irq)
238 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_STARTUP, "irq=%d \n", irq);
240 tx4927_irq_cp0_enable(irq);
245 static void tx4927_irq_cp0_shutdown(unsigned int irq)
247 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_SHUTDOWN, "irq=%d \n", irq);
249 tx4927_irq_cp0_disable(irq);
254 static void tx4927_irq_cp0_enable(unsigned int irq)
258 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE, "irq=%d \n", irq);
260 spin_lock_irqsave(&tx4927_cp0_lock, flags);
262 tx4927_irq_cp0_modify(CCP0_STATUS, 0, tx4927_irq_cp0_mask(irq));
264 spin_unlock_irqrestore(&tx4927_cp0_lock, flags);
269 static void tx4927_irq_cp0_disable(unsigned int irq)
273 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE, "irq=%d \n", irq);
275 spin_lock_irqsave(&tx4927_cp0_lock, flags);
277 tx4927_irq_cp0_modify(CCP0_STATUS, tx4927_irq_cp0_mask(irq), 0);
279 spin_unlock_irqrestore(&tx4927_cp0_lock, flags);
284 static void tx4927_irq_cp0_mask_and_ack(unsigned int irq)
286 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_MASK, "irq=%d \n", irq);
288 tx4927_irq_cp0_disable(irq);
293 static void tx4927_irq_cp0_end(unsigned int irq)
295 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENDIRQ, "irq=%d \n", irq);
297 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
298 tx4927_irq_cp0_enable(irq);
307 u32 tx4927_irq_pic_addr(int irq)
309 /* MVMCP -- need to formulize this */
310 irq -= TX4927_IRQ_PIC_BEG;
364 u32 tx4927_irq_pic_mask(int irq)
366 /* MVMCP -- need to formulize this */
367 irq -= TX4927_IRQ_PIC_BEG;
413 static void tx4927_irq_pic_modify(unsigned pic_reg, unsigned clr_bits,
416 unsigned long val = 0;
418 val = TX4927_RD(pic_reg);
421 TX4927_WR(pic_reg, val);
426 static void __init tx4927_irq_pic_init(void)
431 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT, "beg=%d end=%d\n",
432 TX4927_IRQ_PIC_BEG, TX4927_IRQ_PIC_END);
434 for (i = TX4927_IRQ_PIC_BEG; i <= TX4927_IRQ_PIC_END; i++) {
435 irq_desc[i].status = IRQ_DISABLED;
436 irq_desc[i].action = 0;
437 irq_desc[i].depth = 2;
438 irq_desc[i].handler = &tx4927_irq_pic_type;
441 setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0, &tx4927_irq_pic_action);
443 spin_lock_irqsave(&tx4927_pic_lock, flags);
445 TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
446 TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
448 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
453 static unsigned int tx4927_irq_pic_startup(unsigned int irq)
455 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_STARTUP, "irq=%d\n", irq);
457 tx4927_irq_pic_enable(irq);
462 static void tx4927_irq_pic_shutdown(unsigned int irq)
464 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_SHUTDOWN, "irq=%d\n", irq);
466 tx4927_irq_pic_disable(irq);
471 static void tx4927_irq_pic_enable(unsigned int irq)
475 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE, "irq=%d\n", irq);
477 spin_lock_irqsave(&tx4927_pic_lock, flags);
479 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq), 0,
480 tx4927_irq_pic_mask(irq));
482 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
487 static void tx4927_irq_pic_disable(unsigned int irq)
491 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE, "irq=%d\n", irq);
493 spin_lock_irqsave(&tx4927_pic_lock, flags);
495 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq),
496 tx4927_irq_pic_mask(irq), 0);
498 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
503 static void tx4927_irq_pic_mask_and_ack(unsigned int irq)
505 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_MASK, "irq=%d\n", irq);
507 tx4927_irq_pic_disable(irq);
512 static void tx4927_irq_pic_end(unsigned int irq)
514 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENDIRQ, "irq=%d\n", irq);
516 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
517 tx4927_irq_pic_enable(irq);
524 * Main init functions
526 void __init tx4927_irq_init(void)
528 extern asmlinkage void tx4927_irq_handler(void);
530 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "-\n");
532 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_cp0_init()\n");
533 tx4927_irq_cp0_init();
535 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_pic_init()\n");
536 tx4927_irq_pic_init();
538 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT,
539 "=Calling set_except_vector(tx4927_irq_handler)\n");
540 set_except_vector(0, tx4927_irq_handler);
542 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "+\n");
547 int tx4927_irq_nested(void)
552 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "-\n");
554 level2 = TX4927_RD(0xff1ff6a0);
555 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=level2a=0x%x\n", level2);
557 if ((level2 & 0x10000) == 0) {
559 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=level2b=0x%x\n", level2);
561 sw_irq = TX4927_IRQ_PIC_BEG + level2;
562 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=sw_irq=%d\n", sw_irq);
565 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq-%d\n",
568 #ifdef CONFIG_TOSHIBA_RBTX4927
570 sw_irq = toshiba_rbtx4927_irq_nested(sw_irq);
574 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq+%d\n",
579 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=sw_irq=%d\n", sw_irq);
581 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "+\n");