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 )
69 #define TX4927_IRQ_CP0_ENDIRQ ( 1 << 16 )
71 #define TX4927_IRQ_PIC_INIT ( 1 << 20 )
72 #define TX4927_IRQ_PIC_ENABLE ( 1 << 23 )
73 #define TX4927_IRQ_PIC_DISABLE ( 1 << 24 )
74 #define TX4927_IRQ_PIC_ENDIRQ ( 1 << 26 )
76 #define TX4927_IRQ_ALL 0xffffffff
79 #ifdef TX4927_IRQ_DEBUG
80 static const u32 tx4927_irq_debug_flag = (TX4927_IRQ_NONE
82 | TX4927_IRQ_WARN | TX4927_IRQ_EROR
83 // | TX4927_IRQ_CP0_INIT
84 // | TX4927_IRQ_CP0_ENABLE
85 // | TX4927_IRQ_CP0_DISABLE
86 // | TX4927_IRQ_CP0_ENDIRQ
87 // | TX4927_IRQ_PIC_INIT
88 // | TX4927_IRQ_PIC_ENABLE
89 // | TX4927_IRQ_PIC_DISABLE
90 // | TX4927_IRQ_PIC_ENDIRQ
99 #ifdef TX4927_IRQ_DEBUG
100 #define TX4927_IRQ_DPRINTK(flag,str...) \
101 if ( (tx4927_irq_debug_flag) & (flag) ) \
104 sprintf( tmp, str ); \
105 printk( "%s(%s:%u)::%s", __FUNCTION__, __FILE__, __LINE__, tmp ); \
108 #define TX4927_IRQ_DPRINTK(flag,str...)
112 * Forwad definitions for all pic's
115 static void tx4927_irq_cp0_enable(unsigned int irq);
116 static void tx4927_irq_cp0_disable(unsigned int irq);
117 static void tx4927_irq_cp0_end(unsigned int irq);
119 static void tx4927_irq_pic_enable(unsigned int irq);
120 static void tx4927_irq_pic_disable(unsigned int irq);
121 static void tx4927_irq_pic_end(unsigned int irq);
124 * Kernel structs for all pic's
127 #define TX4927_CP0_NAME "TX4927-CP0"
128 static struct irq_chip tx4927_irq_cp0_type = {
129 .typename = TX4927_CP0_NAME,
130 .ack = tx4927_irq_cp0_disable,
131 .mask = tx4927_irq_cp0_disable,
132 .mask_ack = tx4927_irq_cp0_disable,
133 .unmask = tx4927_irq_cp0_enable,
134 .end = tx4927_irq_cp0_end,
137 #define TX4927_PIC_NAME "TX4927-PIC"
138 static struct irq_chip tx4927_irq_pic_type = {
139 .typename = TX4927_PIC_NAME,
140 .ack = tx4927_irq_pic_disable,
141 .mask = tx4927_irq_pic_disable,
142 .mask_ack = tx4927_irq_pic_disable,
143 .unmask = tx4927_irq_pic_enable,
144 .end = tx4927_irq_pic_end,
147 #define TX4927_PIC_ACTION(s) { no_action, 0, CPU_MASK_NONE, s, NULL, NULL }
148 static struct irqaction tx4927_irq_pic_action =
149 TX4927_PIC_ACTION(TX4927_PIC_NAME);
151 #define CCP0_STATUS 12
152 #define CCP0_CAUSE 13
158 #define tx4927_irq_cp0_mask(irq) ( 1 << ( irq-TX4927_IRQ_CP0_BEG+8 ) )
161 tx4927_irq_cp0_modify(unsigned cp0_reg, unsigned clr_bits, unsigned set_bits)
163 unsigned long val = 0;
167 val = read_c0_status();
171 val = read_c0_cause();
181 write_c0_status(val);
191 static void __init tx4927_irq_cp0_init(void)
195 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_INIT, "beg=%d end=%d\n",
196 TX4927_IRQ_CP0_BEG, TX4927_IRQ_CP0_END);
198 for (i = TX4927_IRQ_CP0_BEG; i <= TX4927_IRQ_CP0_END; i++)
199 set_irq_chip_and_handler(i, &tx4927_irq_cp0_type,
203 static void tx4927_irq_cp0_enable(unsigned int irq)
205 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENABLE, "irq=%d \n", irq);
207 tx4927_irq_cp0_modify(CCP0_STATUS, 0, tx4927_irq_cp0_mask(irq));
210 static void tx4927_irq_cp0_disable(unsigned int irq)
212 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_DISABLE, "irq=%d \n", irq);
214 tx4927_irq_cp0_modify(CCP0_STATUS, tx4927_irq_cp0_mask(irq), 0);
217 static void tx4927_irq_cp0_end(unsigned int irq)
219 TX4927_IRQ_DPRINTK(TX4927_IRQ_CP0_ENDIRQ, "irq=%d \n", irq);
221 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
222 tx4927_irq_cp0_enable(irq);
229 u32 tx4927_irq_pic_addr(int irq)
231 /* MVMCP -- need to formulize this */
232 irq -= TX4927_IRQ_PIC_BEG;
286 u32 tx4927_irq_pic_mask(int irq)
288 /* MVMCP -- need to formulize this */
289 irq -= TX4927_IRQ_PIC_BEG;
335 static void tx4927_irq_pic_modify(unsigned pic_reg, unsigned clr_bits,
338 unsigned long val = 0;
340 val = TX4927_RD(pic_reg);
343 TX4927_WR(pic_reg, val);
346 static void __init tx4927_irq_pic_init(void)
350 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_INIT, "beg=%d end=%d\n",
351 TX4927_IRQ_PIC_BEG, TX4927_IRQ_PIC_END);
353 for (i = TX4927_IRQ_PIC_BEG; i <= TX4927_IRQ_PIC_END; i++)
354 set_irq_chip_and_handler(i, &tx4927_irq_pic_type,
357 setup_irq(TX4927_IRQ_NEST_PIC_ON_CP0, &tx4927_irq_pic_action);
359 TX4927_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
360 TX4927_WR(0xff1ff600, TX4927_RD(0xff1ff600) | 0x1); /* irq enable */
363 static void tx4927_irq_pic_enable(unsigned int irq)
365 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENABLE, "irq=%d\n", irq);
367 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq), 0,
368 tx4927_irq_pic_mask(irq));
371 static void tx4927_irq_pic_disable(unsigned int irq)
373 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_DISABLE, "irq=%d\n", irq);
375 tx4927_irq_pic_modify(tx4927_irq_pic_addr(irq),
376 tx4927_irq_pic_mask(irq), 0);
379 static void tx4927_irq_pic_end(unsigned int irq)
381 TX4927_IRQ_DPRINTK(TX4927_IRQ_PIC_ENDIRQ, "irq=%d\n", irq);
383 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
384 tx4927_irq_pic_enable(irq);
389 * Main init functions
391 void __init tx4927_irq_init(void)
393 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "-\n");
395 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_cp0_init()\n");
396 tx4927_irq_cp0_init();
398 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "=Calling tx4927_irq_pic_init()\n");
399 tx4927_irq_pic_init();
401 TX4927_IRQ_DPRINTK(TX4927_IRQ_INIT, "+\n");
404 static int tx4927_irq_nested(void)
409 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "-\n");
411 level2 = TX4927_RD(0xff1ff6a0);
412 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=level2a=0x%x\n", level2);
414 if ((level2 & 0x10000) == 0) {
416 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=level2b=0x%x\n", level2);
418 sw_irq = TX4927_IRQ_PIC_BEG + level2;
419 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST3, "=sw_irq=%d\n", sw_irq);
422 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq-%d\n",
425 #ifdef CONFIG_TOSHIBA_RBTX4927
427 sw_irq = toshiba_rbtx4927_irq_nested(sw_irq);
431 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST4, "=irq+%d\n",
436 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST2, "=sw_irq=%d\n", sw_irq);
438 TX4927_IRQ_DPRINTK(TX4927_IRQ_NEST1, "+\n");
443 asmlinkage void plat_irq_dispatch(void)
445 unsigned int pending = read_c0_status() & read_c0_cause();
447 if (pending & STATUSF_IP7) /* cpu timer */
448 do_IRQ(TX4927_IRQ_CPU_TIMER);
449 else if (pending & STATUSF_IP2) { /* tx4927 pic */
450 unsigned int irq = tx4927_irq_nested();
452 if (unlikely(irq == 0)) {
453 spurious_interrupt();
457 } else if (pending & STATUSF_IP0) /* user line 0 */
458 do_IRQ(TX4927_IRQ_USER0);
459 else if (pending & STATUSF_IP1) /* user line 1 */
460 do_IRQ(TX4927_IRQ_USER1);
462 spurious_interrupt();