18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2001, 2007-2008 MontaVista Software Inc.
38c2ecf20Sopenharmony_ci * Author: MontaVista Software, Inc. <source@mvista.com>
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  This program is free software; you can redistribute	 it and/or modify it
88c2ecf20Sopenharmony_ci *  under  the terms of	 the GNU General  Public License as published by the
98c2ecf20Sopenharmony_ci *  Free Software Foundation;  either version 2 of the	License, or (at your
108c2ecf20Sopenharmony_ci *  option) any later version.
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci *  THIS  SOFTWARE  IS PROVIDED	  ``AS	IS'' AND   ANY	EXPRESS OR IMPLIED
138c2ecf20Sopenharmony_ci *  WARRANTIES,	  INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
148c2ecf20Sopenharmony_ci *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
158c2ecf20Sopenharmony_ci *  NO	EVENT  SHALL   THE AUTHOR  BE	 LIABLE FOR ANY	  DIRECT, INDIRECT,
168c2ecf20Sopenharmony_ci *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
178c2ecf20Sopenharmony_ci *  NOT LIMITED	  TO, PROCUREMENT OF  SUBSTITUTE GOODS	OR SERVICES; LOSS OF
188c2ecf20Sopenharmony_ci *  USE, DATA,	OR PROFITS; OR	BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
198c2ecf20Sopenharmony_ci *  ANY THEORY OF LIABILITY, WHETHER IN	 CONTRACT, STRICT LIABILITY, OR TORT
208c2ecf20Sopenharmony_ci *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
218c2ecf20Sopenharmony_ci *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci *  You should have received a copy of the  GNU General Public License along
248c2ecf20Sopenharmony_ci *  with this program; if not, write  to the Free Software Foundation, Inc.,
258c2ecf20Sopenharmony_ci *  675 Mass Ave, Cambridge, MA 02139, USA.
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#include <linux/export.h>
298c2ecf20Sopenharmony_ci#include <linux/init.h>
308c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
318c2ecf20Sopenharmony_ci#include <linux/slab.h>
328c2ecf20Sopenharmony_ci#include <linux/syscore_ops.h>
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <asm/irq_cpu.h>
358c2ecf20Sopenharmony_ci#include <asm/mach-au1x00/au1000.h>
368c2ecf20Sopenharmony_ci#include <asm/mach-au1x00/gpio-au1300.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* Interrupt Controller register offsets */
398c2ecf20Sopenharmony_ci#define IC_CFG0RD	0x40
408c2ecf20Sopenharmony_ci#define IC_CFG0SET	0x40
418c2ecf20Sopenharmony_ci#define IC_CFG0CLR	0x44
428c2ecf20Sopenharmony_ci#define IC_CFG1RD	0x48
438c2ecf20Sopenharmony_ci#define IC_CFG1SET	0x48
448c2ecf20Sopenharmony_ci#define IC_CFG1CLR	0x4C
458c2ecf20Sopenharmony_ci#define IC_CFG2RD	0x50
468c2ecf20Sopenharmony_ci#define IC_CFG2SET	0x50
478c2ecf20Sopenharmony_ci#define IC_CFG2CLR	0x54
488c2ecf20Sopenharmony_ci#define IC_REQ0INT	0x54
498c2ecf20Sopenharmony_ci#define IC_SRCRD	0x58
508c2ecf20Sopenharmony_ci#define IC_SRCSET	0x58
518c2ecf20Sopenharmony_ci#define IC_SRCCLR	0x5C
528c2ecf20Sopenharmony_ci#define IC_REQ1INT	0x5C
538c2ecf20Sopenharmony_ci#define IC_ASSIGNRD	0x60
548c2ecf20Sopenharmony_ci#define IC_ASSIGNSET	0x60
558c2ecf20Sopenharmony_ci#define IC_ASSIGNCLR	0x64
568c2ecf20Sopenharmony_ci#define IC_WAKERD	0x68
578c2ecf20Sopenharmony_ci#define IC_WAKESET	0x68
588c2ecf20Sopenharmony_ci#define IC_WAKECLR	0x6C
598c2ecf20Sopenharmony_ci#define IC_MASKRD	0x70
608c2ecf20Sopenharmony_ci#define IC_MASKSET	0x70
618c2ecf20Sopenharmony_ci#define IC_MASKCLR	0x74
628c2ecf20Sopenharmony_ci#define IC_RISINGRD	0x78
638c2ecf20Sopenharmony_ci#define IC_RISINGCLR	0x78
648c2ecf20Sopenharmony_ci#define IC_FALLINGRD	0x7C
658c2ecf20Sopenharmony_ci#define IC_FALLINGCLR	0x7C
668c2ecf20Sopenharmony_ci#define IC_TESTBIT	0x80
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci/* per-processor fixed function irqs */
698c2ecf20Sopenharmony_cistruct alchemy_irqmap {
708c2ecf20Sopenharmony_ci	int irq;	/* linux IRQ number */
718c2ecf20Sopenharmony_ci	int type;	/* IRQ_TYPE_ */
728c2ecf20Sopenharmony_ci	int prio;	/* irq priority, 0 highest, 3 lowest */
738c2ecf20Sopenharmony_ci	int internal;	/* GPIC: internal source (no ext. pin)? */
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic int au1x_ic_settype(struct irq_data *d, unsigned int type);
778c2ecf20Sopenharmony_cistatic int au1300_gpic_settype(struct irq_data *d, unsigned int type);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* NOTE on interrupt priorities: The original writers of this code said:
818c2ecf20Sopenharmony_ci *
828c2ecf20Sopenharmony_ci * Because of the tight timing of SETUP token to reply transactions,
838c2ecf20Sopenharmony_ci * the USB devices-side packet complete interrupt (USB_DEV_REQ_INT)
848c2ecf20Sopenharmony_ci * needs the highest priority.
858c2ecf20Sopenharmony_ci */
868c2ecf20Sopenharmony_cistruct alchemy_irqmap au1000_irqmap[] __initdata = {
878c2ecf20Sopenharmony_ci	{ AU1000_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
888c2ecf20Sopenharmony_ci	{ AU1000_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
898c2ecf20Sopenharmony_ci	{ AU1000_UART2_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
908c2ecf20Sopenharmony_ci	{ AU1000_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
918c2ecf20Sopenharmony_ci	{ AU1000_SSI0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
928c2ecf20Sopenharmony_ci	{ AU1000_SSI1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
938c2ecf20Sopenharmony_ci	{ AU1000_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
948c2ecf20Sopenharmony_ci	{ AU1000_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
958c2ecf20Sopenharmony_ci	{ AU1000_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
968c2ecf20Sopenharmony_ci	{ AU1000_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
978c2ecf20Sopenharmony_ci	{ AU1000_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
988c2ecf20Sopenharmony_ci	{ AU1000_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
998c2ecf20Sopenharmony_ci	{ AU1000_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1008c2ecf20Sopenharmony_ci	{ AU1000_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1018c2ecf20Sopenharmony_ci	{ AU1000_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1028c2ecf20Sopenharmony_ci	{ AU1000_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1038c2ecf20Sopenharmony_ci	{ AU1000_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1048c2ecf20Sopenharmony_ci	{ AU1000_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1058c2ecf20Sopenharmony_ci	{ AU1000_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1068c2ecf20Sopenharmony_ci	{ AU1000_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1078c2ecf20Sopenharmony_ci	{ AU1000_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1088c2ecf20Sopenharmony_ci	{ AU1000_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
1098c2ecf20Sopenharmony_ci	{ AU1000_IRDA_TX_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1108c2ecf20Sopenharmony_ci	{ AU1000_IRDA_RX_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1118c2ecf20Sopenharmony_ci	{ AU1000_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,	0, 0 },
1128c2ecf20Sopenharmony_ci	{ AU1000_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
1138c2ecf20Sopenharmony_ci	{ AU1000_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1148c2ecf20Sopenharmony_ci	{ AU1000_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1158c2ecf20Sopenharmony_ci	{ AU1000_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1168c2ecf20Sopenharmony_ci	{ AU1000_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1178c2ecf20Sopenharmony_ci	{ AU1000_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1188c2ecf20Sopenharmony_ci	{ -1, },
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistruct alchemy_irqmap au1500_irqmap[] __initdata = {
1228c2ecf20Sopenharmony_ci	{ AU1500_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1238c2ecf20Sopenharmony_ci	{ AU1500_PCI_INTA,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1248c2ecf20Sopenharmony_ci	{ AU1500_PCI_INTB,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1258c2ecf20Sopenharmony_ci	{ AU1500_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1268c2ecf20Sopenharmony_ci	{ AU1500_PCI_INTC,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1278c2ecf20Sopenharmony_ci	{ AU1500_PCI_INTD,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1288c2ecf20Sopenharmony_ci	{ AU1500_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1298c2ecf20Sopenharmony_ci	{ AU1500_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1308c2ecf20Sopenharmony_ci	{ AU1500_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1318c2ecf20Sopenharmony_ci	{ AU1500_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1328c2ecf20Sopenharmony_ci	{ AU1500_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1338c2ecf20Sopenharmony_ci	{ AU1500_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1348c2ecf20Sopenharmony_ci	{ AU1500_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1358c2ecf20Sopenharmony_ci	{ AU1500_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1368c2ecf20Sopenharmony_ci	{ AU1500_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1378c2ecf20Sopenharmony_ci	{ AU1500_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1388c2ecf20Sopenharmony_ci	{ AU1500_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1398c2ecf20Sopenharmony_ci	{ AU1500_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1408c2ecf20Sopenharmony_ci	{ AU1500_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1418c2ecf20Sopenharmony_ci	{ AU1500_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1428c2ecf20Sopenharmony_ci	{ AU1500_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1438c2ecf20Sopenharmony_ci	{ AU1500_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
1448c2ecf20Sopenharmony_ci	{ AU1500_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,	0, 0 },
1458c2ecf20Sopenharmony_ci	{ AU1500_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
1468c2ecf20Sopenharmony_ci	{ AU1500_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1478c2ecf20Sopenharmony_ci	{ AU1500_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1488c2ecf20Sopenharmony_ci	{ AU1500_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1498c2ecf20Sopenharmony_ci	{ AU1500_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1508c2ecf20Sopenharmony_ci	{ AU1500_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1518c2ecf20Sopenharmony_ci	{ -1, },
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistruct alchemy_irqmap au1100_irqmap[] __initdata = {
1558c2ecf20Sopenharmony_ci	{ AU1100_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1568c2ecf20Sopenharmony_ci	{ AU1100_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1578c2ecf20Sopenharmony_ci	{ AU1100_SD_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1588c2ecf20Sopenharmony_ci	{ AU1100_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1598c2ecf20Sopenharmony_ci	{ AU1100_SSI0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1608c2ecf20Sopenharmony_ci	{ AU1100_SSI1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1618c2ecf20Sopenharmony_ci	{ AU1100_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1628c2ecf20Sopenharmony_ci	{ AU1100_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1638c2ecf20Sopenharmony_ci	{ AU1100_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1648c2ecf20Sopenharmony_ci	{ AU1100_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1658c2ecf20Sopenharmony_ci	{ AU1100_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1668c2ecf20Sopenharmony_ci	{ AU1100_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1678c2ecf20Sopenharmony_ci	{ AU1100_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1688c2ecf20Sopenharmony_ci	{ AU1100_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1698c2ecf20Sopenharmony_ci	{ AU1100_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1708c2ecf20Sopenharmony_ci	{ AU1100_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1718c2ecf20Sopenharmony_ci	{ AU1100_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1728c2ecf20Sopenharmony_ci	{ AU1100_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1738c2ecf20Sopenharmony_ci	{ AU1100_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1748c2ecf20Sopenharmony_ci	{ AU1100_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1758c2ecf20Sopenharmony_ci	{ AU1100_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1768c2ecf20Sopenharmony_ci	{ AU1100_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
1778c2ecf20Sopenharmony_ci	{ AU1100_IRDA_TX_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1788c2ecf20Sopenharmony_ci	{ AU1100_IRDA_RX_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1798c2ecf20Sopenharmony_ci	{ AU1100_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,	0, 0 },
1808c2ecf20Sopenharmony_ci	{ AU1100_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
1818c2ecf20Sopenharmony_ci	{ AU1100_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1828c2ecf20Sopenharmony_ci	{ AU1100_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1838c2ecf20Sopenharmony_ci	{ AU1100_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1848c2ecf20Sopenharmony_ci	{ AU1100_LCD_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1858c2ecf20Sopenharmony_ci	{ AU1100_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1868c2ecf20Sopenharmony_ci	{ -1, },
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistruct alchemy_irqmap au1550_irqmap[] __initdata = {
1908c2ecf20Sopenharmony_ci	{ AU1550_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1918c2ecf20Sopenharmony_ci	{ AU1550_PCI_INTA,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1928c2ecf20Sopenharmony_ci	{ AU1550_PCI_INTB,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1938c2ecf20Sopenharmony_ci	{ AU1550_DDMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1948c2ecf20Sopenharmony_ci	{ AU1550_CRYPTO_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1958c2ecf20Sopenharmony_ci	{ AU1550_PCI_INTC,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1968c2ecf20Sopenharmony_ci	{ AU1550_PCI_INTD,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1978c2ecf20Sopenharmony_ci	{ AU1550_PCI_RST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1988c2ecf20Sopenharmony_ci	{ AU1550_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1998c2ecf20Sopenharmony_ci	{ AU1550_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2008c2ecf20Sopenharmony_ci	{ AU1550_PSC0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2018c2ecf20Sopenharmony_ci	{ AU1550_PSC1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2028c2ecf20Sopenharmony_ci	{ AU1550_PSC2_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2038c2ecf20Sopenharmony_ci	{ AU1550_PSC3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2048c2ecf20Sopenharmony_ci	{ AU1550_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2058c2ecf20Sopenharmony_ci	{ AU1550_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2068c2ecf20Sopenharmony_ci	{ AU1550_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2078c2ecf20Sopenharmony_ci	{ AU1550_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2088c2ecf20Sopenharmony_ci	{ AU1550_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2098c2ecf20Sopenharmony_ci	{ AU1550_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2108c2ecf20Sopenharmony_ci	{ AU1550_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2118c2ecf20Sopenharmony_ci	{ AU1550_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
2128c2ecf20Sopenharmony_ci	{ AU1550_NAND_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2138c2ecf20Sopenharmony_ci	{ AU1550_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,	0, 0 },
2148c2ecf20Sopenharmony_ci	{ AU1550_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
2158c2ecf20Sopenharmony_ci	{ AU1550_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
2168c2ecf20Sopenharmony_ci	{ AU1550_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2178c2ecf20Sopenharmony_ci	{ AU1550_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2188c2ecf20Sopenharmony_ci	{ -1, },
2198c2ecf20Sopenharmony_ci};
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_cistruct alchemy_irqmap au1200_irqmap[] __initdata = {
2228c2ecf20Sopenharmony_ci	{ AU1200_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2238c2ecf20Sopenharmony_ci	{ AU1200_SWT_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2248c2ecf20Sopenharmony_ci	{ AU1200_SD_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2258c2ecf20Sopenharmony_ci	{ AU1200_DDMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2268c2ecf20Sopenharmony_ci	{ AU1200_MAE_BE_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2278c2ecf20Sopenharmony_ci	{ AU1200_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2288c2ecf20Sopenharmony_ci	{ AU1200_MAE_FE_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2298c2ecf20Sopenharmony_ci	{ AU1200_PSC0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2308c2ecf20Sopenharmony_ci	{ AU1200_PSC1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2318c2ecf20Sopenharmony_ci	{ AU1200_AES_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2328c2ecf20Sopenharmony_ci	{ AU1200_CAMERA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2338c2ecf20Sopenharmony_ci	{ AU1200_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2348c2ecf20Sopenharmony_ci	{ AU1200_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2358c2ecf20Sopenharmony_ci	{ AU1200_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2368c2ecf20Sopenharmony_ci	{ AU1200_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2378c2ecf20Sopenharmony_ci	{ AU1200_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2388c2ecf20Sopenharmony_ci	{ AU1200_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2398c2ecf20Sopenharmony_ci	{ AU1200_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2408c2ecf20Sopenharmony_ci	{ AU1200_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
2418c2ecf20Sopenharmony_ci	{ AU1200_NAND_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2428c2ecf20Sopenharmony_ci	{ AU1200_USB_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2438c2ecf20Sopenharmony_ci	{ AU1200_LCD_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2448c2ecf20Sopenharmony_ci	{ AU1200_MAE_BOTH_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2458c2ecf20Sopenharmony_ci	{ -1, },
2468c2ecf20Sopenharmony_ci};
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistatic struct alchemy_irqmap au1300_irqmap[] __initdata = {
2498c2ecf20Sopenharmony_ci	/* multifunction: gpio pin or device */
2508c2ecf20Sopenharmony_ci	{ AU1300_UART1_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2518c2ecf20Sopenharmony_ci	{ AU1300_UART2_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2528c2ecf20Sopenharmony_ci	{ AU1300_UART3_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2538c2ecf20Sopenharmony_ci	{ AU1300_SD1_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2548c2ecf20Sopenharmony_ci	{ AU1300_SD2_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2558c2ecf20Sopenharmony_ci	{ AU1300_PSC0_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2568c2ecf20Sopenharmony_ci	{ AU1300_PSC1_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2578c2ecf20Sopenharmony_ci	{ AU1300_PSC2_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2588c2ecf20Sopenharmony_ci	{ AU1300_PSC3_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2598c2ecf20Sopenharmony_ci	{ AU1300_NAND_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2608c2ecf20Sopenharmony_ci	/* au1300 internal */
2618c2ecf20Sopenharmony_ci	{ AU1300_DDMA_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2628c2ecf20Sopenharmony_ci	{ AU1300_MMU_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2638c2ecf20Sopenharmony_ci	{ AU1300_MPU_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2648c2ecf20Sopenharmony_ci	{ AU1300_GPU_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2658c2ecf20Sopenharmony_ci	{ AU1300_UDMA_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2668c2ecf20Sopenharmony_ci	{ AU1300_TOY_INT,	 IRQ_TYPE_EDGE_RISING,	1, 1, },
2678c2ecf20Sopenharmony_ci	{ AU1300_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2688c2ecf20Sopenharmony_ci	{ AU1300_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2698c2ecf20Sopenharmony_ci	{ AU1300_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2708c2ecf20Sopenharmony_ci	{ AU1300_RTC_INT,	 IRQ_TYPE_EDGE_RISING,	1, 1, },
2718c2ecf20Sopenharmony_ci	{ AU1300_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2728c2ecf20Sopenharmony_ci	{ AU1300_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2738c2ecf20Sopenharmony_ci	{ AU1300_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING,	0, 1, },
2748c2ecf20Sopenharmony_ci	{ AU1300_UART0_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2758c2ecf20Sopenharmony_ci	{ AU1300_SD0_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2768c2ecf20Sopenharmony_ci	{ AU1300_USB_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2778c2ecf20Sopenharmony_ci	{ AU1300_LCD_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2788c2ecf20Sopenharmony_ci	{ AU1300_BSA_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2798c2ecf20Sopenharmony_ci	{ AU1300_MPE_INT,	 IRQ_TYPE_EDGE_RISING,	1, 1, },
2808c2ecf20Sopenharmony_ci	{ AU1300_ITE_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2818c2ecf20Sopenharmony_ci	{ AU1300_AES_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2828c2ecf20Sopenharmony_ci	{ AU1300_CIM_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2838c2ecf20Sopenharmony_ci	{ -1, },	/* terminator */
2848c2ecf20Sopenharmony_ci};
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci/******************************************************************************/
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistatic void au1x_ic0_unmask(struct irq_data *d)
2898c2ecf20Sopenharmony_ci{
2908c2ecf20Sopenharmony_ci	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
2918c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_MASKSET);
2948c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_WAKESET);
2958c2ecf20Sopenharmony_ci	wmb();
2968c2ecf20Sopenharmony_ci}
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_cistatic void au1x_ic1_unmask(struct irq_data *d)
2998c2ecf20Sopenharmony_ci{
3008c2ecf20Sopenharmony_ci	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
3018c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_MASKSET);
3048c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_WAKESET);
3058c2ecf20Sopenharmony_ci	wmb();
3068c2ecf20Sopenharmony_ci}
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistatic void au1x_ic0_mask(struct irq_data *d)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
3118c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_MASKCLR);
3148c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_WAKECLR);
3158c2ecf20Sopenharmony_ci	wmb();
3168c2ecf20Sopenharmony_ci}
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_cistatic void au1x_ic1_mask(struct irq_data *d)
3198c2ecf20Sopenharmony_ci{
3208c2ecf20Sopenharmony_ci	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
3218c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_MASKCLR);
3248c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_WAKECLR);
3258c2ecf20Sopenharmony_ci	wmb();
3268c2ecf20Sopenharmony_ci}
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_cistatic void au1x_ic0_ack(struct irq_data *d)
3298c2ecf20Sopenharmony_ci{
3308c2ecf20Sopenharmony_ci	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
3318c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	/*
3348c2ecf20Sopenharmony_ci	 * This may assume that we don't get interrupts from
3358c2ecf20Sopenharmony_ci	 * both edges at once, or if we do, that we don't care.
3368c2ecf20Sopenharmony_ci	 */
3378c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_FALLINGCLR);
3388c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_RISINGCLR);
3398c2ecf20Sopenharmony_ci	wmb();
3408c2ecf20Sopenharmony_ci}
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_cistatic void au1x_ic1_ack(struct irq_data *d)
3438c2ecf20Sopenharmony_ci{
3448c2ecf20Sopenharmony_ci	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
3458c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	/*
3488c2ecf20Sopenharmony_ci	 * This may assume that we don't get interrupts from
3498c2ecf20Sopenharmony_ci	 * both edges at once, or if we do, that we don't care.
3508c2ecf20Sopenharmony_ci	 */
3518c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_FALLINGCLR);
3528c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_RISINGCLR);
3538c2ecf20Sopenharmony_ci	wmb();
3548c2ecf20Sopenharmony_ci}
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_cistatic void au1x_ic0_maskack(struct irq_data *d)
3578c2ecf20Sopenharmony_ci{
3588c2ecf20Sopenharmony_ci	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
3598c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_WAKECLR);
3628c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_MASKCLR);
3638c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_RISINGCLR);
3648c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_FALLINGCLR);
3658c2ecf20Sopenharmony_ci	wmb();
3668c2ecf20Sopenharmony_ci}
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_cistatic void au1x_ic1_maskack(struct irq_data *d)
3698c2ecf20Sopenharmony_ci{
3708c2ecf20Sopenharmony_ci	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
3718c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_WAKECLR);
3748c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_MASKCLR);
3758c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_RISINGCLR);
3768c2ecf20Sopenharmony_ci	__raw_writel(1 << bit, base + IC_FALLINGCLR);
3778c2ecf20Sopenharmony_ci	wmb();
3788c2ecf20Sopenharmony_ci}
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_cistatic int au1x_ic1_setwake(struct irq_data *d, unsigned int on)
3818c2ecf20Sopenharmony_ci{
3828c2ecf20Sopenharmony_ci	int bit = d->irq - AU1000_INTC1_INT_BASE;
3838c2ecf20Sopenharmony_ci	unsigned long wakemsk, flags;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	/* only GPIO 0-7 can act as wakeup source.  Fortunately these
3868c2ecf20Sopenharmony_ci	 * are wired up identically on all supported variants.
3878c2ecf20Sopenharmony_ci	 */
3888c2ecf20Sopenharmony_ci	if ((bit < 0) || (bit > 7))
3898c2ecf20Sopenharmony_ci		return -EINVAL;
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_ci	local_irq_save(flags);
3928c2ecf20Sopenharmony_ci	wakemsk = alchemy_rdsys(AU1000_SYS_WAKEMSK);
3938c2ecf20Sopenharmony_ci	if (on)
3948c2ecf20Sopenharmony_ci		wakemsk |= 1 << bit;
3958c2ecf20Sopenharmony_ci	else
3968c2ecf20Sopenharmony_ci		wakemsk &= ~(1 << bit);
3978c2ecf20Sopenharmony_ci	alchemy_wrsys(wakemsk, AU1000_SYS_WAKEMSK);
3988c2ecf20Sopenharmony_ci	local_irq_restore(flags);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	return 0;
4018c2ecf20Sopenharmony_ci}
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci/*
4048c2ecf20Sopenharmony_ci * irq_chips for both ICs; this way the mask handlers can be
4058c2ecf20Sopenharmony_ci * as short as possible.
4068c2ecf20Sopenharmony_ci */
4078c2ecf20Sopenharmony_cistatic struct irq_chip au1x_ic0_chip = {
4088c2ecf20Sopenharmony_ci	.name		= "Alchemy-IC0",
4098c2ecf20Sopenharmony_ci	.irq_ack	= au1x_ic0_ack,
4108c2ecf20Sopenharmony_ci	.irq_mask	= au1x_ic0_mask,
4118c2ecf20Sopenharmony_ci	.irq_mask_ack	= au1x_ic0_maskack,
4128c2ecf20Sopenharmony_ci	.irq_unmask	= au1x_ic0_unmask,
4138c2ecf20Sopenharmony_ci	.irq_set_type	= au1x_ic_settype,
4148c2ecf20Sopenharmony_ci};
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_cistatic struct irq_chip au1x_ic1_chip = {
4178c2ecf20Sopenharmony_ci	.name		= "Alchemy-IC1",
4188c2ecf20Sopenharmony_ci	.irq_ack	= au1x_ic1_ack,
4198c2ecf20Sopenharmony_ci	.irq_mask	= au1x_ic1_mask,
4208c2ecf20Sopenharmony_ci	.irq_mask_ack	= au1x_ic1_maskack,
4218c2ecf20Sopenharmony_ci	.irq_unmask	= au1x_ic1_unmask,
4228c2ecf20Sopenharmony_ci	.irq_set_type	= au1x_ic_settype,
4238c2ecf20Sopenharmony_ci	.irq_set_wake	= au1x_ic1_setwake,
4248c2ecf20Sopenharmony_ci};
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_cistatic int au1x_ic_settype(struct irq_data *d, unsigned int flow_type)
4278c2ecf20Sopenharmony_ci{
4288c2ecf20Sopenharmony_ci	struct irq_chip *chip;
4298c2ecf20Sopenharmony_ci	unsigned int bit, irq = d->irq;
4308c2ecf20Sopenharmony_ci	irq_flow_handler_t handler = NULL;
4318c2ecf20Sopenharmony_ci	unsigned char *name = NULL;
4328c2ecf20Sopenharmony_ci	void __iomem *base;
4338c2ecf20Sopenharmony_ci	int ret;
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_ci	if (irq >= AU1000_INTC1_INT_BASE) {
4368c2ecf20Sopenharmony_ci		bit = irq - AU1000_INTC1_INT_BASE;
4378c2ecf20Sopenharmony_ci		chip = &au1x_ic1_chip;
4388c2ecf20Sopenharmony_ci		base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
4398c2ecf20Sopenharmony_ci	} else {
4408c2ecf20Sopenharmony_ci		bit = irq - AU1000_INTC0_INT_BASE;
4418c2ecf20Sopenharmony_ci		chip = &au1x_ic0_chip;
4428c2ecf20Sopenharmony_ci		base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
4438c2ecf20Sopenharmony_ci	}
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	if (bit > 31)
4468c2ecf20Sopenharmony_ci		return -EINVAL;
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	ret = 0;
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci	switch (flow_type) {	/* cfgregs 2:1:0 */
4518c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_RISING:	/* 0:0:1 */
4528c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG2CLR);
4538c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG1CLR);
4548c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG0SET);
4558c2ecf20Sopenharmony_ci		handler = handle_edge_irq;
4568c2ecf20Sopenharmony_ci		name = "riseedge";
4578c2ecf20Sopenharmony_ci		break;
4588c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_FALLING:	/* 0:1:0 */
4598c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG2CLR);
4608c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG1SET);
4618c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG0CLR);
4628c2ecf20Sopenharmony_ci		handler = handle_edge_irq;
4638c2ecf20Sopenharmony_ci		name = "falledge";
4648c2ecf20Sopenharmony_ci		break;
4658c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_BOTH:	/* 0:1:1 */
4668c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG2CLR);
4678c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG1SET);
4688c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG0SET);
4698c2ecf20Sopenharmony_ci		handler = handle_edge_irq;
4708c2ecf20Sopenharmony_ci		name = "bothedge";
4718c2ecf20Sopenharmony_ci		break;
4728c2ecf20Sopenharmony_ci	case IRQ_TYPE_LEVEL_HIGH:	/* 1:0:1 */
4738c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG2SET);
4748c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG1CLR);
4758c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG0SET);
4768c2ecf20Sopenharmony_ci		handler = handle_level_irq;
4778c2ecf20Sopenharmony_ci		name = "hilevel";
4788c2ecf20Sopenharmony_ci		break;
4798c2ecf20Sopenharmony_ci	case IRQ_TYPE_LEVEL_LOW:	/* 1:1:0 */
4808c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG2SET);
4818c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG1SET);
4828c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG0CLR);
4838c2ecf20Sopenharmony_ci		handler = handle_level_irq;
4848c2ecf20Sopenharmony_ci		name = "lowlevel";
4858c2ecf20Sopenharmony_ci		break;
4868c2ecf20Sopenharmony_ci	case IRQ_TYPE_NONE:		/* 0:0:0 */
4878c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG2CLR);
4888c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG1CLR);
4898c2ecf20Sopenharmony_ci		__raw_writel(1 << bit, base + IC_CFG0CLR);
4908c2ecf20Sopenharmony_ci		break;
4918c2ecf20Sopenharmony_ci	default:
4928c2ecf20Sopenharmony_ci		ret = -EINVAL;
4938c2ecf20Sopenharmony_ci	}
4948c2ecf20Sopenharmony_ci	irq_set_chip_handler_name_locked(d, chip, handler, name);
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	wmb();
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	return ret;
4998c2ecf20Sopenharmony_ci}
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci/******************************************************************************/
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci/*
5048c2ecf20Sopenharmony_ci * au1300_gpic_chgcfg - change PIN configuration.
5058c2ecf20Sopenharmony_ci * @gpio:	pin to change (0-based GPIO number from datasheet).
5068c2ecf20Sopenharmony_ci * @clr:	clear all bits set in 'clr'.
5078c2ecf20Sopenharmony_ci * @set:	set these bits.
5088c2ecf20Sopenharmony_ci *
5098c2ecf20Sopenharmony_ci * modifies a pins' configuration register, bits set in @clr will
5108c2ecf20Sopenharmony_ci * be cleared in the register, bits in @set will be set.
5118c2ecf20Sopenharmony_ci */
5128c2ecf20Sopenharmony_cistatic inline void au1300_gpic_chgcfg(unsigned int gpio,
5138c2ecf20Sopenharmony_ci				      unsigned long clr,
5148c2ecf20Sopenharmony_ci				      unsigned long set)
5158c2ecf20Sopenharmony_ci{
5168c2ecf20Sopenharmony_ci	void __iomem *r = AU1300_GPIC_ADDR;
5178c2ecf20Sopenharmony_ci	unsigned long l;
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	r += gpio * 4;	/* offset into pin config array */
5208c2ecf20Sopenharmony_ci	l = __raw_readl(r + AU1300_GPIC_PINCFG);
5218c2ecf20Sopenharmony_ci	l &= ~clr;
5228c2ecf20Sopenharmony_ci	l |= set;
5238c2ecf20Sopenharmony_ci	__raw_writel(l, r + AU1300_GPIC_PINCFG);
5248c2ecf20Sopenharmony_ci	wmb();
5258c2ecf20Sopenharmony_ci}
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci/*
5288c2ecf20Sopenharmony_ci * au1300_pinfunc_to_gpio - assign a pin as GPIO input (GPIO ctrl).
5298c2ecf20Sopenharmony_ci * @pin:	pin (0-based GPIO number from datasheet).
5308c2ecf20Sopenharmony_ci *
5318c2ecf20Sopenharmony_ci * Assigns a GPIO pin to the GPIO controller, so its level can either
5328c2ecf20Sopenharmony_ci * be read or set through the generic GPIO functions.
5338c2ecf20Sopenharmony_ci * If you need a GPOUT, use au1300_gpio_set_value(pin, 0/1).
5348c2ecf20Sopenharmony_ci * REVISIT: is this function really necessary?
5358c2ecf20Sopenharmony_ci */
5368c2ecf20Sopenharmony_civoid au1300_pinfunc_to_gpio(enum au1300_multifunc_pins gpio)
5378c2ecf20Sopenharmony_ci{
5388c2ecf20Sopenharmony_ci	au1300_gpio_direction_input(gpio + AU1300_GPIO_BASE);
5398c2ecf20Sopenharmony_ci}
5408c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(au1300_pinfunc_to_gpio);
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci/*
5438c2ecf20Sopenharmony_ci * au1300_pinfunc_to_dev - assign a pin to the device function.
5448c2ecf20Sopenharmony_ci * @pin:	pin (0-based GPIO number from datasheet).
5458c2ecf20Sopenharmony_ci *
5468c2ecf20Sopenharmony_ci * Assigns a GPIO pin to its associated device function; the pin will be
5478c2ecf20Sopenharmony_ci * driven by the device and not through GPIO functions.
5488c2ecf20Sopenharmony_ci */
5498c2ecf20Sopenharmony_civoid au1300_pinfunc_to_dev(enum au1300_multifunc_pins gpio)
5508c2ecf20Sopenharmony_ci{
5518c2ecf20Sopenharmony_ci	void __iomem *r = AU1300_GPIC_ADDR;
5528c2ecf20Sopenharmony_ci	unsigned long bit;
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci	r += GPIC_GPIO_BANKOFF(gpio);
5558c2ecf20Sopenharmony_ci	bit = GPIC_GPIO_TO_BIT(gpio);
5568c2ecf20Sopenharmony_ci	__raw_writel(bit, r + AU1300_GPIC_DEVSEL);
5578c2ecf20Sopenharmony_ci	wmb();
5588c2ecf20Sopenharmony_ci}
5598c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(au1300_pinfunc_to_dev);
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci/*
5628c2ecf20Sopenharmony_ci * au1300_set_irq_priority -  set internal priority of IRQ.
5638c2ecf20Sopenharmony_ci * @irq:	irq to set priority (linux irq number).
5648c2ecf20Sopenharmony_ci * @p:		priority (0 = highest, 3 = lowest).
5658c2ecf20Sopenharmony_ci */
5668c2ecf20Sopenharmony_civoid au1300_set_irq_priority(unsigned int irq, int p)
5678c2ecf20Sopenharmony_ci{
5688c2ecf20Sopenharmony_ci	irq -= ALCHEMY_GPIC_INT_BASE;
5698c2ecf20Sopenharmony_ci	au1300_gpic_chgcfg(irq, GPIC_CFG_IL_MASK, GPIC_CFG_IL_SET(p));
5708c2ecf20Sopenharmony_ci}
5718c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(au1300_set_irq_priority);
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci/*
5748c2ecf20Sopenharmony_ci * au1300_set_dbdma_gpio - assign a gpio to one of the DBDMA triggers.
5758c2ecf20Sopenharmony_ci * @dchan:	dbdma trigger select (0, 1).
5768c2ecf20Sopenharmony_ci * @gpio:	pin to assign as trigger.
5778c2ecf20Sopenharmony_ci *
5788c2ecf20Sopenharmony_ci * DBDMA controller has 2 external trigger sources; this function
5798c2ecf20Sopenharmony_ci * assigns a GPIO to the selected trigger.
5808c2ecf20Sopenharmony_ci */
5818c2ecf20Sopenharmony_civoid au1300_set_dbdma_gpio(int dchan, unsigned int gpio)
5828c2ecf20Sopenharmony_ci{
5838c2ecf20Sopenharmony_ci	unsigned long r;
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_ci	if ((dchan >= 0) && (dchan <= 1)) {
5868c2ecf20Sopenharmony_ci		r = __raw_readl(AU1300_GPIC_ADDR + AU1300_GPIC_DMASEL);
5878c2ecf20Sopenharmony_ci		r &= ~(0xff << (8 * dchan));
5888c2ecf20Sopenharmony_ci		r |= (gpio & 0x7f) << (8 * dchan);
5898c2ecf20Sopenharmony_ci		__raw_writel(r, AU1300_GPIC_ADDR + AU1300_GPIC_DMASEL);
5908c2ecf20Sopenharmony_ci		wmb();
5918c2ecf20Sopenharmony_ci	}
5928c2ecf20Sopenharmony_ci}
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_cistatic inline void gpic_pin_set_idlewake(unsigned int gpio, int allow)
5958c2ecf20Sopenharmony_ci{
5968c2ecf20Sopenharmony_ci	au1300_gpic_chgcfg(gpio, GPIC_CFG_IDLEWAKE,
5978c2ecf20Sopenharmony_ci			   allow ? GPIC_CFG_IDLEWAKE : 0);
5988c2ecf20Sopenharmony_ci}
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_cistatic void au1300_gpic_mask(struct irq_data *d)
6018c2ecf20Sopenharmony_ci{
6028c2ecf20Sopenharmony_ci	void __iomem *r = AU1300_GPIC_ADDR;
6038c2ecf20Sopenharmony_ci	unsigned long bit, irq = d->irq;
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci	irq -= ALCHEMY_GPIC_INT_BASE;
6068c2ecf20Sopenharmony_ci	r += GPIC_GPIO_BANKOFF(irq);
6078c2ecf20Sopenharmony_ci	bit = GPIC_GPIO_TO_BIT(irq);
6088c2ecf20Sopenharmony_ci	__raw_writel(bit, r + AU1300_GPIC_IDIS);
6098c2ecf20Sopenharmony_ci	wmb();
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci	gpic_pin_set_idlewake(irq, 0);
6128c2ecf20Sopenharmony_ci}
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_cistatic void au1300_gpic_unmask(struct irq_data *d)
6158c2ecf20Sopenharmony_ci{
6168c2ecf20Sopenharmony_ci	void __iomem *r = AU1300_GPIC_ADDR;
6178c2ecf20Sopenharmony_ci	unsigned long bit, irq = d->irq;
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci	irq -= ALCHEMY_GPIC_INT_BASE;
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	gpic_pin_set_idlewake(irq, 1);
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci	r += GPIC_GPIO_BANKOFF(irq);
6248c2ecf20Sopenharmony_ci	bit = GPIC_GPIO_TO_BIT(irq);
6258c2ecf20Sopenharmony_ci	__raw_writel(bit, r + AU1300_GPIC_IEN);
6268c2ecf20Sopenharmony_ci	wmb();
6278c2ecf20Sopenharmony_ci}
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_cistatic void au1300_gpic_maskack(struct irq_data *d)
6308c2ecf20Sopenharmony_ci{
6318c2ecf20Sopenharmony_ci	void __iomem *r = AU1300_GPIC_ADDR;
6328c2ecf20Sopenharmony_ci	unsigned long bit, irq = d->irq;
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci	irq -= ALCHEMY_GPIC_INT_BASE;
6358c2ecf20Sopenharmony_ci	r += GPIC_GPIO_BANKOFF(irq);
6368c2ecf20Sopenharmony_ci	bit = GPIC_GPIO_TO_BIT(irq);
6378c2ecf20Sopenharmony_ci	__raw_writel(bit, r + AU1300_GPIC_IPEND);	/* ack */
6388c2ecf20Sopenharmony_ci	__raw_writel(bit, r + AU1300_GPIC_IDIS);	/* mask */
6398c2ecf20Sopenharmony_ci	wmb();
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci	gpic_pin_set_idlewake(irq, 0);
6428c2ecf20Sopenharmony_ci}
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_cistatic void au1300_gpic_ack(struct irq_data *d)
6458c2ecf20Sopenharmony_ci{
6468c2ecf20Sopenharmony_ci	void __iomem *r = AU1300_GPIC_ADDR;
6478c2ecf20Sopenharmony_ci	unsigned long bit, irq = d->irq;
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	irq -= ALCHEMY_GPIC_INT_BASE;
6508c2ecf20Sopenharmony_ci	r += GPIC_GPIO_BANKOFF(irq);
6518c2ecf20Sopenharmony_ci	bit = GPIC_GPIO_TO_BIT(irq);
6528c2ecf20Sopenharmony_ci	__raw_writel(bit, r + AU1300_GPIC_IPEND);	/* ack */
6538c2ecf20Sopenharmony_ci	wmb();
6548c2ecf20Sopenharmony_ci}
6558c2ecf20Sopenharmony_ci
6568c2ecf20Sopenharmony_cistatic struct irq_chip au1300_gpic = {
6578c2ecf20Sopenharmony_ci	.name		= "GPIOINT",
6588c2ecf20Sopenharmony_ci	.irq_ack	= au1300_gpic_ack,
6598c2ecf20Sopenharmony_ci	.irq_mask	= au1300_gpic_mask,
6608c2ecf20Sopenharmony_ci	.irq_mask_ack	= au1300_gpic_maskack,
6618c2ecf20Sopenharmony_ci	.irq_unmask	= au1300_gpic_unmask,
6628c2ecf20Sopenharmony_ci	.irq_set_type	= au1300_gpic_settype,
6638c2ecf20Sopenharmony_ci};
6648c2ecf20Sopenharmony_ci
6658c2ecf20Sopenharmony_cistatic int au1300_gpic_settype(struct irq_data *d, unsigned int type)
6668c2ecf20Sopenharmony_ci{
6678c2ecf20Sopenharmony_ci	unsigned long s;
6688c2ecf20Sopenharmony_ci	unsigned char *name = NULL;
6698c2ecf20Sopenharmony_ci	irq_flow_handler_t hdl = NULL;
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci	switch (type) {
6728c2ecf20Sopenharmony_ci	case IRQ_TYPE_LEVEL_HIGH:
6738c2ecf20Sopenharmony_ci		s = GPIC_CFG_IC_LEVEL_HIGH;
6748c2ecf20Sopenharmony_ci		name = "high";
6758c2ecf20Sopenharmony_ci		hdl = handle_level_irq;
6768c2ecf20Sopenharmony_ci		break;
6778c2ecf20Sopenharmony_ci	case IRQ_TYPE_LEVEL_LOW:
6788c2ecf20Sopenharmony_ci		s = GPIC_CFG_IC_LEVEL_LOW;
6798c2ecf20Sopenharmony_ci		name = "low";
6808c2ecf20Sopenharmony_ci		hdl = handle_level_irq;
6818c2ecf20Sopenharmony_ci		break;
6828c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_RISING:
6838c2ecf20Sopenharmony_ci		s = GPIC_CFG_IC_EDGE_RISE;
6848c2ecf20Sopenharmony_ci		name = "posedge";
6858c2ecf20Sopenharmony_ci		hdl = handle_edge_irq;
6868c2ecf20Sopenharmony_ci		break;
6878c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_FALLING:
6888c2ecf20Sopenharmony_ci		s = GPIC_CFG_IC_EDGE_FALL;
6898c2ecf20Sopenharmony_ci		name = "negedge";
6908c2ecf20Sopenharmony_ci		hdl = handle_edge_irq;
6918c2ecf20Sopenharmony_ci		break;
6928c2ecf20Sopenharmony_ci	case IRQ_TYPE_EDGE_BOTH:
6938c2ecf20Sopenharmony_ci		s = GPIC_CFG_IC_EDGE_BOTH;
6948c2ecf20Sopenharmony_ci		name = "bothedge";
6958c2ecf20Sopenharmony_ci		hdl = handle_edge_irq;
6968c2ecf20Sopenharmony_ci		break;
6978c2ecf20Sopenharmony_ci	case IRQ_TYPE_NONE:
6988c2ecf20Sopenharmony_ci		s = GPIC_CFG_IC_OFF;
6998c2ecf20Sopenharmony_ci		name = "disabled";
7008c2ecf20Sopenharmony_ci		hdl = handle_level_irq;
7018c2ecf20Sopenharmony_ci		break;
7028c2ecf20Sopenharmony_ci	default:
7038c2ecf20Sopenharmony_ci		return -EINVAL;
7048c2ecf20Sopenharmony_ci	}
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	irq_set_chip_handler_name_locked(d, &au1300_gpic, hdl, name);
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	au1300_gpic_chgcfg(d->irq - ALCHEMY_GPIC_INT_BASE, GPIC_CFG_IC_MASK, s);
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci	return 0;
7118c2ecf20Sopenharmony_ci}
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_ci/******************************************************************************/
7148c2ecf20Sopenharmony_ci
7158c2ecf20Sopenharmony_cistatic inline void ic_init(void __iomem *base)
7168c2ecf20Sopenharmony_ci{
7178c2ecf20Sopenharmony_ci	/* initialize interrupt controller to a safe state */
7188c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_CFG0CLR);
7198c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_CFG1CLR);
7208c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_CFG2CLR);
7218c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_MASKCLR);
7228c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_ASSIGNCLR);
7238c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_WAKECLR);
7248c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_SRCSET);
7258c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_FALLINGCLR);
7268c2ecf20Sopenharmony_ci	__raw_writel(0xffffffff, base + IC_RISINGCLR);
7278c2ecf20Sopenharmony_ci	__raw_writel(0x00000000, base + IC_TESTBIT);
7288c2ecf20Sopenharmony_ci	wmb();
7298c2ecf20Sopenharmony_ci}
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_cistatic unsigned long alchemy_gpic_pmdata[ALCHEMY_GPIC_INT_NUM + 6];
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_cistatic inline void alchemy_ic_suspend_one(void __iomem *base, unsigned long *d)
7348c2ecf20Sopenharmony_ci{
7358c2ecf20Sopenharmony_ci	d[0] = __raw_readl(base + IC_CFG0RD);
7368c2ecf20Sopenharmony_ci	d[1] = __raw_readl(base + IC_CFG1RD);
7378c2ecf20Sopenharmony_ci	d[2] = __raw_readl(base + IC_CFG2RD);
7388c2ecf20Sopenharmony_ci	d[3] = __raw_readl(base + IC_SRCRD);
7398c2ecf20Sopenharmony_ci	d[4] = __raw_readl(base + IC_ASSIGNRD);
7408c2ecf20Sopenharmony_ci	d[5] = __raw_readl(base + IC_WAKERD);
7418c2ecf20Sopenharmony_ci	d[6] = __raw_readl(base + IC_MASKRD);
7428c2ecf20Sopenharmony_ci	ic_init(base);		/* shut it up too while at it */
7438c2ecf20Sopenharmony_ci}
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_cistatic inline void alchemy_ic_resume_one(void __iomem *base, unsigned long *d)
7468c2ecf20Sopenharmony_ci{
7478c2ecf20Sopenharmony_ci	ic_init(base);
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_ci	__raw_writel(d[0], base + IC_CFG0SET);
7508c2ecf20Sopenharmony_ci	__raw_writel(d[1], base + IC_CFG1SET);
7518c2ecf20Sopenharmony_ci	__raw_writel(d[2], base + IC_CFG2SET);
7528c2ecf20Sopenharmony_ci	__raw_writel(d[3], base + IC_SRCSET);
7538c2ecf20Sopenharmony_ci	__raw_writel(d[4], base + IC_ASSIGNSET);
7548c2ecf20Sopenharmony_ci	__raw_writel(d[5], base + IC_WAKESET);
7558c2ecf20Sopenharmony_ci	wmb();
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci	__raw_writel(d[6], base + IC_MASKSET);
7588c2ecf20Sopenharmony_ci	wmb();
7598c2ecf20Sopenharmony_ci}
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_cistatic int alchemy_ic_suspend(void)
7628c2ecf20Sopenharmony_ci{
7638c2ecf20Sopenharmony_ci	alchemy_ic_suspend_one((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR),
7648c2ecf20Sopenharmony_ci			       alchemy_gpic_pmdata);
7658c2ecf20Sopenharmony_ci	alchemy_ic_suspend_one((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR),
7668c2ecf20Sopenharmony_ci			       &alchemy_gpic_pmdata[7]);
7678c2ecf20Sopenharmony_ci	return 0;
7688c2ecf20Sopenharmony_ci}
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_cistatic void alchemy_ic_resume(void)
7718c2ecf20Sopenharmony_ci{
7728c2ecf20Sopenharmony_ci	alchemy_ic_resume_one((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR),
7738c2ecf20Sopenharmony_ci			      &alchemy_gpic_pmdata[7]);
7748c2ecf20Sopenharmony_ci	alchemy_ic_resume_one((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR),
7758c2ecf20Sopenharmony_ci			      alchemy_gpic_pmdata);
7768c2ecf20Sopenharmony_ci}
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_cistatic int alchemy_gpic_suspend(void)
7798c2ecf20Sopenharmony_ci{
7808c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
7818c2ecf20Sopenharmony_ci	int i;
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	/* save 4 interrupt mask status registers */
7848c2ecf20Sopenharmony_ci	alchemy_gpic_pmdata[0] = __raw_readl(base + AU1300_GPIC_IEN + 0x0);
7858c2ecf20Sopenharmony_ci	alchemy_gpic_pmdata[1] = __raw_readl(base + AU1300_GPIC_IEN + 0x4);
7868c2ecf20Sopenharmony_ci	alchemy_gpic_pmdata[2] = __raw_readl(base + AU1300_GPIC_IEN + 0x8);
7878c2ecf20Sopenharmony_ci	alchemy_gpic_pmdata[3] = __raw_readl(base + AU1300_GPIC_IEN + 0xc);
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_ci	/* save misc register(s) */
7908c2ecf20Sopenharmony_ci	alchemy_gpic_pmdata[4] = __raw_readl(base + AU1300_GPIC_DMASEL);
7918c2ecf20Sopenharmony_ci
7928c2ecf20Sopenharmony_ci	/* molto silenzioso */
7938c2ecf20Sopenharmony_ci	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x0);
7948c2ecf20Sopenharmony_ci	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x4);
7958c2ecf20Sopenharmony_ci	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x8);
7968c2ecf20Sopenharmony_ci	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0xc);
7978c2ecf20Sopenharmony_ci	wmb();
7988c2ecf20Sopenharmony_ci
7998c2ecf20Sopenharmony_ci	/* save pin/int-type configuration */
8008c2ecf20Sopenharmony_ci	base += AU1300_GPIC_PINCFG;
8018c2ecf20Sopenharmony_ci	for (i = 0; i < ALCHEMY_GPIC_INT_NUM; i++)
8028c2ecf20Sopenharmony_ci		alchemy_gpic_pmdata[i + 5] = __raw_readl(base + (i << 2));
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci	wmb();
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci	return 0;
8078c2ecf20Sopenharmony_ci}
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_cistatic void alchemy_gpic_resume(void)
8108c2ecf20Sopenharmony_ci{
8118c2ecf20Sopenharmony_ci	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
8128c2ecf20Sopenharmony_ci	int i;
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	/* disable all first */
8158c2ecf20Sopenharmony_ci	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x0);
8168c2ecf20Sopenharmony_ci	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x4);
8178c2ecf20Sopenharmony_ci	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x8);
8188c2ecf20Sopenharmony_ci	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0xc);
8198c2ecf20Sopenharmony_ci	wmb();
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci	/* restore pin/int-type configurations */
8228c2ecf20Sopenharmony_ci	base += AU1300_GPIC_PINCFG;
8238c2ecf20Sopenharmony_ci	for (i = 0; i < ALCHEMY_GPIC_INT_NUM; i++)
8248c2ecf20Sopenharmony_ci		__raw_writel(alchemy_gpic_pmdata[i + 5], base + (i << 2));
8258c2ecf20Sopenharmony_ci	wmb();
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_ci	/* restore misc register(s) */
8288c2ecf20Sopenharmony_ci	base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
8298c2ecf20Sopenharmony_ci	__raw_writel(alchemy_gpic_pmdata[4], base + AU1300_GPIC_DMASEL);
8308c2ecf20Sopenharmony_ci	wmb();
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci	/* finally restore masks */
8338c2ecf20Sopenharmony_ci	__raw_writel(alchemy_gpic_pmdata[0], base + AU1300_GPIC_IEN + 0x0);
8348c2ecf20Sopenharmony_ci	__raw_writel(alchemy_gpic_pmdata[1], base + AU1300_GPIC_IEN + 0x4);
8358c2ecf20Sopenharmony_ci	__raw_writel(alchemy_gpic_pmdata[2], base + AU1300_GPIC_IEN + 0x8);
8368c2ecf20Sopenharmony_ci	__raw_writel(alchemy_gpic_pmdata[3], base + AU1300_GPIC_IEN + 0xc);
8378c2ecf20Sopenharmony_ci	wmb();
8388c2ecf20Sopenharmony_ci}
8398c2ecf20Sopenharmony_ci
8408c2ecf20Sopenharmony_cistatic struct syscore_ops alchemy_ic_pmops = {
8418c2ecf20Sopenharmony_ci	.suspend	= alchemy_ic_suspend,
8428c2ecf20Sopenharmony_ci	.resume		= alchemy_ic_resume,
8438c2ecf20Sopenharmony_ci};
8448c2ecf20Sopenharmony_ci
8458c2ecf20Sopenharmony_cistatic struct syscore_ops alchemy_gpic_pmops = {
8468c2ecf20Sopenharmony_ci	.suspend	= alchemy_gpic_suspend,
8478c2ecf20Sopenharmony_ci	.resume		= alchemy_gpic_resume,
8488c2ecf20Sopenharmony_ci};
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci/******************************************************************************/
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci/* create chained handlers for the 4 IC requests to the MIPS IRQ ctrl */
8538c2ecf20Sopenharmony_ci#define DISP(name, base, addr)						      \
8548c2ecf20Sopenharmony_cistatic void au1000_##name##_dispatch(struct irq_desc *d)		      \
8558c2ecf20Sopenharmony_ci{									      \
8568c2ecf20Sopenharmony_ci	unsigned long r = __raw_readl((void __iomem *)KSEG1ADDR(addr));	      \
8578c2ecf20Sopenharmony_ci	if (likely(r))							      \
8588c2ecf20Sopenharmony_ci		generic_handle_irq(base + __ffs(r));			      \
8598c2ecf20Sopenharmony_ci	else								      \
8608c2ecf20Sopenharmony_ci		spurious_interrupt();					      \
8618c2ecf20Sopenharmony_ci}
8628c2ecf20Sopenharmony_ci
8638c2ecf20Sopenharmony_ciDISP(ic0r0, AU1000_INTC0_INT_BASE, AU1000_IC0_PHYS_ADDR + IC_REQ0INT)
8648c2ecf20Sopenharmony_ciDISP(ic0r1, AU1000_INTC0_INT_BASE, AU1000_IC0_PHYS_ADDR + IC_REQ1INT)
8658c2ecf20Sopenharmony_ciDISP(ic1r0, AU1000_INTC1_INT_BASE, AU1000_IC1_PHYS_ADDR + IC_REQ0INT)
8668c2ecf20Sopenharmony_ciDISP(ic1r1, AU1000_INTC1_INT_BASE, AU1000_IC1_PHYS_ADDR + IC_REQ1INT)
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_cistatic void alchemy_gpic_dispatch(struct irq_desc *d)
8698c2ecf20Sopenharmony_ci{
8708c2ecf20Sopenharmony_ci	int i = __raw_readl(AU1300_GPIC_ADDR + AU1300_GPIC_PRIENC);
8718c2ecf20Sopenharmony_ci	generic_handle_irq(ALCHEMY_GPIC_INT_BASE + i);
8728c2ecf20Sopenharmony_ci}
8738c2ecf20Sopenharmony_ci
8748c2ecf20Sopenharmony_ci/******************************************************************************/
8758c2ecf20Sopenharmony_ci
8768c2ecf20Sopenharmony_cistatic void __init au1000_init_irq(struct alchemy_irqmap *map)
8778c2ecf20Sopenharmony_ci{
8788c2ecf20Sopenharmony_ci	unsigned int bit, irq_nr;
8798c2ecf20Sopenharmony_ci	void __iomem *base;
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci	ic_init((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR));
8828c2ecf20Sopenharmony_ci	ic_init((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR));
8838c2ecf20Sopenharmony_ci	register_syscore_ops(&alchemy_ic_pmops);
8848c2ecf20Sopenharmony_ci	mips_cpu_irq_init();
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_ci	/* register all 64 possible IC0+IC1 irq sources as type "none".
8878c2ecf20Sopenharmony_ci	 * Use set_irq_type() to set edge/level behaviour at runtime.
8888c2ecf20Sopenharmony_ci	 */
8898c2ecf20Sopenharmony_ci	for (irq_nr = AU1000_INTC0_INT_BASE;
8908c2ecf20Sopenharmony_ci	     (irq_nr < AU1000_INTC0_INT_BASE + 32); irq_nr++)
8918c2ecf20Sopenharmony_ci		au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE);
8928c2ecf20Sopenharmony_ci
8938c2ecf20Sopenharmony_ci	for (irq_nr = AU1000_INTC1_INT_BASE;
8948c2ecf20Sopenharmony_ci	     (irq_nr < AU1000_INTC1_INT_BASE + 32); irq_nr++)
8958c2ecf20Sopenharmony_ci		au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE);
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	/*
8988c2ecf20Sopenharmony_ci	 * Initialize IC0, which is fixed per processor.
8998c2ecf20Sopenharmony_ci	 */
9008c2ecf20Sopenharmony_ci	while (map->irq != -1) {
9018c2ecf20Sopenharmony_ci		irq_nr = map->irq;
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci		if (irq_nr >= AU1000_INTC1_INT_BASE) {
9048c2ecf20Sopenharmony_ci			bit = irq_nr - AU1000_INTC1_INT_BASE;
9058c2ecf20Sopenharmony_ci			base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
9068c2ecf20Sopenharmony_ci		} else {
9078c2ecf20Sopenharmony_ci			bit = irq_nr - AU1000_INTC0_INT_BASE;
9088c2ecf20Sopenharmony_ci			base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
9098c2ecf20Sopenharmony_ci		}
9108c2ecf20Sopenharmony_ci		if (map->prio == 0)
9118c2ecf20Sopenharmony_ci			__raw_writel(1 << bit, base + IC_ASSIGNSET);
9128c2ecf20Sopenharmony_ci
9138c2ecf20Sopenharmony_ci		au1x_ic_settype(irq_get_irq_data(irq_nr), map->type);
9148c2ecf20Sopenharmony_ci		++map;
9158c2ecf20Sopenharmony_ci	}
9168c2ecf20Sopenharmony_ci
9178c2ecf20Sopenharmony_ci	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 2, au1000_ic0r0_dispatch);
9188c2ecf20Sopenharmony_ci	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 3, au1000_ic0r1_dispatch);
9198c2ecf20Sopenharmony_ci	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 4, au1000_ic1r0_dispatch);
9208c2ecf20Sopenharmony_ci	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 5, au1000_ic1r1_dispatch);
9218c2ecf20Sopenharmony_ci}
9228c2ecf20Sopenharmony_ci
9238c2ecf20Sopenharmony_cistatic void __init alchemy_gpic_init_irq(const struct alchemy_irqmap *dints)
9248c2ecf20Sopenharmony_ci{
9258c2ecf20Sopenharmony_ci	int i;
9268c2ecf20Sopenharmony_ci	void __iomem *bank_base;
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ci	register_syscore_ops(&alchemy_gpic_pmops);
9298c2ecf20Sopenharmony_ci	mips_cpu_irq_init();
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ci	/* disable & ack all possible interrupt sources */
9328c2ecf20Sopenharmony_ci	for (i = 0; i < 4; i++) {
9338c2ecf20Sopenharmony_ci		bank_base = AU1300_GPIC_ADDR + (i * 4);
9348c2ecf20Sopenharmony_ci		__raw_writel(~0UL, bank_base + AU1300_GPIC_IDIS);
9358c2ecf20Sopenharmony_ci		wmb();
9368c2ecf20Sopenharmony_ci		__raw_writel(~0UL, bank_base + AU1300_GPIC_IPEND);
9378c2ecf20Sopenharmony_ci		wmb();
9388c2ecf20Sopenharmony_ci	}
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_ci	/* register an irq_chip for them, with 2nd highest priority */
9418c2ecf20Sopenharmony_ci	for (i = ALCHEMY_GPIC_INT_BASE; i <= ALCHEMY_GPIC_INT_LAST; i++) {
9428c2ecf20Sopenharmony_ci		au1300_set_irq_priority(i, 1);
9438c2ecf20Sopenharmony_ci		au1300_gpic_settype(irq_get_irq_data(i), IRQ_TYPE_NONE);
9448c2ecf20Sopenharmony_ci	}
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_ci	/* setup known on-chip sources */
9478c2ecf20Sopenharmony_ci	while ((i = dints->irq) != -1) {
9488c2ecf20Sopenharmony_ci		au1300_gpic_settype(irq_get_irq_data(i), dints->type);
9498c2ecf20Sopenharmony_ci		au1300_set_irq_priority(i, dints->prio);
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci		if (dints->internal)
9528c2ecf20Sopenharmony_ci			au1300_pinfunc_to_dev(i - ALCHEMY_GPIC_INT_BASE);
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_ci		dints++;
9558c2ecf20Sopenharmony_ci	}
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 2, alchemy_gpic_dispatch);
9588c2ecf20Sopenharmony_ci	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 3, alchemy_gpic_dispatch);
9598c2ecf20Sopenharmony_ci	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 4, alchemy_gpic_dispatch);
9608c2ecf20Sopenharmony_ci	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 5, alchemy_gpic_dispatch);
9618c2ecf20Sopenharmony_ci}
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_ci/******************************************************************************/
9648c2ecf20Sopenharmony_ci
9658c2ecf20Sopenharmony_civoid __init arch_init_irq(void)
9668c2ecf20Sopenharmony_ci{
9678c2ecf20Sopenharmony_ci	switch (alchemy_get_cputype()) {
9688c2ecf20Sopenharmony_ci	case ALCHEMY_CPU_AU1000:
9698c2ecf20Sopenharmony_ci		au1000_init_irq(au1000_irqmap);
9708c2ecf20Sopenharmony_ci		break;
9718c2ecf20Sopenharmony_ci	case ALCHEMY_CPU_AU1500:
9728c2ecf20Sopenharmony_ci		au1000_init_irq(au1500_irqmap);
9738c2ecf20Sopenharmony_ci		break;
9748c2ecf20Sopenharmony_ci	case ALCHEMY_CPU_AU1100:
9758c2ecf20Sopenharmony_ci		au1000_init_irq(au1100_irqmap);
9768c2ecf20Sopenharmony_ci		break;
9778c2ecf20Sopenharmony_ci	case ALCHEMY_CPU_AU1550:
9788c2ecf20Sopenharmony_ci		au1000_init_irq(au1550_irqmap);
9798c2ecf20Sopenharmony_ci		break;
9808c2ecf20Sopenharmony_ci	case ALCHEMY_CPU_AU1200:
9818c2ecf20Sopenharmony_ci		au1000_init_irq(au1200_irqmap);
9828c2ecf20Sopenharmony_ci		break;
9838c2ecf20Sopenharmony_ci	case ALCHEMY_CPU_AU1300:
9848c2ecf20Sopenharmony_ci		alchemy_gpic_init_irq(au1300_irqmap);
9858c2ecf20Sopenharmony_ci		break;
9868c2ecf20Sopenharmony_ci	default:
9878c2ecf20Sopenharmony_ci		pr_err("unknown Alchemy IRQ core\n");
9888c2ecf20Sopenharmony_ci		break;
9898c2ecf20Sopenharmony_ci	}
9908c2ecf20Sopenharmony_ci}
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_ciasmlinkage void plat_irq_dispatch(void)
9938c2ecf20Sopenharmony_ci{
9948c2ecf20Sopenharmony_ci	unsigned long r = (read_c0_status() & read_c0_cause()) >> 8;
9958c2ecf20Sopenharmony_ci	do_IRQ(MIPS_CPU_IRQ_BASE + __ffs(r & 0xff));
9968c2ecf20Sopenharmony_ci}
997