Merge branch 'v6v7' into devel
[linux/fpc-iii.git] / arch / arm / plat-s3c24xx / irq.c
blob4434cb56bd9ad898a76ca54c31fb4ca07af52fc1
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>
27 #include <asm/irq.h>
28 #include <asm/mach/irq.h>
30 #include <plat/regs-irqtype.h>
32 #include <plat/cpu.h>
33 #include <plat/pm.h>
34 #include <plat/irq.h>
36 static void
37 s3c_irq_mask(struct irq_data *data)
39 unsigned int irqno = data->irq - IRQ_EINT0;
40 unsigned long mask;
42 mask = __raw_readl(S3C2410_INTMSK);
43 mask |= 1UL << irqno;
44 __raw_writel(mask, S3C2410_INTMSK);
47 static inline void
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);
56 static inline void
57 s3c_irq_maskack(struct irq_data *data)
59 unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
60 unsigned long mask;
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);
70 static void
71 s3c_irq_unmask(struct irq_data *data)
73 unsigned int irqno = data->irq;
74 unsigned long mask;
76 if (irqno != IRQ_TIMER4 && irqno != IRQ_EINT8t23)
77 irqdbf2("s3c_irq_unmask %d\n", irqno);
79 irqno -= IRQ_EINT0;
81 mask = __raw_readl(S3C2410_INTMSK);
82 mask &= ~(1UL << irqno);
83 __raw_writel(mask, S3C2410_INTMSK);
86 struct irq_chip s3c_irq_level_chip = {
87 .name = "s3c-level",
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 = {
95 .name = "s3c",
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
102 static void
103 s3c_irqext_mask(struct irq_data *data)
105 unsigned int irqno = data->irq - EXTINT_OFF;
106 unsigned long mask;
108 mask = __raw_readl(S3C24XX_EINTMASK);
109 mask |= ( 1UL << irqno);
110 __raw_writel(mask, S3C24XX_EINTMASK);
113 static void
114 s3c_irqext_ack(struct irq_data *data)
116 unsigned long req;
117 unsigned long bit;
118 unsigned long mask;
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);
127 req &= ~mask;
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));
134 } else {
135 if ((req >> 8) == 0)
136 s3c_irq_ack(irq_get_irq_data(IRQ_EINT8t23));
140 static void
141 s3c_irqext_unmask(struct irq_data *data)
143 unsigned int irqno = data->irq - EXTINT_OFF;
144 unsigned long mask;
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;
179 } else {
180 return -1;
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 */
189 switch (type)
191 case IRQ_TYPE_NONE:
192 printk(KERN_WARNING "No edge setting!\n");
193 break;
195 case IRQ_TYPE_EDGE_RISING:
196 newvalue = S3C2410_EXTINT_RISEEDGE;
197 break;
199 case IRQ_TYPE_EDGE_FALLING:
200 newvalue = S3C2410_EXTINT_FALLEDGE;
201 break;
203 case IRQ_TYPE_EDGE_BOTH:
204 newvalue = S3C2410_EXTINT_BOTHEDGE;
205 break;
207 case IRQ_TYPE_LEVEL_LOW:
208 newvalue = S3C2410_EXTINT_LOWLEV;
209 break;
211 case IRQ_TYPE_LEVEL_HIGH:
212 newvalue = S3C2410_EXTINT_HILEV;
213 break;
215 default:
216 printk(KERN_ERR "No such irq type %d", type);
217 return -1;
220 value = __raw_readl(extint_reg);
221 value = (value & ~(7 << extint_offset)) | (newvalue << extint_offset);
222 __raw_writel(value, extint_reg);
224 return 0;
227 static struct irq_chip s3c_irqext_chip = {
228 .name = "s3c-ext",
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 = {
237 .name = "s3c-ext0",
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))
253 /* UART0 */
255 static void
256 s3c_irq_uart0_mask(struct irq_data *data)
258 s3c_irqsub_mask(data->irq, INTMSK_UART0, 7);
261 static void
262 s3c_irq_uart0_unmask(struct irq_data *data)
264 s3c_irqsub_unmask(data->irq, INTMSK_UART0);
267 static void
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 = {
274 .name = "s3c-uart0",
275 .irq_mask = s3c_irq_uart0_mask,
276 .irq_unmask = s3c_irq_uart0_unmask,
277 .irq_ack = s3c_irq_uart0_ack,
280 /* UART1 */
282 static void
283 s3c_irq_uart1_mask(struct irq_data *data)
285 s3c_irqsub_mask(data->irq, INTMSK_UART1, 7 << 3);
288 static void
289 s3c_irq_uart1_unmask(struct irq_data *data)
291 s3c_irqsub_unmask(data->irq, INTMSK_UART1);
294 static void
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 = {
301 .name = "s3c-uart1",
302 .irq_mask = s3c_irq_uart1_mask,
303 .irq_unmask = s3c_irq_uart1_unmask,
304 .irq_ack = s3c_irq_uart1_ack,
307 /* UART2 */
309 static void
310 s3c_irq_uart2_mask(struct irq_data *data)
312 s3c_irqsub_mask(data->irq, INTMSK_UART2, 7 << 6);
315 static void
316 s3c_irq_uart2_unmask(struct irq_data *data)
318 s3c_irqsub_unmask(data->irq, INTMSK_UART2);
321 static void
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 = {
328 .name = "s3c-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 */
336 static void
337 s3c_irq_adc_mask(struct irq_data *d)
339 s3c_irqsub_mask(d->irq, INTMSK_ADCPARENT, 3 << 9);
342 static void
343 s3c_irq_adc_unmask(struct irq_data *d)
345 s3c_irqsub_unmask(d->irq, INTMSK_ADCPARENT);
348 static void
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 = {
355 .name = "s3c-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);
374 subsrc &= ~submsk;
375 subsrc >>= offset;
376 subsrc &= 3;
378 if (subsrc != 0) {
379 if (subsrc & 1) {
380 generic_handle_irq(IRQ_TC);
382 if (subsrc & 2) {
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);
402 subsrc &= ~submsk;
403 subsrc >>= offset;
404 subsrc &= 7;
406 if (subsrc != 0) {
407 if (subsrc & 1)
408 generic_handle_irq(start);
410 if (subsrc & 2)
411 generic_handle_irq(start+1);
413 if (subsrc & 4)
414 generic_handle_irq(start+2);
418 /* uart demux entry points */
420 static void
421 s3c_irq_demux_uart0(unsigned int irq,
422 struct irq_desc *desc)
424 irq = irq;
425 s3c_irq_demux_uart(IRQ_S3CUART_RX0);
428 static void
429 s3c_irq_demux_uart1(unsigned int irq,
430 struct irq_desc *desc)
432 irq = irq;
433 s3c_irq_demux_uart(IRQ_S3CUART_RX1);
436 static void
437 s3c_irq_demux_uart2(unsigned int irq,
438 struct irq_desc *desc)
440 irq = irq;
441 s3c_irq_demux_uart(IRQ_S3CUART_RX2);
444 static void
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);
451 eintpnd &= ~eintmsk;
452 eintpnd &= ~0xff; /* ignore lower irqs */
454 /* we may as well handle all the pending IRQs here */
456 while (eintpnd) {
457 irq = __ffs(eintpnd);
458 eintpnd &= ~(1<<irq);
460 irq += (IRQ_EINT4 - 4);
461 generic_handle_irq(irq);
466 static void
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);
473 eintpnd &= ~eintmsk;
474 eintpnd &= 0xff; /* only lower irqs */
476 /* we may as well handle all the pending IRQs here */
478 while (eintpnd) {
479 irq = __ffs(eintpnd);
480 eintpnd &= ~(1<<irq);
482 irq += (IRQ_EINT4 - 4);
484 generic_handle_irq(irq);
488 #ifdef CONFIG_FIQ
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)
501 u32 intmod;
502 unsigned offs;
504 if (on) {
505 offs = irq - FIQ_START;
506 if (offs > 31)
507 return -EINVAL;
509 intmod = 1 << offs;
510 } else {
511 intmod = 0;
514 __raw_writel(intmod, S3C2410_INTMOD);
515 return 0;
518 EXPORT_SYMBOL_GPL(s3c24xx_set_fiq);
519 #endif
522 /* s3c24xx_init_irq
524 * Initialise S3C2410 IRQ system
527 void __init s3c24xx_init_irq(void)
529 unsigned long pend;
530 unsigned long last;
531 int irqno;
532 int i;
534 #ifdef CONFIG_FIQ
535 init_FIQ();
536 #endif
538 irqdbf("s3c2410_init_irq: clearing interrupt status flags\n");
540 /* first, clear all interrupts pending... */
542 last = 0;
543 for (i = 0; i < 4; i++) {
544 pend = __raw_readl(S3C24XX_EINTPEND);
546 if (pend == 0 || pend == last)
547 break;
549 __raw_writel(pend, S3C24XX_EINTPEND);
550 printk("irq: clearing pending ext status %08x\n", (int)pend);
551 last = pend;
554 last = 0;
555 for (i = 0; i < 4; i++) {
556 pend = __raw_readl(S3C2410_INTPND);
558 if (pend == 0 || pend == last)
559 break;
561 __raw_writel(pend, S3C2410_SRCPND);
562 __raw_writel(pend, S3C2410_INTPND);
563 printk("irq: clearing pending status %08x\n", (int)pend);
564 last = pend;
567 last = 0;
568 for (i = 0; i < 4; i++) {
569 pend = __raw_readl(S3C2410_SUBSRCPND);
571 if (pend == 0 || pend == last)
572 break;
574 printk("irq: clearing subpending status %08x\n", (int)pend);
575 __raw_writel(pend, S3C2410_SUBSRCPND);
576 last = pend;
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 */
586 switch (irqno) {
587 /* deal with the special IRQs (cascaded) */
589 case IRQ_EINT4t7:
590 case IRQ_EINT8t23:
591 case IRQ_UART0:
592 case IRQ_UART1:
593 case IRQ_UART2:
594 case IRQ_ADCPARENT:
595 set_irq_chip(irqno, &s3c_irq_level_chip);
596 set_irq_handler(irqno, handle_level_irq);
597 break;
599 case IRQ_RESERVED6:
600 case IRQ_RESERVED24:
601 /* no IRQ here */
602 break;
604 default:
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");