blob: 2f5bd2db8e1faa78a69cedd1bfdc144bec47b615 [file] [log] [blame]
Erik Gilling5ad36c52010-03-15 23:04:46 -07001/*
Colin Cross938fa342011-05-01 14:10:10 -07002 * Copyright (C) 2011 Google, Inc.
Erik Gilling5ad36c52010-03-15 23:04:46 -07003 *
4 * Author:
Colin Cross938fa342011-05-01 14:10:10 -07005 * Colin Cross <ccross@android.com>
Erik Gilling5ad36c52010-03-15 23:04:46 -07006 *
Gary King460907b2010-04-05 20:30:59 -07007 * Copyright (C) 2010, NVIDIA Corporation
8 *
Erik Gilling5ad36c52010-03-15 23:04:46 -07009 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#include <linux/kernel.h>
Erik Gilling5ad36c52010-03-15 23:04:46 -070021#include <linux/interrupt.h>
22#include <linux/irq.h>
23#include <linux/io.h>
pdeschrijver@nvidia.com0d4f7472011-11-29 18:29:19 -070024#include <linux/of.h>
Erik Gilling5ad36c52010-03-15 23:04:46 -070025
26#include <asm/hardware/gic.h>
27
28#include <mach/iomap.h>
29
30#include "board.h"
31
Colin Crossd1d8c662011-05-01 15:26:51 -070032#define ICTLR_CPU_IEP_VFIQ 0x08
33#define ICTLR_CPU_IEP_FIR 0x14
34#define ICTLR_CPU_IEP_FIR_SET 0x18
35#define ICTLR_CPU_IEP_FIR_CLR 0x1c
36
37#define ICTLR_CPU_IER 0x20
38#define ICTLR_CPU_IER_SET 0x24
39#define ICTLR_CPU_IER_CLR 0x28
40#define ICTLR_CPU_IEP_CLASS 0x2C
41
42#define ICTLR_COP_IER 0x30
43#define ICTLR_COP_IER_SET 0x34
44#define ICTLR_COP_IER_CLR 0x38
45#define ICTLR_COP_IEP_CLASS 0x3c
46
Colin Crossd1d8c662011-05-01 15:26:51 -070047#define FIRST_LEGACY_IRQ 32
48
Peter De Schrijvercaa48682012-01-05 03:31:45 +000049static int num_ictlrs;
50
Colin Crossd1d8c662011-05-01 15:26:51 -070051static void __iomem *ictlr_reg_base[] = {
52 IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE),
53 IO_ADDRESS(TEGRA_SECONDARY_ICTLR_BASE),
54 IO_ADDRESS(TEGRA_TERTIARY_ICTLR_BASE),
55 IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE),
Peter De Schrijvercaa48682012-01-05 03:31:45 +000056 IO_ADDRESS(TEGRA_QUINARY_ICTLR_BASE),
Colin Crossd1d8c662011-05-01 15:26:51 -070057};
58
59static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg)
60{
61 void __iomem *base;
62 u32 mask;
63
64 BUG_ON(irq < FIRST_LEGACY_IRQ ||
Peter De Schrijvercaa48682012-01-05 03:31:45 +000065 irq >= FIRST_LEGACY_IRQ + num_ictlrs * 32);
Colin Crossd1d8c662011-05-01 15:26:51 -070066
67 base = ictlr_reg_base[(irq - FIRST_LEGACY_IRQ) / 32];
68 mask = BIT((irq - FIRST_LEGACY_IRQ) % 32);
69
70 __raw_writel(mask, base + reg);
71}
72
Lennert Buytenhek37337a82010-11-29 11:14:46 +010073static void tegra_mask(struct irq_data *d)
Gary King460907b2010-04-05 20:30:59 -070074{
Colin Crossd1d8c662011-05-01 15:26:51 -070075 if (d->irq < FIRST_LEGACY_IRQ)
76 return;
77
78 tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR);
Gary King460907b2010-04-05 20:30:59 -070079}
80
Lennert Buytenhek37337a82010-11-29 11:14:46 +010081static void tegra_unmask(struct irq_data *d)
Gary King460907b2010-04-05 20:30:59 -070082{
Colin Crossd1d8c662011-05-01 15:26:51 -070083 if (d->irq < FIRST_LEGACY_IRQ)
84 return;
85
86 tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET);
Gary King460907b2010-04-05 20:30:59 -070087}
88
Colin Cross26d902c2011-02-09 22:17:17 -080089static void tegra_ack(struct irq_data *d)
90{
Colin Crossd1d8c662011-05-01 15:26:51 -070091 if (d->irq < FIRST_LEGACY_IRQ)
92 return;
93
94 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
Colin Cross26d902c2011-02-09 22:17:17 -080095}
96
Colin Cross4bd66cf2011-05-01 15:27:34 -070097static void tegra_eoi(struct irq_data *d)
98{
99 if (d->irq < FIRST_LEGACY_IRQ)
100 return;
101
102 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
103}
104
Colin Cross26d902c2011-02-09 22:17:17 -0800105static int tegra_retrigger(struct irq_data *d)
106{
Colin Crossd1d8c662011-05-01 15:26:51 -0700107 if (d->irq < FIRST_LEGACY_IRQ)
Colin Cross938fa342011-05-01 14:10:10 -0700108 return 0;
109
Colin Crossd1d8c662011-05-01 15:26:51 -0700110 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET);
111
Colin Cross26d902c2011-02-09 22:17:17 -0800112 return 1;
113}
114
Erik Gilling5ad36c52010-03-15 23:04:46 -0700115void __init tegra_init_irq(void)
116{
Colin Crossd1d8c662011-05-01 15:26:51 -0700117 int i;
Peter De Schrijvercaa48682012-01-05 03:31:45 +0000118 void __iomem *distbase;
Colin Crossd1d8c662011-05-01 15:26:51 -0700119
Peter De Schrijvercaa48682012-01-05 03:31:45 +0000120 distbase = IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE);
121 num_ictlrs = readl_relaxed(distbase + GIC_DIST_CTR) & 0x1f;
122
123 if (num_ictlrs > ARRAY_SIZE(ictlr_reg_base)) {
124 WARN(1, "Too many (%d) interrupt controllers found. Maximum is %d.",
125 num_ictlrs, ARRAY_SIZE(ictlr_reg_base));
126 num_ictlrs = ARRAY_SIZE(ictlr_reg_base);
127 }
128
129 for (i = 0; i < num_ictlrs; i++) {
Colin Crossd1d8c662011-05-01 15:26:51 -0700130 void __iomem *ictlr = ictlr_reg_base[i];
131 writel(~0, ictlr + ICTLR_CPU_IER_CLR);
132 writel(0, ictlr + ICTLR_CPU_IEP_CLASS);
133 }
Gary King460907b2010-04-05 20:30:59 -0700134
Colin Cross938fa342011-05-01 14:10:10 -0700135 gic_arch_extn.irq_ack = tegra_ack;
Colin Cross4bd66cf2011-05-01 15:27:34 -0700136 gic_arch_extn.irq_eoi = tegra_eoi;
Colin Cross938fa342011-05-01 14:10:10 -0700137 gic_arch_extn.irq_mask = tegra_mask;
138 gic_arch_extn.irq_unmask = tegra_unmask;
139 gic_arch_extn.irq_retrigger = tegra_retrigger;
140
pdeschrijver@nvidia.com0d4f7472011-11-29 18:29:19 -0700141 /*
142 * Check if there is a devicetree present, since the GIC will be
143 * initialized elsewhere under DT.
144 */
145 if (!of_have_populated_dt())
Peter De Schrijvercaa48682012-01-05 03:31:45 +0000146 gic_init(0, 29, distbase,
pdeschrijver@nvidia.com0d4f7472011-11-29 18:29:19 -0700147 IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
Erik Gilling5ad36c52010-03-15 23:04:46 -0700148}