blob: e44341d7dfef91189ad960cbcc8264357879eecd [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
37#include <asm/plat-s3c24xx/cpu.h>
38#include <asm/plat-s3c24xx/pm.h>
39#include <asm/plat-s3c24xx/irq.h>
40
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
78static void s3c2443_irq_wdtac97_mask(unsigned int irqno)
Ben Dookse4d06e32007-02-16 12:12:31 +010079{
Ben Dooks72262e82007-02-16 13:02:42 +010080 s3c_irqsub_mask(irqno, INTMSK_WDTAC97, SUBMSK_WDTAC97);
Ben Dookse4d06e32007-02-16 12:12:31 +010081}
82
Ben Dooks72262e82007-02-16 13:02:42 +010083static void s3c2443_irq_wdtac97_unmask(unsigned int irqno)
Ben Dookse4d06e32007-02-16 12:12:31 +010084{
Ben Dooks72262e82007-02-16 13:02:42 +010085 s3c_irqsub_unmask(irqno, INTMSK_WDTAC97);
Ben Dookse4d06e32007-02-16 12:12:31 +010086}
87
Ben Dooks72262e82007-02-16 13:02:42 +010088static void s3c2443_irq_wdtac97_ack(unsigned int irqno)
89{
90 s3c_irqsub_maskack(irqno, INTMSK_WDTAC97, SUBMSK_WDTAC97);
91}
92
93static struct irq_chip s3c2443_irq_wdtac97 = {
94 .mask = s3c2443_irq_wdtac97_mask,
95 .unmask = s3c2443_irq_wdtac97_unmask,
96 .ack = s3c2443_irq_wdtac97_ack,
Ben Dookse4d06e32007-02-16 12:12:31 +010097};
98
Ben Dooks72262e82007-02-16 13:02:42 +010099
100/* LCD sub interrupts */
101
102static void s3c2443_irq_demux_lcd(unsigned int irq, struct irq_desc *desc)
103{
104 s3c2443_irq_demux(IRQ_S3C2443_LCD1, 4);
105}
106
107#define INTMSK_LCD (1UL << (IRQ_LCD - IRQ_EINT0))
108#define SUBMSK_LCD INTMSK(IRQ_S3C2443_LCD1, IRQ_S3C2443_LCD4)
109
110static void s3c2443_irq_lcd_mask(unsigned int irqno)
111{
112 s3c_irqsub_mask(irqno, INTMSK_LCD, SUBMSK_LCD);
113}
114
115static void s3c2443_irq_lcd_unmask(unsigned int irqno)
116{
117 s3c_irqsub_unmask(irqno, INTMSK_LCD);
118}
119
120static void s3c2443_irq_lcd_ack(unsigned int irqno)
121{
122 s3c_irqsub_maskack(irqno, INTMSK_LCD, SUBMSK_LCD);
123}
124
125static struct irq_chip s3c2443_irq_lcd = {
126 .mask = s3c2443_irq_lcd_mask,
127 .unmask = s3c2443_irq_lcd_unmask,
128 .ack = s3c2443_irq_lcd_ack,
129};
130
131
132/* DMA sub interrupts */
133
134static void s3c2443_irq_demux_dma(unsigned int irq, struct irq_desc *desc)
135{
Graeme Gregory5455a512007-03-16 17:11:43 +0100136 s3c2443_irq_demux(IRQ_S3C2443_DMA0, 6);
Ben Dooks72262e82007-02-16 13:02:42 +0100137}
138
139#define INTMSK_DMA (1UL << (IRQ_S3C2443_DMA - IRQ_EINT0))
140#define SUBMSK_DMA INTMSK(IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5)
141
142
143static void s3c2443_irq_dma_mask(unsigned int irqno)
144{
145 s3c_irqsub_mask(irqno, INTMSK_DMA, SUBMSK_DMA);
146}
147
148static void s3c2443_irq_dma_unmask(unsigned int irqno)
149{
150 s3c_irqsub_unmask(irqno, INTMSK_DMA);
151}
152
153static void s3c2443_irq_dma_ack(unsigned int irqno)
154{
155 s3c_irqsub_maskack(irqno, INTMSK_DMA, SUBMSK_DMA);
156}
157
158static struct irq_chip s3c2443_irq_dma = {
159 .mask = s3c2443_irq_dma_mask,
160 .unmask = s3c2443_irq_dma_unmask,
161 .ack = s3c2443_irq_dma_ack,
162};
163
164
165/* UART3 sub interrupts */
166
167static void s3c2443_irq_demux_uart3(unsigned int irq, struct irq_desc *desc)
168{
169 s3c2443_irq_demux(IRQ_S3C2443_UART3, 3);
170}
171
172#define INTMSK_UART3 (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0))
173#define SUBMSK_UART3 (0xf << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0)))
174
175
176static void s3c2443_irq_uart3_mask(unsigned int irqno)
177{
178 s3c_irqsub_mask(irqno, INTMSK_UART3, SUBMSK_UART3);
179}
180
181static void s3c2443_irq_uart3_unmask(unsigned int irqno)
182{
183 s3c_irqsub_unmask(irqno, INTMSK_UART3);
184}
185
186static void s3c2443_irq_uart3_ack(unsigned int irqno)
187{
188 s3c_irqsub_maskack(irqno, INTMSK_UART3, SUBMSK_UART3);
189}
190
191static struct irq_chip s3c2443_irq_uart3 = {
192 .mask = s3c2443_irq_uart3_mask,
193 .unmask = s3c2443_irq_uart3_unmask,
194 .ack = s3c2443_irq_uart3_ack,
195};
196
197
198/* CAM sub interrupts */
199
200static void s3c2443_irq_demux_cam(unsigned int irq, struct irq_desc *desc)
201{
202 s3c2443_irq_demux(IRQ_S3C2440_CAM_C, 4);
203}
204
205#define INTMSK_CAM (1UL << (IRQ_CAM - IRQ_EINT0))
206#define SUBMSK_CAM INTMSK(IRQ_S3C2440_CAM_C, IRQ_S3C2440_CAM_P)
207
208static void s3c2443_irq_cam_mask(unsigned int irqno)
209{
210 s3c_irqsub_mask(irqno, INTMSK_CAM, SUBMSK_CAM);
211}
212
213static void s3c2443_irq_cam_unmask(unsigned int irqno)
214{
215 s3c_irqsub_unmask(irqno, INTMSK_CAM);
216}
217
218static void s3c2443_irq_cam_ack(unsigned int irqno)
219{
220 s3c_irqsub_maskack(irqno, INTMSK_CAM, SUBMSK_CAM);
221}
222
223static struct irq_chip s3c2443_irq_cam = {
224 .mask = s3c2443_irq_cam_mask,
225 .unmask = s3c2443_irq_cam_unmask,
226 .ack = s3c2443_irq_cam_ack,
227};
228
229/* IRQ initialisation code */
230
231static int __init s3c2443_add_sub(unsigned int base,
232 void (*demux)(unsigned int,
233 struct irq_desc *),
234 struct irq_chip *chip,
235 unsigned int start, unsigned int end)
Ben Dookse4d06e32007-02-16 12:12:31 +0100236{
237 unsigned int irqno;
238
Ben Dooks72262e82007-02-16 13:02:42 +0100239 set_irq_chip(base, &s3c_irq_level_chip);
240 set_irq_handler(base, handle_level_irq);
241 set_irq_chained_handler(base, demux);
Ben Dookse4d06e32007-02-16 12:12:31 +0100242
Ben Dooks72262e82007-02-16 13:02:42 +0100243 for (irqno = start; irqno <= end; irqno++) {
244 set_irq_chip(irqno, chip);
Ben Dookse4d06e32007-02-16 12:12:31 +0100245 set_irq_handler(irqno, handle_level_irq);
246 set_irq_flags(irqno, IRQF_VALID);
247 }
248
249 return 0;
250}
251
Krzysztof Helt008d9312007-09-04 17:18:04 +0100252static int __init s3c2443_irq_add(struct sys_device *sysdev)
Ben Dooks72262e82007-02-16 13:02:42 +0100253{
254 printk("S3C2443: IRQ Support\n");
255
256 s3c2443_add_sub(IRQ_CAM, s3c2443_irq_demux_cam, &s3c2443_irq_cam,
257 IRQ_S3C2440_CAM_C, IRQ_S3C2440_CAM_P);
258
259 s3c2443_add_sub(IRQ_LCD, s3c2443_irq_demux_lcd, &s3c2443_irq_lcd,
260 IRQ_S3C2443_LCD1, IRQ_S3C2443_LCD4);
261
262 s3c2443_add_sub(IRQ_S3C2443_DMA, s3c2443_irq_demux_dma,
263 &s3c2443_irq_dma, IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5);
264
265 s3c2443_add_sub(IRQ_S3C2443_UART3, s3c2443_irq_demux_uart3,
266 &s3c2443_irq_uart3,
267 IRQ_S3C2443_RX3, IRQ_S3C2443_ERR3);
268
269 s3c2443_add_sub(IRQ_WDT, s3c2443_irq_demux_wdtac97,
270 &s3c2443_irq_wdtac97,
271 IRQ_S3C2443_WDT, IRQ_S3C2443_AC97);
272
273 return 0;
274}
275
Ben Dookse4d06e32007-02-16 12:12:31 +0100276static struct sysdev_driver s3c2443_irq_driver = {
277 .add = s3c2443_irq_add,
278};
279
Krzysztof Helt008d9312007-09-04 17:18:04 +0100280static int __init s3c2443_irq_init(void)
Ben Dookse4d06e32007-02-16 12:12:31 +0100281{
282 return sysdev_driver_register(&s3c2443_sysclass, &s3c2443_irq_driver);
283}
284
285arch_initcall(s3c2443_irq_init);
286