blob: 67d763178d3f98fe8c79d9ad7249cbca80a90da9 [file] [log] [blame]
Ben Dooksa21765a2007-02-11 18:31:01 +01001/* linux/arch/arm/mach-s3c2412/irq.c
Ben Dooksc6e58eb2006-09-09 21:24:13 +01002 *
3 * Copyright (c) 2006 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
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.
10 *
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.
15 *
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
19 *
20*/
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/interrupt.h>
25#include <linux/ioport.h>
Kay Sievers4a858cf2011-12-21 16:01:38 -080026#include <linux/device.h>
Russell Kingfced80c2008-09-06 12:10:45 +010027#include <linux/io.h>
Ben Dooksc6e58eb2006-09-09 21:24:13 +010028
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/hardware.h>
Ben Dooksc6e58eb2006-09-09 21:24:13 +010030#include <asm/irq.h>
Ben Dooksc6e58eb2006-09-09 21:24:13 +010031
32#include <asm/mach/irq.h>
33
Russell Kinga09e64f2008-08-05 16:14:15 +010034#include <mach/regs-irq.h>
35#include <mach/regs-gpio.h>
Ben Dooksc6e58eb2006-09-09 21:24:13 +010036
Ben Dooksa2b7ba92008-10-07 22:26:09 +010037#include <plat/cpu.h>
38#include <plat/irq.h>
39#include <plat/pm.h>
Ben Dooksc6e58eb2006-09-09 21:24:13 +010040
Kukjin Kim14cce0e2013-02-01 21:49:35 -080041#include "s3c2412-power.h"
42
Ben Dooksf3fb5a52007-10-04 21:41:20 +010043#define INTMSK(start, end) ((1 << ((end) + 1 - (start))) - 1)
44#define INTMSK_SUB(start, end) (INTMSK(start, end) << ((start - S3C2410_IRQSUB(0))))
45
Ben Dooksc6e58eb2006-09-09 21:24:13 +010046/* the s3c2412 changes the behaviour of IRQ_EINT0 through IRQ_EINT3 by
47 * having them turn up in both the INT* and the EINT* registers. Whilst
48 * both show the status, they both now need to be acked when the IRQs
49 * go off.
50*/
51
52static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090053s3c2412_irq_mask(struct irq_data *data)
Ben Dooksc6e58eb2006-09-09 21:24:13 +010054{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090055 unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
Ben Dooksc6e58eb2006-09-09 21:24:13 +010056 unsigned long mask;
57
58 mask = __raw_readl(S3C2410_INTMSK);
59 __raw_writel(mask | bitval, S3C2410_INTMSK);
60
61 mask = __raw_readl(S3C2412_EINTMASK);
62 __raw_writel(mask | bitval, S3C2412_EINTMASK);
63}
64
65static inline void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090066s3c2412_irq_ack(struct irq_data *data)
Ben Dooksc6e58eb2006-09-09 21:24:13 +010067{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090068 unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
Ben Dooksc6e58eb2006-09-09 21:24:13 +010069
70 __raw_writel(bitval, S3C2412_EINTPEND);
71 __raw_writel(bitval, S3C2410_SRCPND);
72 __raw_writel(bitval, S3C2410_INTPND);
73}
74
75static inline void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090076s3c2412_irq_maskack(struct irq_data *data)
Ben Dooksc6e58eb2006-09-09 21:24:13 +010077{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090078 unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
Ben Dooksc6e58eb2006-09-09 21:24:13 +010079 unsigned long mask;
80
81 mask = __raw_readl(S3C2410_INTMSK);
82 __raw_writel(mask|bitval, S3C2410_INTMSK);
83
84 mask = __raw_readl(S3C2412_EINTMASK);
85 __raw_writel(mask | bitval, S3C2412_EINTMASK);
86
87 __raw_writel(bitval, S3C2412_EINTPEND);
88 __raw_writel(bitval, S3C2410_SRCPND);
89 __raw_writel(bitval, S3C2410_INTPND);
90}
91
92static void
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090093s3c2412_irq_unmask(struct irq_data *data)
Ben Dooksc6e58eb2006-09-09 21:24:13 +010094{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090095 unsigned long bitval = 1UL << (data->irq - IRQ_EINT0);
Ben Dooksc6e58eb2006-09-09 21:24:13 +010096 unsigned long mask;
97
98 mask = __raw_readl(S3C2412_EINTMASK);
99 __raw_writel(mask & ~bitval, S3C2412_EINTMASK);
100
101 mask = __raw_readl(S3C2410_INTMSK);
102 __raw_writel(mask & ~bitval, S3C2410_INTMSK);
103}
104
Russell King10dd5ce2006-11-23 11:41:32 +0000105static struct irq_chip s3c2412_irq_eint0t4 = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900106 .irq_ack = s3c2412_irq_ack,
107 .irq_mask = s3c2412_irq_mask,
108 .irq_unmask = s3c2412_irq_unmask,
109 .irq_set_wake = s3c_irq_wake,
110 .irq_set_type = s3c_irqext_type,
Ben Dooksc6e58eb2006-09-09 21:24:13 +0100111};
112
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100113#define INTBIT(x) (1 << ((x) - S3C2410_IRQSUB(0)))
114
115/* CF and SDI sub interrupts */
116
117static void s3c2412_irq_demux_cfsdi(unsigned int irq, struct irq_desc *desc)
118{
119 unsigned int subsrc, submsk;
120
121 subsrc = __raw_readl(S3C2410_SUBSRCPND);
122 submsk = __raw_readl(S3C2410_INTSUBMSK);
123
124 subsrc &= ~submsk;
125
126 if (subsrc & INTBIT(IRQ_S3C2412_SDI))
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100127 generic_handle_irq(IRQ_S3C2412_SDI);
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100128
129 if (subsrc & INTBIT(IRQ_S3C2412_CF))
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +0100130 generic_handle_irq(IRQ_S3C2412_CF);
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100131}
132
133#define INTMSK_CFSDI (1UL << (IRQ_S3C2412_CFSDI - IRQ_EINT0))
134#define SUBMSK_CFSDI INTMSK_SUB(IRQ_S3C2412_SDI, IRQ_S3C2412_CF)
135
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900136static void s3c2412_irq_cfsdi_mask(struct irq_data *data)
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100137{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900138 s3c_irqsub_mask(data->irq, INTMSK_CFSDI, SUBMSK_CFSDI);
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100139}
140
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900141static void s3c2412_irq_cfsdi_unmask(struct irq_data *data)
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100142{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900143 s3c_irqsub_unmask(data->irq, INTMSK_CFSDI);
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100144}
145
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900146static void s3c2412_irq_cfsdi_ack(struct irq_data *data)
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100147{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900148 s3c_irqsub_maskack(data->irq, INTMSK_CFSDI, SUBMSK_CFSDI);
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100149}
150
151static struct irq_chip s3c2412_irq_cfsdi = {
152 .name = "s3c2412-cfsdi",
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900153 .irq_ack = s3c2412_irq_cfsdi_ack,
154 .irq_mask = s3c2412_irq_cfsdi_mask,
155 .irq_unmask = s3c2412_irq_cfsdi_unmask,
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100156};
157
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900158static int s3c2412_irq_rtc_wake(struct irq_data *data, unsigned int state)
Ben Dooks0baada22007-12-23 03:09:33 +0100159{
160 unsigned long pwrcfg;
161
162 pwrcfg = __raw_readl(S3C2412_PWRCFG);
163 if (state)
164 pwrcfg &= ~S3C2412_PWRCFG_RTC_MASKIRQ;
165 else
166 pwrcfg |= S3C2412_PWRCFG_RTC_MASKIRQ;
167 __raw_writel(pwrcfg, S3C2412_PWRCFG);
168
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900169 return s3c_irq_chip.irq_set_wake(data, state);
Ben Dooks0baada22007-12-23 03:09:33 +0100170}
171
172static struct irq_chip s3c2412_irq_rtc_chip;
173
Heiko Stuebner04511a62012-01-27 15:35:25 +0900174static int s3c2412_irq_add(struct device *dev, struct subsys_interface *sif)
Ben Dooksc6e58eb2006-09-09 21:24:13 +0100175{
176 unsigned int irqno;
177
178 for (irqno = IRQ_EINT0; irqno <= IRQ_EINT3; irqno++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100179 irq_set_chip_and_handler(irqno, &s3c2412_irq_eint0t4,
180 handle_edge_irq);
Ben Dooksc6e58eb2006-09-09 21:24:13 +0100181 set_irq_flags(irqno, IRQF_VALID);
182 }
183
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100184 /* add demux support for CF/SDI */
185
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100186 irq_set_chained_handler(IRQ_S3C2412_CFSDI, s3c2412_irq_demux_cfsdi);
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100187
188 for (irqno = IRQ_S3C2412_SDI; irqno <= IRQ_S3C2412_CF; irqno++) {
Thomas Gleixnerf38c02f2011-03-24 13:35:09 +0100189 irq_set_chip_and_handler(irqno, &s3c2412_irq_cfsdi,
190 handle_level_irq);
Ben Dooksf3fb5a52007-10-04 21:41:20 +0100191 set_irq_flags(irqno, IRQF_VALID);
192 }
193
Ben Dooks0baada22007-12-23 03:09:33 +0100194 /* change RTC IRQ's set wake method */
195
196 s3c2412_irq_rtc_chip = s3c_irq_chip;
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900197 s3c2412_irq_rtc_chip.irq_set_wake = s3c2412_irq_rtc_wake;
Ben Dooks0baada22007-12-23 03:09:33 +0100198
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100199 irq_set_chip(IRQ_RTC, &s3c2412_irq_rtc_chip);
Ben Dooks0baada22007-12-23 03:09:33 +0100200
Ben Dooksc6e58eb2006-09-09 21:24:13 +0100201 return 0;
202}
203
Kay Sievers4a858cf2011-12-21 16:01:38 -0800204static struct subsys_interface s3c2412_irq_interface = {
205 .name = "s3c2412_irq",
206 .subsys = &s3c2412_subsys,
207 .add_dev = s3c2412_irq_add,
Ben Dooksc6e58eb2006-09-09 21:24:13 +0100208};
209
210static int s3c2412_irq_init(void)
211{
Kay Sievers4a858cf2011-12-21 16:01:38 -0800212 return subsys_interface_register(&s3c2412_irq_interface);
Ben Dooksc6e58eb2006-09-09 21:24:13 +0100213}
214
215arch_initcall(s3c2412_irq_init);