blob: 2b6943731af9ef06340573708c6f624bb420fca2 [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>
Bartosz Golaszewski06a28712019-02-14 15:52:11 +010011#include <linux/irqchip/irq-davinci-aintc.h>
Russell Kingfced80c2008-09-06 12:10:45 +010012#include <linux/io.h>
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010013#include <linux/irqdomain.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010014
Russell Kinga09e64f2008-08-05 16:14:15 +010015#include <mach/hardware.h>
Sudhakar Rajashekhara9e164692009-04-14 07:53:02 -050016#include <mach/cputype.h>
Mark A. Greer673dd362009-04-15 12:40:00 -070017#include <mach/common.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010018#include <asm/mach/irq.h>
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010019#include <asm/exception.h>
Kevin Hilman7c6337e2007-04-30 19:37:19 +010020
Bartosz Golaszewski544ca0b2019-02-14 15:52:03 +010021#include "irqs.h"
22
Bartosz Golaszewski919da6f12019-02-14 15:52:07 +010023#define DAVINCI_AINTC_FIQ_REG0 0x00
24#define DAVINCI_AINTC_FIQ_REG1 0x04
25#define DAVINCI_AINTC_IRQ_REG0 0x08
26#define DAVINCI_AINTC_IRQ_REG1 0x0c
27#define DAVINCI_AINTC_IRQ_IRQENTRY 0x14
28#define DAVINCI_AINTC_IRQ_ENT_REG0 0x18
29#define DAVINCI_AINTC_IRQ_ENT_REG1 0x1c
30#define DAVINCI_AINTC_IRQ_INCTL_REG 0x20
31#define DAVINCI_AINTC_IRQ_EABASE_REG 0x24
32#define DAVINCI_AINTC_IRQ_INTPRI0_REG 0x30
33#define DAVINCI_AINTC_IRQ_INTPRI7_REG 0x4c
Kevin Hilman7c6337e2007-04-30 19:37:19 +010034
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010035static void __iomem *davinci_aintc_base;
36static struct irq_domain *davinci_aintc_irq_domain;
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010037
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010038static inline void davinci_aintc_writel(unsigned long value, int offset)
Kevin Hilman7c6337e2007-04-30 19:37:19 +010039{
Bartosz Golaszewskif4123842019-02-14 15:52:08 +010040 writel_relaxed(value, davinci_aintc_base + offset);
Kevin Hilman7c6337e2007-04-30 19:37:19 +010041}
42
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010043static inline unsigned long davinci_aintc_readl(int offset)
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010044{
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010045 return readl_relaxed(davinci_aintc_base + offset);
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010046}
47
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020048static __init void
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010049davinci_aintc_setup_gc(void __iomem *base,
50 unsigned int irq_start, unsigned int num)
Kevin Hilman7c6337e2007-04-30 19:37:19 +010051{
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020052 struct irq_chip_generic *gc;
53 struct irq_chip_type *ct;
Kevin Hilman7c6337e2007-04-30 19:37:19 +010054
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010055 gc = irq_get_domain_generic_chip(davinci_aintc_irq_domain, irq_start);
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010056 gc->reg_base = base;
57 gc->irq_base = irq_start;
Todd Poynor33e1e5e2011-07-16 22:39:35 -070058
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020059 ct = gc->chip_types;
Simon Guinot659fb322011-07-06 12:41:31 -040060 ct->chip.irq_ack = irq_gc_ack_set_bit;
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020061 ct->chip.irq_mask = irq_gc_mask_clr_bit;
62 ct->chip.irq_unmask = irq_gc_mask_set_bit;
Kevin Hilman7c6337e2007-04-30 19:37:19 +010063
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010064 ct->regs.ack = DAVINCI_AINTC_IRQ_REG0;
65 ct->regs.mask = DAVINCI_AINTC_IRQ_ENT_REG0;
Thomas Gleixneraac4dd12011-04-15 11:19:57 +020066 irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
67 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
Kevin Hilman7c6337e2007-04-30 19:37:19 +010068}
69
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010070static asmlinkage void __exception_irq_entry
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010071davinci_aintc_handle_irq(struct pt_regs *regs)
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010072{
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010073 int irqnr = davinci_aintc_readl(DAVINCI_AINTC_IRQ_IRQENTRY);
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010074
75 /*
76 * Use the formula for entry vector index generation from section
77 * 8.3.3 of the manual.
78 */
79 irqnr >>= 2;
80 irqnr -= 1;
81
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +010082 handle_domain_irq(davinci_aintc_irq_domain, irqnr, regs);
Bartosz Golaszewskid0064592019-02-14 15:51:58 +010083}
84
Kevin Hilman7c6337e2007-04-30 19:37:19 +010085/* ARM Interrupt Controller Initialization */
Bartosz Golaszewski06a28712019-02-14 15:52:11 +010086void __init davinci_aintc_init(const struct davinci_aintc_config *config)
Kevin Hilman7c6337e2007-04-30 19:37:19 +010087{
Bartosz Golaszewski06a28712019-02-14 15:52:11 +010088 unsigned int irq_off, reg_off, prio, shift;
Bartosz Golaszewski882bed72019-02-14 15:52:13 +010089 void __iomem *req;
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +010090 int ret, irq_base;
Bartosz Golaszewski06a28712019-02-14 15:52:11 +010091 const u8 *prios;
Kevin Hilman7c6337e2007-04-30 19:37:19 +010092
Bartosz Golaszewski882bed72019-02-14 15:52:13 +010093 req = request_mem_region(config->reg.start,
94 resource_size(&config->reg),
95 "davinci-cp-intc");
96 if (!req) {
97 pr_err("%s: register range busy\n", __func__);
98 return;
99 }
100
Bartosz Golaszewski06a28712019-02-14 15:52:11 +0100101 davinci_aintc_base = ioremap(config->reg.start,
102 resource_size(&config->reg));
Bartosz Golaszewskia6c0bba2019-02-14 15:52:12 +0100103 if (!davinci_aintc_base) {
104 pr_err("%s: unable to ioremap register range\n", __func__);
Cyril Chemparathybd808942010-05-07 17:06:37 -0400105 return;
Bartosz Golaszewskia6c0bba2019-02-14 15:52:12 +0100106 }
Cyril Chemparathybd808942010-05-07 17:06:37 -0400107
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100108 /* Clear all interrupt requests */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100109 davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG0);
110 davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG1);
111 davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG0);
112 davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG1);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100113
114 /* Disable all interrupts */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100115 davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_ENT_REG0);
116 davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_ENT_REG1);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100117
118 /* Interrupts disabled immediately, IRQ entry reflects all */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100119 davinci_aintc_writel(0x0, DAVINCI_AINTC_IRQ_INCTL_REG);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100120
121 /* we don't use the hardware vector table, just its entry addresses */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100122 davinci_aintc_writel(0, DAVINCI_AINTC_IRQ_EABASE_REG);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100123
124 /* Clear all interrupt requests */
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100125 davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG0);
126 davinci_aintc_writel(~0x0, DAVINCI_AINTC_FIQ_REG1);
127 davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG0);
128 davinci_aintc_writel(~0x0, DAVINCI_AINTC_IRQ_REG1);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100129
Bartosz Golaszewski06a28712019-02-14 15:52:11 +0100130 prios = config->prios;
131 for (reg_off = DAVINCI_AINTC_IRQ_INTPRI0_REG;
132 reg_off <= DAVINCI_AINTC_IRQ_INTPRI7_REG; reg_off += 4) {
133 for (shift = 0, prio = 0; shift < 32; shift += 4, prios++)
134 prio |= (*prios & 0x07) << shift;
135 davinci_aintc_writel(prio, reg_off);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100136 }
137
Bartosz Golaszewski06a28712019-02-14 15:52:11 +0100138 irq_base = irq_alloc_descs(-1, 0, config->num_irqs, 0);
Bartosz Golaszewskia6c0bba2019-02-14 15:52:12 +0100139 if (irq_base < 0) {
140 pr_err("%s: unable to allocate interrupt descriptors: %d\n",
141 __func__, irq_base);
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100142 return;
Bartosz Golaszewskia6c0bba2019-02-14 15:52:12 +0100143 }
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100144
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100145 davinci_aintc_irq_domain = irq_domain_add_legacy(NULL,
Bartosz Golaszewski06a28712019-02-14 15:52:11 +0100146 config->num_irqs, irq_base, 0,
147 &irq_domain_simple_ops, NULL);
Bartosz Golaszewskia6c0bba2019-02-14 15:52:12 +0100148 if (!davinci_aintc_irq_domain) {
149 pr_err("%s: unable to create interrupt domain\n", __func__);
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100150 return;
Bartosz Golaszewskia6c0bba2019-02-14 15:52:12 +0100151 }
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100152
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100153 ret = irq_alloc_domain_generic_chips(davinci_aintc_irq_domain, 32, 1,
154 "AINTC", handle_edge_irq,
155 IRQ_NOREQUEST | IRQ_NOPROBE, 0, 0);
Bartosz Golaszewskia6c0bba2019-02-14 15:52:12 +0100156 if (ret) {
157 pr_err("%s: unable to allocate generic irq chips for domain\n",
158 __func__);
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100159 return;
Bartosz Golaszewskia6c0bba2019-02-14 15:52:12 +0100160 }
Bartosz Golaszewski74b0eac2019-02-14 15:51:57 +0100161
Bartosz Golaszewski06a28712019-02-14 15:52:11 +0100162 for (irq_off = 0, reg_off = 0;
163 irq_off < config->num_irqs;
164 irq_off += 32, reg_off += 0x04)
165 davinci_aintc_setup_gc(davinci_aintc_base + reg_off,
166 irq_base + irq_off, 32);
Thomas Gleixneraac4dd12011-04-15 11:19:57 +0200167
Bartosz Golaszewskia98ca732019-02-14 15:52:01 +0100168 irq_set_handler(DAVINCI_INTC_IRQ(IRQ_TINT1_TINT34), handle_level_irq);
Bartosz Golaszewski2b6a2e72019-02-14 15:52:06 +0100169 set_handle_irq(davinci_aintc_handle_irq);
Kevin Hilman7c6337e2007-04-30 19:37:19 +0100170}