blob: 683b3491ba3c4ae4634aed2e7a217363dc03f45b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/arm/mach-s3c2410/irq.c
2 *
3 * Copyright (c) 2003,2004 Simtec Electronics
4 * 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
19 *
20 * Changelog:
21 *
22 * 22-Jul-2004 Ben Dooks <ben@simtec.co.uk>
23 * Fixed compile warnings
24 *
25 * 22-Jul-2004 Roc Wu <cooloney@yahoo.com.cn>
26 * Fixed s3c_extirq_type
27 *
28 * 21-Jul-2004 Arnaud Patard (Rtp) <arnaud.patard@rtp-net.org>
29 * Addition of ADC/TC demux
30 *
31 * 04-Oct-2004 Klaus Fetscher <k.fetscher@fetron.de>
32 * Fix for set_irq_type() on low EINT numbers
33 *
34 * 05-Oct-2004 Ben Dooks <ben@simtec.co.uk>
35 * Tidy up KF's patch and sort out new release
36 *
37 * 05-Oct-2004 Ben Dooks <ben@simtec.co.uk>
38 * Add support for power management controls
39 *
40 * 04-Nov-2004 Ben Dooks
41 * Fix standard IRQ wake for EINT0..4 and RTC
42 *
Ben Dooks50273972005-06-28 22:42:06 +010043 * 22-Feb-2005 Ben Dooks
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 * Fixed edge-triggering on ADC IRQ
Ben Dooks50273972005-06-28 22:42:06 +010045 *
46 * 28-Jun-2005 Ben Dooks
47 * Mark IRQ_LCD valid
Ben Dooks7fcc1132005-07-26 19:20:27 +010048 *
49 * 25-Jul-2005 Ben Dooks
50 * Split the S3C2440 IRQ code to seperate file
Linus Torvalds1da177e2005-04-16 15:20:36 -070051*/
52
53#include <linux/init.h>
54#include <linux/module.h>
55#include <linux/interrupt.h>
56#include <linux/ioport.h>
57#include <linux/ptrace.h>
58#include <linux/sysdev.h>
59
60#include <asm/hardware.h>
61#include <asm/irq.h>
62#include <asm/io.h>
63
64#include <asm/mach/irq.h>
65
66#include <asm/arch/regs-irq.h>
67#include <asm/arch/regs-gpio.h>
68
69#include "cpu.h"
70#include "pm.h"
Ben Dooks7fcc1132005-07-26 19:20:27 +010071#include "irq.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/* wakeup irq control */
74
75#ifdef CONFIG_PM
76
77/* state for IRQs over sleep */
78
79/* default is to allow for EINT0..EINT15, and IRQ_RTC as wakeup sources
80 *
81 * set bit to 1 in allow bitfield to enable the wakeup settings on it
82*/
83
84unsigned long s3c_irqwake_intallow = 1L << (IRQ_RTC - IRQ_EINT0) | 0xfL;
85unsigned long s3c_irqwake_intmask = 0xffffffffL;
86unsigned long s3c_irqwake_eintallow = 0x0000fff0L;
87unsigned long s3c_irqwake_eintmask = 0xffffffffL;
88
Ben Dooksc6e58eb2006-09-09 21:24:13 +010089int
Linus Torvalds1da177e2005-04-16 15:20:36 -070090s3c_irq_wake(unsigned int irqno, unsigned int state)
91{
92 unsigned long irqbit = 1 << (irqno - IRQ_EINT0);
93
94 if (!(s3c_irqwake_intallow & irqbit))
95 return -ENOENT;
96
97 printk(KERN_INFO "wake %s for irq %d\n",
98 state ? "enabled" : "disabled", irqno);
99
100 if (!state)
101 s3c_irqwake_intmask |= irqbit;
102 else
103 s3c_irqwake_intmask &= ~irqbit;
104
105 return 0;
106}
107
108static int
109s3c_irqext_wake(unsigned int irqno, unsigned int state)
110{
111 unsigned long bit = 1L << (irqno - EXTINT_OFF);
112
113 if (!(s3c_irqwake_eintallow & bit))
114 return -ENOENT;
115
116 printk(KERN_INFO "wake %s for irq %d\n",
117 state ? "enabled" : "disabled", irqno);
118
119 if (!state)
120 s3c_irqwake_eintmask |= bit;
121 else
122 s3c_irqwake_eintmask &= ~bit;
123
124 return 0;
125}
126
127#else
128#define s3c_irqext_wake NULL
129#define s3c_irq_wake NULL
130#endif
131
132
133static void
134s3c_irq_mask(unsigned int irqno)
135{
136 unsigned long mask;
137
138 irqno -= IRQ_EINT0;
139
140 mask = __raw_readl(S3C2410_INTMSK);
141 mask |= 1UL << irqno;
142 __raw_writel(mask, S3C2410_INTMSK);
143}
144
145static inline void
146s3c_irq_ack(unsigned int irqno)
147{
148 unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
149
150 __raw_writel(bitval, S3C2410_SRCPND);
151 __raw_writel(bitval, S3C2410_INTPND);
152}
153
154static inline void
155s3c_irq_maskack(unsigned int irqno)
156{
157 unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
158 unsigned long mask;
159
160 mask = __raw_readl(S3C2410_INTMSK);
161 __raw_writel(mask|bitval, S3C2410_INTMSK);
162
163 __raw_writel(bitval, S3C2410_SRCPND);
164 __raw_writel(bitval, S3C2410_INTPND);
165}
166
167
168static void
169s3c_irq_unmask(unsigned int irqno)
170{
171 unsigned long mask;
172
173 if (irqno != IRQ_TIMER4 && irqno != IRQ_EINT8t23)
174 irqdbf2("s3c_irq_unmask %d\n", irqno);
175
176 irqno -= IRQ_EINT0;
177
178 mask = __raw_readl(S3C2410_INTMSK);
179 mask &= ~(1UL << irqno);
180 __raw_writel(mask, S3C2410_INTMSK);
181}
182
Ben Dooks7fcc1132005-07-26 19:20:27 +0100183struct irqchip s3c_irq_level_chip = {
Ben Dooks82606c62006-09-28 20:51:35 +0100184 .name = "s3c-level",
Ben Dooks625ac112006-09-28 20:45:29 +0100185 .ack = s3c_irq_maskack,
186 .mask = s3c_irq_mask,
187 .unmask = s3c_irq_unmask,
188 .set_wake = s3c_irq_wake
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189};
190
191static struct irqchip s3c_irq_chip = {
Ben Dooks82606c62006-09-28 20:51:35 +0100192 .name = "s3c",
Ben Dooks625ac112006-09-28 20:45:29 +0100193 .ack = s3c_irq_ack,
194 .mask = s3c_irq_mask,
195 .unmask = s3c_irq_unmask,
196 .set_wake = s3c_irq_wake
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199static void
200s3c_irqext_mask(unsigned int irqno)
201{
202 unsigned long mask;
203
204 irqno -= EXTINT_OFF;
205
Ben Dooksa019f4a2006-06-24 21:21:37 +0100206 mask = __raw_readl(S3C24XX_EINTMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 mask |= ( 1UL << irqno);
Ben Dooksa019f4a2006-06-24 21:21:37 +0100208 __raw_writel(mask, S3C24XX_EINTMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 if (irqno <= (IRQ_EINT7 - EXTINT_OFF)) {
211 /* check to see if all need masking */
212
213 if ((mask & (0xf << 4)) == (0xf << 4)) {
214 /* all masked, mask the parent */
215 s3c_irq_mask(IRQ_EINT4t7);
216 }
217 } else {
218 /* todo: the same check as above for the rest of the irq regs...*/
219
220 }
221}
222
223static void
224s3c_irqext_ack(unsigned int irqno)
225{
226 unsigned long req;
227 unsigned long bit;
228 unsigned long mask;
229
230 bit = 1UL << (irqno - EXTINT_OFF);
231
232
Ben Dooksa019f4a2006-06-24 21:21:37 +0100233 mask = __raw_readl(S3C24XX_EINTMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Ben Dooksa019f4a2006-06-24 21:21:37 +0100235 __raw_writel(bit, S3C24XX_EINTPEND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Ben Dooksa019f4a2006-06-24 21:21:37 +0100237 req = __raw_readl(S3C24XX_EINTPEND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 req &= ~mask;
239
240 /* not sure if we should be acking the parent irq... */
241
242 if (irqno <= IRQ_EINT7 ) {
243 if ((req & 0xf0) == 0)
244 s3c_irq_ack(IRQ_EINT4t7);
245 } else {
246 if ((req >> 8) == 0)
247 s3c_irq_ack(IRQ_EINT8t23);
248 }
249}
250
251static void
252s3c_irqext_unmask(unsigned int irqno)
253{
254 unsigned long mask;
255
256 irqno -= EXTINT_OFF;
257
Ben Dooksa019f4a2006-06-24 21:21:37 +0100258 mask = __raw_readl(S3C24XX_EINTMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 mask &= ~( 1UL << irqno);
Ben Dooksa019f4a2006-06-24 21:21:37 +0100260 __raw_writel(mask, S3C24XX_EINTMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 s3c_irq_unmask((irqno <= (IRQ_EINT7 - EXTINT_OFF)) ? IRQ_EINT4t7 : IRQ_EINT8t23);
263}
264
Ben Dooksc6e58eb2006-09-09 21:24:13 +0100265int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266s3c_irqext_type(unsigned int irq, unsigned int type)
267{
268 void __iomem *extint_reg;
269 void __iomem *gpcon_reg;
270 unsigned long gpcon_offset, extint_offset;
271 unsigned long newvalue = 0, value;
272
273 if ((irq >= IRQ_EINT0) && (irq <= IRQ_EINT3))
274 {
275 gpcon_reg = S3C2410_GPFCON;
Ben Dooks44cc7c92006-06-24 21:21:33 +0100276 extint_reg = S3C24XX_EXTINT0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 gpcon_offset = (irq - IRQ_EINT0) * 2;
278 extint_offset = (irq - IRQ_EINT0) * 4;
279 }
280 else if ((irq >= IRQ_EINT4) && (irq <= IRQ_EINT7))
281 {
282 gpcon_reg = S3C2410_GPFCON;
Ben Dooks44cc7c92006-06-24 21:21:33 +0100283 extint_reg = S3C24XX_EXTINT0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 gpcon_offset = (irq - (EXTINT_OFF)) * 2;
285 extint_offset = (irq - (EXTINT_OFF)) * 4;
286 }
287 else if ((irq >= IRQ_EINT8) && (irq <= IRQ_EINT15))
288 {
289 gpcon_reg = S3C2410_GPGCON;
Ben Dooks44cc7c92006-06-24 21:21:33 +0100290 extint_reg = S3C24XX_EXTINT1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 gpcon_offset = (irq - IRQ_EINT8) * 2;
292 extint_offset = (irq - IRQ_EINT8) * 4;
293 }
294 else if ((irq >= IRQ_EINT16) && (irq <= IRQ_EINT23))
295 {
296 gpcon_reg = S3C2410_GPGCON;
Ben Dooks44cc7c92006-06-24 21:21:33 +0100297 extint_reg = S3C24XX_EXTINT2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 gpcon_offset = (irq - IRQ_EINT8) * 2;
299 extint_offset = (irq - IRQ_EINT16) * 4;
300 } else
301 return -1;
302
303 /* Set the GPIO to external interrupt mode */
304 value = __raw_readl(gpcon_reg);
305 value = (value & ~(3 << gpcon_offset)) | (0x02 << gpcon_offset);
306 __raw_writel(value, gpcon_reg);
307
308 /* Set the external interrupt to pointed trigger type */
309 switch (type)
310 {
311 case IRQT_NOEDGE:
312 printk(KERN_WARNING "No edge setting!\n");
313 break;
314
315 case IRQT_RISING:
316 newvalue = S3C2410_EXTINT_RISEEDGE;
317 break;
318
319 case IRQT_FALLING:
320 newvalue = S3C2410_EXTINT_FALLEDGE;
321 break;
322
323 case IRQT_BOTHEDGE:
324 newvalue = S3C2410_EXTINT_BOTHEDGE;
325 break;
326
327 case IRQT_LOW:
328 newvalue = S3C2410_EXTINT_LOWLEV;
329 break;
330
331 case IRQT_HIGH:
332 newvalue = S3C2410_EXTINT_HILEV;
333 break;
334
335 default:
336 printk(KERN_ERR "No such irq type %d", type);
337 return -1;
338 }
339
340 value = __raw_readl(extint_reg);
341 value = (value & ~(7 << extint_offset)) | (newvalue << extint_offset);
342 __raw_writel(value, extint_reg);
343
344 return 0;
345}
346
347static struct irqchip s3c_irqext_chip = {
Ben Dooks82606c62006-09-28 20:51:35 +0100348 .name = "s3c-ext",
Ben Dooks625ac112006-09-28 20:45:29 +0100349 .mask = s3c_irqext_mask,
350 .unmask = s3c_irqext_unmask,
351 .ack = s3c_irqext_ack,
352 .set_type = s3c_irqext_type,
353 .set_wake = s3c_irqext_wake
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354};
355
356static struct irqchip s3c_irq_eint0t4 = {
Ben Dooks82606c62006-09-28 20:51:35 +0100357 .name = "s3c-ext0",
Ben Dooks625ac112006-09-28 20:45:29 +0100358 .ack = s3c_irq_ack,
359 .mask = s3c_irq_mask,
360 .unmask = s3c_irq_unmask,
361 .set_wake = s3c_irq_wake,
362 .set_type = s3c_irqext_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363};
364
365/* mask values for the parent registers for each of the interrupt types */
366
367#define INTMSK_UART0 (1UL << (IRQ_UART0 - IRQ_EINT0))
368#define INTMSK_UART1 (1UL << (IRQ_UART1 - IRQ_EINT0))
369#define INTMSK_UART2 (1UL << (IRQ_UART2 - IRQ_EINT0))
370#define INTMSK_ADCPARENT (1UL << (IRQ_ADCPARENT - IRQ_EINT0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373/* UART0 */
374
375static void
376s3c_irq_uart0_mask(unsigned int irqno)
377{
378 s3c_irqsub_mask(irqno, INTMSK_UART0, 7);
379}
380
381static void
382s3c_irq_uart0_unmask(unsigned int irqno)
383{
384 s3c_irqsub_unmask(irqno, INTMSK_UART0);
385}
386
387static void
388s3c_irq_uart0_ack(unsigned int irqno)
389{
390 s3c_irqsub_maskack(irqno, INTMSK_UART0, 7);
391}
392
393static struct irqchip s3c_irq_uart0 = {
Ben Dooks82606c62006-09-28 20:51:35 +0100394 .name = "s3c-uart0",
Ben Dooks625ac112006-09-28 20:45:29 +0100395 .mask = s3c_irq_uart0_mask,
396 .unmask = s3c_irq_uart0_unmask,
397 .ack = s3c_irq_uart0_ack,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398};
399
400/* UART1 */
401
402static void
403s3c_irq_uart1_mask(unsigned int irqno)
404{
405 s3c_irqsub_mask(irqno, INTMSK_UART1, 7 << 3);
406}
407
408static void
409s3c_irq_uart1_unmask(unsigned int irqno)
410{
411 s3c_irqsub_unmask(irqno, INTMSK_UART1);
412}
413
414static void
415s3c_irq_uart1_ack(unsigned int irqno)
416{
417 s3c_irqsub_maskack(irqno, INTMSK_UART1, 7 << 3);
418}
419
420static struct irqchip s3c_irq_uart1 = {
Ben Dooks82606c62006-09-28 20:51:35 +0100421 .name = "s3c-uart1",
Ben Dooks625ac112006-09-28 20:45:29 +0100422 .mask = s3c_irq_uart1_mask,
423 .unmask = s3c_irq_uart1_unmask,
424 .ack = s3c_irq_uart1_ack,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425};
426
427/* UART2 */
428
429static void
430s3c_irq_uart2_mask(unsigned int irqno)
431{
432 s3c_irqsub_mask(irqno, INTMSK_UART2, 7 << 6);
433}
434
435static void
436s3c_irq_uart2_unmask(unsigned int irqno)
437{
438 s3c_irqsub_unmask(irqno, INTMSK_UART2);
439}
440
441static void
442s3c_irq_uart2_ack(unsigned int irqno)
443{
444 s3c_irqsub_maskack(irqno, INTMSK_UART2, 7 << 6);
445}
446
447static struct irqchip s3c_irq_uart2 = {
Ben Dooks82606c62006-09-28 20:51:35 +0100448 .name = "s3c-uart2",
Ben Dooks625ac112006-09-28 20:45:29 +0100449 .mask = s3c_irq_uart2_mask,
450 .unmask = s3c_irq_uart2_unmask,
451 .ack = s3c_irq_uart2_ack,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452};
453
454/* ADC and Touchscreen */
455
456static void
457s3c_irq_adc_mask(unsigned int irqno)
458{
459 s3c_irqsub_mask(irqno, INTMSK_ADCPARENT, 3 << 9);
460}
461
462static void
463s3c_irq_adc_unmask(unsigned int irqno)
464{
465 s3c_irqsub_unmask(irqno, INTMSK_ADCPARENT);
466}
467
468static void
469s3c_irq_adc_ack(unsigned int irqno)
470{
471 s3c_irqsub_ack(irqno, INTMSK_ADCPARENT, 3 << 9);
472}
473
474static struct irqchip s3c_irq_adc = {
Ben Dooks82606c62006-09-28 20:51:35 +0100475 .name = "s3c-adc",
Ben Dooks625ac112006-09-28 20:45:29 +0100476 .mask = s3c_irq_adc_mask,
477 .unmask = s3c_irq_adc_unmask,
478 .ack = s3c_irq_adc_ack,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479};
480
481/* irq demux for adc */
482static void s3c_irq_demux_adc(unsigned int irq,
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700483 struct irqdesc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
485 unsigned int subsrc, submsk;
486 unsigned int offset = 9;
487 struct irqdesc *mydesc;
488
489 /* read the current pending interrupts, and the mask
490 * for what it is available */
491
492 subsrc = __raw_readl(S3C2410_SUBSRCPND);
493 submsk = __raw_readl(S3C2410_INTSUBMSK);
494
495 subsrc &= ~submsk;
496 subsrc >>= offset;
497 subsrc &= 3;
498
499 if (subsrc != 0) {
500 if (subsrc & 1) {
501 mydesc = irq_desc + IRQ_TC;
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700502 desc_handle_irq(IRQ_TC, mydesc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504 if (subsrc & 2) {
505 mydesc = irq_desc + IRQ_ADC;
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700506 desc_handle_irq(IRQ_ADC, mydesc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
508 }
509}
510
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700511static void s3c_irq_demux_uart(unsigned int start)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
513 unsigned int subsrc, submsk;
514 unsigned int offset = start - IRQ_S3CUART_RX0;
515 struct irqdesc *desc;
516
517 /* read the current pending interrupts, and the mask
518 * for what it is available */
519
520 subsrc = __raw_readl(S3C2410_SUBSRCPND);
521 submsk = __raw_readl(S3C2410_INTSUBMSK);
522
523 irqdbf2("s3c_irq_demux_uart: start=%d (%d), subsrc=0x%08x,0x%08x\n",
524 start, offset, subsrc, submsk);
525
526 subsrc &= ~submsk;
527 subsrc >>= offset;
528 subsrc &= 7;
529
530 if (subsrc != 0) {
531 desc = irq_desc + start;
532
533 if (subsrc & 1)
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700534 desc_handle_irq(start, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 desc++;
537
538 if (subsrc & 2)
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700539 desc_handle_irq(start+1, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541 desc++;
542
543 if (subsrc & 4)
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700544 desc_handle_irq(start+2, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 }
546}
547
548/* uart demux entry points */
549
550static void
551s3c_irq_demux_uart0(unsigned int irq,
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700552 struct irqdesc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
554 irq = irq;
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700555 s3c_irq_demux_uart(IRQ_S3CUART_RX0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
558static void
559s3c_irq_demux_uart1(unsigned int irq,
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700560 struct irqdesc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561{
562 irq = irq;
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700563 s3c_irq_demux_uart(IRQ_S3CUART_RX1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564}
565
566static void
567s3c_irq_demux_uart2(unsigned int irq,
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700568 struct irqdesc *desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569{
570 irq = irq;
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700571 s3c_irq_demux_uart(IRQ_S3CUART_RX2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
573
Ben Dooksa019f4a2006-06-24 21:21:37 +0100574static void
Ben Dooks38e05332006-09-28 20:40:50 +0100575s3c_irq_demux_extint8(unsigned int irq,
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700576 struct irqdesc *desc)
Ben Dooksa019f4a2006-06-24 21:21:37 +0100577{
578 unsigned long eintpnd = __raw_readl(S3C24XX_EINTPEND);
579 unsigned long eintmsk = __raw_readl(S3C24XX_EINTMASK);
580
581 eintpnd &= ~eintmsk;
Ben Dooks38e05332006-09-28 20:40:50 +0100582 eintpnd &= ~0xff; /* ignore lower irqs */
Ben Dooksa019f4a2006-06-24 21:21:37 +0100583
Ben Dooks38e05332006-09-28 20:40:50 +0100584 /* we may as well handle all the pending IRQs here */
585
586 while (eintpnd) {
587 irq = __ffs(eintpnd);
588 eintpnd &= ~(1<<irq);
589
590 irq += (IRQ_EINT4 - 4);
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700591 desc_handle_irq(irq, irq_desc + irq);
Ben Dooks38e05332006-09-28 20:40:50 +0100592 }
593
594}
595
596static void
597s3c_irq_demux_extint4t7(unsigned int irq,
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700598 struct irqdesc *desc)
Ben Dooks38e05332006-09-28 20:40:50 +0100599{
600 unsigned long eintpnd = __raw_readl(S3C24XX_EINTPEND);
601 unsigned long eintmsk = __raw_readl(S3C24XX_EINTMASK);
602
603 eintpnd &= ~eintmsk;
604 eintpnd &= 0xff; /* only lower irqs */
605
606 /* we may as well handle all the pending IRQs here */
607
608 while (eintpnd) {
609 irq = __ffs(eintpnd);
610 eintpnd &= ~(1<<irq);
611
612 irq += (IRQ_EINT4 - 4);
Ben Dooksa019f4a2006-06-24 21:21:37 +0100613
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700614 desc_handle_irq(irq, irq_desc + irq);
Ben Dooksa019f4a2006-06-24 21:21:37 +0100615 }
616}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Ben Dooks1e582fc2006-09-16 00:01:39 +0100618#ifdef CONFIG_PM
619
620static struct sleep_save irq_save[] = {
621 SAVE_ITEM(S3C2410_INTMSK),
622 SAVE_ITEM(S3C2410_INTSUBMSK),
623};
624
625/* the extint values move between the s3c2410/s3c2440 and the s3c2412
626 * so we use an array to hold them, and to calculate the address of
627 * the register at run-time
628*/
629
630static unsigned long save_extint[3];
631static unsigned long save_eintflt[4];
632static unsigned long save_eintmask;
633
634int s3c24xx_irq_suspend(struct sys_device *dev, pm_message_t state)
635{
636 unsigned int i;
637
638 for (i = 0; i < ARRAY_SIZE(save_extint); i++)
639 save_extint[i] = __raw_readl(S3C24XX_EXTINT0 + (i*4));
640
641 for (i = 0; i < ARRAY_SIZE(save_eintflt); i++)
642 save_eintflt[i] = __raw_readl(S3C24XX_EINFLT0 + (i*4));
643
644 s3c2410_pm_do_save(irq_save, ARRAY_SIZE(irq_save));
645 save_eintmask = __raw_readl(S3C24XX_EINTMASK);
646
647 return 0;
648}
649
650int s3c24xx_irq_resume(struct sys_device *dev)
651{
652 unsigned int i;
653
654 for (i = 0; i < ARRAY_SIZE(save_extint); i++)
655 __raw_writel(save_extint[i], S3C24XX_EXTINT0 + (i*4));
656
657 for (i = 0; i < ARRAY_SIZE(save_eintflt); i++)
658 __raw_writel(save_eintflt[i], S3C24XX_EINFLT0 + (i*4));
659
660 s3c2410_pm_do_restore(irq_save, ARRAY_SIZE(irq_save));
661 __raw_writel(save_eintmask, S3C24XX_EINTMASK);
662
663 return 0;
664}
665
666#else
667#define s3c24xx_irq_suspend NULL
668#define s3c24xx_irq_resume NULL
669#endif
670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671/* s3c24xx_init_irq
672 *
673 * Initialise S3C2410 IRQ system
674*/
675
676void __init s3c24xx_init_irq(void)
677{
678 unsigned long pend;
679 unsigned long last;
680 int irqno;
681 int i;
682
683 irqdbf("s3c2410_init_irq: clearing interrupt status flags\n");
684
685 /* first, clear all interrupts pending... */
686
687 last = 0;
688 for (i = 0; i < 4; i++) {
Ben Dooksa019f4a2006-06-24 21:21:37 +0100689 pend = __raw_readl(S3C24XX_EINTPEND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 if (pend == 0 || pend == last)
692 break;
693
Ben Dooksa019f4a2006-06-24 21:21:37 +0100694 __raw_writel(pend, S3C24XX_EINTPEND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 printk("irq: clearing pending ext status %08x\n", (int)pend);
696 last = pend;
697 }
698
699 last = 0;
700 for (i = 0; i < 4; i++) {
701 pend = __raw_readl(S3C2410_INTPND);
702
703 if (pend == 0 || pend == last)
704 break;
705
706 __raw_writel(pend, S3C2410_SRCPND);
707 __raw_writel(pend, S3C2410_INTPND);
708 printk("irq: clearing pending status %08x\n", (int)pend);
709 last = pend;
710 }
711
712 last = 0;
713 for (i = 0; i < 4; i++) {
714 pend = __raw_readl(S3C2410_SUBSRCPND);
715
716 if (pend == 0 || pend == last)
717 break;
718
719 printk("irq: clearing subpending status %08x\n", (int)pend);
720 __raw_writel(pend, S3C2410_SUBSRCPND);
721 last = pend;
722 }
723
724 /* register the main interrupts */
725
726 irqdbf("s3c2410_init_irq: registering s3c2410 interrupt handlers\n");
727
Ben Dooksa019f4a2006-06-24 21:21:37 +0100728 for (irqno = IRQ_EINT4t7; irqno <= IRQ_ADCPARENT; irqno++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 /* set all the s3c2410 internal irqs */
730
731 switch (irqno) {
732 /* deal with the special IRQs (cascaded) */
733
Ben Dooksa019f4a2006-06-24 21:21:37 +0100734 case IRQ_EINT4t7:
735 case IRQ_EINT8t23:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 case IRQ_UART0:
737 case IRQ_UART1:
738 case IRQ_UART2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 case IRQ_ADCPARENT:
740 set_irq_chip(irqno, &s3c_irq_level_chip);
741 set_irq_handler(irqno, do_level_IRQ);
742 break;
743
744 case IRQ_RESERVED6:
745 case IRQ_RESERVED24:
746 /* no IRQ here */
747 break;
748
749 default:
750 //irqdbf("registering irq %d (s3c irq)\n", irqno);
751 set_irq_chip(irqno, &s3c_irq_chip);
752 set_irq_handler(irqno, do_edge_IRQ);
753 set_irq_flags(irqno, IRQF_VALID);
754 }
755 }
756
757 /* setup the cascade irq handlers */
758
Ben Dooks38e05332006-09-28 20:40:50 +0100759 set_irq_chained_handler(IRQ_EINT4t7, s3c_irq_demux_extint4t7);
760 set_irq_chained_handler(IRQ_EINT8t23, s3c_irq_demux_extint8);
Ben Dooksa019f4a2006-06-24 21:21:37 +0100761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 set_irq_chained_handler(IRQ_UART0, s3c_irq_demux_uart0);
763 set_irq_chained_handler(IRQ_UART1, s3c_irq_demux_uart1);
764 set_irq_chained_handler(IRQ_UART2, s3c_irq_demux_uart2);
765 set_irq_chained_handler(IRQ_ADCPARENT, s3c_irq_demux_adc);
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 /* external interrupts */
768
769 for (irqno = IRQ_EINT0; irqno <= IRQ_EINT3; irqno++) {
770 irqdbf("registering irq %d (ext int)\n", irqno);
771 set_irq_chip(irqno, &s3c_irq_eint0t4);
772 set_irq_handler(irqno, do_edge_IRQ);
773 set_irq_flags(irqno, IRQF_VALID);
774 }
775
776 for (irqno = IRQ_EINT4; irqno <= IRQ_EINT23; irqno++) {
777 irqdbf("registering irq %d (extended s3c irq)\n", irqno);
778 set_irq_chip(irqno, &s3c_irqext_chip);
779 set_irq_handler(irqno, do_edge_IRQ);
780 set_irq_flags(irqno, IRQF_VALID);
781 }
782
783 /* register the uart interrupts */
784
785 irqdbf("s3c2410: registering external interrupts\n");
786
787 for (irqno = IRQ_S3CUART_RX0; irqno <= IRQ_S3CUART_ERR0; irqno++) {
788 irqdbf("registering irq %d (s3c uart0 irq)\n", irqno);
789 set_irq_chip(irqno, &s3c_irq_uart0);
790 set_irq_handler(irqno, do_level_IRQ);
791 set_irq_flags(irqno, IRQF_VALID);
792 }
793
794 for (irqno = IRQ_S3CUART_RX1; irqno <= IRQ_S3CUART_ERR1; irqno++) {
795 irqdbf("registering irq %d (s3c uart1 irq)\n", irqno);
796 set_irq_chip(irqno, &s3c_irq_uart1);
797 set_irq_handler(irqno, do_level_IRQ);
798 set_irq_flags(irqno, IRQF_VALID);
799 }
800
801 for (irqno = IRQ_S3CUART_RX2; irqno <= IRQ_S3CUART_ERR2; irqno++) {
802 irqdbf("registering irq %d (s3c uart2 irq)\n", irqno);
803 set_irq_chip(irqno, &s3c_irq_uart2);
804 set_irq_handler(irqno, do_level_IRQ);
805 set_irq_flags(irqno, IRQF_VALID);
806 }
807
808 for (irqno = IRQ_TC; irqno <= IRQ_ADC; irqno++) {
809 irqdbf("registering irq %d (s3c adc irq)\n", irqno);
810 set_irq_chip(irqno, &s3c_irq_adc);
811 set_irq_handler(irqno, do_edge_IRQ);
812 set_irq_flags(irqno, IRQF_VALID);
813 }
814
815 irqdbf("s3c2410: registered interrupt handlers\n");
816}