blob: ff141b0af26bfb3f2cc223a202c2d9f278a7a1ef [file] [log] [blame]
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +09001/* linux/arch/arm/mach-s3c2416/irq.c
2 *
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>
7 *
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.
12 *
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.
17 *
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
21 *
22*/
23
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/interrupt.h>
27#include <linux/ioport.h>
Kay Sievers4a858cf2011-12-21 16:01:38 -080028#include <linux/device.h>
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +090029#include <linux/io.h>
Heiko Stuebner0e944e22012-05-20 01:01:35 +090030#include <linux/syscore_ops.h>
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +090031
32#include <mach/hardware.h>
33#include <asm/irq.h>
34
35#include <asm/mach/irq.h>
36
37#include <mach/regs-irq.h>
38#include <mach/regs-gpio.h>
39
40#include <plat/cpu.h>
41#include <plat/pm.h>
42#include <plat/irq.h>
43
44#define INTMSK(start, end) ((1 << ((end) + 1 - (start))) - 1)
45
46static inline void s3c2416_irq_demux(unsigned int irq, unsigned int len)
47{
48 unsigned int subsrc, submsk;
49 unsigned int end;
50
51 /* read the current pending interrupts, and the mask
52 * for what it is available */
53
54 subsrc = __raw_readl(S3C2410_SUBSRCPND);
55 submsk = __raw_readl(S3C2410_INTSUBMSK);
56
57 subsrc &= ~submsk;
58 subsrc >>= (irq - S3C2410_IRQSUB(0));
59 subsrc &= (1 << len)-1;
60
61 end = len + irq;
62
63 for (; irq < end && subsrc; irq++) {
64 if (subsrc & 1)
65 generic_handle_irq(irq);
66
67 subsrc >>= 1;
68 }
69}
70
71/* WDT/AC97 sub interrupts */
72
73static void s3c2416_irq_demux_wdtac97(unsigned int irq, struct irq_desc *desc)
74{
75 s3c2416_irq_demux(IRQ_S3C2443_WDT, 4);
76}
77
78#define INTMSK_WDTAC97 (1UL << (IRQ_WDT - IRQ_EINT0))
79#define SUBMSK_WDTAC97 INTMSK(IRQ_S3C2443_WDT, IRQ_S3C2443_AC97)
80
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090081static void s3c2416_irq_wdtac97_mask(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +090082{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090083 s3c_irqsub_mask(data->irq, INTMSK_WDTAC97, SUBMSK_WDTAC97);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +090084}
85
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090086static void s3c2416_irq_wdtac97_unmask(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +090087{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090088 s3c_irqsub_unmask(data->irq, INTMSK_WDTAC97);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +090089}
90
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090091static void s3c2416_irq_wdtac97_ack(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +090092{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090093 s3c_irqsub_maskack(data->irq, INTMSK_WDTAC97, SUBMSK_WDTAC97);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +090094}
95
96static struct irq_chip s3c2416_irq_wdtac97 = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090097 .irq_mask = s3c2416_irq_wdtac97_mask,
98 .irq_unmask = s3c2416_irq_wdtac97_unmask,
99 .irq_ack = s3c2416_irq_wdtac97_ack,
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900100};
101
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900102/* LCD sub interrupts */
103
104static void s3c2416_irq_demux_lcd(unsigned int irq, struct irq_desc *desc)
105{
106 s3c2416_irq_demux(IRQ_S3C2443_LCD1, 4);
107}
108
109#define INTMSK_LCD (1UL << (IRQ_LCD - IRQ_EINT0))
110#define SUBMSK_LCD INTMSK(IRQ_S3C2443_LCD1, IRQ_S3C2443_LCD4)
111
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900112static void s3c2416_irq_lcd_mask(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900113{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900114 s3c_irqsub_mask(data->irq, INTMSK_LCD, SUBMSK_LCD);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900115}
116
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900117static void s3c2416_irq_lcd_unmask(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900118{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900119 s3c_irqsub_unmask(data->irq, INTMSK_LCD);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900120}
121
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900122static void s3c2416_irq_lcd_ack(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900123{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900124 s3c_irqsub_maskack(data->irq, INTMSK_LCD, SUBMSK_LCD);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900125}
126
127static struct irq_chip s3c2416_irq_lcd = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900128 .irq_mask = s3c2416_irq_lcd_mask,
129 .irq_unmask = s3c2416_irq_lcd_unmask,
130 .irq_ack = s3c2416_irq_lcd_ack,
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900131};
132
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900133/* DMA sub interrupts */
134
135static void s3c2416_irq_demux_dma(unsigned int irq, struct irq_desc *desc)
136{
137 s3c2416_irq_demux(IRQ_S3C2443_DMA0, 6);
138}
139
140#define INTMSK_DMA (1UL << (IRQ_S3C2443_DMA - IRQ_EINT0))
141#define SUBMSK_DMA INTMSK(IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5)
142
143
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900144static void s3c2416_irq_dma_mask(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900145{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900146 s3c_irqsub_mask(data->irq, INTMSK_DMA, SUBMSK_DMA);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900147}
148
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900149static void s3c2416_irq_dma_unmask(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900150{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900151 s3c_irqsub_unmask(data->irq, INTMSK_DMA);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900152}
153
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900154static void s3c2416_irq_dma_ack(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900155{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900156 s3c_irqsub_maskack(data->irq, INTMSK_DMA, SUBMSK_DMA);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900157}
158
159static struct irq_chip s3c2416_irq_dma = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900160 .irq_mask = s3c2416_irq_dma_mask,
161 .irq_unmask = s3c2416_irq_dma_unmask,
162 .irq_ack = s3c2416_irq_dma_ack,
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900163};
164
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900165/* UART3 sub interrupts */
166
167static void s3c2416_irq_demux_uart3(unsigned int irq, struct irq_desc *desc)
168{
Abhilash Kesavan18ad7822010-10-21 06:45:48 +0530169 s3c2416_irq_demux(IRQ_S3C2443_RX3, 3);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900170}
171
172#define INTMSK_UART3 (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0))
Abhilash Kesavan35bbcfe2010-10-21 06:45:48 +0530173#define SUBMSK_UART3 (0x7 << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0)))
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900174
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900175static void s3c2416_irq_uart3_mask(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900176{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900177 s3c_irqsub_mask(data->irq, INTMSK_UART3, SUBMSK_UART3);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900178}
179
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900180static void s3c2416_irq_uart3_unmask(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900181{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900182 s3c_irqsub_unmask(data->irq, INTMSK_UART3);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900183}
184
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900185static void s3c2416_irq_uart3_ack(struct irq_data *data)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900186{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900187 s3c_irqsub_maskack(data->irq, INTMSK_UART3, SUBMSK_UART3);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900188}
189
190static struct irq_chip s3c2416_irq_uart3 = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900191 .irq_mask = s3c2416_irq_uart3_mask,
192 .irq_unmask = s3c2416_irq_uart3_unmask,
193 .irq_ack = s3c2416_irq_uart3_ack,
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900194};
195
Heiko Stuebner0e944e22012-05-20 01:01:35 +0900196/* second interrupt register */
197
198static inline void s3c2416_irq_ack_second(struct irq_data *data)
199{
200 unsigned long bitval = 1UL << (data->irq - IRQ_S3C2416_2D);
201
202 __raw_writel(bitval, S3C2416_SRCPND2);
203 __raw_writel(bitval, S3C2416_INTPND2);
204}
205
206static void s3c2416_irq_mask_second(struct irq_data *data)
207{
208 unsigned long bitval = 1UL << (data->irq - IRQ_S3C2416_2D);
209 unsigned long mask;
210
211 mask = __raw_readl(S3C2416_INTMSK2);
212 mask |= bitval;
213 __raw_writel(mask, S3C2416_INTMSK2);
214}
215
216static void s3c2416_irq_unmask_second(struct irq_data *data)
217{
218 unsigned long bitval = 1UL << (data->irq - IRQ_S3C2416_2D);
219 unsigned long mask;
220
221 mask = __raw_readl(S3C2416_INTMSK2);
222 mask &= ~bitval;
223 __raw_writel(mask, S3C2416_INTMSK2);
224}
225
226struct 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,
230};
231
232
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900233/* IRQ initialisation code */
234
Arnd Bergmann673550a2012-05-27 02:42:12 +0000235static int s3c2416_add_sub(unsigned int base,
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900236 void (*demux)(unsigned int,
237 struct irq_desc *),
238 struct irq_chip *chip,
239 unsigned int start, unsigned int end)
240{
241 unsigned int irqno;
242
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100243 irq_set_chip_and_handler(base, &s3c_irq_level_chip, handle_level_irq);
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100244 irq_set_chained_handler(base, demux);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900245
246 for (irqno = start; irqno <= end; irqno++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100247 irq_set_chip_and_handler(irqno, chip, handle_level_irq);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900248 set_irq_flags(irqno, IRQF_VALID);
249 }
250
251 return 0;
252}
253
Arnd Bergmann673550a2012-05-27 02:42:12 +0000254static void s3c2416_irq_add_second(void)
Heiko Stuebner0e944e22012-05-20 01:01:35 +0900255{
256 unsigned long pend;
257 unsigned long last;
258 int irqno;
259 int i;
260
261 /* first, clear all interrupts pending... */
262 last = 0;
263 for (i = 0; i < 4; i++) {
264 pend = __raw_readl(S3C2416_INTPND2);
265
266 if (pend == 0 || pend == last)
267 break;
268
269 __raw_writel(pend, S3C2416_SRCPND2);
270 __raw_writel(pend, S3C2416_INTPND2);
271 printk(KERN_INFO "irq: clearing pending status %08x\n",
272 (int)pend);
273 last = pend;
274 }
275
276 for (irqno = IRQ_S3C2416_2D; irqno <= IRQ_S3C2416_I2S1; irqno++) {
277 switch (irqno) {
278 case IRQ_S3C2416_RESERVED2:
279 case IRQ_S3C2416_RESERVED3:
280 /* no IRQ here */
281 break;
282 default:
283 irq_set_chip_and_handler(irqno, &s3c2416_irq_second,
284 handle_edge_irq);
285 set_irq_flags(irqno, IRQF_VALID);
286 }
287 }
288}
289
Arnd Bergmann673550a2012-05-27 02:42:12 +0000290static int s3c2416_irq_add(struct device *dev,
Heiko Stuebner04511a62012-01-27 15:35:25 +0900291 struct subsys_interface *sif)
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900292{
293 printk(KERN_INFO "S3C2416: IRQ Support\n");
294
295 s3c2416_add_sub(IRQ_LCD, s3c2416_irq_demux_lcd, &s3c2416_irq_lcd,
296 IRQ_S3C2443_LCD2, IRQ_S3C2443_LCD4);
297
298 s3c2416_add_sub(IRQ_S3C2443_DMA, s3c2416_irq_demux_dma,
299 &s3c2416_irq_dma, IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5);
300
301 s3c2416_add_sub(IRQ_S3C2443_UART3, s3c2416_irq_demux_uart3,
302 &s3c2416_irq_uart3,
303 IRQ_S3C2443_RX3, IRQ_S3C2443_ERR3);
304
305 s3c2416_add_sub(IRQ_WDT, s3c2416_irq_demux_wdtac97,
306 &s3c2416_irq_wdtac97,
307 IRQ_S3C2443_WDT, IRQ_S3C2443_AC97);
308
Heiko Stuebner0e944e22012-05-20 01:01:35 +0900309 s3c2416_irq_add_second();
310
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900311 return 0;
312}
313
Kay Sievers4a858cf2011-12-21 16:01:38 -0800314static struct subsys_interface s3c2416_irq_interface = {
315 .name = "s3c2416_irq",
316 .subsys = &s3c2416_subsys,
317 .add_dev = s3c2416_irq_add,
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900318};
319
320static int __init s3c2416_irq_init(void)
321{
Kay Sievers4a858cf2011-12-21 16:01:38 -0800322 return subsys_interface_register(&s3c2416_irq_interface);
Yauhen Kharuzhyf1290a42010-04-28 18:09:01 +0900323}
324
325arch_initcall(s3c2416_irq_init);
326
Heiko Stuebner0e944e22012-05-20 01:01:35 +0900327#ifdef CONFIG_PM
328static struct sleep_save irq_save[] = {
329 SAVE_ITEM(S3C2416_INTMSK2),
330};
331
332int s3c2416_irq_suspend(void)
333{
334 s3c_pm_do_save(irq_save, ARRAY_SIZE(irq_save));
335
336 return 0;
337}
338
339void s3c2416_irq_resume(void)
340{
341 s3c_pm_do_restore(irq_save, ARRAY_SIZE(irq_save));
342}
343
344struct syscore_ops s3c2416_irq_syscore_ops = {
345 .suspend = s3c2416_irq_suspend,
346 .resume = s3c2416_irq_resume,
347};
348#endif