blob: 80bf99c8fa55802188b46ea462e1c200b5dfc4af [file] [log] [blame]
Kevin Hilman7c6337e2007-04-30 19:37:19 +01001/*
2 * Interrupt handler for DaVinci boards.
3 *
4 * Copyright (C) 2006 Texas Instruments.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/interrupt.h>
24#include <linux/irq.h>
Russell Kingfced80c2008-09-06 12:10:45 +010025#include <linux/io.h>
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010026#include <linux/irqdomain.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010027
Russell Kinga09e64f2008-08-05 16:14:15 +010028#include <mach/hardware.h>
Sudhakar Rajashekhara9e164692009-04-14 07:53:02 -050029#include <mach/cputype.h>
Mark A. Greer673dd362009-04-15 12:40:00 -070030#include <mach/common.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010031#include <asm/mach/irq.h>
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010032#include <asm/exception.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010033
Kevin Hilman7c6337e2007-04-30 19:37:19 +010034#define FIQ_REG0_OFFSET 0x0000
35#define FIQ_REG1_OFFSET 0x0004
36#define IRQ_REG0_OFFSET 0x0008
37#define IRQ_REG1_OFFSET 0x000C
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010038#define IRQ_IRQENTRY_OFFSET 0x0014
Kevin Hilman7c6337e2007-04-30 19:37:19 +010039#define IRQ_ENT_REG0_OFFSET 0x0018
40#define IRQ_ENT_REG1_OFFSET 0x001C
41#define IRQ_INCTL_REG_OFFSET 0x0020
42#define IRQ_EABASE_REG_OFFSET 0x0024
43#define IRQ_INTPRI0_REG_OFFSET 0x0030
44#define IRQ_INTPRI7_REG_OFFSET 0x004C
45
Bartosz Golaszewskifb746842019-02-14 15:52:00 +010046static void __iomem *davinci_intc_base;
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010047static struct irq_domain *davinci_irq_domain;
48
Kevin Hilman7c6337e2007-04-30 19:37:19 +010049static inline void davinci_irq_writel(unsigned long value, int offset)
50{
Mark A. Greer673dd362009-04-15 12:40:00 -070051 __raw_writel(value, davinci_intc_base + offset);
Kevin Hilman7c6337e2007-04-30 19:37:19 +010052}
53
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010054static inline unsigned long davinci_irq_readl(int offset)
55{
56 return readl_relaxed(davinci_intc_base + offset);
57}
58
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020059static __init void
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010060davinci_irq_setup_gc(void __iomem *base,
61 unsigned int irq_start, unsigned int num)
Kevin Hilman7c6337e2007-04-30 19:37:19 +010062{
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020063 struct irq_chip_generic *gc;
64 struct irq_chip_type *ct;
Kevin Hilman7c6337e2007-04-30 19:37:19 +010065
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010066 gc = irq_get_domain_generic_chip(davinci_irq_domain, irq_start);
67 gc->reg_base = base;
68 gc->irq_base = irq_start;
Todd Poynor33e1e5e2011-07-16 22:39:35 -070069
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020070 ct = gc->chip_types;
Simon Guinot659fb322011-07-06 12:41:31 -040071 ct->chip.irq_ack = irq_gc_ack_set_bit;
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020072 ct->chip.irq_mask = irq_gc_mask_clr_bit;
73 ct->chip.irq_unmask = irq_gc_mask_set_bit;
Kevin Hilman7c6337e2007-04-30 19:37:19 +010074
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020075 ct->regs.ack = IRQ_REG0_OFFSET;
76 ct->regs.mask = IRQ_ENT_REG0_OFFSET;
77 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
78 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
Kevin Hilman7c6337e2007-04-30 19:37:19 +010079}
80
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010081static asmlinkage void __exception_irq_entry
82davinci_handle_irq(struct pt_regs *regs)
83{
84 int irqnr = davinci_irq_readl(IRQ_IRQENTRY_OFFSET);
85
86 /*
87 * Use the formula for entry vector index generation from section
88 * 8.3.3 of the manual.
89 */
90 irqnr >>= 2;
91 irqnr -= 1;
92
93 handle_domain_irq(davinci_irq_domain, irqnr, regs);
94}
95
Kevin Hilman7c6337e2007-04-30 19:37:19 +010096/* ARM Interrupt Controller Initialization */
97void __init davinci_irq_init(void)
98{
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020099 unsigned i, j;
Mark A. Greer673dd362009-04-15 12:40:00 -0700100 const u8 *davinci_def_priorities = davinci_soc_info.intc_irq_prios;
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100101 int ret, irq_base;
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100102
Cyril Chemparathybd808942010-05-07 17:06:37 -0400103 davinci_intc_base = ioremap(davinci_soc_info.intc_base, SZ_4K);
104 if (WARN_ON(!davinci_intc_base))
105 return;
106
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100107 /* Clear all interrupt requests */
108 davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
109 davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
110 davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
111 davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);
112
113 /* Disable all interrupts */
114 davinci_irq_writel(0x0, IRQ_ENT_REG0_OFFSET);
115 davinci_irq_writel(0x0, IRQ_ENT_REG1_OFFSET);
116
117 /* Interrupts disabled immediately, IRQ entry reflects all */
118 davinci_irq_writel(0x0, IRQ_INCTL_REG_OFFSET);
119
120 /* we don't use the hardware vector table, just its entry addresses */
121 davinci_irq_writel(0, IRQ_EABASE_REG_OFFSET);
122
123 /* Clear all interrupt requests */
124 davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
125 davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
126 davinci_irq_writel(~0x0, IRQ_REG0_OFFSET);
127 davinci_irq_writel(~0x0, IRQ_REG1_OFFSET);
128
129 for (i = IRQ_INTPRI0_REG_OFFSET; i <= IRQ_INTPRI7_REG_OFFSET; i += 4) {
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100130 u32 pri;
131
Sudhakar Rajashekhara9e164692009-04-14 07:53:02 -0500132 for (j = 0, pri = 0; j < 32; j += 4, davinci_def_priorities++)
133 pri |= (*davinci_def_priorities & 0x07) << j;
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100134 davinci_irq_writel(pri, i);
135 }
136
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100137 irq_base = irq_alloc_descs(-1, 0, davinci_soc_info.intc_irq_num, 0);
138 if (WARN_ON(irq_base < 0))
139 return;
140
141 davinci_irq_domain = irq_domain_add_legacy(NULL,
142 davinci_soc_info.intc_irq_num,
143 irq_base, 0, &irq_domain_simple_ops,
144 NULL);
145 if (WARN_ON(!davinci_irq_domain))
146 return;
147
148 ret = irq_alloc_domain_generic_chips(davinci_irq_domain, 32, 1,
149 "AINTC", handle_edge_irq,
150 IRQ_NOREQUEST | IRQ_NOPROBE, 0, 0);
151 if (WARN_ON(ret))
152 return;
153
Thomas Gleixneraac4dd12011-04-15 11:19:57 +0200154 for (i = 0, j = 0; i < davinci_soc_info.intc_irq_num; i += 32, j += 0x04)
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100155 davinci_irq_setup_gc(davinci_intc_base + j, irq_base + i, 32);
Thomas Gleixneraac4dd12011-04-15 11:19:57 +0200156
Bartosz Golaszewskia98ca732019-02-14 15:52:01 +0100157 irq_set_handler(DAVINCI_INTC_IRQ(IRQ_TINT1_TINT34), handle_level_irq);
Bartosz Golaszewskid0064592019-02-14 15:51:58 +0100158 set_handle_irq(davinci_handle_irq);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100159}