Merge tag 'dt' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[linux-2.6-microblaze.git] / arch / arm / mach-s3c24xx / bast-irq.c
1 /* linux/arch/arm/mach-s3c2410/bast-irq.c
2  *
3  * Copyright 2003-2005 Simtec Electronics
4  *   Ben Dooks <ben@simtec.co.uk>
5  *
6  * http://www.simtec.co.uk/products/EB2410ITX/
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/ioport.h>
27 #include <linux/device.h>
28 #include <linux/io.h>
29
30 #include <asm/irq.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/irq.h>
33
34 #include <mach/hardware.h>
35 #include <mach/regs-irq.h>
36
37 #include <plat/irq.h>
38
39 #include "bast.h"
40
41 #define irqdbf(x...)
42 #define irqdbf2(x...)
43
44 /* handle PC104 ISA interrupts from the system CPLD */
45
46 /* table of ISA irq nos to the relevant mask... zero means
47  * the irq is not implemented
48 */
49 static unsigned char bast_pc104_irqmasks[] = {
50         0,   /* 0 */
51         0,   /* 1 */
52         0,   /* 2 */
53         1,   /* 3 */
54         0,   /* 4 */
55         2,   /* 5 */
56         0,   /* 6 */
57         4,   /* 7 */
58         0,   /* 8 */
59         0,   /* 9 */
60         8,   /* 10 */
61         0,   /* 11 */
62         0,   /* 12 */
63         0,   /* 13 */
64         0,   /* 14 */
65         0,   /* 15 */
66 };
67
68 static unsigned char bast_pc104_irqs[] = { 3, 5, 7, 10 };
69
70 static void
71 bast_pc104_mask(struct irq_data *data)
72 {
73         unsigned long temp;
74
75         temp = __raw_readb(BAST_VA_PC104_IRQMASK);
76         temp &= ~bast_pc104_irqmasks[data->irq];
77         __raw_writeb(temp, BAST_VA_PC104_IRQMASK);
78 }
79
80 static void
81 bast_pc104_maskack(struct irq_data *data)
82 {
83         struct irq_desc *desc = irq_desc + BAST_IRQ_ISA;
84
85         bast_pc104_mask(data);
86         desc->irq_data.chip->irq_ack(&desc->irq_data);
87 }
88
89 static void
90 bast_pc104_unmask(struct irq_data *data)
91 {
92         unsigned long temp;
93
94         temp = __raw_readb(BAST_VA_PC104_IRQMASK);
95         temp |= bast_pc104_irqmasks[data->irq];
96         __raw_writeb(temp, BAST_VA_PC104_IRQMASK);
97 }
98
99 static struct irq_chip  bast_pc104_chip = {
100         .irq_mask       = bast_pc104_mask,
101         .irq_unmask     = bast_pc104_unmask,
102         .irq_ack        = bast_pc104_maskack
103 };
104
105 static void
106 bast_irq_pc104_demux(unsigned int irq,
107                      struct irq_desc *desc)
108 {
109         unsigned int stat;
110         unsigned int irqno;
111         int i;
112
113         stat = __raw_readb(BAST_VA_PC104_IRQREQ) & 0xf;
114
115         if (unlikely(stat == 0)) {
116                 /* ack if we get an irq with nothing (ie, startup) */
117
118                 desc = irq_desc + BAST_IRQ_ISA;
119                 desc->irq_data.chip->irq_ack(&desc->irq_data);
120         } else {
121                 /* handle the IRQ */
122
123                 for (i = 0; stat != 0; i++, stat >>= 1) {
124                         if (stat & 1) {
125                                 irqno = bast_pc104_irqs[i];
126                                 generic_handle_irq(irqno);
127                         }
128                 }
129         }
130 }
131
132 static __init int bast_irq_init(void)
133 {
134         unsigned int i;
135
136         if (machine_is_bast()) {
137                 printk(KERN_INFO "BAST PC104 IRQ routing, Copyright 2005 Simtec Electronics\n");
138
139                 /* zap all the IRQs */
140
141                 __raw_writeb(0x0, BAST_VA_PC104_IRQMASK);
142
143                 irq_set_chained_handler(BAST_IRQ_ISA, bast_irq_pc104_demux);
144
145                 /* register our IRQs */
146
147                 for (i = 0; i < 4; i++) {
148                         unsigned int irqno = bast_pc104_irqs[i];
149
150                         irq_set_chip_and_handler(irqno, &bast_pc104_chip,
151                                                  handle_level_irq);
152                         set_irq_flags(irqno, IRQF_VALID);
153                 }
154         }
155
156         return 0;
157 }
158
159 arch_initcall(bast_irq_init);