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> 240d4f7479Spdeschrijver@nvidia.com #include <linux/of.h> 25*520f7bd7SRob Herring #include <linux/irqchip/arm-gic.h> 265ad36c5fSErik Gilling 275ad36c5fSErik Gilling #include "board.h" 282be39c07SStephen Warren #include "iomap.h" 295ad36c5fSErik Gilling 30d1d8c666SColin Cross #define ICTLR_CPU_IEP_VFIQ 0x08 31d1d8c666SColin Cross #define ICTLR_CPU_IEP_FIR 0x14 32d1d8c666SColin Cross #define ICTLR_CPU_IEP_FIR_SET 0x18 33d1d8c666SColin Cross #define ICTLR_CPU_IEP_FIR_CLR 0x1c 34d1d8c666SColin Cross 35d1d8c666SColin Cross #define ICTLR_CPU_IER 0x20 36d1d8c666SColin Cross #define ICTLR_CPU_IER_SET 0x24 37d1d8c666SColin Cross #define ICTLR_CPU_IER_CLR 0x28 38d1d8c666SColin Cross #define ICTLR_CPU_IEP_CLASS 0x2C 39d1d8c666SColin Cross 40d1d8c666SColin Cross #define ICTLR_COP_IER 0x30 41d1d8c666SColin Cross #define ICTLR_COP_IER_SET 0x34 42d1d8c666SColin Cross #define ICTLR_COP_IER_CLR 0x38 43d1d8c666SColin Cross #define ICTLR_COP_IEP_CLASS 0x3c 44d1d8c666SColin Cross 45d1d8c666SColin Cross #define FIRST_LEGACY_IRQ 32 46d1d8c666SColin Cross 47caa4868eSPeter De Schrijver static int num_ictlrs; 48caa4868eSPeter De Schrijver 49d1d8c666SColin Cross static void __iomem *ictlr_reg_base[] = { 50d1d8c666SColin Cross IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE), 51d1d8c666SColin Cross IO_ADDRESS(TEGRA_SECONDARY_ICTLR_BASE), 52d1d8c666SColin Cross IO_ADDRESS(TEGRA_TERTIARY_ICTLR_BASE), 53d1d8c666SColin Cross IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE), 54caa4868eSPeter De Schrijver IO_ADDRESS(TEGRA_QUINARY_ICTLR_BASE), 55d1d8c666SColin Cross }; 56d1d8c666SColin Cross 57d1d8c666SColin Cross static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg) 58d1d8c666SColin Cross { 59d1d8c666SColin Cross void __iomem *base; 60d1d8c666SColin Cross u32 mask; 61d1d8c666SColin Cross 62d1d8c666SColin Cross BUG_ON(irq < FIRST_LEGACY_IRQ || 63caa4868eSPeter De Schrijver irq >= FIRST_LEGACY_IRQ + num_ictlrs * 32); 64d1d8c666SColin Cross 65d1d8c666SColin Cross base = ictlr_reg_base[(irq - FIRST_LEGACY_IRQ) / 32]; 66d1d8c666SColin Cross mask = BIT((irq - FIRST_LEGACY_IRQ) % 32); 67d1d8c666SColin Cross 68d1d8c666SColin Cross __raw_writel(mask, base + reg); 69d1d8c666SColin Cross } 70d1d8c666SColin Cross 7137337a8dSLennert Buytenhek static void tegra_mask(struct irq_data *d) 72460907bcSGary King { 73d1d8c666SColin Cross if (d->irq < FIRST_LEGACY_IRQ) 74d1d8c666SColin Cross return; 75d1d8c666SColin Cross 76d1d8c666SColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR); 77460907bcSGary King } 78460907bcSGary King 7937337a8dSLennert Buytenhek static void tegra_unmask(struct irq_data *d) 80460907bcSGary King { 81d1d8c666SColin Cross if (d->irq < FIRST_LEGACY_IRQ) 82d1d8c666SColin Cross return; 83d1d8c666SColin Cross 84d1d8c666SColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET); 85460907bcSGary King } 86460907bcSGary King 8726d902c0SColin Cross static void tegra_ack(struct irq_data *d) 8826d902c0SColin Cross { 89d1d8c666SColin Cross if (d->irq < FIRST_LEGACY_IRQ) 90d1d8c666SColin Cross return; 91d1d8c666SColin Cross 92d1d8c666SColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR); 9326d902c0SColin Cross } 9426d902c0SColin Cross 954bd66cfdSColin Cross static void tegra_eoi(struct irq_data *d) 964bd66cfdSColin Cross { 974bd66cfdSColin Cross if (d->irq < FIRST_LEGACY_IRQ) 984bd66cfdSColin Cross return; 994bd66cfdSColin Cross 1004bd66cfdSColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR); 1014bd66cfdSColin Cross } 1024bd66cfdSColin Cross 10326d902c0SColin Cross static int tegra_retrigger(struct irq_data *d) 10426d902c0SColin Cross { 105d1d8c666SColin Cross if (d->irq < FIRST_LEGACY_IRQ) 106938fa349SColin Cross return 0; 107938fa349SColin Cross 108d1d8c666SColin Cross tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET); 109d1d8c666SColin Cross 11026d902c0SColin Cross return 1; 11126d902c0SColin Cross } 11226d902c0SColin Cross 1135ad36c5fSErik Gilling void __init tegra_init_irq(void) 1145ad36c5fSErik Gilling { 115d1d8c666SColin Cross int i; 116caa4868eSPeter De Schrijver void __iomem *distbase; 117d1d8c666SColin Cross 118caa4868eSPeter De Schrijver distbase = IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE); 119caa4868eSPeter De Schrijver num_ictlrs = readl_relaxed(distbase + GIC_DIST_CTR) & 0x1f; 120caa4868eSPeter De Schrijver 121caa4868eSPeter De Schrijver if (num_ictlrs > ARRAY_SIZE(ictlr_reg_base)) { 122caa4868eSPeter De Schrijver WARN(1, "Too many (%d) interrupt controllers found. Maximum is %d.", 123caa4868eSPeter De Schrijver num_ictlrs, ARRAY_SIZE(ictlr_reg_base)); 124caa4868eSPeter De Schrijver num_ictlrs = ARRAY_SIZE(ictlr_reg_base); 125caa4868eSPeter De Schrijver } 126caa4868eSPeter De Schrijver 127caa4868eSPeter De Schrijver for (i = 0; i < num_ictlrs; i++) { 128d1d8c666SColin Cross void __iomem *ictlr = ictlr_reg_base[i]; 129d1d8c666SColin Cross writel(~0, ictlr + ICTLR_CPU_IER_CLR); 130d1d8c666SColin Cross writel(0, ictlr + ICTLR_CPU_IEP_CLASS); 131d1d8c666SColin Cross } 132460907bcSGary King 133938fa349SColin Cross gic_arch_extn.irq_ack = tegra_ack; 1344bd66cfdSColin Cross gic_arch_extn.irq_eoi = tegra_eoi; 135938fa349SColin Cross gic_arch_extn.irq_mask = tegra_mask; 136938fa349SColin Cross gic_arch_extn.irq_unmask = tegra_unmask; 137938fa349SColin Cross gic_arch_extn.irq_retrigger = tegra_retrigger; 138938fa349SColin Cross 1390d4f7479Spdeschrijver@nvidia.com /* 1400d4f7479Spdeschrijver@nvidia.com * Check if there is a devicetree present, since the GIC will be 1410d4f7479Spdeschrijver@nvidia.com * initialized elsewhere under DT. 1420d4f7479Spdeschrijver@nvidia.com */ 1430d4f7479Spdeschrijver@nvidia.com if (!of_have_populated_dt()) 144caa4868eSPeter De Schrijver gic_init(0, 29, distbase, 145b580b899SRussell King IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100)); 146460907bcSGary King } 147