2 * icu.c, Interrupt Control Unit routines for the NEC VR4100 series.
4 * Copyright (C) 2001-2002 MontaVista Software Inc.
5 * Author: Yoichi Yuasa <yyuasa@mvista.com or source@mvista.com>
6 * Copyright (C) 2003-2004 Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
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.
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.
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
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.
28 * Yoichi Yuasa <yuasa@hh.iij4u.or.jp>
29 * - Coped with INTASSIGN of NEC VR4133.
31 #include <linux/config.h>
32 #include <linux/errno.h>
33 #include <linux/init.h>
34 #include <linux/interrupt.h>
35 #include <linux/irq.h>
36 #include <linux/module.h>
37 #include <linux/smp.h>
38 #include <linux/types.h>
43 #include <asm/irq_cpu.h>
44 #include <asm/vr41xx/vr41xx.h>
46 extern asmlinkage void vr41xx_handle_interrupt(void);
48 extern void init_vr41xx_giuint_irq(void);
49 extern void giuint_irq_dispatch(struct pt_regs *regs);
51 static uint32_t icu1_base;
52 static uint32_t icu2_base;
54 static unsigned char sysint1_assign[16] = {
55 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
56 static unsigned char sysint2_assign[16] = {
57 2, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
59 #define SYSINT1REG_TYPE1 KSEG1ADDR(0x0b000080)
60 #define SYSINT2REG_TYPE1 KSEG1ADDR(0x0b000200)
62 #define SYSINT1REG_TYPE2 KSEG1ADDR(0x0f000080)
63 #define SYSINT2REG_TYPE2 KSEG1ADDR(0x0f0000a0)
65 #define SYSINT1REG 0x00
66 #define PIUINTREG 0x02
67 #define INTASSIGN0 0x04
68 #define INTASSIGN1 0x06
69 #define GIUINTLREG 0x08
70 #define DSIUINTREG 0x0a
71 #define MSYSINT1REG 0x0c
72 #define MPIUINTREG 0x0e
73 #define MAIUINTREG 0x10
74 #define MKIUINTREG 0x12
75 #define MGIUINTLREG 0x14
76 #define MDSIUINTREG 0x16
79 #define INTASSIGN2 0x1c
80 #define INTASSIGN3 0x1e
82 #define SYSINT2REG 0x00
83 #define GIUINTHREG 0x02
84 #define FIRINTREG 0x04
85 #define MSYSINT2REG 0x06
86 #define MGIUINTHREG 0x08
87 #define MFIRINTREG 0x0a
88 #define PCIINTREG 0x0c
89 #define PCIINT0 0x0001
90 #define SCUINTREG 0x0e
91 #define SCUINT0 0x0001
92 #define CSIINTREG 0x10
93 #define MPCIINTREG 0x12
94 #define MSCUINTREG 0x14
95 #define MCSIINTREG 0x16
96 #define BCUINTREG 0x18
97 #define BCUINTR 0x0001
98 #define MBCUINTREG 0x1a
100 #define SYSINT1_IRQ_TO_PIN(x) ((x) - SYSINT1_IRQ_BASE) /* Pin 0-15 */
101 #define SYSINT2_IRQ_TO_PIN(x) ((x) - SYSINT2_IRQ_BASE) /* Pin 0-15 */
103 #define read_icu1(offset) readw(icu1_base + (offset))
104 #define write_icu1(val, offset) writew((val), icu1_base + (offset))
106 #define read_icu2(offset) readw(icu2_base + (offset))
107 #define write_icu2(val, offset) writew((val), icu2_base + (offset))
109 #define INTASSIGN_MAX 4
110 #define INTASSIGN_MASK 0x0007
112 static inline uint16_t set_icu1(uint8_t offset, uint16_t set)
116 res = read_icu1(offset);
118 write_icu1(res, offset);
123 static inline uint16_t clear_icu1(uint8_t offset, uint16_t clear)
127 res = read_icu1(offset);
129 write_icu1(res, offset);
134 static inline uint16_t set_icu2(uint8_t offset, uint16_t set)
138 res = read_icu2(offset);
140 write_icu2(res, offset);
145 static inline uint16_t clear_icu2(uint8_t offset, uint16_t clear)
149 res = read_icu2(offset);
151 write_icu2(res, offset);
156 /*=======================================================================*/
158 void vr41xx_enable_piuint(uint16_t mask)
160 irq_desc_t *desc = irq_desc + PIU_IRQ;
164 spin_lock_irqsave(&desc->lock, flags);
165 val = read_icu1(MPIUINTREG);
167 write_icu1(val, MPIUINTREG);
168 spin_unlock_irqrestore(&desc->lock, flags);
171 void vr41xx_disable_piuint(uint16_t mask)
173 irq_desc_t *desc = irq_desc + PIU_IRQ;
177 spin_lock_irqsave(&desc->lock, flags);
178 val = read_icu1(MPIUINTREG);
180 write_icu1(val, MPIUINTREG);
181 spin_unlock_irqrestore(&desc->lock, flags);
184 void vr41xx_enable_aiuint(uint16_t mask)
186 irq_desc_t *desc = irq_desc + AIU_IRQ;
190 spin_lock_irqsave(&desc->lock, flags);
191 val = read_icu1(MAIUINTREG);
193 write_icu1(val, MAIUINTREG);
194 spin_unlock_irqrestore(&desc->lock, flags);
197 void vr41xx_disable_aiuint(uint16_t mask)
199 irq_desc_t *desc = irq_desc + AIU_IRQ;
203 spin_lock_irqsave(&desc->lock, flags);
204 val = read_icu1(MAIUINTREG);
206 write_icu1(val, MAIUINTREG);
207 spin_unlock_irqrestore(&desc->lock, flags);
210 void vr41xx_enable_kiuint(uint16_t mask)
212 irq_desc_t *desc = irq_desc + KIU_IRQ;
216 spin_lock_irqsave(&desc->lock, flags);
217 val = read_icu1(MKIUINTREG);
219 write_icu1(val, MKIUINTREG);
220 spin_unlock_irqrestore(&desc->lock, flags);
223 void vr41xx_disable_kiuint(uint16_t mask)
225 irq_desc_t *desc = irq_desc + KIU_IRQ;
229 spin_lock_irqsave(&desc->lock, flags);
230 val = read_icu1(MKIUINTREG);
232 write_icu1(val, MKIUINTREG);
233 spin_unlock_irqrestore(&desc->lock, flags);
236 void vr41xx_enable_dsiuint(uint16_t mask)
238 irq_desc_t *desc = irq_desc + DSIU_IRQ;
242 spin_lock_irqsave(&desc->lock, flags);
243 val = read_icu1(MDSIUINTREG);
245 write_icu1(val, MDSIUINTREG);
246 spin_unlock_irqrestore(&desc->lock, flags);
249 void vr41xx_disable_dsiuint(uint16_t mask)
251 irq_desc_t *desc = irq_desc + DSIU_IRQ;
255 spin_lock_irqsave(&desc->lock, flags);
256 val = read_icu1(MDSIUINTREG);
258 write_icu1(val, MDSIUINTREG);
259 spin_unlock_irqrestore(&desc->lock, flags);
262 void vr41xx_enable_firint(uint16_t mask)
264 irq_desc_t *desc = irq_desc + FIR_IRQ;
268 spin_lock_irqsave(&desc->lock, flags);
269 val = read_icu2(MFIRINTREG);
271 write_icu2(val, MFIRINTREG);
272 spin_unlock_irqrestore(&desc->lock, flags);
275 void vr41xx_disable_firint(uint16_t mask)
277 irq_desc_t *desc = irq_desc + FIR_IRQ;
281 spin_lock_irqsave(&desc->lock, flags);
282 val = read_icu2(MFIRINTREG);
284 write_icu2(val, MFIRINTREG);
285 spin_unlock_irqrestore(&desc->lock, flags);
288 void vr41xx_enable_pciint(void)
290 irq_desc_t *desc = irq_desc + PCI_IRQ;
293 spin_lock_irqsave(&desc->lock, flags);
294 write_icu2(PCIINT0, MPCIINTREG);
295 spin_unlock_irqrestore(&desc->lock, flags);
298 void vr41xx_disable_pciint(void)
300 irq_desc_t *desc = irq_desc + PCI_IRQ;
303 spin_lock_irqsave(&desc->lock, flags);
304 write_icu2(0, MPCIINTREG);
305 spin_unlock_irqrestore(&desc->lock, flags);
308 void vr41xx_enable_scuint(void)
310 irq_desc_t *desc = irq_desc + SCU_IRQ;
313 spin_lock_irqsave(&desc->lock, flags);
314 write_icu2(SCUINT0, MSCUINTREG);
315 spin_unlock_irqrestore(&desc->lock, flags);
318 void vr41xx_disable_scuint(void)
320 irq_desc_t *desc = irq_desc + SCU_IRQ;
323 spin_lock_irqsave(&desc->lock, flags);
324 write_icu2(0, MSCUINTREG);
325 spin_unlock_irqrestore(&desc->lock, flags);
328 void vr41xx_enable_csiint(uint16_t mask)
330 irq_desc_t *desc = irq_desc + CSI_IRQ;
334 spin_lock_irqsave(&desc->lock, flags);
335 val = read_icu2(MCSIINTREG);
337 write_icu2(val, MCSIINTREG);
338 spin_unlock_irqrestore(&desc->lock, flags);
341 void vr41xx_disable_csiint(uint16_t mask)
343 irq_desc_t *desc = irq_desc + CSI_IRQ;
347 spin_lock_irqsave(&desc->lock, flags);
348 val = read_icu2(MCSIINTREG);
350 write_icu2(val, MCSIINTREG);
351 spin_unlock_irqrestore(&desc->lock, flags);
354 void vr41xx_enable_bcuint(void)
356 irq_desc_t *desc = irq_desc + BCU_IRQ;
359 spin_lock_irqsave(&desc->lock, flags);
360 write_icu2(BCUINTR, MBCUINTREG);
361 spin_unlock_irqrestore(&desc->lock, flags);
364 void vr41xx_disable_bcuint(void)
366 irq_desc_t *desc = irq_desc + BCU_IRQ;
369 spin_lock_irqsave(&desc->lock, flags);
370 write_icu2(0, MBCUINTREG);
371 spin_unlock_irqrestore(&desc->lock, flags);
374 /*=======================================================================*/
376 static unsigned int startup_sysint1_irq(unsigned int irq)
378 set_icu1(MSYSINT1REG, (uint16_t)1 << SYSINT1_IRQ_TO_PIN(irq));
380 return 0; /* never anything pending */
383 static void shutdown_sysint1_irq(unsigned int irq)
385 clear_icu1(MSYSINT1REG, (uint16_t)1 << SYSINT1_IRQ_TO_PIN(irq));
388 static void enable_sysint1_irq(unsigned int irq)
390 set_icu1(MSYSINT1REG, (uint16_t)1 << SYSINT1_IRQ_TO_PIN(irq));
393 #define disable_sysint1_irq shutdown_sysint1_irq
394 #define ack_sysint1_irq shutdown_sysint1_irq
396 static void end_sysint1_irq(unsigned int irq)
398 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
399 set_icu1(MSYSINT1REG, (uint16_t)1 << SYSINT1_IRQ_TO_PIN(irq));
402 static struct hw_interrupt_type sysint1_irq_type = {
403 .typename = "SYSINT1",
404 .startup = startup_sysint1_irq,
405 .shutdown = shutdown_sysint1_irq,
406 .enable = enable_sysint1_irq,
407 .disable = disable_sysint1_irq,
408 .ack = ack_sysint1_irq,
409 .end = end_sysint1_irq,
412 /*=======================================================================*/
414 static unsigned int startup_sysint2_irq(unsigned int irq)
416 set_icu2(MSYSINT2REG, (uint16_t)1 << SYSINT2_IRQ_TO_PIN(irq));
418 return 0; /* never anything pending */
421 static void shutdown_sysint2_irq(unsigned int irq)
423 clear_icu2(MSYSINT2REG, (uint16_t)1 << SYSINT2_IRQ_TO_PIN(irq));
426 static void enable_sysint2_irq(unsigned int irq)
428 set_icu2(MSYSINT2REG, (uint16_t)1 << SYSINT2_IRQ_TO_PIN(irq));
431 #define disable_sysint2_irq shutdown_sysint2_irq
432 #define ack_sysint2_irq shutdown_sysint2_irq
434 static void end_sysint2_irq(unsigned int irq)
436 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
437 set_icu2(MSYSINT2REG, (uint16_t)1 << SYSINT2_IRQ_TO_PIN(irq));
440 static struct hw_interrupt_type sysint2_irq_type = {
441 .typename = "SYSINT2",
442 .startup = startup_sysint2_irq,
443 .shutdown = shutdown_sysint2_irq,
444 .enable = enable_sysint2_irq,
445 .disable = disable_sysint2_irq,
446 .ack = ack_sysint2_irq,
447 .end = end_sysint2_irq,
450 /*=======================================================================*/
452 static inline int set_sysint1_assign(unsigned int irq, unsigned char assign)
454 irq_desc_t *desc = irq_desc + irq;
455 uint16_t intassign0, intassign1;
458 pin = SYSINT1_IRQ_TO_PIN(irq);
460 spin_lock_irq(&desc->lock);
462 intassign0 = read_icu1(INTASSIGN0);
463 intassign1 = read_icu1(INTASSIGN1);
467 intassign0 &= ~INTASSIGN_MASK;
468 intassign0 |= (uint16_t)assign;
471 intassign0 &= ~(INTASSIGN_MASK << 3);
472 intassign0 |= (uint16_t)assign << 3;
475 intassign0 &= ~(INTASSIGN_MASK << 6);
476 intassign0 |= (uint16_t)assign << 6;
479 intassign0 &= ~(INTASSIGN_MASK << 9);
480 intassign0 |= (uint16_t)assign << 9;
483 intassign0 &= ~(INTASSIGN_MASK << 12);
484 intassign0 |= (uint16_t)assign << 12;
487 intassign1 &= ~INTASSIGN_MASK;
488 intassign1 |= (uint16_t)assign;
491 intassign1 &= ~(INTASSIGN_MASK << 6);
492 intassign1 |= (uint16_t)assign << 6;
495 intassign1 &= ~(INTASSIGN_MASK << 9);
496 intassign1 |= (uint16_t)assign << 9;
502 sysint1_assign[pin] = assign;
503 write_icu1(intassign0, INTASSIGN0);
504 write_icu1(intassign1, INTASSIGN1);
506 spin_unlock_irq(&desc->lock);
511 static inline int set_sysint2_assign(unsigned int irq, unsigned char assign)
513 irq_desc_t *desc = irq_desc + irq;
514 uint16_t intassign2, intassign3;
517 pin = SYSINT2_IRQ_TO_PIN(irq);
519 spin_lock_irq(&desc->lock);
521 intassign2 = read_icu1(INTASSIGN2);
522 intassign3 = read_icu1(INTASSIGN3);
526 intassign2 &= ~INTASSIGN_MASK;
527 intassign2 |= (uint16_t)assign;
530 intassign2 &= ~(INTASSIGN_MASK << 3);
531 intassign2 |= (uint16_t)assign << 3;
534 intassign2 &= ~(INTASSIGN_MASK << 6);
535 intassign2 |= (uint16_t)assign << 6;
538 intassign2 &= ~(INTASSIGN_MASK << 9);
539 intassign2 |= (uint16_t)assign << 9;
542 intassign2 &= ~(INTASSIGN_MASK << 12);
543 intassign2 |= (uint16_t)assign << 12;
546 intassign3 &= ~INTASSIGN_MASK;
547 intassign3 |= (uint16_t)assign;
550 intassign3 &= ~(INTASSIGN_MASK << 3);
551 intassign3 |= (uint16_t)assign << 3;
554 intassign3 &= ~(INTASSIGN_MASK << 6);
555 intassign3 |= (uint16_t)assign << 6;
558 intassign3 &= ~(INTASSIGN_MASK << 9);
559 intassign3 |= (uint16_t)assign << 9;
562 intassign3 &= ~(INTASSIGN_MASK << 12);
563 intassign3 |= (uint16_t)assign << 12;
569 sysint2_assign[pin] = assign;
570 write_icu1(intassign2, INTASSIGN2);
571 write_icu1(intassign3, INTASSIGN3);
573 spin_unlock_irq(&desc->lock);
578 int vr41xx_set_intassign(unsigned int irq, unsigned char intassign)
580 int retval = -EINVAL;
582 if (current_cpu_data.cputype != CPU_VR4133)
585 if (intassign > INTASSIGN_MAX)
588 if (irq >= SYSINT1_IRQ_BASE && irq <= SYSINT1_IRQ_LAST)
589 retval = set_sysint1_assign(irq, intassign);
590 else if (irq >= SYSINT2_IRQ_BASE && irq <= SYSINT2_IRQ_LAST)
591 retval = set_sysint2_assign(irq, intassign);
596 EXPORT_SYMBOL(vr41xx_set_intassign);
598 /*=======================================================================*/
600 asmlinkage void irq_dispatch(unsigned char intnum, struct pt_regs *regs)
602 uint16_t pend1, pend2;
603 uint16_t mask1, mask2;
606 pend1 = read_icu1(SYSINT1REG);
607 mask1 = read_icu1(MSYSINT1REG);
609 pend2 = read_icu2(SYSINT2REG);
610 mask2 = read_icu2(MSYSINT2REG);
616 for (i = 0; i < 16; i++) {
617 if (intnum == sysint1_assign[i] &&
618 (mask1 & ((uint16_t)1 << i))) {
620 giuint_irq_dispatch(regs);
622 do_IRQ(SYSINT1_IRQ(i), regs);
629 for (i = 0; i < 16; i++) {
630 if (intnum == sysint2_assign[i] &&
631 (mask2 & ((uint16_t)1 << i))) {
632 do_IRQ(SYSINT2_IRQ(i), regs);
638 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
640 atomic_inc(&irq_err_count);
643 /*=======================================================================*/
645 static int __init vr41xx_icu_init(void)
647 switch (current_cpu_data.cputype) {
650 icu1_base = SYSINT1REG_TYPE1;
651 icu2_base = SYSINT2REG_TYPE1;
656 icu1_base = SYSINT1REG_TYPE2;
657 icu2_base = SYSINT2REG_TYPE2;
660 printk(KERN_ERR "ICU: Unexpected CPU of NEC VR4100 series\n");
664 write_icu1(0, MSYSINT1REG);
665 write_icu1(0xffff, MGIUINTLREG);
667 write_icu2(0, MSYSINT2REG);
668 write_icu2(0xffff, MGIUINTHREG);
673 early_initcall(vr41xx_icu_init);
675 /*=======================================================================*/
677 static struct irqaction icu_cascade = {no_action, 0, 0, "cascade", NULL, NULL};
679 static inline void init_vr41xx_icu_irq(void)
683 for (i = SYSINT1_IRQ_BASE; i <= SYSINT1_IRQ_LAST; i++)
684 irq_desc[i].handler = &sysint1_irq_type;
686 for (i = SYSINT2_IRQ_BASE; i <= SYSINT2_IRQ_LAST; i++)
687 irq_desc[i].handler = &sysint2_irq_type;
689 setup_irq(INT0_CASCADE_IRQ, &icu_cascade);
690 setup_irq(INT1_CASCADE_IRQ, &icu_cascade);
691 setup_irq(INT2_CASCADE_IRQ, &icu_cascade);
692 setup_irq(INT3_CASCADE_IRQ, &icu_cascade);
693 setup_irq(INT4_CASCADE_IRQ, &icu_cascade);
696 void __init init_IRQ(void)
698 memset(irq_desc, 0, sizeof(irq_desc));
701 mips_cpu_irq_init(MIPS_CPU_IRQ_BASE);
702 init_vr41xx_icu_irq();
703 init_vr41xx_giuint_irq();
705 set_except_vector(0, vr41xx_handle_interrupt);