]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright 2001 MontaVista Software Inc. | |
3 | * Author: Jun Sun, [email protected] or [email protected] | |
4 | * | |
5 | * arch/mips/ddb5xxx/ddb5477/irq_5477.c | |
6 | * This file defines the irq handler for Vrc5477. | |
7 | * | |
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. | |
12 | * | |
13 | */ | |
14 | ||
15 | /* | |
16 | * Vrc5477 defines 32 IRQs. | |
17 | * | |
18 | * This file exports one function: | |
19 | * vrc5477_irq_init(u32 irq_base); | |
20 | */ | |
21 | ||
22 | #include <linux/interrupt.h> | |
23 | #include <linux/types.h> | |
24 | #include <linux/ptrace.h> | |
25 | ||
26 | #include <asm/debug.h> | |
27 | ||
28 | #include <asm/ddb5xxx/ddb5xxx.h> | |
29 | ||
30 | /* number of total irqs supported by Vrc5477 */ | |
31 | #define NUM_5477_IRQ 32 | |
32 | ||
33 | static int vrc5477_irq_base = -1; | |
34 | ||
35 | ||
36 | static void | |
37 | vrc5477_irq_enable(unsigned int irq) | |
38 | { | |
39 | db_assert(vrc5477_irq_base != -1); | |
40 | db_assert(irq >= vrc5477_irq_base); | |
41 | db_assert(irq < vrc5477_irq_base+ NUM_5477_IRQ); | |
42 | ||
43 | ll_vrc5477_irq_enable(irq - vrc5477_irq_base); | |
44 | } | |
45 | ||
46 | static void | |
47 | vrc5477_irq_disable(unsigned int irq) | |
48 | { | |
49 | db_assert(vrc5477_irq_base != -1); | |
50 | db_assert(irq >= vrc5477_irq_base); | |
51 | db_assert(irq < vrc5477_irq_base + NUM_5477_IRQ); | |
52 | ||
53 | ll_vrc5477_irq_disable(irq - vrc5477_irq_base); | |
54 | } | |
55 | ||
56 | static unsigned int vrc5477_irq_startup(unsigned int irq) | |
57 | { | |
58 | vrc5477_irq_enable(irq); | |
59 | return 0; | |
60 | } | |
61 | ||
62 | #define vrc5477_irq_shutdown vrc5477_irq_disable | |
63 | ||
64 | static void | |
65 | vrc5477_irq_ack(unsigned int irq) | |
66 | { | |
67 | db_assert(vrc5477_irq_base != -1); | |
68 | db_assert(irq >= vrc5477_irq_base); | |
69 | db_assert(irq < vrc5477_irq_base+ NUM_5477_IRQ); | |
70 | ||
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)); | |
74 | ||
75 | /* disable interrupt - some handler will re-enable the irq | |
76 | * and if the interrupt is leveled, we will have infinite loop | |
77 | */ | |
78 | ll_vrc5477_irq_disable(irq - vrc5477_irq_base); | |
79 | } | |
80 | ||
81 | static void | |
82 | vrc5477_irq_end(unsigned int irq) | |
83 | { | |
84 | db_assert(vrc5477_irq_base != -1); | |
85 | db_assert(irq >= vrc5477_irq_base); | |
86 | db_assert(irq < vrc5477_irq_base + NUM_5477_IRQ); | |
87 | ||
88 | if(!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) | |
89 | ll_vrc5477_irq_enable( irq - vrc5477_irq_base); | |
90 | } | |
91 | ||
94dee171 | 92 | struct irq_chip vrc5477_irq_controller = { |
8ab00b9a RB |
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 | |
1da177e4 LT |
100 | }; |
101 | ||
102 | void __init vrc5477_irq_init(u32 irq_base) | |
103 | { | |
104 | u32 i; | |
105 | ||
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; | |
d1bef4ed | 110 | irq_desc[i].chip = &vrc5477_irq_controller; |
1da177e4 LT |
111 | } |
112 | ||
113 | vrc5477_irq_base = irq_base; | |
114 | } | |
115 | ||
116 | void ll_vrc5477_irq_route(int vrc5477_irq, int ip) | |
117 | { | |
118 | u32 reg_value; | |
119 | u32 reg_bitmask; | |
120 | u32 reg_index; | |
121 | ||
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)); | |
126 | ||
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); | |
133 | } | |
134 | ||
135 | void ll_vrc5477_irq_enable(int vrc5477_irq) | |
136 | { | |
137 | u32 reg_value; | |
138 | u32 reg_bitmask; | |
139 | u32 reg_index; | |
140 | ||
141 | db_assert(vrc5477_irq >= 0); | |
142 | db_assert(vrc5477_irq < NUM_5477_IRQ); | |
143 | ||
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); | |
149 | } | |
150 | ||
151 | void ll_vrc5477_irq_disable(int vrc5477_irq) | |
152 | { | |
153 | u32 reg_value; | |
154 | u32 reg_bitmask; | |
155 | u32 reg_index; | |
156 | ||
157 | db_assert(vrc5477_irq >= 0); | |
158 | db_assert(vrc5477_irq < NUM_5477_IRQ); | |
159 | ||
160 | reg_index = DDB_INTCTRL0 + vrc5477_irq/8*4; | |
161 | reg_value = ddb_in32(reg_index); | |
162 | reg_bitmask = 8 << (vrc5477_irq % 8 * 4); | |
163 | ||
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); | |
167 | } |