[PATCH] genirq: rename desc->handler to desc->chip
[linux-2.6/linux-2.6-openrd.git] / arch / mips / tx4938 / common / irq.c
blob0b2f8c8492181e4724b5675fdffed196ba207877
1 /*
2 * linux/arch/mps/tx4938/common/irq.c
4 * Common tx4938 irq handler
5 * Copyright (C) 2000-2001 Toshiba Corporation
7 * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
8 * terms of the GNU General Public License version 2. This program is
9 * licensed "as is" without any warranty of any kind, whether express
10 * or implied.
12 * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
14 #include <linux/errno.h>
15 #include <linux/init.h>
16 #include <linux/kernel_stat.h>
17 #include <linux/module.h>
18 #include <linux/signal.h>
19 #include <linux/sched.h>
20 #include <linux/types.h>
21 #include <linux/interrupt.h>
22 #include <linux/ioport.h>
23 #include <linux/timex.h>
24 #include <linux/slab.h>
25 #include <linux/random.h>
26 #include <linux/irq.h>
27 #include <asm/bitops.h>
28 #include <asm/bootinfo.h>
29 #include <asm/io.h>
30 #include <asm/irq.h>
31 #include <asm/mipsregs.h>
32 #include <asm/system.h>
33 #include <asm/tx4938/rbtx4938.h>
35 /**********************************************************************************/
36 /* Forwad definitions for all pic's */
37 /**********************************************************************************/
39 static unsigned int tx4938_irq_cp0_startup(unsigned int irq);
40 static void tx4938_irq_cp0_shutdown(unsigned int irq);
41 static void tx4938_irq_cp0_enable(unsigned int irq);
42 static void tx4938_irq_cp0_disable(unsigned int irq);
43 static void tx4938_irq_cp0_mask_and_ack(unsigned int irq);
44 static void tx4938_irq_cp0_end(unsigned int irq);
46 static unsigned int tx4938_irq_pic_startup(unsigned int irq);
47 static void tx4938_irq_pic_shutdown(unsigned int irq);
48 static void tx4938_irq_pic_enable(unsigned int irq);
49 static void tx4938_irq_pic_disable(unsigned int irq);
50 static void tx4938_irq_pic_mask_and_ack(unsigned int irq);
51 static void tx4938_irq_pic_end(unsigned int irq);
53 /**********************************************************************************/
54 /* Kernel structs for all pic's */
55 /**********************************************************************************/
56 DEFINE_SPINLOCK(tx4938_cp0_lock);
57 DEFINE_SPINLOCK(tx4938_pic_lock);
59 #define TX4938_CP0_NAME "TX4938-CP0"
60 static struct hw_interrupt_type tx4938_irq_cp0_type = {
61 .typename = TX4938_CP0_NAME,
62 .startup = tx4938_irq_cp0_startup,
63 .shutdown = tx4938_irq_cp0_shutdown,
64 .enable = tx4938_irq_cp0_enable,
65 .disable = tx4938_irq_cp0_disable,
66 .ack = tx4938_irq_cp0_mask_and_ack,
67 .end = tx4938_irq_cp0_end,
68 .set_affinity = NULL
71 #define TX4938_PIC_NAME "TX4938-PIC"
72 static struct hw_interrupt_type tx4938_irq_pic_type = {
73 .typename = TX4938_PIC_NAME,
74 .startup = tx4938_irq_pic_startup,
75 .shutdown = tx4938_irq_pic_shutdown,
76 .enable = tx4938_irq_pic_enable,
77 .disable = tx4938_irq_pic_disable,
78 .ack = tx4938_irq_pic_mask_and_ack,
79 .end = tx4938_irq_pic_end,
80 .set_affinity = NULL
83 static struct irqaction tx4938_irq_pic_action = {
84 .handler = no_action,
85 .flags = 0,
86 .mask = CPU_MASK_NONE,
87 .name = TX4938_PIC_NAME
90 /**********************************************************************************/
91 /* Functions for cp0 */
92 /**********************************************************************************/
94 #define tx4938_irq_cp0_mask(irq) ( 1 << ( irq-TX4938_IRQ_CP0_BEG+8 ) )
96 static void __init
97 tx4938_irq_cp0_init(void)
99 int i;
101 for (i = TX4938_IRQ_CP0_BEG; i <= TX4938_IRQ_CP0_END; i++) {
102 irq_desc[i].status = IRQ_DISABLED;
103 irq_desc[i].action = 0;
104 irq_desc[i].depth = 1;
105 irq_desc[i].chip = &tx4938_irq_cp0_type;
108 return;
111 static unsigned int
112 tx4938_irq_cp0_startup(unsigned int irq)
114 tx4938_irq_cp0_enable(irq);
116 return (0);
119 static void
120 tx4938_irq_cp0_shutdown(unsigned int irq)
122 tx4938_irq_cp0_disable(irq);
125 static void
126 tx4938_irq_cp0_enable(unsigned int irq)
128 unsigned long flags;
130 spin_lock_irqsave(&tx4938_cp0_lock, flags);
132 set_c0_status(tx4938_irq_cp0_mask(irq));
134 spin_unlock_irqrestore(&tx4938_cp0_lock, flags);
137 static void
138 tx4938_irq_cp0_disable(unsigned int irq)
140 unsigned long flags;
142 spin_lock_irqsave(&tx4938_cp0_lock, flags);
144 clear_c0_status(tx4938_irq_cp0_mask(irq));
146 spin_unlock_irqrestore(&tx4938_cp0_lock, flags);
148 return;
151 static void
152 tx4938_irq_cp0_mask_and_ack(unsigned int irq)
154 tx4938_irq_cp0_disable(irq);
156 return;
159 static void
160 tx4938_irq_cp0_end(unsigned int irq)
162 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
163 tx4938_irq_cp0_enable(irq);
166 return;
169 /**********************************************************************************/
170 /* Functions for pic */
171 /**********************************************************************************/
174 tx4938_irq_pic_addr(int irq)
176 /* MVMCP -- need to formulize this */
177 irq -= TX4938_IRQ_PIC_BEG;
179 switch (irq) {
180 case 17:
181 case 16:
182 case 1:
183 case 0:{
184 return (TX4938_MKA(TX4938_IRC_IRLVL0));
186 case 19:
187 case 18:
188 case 3:
189 case 2:{
190 return (TX4938_MKA(TX4938_IRC_IRLVL1));
192 case 21:
193 case 20:
194 case 5:
195 case 4:{
196 return (TX4938_MKA(TX4938_IRC_IRLVL2));
198 case 23:
199 case 22:
200 case 7:
201 case 6:{
202 return (TX4938_MKA(TX4938_IRC_IRLVL3));
204 case 25:
205 case 24:
206 case 9:
207 case 8:{
208 return (TX4938_MKA(TX4938_IRC_IRLVL4));
210 case 27:
211 case 26:
212 case 11:
213 case 10:{
214 return (TX4938_MKA(TX4938_IRC_IRLVL5));
216 case 29:
217 case 28:
218 case 13:
219 case 12:{
220 return (TX4938_MKA(TX4938_IRC_IRLVL6));
222 case 31:
223 case 30:
224 case 15:
225 case 14:{
226 return (TX4938_MKA(TX4938_IRC_IRLVL7));
230 return (0);
234 tx4938_irq_pic_mask(int irq)
236 /* MVMCP -- need to formulize this */
237 irq -= TX4938_IRQ_PIC_BEG;
239 switch (irq) {
240 case 31:
241 case 29:
242 case 27:
243 case 25:
244 case 23:
245 case 21:
246 case 19:
247 case 17:{
248 return (0x07000000);
250 case 30:
251 case 28:
252 case 26:
253 case 24:
254 case 22:
255 case 20:
256 case 18:
257 case 16:{
258 return (0x00070000);
260 case 15:
261 case 13:
262 case 11:
263 case 9:
264 case 7:
265 case 5:
266 case 3:
267 case 1:{
268 return (0x00000700);
270 case 14:
271 case 12:
272 case 10:
273 case 8:
274 case 6:
275 case 4:
276 case 2:
277 case 0:{
278 return (0x00000007);
281 return (0x00000000);
284 static void
285 tx4938_irq_pic_modify(unsigned pic_reg, unsigned clr_bits, unsigned set_bits)
287 unsigned long val = 0;
289 val = TX4938_RD(pic_reg);
290 val &= (~clr_bits);
291 val |= (set_bits);
292 TX4938_WR(pic_reg, val);
293 mmiowb();
294 TX4938_RD(pic_reg);
296 return;
299 static void __init
300 tx4938_irq_pic_init(void)
302 unsigned long flags;
303 int i;
305 for (i = TX4938_IRQ_PIC_BEG; i <= TX4938_IRQ_PIC_END; i++) {
306 irq_desc[i].status = IRQ_DISABLED;
307 irq_desc[i].action = 0;
308 irq_desc[i].depth = 2;
309 irq_desc[i].chip = &tx4938_irq_pic_type;
312 setup_irq(TX4938_IRQ_NEST_PIC_ON_CP0, &tx4938_irq_pic_action);
314 spin_lock_irqsave(&tx4938_pic_lock, flags);
316 TX4938_WR(0xff1ff640, 0x6); /* irq level mask -- only accept hightest */
317 TX4938_WR(0xff1ff600, TX4938_RD(0xff1ff600) | 0x1); /* irq enable */
319 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
321 return;
324 static unsigned int
325 tx4938_irq_pic_startup(unsigned int irq)
327 tx4938_irq_pic_enable(irq);
329 return (0);
332 static void
333 tx4938_irq_pic_shutdown(unsigned int irq)
335 tx4938_irq_pic_disable(irq);
337 return;
340 static void
341 tx4938_irq_pic_enable(unsigned int irq)
343 unsigned long flags;
345 spin_lock_irqsave(&tx4938_pic_lock, flags);
347 tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq), 0,
348 tx4938_irq_pic_mask(irq));
350 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
352 return;
355 static void
356 tx4938_irq_pic_disable(unsigned int irq)
358 unsigned long flags;
360 spin_lock_irqsave(&tx4938_pic_lock, flags);
362 tx4938_irq_pic_modify(tx4938_irq_pic_addr(irq),
363 tx4938_irq_pic_mask(irq), 0);
365 spin_unlock_irqrestore(&tx4938_pic_lock, flags);
367 return;
370 static void
371 tx4938_irq_pic_mask_and_ack(unsigned int irq)
373 tx4938_irq_pic_disable(irq);
375 return;
378 static void
379 tx4938_irq_pic_end(unsigned int irq)
381 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
382 tx4938_irq_pic_enable(irq);
385 return;
388 /**********************************************************************************/
389 /* Main init functions */
390 /**********************************************************************************/
392 void __init
393 tx4938_irq_init(void)
395 tx4938_irq_cp0_init();
396 tx4938_irq_pic_init();
398 return;
402 tx4938_irq_nested(void)
404 int sw_irq = 0;
405 u32 level2;
407 level2 = TX4938_RD(0xff1ff6a0);
408 if ((level2 & 0x10000) == 0) {
409 level2 &= 0x1f;
410 sw_irq = TX4938_IRQ_PIC_BEG + level2;
411 if (sw_irq == 26) {
413 extern int toshiba_rbtx4938_irq_nested(int sw_irq);
414 sw_irq = toshiba_rbtx4938_irq_nested(sw_irq);
419 wbflush();
420 return (sw_irq);
423 asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
425 unsigned int pending = read_c0_cause() & read_c0_status();
427 if (pending & STATUSF_IP7)
428 do_IRQ(TX4938_IRQ_CPU_TIMER, regs);
429 else if (pending & STATUSF_IP2) {
430 int irq = tx4938_irq_nested();
431 if (irq)
432 do_IRQ(irq, regs);
433 else
434 spurious_interrupt(regs);
435 } else if (pending & STATUSF_IP1)
436 do_IRQ(TX4938_IRQ_USER1, regs);
437 else if (pending & STATUSF_IP0)
438 do_IRQ(TX4938_IRQ_USER0, regs);