blob: 004b0fdf0d76178cd5f037deeec55bdbb0a39494 [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 INT_SYS_NR (INT_GPIO_BASE - INT_PRI_BASE)
33#define INT_SYS_SZ (INT_SEC_BASE - INT_PRI_BASE)
34#define PPI_NR ((INT_SYS_NR+INT_SYS_SZ-1)/INT_SYS_SZ)
35
36#define ICTLR_CPU_IEP_VFIQ 0x08
37#define ICTLR_CPU_IEP_FIR 0x14
38#define ICTLR_CPU_IEP_FIR_SET 0x18
39#define ICTLR_CPU_IEP_FIR_CLR 0x1c
40
41#define ICTLR_CPU_IER 0x20
42#define ICTLR_CPU_IER_SET 0x24
43#define ICTLR_CPU_IER_CLR 0x28
44#define ICTLR_CPU_IEP_CLASS 0x2C
45
46#define ICTLR_COP_IER 0x30
47#define ICTLR_COP_IER_SET 0x34
48#define ICTLR_COP_IER_CLR 0x38
49#define ICTLR_COP_IEP_CLASS 0x3c
50
51#define NUM_ICTLRS 4
52#define FIRST_LEGACY_IRQ 32
53
54static void __iomem *ictlr_reg_base[] = {
55 IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE),
56 IO_ADDRESS(TEGRA_SECONDARY_ICTLR_BASE),
57 IO_ADDRESS(TEGRA_TERTIARY_ICTLR_BASE),
58 IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE),
59};
60
61static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg)
62{
63 void __iomem *base;
64 u32 mask;
65
66 BUG_ON(irq < FIRST_LEGACY_IRQ ||
67 irq >= FIRST_LEGACY_IRQ + NUM_ICTLRS * 32);
68
69 base = ictlr_reg_base[(irq - FIRST_LEGACY_IRQ) / 32];
70 mask = BIT((irq - FIRST_LEGACY_IRQ) % 32);
71
72 __raw_writel(mask, base + reg);
73}
74
Lennert Buytenhek37337a82010-11-29 11:14:46 +010075static void tegra_mask(struct irq_data *d)
Gary King460907b2010-04-05 20:30:59 -070076{
Colin Crossd1d8c662011-05-01 15:26:51 -070077 if (d->irq < FIRST_LEGACY_IRQ)
78 return;
79
80 tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR);
Gary King460907b2010-04-05 20:30:59 -070081}
82
Lennert Buytenhek37337a82010-11-29 11:14:46 +010083static void tegra_unmask(struct irq_data *d)
Gary King460907b2010-04-05 20:30:59 -070084{
Colin Crossd1d8c662011-05-01 15:26:51 -070085 if (d->irq < FIRST_LEGACY_IRQ)
86 return;
87
88 tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET);
Gary King460907b2010-04-05 20:30:59 -070089}
90
Colin Cross26d902c2011-02-09 22:17:17 -080091static void tegra_ack(struct irq_data *d)
92{
Colin Crossd1d8c662011-05-01 15:26:51 -070093 if (d->irq < FIRST_LEGACY_IRQ)
94 return;
95
96 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
Colin Cross26d902c2011-02-09 22:17:17 -080097}
98
Colin Cross4bd66cf2011-05-01 15:27:34 -070099static void tegra_eoi(struct irq_data *d)
100{
101 if (d->irq < FIRST_LEGACY_IRQ)
102 return;
103
104 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR);
105}
106
Colin Cross26d902c2011-02-09 22:17:17 -0800107static int tegra_retrigger(struct irq_data *d)
108{
Colin Crossd1d8c662011-05-01 15:26:51 -0700109 if (d->irq < FIRST_LEGACY_IRQ)
Colin Cross938fa342011-05-01 14:10:10 -0700110 return 0;
111
Colin Crossd1d8c662011-05-01 15:26:51 -0700112 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET);
113
Colin Cross26d902c2011-02-09 22:17:17 -0800114 return 1;
115}
116
Erik Gilling5ad36c52010-03-15 23:04:46 -0700117void __init tegra_init_irq(void)
118{
Colin Crossd1d8c662011-05-01 15:26:51 -0700119 int i;
120
121 for (i = 0; i < NUM_ICTLRS; i++) {
122 void __iomem *ictlr = ictlr_reg_base[i];
123 writel(~0, ictlr + ICTLR_CPU_IER_CLR);
124 writel(0, ictlr + ICTLR_CPU_IEP_CLASS);
125 }
Gary King460907b2010-04-05 20:30:59 -0700126
Colin Cross938fa342011-05-01 14:10:10 -0700127 gic_arch_extn.irq_ack = tegra_ack;
Colin Cross4bd66cf2011-05-01 15:27:34 -0700128 gic_arch_extn.irq_eoi = tegra_eoi;
Colin Cross938fa342011-05-01 14:10:10 -0700129 gic_arch_extn.irq_mask = tegra_mask;
130 gic_arch_extn.irq_unmask = tegra_unmask;
131 gic_arch_extn.irq_retrigger = tegra_retrigger;
132
pdeschrijver@nvidia.com0d4f7472011-11-29 18:29:19 -0700133 /*
134 * Check if there is a devicetree present, since the GIC will be
135 * initialized elsewhere under DT.
136 */
137 if (!of_have_populated_dt())
138 gic_init(0, 29, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE),
139 IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
Erik Gilling5ad36c52010-03-15 23:04:46 -0700140}