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-2006 Yoichi Yuasa <yoichi_yuasa@tripeaks.co.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 <yoichi_yuasa@tripeaks.co.jp>
29 * - Coped with INTASSIGN of NEC VR4133.
31 #include <linux/errno.h>
32 #include <linux/init.h>
33 #include <linux/ioport.h>
34 #include <linux/irq.h>
35 #include <linux/module.h>
36 #include <linux/smp.h>
37 #include <linux/types.h>
41 #include <asm/vr41xx/irq.h>
42 #include <asm/vr41xx/vr41xx.h>
44 static void __iomem *icu1_base;
45 static void __iomem *icu2_base;
47 static unsigned char sysint1_assign[16] = {
48 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
49 static unsigned char sysint2_assign[16] = {
50 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
52 #define ICU1_TYPE1_BASE 0x0b000080UL
53 #define ICU2_TYPE1_BASE 0x0b000200UL
55 #define ICU1_TYPE2_BASE 0x0f000080UL
56 #define ICU2_TYPE2_BASE 0x0f0000a0UL
58 #define ICU1_SIZE 0x20
59 #define ICU2_SIZE 0x1c
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 MMACINTREG 0x12
72 #define MGIUINTLREG 0x14
73 #define MDSIUINTREG 0x16
76 #define INTASSIGN2 0x1c
77 #define INTASSIGN3 0x1e
79 #define SYSINT2REG 0x00
80 #define GIUINTHREG 0x02
81 #define FIRINTREG 0x04
82 #define MSYSINT2REG 0x06
83 #define MGIUINTHREG 0x08
84 #define MFIRINTREG 0x0a
85 #define PCIINTREG 0x0c
86 #define PCIINT0 0x0001
87 #define SCUINTREG 0x0e
88 #define SCUINT0 0x0001
89 #define CSIINTREG 0x10
90 #define MPCIINTREG 0x12
91 #define MSCUINTREG 0x14
92 #define MCSIINTREG 0x16
93 #define BCUINTREG 0x18
94 #define BCUINTR 0x0001
95 #define MBCUINTREG 0x1a
97 #define SYSINT1_IRQ_TO_PIN(x) ((x) - SYSINT1_IRQ_BASE) /* Pin 0-15 */
98 #define SYSINT2_IRQ_TO_PIN(x) ((x) - SYSINT2_IRQ_BASE) /* Pin 0-15 */
100 #define INT_TO_IRQ(x) ((x) + 2) /* Int0-4 -> IRQ2-6 */
102 #define icu1_read(offset) readw(icu1_base + (offset))
103 #define icu1_write(offset, value) writew((value), icu1_base + (offset))
105 #define icu2_read(offset) readw(icu2_base + (offset))
106 #define icu2_write(offset, value) writew((value), icu2_base + (offset))
108 #define INTASSIGN_MAX 4
109 #define INTASSIGN_MASK 0x0007
111 static inline uint16_t icu1_set(uint8_t offset, uint16_t set)
115 data = icu1_read(offset);
117 icu1_write(offset, data);
122 static inline uint16_t icu1_clear(uint8_t offset, uint16_t clear)
126 data = icu1_read(offset);
128 icu1_write(offset, data);
133 static inline uint16_t icu2_set(uint8_t offset, uint16_t set)
137 data = icu2_read(offset);
139 icu2_write(offset, data);
144 static inline uint16_t icu2_clear(uint8_t offset, uint16_t clear)
148 data = icu2_read(offset);
150 icu2_write(offset, data);
155 void vr41xx_enable_piuint(uint16_t mask)
157 struct irq_desc *desc = irq_desc + PIU_IRQ;
160 if (current_cpu_type() == CPU_VR4111 ||
161 current_cpu_type() == CPU_VR4121) {
162 spin_lock_irqsave(&desc->lock, flags);
163 icu1_set(MPIUINTREG, mask);
164 spin_unlock_irqrestore(&desc->lock, flags);
168 EXPORT_SYMBOL(vr41xx_enable_piuint);
170 void vr41xx_disable_piuint(uint16_t mask)
172 struct irq_desc *desc = irq_desc + PIU_IRQ;
175 if (current_cpu_type() == CPU_VR4111 ||
176 current_cpu_type() == CPU_VR4121) {
177 spin_lock_irqsave(&desc->lock, flags);
178 icu1_clear(MPIUINTREG, mask);
179 spin_unlock_irqrestore(&desc->lock, flags);
183 EXPORT_SYMBOL(vr41xx_disable_piuint);
185 void vr41xx_enable_aiuint(uint16_t mask)
187 struct irq_desc *desc = irq_desc + AIU_IRQ;
190 if (current_cpu_type() == CPU_VR4111 ||
191 current_cpu_type() == CPU_VR4121) {
192 spin_lock_irqsave(&desc->lock, flags);
193 icu1_set(MAIUINTREG, mask);
194 spin_unlock_irqrestore(&desc->lock, flags);
198 EXPORT_SYMBOL(vr41xx_enable_aiuint);
200 void vr41xx_disable_aiuint(uint16_t mask)
202 struct irq_desc *desc = irq_desc + AIU_IRQ;
205 if (current_cpu_type() == CPU_VR4111 ||
206 current_cpu_type() == CPU_VR4121) {
207 spin_lock_irqsave(&desc->lock, flags);
208 icu1_clear(MAIUINTREG, mask);
209 spin_unlock_irqrestore(&desc->lock, flags);
213 EXPORT_SYMBOL(vr41xx_disable_aiuint);
215 void vr41xx_enable_kiuint(uint16_t mask)
217 struct irq_desc *desc = irq_desc + KIU_IRQ;
220 if (current_cpu_type() == CPU_VR4111 ||
221 current_cpu_type() == CPU_VR4121) {
222 spin_lock_irqsave(&desc->lock, flags);
223 icu1_set(MKIUINTREG, mask);
224 spin_unlock_irqrestore(&desc->lock, flags);
228 EXPORT_SYMBOL(vr41xx_enable_kiuint);
230 void vr41xx_disable_kiuint(uint16_t mask)
232 struct irq_desc *desc = irq_desc + KIU_IRQ;
235 if (current_cpu_type() == CPU_VR4111 ||
236 current_cpu_type() == CPU_VR4121) {
237 spin_lock_irqsave(&desc->lock, flags);
238 icu1_clear(MKIUINTREG, mask);
239 spin_unlock_irqrestore(&desc->lock, flags);
243 EXPORT_SYMBOL(vr41xx_disable_kiuint);
245 void vr41xx_enable_macint(uint16_t mask)
247 struct irq_desc *desc = irq_desc + ETHERNET_IRQ;
250 spin_lock_irqsave(&desc->lock, flags);
251 icu1_set(MMACINTREG, mask);
252 spin_unlock_irqrestore(&desc->lock, flags);
255 EXPORT_SYMBOL(vr41xx_enable_macint);
257 void vr41xx_disable_macint(uint16_t mask)
259 struct irq_desc *desc = irq_desc + ETHERNET_IRQ;
262 spin_lock_irqsave(&desc->lock, flags);
263 icu1_clear(MMACINTREG, mask);
264 spin_unlock_irqrestore(&desc->lock, flags);
267 EXPORT_SYMBOL(vr41xx_disable_macint);
269 void vr41xx_enable_dsiuint(uint16_t mask)
271 struct irq_desc *desc = irq_desc + DSIU_IRQ;
274 spin_lock_irqsave(&desc->lock, flags);
275 icu1_set(MDSIUINTREG, mask);
276 spin_unlock_irqrestore(&desc->lock, flags);
279 EXPORT_SYMBOL(vr41xx_enable_dsiuint);
281 void vr41xx_disable_dsiuint(uint16_t mask)
283 struct irq_desc *desc = irq_desc + DSIU_IRQ;
286 spin_lock_irqsave(&desc->lock, flags);
287 icu1_clear(MDSIUINTREG, mask);
288 spin_unlock_irqrestore(&desc->lock, flags);
291 EXPORT_SYMBOL(vr41xx_disable_dsiuint);
293 void vr41xx_enable_firint(uint16_t mask)
295 struct irq_desc *desc = irq_desc + FIR_IRQ;
298 spin_lock_irqsave(&desc->lock, flags);
299 icu2_set(MFIRINTREG, mask);
300 spin_unlock_irqrestore(&desc->lock, flags);
303 EXPORT_SYMBOL(vr41xx_enable_firint);
305 void vr41xx_disable_firint(uint16_t mask)
307 struct irq_desc *desc = irq_desc + FIR_IRQ;
310 spin_lock_irqsave(&desc->lock, flags);
311 icu2_clear(MFIRINTREG, mask);
312 spin_unlock_irqrestore(&desc->lock, flags);
315 EXPORT_SYMBOL(vr41xx_disable_firint);
317 void vr41xx_enable_pciint(void)
319 struct irq_desc *desc = irq_desc + PCI_IRQ;
322 if (current_cpu_type() == CPU_VR4122 ||
323 current_cpu_type() == CPU_VR4131 ||
324 current_cpu_type() == CPU_VR4133) {
325 spin_lock_irqsave(&desc->lock, flags);
326 icu2_write(MPCIINTREG, PCIINT0);
327 spin_unlock_irqrestore(&desc->lock, flags);
331 EXPORT_SYMBOL(vr41xx_enable_pciint);
333 void vr41xx_disable_pciint(void)
335 struct irq_desc *desc = irq_desc + PCI_IRQ;
338 if (current_cpu_type() == CPU_VR4122 ||
339 current_cpu_type() == CPU_VR4131 ||
340 current_cpu_type() == CPU_VR4133) {
341 spin_lock_irqsave(&desc->lock, flags);
342 icu2_write(MPCIINTREG, 0);
343 spin_unlock_irqrestore(&desc->lock, flags);
347 EXPORT_SYMBOL(vr41xx_disable_pciint);
349 void vr41xx_enable_scuint(void)
351 struct irq_desc *desc = irq_desc + SCU_IRQ;
354 if (current_cpu_type() == CPU_VR4122 ||
355 current_cpu_type() == CPU_VR4131 ||
356 current_cpu_type() == CPU_VR4133) {
357 spin_lock_irqsave(&desc->lock, flags);
358 icu2_write(MSCUINTREG, SCUINT0);
359 spin_unlock_irqrestore(&desc->lock, flags);
363 EXPORT_SYMBOL(vr41xx_enable_scuint);
365 void vr41xx_disable_scuint(void)
367 struct irq_desc *desc = irq_desc + SCU_IRQ;
370 if (current_cpu_type() == CPU_VR4122 ||
371 current_cpu_type() == CPU_VR4131 ||
372 current_cpu_type() == CPU_VR4133) {
373 spin_lock_irqsave(&desc->lock, flags);
374 icu2_write(MSCUINTREG, 0);
375 spin_unlock_irqrestore(&desc->lock, flags);
379 EXPORT_SYMBOL(vr41xx_disable_scuint);
381 void vr41xx_enable_csiint(uint16_t mask)
383 struct irq_desc *desc = irq_desc + CSI_IRQ;
386 if (current_cpu_type() == CPU_VR4122 ||
387 current_cpu_type() == CPU_VR4131 ||
388 current_cpu_type() == CPU_VR4133) {
389 spin_lock_irqsave(&desc->lock, flags);
390 icu2_set(MCSIINTREG, mask);
391 spin_unlock_irqrestore(&desc->lock, flags);
395 EXPORT_SYMBOL(vr41xx_enable_csiint);
397 void vr41xx_disable_csiint(uint16_t mask)
399 struct irq_desc *desc = irq_desc + CSI_IRQ;
402 if (current_cpu_type() == CPU_VR4122 ||
403 current_cpu_type() == CPU_VR4131 ||
404 current_cpu_type() == CPU_VR4133) {
405 spin_lock_irqsave(&desc->lock, flags);
406 icu2_clear(MCSIINTREG, mask);
407 spin_unlock_irqrestore(&desc->lock, flags);
411 EXPORT_SYMBOL(vr41xx_disable_csiint);
413 void vr41xx_enable_bcuint(void)
415 struct irq_desc *desc = irq_desc + BCU_IRQ;
418 if (current_cpu_type() == CPU_VR4122 ||
419 current_cpu_type() == CPU_VR4131 ||
420 current_cpu_type() == CPU_VR4133) {
421 spin_lock_irqsave(&desc->lock, flags);
422 icu2_write(MBCUINTREG, BCUINTR);
423 spin_unlock_irqrestore(&desc->lock, flags);
427 EXPORT_SYMBOL(vr41xx_enable_bcuint);
429 void vr41xx_disable_bcuint(void)
431 struct irq_desc *desc = irq_desc + BCU_IRQ;
434 if (current_cpu_type() == CPU_VR4122 ||
435 current_cpu_type() == CPU_VR4131 ||
436 current_cpu_type() == CPU_VR4133) {
437 spin_lock_irqsave(&desc->lock, flags);
438 icu2_write(MBCUINTREG, 0);
439 spin_unlock_irqrestore(&desc->lock, flags);
443 EXPORT_SYMBOL(vr41xx_disable_bcuint);
445 static void disable_sysint1_irq(unsigned int irq)
447 icu1_clear(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
450 static void enable_sysint1_irq(unsigned int irq)
452 icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(irq));
455 static struct irq_chip sysint1_irq_type = {
457 .ack = disable_sysint1_irq,
458 .mask = disable_sysint1_irq,
459 .mask_ack = disable_sysint1_irq,
460 .unmask = enable_sysint1_irq,
463 static void disable_sysint2_irq(unsigned int irq)
465 icu2_clear(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
468 static void enable_sysint2_irq(unsigned int irq)
470 icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(irq));
473 static struct irq_chip sysint2_irq_type = {
475 .ack = disable_sysint2_irq,
476 .mask = disable_sysint2_irq,
477 .mask_ack = disable_sysint2_irq,
478 .unmask = enable_sysint2_irq,
481 static inline int set_sysint1_assign(unsigned int irq, unsigned char assign)
483 struct irq_desc *desc = irq_desc + irq;
484 uint16_t intassign0, intassign1;
487 pin = SYSINT1_IRQ_TO_PIN(irq);
489 spin_lock_irq(&desc->lock);
491 intassign0 = icu1_read(INTASSIGN0);
492 intassign1 = icu1_read(INTASSIGN1);
496 intassign0 &= ~INTASSIGN_MASK;
497 intassign0 |= (uint16_t)assign;
500 intassign0 &= ~(INTASSIGN_MASK << 3);
501 intassign0 |= (uint16_t)assign << 3;
504 intassign0 &= ~(INTASSIGN_MASK << 6);
505 intassign0 |= (uint16_t)assign << 6;
508 intassign0 &= ~(INTASSIGN_MASK << 9);
509 intassign0 |= (uint16_t)assign << 9;
512 intassign0 &= ~(INTASSIGN_MASK << 12);
513 intassign0 |= (uint16_t)assign << 12;
516 intassign1 &= ~INTASSIGN_MASK;
517 intassign1 |= (uint16_t)assign;
520 intassign1 &= ~(INTASSIGN_MASK << 6);
521 intassign1 |= (uint16_t)assign << 6;
524 intassign1 &= ~(INTASSIGN_MASK << 9);
525 intassign1 |= (uint16_t)assign << 9;
528 spin_unlock_irq(&desc->lock);
532 sysint1_assign[pin] = assign;
533 icu1_write(INTASSIGN0, intassign0);
534 icu1_write(INTASSIGN1, intassign1);
536 spin_unlock_irq(&desc->lock);
541 static inline int set_sysint2_assign(unsigned int irq, unsigned char assign)
543 struct irq_desc *desc = irq_desc + irq;
544 uint16_t intassign2, intassign3;
547 pin = SYSINT2_IRQ_TO_PIN(irq);
549 spin_lock_irq(&desc->lock);
551 intassign2 = icu1_read(INTASSIGN2);
552 intassign3 = icu1_read(INTASSIGN3);
556 intassign2 &= ~INTASSIGN_MASK;
557 intassign2 |= (uint16_t)assign;
560 intassign2 &= ~(INTASSIGN_MASK << 3);
561 intassign2 |= (uint16_t)assign << 3;
564 intassign2 &= ~(INTASSIGN_MASK << 6);
565 intassign2 |= (uint16_t)assign << 6;
568 intassign2 &= ~(INTASSIGN_MASK << 9);
569 intassign2 |= (uint16_t)assign << 9;
572 intassign2 &= ~(INTASSIGN_MASK << 12);
573 intassign2 |= (uint16_t)assign << 12;
576 intassign3 &= ~INTASSIGN_MASK;
577 intassign3 |= (uint16_t)assign;
580 intassign3 &= ~(INTASSIGN_MASK << 3);
581 intassign3 |= (uint16_t)assign << 3;
584 intassign3 &= ~(INTASSIGN_MASK << 6);
585 intassign3 |= (uint16_t)assign << 6;
588 intassign3 &= ~(INTASSIGN_MASK << 9);
589 intassign3 |= (uint16_t)assign << 9;
592 intassign3 &= ~(INTASSIGN_MASK << 12);
593 intassign3 |= (uint16_t)assign << 12;
596 spin_unlock_irq(&desc->lock);
600 sysint2_assign[pin] = assign;
601 icu1_write(INTASSIGN2, intassign2);
602 icu1_write(INTASSIGN3, intassign3);
604 spin_unlock_irq(&desc->lock);
609 int vr41xx_set_intassign(unsigned int irq, unsigned char intassign)
611 int retval = -EINVAL;
613 if (current_cpu_type() != CPU_VR4133)
616 if (intassign > INTASSIGN_MAX)
619 if (irq >= SYSINT1_IRQ_BASE && irq <= SYSINT1_IRQ_LAST)
620 retval = set_sysint1_assign(irq, intassign);
621 else if (irq >= SYSINT2_IRQ_BASE && irq <= SYSINT2_IRQ_LAST)
622 retval = set_sysint2_assign(irq, intassign);
627 EXPORT_SYMBOL(vr41xx_set_intassign);
629 static int icu_get_irq(unsigned int irq)
631 uint16_t pend1, pend2;
632 uint16_t mask1, mask2;
635 pend1 = icu1_read(SYSINT1REG);
636 mask1 = icu1_read(MSYSINT1REG);
638 pend2 = icu2_read(SYSINT2REG);
639 mask2 = icu2_read(MSYSINT2REG);
645 for (i = 0; i < 16; i++) {
646 if (irq == INT_TO_IRQ(sysint1_assign[i]) && (mask1 & (1 << i)))
647 return SYSINT1_IRQ(i);
652 for (i = 0; i < 16; i++) {
653 if (irq == INT_TO_IRQ(sysint2_assign[i]) && (mask2 & (1 << i)))
654 return SYSINT2_IRQ(i);
658 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
660 atomic_inc(&irq_err_count);
665 static int __init vr41xx_icu_init(void)
667 unsigned long icu1_start, icu2_start;
670 switch (current_cpu_type()) {
673 icu1_start = ICU1_TYPE1_BASE;
674 icu2_start = ICU2_TYPE1_BASE;
679 icu1_start = ICU1_TYPE2_BASE;
680 icu2_start = ICU2_TYPE2_BASE;
683 printk(KERN_ERR "ICU: Unexpected CPU of NEC VR4100 series\n");
687 if (request_mem_region(icu1_start, ICU1_SIZE, "ICU") == NULL)
690 if (request_mem_region(icu2_start, ICU2_SIZE, "ICU") == NULL) {
691 release_mem_region(icu1_start, ICU1_SIZE);
695 icu1_base = ioremap(icu1_start, ICU1_SIZE);
696 if (icu1_base == NULL) {
697 release_mem_region(icu1_start, ICU1_SIZE);
698 release_mem_region(icu2_start, ICU2_SIZE);
702 icu2_base = ioremap(icu2_start, ICU2_SIZE);
703 if (icu2_base == NULL) {
705 release_mem_region(icu1_start, ICU1_SIZE);
706 release_mem_region(icu2_start, ICU2_SIZE);
710 icu1_write(MSYSINT1REG, 0);
711 icu1_write(MGIUINTLREG, 0xffff);
713 icu2_write(MSYSINT2REG, 0);
714 icu2_write(MGIUINTHREG, 0xffff);
716 for (i = SYSINT1_IRQ_BASE; i <= SYSINT1_IRQ_LAST; i++)
717 set_irq_chip_and_handler(i, &sysint1_irq_type,
720 for (i = SYSINT2_IRQ_BASE; i <= SYSINT2_IRQ_LAST; i++)
721 set_irq_chip_and_handler(i, &sysint2_irq_type,
724 cascade_irq(INT0_IRQ, icu_get_irq);
725 cascade_irq(INT1_IRQ, icu_get_irq);
726 cascade_irq(INT2_IRQ, icu_get_irq);
727 cascade_irq(INT3_IRQ, icu_get_irq);
728 cascade_irq(INT4_IRQ, icu_get_irq);
733 core_initcall(vr41xx_icu_init);