blob: 7a5c31d58378cd0abefa03d215e71de8415bd44a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * icu.c, Interrupt Control Unit routines for the NEC VR4100 series.
3 *
4 * Copyright (C) 2001-2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
Ralf Baechle29ce2c72005-12-12 20:11:50 +00006 * Copyright (C) 2003-2005 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22/*
23 * Changes:
24 * MontaVista Software Inc. <yyuasa@mvista.com> or <source@mvista.com>
25 * - New creation, NEC VR4122 and VR4131 are supported.
26 * - Added support for NEC VR4111 and VR4121.
27 *
Ralf Baechle29ce2c72005-12-12 20:11:50 +000028 * Yoichi Yuasa <yoichi_yuasa@tripeaks.co.jp>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * - Coped with INTASSIGN of NEC VR4133.
30 */
31#include <linux/errno.h>
32#include <linux/init.h>
Yoichi Yuasa979934d2005-09-03 15:56:04 -070033#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/irq.h>
35#include <linux/module.h>
36#include <linux/smp.h>
37#include <linux/types.h>
38
39#include <asm/cpu.h>
40#include <asm/io.h>
Yoichi Yuasa66151bb2006-07-13 17:33:03 +090041#include <asm/vr41xx/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/vr41xx/vr41xx.h>
43
Yoichi Yuasa979934d2005-09-03 15:56:04 -070044static void __iomem *icu1_base;
45static void __iomem *icu2_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47static unsigned char sysint1_assign[16] = {
48 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
49static unsigned char sysint2_assign[16] = {
Yoichi Yuasa979934d2005-09-03 15:56:04 -070050 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Yoichi Yuasa979934d2005-09-03 15:56:04 -070052#define ICU1_TYPE1_BASE 0x0b000080UL
53#define ICU2_TYPE1_BASE 0x0b000200UL
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Yoichi Yuasa979934d2005-09-03 15:56:04 -070055#define ICU1_TYPE2_BASE 0x0f000080UL
56#define ICU2_TYPE2_BASE 0x0f0000a0UL
57
58#define ICU1_SIZE 0x20
59#define ICU2_SIZE 0x1c
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61#define SYSINT1REG 0x00
62#define PIUINTREG 0x02
63#define INTASSIGN0 0x04
64#define INTASSIGN1 0x06
65#define GIUINTLREG 0x08
66#define DSIUINTREG 0x0a
67#define MSYSINT1REG 0x0c
68#define MPIUINTREG 0x0e
69#define MAIUINTREG 0x10
70#define MKIUINTREG 0x12
71#define MGIUINTLREG 0x14
72#define MDSIUINTREG 0x16
73#define NMIREG 0x18
74#define SOFTREG 0x1a
75#define INTASSIGN2 0x1c
76#define INTASSIGN3 0x1e
77
78#define SYSINT2REG 0x00
79#define GIUINTHREG 0x02
80#define FIRINTREG 0x04
81#define MSYSINT2REG 0x06
82#define MGIUINTHREG 0x08
83#define MFIRINTREG 0x0a
84#define PCIINTREG 0x0c
85 #define PCIINT0 0x0001
86#define SCUINTREG 0x0e
87 #define SCUINT0 0x0001
88#define CSIINTREG 0x10
89#define MPCIINTREG 0x12
90#define MSCUINTREG 0x14
91#define MCSIINTREG 0x16
92#define BCUINTREG 0x18
93 #define BCUINTR 0x0001
94#define MBCUINTREG 0x1a
95
96#define SYSINT1_IRQ_TO_PIN(x) ((x) - SYSINT1_IRQ_BASE) /* Pin 0-15 */
97#define SYSINT2_IRQ_TO_PIN(x) ((x) - SYSINT2_IRQ_BASE) /* Pin 0-15 */
98
Yoichi Yuasa979934d2005-09-03 15:56:04 -070099#define INT_TO_IRQ(x) ((x) + 2) /* Int0-4 -> IRQ2-6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700101#define icu1_read(offset) readw(icu1_base + (offset))
102#define icu1_write(offset, value) writew((value), icu1_base + (offset))
103
104#define icu2_read(offset) readw(icu2_base + (offset))
105#define icu2_write(offset, value) writew((value), icu2_base + (offset))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107#define INTASSIGN_MAX 4
108#define INTASSIGN_MASK 0x0007
109
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700110static inline uint16_t icu1_set(uint8_t offset, uint16_t set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700112 uint16_t data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700114 data = icu1_read(offset);
115 data |= set;
116 icu1_write(offset, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700118 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700121static inline uint16_t icu1_clear(uint8_t offset, uint16_t clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700123 uint16_t data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700125 data = icu1_read(offset);
126 data &= ~clear;
127 icu1_write(offset, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700129 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700132static inline uint16_t icu2_set(uint8_t offset, uint16_t set)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700134 uint16_t data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700136 data = icu2_read(offset);
137 data |= set;
138 icu2_write(offset, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700140 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700143static inline uint16_t icu2_clear(uint8_t offset, uint16_t clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700145 uint16_t data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700147 data = icu2_read(offset);
148 data &= ~clear;
149 icu2_write(offset, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700151 return data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154void vr41xx_enable_piuint(uint16_t mask)
155{
Ralf Baechle94dee172006-07-02 14:41:42 +0100156 struct irq_desc *desc = irq_desc + PIU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 unsigned long flags;
158
159 if (current_cpu_data.cputype == CPU_VR4111 ||
160 current_cpu_data.cputype == CPU_VR4121) {
161 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700162 icu1_set(MPIUINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 spin_unlock_irqrestore(&desc->lock, flags);
164 }
165}
166
167EXPORT_SYMBOL(vr41xx_enable_piuint);
168
169void vr41xx_disable_piuint(uint16_t mask)
170{
Ralf Baechle94dee172006-07-02 14:41:42 +0100171 struct irq_desc *desc = irq_desc + PIU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 unsigned long flags;
173
174 if (current_cpu_data.cputype == CPU_VR4111 ||
175 current_cpu_data.cputype == CPU_VR4121) {
176 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700177 icu1_clear(MPIUINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 spin_unlock_irqrestore(&desc->lock, flags);
179 }
180}
181
182EXPORT_SYMBOL(vr41xx_disable_piuint);
183
184void vr41xx_enable_aiuint(uint16_t mask)
185{
Ralf Baechle94dee172006-07-02 14:41:42 +0100186 struct irq_desc *desc = irq_desc + AIU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 unsigned long flags;
188
189 if (current_cpu_data.cputype == CPU_VR4111 ||
190 current_cpu_data.cputype == CPU_VR4121) {
191 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700192 icu1_set(MAIUINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 spin_unlock_irqrestore(&desc->lock, flags);
194 }
195}
196
197EXPORT_SYMBOL(vr41xx_enable_aiuint);
198
199void vr41xx_disable_aiuint(uint16_t mask)
200{
Ralf Baechle94dee172006-07-02 14:41:42 +0100201 struct irq_desc *desc = irq_desc + AIU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 unsigned long flags;
203
204 if (current_cpu_data.cputype == CPU_VR4111 ||
205 current_cpu_data.cputype == CPU_VR4121) {
206 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700207 icu1_clear(MAIUINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 spin_unlock_irqrestore(&desc->lock, flags);
209 }
210}
211
212EXPORT_SYMBOL(vr41xx_disable_aiuint);
213
214void vr41xx_enable_kiuint(uint16_t mask)
215{
Ralf Baechle94dee172006-07-02 14:41:42 +0100216 struct irq_desc *desc = irq_desc + KIU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 unsigned long flags;
218
219 if (current_cpu_data.cputype == CPU_VR4111 ||
220 current_cpu_data.cputype == CPU_VR4121) {
221 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700222 icu1_set(MKIUINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 spin_unlock_irqrestore(&desc->lock, flags);
224 }
225}
226
227EXPORT_SYMBOL(vr41xx_enable_kiuint);
228
229void vr41xx_disable_kiuint(uint16_t mask)
230{
Ralf Baechle94dee172006-07-02 14:41:42 +0100231 struct irq_desc *desc = irq_desc + KIU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 unsigned long flags;
233
234 if (current_cpu_data.cputype == CPU_VR4111 ||
235 current_cpu_data.cputype == CPU_VR4121) {
236 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700237 icu1_clear(MKIUINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 spin_unlock_irqrestore(&desc->lock, flags);
239 }
240}
241
242EXPORT_SYMBOL(vr41xx_disable_kiuint);
243
244void vr41xx_enable_dsiuint(uint16_t mask)
245{
Ralf Baechle94dee172006-07-02 14:41:42 +0100246 struct irq_desc *desc = irq_desc + DSIU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 unsigned long flags;
248
249 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700250 icu1_set(MDSIUINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 spin_unlock_irqrestore(&desc->lock, flags);
252}
253
254EXPORT_SYMBOL(vr41xx_enable_dsiuint);
255
256void vr41xx_disable_dsiuint(uint16_t mask)
257{
Ralf Baechle94dee172006-07-02 14:41:42 +0100258 struct irq_desc *desc = irq_desc + DSIU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 unsigned long flags;
260
261 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700262 icu1_clear(MDSIUINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 spin_unlock_irqrestore(&desc->lock, flags);
264}
265
266EXPORT_SYMBOL(vr41xx_disable_dsiuint);
267
268void vr41xx_enable_firint(uint16_t mask)
269{
Ralf Baechle94dee172006-07-02 14:41:42 +0100270 struct irq_desc *desc = irq_desc + FIR_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 unsigned long flags;
272
273 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700274 icu2_set(MFIRINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 spin_unlock_irqrestore(&desc->lock, flags);
276}
277
278EXPORT_SYMBOL(vr41xx_enable_firint);
279
280void vr41xx_disable_firint(uint16_t mask)
281{
Ralf Baechle94dee172006-07-02 14:41:42 +0100282 struct irq_desc *desc = irq_desc + FIR_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 unsigned long flags;
284
285 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700286 icu2_clear(MFIRINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 spin_unlock_irqrestore(&desc->lock, flags);
288}
289
290EXPORT_SYMBOL(vr41xx_disable_firint);
291
292void vr41xx_enable_pciint(void)
293{
Ralf Baechle94dee172006-07-02 14:41:42 +0100294 struct irq_desc *desc = irq_desc + PCI_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 unsigned long flags;
296
297 if (current_cpu_data.cputype == CPU_VR4122 ||
298 current_cpu_data.cputype == CPU_VR4131 ||
299 current_cpu_data.cputype == CPU_VR4133) {
300 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700301 icu2_write(MPCIINTREG, PCIINT0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 spin_unlock_irqrestore(&desc->lock, flags);
303 }
304}
305
306EXPORT_SYMBOL(vr41xx_enable_pciint);
307
308void vr41xx_disable_pciint(void)
309{
Ralf Baechle94dee172006-07-02 14:41:42 +0100310 struct irq_desc *desc = irq_desc + PCI_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 unsigned long flags;
312
313 if (current_cpu_data.cputype == CPU_VR4122 ||
314 current_cpu_data.cputype == CPU_VR4131 ||
315 current_cpu_data.cputype == CPU_VR4133) {
316 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700317 icu2_write(MPCIINTREG, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 spin_unlock_irqrestore(&desc->lock, flags);
319 }
320}
321
322EXPORT_SYMBOL(vr41xx_disable_pciint);
323
324void vr41xx_enable_scuint(void)
325{
Ralf Baechle94dee172006-07-02 14:41:42 +0100326 struct irq_desc *desc = irq_desc + SCU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 unsigned long flags;
328
329 if (current_cpu_data.cputype == CPU_VR4122 ||
330 current_cpu_data.cputype == CPU_VR4131 ||
331 current_cpu_data.cputype == CPU_VR4133) {
332 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700333 icu2_write(MSCUINTREG, SCUINT0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 spin_unlock_irqrestore(&desc->lock, flags);
335 }
336}
337
338EXPORT_SYMBOL(vr41xx_enable_scuint);
339
340void vr41xx_disable_scuint(void)
341{
Ralf Baechle94dee172006-07-02 14:41:42 +0100342 struct irq_desc *desc = irq_desc + SCU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 unsigned long flags;
344
345 if (current_cpu_data.cputype == CPU_VR4122 ||
346 current_cpu_data.cputype == CPU_VR4131 ||
347 current_cpu_data.cputype == CPU_VR4133) {
348 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700349 icu2_write(MSCUINTREG, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 spin_unlock_irqrestore(&desc->lock, flags);
351 }
352}
353
354EXPORT_SYMBOL(vr41xx_disable_scuint);
355
356void vr41xx_enable_csiint(uint16_t mask)
357{
Ralf Baechle94dee172006-07-02 14:41:42 +0100358 struct irq_desc *desc = irq_desc + CSI_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 unsigned long flags;
360
361 if (current_cpu_data.cputype == CPU_VR4122 ||
362 current_cpu_data.cputype == CPU_VR4131 ||
363 current_cpu_data.cputype == CPU_VR4133) {
364 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700365 icu2_set(MCSIINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 spin_unlock_irqrestore(&desc->lock, flags);
367 }
368}
369
370EXPORT_SYMBOL(vr41xx_enable_csiint);
371
372void vr41xx_disable_csiint(uint16_t mask)
373{
Ralf Baechle94dee172006-07-02 14:41:42 +0100374 struct irq_desc *desc = irq_desc + CSI_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 unsigned long flags;
376
377 if (current_cpu_data.cputype == CPU_VR4122 ||
378 current_cpu_data.cputype == CPU_VR4131 ||
379 current_cpu_data.cputype == CPU_VR4133) {
380 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700381 icu2_clear(MCSIINTREG, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 spin_unlock_irqrestore(&desc->lock, flags);
383 }
384}
385
386EXPORT_SYMBOL(vr41xx_disable_csiint);
387
388void vr41xx_enable_bcuint(void)
389{
Ralf Baechle94dee172006-07-02 14:41:42 +0100390 struct irq_desc *desc = irq_desc + BCU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 unsigned long flags;
392
393 if (current_cpu_data.cputype == CPU_VR4122 ||
394 current_cpu_data.cputype == CPU_VR4131 ||
395 current_cpu_data.cputype == CPU_VR4133) {
396 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700397 icu2_write(MBCUINTREG, BCUINTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 spin_unlock_irqrestore(&desc->lock, flags);
399 }
400}
401
402EXPORT_SYMBOL(vr41xx_enable_bcuint);
403
404void vr41xx_disable_bcuint(void)
405{
Ralf Baechle94dee172006-07-02 14:41:42 +0100406 struct irq_desc *desc = irq_desc + BCU_IRQ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 unsigned long flags;
408
409 if (current_cpu_data.cputype == CPU_VR4122 ||
410 current_cpu_data.cputype == CPU_VR4131 ||
411 current_cpu_data.cputype == CPU_VR4133) {
412 spin_lock_irqsave(&desc->lock, flags);
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700413 icu2_write(MBCUINTREG, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 spin_unlock_irqrestore(&desc->lock, flags);
415 }
416}
417
418EXPORT_SYMBOL(vr41xx_disable_bcuint);
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420static unsigned int startup_sysint1_irq(unsigned int irq)
421{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700422 icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424 return 0; /* never anything pending */
425}
426
427static void shutdown_sysint1_irq(unsigned int irq)
428{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700429 icu1_clear(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
432static void enable_sysint1_irq(unsigned int irq)
433{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700434 icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
437#define disable_sysint1_irq shutdown_sysint1_irq
438#define ack_sysint1_irq shutdown_sysint1_irq
439
440static void end_sysint1_irq(unsigned int irq)
441{
442 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700443 icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
Ralf Baechle94dee172006-07-02 14:41:42 +0100446static struct irq_chip sysint1_irq_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 .typename = "SYSINT1",
448 .startup = startup_sysint1_irq,
449 .shutdown = shutdown_sysint1_irq,
450 .enable = enable_sysint1_irq,
451 .disable = disable_sysint1_irq,
452 .ack = ack_sysint1_irq,
453 .end = end_sysint1_irq,
454};
455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456static unsigned int startup_sysint2_irq(unsigned int irq)
457{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700458 icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 return 0; /* never anything pending */
461}
462
463static void shutdown_sysint2_irq(unsigned int irq)
464{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700465 icu2_clear(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
467
468static void enable_sysint2_irq(unsigned int irq)
469{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700470 icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
472
473#define disable_sysint2_irq shutdown_sysint2_irq
474#define ack_sysint2_irq shutdown_sysint2_irq
475
476static void end_sysint2_irq(unsigned int irq)
477{
478 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700479 icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
Ralf Baechle94dee172006-07-02 14:41:42 +0100482static struct irq_chip sysint2_irq_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .typename = "SYSINT2",
484 .startup = startup_sysint2_irq,
485 .shutdown = shutdown_sysint2_irq,
486 .enable = enable_sysint2_irq,
487 .disable = disable_sysint2_irq,
488 .ack = ack_sysint2_irq,
489 .end = end_sysint2_irq,
490};
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492static inline int set_sysint1_assign(unsigned int irq, unsigned char assign)
493{
Ralf Baechle94dee172006-07-02 14:41:42 +0100494 struct irq_desc *desc = irq_desc + irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 uint16_t intassign0, intassign1;
496 unsigned int pin;
497
498 pin = SYSINT1_IRQ_TO_PIN(irq);
499
500 spin_lock_irq(&desc->lock);
501
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700502 intassign0 = icu1_read(INTASSIGN0);
503 intassign1 = icu1_read(INTASSIGN1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 switch (pin) {
506 case 0:
507 intassign0 &= ~INTASSIGN_MASK;
508 intassign0 |= (uint16_t)assign;
509 break;
510 case 1:
511 intassign0 &= ~(INTASSIGN_MASK << 3);
512 intassign0 |= (uint16_t)assign << 3;
513 break;
514 case 2:
515 intassign0 &= ~(INTASSIGN_MASK << 6);
516 intassign0 |= (uint16_t)assign << 6;
517 break;
518 case 3:
519 intassign0 &= ~(INTASSIGN_MASK << 9);
520 intassign0 |= (uint16_t)assign << 9;
521 break;
522 case 8:
523 intassign0 &= ~(INTASSIGN_MASK << 12);
524 intassign0 |= (uint16_t)assign << 12;
525 break;
526 case 9:
527 intassign1 &= ~INTASSIGN_MASK;
528 intassign1 |= (uint16_t)assign;
529 break;
530 case 11:
531 intassign1 &= ~(INTASSIGN_MASK << 6);
532 intassign1 |= (uint16_t)assign << 6;
533 break;
534 case 12:
535 intassign1 &= ~(INTASSIGN_MASK << 9);
536 intassign1 |= (uint16_t)assign << 9;
537 break;
538 default:
539 return -EINVAL;
540 }
541
542 sysint1_assign[pin] = assign;
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700543 icu1_write(INTASSIGN0, intassign0);
544 icu1_write(INTASSIGN1, intassign1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 spin_unlock_irq(&desc->lock);
547
548 return 0;
549}
550
551static inline int set_sysint2_assign(unsigned int irq, unsigned char assign)
552{
Ralf Baechle94dee172006-07-02 14:41:42 +0100553 struct irq_desc *desc = irq_desc + irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 uint16_t intassign2, intassign3;
555 unsigned int pin;
556
557 pin = SYSINT2_IRQ_TO_PIN(irq);
558
559 spin_lock_irq(&desc->lock);
560
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700561 intassign2 = icu1_read(INTASSIGN2);
562 intassign3 = icu1_read(INTASSIGN3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 switch (pin) {
565 case 0:
566 intassign2 &= ~INTASSIGN_MASK;
567 intassign2 |= (uint16_t)assign;
568 break;
569 case 1:
570 intassign2 &= ~(INTASSIGN_MASK << 3);
571 intassign2 |= (uint16_t)assign << 3;
572 break;
573 case 3:
574 intassign2 &= ~(INTASSIGN_MASK << 6);
575 intassign2 |= (uint16_t)assign << 6;
576 break;
577 case 4:
578 intassign2 &= ~(INTASSIGN_MASK << 9);
579 intassign2 |= (uint16_t)assign << 9;
580 break;
581 case 5:
582 intassign2 &= ~(INTASSIGN_MASK << 12);
583 intassign2 |= (uint16_t)assign << 12;
584 break;
585 case 6:
586 intassign3 &= ~INTASSIGN_MASK;
587 intassign3 |= (uint16_t)assign;
588 break;
589 case 7:
590 intassign3 &= ~(INTASSIGN_MASK << 3);
591 intassign3 |= (uint16_t)assign << 3;
592 break;
593 case 8:
594 intassign3 &= ~(INTASSIGN_MASK << 6);
595 intassign3 |= (uint16_t)assign << 6;
596 break;
597 case 9:
598 intassign3 &= ~(INTASSIGN_MASK << 9);
599 intassign3 |= (uint16_t)assign << 9;
600 break;
601 case 10:
602 intassign3 &= ~(INTASSIGN_MASK << 12);
603 intassign3 |= (uint16_t)assign << 12;
604 break;
605 default:
606 return -EINVAL;
607 }
608
609 sysint2_assign[pin] = assign;
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700610 icu1_write(INTASSIGN2, intassign2);
611 icu1_write(INTASSIGN3, intassign3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 spin_unlock_irq(&desc->lock);
614
615 return 0;
616}
617
618int vr41xx_set_intassign(unsigned int irq, unsigned char intassign)
619{
620 int retval = -EINVAL;
621
622 if (current_cpu_data.cputype != CPU_VR4133)
623 return -EINVAL;
624
625 if (intassign > INTASSIGN_MAX)
626 return -EINVAL;
627
628 if (irq >= SYSINT1_IRQ_BASE && irq <= SYSINT1_IRQ_LAST)
629 retval = set_sysint1_assign(irq, intassign);
630 else if (irq >= SYSINT2_IRQ_BASE && irq <= SYSINT2_IRQ_LAST)
631 retval = set_sysint2_assign(irq, intassign);
632
633 return retval;
634}
635
636EXPORT_SYMBOL(vr41xx_set_intassign);
637
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700638static int icu_get_irq(unsigned int irq, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
640 uint16_t pend1, pend2;
641 uint16_t mask1, mask2;
642 int i;
643
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700644 pend1 = icu1_read(SYSINT1REG);
645 mask1 = icu1_read(MSYSINT1REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700647 pend2 = icu2_read(SYSINT2REG);
648 mask2 = icu2_read(MSYSINT2REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650 mask1 &= pend1;
651 mask2 &= pend2;
652
653 if (mask1) {
654 for (i = 0; i < 16; i++) {
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700655 if (irq == INT_TO_IRQ(sysint1_assign[i]) && (mask1 & (1 << i)))
656 return SYSINT1_IRQ(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
658 }
659
660 if (mask2) {
661 for (i = 0; i < 16; i++) {
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700662 if (irq == INT_TO_IRQ(sysint2_assign[i]) && (mask2 & (1 << i)))
663 return SYSINT2_IRQ(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 }
665 }
666
667 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
668
669 atomic_inc(&irq_err_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700671 return -1;
672}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674static int __init vr41xx_icu_init(void)
675{
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700676 unsigned long icu1_start, icu2_start;
677 int i;
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 switch (current_cpu_data.cputype) {
680 case CPU_VR4111:
681 case CPU_VR4121:
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700682 icu1_start = ICU1_TYPE1_BASE;
683 icu2_start = ICU2_TYPE1_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 break;
685 case CPU_VR4122:
686 case CPU_VR4131:
687 case CPU_VR4133:
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700688 icu1_start = ICU1_TYPE2_BASE;
689 icu2_start = ICU2_TYPE2_BASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
691 default:
692 printk(KERN_ERR "ICU: Unexpected CPU of NEC VR4100 series\n");
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700693 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
695
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700696 if (request_mem_region(icu1_start, ICU1_SIZE, "ICU") == NULL)
697 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700699 if (request_mem_region(icu2_start, ICU2_SIZE, "ICU") == NULL) {
700 release_mem_region(icu1_start, ICU1_SIZE);
701 return -EBUSY;
702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700704 icu1_base = ioremap(icu1_start, ICU1_SIZE);
705 if (icu1_base == NULL) {
706 release_mem_region(icu1_start, ICU1_SIZE);
707 release_mem_region(icu2_start, ICU2_SIZE);
708 return -ENOMEM;
709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700711 icu2_base = ioremap(icu2_start, ICU2_SIZE);
712 if (icu2_base == NULL) {
713 iounmap(icu1_base);
714 release_mem_region(icu1_start, ICU1_SIZE);
715 release_mem_region(icu2_start, ICU2_SIZE);
716 return -ENOMEM;
717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700719 icu1_write(MSYSINT1REG, 0);
720 icu1_write(MGIUINTLREG, 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700722 icu2_write(MSYSINT2REG, 0);
723 icu2_write(MGIUINTHREG, 0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 for (i = SYSINT1_IRQ_BASE; i <= SYSINT1_IRQ_LAST; i++)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700726 irq_desc[i].chip = &sysint1_irq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
728 for (i = SYSINT2_IRQ_BASE; i <= SYSINT2_IRQ_LAST; i++)
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700729 irq_desc[i].chip = &sysint2_irq_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700731 cascade_irq(INT0_IRQ, icu_get_irq);
732 cascade_irq(INT1_IRQ, icu_get_irq);
733 cascade_irq(INT2_IRQ, icu_get_irq);
734 cascade_irq(INT3_IRQ, icu_get_irq);
735 cascade_irq(INT4_IRQ, icu_get_irq);
736
737 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
Yoichi Yuasa979934d2005-09-03 15:56:04 -0700740core_initcall(vr41xx_icu_init);