1 /* linux/arch/arm/mach-s3c2416/irq.c
3 * Copyright (c) 2009 Yauhen Kharuzhy <jekhor@gmail.com>,
4 * as part of OpenInkpot project
5 * Copyright (c) 2009 Promwad Innovation Company
6 * Yauhen Kharuzhy <yauhen.kharuzhy@promwad.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/init.h>
25 #include <linux/module.h>
26 #include <linux/interrupt.h>
27 #include <linux/ioport.h>
28 #include <linux/device.h>
30 #include <linux/syscore_ops.h>
32 #include <mach/hardware.h>
35 #include <asm/mach/irq.h>
37 #include <mach/regs-irq.h>
38 #include <mach/regs-gpio.h>
44 #define INTMSK(start, end) ((1 << ((end) + 1 - (start))) - 1)
46 static inline void s3c2416_irq_demux(unsigned int irq
, unsigned int len
)
48 unsigned int subsrc
, submsk
;
51 /* read the current pending interrupts, and the mask
52 * for what it is available */
54 subsrc
= __raw_readl(S3C2410_SUBSRCPND
);
55 submsk
= __raw_readl(S3C2410_INTSUBMSK
);
58 subsrc
>>= (irq
- S3C2410_IRQSUB(0));
59 subsrc
&= (1 << len
)-1;
63 for (; irq
< end
&& subsrc
; irq
++) {
65 generic_handle_irq(irq
);
71 /* WDT/AC97 sub interrupts */
73 static void s3c2416_irq_demux_wdtac97(unsigned int irq
, struct irq_desc
*desc
)
75 s3c2416_irq_demux(IRQ_S3C2443_WDT
, 4);
78 #define INTMSK_WDTAC97 (1UL << (IRQ_WDT - IRQ_EINT0))
79 #define SUBMSK_WDTAC97 INTMSK(IRQ_S3C2443_WDT, IRQ_S3C2443_AC97)
81 static void s3c2416_irq_wdtac97_mask(struct irq_data
*data
)
83 s3c_irqsub_mask(data
->irq
, INTMSK_WDTAC97
, SUBMSK_WDTAC97
);
86 static void s3c2416_irq_wdtac97_unmask(struct irq_data
*data
)
88 s3c_irqsub_unmask(data
->irq
, INTMSK_WDTAC97
);
91 static void s3c2416_irq_wdtac97_ack(struct irq_data
*data
)
93 s3c_irqsub_maskack(data
->irq
, INTMSK_WDTAC97
, SUBMSK_WDTAC97
);
96 static struct irq_chip s3c2416_irq_wdtac97
= {
97 .irq_mask
= s3c2416_irq_wdtac97_mask
,
98 .irq_unmask
= s3c2416_irq_wdtac97_unmask
,
99 .irq_ack
= s3c2416_irq_wdtac97_ack
,
102 /* LCD sub interrupts */
104 static void s3c2416_irq_demux_lcd(unsigned int irq
, struct irq_desc
*desc
)
106 s3c2416_irq_demux(IRQ_S3C2443_LCD1
, 4);
109 #define INTMSK_LCD (1UL << (IRQ_LCD - IRQ_EINT0))
110 #define SUBMSK_LCD INTMSK(IRQ_S3C2443_LCD1, IRQ_S3C2443_LCD4)
112 static void s3c2416_irq_lcd_mask(struct irq_data
*data
)
114 s3c_irqsub_mask(data
->irq
, INTMSK_LCD
, SUBMSK_LCD
);
117 static void s3c2416_irq_lcd_unmask(struct irq_data
*data
)
119 s3c_irqsub_unmask(data
->irq
, INTMSK_LCD
);
122 static void s3c2416_irq_lcd_ack(struct irq_data
*data
)
124 s3c_irqsub_maskack(data
->irq
, INTMSK_LCD
, SUBMSK_LCD
);
127 static struct irq_chip s3c2416_irq_lcd
= {
128 .irq_mask
= s3c2416_irq_lcd_mask
,
129 .irq_unmask
= s3c2416_irq_lcd_unmask
,
130 .irq_ack
= s3c2416_irq_lcd_ack
,
133 /* DMA sub interrupts */
135 static void s3c2416_irq_demux_dma(unsigned int irq
, struct irq_desc
*desc
)
137 s3c2416_irq_demux(IRQ_S3C2443_DMA0
, 6);
140 #define INTMSK_DMA (1UL << (IRQ_S3C2443_DMA - IRQ_EINT0))
141 #define SUBMSK_DMA INTMSK(IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5)
144 static void s3c2416_irq_dma_mask(struct irq_data
*data
)
146 s3c_irqsub_mask(data
->irq
, INTMSK_DMA
, SUBMSK_DMA
);
149 static void s3c2416_irq_dma_unmask(struct irq_data
*data
)
151 s3c_irqsub_unmask(data
->irq
, INTMSK_DMA
);
154 static void s3c2416_irq_dma_ack(struct irq_data
*data
)
156 s3c_irqsub_maskack(data
->irq
, INTMSK_DMA
, SUBMSK_DMA
);
159 static struct irq_chip s3c2416_irq_dma
= {
160 .irq_mask
= s3c2416_irq_dma_mask
,
161 .irq_unmask
= s3c2416_irq_dma_unmask
,
162 .irq_ack
= s3c2416_irq_dma_ack
,
165 /* UART3 sub interrupts */
167 static void s3c2416_irq_demux_uart3(unsigned int irq
, struct irq_desc
*desc
)
169 s3c2416_irq_demux(IRQ_S3C2443_RX3
, 3);
172 #define INTMSK_UART3 (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0))
173 #define SUBMSK_UART3 (0x7 << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0)))
175 static void s3c2416_irq_uart3_mask(struct irq_data
*data
)
177 s3c_irqsub_mask(data
->irq
, INTMSK_UART3
, SUBMSK_UART3
);
180 static void s3c2416_irq_uart3_unmask(struct irq_data
*data
)
182 s3c_irqsub_unmask(data
->irq
, INTMSK_UART3
);
185 static void s3c2416_irq_uart3_ack(struct irq_data
*data
)
187 s3c_irqsub_maskack(data
->irq
, INTMSK_UART3
, SUBMSK_UART3
);
190 static struct irq_chip s3c2416_irq_uart3
= {
191 .irq_mask
= s3c2416_irq_uart3_mask
,
192 .irq_unmask
= s3c2416_irq_uart3_unmask
,
193 .irq_ack
= s3c2416_irq_uart3_ack
,
196 /* second interrupt register */
198 static inline void s3c2416_irq_ack_second(struct irq_data
*data
)
200 unsigned long bitval
= 1UL << (data
->irq
- IRQ_S3C2416_2D
);
202 __raw_writel(bitval
, S3C2416_SRCPND2
);
203 __raw_writel(bitval
, S3C2416_INTPND2
);
206 static void s3c2416_irq_mask_second(struct irq_data
*data
)
208 unsigned long bitval
= 1UL << (data
->irq
- IRQ_S3C2416_2D
);
211 mask
= __raw_readl(S3C2416_INTMSK2
);
213 __raw_writel(mask
, S3C2416_INTMSK2
);
216 static void s3c2416_irq_unmask_second(struct irq_data
*data
)
218 unsigned long bitval
= 1UL << (data
->irq
- IRQ_S3C2416_2D
);
221 mask
= __raw_readl(S3C2416_INTMSK2
);
223 __raw_writel(mask
, S3C2416_INTMSK2
);
226 struct irq_chip s3c2416_irq_second
= {
227 .irq_ack
= s3c2416_irq_ack_second
,
228 .irq_mask
= s3c2416_irq_mask_second
,
229 .irq_unmask
= s3c2416_irq_unmask_second
,
233 /* IRQ initialisation code */
235 static int s3c2416_add_sub(unsigned int base
,
236 void (*demux
)(unsigned int,
238 struct irq_chip
*chip
,
239 unsigned int start
, unsigned int end
)
243 irq_set_chip_and_handler(base
, &s3c_irq_level_chip
, handle_level_irq
);
244 irq_set_chained_handler(base
, demux
);
246 for (irqno
= start
; irqno
<= end
; irqno
++) {
247 irq_set_chip_and_handler(irqno
, chip
, handle_level_irq
);
248 set_irq_flags(irqno
, IRQF_VALID
);
254 static void s3c2416_irq_add_second(void)
261 /* first, clear all interrupts pending... */
263 for (i
= 0; i
< 4; i
++) {
264 pend
= __raw_readl(S3C2416_INTPND2
);
266 if (pend
== 0 || pend
== last
)
269 __raw_writel(pend
, S3C2416_SRCPND2
);
270 __raw_writel(pend
, S3C2416_INTPND2
);
271 printk(KERN_INFO
"irq: clearing pending status %08x\n",
276 for (irqno
= IRQ_S3C2416_2D
; irqno
<= IRQ_S3C2416_I2S1
; irqno
++) {
278 case IRQ_S3C2416_RESERVED2
:
279 case IRQ_S3C2416_RESERVED3
:
283 irq_set_chip_and_handler(irqno
, &s3c2416_irq_second
,
285 set_irq_flags(irqno
, IRQF_VALID
);
290 static int s3c2416_irq_add(struct device
*dev
,
291 struct subsys_interface
*sif
)
293 printk(KERN_INFO
"S3C2416: IRQ Support\n");
295 s3c2416_add_sub(IRQ_LCD
, s3c2416_irq_demux_lcd
, &s3c2416_irq_lcd
,
296 IRQ_S3C2443_LCD2
, IRQ_S3C2443_LCD4
);
298 s3c2416_add_sub(IRQ_S3C2443_DMA
, s3c2416_irq_demux_dma
,
299 &s3c2416_irq_dma
, IRQ_S3C2443_DMA0
, IRQ_S3C2443_DMA5
);
301 s3c2416_add_sub(IRQ_S3C2443_UART3
, s3c2416_irq_demux_uart3
,
303 IRQ_S3C2443_RX3
, IRQ_S3C2443_ERR3
);
305 s3c2416_add_sub(IRQ_WDT
, s3c2416_irq_demux_wdtac97
,
306 &s3c2416_irq_wdtac97
,
307 IRQ_S3C2443_WDT
, IRQ_S3C2443_AC97
);
309 s3c2416_irq_add_second();
314 static struct subsys_interface s3c2416_irq_interface
= {
315 .name
= "s3c2416_irq",
316 .subsys
= &s3c2416_subsys
,
317 .add_dev
= s3c2416_irq_add
,
320 static int __init
s3c2416_irq_init(void)
322 return subsys_interface_register(&s3c2416_irq_interface
);
325 arch_initcall(s3c2416_irq_init
);
328 static struct sleep_save irq_save
[] = {
329 SAVE_ITEM(S3C2416_INTMSK2
),
332 int s3c2416_irq_suspend(void)
334 s3c_pm_do_save(irq_save
, ARRAY_SIZE(irq_save
));
339 void s3c2416_irq_resume(void)
341 s3c_pm_do_restore(irq_save
, ARRAY_SIZE(irq_save
));
344 struct syscore_ops s3c2416_irq_syscore_ops
= {
345 .suspend
= s3c2416_irq_suspend
,
346 .resume
= s3c2416_irq_resume
,