blob: aee4266f27f758f252bc874159b584eb05c73842 [file] [log] [blame]
Heiko Stuebner1f629b72013-01-29 10:25:22 -08001/*
2 * S3C24XX IRQ handling
Ben Dooksa21765a2007-02-11 18:31:01 +01003 *
Ben Dookse02f8662009-11-13 22:54:13 +00004 * Copyright (c) 2003-2004 Simtec Electronics
Ben Dooksa21765a2007-02-11 18:31:01 +01005 * Ben Dooks <ben@simtec.co.uk>
Heiko Stuebner1f629b72013-01-29 10:25:22 -08006 * Copyright (c) 2012 Heiko Stuebner <heiko@sntech.de>
Ben Dooksa21765a2007-02-11 18:31:01 +01007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Ben Dooksa21765a2007-02-11 18:31:01 +010017*/
18
19#include <linux/init.h>
Heiko Stuebner1f629b72013-01-29 10:25:22 -080020#include <linux/slab.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010021#include <linux/module.h>
Heiko Stuebner1f629b72013-01-29 10:25:22 -080022#include <linux/io.h>
23#include <linux/err.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010024#include <linux/interrupt.h>
25#include <linux/ioport.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080026#include <linux/device.h>
Heiko Stuebner1f629b72013-01-29 10:25:22 -080027#include <linux/irqdomain.h>
Joel Porquet41a83e02015-07-07 17:11:46 -040028#include <linux/irqchip.h>
Linus Torvalds6fa52ed2013-05-04 12:31:18 -070029#include <linux/irqchip/chained_irq.h>
Heiko Stuebnerf0774d42013-04-04 14:55:10 +090030#include <linux/of.h>
31#include <linux/of_irq.h>
32#include <linux/of_address.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010033
Heiko Stuebner17453dd2013-03-07 12:38:25 +090034#include <asm/exception.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010035#include <asm/mach/irq.h>
36
Heiko Stuebner1f629b72013-01-29 10:25:22 -080037#include <mach/regs-irq.h>
38#include <mach/regs-gpio.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010039
Ben Dooksa2b7ba92008-10-07 22:26:09 +010040#include <plat/cpu.h>
Heiko Stuebner1f629b72013-01-29 10:25:22 -080041#include <plat/regs-irqtype.h>
Ben Dooksa2b7ba92008-10-07 22:26:09 +010042#include <plat/pm.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010043
Heiko Stuebner1f629b72013-01-29 10:25:22 -080044#define S3C_IRQTYPE_NONE 0
45#define S3C_IRQTYPE_EINT 1
46#define S3C_IRQTYPE_EDGE 2
47#define S3C_IRQTYPE_LEVEL 3
Ben Dooksa21765a2007-02-11 18:31:01 +010048
Heiko Stuebner1f629b72013-01-29 10:25:22 -080049struct s3c_irq_data {
50 unsigned int type;
Heiko Stuebnerf5a25522013-04-04 14:53:52 +090051 unsigned long offset;
Heiko Stuebner1f629b72013-01-29 10:25:22 -080052 unsigned long parent_irq;
Ben Dooksa21765a2007-02-11 18:31:01 +010053
Heiko Stuebner1f629b72013-01-29 10:25:22 -080054 /* data gets filled during init */
55 struct s3c_irq_intc *intc;
56 unsigned long sub_bits;
57 struct s3c_irq_intc *sub_intc;
Ben Dooksa21765a2007-02-11 18:31:01 +010058};
59
Heiko Stuebner1f629b72013-01-29 10:25:22 -080060/*
61 * Sructure holding the controller data
62 * @reg_pending register holding pending irqs
63 * @reg_intpnd special register intpnd in main intc
64 * @reg_mask mask register
65 * @domain irq_domain of the controller
66 * @parent parent controller for ext and sub irqs
67 * @irqs irq-data, always s3c_irq_data[32]
68 */
69struct s3c_irq_intc {
70 void __iomem *reg_pending;
71 void __iomem *reg_intpnd;
72 void __iomem *reg_mask;
73 struct irq_domain *domain;
74 struct s3c_irq_intc *parent;
75 struct s3c_irq_data *irqs;
Ben Dooksa21765a2007-02-11 18:31:01 +010076};
77
Heiko Stuebner658dc8f2013-04-04 14:53:49 +090078/*
79 * Array holding pointers to the global controller structs
80 * [0] ... main_intc
81 * [1] ... sub_intc
82 * [2] ... main_intc2 on s3c2416
83 */
84static struct s3c_irq_intc *s3c_intc[3];
85
Heiko Stuebner1f629b72013-01-29 10:25:22 -080086static void s3c_irq_mask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +010087{
Heiko Stuebnerf5a25522013-04-04 14:53:52 +090088 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
89 struct s3c_irq_intc *intc = irq_data->intc;
Heiko Stuebner1f629b72013-01-29 10:25:22 -080090 struct s3c_irq_intc *parent_intc = intc->parent;
Heiko Stuebner1f629b72013-01-29 10:25:22 -080091 struct s3c_irq_data *parent_data;
Ben Dooksa21765a2007-02-11 18:31:01 +010092 unsigned long mask;
Heiko Stuebner1f629b72013-01-29 10:25:22 -080093 unsigned int irqno;
Ben Dooksa21765a2007-02-11 18:31:01 +010094
Heiko Stuebner1f629b72013-01-29 10:25:22 -080095 mask = __raw_readl(intc->reg_mask);
Heiko Stuebnerf5a25522013-04-04 14:53:52 +090096 mask |= (1UL << irq_data->offset);
Heiko Stuebner1f629b72013-01-29 10:25:22 -080097 __raw_writel(mask, intc->reg_mask);
Ben Dooksa21765a2007-02-11 18:31:01 +010098
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +090099 if (parent_intc) {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800100 parent_data = &parent_intc->irqs[irq_data->parent_irq];
Ben Dooksa21765a2007-02-11 18:31:01 +0100101
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900102 /* check to see if we need to mask the parent IRQ
103 * The parent_irq is always in main_intc, so the hwirq
104 * for find_mapping does not need an offset in any case.
105 */
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800106 if ((mask & parent_data->sub_bits) == parent_data->sub_bits) {
107 irqno = irq_find_mapping(parent_intc->domain,
108 irq_data->parent_irq);
109 s3c_irq_mask(irq_get_irq_data(irqno));
110 }
Ben Dooksa21765a2007-02-11 18:31:01 +0100111 }
112}
113
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800114static void s3c_irq_unmask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100115{
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900116 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
117 struct s3c_irq_intc *intc = irq_data->intc;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800118 struct s3c_irq_intc *parent_intc = intc->parent;
Ben Dooksa21765a2007-02-11 18:31:01 +0100119 unsigned long mask;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800120 unsigned int irqno;
Ben Dooksa21765a2007-02-11 18:31:01 +0100121
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800122 mask = __raw_readl(intc->reg_mask);
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900123 mask &= ~(1UL << irq_data->offset);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800124 __raw_writel(mask, intc->reg_mask);
125
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900126 if (parent_intc) {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800127 irqno = irq_find_mapping(parent_intc->domain,
128 irq_data->parent_irq);
129 s3c_irq_unmask(irq_get_irq_data(irqno));
130 }
Ben Dooksa21765a2007-02-11 18:31:01 +0100131}
132
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800133static inline void s3c_irq_ack(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100134{
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900135 struct s3c_irq_data *irq_data = irq_data_get_irq_chip_data(data);
136 struct s3c_irq_intc *intc = irq_data->intc;
137 unsigned long bitval = 1UL << irq_data->offset;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800138
139 __raw_writel(bitval, intc->reg_pending);
140 if (intc->reg_intpnd)
141 __raw_writel(bitval, intc->reg_intpnd);
142}
143
Heiko Stuebnerbd7c0da2013-04-04 14:53:45 +0900144static int s3c_irq_type(struct irq_data *data, unsigned int type)
145{
146 switch (type) {
147 case IRQ_TYPE_NONE:
148 break;
149 case IRQ_TYPE_EDGE_RISING:
150 case IRQ_TYPE_EDGE_FALLING:
151 case IRQ_TYPE_EDGE_BOTH:
152 irq_set_handler(data->irq, handle_edge_irq);
153 break;
154 case IRQ_TYPE_LEVEL_LOW:
155 case IRQ_TYPE_LEVEL_HIGH:
156 irq_set_handler(data->irq, handle_level_irq);
157 break;
158 default:
159 pr_err("No such irq type %d", type);
160 return -EINVAL;
161 }
162
163 return 0;
164}
165
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800166static int s3c_irqext_type_set(void __iomem *gpcon_reg,
167 void __iomem *extint_reg,
168 unsigned long gpcon_offset,
169 unsigned long extint_offset,
170 unsigned int type)
171{
Ben Dooksa21765a2007-02-11 18:31:01 +0100172 unsigned long newvalue = 0, value;
173
Ben Dooksa21765a2007-02-11 18:31:01 +0100174 /* Set the GPIO to external interrupt mode */
175 value = __raw_readl(gpcon_reg);
176 value = (value & ~(3 << gpcon_offset)) | (0x02 << gpcon_offset);
177 __raw_writel(value, gpcon_reg);
178
179 /* Set the external interrupt to pointed trigger type */
180 switch (type)
181 {
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100182 case IRQ_TYPE_NONE:
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800183 pr_warn("No edge setting!\n");
Ben Dooksa21765a2007-02-11 18:31:01 +0100184 break;
185
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100186 case IRQ_TYPE_EDGE_RISING:
Ben Dooksa21765a2007-02-11 18:31:01 +0100187 newvalue = S3C2410_EXTINT_RISEEDGE;
188 break;
189
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100190 case IRQ_TYPE_EDGE_FALLING:
Ben Dooksa21765a2007-02-11 18:31:01 +0100191 newvalue = S3C2410_EXTINT_FALLEDGE;
192 break;
193
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100194 case IRQ_TYPE_EDGE_BOTH:
Ben Dooksa21765a2007-02-11 18:31:01 +0100195 newvalue = S3C2410_EXTINT_BOTHEDGE;
196 break;
197
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100198 case IRQ_TYPE_LEVEL_LOW:
Ben Dooksa21765a2007-02-11 18:31:01 +0100199 newvalue = S3C2410_EXTINT_LOWLEV;
200 break;
201
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100202 case IRQ_TYPE_LEVEL_HIGH:
Ben Dooksa21765a2007-02-11 18:31:01 +0100203 newvalue = S3C2410_EXTINT_HILEV;
204 break;
205
206 default:
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800207 pr_err("No such irq type %d", type);
208 return -EINVAL;
Ben Dooksa21765a2007-02-11 18:31:01 +0100209 }
210
211 value = __raw_readl(extint_reg);
212 value = (value & ~(7 << extint_offset)) | (newvalue << extint_offset);
213 __raw_writel(value, extint_reg);
214
215 return 0;
216}
217
Heiko Stuebnerdc1a3532013-02-12 14:23:01 -0800218static int s3c_irqext_type(struct irq_data *data, unsigned int type)
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800219{
220 void __iomem *extint_reg;
221 void __iomem *gpcon_reg;
222 unsigned long gpcon_offset, extint_offset;
223
224 if ((data->hwirq >= 4) && (data->hwirq <= 7)) {
225 gpcon_reg = S3C2410_GPFCON;
226 extint_reg = S3C24XX_EXTINT0;
227 gpcon_offset = (data->hwirq) * 2;
228 extint_offset = (data->hwirq) * 4;
229 } else if ((data->hwirq >= 8) && (data->hwirq <= 15)) {
230 gpcon_reg = S3C2410_GPGCON;
231 extint_reg = S3C24XX_EXTINT1;
232 gpcon_offset = (data->hwirq - 8) * 2;
233 extint_offset = (data->hwirq - 8) * 4;
234 } else if ((data->hwirq >= 16) && (data->hwirq <= 23)) {
235 gpcon_reg = S3C2410_GPGCON;
236 extint_reg = S3C24XX_EXTINT2;
237 gpcon_offset = (data->hwirq - 8) * 2;
238 extint_offset = (data->hwirq - 16) * 4;
239 } else {
240 return -EINVAL;
241 }
242
243 return s3c_irqext_type_set(gpcon_reg, extint_reg, gpcon_offset,
244 extint_offset, type);
245}
246
247static int s3c_irqext0_type(struct irq_data *data, unsigned int type)
248{
249 void __iomem *extint_reg;
250 void __iomem *gpcon_reg;
251 unsigned long gpcon_offset, extint_offset;
252
253 if ((data->hwirq >= 0) && (data->hwirq <= 3)) {
254 gpcon_reg = S3C2410_GPFCON;
255 extint_reg = S3C24XX_EXTINT0;
256 gpcon_offset = (data->hwirq) * 2;
257 extint_offset = (data->hwirq) * 4;
258 } else {
259 return -EINVAL;
260 }
261
262 return s3c_irqext_type_set(gpcon_reg, extint_reg, gpcon_offset,
263 extint_offset, type);
264}
265
Heiko Stuebnerdc1a3532013-02-12 14:23:01 -0800266static struct irq_chip s3c_irq_chip = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800267 .name = "s3c",
268 .irq_ack = s3c_irq_ack,
269 .irq_mask = s3c_irq_mask,
270 .irq_unmask = s3c_irq_unmask,
Heiko Stuebnerbd7c0da2013-04-04 14:53:45 +0900271 .irq_set_type = s3c_irq_type,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800272 .irq_set_wake = s3c_irq_wake
273};
274
Heiko Stuebnerdc1a3532013-02-12 14:23:01 -0800275static struct irq_chip s3c_irq_level_chip = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800276 .name = "s3c-level",
277 .irq_mask = s3c_irq_mask,
278 .irq_unmask = s3c_irq_unmask,
279 .irq_ack = s3c_irq_ack,
Heiko Stuebnerbd7c0da2013-04-04 14:53:45 +0900280 .irq_set_type = s3c_irq_type,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800281};
282
Ben Dooksa21765a2007-02-11 18:31:01 +0100283static struct irq_chip s3c_irqext_chip = {
284 .name = "s3c-ext",
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800285 .irq_mask = s3c_irq_mask,
286 .irq_unmask = s3c_irq_unmask,
287 .irq_ack = s3c_irq_ack,
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900288 .irq_set_type = s3c_irqext_type,
Mark Brownf5aeffb2010-12-02 14:35:38 +0900289 .irq_set_wake = s3c_irqext_wake
Ben Dooksa21765a2007-02-11 18:31:01 +0100290};
291
292static struct irq_chip s3c_irq_eint0t4 = {
293 .name = "s3c-ext0",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900294 .irq_ack = s3c_irq_ack,
295 .irq_mask = s3c_irq_mask,
296 .irq_unmask = s3c_irq_unmask,
297 .irq_set_wake = s3c_irq_wake,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800298 .irq_set_type = s3c_irqext0_type,
Ben Dooksa21765a2007-02-11 18:31:01 +0100299};
300
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800301static void s3c_irq_demux(unsigned int irq, struct irq_desc *desc)
Ben Dooksa21765a2007-02-11 18:31:01 +0100302{
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800303 struct irq_chip *chip = irq_desc_get_chip(desc);
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900304 struct s3c_irq_data *irq_data = irq_desc_get_chip_data(desc);
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900305 struct s3c_irq_intc *intc = irq_data->intc;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800306 struct s3c_irq_intc *sub_intc = irq_data->sub_intc;
307 unsigned long src;
308 unsigned long msk;
309 unsigned int n;
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900310 unsigned int offset;
311
312 /* we're using individual domains for the non-dt case
313 * and one big domain for the dt case where the subintc
314 * starts at hwirq number 32.
315 */
316 offset = (intc->domain->of_node) ? 32 : 0;
Ben Dooksa21765a2007-02-11 18:31:01 +0100317
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800318 chained_irq_enter(chip, desc);
Ben Dooksa21765a2007-02-11 18:31:01 +0100319
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800320 src = __raw_readl(sub_intc->reg_pending);
321 msk = __raw_readl(sub_intc->reg_mask);
Ben Dooksa21765a2007-02-11 18:31:01 +0100322
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800323 src &= ~msk;
324 src &= irq_data->sub_bits;
Ben Dooksa21765a2007-02-11 18:31:01 +0100325
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800326 while (src) {
327 n = __ffs(src);
328 src &= ~(1 << n);
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900329 irq = irq_find_mapping(sub_intc->domain, offset + n);
330 generic_handle_irq(irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100331 }
332
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800333 chained_irq_exit(chip, desc);
Ben Dooksa21765a2007-02-11 18:31:01 +0100334}
335
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900336static inline int s3c24xx_handle_intc(struct s3c_irq_intc *intc,
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900337 struct pt_regs *regs, int intc_offset)
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900338{
339 int pnd;
340 int offset;
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900341
342 pnd = __raw_readl(intc->reg_intpnd);
343 if (!pnd)
344 return false;
345
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900346 /* non-dt machines use individual domains */
347 if (!intc->domain->of_node)
348 intc_offset = 0;
349
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900350 /* We have a problem that the INTOFFSET register does not always
351 * show one interrupt. Occasionally we get two interrupts through
352 * the prioritiser, and this causes the INTOFFSET register to show
353 * what looks like the logical-or of the two interrupt numbers.
354 *
355 * Thanks to Klaus, Shannon, et al for helping to debug this problem
356 */
357 offset = __raw_readl(intc->reg_intpnd + 4);
358
359 /* Find the bit manually, when the offset is wrong.
360 * The pending register only ever contains the one bit of the next
361 * interrupt to handle.
362 */
363 if (!(pnd & (1 << offset)))
364 offset = __ffs(pnd);
365
Marc Zyngiercf86bfd2014-08-26 11:03:26 +0100366 handle_domain_irq(intc->domain, intc_offset + offset, regs);
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900367 return true;
368}
369
370asmlinkage void __exception_irq_entry s3c24xx_handle_irq(struct pt_regs *regs)
371{
372 do {
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900373 if (likely(s3c_intc[0]))
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900374 if (s3c24xx_handle_intc(s3c_intc[0], regs, 0))
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900375 continue;
376
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900377 if (s3c_intc[2])
Heiko Stuebnerf0774d42013-04-04 14:55:10 +0900378 if (s3c24xx_handle_intc(s3c_intc[2], regs, 64))
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900379 continue;
380
381 break;
382 } while (1);
383}
384
Ben Dooks229fd8f2009-08-03 17:26:57 +0100385#ifdef CONFIG_FIQ
386/**
387 * s3c24xx_set_fiq - set the FIQ routing
388 * @irq: IRQ number to route to FIQ on processor.
389 * @on: Whether to route @irq to the FIQ, or to remove the FIQ routing.
390 *
391 * Change the state of the IRQ to FIQ routing depending on @irq and @on. If
392 * @on is true, the @irq is checked to see if it can be routed and the
393 * interrupt controller updated to route the IRQ. If @on is false, the FIQ
394 * routing is cleared, regardless of which @irq is specified.
395 */
396int s3c24xx_set_fiq(unsigned int irq, bool on)
397{
398 u32 intmod;
399 unsigned offs;
400
401 if (on) {
402 offs = irq - FIQ_START;
403 if (offs > 31)
404 return -EINVAL;
405
406 intmod = 1 << offs;
407 } else {
408 intmod = 0;
409 }
410
411 __raw_writel(intmod, S3C2410_INTMOD);
412 return 0;
413}
Ben Dooks0f13c822009-12-07 14:51:38 +0000414
415EXPORT_SYMBOL_GPL(s3c24xx_set_fiq);
Ben Dooks229fd8f2009-08-03 17:26:57 +0100416#endif
417
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800418static int s3c24xx_irq_map(struct irq_domain *h, unsigned int virq,
419 irq_hw_number_t hw)
420{
421 struct s3c_irq_intc *intc = h->host_data;
422 struct s3c_irq_data *irq_data = &intc->irqs[hw];
423 struct s3c_irq_intc *parent_intc;
424 struct s3c_irq_data *parent_irq_data;
425 unsigned int irqno;
426
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800427 /* attach controller pointer to irq_data */
428 irq_data->intc = intc;
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900429 irq_data->offset = hw;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800430
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900431 parent_intc = intc->parent;
432
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800433 /* set handler and flags */
434 switch (irq_data->type) {
435 case S3C_IRQTYPE_NONE:
436 return 0;
437 case S3C_IRQTYPE_EINT:
Heiko Stuebner1c8408e2013-02-12 10:12:09 -0800438 /* On the S3C2412, the EINT0to3 have a parent irq
439 * but need the s3c_irq_eint0t4 chip
440 */
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900441 if (parent_intc && (!soc_is_s3c2412() || hw >= 4))
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800442 irq_set_chip_and_handler(virq, &s3c_irqext_chip,
443 handle_edge_irq);
444 else
445 irq_set_chip_and_handler(virq, &s3c_irq_eint0t4,
446 handle_edge_irq);
447 break;
448 case S3C_IRQTYPE_EDGE:
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900449 if (parent_intc || intc->reg_pending == S3C2416_SRCPND2)
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800450 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
451 handle_edge_irq);
452 else
453 irq_set_chip_and_handler(virq, &s3c_irq_chip,
454 handle_edge_irq);
455 break;
456 case S3C_IRQTYPE_LEVEL:
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900457 if (parent_intc)
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800458 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
459 handle_level_irq);
460 else
461 irq_set_chip_and_handler(virq, &s3c_irq_chip,
462 handle_level_irq);
463 break;
464 default:
465 pr_err("irq-s3c24xx: unsupported irqtype %d\n", irq_data->type);
466 return -EINVAL;
467 }
Heiko Stuebnerf5a25522013-04-04 14:53:52 +0900468
469 irq_set_chip_data(virq, irq_data);
470
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800471 set_irq_flags(virq, IRQF_VALID);
472
Heiko Stuebner0fe3cb12013-03-07 12:38:16 +0900473 if (parent_intc && irq_data->type != S3C_IRQTYPE_NONE) {
Heiko Stuebner502a2982013-03-07 12:38:13 +0900474 if (irq_data->parent_irq > 31) {
475 pr_err("irq-s3c24xx: parent irq %lu is out of range\n",
476 irq_data->parent_irq);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800477 goto err;
478 }
479
Heiko Stuebner502a2982013-03-07 12:38:13 +0900480 parent_irq_data = &parent_intc->irqs[irq_data->parent_irq];
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800481 parent_irq_data->sub_intc = intc;
482 parent_irq_data->sub_bits |= (1UL << hw);
483
484 /* attach the demuxer to the parent irq */
485 irqno = irq_find_mapping(parent_intc->domain,
486 irq_data->parent_irq);
487 if (!irqno) {
488 pr_err("irq-s3c24xx: could not find mapping for parent irq %lu\n",
489 irq_data->parent_irq);
490 goto err;
491 }
492 irq_set_chained_handler(irqno, s3c_irq_demux);
493 }
494
495 return 0;
496
497err:
498 set_irq_flags(virq, 0);
499
500 /* the only error can result from bad mapping data*/
501 return -EINVAL;
502}
503
Krzysztof Kozlowski96009732015-04-27 21:54:24 +0900504static const struct irq_domain_ops s3c24xx_irq_ops = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800505 .map = s3c24xx_irq_map,
506 .xlate = irq_domain_xlate_twocell,
507};
508
509static void s3c24xx_clear_intc(struct s3c_irq_intc *intc)
510{
511 void __iomem *reg_source;
512 unsigned long pend;
513 unsigned long last;
514 int i;
515
516 /* if intpnd is set, read the next pending irq from there */
517 reg_source = intc->reg_intpnd ? intc->reg_intpnd : intc->reg_pending;
518
519 last = 0;
520 for (i = 0; i < 4; i++) {
521 pend = __raw_readl(reg_source);
522
523 if (pend == 0 || pend == last)
524 break;
525
526 __raw_writel(pend, intc->reg_pending);
527 if (intc->reg_intpnd)
528 __raw_writel(pend, intc->reg_intpnd);
529
530 pr_info("irq: clearing pending status %08x\n", (int)pend);
531 last = pend;
532 }
533}
534
Arnd Bergmannbc8fd902013-04-25 16:49:05 +0200535static struct s3c_irq_intc * __init s3c24xx_init_intc(struct device_node *np,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800536 struct s3c_irq_data *irq_data,
537 struct s3c_irq_intc *parent,
538 unsigned long address)
539{
540 struct s3c_irq_intc *intc;
541 void __iomem *base = (void *)0xf6000000; /* static mapping */
542 int irq_num;
543 int irq_start;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800544 int ret;
545
546 intc = kzalloc(sizeof(struct s3c_irq_intc), GFP_KERNEL);
547 if (!intc)
548 return ERR_PTR(-ENOMEM);
549
550 intc->irqs = irq_data;
551
552 if (parent)
553 intc->parent = parent;
554
555 /* select the correct data for the controller.
556 * Need to hard code the irq num start and offset
557 * to preserve the static mapping for now
558 */
559 switch (address) {
560 case 0x4a000000:
561 pr_debug("irq: found main intc\n");
562 intc->reg_pending = base;
563 intc->reg_mask = base + 0x08;
564 intc->reg_intpnd = base + 0x10;
565 irq_num = 32;
566 irq_start = S3C2410_IRQ(0);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800567 break;
568 case 0x4a000018:
569 pr_debug("irq: found subintc\n");
570 intc->reg_pending = base + 0x18;
571 intc->reg_mask = base + 0x1c;
572 irq_num = 29;
573 irq_start = S3C2410_IRQSUB(0);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800574 break;
575 case 0x4a000040:
576 pr_debug("irq: found intc2\n");
577 intc->reg_pending = base + 0x40;
578 intc->reg_mask = base + 0x48;
579 intc->reg_intpnd = base + 0x50;
580 irq_num = 8;
581 irq_start = S3C2416_IRQ(0);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800582 break;
583 case 0x560000a4:
584 pr_debug("irq: found eintc\n");
585 base = (void *)0xfd000000;
586
587 intc->reg_mask = base + 0xa4;
Linus Torvalds6fa52ed2013-05-04 12:31:18 -0700588 intc->reg_pending = base + 0xa8;
Heiko Stuebner5424f212013-02-12 10:12:04 -0800589 irq_num = 24;
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800590 irq_start = S3C2410_IRQ(32);
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800591 break;
592 default:
593 pr_err("irq: unsupported controller address\n");
594 ret = -EINVAL;
595 goto err;
596 }
597
598 /* now that all the data is complete, init the irq-domain */
599 s3c24xx_clear_intc(intc);
600 intc->domain = irq_domain_add_legacy(np, irq_num, irq_start,
Heiko Stuebner5424f212013-02-12 10:12:04 -0800601 0, &s3c24xx_irq_ops,
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800602 intc);
603 if (!intc->domain) {
604 pr_err("irq: could not create irq-domain\n");
605 ret = -EINVAL;
606 goto err;
607 }
608
Heiko Stuebner17453dd2013-03-07 12:38:25 +0900609 set_handle_irq(s3c24xx_handle_irq);
610
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800611 return intc;
612
613err:
614 kfree(intc);
615 return ERR_PTR(ret);
616}
Ben Dooks229fd8f2009-08-03 17:26:57 +0100617
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900618static struct s3c_irq_data init_eint[32] = {
619 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
620 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
621 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
622 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
623 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT4 */
624 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT5 */
625 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT6 */
626 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT7 */
627 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT8 */
628 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT9 */
629 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT10 */
630 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT11 */
631 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT12 */
632 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT13 */
633 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT14 */
634 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT15 */
635 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT16 */
636 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT17 */
637 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT18 */
638 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT19 */
639 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT20 */
640 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT21 */
641 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT22 */
642 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT23 */
643};
Ben Dooksa21765a2007-02-11 18:31:01 +0100644
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900645#ifdef CONFIG_CPU_S3C2410
646static struct s3c_irq_data init_s3c2410base[32] = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800647 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
648 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
649 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
650 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
651 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
652 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
653 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
654 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
655 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
656 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
657 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
658 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
659 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
660 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
661 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
662 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
663 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
664 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
665 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
666 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
667 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
668 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
669 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
670 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
671 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
672 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
673 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
674 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
675 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
676 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
677 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
678 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
679};
680
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900681static struct s3c_irq_data init_s3c2410subint[32] = {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800682 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
683 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
684 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
685 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
686 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
687 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
688 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
689 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
690 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
691 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
692 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
693};
694
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900695void __init s3c2410_init_irq(void)
Ben Dooksa21765a2007-02-11 18:31:01 +0100696{
Ben Dooks229fd8f2009-08-03 17:26:57 +0100697#ifdef CONFIG_FIQ
Shawn Guobc896632012-06-28 14:42:08 +0800698 init_FIQ(FIQ_START);
Ben Dooks229fd8f2009-08-03 17:26:57 +0100699#endif
700
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900701 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2410base[0], NULL,
702 0x4a000000);
703 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebner1f629b72013-01-29 10:25:22 -0800704 pr_err("irq: could not create main interrupt controller\n");
705 return;
Ben Dooksa21765a2007-02-11 18:31:01 +0100706 }
707
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900708 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2410subint[0],
709 s3c_intc[0], 0x4a000018);
710 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
Ben Dooksa21765a2007-02-11 18:31:01 +0100711}
Heiko Stuebnerf182aa12013-03-07 12:38:19 +0900712#endif
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800713
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800714#ifdef CONFIG_CPU_S3C2412
Heiko Stuebner42459442013-02-12 10:09:21 -0800715static struct s3c_irq_data init_s3c2412base[32] = {
Heiko Stuebner1c8408e2013-02-12 10:12:09 -0800716 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT0 */
717 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT1 */
718 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT2 */
719 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT3 */
Heiko Stuebner42459442013-02-12 10:09:21 -0800720 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
721 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
722 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
723 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
724 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
725 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
726 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
727 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
728 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
729 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
730 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
731 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
732 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
733 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
734 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
735 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
736 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
737 { .type = S3C_IRQTYPE_LEVEL, }, /* SDI/CF */
738 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
739 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
740 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
741 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
742 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
743 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
744 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
745 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
746 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
747 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
748};
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800749
Heiko Stuebner1c8408e2013-02-12 10:12:09 -0800750static struct s3c_irq_data init_s3c2412eint[32] = {
751 { .type = S3C_IRQTYPE_EINT, .parent_irq = 0 }, /* EINT0 */
752 { .type = S3C_IRQTYPE_EINT, .parent_irq = 1 }, /* EINT1 */
753 { .type = S3C_IRQTYPE_EINT, .parent_irq = 2 }, /* EINT2 */
754 { .type = S3C_IRQTYPE_EINT, .parent_irq = 3 }, /* EINT3 */
755 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT4 */
756 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT5 */
757 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT6 */
758 { .type = S3C_IRQTYPE_EINT, .parent_irq = 4 }, /* EINT7 */
759 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT8 */
760 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT9 */
761 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT10 */
762 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT11 */
763 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT12 */
764 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT13 */
765 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT14 */
766 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT15 */
767 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT16 */
768 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT17 */
769 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT18 */
770 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT19 */
771 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT20 */
772 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT21 */
773 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT22 */
774 { .type = S3C_IRQTYPE_EINT, .parent_irq = 5 }, /* EINT23 */
775};
776
Heiko Stuebner42459442013-02-12 10:09:21 -0800777static struct s3c_irq_data init_s3c2412subint[32] = {
778 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
779 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
780 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
781 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
782 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
783 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
784 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
785 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
786 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
787 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
788 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
789 { .type = S3C_IRQTYPE_NONE, },
790 { .type = S3C_IRQTYPE_NONE, },
791 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 21 }, /* SDI */
792 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 21 }, /* CF */
793};
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800794
Arnd Bergmannbc8fd902013-04-25 16:49:05 +0200795void __init s3c2412_init_irq(void)
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800796{
Heiko Stuebner42459442013-02-12 10:09:21 -0800797 pr_info("S3C2412: IRQ Support\n");
798
799#ifdef CONFIG_FIQ
800 init_FIQ(FIQ_START);
801#endif
802
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900803 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2412base[0], NULL,
804 0x4a000000);
805 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebner42459442013-02-12 10:09:21 -0800806 pr_err("irq: could not create main interrupt controller\n");
807 return;
808 }
809
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900810 s3c24xx_init_intc(NULL, &init_s3c2412eint[0], s3c_intc[0], 0x560000a4);
811 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2412subint[0],
812 s3c_intc[0], 0x4a000018);
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800813}
Heiko Stuebnerd3d5a2c2013-02-12 10:09:13 -0800814#endif
815
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800816#ifdef CONFIG_CPU_S3C2416
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800817static struct s3c_irq_data init_s3c2416base[32] = {
818 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
819 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
820 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
821 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
822 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
823 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
824 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
825 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
826 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
827 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
828 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
829 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
830 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
831 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
832 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
833 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
834 { .type = S3C_IRQTYPE_LEVEL, }, /* LCD */
835 { .type = S3C_IRQTYPE_LEVEL, }, /* DMA */
836 { .type = S3C_IRQTYPE_LEVEL, }, /* UART3 */
837 { .type = S3C_IRQTYPE_NONE, }, /* reserved */
838 { .type = S3C_IRQTYPE_EDGE, }, /* SDI1 */
839 { .type = S3C_IRQTYPE_EDGE, }, /* SDI0 */
840 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
841 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
842 { .type = S3C_IRQTYPE_EDGE, }, /* NAND */
843 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
844 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
845 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
846 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
847 { .type = S3C_IRQTYPE_NONE, },
848 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
849 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800850};
851
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800852static struct s3c_irq_data init_s3c2416subint[32] = {
853 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
854 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
855 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
856 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
857 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
858 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
859 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
860 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
861 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
862 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
863 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
864 { .type = S3C_IRQTYPE_NONE }, /* reserved */
865 { .type = S3C_IRQTYPE_NONE }, /* reserved */
866 { .type = S3C_IRQTYPE_NONE }, /* reserved */
867 { .type = S3C_IRQTYPE_NONE }, /* reserved */
868 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD2 */
869 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD3 */
870 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD4 */
871 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA0 */
872 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA1 */
873 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA2 */
874 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA3 */
875 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA4 */
876 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA5 */
877 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-RX */
878 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-TX */
879 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-ERR */
880 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
881 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800882};
883
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800884static struct s3c_irq_data init_s3c2416_second[32] = {
885 { .type = S3C_IRQTYPE_EDGE }, /* 2D */
Heiko Stuebner1ebc7e82013-04-04 14:53:41 +0900886 { .type = S3C_IRQTYPE_NONE }, /* reserved */
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800887 { .type = S3C_IRQTYPE_NONE }, /* reserved */
888 { .type = S3C_IRQTYPE_NONE }, /* reserved */
889 { .type = S3C_IRQTYPE_EDGE }, /* PCM0 */
Heiko Stuebner1ebc7e82013-04-04 14:53:41 +0900890 { .type = S3C_IRQTYPE_NONE }, /* reserved */
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800891 { .type = S3C_IRQTYPE_EDGE }, /* I2S0 */
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800892};
893
Heiko Stuebner4a282dd2013-01-29 10:25:22 -0800894void __init s3c2416_init_irq(void)
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800895{
Heiko Stuebner4a282dd2013-01-29 10:25:22 -0800896 pr_info("S3C2416: IRQ Support\n");
897
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800898#ifdef CONFIG_FIQ
899 init_FIQ(FIQ_START);
900#endif
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800901
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900902 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2416base[0], NULL,
903 0x4a000000);
904 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebner20f6c782013-01-29 10:25:22 -0800905 pr_err("irq: could not create main interrupt controller\n");
906 return;
907 }
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800908
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900909 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
910 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2416subint[0],
911 s3c_intc[0], 0x4a000018);
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800912
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900913 s3c_intc[2] = s3c24xx_init_intc(NULL, &init_s3c2416_second[0],
914 NULL, 0x4a000040);
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800915}
916
Heiko Stuebneref602eb2013-01-29 10:25:22 -0800917#endif
Heiko Stuebner6b628912013-01-29 10:25:22 -0800918
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800919#ifdef CONFIG_CPU_S3C2440
920static struct s3c_irq_data init_s3c2440base[32] = {
921 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
922 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
923 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
924 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
925 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
926 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
927 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
928 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
929 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
930 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
931 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
932 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
933 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
934 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
935 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
936 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
937 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
938 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
939 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
940 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
941 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
942 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
943 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
944 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
945 { .type = S3C_IRQTYPE_LEVEL, }, /* NFCON */
946 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
947 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
948 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
949 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
950 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
951 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
952 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -0800953};
954
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800955static struct s3c_irq_data init_s3c2440subint[32] = {
956 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
957 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
958 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
959 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
960 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
961 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
962 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
963 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
964 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
965 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
966 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
Heiko Stuebnere2714f72013-04-04 14:53:37 +0900967 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
968 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800969 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
970 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
Heiko Stuebner2286cf42013-02-12 09:59:24 -0800971};
972
Heiko Stuebner7cefed52013-02-12 09:59:27 -0800973void __init s3c2440_init_irq(void)
Heiko Stuebner2286cf42013-02-12 09:59:24 -0800974{
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800975 pr_info("S3C2440: IRQ Support\n");
Heiko Stuebner2286cf42013-02-12 09:59:24 -0800976
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800977#ifdef CONFIG_FIQ
978 init_FIQ(FIQ_START);
979#endif
Heiko Stuebnerce6c1642013-02-12 09:59:20 -0800980
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900981 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2440base[0], NULL,
982 0x4a000000);
983 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebnerf0301672013-02-12 09:59:35 -0800984 pr_err("irq: could not create main interrupt controller\n");
985 return;
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -0800986 }
Heiko Stuebner7cefed52013-02-12 09:59:27 -0800987
Heiko Stuebner658dc8f2013-04-04 14:53:49 +0900988 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
989 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2440subint[0],
990 s3c_intc[0], 0x4a000018);
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -0800991}
Heiko Stuebnerce6c1642013-02-12 09:59:20 -0800992#endif
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -0800993
Heiko Stuebnerce6c1642013-02-12 09:59:20 -0800994#ifdef CONFIG_CPU_S3C2442
Heiko Stuebner70644ad2013-02-12 09:59:31 -0800995static struct s3c_irq_data init_s3c2442base[32] = {
996 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
997 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
998 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
999 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
1000 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
1001 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
1002 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
1003 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
1004 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
1005 { .type = S3C_IRQTYPE_EDGE, }, /* WDT */
1006 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
1007 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
1008 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
1009 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
1010 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
1011 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
1012 { .type = S3C_IRQTYPE_EDGE, }, /* LCD */
1013 { .type = S3C_IRQTYPE_EDGE, }, /* DMA0 */
1014 { .type = S3C_IRQTYPE_EDGE, }, /* DMA1 */
1015 { .type = S3C_IRQTYPE_EDGE, }, /* DMA2 */
1016 { .type = S3C_IRQTYPE_EDGE, }, /* DMA3 */
1017 { .type = S3C_IRQTYPE_EDGE, }, /* SDI */
1018 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
1019 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
1020 { .type = S3C_IRQTYPE_LEVEL, }, /* NFCON */
1021 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
1022 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
1023 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
1024 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
1025 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
1026 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
1027 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
1028};
1029
1030static struct s3c_irq_data init_s3c2442subint[32] = {
1031 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
1032 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
1033 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
1034 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
1035 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
1036 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
1037 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
1038 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
1039 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
1040 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
1041 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
Heiko Stuebnere2714f72013-04-04 14:53:37 +09001042 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
1043 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001044};
1045
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001046void __init s3c2442_init_irq(void)
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -08001047{
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001048 pr_info("S3C2442: IRQ Support\n");
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001049
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001050#ifdef CONFIG_FIQ
1051 init_FIQ(FIQ_START);
1052#endif
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001053
Heiko Stuebner658dc8f2013-04-04 14:53:49 +09001054 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2442base[0], NULL,
1055 0x4a000000);
1056 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001057 pr_err("irq: could not create main interrupt controller\n");
1058 return;
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001059 }
Heiko Stuebner70644ad2013-02-12 09:59:31 -08001060
Heiko Stuebner658dc8f2013-04-04 14:53:49 +09001061 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
1062 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2442subint[0],
1063 s3c_intc[0], 0x4a000018);
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -08001064}
Heiko Stuebnerce6c1642013-02-12 09:59:20 -08001065#endif
Heiko Stuebner6f8d7ea2013-02-12 09:59:17 -08001066
Heiko Stuebner6b628912013-01-29 10:25:22 -08001067#ifdef CONFIG_CPU_S3C2443
Heiko Stuebnerf44ddba2013-01-29 10:25:23 -08001068static struct s3c_irq_data init_s3c2443base[32] = {
1069 { .type = S3C_IRQTYPE_EINT, }, /* EINT0 */
1070 { .type = S3C_IRQTYPE_EINT, }, /* EINT1 */
1071 { .type = S3C_IRQTYPE_EINT, }, /* EINT2 */
1072 { .type = S3C_IRQTYPE_EINT, }, /* EINT3 */
1073 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT4to7 */
1074 { .type = S3C_IRQTYPE_LEVEL, }, /* EINT8to23 */
1075 { .type = S3C_IRQTYPE_LEVEL, }, /* CAM */
1076 { .type = S3C_IRQTYPE_EDGE, }, /* nBATT_FLT */
1077 { .type = S3C_IRQTYPE_EDGE, }, /* TICK */
1078 { .type = S3C_IRQTYPE_LEVEL, }, /* WDT/AC97 */
1079 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER0 */
1080 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER1 */
1081 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER2 */
1082 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER3 */
1083 { .type = S3C_IRQTYPE_EDGE, }, /* TIMER4 */
1084 { .type = S3C_IRQTYPE_LEVEL, }, /* UART2 */
1085 { .type = S3C_IRQTYPE_LEVEL, }, /* LCD */
1086 { .type = S3C_IRQTYPE_LEVEL, }, /* DMA */
1087 { .type = S3C_IRQTYPE_LEVEL, }, /* UART3 */
1088 { .type = S3C_IRQTYPE_EDGE, }, /* CFON */
1089 { .type = S3C_IRQTYPE_EDGE, }, /* SDI1 */
1090 { .type = S3C_IRQTYPE_EDGE, }, /* SDI0 */
1091 { .type = S3C_IRQTYPE_EDGE, }, /* SPI0 */
1092 { .type = S3C_IRQTYPE_LEVEL, }, /* UART1 */
1093 { .type = S3C_IRQTYPE_EDGE, }, /* NAND */
1094 { .type = S3C_IRQTYPE_EDGE, }, /* USBD */
1095 { .type = S3C_IRQTYPE_EDGE, }, /* USBH */
1096 { .type = S3C_IRQTYPE_EDGE, }, /* IIC */
1097 { .type = S3C_IRQTYPE_LEVEL, }, /* UART0 */
1098 { .type = S3C_IRQTYPE_EDGE, }, /* SPI1 */
1099 { .type = S3C_IRQTYPE_EDGE, }, /* RTC */
1100 { .type = S3C_IRQTYPE_LEVEL, }, /* ADCPARENT */
Heiko Stuebner6b628912013-01-29 10:25:22 -08001101};
1102
Heiko Stuebner6b628912013-01-29 10:25:22 -08001103
Heiko Stuebnerf44ddba2013-01-29 10:25:23 -08001104static struct s3c_irq_data init_s3c2443subint[32] = {
1105 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-RX */
1106 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-TX */
1107 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 28 }, /* UART0-ERR */
1108 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-RX */
1109 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-TX */
1110 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 23 }, /* UART1-ERR */
1111 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-RX */
1112 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-TX */
1113 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 15 }, /* UART2-ERR */
1114 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* TC */
1115 { .type = S3C_IRQTYPE_EDGE, .parent_irq = 31 }, /* ADC */
1116 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_C */
1117 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 6 }, /* CAM_P */
1118 { .type = S3C_IRQTYPE_NONE }, /* reserved */
1119 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD1 */
1120 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD2 */
1121 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD3 */
1122 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 16 }, /* LCD4 */
1123 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA0 */
1124 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA1 */
1125 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA2 */
1126 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA3 */
1127 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA4 */
1128 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 17 }, /* DMA5 */
1129 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-RX */
1130 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-TX */
1131 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 18 }, /* UART3-ERR */
1132 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* WDT */
1133 { .type = S3C_IRQTYPE_LEVEL, .parent_irq = 9 }, /* AC97 */
Heiko Stuebner6b628912013-01-29 10:25:22 -08001134};
1135
Heiko Stuebnerb499b7a2013-01-29 10:25:23 -08001136void __init s3c2443_init_irq(void)
Heiko Stuebner6b628912013-01-29 10:25:22 -08001137{
Heiko Stuebnerb499b7a2013-01-29 10:25:23 -08001138 pr_info("S3C2443: IRQ Support\n");
1139
Heiko Stuebnerf44ddba2013-01-29 10:25:23 -08001140#ifdef CONFIG_FIQ
1141 init_FIQ(FIQ_START);
1142#endif
Heiko Stuebner6b628912013-01-29 10:25:22 -08001143
Heiko Stuebner658dc8f2013-04-04 14:53:49 +09001144 s3c_intc[0] = s3c24xx_init_intc(NULL, &init_s3c2443base[0], NULL,
1145 0x4a000000);
1146 if (IS_ERR(s3c_intc[0])) {
Heiko Stuebnerf44ddba2013-01-29 10:25:23 -08001147 pr_err("irq: could not create main interrupt controller\n");
1148 return;
1149 }
Heiko Stuebner6b628912013-01-29 10:25:22 -08001150
Heiko Stuebner658dc8f2013-04-04 14:53:49 +09001151 s3c24xx_init_intc(NULL, &init_eint[0], s3c_intc[0], 0x560000a4);
1152 s3c_intc[1] = s3c24xx_init_intc(NULL, &init_s3c2443subint[0],
1153 s3c_intc[0], 0x4a000018);
Heiko Stuebner6b628912013-01-29 10:25:22 -08001154}
Heiko Stuebner6b628912013-01-29 10:25:22 -08001155#endif
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001156
1157#ifdef CONFIG_OF
1158static int s3c24xx_irq_map_of(struct irq_domain *h, unsigned int virq,
1159 irq_hw_number_t hw)
1160{
1161 unsigned int ctrl_num = hw / 32;
1162 unsigned int intc_hw = hw % 32;
1163 struct s3c_irq_intc *intc = s3c_intc[ctrl_num];
1164 struct s3c_irq_intc *parent_intc = intc->parent;
1165 struct s3c_irq_data *irq_data = &intc->irqs[intc_hw];
1166
1167 /* attach controller pointer to irq_data */
1168 irq_data->intc = intc;
1169 irq_data->offset = intc_hw;
1170
1171 if (!parent_intc)
1172 irq_set_chip_and_handler(virq, &s3c_irq_chip, handle_edge_irq);
1173 else
1174 irq_set_chip_and_handler(virq, &s3c_irq_level_chip,
1175 handle_edge_irq);
1176
1177 irq_set_chip_data(virq, irq_data);
1178
1179 set_irq_flags(virq, IRQF_VALID);
1180
1181 return 0;
1182}
1183
1184/* Translate our of irq notation
1185 * format: <ctrl_num ctrl_irq parent_irq type>
1186 */
1187static int s3c24xx_irq_xlate_of(struct irq_domain *d, struct device_node *n,
1188 const u32 *intspec, unsigned int intsize,
1189 irq_hw_number_t *out_hwirq, unsigned int *out_type)
1190{
1191 struct s3c_irq_intc *intc;
1192 struct s3c_irq_intc *parent_intc;
1193 struct s3c_irq_data *irq_data;
1194 struct s3c_irq_data *parent_irq_data;
1195 int irqno;
1196
1197 if (WARN_ON(intsize < 4))
1198 return -EINVAL;
1199
1200 if (intspec[0] > 2 || !s3c_intc[intspec[0]]) {
1201 pr_err("controller number %d invalid\n", intspec[0]);
1202 return -EINVAL;
1203 }
1204 intc = s3c_intc[intspec[0]];
1205
1206 *out_hwirq = intspec[0] * 32 + intspec[2];
1207 *out_type = intspec[3] & IRQ_TYPE_SENSE_MASK;
1208
1209 parent_intc = intc->parent;
1210 if (parent_intc) {
1211 irq_data = &intc->irqs[intspec[2]];
1212 irq_data->parent_irq = intspec[1];
1213 parent_irq_data = &parent_intc->irqs[irq_data->parent_irq];
1214 parent_irq_data->sub_intc = intc;
1215 parent_irq_data->sub_bits |= (1UL << intspec[2]);
1216
1217 /* parent_intc is always s3c_intc[0], so no offset */
1218 irqno = irq_create_mapping(parent_intc->domain, intspec[1]);
1219 if (irqno < 0) {
1220 pr_err("irq: could not map parent interrupt\n");
1221 return irqno;
1222 }
1223
1224 irq_set_chained_handler(irqno, s3c_irq_demux);
1225 }
1226
1227 return 0;
1228}
1229
Krzysztof Kozlowski96009732015-04-27 21:54:24 +09001230static const struct irq_domain_ops s3c24xx_irq_ops_of = {
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001231 .map = s3c24xx_irq_map_of,
1232 .xlate = s3c24xx_irq_xlate_of,
1233};
1234
1235struct s3c24xx_irq_of_ctrl {
1236 char *name;
1237 unsigned long offset;
1238 struct s3c_irq_intc **handle;
1239 struct s3c_irq_intc **parent;
1240 struct irq_domain_ops *ops;
1241};
1242
1243static int __init s3c_init_intc_of(struct device_node *np,
1244 struct device_node *interrupt_parent,
1245 struct s3c24xx_irq_of_ctrl *s3c_ctrl, int num_ctrl)
1246{
1247 struct s3c_irq_intc *intc;
1248 struct s3c24xx_irq_of_ctrl *ctrl;
1249 struct irq_domain *domain;
1250 void __iomem *reg_base;
1251 int i;
1252
1253 reg_base = of_iomap(np, 0);
1254 if (!reg_base) {
1255 pr_err("irq-s3c24xx: could not map irq registers\n");
1256 return -EINVAL;
1257 }
1258
1259 domain = irq_domain_add_linear(np, num_ctrl * 32,
1260 &s3c24xx_irq_ops_of, NULL);
1261 if (!domain) {
1262 pr_err("irq: could not create irq-domain\n");
1263 return -EINVAL;
1264 }
1265
1266 for (i = 0; i < num_ctrl; i++) {
1267 ctrl = &s3c_ctrl[i];
1268
1269 pr_debug("irq: found controller %s\n", ctrl->name);
1270
1271 intc = kzalloc(sizeof(struct s3c_irq_intc), GFP_KERNEL);
1272 if (!intc)
1273 return -ENOMEM;
1274
1275 intc->domain = domain;
1276 intc->irqs = kzalloc(sizeof(struct s3c_irq_data) * 32,
1277 GFP_KERNEL);
1278 if (!intc->irqs) {
1279 kfree(intc);
1280 return -ENOMEM;
1281 }
1282
1283 if (ctrl->parent) {
1284 intc->reg_pending = reg_base + ctrl->offset;
1285 intc->reg_mask = reg_base + ctrl->offset + 0x4;
1286
1287 if (*(ctrl->parent)) {
1288 intc->parent = *(ctrl->parent);
1289 } else {
1290 pr_warn("irq: parent of %s missing\n",
1291 ctrl->name);
1292 kfree(intc->irqs);
1293 kfree(intc);
1294 continue;
1295 }
1296 } else {
1297 intc->reg_pending = reg_base + ctrl->offset;
1298 intc->reg_mask = reg_base + ctrl->offset + 0x08;
1299 intc->reg_intpnd = reg_base + ctrl->offset + 0x10;
1300 }
1301
1302 s3c24xx_clear_intc(intc);
1303 s3c_intc[i] = intc;
1304 }
1305
1306 set_handle_irq(s3c24xx_handle_irq);
1307
1308 return 0;
1309}
1310
1311static struct s3c24xx_irq_of_ctrl s3c2410_ctrl[] = {
1312 {
1313 .name = "intc",
1314 .offset = 0,
1315 }, {
1316 .name = "subintc",
1317 .offset = 0x18,
1318 .parent = &s3c_intc[0],
1319 }
1320};
1321
1322int __init s3c2410_init_intc_of(struct device_node *np,
Rob Herring4f410832014-05-12 11:35:52 -05001323 struct device_node *interrupt_parent)
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001324{
1325 return s3c_init_intc_of(np, interrupt_parent,
1326 s3c2410_ctrl, ARRAY_SIZE(s3c2410_ctrl));
1327}
1328IRQCHIP_DECLARE(s3c2410_irq, "samsung,s3c2410-irq", s3c2410_init_intc_of);
1329
1330static struct s3c24xx_irq_of_ctrl s3c2416_ctrl[] = {
1331 {
1332 .name = "intc",
1333 .offset = 0,
1334 }, {
1335 .name = "subintc",
1336 .offset = 0x18,
1337 .parent = &s3c_intc[0],
1338 }, {
1339 .name = "intc2",
1340 .offset = 0x40,
1341 }
1342};
1343
1344int __init s3c2416_init_intc_of(struct device_node *np,
Rob Herring4f410832014-05-12 11:35:52 -05001345 struct device_node *interrupt_parent)
Heiko Stuebnerf0774d42013-04-04 14:55:10 +09001346{
1347 return s3c_init_intc_of(np, interrupt_parent,
1348 s3c2416_ctrl, ARRAY_SIZE(s3c2416_ctrl));
1349}
1350IRQCHIP_DECLARE(s3c2416_irq, "samsung,s3c2416-irq", s3c2416_init_intc_of);
1351#endif