blob: c7820f9c135231105c08a50f2b58cb1d4115a588 [file] [log] [blame]
Ben Dookse4d06e32007-02-16 12:12:31 +01001/* linux/arch/arm/mach-s3c2443/irq.c
2 *
3 * Copyright (c) 2007 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>
Ben Dookse4d06e32007-02-16 12:12:31 +010026#include <linux/sysdev.h>
Russell Kingfced80c2008-09-06 12:10:45 +010027#include <linux/io.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010028
Russell Kinga09e64f2008-08-05 16:14:15 +010029#include <mach/hardware.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010030#include <asm/irq.h>
Ben Dookse4d06e32007-02-16 12:12:31 +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 Dookse4d06e32007-02-16 12:12:31 +010036
Ben Dooksa2b7ba92008-10-07 22:26:09 +010037#include <plat/cpu.h>
38#include <plat/pm.h>
39#include <plat/irq.h>
Ben Dookse4d06e32007-02-16 12:12:31 +010040
Ben Dooks72262e82007-02-16 13:02:42 +010041#define INTMSK(start, end) ((1 << ((end) + 1 - (start))) - 1)
Ben Dookse4d06e32007-02-16 12:12:31 +010042
Ben Dooks72262e82007-02-16 13:02:42 +010043static inline void s3c2443_irq_demux(unsigned int irq, unsigned int len)
Ben Dookse4d06e32007-02-16 12:12:31 +010044{
45 unsigned int subsrc, submsk;
Ben Dooks72262e82007-02-16 13:02:42 +010046 unsigned int end;
Ben Dookse4d06e32007-02-16 12:12:31 +010047
48 /* read the current pending interrupts, and the mask
49 * for what it is available */
50
51 subsrc = __raw_readl(S3C2410_SUBSRCPND);
52 submsk = __raw_readl(S3C2410_INTSUBMSK);
53
Ben Dooks72262e82007-02-16 13:02:42 +010054 subsrc &= ~submsk;
55 subsrc >>= (irq - S3C2410_IRQSUB(0));
56 subsrc &= (1 << len)-1;
Ben Dookse4d06e32007-02-16 12:12:31 +010057
Ben Dooks72262e82007-02-16 13:02:42 +010058 end = len + irq;
Ben Dooks72262e82007-02-16 13:02:42 +010059
60 for (; irq < end && subsrc; irq++) {
61 if (subsrc & 1)
Dmitry Baryshkovd8aa0252008-10-09 13:36:24 +010062 generic_handle_irq(irq);
Ben Dooks72262e82007-02-16 13:02:42 +010063
Ben Dooks72262e82007-02-16 13:02:42 +010064 subsrc >>= 1;
Ben Dookse4d06e32007-02-16 12:12:31 +010065 }
66}
67
Ben Dooks72262e82007-02-16 13:02:42 +010068/* WDT/AC97 sub interrupts */
Ben Dookse4d06e32007-02-16 12:12:31 +010069
Ben Dooks72262e82007-02-16 13:02:42 +010070static void s3c2443_irq_demux_wdtac97(unsigned int irq, struct irq_desc *desc)
Ben Dookse4d06e32007-02-16 12:12:31 +010071{
Ben Dooks72262e82007-02-16 13:02:42 +010072 s3c2443_irq_demux(IRQ_S3C2443_WDT, 4);
Ben Dookse4d06e32007-02-16 12:12:31 +010073}
74
Ben Dooks72262e82007-02-16 13:02:42 +010075#define INTMSK_WDTAC97 (1UL << (IRQ_WDT - IRQ_EINT0))
76#define SUBMSK_WDTAC97 INTMSK(IRQ_S3C2443_WDT, IRQ_S3C2443_AC97)
77
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090078static void s3c2443_irq_wdtac97_mask(struct irq_data *data)
Ben Dookse4d06e32007-02-16 12:12:31 +010079{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090080 s3c_irqsub_mask(data->irq, INTMSK_WDTAC97, SUBMSK_WDTAC97);
Ben Dookse4d06e32007-02-16 12:12:31 +010081}
82
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090083static void s3c2443_irq_wdtac97_unmask(struct irq_data *data)
Ben Dookse4d06e32007-02-16 12:12:31 +010084{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090085 s3c_irqsub_unmask(data->irq, INTMSK_WDTAC97);
Ben Dookse4d06e32007-02-16 12:12:31 +010086}
87
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090088static void s3c2443_irq_wdtac97_ack(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +010089{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090090 s3c_irqsub_maskack(data->irq, INTMSK_WDTAC97, SUBMSK_WDTAC97);
Ben Dooks72262e82007-02-16 13:02:42 +010091}
92
93static struct irq_chip s3c2443_irq_wdtac97 = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +090094 .irq_mask = s3c2443_irq_wdtac97_mask,
95 .irq_unmask = s3c2443_irq_wdtac97_unmask,
96 .irq_ack = s3c2443_irq_wdtac97_ack,
Ben Dookse4d06e32007-02-16 12:12:31 +010097};
98
Ben Dooks72262e82007-02-16 13:02:42 +010099/* LCD sub interrupts */
100
101static void s3c2443_irq_demux_lcd(unsigned int irq, struct irq_desc *desc)
102{
103 s3c2443_irq_demux(IRQ_S3C2443_LCD1, 4);
104}
105
106#define INTMSK_LCD (1UL << (IRQ_LCD - IRQ_EINT0))
107#define SUBMSK_LCD INTMSK(IRQ_S3C2443_LCD1, IRQ_S3C2443_LCD4)
108
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900109static void s3c2443_irq_lcd_mask(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100110{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900111 s3c_irqsub_mask(data->irq, INTMSK_LCD, SUBMSK_LCD);
Ben Dooks72262e82007-02-16 13:02:42 +0100112}
113
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900114static void s3c2443_irq_lcd_unmask(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100115{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900116 s3c_irqsub_unmask(data->irq, INTMSK_LCD);
Ben Dooks72262e82007-02-16 13:02:42 +0100117}
118
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900119static void s3c2443_irq_lcd_ack(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100120{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900121 s3c_irqsub_maskack(data->irq, INTMSK_LCD, SUBMSK_LCD);
Ben Dooks72262e82007-02-16 13:02:42 +0100122}
123
124static struct irq_chip s3c2443_irq_lcd = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900125 .irq_mask = s3c2443_irq_lcd_mask,
126 .irq_unmask = s3c2443_irq_lcd_unmask,
127 .irq_ack = s3c2443_irq_lcd_ack,
Ben Dooks72262e82007-02-16 13:02:42 +0100128};
129
Ben Dooks72262e82007-02-16 13:02:42 +0100130/* DMA sub interrupts */
131
132static void s3c2443_irq_demux_dma(unsigned int irq, struct irq_desc *desc)
133{
Graeme Gregory5455a512007-03-16 17:11:43 +0100134 s3c2443_irq_demux(IRQ_S3C2443_DMA0, 6);
Ben Dooks72262e82007-02-16 13:02:42 +0100135}
136
137#define INTMSK_DMA (1UL << (IRQ_S3C2443_DMA - IRQ_EINT0))
138#define SUBMSK_DMA INTMSK(IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5)
139
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900140static void s3c2443_irq_dma_mask(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100141{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900142 s3c_irqsub_mask(data->irq, INTMSK_DMA, SUBMSK_DMA);
Ben Dooks72262e82007-02-16 13:02:42 +0100143}
144
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900145static void s3c2443_irq_dma_unmask(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100146{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900147 s3c_irqsub_unmask(data->irq, INTMSK_DMA);
Ben Dooks72262e82007-02-16 13:02:42 +0100148}
149
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900150static void s3c2443_irq_dma_ack(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100151{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900152 s3c_irqsub_maskack(data->irq, INTMSK_DMA, SUBMSK_DMA);
Ben Dooks72262e82007-02-16 13:02:42 +0100153}
154
155static struct irq_chip s3c2443_irq_dma = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900156 .irq_mask = s3c2443_irq_dma_mask,
157 .irq_unmask = s3c2443_irq_dma_unmask,
158 .irq_ack = s3c2443_irq_dma_ack,
Ben Dooks72262e82007-02-16 13:02:42 +0100159};
160
Ben Dooks72262e82007-02-16 13:02:42 +0100161/* UART3 sub interrupts */
162
163static void s3c2443_irq_demux_uart3(unsigned int irq, struct irq_desc *desc)
164{
Abhilash Kesavan18ad7822010-10-21 06:45:48 +0530165 s3c2443_irq_demux(IRQ_S3C2443_RX3, 3);
Ben Dooks72262e82007-02-16 13:02:42 +0100166}
167
168#define INTMSK_UART3 (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0))
Abhilash Kesavan35bbcfe2010-10-21 06:45:48 +0530169#define SUBMSK_UART3 (0x7 << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0)))
Ben Dooks72262e82007-02-16 13:02:42 +0100170
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900171static void s3c2443_irq_uart3_mask(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100172{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900173 s3c_irqsub_mask(data->irq, INTMSK_UART3, SUBMSK_UART3);
Ben Dooks72262e82007-02-16 13:02:42 +0100174}
175
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900176static void s3c2443_irq_uart3_unmask(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100177{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900178 s3c_irqsub_unmask(data->irq, INTMSK_UART3);
Ben Dooks72262e82007-02-16 13:02:42 +0100179}
180
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900181static void s3c2443_irq_uart3_ack(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100182{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900183 s3c_irqsub_maskack(data->irq, INTMSK_UART3, SUBMSK_UART3);
Ben Dooks72262e82007-02-16 13:02:42 +0100184}
185
186static struct irq_chip s3c2443_irq_uart3 = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900187 .irq_mask = s3c2443_irq_uart3_mask,
188 .irq_unmask = s3c2443_irq_uart3_unmask,
189 .irq_ack = s3c2443_irq_uart3_ack,
Ben Dooks72262e82007-02-16 13:02:42 +0100190};
191
Ben Dooks72262e82007-02-16 13:02:42 +0100192/* CAM sub interrupts */
193
194static void s3c2443_irq_demux_cam(unsigned int irq, struct irq_desc *desc)
195{
196 s3c2443_irq_demux(IRQ_S3C2440_CAM_C, 4);
197}
198
199#define INTMSK_CAM (1UL << (IRQ_CAM - IRQ_EINT0))
200#define SUBMSK_CAM INTMSK(IRQ_S3C2440_CAM_C, IRQ_S3C2440_CAM_P)
201
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900202static void s3c2443_irq_cam_mask(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100203{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900204 s3c_irqsub_mask(data->irq, INTMSK_CAM, SUBMSK_CAM);
Ben Dooks72262e82007-02-16 13:02:42 +0100205}
206
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900207static void s3c2443_irq_cam_unmask(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100208{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900209 s3c_irqsub_unmask(data->irq, INTMSK_CAM);
Ben Dooks72262e82007-02-16 13:02:42 +0100210}
211
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900212static void s3c2443_irq_cam_ack(struct irq_data *data)
Ben Dooks72262e82007-02-16 13:02:42 +0100213{
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900214 s3c_irqsub_maskack(data->irq, INTMSK_CAM, SUBMSK_CAM);
Ben Dooks72262e82007-02-16 13:02:42 +0100215}
216
217static struct irq_chip s3c2443_irq_cam = {
Lennert Buytenhek57436c2d2011-01-03 19:15:54 +0900218 .irq_mask = s3c2443_irq_cam_mask,
219 .irq_unmask = s3c2443_irq_cam_unmask,
220 .irq_ack = s3c2443_irq_cam_ack,
Ben Dooks72262e82007-02-16 13:02:42 +0100221};
222
223/* IRQ initialisation code */
224
225static int __init s3c2443_add_sub(unsigned int base,
226 void (*demux)(unsigned int,
227 struct irq_desc *),
228 struct irq_chip *chip,
229 unsigned int start, unsigned int end)
Ben Dookse4d06e32007-02-16 12:12:31 +0100230{
231 unsigned int irqno;
232
Ben Dooks72262e82007-02-16 13:02:42 +0100233 set_irq_chip(base, &s3c_irq_level_chip);
234 set_irq_handler(base, handle_level_irq);
235 set_irq_chained_handler(base, demux);
Ben Dookse4d06e32007-02-16 12:12:31 +0100236
Ben Dooks72262e82007-02-16 13:02:42 +0100237 for (irqno = start; irqno <= end; irqno++) {
238 set_irq_chip(irqno, chip);
Ben Dookse4d06e32007-02-16 12:12:31 +0100239 set_irq_handler(irqno, handle_level_irq);
240 set_irq_flags(irqno, IRQF_VALID);
241 }
242
243 return 0;
244}
245
Krzysztof Helt008d9312007-09-04 17:18:04 +0100246static int __init s3c2443_irq_add(struct sys_device *sysdev)
Ben Dooks72262e82007-02-16 13:02:42 +0100247{
248 printk("S3C2443: IRQ Support\n");
249
250 s3c2443_add_sub(IRQ_CAM, s3c2443_irq_demux_cam, &s3c2443_irq_cam,
251 IRQ_S3C2440_CAM_C, IRQ_S3C2440_CAM_P);
252
253 s3c2443_add_sub(IRQ_LCD, s3c2443_irq_demux_lcd, &s3c2443_irq_lcd,
254 IRQ_S3C2443_LCD1, IRQ_S3C2443_LCD4);
255
256 s3c2443_add_sub(IRQ_S3C2443_DMA, s3c2443_irq_demux_dma,
257 &s3c2443_irq_dma, IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5);
258
259 s3c2443_add_sub(IRQ_S3C2443_UART3, s3c2443_irq_demux_uart3,
260 &s3c2443_irq_uart3,
261 IRQ_S3C2443_RX3, IRQ_S3C2443_ERR3);
262
263 s3c2443_add_sub(IRQ_WDT, s3c2443_irq_demux_wdtac97,
264 &s3c2443_irq_wdtac97,
265 IRQ_S3C2443_WDT, IRQ_S3C2443_AC97);
266
267 return 0;
268}
269
Ben Dookse4d06e32007-02-16 12:12:31 +0100270static struct sysdev_driver s3c2443_irq_driver = {
271 .add = s3c2443_irq_add,
272};
273
Krzysztof Helt008d9312007-09-04 17:18:04 +0100274static int __init s3c2443_irq_init(void)
Ben Dookse4d06e32007-02-16 12:12:31 +0100275{
276 return sysdev_driver_register(&s3c2443_sysclass, &s3c2443_irq_driver);
277}
278
279arch_initcall(s3c2443_irq_init);
280