1 /* linux/arch/arm/plat-s3c24xx/irq.c
3 * Copyright (c) 2003,2004 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
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.
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.
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
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/interrupt.h>
24 #include <linux/ioport.h>
25 #include <linux/sysdev.h>
28 #include <asm/mach/irq.h>
30 #include <plat/regs-irqtype.h>
37 s3c_irq_mask(unsigned int irqno
)
43 mask
= __raw_readl(S3C2410_INTMSK
);
45 __raw_writel(mask
, S3C2410_INTMSK
);
49 s3c_irq_ack(unsigned int irqno
)
51 unsigned long bitval
= 1UL << (irqno
- IRQ_EINT0
);
53 __raw_writel(bitval
, S3C2410_SRCPND
);
54 __raw_writel(bitval
, S3C2410_INTPND
);
58 s3c_irq_maskack(unsigned int irqno
)
60 unsigned long bitval
= 1UL << (irqno
- IRQ_EINT0
);
63 mask
= __raw_readl(S3C2410_INTMSK
);
64 __raw_writel(mask
|bitval
, S3C2410_INTMSK
);
66 __raw_writel(bitval
, S3C2410_SRCPND
);
67 __raw_writel(bitval
, S3C2410_INTPND
);
72 s3c_irq_unmask(unsigned int irqno
)
76 if (irqno
!= IRQ_TIMER4
&& irqno
!= IRQ_EINT8t23
)
77 irqdbf2("s3c_irq_unmask %d\n", irqno
);
81 mask
= __raw_readl(S3C2410_INTMSK
);
82 mask
&= ~(1UL << irqno
);
83 __raw_writel(mask
, S3C2410_INTMSK
);
86 struct irq_chip s3c_irq_level_chip
= {
88 .ack
= s3c_irq_maskack
,
90 .unmask
= s3c_irq_unmask
,
91 .set_wake
= s3c_irq_wake
94 struct irq_chip s3c_irq_chip
= {
98 .unmask
= s3c_irq_unmask
,
99 .set_wake
= s3c_irq_wake
103 s3c_irqext_mask(unsigned int irqno
)
109 mask
= __raw_readl(S3C24XX_EINTMASK
);
110 mask
|= ( 1UL << irqno
);
111 __raw_writel(mask
, S3C24XX_EINTMASK
);
115 s3c_irqext_ack(unsigned int irqno
)
121 bit
= 1UL << (irqno
- EXTINT_OFF
);
123 mask
= __raw_readl(S3C24XX_EINTMASK
);
125 __raw_writel(bit
, S3C24XX_EINTPEND
);
127 req
= __raw_readl(S3C24XX_EINTPEND
);
130 /* not sure if we should be acking the parent irq... */
132 if (irqno
<= IRQ_EINT7
) {
133 if ((req
& 0xf0) == 0)
134 s3c_irq_ack(IRQ_EINT4t7
);
137 s3c_irq_ack(IRQ_EINT8t23
);
142 s3c_irqext_unmask(unsigned int irqno
)
148 mask
= __raw_readl(S3C24XX_EINTMASK
);
149 mask
&= ~( 1UL << irqno
);
150 __raw_writel(mask
, S3C24XX_EINTMASK
);
154 s3c_irqext_type(unsigned int irq
, unsigned int type
)
156 void __iomem
*extint_reg
;
157 void __iomem
*gpcon_reg
;
158 unsigned long gpcon_offset
, extint_offset
;
159 unsigned long newvalue
= 0, value
;
161 if ((irq
>= IRQ_EINT0
) && (irq
<= IRQ_EINT3
))
163 gpcon_reg
= S3C2410_GPFCON
;
164 extint_reg
= S3C24XX_EXTINT0
;
165 gpcon_offset
= (irq
- IRQ_EINT0
) * 2;
166 extint_offset
= (irq
- IRQ_EINT0
) * 4;
168 else if ((irq
>= IRQ_EINT4
) && (irq
<= IRQ_EINT7
))
170 gpcon_reg
= S3C2410_GPFCON
;
171 extint_reg
= S3C24XX_EXTINT0
;
172 gpcon_offset
= (irq
- (EXTINT_OFF
)) * 2;
173 extint_offset
= (irq
- (EXTINT_OFF
)) * 4;
175 else if ((irq
>= IRQ_EINT8
) && (irq
<= IRQ_EINT15
))
177 gpcon_reg
= S3C2410_GPGCON
;
178 extint_reg
= S3C24XX_EXTINT1
;
179 gpcon_offset
= (irq
- IRQ_EINT8
) * 2;
180 extint_offset
= (irq
- IRQ_EINT8
) * 4;
182 else if ((irq
>= IRQ_EINT16
) && (irq
<= IRQ_EINT23
))
184 gpcon_reg
= S3C2410_GPGCON
;
185 extint_reg
= S3C24XX_EXTINT2
;
186 gpcon_offset
= (irq
- IRQ_EINT8
) * 2;
187 extint_offset
= (irq
- IRQ_EINT16
) * 4;
191 /* Set the GPIO to external interrupt mode */
192 value
= __raw_readl(gpcon_reg
);
193 value
= (value
& ~(3 << gpcon_offset
)) | (0x02 << gpcon_offset
);
194 __raw_writel(value
, gpcon_reg
);
196 /* Set the external interrupt to pointed trigger type */
200 printk(KERN_WARNING
"No edge setting!\n");
203 case IRQ_TYPE_EDGE_RISING
:
204 newvalue
= S3C2410_EXTINT_RISEEDGE
;
207 case IRQ_TYPE_EDGE_FALLING
:
208 newvalue
= S3C2410_EXTINT_FALLEDGE
;
211 case IRQ_TYPE_EDGE_BOTH
:
212 newvalue
= S3C2410_EXTINT_BOTHEDGE
;
215 case IRQ_TYPE_LEVEL_LOW
:
216 newvalue
= S3C2410_EXTINT_LOWLEV
;
219 case IRQ_TYPE_LEVEL_HIGH
:
220 newvalue
= S3C2410_EXTINT_HILEV
;
224 printk(KERN_ERR
"No such irq type %d", type
);
228 value
= __raw_readl(extint_reg
);
229 value
= (value
& ~(7 << extint_offset
)) | (newvalue
<< extint_offset
);
230 __raw_writel(value
, extint_reg
);
235 static struct irq_chip s3c_irqext_chip
= {
237 .mask
= s3c_irqext_mask
,
238 .unmask
= s3c_irqext_unmask
,
239 .ack
= s3c_irqext_ack
,
240 .set_type
= s3c_irqext_type
,
241 .set_wake
= s3c_irqext_wake
244 static struct irq_chip s3c_irq_eint0t4
= {
247 .mask
= s3c_irq_mask
,
248 .unmask
= s3c_irq_unmask
,
249 .set_wake
= s3c_irq_wake
,
250 .set_type
= s3c_irqext_type
,
253 /* mask values for the parent registers for each of the interrupt types */
255 #define INTMSK_UART0 (1UL << (IRQ_UART0 - IRQ_EINT0))
256 #define INTMSK_UART1 (1UL << (IRQ_UART1 - IRQ_EINT0))
257 #define INTMSK_UART2 (1UL << (IRQ_UART2 - IRQ_EINT0))
258 #define INTMSK_ADCPARENT (1UL << (IRQ_ADCPARENT - IRQ_EINT0))
264 s3c_irq_uart0_mask(unsigned int irqno
)
266 s3c_irqsub_mask(irqno
, INTMSK_UART0
, 7);
270 s3c_irq_uart0_unmask(unsigned int irqno
)
272 s3c_irqsub_unmask(irqno
, INTMSK_UART0
);
276 s3c_irq_uart0_ack(unsigned int irqno
)
278 s3c_irqsub_maskack(irqno
, INTMSK_UART0
, 7);
281 static struct irq_chip s3c_irq_uart0
= {
283 .mask
= s3c_irq_uart0_mask
,
284 .unmask
= s3c_irq_uart0_unmask
,
285 .ack
= s3c_irq_uart0_ack
,
291 s3c_irq_uart1_mask(unsigned int irqno
)
293 s3c_irqsub_mask(irqno
, INTMSK_UART1
, 7 << 3);
297 s3c_irq_uart1_unmask(unsigned int irqno
)
299 s3c_irqsub_unmask(irqno
, INTMSK_UART1
);
303 s3c_irq_uart1_ack(unsigned int irqno
)
305 s3c_irqsub_maskack(irqno
, INTMSK_UART1
, 7 << 3);
308 static struct irq_chip s3c_irq_uart1
= {
310 .mask
= s3c_irq_uart1_mask
,
311 .unmask
= s3c_irq_uart1_unmask
,
312 .ack
= s3c_irq_uart1_ack
,
318 s3c_irq_uart2_mask(unsigned int irqno
)
320 s3c_irqsub_mask(irqno
, INTMSK_UART2
, 7 << 6);
324 s3c_irq_uart2_unmask(unsigned int irqno
)
326 s3c_irqsub_unmask(irqno
, INTMSK_UART2
);
330 s3c_irq_uart2_ack(unsigned int irqno
)
332 s3c_irqsub_maskack(irqno
, INTMSK_UART2
, 7 << 6);
335 static struct irq_chip s3c_irq_uart2
= {
337 .mask
= s3c_irq_uart2_mask
,
338 .unmask
= s3c_irq_uart2_unmask
,
339 .ack
= s3c_irq_uart2_ack
,
342 /* ADC and Touchscreen */
345 s3c_irq_adc_mask(unsigned int irqno
)
347 s3c_irqsub_mask(irqno
, INTMSK_ADCPARENT
, 3 << 9);
351 s3c_irq_adc_unmask(unsigned int irqno
)
353 s3c_irqsub_unmask(irqno
, INTMSK_ADCPARENT
);
357 s3c_irq_adc_ack(unsigned int irqno
)
359 s3c_irqsub_ack(irqno
, INTMSK_ADCPARENT
, 3 << 9);
362 static struct irq_chip s3c_irq_adc
= {
364 .mask
= s3c_irq_adc_mask
,
365 .unmask
= s3c_irq_adc_unmask
,
366 .ack
= s3c_irq_adc_ack
,
369 /* irq demux for adc */
370 static void s3c_irq_demux_adc(unsigned int irq
,
371 struct irq_desc
*desc
)
373 unsigned int subsrc
, submsk
;
374 unsigned int offset
= 9;
376 /* read the current pending interrupts, and the mask
377 * for what it is available */
379 subsrc
= __raw_readl(S3C2410_SUBSRCPND
);
380 submsk
= __raw_readl(S3C2410_INTSUBMSK
);
388 generic_handle_irq(IRQ_TC
);
391 generic_handle_irq(IRQ_ADC
);
396 static void s3c_irq_demux_uart(unsigned int start
)
398 unsigned int subsrc
, submsk
;
399 unsigned int offset
= start
- IRQ_S3CUART_RX0
;
401 /* read the current pending interrupts, and the mask
402 * for what it is available */
404 subsrc
= __raw_readl(S3C2410_SUBSRCPND
);
405 submsk
= __raw_readl(S3C2410_INTSUBMSK
);
407 irqdbf2("s3c_irq_demux_uart: start=%d (%d), subsrc=0x%08x,0x%08x\n",
408 start
, offset
, subsrc
, submsk
);
416 generic_handle_irq(start
);
419 generic_handle_irq(start
+1);
422 generic_handle_irq(start
+2);
426 /* uart demux entry points */
429 s3c_irq_demux_uart0(unsigned int irq
,
430 struct irq_desc
*desc
)
433 s3c_irq_demux_uart(IRQ_S3CUART_RX0
);
437 s3c_irq_demux_uart1(unsigned int irq
,
438 struct irq_desc
*desc
)
441 s3c_irq_demux_uart(IRQ_S3CUART_RX1
);
445 s3c_irq_demux_uart2(unsigned int irq
,
446 struct irq_desc
*desc
)
449 s3c_irq_demux_uart(IRQ_S3CUART_RX2
);
453 s3c_irq_demux_extint8(unsigned int irq
,
454 struct irq_desc
*desc
)
456 unsigned long eintpnd
= __raw_readl(S3C24XX_EINTPEND
);
457 unsigned long eintmsk
= __raw_readl(S3C24XX_EINTMASK
);
460 eintpnd
&= ~0xff; /* ignore lower irqs */
462 /* we may as well handle all the pending IRQs here */
465 irq
= __ffs(eintpnd
);
466 eintpnd
&= ~(1<<irq
);
468 irq
+= (IRQ_EINT4
- 4);
469 generic_handle_irq(irq
);
475 s3c_irq_demux_extint4t7(unsigned int irq
,
476 struct irq_desc
*desc
)
478 unsigned long eintpnd
= __raw_readl(S3C24XX_EINTPEND
);
479 unsigned long eintmsk
= __raw_readl(S3C24XX_EINTMASK
);
482 eintpnd
&= 0xff; /* only lower irqs */
484 /* we may as well handle all the pending IRQs here */
487 irq
= __ffs(eintpnd
);
488 eintpnd
&= ~(1<<irq
);
490 irq
+= (IRQ_EINT4
- 4);
492 generic_handle_irq(irq
);
498 * Initialise S3C2410 IRQ system
501 void __init
s3c24xx_init_irq(void)
508 irqdbf("s3c2410_init_irq: clearing interrupt status flags\n");
510 /* first, clear all interrupts pending... */
513 for (i
= 0; i
< 4; i
++) {
514 pend
= __raw_readl(S3C24XX_EINTPEND
);
516 if (pend
== 0 || pend
== last
)
519 __raw_writel(pend
, S3C24XX_EINTPEND
);
520 printk("irq: clearing pending ext status %08x\n", (int)pend
);
525 for (i
= 0; i
< 4; i
++) {
526 pend
= __raw_readl(S3C2410_INTPND
);
528 if (pend
== 0 || pend
== last
)
531 __raw_writel(pend
, S3C2410_SRCPND
);
532 __raw_writel(pend
, S3C2410_INTPND
);
533 printk("irq: clearing pending status %08x\n", (int)pend
);
538 for (i
= 0; i
< 4; i
++) {
539 pend
= __raw_readl(S3C2410_SUBSRCPND
);
541 if (pend
== 0 || pend
== last
)
544 printk("irq: clearing subpending status %08x\n", (int)pend
);
545 __raw_writel(pend
, S3C2410_SUBSRCPND
);
549 /* register the main interrupts */
551 irqdbf("s3c2410_init_irq: registering s3c2410 interrupt handlers\n");
553 for (irqno
= IRQ_EINT4t7
; irqno
<= IRQ_ADCPARENT
; irqno
++) {
554 /* set all the s3c2410 internal irqs */
557 /* deal with the special IRQs (cascaded) */
565 set_irq_chip(irqno
, &s3c_irq_level_chip
);
566 set_irq_handler(irqno
, handle_level_irq
);
575 //irqdbf("registering irq %d (s3c irq)\n", irqno);
576 set_irq_chip(irqno
, &s3c_irq_chip
);
577 set_irq_handler(irqno
, handle_edge_irq
);
578 set_irq_flags(irqno
, IRQF_VALID
);
582 /* setup the cascade irq handlers */
584 set_irq_chained_handler(IRQ_EINT4t7
, s3c_irq_demux_extint4t7
);
585 set_irq_chained_handler(IRQ_EINT8t23
, s3c_irq_demux_extint8
);
587 set_irq_chained_handler(IRQ_UART0
, s3c_irq_demux_uart0
);
588 set_irq_chained_handler(IRQ_UART1
, s3c_irq_demux_uart1
);
589 set_irq_chained_handler(IRQ_UART2
, s3c_irq_demux_uart2
);
590 set_irq_chained_handler(IRQ_ADCPARENT
, s3c_irq_demux_adc
);
592 /* external interrupts */
594 for (irqno
= IRQ_EINT0
; irqno
<= IRQ_EINT3
; irqno
++) {
595 irqdbf("registering irq %d (ext int)\n", irqno
);
596 set_irq_chip(irqno
, &s3c_irq_eint0t4
);
597 set_irq_handler(irqno
, handle_edge_irq
);
598 set_irq_flags(irqno
, IRQF_VALID
);
601 for (irqno
= IRQ_EINT4
; irqno
<= IRQ_EINT23
; irqno
++) {
602 irqdbf("registering irq %d (extended s3c irq)\n", irqno
);
603 set_irq_chip(irqno
, &s3c_irqext_chip
);
604 set_irq_handler(irqno
, handle_edge_irq
);
605 set_irq_flags(irqno
, IRQF_VALID
);
608 /* register the uart interrupts */
610 irqdbf("s3c2410: registering external interrupts\n");
612 for (irqno
= IRQ_S3CUART_RX0
; irqno
<= IRQ_S3CUART_ERR0
; irqno
++) {
613 irqdbf("registering irq %d (s3c uart0 irq)\n", irqno
);
614 set_irq_chip(irqno
, &s3c_irq_uart0
);
615 set_irq_handler(irqno
, handle_level_irq
);
616 set_irq_flags(irqno
, IRQF_VALID
);
619 for (irqno
= IRQ_S3CUART_RX1
; irqno
<= IRQ_S3CUART_ERR1
; irqno
++) {
620 irqdbf("registering irq %d (s3c uart1 irq)\n", irqno
);
621 set_irq_chip(irqno
, &s3c_irq_uart1
);
622 set_irq_handler(irqno
, handle_level_irq
);
623 set_irq_flags(irqno
, IRQF_VALID
);
626 for (irqno
= IRQ_S3CUART_RX2
; irqno
<= IRQ_S3CUART_ERR2
; irqno
++) {
627 irqdbf("registering irq %d (s3c uart2 irq)\n", irqno
);
628 set_irq_chip(irqno
, &s3c_irq_uart2
);
629 set_irq_handler(irqno
, handle_level_irq
);
630 set_irq_flags(irqno
, IRQF_VALID
);
633 for (irqno
= IRQ_TC
; irqno
<= IRQ_ADC
; irqno
++) {
634 irqdbf("registering irq %d (s3c adc irq)\n", irqno
);
635 set_irq_chip(irqno
, &s3c_irq_adc
);
636 set_irq_handler(irqno
, handle_edge_irq
);
637 set_irq_flags(irqno
, IRQF_VALID
);
640 irqdbf("s3c2410: registered interrupt handlers\n");