[ARM] Support register switch in nommu mode
[linux-2.6/verdex.git] / arch / mips / ddb5xxx / ddb5477 / irq_5477.c
blob5fcd5f070cdcf6a52cdf5a9ed52185be36932fbb
1 /*
2 * Copyright 2001 MontaVista Software Inc.
3 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
5 * arch/mips/ddb5xxx/ddb5477/irq_5477.c
6 * This file defines the irq handler for Vrc5477.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
16 * Vrc5477 defines 32 IRQs.
18 * This file exports one function:
19 * vrc5477_irq_init(u32 irq_base);
22 #include <linux/interrupt.h>
23 #include <linux/types.h>
24 #include <linux/ptrace.h>
26 #include <asm/debug.h>
28 #include <asm/ddb5xxx/ddb5xxx.h>
30 /* number of total irqs supported by Vrc5477 */
31 #define NUM_5477_IRQ 32
33 static int vrc5477_irq_base = -1;
36 static void
37 vrc5477_irq_enable(unsigned int irq)
39 db_assert(vrc5477_irq_base != -1);
40 db_assert(irq >= vrc5477_irq_base);
41 db_assert(irq < vrc5477_irq_base+ NUM_5477_IRQ);
43 ll_vrc5477_irq_enable(irq - vrc5477_irq_base);
46 static void
47 vrc5477_irq_disable(unsigned int irq)
49 db_assert(vrc5477_irq_base != -1);
50 db_assert(irq >= vrc5477_irq_base);
51 db_assert(irq < vrc5477_irq_base + NUM_5477_IRQ);
53 ll_vrc5477_irq_disable(irq - vrc5477_irq_base);
56 static unsigned int vrc5477_irq_startup(unsigned int irq)
58 vrc5477_irq_enable(irq);
59 return 0;
62 #define vrc5477_irq_shutdown vrc5477_irq_disable
64 static void
65 vrc5477_irq_ack(unsigned int irq)
67 db_assert(vrc5477_irq_base != -1);
68 db_assert(irq >= vrc5477_irq_base);
69 db_assert(irq < vrc5477_irq_base+ NUM_5477_IRQ);
71 /* clear the interrupt bit */
72 /* some irqs require the driver to clear the sources */
73 ddb_out32(DDB_INTCLR32, 1 << (irq - vrc5477_irq_base));
75 /* disable interrupt - some handler will re-enable the irq
76 * and if the interrupt is leveled, we will have infinite loop
78 ll_vrc5477_irq_disable(irq - vrc5477_irq_base);
81 static void
82 vrc5477_irq_end(unsigned int irq)
84 db_assert(vrc5477_irq_base != -1);
85 db_assert(irq >= vrc5477_irq_base);
86 db_assert(irq < vrc5477_irq_base + NUM_5477_IRQ);
88 if(!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
89 ll_vrc5477_irq_enable( irq - vrc5477_irq_base);
92 hw_irq_controller vrc5477_irq_controller = {
93 .typename = "vrc5477_irq",
94 .startup = vrc5477_irq_startup,
95 .shutdown = vrc5477_irq_shutdown,
96 .enable = vrc5477_irq_enable,
97 .disable = vrc5477_irq_disable,
98 .ack = vrc5477_irq_ack,
99 .end = vrc5477_irq_end
102 void __init vrc5477_irq_init(u32 irq_base)
104 u32 i;
106 for (i= irq_base; i< irq_base+ NUM_5477_IRQ; i++) {
107 irq_desc[i].status = IRQ_DISABLED;
108 irq_desc[i].action = NULL;
109 irq_desc[i].depth = 1;
110 irq_desc[i].handler = &vrc5477_irq_controller;
113 vrc5477_irq_base = irq_base;
116 void ll_vrc5477_irq_route(int vrc5477_irq, int ip)
118 u32 reg_value;
119 u32 reg_bitmask;
120 u32 reg_index;
122 db_assert(vrc5477_irq >= 0);
123 db_assert(vrc5477_irq < NUM_5477_IRQ);
124 db_assert(ip >= 0);
125 db_assert((ip < 5) || (ip == 6));
127 reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
128 reg_value = ddb_in32(reg_index);
129 reg_bitmask = 7 << (vrc5477_irq % 8 * 4);
130 reg_value &= ~reg_bitmask;
131 reg_value |= ip << (vrc5477_irq % 8 * 4);
132 ddb_out32(reg_index, reg_value);
135 void ll_vrc5477_irq_enable(int vrc5477_irq)
137 u32 reg_value;
138 u32 reg_bitmask;
139 u32 reg_index;
141 db_assert(vrc5477_irq >= 0);
142 db_assert(vrc5477_irq < NUM_5477_IRQ);
144 reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
145 reg_value = ddb_in32(reg_index);
146 reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
147 db_assert((reg_value & reg_bitmask) == 0);
148 ddb_out32(reg_index, reg_value | reg_bitmask);
151 void ll_vrc5477_irq_disable(int vrc5477_irq)
153 u32 reg_value;
154 u32 reg_bitmask;
155 u32 reg_index;
157 db_assert(vrc5477_irq >= 0);
158 db_assert(vrc5477_irq < NUM_5477_IRQ);
160 reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4;
161 reg_value = ddb_in32(reg_index);
162 reg_bitmask = 8 << (vrc5477_irq % 8 * 4);
164 /* we assert that the interrupt is enabled (perhaps over-zealous) */
165 db_assert( (reg_value & reg_bitmask) != 0);
166 ddb_out32(reg_index, reg_value & ~reg_bitmask);