/*
 * include/asm-arm/arch-cxd4105/irqs.h
 *
 * IRQ and cascade IRQ definitions
 *
 * Copyright 2005,2006,2007 Sony Corporation
 *
 * This code is based on include/asm-arm/arch-integrator/irqs.h.
 */
/*
 *  linux/include/asm-arm/arch-integrator/irqs.h
 *
 *  Copyright (C) 1999 ARM Limited
 *  Copyright (C) 2000 Deep Blue Solutions Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <asm/arch/platform.h>
#include <asm/arch/regs-intctrl.h>

#define IRQ_UART	INT_UART
#define IRQ_SSP		INT_SSP
#define IRQ_TIMER	INT_TIMER
#define IRQ_DMAC	INT_DMAC
#define IRQ_SIRCS	INT_SIRCS
#define IRQ_I2C		INT_I2C
#define IRQ_JOG		INT_JOG
#define IRQ_SIO		INT_SIO
#ifdef INT_SDIF
# define IRQ_SDIF	INT_SDIF
#endif /* INT_SDIF */
#ifdef INT_I2S
# define IRQ_I2S	INT_I2S
#endif /* INT_I2S */
#define IRQ_ATA		INT_ATA
#define IRQ_CF		INT_CF
#define IRQ_CML		INT_CML
#ifdef INT_PCI
# define IRQ_PCI	INT_PCI
#endif /* INT_PCI */
#define IRQ_USB		INT_USB
#define IRQ_MS		INT_MS
#define IRQ_MSIO	INT_MSIO
#define IRQ_TPU		INT_TPU
#define IRQ_ADC		INT_ADC
#define IRQ_TP		INT_TP
#define IRQ_GPIO	INT_GPIO
#define IRQ_MXX		INT_MXX
#define IRQ_MBOX	INT_MBOX
#define IRQ_VIDEO	INT_VIDEO
#define IRQ_CODEC	INT_CODEC
#define IRQ_WSX		INT_WSX
#define IRQ_IMG		INT_IMG
#define IRQ_IMGMC	INT_IMGMC
#define IRQ_BUS		INT_BUS
#define IRQ_IMGV	INT_IMGV
#define IRQ_SYSV	INT_SYSV
#define IRQ_AUDIO	INT_AUDIO

/* IRQ for cascade */
#define IRQ_L2_BASE		32

/*
	IRQ_XXX_BASE		Start IRQ#
	IRQ_XXX_NUM		Number of IRQs (includes reserved bits)
	IRQ_XXX_ALLOWMAP	Bitmap of available IRQs
*/

#define IRQ_UART_BASE		(IRQ_L2_BASE)
#define IRQ_UART_NUM		4
#ifdef CONFIG_CXD4105_EXTIO
#define IRQ_UART_ALLOWMAP	0x0000000f
#else
#ifdef CONFIG_ARCH_CXD4105
# ifdef CONFIG_CXD4105_HANDLE_UART3
#  define IRQ_UART_ALLOWMAP	0x0000000f
# else
#  define IRQ_UART_ALLOWMAP	0x00000007
# endif
#else /* CXD4108 */
# ifdef CONFIG_CXD4105_HANDLE_UART3
#  define IRQ_UART_ALLOWMAP	0x00000003
# else
#  define IRQ_UART_ALLOWMAP	0x00000001
# endif
#endif
#endif
#define IRQ_UARTx(x)		(IRQ_UART_BASE+(x))
#define IRQ_UART0		IRQ_UARTx(0)
#define IRQ_UART1		IRQ_UARTx(1)
#define IRQ_UART2		IRQ_UARTx(2)
#define IRQ_UART3		IRQ_UARTx(3)

#define IRQ_SSP_BASE		(IRQ_UART_BASE + IRQ_UART_NUM)
#define IRQ_SSP_NUM		2
#define IRQ_SSP_ALLOWMAP	0x00000000
#define IRQ_SSPx(x)		(IRQ_SSP_BASE + (x))
#define IRQ_SSP0		IRQ_SSPx(0)
#define IRQ_SSP1		IRQ_SSPx(1)

#define IRQ_TIMER_BASE		(IRQ_SSP_BASE + IRQ_SSP_NUM)
#define IRQ_TIMER_NUM		16
#ifdef CONFIG_CXD4105_EXTIO
#define IRQ_TIMER_ALLOWMAP	0x00007fff
#else
#ifdef CONFIG_ARCH_CXD4105
#define IRQ_TIMER_ALLOWMAP	0x0000000f
#else
#define IRQ_TIMER_ALLOWMAP	0x00000007
#endif /* CONFIG_ARCH_CXD4105 */
#endif
#define IRQ_TIMERx(x)		(IRQ_TIMER_BASE+(x))
#define IRQ_TIMER0		IRQ_TIMERx(0)
#define IRQ_TIMER1		IRQ_TIMERx(1)
#define IRQ_TIMER2		IRQ_TIMERx(2)
#define IRQ_TIMER3		IRQ_TIMERx(3)
#define IRQ_TIMER4		IRQ_TIMERx(4)
#define IRQ_TIMER5		IRQ_TIMERx(5)
#define IRQ_TIMER6		IRQ_TIMERx(6)
#define IRQ_TIMER7		IRQ_TIMERx(7)
#define IRQ_TIMER8		IRQ_TIMERx(8)
#define IRQ_TIMER9		IRQ_TIMERx(9)
#define IRQ_TIMER10		IRQ_TIMERx(10)
#define IRQ_TIMER11		IRQ_TIMERx(11)
#define IRQ_TIMER12		IRQ_TIMERx(12)
#define IRQ_TIMER13		IRQ_TIMERx(13)
#define IRQ_WDT			IRQ_TIMERx(14)

#define IRQ_DMAC_BASE		(IRQ_TIMER_BASE + IRQ_TIMER_NUM)
#define IRQ_DMAC_NUM		10
#ifdef CONFIG_CXD4105_EXTIO
#define IRQ_DMAC_ALLOWMAP	0x000003ff
#else
#define IRQ_DMAC_ALLOWMAP	0x000003fc
#endif
#define IRQ_DMAC0		(IRQ_DMAC_BASE)		/* FIFO32 */
#define IRQ_DMAC1		(IRQ_DMAC_BASE + 1)	/* FIFO16 */
#define IRQ_DMA0x(x)		(IRQ_DMAC_BASE + 2 + (x))
#define IRQ_DMA0_0		IRQ_DMA0x(0)
#define IRQ_DMA0_1		IRQ_DMA0x(1)
#define IRQ_DMA0_2		IRQ_DMA0x(2)
#define IRQ_DMA0_3		IRQ_DMA0x(3)
#define IRQ_DMA0_4		IRQ_DMA0x(4)
#define IRQ_DMA0_5		IRQ_DMA0x(5)
#define IRQ_DMA0_6		IRQ_DMA0x(6)
#define IRQ_DMA0_7		IRQ_DMA0x(7)

#define IRQ_SIRCS_BASE		(IRQ_DMAC_BASE + IRQ_DMAC_NUM)
#define IRQ_SIRCS_NUM		4
#ifdef CONFIG_CXD4105_EXTIO
#define IRQ_SIRCS_ALLOWMAP	0x00000007
#else
#define IRQ_SIRCS_ALLOWMAP	0x00000000
#endif
#define IRQ_SIRCSx(x)		(IRQ_SIRCS_BASE + (x))
#define IRQ_SIRCSTX		IRQ_SIRCSx(0)
#define IRQ_SIRCSRX		IRQ_SIRCSx(1)
#define IRQ_SIRCSROR		IRQ_SIRCSx(2)

#define IRQ_JOG_BASE		(IRQ_SIRCS_BASE + IRQ_SIRCS_NUM)
#define IRQ_JOG_NUM		2
#define IRQ_JOG_ALLOWMAP	0x00000003
#define IRQ_JOGx(x)		(IRQ_JOG_BASE + (x))
#define IRQ_JOG0		IRQ_JOGx(0)
#define IRQ_JOG1		IRQ_JOGx(1)

#define IRQ_SIO_BASE		(IRQ_JOG_BASE + IRQ_JOG_NUM)
#define IRQ_SIO_NUM		4
#define IRQ_SIO_ALLOWMAP	0x0000000f
#define IRQ_SIOx(x)		(IRQ_SIO_BASE + (x))
#define IRQ_SIO0		IRQ_SIOx(0)
#define IRQ_SIO1		IRQ_SIOx(1)
#define IRQ_SIO2		IRQ_SIOx(2)
#define IRQ_SIO3		IRQ_SIOx(3)

#define IRQ_I2S_BASE		(IRQ_SIO_BASE + IRQ_SIO_NUM)
#define IRQ_I2S_NUM		4
#ifdef INT_I2S
# ifdef CONFIG_CXD4105_EXTIO
#  define IRQ_I2S_ALLOWMAP	0x00000007
# else
#  define IRQ_I2S_ALLOWMAP	0x00000000
# endif
# define IRQ_I2Sx(x)		(IRQ_I2S_BASE + (x))
# define IRQ_I2S0		IRQ_I2Sx(0)
# define IRQ_I2S1		IRQ_I2Sx(1)
# define IRQ_I2S2		IRQ_I2Sx(2)
#endif /* INT_I2S */

#define IRQ_PCI_BASE		(IRQ_I2S_BASE + IRQ_I2S_NUM)
#define IRQ_PCI_NUM		8
#ifdef INT_PCI
# define IRQ_PCI_ALLOWMAP	0x0000001f
# define IRQ_PCIx(x)		(IRQ_PCI_BASE + (x))
# define IRQ_PCI_BRIDGE		IRQ_PCIx(0)
# define IRQ_PCI_INT0		IRQ_PCIx(1)
# define IRQ_PCI_INT1		IRQ_PCIx(2)
# define IRQ_PCI_INT2		IRQ_PCIx(3)
# define IRQ_PCI_INT3		IRQ_PCIx(4)
# define IRQ_PCI_INTA		IRQ_PCI_INT3
# define IRQ_PCI_INTB		IRQ_PCI_INT2
# define IRQ_PCI_INTC		IRQ_PCI_INT1
# define IRQ_PCI_INTD		IRQ_PCI_INT0
#endif /* INT_PCI */

#ifdef INT_SDIF
# if defined(CONFIG_ARCH_CXD4108)	/* replace I2S */
#  define IRQ_SDIF_BASE		IRQ_I2S_BASE
#  define IRQ_SDIF_NUM		IRQ_I2S_NUM
#  define IRQ_SDIF_ALLOWMAP	0x00000001
# elif defined(CONFIG_ARCH_MB8AC102)	/* replace PCI */
#  define IRQ_SDIF_BASE		IRQ_PCI_BASE
#  define IRQ_SDIF_NUM		IRQ_PCI_NUM
#  define IRQ_SDIF_ALLOWMAP	0x00000003
# endif
# define IRQ_SDIFx(x)		(IRQ_SDIF_BASE + (x))
# define IRQ_SDIF0		IRQ_SDIFx(0)
# define IRQ_SDIF1		IRQ_SDIFx(1)
#endif /* INT_SDIF */

#define IRQ_USB_BASE		(IRQ_PCI_BASE + IRQ_PCI_NUM)
#define IRQ_USB_NUM		2
#define IRQ_USB_ALLOWMAP	0x00000003
#define IRQ_USBx(x)		(IRQ_USB_BASE + (x))
#define IRQ_USB_HS		IRQ_USBx(0)
#define IRQ_USB_DMAC		IRQ_USBx(1)

#define IRQ_TPU_BASE		(IRQ_USB_BASE + IRQ_USB_NUM)
#define IRQ_TPU_NUM		8
#ifdef CONFIG_CXD4105_EXTIO
# define IRQ_TPU_ALLOWMAP	0x0000001f
#else
# define IRQ_TPU_ALLOWMAP	0x00000000
#endif
#define IRQ_TPUx(x)		(IRQ_TPU_BASE + (x))
#define IRQ_TPU0		IRQ_TPUx(0)
#define IRQ_TPU1		IRQ_TPUx(1)
#define IRQ_TPU2		IRQ_TPUx(2)
#define IRQ_TPU3		IRQ_TPUx(3)
#define IRQ_TPU4		IRQ_TPUx(4)

#define IRQ_ADC_BASE		(IRQ_TPU_BASE + IRQ_TPU_NUM)
#define IRQ_ADC_NUM		2
#ifdef CONFIG_CXD4105_EXTIO
# define IRQ_ADC_ALLOWMAP	0x00000003
#else
# define IRQ_ADC_ALLOWMAP	0x00000001
#endif
#define IRQ_ADCx(x)		(IRQ_ADC_BASE + (x))
#define IRQ_ADC0		IRQ_ADCx(0)
#define IRQ_ADC1		IRQ_ADCx(1)

#define IRQ_GPIO_BASE		(IRQ_ADC_BASE + IRQ_ADC_NUM)
#define IRQ_GPIO_NUM		16
#define IRQ_GPIO_ALLOWMAP	0x0000ffff
#define IRQ_GPIOx(x)		(IRQ_GPIO_BASE + (x))
#define IRQ_GPIO0		IRQ_GPIOx(0)
#define IRQ_GPIO1		IRQ_GPIOx(1)
#define IRQ_GPIO2		IRQ_GPIOx(2)
#define IRQ_GPIO3		IRQ_GPIOx(3)
#define IRQ_GPIO4		IRQ_GPIOx(4)
#define IRQ_GPIO5		IRQ_GPIOx(5)
#define IRQ_GPIO6		IRQ_GPIOx(6)
#define IRQ_GPIO7		IRQ_GPIOx(7)
#define IRQ_GPIO8		IRQ_GPIOx(8)
#define IRQ_GPIO9		IRQ_GPIOx(9)
#define IRQ_GPIO10		IRQ_GPIOx(10)
#define IRQ_GPIO11		IRQ_GPIOx(11)
#define IRQ_GPIO12		IRQ_GPIOx(12)
#define IRQ_GPIO13		IRQ_GPIOx(13)
#define IRQ_GPIO14		IRQ_GPIOx(14)
#define IRQ_GPIO15		IRQ_GPIOx(15)

#define IRQ_CF_BASE		(IRQ_GPIO_BASE + IRQ_GPIO_NUM)
#define IRQ_CF_NUM		2
#define IRQ_CF_ALLOWMAP		0x00000003
#define IRQ_CFx(x)		(IRQ_CF_BASE + (x))
#define IRQ_CF0			IRQ_CFx(0)
#define IRQ_EXIO		IRQ_CFx(1)

#define IRQ_SYSV_BASE		(IRQ_CF_BASE + IRQ_CF_NUM)
#define IRQ_SYSV_NUM		16
#define IRQ_SYSV_ALLOWMAP	0x000001ff
#define IRQ_SYSVx(x)		(IRQ_SYSV_BASE + (x))
#define IRQ_SYSV0		IRQ_SYSVx(0)
#define IRQ_SYSV1		IRQ_SYSVx(1)
#define IRQ_SYSV2		IRQ_SYSVx(2)
#define IRQ_SYSV3		IRQ_SYSVx(3)
#define IRQ_SYSV4		IRQ_SYSVx(4)
#define IRQ_SYSV5		IRQ_SYSVx(5)
#define IRQ_SYSV6		IRQ_SYSVx(6)
#define IRQ_SYSV7		IRQ_SYSVx(7)
#define IRQ_SYSV8		IRQ_SYSVx(8)

#ifndef CONFIG_CXD4105_EXTIO
#define NR_IRQS			(IRQ_SYSV_BASE + IRQ_SYSV_NUM)
#else
#define IRQ_I2C_BASE		(IRQ_SYSV_BASE + IRQ_SYSV_NUM)
#define IRQ_I2C_NUM		0
#define IRQ_I2C_ALLOWMAP	0x00000000
#define IRQ_I2Cx(x)		(IRQ_I2C_BASE + (x))

#define IRQ_MXX_BASE		(IRQ_I2C_BASE + IRQ_I2C_NUM)
#define IRQ_MXX_NUM		0
#define IRQ_MXX_ALLOWMAP	0x00000000
#define IRQ_MXXx(x)		(IRQ_MXX_BASE + (x))

#define IRQ_MBOX_BASE		(IRQ_MXX_BASE + IRQ_MXX_NUM)
#define IRQ_MBOX_NUM		0
#define IRQ_MBOX_ALLOWMAP	0x00000000
#define IRQ_MBOXx(x)		(IRQ_MBOX_BASE + (x))

#define IRQ_VIDEO_BASE		(IRQ_MBOX_BASE + IRQ_MBOX_NUM)
#define IRQ_VIDEO_NUM		8
#define IRQ_VIDEO_ALLOWMAP	0x0000003f
#define IRQ_VIDEOx(x)		(IRQ_MBOX_BASE + (x))

#define IRQ_CODEC_BASE		(IRQ_VIDEO_BASE + IRQ_VIDEO_NUM)
#define IRQ_CODEC_NUM		2
#define IRQ_CODEC_ALLOWMAP	0x00000003
#define IRQ_CODECx(x)		(IRQ_CODEC_BASE + (x))

#define IRQ_WSX_BASE		(IRQ_CODEC_BASE + IRQ_CODEC_NUM)
#define IRQ_WSX_NUM		0
#define IRQ_WSX_ALLOWMAP	0x00000000
#define IRQ_WSXx(x)		(IRQ_WSX_BASE + (x))

#define IRQ_IMG_BASE		(IRQ_WSX_BASE + IRQ_WSX_NUM)
#define IRQ_IMG_NUM		8
#define IRQ_IMG_ALLOWMAP	0x0000007f
#define IRQ_IMGx(x)		(IRQ_IMG_BASE + (x))

#define IRQ_IMGMC_BASE		(IRQ_IMG_BASE + IRQ_IMG_NUM)
#define IRQ_IMGMC_NUM		8
#define IRQ_IMGMC_ALLOWMAP	0x0000007f
#define IRQ_IMGMCx(x)		(IRQ_IMGMC_BASE + (x))

#define IRQ_BUS_BASE		(IRQ_IMGMC_BASE + IRQ_IMGMC_NUM)
#define IRQ_BUS_NUM		1
#define IRQ_BUS_ALLOWMAP	0x00000001
#define IRQ_BUSx(x)		(IRQ_BUS_BASE + (x))

#define IRQ_IMGV_BASE		(IRQ_BUS_BASE + IRQ_BUS_NUM)
#define IRQ_IMGV_NUM		4
#define IRQ_IMGV_ALLOWMAP	0x00000007
#define IRQ_IMGVx(x)		(IRQ_IMGV_BASE + (x))

#define IRQ_AUDIO_BASE		(IRQ_IMGV_BASE + IRQ_IMGV_NUM)
#define IRQ_AUDIO_NUM		8
#define IRQ_AUDIO_ALLOWMAP	0x00000003
#define IRQ_AUDIOx(x)		(IRQ_AUDIO_BASE + (x))
 
#define NR_IRQS			(IRQ_AUDIO_BASE + IRQ_AUDIO_NUM)
#endif
