15ad36c5fSErik Gilling /* 2938fa349SColin Cross * Copyright (C) 2011 Google, Inc. 35ad36c5fSErik Gilling * 45ad36c5fSErik Gilling * Author: 5938fa349SColin Cross * Colin Cross <ccross@android.com> 65ad36c5fSErik Gilling * 7460907bcSGary King * Copyright (C) 2010, NVIDIA Corporation 8460907bcSGary King * 95ad36c5fSErik Gilling * This software is licensed under the terms of the GNU General Public 105ad36c5fSErik Gilling * License version 2, as published by the Free Software Foundation, and 115ad36c5fSErik Gilling * may be copied, distributed, and modified under those terms. 125ad36c5fSErik Gilling * 135ad36c5fSErik Gilling * This program is distributed in the hope that it will be useful, 145ad36c5fSErik Gilling * but WITHOUT ANY WARRANTY; without even the implied warranty of 155ad36c5fSErik Gilling * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165ad36c5fSErik Gilling * GNU General Public License for more details. 175ad36c5fSErik Gilling * 185ad36c5fSErik Gilling */ 195ad36c5fSErik Gilling 205ad36c5fSErik Gilling #include <linux/kernel.h> 215ad36c5fSErik Gilling #include <linux/interrupt.h> 225ad36c5fSErik Gilling #include <linux/irq.h> 235ad36c5fSErik Gilling #include <linux/io.h> 245ad36c5fSErik Gilling 255ad36c5fSErik Gilling #include <asm/hardware/gic.h> 265ad36c5fSErik Gilling 275ad36c5fSErik Gilling #include <mach/iomap.h> 285ad36c5fSErik Gilling 295ad36c5fSErik Gilling #include "board.h" 305ad36c5fSErik Gilling 31*d1d8c666SColin Cross #define INT_SYS_NR (INT_GPIO_BASE - INT_PRI_BASE) 32*d1d8c666SColin Cross #define INT_SYS_SZ (INT_SEC_BASE - INT_PRI_BASE) 33*d1d8c666SColin Cross #define PPI_NR ((INT_SYS_NR+INT_SYS_SZ-1)/INT_SYS_SZ) 34*d1d8c666SColin Cross 35*d1d8c666SColin Cross #define ICTLR_CPU_IEP_VFIQ 0x08 36*d1d8c666SColin Cross #define ICTLR_CPU_IEP_FIR 0x14 37*d1d8c666SColin Cross #define ICTLR_CPU_IEP_FIR_SET 0x18 38*d1d8c666SColin Cross #define ICTLR_CPU_IEP_FIR_CLR 0x1c 39*d1d8c666SColin Cross 40*d1d8c666SColin Cross #define ICTLR_CPU_IER 0x20 41*d1d8c666SColin Cross #define ICTLR_CPU_IER_SET 0x24 42*d1d8c666SColin Cross #define ICTLR_CPU_IER_CLR 0x28 43*d1d8c666SColin Cross #define ICTLR_CPU_IEP_CLASS 0x2C 44*d1d8c666SColin Cross 45*d1d8c666SColin Cross #define ICTLR_COP_IER 0x30 46*d1d8c666SColin Cross #define ICTLR_COP_IER_SET 0x34 47*d1d8c666SColin Cross #define ICTLR_COP_IER_CLR 0x38 48*d1d8c666SColin Cross #define ICTLR_COP_IEP_CLASS 0x3c 49*d1d8c666SColin Cross 50*d1d8c666SColin Cross #define NUM_ICTLRS 4 51*d1d8c666SColin Cross #define FIRST_LEGACY_IRQ 32 52*d1d8c666SColin Cross 53*d1d8c666SColin Cross static void __iomem *ictlr_reg_base[] = { 54*d1d8c666SColin Cross IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE), 55*d1d8c666SColin Cross IO_ADDRESS(TEGRA_SECONDARY_ICTLR_BASE), 56*d1d8c666SColin Cross IO_ADDRESS(TEGRA_TERTIARY_ICTLR_BASE), 57*d1d8c666SColin Cross IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE), 58*d1d8c666SColin Cross }; 59*d1d8c666SColin Cross 60*d1d8c666SColin Cross static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg) 61*d1d8c666SColin Cross { 62*d1d8c666SColin Cross void __iomem *base; 63*d1d8c666SColin Cross u32 mask; 64*d1d8c666SColin Cross 65*d1d8c666SColin Cross BUG_ON(irq < FIRST_LEGACY_IRQ || 66*d1d8c666SColin Cross irq >= FIRST_LEGACY_IRQ + NUM_ICTLRS * 32); 67*d1d8c666SColin Cross 68*d1d8c666SColin Cross base = ictlr_reg_base[(irq - FIRST_LEGACY_IRQ) / 32]; 69*d1d8c666SColin Cross mask = BIT((irq - FIRST_LEGACY_IRQ) % 32); 70*d1d8c666SColin Cross 71*d1d8c666SColin Cross __raw_writel(mask, base + reg); 72*d1d8c666SColin Cross } 73*d1d8c666SColin Cross 7437337a8dSLennert Buytenhek static void tegra_mask(struct irq_data *d) 75460907bcSGary King { 76*d1d8c666SColin Cross if (d->irq < FIRST_LEGACY_IRQ) 77*d1d8c666SColin Cross return; 78*d1d8c666SColin Cross 79*d1d8c666SColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR); 80460907bcSGary King } 81460907bcSGary King 8237337a8dSLennert Buytenhek static void tegra_unmask(struct irq_data *d) 83460907bcSGary King { 84*d1d8c666SColin Cross if (d->irq < FIRST_LEGACY_IRQ) 85*d1d8c666SColin Cross return; 86*d1d8c666SColin Cross 87*d1d8c666SColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET); 88460907bcSGary King } 89460907bcSGary King 9026d902c0SColin Cross static void tegra_ack(struct irq_data *d) 9126d902c0SColin Cross { 92*d1d8c666SColin Cross if (d->irq < FIRST_LEGACY_IRQ) 93*d1d8c666SColin Cross return; 94*d1d8c666SColin Cross 95*d1d8c666SColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR); 9626d902c0SColin Cross } 9726d902c0SColin Cross 9826d902c0SColin Cross static int tegra_retrigger(struct irq_data *d) 9926d902c0SColin Cross { 100*d1d8c666SColin Cross if (d->irq < FIRST_LEGACY_IRQ) 101938fa349SColin Cross return 0; 102938fa349SColin Cross 103*d1d8c666SColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET); 104*d1d8c666SColin Cross 10526d902c0SColin Cross return 1; 10626d902c0SColin Cross } 10726d902c0SColin Cross 1085ad36c5fSErik Gilling void __init tegra_init_irq(void) 1095ad36c5fSErik Gilling { 110*d1d8c666SColin Cross int i; 111*d1d8c666SColin Cross 112*d1d8c666SColin Cross for (i = 0; i < NUM_ICTLRS; i++) { 113*d1d8c666SColin Cross void __iomem *ictlr = ictlr_reg_base[i]; 114*d1d8c666SColin Cross writel(~0, ictlr + ICTLR_CPU_IER_CLR); 115*d1d8c666SColin Cross writel(0, ictlr + ICTLR_CPU_IEP_CLASS); 116*d1d8c666SColin Cross } 117460907bcSGary King 118938fa349SColin Cross gic_arch_extn.irq_ack = tegra_ack; 119938fa349SColin Cross gic_arch_extn.irq_mask = tegra_mask; 120938fa349SColin Cross gic_arch_extn.irq_unmask = tegra_unmask; 121938fa349SColin Cross gic_arch_extn.irq_retrigger = tegra_retrigger; 122938fa349SColin Cross 123b580b899SRussell King gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE), 124b580b899SRussell King IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100)); 125460907bcSGary King } 126