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_ENABLE ( 1 << 13 )
68 #define TX4927_IRQ_CP0_DISABLE ( 1 << 14 )
70 #define TX4927_IRQ_PIC_INIT ( 1 << 20 )
71 #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
72 #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
74 #define TX4927_IRQ_ALL 0xffffffff
77 #ifdef TX4927_IRQ_DEBUG
78 static const u32 tx4927_irq_debug_flag
= (TX4927_IRQ_NONE
80 | TX4927_IRQ_WARN
| TX4927_IRQ_EROR
81 // | TX4927_IRQ_CP0_INIT
82 // | TX4927_IRQ_CP0_ENABLE
83 // | TX4927_IRQ_CP0_ENDIRQ
84 // | TX4927_IRQ_PIC_INIT
85 // | TX4927_IRQ_PIC_ENABLE
86 // | TX4927_IRQ_PIC_DISABLE
95 #ifdef TX4927_IRQ_DEBUG
96 #define TX4927_IRQ_DPRINTK(flag,str...) \
97 if ( (tx4927_irq_debug_flag) & (flag) ) \
100 sprintf( tmp, str ); \
101 printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
104 #define TX4927_IRQ_DPRINTK(flag,str...)
108 * Forwad definitions for all pic's
111 static void tx4927_irq_cp0_enable(unsigned int irq
);
112 static void tx4927_irq_cp0_disable(unsigned int irq
);
114 static void tx4927_irq_pic_enable(unsigned int irq
);
115 static void tx4927_irq_pic_disable(unsigned int irq
);
118 * Kernel structs for all pic's
121 #define TX4927_CP0_NAME "TX4927-CP0"
122 static struct irq_chip tx4927_irq_cp0_type
= {
123 .name
= TX4927_CP0_NAME
,
124 .ack
= tx4927_irq_cp0_disable
,
125 .mask
= tx4927_irq_cp0_disable
,
126 .mask_ack
= tx4927_irq_cp0_disable
,
127 .unmask
= tx4927_irq_cp0_enable
,
130 #define TX4927_PIC_NAME "TX4927-PIC"
131 static struct irq_chip tx4927_irq_pic_type
= {
132 .name
= TX4927_PIC_NAME
,
133 .ack
= tx4927_irq_pic_disable
,
134 .mask
= tx4927_irq_pic_disable
,
135 .mask_ack
= tx4927_irq_pic_disable
,
136 .unmask
= tx4927_irq_pic_enable
,
139 #define TX4927_PIC_ACTION(s) { no_action, 0, CPU_MASK_NONE, s, NULL, NULL }
140 static struct irqaction tx4927_irq_pic_action
=
141 TX4927_PIC_ACTION(TX4927_PIC_NAME
);
143 #define CCP0_STATUS 12
144 #define CCP0_CAUSE 13
150 #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
153 tx4927_irq_cp0_modify(unsigned cp0_reg
, unsigned clr_bits
, unsigned set_bits
)
155 unsigned long val
= 0;
159 val
= read_c0_status();
163 val
= read_c0_cause();
173 write_c0_status(val
);
183 static void __init
tx4927_irq_cp0_init(void)
187 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT
, "beg=%d end=%d\n",
188 TX4927_IRQ_CP0_BEG
, TX4927_IRQ_CP0_END
);
190 for (i
= TX4927_IRQ_CP0_BEG
; i
<= TX4927_IRQ_CP0_END
; i
++)
191 set_irq_chip_and_handler(i
, &tx4927_irq_cp0_type
,
195 static void tx4927_irq_cp0_enable(unsigned int irq
)
197 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE
, "irq=%d \n", irq
);
199 tx4927_irq_cp0_modify(CCP0_STATUS
, 0, tx4927_irq_cp0_mask(irq
));
202 static void tx4927_irq_cp0_disable(unsigned int irq
)
204 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE
, "irq=%d \n", irq
);
206 tx4927_irq_cp0_modify(CCP0_STATUS
, tx4927_irq_cp0_mask(irq
), 0);
212 u32
tx4927_irq_pic_addr(int irq
)
214 /* MVMCP -- need to formulize this */
215 irq
-= TX4927_IRQ_PIC_BEG
;
269 u32
tx4927_irq_pic_mask(int irq
)
271 /* MVMCP -- need to formulize this */
272 irq
-= TX4927_IRQ_PIC_BEG
;
318 static void tx4927_irq_pic_modify(unsigned pic_reg
, unsigned clr_bits
,
321 unsigned long val
= 0;
323 val
= TX4927_RD(pic_reg
);
326 TX4927_WR(pic_reg
, val
);
329 static void __init
tx4927_irq_pic_init(void)
333 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT
, "beg=%d end=%d\n",
334 TX4927_IRQ_PIC_BEG
, TX4927_IRQ_PIC_END
);
336 for (i
= TX4927_IRQ_PIC_BEG
; i
<= TX4927_IRQ_PIC_END
; i
++)
337 set_irq_chip_and_handler(i
, &tx4927_irq_pic_type
,
340 setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0
, &tx4927_irq_pic_action
);
342 TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
343 TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
346 static void tx4927_irq_pic_enable(unsigned int irq
)
348 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE
, "irq=%d\n", irq
);
350 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq
), 0,
351 tx4927_irq_pic_mask(irq
));
354 static void tx4927_irq_pic_disable(unsigned int irq
)
356 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE
, "irq=%d\n", irq
);
358 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq
),
359 tx4927_irq_pic_mask(irq
), 0);
363 * Main init functions
365 void __init
tx4927_irq_init(void)
367 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT
, "-\n");
369 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT
, "=Calling tx4927_irq_cp0_init()\n");
370 tx4927_irq_cp0_init();
372 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT
, "=Calling tx4927_irq_pic_init()\n");
373 tx4927_irq_pic_init();
375 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT
, "+\n");
378 static int tx4927_irq_nested(void)
383 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1
, "-\n");
385 level2
= TX4927_RD(0xff1ff6a0);
386 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2
, "=level2a=0x%x\n", level2
);
388 if ((level2
& 0x10000) == 0) {
390 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3
, "=level2b=0x%x\n", level2
);
392 sw_irq
= TX4927_IRQ_PIC_BEG
+ level2
;
393 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3
, "=sw_irq=%d\n", sw_irq
);
396 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4
, "=irq-%d\n",
399 #ifdef CONFIG_TOSHIBA_RBTX4927
401 sw_irq
= toshiba_rbtx4927_irq_nested(sw_irq
);
405 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4
, "=irq+%d\n",
410 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2
, "=sw_irq=%d\n", sw_irq
);
412 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1
, "+\n");
417 asmlinkage
void plat_irq_dispatch(void)
419 unsigned int pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
421 if (pending
& STATUSF_IP7
) /* cpu timer */
422 do_IRQ(TX4927_IRQ_CPU_TIMER
);
423 else if (pending
& STATUSF_IP2
) { /* tx4927 pic */
424 unsigned int irq
= tx4927_irq_nested();
426 if (unlikely(irq
== 0)) {
427 spurious_interrupt();
431 } else if (pending
& STATUSF_IP0
) /* user line 0 */
432 do_IRQ(TX4927_IRQ_USER0
);
433 else if (pending
& STATUSF_IP1
) /* user line 1 */
434 do_IRQ(TX4927_IRQ_USER1
);
436 spurious_interrupt();