blob: 494c2e21b538a0b060a5c3044fc34acfa1e5f09c [file] [log] [blame]
Rob Herringa900e5d2013-02-12 16:04:52 -06001/*
2 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
4 *
5 * Combiner irqchip for EXYNOS
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/err.h>
12#include <linux/export.h>
13#include <linux/init.h>
14#include <linux/io.h>
Arnd Bergmannd34f03d2013-04-10 15:31:11 +020015#include <linux/slab.h>
Rob Herringa900e5d2013-02-12 16:04:52 -060016#include <linux/irqdomain.h>
17#include <linux/of_address.h>
18#include <linux/of_irq.h>
19#include <asm/mach/irq.h>
20
Arnd Bergmann92c8e492013-04-10 15:59:58 +020021#ifdef CONFIG_EXYNOS_ATAGS
Rob Herringa900e5d2013-02-12 16:04:52 -060022#include <plat/cpu.h>
Arnd Bergmann92c8e492013-04-10 15:59:58 +020023#endif
Rob Herringa900e5d2013-02-12 16:04:52 -060024
25#include "irqchip.h"
26
27#define COMBINER_ENABLE_SET 0x0
28#define COMBINER_ENABLE_CLEAR 0x4
29#define COMBINER_INT_STATUS 0xC
30
Arnd Bergmann6761dcf2013-04-10 15:17:47 +020031#define IRQ_IN_COMBINER 8
32
Rob Herringa900e5d2013-02-12 16:04:52 -060033static DEFINE_SPINLOCK(irq_controller_lock);
34
35struct combiner_chip_data {
Arnd Bergmann20adee82013-04-18 23:57:26 +020036 unsigned int hwirq_offset;
Rob Herringa900e5d2013-02-12 16:04:52 -060037 unsigned int irq_mask;
38 void __iomem *base;
Chanho Parkdf7ef462012-12-12 14:02:45 +090039 unsigned int parent_irq;
Rob Herringa900e5d2013-02-12 16:04:52 -060040};
41
42static struct irq_domain *combiner_irq_domain;
Rob Herringa900e5d2013-02-12 16:04:52 -060043
44static inline void __iomem *combiner_base(struct irq_data *data)
45{
46 struct combiner_chip_data *combiner_data =
47 irq_data_get_irq_chip_data(data);
48
49 return combiner_data->base;
50}
51
52static void combiner_mask_irq(struct irq_data *data)
53{
54 u32 mask = 1 << (data->hwirq % 32);
55
56 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR);
57}
58
59static void combiner_unmask_irq(struct irq_data *data)
60{
61 u32 mask = 1 << (data->hwirq % 32);
62
63 __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET);
64}
65
66static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
67{
68 struct combiner_chip_data *chip_data = irq_get_handler_data(irq);
69 struct irq_chip *chip = irq_get_chip(irq);
70 unsigned int cascade_irq, combiner_irq;
71 unsigned long status;
72
73 chained_irq_enter(chip, desc);
74
75 spin_lock(&irq_controller_lock);
76 status = __raw_readl(chip_data->base + COMBINER_INT_STATUS);
77 spin_unlock(&irq_controller_lock);
78 status &= chip_data->irq_mask;
79
80 if (status == 0)
81 goto out;
82
Arnd Bergmann20adee82013-04-18 23:57:26 +020083 combiner_irq = chip_data->hwirq_offset + __ffs(status);
84 cascade_irq = irq_find_mapping(combiner_irq_domain, combiner_irq);
Rob Herringa900e5d2013-02-12 16:04:52 -060085
Arnd Bergmann20adee82013-04-18 23:57:26 +020086 if (unlikely(!cascade_irq))
87 do_bad_IRQ(irq, desc);
Rob Herringa900e5d2013-02-12 16:04:52 -060088 else
89 generic_handle_irq(cascade_irq);
90
91 out:
92 chained_irq_exit(chip, desc);
93}
94
Chanho Parkdf7ef462012-12-12 14:02:45 +090095#ifdef CONFIG_SMP
96static int combiner_set_affinity(struct irq_data *d,
97 const struct cpumask *mask_val, bool force)
98{
99 struct combiner_chip_data *chip_data = irq_data_get_irq_chip_data(d);
100 struct irq_chip *chip = irq_get_chip(chip_data->parent_irq);
101 struct irq_data *data = irq_get_irq_data(chip_data->parent_irq);
102
103 if (chip && chip->irq_set_affinity)
104 return chip->irq_set_affinity(data, mask_val, force);
105 else
106 return -EINVAL;
107}
108#endif
109
Rob Herringa900e5d2013-02-12 16:04:52 -0600110static struct irq_chip combiner_chip = {
Chanho Parkdf7ef462012-12-12 14:02:45 +0900111 .name = "COMBINER",
112 .irq_mask = combiner_mask_irq,
113 .irq_unmask = combiner_unmask_irq,
114#ifdef CONFIG_SMP
115 .irq_set_affinity = combiner_set_affinity,
116#endif
Rob Herringa900e5d2013-02-12 16:04:52 -0600117};
118
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200119static void __init combiner_cascade_irq(struct combiner_chip_data *combiner_data,
Chanho Park4e164dc2012-12-12 14:02:49 +0900120 unsigned int irq)
121{
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200122 if (irq_set_handler_data(irq, combiner_data) != 0)
Rob Herringa900e5d2013-02-12 16:04:52 -0600123 BUG();
124 irq_set_chained_handler(irq, combiner_handle_cascade_irq);
125}
126
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200127static void __init combiner_init_one(struct combiner_chip_data *combiner_data,
128 unsigned int combiner_nr,
Chanho Parkdf7ef462012-12-12 14:02:45 +0900129 void __iomem *base, unsigned int irq)
Rob Herringa900e5d2013-02-12 16:04:52 -0600130{
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200131 combiner_data->base = base;
Arnd Bergmann20adee82013-04-18 23:57:26 +0200132 combiner_data->hwirq_offset = (combiner_nr & ~3) * IRQ_IN_COMBINER;
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200133 combiner_data->irq_mask = 0xff << ((combiner_nr % 4) << 3);
134 combiner_data->parent_irq = irq;
Rob Herringa900e5d2013-02-12 16:04:52 -0600135
136 /* Disable all interrupts */
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200137 __raw_writel(combiner_data->irq_mask, base + COMBINER_ENABLE_CLEAR);
Rob Herringa900e5d2013-02-12 16:04:52 -0600138}
139
140#ifdef CONFIG_OF
141static int combiner_irq_domain_xlate(struct irq_domain *d,
142 struct device_node *controller,
143 const u32 *intspec, unsigned int intsize,
144 unsigned long *out_hwirq,
145 unsigned int *out_type)
146{
147 if (d->of_node != controller)
148 return -EINVAL;
149
150 if (intsize < 2)
151 return -EINVAL;
152
Arnd Bergmann6761dcf2013-04-10 15:17:47 +0200153 *out_hwirq = intspec[0] * IRQ_IN_COMBINER + intspec[1];
Rob Herringa900e5d2013-02-12 16:04:52 -0600154 *out_type = 0;
155
156 return 0;
157}
158#else
159static int combiner_irq_domain_xlate(struct irq_domain *d,
160 struct device_node *controller,
161 const u32 *intspec, unsigned int intsize,
162 unsigned long *out_hwirq,
163 unsigned int *out_type)
164{
165 return -EINVAL;
166}
167#endif
168
169static int combiner_irq_domain_map(struct irq_domain *d, unsigned int irq,
170 irq_hw_number_t hw)
171{
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200172 struct combiner_chip_data *combiner_data = d->host_data;
173
Rob Herringa900e5d2013-02-12 16:04:52 -0600174 irq_set_chip_and_handler(irq, &combiner_chip, handle_level_irq);
175 irq_set_chip_data(irq, &combiner_data[hw >> 3]);
176 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
177
178 return 0;
179}
180
181static struct irq_domain_ops combiner_irq_domain_ops = {
182 .xlate = combiner_irq_domain_xlate,
183 .map = combiner_irq_domain_map,
184};
185
Arnd Bergmann92c8e492013-04-10 15:59:58 +0200186static unsigned int combiner_lookup_irq(int group)
Chanho Park4e164dc2012-12-12 14:02:49 +0900187{
Arnd Bergmann92c8e492013-04-10 15:59:58 +0200188#ifdef CONFIG_EXYNOS_ATAGS
189 if (group < EXYNOS4210_MAX_COMBINER_NR || soc_is_exynos5250())
190 return IRQ_SPI(group);
191
Chanho Park4e164dc2012-12-12 14:02:49 +0900192 switch (group) {
193 case 16:
194 return IRQ_SPI(107);
195 case 17:
196 return IRQ_SPI(108);
197 case 18:
198 return IRQ_SPI(48);
199 case 19:
200 return IRQ_SPI(42);
Chanho Park4e164dc2012-12-12 14:02:49 +0900201 }
Arnd Bergmann92c8e492013-04-10 15:59:58 +0200202#endif
203 return 0;
Chanho Park4e164dc2012-12-12 14:02:49 +0900204}
205
Rob Herringa900e5d2013-02-12 16:04:52 -0600206void __init combiner_init(void __iomem *combiner_base,
Arnd Bergmann6761dcf2013-04-10 15:17:47 +0200207 struct device_node *np,
Arnd Bergmann863a08d2013-04-12 15:27:09 +0200208 unsigned int max_nr,
209 int irq_base)
Rob Herringa900e5d2013-02-12 16:04:52 -0600210{
Arnd Bergmann863a08d2013-04-12 15:27:09 +0200211 int i, irq;
Arnd Bergmann6761dcf2013-04-10 15:17:47 +0200212 unsigned int nr_irq;
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200213 struct combiner_chip_data *combiner_data;
Rob Herringa900e5d2013-02-12 16:04:52 -0600214
Arnd Bergmann6761dcf2013-04-10 15:17:47 +0200215 nr_irq = max_nr * IRQ_IN_COMBINER;
Rob Herringa900e5d2013-02-12 16:04:52 -0600216
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200217 combiner_data = kcalloc(max_nr, sizeof (*combiner_data), GFP_KERNEL);
218 if (!combiner_data) {
219 pr_warning("%s: could not allocate combiner data\n", __func__);
220 return;
221 }
222
Arnd Bergmann863a08d2013-04-12 15:27:09 +0200223 combiner_irq_domain = irq_domain_add_simple(np, nr_irq, irq_base,
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200224 &combiner_irq_domain_ops, combiner_data);
Rob Herringa900e5d2013-02-12 16:04:52 -0600225 if (WARN_ON(!combiner_irq_domain)) {
226 pr_warning("%s: irq domain init failed\n", __func__);
227 return;
228 }
229
230 for (i = 0; i < max_nr; i++) {
Rob Herringa900e5d2013-02-12 16:04:52 -0600231#ifdef CONFIG_OF
232 if (np)
233 irq = irq_of_parse_and_map(np, i);
Arnd Bergmann92c8e492013-04-10 15:59:58 +0200234 else
Rob Herringa900e5d2013-02-12 16:04:52 -0600235#endif
Arnd Bergmann92c8e492013-04-10 15:59:58 +0200236 irq = combiner_lookup_irq(i);
237
Arnd Bergmannd34f03d2013-04-10 15:31:11 +0200238 combiner_init_one(&combiner_data[i], i,
239 combiner_base + (i >> 2) * 0x10, irq);
240 combiner_cascade_irq(&combiner_data[i], irq);
Rob Herringa900e5d2013-02-12 16:04:52 -0600241 }
242}
243
244#ifdef CONFIG_OF
245static int __init combiner_of_init(struct device_node *np,
246 struct device_node *parent)
247{
248 void __iomem *combiner_base;
Arnd Bergmann6761dcf2013-04-10 15:17:47 +0200249 unsigned int max_nr = 20;
Arnd Bergmann863a08d2013-04-12 15:27:09 +0200250 int irq_base = -1;
Rob Herringa900e5d2013-02-12 16:04:52 -0600251
252 combiner_base = of_iomap(np, 0);
253 if (!combiner_base) {
254 pr_err("%s: failed to map combiner registers\n", __func__);
255 return -ENXIO;
256 }
257
Arnd Bergmann6761dcf2013-04-10 15:17:47 +0200258 if (of_property_read_u32(np, "samsung,combiner-nr", &max_nr)) {
259 pr_info("%s: number of combiners not specified, "
260 "setting default as %d.\n",
261 __func__, max_nr);
262 }
263
Arnd Bergmann863a08d2013-04-12 15:27:09 +0200264 /*
265 * FIXME: This is a hardwired COMBINER_IRQ(0,0). Once all devices
266 * get their IRQ from DT, remove this in order to get dynamic
267 * allocation.
268 */
269 irq_base = 160;
270
271 combiner_init(combiner_base, np, max_nr, irq_base);
Rob Herringa900e5d2013-02-12 16:04:52 -0600272
273 return 0;
274}
275IRQCHIP_DECLARE(exynos4210_combiner, "samsung,exynos4210-combiner",
276 combiner_of_init);
277#endif