ia64/kvm: compilation fix. export account_system_vtime.
[pv_ops_mirror.git] / arch / arm / mach-s3c2412 / irq.c
blobcc1917bf952ad2e24872141eb04d7869ccd416ee
1 /* linux/arch/arm/mach-s3c2412/irq.c
3 * Copyright (c) 2006 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
22 #include <linux/init.h>
23 #include <linux/module.h>
24 #include <linux/interrupt.h>
25 #include <linux/ioport.h>
26 #include <linux/sysdev.h>
28 #include <asm/hardware.h>
29 #include <asm/irq.h>
30 #include <asm/io.h>
32 #include <asm/mach/irq.h>
34 #include <asm/arch/regs-irq.h>
35 #include <asm/arch/regs-gpio.h>
36 #include <asm/arch/regs-power.h>
38 #include <asm/plat-s3c24xx/cpu.h>
39 #include <asm/plat-s3c24xx/irq.h>
40 #include <asm/plat-s3c24xx/pm.h>
42 #define INTMSK(start, end) ((1 << ((end) + 1 - (start))) - 1)
43 #define INTMSK_SUB(start, end) (INTMSK(start, end) << ((start - S3C2410_IRQSUB(0))))
45 /* the s3c2412 changes the behaviour of IRQ_EINT0 through IRQ_EINT3 by
46 * having them turn up in both the INT* and the EINT* registers. Whilst
47 * both show the status, they both now need to be acked when the IRQs
48 * go off.
51 static void
52 s3c2412_irq_mask(unsigned int irqno)
54 unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
55 unsigned long mask;
57 mask = __raw_readl(S3C2410_INTMSK);
58 __raw_writel(mask | bitval, S3C2410_INTMSK);
60 mask = __raw_readl(S3C2412_EINTMASK);
61 __raw_writel(mask | bitval, S3C2412_EINTMASK);
64 static inline void
65 s3c2412_irq_ack(unsigned int irqno)
67 unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
69 __raw_writel(bitval, S3C2412_EINTPEND);
70 __raw_writel(bitval, S3C2410_SRCPND);
71 __raw_writel(bitval, S3C2410_INTPND);
74 static inline void
75 s3c2412_irq_maskack(unsigned int irqno)
77 unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
78 unsigned long mask;
80 mask = __raw_readl(S3C2410_INTMSK);
81 __raw_writel(mask|bitval, S3C2410_INTMSK);
83 mask = __raw_readl(S3C2412_EINTMASK);
84 __raw_writel(mask | bitval, S3C2412_EINTMASK);
86 __raw_writel(bitval, S3C2412_EINTPEND);
87 __raw_writel(bitval, S3C2410_SRCPND);
88 __raw_writel(bitval, S3C2410_INTPND);
91 static void
92 s3c2412_irq_unmask(unsigned int irqno)
94 unsigned long bitval = 1UL << (irqno - IRQ_EINT0);
95 unsigned long mask;
97 mask = __raw_readl(S3C2412_EINTMASK);
98 __raw_writel(mask & ~bitval, S3C2412_EINTMASK);
100 mask = __raw_readl(S3C2410_INTMSK);
101 __raw_writel(mask & ~bitval, S3C2410_INTMSK);
104 static struct irq_chip s3c2412_irq_eint0t4 = {
105 .ack = s3c2412_irq_ack,
106 .mask = s3c2412_irq_mask,
107 .unmask = s3c2412_irq_unmask,
108 .set_wake = s3c_irq_wake,
109 .set_type = s3c_irqext_type,
112 #define INTBIT(x) (1 << ((x) - S3C2410_IRQSUB(0)))
114 /* CF and SDI sub interrupts */
116 static void s3c2412_irq_demux_cfsdi(unsigned int irq, struct irq_desc *desc)
118 unsigned int subsrc, submsk;
120 subsrc = __raw_readl(S3C2410_SUBSRCPND);
121 submsk = __raw_readl(S3C2410_INTSUBMSK);
123 subsrc &= ~submsk;
125 if (subsrc & INTBIT(IRQ_S3C2412_SDI))
126 desc_handle_irq(IRQ_S3C2412_SDI, irq_desc + IRQ_S3C2412_SDI);
128 if (subsrc & INTBIT(IRQ_S3C2412_CF))
129 desc_handle_irq(IRQ_S3C2412_CF, irq_desc + IRQ_S3C2412_CF);
132 #define INTMSK_CFSDI (1UL << (IRQ_S3C2412_CFSDI - IRQ_EINT0))
133 #define SUBMSK_CFSDI INTMSK_SUB(IRQ_S3C2412_SDI, IRQ_S3C2412_CF)
135 static void s3c2412_irq_cfsdi_mask(unsigned int irqno)
137 s3c_irqsub_mask(irqno, INTMSK_CFSDI, SUBMSK_CFSDI);
140 static void s3c2412_irq_cfsdi_unmask(unsigned int irqno)
142 s3c_irqsub_unmask(irqno, INTMSK_CFSDI);
145 static void s3c2412_irq_cfsdi_ack(unsigned int irqno)
147 s3c_irqsub_maskack(irqno, INTMSK_CFSDI, SUBMSK_CFSDI);
150 static struct irq_chip s3c2412_irq_cfsdi = {
151 .name = "s3c2412-cfsdi",
152 .ack = s3c2412_irq_cfsdi_ack,
153 .mask = s3c2412_irq_cfsdi_mask,
154 .unmask = s3c2412_irq_cfsdi_unmask,
157 static int s3c2412_irq_rtc_wake(unsigned int irqno, unsigned int state)
159 unsigned long pwrcfg;
161 pwrcfg = __raw_readl(S3C2412_PWRCFG);
162 if (state)
163 pwrcfg &= ~S3C2412_PWRCFG_RTC_MASKIRQ;
164 else
165 pwrcfg |= S3C2412_PWRCFG_RTC_MASKIRQ;
166 __raw_writel(pwrcfg, S3C2412_PWRCFG);
168 return s3c_irq_chip.set_wake(irqno, state);
171 static struct irq_chip s3c2412_irq_rtc_chip;
173 static int s3c2412_irq_add(struct sys_device *sysdev)
175 unsigned int irqno;
177 for (irqno = IRQ_EINT0; irqno <= IRQ_EINT3; irqno++) {
178 set_irq_chip(irqno, &s3c2412_irq_eint0t4);
179 set_irq_handler(irqno, handle_edge_irq);
180 set_irq_flags(irqno, IRQF_VALID);
183 /* add demux support for CF/SDI */
185 set_irq_chained_handler(IRQ_S3C2412_CFSDI, s3c2412_irq_demux_cfsdi);
187 for (irqno = IRQ_S3C2412_SDI; irqno <= IRQ_S3C2412_CF; irqno++) {
188 set_irq_chip(irqno, &s3c2412_irq_cfsdi);
189 set_irq_handler(irqno, handle_level_irq);
190 set_irq_flags(irqno, IRQF_VALID);
193 /* change RTC IRQ's set wake method */
195 s3c2412_irq_rtc_chip = s3c_irq_chip;
196 s3c2412_irq_rtc_chip.set_wake = s3c2412_irq_rtc_wake;
198 set_irq_chip(IRQ_RTC, &s3c2412_irq_rtc_chip);
200 return 0;
203 static struct sysdev_driver s3c2412_irq_driver = {
204 .add = s3c2412_irq_add,
205 .suspend = s3c24xx_irq_suspend,
206 .resume = s3c24xx_irq_resume,
209 static int s3c2412_irq_init(void)
211 return sysdev_driver_register(&s3c2412_sysclass, &s3c2412_irq_driver);
214 arch_initcall(s3c2412_irq_init);