blob: ec52bee0e089b73893917b591dab6bad7e5e4c51 [file] [log] [blame]
Tony Lindgren1dbae812005-11-10 14:26:51 +00001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * linux/arch/arm/mach-omap2/irq.c
Tony Lindgren1dbae812005-11-10 14:26:51 +00003 *
4 * Interrupt handler for OMAP2 boards.
5 *
6 * Copyright (C) 2005 Nokia Corporation
7 * Author: Paul Mundt <paul.mundt@nokia.com>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13#include <linux/kernel.h>
14#include <linux/init.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000015#include <linux/interrupt.h>
Paul Walmsley2e7509e2008-10-09 17:51:28 +030016#include <linux/io.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010017#include <mach/hardware.h>
Marc Zyngier2db14992011-09-06 09:56:17 +010018#include <asm/exception.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000019#include <asm/mach/irq.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000020
Paul Walmsley2e7509e2008-10-09 17:51:28 +030021
22/* selected INTC register offsets */
23
24#define INTC_REVISION 0x0000
25#define INTC_SYSCONFIG 0x0010
26#define INTC_SYSSTATUS 0x0014
Tony Lindgren6ccc4c02008-12-10 17:36:52 -080027#define INTC_SIR 0x0040
Paul Walmsley2e7509e2008-10-09 17:51:28 +030028#define INTC_CONTROL 0x0048
Rajendra Nayak0addd612008-09-26 17:48:20 +053029#define INTC_PROTECTION 0x004C
30#define INTC_IDLE 0x0050
31#define INTC_THRESHOLD 0x0068
32#define INTC_MIR0 0x0084
Paul Walmsley2e7509e2008-10-09 17:51:28 +030033#define INTC_MIR_CLEAR0 0x0088
34#define INTC_MIR_SET0 0x008c
35#define INTC_PENDING_IRQ0 0x0098
Paul Walmsley2e7509e2008-10-09 17:51:28 +030036/* Number of IRQ state bits in each MIR register */
37#define IRQ_BITS_PER_REG 32
Tony Lindgren1dbae812005-11-10 14:26:51 +000038
Marc Zyngier2db14992011-09-06 09:56:17 +010039#define OMAP2_IRQ_BASE OMAP2_L4_IO_ADDRESS(OMAP24XX_IC_BASE)
40#define OMAP3_IRQ_BASE OMAP2_L4_IO_ADDRESS(OMAP34XX_IC_BASE)
41#define INTCPS_SIR_IRQ_OFFSET 0x0040 /* omap2/3 active interrupt offset */
42#define ACTIVEIRQ_MASK 0x7f /* omap2/3 active interrupt bits */
43
Tony Lindgren1dbae812005-11-10 14:26:51 +000044/*
45 * OMAP2 has a number of different interrupt controllers, each interrupt
46 * controller is identified as its own "bank". Register definitions are
47 * fairly consistent for each bank, but not all registers are implemented
48 * for each bank.. when in doubt, consult the TRM.
49 */
50static struct omap_irq_bank {
Russell Kinge8a91c92008-09-01 22:07:37 +010051 void __iomem *base_reg;
Tony Lindgren1dbae812005-11-10 14:26:51 +000052 unsigned int nr_irqs;
53} __attribute__ ((aligned(4))) irq_banks[] = {
54 {
55 /* MPU INTC */
Tony Lindgren1dbae812005-11-10 14:26:51 +000056 .nr_irqs = 96,
Tony Lindgren646e3ed2008-10-06 15:49:36 +030057 },
Tony Lindgren1dbae812005-11-10 14:26:51 +000058};
59
Rajendra Nayak0addd612008-09-26 17:48:20 +053060/* Structure to save interrupt controller context */
61struct omap3_intc_regs {
62 u32 sysconfig;
63 u32 protection;
64 u32 idle;
65 u32 threshold;
66 u32 ilr[INTCPS_NR_IRQS];
67 u32 mir[INTCPS_NR_MIR_REGS];
68};
69
Paul Walmsley2e7509e2008-10-09 17:51:28 +030070/* INTC bank register get/set */
71
72static void intc_bank_write_reg(u32 val, struct omap_irq_bank *bank, u16 reg)
73{
74 __raw_writel(val, bank->base_reg + reg);
75}
76
77static u32 intc_bank_read_reg(struct omap_irq_bank *bank, u16 reg)
78{
79 return __raw_readl(bank->base_reg + reg);
80}
81
Tony Lindgren1dbae812005-11-10 14:26:51 +000082/* XXX: FIQ and additional INTC support (only MPU at the moment) */
Lennert Buytenhekdf303472010-11-29 10:39:59 +010083static void omap_ack_irq(struct irq_data *d)
Tony Lindgren1dbae812005-11-10 14:26:51 +000084{
Paul Walmsley2e7509e2008-10-09 17:51:28 +030085 intc_bank_write_reg(0x1, &irq_banks[0], INTC_CONTROL);
Tony Lindgren1dbae812005-11-10 14:26:51 +000086}
87
Lennert Buytenhekdf303472010-11-29 10:39:59 +010088static void omap_mask_ack_irq(struct irq_data *d)
Tony Lindgren1dbae812005-11-10 14:26:51 +000089{
Tony Lindgren667a11f2011-05-16 02:07:38 -070090 irq_gc_mask_disable_reg(d);
Lennert Buytenhekdf303472010-11-29 10:39:59 +010091 omap_ack_irq(d);
Tony Lindgren1dbae812005-11-10 14:26:51 +000092}
93
Tony Lindgren1dbae812005-11-10 14:26:51 +000094static void __init omap_irq_bank_init_one(struct omap_irq_bank *bank)
95{
96 unsigned long tmp;
97
Paul Walmsley2e7509e2008-10-09 17:51:28 +030098 tmp = intc_bank_read_reg(bank, INTC_REVISION) & 0xff;
Russell Kinge8a91c92008-09-01 22:07:37 +010099 printk(KERN_INFO "IRQ: Found an INTC at 0x%p "
Tony Lindgren1dbae812005-11-10 14:26:51 +0000100 "(revision %ld.%ld) with %d interrupts\n",
101 bank->base_reg, tmp >> 4, tmp & 0xf, bank->nr_irqs);
102
Paul Walmsley2e7509e2008-10-09 17:51:28 +0300103 tmp = intc_bank_read_reg(bank, INTC_SYSCONFIG);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000104 tmp |= 1 << 1; /* soft reset */
Paul Walmsley2e7509e2008-10-09 17:51:28 +0300105 intc_bank_write_reg(tmp, bank, INTC_SYSCONFIG);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000106
Paul Walmsley2e7509e2008-10-09 17:51:28 +0300107 while (!(intc_bank_read_reg(bank, INTC_SYSSTATUS) & 0x1))
Tony Lindgren1dbae812005-11-10 14:26:51 +0000108 /* Wait for reset to complete */;
Juha Yrjola375e12a2006-12-06 17:13:50 -0800109
110 /* Enable autoidle */
Paul Walmsley2e7509e2008-10-09 17:51:28 +0300111 intc_bank_write_reg(1 << 0, bank, INTC_SYSCONFIG);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000112}
113
Jouni Hogander94434532009-02-03 15:49:04 -0800114int omap_irq_pending(void)
115{
116 int i;
117
118 for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
119 struct omap_irq_bank *bank = irq_banks + i;
120 int irq;
121
122 for (irq = 0; irq < bank->nr_irqs; irq += 32)
123 if (intc_bank_read_reg(bank, INTC_PENDING_IRQ0 +
124 ((irq >> 5) << 5)))
125 return 1;
126 }
127 return 0;
128}
129
Tony Lindgren667a11f2011-05-16 02:07:38 -0700130static __init void
131omap_alloc_gc(void __iomem *base, unsigned int irq_start, unsigned int num)
132{
133 struct irq_chip_generic *gc;
134 struct irq_chip_type *ct;
135
136 gc = irq_alloc_generic_chip("INTC", 1, irq_start, base,
137 handle_level_irq);
138 ct = gc->chip_types;
139 ct->chip.irq_ack = omap_mask_ack_irq;
140 ct->chip.irq_mask = irq_gc_mask_disable_reg;
141 ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
142
143 ct->regs.ack = INTC_CONTROL;
144 ct->regs.enable = INTC_MIR_CLEAR0;
145 ct->regs.disable = INTC_MIR_SET0;
146 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
147 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
148}
149
Tony Lindgren741e3a82011-05-17 03:51:26 -0700150static void __init omap_init_irq(u32 base, int nr_irqs)
Tony Lindgren1dbae812005-11-10 14:26:51 +0000151{
Thomas Gleixner4b1135a2008-10-16 15:33:18 +0200152 unsigned long nr_of_irqs = 0;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000153 unsigned int nr_banks = 0;
Tony Lindgren667a11f2011-05-16 02:07:38 -0700154 int i, j;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000155
Tony Lindgren741e3a82011-05-17 03:51:26 -0700156 omap_irq_base = ioremap(base, SZ_4K);
157 if (WARN_ON(!omap_irq_base))
158 return;
159
Tony Lindgren1dbae812005-11-10 14:26:51 +0000160 for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
161 struct omap_irq_bank *bank = irq_banks + i;
162
Tony Lindgren741e3a82011-05-17 03:51:26 -0700163 bank->nr_irqs = nr_irqs;
Hemant Pedanekar01001712011-02-16 08:31:39 -0800164
Tony Lindgren1b26fe82009-10-19 15:25:13 -0700165 /* Static mapping, never released */
166 bank->base_reg = ioremap(base, SZ_4K);
167 if (!bank->base_reg) {
168 printk(KERN_ERR "Could not ioremap irq bank%i\n", i);
169 continue;
170 }
Paul Walmsley2e7509e2008-10-09 17:51:28 +0300171
Tony Lindgren1dbae812005-11-10 14:26:51 +0000172 omap_irq_bank_init_one(bank);
173
Tapani Utriainen5c30cdf2011-09-30 11:05:56 -0700174 for (j = 0; j < bank->nr_irqs; j += 32)
175 omap_alloc_gc(bank->base_reg + j, j, 32);
Tony Lindgren667a11f2011-05-16 02:07:38 -0700176
Thomas Gleixner4b1135a2008-10-16 15:33:18 +0200177 nr_of_irqs += bank->nr_irqs;
Tony Lindgren1dbae812005-11-10 14:26:51 +0000178 nr_banks++;
179 }
180
181 printk(KERN_INFO "Total of %ld interrupts on %d active controller%s\n",
Thomas Gleixner4b1135a2008-10-16 15:33:18 +0200182 nr_of_irqs, nr_banks, nr_banks > 1 ? "s" : "");
Tony Lindgren1dbae812005-11-10 14:26:51 +0000183}
184
Tony Lindgren741e3a82011-05-17 03:51:26 -0700185void __init omap2_init_irq(void)
186{
187 omap_init_irq(OMAP24XX_IC_BASE, 96);
188}
189
190void __init omap3_init_irq(void)
191{
192 omap_init_irq(OMAP34XX_IC_BASE, 96);
193}
194
195void __init ti816x_init_irq(void)
196{
197 omap_init_irq(OMAP34XX_IC_BASE, 128);
198}
199
Marc Zyngier2db14992011-09-06 09:56:17 +0100200static inline void omap_intc_handle_irq(void __iomem *base_addr, struct pt_regs *regs)
201{
202 u32 irqnr;
203
204 do {
205 irqnr = readl_relaxed(base_addr + 0x98);
206 if (irqnr)
207 goto out;
208
209 irqnr = readl_relaxed(base_addr + 0xb8);
210 if (irqnr)
211 goto out;
212
213 irqnr = readl_relaxed(base_addr + 0xd8);
214#ifdef CONFIG_SOC_OMAPTI816X
215 if (irqnr)
216 goto out;
217 irqnr = readl_relaxed(base_addr + 0xf8);
218#endif
219
220out:
221 if (!irqnr)
222 break;
223
224 irqnr = readl_relaxed(base_addr + INTCPS_SIR_IRQ_OFFSET);
225 irqnr &= ACTIVEIRQ_MASK;
226
227 if (irqnr)
228 handle_IRQ(irqnr, regs);
229 } while (irqnr);
230}
231
232asmlinkage void __exception_irq_entry omap2_intc_handle_irq(struct pt_regs *regs)
233{
234 void __iomem *base_addr = OMAP2_IRQ_BASE;
235 omap_intc_handle_irq(base_addr, regs);
236}
237
Rajendra Nayak0addd612008-09-26 17:48:20 +0530238#ifdef CONFIG_ARCH_OMAP3
Felipe Balbiee23b932011-01-27 16:39:43 -0800239static struct omap3_intc_regs intc_context[ARRAY_SIZE(irq_banks)];
240
Rajendra Nayak0addd612008-09-26 17:48:20 +0530241void omap_intc_save_context(void)
242{
243 int ind = 0, i = 0;
244 for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
245 struct omap_irq_bank *bank = irq_banks + ind;
246 intc_context[ind].sysconfig =
247 intc_bank_read_reg(bank, INTC_SYSCONFIG);
248 intc_context[ind].protection =
249 intc_bank_read_reg(bank, INTC_PROTECTION);
250 intc_context[ind].idle =
251 intc_bank_read_reg(bank, INTC_IDLE);
252 intc_context[ind].threshold =
253 intc_bank_read_reg(bank, INTC_THRESHOLD);
254 for (i = 0; i < INTCPS_NR_IRQS; i++)
255 intc_context[ind].ilr[i] =
Aaro Koskinen2329e7c2009-03-12 18:12:29 +0200256 intc_bank_read_reg(bank, (0x100 + 0x4*i));
Rajendra Nayak0addd612008-09-26 17:48:20 +0530257 for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
258 intc_context[ind].mir[i] =
259 intc_bank_read_reg(&irq_banks[0], INTC_MIR0 +
260 (0x20 * i));
261 }
262}
263
264void omap_intc_restore_context(void)
265{
266 int ind = 0, i = 0;
267
268 for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
269 struct omap_irq_bank *bank = irq_banks + ind;
270 intc_bank_write_reg(intc_context[ind].sysconfig,
271 bank, INTC_SYSCONFIG);
272 intc_bank_write_reg(intc_context[ind].sysconfig,
273 bank, INTC_SYSCONFIG);
274 intc_bank_write_reg(intc_context[ind].protection,
275 bank, INTC_PROTECTION);
276 intc_bank_write_reg(intc_context[ind].idle,
277 bank, INTC_IDLE);
278 intc_bank_write_reg(intc_context[ind].threshold,
279 bank, INTC_THRESHOLD);
280 for (i = 0; i < INTCPS_NR_IRQS; i++)
281 intc_bank_write_reg(intc_context[ind].ilr[i],
Aaro Koskinen2329e7c2009-03-12 18:12:29 +0200282 bank, (0x100 + 0x4*i));
Rajendra Nayak0addd612008-09-26 17:48:20 +0530283 for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
284 intc_bank_write_reg(intc_context[ind].mir[i],
285 &irq_banks[0], INTC_MIR0 + (0x20 * i));
286 }
287 /* MIRs are saved and restore with other PRCM registers */
288}
Tero Kristo2bbe3af2009-10-23 19:03:48 +0300289
290void omap3_intc_suspend(void)
291{
292 /* A pending interrupt would prevent OMAP from entering suspend */
293 omap_ack_irq(0);
294}
Tero Kristof18cc2f2009-10-23 19:03:50 +0300295
296void omap3_intc_prepare_idle(void)
297{
Jean Pihet447b8da2010-11-17 17:52:11 +0000298 /*
299 * Disable autoidle as it can stall interrupt controller,
300 * cf. errata ID i540 for 3430 (all revisions up to 3.1.x)
301 */
Tero Kristof18cc2f2009-10-23 19:03:50 +0300302 intc_bank_write_reg(0, &irq_banks[0], INTC_SYSCONFIG);
303}
304
305void omap3_intc_resume_idle(void)
306{
307 /* Re-enable autoidle */
308 intc_bank_write_reg(1, &irq_banks[0], INTC_SYSCONFIG);
309}
Marc Zyngier2db14992011-09-06 09:56:17 +0100310
311asmlinkage void __exception_irq_entry omap3_intc_handle_irq(struct pt_regs *regs)
312{
313 void __iomem *base_addr = OMAP3_IRQ_BASE;
314 omap_intc_handle_irq(base_addr, regs);
315}
Rajendra Nayak0addd612008-09-26 17:48:20 +0530316#endif /* CONFIG_ARCH_OMAP3 */