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 <asm/bitops.h>
41 #include <asm/bootinfo.h>
44 #include <asm/mipsregs.h>
45 #include <asm/system.h>
46 #include <asm/tx4927/tx4927.h>
51 #define TX4927_IRQ_CHECK_CP0
52 #define TX4927_IRQ_CHECK_PIC
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_STARTUP ( 1 << 11 )
71 #define TX4927_IRQ_CP0_SHUTDOWN ( 1 << 12 )
72 #define TX4927_IRQ_CP0_ENABLE ( 1 << 13 )
73 #define TX4927_IRQ_CP0_DISABLE ( 1 << 14 )
74 #define TX4927_IRQ_CP0_MASK ( 1 << 15 )
75 #define TX4927_IRQ_CP0_ENDIRQ ( 1 << 16 )
77 #define TX4927_IRQ_PIC_INIT ( 1 << 20 )
78 #define TX4927_IRQ_PIC_STARTUP ( 1 << 21 )
79 #define TX4927_IRQ_PIC_SHUTDOWN ( 1 << 22 )
80 #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
81 #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
82 #define TX4927_IRQ_PIC_MASK ( 1 << 25 )
83 #define TX4927_IRQ_PIC_ENDIRQ ( 1 << 26 )
85 #define TX4927_IRQ_ALL 0xffffffff
88 #ifdef TX4927_IRQ_DEBUG
89 static const u32 tx4927_irq_debug_flag = (TX4927_IRQ_NONE
91 | TX4927_IRQ_WARN | TX4927_IRQ_EROR
92 // | TX4927_IRQ_CP0_INIT
93 // | TX4927_IRQ_CP0_STARTUP
94 // | TX4927_IRQ_CP0_SHUTDOWN
95 // | TX4927_IRQ_CP0_ENABLE
96 // | TX4927_IRQ_CP0_DISABLE
97 // | TX4927_IRQ_CP0_MASK
98 // | TX4927_IRQ_CP0_ENDIRQ
99 // | TX4927_IRQ_PIC_INIT
100 // | TX4927_IRQ_PIC_STARTUP
101 // | TX4927_IRQ_PIC_SHUTDOWN
102 // | TX4927_IRQ_PIC_ENABLE
103 // | TX4927_IRQ_PIC_DISABLE
104 // | TX4927_IRQ_PIC_MASK
105 // | TX4927_IRQ_PIC_ENDIRQ
107 // | TX4927_IRQ_NEST1
108 // | TX4927_IRQ_NEST2
109 // | TX4927_IRQ_NEST3
110 // | TX4927_IRQ_NEST4
114 #ifdef TX4927_IRQ_DEBUG
115 #define TX4927_IRQ_DPRINTK(flag,str...) \
116 if ( (tx4927_irq_debug_flag) & (flag) ) \
119 sprintf( tmp, str ); \
120 printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
123 #define TX4927_IRQ_DPRINTK(flag,str...)
127 * Forwad definitions for all pic's
130 static unsigned int tx4927_irq_cp0_startup(unsigned int irq);
131 static void tx4927_irq_cp0_shutdown(unsigned int irq);
132 static void tx4927_irq_cp0_enable(unsigned int irq);
133 static void tx4927_irq_cp0_disable(unsigned int irq);
134 static void tx4927_irq_cp0_mask_and_ack(unsigned int irq);
135 static void tx4927_irq_cp0_end(unsigned int irq);
137 static unsigned int tx4927_irq_pic_startup(unsigned int irq);
138 static void tx4927_irq_pic_shutdown(unsigned int irq);
139 static void tx4927_irq_pic_enable(unsigned int irq);
140 static void tx4927_irq_pic_disable(unsigned int irq);
141 static void tx4927_irq_pic_mask_and_ack(unsigned int irq);
142 static void tx4927_irq_pic_end(unsigned int irq);
145 * Kernel structs for all pic's
148 static spinlock_t tx4927_cp0_lock = SPIN_LOCK_UNLOCKED;
149 static spinlock_t tx4927_pic_lock = SPIN_LOCK_UNLOCKED;
151 #define TX4927_CP0_NAME "TX4927-CP0"
152 static struct hw_interrupt_type tx4927_irq_cp0_type = {
153 .typename = TX4927_CP0_NAME,
154 .startup = tx4927_irq_cp0_startup,
155 .shutdown = tx4927_irq_cp0_shutdown,
156 .enable = tx4927_irq_cp0_enable,
157 .disable = tx4927_irq_cp0_disable,
158 .ack = tx4927_irq_cp0_mask_and_ack,
159 .end = tx4927_irq_cp0_end,
163 #define TX4927_PIC_NAME "TX4927-PIC"
164 static struct hw_interrupt_type tx4927_irq_pic_type = {
165 .typename = TX4927_PIC_NAME,
166 .startup = tx4927_irq_pic_startup,
167 .shutdown = tx4927_irq_pic_shutdown,
168 .enable = tx4927_irq_pic_enable,
169 .disable = tx4927_irq_pic_disable,
170 .ack = tx4927_irq_pic_mask_and_ack,
171 .end = tx4927_irq_pic_end,
175 #define TX4927_PIC_ACTION(s) { no_action, 0, 0, s, NULL, NULL }
176 static struct irqaction tx4927_irq_pic_action =
177 TX4927_PIC_ACTION(TX4927_PIC_NAME);
179 #define CCP0_STATUS 12
180 #define CCP0_CAUSE 13
186 #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
189 tx4927_irq_cp0_modify(unsigned cp0_reg, unsigned clr_bits, unsigned set_bits)
191 unsigned long val = 0;
195 val = read_c0_status();
199 val = read_c0_cause();
209 write_c0_status(val);
221 static void __init tx4927_irq_cp0_init(void)
225 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT, "beg=%d end=%d\n",
226 TX4927_IRQ_CP0_BEG, TX4927_IRQ_CP0_END);
228 for (i = TX4927_IRQ_CP0_BEG; i <= TX4927_IRQ_CP0_END; i++) {
229 irq_desc[i].status = IRQ_DISABLED;
230 irq_desc[i].action = 0;
231 irq_desc[i].depth = 1;
232 irq_desc[i].handler = &tx4927_irq_cp0_type;
238 static unsigned int tx4927_irq_cp0_startup(unsigned int irq)
240 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_STARTUP, "irq=%d \n", irq);
242 #ifdef TX4927_IRQ_CHECK_CP0
244 if (irq < TX4927_IRQ_CP0_BEG || irq > TX4927_IRQ_CP0_END) {
245 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
246 "bad irq=%d \n", irq);
252 tx4927_irq_cp0_enable(irq);
257 static void tx4927_irq_cp0_shutdown(unsigned int irq)
259 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_SHUTDOWN, "irq=%d \n", irq);
261 #ifdef TX4927_IRQ_CHECK_CP0
263 if (irq < TX4927_IRQ_CP0_BEG || irq > TX4927_IRQ_CP0_END) {
264 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
265 "bad irq=%d \n", irq);
271 tx4927_irq_cp0_disable(irq);
276 static void tx4927_irq_cp0_enable(unsigned int irq)
280 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE, "irq=%d \n", irq);
282 #ifdef TX4927_IRQ_CHECK_CP0
284 if (irq < TX4927_IRQ_CP0_BEG || irq > TX4927_IRQ_CP0_END) {
285 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
286 "bad irq=%d \n", irq);
292 spin_lock_irqsave(&tx4927_cp0_lock, flags);
294 tx4927_irq_cp0_modify(CCP0_STATUS, 0, tx4927_irq_cp0_mask(irq));
296 spin_unlock_irqrestore(&tx4927_cp0_lock, flags);
301 static void tx4927_irq_cp0_disable(unsigned int irq)
305 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE, "irq=%d \n", irq);
307 #ifdef TX4927_IRQ_CHECK_CP0
309 if (irq < TX4927_IRQ_CP0_BEG || irq > TX4927_IRQ_CP0_END) {
310 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
311 "bad irq=%d \n", irq);
317 spin_lock_irqsave(&tx4927_cp0_lock, flags);
319 tx4927_irq_cp0_modify(CCP0_STATUS, tx4927_irq_cp0_mask(irq), 0);
321 spin_unlock_irqrestore(&tx4927_cp0_lock, flags);
326 static void tx4927_irq_cp0_mask_and_ack(unsigned int irq)
328 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_MASK, "irq=%d \n", irq);
330 #ifdef TX4927_IRQ_CHECK_CP0
332 if (irq < TX4927_IRQ_CP0_BEG || irq > TX4927_IRQ_CP0_END) {
333 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
334 "bad irq=%d \n", irq);
340 tx4927_irq_cp0_disable(irq);
345 static void tx4927_irq_cp0_end(unsigned int irq)
347 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENDIRQ, "irq=%d \n", irq);
349 #ifdef TX4927_IRQ_CHECK_CP0
351 if (irq < TX4927_IRQ_CP0_BEG || irq > TX4927_IRQ_CP0_END) {
352 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
353 "bad irq=%d \n", irq);
359 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
360 tx4927_irq_cp0_enable(irq);
369 u32 tx4927_irq_pic_addr(int irq)
371 /* MVMCP -- need to formulize this */
372 irq -= TX4927_IRQ_PIC_BEG;
426 u32 tx4927_irq_pic_mask(int irq)
428 /* MVMCP -- need to formulize this */
429 irq -= TX4927_IRQ_PIC_BEG;
475 static void tx4927_irq_pic_modify(unsigned pic_reg, unsigned clr_bits,
478 unsigned long val = 0;
480 val = TX4927_RD(pic_reg);
483 TX4927_WR(pic_reg, val);
488 static void __init tx4927_irq_pic_init(void)
493 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT, "beg=%d end=%d\n",
494 TX4927_IRQ_PIC_BEG, TX4927_IRQ_PIC_END);
496 for (i = TX4927_IRQ_PIC_BEG; i <= TX4927_IRQ_PIC_END; i++) {
497 irq_desc[i].status = IRQ_DISABLED;
498 irq_desc[i].action = 0;
499 irq_desc[i].depth = 2;
500 irq_desc[i].handler = &tx4927_irq_pic_type;
503 setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0, &tx4927_irq_pic_action);
505 spin_lock_irqsave(&tx4927_pic_lock, flags);
507 TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
508 TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
510 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
515 static unsigned int tx4927_irq_pic_startup(unsigned int irq)
517 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_STARTUP, "irq=%d\n", irq);
519 #ifdef TX4927_IRQ_CHECK_PIC
521 if (irq < TX4927_IRQ_PIC_BEG || irq > TX4927_IRQ_PIC_END) {
522 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
523 "bad irq=%d \n", irq);
529 tx4927_irq_pic_enable(irq);
534 static void tx4927_irq_pic_shutdown(unsigned int irq)
536 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_SHUTDOWN, "irq=%d\n", irq);
538 #ifdef TX4927_IRQ_CHECK_PIC
540 if (irq < TX4927_IRQ_PIC_BEG || irq > TX4927_IRQ_PIC_END) {
541 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
542 "bad irq=%d \n", irq);
548 tx4927_irq_pic_disable(irq);
553 static void tx4927_irq_pic_enable(unsigned int irq)
557 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE, "irq=%d\n", irq);
559 #ifdef TX4927_IRQ_CHECK_PIC
561 if (irq < TX4927_IRQ_PIC_BEG || irq > TX4927_IRQ_PIC_END) {
562 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
563 "bad irq=%d \n", irq);
569 spin_lock_irqsave(&tx4927_pic_lock, flags);
571 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq), 0,
572 tx4927_irq_pic_mask(irq));
574 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
579 static void tx4927_irq_pic_disable(unsigned int irq)
583 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE, "irq=%d\n", irq);
585 #ifdef TX4927_IRQ_CHECK_PIC
587 if (irq < TX4927_IRQ_PIC_BEG || irq > TX4927_IRQ_PIC_END) {
588 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
589 "bad irq=%d \n", irq);
595 spin_lock_irqsave(&tx4927_pic_lock, flags);
597 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq),
598 tx4927_irq_pic_mask(irq), 0);
600 spin_unlock_irqrestore(&tx4927_pic_lock, flags);
605 static void tx4927_irq_pic_mask_and_ack(unsigned int irq)
607 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_MASK, "irq=%d\n", irq);
609 #ifdef TX4927_IRQ_CHECK_PIC
611 if (irq < TX4927_IRQ_PIC_BEG || irq > TX4927_IRQ_PIC_END) {
612 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
613 "bad irq=%d \n", irq);
619 tx4927_irq_pic_disable(irq);
624 static void tx4927_irq_pic_end(unsigned int irq)
626 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENDIRQ, "irq=%d\n", irq);
628 #ifdef TX4927_IRQ_CHECK_PIC
630 if (irq < TX4927_IRQ_PIC_BEG || irq > TX4927_IRQ_PIC_END) {
631 TX4927_IRQ_DPRINTK(TX4927_IRQ_EROR,
632 "bad irq=%d \n", irq);
638 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
639 tx4927_irq_pic_enable(irq);
646 * Main init functions
648 void __init tx4927_irq_init(void)
650 extern asmlinkage void tx4927_irq_handler(void);
652 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "-\n");
654 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_cp0_init()\n");
655 tx4927_irq_cp0_init();
657 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_pic_init()\n");
658 tx4927_irq_pic_init();
660 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT,
661 "=Calling set_except_vector(tx4927_irq_handler)\n");
662 set_except_vector(0, tx4927_irq_handler);
664 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "+\n");
669 int tx4927_irq_nested(void)
674 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "-\n");
676 level2 = TX4927_RD(0xff1ff6a0);
677 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=level2a=0x%x\n", level2);
679 if ((level2 & 0x10000) == 0) {
681 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=level2b=0x%x\n", level2);
683 sw_irq = TX4927_IRQ_PIC_BEG + level2;
684 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=sw_irq=%d\n", sw_irq);
687 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq-%d\n",
690 #ifdef CONFIG_TOSHIBA_RBTX4927
692 sw_irq = toshiba_rbtx4927_irq_nested(sw_irq);
696 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq+%d\n",
701 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=sw_irq=%d\n", sw_irq);
703 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "+\n");