blob: 5bce936af5d9840ab1fc9ee5853b73fd93f342cc [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Alexey Charkov21f47fb2010-12-23 13:11:21 +01002/*
3 * arch/arm/mach-vt8500/irq.c
4 *
Tony Priske9a91de2012-08-03 21:00:06 +12005 * Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz>
Alexey Charkov21f47fb2010-12-23 13:11:21 +01006 * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
Alexey Charkov21f47fb2010-12-23 13:11:21 +01007 */
8
Tony Priske9a91de2012-08-03 21:00:06 +12009/*
10 * This file is copied and modified from the original irq.c provided by
11 * Alexey Charkov. Minor changes have been made for Device Tree Support.
12 */
13
14#include <linux/slab.h>
Alexey Charkov21f47fb2010-12-23 13:11:21 +010015#include <linux/io.h>
16#include <linux/irq.h>
Joel Porquet41a83e062015-07-07 17:11:46 -040017#include <linux/irqchip.h>
Tony Priske9a91de2012-08-03 21:00:06 +120018#include <linux/irqdomain.h>
Alexey Charkov21f47fb2010-12-23 13:11:21 +010019#include <linux/interrupt.h>
Tony Priske9a91de2012-08-03 21:00:06 +120020#include <linux/bitops.h>
21
22#include <linux/of.h>
23#include <linux/of_irq.h>
24#include <linux/of_address.h>
Alexey Charkov21f47fb2010-12-23 13:11:21 +010025
26#include <asm/irq.h>
Tony Prisk0c464d52012-10-10 20:59:32 +130027#include <asm/exception.h>
Tony Prisk06ff14c2013-03-24 01:12:25 +000028#include <asm/mach/irq.h>
29
Tony Priske9a91de2012-08-03 21:00:06 +120030#define VT8500_ICPC_IRQ 0x20
31#define VT8500_ICPC_FIQ 0x24
32#define VT8500_ICDC 0x40 /* Destination Control 64*u32 */
33#define VT8500_ICIS 0x80 /* Interrupt status, 16*u32 */
34
35/* ICPC */
36#define ICPC_MASK 0x3F
37#define ICPC_ROTATE BIT(6)
38
39/* IC_DCTR */
40#define ICDC_IRQ 0x00
41#define ICDC_FIQ 0x01
42#define ICDC_DSS0 0x02
43#define ICDC_DSS1 0x03
44#define ICDC_DSS2 0x04
45#define ICDC_DSS3 0x05
46#define ICDC_DSS4 0x06
47#define ICDC_DSS5 0x07
48
49#define VT8500_INT_DISABLE 0
50#define VT8500_INT_ENABLE BIT(3)
51
52#define VT8500_TRIGGER_HIGH 0
53#define VT8500_TRIGGER_RISING BIT(5)
54#define VT8500_TRIGGER_FALLING BIT(6)
Alexey Charkov21f47fb2010-12-23 13:11:21 +010055#define VT8500_EDGE ( VT8500_TRIGGER_RISING \
56 | VT8500_TRIGGER_FALLING)
Alexey Charkov21f47fb2010-12-23 13:11:21 +010057
Tony Prisk0c464d52012-10-10 20:59:32 +130058/* vt8500 has 1 intc, wm8505 and wm8650 have 2 */
59#define VT8500_INTC_MAX 2
Tony Priske9a91de2012-08-03 21:00:06 +120060
Tony Prisk0c464d52012-10-10 20:59:32 +130061struct vt8500_irq_data {
62 void __iomem *base; /* IO Memory base address */
63 struct irq_domain *domain; /* Domain for this controller */
Tony Priske9a91de2012-08-03 21:00:06 +120064};
Alexey Charkov21f47fb2010-12-23 13:11:21 +010065
Tony Prisk0c464d52012-10-10 20:59:32 +130066/* Global variable for accessing io-mem addresses */
67static struct vt8500_irq_data intc[VT8500_INTC_MAX];
68static u32 active_cnt = 0;
69
Wolfram Sang2eb5af42011-06-28 09:53:20 +010070static void vt8500_irq_mask(struct irq_data *d)
Alexey Charkov21f47fb2010-12-23 13:11:21 +010071{
Tony Prisk0c464d52012-10-10 20:59:32 +130072 struct vt8500_irq_data *priv = d->domain->host_data;
Tony Priske9a91de2012-08-03 21:00:06 +120073 void __iomem *base = priv->base;
Tony Prisk0c464d52012-10-10 20:59:32 +130074 void __iomem *stat_reg = base + VT8500_ICIS + (d->hwirq < 32 ? 0 : 4);
75 u8 edge, dctr;
76 u32 status;
Alexey Charkov21f47fb2010-12-23 13:11:21 +010077
Tony Priske9a91de2012-08-03 21:00:06 +120078 edge = readb(base + VT8500_ICDC + d->hwirq) & VT8500_EDGE;
Alexey Charkov21f47fb2010-12-23 13:11:21 +010079 if (edge) {
Tony Prisk0c464d52012-10-10 20:59:32 +130080 status = readl(stat_reg);
Alexey Charkov21f47fb2010-12-23 13:11:21 +010081
Tony Priske9a91de2012-08-03 21:00:06 +120082 status |= (1 << (d->hwirq & 0x1f));
Alexey Charkov21f47fb2010-12-23 13:11:21 +010083 writel(status, stat_reg);
84 } else {
Tony Prisk0c464d52012-10-10 20:59:32 +130085 dctr = readb(base + VT8500_ICDC + d->hwirq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +010086 dctr &= ~VT8500_INT_ENABLE;
Tony Priske9a91de2012-08-03 21:00:06 +120087 writeb(dctr, base + VT8500_ICDC + d->hwirq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +010088 }
89}
90
Wolfram Sang2eb5af42011-06-28 09:53:20 +010091static void vt8500_irq_unmask(struct irq_data *d)
Alexey Charkov21f47fb2010-12-23 13:11:21 +010092{
Tony Prisk0c464d52012-10-10 20:59:32 +130093 struct vt8500_irq_data *priv = d->domain->host_data;
Tony Priske9a91de2012-08-03 21:00:06 +120094 void __iomem *base = priv->base;
Alexey Charkov21f47fb2010-12-23 13:11:21 +010095 u8 dctr;
96
Tony Priske9a91de2012-08-03 21:00:06 +120097 dctr = readb(base + VT8500_ICDC + d->hwirq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +010098 dctr |= VT8500_INT_ENABLE;
Tony Priske9a91de2012-08-03 21:00:06 +120099 writeb(dctr, base + VT8500_ICDC + d->hwirq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100100}
101
Wolfram Sang2eb5af42011-06-28 09:53:20 +0100102static int vt8500_irq_set_type(struct irq_data *d, unsigned int flow_type)
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100103{
Tony Prisk0c464d52012-10-10 20:59:32 +1300104 struct vt8500_irq_data *priv = d->domain->host_data;
Tony Priske9a91de2012-08-03 21:00:06 +1200105 void __iomem *base = priv->base;
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100106 u8 dctr;
107
Tony Priske9a91de2012-08-03 21:00:06 +1200108 dctr = readb(base + VT8500_ICDC + d->hwirq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100109 dctr &= ~VT8500_EDGE;
110
111 switch (flow_type) {
112 case IRQF_TRIGGER_LOW:
113 return -EINVAL;
114 case IRQF_TRIGGER_HIGH:
115 dctr |= VT8500_TRIGGER_HIGH;
Thomas Gleixnerd2aa9142015-06-23 15:52:41 +0200116 irq_set_handler_locked(d, handle_level_irq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100117 break;
118 case IRQF_TRIGGER_FALLING:
119 dctr |= VT8500_TRIGGER_FALLING;
Thomas Gleixnerd2aa9142015-06-23 15:52:41 +0200120 irq_set_handler_locked(d, handle_edge_irq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100121 break;
122 case IRQF_TRIGGER_RISING:
123 dctr |= VT8500_TRIGGER_RISING;
Thomas Gleixnerd2aa9142015-06-23 15:52:41 +0200124 irq_set_handler_locked(d, handle_edge_irq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100125 break;
126 }
Tony Priske9a91de2012-08-03 21:00:06 +1200127 writeb(dctr, base + VT8500_ICDC + d->hwirq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100128
129 return 0;
130}
131
132static struct irq_chip vt8500_irq_chip = {
Wolfram Sang2eb5af42011-06-28 09:53:20 +0100133 .name = "vt8500",
134 .irq_ack = vt8500_irq_mask,
135 .irq_mask = vt8500_irq_mask,
136 .irq_unmask = vt8500_irq_unmask,
137 .irq_set_type = vt8500_irq_set_type,
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100138};
139
Tony Priske9a91de2012-08-03 21:00:06 +1200140static void __init vt8500_init_irq_hw(void __iomem *base)
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100141{
Tony Prisk0c464d52012-10-10 20:59:32 +1300142 u32 i;
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100143
Tony Priske9a91de2012-08-03 21:00:06 +1200144 /* Enable rotating priority for IRQ */
145 writel(ICPC_ROTATE, base + VT8500_ICPC_IRQ);
146 writel(0x00, base + VT8500_ICPC_FIQ);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100147
Tony Prisk0c464d52012-10-10 20:59:32 +1300148 /* Disable all interrupts and route them to IRQ */
149 for (i = 0; i < 64; i++)
150 writeb(VT8500_INT_DISABLE | ICDC_IRQ, base + VT8500_ICDC + i);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100151}
152
Tony Priske9a91de2012-08-03 21:00:06 +1200153static int vt8500_irq_map(struct irq_domain *h, unsigned int virq,
154 irq_hw_number_t hw)
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100155{
Tony Priske9a91de2012-08-03 21:00:06 +1200156 irq_set_chip_and_handler(virq, &vt8500_irq_chip, handle_level_irq);
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100157
Tony Priske9a91de2012-08-03 21:00:06 +1200158 return 0;
Alexey Charkov21f47fb2010-12-23 13:11:21 +0100159}
Tony Priske9a91de2012-08-03 21:00:06 +1200160
Krzysztof Kozlowski96009732015-04-27 21:54:24 +0900161static const struct irq_domain_ops vt8500_irq_domain_ops = {
Tony Priske9a91de2012-08-03 21:00:06 +1200162 .map = vt8500_irq_map,
163 .xlate = irq_domain_xlate_onecell,
164};
165
Stephen Boyd8783dd32014-03-04 16:40:30 -0800166static void __exception_irq_entry vt8500_handle_irq(struct pt_regs *regs)
Tony Prisk0c464d52012-10-10 20:59:32 +1300167{
168 u32 stat, i;
Marc Zyngier0beb6502014-08-26 11:03:31 +0100169 int irqnr;
Tony Prisk0c464d52012-10-10 20:59:32 +1300170 void __iomem *base;
171
172 /* Loop through each active controller */
173 for (i=0; i<active_cnt; i++) {
174 base = intc[i].base;
175 irqnr = readl_relaxed(base) & 0x3F;
176 /*
177 Highest Priority register default = 63, so check that this
178 is a real interrupt by checking the status register
179 */
180 if (irqnr == 63) {
181 stat = readl_relaxed(base + VT8500_ICIS + 4);
182 if (!(stat & BIT(31)))
183 continue;
184 }
185
Marc Zyngier0beb6502014-08-26 11:03:31 +0100186 handle_domain_irq(intc[i].domain, irqnr, regs);
Tony Prisk0c464d52012-10-10 20:59:32 +1300187 }
188}
189
Axel Line6587182013-07-05 11:33:49 +0800190static int __init vt8500_irq_init(struct device_node *node,
191 struct device_node *parent)
Tony Priske9a91de2012-08-03 21:00:06 +1200192{
Tony Priske9a91de2012-08-03 21:00:06 +1200193 int irq, i;
194 struct device_node *np = node;
195
Tony Prisk0c464d52012-10-10 20:59:32 +1300196 if (active_cnt == VT8500_INTC_MAX) {
197 pr_err("%s: Interrupt controllers > VT8500_INTC_MAX\n",
198 __func__);
199 goto out;
200 }
Tony Priske9a91de2012-08-03 21:00:06 +1200201
Tony Prisk0c464d52012-10-10 20:59:32 +1300202 intc[active_cnt].base = of_iomap(np, 0);
203 intc[active_cnt].domain = irq_domain_add_linear(node, 64,
204 &vt8500_irq_domain_ops, &intc[active_cnt]);
Tony Priske9a91de2012-08-03 21:00:06 +1200205
Tony Prisk0c464d52012-10-10 20:59:32 +1300206 if (!intc[active_cnt].base) {
207 pr_err("%s: Unable to map IO memory\n", __func__);
208 goto out;
209 }
Tony Priske9a91de2012-08-03 21:00:06 +1200210
Tony Prisk0c464d52012-10-10 20:59:32 +1300211 if (!intc[active_cnt].domain) {
212 pr_err("%s: Unable to add irq domain!\n", __func__);
213 goto out;
214 }
Tony Priske9a91de2012-08-03 21:00:06 +1200215
Tony Prisk06ff14c2013-03-24 01:12:25 +0000216 set_handle_irq(vt8500_handle_irq);
217
Tony Prisk0c464d52012-10-10 20:59:32 +1300218 vt8500_init_irq_hw(intc[active_cnt].base);
219
220 pr_info("vt8500-irq: Added interrupt controller\n");
221
222 active_cnt++;
Tony Priske9a91de2012-08-03 21:00:06 +1200223
224 /* check if this is a slaved controller */
225 if (of_irq_count(np) != 0) {
226 /* check that we have the correct number of interrupts */
227 if (of_irq_count(np) != 8) {
Tony Prisk0c464d52012-10-10 20:59:32 +1300228 pr_err("%s: Incorrect IRQ map for slaved controller\n",
Tony Priske9a91de2012-08-03 21:00:06 +1200229 __func__);
230 return -EINVAL;
231 }
232
233 for (i = 0; i < 8; i++) {
234 irq = irq_of_parse_and_map(np, i);
235 enable_irq(irq);
236 }
237
238 pr_info("vt8500-irq: Enabled slave->parent interrupts\n");
239 }
Tony Prisk0c464d52012-10-10 20:59:32 +1300240out:
Tony Priske9a91de2012-08-03 21:00:06 +1200241 return 0;
242}
243
Tony Prisk06ff14c2013-03-24 01:12:25 +0000244IRQCHIP_DECLARE(vt8500_irq, "via,vt8500-intc", vt8500_irq_init);