diff options
author | Magnus Damm <damm@igel.co.jp> | 2007-07-18 04:25:09 -0400 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2007-07-19 23:18:20 -0400 |
commit | 02ab3f70791f7d5c9098acaa31a72dd7d0961cb0 (patch) | |
tree | b95f0ec8cc57ed2166eb28e53bb604374e6f0f44 | |
parent | 53aba19f82045c1df838570b8484043e93c4442a (diff) |
sh: intc - shared IPR and INTC2 controller
This is the second version of the shared interrupt controller patch
for the sh architecture, fixing up handling of intc_reg_fns[].
The three main advantages with this controller over the existing
ones are:
- Both priority (ipr) and bitmap (intc2) registers are
supported
- External pin sense configuration is supported, ie edge
vs level triggered
- CPU/Board specific code maps 1:1 with datasheet for
easy verification
This controller can easily coexist with the current IPR and INTC2
controllers, but the idea is that CPUs/Boards should be moved over
to this controller over time so we have a single code base to
maintain.
Signed-off-by: Magnus Damm <damm@igel.co.jp>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
-rw-r--r-- | arch/sh/Kconfig | 3 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/irq/Makefile | 1 | ||||
-rw-r--r-- | arch/sh/kernel/cpu/irq/intc.c | 352 | ||||
-rw-r--r-- | include/asm-sh/hw_irq.h | 68 |
4 files changed, 424 insertions, 0 deletions
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index d8ed6676ae86..3ac6db263ed8 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig | |||
@@ -178,6 +178,9 @@ config CPU_HAS_PINT_IRQ | |||
178 | config CPU_HAS_MASKREG_IRQ | 178 | config CPU_HAS_MASKREG_IRQ |
179 | bool | 179 | bool |
180 | 180 | ||
181 | config CPU_HAS_INTC_IRQ | ||
182 | bool | ||
183 | |||
181 | config CPU_HAS_INTC2_IRQ | 184 | config CPU_HAS_INTC2_IRQ |
182 | bool | 185 | bool |
183 | 186 | ||
diff --git a/arch/sh/kernel/cpu/irq/Makefile b/arch/sh/kernel/cpu/irq/Makefile index 1c23308cfc25..9ddb446ac930 100644 --- a/arch/sh/kernel/cpu/irq/Makefile +++ b/arch/sh/kernel/cpu/irq/Makefile | |||
@@ -6,4 +6,5 @@ obj-y += imask.o | |||
6 | obj-$(CONFIG_CPU_HAS_IPR_IRQ) += ipr.o | 6 | obj-$(CONFIG_CPU_HAS_IPR_IRQ) += ipr.o |
7 | obj-$(CONFIG_CPU_HAS_PINT_IRQ) += pint.o | 7 | obj-$(CONFIG_CPU_HAS_PINT_IRQ) += pint.o |
8 | obj-$(CONFIG_CPU_HAS_MASKREG_IRQ) += maskreg.o | 8 | obj-$(CONFIG_CPU_HAS_MASKREG_IRQ) += maskreg.o |
9 | obj-$(CONFIG_CPU_HAS_INTC_IRQ) += intc.o | ||
9 | obj-$(CONFIG_CPU_HAS_INTC2_IRQ) += intc2.o | 10 | obj-$(CONFIG_CPU_HAS_INTC2_IRQ) += intc2.o |
diff --git a/arch/sh/kernel/cpu/irq/intc.c b/arch/sh/kernel/cpu/irq/intc.c new file mode 100644 index 000000000000..626b4d8d7932 --- /dev/null +++ b/arch/sh/kernel/cpu/irq/intc.c | |||
@@ -0,0 +1,352 @@ | |||
1 | /* | ||
2 | * Shared interrupt handling code for IPR and INTC2 types of IRQs. | ||
3 | * | ||
4 | * Copyright (C) 2007 Magnus Damm | ||
5 | * | ||
6 | * Based on intc2.c and ipr.c | ||
7 | * | ||
8 | * Copyright (C) 1999 Niibe Yutaka & Takeshi Yaegashi | ||
9 | * Copyright (C) 2000 Kazumoto Kojima | ||
10 | * Copyright (C) 2001 David J. Mckay (david.mckay@st.com) | ||
11 | * Copyright (C) 2003 Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp> | ||
12 | * Copyright (C) 2005, 2006 Paul Mundt | ||
13 | * | ||
14 | * This file is subject to the terms and conditions of the GNU General Public | ||
15 | * License. See the file "COPYING" in the main directory of this archive | ||
16 | * for more details. | ||
17 | */ | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/irq.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <linux/interrupt.h> | ||
23 | |||
24 | #define _INTC_MK(fn, idx, bit, value) \ | ||
25 | ((fn) << 24 | ((value) << 16) | ((idx) << 8) | (bit)) | ||
26 | #define _INTC_FN(h) (h >> 24) | ||
27 | #define _INTC_VALUE(h) ((h >> 16) & 0xff) | ||
28 | #define _INTC_IDX(h) ((h >> 8) & 0xff) | ||
29 | #define _INTC_BIT(h) (h & 0xff) | ||
30 | |||
31 | #define _INTC_PTR(desc, member, data) \ | ||
32 | (desc->member + _INTC_IDX(data)) | ||
33 | |||
34 | static inline struct intc_desc *get_intc_desc(unsigned int irq) | ||
35 | { | ||
36 | struct irq_chip *chip = get_irq_chip(irq); | ||
37 | return (void *)((char *)chip - offsetof(struct intc_desc, chip)); | ||
38 | } | ||
39 | |||
40 | static inline unsigned int set_field(unsigned int value, | ||
41 | unsigned int field_value, | ||
42 | unsigned int width, | ||
43 | unsigned int shift) | ||
44 | { | ||
45 | value &= ~(((1 << width) - 1) << shift); | ||
46 | value |= field_value << shift; | ||
47 | return value; | ||
48 | } | ||
49 | |||
50 | static inline unsigned int set_prio_field(struct intc_desc *desc, | ||
51 | unsigned int value, | ||
52 | unsigned int priority, | ||
53 | unsigned int data) | ||
54 | { | ||
55 | unsigned int width = _INTC_PTR(desc, prio_regs, data)->field_width; | ||
56 | |||
57 | return set_field(value, priority, width, _INTC_BIT(data)); | ||
58 | } | ||
59 | |||
60 | static void disable_prio_16(struct intc_desc *desc, unsigned int data) | ||
61 | { | ||
62 | unsigned long addr = _INTC_PTR(desc, prio_regs, data)->reg; | ||
63 | |||
64 | ctrl_outw(set_prio_field(desc, ctrl_inw(addr), 0, data), addr); | ||
65 | } | ||
66 | |||
67 | static void enable_prio_16(struct intc_desc *desc, unsigned int data) | ||
68 | { | ||
69 | unsigned long addr = _INTC_PTR(desc, prio_regs, data)->reg; | ||
70 | unsigned int prio = _INTC_VALUE(data); | ||
71 | |||
72 | ctrl_outw(set_prio_field(desc, ctrl_inw(addr), prio, data), addr); | ||
73 | } | ||
74 | |||
75 | static void disable_prio_32(struct intc_desc *desc, unsigned int data) | ||
76 | { | ||
77 | unsigned long addr = _INTC_PTR(desc, prio_regs, data)->reg; | ||
78 | |||
79 | ctrl_outl(set_prio_field(desc, ctrl_inl(addr), 0, data), addr); | ||
80 | } | ||
81 | |||
82 | static void enable_prio_32(struct intc_desc *desc, unsigned int data) | ||
83 | { | ||
84 | unsigned long addr = _INTC_PTR(desc, prio_regs, data)->reg; | ||
85 | unsigned int prio = _INTC_VALUE(data); | ||
86 | |||
87 | ctrl_outl(set_prio_field(desc, ctrl_inl(addr), prio, data), addr); | ||
88 | } | ||
89 | |||
90 | static void disable_mask_8(struct intc_desc *desc, unsigned int data) | ||
91 | { | ||
92 | ctrl_outb(1 << _INTC_BIT(data), | ||
93 | _INTC_PTR(desc, mask_regs, data)->set_reg); | ||
94 | } | ||
95 | |||
96 | static void enable_mask_8(struct intc_desc *desc, unsigned int data) | ||
97 | { | ||
98 | ctrl_outb(1 << _INTC_BIT(data), | ||
99 | _INTC_PTR(desc, mask_regs, data)->clr_reg); | ||
100 | } | ||
101 | |||
102 | static void disable_mask_32(struct intc_desc *desc, unsigned int data) | ||
103 | { | ||
104 | ctrl_outl(1 << _INTC_BIT(data), | ||
105 | _INTC_PTR(desc, mask_regs, data)->set_reg); | ||
106 | } | ||
107 | |||
108 | static void enable_mask_32(struct intc_desc *desc, unsigned int data) | ||
109 | { | ||
110 | ctrl_outl(1 << _INTC_BIT(data), | ||
111 | _INTC_PTR(desc, mask_regs, data)->clr_reg); | ||
112 | } | ||
113 | |||
114 | enum { REG_FN_ERROR=0, | ||
115 | REG_FN_MASK_8, REG_FN_MASK_32, | ||
116 | REG_FN_PRIO_16, REG_FN_PRIO_32 }; | ||
117 | |||
118 | static struct { | ||
119 | void (*enable)(struct intc_desc *, unsigned int); | ||
120 | void (*disable)(struct intc_desc *, unsigned int); | ||
121 | } intc_reg_fns[] = { | ||
122 | [REG_FN_MASK_8] = { enable_mask_8, disable_mask_8 }, | ||
123 | [REG_FN_MASK_32] = { enable_mask_32, disable_mask_32 }, | ||
124 | [REG_FN_PRIO_16] = { enable_prio_16, disable_prio_16 }, | ||
125 | [REG_FN_PRIO_32] = { enable_prio_32, disable_prio_32 }, | ||
126 | }; | ||
127 | |||
128 | static void intc_enable(unsigned int irq) | ||
129 | { | ||
130 | struct intc_desc *desc = get_intc_desc(irq); | ||
131 | unsigned int data = (unsigned int) get_irq_chip_data(irq); | ||
132 | |||
133 | intc_reg_fns[_INTC_FN(data)].enable(desc, data); | ||
134 | } | ||
135 | |||
136 | static void intc_disable(unsigned int irq) | ||
137 | { | ||
138 | struct intc_desc *desc = get_intc_desc(irq); | ||
139 | unsigned int data = (unsigned int) get_irq_chip_data(irq); | ||
140 | |||
141 | intc_reg_fns[_INTC_FN(data)].disable(desc, data); | ||
142 | } | ||
143 | |||
144 | static void set_sense_16(struct intc_desc *desc, unsigned int data) | ||
145 | { | ||
146 | unsigned long addr = _INTC_PTR(desc, sense_regs, data)->reg; | ||
147 | unsigned int width = _INTC_PTR(desc, sense_regs, data)->field_width; | ||
148 | unsigned int bit = _INTC_BIT(data); | ||
149 | unsigned int value = _INTC_VALUE(data); | ||
150 | |||
151 | ctrl_outw(set_field(ctrl_inw(addr), value, width, bit), addr); | ||
152 | } | ||
153 | |||
154 | static void set_sense_32(struct intc_desc *desc, unsigned int data) | ||
155 | { | ||
156 | unsigned long addr = _INTC_PTR(desc, sense_regs, data)->reg; | ||
157 | unsigned int width = _INTC_PTR(desc, sense_regs, data)->field_width; | ||
158 | unsigned int bit = _INTC_BIT(data); | ||
159 | unsigned int value = _INTC_VALUE(data); | ||
160 | |||
161 | ctrl_outl(set_field(ctrl_inl(addr), value, width, bit), addr); | ||
162 | } | ||
163 | |||
164 | #define VALID(x) (x | 0x80) | ||
165 | |||
166 | static unsigned char intc_irq_sense_table[IRQ_TYPE_SENSE_MASK + 1] = { | ||
167 | [IRQ_TYPE_EDGE_FALLING] = VALID(0), | ||
168 | [IRQ_TYPE_EDGE_RISING] = VALID(1), | ||
169 | [IRQ_TYPE_LEVEL_LOW] = VALID(2), | ||
170 | [IRQ_TYPE_LEVEL_HIGH] = VALID(3), | ||
171 | }; | ||
172 | |||
173 | static int intc_set_sense(unsigned int irq, unsigned int type) | ||
174 | { | ||
175 | struct intc_desc *desc = get_intc_desc(irq); | ||
176 | unsigned char value = intc_irq_sense_table[type & IRQ_TYPE_SENSE_MASK]; | ||
177 | unsigned int i, j, data, bit; | ||
178 | intc_enum enum_id = 0; | ||
179 | |||
180 | for (i = 0; i < desc->nr_vectors; i++) { | ||
181 | struct intc_vect *vect = desc->vectors + i; | ||
182 | |||
183 | if (evt2irq(vect->vect) != irq) | ||
184 | continue; | ||
185 | |||
186 | enum_id = vect->enum_id; | ||
187 | break; | ||
188 | } | ||
189 | |||
190 | if (!enum_id || !value) | ||
191 | return -EINVAL; | ||
192 | |||
193 | value ^= VALID(0); | ||
194 | |||
195 | for (i = 0; i < desc->nr_sense_regs; i++) { | ||
196 | struct intc_sense_reg *sr = desc->sense_regs + i; | ||
197 | |||
198 | for (j = 0; j < ARRAY_SIZE(sr->enum_ids); j++) { | ||
199 | if (sr->enum_ids[j] != enum_id) | ||
200 | continue; | ||
201 | |||
202 | bit = sr->reg_width - ((j + 1) * sr->field_width); | ||
203 | data = _INTC_MK(0, i, bit, value); | ||
204 | |||
205 | switch(sr->reg_width) { | ||
206 | case 16: | ||
207 | set_sense_16(desc, data); | ||
208 | break; | ||
209 | case 32: | ||
210 | set_sense_32(desc, data); | ||
211 | break; | ||
212 | } | ||
213 | |||
214 | return 0; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | return -EINVAL; | ||
219 | } | ||
220 | |||
221 | static unsigned int __init intc_find_mask_handler(unsigned int width) | ||
222 | { | ||
223 | switch (width) { | ||
224 | case 8: | ||
225 | return REG_FN_MASK_8; | ||
226 | case 32: | ||
227 | return REG_FN_MASK_32; | ||
228 | } | ||
229 | |||
230 | BUG(); | ||
231 | return REG_FN_ERROR; | ||
232 | } | ||
233 | |||
234 | static unsigned int __init intc_find_prio_handler(unsigned int width) | ||
235 | { | ||
236 | switch (width) { | ||
237 | case 16: | ||
238 | return REG_FN_PRIO_16; | ||
239 | case 32: | ||
240 | return REG_FN_PRIO_32; | ||
241 | } | ||
242 | |||
243 | BUG(); | ||
244 | return REG_FN_ERROR; | ||
245 | } | ||
246 | |||
247 | static unsigned int __init intc_prio_value(struct intc_desc *desc, | ||
248 | intc_enum enum_id) | ||
249 | { | ||
250 | unsigned int i; | ||
251 | |||
252 | for (i = 0; i < desc->nr_priorities; i++) { | ||
253 | struct intc_prio *p = desc->priorities + i; | ||
254 | |||
255 | if (p->enum_id != enum_id) | ||
256 | continue; | ||
257 | |||
258 | return p->priority; | ||
259 | } | ||
260 | |||
261 | return 1; /* default to the lowest priority if no priority is set */ | ||
262 | } | ||
263 | |||
264 | static unsigned int __init intc_mask_data(struct intc_desc *desc, | ||
265 | intc_enum enum_id) | ||
266 | { | ||
267 | unsigned int i, j, fn; | ||
268 | |||
269 | for (i = 0; i < desc->nr_mask_regs; i++) { | ||
270 | struct intc_mask_reg *mr = desc->mask_regs + i; | ||
271 | |||
272 | for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) { | ||
273 | if (mr->enum_ids[j] != enum_id) | ||
274 | continue; | ||
275 | |||
276 | fn = intc_find_mask_handler(mr->reg_width); | ||
277 | if (fn == REG_FN_ERROR) | ||
278 | return 0; | ||
279 | |||
280 | return _INTC_MK(fn, i, (mr->reg_width - 1) - j, 0); | ||
281 | } | ||
282 | } | ||
283 | |||
284 | return 0; | ||
285 | } | ||
286 | |||
287 | static unsigned int __init intc_prio_data(struct intc_desc *desc, | ||
288 | intc_enum enum_id) | ||
289 | { | ||
290 | unsigned int i, j, fn, bit, prio; | ||
291 | |||
292 | for (i = 0; i < desc->nr_prio_regs; i++) { | ||
293 | struct intc_prio_reg *pr = desc->prio_regs + i; | ||
294 | |||
295 | for (j = 0; j < ARRAY_SIZE(pr->enum_ids); j++) { | ||
296 | if (pr->enum_ids[j] != enum_id) | ||
297 | continue; | ||
298 | |||
299 | fn = intc_find_prio_handler(pr->reg_width); | ||
300 | if (fn == REG_FN_ERROR) | ||
301 | return 0; | ||
302 | |||
303 | prio = intc_prio_value(desc, enum_id); | ||
304 | bit = pr->reg_width - ((j + 1) * pr->field_width); | ||
305 | |||
306 | BUG_ON(bit < 0); | ||
307 | |||
308 | return _INTC_MK(fn, i, bit, prio); | ||
309 | } | ||
310 | } | ||
311 | |||
312 | return 0; | ||
313 | } | ||
314 | |||
315 | static void __init intc_register_irq(struct intc_desc *desc, intc_enum enum_id, | ||
316 | unsigned int irq) | ||
317 | { | ||
318 | unsigned int mask_data = intc_mask_data(desc, enum_id); | ||
319 | unsigned int prio_data = intc_prio_data(desc, enum_id); | ||
320 | unsigned int data = mask_data ? mask_data : prio_data; | ||
321 | |||
322 | BUG_ON(!data); | ||
323 | |||
324 | disable_irq_nosync(irq); | ||
325 | set_irq_chip_and_handler_name(irq, &desc->chip, | ||
326 | handle_level_irq, "level"); | ||
327 | set_irq_chip_data(irq, (void *)data); | ||
328 | |||
329 | /* set priority */ | ||
330 | |||
331 | if (prio_data) | ||
332 | intc_reg_fns[_INTC_FN(prio_data)].enable(desc, prio_data); | ||
333 | |||
334 | /* irq should be disabled by default */ | ||
335 | desc->chip.mask(irq); | ||
336 | } | ||
337 | |||
338 | void __init register_intc_controller(struct intc_desc *desc) | ||
339 | { | ||
340 | unsigned int i; | ||
341 | |||
342 | desc->chip.mask = intc_disable; | ||
343 | desc->chip.unmask = intc_enable; | ||
344 | desc->chip.mask_ack = intc_disable; | ||
345 | desc->chip.set_type = intc_set_sense; | ||
346 | |||
347 | for (i = 0; i < desc->nr_vectors; i++) { | ||
348 | struct intc_vect *vect = desc->vectors + i; | ||
349 | |||
350 | intc_register_irq(desc, vect->enum_id, evt2irq(vect->vect)); | ||
351 | } | ||
352 | } | ||
diff --git a/include/asm-sh/hw_irq.h b/include/asm-sh/hw_irq.h index 4ca3f765bacc..34ff8c7cfb55 100644 --- a/include/asm-sh/hw_irq.h +++ b/include/asm-sh/hw_irq.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef __ASM_SH_HW_IRQ_H | 1 | #ifndef __ASM_SH_HW_IRQ_H |
2 | #define __ASM_SH_HW_IRQ_H | 2 | #define __ASM_SH_HW_IRQ_H |
3 | 3 | ||
4 | #include <linux/init.h> | ||
4 | #include <asm/atomic.h> | 5 | #include <asm/atomic.h> |
5 | 6 | ||
6 | extern atomic_t irq_err_count; | 7 | extern atomic_t irq_err_count; |
@@ -47,4 +48,71 @@ void init_IRQ_ipr(void); | |||
47 | */ | 48 | */ |
48 | void ipr_irq_enable_irlm(void); | 49 | void ipr_irq_enable_irlm(void); |
49 | 50 | ||
51 | typedef unsigned char intc_enum; | ||
52 | |||
53 | struct intc_vect { | ||
54 | intc_enum enum_id; | ||
55 | unsigned short vect; | ||
56 | }; | ||
57 | |||
58 | #define INTC_VECT(enum_id, vect) { enum_id, vect } | ||
59 | |||
60 | struct intc_prio { | ||
61 | intc_enum enum_id; | ||
62 | unsigned char priority; | ||
63 | }; | ||
64 | |||
65 | #define INTC_PRIO(enum_id, prio) { enum_id, prio } | ||
66 | |||
67 | struct intc_group { | ||
68 | intc_enum enum_id; | ||
69 | intc_enum *enum_ids; | ||
70 | }; | ||
71 | |||
72 | #define INTC_GROUP(enum_id, ids...) { enum_id, (intc_enum []) { ids, 0 } } | ||
73 | |||
74 | struct intc_mask_reg { | ||
75 | unsigned long set_reg, clr_reg, reg_width; | ||
76 | intc_enum enum_ids[32]; | ||
77 | }; | ||
78 | |||
79 | struct intc_prio_reg { | ||
80 | unsigned long reg, reg_width, field_width; | ||
81 | intc_enum enum_ids[16]; | ||
82 | }; | ||
83 | |||
84 | struct intc_sense_reg { | ||
85 | unsigned long reg, reg_width, field_width; | ||
86 | intc_enum enum_ids[16]; | ||
87 | }; | ||
88 | |||
89 | struct intc_desc { | ||
90 | struct intc_vect *vectors; | ||
91 | unsigned int nr_vectors; | ||
92 | struct intc_group *groups; | ||
93 | unsigned int nr_groups; | ||
94 | struct intc_prio *priorities; | ||
95 | unsigned int nr_priorities; | ||
96 | struct intc_mask_reg *mask_regs; | ||
97 | unsigned int nr_mask_regs; | ||
98 | struct intc_prio_reg *prio_regs; | ||
99 | unsigned int nr_prio_regs; | ||
100 | struct intc_sense_reg *sense_regs; | ||
101 | unsigned int nr_sense_regs; | ||
102 | struct irq_chip chip; | ||
103 | }; | ||
104 | |||
105 | #define _INTC_ARRAY(a) a, sizeof(a)/sizeof(*a) | ||
106 | #define DECLARE_INTC_DESC(symbol, chipname, vectors, groups, \ | ||
107 | priorities, mask_regs, prio_regs, sense_regs) \ | ||
108 | static struct intc_desc symbol = { \ | ||
109 | _INTC_ARRAY(vectors), _INTC_ARRAY(groups), \ | ||
110 | _INTC_ARRAY(priorities), \ | ||
111 | _INTC_ARRAY(mask_regs), _INTC_ARRAY(prio_regs), \ | ||
112 | _INTC_ARRAY(sense_regs), \ | ||
113 | .chip.name = chipname, \ | ||
114 | } | ||
115 | |||
116 | void __init register_intc_controller(struct intc_desc *desc); | ||
117 | |||
50 | #endif /* __ASM_SH_HW_IRQ_H */ | 118 | #endif /* __ASM_SH_HW_IRQ_H */ |