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(struct irq_data
*data
)
39 unsigned int irqno
= data
->irq
- IRQ_EINT0
;
42 mask
= __raw_readl(S3C2410_INTMSK
);
44 __raw_writel(mask
, S3C2410_INTMSK
);
48 s3c_irq_ack(struct irq_data
*data
)
50 unsigned long bitval
= 1UL << (data
->irq
- IRQ_EINT0
);
52 __raw_writel(bitval
, S3C2410_SRCPND
);
53 __raw_writel(bitval
, S3C2410_INTPND
);
57 s3c_irq_maskack(struct irq_data
*data
)
59 unsigned long bitval
= 1UL << (data
->irq
- IRQ_EINT0
);
62 mask
= __raw_readl(S3C2410_INTMSK
);
63 __raw_writel(mask
|bitval
, S3C2410_INTMSK
);
65 __raw_writel(bitval
, S3C2410_SRCPND
);
66 __raw_writel(bitval
, S3C2410_INTPND
);
71 s3c_irq_unmask(struct irq_data
*data
)
73 unsigned int irqno
= data
->irq
;
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 .irq_ack
= s3c_irq_maskack
,
89 .irq_mask
= s3c_irq_mask
,
90 .irq_unmask
= s3c_irq_unmask
,
91 .irq_set_wake
= s3c_irq_wake
94 struct irq_chip s3c_irq_chip
= {
96 .irq_ack
= s3c_irq_ack
,
97 .irq_mask
= s3c_irq_mask
,
98 .irq_unmask
= s3c_irq_unmask
,
99 .irq_set_wake
= s3c_irq_wake
103 s3c_irqext_mask(struct irq_data
*data
)
105 unsigned int irqno
= data
->irq
- EXTINT_OFF
;
108 mask
= __raw_readl(S3C24XX_EINTMASK
);
109 mask
|= ( 1UL << irqno
);
110 __raw_writel(mask
, S3C24XX_EINTMASK
);
114 s3c_irqext_ack(struct irq_data
*data
)
120 bit
= 1UL << (data
->irq
- EXTINT_OFF
);
122 mask
= __raw_readl(S3C24XX_EINTMASK
);
124 __raw_writel(bit
, S3C24XX_EINTPEND
);
126 req
= __raw_readl(S3C24XX_EINTPEND
);
129 /* not sure if we should be acking the parent irq... */
131 if (data
->irq
<= IRQ_EINT7
) {
132 if ((req
& 0xf0) == 0)
133 s3c_irq_ack(irq_get_irq_data(IRQ_EINT4t7
));
136 s3c_irq_ack(irq_get_irq_data(IRQ_EINT8t23
));
141 s3c_irqext_unmask(struct irq_data
*data
)
143 unsigned int irqno
= data
->irq
- EXTINT_OFF
;
146 mask
= __raw_readl(S3C24XX_EINTMASK
);
147 mask
&= ~(1UL << irqno
);
148 __raw_writel(mask
, S3C24XX_EINTMASK
);
152 s3c_irqext_type(struct irq_data
*data
, unsigned int type
)
154 void __iomem
*extint_reg
;
155 void __iomem
*gpcon_reg
;
156 unsigned long gpcon_offset
, extint_offset
;
157 unsigned long newvalue
= 0, value
;
159 if ((data
->irq
>= IRQ_EINT0
) && (data
->irq
<= IRQ_EINT3
)) {
160 gpcon_reg
= S3C2410_GPFCON
;
161 extint_reg
= S3C24XX_EXTINT0
;
162 gpcon_offset
= (data
->irq
- IRQ_EINT0
) * 2;
163 extint_offset
= (data
->irq
- IRQ_EINT0
) * 4;
164 } else if ((data
->irq
>= IRQ_EINT4
) && (data
->irq
<= IRQ_EINT7
)) {
165 gpcon_reg
= S3C2410_GPFCON
;
166 extint_reg
= S3C24XX_EXTINT0
;
167 gpcon_offset
= (data
->irq
- (EXTINT_OFF
)) * 2;
168 extint_offset
= (data
->irq
- (EXTINT_OFF
)) * 4;
169 } else if ((data
->irq
>= IRQ_EINT8
) && (data
->irq
<= IRQ_EINT15
)) {
170 gpcon_reg
= S3C2410_GPGCON
;
171 extint_reg
= S3C24XX_EXTINT1
;
172 gpcon_offset
= (data
->irq
- IRQ_EINT8
) * 2;
173 extint_offset
= (data
->irq
- IRQ_EINT8
) * 4;
174 } else if ((data
->irq
>= IRQ_EINT16
) && (data
->irq
<= IRQ_EINT23
)) {
175 gpcon_reg
= S3C2410_GPGCON
;
176 extint_reg
= S3C24XX_EXTINT2
;
177 gpcon_offset
= (data
->irq
- IRQ_EINT8
) * 2;
178 extint_offset
= (data
->irq
- IRQ_EINT16
) * 4;
183 /* Set the GPIO to external interrupt mode */
184 value
= __raw_readl(gpcon_reg
);
185 value
= (value
& ~(3 << gpcon_offset
)) | (0x02 << gpcon_offset
);
186 __raw_writel(value
, gpcon_reg
);
188 /* Set the external interrupt to pointed trigger type */
192 printk(KERN_WARNING
"No edge setting!\n");
195 case IRQ_TYPE_EDGE_RISING
:
196 newvalue
= S3C2410_EXTINT_RISEEDGE
;
199 case IRQ_TYPE_EDGE_FALLING
:
200 newvalue
= S3C2410_EXTINT_FALLEDGE
;
203 case IRQ_TYPE_EDGE_BOTH
:
204 newvalue
= S3C2410_EXTINT_BOTHEDGE
;
207 case IRQ_TYPE_LEVEL_LOW
:
208 newvalue
= S3C2410_EXTINT_LOWLEV
;
211 case IRQ_TYPE_LEVEL_HIGH
:
212 newvalue
= S3C2410_EXTINT_HILEV
;
216 printk(KERN_ERR
"No such irq type %d", type
);
220 value
= __raw_readl(extint_reg
);
221 value
= (value
& ~(7 << extint_offset
)) | (newvalue
<< extint_offset
);
222 __raw_writel(value
, extint_reg
);
227 static struct irq_chip s3c_irqext_chip
= {
229 .irq_mask
= s3c_irqext_mask
,
230 .irq_unmask
= s3c_irqext_unmask
,
231 .irq_ack
= s3c_irqext_ack
,
232 .irq_set_type
= s3c_irqext_type
,
233 .irq_set_wake
= s3c_irqext_wake
236 static struct irq_chip s3c_irq_eint0t4
= {
238 .irq_ack
= s3c_irq_ack
,
239 .irq_mask
= s3c_irq_mask
,
240 .irq_unmask
= s3c_irq_unmask
,
241 .irq_set_wake
= s3c_irq_wake
,
242 .irq_set_type
= s3c_irqext_type
,
245 /* mask values for the parent registers for each of the interrupt types */
247 #define INTMSK_UART0 (1UL << (IRQ_UART0 - IRQ_EINT0))
248 #define INTMSK_UART1 (1UL << (IRQ_UART1 - IRQ_EINT0))
249 #define INTMSK_UART2 (1UL << (IRQ_UART2 - IRQ_EINT0))
250 #define INTMSK_ADCPARENT (1UL << (IRQ_ADCPARENT - IRQ_EINT0))
256 s3c_irq_uart0_mask(struct irq_data
*data
)
258 s3c_irqsub_mask(data
->irq
, INTMSK_UART0
, 7);
262 s3c_irq_uart0_unmask(struct irq_data
*data
)
264 s3c_irqsub_unmask(data
->irq
, INTMSK_UART0
);
268 s3c_irq_uart0_ack(struct irq_data
*data
)
270 s3c_irqsub_maskack(data
->irq
, INTMSK_UART0
, 7);
273 static struct irq_chip s3c_irq_uart0
= {
275 .irq_mask
= s3c_irq_uart0_mask
,
276 .irq_unmask
= s3c_irq_uart0_unmask
,
277 .irq_ack
= s3c_irq_uart0_ack
,
283 s3c_irq_uart1_mask(struct irq_data
*data
)
285 s3c_irqsub_mask(data
->irq
, INTMSK_UART1
, 7 << 3);
289 s3c_irq_uart1_unmask(struct irq_data
*data
)
291 s3c_irqsub_unmask(data
->irq
, INTMSK_UART1
);
295 s3c_irq_uart1_ack(struct irq_data
*data
)
297 s3c_irqsub_maskack(data
->irq
, INTMSK_UART1
, 7 << 3);
300 static struct irq_chip s3c_irq_uart1
= {
302 .irq_mask
= s3c_irq_uart1_mask
,
303 .irq_unmask
= s3c_irq_uart1_unmask
,
304 .irq_ack
= s3c_irq_uart1_ack
,
310 s3c_irq_uart2_mask(struct irq_data
*data
)
312 s3c_irqsub_mask(data
->irq
, INTMSK_UART2
, 7 << 6);
316 s3c_irq_uart2_unmask(struct irq_data
*data
)
318 s3c_irqsub_unmask(data
->irq
, INTMSK_UART2
);
322 s3c_irq_uart2_ack(struct irq_data
*data
)
324 s3c_irqsub_maskack(data
->irq
, INTMSK_UART2
, 7 << 6);
327 static struct irq_chip s3c_irq_uart2
= {
329 .irq_mask
= s3c_irq_uart2_mask
,
330 .irq_unmask
= s3c_irq_uart2_unmask
,
331 .irq_ack
= s3c_irq_uart2_ack
,
334 /* ADC and Touchscreen */
337 s3c_irq_adc_mask(struct irq_data
*d
)
339 s3c_irqsub_mask(d
->irq
, INTMSK_ADCPARENT
, 3 << 9);
343 s3c_irq_adc_unmask(struct irq_data
*d
)
345 s3c_irqsub_unmask(d
->irq
, INTMSK_ADCPARENT
);
349 s3c_irq_adc_ack(struct irq_data
*d
)
351 s3c_irqsub_ack(d
->irq
, INTMSK_ADCPARENT
, 3 << 9);
354 static struct irq_chip s3c_irq_adc
= {
356 .irq_mask
= s3c_irq_adc_mask
,
357 .irq_unmask
= s3c_irq_adc_unmask
,
358 .irq_ack
= s3c_irq_adc_ack
,
361 /* irq demux for adc */
362 static void s3c_irq_demux_adc(unsigned int irq
,
363 struct irq_desc
*desc
)
365 unsigned int subsrc
, submsk
;
366 unsigned int offset
= 9;
368 /* read the current pending interrupts, and the mask
369 * for what it is available */
371 subsrc
= __raw_readl(S3C2410_SUBSRCPND
);
372 submsk
= __raw_readl(S3C2410_INTSUBMSK
);
380 generic_handle_irq(IRQ_TC
);
383 generic_handle_irq(IRQ_ADC
);
388 static void s3c_irq_demux_uart(unsigned int start
)
390 unsigned int subsrc
, submsk
;
391 unsigned int offset
= start
- IRQ_S3CUART_RX0
;
393 /* read the current pending interrupts, and the mask
394 * for what it is available */
396 subsrc
= __raw_readl(S3C2410_SUBSRCPND
);
397 submsk
= __raw_readl(S3C2410_INTSUBMSK
);
399 irqdbf2("s3c_irq_demux_uart: start=%d (%d), subsrc=0x%08x,0x%08x\n",
400 start
, offset
, subsrc
, submsk
);
408 generic_handle_irq(start
);
411 generic_handle_irq(start
+1);
414 generic_handle_irq(start
+2);
418 /* uart demux entry points */
421 s3c_irq_demux_uart0(unsigned int irq
,
422 struct irq_desc
*desc
)
425 s3c_irq_demux_uart(IRQ_S3CUART_RX0
);
429 s3c_irq_demux_uart1(unsigned int irq
,
430 struct irq_desc
*desc
)
433 s3c_irq_demux_uart(IRQ_S3CUART_RX1
);
437 s3c_irq_demux_uart2(unsigned int irq
,
438 struct irq_desc
*desc
)
441 s3c_irq_demux_uart(IRQ_S3CUART_RX2
);
445 s3c_irq_demux_extint8(unsigned int irq
,
446 struct irq_desc
*desc
)
448 unsigned long eintpnd
= __raw_readl(S3C24XX_EINTPEND
);
449 unsigned long eintmsk
= __raw_readl(S3C24XX_EINTMASK
);
452 eintpnd
&= ~0xff; /* ignore lower irqs */
454 /* we may as well handle all the pending IRQs here */
457 irq
= __ffs(eintpnd
);
458 eintpnd
&= ~(1<<irq
);
460 irq
+= (IRQ_EINT4
- 4);
461 generic_handle_irq(irq
);
467 s3c_irq_demux_extint4t7(unsigned int irq
,
468 struct irq_desc
*desc
)
470 unsigned long eintpnd
= __raw_readl(S3C24XX_EINTPEND
);
471 unsigned long eintmsk
= __raw_readl(S3C24XX_EINTMASK
);
474 eintpnd
&= 0xff; /* only lower irqs */
476 /* we may as well handle all the pending IRQs here */
479 irq
= __ffs(eintpnd
);
480 eintpnd
&= ~(1<<irq
);
482 irq
+= (IRQ_EINT4
- 4);
484 generic_handle_irq(irq
);
490 * s3c24xx_set_fiq - set the FIQ routing
491 * @irq: IRQ number to route to FIQ on processor.
492 * @on: Whether to route @irq to the FIQ, or to remove the FIQ routing.
494 * Change the state of the IRQ to FIQ routing depending on @irq and @on. If
495 * @on is true, the @irq is checked to see if it can be routed and the
496 * interrupt controller updated to route the IRQ. If @on is false, the FIQ
497 * routing is cleared, regardless of which @irq is specified.
499 int s3c24xx_set_fiq(unsigned int irq
, bool on
)
505 offs
= irq
- FIQ_START
;
514 __raw_writel(intmod
, S3C2410_INTMOD
);
518 EXPORT_SYMBOL_GPL(s3c24xx_set_fiq
);
524 * Initialise S3C2410 IRQ system
527 void __init
s3c24xx_init_irq(void)
538 irqdbf("s3c2410_init_irq: clearing interrupt status flags\n");
540 /* first, clear all interrupts pending... */
543 for (i
= 0; i
< 4; i
++) {
544 pend
= __raw_readl(S3C24XX_EINTPEND
);
546 if (pend
== 0 || pend
== last
)
549 __raw_writel(pend
, S3C24XX_EINTPEND
);
550 printk("irq: clearing pending ext status %08x\n", (int)pend
);
555 for (i
= 0; i
< 4; i
++) {
556 pend
= __raw_readl(S3C2410_INTPND
);
558 if (pend
== 0 || pend
== last
)
561 __raw_writel(pend
, S3C2410_SRCPND
);
562 __raw_writel(pend
, S3C2410_INTPND
);
563 printk("irq: clearing pending status %08x\n", (int)pend
);
568 for (i
= 0; i
< 4; i
++) {
569 pend
= __raw_readl(S3C2410_SUBSRCPND
);
571 if (pend
== 0 || pend
== last
)
574 printk("irq: clearing subpending status %08x\n", (int)pend
);
575 __raw_writel(pend
, S3C2410_SUBSRCPND
);
579 /* register the main interrupts */
581 irqdbf("s3c2410_init_irq: registering s3c2410 interrupt handlers\n");
583 for (irqno
= IRQ_EINT4t7
; irqno
<= IRQ_ADCPARENT
; irqno
++) {
584 /* set all the s3c2410 internal irqs */
587 /* deal with the special IRQs (cascaded) */
595 set_irq_chip(irqno
, &s3c_irq_level_chip
);
596 set_irq_handler(irqno
, handle_level_irq
);
605 //irqdbf("registering irq %d (s3c irq)\n", irqno);
606 set_irq_chip(irqno
, &s3c_irq_chip
);
607 set_irq_handler(irqno
, handle_edge_irq
);
608 set_irq_flags(irqno
, IRQF_VALID
);
612 /* setup the cascade irq handlers */
614 set_irq_chained_handler(IRQ_EINT4t7
, s3c_irq_demux_extint4t7
);
615 set_irq_chained_handler(IRQ_EINT8t23
, s3c_irq_demux_extint8
);
617 set_irq_chained_handler(IRQ_UART0
, s3c_irq_demux_uart0
);
618 set_irq_chained_handler(IRQ_UART1
, s3c_irq_demux_uart1
);
619 set_irq_chained_handler(IRQ_UART2
, s3c_irq_demux_uart2
);
620 set_irq_chained_handler(IRQ_ADCPARENT
, s3c_irq_demux_adc
);
622 /* external interrupts */
624 for (irqno
= IRQ_EINT0
; irqno
<= IRQ_EINT3
; irqno
++) {
625 irqdbf("registering irq %d (ext int)\n", irqno
);
626 set_irq_chip(irqno
, &s3c_irq_eint0t4
);
627 set_irq_handler(irqno
, handle_edge_irq
);
628 set_irq_flags(irqno
, IRQF_VALID
);
631 for (irqno
= IRQ_EINT4
; irqno
<= IRQ_EINT23
; irqno
++) {
632 irqdbf("registering irq %d (extended s3c irq)\n", irqno
);
633 set_irq_chip(irqno
, &s3c_irqext_chip
);
634 set_irq_handler(irqno
, handle_edge_irq
);
635 set_irq_flags(irqno
, IRQF_VALID
);
638 /* register the uart interrupts */
640 irqdbf("s3c2410: registering external interrupts\n");
642 for (irqno
= IRQ_S3CUART_RX0
; irqno
<= IRQ_S3CUART_ERR0
; irqno
++) {
643 irqdbf("registering irq %d (s3c uart0 irq)\n", irqno
);
644 set_irq_chip(irqno
, &s3c_irq_uart0
);
645 set_irq_handler(irqno
, handle_level_irq
);
646 set_irq_flags(irqno
, IRQF_VALID
);
649 for (irqno
= IRQ_S3CUART_RX1
; irqno
<= IRQ_S3CUART_ERR1
; irqno
++) {
650 irqdbf("registering irq %d (s3c uart1 irq)\n", irqno
);
651 set_irq_chip(irqno
, &s3c_irq_uart1
);
652 set_irq_handler(irqno
, handle_level_irq
);
653 set_irq_flags(irqno
, IRQF_VALID
);
656 for (irqno
= IRQ_S3CUART_RX2
; irqno
<= IRQ_S3CUART_ERR2
; irqno
++) {
657 irqdbf("registering irq %d (s3c uart2 irq)\n", irqno
);
658 set_irq_chip(irqno
, &s3c_irq_uart2
);
659 set_irq_handler(irqno
, handle_level_irq
);
660 set_irq_flags(irqno
, IRQF_VALID
);
663 for (irqno
= IRQ_TC
; irqno
<= IRQ_ADC
; irqno
++) {
664 irqdbf("registering irq %d (s3c adc irq)\n", irqno
);
665 set_irq_chip(irqno
, &s3c_irq_adc
);
666 set_irq_handler(irqno
, handle_edge_irq
);
667 set_irq_flags(irqno
, IRQF_VALID
);
670 irqdbf("s3c2410: registered interrupt handlers\n");