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>
26 #include <linux/syscore_ops.h>
29 #include <asm/mach/irq.h>
31 #include <plat/regs-irqtype.h>
38 s3c_irq_mask(struct irq_data
*data
)
40 unsigned int irqno
= data
->irq
- IRQ_EINT0
;
43 mask
= __raw_readl(S3C2410_INTMSK
);
45 __raw_writel(mask
, S3C2410_INTMSK
);
49 s3c_irq_ack(struct irq_data
*data
)
51 unsigned long bitval
= 1UL << (data
->irq
- IRQ_EINT0
);
53 __raw_writel(bitval
, S3C2410_SRCPND
);
54 __raw_writel(bitval
, S3C2410_INTPND
);
58 s3c_irq_maskack(struct irq_data
*data
)
60 unsigned long bitval
= 1UL << (data
->irq
- 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(struct irq_data
*data
)
74 unsigned int irqno
= data
->irq
;
77 if (irqno
!= IRQ_TIMER4
&& irqno
!= IRQ_EINT8t23
)
78 irqdbf2("s3c_irq_unmask %d\n", irqno
);
82 mask
= __raw_readl(S3C2410_INTMSK
);
83 mask
&= ~(1UL << irqno
);
84 __raw_writel(mask
, S3C2410_INTMSK
);
87 struct irq_chip s3c_irq_level_chip
= {
89 .irq_ack
= s3c_irq_maskack
,
90 .irq_mask
= s3c_irq_mask
,
91 .irq_unmask
= s3c_irq_unmask
,
92 .irq_set_wake
= s3c_irq_wake
95 struct irq_chip s3c_irq_chip
= {
97 .irq_ack
= s3c_irq_ack
,
98 .irq_mask
= s3c_irq_mask
,
99 .irq_unmask
= s3c_irq_unmask
,
100 .irq_set_wake
= s3c_irq_wake
104 s3c_irqext_mask(struct irq_data
*data
)
106 unsigned int irqno
= data
->irq
- EXTINT_OFF
;
109 mask
= __raw_readl(S3C24XX_EINTMASK
);
110 mask
|= ( 1UL << irqno
);
111 __raw_writel(mask
, S3C24XX_EINTMASK
);
115 s3c_irqext_ack(struct irq_data
*data
)
121 bit
= 1UL << (data
->irq
- 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 (data
->irq
<= IRQ_EINT7
) {
133 if ((req
& 0xf0) == 0)
134 s3c_irq_ack(irq_get_irq_data(IRQ_EINT4t7
));
137 s3c_irq_ack(irq_get_irq_data(IRQ_EINT8t23
));
142 s3c_irqext_unmask(struct irq_data
*data
)
144 unsigned int irqno
= data
->irq
- EXTINT_OFF
;
147 mask
= __raw_readl(S3C24XX_EINTMASK
);
148 mask
&= ~(1UL << irqno
);
149 __raw_writel(mask
, S3C24XX_EINTMASK
);
153 s3c_irqext_type(struct irq_data
*data
, unsigned int type
)
155 void __iomem
*extint_reg
;
156 void __iomem
*gpcon_reg
;
157 unsigned long gpcon_offset
, extint_offset
;
158 unsigned long newvalue
= 0, value
;
160 if ((data
->irq
>= IRQ_EINT0
) && (data
->irq
<= IRQ_EINT3
)) {
161 gpcon_reg
= S3C2410_GPFCON
;
162 extint_reg
= S3C24XX_EXTINT0
;
163 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
)) {
166 gpcon_reg
= S3C2410_GPFCON
;
167 extint_reg
= S3C24XX_EXTINT0
;
168 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
)) {
171 gpcon_reg
= S3C2410_GPGCON
;
172 extint_reg
= S3C24XX_EXTINT1
;
173 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
)) {
176 gpcon_reg
= S3C2410_GPGCON
;
177 extint_reg
= S3C24XX_EXTINT2
;
178 gpcon_offset
= (data
->irq
- IRQ_EINT8
) * 2;
179 extint_offset
= (data
->irq
- IRQ_EINT16
) * 4;
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
);
189 /* Set the external interrupt to pointed trigger type */
193 printk(KERN_WARNING
"No edge setting!\n");
196 case IRQ_TYPE_EDGE_RISING
:
197 newvalue
= S3C2410_EXTINT_RISEEDGE
;
200 case IRQ_TYPE_EDGE_FALLING
:
201 newvalue
= S3C2410_EXTINT_FALLEDGE
;
204 case IRQ_TYPE_EDGE_BOTH
:
205 newvalue
= S3C2410_EXTINT_BOTHEDGE
;
208 case IRQ_TYPE_LEVEL_LOW
:
209 newvalue
= S3C2410_EXTINT_LOWLEV
;
212 case IRQ_TYPE_LEVEL_HIGH
:
213 newvalue
= S3C2410_EXTINT_HILEV
;
217 printk(KERN_ERR
"No such irq type %d", type
);
221 value
= __raw_readl(extint_reg
);
222 value
= (value
& ~(7 << extint_offset
)) | (newvalue
<< extint_offset
);
223 __raw_writel(value
, extint_reg
);
228 static struct irq_chip s3c_irqext_chip
= {
230 .irq_mask
= s3c_irqext_mask
,
231 .irq_unmask
= s3c_irqext_unmask
,
232 .irq_ack
= s3c_irqext_ack
,
233 .irq_set_type
= s3c_irqext_type
,
234 .irq_set_wake
= s3c_irqext_wake
237 static struct irq_chip s3c_irq_eint0t4
= {
239 .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
,
246 /* mask values for the parent registers for each of the interrupt types */
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))
257 s3c_irq_uart0_mask(struct irq_data
*data
)
259 s3c_irqsub_mask(data
->irq
, INTMSK_UART0
, 7);
263 s3c_irq_uart0_unmask(struct irq_data
*data
)
265 s3c_irqsub_unmask(data
->irq
, INTMSK_UART0
);
269 s3c_irq_uart0_ack(struct irq_data
*data
)
271 s3c_irqsub_maskack(data
->irq
, INTMSK_UART0
, 7);
274 static struct irq_chip s3c_irq_uart0
= {
276 .irq_mask
= s3c_irq_uart0_mask
,
277 .irq_unmask
= s3c_irq_uart0_unmask
,
278 .irq_ack
= s3c_irq_uart0_ack
,
284 s3c_irq_uart1_mask(struct irq_data
*data
)
286 s3c_irqsub_mask(data
->irq
, INTMSK_UART1
, 7 << 3);
290 s3c_irq_uart1_unmask(struct irq_data
*data
)
292 s3c_irqsub_unmask(data
->irq
, INTMSK_UART1
);
296 s3c_irq_uart1_ack(struct irq_data
*data
)
298 s3c_irqsub_maskack(data
->irq
, INTMSK_UART1
, 7 << 3);
301 static struct irq_chip s3c_irq_uart1
= {
303 .irq_mask
= s3c_irq_uart1_mask
,
304 .irq_unmask
= s3c_irq_uart1_unmask
,
305 .irq_ack
= s3c_irq_uart1_ack
,
311 s3c_irq_uart2_mask(struct irq_data
*data
)
313 s3c_irqsub_mask(data
->irq
, INTMSK_UART2
, 7 << 6);
317 s3c_irq_uart2_unmask(struct irq_data
*data
)
319 s3c_irqsub_unmask(data
->irq
, INTMSK_UART2
);
323 s3c_irq_uart2_ack(struct irq_data
*data
)
325 s3c_irqsub_maskack(data
->irq
, INTMSK_UART2
, 7 << 6);
328 static struct irq_chip s3c_irq_uart2
= {
330 .irq_mask
= s3c_irq_uart2_mask
,
331 .irq_unmask
= s3c_irq_uart2_unmask
,
332 .irq_ack
= s3c_irq_uart2_ack
,
335 /* ADC and Touchscreen */
338 s3c_irq_adc_mask(struct irq_data
*d
)
340 s3c_irqsub_mask(d
->irq
, INTMSK_ADCPARENT
, 3 << 9);
344 s3c_irq_adc_unmask(struct irq_data
*d
)
346 s3c_irqsub_unmask(d
->irq
, INTMSK_ADCPARENT
);
350 s3c_irq_adc_ack(struct irq_data
*d
)
352 s3c_irqsub_ack(d
->irq
, INTMSK_ADCPARENT
, 3 << 9);
355 static struct irq_chip s3c_irq_adc
= {
357 .irq_mask
= s3c_irq_adc_mask
,
358 .irq_unmask
= s3c_irq_adc_unmask
,
359 .irq_ack
= s3c_irq_adc_ack
,
362 /* irq demux for adc */
363 static void s3c_irq_demux_adc(unsigned int irq
,
364 struct irq_desc
*desc
)
366 unsigned int subsrc
, submsk
;
367 unsigned int offset
= 9;
369 /* read the current pending interrupts, and the mask
370 * for what it is available */
372 subsrc
= __raw_readl(S3C2410_SUBSRCPND
);
373 submsk
= __raw_readl(S3C2410_INTSUBMSK
);
381 generic_handle_irq(IRQ_TC
);
384 generic_handle_irq(IRQ_ADC
);
389 static void s3c_irq_demux_uart(unsigned int start
)
391 unsigned int subsrc
, submsk
;
392 unsigned int offset
= start
- IRQ_S3CUART_RX0
;
394 /* read the current pending interrupts, and the mask
395 * for what it is available */
397 subsrc
= __raw_readl(S3C2410_SUBSRCPND
);
398 submsk
= __raw_readl(S3C2410_INTSUBMSK
);
400 irqdbf2("s3c_irq_demux_uart: start=%d (%d), subsrc=0x%08x,0x%08x\n",
401 start
, offset
, subsrc
, submsk
);
409 generic_handle_irq(start
);
412 generic_handle_irq(start
+1);
415 generic_handle_irq(start
+2);
419 /* uart demux entry points */
422 s3c_irq_demux_uart0(unsigned int irq
,
423 struct irq_desc
*desc
)
426 s3c_irq_demux_uart(IRQ_S3CUART_RX0
);
430 s3c_irq_demux_uart1(unsigned int irq
,
431 struct irq_desc
*desc
)
434 s3c_irq_demux_uart(IRQ_S3CUART_RX1
);
438 s3c_irq_demux_uart2(unsigned int irq
,
439 struct irq_desc
*desc
)
442 s3c_irq_demux_uart(IRQ_S3CUART_RX2
);
446 s3c_irq_demux_extint8(unsigned int irq
,
447 struct irq_desc
*desc
)
449 unsigned long eintpnd
= __raw_readl(S3C24XX_EINTPEND
);
450 unsigned long eintmsk
= __raw_readl(S3C24XX_EINTMASK
);
453 eintpnd
&= ~0xff; /* ignore lower irqs */
455 /* we may as well handle all the pending IRQs here */
458 irq
= __ffs(eintpnd
);
459 eintpnd
&= ~(1<<irq
);
461 irq
+= (IRQ_EINT4
- 4);
462 generic_handle_irq(irq
);
468 s3c_irq_demux_extint4t7(unsigned int irq
,
469 struct irq_desc
*desc
)
471 unsigned long eintpnd
= __raw_readl(S3C24XX_EINTPEND
);
472 unsigned long eintmsk
= __raw_readl(S3C24XX_EINTMASK
);
475 eintpnd
&= 0xff; /* only lower irqs */
477 /* we may as well handle all the pending IRQs here */
480 irq
= __ffs(eintpnd
);
481 eintpnd
&= ~(1<<irq
);
483 irq
+= (IRQ_EINT4
- 4);
485 generic_handle_irq(irq
);
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.
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.
500 int s3c24xx_set_fiq(unsigned int irq
, bool on
)
506 offs
= irq
- FIQ_START
;
515 __raw_writel(intmod
, S3C2410_INTMOD
);
519 EXPORT_SYMBOL_GPL(s3c24xx_set_fiq
);
525 * Initialise S3C2410 IRQ system
528 void __init
s3c24xx_init_irq(void)
539 irqdbf("s3c2410_init_irq: clearing interrupt status flags\n");
541 /* first, clear all interrupts pending... */
544 for (i
= 0; i
< 4; i
++) {
545 pend
= __raw_readl(S3C24XX_EINTPEND
);
547 if (pend
== 0 || pend
== last
)
550 __raw_writel(pend
, S3C24XX_EINTPEND
);
551 printk("irq: clearing pending ext status %08x\n", (int)pend
);
556 for (i
= 0; i
< 4; i
++) {
557 pend
= __raw_readl(S3C2410_INTPND
);
559 if (pend
== 0 || pend
== last
)
562 __raw_writel(pend
, S3C2410_SRCPND
);
563 __raw_writel(pend
, S3C2410_INTPND
);
564 printk("irq: clearing pending status %08x\n", (int)pend
);
569 for (i
= 0; i
< 4; i
++) {
570 pend
= __raw_readl(S3C2410_SUBSRCPND
);
572 if (pend
== 0 || pend
== last
)
575 printk("irq: clearing subpending status %08x\n", (int)pend
);
576 __raw_writel(pend
, S3C2410_SUBSRCPND
);
580 /* register the main interrupts */
582 irqdbf("s3c2410_init_irq: registering s3c2410 interrupt handlers\n");
584 for (irqno
= IRQ_EINT4t7
; irqno
<= IRQ_ADCPARENT
; irqno
++) {
585 /* set all the s3c2410 internal irqs */
588 /* deal with the special IRQs (cascaded) */
596 irq_set_chip_and_handler(irqno
, &s3c_irq_level_chip
,
606 //irqdbf("registering irq %d (s3c irq)\n", irqno);
607 irq_set_chip_and_handler(irqno
, &s3c_irq_chip
,
609 set_irq_flags(irqno
, IRQF_VALID
);
613 /* setup the cascade irq handlers */
615 irq_set_chained_handler(IRQ_EINT4t7
, s3c_irq_demux_extint4t7
);
616 irq_set_chained_handler(IRQ_EINT8t23
, s3c_irq_demux_extint8
);
618 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
);
623 /* external interrupts */
625 for (irqno
= IRQ_EINT0
; irqno
<= IRQ_EINT3
; irqno
++) {
626 irqdbf("registering irq %d (ext int)\n", irqno
);
627 irq_set_chip_and_handler(irqno
, &s3c_irq_eint0t4
,
629 set_irq_flags(irqno
, IRQF_VALID
);
632 for (irqno
= IRQ_EINT4
; irqno
<= IRQ_EINT23
; irqno
++) {
633 irqdbf("registering irq %d (extended s3c irq)\n", irqno
);
634 irq_set_chip_and_handler(irqno
, &s3c_irqext_chip
,
636 set_irq_flags(irqno
, IRQF_VALID
);
639 /* register the uart interrupts */
641 irqdbf("s3c2410: registering external interrupts\n");
643 for (irqno
= IRQ_S3CUART_RX0
; irqno
<= IRQ_S3CUART_ERR0
; irqno
++) {
644 irqdbf("registering irq %d (s3c uart0 irq)\n", irqno
);
645 irq_set_chip_and_handler(irqno
, &s3c_irq_uart0
,
647 set_irq_flags(irqno
, IRQF_VALID
);
650 for (irqno
= IRQ_S3CUART_RX1
; irqno
<= IRQ_S3CUART_ERR1
; irqno
++) {
651 irqdbf("registering irq %d (s3c uart1 irq)\n", irqno
);
652 irq_set_chip_and_handler(irqno
, &s3c_irq_uart1
,
654 set_irq_flags(irqno
, IRQF_VALID
);
657 for (irqno
= IRQ_S3CUART_RX2
; irqno
<= IRQ_S3CUART_ERR2
; irqno
++) {
658 irqdbf("registering irq %d (s3c uart2 irq)\n", irqno
);
659 irq_set_chip_and_handler(irqno
, &s3c_irq_uart2
,
661 set_irq_flags(irqno
, IRQF_VALID
);
664 for (irqno
= IRQ_TC
; irqno
<= IRQ_ADC
; irqno
++) {
665 irqdbf("registering irq %d (s3c adc irq)\n", irqno
);
666 irq_set_chip_and_handler(irqno
, &s3c_irq_adc
, handle_edge_irq
);
667 set_irq_flags(irqno
, IRQF_VALID
);
670 irqdbf("s3c2410: registered interrupt handlers\n");
673 struct syscore_ops s3c24xx_irq_syscore_ops
= {
674 .suspend
= s3c24xx_irq_suspend
,
675 .resume
= s3c24xx_irq_resume
,