blob: 509be44eda228150390e2605319a9737c0d3b16b [file] [log] [blame]
Bartosz Golaszewski2d242aa2019-02-14 15:52:04 +01001// SPDX-License-Identifier: GPL-2.0-or-later
2//
3// Copyright (C) 2006, 2019 Texas Instruments.
4//
5// Interrupt handler for DaVinci boards.
6
Kevin Hilman7c6337e2007-04-30 19:37:19 +01007#include <linux/kernel.h>
8#include <linux/init.h>
9#include <linux/interrupt.h>
10#include <linux/irq.h>
Russell Kingfced80c2008-09-06 12:10:45 +010011#include <linux/io.h>
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010012#include <linux/irqdomain.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010013
Russell Kinga09e64f2008-08-05 16:14:15 +010014#include <mach/hardware.h>
Sudhakar Rajashekhara9e164692009-04-14 07:53:02 -050015#include <mach/cputype.h>
Mark A. Greer673dd362009-04-15 12:40:00 -070016#include <mach/common.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010017#include <asm/mach/irq.h>
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010018#include <asm/exception.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010019
Bartosz Golaszewski544ca0b2019-02-14 15:52:03 +010020#include "irqs.h"
21
Bartosz Golaszewski919da6f12019-02-14 15:52:07 +010022#define DAVINCI_AINTC_FIQ_REG0 0x00
23#define DAVINCI_AINTC_FIQ_REG1 0x04
24#define DAVINCI_AINTC_IRQ_REG0 0x08
25#define DAVINCI_AINTC_IRQ_REG1 0x0c
26#define DAVINCI_AINTC_IRQ_IRQENTRY 0x14
27#define DAVINCI_AINTC_IRQ_ENT_REG0 0x18
28#define DAVINCI_AINTC_IRQ_ENT_REG1 0x1c
29#define DAVINCI_AINTC_IRQ_INCTL_REG 0x20
30#define DAVINCI_AINTC_IRQ_EABASE_REG 0x24
31#define DAVINCI_AINTC_IRQ_INTPRI0_REG 0x30
32#define DAVINCI_AINTC_IRQ_INTPRI7_REG 0x4c
Kevin Hilman7c6337e2007-04-30 19:37:19 +010033
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010034static void __iomem *davinci_aintc_base;
35static struct irq_domain *davinci_aintc_irq_domain;
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010036
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010037static inline void davinci_aintc_writel(unsigned long value, int offset)
Kevin Hilman7c6337e2007-04-30 19:37:19 +010038{
Bartosz Golaszewskif4123842019-02-14 15:52:08 +010039 writel_relaxed(value, davinci_aintc_base + offset);
Kevin Hilman7c6337e2007-04-30 19:37:19 +010040}
41
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010042static inline unsigned long davinci_aintc_readl(int offset)
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010043{
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010044 return readl_relaxed(davinci_aintc_base + offset);
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010045}
46
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020047static __init void
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010048davinci_aintc_setup_gc(void __iomem *base,
49 unsigned int irq_start, unsigned int num)
Kevin Hilman7c6337e2007-04-30 19:37:19 +010050{
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020051 struct irq_chip_generic *gc;
52 struct irq_chip_type *ct;
Kevin Hilman7c6337e2007-04-30 19:37:19 +010053
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010054 gc = irq_get_domain_generic_chip(davinci_aintc_irq_domain, irq_start);
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010055 gc->reg_base = base;
56 gc->irq_base = irq_start;
Todd Poynor33e1e5e2011-07-16 22:39:35 -070057
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020058 ct = gc->chip_types;
Simon Guinot659fb322011-07-06 12:41:31 -040059 ct->chip.irq_ack = irq_gc_ack_set_bit;
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020060 ct->chip.irq_mask = irq_gc_mask_clr_bit;
61 ct->chip.irq_unmask = irq_gc_mask_set_bit;
Kevin Hilman7c6337e2007-04-30 19:37:19 +010062
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010063 ct->regs.ack = DAVINCI_AINTC_IRQ_REG0;
64 ct->regs.mask = DAVINCI_AINTC_IRQ_ENT_REG0;
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020065 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
66 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
Kevin Hilman7c6337e2007-04-30 19:37:19 +010067}
68
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010069static asmlinkage void __exception_irq_entry
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010070davinci_aintc_handle_irq(struct pt_regs *regs)
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010071{
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010072 int irqnr = davinci_aintc_readl(DAVINCI_AINTC_IRQ_IRQENTRY);
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010073
74 /*
75 * Use the formula for entry vector index generation from section
76 * 8.3.3 of the manual.
77 */
78 irqnr >>= 2;
79 irqnr -= 1;
80
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010081 handle_domain_irq(davinci_aintc_irq_domain, irqnr, regs);
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010082}
83
Kevin Hilman7c6337e2007-04-30 19:37:19 +010084/* ARM Interrupt Controller Initialization */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010085void __init davinci_aintc_init(void)
Kevin Hilman7c6337e2007-04-30 19:37:19 +010086{
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020087 unsigned i, j;
Mark A. Greer673dd362009-04-15 12:40:00 -070088 const u8 *davinci_def_priorities = davinci_soc_info.intc_irq_prios;
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010089 int ret, irq_base;
Kevin Hilman7c6337e2007-04-30 19:37:19 +010090
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010091 davinci_aintc_base = ioremap(davinci_soc_info.intc_base, SZ_4K);
92 if (WARN_ON(!davinci_aintc_base))
Cyril Chemparathybd808942010-05-07 17:06:37 -040093 return;
94
Kevin Hilman7c6337e2007-04-30 19:37:19 +010095 /* Clear all interrupt requests */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010096 davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG0);
97 davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG1);
98 davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG0);
99 davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG1);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100100
101 /* Disable all interrupts */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100102 davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_ENT_REG0);
103 davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_ENT_REG1);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100104
105 /* Interrupts disabled immediately, IRQ entry reflects all */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100106 davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_INCTL_REG);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100107
108 /* we don't use the hardware vector table, just its entry addresses */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100109 davinci_aintc_writel(0, DAVINCI_AINTC_IRQ_EABASE_REG);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100110
111 /* Clear all interrupt requests */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100112 davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG0);
113 davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG1);
114 davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG0);
115 davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG1);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100116
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100117 for (i = DAVINCI_AINTC_IRQ_INTPRI0_REG;
118 i <= DAVINCI_AINTC_IRQ_INTPRI7_REG; i += 4) {
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100119 u32 pri;
120
Sudhakar Rajashekhara9e164692009-04-14 07:53:02 -0500121 for (j = 0, pri = 0; j < 32; j += 4, davinci_def_priorities++)
122 pri |= (*davinci_def_priorities & 0x07) << j;
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100123 davinci_aintc_writel(pri, i);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100124 }
125
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100126 irq_base = irq_alloc_descs(-1, 0, davinci_soc_info.intc_irq_num, 0);
127 if (WARN_ON(irq_base < 0))
128 return;
129
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100130 davinci_aintc_irq_domain = irq_domain_add_legacy(NULL,
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100131 davinci_soc_info.intc_irq_num,
132 irq_base, 0, &irq_domain_simple_ops,
133 NULL);
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100134 if (WARN_ON(!davinci_aintc_irq_domain))
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100135 return;
136
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100137 ret = irq_alloc_domain_generic_chips(davinci_aintc_irq_domain, 32, 1,
138 "AINTC", handle_edge_irq,
139 IRQ_NOREQUEST | IRQ_NOPROBE, 0, 0);
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100140 if (WARN_ON(ret))
141 return;
142
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100143 for (i = 0, j = 0; i < davinci_soc_info.intc_irq_num;
144 i += 32, j += 0x04)
145 davinci_aintc_setup_gc(davinci_aintc_base + j,
146 irq_base + i, 32);
Thomas Gleixneraac4dd12011-04-15 11:19:57 +0200147
Bartosz Golaszewskia98ca732019-02-14 15:52:01 +0100148 irq_set_handler(DAVINCI_INTC_IRQ(IRQ_TINT1_TINT34), handle_level_irq);
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100149 set_handle_irq(davinci_aintc_handle_irq);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100150}