xref: /openbmc/linux/arch/mips/alchemy/common/irq.c (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
1e8c7c482SRalf Baechle /*
2e8c7c482SRalf Baechle  * Copyright 2001, 2007-2008 MontaVista Software Inc.
3e8c7c482SRalf Baechle  * Author: MontaVista Software, Inc. <source@mvista.com>
4e8c7c482SRalf Baechle  *
5e8c7c482SRalf Baechle  * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
6e8c7c482SRalf Baechle  *
7e8c7c482SRalf Baechle  *  This program is free software; you can redistribute	 it and/or modify it
8e8c7c482SRalf Baechle  *  under  the terms of	 the GNU General  Public License as published by the
9e8c7c482SRalf Baechle  *  Free Software Foundation;  either version 2 of the	License, or (at your
10e8c7c482SRalf Baechle  *  option) any later version.
11e8c7c482SRalf Baechle  *
12e8c7c482SRalf Baechle  *  THIS  SOFTWARE  IS PROVIDED	  ``AS	IS'' AND   ANY	EXPRESS OR IMPLIED
13e8c7c482SRalf Baechle  *  WARRANTIES,	  INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
14e8c7c482SRalf Baechle  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
15e8c7c482SRalf Baechle  *  NO	EVENT  SHALL   THE AUTHOR  BE	 LIABLE FOR ANY	  DIRECT, INDIRECT,
16e8c7c482SRalf Baechle  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17e8c7c482SRalf Baechle  *  NOT LIMITED	  TO, PROCUREMENT OF  SUBSTITUTE GOODS	OR SERVICES; LOSS OF
18e8c7c482SRalf Baechle  *  USE, DATA,	OR PROFITS; OR	BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19e8c7c482SRalf Baechle  *  ANY THEORY OF LIABILITY, WHETHER IN	 CONTRACT, STRICT LIABILITY, OR TORT
20e8c7c482SRalf Baechle  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21e8c7c482SRalf Baechle  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22e8c7c482SRalf Baechle  *
23e8c7c482SRalf Baechle  *  You should have received a copy of the  GNU General Public License along
24e8c7c482SRalf Baechle  *  with this program; if not, write  to the Free Software Foundation, Inc.,
25e8c7c482SRalf Baechle  *  675 Mass Ave, Cambridge, MA 02139, USA.
26e8c7c482SRalf Baechle  */
27785e3268SManuel Lauss 
283eab8095SManuel Lauss #include <linux/export.h>
29e8c7c482SRalf Baechle #include <linux/init.h>
30e8c7c482SRalf Baechle #include <linux/interrupt.h>
310f0d85bcSManuel Lauss #include <linux/slab.h>
324b5c82b5SManuel Lauss #include <linux/syscore_ops.h>
33e8c7c482SRalf Baechle 
34e8c7c482SRalf Baechle #include <asm/irq_cpu.h>
35e8c7c482SRalf Baechle #include <asm/mach-au1x00/au1000.h>
363eab8095SManuel Lauss #include <asm/mach-au1x00/gpio-au1300.h>
37e8c7c482SRalf Baechle 
38dca75871SManuel Lauss /* Interrupt Controller register offsets */
39dca75871SManuel Lauss #define IC_CFG0RD	0x40
40dca75871SManuel Lauss #define IC_CFG0SET	0x40
41dca75871SManuel Lauss #define IC_CFG0CLR	0x44
42dca75871SManuel Lauss #define IC_CFG1RD	0x48
43dca75871SManuel Lauss #define IC_CFG1SET	0x48
44dca75871SManuel Lauss #define IC_CFG1CLR	0x4C
45dca75871SManuel Lauss #define IC_CFG2RD	0x50
46dca75871SManuel Lauss #define IC_CFG2SET	0x50
47dca75871SManuel Lauss #define IC_CFG2CLR	0x54
48dca75871SManuel Lauss #define IC_REQ0INT	0x54
49dca75871SManuel Lauss #define IC_SRCRD	0x58
50dca75871SManuel Lauss #define IC_SRCSET	0x58
51dca75871SManuel Lauss #define IC_SRCCLR	0x5C
52dca75871SManuel Lauss #define IC_REQ1INT	0x5C
53dca75871SManuel Lauss #define IC_ASSIGNRD	0x60
54dca75871SManuel Lauss #define IC_ASSIGNSET	0x60
55dca75871SManuel Lauss #define IC_ASSIGNCLR	0x64
56dca75871SManuel Lauss #define IC_WAKERD	0x68
57dca75871SManuel Lauss #define IC_WAKESET	0x68
58dca75871SManuel Lauss #define IC_WAKECLR	0x6C
59dca75871SManuel Lauss #define IC_MASKRD	0x70
60dca75871SManuel Lauss #define IC_MASKSET	0x70
61dca75871SManuel Lauss #define IC_MASKCLR	0x74
62dca75871SManuel Lauss #define IC_RISINGRD	0x78
63dca75871SManuel Lauss #define IC_RISINGCLR	0x78
64dca75871SManuel Lauss #define IC_FALLINGRD	0x7C
65dca75871SManuel Lauss #define IC_FALLINGCLR	0x7C
66dca75871SManuel Lauss #define IC_TESTBIT	0x80
67dca75871SManuel Lauss 
683eab8095SManuel Lauss /* per-processor fixed function irqs */
693eab8095SManuel Lauss struct alchemy_irqmap {
703eab8095SManuel Lauss 	int irq;	/* linux IRQ number */
713eab8095SManuel Lauss 	int type;	/* IRQ_TYPE_ */
723eab8095SManuel Lauss 	int prio;	/* irq priority, 0 highest, 3 lowest */
733eab8095SManuel Lauss 	int internal;	/* GPIC: internal source (no ext. pin)? */
743eab8095SManuel Lauss };
753eab8095SManuel Lauss 
763eab8095SManuel Lauss static int au1x_ic_settype(struct irq_data *d, unsigned int type);
773eab8095SManuel Lauss static int au1300_gpic_settype(struct irq_data *d, unsigned int type);
783eab8095SManuel Lauss 
79785e3268SManuel Lauss 
805047201bSManuel Lauss /* NOTE on interrupt priorities: The original writers of this code said:
815047201bSManuel Lauss  *
825047201bSManuel Lauss  * Because of the tight timing of SETUP token to reply transactions,
835047201bSManuel Lauss  * the USB devices-side packet complete interrupt (USB_DEV_REQ_INT)
845047201bSManuel Lauss  * needs the highest priority.
855047201bSManuel Lauss  */
863eab8095SManuel Lauss struct alchemy_irqmap au1000_irqmap[] __initdata = {
873eab8095SManuel Lauss 	{ AU1000_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
883eab8095SManuel Lauss 	{ AU1000_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
893eab8095SManuel Lauss 	{ AU1000_UART2_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
903eab8095SManuel Lauss 	{ AU1000_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
913eab8095SManuel Lauss 	{ AU1000_SSI0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
923eab8095SManuel Lauss 	{ AU1000_SSI1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
933eab8095SManuel Lauss 	{ AU1000_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
943eab8095SManuel Lauss 	{ AU1000_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
953eab8095SManuel Lauss 	{ AU1000_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
963eab8095SManuel Lauss 	{ AU1000_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
973eab8095SManuel Lauss 	{ AU1000_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
983eab8095SManuel Lauss 	{ AU1000_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
993eab8095SManuel Lauss 	{ AU1000_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1003eab8095SManuel Lauss 	{ AU1000_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1013eab8095SManuel Lauss 	{ AU1000_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1023eab8095SManuel Lauss 	{ AU1000_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1033eab8095SManuel Lauss 	{ AU1000_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1043eab8095SManuel Lauss 	{ AU1000_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1053eab8095SManuel Lauss 	{ AU1000_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1063eab8095SManuel Lauss 	{ AU1000_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1073eab8095SManuel Lauss 	{ AU1000_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1083eab8095SManuel Lauss 	{ AU1000_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
1093eab8095SManuel Lauss 	{ AU1000_IRDA_TX_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1103eab8095SManuel Lauss 	{ AU1000_IRDA_RX_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1113eab8095SManuel Lauss 	{ AU1000_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,	0, 0 },
1123eab8095SManuel Lauss 	{ AU1000_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
1133eab8095SManuel Lauss 	{ AU1000_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1143eab8095SManuel Lauss 	{ AU1000_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1153eab8095SManuel Lauss 	{ AU1000_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1163eab8095SManuel Lauss 	{ AU1000_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1173eab8095SManuel Lauss 	{ AU1000_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
118ef6c1fd6SManuel Lauss 	{ -1, },
119ef6c1fd6SManuel Lauss };
120785e3268SManuel Lauss 
1213eab8095SManuel Lauss struct alchemy_irqmap au1500_irqmap[] __initdata = {
1223eab8095SManuel Lauss 	{ AU1500_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1233eab8095SManuel Lauss 	{ AU1500_PCI_INTA,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1243eab8095SManuel Lauss 	{ AU1500_PCI_INTB,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1253eab8095SManuel Lauss 	{ AU1500_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1263eab8095SManuel Lauss 	{ AU1500_PCI_INTC,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1273eab8095SManuel Lauss 	{ AU1500_PCI_INTD,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1283eab8095SManuel Lauss 	{ AU1500_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1293eab8095SManuel Lauss 	{ AU1500_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1303eab8095SManuel Lauss 	{ AU1500_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1313eab8095SManuel Lauss 	{ AU1500_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1323eab8095SManuel Lauss 	{ AU1500_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1333eab8095SManuel Lauss 	{ AU1500_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1343eab8095SManuel Lauss 	{ AU1500_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1353eab8095SManuel Lauss 	{ AU1500_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1363eab8095SManuel Lauss 	{ AU1500_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1373eab8095SManuel Lauss 	{ AU1500_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1383eab8095SManuel Lauss 	{ AU1500_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1393eab8095SManuel Lauss 	{ AU1500_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1403eab8095SManuel Lauss 	{ AU1500_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1413eab8095SManuel Lauss 	{ AU1500_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1423eab8095SManuel Lauss 	{ AU1500_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1433eab8095SManuel Lauss 	{ AU1500_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
1443eab8095SManuel Lauss 	{ AU1500_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,	0, 0 },
1453eab8095SManuel Lauss 	{ AU1500_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
1463eab8095SManuel Lauss 	{ AU1500_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1473eab8095SManuel Lauss 	{ AU1500_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1483eab8095SManuel Lauss 	{ AU1500_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1493eab8095SManuel Lauss 	{ AU1500_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1503eab8095SManuel Lauss 	{ AU1500_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
151ef6c1fd6SManuel Lauss 	{ -1, },
152ef6c1fd6SManuel Lauss };
153785e3268SManuel Lauss 
1543eab8095SManuel Lauss struct alchemy_irqmap au1100_irqmap[] __initdata = {
1553eab8095SManuel Lauss 	{ AU1100_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1563eab8095SManuel Lauss 	{ AU1100_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1573eab8095SManuel Lauss 	{ AU1100_SD_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1583eab8095SManuel Lauss 	{ AU1100_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1593eab8095SManuel Lauss 	{ AU1100_SSI0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1603eab8095SManuel Lauss 	{ AU1100_SSI1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1613eab8095SManuel Lauss 	{ AU1100_DMA_INT_BASE,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1623eab8095SManuel Lauss 	{ AU1100_DMA_INT_BASE+1,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1633eab8095SManuel Lauss 	{ AU1100_DMA_INT_BASE+2,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1643eab8095SManuel Lauss 	{ AU1100_DMA_INT_BASE+3,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1653eab8095SManuel Lauss 	{ AU1100_DMA_INT_BASE+4,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1663eab8095SManuel Lauss 	{ AU1100_DMA_INT_BASE+5,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1673eab8095SManuel Lauss 	{ AU1100_DMA_INT_BASE+6,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1683eab8095SManuel Lauss 	{ AU1100_DMA_INT_BASE+7,  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1693eab8095SManuel Lauss 	{ AU1100_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1703eab8095SManuel Lauss 	{ AU1100_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1713eab8095SManuel Lauss 	{ AU1100_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1723eab8095SManuel Lauss 	{ AU1100_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1733eab8095SManuel Lauss 	{ AU1100_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1743eab8095SManuel Lauss 	{ AU1100_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1753eab8095SManuel Lauss 	{ AU1100_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
1763eab8095SManuel Lauss 	{ AU1100_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
1773eab8095SManuel Lauss 	{ AU1100_IRDA_TX_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1783eab8095SManuel Lauss 	{ AU1100_IRDA_RX_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1793eab8095SManuel Lauss 	{ AU1100_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,	0, 0 },
1803eab8095SManuel Lauss 	{ AU1100_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
1813eab8095SManuel Lauss 	{ AU1100_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1823eab8095SManuel Lauss 	{ AU1100_ACSYNC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
1833eab8095SManuel Lauss 	{ AU1100_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1843eab8095SManuel Lauss 	{ AU1100_LCD_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1853eab8095SManuel Lauss 	{ AU1100_AC97C_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
186ef6c1fd6SManuel Lauss 	{ -1, },
187ef6c1fd6SManuel Lauss };
188785e3268SManuel Lauss 
1893eab8095SManuel Lauss struct alchemy_irqmap au1550_irqmap[] __initdata = {
1903eab8095SManuel Lauss 	{ AU1550_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1913eab8095SManuel Lauss 	{ AU1550_PCI_INTA,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1923eab8095SManuel Lauss 	{ AU1550_PCI_INTB,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1933eab8095SManuel Lauss 	{ AU1550_DDMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1943eab8095SManuel Lauss 	{ AU1550_CRYPTO_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1953eab8095SManuel Lauss 	{ AU1550_PCI_INTC,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1963eab8095SManuel Lauss 	{ AU1550_PCI_INTD,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1973eab8095SManuel Lauss 	{ AU1550_PCI_RST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
1983eab8095SManuel Lauss 	{ AU1550_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
1993eab8095SManuel Lauss 	{ AU1550_UART3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2003eab8095SManuel Lauss 	{ AU1550_PSC0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2013eab8095SManuel Lauss 	{ AU1550_PSC1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2023eab8095SManuel Lauss 	{ AU1550_PSC2_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2033eab8095SManuel Lauss 	{ AU1550_PSC3_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2043eab8095SManuel Lauss 	{ AU1550_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2053eab8095SManuel Lauss 	{ AU1550_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2063eab8095SManuel Lauss 	{ AU1550_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2073eab8095SManuel Lauss 	{ AU1550_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2083eab8095SManuel Lauss 	{ AU1550_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2093eab8095SManuel Lauss 	{ AU1550_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2103eab8095SManuel Lauss 	{ AU1550_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2113eab8095SManuel Lauss 	{ AU1550_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
2123eab8095SManuel Lauss 	{ AU1550_NAND_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2133eab8095SManuel Lauss 	{ AU1550_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH,	0, 0 },
2143eab8095SManuel Lauss 	{ AU1550_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
2153eab8095SManuel Lauss 	{ AU1550_USB_HOST_INT,	  IRQ_TYPE_LEVEL_LOW,	1, 0 },
2163eab8095SManuel Lauss 	{ AU1550_MAC0_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2173eab8095SManuel Lauss 	{ AU1550_MAC1_DMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
218ef6c1fd6SManuel Lauss 	{ -1, },
219ef6c1fd6SManuel Lauss };
220785e3268SManuel Lauss 
2213eab8095SManuel Lauss struct alchemy_irqmap au1200_irqmap[] __initdata = {
2223eab8095SManuel Lauss 	{ AU1200_UART0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2233eab8095SManuel Lauss 	{ AU1200_SWT_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2243eab8095SManuel Lauss 	{ AU1200_SD_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2253eab8095SManuel Lauss 	{ AU1200_DDMA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2263eab8095SManuel Lauss 	{ AU1200_MAE_BE_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2273eab8095SManuel Lauss 	{ AU1200_UART1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2283eab8095SManuel Lauss 	{ AU1200_MAE_FE_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2293eab8095SManuel Lauss 	{ AU1200_PSC0_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2303eab8095SManuel Lauss 	{ AU1200_PSC1_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2313eab8095SManuel Lauss 	{ AU1200_AES_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2323eab8095SManuel Lauss 	{ AU1200_CAMERA_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2333eab8095SManuel Lauss 	{ AU1200_TOY_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2343eab8095SManuel Lauss 	{ AU1200_TOY_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2353eab8095SManuel Lauss 	{ AU1200_TOY_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2363eab8095SManuel Lauss 	{ AU1200_TOY_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2373eab8095SManuel Lauss 	{ AU1200_RTC_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2383eab8095SManuel Lauss 	{ AU1200_RTC_MATCH0_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2393eab8095SManuel Lauss 	{ AU1200_RTC_MATCH1_INT,  IRQ_TYPE_EDGE_RISING, 1, 0 },
2403eab8095SManuel Lauss 	{ AU1200_RTC_MATCH2_INT,  IRQ_TYPE_EDGE_RISING, 0, 0 },
2413eab8095SManuel Lauss 	{ AU1200_NAND_INT,	  IRQ_TYPE_EDGE_RISING, 1, 0 },
2423eab8095SManuel Lauss 	{ AU1200_USB_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2433eab8095SManuel Lauss 	{ AU1200_LCD_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
2443eab8095SManuel Lauss 	{ AU1200_MAE_BOTH_INT,	  IRQ_TYPE_LEVEL_HIGH,	1, 0 },
245ef6c1fd6SManuel Lauss 	{ -1, },
246785e3268SManuel Lauss };
247785e3268SManuel Lauss 
2483eab8095SManuel Lauss static struct alchemy_irqmap au1300_irqmap[] __initdata = {
2493eab8095SManuel Lauss 	/* multifunction: gpio pin or device */
2503eab8095SManuel Lauss 	{ AU1300_UART1_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2513eab8095SManuel Lauss 	{ AU1300_UART2_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2523eab8095SManuel Lauss 	{ AU1300_UART3_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2533eab8095SManuel Lauss 	{ AU1300_SD1_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2543eab8095SManuel Lauss 	{ AU1300_SD2_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2553eab8095SManuel Lauss 	{ AU1300_PSC0_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2563eab8095SManuel Lauss 	{ AU1300_PSC1_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2573eab8095SManuel Lauss 	{ AU1300_PSC2_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2583eab8095SManuel Lauss 	{ AU1300_PSC3_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2593eab8095SManuel Lauss 	{ AU1300_NAND_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 0, },
2603eab8095SManuel Lauss 	/* au1300 internal */
2613eab8095SManuel Lauss 	{ AU1300_DDMA_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2623eab8095SManuel Lauss 	{ AU1300_MMU_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2633eab8095SManuel Lauss 	{ AU1300_MPU_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2643eab8095SManuel Lauss 	{ AU1300_GPU_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2653eab8095SManuel Lauss 	{ AU1300_UDMA_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2663eab8095SManuel Lauss 	{ AU1300_TOY_INT,	 IRQ_TYPE_EDGE_RISING,	1, 1, },
2673eab8095SManuel Lauss 	{ AU1300_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2683eab8095SManuel Lauss 	{ AU1300_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2693eab8095SManuel Lauss 	{ AU1300_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2703eab8095SManuel Lauss 	{ AU1300_RTC_INT,	 IRQ_TYPE_EDGE_RISING,	1, 1, },
2713eab8095SManuel Lauss 	{ AU1300_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2723eab8095SManuel Lauss 	{ AU1300_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING,	1, 1, },
2733eab8095SManuel Lauss 	{ AU1300_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING,	0, 1, },
2743eab8095SManuel Lauss 	{ AU1300_UART0_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2753eab8095SManuel Lauss 	{ AU1300_SD0_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2763eab8095SManuel Lauss 	{ AU1300_USB_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2773eab8095SManuel Lauss 	{ AU1300_LCD_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2783eab8095SManuel Lauss 	{ AU1300_BSA_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2793eab8095SManuel Lauss 	{ AU1300_MPE_INT,	 IRQ_TYPE_EDGE_RISING,	1, 1, },
2803eab8095SManuel Lauss 	{ AU1300_ITE_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2813eab8095SManuel Lauss 	{ AU1300_AES_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2823eab8095SManuel Lauss 	{ AU1300_CIM_INT,	 IRQ_TYPE_LEVEL_HIGH,	1, 1, },
2833eab8095SManuel Lauss 	{ -1, },	/* terminator */
2843eab8095SManuel Lauss };
2853eab8095SManuel Lauss 
2863eab8095SManuel Lauss /******************************************************************************/
287785e3268SManuel Lauss 
au1x_ic0_unmask(struct irq_data * d)288d24c1a26SThomas Gleixner static void au1x_ic0_unmask(struct irq_data *d)
289e8c7c482SRalf Baechle {
290d24c1a26SThomas Gleixner 	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
291dca75871SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
292dca75871SManuel Lauss 
293dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_MASKSET);
294dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_WAKESET);
295dca75871SManuel Lauss 	wmb();
296e8c7c482SRalf Baechle }
297e8c7c482SRalf Baechle 
au1x_ic1_unmask(struct irq_data * d)298d24c1a26SThomas Gleixner static void au1x_ic1_unmask(struct irq_data *d)
299785e3268SManuel Lauss {
300d24c1a26SThomas Gleixner 	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
301dca75871SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
302dca75871SManuel Lauss 
303dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_MASKSET);
304dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_WAKESET);
305dca75871SManuel Lauss 	wmb();
306785e3268SManuel Lauss }
307785e3268SManuel Lauss 
au1x_ic0_mask(struct irq_data * d)308d24c1a26SThomas Gleixner static void au1x_ic0_mask(struct irq_data *d)
309e8c7c482SRalf Baechle {
310d24c1a26SThomas Gleixner 	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
311dca75871SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
312dca75871SManuel Lauss 
313dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_MASKCLR);
314dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_WAKECLR);
315dca75871SManuel Lauss 	wmb();
316e8c7c482SRalf Baechle }
317e8c7c482SRalf Baechle 
au1x_ic1_mask(struct irq_data * d)318d24c1a26SThomas Gleixner static void au1x_ic1_mask(struct irq_data *d)
319e8c7c482SRalf Baechle {
320d24c1a26SThomas Gleixner 	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
321dca75871SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
322dca75871SManuel Lauss 
323dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_MASKCLR);
324dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_WAKECLR);
325dca75871SManuel Lauss 	wmb();
326e8c7c482SRalf Baechle }
327e8c7c482SRalf Baechle 
au1x_ic0_ack(struct irq_data * d)328d24c1a26SThomas Gleixner static void au1x_ic0_ack(struct irq_data *d)
329e8c7c482SRalf Baechle {
330d24c1a26SThomas Gleixner 	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
331dca75871SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
332e8c7c482SRalf Baechle 
333e8c7c482SRalf Baechle 	/*
334e8c7c482SRalf Baechle 	 * This may assume that we don't get interrupts from
335e8c7c482SRalf Baechle 	 * both edges at once, or if we do, that we don't care.
336e8c7c482SRalf Baechle 	 */
337dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_FALLINGCLR);
338dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_RISINGCLR);
339dca75871SManuel Lauss 	wmb();
340e8c7c482SRalf Baechle }
341e8c7c482SRalf Baechle 
au1x_ic1_ack(struct irq_data * d)342d24c1a26SThomas Gleixner static void au1x_ic1_ack(struct irq_data *d)
343e8c7c482SRalf Baechle {
344d24c1a26SThomas Gleixner 	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
345dca75871SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
346785e3268SManuel Lauss 
347785e3268SManuel Lauss 	/*
348785e3268SManuel Lauss 	 * This may assume that we don't get interrupts from
349785e3268SManuel Lauss 	 * both edges at once, or if we do, that we don't care.
350785e3268SManuel Lauss 	 */
351dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_FALLINGCLR);
352dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_RISINGCLR);
353dca75871SManuel Lauss 	wmb();
354e8c7c482SRalf Baechle }
355e8c7c482SRalf Baechle 
au1x_ic0_maskack(struct irq_data * d)356d24c1a26SThomas Gleixner static void au1x_ic0_maskack(struct irq_data *d)
35744f2c586SManuel Lauss {
358d24c1a26SThomas Gleixner 	unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
359dca75871SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
36044f2c586SManuel Lauss 
361dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_WAKECLR);
362dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_MASKCLR);
363dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_RISINGCLR);
364dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_FALLINGCLR);
365dca75871SManuel Lauss 	wmb();
36644f2c586SManuel Lauss }
36744f2c586SManuel Lauss 
au1x_ic1_maskack(struct irq_data * d)368d24c1a26SThomas Gleixner static void au1x_ic1_maskack(struct irq_data *d)
36944f2c586SManuel Lauss {
370d24c1a26SThomas Gleixner 	unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
371dca75871SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
37244f2c586SManuel Lauss 
373dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_WAKECLR);
374dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_MASKCLR);
375dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_RISINGCLR);
376dca75871SManuel Lauss 	__raw_writel(1 << bit, base + IC_FALLINGCLR);
377dca75871SManuel Lauss 	wmb();
37844f2c586SManuel Lauss }
37944f2c586SManuel Lauss 
au1x_ic1_setwake(struct irq_data * d,unsigned int on)380d24c1a26SThomas Gleixner static int au1x_ic1_setwake(struct irq_data *d, unsigned int on)
381e8c7c482SRalf Baechle {
382d24c1a26SThomas Gleixner 	int bit = d->irq - AU1000_INTC1_INT_BASE;
383785e3268SManuel Lauss 	unsigned long wakemsk, flags;
384e8c7c482SRalf Baechle 
38578814465SManuel Lauss 	/* only GPIO 0-7 can act as wakeup source.  Fortunately these
38678814465SManuel Lauss 	 * are wired up identically on all supported variants.
38778814465SManuel Lauss 	 */
38878814465SManuel Lauss 	if ((bit < 0) || (bit > 7))
389785e3268SManuel Lauss 		return -EINVAL;
390e8c7c482SRalf Baechle 
391785e3268SManuel Lauss 	local_irq_save(flags);
3921d09de7dSManuel Lauss 	wakemsk = alchemy_rdsys(AU1000_SYS_WAKEMSK);
393785e3268SManuel Lauss 	if (on)
394785e3268SManuel Lauss 		wakemsk |= 1 << bit;
395e8c7c482SRalf Baechle 	else
396785e3268SManuel Lauss 		wakemsk &= ~(1 << bit);
3971d09de7dSManuel Lauss 	alchemy_wrsys(wakemsk, AU1000_SYS_WAKEMSK);
398785e3268SManuel Lauss 	local_irq_restore(flags);
399785e3268SManuel Lauss 
400785e3268SManuel Lauss 	return 0;
401e8c7c482SRalf Baechle }
402e8c7c482SRalf Baechle 
403e8c7c482SRalf Baechle /*
404785e3268SManuel Lauss  * irq_chips for both ICs; this way the mask handlers can be
405785e3268SManuel Lauss  * as short as possible.
406e8c7c482SRalf Baechle  */
407785e3268SManuel Lauss static struct irq_chip au1x_ic0_chip = {
408785e3268SManuel Lauss 	.name		= "Alchemy-IC0",
409d24c1a26SThomas Gleixner 	.irq_ack	= au1x_ic0_ack,
410d24c1a26SThomas Gleixner 	.irq_mask	= au1x_ic0_mask,
411d24c1a26SThomas Gleixner 	.irq_mask_ack	= au1x_ic0_maskack,
412d24c1a26SThomas Gleixner 	.irq_unmask	= au1x_ic0_unmask,
413d24c1a26SThomas Gleixner 	.irq_set_type	= au1x_ic_settype,
414785e3268SManuel Lauss };
415e8c7c482SRalf Baechle 
416785e3268SManuel Lauss static struct irq_chip au1x_ic1_chip = {
417785e3268SManuel Lauss 	.name		= "Alchemy-IC1",
418d24c1a26SThomas Gleixner 	.irq_ack	= au1x_ic1_ack,
419d24c1a26SThomas Gleixner 	.irq_mask	= au1x_ic1_mask,
420d24c1a26SThomas Gleixner 	.irq_mask_ack	= au1x_ic1_maskack,
421d24c1a26SThomas Gleixner 	.irq_unmask	= au1x_ic1_unmask,
422d24c1a26SThomas Gleixner 	.irq_set_type	= au1x_ic_settype,
423d24c1a26SThomas Gleixner 	.irq_set_wake	= au1x_ic1_setwake,
424785e3268SManuel Lauss };
425785e3268SManuel Lauss 
au1x_ic_settype(struct irq_data * d,unsigned int flow_type)426d24c1a26SThomas Gleixner static int au1x_ic_settype(struct irq_data *d, unsigned int flow_type)
427e8c7c482SRalf Baechle {
428785e3268SManuel Lauss 	struct irq_chip *chip;
429dca75871SManuel Lauss 	unsigned int bit, irq = d->irq;
430d24c1a26SThomas Gleixner 	irq_flow_handler_t handler = NULL;
431d24c1a26SThomas Gleixner 	unsigned char *name = NULL;
432dca75871SManuel Lauss 	void __iomem *base;
433785e3268SManuel Lauss 	int ret;
434e8c7c482SRalf Baechle 
435785e3268SManuel Lauss 	if (irq >= AU1000_INTC1_INT_BASE) {
436785e3268SManuel Lauss 		bit = irq - AU1000_INTC1_INT_BASE;
437785e3268SManuel Lauss 		chip = &au1x_ic1_chip;
438dca75871SManuel Lauss 		base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
439785e3268SManuel Lauss 	} else {
440785e3268SManuel Lauss 		bit = irq - AU1000_INTC0_INT_BASE;
441785e3268SManuel Lauss 		chip = &au1x_ic0_chip;
442dca75871SManuel Lauss 		base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
443785e3268SManuel Lauss 	}
444e8c7c482SRalf Baechle 
445785e3268SManuel Lauss 	if (bit > 31)
446785e3268SManuel Lauss 		return -EINVAL;
447785e3268SManuel Lauss 
448785e3268SManuel Lauss 	ret = 0;
449785e3268SManuel Lauss 
450785e3268SManuel Lauss 	switch (flow_type) {	/* cfgregs 2:1:0 */
451785e3268SManuel Lauss 	case IRQ_TYPE_EDGE_RISING:	/* 0:0:1 */
452dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG2CLR);
453dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG1CLR);
454dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG0SET);
455d24c1a26SThomas Gleixner 		handler = handle_edge_irq;
456d24c1a26SThomas Gleixner 		name = "riseedge";
457785e3268SManuel Lauss 		break;
458785e3268SManuel Lauss 	case IRQ_TYPE_EDGE_FALLING:	/* 0:1:0 */
459dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG2CLR);
460dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG1SET);
461dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG0CLR);
462d24c1a26SThomas Gleixner 		handler = handle_edge_irq;
463d24c1a26SThomas Gleixner 		name = "falledge";
464785e3268SManuel Lauss 		break;
465785e3268SManuel Lauss 	case IRQ_TYPE_EDGE_BOTH:	/* 0:1:1 */
466dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG2CLR);
467dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG1SET);
468dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG0SET);
469d24c1a26SThomas Gleixner 		handler = handle_edge_irq;
470d24c1a26SThomas Gleixner 		name = "bothedge";
471785e3268SManuel Lauss 		break;
472785e3268SManuel Lauss 	case IRQ_TYPE_LEVEL_HIGH:	/* 1:0:1 */
473dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG2SET);
474dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG1CLR);
475dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG0SET);
476d24c1a26SThomas Gleixner 		handler = handle_level_irq;
477d24c1a26SThomas Gleixner 		name = "hilevel";
478785e3268SManuel Lauss 		break;
479785e3268SManuel Lauss 	case IRQ_TYPE_LEVEL_LOW:	/* 1:1:0 */
480dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG2SET);
481dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG1SET);
482dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG0CLR);
483d24c1a26SThomas Gleixner 		handler = handle_level_irq;
484d24c1a26SThomas Gleixner 		name = "lowlevel";
485785e3268SManuel Lauss 		break;
486785e3268SManuel Lauss 	case IRQ_TYPE_NONE:		/* 0:0:0 */
487dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG2CLR);
488dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG1CLR);
489dca75871SManuel Lauss 		__raw_writel(1 << bit, base + IC_CFG0CLR);
490785e3268SManuel Lauss 		break;
491785e3268SManuel Lauss 	default:
492785e3268SManuel Lauss 		ret = -EINVAL;
493785e3268SManuel Lauss 	}
4945a065450SThomas Gleixner 	irq_set_chip_handler_name_locked(d, chip, handler, name);
495d24c1a26SThomas Gleixner 
496dca75871SManuel Lauss 	wmb();
497785e3268SManuel Lauss 
498785e3268SManuel Lauss 	return ret;
499785e3268SManuel Lauss }
500785e3268SManuel Lauss 
5013eab8095SManuel Lauss /******************************************************************************/
5023eab8095SManuel Lauss 
5033eab8095SManuel Lauss /*
5043eab8095SManuel Lauss  * au1300_gpic_chgcfg - change PIN configuration.
5053eab8095SManuel Lauss  * @gpio:	pin to change (0-based GPIO number from datasheet).
5063eab8095SManuel Lauss  * @clr:	clear all bits set in 'clr'.
5073eab8095SManuel Lauss  * @set:	set these bits.
5083eab8095SManuel Lauss  *
5093eab8095SManuel Lauss  * modifies a pins' configuration register, bits set in @clr will
5103eab8095SManuel Lauss  * be cleared in the register, bits in @set will be set.
5113eab8095SManuel Lauss  */
au1300_gpic_chgcfg(unsigned int gpio,unsigned long clr,unsigned long set)5123eab8095SManuel Lauss static inline void au1300_gpic_chgcfg(unsigned int gpio,
5133eab8095SManuel Lauss 				      unsigned long clr,
5143eab8095SManuel Lauss 				      unsigned long set)
5153eab8095SManuel Lauss {
5163eab8095SManuel Lauss 	void __iomem *r = AU1300_GPIC_ADDR;
5173eab8095SManuel Lauss 	unsigned long l;
5183eab8095SManuel Lauss 
5193eab8095SManuel Lauss 	r += gpio * 4;	/* offset into pin config array */
5203eab8095SManuel Lauss 	l = __raw_readl(r + AU1300_GPIC_PINCFG);
5213eab8095SManuel Lauss 	l &= ~clr;
5223eab8095SManuel Lauss 	l |= set;
5233eab8095SManuel Lauss 	__raw_writel(l, r + AU1300_GPIC_PINCFG);
5243eab8095SManuel Lauss 	wmb();
5253eab8095SManuel Lauss }
5263eab8095SManuel Lauss 
5273eab8095SManuel Lauss /*
5283eab8095SManuel Lauss  * au1300_pinfunc_to_gpio - assign a pin as GPIO input (GPIO ctrl).
5293eab8095SManuel Lauss  * @pin:	pin (0-based GPIO number from datasheet).
5303eab8095SManuel Lauss  *
5313eab8095SManuel Lauss  * Assigns a GPIO pin to the GPIO controller, so its level can either
5323eab8095SManuel Lauss  * be read or set through the generic GPIO functions.
5333eab8095SManuel Lauss  * If you need a GPOUT, use au1300_gpio_set_value(pin, 0/1).
5343eab8095SManuel Lauss  * REVISIT: is this function really necessary?
5353eab8095SManuel Lauss  */
au1300_pinfunc_to_gpio(enum au1300_multifunc_pins gpio)5363eab8095SManuel Lauss void au1300_pinfunc_to_gpio(enum au1300_multifunc_pins gpio)
5373eab8095SManuel Lauss {
5383eab8095SManuel Lauss 	au1300_gpio_direction_input(gpio + AU1300_GPIO_BASE);
5393eab8095SManuel Lauss }
5403eab8095SManuel Lauss EXPORT_SYMBOL_GPL(au1300_pinfunc_to_gpio);
5413eab8095SManuel Lauss 
5423eab8095SManuel Lauss /*
5433eab8095SManuel Lauss  * au1300_pinfunc_to_dev - assign a pin to the device function.
5443eab8095SManuel Lauss  * @pin:	pin (0-based GPIO number from datasheet).
5453eab8095SManuel Lauss  *
5463eab8095SManuel Lauss  * Assigns a GPIO pin to its associated device function; the pin will be
5473eab8095SManuel Lauss  * driven by the device and not through GPIO functions.
5483eab8095SManuel Lauss  */
au1300_pinfunc_to_dev(enum au1300_multifunc_pins gpio)5493eab8095SManuel Lauss void au1300_pinfunc_to_dev(enum au1300_multifunc_pins gpio)
5503eab8095SManuel Lauss {
5513eab8095SManuel Lauss 	void __iomem *r = AU1300_GPIC_ADDR;
5523eab8095SManuel Lauss 	unsigned long bit;
5533eab8095SManuel Lauss 
5543eab8095SManuel Lauss 	r += GPIC_GPIO_BANKOFF(gpio);
5553eab8095SManuel Lauss 	bit = GPIC_GPIO_TO_BIT(gpio);
5563eab8095SManuel Lauss 	__raw_writel(bit, r + AU1300_GPIC_DEVSEL);
5573eab8095SManuel Lauss 	wmb();
5583eab8095SManuel Lauss }
5593eab8095SManuel Lauss EXPORT_SYMBOL_GPL(au1300_pinfunc_to_dev);
5603eab8095SManuel Lauss 
5613eab8095SManuel Lauss /*
5623eab8095SManuel Lauss  * au1300_set_irq_priority -  set internal priority of IRQ.
5633eab8095SManuel Lauss  * @irq:	irq to set priority (linux irq number).
5643eab8095SManuel Lauss  * @p:		priority (0 = highest, 3 = lowest).
5653eab8095SManuel Lauss  */
au1300_set_irq_priority(unsigned int irq,int p)5663eab8095SManuel Lauss void au1300_set_irq_priority(unsigned int irq, int p)
5673eab8095SManuel Lauss {
5683eab8095SManuel Lauss 	irq -= ALCHEMY_GPIC_INT_BASE;
5693eab8095SManuel Lauss 	au1300_gpic_chgcfg(irq, GPIC_CFG_IL_MASK, GPIC_CFG_IL_SET(p));
5703eab8095SManuel Lauss }
5713eab8095SManuel Lauss EXPORT_SYMBOL_GPL(au1300_set_irq_priority);
5723eab8095SManuel Lauss 
5733eab8095SManuel Lauss /*
5743eab8095SManuel Lauss  * au1300_set_dbdma_gpio - assign a gpio to one of the DBDMA triggers.
5753eab8095SManuel Lauss  * @dchan:	dbdma trigger select (0, 1).
5763eab8095SManuel Lauss  * @gpio:	pin to assign as trigger.
5773eab8095SManuel Lauss  *
5783eab8095SManuel Lauss  * DBDMA controller has 2 external trigger sources; this function
5793eab8095SManuel Lauss  * assigns a GPIO to the selected trigger.
5803eab8095SManuel Lauss  */
au1300_set_dbdma_gpio(int dchan,unsigned int gpio)5813eab8095SManuel Lauss void au1300_set_dbdma_gpio(int dchan, unsigned int gpio)
5823eab8095SManuel Lauss {
5833eab8095SManuel Lauss 	unsigned long r;
5843eab8095SManuel Lauss 
5853eab8095SManuel Lauss 	if ((dchan >= 0) && (dchan <= 1)) {
5863eab8095SManuel Lauss 		r = __raw_readl(AU1300_GPIC_ADDR + AU1300_GPIC_DMASEL);
5873eab8095SManuel Lauss 		r &= ~(0xff << (8 * dchan));
5883eab8095SManuel Lauss 		r |= (gpio & 0x7f) << (8 * dchan);
5893eab8095SManuel Lauss 		__raw_writel(r, AU1300_GPIC_ADDR + AU1300_GPIC_DMASEL);
5903eab8095SManuel Lauss 		wmb();
5913eab8095SManuel Lauss 	}
5923eab8095SManuel Lauss }
5933eab8095SManuel Lauss 
gpic_pin_set_idlewake(unsigned int gpio,int allow)5943eab8095SManuel Lauss static inline void gpic_pin_set_idlewake(unsigned int gpio, int allow)
5953eab8095SManuel Lauss {
5963eab8095SManuel Lauss 	au1300_gpic_chgcfg(gpio, GPIC_CFG_IDLEWAKE,
5973eab8095SManuel Lauss 			   allow ? GPIC_CFG_IDLEWAKE : 0);
5983eab8095SManuel Lauss }
5993eab8095SManuel Lauss 
au1300_gpic_mask(struct irq_data * d)6003eab8095SManuel Lauss static void au1300_gpic_mask(struct irq_data *d)
6013eab8095SManuel Lauss {
6023eab8095SManuel Lauss 	void __iomem *r = AU1300_GPIC_ADDR;
6033eab8095SManuel Lauss 	unsigned long bit, irq = d->irq;
6043eab8095SManuel Lauss 
6053eab8095SManuel Lauss 	irq -= ALCHEMY_GPIC_INT_BASE;
6063eab8095SManuel Lauss 	r += GPIC_GPIO_BANKOFF(irq);
6073eab8095SManuel Lauss 	bit = GPIC_GPIO_TO_BIT(irq);
6083eab8095SManuel Lauss 	__raw_writel(bit, r + AU1300_GPIC_IDIS);
6093eab8095SManuel Lauss 	wmb();
6103eab8095SManuel Lauss 
6113eab8095SManuel Lauss 	gpic_pin_set_idlewake(irq, 0);
6123eab8095SManuel Lauss }
6133eab8095SManuel Lauss 
au1300_gpic_unmask(struct irq_data * d)6143eab8095SManuel Lauss static void au1300_gpic_unmask(struct irq_data *d)
6153eab8095SManuel Lauss {
6163eab8095SManuel Lauss 	void __iomem *r = AU1300_GPIC_ADDR;
6173eab8095SManuel Lauss 	unsigned long bit, irq = d->irq;
6183eab8095SManuel Lauss 
6193eab8095SManuel Lauss 	irq -= ALCHEMY_GPIC_INT_BASE;
6203eab8095SManuel Lauss 
6213eab8095SManuel Lauss 	gpic_pin_set_idlewake(irq, 1);
6223eab8095SManuel Lauss 
6233eab8095SManuel Lauss 	r += GPIC_GPIO_BANKOFF(irq);
6243eab8095SManuel Lauss 	bit = GPIC_GPIO_TO_BIT(irq);
6253eab8095SManuel Lauss 	__raw_writel(bit, r + AU1300_GPIC_IEN);
6263eab8095SManuel Lauss 	wmb();
6273eab8095SManuel Lauss }
6283eab8095SManuel Lauss 
au1300_gpic_maskack(struct irq_data * d)6293eab8095SManuel Lauss static void au1300_gpic_maskack(struct irq_data *d)
6303eab8095SManuel Lauss {
6313eab8095SManuel Lauss 	void __iomem *r = AU1300_GPIC_ADDR;
6323eab8095SManuel Lauss 	unsigned long bit, irq = d->irq;
6333eab8095SManuel Lauss 
6343eab8095SManuel Lauss 	irq -= ALCHEMY_GPIC_INT_BASE;
6353eab8095SManuel Lauss 	r += GPIC_GPIO_BANKOFF(irq);
6363eab8095SManuel Lauss 	bit = GPIC_GPIO_TO_BIT(irq);
6373eab8095SManuel Lauss 	__raw_writel(bit, r + AU1300_GPIC_IPEND);	/* ack */
6383eab8095SManuel Lauss 	__raw_writel(bit, r + AU1300_GPIC_IDIS);	/* mask */
6393eab8095SManuel Lauss 	wmb();
6403eab8095SManuel Lauss 
6413eab8095SManuel Lauss 	gpic_pin_set_idlewake(irq, 0);
6423eab8095SManuel Lauss }
6433eab8095SManuel Lauss 
au1300_gpic_ack(struct irq_data * d)6443eab8095SManuel Lauss static void au1300_gpic_ack(struct irq_data *d)
6453eab8095SManuel Lauss {
6463eab8095SManuel Lauss 	void __iomem *r = AU1300_GPIC_ADDR;
6473eab8095SManuel Lauss 	unsigned long bit, irq = d->irq;
6483eab8095SManuel Lauss 
6493eab8095SManuel Lauss 	irq -= ALCHEMY_GPIC_INT_BASE;
6503eab8095SManuel Lauss 	r += GPIC_GPIO_BANKOFF(irq);
6513eab8095SManuel Lauss 	bit = GPIC_GPIO_TO_BIT(irq);
6523eab8095SManuel Lauss 	__raw_writel(bit, r + AU1300_GPIC_IPEND);	/* ack */
6533eab8095SManuel Lauss 	wmb();
6543eab8095SManuel Lauss }
6553eab8095SManuel Lauss 
6563eab8095SManuel Lauss static struct irq_chip au1300_gpic = {
6573eab8095SManuel Lauss 	.name		= "GPIOINT",
6583eab8095SManuel Lauss 	.irq_ack	= au1300_gpic_ack,
6593eab8095SManuel Lauss 	.irq_mask	= au1300_gpic_mask,
6603eab8095SManuel Lauss 	.irq_mask_ack	= au1300_gpic_maskack,
6613eab8095SManuel Lauss 	.irq_unmask	= au1300_gpic_unmask,
6623eab8095SManuel Lauss 	.irq_set_type	= au1300_gpic_settype,
6633eab8095SManuel Lauss };
6643eab8095SManuel Lauss 
au1300_gpic_settype(struct irq_data * d,unsigned int type)6653eab8095SManuel Lauss static int au1300_gpic_settype(struct irq_data *d, unsigned int type)
6663eab8095SManuel Lauss {
6673eab8095SManuel Lauss 	unsigned long s;
6683eab8095SManuel Lauss 	unsigned char *name = NULL;
6693eab8095SManuel Lauss 	irq_flow_handler_t hdl = NULL;
6703eab8095SManuel Lauss 
6713eab8095SManuel Lauss 	switch (type) {
6723eab8095SManuel Lauss 	case IRQ_TYPE_LEVEL_HIGH:
6733eab8095SManuel Lauss 		s = GPIC_CFG_IC_LEVEL_HIGH;
6743eab8095SManuel Lauss 		name = "high";
6753eab8095SManuel Lauss 		hdl = handle_level_irq;
6763eab8095SManuel Lauss 		break;
6773eab8095SManuel Lauss 	case IRQ_TYPE_LEVEL_LOW:
6783eab8095SManuel Lauss 		s = GPIC_CFG_IC_LEVEL_LOW;
6793eab8095SManuel Lauss 		name = "low";
6803eab8095SManuel Lauss 		hdl = handle_level_irq;
6813eab8095SManuel Lauss 		break;
6823eab8095SManuel Lauss 	case IRQ_TYPE_EDGE_RISING:
6833eab8095SManuel Lauss 		s = GPIC_CFG_IC_EDGE_RISE;
6843eab8095SManuel Lauss 		name = "posedge";
6853eab8095SManuel Lauss 		hdl = handle_edge_irq;
6863eab8095SManuel Lauss 		break;
6873eab8095SManuel Lauss 	case IRQ_TYPE_EDGE_FALLING:
6883eab8095SManuel Lauss 		s = GPIC_CFG_IC_EDGE_FALL;
6893eab8095SManuel Lauss 		name = "negedge";
6903eab8095SManuel Lauss 		hdl = handle_edge_irq;
6913eab8095SManuel Lauss 		break;
6923eab8095SManuel Lauss 	case IRQ_TYPE_EDGE_BOTH:
6933eab8095SManuel Lauss 		s = GPIC_CFG_IC_EDGE_BOTH;
6943eab8095SManuel Lauss 		name = "bothedge";
6953eab8095SManuel Lauss 		hdl = handle_edge_irq;
6963eab8095SManuel Lauss 		break;
6973eab8095SManuel Lauss 	case IRQ_TYPE_NONE:
6983eab8095SManuel Lauss 		s = GPIC_CFG_IC_OFF;
6993eab8095SManuel Lauss 		name = "disabled";
7003eab8095SManuel Lauss 		hdl = handle_level_irq;
7013eab8095SManuel Lauss 		break;
7023eab8095SManuel Lauss 	default:
7033eab8095SManuel Lauss 		return -EINVAL;
7043eab8095SManuel Lauss 	}
7053eab8095SManuel Lauss 
7065a065450SThomas Gleixner 	irq_set_chip_handler_name_locked(d, &au1300_gpic, hdl, name);
7073eab8095SManuel Lauss 
7083eab8095SManuel Lauss 	au1300_gpic_chgcfg(d->irq - ALCHEMY_GPIC_INT_BASE, GPIC_CFG_IC_MASK, s);
7093eab8095SManuel Lauss 
7103eab8095SManuel Lauss 	return 0;
7113eab8095SManuel Lauss }
7123eab8095SManuel Lauss 
7133eab8095SManuel Lauss /******************************************************************************/
7143eab8095SManuel Lauss 
ic_init(void __iomem * base)715dca75871SManuel Lauss static inline void ic_init(void __iomem *base)
716dca75871SManuel Lauss {
717dca75871SManuel Lauss 	/* initialize interrupt controller to a safe state */
718dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_CFG0CLR);
719dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_CFG1CLR);
720dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_CFG2CLR);
721dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_MASKCLR);
722dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_ASSIGNCLR);
723dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_WAKECLR);
724dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_SRCSET);
725dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_FALLINGCLR);
726dca75871SManuel Lauss 	__raw_writel(0xffffffff, base + IC_RISINGCLR);
727dca75871SManuel Lauss 	__raw_writel(0x00000000, base + IC_TESTBIT);
728dca75871SManuel Lauss 	wmb();
729dca75871SManuel Lauss }
730dca75871SManuel Lauss 
7313eab8095SManuel Lauss static unsigned long alchemy_gpic_pmdata[ALCHEMY_GPIC_INT_NUM + 6];
732f267c882SManuel Lauss 
alchemy_ic_suspend_one(void __iomem * base,unsigned long * d)733f267c882SManuel Lauss static inline void alchemy_ic_suspend_one(void __iomem *base, unsigned long *d)
734f267c882SManuel Lauss {
735f267c882SManuel Lauss 	d[0] = __raw_readl(base + IC_CFG0RD);
736f267c882SManuel Lauss 	d[1] = __raw_readl(base + IC_CFG1RD);
737f267c882SManuel Lauss 	d[2] = __raw_readl(base + IC_CFG2RD);
738f267c882SManuel Lauss 	d[3] = __raw_readl(base + IC_SRCRD);
739f267c882SManuel Lauss 	d[4] = __raw_readl(base + IC_ASSIGNRD);
740f267c882SManuel Lauss 	d[5] = __raw_readl(base + IC_WAKERD);
741f267c882SManuel Lauss 	d[6] = __raw_readl(base + IC_MASKRD);
742f267c882SManuel Lauss 	ic_init(base);		/* shut it up too while at it */
743f267c882SManuel Lauss }
744f267c882SManuel Lauss 
alchemy_ic_resume_one(void __iomem * base,unsigned long * d)745f267c882SManuel Lauss static inline void alchemy_ic_resume_one(void __iomem *base, unsigned long *d)
746f267c882SManuel Lauss {
747f267c882SManuel Lauss 	ic_init(base);
748f267c882SManuel Lauss 
749f267c882SManuel Lauss 	__raw_writel(d[0], base + IC_CFG0SET);
750f267c882SManuel Lauss 	__raw_writel(d[1], base + IC_CFG1SET);
751f267c882SManuel Lauss 	__raw_writel(d[2], base + IC_CFG2SET);
752f267c882SManuel Lauss 	__raw_writel(d[3], base + IC_SRCSET);
753f267c882SManuel Lauss 	__raw_writel(d[4], base + IC_ASSIGNSET);
754f267c882SManuel Lauss 	__raw_writel(d[5], base + IC_WAKESET);
755f267c882SManuel Lauss 	wmb();
756f267c882SManuel Lauss 
757f267c882SManuel Lauss 	__raw_writel(d[6], base + IC_MASKSET);
758f267c882SManuel Lauss 	wmb();
759f267c882SManuel Lauss }
760f267c882SManuel Lauss 
alchemy_ic_suspend(void)761f267c882SManuel Lauss static int alchemy_ic_suspend(void)
762f267c882SManuel Lauss {
763f267c882SManuel Lauss 	alchemy_ic_suspend_one((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR),
7643eab8095SManuel Lauss 			       alchemy_gpic_pmdata);
765f267c882SManuel Lauss 	alchemy_ic_suspend_one((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR),
7663eab8095SManuel Lauss 			       &alchemy_gpic_pmdata[7]);
767f267c882SManuel Lauss 	return 0;
768f267c882SManuel Lauss }
769f267c882SManuel Lauss 
alchemy_ic_resume(void)770f267c882SManuel Lauss static void alchemy_ic_resume(void)
771f267c882SManuel Lauss {
772f267c882SManuel Lauss 	alchemy_ic_resume_one((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR),
7733eab8095SManuel Lauss 			      &alchemy_gpic_pmdata[7]);
774f267c882SManuel Lauss 	alchemy_ic_resume_one((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR),
7753eab8095SManuel Lauss 			      alchemy_gpic_pmdata);
776f267c882SManuel Lauss }
777f267c882SManuel Lauss 
alchemy_gpic_suspend(void)7783eab8095SManuel Lauss static int alchemy_gpic_suspend(void)
7793eab8095SManuel Lauss {
7803eab8095SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
7813eab8095SManuel Lauss 	int i;
7823eab8095SManuel Lauss 
7833eab8095SManuel Lauss 	/* save 4 interrupt mask status registers */
7843eab8095SManuel Lauss 	alchemy_gpic_pmdata[0] = __raw_readl(base + AU1300_GPIC_IEN + 0x0);
7853eab8095SManuel Lauss 	alchemy_gpic_pmdata[1] = __raw_readl(base + AU1300_GPIC_IEN + 0x4);
7863eab8095SManuel Lauss 	alchemy_gpic_pmdata[2] = __raw_readl(base + AU1300_GPIC_IEN + 0x8);
7873eab8095SManuel Lauss 	alchemy_gpic_pmdata[3] = __raw_readl(base + AU1300_GPIC_IEN + 0xc);
7883eab8095SManuel Lauss 
7893eab8095SManuel Lauss 	/* save misc register(s) */
7903eab8095SManuel Lauss 	alchemy_gpic_pmdata[4] = __raw_readl(base + AU1300_GPIC_DMASEL);
7913eab8095SManuel Lauss 
7923eab8095SManuel Lauss 	/* molto silenzioso */
7933eab8095SManuel Lauss 	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x0);
7943eab8095SManuel Lauss 	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x4);
7953eab8095SManuel Lauss 	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x8);
7963eab8095SManuel Lauss 	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0xc);
7973eab8095SManuel Lauss 	wmb();
7983eab8095SManuel Lauss 
7993eab8095SManuel Lauss 	/* save pin/int-type configuration */
8003eab8095SManuel Lauss 	base += AU1300_GPIC_PINCFG;
8013eab8095SManuel Lauss 	for (i = 0; i < ALCHEMY_GPIC_INT_NUM; i++)
8023eab8095SManuel Lauss 		alchemy_gpic_pmdata[i + 5] = __raw_readl(base + (i << 2));
8033eab8095SManuel Lauss 
8043eab8095SManuel Lauss 	wmb();
8053eab8095SManuel Lauss 
8063eab8095SManuel Lauss 	return 0;
8073eab8095SManuel Lauss }
8083eab8095SManuel Lauss 
alchemy_gpic_resume(void)8093eab8095SManuel Lauss static void alchemy_gpic_resume(void)
8103eab8095SManuel Lauss {
8113eab8095SManuel Lauss 	void __iomem *base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
8123eab8095SManuel Lauss 	int i;
8133eab8095SManuel Lauss 
8143eab8095SManuel Lauss 	/* disable all first */
8153eab8095SManuel Lauss 	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x0);
8163eab8095SManuel Lauss 	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x4);
8173eab8095SManuel Lauss 	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x8);
8183eab8095SManuel Lauss 	__raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0xc);
8193eab8095SManuel Lauss 	wmb();
8203eab8095SManuel Lauss 
8213eab8095SManuel Lauss 	/* restore pin/int-type configurations */
8223eab8095SManuel Lauss 	base += AU1300_GPIC_PINCFG;
8233eab8095SManuel Lauss 	for (i = 0; i < ALCHEMY_GPIC_INT_NUM; i++)
8243eab8095SManuel Lauss 		__raw_writel(alchemy_gpic_pmdata[i + 5], base + (i << 2));
8253eab8095SManuel Lauss 	wmb();
8263eab8095SManuel Lauss 
8273eab8095SManuel Lauss 	/* restore misc register(s) */
8283eab8095SManuel Lauss 	base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
8293eab8095SManuel Lauss 	__raw_writel(alchemy_gpic_pmdata[4], base + AU1300_GPIC_DMASEL);
8303eab8095SManuel Lauss 	wmb();
8313eab8095SManuel Lauss 
8323eab8095SManuel Lauss 	/* finally restore masks */
8333eab8095SManuel Lauss 	__raw_writel(alchemy_gpic_pmdata[0], base + AU1300_GPIC_IEN + 0x0);
8343eab8095SManuel Lauss 	__raw_writel(alchemy_gpic_pmdata[1], base + AU1300_GPIC_IEN + 0x4);
8353eab8095SManuel Lauss 	__raw_writel(alchemy_gpic_pmdata[2], base + AU1300_GPIC_IEN + 0x8);
8363eab8095SManuel Lauss 	__raw_writel(alchemy_gpic_pmdata[3], base + AU1300_GPIC_IEN + 0xc);
8373eab8095SManuel Lauss 	wmb();
8383eab8095SManuel Lauss }
8393eab8095SManuel Lauss 
8403eab8095SManuel Lauss static struct syscore_ops alchemy_ic_pmops = {
841f267c882SManuel Lauss 	.suspend	= alchemy_ic_suspend,
842f267c882SManuel Lauss 	.resume		= alchemy_ic_resume,
843f267c882SManuel Lauss };
844f267c882SManuel Lauss 
8453eab8095SManuel Lauss static struct syscore_ops alchemy_gpic_pmops = {
8463eab8095SManuel Lauss 	.suspend	= alchemy_gpic_suspend,
8473eab8095SManuel Lauss 	.resume		= alchemy_gpic_resume,
8483eab8095SManuel Lauss };
8493eab8095SManuel Lauss 
8503eab8095SManuel Lauss /******************************************************************************/
8513eab8095SManuel Lauss 
852894cc87eSManuel Lauss /* create chained handlers for the 4 IC requests to the MIPS IRQ ctrl */
853894cc87eSManuel Lauss #define DISP(name, base, addr)						      \
854*bd0b9ac4SThomas Gleixner static void au1000_##name##_dispatch(struct irq_desc *d)		      \
855894cc87eSManuel Lauss {									      \
856894cc87eSManuel Lauss 	unsigned long r = __raw_readl((void __iomem *)KSEG1ADDR(addr));	      \
857894cc87eSManuel Lauss 	if (likely(r))							      \
858894cc87eSManuel Lauss 		generic_handle_irq(base + __ffs(r));			      \
859894cc87eSManuel Lauss 	else								      \
860894cc87eSManuel Lauss 		spurious_interrupt();					      \
861894cc87eSManuel Lauss }
862894cc87eSManuel Lauss 
863894cc87eSManuel Lauss DISP(ic0r0, AU1000_INTC0_INT_BASE, AU1000_IC0_PHYS_ADDR + IC_REQ0INT)
864894cc87eSManuel Lauss DISP(ic0r1, AU1000_INTC0_INT_BASE, AU1000_IC0_PHYS_ADDR + IC_REQ1INT)
865894cc87eSManuel Lauss DISP(ic1r0, AU1000_INTC1_INT_BASE, AU1000_IC1_PHYS_ADDR + IC_REQ0INT)
866894cc87eSManuel Lauss DISP(ic1r1, AU1000_INTC1_INT_BASE, AU1000_IC1_PHYS_ADDR + IC_REQ1INT)
867894cc87eSManuel Lauss 
alchemy_gpic_dispatch(struct irq_desc * d)868*bd0b9ac4SThomas Gleixner static void alchemy_gpic_dispatch(struct irq_desc *d)
8693eab8095SManuel Lauss {
8703eab8095SManuel Lauss 	int i = __raw_readl(AU1300_GPIC_ADDR + AU1300_GPIC_PRIENC);
8713eab8095SManuel Lauss 	generic_handle_irq(ALCHEMY_GPIC_INT_BASE + i);
8723eab8095SManuel Lauss }
8733eab8095SManuel Lauss 
8743eab8095SManuel Lauss /******************************************************************************/
8753eab8095SManuel Lauss 
au1000_init_irq(struct alchemy_irqmap * map)8763eab8095SManuel Lauss static void __init au1000_init_irq(struct alchemy_irqmap *map)
877e8c7c482SRalf Baechle {
878785e3268SManuel Lauss 	unsigned int bit, irq_nr;
879dca75871SManuel Lauss 	void __iomem *base;
880e8c7c482SRalf Baechle 
881dca75871SManuel Lauss 	ic_init((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR));
882dca75871SManuel Lauss 	ic_init((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR));
8833eab8095SManuel Lauss 	register_syscore_ops(&alchemy_ic_pmops);
884e8c7c482SRalf Baechle 	mips_cpu_irq_init();
885e8c7c482SRalf Baechle 
886785e3268SManuel Lauss 	/* register all 64 possible IC0+IC1 irq sources as type "none".
887785e3268SManuel Lauss 	 * Use set_irq_type() to set edge/level behaviour at runtime.
888785e3268SManuel Lauss 	 */
889dca75871SManuel Lauss 	for (irq_nr = AU1000_INTC0_INT_BASE;
890dca75871SManuel Lauss 	     (irq_nr < AU1000_INTC0_INT_BASE + 32); irq_nr++)
891dca75871SManuel Lauss 		au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE);
892785e3268SManuel Lauss 
893dca75871SManuel Lauss 	for (irq_nr = AU1000_INTC1_INT_BASE;
894dca75871SManuel Lauss 	     (irq_nr < AU1000_INTC1_INT_BASE + 32); irq_nr++)
895dca75871SManuel Lauss 		au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE);
896785e3268SManuel Lauss 
897e8c7c482SRalf Baechle 	/*
898e8c7c482SRalf Baechle 	 * Initialize IC0, which is fixed per processor.
899e8c7c482SRalf Baechle 	 */
9003eab8095SManuel Lauss 	while (map->irq != -1) {
9013eab8095SManuel Lauss 		irq_nr = map->irq;
902ef6c1fd6SManuel Lauss 
903ef6c1fd6SManuel Lauss 		if (irq_nr >= AU1000_INTC1_INT_BASE) {
904ef6c1fd6SManuel Lauss 			bit = irq_nr - AU1000_INTC1_INT_BASE;
905dca75871SManuel Lauss 			base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
906ef6c1fd6SManuel Lauss 		} else {
907ef6c1fd6SManuel Lauss 			bit = irq_nr - AU1000_INTC0_INT_BASE;
908dca75871SManuel Lauss 			base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
909ef6c1fd6SManuel Lauss 		}
9103eab8095SManuel Lauss 		if (map->prio == 0)
911dca75871SManuel Lauss 			__raw_writel(1 << bit, base + IC_ASSIGNSET);
912ef6c1fd6SManuel Lauss 
9133eab8095SManuel Lauss 		au1x_ic_settype(irq_get_irq_data(irq_nr), map->type);
914ef6c1fd6SManuel Lauss 		++map;
915ef6c1fd6SManuel Lauss 	}
916785e3268SManuel Lauss 
917894cc87eSManuel Lauss 	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 2, au1000_ic0r0_dispatch);
918894cc87eSManuel Lauss 	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 3, au1000_ic0r1_dispatch);
919894cc87eSManuel Lauss 	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 4, au1000_ic1r0_dispatch);
920894cc87eSManuel Lauss 	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 5, au1000_ic1r1_dispatch);
921785e3268SManuel Lauss }
922ef6c1fd6SManuel Lauss 
alchemy_gpic_init_irq(const struct alchemy_irqmap * dints)9233eab8095SManuel Lauss static void __init alchemy_gpic_init_irq(const struct alchemy_irqmap *dints)
9243eab8095SManuel Lauss {
9253eab8095SManuel Lauss 	int i;
9263eab8095SManuel Lauss 	void __iomem *bank_base;
9273eab8095SManuel Lauss 
9283eab8095SManuel Lauss 	register_syscore_ops(&alchemy_gpic_pmops);
9293eab8095SManuel Lauss 	mips_cpu_irq_init();
9303eab8095SManuel Lauss 
9313eab8095SManuel Lauss 	/* disable & ack all possible interrupt sources */
9323eab8095SManuel Lauss 	for (i = 0; i < 4; i++) {
9333eab8095SManuel Lauss 		bank_base = AU1300_GPIC_ADDR + (i * 4);
9343eab8095SManuel Lauss 		__raw_writel(~0UL, bank_base + AU1300_GPIC_IDIS);
9353eab8095SManuel Lauss 		wmb();
9363eab8095SManuel Lauss 		__raw_writel(~0UL, bank_base + AU1300_GPIC_IPEND);
9373eab8095SManuel Lauss 		wmb();
9383eab8095SManuel Lauss 	}
9393eab8095SManuel Lauss 
9403eab8095SManuel Lauss 	/* register an irq_chip for them, with 2nd highest priority */
9413eab8095SManuel Lauss 	for (i = ALCHEMY_GPIC_INT_BASE; i <= ALCHEMY_GPIC_INT_LAST; i++) {
9423eab8095SManuel Lauss 		au1300_set_irq_priority(i, 1);
9433eab8095SManuel Lauss 		au1300_gpic_settype(irq_get_irq_data(i), IRQ_TYPE_NONE);
9443eab8095SManuel Lauss 	}
9453eab8095SManuel Lauss 
9463eab8095SManuel Lauss 	/* setup known on-chip sources */
9473eab8095SManuel Lauss 	while ((i = dints->irq) != -1) {
9483eab8095SManuel Lauss 		au1300_gpic_settype(irq_get_irq_data(i), dints->type);
9493eab8095SManuel Lauss 		au1300_set_irq_priority(i, dints->prio);
9503eab8095SManuel Lauss 
9513eab8095SManuel Lauss 		if (dints->internal)
9523eab8095SManuel Lauss 			au1300_pinfunc_to_dev(i - ALCHEMY_GPIC_INT_BASE);
9533eab8095SManuel Lauss 
9543eab8095SManuel Lauss 		dints++;
9553eab8095SManuel Lauss 	}
9563eab8095SManuel Lauss 
9573eab8095SManuel Lauss 	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 2, alchemy_gpic_dispatch);
9583eab8095SManuel Lauss 	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 3, alchemy_gpic_dispatch);
9593eab8095SManuel Lauss 	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 4, alchemy_gpic_dispatch);
9603eab8095SManuel Lauss 	irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 5, alchemy_gpic_dispatch);
9613eab8095SManuel Lauss }
9623eab8095SManuel Lauss 
9633eab8095SManuel Lauss /******************************************************************************/
9643eab8095SManuel Lauss 
arch_init_irq(void)965ef6c1fd6SManuel Lauss void __init arch_init_irq(void)
966ef6c1fd6SManuel Lauss {
967ef6c1fd6SManuel Lauss 	switch (alchemy_get_cputype()) {
968ef6c1fd6SManuel Lauss 	case ALCHEMY_CPU_AU1000:
969ef6c1fd6SManuel Lauss 		au1000_init_irq(au1000_irqmap);
970ef6c1fd6SManuel Lauss 		break;
971ef6c1fd6SManuel Lauss 	case ALCHEMY_CPU_AU1500:
972ef6c1fd6SManuel Lauss 		au1000_init_irq(au1500_irqmap);
973ef6c1fd6SManuel Lauss 		break;
974ef6c1fd6SManuel Lauss 	case ALCHEMY_CPU_AU1100:
975ef6c1fd6SManuel Lauss 		au1000_init_irq(au1100_irqmap);
976ef6c1fd6SManuel Lauss 		break;
977ef6c1fd6SManuel Lauss 	case ALCHEMY_CPU_AU1550:
978ef6c1fd6SManuel Lauss 		au1000_init_irq(au1550_irqmap);
979ef6c1fd6SManuel Lauss 		break;
980ef6c1fd6SManuel Lauss 	case ALCHEMY_CPU_AU1200:
981ef6c1fd6SManuel Lauss 		au1000_init_irq(au1200_irqmap);
982ef6c1fd6SManuel Lauss 		break;
9833eab8095SManuel Lauss 	case ALCHEMY_CPU_AU1300:
9843eab8095SManuel Lauss 		alchemy_gpic_init_irq(au1300_irqmap);
9853eab8095SManuel Lauss 		break;
9863eab8095SManuel Lauss 	default:
9873eab8095SManuel Lauss 		pr_err("unknown Alchemy IRQ core\n");
9883eab8095SManuel Lauss 		break;
989ef6c1fd6SManuel Lauss 	}
990ef6c1fd6SManuel Lauss }
991894cc87eSManuel Lauss 
plat_irq_dispatch(void)992894cc87eSManuel Lauss asmlinkage void plat_irq_dispatch(void)
993894cc87eSManuel Lauss {
994894cc87eSManuel Lauss 	unsigned long r = (read_c0_status() & read_c0_cause()) >> 8;
995894cc87eSManuel Lauss 	do_IRQ(MIPS_CPU_IRQ_BASE + __ffs(r & 0xff));
996894cc87eSManuel Lauss }
997