blob: d2031fecc3861c5144ba5c7688be64342f04e504 [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Heiko Stuebner1f629b72013-01-29 10:25:22 -08002/*
3 * S3C24XX IRQ handling
Ben Dooksa21765a2007-02-11 18:31:01 +01004 *
Ben Dookse02f8662009-11-13 22:54:13 +00005 * Copyright (c) 2003-2004 Simtec Electronics
Ben Dooksa21765a2007-02-11 18:31:01 +01006 * Ben Dooks <ben@simtec.co.uk>
Heiko Stuebner1f629b72013-01-29 10:25:22 -08007 * Copyright (c) 2012 Heiko Stuebner <heiko@sntech.de>
Ben Dooksa21765a2007-02-11 18:31:01 +01008*/
9
10#include <linux/init.h>
Heiko Stuebner1f629b72013-01-29 10:25:22 -080011#include <linux/slab.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010012#include <linux/module.h>
Heiko Stuebner1f629b72013-01-29 10:25:22 -080013#include <linux/io.h>
14#include <linux/err.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010015#include <linux/interrupt.h>
16#include <linux/ioport.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080017#include <linux/device.h>
Heiko Stuebner1f629b72013-01-29 10:25:22 -080018#include <linux/irqdomain.h>
Joel Porquet41a83e062015-07-07 17:11:46 -040019#include <linux/irqchip.h>
Linus Torvalds6fa52ed2013-05-04 12:31:18 -070020#include <linux/irqchip/chained_irq.h>
Heiko Stuebnerf0774d42013-04-04 14:55:10 +090021#include <linux/of.h>
22#include <linux/of_irq.h>
23#include <linux/of_address.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010024
Heiko Stuebner17453dd2013-03-07 12:38:25 +090025#include <asm/exception.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010026#include <asm/mach/irq.h>
27
Heiko Stuebner1f629b72013-01-29 10:25:22 -080028#include <mach/regs-irq.h>
29#include <mach/regs-gpio.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010030
Ben Dooksa2b7ba92008-10-07 22:26:09 +010031#include <plat/cpu.h>
Heiko Stuebner1f629b72013-01-29 10:25:22 -080032#include <plat/regs-irqtype.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010033#include <plat/pm.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010034
Heiko Stuebner1f629b72013-01-29 10:25:22 -080035#define S3C_IRQTYPE_NONE 0
36#define S3C_IRQTYPE_EINT 1
37#define S3C_IRQTYPE_EDGE 2
38#define S3C_IRQTYPE_LEVEL 3
Ben Dooksa21765a2007-02-11 18:31:01 +010039
Heiko Stuebner1f629b72013-01-29 10:25:22 -080040struct s3c_irq_data {
41 unsigned int type;
Heiko Stuebnerf5a25522013-04-04 14:53:52 +090042 unsigned long offset;
Heiko Stuebner1f629b72013-01-29 10:25:22 -080043 unsigned long parent_irq;
Ben Dooksa21765a2007-02-11 18:31:01 +010044
Heiko Stuebner1f629b72013-01-29 10:25:22 -080045 /* data gets filled during init */
46 struct s3c_irq_intc *intc;
47 unsigned long sub_bits;
48 struct s3c_irq_intc *sub_intc;
Ben Dooksa21765a2007-02-11 18:31:01 +010049};
50
Heiko Stuebner1f629b72013-01-29 10:25:22 -080051/*
Ingo Molnarc5f48c02018-12-03 11:44:51 +010052 * Structure holding the controller data
Heiko Stuebner1f629b72013-01-29 10:25:22 -080053 * @reg_pending register holding pending irqs
54 * @reg_intpnd special register intpnd in main intc
55 * @reg_mask mask register
56 * @domain irq_domain of the controller
57 * @parent parent controller for ext and sub irqs
58 * @irqs irq-data, always s3c_irq_data[32]
59 */
60struct s3c_irq_intc {
61 void __iomem *reg_pending;
62 void __iomem *reg_intpnd;
63 void __iomem *reg_mask;
64 struct irq_domain *domain;
65 struct s3c_irq_intc *parent;
66 struct s3c_irq_data *irqs;
Ben Dooksa21765a2007-02-11 18:31:01 +010067};
68
Heiko Stuebner658dc8f2013-04-04 14:53:49 +090069/*
70 * Array holding pointers to the global controller structs
71 * [0] ... main_intc
72 * [1] ... sub_intc
73 * [2] ... main_intc2 on s3c2416
74 */
75static struct s3c_irq_intc *s3c_intc[3];
76
Heiko Stuebner1f629b72013-01-29 10:25:22 -080077static void s3c_irq_mask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +010078{
Heiko Stuebnerf5a25522013-04-04 14:53:52 +090079 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
80 struct s3c_irq_intc *intc = irq_data->intc;
Heiko Stuebner1f629b72013-01-29 10:25:22 -080081 struct s3c_irq_intc *parent_intc = intc->parent;
Heiko Stuebner1f629b72013-01-29 10:25:22 -080082 struct s3c_irq_data *parent_data;
Ben Dooksa21765a2007-02-11 18:31:01 +010083 unsigned long mask;
Heiko Stuebner1f629b72013-01-29 10:25:22 -080084 unsigned int irqno;
Ben Dooksa21765a2007-02-11 18:31:01 +010085
Ben Dooks35333282016-06-21 11:20:30 +010086 mask = readl_relaxed(intc->reg_mask);
Heiko Stuebnerf5a25522013-04-04 14:53:52 +090087 mask |= (1UL << irq_data->offset);
Ben Dooks35333282016-06-21 11:20:30 +010088 writel_relaxed(mask, intc->reg_mask);
Ben Dooksa21765a2007-02-11 18:31:01 +010089
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +090090 if (parent_intc) {
Heiko Stuebner1f629b72013-01-29 10:25:22 -080091 parent_data = &parent_intc->irqs[irq_data->parent_irq];
Ben Dooksa21765a2007-02-11 18:31:01 +010092
Heiko Stuebnerf0774d42013-04-04 14:55:10 +090093 /* check to see if we need to mask the parent IRQ
94 * The parent_irq is always in main_intc, so the hwirq
95 * for find_mapping does not need an offset in any case.
96 */
Heiko Stuebner1f629b72013-01-29 10:25:22 -080097 if ((mask & parent_data->sub_bits) == parent_data->sub_bits) {
98 irqno = irq_find_mapping(parent_intc->domain,
99 irq_data->parent_irq);
100 s3c_irq_mask(irq_get_irq_data(irqno));
101 }
Ben Dooksa21765a2007-02-11 18:31:01 +0100102 }
103}
104
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800105static void s3c_irq_unmask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100106{
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900107 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
108 struct s3c_irq_intc *intc = irq_data->intc;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800109 struct s3c_irq_intc *parent_intc = intc->parent;
Ben Dooksa21765a2007-02-11 18:31:01 +0100110 unsigned long mask;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800111 unsigned int irqno;
Ben Dooksa21765a2007-02-11 18:31:01 +0100112
Ben Dooks35333282016-06-21 11:20:30 +0100113 mask = readl_relaxed(intc->reg_mask);
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900114 mask &= ~(1UL << irq_data->offset);
Ben Dooks35333282016-06-21 11:20:30 +0100115 writel_relaxed(mask, intc->reg_mask);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800116
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900117 if (parent_intc) {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800118 irqno = irq_find_mapping(parent_intc->domain,
119 irq_data->parent_irq);
120 s3c_irq_unmask(irq_get_irq_data(irqno));
121 }
Ben Dooksa21765a2007-02-11 18:31:01 +0100122}
123
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800124static inline void s3c_irq_ack(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100125{
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900126 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
127 struct s3c_irq_intc *intc = irq_data->intc;
128 unsigned long bitval = 1UL << irq_data->offset;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800129
Ben Dooks35333282016-06-21 11:20:30 +0100130 writel_relaxed(bitval, intc->reg_pending);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800131 if (intc->reg_intpnd)
Ben Dooks35333282016-06-21 11:20:30 +0100132 writel_relaxed(bitval, intc->reg_intpnd);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800133}
134
Heiko Stuebnerbd7c0da2013-04-04 14:53:45 +0900135static int s3c_irq_type(struct irq_data *data, unsigned int type)
136{
137 switch (type) {
138 case IRQ_TYPE_NONE:
139 break;
140 case IRQ_TYPE_EDGE_RISING:
141 case IRQ_TYPE_EDGE_FALLING:
142 case IRQ_TYPE_EDGE_BOTH:
143 irq_set_handler(data->irq, handle_edge_irq);
144 break;
145 case IRQ_TYPE_LEVEL_LOW:
146 case IRQ_TYPE_LEVEL_HIGH:
147 irq_set_handler(data->irq, handle_level_irq);
148 break;
149 default:
Arvind Yadav6b15e082017-11-13 19:23:48 +0530150 pr_err("No such irq type %d\n", type);
Heiko Stuebnerbd7c0da2013-04-04 14:53:45 +0900151 return -EINVAL;
152 }
153
154 return 0;
155}
156
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800157static int s3c_irqext_type_set(void __iomem *gpcon_reg,
158 void __iomem *extint_reg,
159 unsigned long gpcon_offset,
160 unsigned long extint_offset,
161 unsigned int type)
162{
Ben Dooksa21765a2007-02-11 18:31:01 +0100163 unsigned long newvalue = 0, value;
164
Ben Dooksa21765a2007-02-11 18:31:01 +0100165 /* Set the GPIO to external interrupt mode */
Ben Dooks35333282016-06-21 11:20:30 +0100166 value = readl_relaxed(gpcon_reg);
Ben Dooksa21765a2007-02-11 18:31:01 +0100167 value = (value & ~(3 << gpcon_offset)) | (0x02 << gpcon_offset);
Ben Dooks35333282016-06-21 11:20:30 +0100168 writel_relaxed(value, gpcon_reg);
Ben Dooksa21765a2007-02-11 18:31:01 +0100169
170 /* Set the external interrupt to pointed trigger type */
171 switch (type)
172 {
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100173 case IRQ_TYPE_NONE:
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800174 pr_warn("No edge setting!\n");
Ben Dooksa21765a2007-02-11 18:31:01 +0100175 break;
176
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100177 case IRQ_TYPE_EDGE_RISING:
Ben Dooksa21765a2007-02-11 18:31:01 +0100178 newvalue = S3C2410_EXTINT_RISEEDGE;
179 break;
180
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100181 case IRQ_TYPE_EDGE_FALLING:
Ben Dooksa21765a2007-02-11 18:31:01 +0100182 newvalue = S3C2410_EXTINT_FALLEDGE;
183 break;
184
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100185 case IRQ_TYPE_EDGE_BOTH:
Ben Dooksa21765a2007-02-11 18:31:01 +0100186 newvalue = S3C2410_EXTINT_BOTHEDGE;
187 break;
188
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100189 case IRQ_TYPE_LEVEL_LOW:
Ben Dooksa21765a2007-02-11 18:31:01 +0100190 newvalue = S3C2410_EXTINT_LOWLEV;
191 break;
192
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100193 case IRQ_TYPE_LEVEL_HIGH:
Ben Dooksa21765a2007-02-11 18:31:01 +0100194 newvalue = S3C2410_EXTINT_HILEV;
195 break;
196
197 default:
Arvind Yadav6b15e082017-11-13 19:23:48 +0530198 pr_err("No such irq type %d\n", type);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800199 return -EINVAL;
Ben Dooksa21765a2007-02-11 18:31:01 +0100200 }
201
Ben Dooks35333282016-06-21 11:20:30 +0100202 value = readl_relaxed(extint_reg);
Ben Dooksa21765a2007-02-11 18:31:01 +0100203 value = (value & ~(7 << extint_offset)) | (newvalue << extint_offset);
Ben Dooks35333282016-06-21 11:20:30 +0100204 writel_relaxed(value, extint_reg);
Ben Dooksa21765a2007-02-11 18:31:01 +0100205
206 return 0;
207}
208
Heiko Stuebnerdc1a3532013-02-12 14:23:01 -0800209static int s3c_irqext_type(struct irq_data *data, unsigned int type)
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800210{
211 void __iomem *extint_reg;
212 void __iomem *gpcon_reg;
213 unsigned long gpcon_offset, extint_offset;
214
215 if ((data->hwirq >= 4) && (data->hwirq <= 7)) {
216 gpcon_reg = S3C2410_GPFCON;
217 extint_reg = S3C24XX_EXTINT0;
218 gpcon_offset = (data->hwirq) * 2;
219 extint_offset = (data->hwirq) * 4;
220 } else if ((data->hwirq >= 8) && (data->hwirq <= 15)) {
221 gpcon_reg = S3C2410_GPGCON;
222 extint_reg = S3C24XX_EXTINT1;
223 gpcon_offset = (data->hwirq - 8) * 2;
224 extint_offset = (data->hwirq - 8) * 4;
225 } else if ((data->hwirq >= 16) && (data->hwirq <= 23)) {
226 gpcon_reg = S3C2410_GPGCON;
227 extint_reg = S3C24XX_EXTINT2;
228 gpcon_offset = (data->hwirq - 8) * 2;
229 extint_offset = (data->hwirq - 16) * 4;
230 } else {
231 return -EINVAL;
232 }
233
234 return s3c_irqext_type_set(gpcon_reg, extint_reg, gpcon_offset,
235 extint_offset, type);
236}
237
238static int s3c_irqext0_type(struct irq_data *data, unsigned int type)
239{
240 void __iomem *extint_reg;
241 void __iomem *gpcon_reg;
242 unsigned long gpcon_offset, extint_offset;
243
Krzysztof Kozlowskif3b28362018-08-13 17:11:44 +0200244 if (data->hwirq <= 3) {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800245 gpcon_reg = S3C2410_GPFCON;
246 extint_reg = S3C24XX_EXTINT0;
247 gpcon_offset = (data->hwirq) * 2;
248 extint_offset = (data->hwirq) * 4;
249 } else {
250 return -EINVAL;
251 }
252
253 return s3c_irqext_type_set(gpcon_reg, extint_reg, gpcon_offset,
254 extint_offset, type);
255}
256
Heiko Stuebnerdc1a3532013-02-12 14:23:01 -0800257static struct irq_chip s3c_irq_chip = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800258 .name = "s3c",
259 .irq_ack = s3c_irq_ack,
260 .irq_mask = s3c_irq_mask,
261 .irq_unmask = s3c_irq_unmask,
Heiko Stuebnerbd7c0da2013-04-04 14:53:45 +0900262 .irq_set_type = s3c_irq_type,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800263 .irq_set_wake = s3c_irq_wake
264};
265
Heiko Stuebnerdc1a3532013-02-12 14:23:01 -0800266static struct irq_chip s3c_irq_level_chip = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800267 .name = "s3c-level",
268 .irq_mask = s3c_irq_mask,
269 .irq_unmask = s3c_irq_unmask,
270 .irq_ack = s3c_irq_ack,
Heiko Stuebnerbd7c0da2013-04-04 14:53:45 +0900271 .irq_set_type = s3c_irq_type,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800272};
273
Ben Dooksa21765a2007-02-11 18:31:01 +0100274static struct irq_chip s3c_irqext_chip = {
275 .name = "s3c-ext",
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800276 .irq_mask = s3c_irq_mask,
277 .irq_unmask = s3c_irq_unmask,
278 .irq_ack = s3c_irq_ack,
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900279 .irq_set_type = s3c_irqext_type,
Mark Brownf5aeffb2010-12-02 14:35:38 +0900280 .irq_set_wake = s3c_irqext_wake
Ben Dooksa21765a2007-02-11 18:31:01 +0100281};
282
283static struct irq_chip s3c_irq_eint0t4 = {
284 .name = "s3c-ext0",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900285 .irq_ack = s3c_irq_ack,
286 .irq_mask = s3c_irq_mask,
287 .irq_unmask = s3c_irq_unmask,
288 .irq_set_wake = s3c_irq_wake,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800289 .irq_set_type = s3c_irqext0_type,
Ben Dooksa21765a2007-02-11 18:31:01 +0100290};
291
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200292static void s3c_irq_demux(struct irq_desc *desc)
Ben Dooksa21765a2007-02-11 18:31:01 +0100293{
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800294 struct irq_chip *chip = irq_desc_get_chip(desc);
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900295 struct s3c_irq_data *irq_data = irq_desc_get_chip_data(desc);
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900296 struct s3c_irq_intc *intc = irq_data->intc;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800297 struct s3c_irq_intc *sub_intc = irq_data->sub_intc;
Thomas Gleixner4df18a62015-07-16 22:39:29 +0200298 unsigned int n, offset, irq;
299 unsigned long src, msk;
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900300
301 /* we're using individual domains for the non-dt case
302 * and one big domain for the dt case where the subintc
303 * starts at hwirq number 32.
304 */
Marc Zyngier5d4c9bc2015-10-13 12:51:29 +0100305 offset = irq_domain_get_of_node(intc->domain) ? 32 : 0;
Ben Dooksa21765a2007-02-11 18:31:01 +0100306
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800307 chained_irq_enter(chip, desc);
Ben Dooksa21765a2007-02-11 18:31:01 +0100308
Ben Dooks35333282016-06-21 11:20:30 +0100309 src = readl_relaxed(sub_intc->reg_pending);
310 msk = readl_relaxed(sub_intc->reg_mask);
Ben Dooksa21765a2007-02-11 18:31:01 +0100311
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800312 src &= ~msk;
313 src &= irq_data->sub_bits;
Ben Dooksa21765a2007-02-11 18:31:01 +0100314
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800315 while (src) {
316 n = __ffs(src);
317 src &= ~(1 << n);
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900318 irq = irq_find_mapping(sub_intc->domain, offset + n);
319 generic_handle_irq(irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100320 }
321
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800322 chained_irq_exit(chip, desc);
Ben Dooksa21765a2007-02-11 18:31:01 +0100323}
324
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900325static inline int s3c24xx_handle_intc(struct s3c_irq_intc *intc,
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900326 struct pt_regs *regs, int intc_offset)
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900327{
328 int pnd;
329 int offset;
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900330
Ben Dooks35333282016-06-21 11:20:30 +0100331 pnd = readl_relaxed(intc->reg_intpnd);
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900332 if (!pnd)
333 return false;
334
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900335 /* non-dt machines use individual domains */
Marc Zyngier5d4c9bc2015-10-13 12:51:29 +0100336 if (!irq_domain_get_of_node(intc->domain))
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900337 intc_offset = 0;
338
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900339 /* We have a problem that the INTOFFSET register does not always
340 * show one interrupt. Occasionally we get two interrupts through
341 * the prioritiser, and this causes the INTOFFSET register to show
342 * what looks like the logical-or of the two interrupt numbers.
343 *
344 * Thanks to Klaus, Shannon, et al for helping to debug this problem
345 */
Ben Dooks35333282016-06-21 11:20:30 +0100346 offset = readl_relaxed(intc->reg_intpnd + 4);
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900347
348 /* Find the bit manually, when the offset is wrong.
349 * The pending register only ever contains the one bit of the next
350 * interrupt to handle.
351 */
352 if (!(pnd & (1 << offset)))
353 offset = __ffs(pnd);
354
Marc Zyngiercf86bfd2014-08-26 11:03:26 +0100355 handle_domain_irq(intc->domain, intc_offset + offset, regs);
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900356 return true;
357}
358
359asmlinkage void __exception_irq_entry s3c24xx_handle_irq(struct pt_regs *regs)
360{
361 do {
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900362 if (likely(s3c_intc[0]))
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900363 if (s3c24xx_handle_intc(s3c_intc[0], regs, 0))
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900364 continue;
365
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900366 if (s3c_intc[2])
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900367 if (s3c24xx_handle_intc(s3c_intc[2], regs, 64))
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900368 continue;
369
370 break;
371 } while (1);
372}
373
Ben Dooks229fd8f2009-08-03 17:26:57 +0100374#ifdef CONFIG_FIQ
375/**
376 * s3c24xx_set_fiq - set the FIQ routing
377 * @irq: IRQ number to route to FIQ on processor.
378 * @on: Whether to route @irq to the FIQ, or to remove the FIQ routing.
379 *
380 * Change the state of the IRQ to FIQ routing depending on @irq and @on. If
381 * @on is true, the @irq is checked to see if it can be routed and the
382 * interrupt controller updated to route the IRQ. If @on is false, the FIQ
383 * routing is cleared, regardless of which @irq is specified.
384 */
385int s3c24xx_set_fiq(unsigned int irq, bool on)
386{
387 u32 intmod;
388 unsigned offs;
389
390 if (on) {
391 offs = irq - FIQ_START;
392 if (offs > 31)
393 return -EINVAL;
394
395 intmod = 1 << offs;
396 } else {
397 intmod = 0;
398 }
399
Ben Dooks35333282016-06-21 11:20:30 +0100400 writel_relaxed(intmod, S3C2410_INTMOD);
Ben Dooks229fd8f2009-08-03 17:26:57 +0100401 return 0;
402}
Ben Dooks0f13c822009-12-07 14:51:38 +0000403
404EXPORT_SYMBOL_GPL(s3c24xx_set_fiq);
Ben Dooks229fd8f2009-08-03 17:26:57 +0100405#endif
406
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800407static int s3c24xx_irq_map(struct irq_domain *h, unsigned int virq,
408 irq_hw_number_t hw)
409{
410 struct s3c_irq_intc *intc = h->host_data;
411 struct s3c_irq_data *irq_data = &intc->irqs[hw];
412 struct s3c_irq_intc *parent_intc;
413 struct s3c_irq_data *parent_irq_data;
414 unsigned int irqno;
415
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800416 /* attach controller pointer to irq_data */
417 irq_data->intc = intc;
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900418 irq_data->offset = hw;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800419
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900420 parent_intc = intc->parent;
421
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800422 /* set handler and flags */
423 switch (irq_data->type) {
424 case S3C_IRQTYPE_NONE:
425 return 0;
426 case S3C_IRQTYPE_EINT:
Heiko Stuebner1c8408e2013-02-12 10:12:09 -0800427 /* On the S3C2412, the EINT0to3 have a parent irq
428 * but need the s3c_irq_eint0t4 chip
429 */
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900430 if (parent_intc && (!soc_is_s3c2412() || hw >= 4))
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800431 irq_set_chip_and_handler(virq, &s3c_irqext_chip,
432 handle_edge_irq);
433 else
434 irq_set_chip_and_handler(virq, &s3c_irq_eint0t4,
435 handle_edge_irq);
436 break;
437 case S3C_IRQTYPE_EDGE:
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900438 if (parent_intc || intc->reg_pending == S3C2416_SRCPND2)
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800439 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
440 handle_edge_irq);
441 else
442 irq_set_chip_and_handler(virq, &s3c_irq_chip,
443 handle_edge_irq);
444 break;
445 case S3C_IRQTYPE_LEVEL:
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900446 if (parent_intc)
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800447 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
448 handle_level_irq);
449 else
450 irq_set_chip_and_handler(virq, &s3c_irq_chip,
451 handle_level_irq);
452 break;
453 default:
454 pr_err("irq-s3c24xx: unsupported irqtype %d\n", irq_data->type);
455 return -EINVAL;
456 }
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900457
458 irq_set_chip_data(virq, irq_data);
459
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900460 if (parent_intc && irq_data->type != S3C_IRQTYPE_NONE) {
Heiko Stuebner502a2982013-03-07 12:38:13 +0900461 if (irq_data->parent_irq > 31) {
462 pr_err("irq-s3c24xx: parent irq %lu is out of range\n",
463 irq_data->parent_irq);
Rob Herringd17cab42015-08-29 18:01:22 -0500464 return -EINVAL;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800465 }
466
Heiko Stuebner502a2982013-03-07 12:38:13 +0900467 parent_irq_data = &parent_intc->irqs[irq_data->parent_irq];
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800468 parent_irq_data->sub_intc = intc;
469 parent_irq_data->sub_bits |= (1UL << hw);
470
471 /* attach the demuxer to the parent irq */
472 irqno = irq_find_mapping(parent_intc->domain,
473 irq_data->parent_irq);
474 if (!irqno) {
475 pr_err("irq-s3c24xx: could not find mapping for parent irq %lu\n",
476 irq_data->parent_irq);
Rob Herringd17cab42015-08-29 18:01:22 -0500477 return -EINVAL;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800478 }
479 irq_set_chained_handler(irqno, s3c_irq_demux);
480 }
481
482 return 0;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800483}
484
Krzysztof Kozlowski96009732015-04-27 21:54:24 +0900485static const struct irq_domain_ops s3c24xx_irq_ops = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800486 .map = s3c24xx_irq_map,
487 .xlate = irq_domain_xlate_twocell,
488};
489
490static void s3c24xx_clear_intc(struct s3c_irq_intc *intc)
491{
492 void __iomem *reg_source;
493 unsigned long pend;
494 unsigned long last;
495 int i;
496
497 /* if intpnd is set, read the next pending irq from there */
498 reg_source = intc->reg_intpnd ? intc->reg_intpnd : intc->reg_pending;
499
500 last = 0;
501 for (i = 0; i < 4; i++) {
Ben Dooks35333282016-06-21 11:20:30 +0100502 pend = readl_relaxed(reg_source);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800503
504 if (pend == 0 || pend == last)
505 break;
506
Ben Dooks35333282016-06-21 11:20:30 +0100507 writel_relaxed(pend, intc->reg_pending);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800508 if (intc->reg_intpnd)
Ben Dooks35333282016-06-21 11:20:30 +0100509 writel_relaxed(pend, intc->reg_intpnd);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800510
511 pr_info("irq: clearing pending status %08x\n", (int)pend);
512 last = pend;
513 }
514}
515
Arnd Bergmannbc8fd902013-04-25 16:49:05 +0200516static struct s3c_irq_intc * __init s3c24xx_init_intc(struct device_node *np,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800517 struct s3c_irq_data *irq_data,
518 struct s3c_irq_intc *parent,
519 unsigned long address)
520{
521 struct s3c_irq_intc *intc;
522 void __iomem *base = (void *)0xf6000000; /* static mapping */
523 int irq_num;
524 int irq_start;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800525 int ret;
526
527 intc = kzalloc(sizeof(struct s3c_irq_intc), GFP_KERNEL);
528 if (!intc)
529 return ERR_PTR(-ENOMEM);
530
531 intc->irqs = irq_data;
532
533 if (parent)
534 intc->parent = parent;
535
536 /* select the correct data for the controller.
537 * Need to hard code the irq num start and offset
538 * to preserve the static mapping for now
539 */
540 switch (address) {
541 case 0x4a000000:
542 pr_debug("irq: found main intc\n");
543 intc->reg_pending = base;
544 intc->reg_mask = base + 0x08;
545 intc->reg_intpnd = base + 0x10;
546 irq_num = 32;
547 irq_start = S3C2410_IRQ(0);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800548 break;
549 case 0x4a000018:
550 pr_debug("irq: found subintc\n");
551 intc->reg_pending = base + 0x18;
552 intc->reg_mask = base + 0x1c;
553 irq_num = 29;
554 irq_start = S3C2410_IRQSUB(0);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800555 break;
556 case 0x4a000040:
557 pr_debug("irq: found intc2\n");
558 intc->reg_pending = base + 0x40;
559 intc->reg_mask = base + 0x48;
560 intc->reg_intpnd = base + 0x50;
561 irq_num = 8;
562 irq_start = S3C2416_IRQ(0);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800563 break;
564 case 0x560000a4:
565 pr_debug("irq: found eintc\n");
566 base = (void *)0xfd000000;
567
568 intc->reg_mask = base + 0xa4;
Linus Torvalds6fa52ed2013-05-04 12:31:18 -0700569 intc->reg_pending = base + 0xa8;
Heiko Stuebner5424f212013-02-12 10:12:04 -0800570 irq_num = 24;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800571 irq_start = S3C2410_IRQ(32);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800572 break;
573 default:
574 pr_err("irq: unsupported controller address\n");
575 ret = -EINVAL;
576 goto err;
577 }
578
579 /* now that all the data is complete, init the irq-domain */
580 s3c24xx_clear_intc(intc);
581 intc->domain = irq_domain_add_legacy(np, irq_num, irq_start,
Heiko Stuebner5424f212013-02-12 10:12:04 -0800582 0, &s3c24xx_irq_ops,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800583 intc);
584 if (!intc->domain) {
585 pr_err("irq: could not create irq-domain\n");
586 ret = -EINVAL;
587 goto err;
588 }
589
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900590 set_handle_irq(s3c24xx_handle_irq);
591
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800592 return intc;
593
594err:
595 kfree(intc);
596 return ERR_PTR(ret);
597}
Ben Dooks229fd8f2009-08-03 17:26:57 +0100598
Arnd Bergmanneb249a12016-01-25 16:58:08 +0100599static struct s3c_irq_data __maybe_unused init_eint[32] = {
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900600 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
601 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
602 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
603 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
604 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT4 */
605 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT5 */
606 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT6 */
607 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT7 */
608 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT8 */
609 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT9 */
610 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT10 */
611 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT11 */
612 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT12 */
613 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT13 */
614 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT14 */
615 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT15 */
616 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT16 */
617 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT17 */
618 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT18 */
619 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT19 */
620 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT20 */
621 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT21 */
622 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT22 */
623 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT23 */
624};
Ben Dooksa21765a2007-02-11 18:31:01 +0100625
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900626#ifdef CONFIG_CPU_S3C2410
627static struct s3c_irq_data init_s3c2410base[32] = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800628 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
629 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
630 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
631 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
632 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
633 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
634 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
635 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
636 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
637 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
638 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
639 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
640 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
641 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
642 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
643 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
644 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
645 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
646 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
647 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
648 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
649 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
650 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
651 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
652 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
653 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
654 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
655 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
656 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
657 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
658 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
659 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
660};
661
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900662static struct s3c_irq_data init_s3c2410subint[32] = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800663 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
664 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
665 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
666 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
667 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
668 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
669 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
670 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
671 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
672 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
673 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
674};
675
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900676void __init s3c2410_init_irq(void)
Ben Dooksa21765a2007-02-11 18:31:01 +0100677{
Ben Dooks229fd8f2009-08-03 17:26:57 +0100678#ifdef CONFIG_FIQ
Shawn Guobc896632012-06-28 14:42:08 +0800679 init_FIQ(FIQ_START);
Ben Dooks229fd8f2009-08-03 17:26:57 +0100680#endif
681
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900682 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2410base[0], NULL,
683 0x4a000000);
684 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800685 pr_err("irq: could not create main interrupt controller\n");
686 return;
Ben Dooksa21765a2007-02-11 18:31:01 +0100687 }
688
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900689 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2410subint[0],
690 s3c_intc[0], 0x4a000018);
691 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
Ben Dooksa21765a2007-02-11 18:31:01 +0100692}
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900693#endif
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800694
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800695#ifdef CONFIG_CPU_S3C2412
Heiko Stuebner42459442013-02-12 10:09:21 -0800696static struct s3c_irq_data init_s3c2412base[32] = {
Heiko Stuebner1c8408e2013-02-12 10:12:09 -0800697 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT0 */
698 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT1 */
699 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT2 */
700 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT3 */
Heiko Stuebner42459442013-02-12 10:09:21 -0800701 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
702 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
703 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
704 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
705 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
706 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
707 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
708 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
709 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
710 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
711 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
712 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
713 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
714 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
715 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
716 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
717 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
718 { .type = S3C_IRQTYPE_LEVEL, }, /* SDI/CF */
719 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
720 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
721 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
722 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
723 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
724 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
725 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
726 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
727 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
728 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
729};
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800730
Heiko Stuebner1c8408e2013-02-12 10:12:09 -0800731static struct s3c_irq_data init_s3c2412eint[32] = {
732 { .type = S3C_IRQTYPE_EINT, .parent_irq = 0 }, /* EINT0 */
733 { .type = S3C_IRQTYPE_EINT, .parent_irq = 1 }, /* EINT1 */
734 { .type = S3C_IRQTYPE_EINT, .parent_irq = 2 }, /* EINT2 */
735 { .type = S3C_IRQTYPE_EINT, .parent_irq = 3 }, /* EINT3 */
736 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT4 */
737 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT5 */
738 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT6 */
739 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT7 */
740 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT8 */
741 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT9 */
742 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT10 */
743 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT11 */
744 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT12 */
745 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT13 */
746 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT14 */
747 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT15 */
748 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT16 */
749 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT17 */
750 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT18 */
751 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT19 */
752 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT20 */
753 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT21 */
754 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT22 */
755 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT23 */
756};
757
Heiko Stuebner42459442013-02-12 10:09:21 -0800758static struct s3c_irq_data init_s3c2412subint[32] = {
759 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
760 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
761 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
762 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
763 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
764 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
765 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
766 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
767 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
768 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
769 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
770 { .type = S3C_IRQTYPE_NONE, },
771 { .type = S3C_IRQTYPE_NONE, },
772 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 21 }, /* SDI */
773 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 21 }, /* CF */
774};
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800775
Arnd Bergmannbc8fd902013-04-25 16:49:05 +0200776void __init s3c2412_init_irq(void)
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800777{
Heiko Stuebner42459442013-02-12 10:09:21 -0800778 pr_info("S3C2412: IRQ Support\n");
779
780#ifdef CONFIG_FIQ
781 init_FIQ(FIQ_START);
782#endif
783
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900784 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2412base[0], NULL,
785 0x4a000000);
786 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebner42459442013-02-12 10:09:21 -0800787 pr_err("irq: could not create main interrupt controller\n");
788 return;
789 }
790
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900791 s3c24xx_init_intc(NULL, &init_s3c2412eint[0], s3c_intc[0], 0x560000a4);
792 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2412subint[0],
793 s3c_intc[0], 0x4a000018);
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800794}
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800795#endif
796
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800797#ifdef CONFIG_CPU_S3C2416
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800798static struct s3c_irq_data init_s3c2416base[32] = {
799 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
800 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
801 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
802 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
803 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
804 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
805 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
806 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
807 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
808 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
809 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
810 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
811 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
812 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
813 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
814 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
815 { .type = S3C_IRQTYPE_LEVEL, }, /* LCD */
816 { .type = S3C_IRQTYPE_LEVEL, }, /* DMA */
817 { .type = S3C_IRQTYPE_LEVEL, }, /* UART3 */
818 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
819 { .type = S3C_IRQTYPE_EDGE, }, /* SDI1 */
820 { .type = S3C_IRQTYPE_EDGE, }, /* SDI0 */
821 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
822 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
823 { .type = S3C_IRQTYPE_EDGE, }, /* NAND */
824 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
825 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
826 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
827 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
828 { .type = S3C_IRQTYPE_NONE, },
829 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
830 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800831};
832
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800833static struct s3c_irq_data init_s3c2416subint[32] = {
834 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
835 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
836 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
837 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
838 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
839 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
840 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
841 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
842 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
843 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
844 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
845 { .type = S3C_IRQTYPE_NONE }, /* reserved */
846 { .type = S3C_IRQTYPE_NONE }, /* reserved */
847 { .type = S3C_IRQTYPE_NONE }, /* reserved */
848 { .type = S3C_IRQTYPE_NONE }, /* reserved */
849 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD2 */
850 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD3 */
851 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD4 */
852 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA0 */
853 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA1 */
854 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA2 */
855 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA3 */
856 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA4 */
857 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA5 */
858 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-RX */
859 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-TX */
860 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-ERR */
861 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
862 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800863};
864
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800865static struct s3c_irq_data init_s3c2416_second[32] = {
866 { .type = S3C_IRQTYPE_EDGE }, /* 2D */
Heiko Stuebner1ebc7e82013-04-04 14:53:41 +0900867 { .type = S3C_IRQTYPE_NONE }, /* reserved */
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800868 { .type = S3C_IRQTYPE_NONE }, /* reserved */
869 { .type = S3C_IRQTYPE_NONE }, /* reserved */
870 { .type = S3C_IRQTYPE_EDGE }, /* PCM0 */
Heiko Stuebner1ebc7e82013-04-04 14:53:41 +0900871 { .type = S3C_IRQTYPE_NONE }, /* reserved */
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800872 { .type = S3C_IRQTYPE_EDGE }, /* I2S0 */
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800873};
874
Heiko Stuebner4a282dd2013-01-29 10:25:22 -0800875void __init s3c2416_init_irq(void)
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800876{
Heiko Stuebner4a282dd2013-01-29 10:25:22 -0800877 pr_info("S3C2416: IRQ Support\n");
878
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800879#ifdef CONFIG_FIQ
880 init_FIQ(FIQ_START);
881#endif
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800882
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900883 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2416base[0], NULL,
884 0x4a000000);
885 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800886 pr_err("irq: could not create main interrupt controller\n");
887 return;
888 }
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800889
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900890 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
891 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2416subint[0],
892 s3c_intc[0], 0x4a000018);
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800893
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900894 s3c_intc[2] = s3c24xx_init_intc(NULL, &init_s3c2416_second[0],
895 NULL, 0x4a000040);
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800896}
897
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800898#endif
Heiko Stuebner6b628912013-01-29 10:25:22 -0800899
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800900#ifdef CONFIG_CPU_S3C2440
901static struct s3c_irq_data init_s3c2440base[32] = {
902 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
903 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
904 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
905 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
906 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
907 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
908 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
909 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
910 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
911 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
912 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
913 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
914 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
915 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
916 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
917 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
918 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
919 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
920 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
921 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
922 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
923 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
924 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
925 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
926 { .type = S3C_IRQTYPE_LEVEL, }, /* NFCON */
927 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
928 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
929 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
930 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
931 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
932 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
933 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -0800934};
935
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800936static struct s3c_irq_data init_s3c2440subint[32] = {
937 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
938 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
939 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
940 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
941 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
942 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
943 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
944 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
945 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
946 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
947 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
Heiko Stuebnere2714f72013-04-04 14:53:37 +0900948 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
949 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800950 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
951 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
Heiko Stuebner2286cf42013-02-12 09:59:24 -0800952};
953
Heiko Stuebner7cefed52013-02-12 09:59:27 -0800954void __init s3c2440_init_irq(void)
Heiko Stuebner2286cf42013-02-12 09:59:24 -0800955{
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800956 pr_info("S3C2440: IRQ Support\n");
Heiko Stuebner2286cf42013-02-12 09:59:24 -0800957
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800958#ifdef CONFIG_FIQ
959 init_FIQ(FIQ_START);
960#endif
Heiko Stuebnerce6c1642013-02-12 09:59:20 -0800961
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900962 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2440base[0], NULL,
963 0x4a000000);
964 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800965 pr_err("irq: could not create main interrupt controller\n");
966 return;
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -0800967 }
Heiko Stuebner7cefed52013-02-12 09:59:27 -0800968
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900969 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
970 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2440subint[0],
971 s3c_intc[0], 0x4a000018);
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -0800972}
Heiko Stuebnerce6c1642013-02-12 09:59:20 -0800973#endif
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -0800974
Heiko Stuebnerce6c1642013-02-12 09:59:20 -0800975#ifdef CONFIG_CPU_S3C2442
Heiko Stuebner70644ad2013-02-12 09:59:31 -0800976static struct s3c_irq_data init_s3c2442base[32] = {
977 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
978 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
979 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
980 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
981 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
982 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
983 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
984 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
985 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
986 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
987 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
988 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
989 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
990 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
991 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
992 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
993 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
994 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
995 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
996 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
997 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
998 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
999 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
1000 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
1001 { .type = S3C_IRQTYPE_LEVEL, }, /* NFCON */
1002 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
1003 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
1004 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
1005 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
1006 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
1007 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
1008 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
1009};
1010
1011static struct s3c_irq_data init_s3c2442subint[32] = {
1012 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
1013 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
1014 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
1015 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
1016 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
1017 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
1018 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
1019 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
1020 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
1021 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
1022 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
Heiko Stuebnere2714f72013-04-04 14:53:37 +09001023 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
1024 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001025};
1026
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001027void __init s3c2442_init_irq(void)
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -08001028{
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001029 pr_info("S3C2442: IRQ Support\n");
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001030
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001031#ifdef CONFIG_FIQ
1032 init_FIQ(FIQ_START);
1033#endif
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001034
Heiko Stuebner658dc8f2013-04-04 14:53:49 +09001035 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2442base[0], NULL,
1036 0x4a000000);
1037 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001038 pr_err("irq: could not create main interrupt controller\n");
1039 return;
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001040 }
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001041
Heiko Stuebner658dc8f2013-04-04 14:53:49 +09001042 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
1043 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2442subint[0],
1044 s3c_intc[0], 0x4a000018);
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -08001045}
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001046#endif
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -08001047
Heiko Stuebner6b628912013-01-29 10:25:22 -08001048#ifdef CONFIG_CPU_S3C2443
Heiko Stuebnerf44ddba2013-01-29 10:25:23 -08001049static struct s3c_irq_data init_s3c2443base[32] = {
1050 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
1051 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
1052 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
1053 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
1054 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
1055 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
1056 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
1057 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
1058 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
1059 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
1060 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
1061 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
1062 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
1063 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
1064 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
1065 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
1066 { .type = S3C_IRQTYPE_LEVEL, }, /* LCD */
1067 { .type = S3C_IRQTYPE_LEVEL, }, /* DMA */
1068 { .type = S3C_IRQTYPE_LEVEL, }, /* UART3 */
1069 { .type = S3C_IRQTYPE_EDGE, }, /* CFON */
1070 { .type = S3C_IRQTYPE_EDGE, }, /* SDI1 */
1071 { .type = S3C_IRQTYPE_EDGE, }, /* SDI0 */
1072 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
1073 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
1074 { .type = S3C_IRQTYPE_EDGE, }, /* NAND */
1075 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
1076 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
1077 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
1078 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
1079 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
1080 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
1081 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
Heiko Stuebner6b628912013-01-29 10:25:22 -08001082};
1083
Heiko Stuebner6b628912013-01-29 10:25:22 -08001084
Heiko Stuebnerf44ddba2013-01-29 10:25:23 -08001085static struct s3c_irq_data init_s3c2443subint[32] = {
1086 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
1087 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
1088 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
1089 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
1090 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
1091 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
1092 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
1093 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
1094 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
1095 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
1096 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
1097 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
1098 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
1099 { .type = S3C_IRQTYPE_NONE }, /* reserved */
1100 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD1 */
1101 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD2 */
1102 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD3 */
1103 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD4 */
1104 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA0 */
1105 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA1 */
1106 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA2 */
1107 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA3 */
1108 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA4 */
1109 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA5 */
1110 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-RX */
1111 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-TX */
1112 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-ERR */
1113 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
1114 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
Heiko Stuebner6b628912013-01-29 10:25:22 -08001115};
1116
Heiko Stuebnerb499b7a2013-01-29 10:25:23 -08001117void __init s3c2443_init_irq(void)
Heiko Stuebner6b628912013-01-29 10:25:22 -08001118{
Heiko Stuebnerb499b7a2013-01-29 10:25:23 -08001119 pr_info("S3C2443: IRQ Support\n");
1120
Heiko Stuebnerf44ddba2013-01-29 10:25:23 -08001121#ifdef CONFIG_FIQ
1122 init_FIQ(FIQ_START);
1123#endif
Heiko Stuebner6b628912013-01-29 10:25:22 -08001124
Heiko Stuebner658dc8f2013-04-04 14:53:49 +09001125 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2443base[0], NULL,
1126 0x4a000000);
1127 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebnerf44ddba2013-01-29 10:25:23 -08001128 pr_err("irq: could not create main interrupt controller\n");
1129 return;
1130 }
Heiko Stuebner6b628912013-01-29 10:25:22 -08001131
Heiko Stuebner658dc8f2013-04-04 14:53:49 +09001132 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
1133 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2443subint[0],
1134 s3c_intc[0], 0x4a000018);
Heiko Stuebner6b628912013-01-29 10:25:22 -08001135}
Heiko Stuebner6b628912013-01-29 10:25:22 -08001136#endif
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001137
1138#ifdef CONFIG_OF
1139static int s3c24xx_irq_map_of(struct irq_domain *h, unsigned int virq,
1140 irq_hw_number_t hw)
1141{
1142 unsigned int ctrl_num = hw / 32;
1143 unsigned int intc_hw = hw % 32;
1144 struct s3c_irq_intc *intc = s3c_intc[ctrl_num];
1145 struct s3c_irq_intc *parent_intc = intc->parent;
1146 struct s3c_irq_data *irq_data = &intc->irqs[intc_hw];
1147
1148 /* attach controller pointer to irq_data */
1149 irq_data->intc = intc;
1150 irq_data->offset = intc_hw;
1151
1152 if (!parent_intc)
1153 irq_set_chip_and_handler(virq, &s3c_irq_chip, handle_edge_irq);
1154 else
1155 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
1156 handle_edge_irq);
1157
1158 irq_set_chip_data(virq, irq_data);
1159
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001160 return 0;
1161}
1162
1163/* Translate our of irq notation
1164 * format: <ctrl_num ctrl_irq parent_irq type>
1165 */
1166static int s3c24xx_irq_xlate_of(struct irq_domain *d, struct device_node *n,
1167 const u32 *intspec, unsigned int intsize,
1168 irq_hw_number_t *out_hwirq, unsigned int *out_type)
1169{
1170 struct s3c_irq_intc *intc;
1171 struct s3c_irq_intc *parent_intc;
1172 struct s3c_irq_data *irq_data;
1173 struct s3c_irq_data *parent_irq_data;
1174 int irqno;
1175
1176 if (WARN_ON(intsize < 4))
1177 return -EINVAL;
1178
1179 if (intspec[0] > 2 || !s3c_intc[intspec[0]]) {
1180 pr_err("controller number %d invalid\n", intspec[0]);
1181 return -EINVAL;
1182 }
1183 intc = s3c_intc[intspec[0]];
1184
1185 *out_hwirq = intspec[0] * 32 + intspec[2];
1186 *out_type = intspec[3] & IRQ_TYPE_SENSE_MASK;
1187
1188 parent_intc = intc->parent;
1189 if (parent_intc) {
1190 irq_data = &intc->irqs[intspec[2]];
1191 irq_data->parent_irq = intspec[1];
1192 parent_irq_data = &parent_intc->irqs[irq_data->parent_irq];
1193 parent_irq_data->sub_intc = intc;
1194 parent_irq_data->sub_bits |= (1UL << intspec[2]);
1195
1196 /* parent_intc is always s3c_intc[0], so no offset */
1197 irqno = irq_create_mapping(parent_intc->domain, intspec[1]);
1198 if (irqno < 0) {
1199 pr_err("irq: could not map parent interrupt\n");
1200 return irqno;
1201 }
1202
1203 irq_set_chained_handler(irqno, s3c_irq_demux);
1204 }
1205
1206 return 0;
1207}
1208
Krzysztof Kozlowski96009732015-04-27 21:54:24 +09001209static const struct irq_domain_ops s3c24xx_irq_ops_of = {
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001210 .map = s3c24xx_irq_map_of,
1211 .xlate = s3c24xx_irq_xlate_of,
1212};
1213
1214struct s3c24xx_irq_of_ctrl {
1215 char *name;
1216 unsigned long offset;
1217 struct s3c_irq_intc **handle;
1218 struct s3c_irq_intc **parent;
1219 struct irq_domain_ops *ops;
1220};
1221
1222static int __init s3c_init_intc_of(struct device_node *np,
1223 struct device_node *interrupt_parent,
1224 struct s3c24xx_irq_of_ctrl *s3c_ctrl, int num_ctrl)
1225{
1226 struct s3c_irq_intc *intc;
1227 struct s3c24xx_irq_of_ctrl *ctrl;
1228 struct irq_domain *domain;
1229 void __iomem *reg_base;
1230 int i;
1231
1232 reg_base = of_iomap(np, 0);
1233 if (!reg_base) {
1234 pr_err("irq-s3c24xx: could not map irq registers\n");
1235 return -EINVAL;
1236 }
1237
1238 domain = irq_domain_add_linear(np, num_ctrl * 32,
1239 &s3c24xx_irq_ops_of, NULL);
1240 if (!domain) {
1241 pr_err("irq: could not create irq-domain\n");
1242 return -EINVAL;
1243 }
1244
1245 for (i = 0; i < num_ctrl; i++) {
1246 ctrl = &s3c_ctrl[i];
1247
1248 pr_debug("irq: found controller %s\n", ctrl->name);
1249
1250 intc = kzalloc(sizeof(struct s3c_irq_intc), GFP_KERNEL);
1251 if (!intc)
1252 return -ENOMEM;
1253
1254 intc->domain = domain;
Kees Cook6396bb22018-06-12 14:03:40 -07001255 intc->irqs = kcalloc(32, sizeof(struct s3c_irq_data),
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001256 GFP_KERNEL);
1257 if (!intc->irqs) {
1258 kfree(intc);
1259 return -ENOMEM;
1260 }
1261
1262 if (ctrl->parent) {
1263 intc->reg_pending = reg_base + ctrl->offset;
1264 intc->reg_mask = reg_base + ctrl->offset + 0x4;
1265
1266 if (*(ctrl->parent)) {
1267 intc->parent = *(ctrl->parent);
1268 } else {
1269 pr_warn("irq: parent of %s missing\n",
1270 ctrl->name);
1271 kfree(intc->irqs);
1272 kfree(intc);
1273 continue;
1274 }
1275 } else {
1276 intc->reg_pending = reg_base + ctrl->offset;
1277 intc->reg_mask = reg_base + ctrl->offset + 0x08;
1278 intc->reg_intpnd = reg_base + ctrl->offset + 0x10;
1279 }
1280
1281 s3c24xx_clear_intc(intc);
1282 s3c_intc[i] = intc;
1283 }
1284
1285 set_handle_irq(s3c24xx_handle_irq);
1286
1287 return 0;
1288}
1289
1290static struct s3c24xx_irq_of_ctrl s3c2410_ctrl[] = {
1291 {
1292 .name = "intc",
1293 .offset = 0,
1294 }, {
1295 .name = "subintc",
1296 .offset = 0x18,
1297 .parent = &s3c_intc[0],
1298 }
1299};
1300
1301int __init s3c2410_init_intc_of(struct device_node *np,
Rob Herring4f410832014-05-12 11:35:52 -05001302 struct device_node *interrupt_parent)
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001303{
1304 return s3c_init_intc_of(np, interrupt_parent,
1305 s3c2410_ctrl, ARRAY_SIZE(s3c2410_ctrl));
1306}
1307IRQCHIP_DECLARE(s3c2410_irq, "samsung,s3c2410-irq", s3c2410_init_intc_of);
1308
1309static struct s3c24xx_irq_of_ctrl s3c2416_ctrl[] = {
1310 {
1311 .name = "intc",
1312 .offset = 0,
1313 }, {
1314 .name = "subintc",
1315 .offset = 0x18,
1316 .parent = &s3c_intc[0],
1317 }, {
1318 .name = "intc2",
1319 .offset = 0x40,
1320 }
1321};
1322
1323int __init s3c2416_init_intc_of(struct device_node *np,
Rob Herring4f410832014-05-12 11:35:52 -05001324 struct device_node *interrupt_parent)
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001325{
1326 return s3c_init_intc_of(np, interrupt_parent,
1327 s3c2416_ctrl, ARRAY_SIZE(s3c2416_ctrl));
1328}
1329IRQCHIP_DECLARE(s3c2416_irq, "samsung,s3c2416-irq", s3c2416_init_intc_of);
1330#endif