blob: fe57bbbf166bae61ccb21203e185b6e7e64c827c [file] [log] [blame]
Ben Dooksa21765a2007-02-11 18:31:01 +01001/* linux/arch/arm/plat-s3c24xx/irq.c
2 *
Ben Dookse02f8662009-11-13 22:54:13 +00003 * Copyright (c) 2003-2004 Simtec Electronics
Ben Dooksa21765a2007-02-11 18:31:01 +01004 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Ben Dooksa21765a2007-02-11 18:31:01 +010019*/
20
21#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/interrupt.h>
24#include <linux/ioport.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080025#include <linux/device.h>
Heiko Stuebnerde11c582011-06-02 12:57:41 +020026#include <linux/syscore_ops.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010027
Ben Dooksa21765a2007-02-11 18:31:01 +010028#include <asm/irq.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010029#include <asm/mach/irq.h>
30
Ben Dooks6af0e922008-10-21 14:06:47 +010031#include <plat/regs-irqtype.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010032
Ben Dooksa2b7ba92008-10-07 22:26:09 +010033#include <plat/cpu.h>
34#include <plat/pm.h>
35#include <plat/irq.h>
Ben Dooksa21765a2007-02-11 18:31:01 +010036
Ben Dooksa21765a2007-02-11 18:31:01 +010037static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090038s3c_irq_mask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +010039{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090040 unsigned int irqno = data->irq - IRQ_EINT0;
Ben Dooksa21765a2007-02-11 18:31:01 +010041 unsigned long mask;
42
Ben Dooksa21765a2007-02-11 18:31:01 +010043 mask = __raw_readl(S3C2410_INTMSK);
44 mask |= 1UL << irqno;
45 __raw_writel(mask, S3C2410_INTMSK);
46}
47
48static inline void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090049s3c_irq_ack(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +010050{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090051 unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
Ben Dooksa21765a2007-02-11 18:31:01 +010052
53 __raw_writel(bitval, S3C2410_SRCPND);
54 __raw_writel(bitval, S3C2410_INTPND);
55}
56
57static inline void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090058s3c_irq_maskack(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +010059{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090060 unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
Ben Dooksa21765a2007-02-11 18:31:01 +010061 unsigned long mask;
62
63 mask = __raw_readl(S3C2410_INTMSK);
64 __raw_writel(mask|bitval, S3C2410_INTMSK);
65
66 __raw_writel(bitval, S3C2410_SRCPND);
67 __raw_writel(bitval, S3C2410_INTPND);
68}
69
70
71static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090072s3c_irq_unmask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +010073{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090074 unsigned int irqno = data->irq;
Ben Dooksa21765a2007-02-11 18:31:01 +010075 unsigned long mask;
76
77 if (irqno != IRQ_TIMER4 && irqno != IRQ_EINT8t23)
78 irqdbf2("s3c_irq_unmask %d\n", irqno);
79
80 irqno -= IRQ_EINT0;
81
82 mask = __raw_readl(S3C2410_INTMSK);
83 mask &= ~(1UL << irqno);
84 __raw_writel(mask, S3C2410_INTMSK);
85}
86
87struct irq_chip s3c_irq_level_chip = {
88 .name = "s3c-level",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090089 .irq_ack = s3c_irq_maskack,
90 .irq_mask = s3c_irq_mask,
91 .irq_unmask = s3c_irq_unmask,
92 .irq_set_wake = s3c_irq_wake
Ben Dooksa21765a2007-02-11 18:31:01 +010093};
94
Ben Dooks0baada22007-12-23 03:09:33 +010095struct irq_chip s3c_irq_chip = {
Ben Dooksa21765a2007-02-11 18:31:01 +010096 .name = "s3c",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090097 .irq_ack = s3c_irq_ack,
98 .irq_mask = s3c_irq_mask,
99 .irq_unmask = s3c_irq_unmask,
100 .irq_set_wake = s3c_irq_wake
Ben Dooksa21765a2007-02-11 18:31:01 +0100101};
102
103static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900104s3c_irqext_mask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100105{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900106 unsigned int irqno = data->irq - EXTINT_OFF;
Ben Dooksa21765a2007-02-11 18:31:01 +0100107 unsigned long mask;
108
Ben Dooksa21765a2007-02-11 18:31:01 +0100109 mask = __raw_readl(S3C24XX_EINTMASK);
110 mask |= ( 1UL << irqno);
111 __raw_writel(mask, S3C24XX_EINTMASK);
112}
113
114static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900115s3c_irqext_ack(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100116{
117 unsigned long req;
118 unsigned long bit;
119 unsigned long mask;
120
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900121 bit = 1UL << (data->irq - EXTINT_OFF);
Ben Dooksa21765a2007-02-11 18:31:01 +0100122
123 mask = __raw_readl(S3C24XX_EINTMASK);
124
125 __raw_writel(bit, S3C24XX_EINTPEND);
126
127 req = __raw_readl(S3C24XX_EINTPEND);
128 req &= ~mask;
129
130 /* not sure if we should be acking the parent irq... */
131
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900132 if (data->irq <= IRQ_EINT7) {
Ben Dooksa21765a2007-02-11 18:31:01 +0100133 if ((req & 0xf0) == 0)
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900134 s3c_irq_ack(irq_get_irq_data(IRQ_EINT4t7));
Ben Dooksa21765a2007-02-11 18:31:01 +0100135 } else {
136 if ((req >> 8) == 0)
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900137 s3c_irq_ack(irq_get_irq_data(IRQ_EINT8t23));
Ben Dooksa21765a2007-02-11 18:31:01 +0100138 }
139}
140
141static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900142s3c_irqext_unmask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100143{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900144 unsigned int irqno = data->irq - EXTINT_OFF;
Ben Dooksa21765a2007-02-11 18:31:01 +0100145 unsigned long mask;
146
Ben Dooksa21765a2007-02-11 18:31:01 +0100147 mask = __raw_readl(S3C24XX_EINTMASK);
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900148 mask &= ~(1UL << irqno);
Ben Dooksa21765a2007-02-11 18:31:01 +0100149 __raw_writel(mask, S3C24XX_EINTMASK);
150}
151
152int
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900153s3c_irqext_type(struct irq_data *data, unsigned int type)
Ben Dooksa21765a2007-02-11 18:31:01 +0100154{
155 void __iomem *extint_reg;
156 void __iomem *gpcon_reg;
157 unsigned long gpcon_offset, extint_offset;
158 unsigned long newvalue = 0, value;
159
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900160 if ((data->irq >= IRQ_EINT0) && (data->irq <= IRQ_EINT3)) {
Ben Dooksa21765a2007-02-11 18:31:01 +0100161 gpcon_reg = S3C2410_GPFCON;
162 extint_reg = S3C24XX_EXTINT0;
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900163 gpcon_offset = (data->irq - IRQ_EINT0) * 2;
164 extint_offset = (data->irq - IRQ_EINT0) * 4;
165 } else if ((data->irq >= IRQ_EINT4) && (data->irq <= IRQ_EINT7)) {
Ben Dooksa21765a2007-02-11 18:31:01 +0100166 gpcon_reg = S3C2410_GPFCON;
167 extint_reg = S3C24XX_EXTINT0;
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900168 gpcon_offset = (data->irq - (EXTINT_OFF)) * 2;
169 extint_offset = (data->irq - (EXTINT_OFF)) * 4;
170 } else if ((data->irq >= IRQ_EINT8) && (data->irq <= IRQ_EINT15)) {
Ben Dooksa21765a2007-02-11 18:31:01 +0100171 gpcon_reg = S3C2410_GPGCON;
172 extint_reg = S3C24XX_EXTINT1;
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900173 gpcon_offset = (data->irq - IRQ_EINT8) * 2;
174 extint_offset = (data->irq - IRQ_EINT8) * 4;
175 } else if ((data->irq >= IRQ_EINT16) && (data->irq <= IRQ_EINT23)) {
Ben Dooksa21765a2007-02-11 18:31:01 +0100176 gpcon_reg = S3C2410_GPGCON;
177 extint_reg = S3C24XX_EXTINT2;
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900178 gpcon_offset = (data->irq - IRQ_EINT8) * 2;
179 extint_offset = (data->irq - IRQ_EINT16) * 4;
180 } else {
Ben Dooksa21765a2007-02-11 18:31:01 +0100181 return -1;
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900182 }
Ben Dooksa21765a2007-02-11 18:31:01 +0100183
184 /* Set the GPIO to external interrupt mode */
185 value = __raw_readl(gpcon_reg);
186 value = (value & ~(3 << gpcon_offset)) | (0x02 << gpcon_offset);
187 __raw_writel(value, gpcon_reg);
188
189 /* Set the external interrupt to pointed trigger type */
190 switch (type)
191 {
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100192 case IRQ_TYPE_NONE:
Ben Dooksa21765a2007-02-11 18:31:01 +0100193 printk(KERN_WARNING "No edge setting!\n");
194 break;
195
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100196 case IRQ_TYPE_EDGE_RISING:
Ben Dooksa21765a2007-02-11 18:31:01 +0100197 newvalue = S3C2410_EXTINT_RISEEDGE;
198 break;
199
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100200 case IRQ_TYPE_EDGE_FALLING:
Ben Dooksa21765a2007-02-11 18:31:01 +0100201 newvalue = S3C2410_EXTINT_FALLEDGE;
202 break;
203
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100204 case IRQ_TYPE_EDGE_BOTH:
Ben Dooksa21765a2007-02-11 18:31:01 +0100205 newvalue = S3C2410_EXTINT_BOTHEDGE;
206 break;
207
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100208 case IRQ_TYPE_LEVEL_LOW:
Ben Dooksa21765a2007-02-11 18:31:01 +0100209 newvalue = S3C2410_EXTINT_LOWLEV;
210 break;
211
Dmitry Baryshkov6cab4862008-07-27 04:23:31 +0100212 case IRQ_TYPE_LEVEL_HIGH:
Ben Dooksa21765a2007-02-11 18:31:01 +0100213 newvalue = S3C2410_EXTINT_HILEV;
214 break;
215
216 default:
217 printk(KERN_ERR "No such irq type %d", type);
218 return -1;
219 }
220
221 value = __raw_readl(extint_reg);
222 value = (value & ~(7 << extint_offset)) | (newvalue << extint_offset);
223 __raw_writel(value, extint_reg);
224
225 return 0;
226}
227
228static struct irq_chip s3c_irqext_chip = {
229 .name = "s3c-ext",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900230 .irq_mask = s3c_irqext_mask,
231 .irq_unmask = s3c_irqext_unmask,
232 .irq_ack = s3c_irqext_ack,
233 .irq_set_type = s3c_irqext_type,
Mark Brownf5aeffb2010-12-02 14:35:38 +0900234 .irq_set_wake = s3c_irqext_wake
Ben Dooksa21765a2007-02-11 18:31:01 +0100235};
236
237static struct irq_chip s3c_irq_eint0t4 = {
238 .name = "s3c-ext0",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900239 .irq_ack = s3c_irq_ack,
240 .irq_mask = s3c_irq_mask,
241 .irq_unmask = s3c_irq_unmask,
242 .irq_set_wake = s3c_irq_wake,
243 .irq_set_type = s3c_irqext_type,
Ben Dooksa21765a2007-02-11 18:31:01 +0100244};
245
246/* mask values for the parent registers for each of the interrupt types */
247
248#define INTMSK_UART0 (1UL << (IRQ_UART0 - IRQ_EINT0))
249#define INTMSK_UART1 (1UL << (IRQ_UART1 - IRQ_EINT0))
250#define INTMSK_UART2 (1UL << (IRQ_UART2 - IRQ_EINT0))
251#define INTMSK_ADCPARENT (1UL << (IRQ_ADCPARENT - IRQ_EINT0))
252
253
254/* UART0 */
255
256static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900257s3c_irq_uart0_mask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100258{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900259 s3c_irqsub_mask(data->irq, INTMSK_UART0, 7);
Ben Dooksa21765a2007-02-11 18:31:01 +0100260}
261
262static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900263s3c_irq_uart0_unmask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100264{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900265 s3c_irqsub_unmask(data->irq, INTMSK_UART0);
Ben Dooksa21765a2007-02-11 18:31:01 +0100266}
267
268static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900269s3c_irq_uart0_ack(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100270{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900271 s3c_irqsub_maskack(data->irq, INTMSK_UART0, 7);
Ben Dooksa21765a2007-02-11 18:31:01 +0100272}
273
274static struct irq_chip s3c_irq_uart0 = {
275 .name = "s3c-uart0",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900276 .irq_mask = s3c_irq_uart0_mask,
277 .irq_unmask = s3c_irq_uart0_unmask,
278 .irq_ack = s3c_irq_uart0_ack,
Ben Dooksa21765a2007-02-11 18:31:01 +0100279};
280
281/* UART1 */
282
283static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900284s3c_irq_uart1_mask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100285{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900286 s3c_irqsub_mask(data->irq, INTMSK_UART1, 7 << 3);
Ben Dooksa21765a2007-02-11 18:31:01 +0100287}
288
289static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900290s3c_irq_uart1_unmask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100291{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900292 s3c_irqsub_unmask(data->irq, INTMSK_UART1);
Ben Dooksa21765a2007-02-11 18:31:01 +0100293}
294
295static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900296s3c_irq_uart1_ack(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100297{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900298 s3c_irqsub_maskack(data->irq, INTMSK_UART1, 7 << 3);
Ben Dooksa21765a2007-02-11 18:31:01 +0100299}
300
301static struct irq_chip s3c_irq_uart1 = {
302 .name = "s3c-uart1",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900303 .irq_mask = s3c_irq_uart1_mask,
304 .irq_unmask = s3c_irq_uart1_unmask,
305 .irq_ack = s3c_irq_uart1_ack,
Ben Dooksa21765a2007-02-11 18:31:01 +0100306};
307
308/* UART2 */
309
310static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900311s3c_irq_uart2_mask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100312{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900313 s3c_irqsub_mask(data->irq, INTMSK_UART2, 7 << 6);
Ben Dooksa21765a2007-02-11 18:31:01 +0100314}
315
316static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900317s3c_irq_uart2_unmask(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100318{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900319 s3c_irqsub_unmask(data->irq, INTMSK_UART2);
Ben Dooksa21765a2007-02-11 18:31:01 +0100320}
321
322static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900323s3c_irq_uart2_ack(struct irq_data *data)
Ben Dooksa21765a2007-02-11 18:31:01 +0100324{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900325 s3c_irqsub_maskack(data->irq, INTMSK_UART2, 7 << 6);
Ben Dooksa21765a2007-02-11 18:31:01 +0100326}
327
328static struct irq_chip s3c_irq_uart2 = {
329 .name = "s3c-uart2",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900330 .irq_mask = s3c_irq_uart2_mask,
331 .irq_unmask = s3c_irq_uart2_unmask,
332 .irq_ack = s3c_irq_uart2_ack,
Ben Dooksa21765a2007-02-11 18:31:01 +0100333};
334
335/* ADC and Touchscreen */
336
337static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900338s3c_irq_adc_mask(struct irq_data *d)
Ben Dooksa21765a2007-02-11 18:31:01 +0100339{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900340 s3c_irqsub_mask(d->irq, INTMSK_ADCPARENT, 3 << 9);
Ben Dooksa21765a2007-02-11 18:31:01 +0100341}
342
343static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900344s3c_irq_adc_unmask(struct irq_data *d)
Ben Dooksa21765a2007-02-11 18:31:01 +0100345{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900346 s3c_irqsub_unmask(d->irq, INTMSK_ADCPARENT);
Ben Dooksa21765a2007-02-11 18:31:01 +0100347}
348
349static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900350s3c_irq_adc_ack(struct irq_data *d)
Ben Dooksa21765a2007-02-11 18:31:01 +0100351{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900352 s3c_irqsub_ack(d->irq, INTMSK_ADCPARENT, 3 << 9);
Ben Dooksa21765a2007-02-11 18:31:01 +0100353}
354
355static struct irq_chip s3c_irq_adc = {
356 .name = "s3c-adc",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900357 .irq_mask = s3c_irq_adc_mask,
358 .irq_unmask = s3c_irq_adc_unmask,
359 .irq_ack = s3c_irq_adc_ack,
Ben Dooksa21765a2007-02-11 18:31:01 +0100360};
361
362/* irq demux for adc */
363static void s3c_irq_demux_adc(unsigned int irq,
364 struct irq_desc *desc)
365{
366 unsigned int subsrc, submsk;
367 unsigned int offset = 9;
Ben Dooksa21765a2007-02-11 18:31:01 +0100368
369 /* read the current pending interrupts, and the mask
370 * for what it is available */
371
372 subsrc = __raw_readl(S3C2410_SUBSRCPND);
373 submsk = __raw_readl(S3C2410_INTSUBMSK);
374
375 subsrc &= ~submsk;
376 subsrc >>= offset;
377 subsrc &= 3;
378
379 if (subsrc != 0) {
380 if (subsrc & 1) {
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100381 generic_handle_irq(IRQ_TC);
Ben Dooksa21765a2007-02-11 18:31:01 +0100382 }
383 if (subsrc & 2) {
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100384 generic_handle_irq(IRQ_ADC);
Ben Dooksa21765a2007-02-11 18:31:01 +0100385 }
386 }
387}
388
389static void s3c_irq_demux_uart(unsigned int start)
390{
391 unsigned int subsrc, submsk;
392 unsigned int offset = start - IRQ_S3CUART_RX0;
Ben Dooksa21765a2007-02-11 18:31:01 +0100393
394 /* read the current pending interrupts, and the mask
395 * for what it is available */
396
397 subsrc = __raw_readl(S3C2410_SUBSRCPND);
398 submsk = __raw_readl(S3C2410_INTSUBMSK);
399
400 irqdbf2("s3c_irq_demux_uart: start=%d (%d), subsrc=0x%08x,0x%08x\n",
401 start, offset, subsrc, submsk);
402
403 subsrc &= ~submsk;
404 subsrc >>= offset;
405 subsrc &= 7;
406
407 if (subsrc != 0) {
Ben Dooksa21765a2007-02-11 18:31:01 +0100408 if (subsrc & 1)
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100409 generic_handle_irq(start);
Ben Dooksa21765a2007-02-11 18:31:01 +0100410
411 if (subsrc & 2)
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100412 generic_handle_irq(start+1);
Ben Dooksa21765a2007-02-11 18:31:01 +0100413
414 if (subsrc & 4)
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100415 generic_handle_irq(start+2);
Ben Dooksa21765a2007-02-11 18:31:01 +0100416 }
417}
418
419/* uart demux entry points */
420
421static void
422s3c_irq_demux_uart0(unsigned int irq,
423 struct irq_desc *desc)
424{
425 irq = irq;
426 s3c_irq_demux_uart(IRQ_S3CUART_RX0);
427}
428
429static void
430s3c_irq_demux_uart1(unsigned int irq,
431 struct irq_desc *desc)
432{
433 irq = irq;
434 s3c_irq_demux_uart(IRQ_S3CUART_RX1);
435}
436
437static void
438s3c_irq_demux_uart2(unsigned int irq,
439 struct irq_desc *desc)
440{
441 irq = irq;
442 s3c_irq_demux_uart(IRQ_S3CUART_RX2);
443}
444
445static void
446s3c_irq_demux_extint8(unsigned int irq,
447 struct irq_desc *desc)
448{
449 unsigned long eintpnd = __raw_readl(S3C24XX_EINTPEND);
450 unsigned long eintmsk = __raw_readl(S3C24XX_EINTMASK);
451
452 eintpnd &= ~eintmsk;
453 eintpnd &= ~0xff; /* ignore lower irqs */
454
455 /* we may as well handle all the pending IRQs here */
456
457 while (eintpnd) {
458 irq = __ffs(eintpnd);
459 eintpnd &= ~(1<<irq);
460
461 irq += (IRQ_EINT4 - 4);
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100462 generic_handle_irq(irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100463 }
464
465}
466
467static void
468s3c_irq_demux_extint4t7(unsigned int irq,
469 struct irq_desc *desc)
470{
471 unsigned long eintpnd = __raw_readl(S3C24XX_EINTPEND);
472 unsigned long eintmsk = __raw_readl(S3C24XX_EINTMASK);
473
474 eintpnd &= ~eintmsk;
475 eintpnd &= 0xff; /* only lower irqs */
476
477 /* we may as well handle all the pending IRQs here */
478
479 while (eintpnd) {
480 irq = __ffs(eintpnd);
481 eintpnd &= ~(1<<irq);
482
483 irq += (IRQ_EINT4 - 4);
484
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100485 generic_handle_irq(irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100486 }
487}
488
Ben Dooks229fd8f2009-08-03 17:26:57 +0100489#ifdef CONFIG_FIQ
490/**
491 * s3c24xx_set_fiq - set the FIQ routing
492 * @irq: IRQ number to route to FIQ on processor.
493 * @on: Whether to route @irq to the FIQ, or to remove the FIQ routing.
494 *
495 * Change the state of the IRQ to FIQ routing depending on @irq and @on. If
496 * @on is true, the @irq is checked to see if it can be routed and the
497 * interrupt controller updated to route the IRQ. If @on is false, the FIQ
498 * routing is cleared, regardless of which @irq is specified.
499 */
500int s3c24xx_set_fiq(unsigned int irq, bool on)
501{
502 u32 intmod;
503 unsigned offs;
504
505 if (on) {
506 offs = irq - FIQ_START;
507 if (offs > 31)
508 return -EINVAL;
509
510 intmod = 1 << offs;
511 } else {
512 intmod = 0;
513 }
514
515 __raw_writel(intmod, S3C2410_INTMOD);
516 return 0;
517}
Ben Dooks0f13c822009-12-07 14:51:38 +0000518
519EXPORT_SYMBOL_GPL(s3c24xx_set_fiq);
Ben Dooks229fd8f2009-08-03 17:26:57 +0100520#endif
521
522
Ben Dooksa21765a2007-02-11 18:31:01 +0100523/* s3c24xx_init_irq
524 *
525 * Initialise S3C2410 IRQ system
526*/
527
528void __init s3c24xx_init_irq(void)
529{
530 unsigned long pend;
531 unsigned long last;
532 int irqno;
533 int i;
534
Ben Dooks229fd8f2009-08-03 17:26:57 +0100535#ifdef CONFIG_FIQ
Shawn Guobc896632012-06-28 14:42:08 +0800536 init_FIQ(FIQ_START);
Ben Dooks229fd8f2009-08-03 17:26:57 +0100537#endif
538
Ben Dooksa21765a2007-02-11 18:31:01 +0100539 irqdbf("s3c2410_init_irq: clearing interrupt status flags\n");
540
541 /* first, clear all interrupts pending... */
542
543 last = 0;
544 for (i = 0; i < 4; i++) {
545 pend = __raw_readl(S3C24XX_EINTPEND);
546
547 if (pend == 0 || pend == last)
548 break;
549
550 __raw_writel(pend, S3C24XX_EINTPEND);
551 printk("irq: clearing pending ext status %08x\n", (int)pend);
552 last = pend;
553 }
554
555 last = 0;
556 for (i = 0; i < 4; i++) {
557 pend = __raw_readl(S3C2410_INTPND);
558
559 if (pend == 0 || pend == last)
560 break;
561
562 __raw_writel(pend, S3C2410_SRCPND);
563 __raw_writel(pend, S3C2410_INTPND);
564 printk("irq: clearing pending status %08x\n", (int)pend);
565 last = pend;
566 }
567
568 last = 0;
569 for (i = 0; i < 4; i++) {
570 pend = __raw_readl(S3C2410_SUBSRCPND);
571
572 if (pend == 0 || pend == last)
573 break;
574
575 printk("irq: clearing subpending status %08x\n", (int)pend);
576 __raw_writel(pend, S3C2410_SUBSRCPND);
577 last = pend;
578 }
579
580 /* register the main interrupts */
581
582 irqdbf("s3c2410_init_irq: registering s3c2410 interrupt handlers\n");
583
584 for (irqno = IRQ_EINT4t7; irqno <= IRQ_ADCPARENT; irqno++) {
585 /* set all the s3c2410 internal irqs */
586
587 switch (irqno) {
588 /* deal with the special IRQs (cascaded) */
589
590 case IRQ_EINT4t7:
591 case IRQ_EINT8t23:
592 case IRQ_UART0:
593 case IRQ_UART1:
594 case IRQ_UART2:
595 case IRQ_ADCPARENT:
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100596 irq_set_chip_and_handler(irqno, &s3c_irq_level_chip,
597 handle_level_irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100598 break;
599
600 case IRQ_RESERVED6:
601 case IRQ_RESERVED24:
602 /* no IRQ here */
603 break;
604
605 default:
606 //irqdbf("registering irq %d (s3c irq)\n", irqno);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100607 irq_set_chip_and_handler(irqno, &s3c_irq_chip,
608 handle_edge_irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100609 set_irq_flags(irqno, IRQF_VALID);
610 }
611 }
612
613 /* setup the cascade irq handlers */
614
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100615 irq_set_chained_handler(IRQ_EINT4t7, s3c_irq_demux_extint4t7);
616 irq_set_chained_handler(IRQ_EINT8t23, s3c_irq_demux_extint8);
Ben Dooksa21765a2007-02-11 18:31:01 +0100617
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100618 irq_set_chained_handler(IRQ_UART0, s3c_irq_demux_uart0);
619 irq_set_chained_handler(IRQ_UART1, s3c_irq_demux_uart1);
620 irq_set_chained_handler(IRQ_UART2, s3c_irq_demux_uart2);
621 irq_set_chained_handler(IRQ_ADCPARENT, s3c_irq_demux_adc);
Ben Dooksa21765a2007-02-11 18:31:01 +0100622
623 /* external interrupts */
624
625 for (irqno = IRQ_EINT0; irqno <= IRQ_EINT3; irqno++) {
626 irqdbf("registering irq %d (ext int)\n", irqno);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100627 irq_set_chip_and_handler(irqno, &s3c_irq_eint0t4,
628 handle_edge_irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100629 set_irq_flags(irqno, IRQF_VALID);
630 }
631
632 for (irqno = IRQ_EINT4; irqno <= IRQ_EINT23; irqno++) {
633 irqdbf("registering irq %d (extended s3c irq)\n", irqno);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100634 irq_set_chip_and_handler(irqno, &s3c_irqext_chip,
635 handle_edge_irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100636 set_irq_flags(irqno, IRQF_VALID);
637 }
638
639 /* register the uart interrupts */
640
641 irqdbf("s3c2410: registering external interrupts\n");
642
643 for (irqno = IRQ_S3CUART_RX0; irqno <= IRQ_S3CUART_ERR0; irqno++) {
644 irqdbf("registering irq %d (s3c uart0 irq)\n", irqno);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100645 irq_set_chip_and_handler(irqno, &s3c_irq_uart0,
646 handle_level_irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100647 set_irq_flags(irqno, IRQF_VALID);
648 }
649
650 for (irqno = IRQ_S3CUART_RX1; irqno <= IRQ_S3CUART_ERR1; irqno++) {
651 irqdbf("registering irq %d (s3c uart1 irq)\n", irqno);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100652 irq_set_chip_and_handler(irqno, &s3c_irq_uart1,
653 handle_level_irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100654 set_irq_flags(irqno, IRQF_VALID);
655 }
656
657 for (irqno = IRQ_S3CUART_RX2; irqno <= IRQ_S3CUART_ERR2; irqno++) {
658 irqdbf("registering irq %d (s3c uart2 irq)\n", irqno);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100659 irq_set_chip_and_handler(irqno, &s3c_irq_uart2,
660 handle_level_irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100661 set_irq_flags(irqno, IRQF_VALID);
662 }
663
664 for (irqno = IRQ_TC; irqno <= IRQ_ADC; irqno++) {
665 irqdbf("registering irq %d (s3c adc irq)\n", irqno);
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100666 irq_set_chip_and_handler(irqno, &s3c_irq_adc, handle_edge_irq);
Ben Dooksa21765a2007-02-11 18:31:01 +0100667 set_irq_flags(irqno, IRQF_VALID);
668 }
669
670 irqdbf("s3c2410: registered interrupt handlers\n");
671}
Heiko Stuebnerde11c582011-06-02 12:57:41 +0200672
673struct syscore_ops s3c24xx_irq_syscore_ops = {
674 .suspend = s3c24xx_irq_suspend,
675 .resume = s3c24xx_irq_resume,
676};