blob: a9a0c3fab159744900a60b6bbbc27b5dd1385be2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mach-pxa/irq.c
3 *
eric miaoe3630db2008-03-04 11:42:26 +08004 * Generic PXA IRQ handling
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Author: Nicolas Pitre
7 * Created: Jun 15, 2001
8 * Copyright: MontaVista Software Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/interrupt.h>
eric miaoc01655042008-01-28 23:00:02 +000018#include <linux/sysdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
20#include <asm/hardware.h>
21#include <asm/irq.h>
22#include <asm/mach/irq.h>
23#include <asm/arch/pxa-regs.h>
eric miaoa683b142008-03-03 09:44:25 +080024#include <asm/arch/pxa2xx-gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include "generic.h"
27
eric miaof6fb7af2008-03-04 13:53:05 +080028#define IRQ_BIT(n) (((n) - PXA_IRQ(0)) & 0x1f)
29#define _ICMR(n) (*((((n) - PXA_IRQ(0)) & ~0x1f) ? &ICMR2 : &ICMR))
30#define _ICLR(n) (*((((n) - PXA_IRQ(0)) & ~0x1f) ? &ICLR2 : &ICLR))
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/*
33 * This is for peripheral IRQs internal to the PXA chip.
34 */
35
eric miaof6fb7af2008-03-04 13:53:05 +080036static int pxa_internal_irq_nr;
37
38static void pxa_mask_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
eric miaof6fb7af2008-03-04 13:53:05 +080040 _ICMR(irq) &= ~(1 << IRQ_BIT(irq));
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
eric miaof6fb7af2008-03-04 13:53:05 +080043static void pxa_unmask_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
eric miaof6fb7af2008-03-04 13:53:05 +080045 _ICMR(irq) |= 1 << IRQ_BIT(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
eric miaof6fb7af2008-03-04 13:53:05 +080048static struct irq_chip pxa_internal_irq_chip = {
David Brownell38c677c2006-08-01 22:26:25 +010049 .name = "SC",
eric miaof6fb7af2008-03-04 13:53:05 +080050 .ack = pxa_mask_irq,
51 .mask = pxa_mask_irq,
52 .unmask = pxa_unmask_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
eric miaob9e25ac2008-03-04 14:19:58 +080055void __init pxa_init_irq(int irq_nr, set_wake_t fn)
Eric Miao53665a52007-06-06 06:36:04 +010056{
57 int irq;
58
eric miaof6fb7af2008-03-04 13:53:05 +080059 pxa_internal_irq_nr = irq_nr;
Eric Miao53665a52007-06-06 06:36:04 +010060
eric miaof6fb7af2008-03-04 13:53:05 +080061 for (irq = 0; irq < irq_nr; irq += 32) {
62 _ICMR(irq) = 0; /* disable all IRQs */
63 _ICLR(irq) = 0; /* all IRQs are IRQ, not FIQ */
64 }
Eric Miao53665a52007-06-06 06:36:04 +010065
66 /* only unmasked interrupts kick us out of idle */
67 ICCR = 1;
68
eric miaof6fb7af2008-03-04 13:53:05 +080069 for (irq = PXA_IRQ(0); irq < PXA_IRQ(irq_nr); irq++) {
70 set_irq_chip(irq, &pxa_internal_irq_chip);
Eric Miao53665a52007-06-06 06:36:04 +010071 set_irq_handler(irq, handle_level_irq);
72 set_irq_flags(irq, IRQF_VALID);
73 }
Eric Miao53665a52007-06-06 06:36:04 +010074
eric miaob9e25ac2008-03-04 14:19:58 +080075 pxa_internal_irq_chip.set_wake = fn;
eric miaoc95530c2007-08-29 10:22:17 +010076}
eric miaoc01655042008-01-28 23:00:02 +000077
78#ifdef CONFIG_PM
79static unsigned long saved_icmr[2];
80
81static int pxa_irq_suspend(struct sys_device *dev, pm_message_t state)
82{
eric miaof6fb7af2008-03-04 13:53:05 +080083 int i, irq = PXA_IRQ(0);
84
85 for (i = 0; irq < PXA_IRQ(pxa_internal_irq_nr); i++, irq += 32) {
86 saved_icmr[i] = _ICMR(irq);
87 _ICMR(irq) = 0;
eric miaoc01655042008-01-28 23:00:02 +000088 }
89
90 return 0;
91}
92
93static int pxa_irq_resume(struct sys_device *dev)
94{
eric miaof6fb7af2008-03-04 13:53:05 +080095 int i, irq = PXA_IRQ(0);
96
97 for (i = 0; irq < PXA_IRQ(pxa_internal_irq_nr); i++, irq += 32) {
98 _ICMR(irq) = saved_icmr[i];
99 _ICLR(irq) = 0;
eric miaoc01655042008-01-28 23:00:02 +0000100 }
101
eric miaof6fb7af2008-03-04 13:53:05 +0800102 ICCR = 1;
eric miaoc01655042008-01-28 23:00:02 +0000103 return 0;
104}
105#else
106#define pxa_irq_suspend NULL
107#define pxa_irq_resume NULL
108#endif
109
110struct sysdev_class pxa_irq_sysclass = {
111 .name = "irq",
112 .suspend = pxa_irq_suspend,
113 .resume = pxa_irq_resume,
114};
115
116static int __init pxa_irq_init(void)
117{
118 return sysdev_class_register(&pxa_irq_sysclass);
119}
120
121core_initcall(pxa_irq_init);