18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  icu.c, Interrupt Control Unit routines for the NEC VR4100 series.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2001-2002  MontaVista Software Inc.
68c2ecf20Sopenharmony_ci *    Author: Yoichi Yuasa <source@mvista.com>
78c2ecf20Sopenharmony_ci *  Copyright (C) 2003-2006  Yoichi Yuasa <yuasa@linux-mips.org>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * Changes:
118c2ecf20Sopenharmony_ci *  MontaVista Software Inc. <source@mvista.com>
128c2ecf20Sopenharmony_ci *  - New creation, NEC VR4122 and VR4131 are supported.
138c2ecf20Sopenharmony_ci *  - Added support for NEC VR4111 and VR4121.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci *  Yoichi Yuasa <yuasa@linux-mips.org>
168c2ecf20Sopenharmony_ci *  - Coped with INTASSIGN of NEC VR4133.
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci#include <linux/errno.h>
198c2ecf20Sopenharmony_ci#include <linux/export.h>
208c2ecf20Sopenharmony_ci#include <linux/init.h>
218c2ecf20Sopenharmony_ci#include <linux/ioport.h>
228c2ecf20Sopenharmony_ci#include <linux/irq.h>
238c2ecf20Sopenharmony_ci#include <linux/smp.h>
248c2ecf20Sopenharmony_ci#include <linux/types.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include <asm/cpu.h>
278c2ecf20Sopenharmony_ci#include <asm/io.h>
288c2ecf20Sopenharmony_ci#include <asm/vr41xx/irq.h>
298c2ecf20Sopenharmony_ci#include <asm/vr41xx/vr41xx.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic void __iomem *icu1_base;
328c2ecf20Sopenharmony_cistatic void __iomem *icu2_base;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic unsigned char sysint1_assign[16] = {
358c2ecf20Sopenharmony_ci	0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
368c2ecf20Sopenharmony_cistatic unsigned char sysint2_assign[16] = {
378c2ecf20Sopenharmony_ci	2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define ICU1_TYPE1_BASE 0x0b000080UL
408c2ecf20Sopenharmony_ci#define ICU2_TYPE1_BASE 0x0b000200UL
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define ICU1_TYPE2_BASE 0x0f000080UL
438c2ecf20Sopenharmony_ci#define ICU2_TYPE2_BASE 0x0f0000a0UL
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define ICU1_SIZE	0x20
468c2ecf20Sopenharmony_ci#define ICU2_SIZE	0x1c
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define SYSINT1REG	0x00
498c2ecf20Sopenharmony_ci#define PIUINTREG	0x02
508c2ecf20Sopenharmony_ci#define INTASSIGN0	0x04
518c2ecf20Sopenharmony_ci#define INTASSIGN1	0x06
528c2ecf20Sopenharmony_ci#define GIUINTLREG	0x08
538c2ecf20Sopenharmony_ci#define DSIUINTREG	0x0a
548c2ecf20Sopenharmony_ci#define MSYSINT1REG	0x0c
558c2ecf20Sopenharmony_ci#define MPIUINTREG	0x0e
568c2ecf20Sopenharmony_ci#define MAIUINTREG	0x10
578c2ecf20Sopenharmony_ci#define MKIUINTREG	0x12
588c2ecf20Sopenharmony_ci#define MMACINTREG	0x12
598c2ecf20Sopenharmony_ci#define MGIUINTLREG	0x14
608c2ecf20Sopenharmony_ci#define MDSIUINTREG	0x16
618c2ecf20Sopenharmony_ci#define NMIREG		0x18
628c2ecf20Sopenharmony_ci#define SOFTREG		0x1a
638c2ecf20Sopenharmony_ci#define INTASSIGN2	0x1c
648c2ecf20Sopenharmony_ci#define INTASSIGN3	0x1e
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define SYSINT2REG	0x00
678c2ecf20Sopenharmony_ci#define GIUINTHREG	0x02
688c2ecf20Sopenharmony_ci#define FIRINTREG	0x04
698c2ecf20Sopenharmony_ci#define MSYSINT2REG	0x06
708c2ecf20Sopenharmony_ci#define MGIUINTHREG	0x08
718c2ecf20Sopenharmony_ci#define MFIRINTREG	0x0a
728c2ecf20Sopenharmony_ci#define PCIINTREG	0x0c
738c2ecf20Sopenharmony_ci #define PCIINT0	0x0001
748c2ecf20Sopenharmony_ci#define SCUINTREG	0x0e
758c2ecf20Sopenharmony_ci #define SCUINT0	0x0001
768c2ecf20Sopenharmony_ci#define CSIINTREG	0x10
778c2ecf20Sopenharmony_ci#define MPCIINTREG	0x12
788c2ecf20Sopenharmony_ci#define MSCUINTREG	0x14
798c2ecf20Sopenharmony_ci#define MCSIINTREG	0x16
808c2ecf20Sopenharmony_ci#define BCUINTREG	0x18
818c2ecf20Sopenharmony_ci #define BCUINTR	0x0001
828c2ecf20Sopenharmony_ci#define MBCUINTREG	0x1a
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define SYSINT1_IRQ_TO_PIN(x)	((x) - SYSINT1_IRQ_BASE)	/* Pin 0-15 */
858c2ecf20Sopenharmony_ci#define SYSINT2_IRQ_TO_PIN(x)	((x) - SYSINT2_IRQ_BASE)	/* Pin 0-15 */
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define INT_TO_IRQ(x)		((x) + 2)	/* Int0-4 -> IRQ2-6 */
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define icu1_read(offset)		readw(icu1_base + (offset))
908c2ecf20Sopenharmony_ci#define icu1_write(offset, value)	writew((value), icu1_base + (offset))
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define icu2_read(offset)		readw(icu2_base + (offset))
938c2ecf20Sopenharmony_ci#define icu2_write(offset, value)	writew((value), icu2_base + (offset))
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define INTASSIGN_MAX	4
968c2ecf20Sopenharmony_ci#define INTASSIGN_MASK	0x0007
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic inline uint16_t icu1_set(uint8_t offset, uint16_t set)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	uint16_t data;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	data = icu1_read(offset);
1038c2ecf20Sopenharmony_ci	data |= set;
1048c2ecf20Sopenharmony_ci	icu1_write(offset, data);
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	return data;
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistatic inline uint16_t icu1_clear(uint8_t offset, uint16_t clear)
1108c2ecf20Sopenharmony_ci{
1118c2ecf20Sopenharmony_ci	uint16_t data;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	data = icu1_read(offset);
1148c2ecf20Sopenharmony_ci	data &= ~clear;
1158c2ecf20Sopenharmony_ci	icu1_write(offset, data);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	return data;
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic inline uint16_t icu2_set(uint8_t offset, uint16_t set)
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	uint16_t data;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	data = icu2_read(offset);
1258c2ecf20Sopenharmony_ci	data |= set;
1268c2ecf20Sopenharmony_ci	icu2_write(offset, data);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	return data;
1298c2ecf20Sopenharmony_ci}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistatic inline uint16_t icu2_clear(uint8_t offset, uint16_t clear)
1328c2ecf20Sopenharmony_ci{
1338c2ecf20Sopenharmony_ci	uint16_t data;
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	data = icu2_read(offset);
1368c2ecf20Sopenharmony_ci	data &= ~clear;
1378c2ecf20Sopenharmony_ci	icu2_write(offset, data);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	return data;
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_civoid vr41xx_enable_piuint(uint16_t mask)
1438c2ecf20Sopenharmony_ci{
1448c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(PIU_IRQ);
1458c2ecf20Sopenharmony_ci	unsigned long flags;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4111 ||
1488c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4121) {
1498c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
1508c2ecf20Sopenharmony_ci		icu1_set(MPIUINTREG, mask);
1518c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
1528c2ecf20Sopenharmony_ci	}
1538c2ecf20Sopenharmony_ci}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_piuint);
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_civoid vr41xx_disable_piuint(uint16_t mask)
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(PIU_IRQ);
1608c2ecf20Sopenharmony_ci	unsigned long flags;
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4111 ||
1638c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4121) {
1648c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
1658c2ecf20Sopenharmony_ci		icu1_clear(MPIUINTREG, mask);
1668c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
1678c2ecf20Sopenharmony_ci	}
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_piuint);
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_civoid vr41xx_enable_aiuint(uint16_t mask)
1738c2ecf20Sopenharmony_ci{
1748c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(AIU_IRQ);
1758c2ecf20Sopenharmony_ci	unsigned long flags;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4111 ||
1788c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4121) {
1798c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
1808c2ecf20Sopenharmony_ci		icu1_set(MAIUINTREG, mask);
1818c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
1828c2ecf20Sopenharmony_ci	}
1838c2ecf20Sopenharmony_ci}
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_aiuint);
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_civoid vr41xx_disable_aiuint(uint16_t mask)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(AIU_IRQ);
1908c2ecf20Sopenharmony_ci	unsigned long flags;
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4111 ||
1938c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4121) {
1948c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
1958c2ecf20Sopenharmony_ci		icu1_clear(MAIUINTREG, mask);
1968c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
1978c2ecf20Sopenharmony_ci	}
1988c2ecf20Sopenharmony_ci}
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_aiuint);
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_civoid vr41xx_enable_kiuint(uint16_t mask)
2038c2ecf20Sopenharmony_ci{
2048c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(KIU_IRQ);
2058c2ecf20Sopenharmony_ci	unsigned long flags;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4111 ||
2088c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4121) {
2098c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
2108c2ecf20Sopenharmony_ci		icu1_set(MKIUINTREG, mask);
2118c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
2128c2ecf20Sopenharmony_ci	}
2138c2ecf20Sopenharmony_ci}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_kiuint);
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_civoid vr41xx_disable_kiuint(uint16_t mask)
2188c2ecf20Sopenharmony_ci{
2198c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(KIU_IRQ);
2208c2ecf20Sopenharmony_ci	unsigned long flags;
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4111 ||
2238c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4121) {
2248c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
2258c2ecf20Sopenharmony_ci		icu1_clear(MKIUINTREG, mask);
2268c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
2278c2ecf20Sopenharmony_ci	}
2288c2ecf20Sopenharmony_ci}
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_kiuint);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_civoid vr41xx_enable_macint(uint16_t mask)
2338c2ecf20Sopenharmony_ci{
2348c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(ETHERNET_IRQ);
2358c2ecf20Sopenharmony_ci	unsigned long flags;
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&desc->lock, flags);
2388c2ecf20Sopenharmony_ci	icu1_set(MMACINTREG, mask);
2398c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&desc->lock, flags);
2408c2ecf20Sopenharmony_ci}
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_macint);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_civoid vr41xx_disable_macint(uint16_t mask)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(ETHERNET_IRQ);
2478c2ecf20Sopenharmony_ci	unsigned long flags;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&desc->lock, flags);
2508c2ecf20Sopenharmony_ci	icu1_clear(MMACINTREG, mask);
2518c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&desc->lock, flags);
2528c2ecf20Sopenharmony_ci}
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_macint);
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_civoid vr41xx_enable_dsiuint(uint16_t mask)
2578c2ecf20Sopenharmony_ci{
2588c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(DSIU_IRQ);
2598c2ecf20Sopenharmony_ci	unsigned long flags;
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&desc->lock, flags);
2628c2ecf20Sopenharmony_ci	icu1_set(MDSIUINTREG, mask);
2638c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&desc->lock, flags);
2648c2ecf20Sopenharmony_ci}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_dsiuint);
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_civoid vr41xx_disable_dsiuint(uint16_t mask)
2698c2ecf20Sopenharmony_ci{
2708c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(DSIU_IRQ);
2718c2ecf20Sopenharmony_ci	unsigned long flags;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&desc->lock, flags);
2748c2ecf20Sopenharmony_ci	icu1_clear(MDSIUINTREG, mask);
2758c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&desc->lock, flags);
2768c2ecf20Sopenharmony_ci}
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_dsiuint);
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_civoid vr41xx_enable_firint(uint16_t mask)
2818c2ecf20Sopenharmony_ci{
2828c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(FIR_IRQ);
2838c2ecf20Sopenharmony_ci	unsigned long flags;
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&desc->lock, flags);
2868c2ecf20Sopenharmony_ci	icu2_set(MFIRINTREG, mask);
2878c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&desc->lock, flags);
2888c2ecf20Sopenharmony_ci}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_firint);
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_civoid vr41xx_disable_firint(uint16_t mask)
2938c2ecf20Sopenharmony_ci{
2948c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(FIR_IRQ);
2958c2ecf20Sopenharmony_ci	unsigned long flags;
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&desc->lock, flags);
2988c2ecf20Sopenharmony_ci	icu2_clear(MFIRINTREG, mask);
2998c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&desc->lock, flags);
3008c2ecf20Sopenharmony_ci}
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_firint);
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_civoid vr41xx_enable_pciint(void)
3058c2ecf20Sopenharmony_ci{
3068c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(PCI_IRQ);
3078c2ecf20Sopenharmony_ci	unsigned long flags;
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4122 ||
3108c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4131 ||
3118c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4133) {
3128c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
3138c2ecf20Sopenharmony_ci		icu2_write(MPCIINTREG, PCIINT0);
3148c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
3158c2ecf20Sopenharmony_ci	}
3168c2ecf20Sopenharmony_ci}
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_pciint);
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_civoid vr41xx_disable_pciint(void)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(PCI_IRQ);
3238c2ecf20Sopenharmony_ci	unsigned long flags;
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4122 ||
3268c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4131 ||
3278c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4133) {
3288c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
3298c2ecf20Sopenharmony_ci		icu2_write(MPCIINTREG, 0);
3308c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
3318c2ecf20Sopenharmony_ci	}
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_pciint);
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_civoid vr41xx_enable_scuint(void)
3378c2ecf20Sopenharmony_ci{
3388c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(SCU_IRQ);
3398c2ecf20Sopenharmony_ci	unsigned long flags;
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4122 ||
3428c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4131 ||
3438c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4133) {
3448c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
3458c2ecf20Sopenharmony_ci		icu2_write(MSCUINTREG, SCUINT0);
3468c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
3478c2ecf20Sopenharmony_ci	}
3488c2ecf20Sopenharmony_ci}
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_scuint);
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_civoid vr41xx_disable_scuint(void)
3538c2ecf20Sopenharmony_ci{
3548c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(SCU_IRQ);
3558c2ecf20Sopenharmony_ci	unsigned long flags;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4122 ||
3588c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4131 ||
3598c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4133) {
3608c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
3618c2ecf20Sopenharmony_ci		icu2_write(MSCUINTREG, 0);
3628c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
3638c2ecf20Sopenharmony_ci	}
3648c2ecf20Sopenharmony_ci}
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_scuint);
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_civoid vr41xx_enable_csiint(uint16_t mask)
3698c2ecf20Sopenharmony_ci{
3708c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(CSI_IRQ);
3718c2ecf20Sopenharmony_ci	unsigned long flags;
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4122 ||
3748c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4131 ||
3758c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4133) {
3768c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
3778c2ecf20Sopenharmony_ci		icu2_set(MCSIINTREG, mask);
3788c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
3798c2ecf20Sopenharmony_ci	}
3808c2ecf20Sopenharmony_ci}
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_csiint);
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_civoid vr41xx_disable_csiint(uint16_t mask)
3858c2ecf20Sopenharmony_ci{
3868c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(CSI_IRQ);
3878c2ecf20Sopenharmony_ci	unsigned long flags;
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4122 ||
3908c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4131 ||
3918c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4133) {
3928c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
3938c2ecf20Sopenharmony_ci		icu2_clear(MCSIINTREG, mask);
3948c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
3958c2ecf20Sopenharmony_ci	}
3968c2ecf20Sopenharmony_ci}
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_csiint);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_civoid vr41xx_enable_bcuint(void)
4018c2ecf20Sopenharmony_ci{
4028c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(BCU_IRQ);
4038c2ecf20Sopenharmony_ci	unsigned long flags;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4122 ||
4068c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4131 ||
4078c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4133) {
4088c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
4098c2ecf20Sopenharmony_ci		icu2_write(MBCUINTREG, BCUINTR);
4108c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
4118c2ecf20Sopenharmony_ci	}
4128c2ecf20Sopenharmony_ci}
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_enable_bcuint);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_civoid vr41xx_disable_bcuint(void)
4178c2ecf20Sopenharmony_ci{
4188c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(BCU_IRQ);
4198c2ecf20Sopenharmony_ci	unsigned long flags;
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	if (current_cpu_type() == CPU_VR4122 ||
4228c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4131 ||
4238c2ecf20Sopenharmony_ci	    current_cpu_type() == CPU_VR4133) {
4248c2ecf20Sopenharmony_ci		raw_spin_lock_irqsave(&desc->lock, flags);
4258c2ecf20Sopenharmony_ci		icu2_write(MBCUINTREG, 0);
4268c2ecf20Sopenharmony_ci		raw_spin_unlock_irqrestore(&desc->lock, flags);
4278c2ecf20Sopenharmony_ci	}
4288c2ecf20Sopenharmony_ci}
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_disable_bcuint);
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_cistatic void disable_sysint1_irq(struct irq_data *d)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	icu1_clear(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(d->irq));
4358c2ecf20Sopenharmony_ci}
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_cistatic void enable_sysint1_irq(struct irq_data *d)
4388c2ecf20Sopenharmony_ci{
4398c2ecf20Sopenharmony_ci	icu1_set(MSYSINT1REG, 1 << SYSINT1_IRQ_TO_PIN(d->irq));
4408c2ecf20Sopenharmony_ci}
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_cistatic struct irq_chip sysint1_irq_type = {
4438c2ecf20Sopenharmony_ci	.name		= "SYSINT1",
4448c2ecf20Sopenharmony_ci	.irq_mask	= disable_sysint1_irq,
4458c2ecf20Sopenharmony_ci	.irq_unmask	= enable_sysint1_irq,
4468c2ecf20Sopenharmony_ci};
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_cistatic void disable_sysint2_irq(struct irq_data *d)
4498c2ecf20Sopenharmony_ci{
4508c2ecf20Sopenharmony_ci	icu2_clear(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(d->irq));
4518c2ecf20Sopenharmony_ci}
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_cistatic void enable_sysint2_irq(struct irq_data *d)
4548c2ecf20Sopenharmony_ci{
4558c2ecf20Sopenharmony_ci	icu2_set(MSYSINT2REG, 1 << SYSINT2_IRQ_TO_PIN(d->irq));
4568c2ecf20Sopenharmony_ci}
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_cistatic struct irq_chip sysint2_irq_type = {
4598c2ecf20Sopenharmony_ci	.name		= "SYSINT2",
4608c2ecf20Sopenharmony_ci	.irq_mask	= disable_sysint2_irq,
4618c2ecf20Sopenharmony_ci	.irq_unmask	= enable_sysint2_irq,
4628c2ecf20Sopenharmony_ci};
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_cistatic inline int set_sysint1_assign(unsigned int irq, unsigned char assign)
4658c2ecf20Sopenharmony_ci{
4668c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(irq);
4678c2ecf20Sopenharmony_ci	uint16_t intassign0, intassign1;
4688c2ecf20Sopenharmony_ci	unsigned int pin;
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci	pin = SYSINT1_IRQ_TO_PIN(irq);
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_ci	raw_spin_lock_irq(&desc->lock);
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	intassign0 = icu1_read(INTASSIGN0);
4758c2ecf20Sopenharmony_ci	intassign1 = icu1_read(INTASSIGN1);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	switch (pin) {
4788c2ecf20Sopenharmony_ci	case 0:
4798c2ecf20Sopenharmony_ci		intassign0 &= ~INTASSIGN_MASK;
4808c2ecf20Sopenharmony_ci		intassign0 |= (uint16_t)assign;
4818c2ecf20Sopenharmony_ci		break;
4828c2ecf20Sopenharmony_ci	case 1:
4838c2ecf20Sopenharmony_ci		intassign0 &= ~(INTASSIGN_MASK << 3);
4848c2ecf20Sopenharmony_ci		intassign0 |= (uint16_t)assign << 3;
4858c2ecf20Sopenharmony_ci		break;
4868c2ecf20Sopenharmony_ci	case 2:
4878c2ecf20Sopenharmony_ci		intassign0 &= ~(INTASSIGN_MASK << 6);
4888c2ecf20Sopenharmony_ci		intassign0 |= (uint16_t)assign << 6;
4898c2ecf20Sopenharmony_ci		break;
4908c2ecf20Sopenharmony_ci	case 3:
4918c2ecf20Sopenharmony_ci		intassign0 &= ~(INTASSIGN_MASK << 9);
4928c2ecf20Sopenharmony_ci		intassign0 |= (uint16_t)assign << 9;
4938c2ecf20Sopenharmony_ci		break;
4948c2ecf20Sopenharmony_ci	case 8:
4958c2ecf20Sopenharmony_ci		intassign0 &= ~(INTASSIGN_MASK << 12);
4968c2ecf20Sopenharmony_ci		intassign0 |= (uint16_t)assign << 12;
4978c2ecf20Sopenharmony_ci		break;
4988c2ecf20Sopenharmony_ci	case 9:
4998c2ecf20Sopenharmony_ci		intassign1 &= ~INTASSIGN_MASK;
5008c2ecf20Sopenharmony_ci		intassign1 |= (uint16_t)assign;
5018c2ecf20Sopenharmony_ci		break;
5028c2ecf20Sopenharmony_ci	case 11:
5038c2ecf20Sopenharmony_ci		intassign1 &= ~(INTASSIGN_MASK << 6);
5048c2ecf20Sopenharmony_ci		intassign1 |= (uint16_t)assign << 6;
5058c2ecf20Sopenharmony_ci		break;
5068c2ecf20Sopenharmony_ci	case 12:
5078c2ecf20Sopenharmony_ci		intassign1 &= ~(INTASSIGN_MASK << 9);
5088c2ecf20Sopenharmony_ci		intassign1 |= (uint16_t)assign << 9;
5098c2ecf20Sopenharmony_ci		break;
5108c2ecf20Sopenharmony_ci	default:
5118c2ecf20Sopenharmony_ci		raw_spin_unlock_irq(&desc->lock);
5128c2ecf20Sopenharmony_ci		return -EINVAL;
5138c2ecf20Sopenharmony_ci	}
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	sysint1_assign[pin] = assign;
5168c2ecf20Sopenharmony_ci	icu1_write(INTASSIGN0, intassign0);
5178c2ecf20Sopenharmony_ci	icu1_write(INTASSIGN1, intassign1);
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	raw_spin_unlock_irq(&desc->lock);
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_ci	return 0;
5228c2ecf20Sopenharmony_ci}
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_cistatic inline int set_sysint2_assign(unsigned int irq, unsigned char assign)
5258c2ecf20Sopenharmony_ci{
5268c2ecf20Sopenharmony_ci	struct irq_desc *desc = irq_to_desc(irq);
5278c2ecf20Sopenharmony_ci	uint16_t intassign2, intassign3;
5288c2ecf20Sopenharmony_ci	unsigned int pin;
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci	pin = SYSINT2_IRQ_TO_PIN(irq);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci	raw_spin_lock_irq(&desc->lock);
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci	intassign2 = icu1_read(INTASSIGN2);
5358c2ecf20Sopenharmony_ci	intassign3 = icu1_read(INTASSIGN3);
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	switch (pin) {
5388c2ecf20Sopenharmony_ci	case 0:
5398c2ecf20Sopenharmony_ci		intassign2 &= ~INTASSIGN_MASK;
5408c2ecf20Sopenharmony_ci		intassign2 |= (uint16_t)assign;
5418c2ecf20Sopenharmony_ci		break;
5428c2ecf20Sopenharmony_ci	case 1:
5438c2ecf20Sopenharmony_ci		intassign2 &= ~(INTASSIGN_MASK << 3);
5448c2ecf20Sopenharmony_ci		intassign2 |= (uint16_t)assign << 3;
5458c2ecf20Sopenharmony_ci		break;
5468c2ecf20Sopenharmony_ci	case 3:
5478c2ecf20Sopenharmony_ci		intassign2 &= ~(INTASSIGN_MASK << 6);
5488c2ecf20Sopenharmony_ci		intassign2 |= (uint16_t)assign << 6;
5498c2ecf20Sopenharmony_ci		break;
5508c2ecf20Sopenharmony_ci	case 4:
5518c2ecf20Sopenharmony_ci		intassign2 &= ~(INTASSIGN_MASK << 9);
5528c2ecf20Sopenharmony_ci		intassign2 |= (uint16_t)assign << 9;
5538c2ecf20Sopenharmony_ci		break;
5548c2ecf20Sopenharmony_ci	case 5:
5558c2ecf20Sopenharmony_ci		intassign2 &= ~(INTASSIGN_MASK << 12);
5568c2ecf20Sopenharmony_ci		intassign2 |= (uint16_t)assign << 12;
5578c2ecf20Sopenharmony_ci		break;
5588c2ecf20Sopenharmony_ci	case 6:
5598c2ecf20Sopenharmony_ci		intassign3 &= ~INTASSIGN_MASK;
5608c2ecf20Sopenharmony_ci		intassign3 |= (uint16_t)assign;
5618c2ecf20Sopenharmony_ci		break;
5628c2ecf20Sopenharmony_ci	case 7:
5638c2ecf20Sopenharmony_ci		intassign3 &= ~(INTASSIGN_MASK << 3);
5648c2ecf20Sopenharmony_ci		intassign3 |= (uint16_t)assign << 3;
5658c2ecf20Sopenharmony_ci		break;
5668c2ecf20Sopenharmony_ci	case 8:
5678c2ecf20Sopenharmony_ci		intassign3 &= ~(INTASSIGN_MASK << 6);
5688c2ecf20Sopenharmony_ci		intassign3 |= (uint16_t)assign << 6;
5698c2ecf20Sopenharmony_ci		break;
5708c2ecf20Sopenharmony_ci	case 9:
5718c2ecf20Sopenharmony_ci		intassign3 &= ~(INTASSIGN_MASK << 9);
5728c2ecf20Sopenharmony_ci		intassign3 |= (uint16_t)assign << 9;
5738c2ecf20Sopenharmony_ci		break;
5748c2ecf20Sopenharmony_ci	case 10:
5758c2ecf20Sopenharmony_ci		intassign3 &= ~(INTASSIGN_MASK << 12);
5768c2ecf20Sopenharmony_ci		intassign3 |= (uint16_t)assign << 12;
5778c2ecf20Sopenharmony_ci		break;
5788c2ecf20Sopenharmony_ci	default:
5798c2ecf20Sopenharmony_ci		raw_spin_unlock_irq(&desc->lock);
5808c2ecf20Sopenharmony_ci		return -EINVAL;
5818c2ecf20Sopenharmony_ci	}
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	sysint2_assign[pin] = assign;
5848c2ecf20Sopenharmony_ci	icu1_write(INTASSIGN2, intassign2);
5858c2ecf20Sopenharmony_ci	icu1_write(INTASSIGN3, intassign3);
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci	raw_spin_unlock_irq(&desc->lock);
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	return 0;
5908c2ecf20Sopenharmony_ci}
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ciint vr41xx_set_intassign(unsigned int irq, unsigned char intassign)
5938c2ecf20Sopenharmony_ci{
5948c2ecf20Sopenharmony_ci	int retval = -EINVAL;
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci	if (current_cpu_type() != CPU_VR4133)
5978c2ecf20Sopenharmony_ci		return -EINVAL;
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	if (intassign > INTASSIGN_MAX)
6008c2ecf20Sopenharmony_ci		return -EINVAL;
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci	if (irq >= SYSINT1_IRQ_BASE && irq <= SYSINT1_IRQ_LAST)
6038c2ecf20Sopenharmony_ci		retval = set_sysint1_assign(irq, intassign);
6048c2ecf20Sopenharmony_ci	else if (irq >= SYSINT2_IRQ_BASE && irq <= SYSINT2_IRQ_LAST)
6058c2ecf20Sopenharmony_ci		retval = set_sysint2_assign(irq, intassign);
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_ci	return retval;
6088c2ecf20Sopenharmony_ci}
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ciEXPORT_SYMBOL(vr41xx_set_intassign);
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_cistatic int icu_get_irq(unsigned int irq)
6138c2ecf20Sopenharmony_ci{
6148c2ecf20Sopenharmony_ci	uint16_t pend1, pend2;
6158c2ecf20Sopenharmony_ci	uint16_t mask1, mask2;
6168c2ecf20Sopenharmony_ci	int i;
6178c2ecf20Sopenharmony_ci
6188c2ecf20Sopenharmony_ci	pend1 = icu1_read(SYSINT1REG);
6198c2ecf20Sopenharmony_ci	mask1 = icu1_read(MSYSINT1REG);
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	pend2 = icu2_read(SYSINT2REG);
6228c2ecf20Sopenharmony_ci	mask2 = icu2_read(MSYSINT2REG);
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci	mask1 &= pend1;
6258c2ecf20Sopenharmony_ci	mask2 &= pend2;
6268c2ecf20Sopenharmony_ci
6278c2ecf20Sopenharmony_ci	if (mask1) {
6288c2ecf20Sopenharmony_ci		for (i = 0; i < 16; i++) {
6298c2ecf20Sopenharmony_ci			if (irq == INT_TO_IRQ(sysint1_assign[i]) && (mask1 & (1 << i)))
6308c2ecf20Sopenharmony_ci				return SYSINT1_IRQ(i);
6318c2ecf20Sopenharmony_ci		}
6328c2ecf20Sopenharmony_ci	}
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci	if (mask2) {
6358c2ecf20Sopenharmony_ci		for (i = 0; i < 16; i++) {
6368c2ecf20Sopenharmony_ci			if (irq == INT_TO_IRQ(sysint2_assign[i]) && (mask2 & (1 << i)))
6378c2ecf20Sopenharmony_ci				return SYSINT2_IRQ(i);
6388c2ecf20Sopenharmony_ci		}
6398c2ecf20Sopenharmony_ci	}
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci	printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci	return -1;
6448c2ecf20Sopenharmony_ci}
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_cistatic int __init vr41xx_icu_init(void)
6478c2ecf20Sopenharmony_ci{
6488c2ecf20Sopenharmony_ci	unsigned long icu1_start, icu2_start;
6498c2ecf20Sopenharmony_ci	int i;
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ci	switch (current_cpu_type()) {
6528c2ecf20Sopenharmony_ci	case CPU_VR4111:
6538c2ecf20Sopenharmony_ci	case CPU_VR4121:
6548c2ecf20Sopenharmony_ci		icu1_start = ICU1_TYPE1_BASE;
6558c2ecf20Sopenharmony_ci		icu2_start = ICU2_TYPE1_BASE;
6568c2ecf20Sopenharmony_ci		break;
6578c2ecf20Sopenharmony_ci	case CPU_VR4122:
6588c2ecf20Sopenharmony_ci	case CPU_VR4131:
6598c2ecf20Sopenharmony_ci	case CPU_VR4133:
6608c2ecf20Sopenharmony_ci		icu1_start = ICU1_TYPE2_BASE;
6618c2ecf20Sopenharmony_ci		icu2_start = ICU2_TYPE2_BASE;
6628c2ecf20Sopenharmony_ci		break;
6638c2ecf20Sopenharmony_ci	default:
6648c2ecf20Sopenharmony_ci		printk(KERN_ERR "ICU: Unexpected CPU of NEC VR4100 series\n");
6658c2ecf20Sopenharmony_ci		return -ENODEV;
6668c2ecf20Sopenharmony_ci	}
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ci	if (request_mem_region(icu1_start, ICU1_SIZE, "ICU") == NULL)
6698c2ecf20Sopenharmony_ci		return -EBUSY;
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci	if (request_mem_region(icu2_start, ICU2_SIZE, "ICU") == NULL) {
6728c2ecf20Sopenharmony_ci		release_mem_region(icu1_start, ICU1_SIZE);
6738c2ecf20Sopenharmony_ci		return -EBUSY;
6748c2ecf20Sopenharmony_ci	}
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	icu1_base = ioremap(icu1_start, ICU1_SIZE);
6778c2ecf20Sopenharmony_ci	if (icu1_base == NULL) {
6788c2ecf20Sopenharmony_ci		release_mem_region(icu1_start, ICU1_SIZE);
6798c2ecf20Sopenharmony_ci		release_mem_region(icu2_start, ICU2_SIZE);
6808c2ecf20Sopenharmony_ci		return -ENOMEM;
6818c2ecf20Sopenharmony_ci	}
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_ci	icu2_base = ioremap(icu2_start, ICU2_SIZE);
6848c2ecf20Sopenharmony_ci	if (icu2_base == NULL) {
6858c2ecf20Sopenharmony_ci		iounmap(icu1_base);
6868c2ecf20Sopenharmony_ci		release_mem_region(icu1_start, ICU1_SIZE);
6878c2ecf20Sopenharmony_ci		release_mem_region(icu2_start, ICU2_SIZE);
6888c2ecf20Sopenharmony_ci		return -ENOMEM;
6898c2ecf20Sopenharmony_ci	}
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	icu1_write(MSYSINT1REG, 0);
6928c2ecf20Sopenharmony_ci	icu1_write(MGIUINTLREG, 0xffff);
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	icu2_write(MSYSINT2REG, 0);
6958c2ecf20Sopenharmony_ci	icu2_write(MGIUINTHREG, 0xffff);
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci	for (i = SYSINT1_IRQ_BASE; i <= SYSINT1_IRQ_LAST; i++)
6988c2ecf20Sopenharmony_ci		irq_set_chip_and_handler(i, &sysint1_irq_type,
6998c2ecf20Sopenharmony_ci					 handle_level_irq);
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci	for (i = SYSINT2_IRQ_BASE; i <= SYSINT2_IRQ_LAST; i++)
7028c2ecf20Sopenharmony_ci		irq_set_chip_and_handler(i, &sysint2_irq_type,
7038c2ecf20Sopenharmony_ci					 handle_level_irq);
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_ci	cascade_irq(INT0_IRQ, icu_get_irq);
7068c2ecf20Sopenharmony_ci	cascade_irq(INT1_IRQ, icu_get_irq);
7078c2ecf20Sopenharmony_ci	cascade_irq(INT2_IRQ, icu_get_irq);
7088c2ecf20Sopenharmony_ci	cascade_irq(INT3_IRQ, icu_get_irq);
7098c2ecf20Sopenharmony_ci	cascade_irq(INT4_IRQ, icu_get_irq);
7108c2ecf20Sopenharmony_ci
7118c2ecf20Sopenharmony_ci	return 0;
7128c2ecf20Sopenharmony_ci}
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_cicore_initcall(vr41xx_icu_init);
715