blob: fbbeb05530061eaf24089f3e62acea6d078edad7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* linux/arch/arm/mach-s3c2410/bast-irq.c
2 *
Ben Dooksbafa49c2005-09-07 17:24:48 +01003 * Copyright (c) 2003,2005 Simtec Electronics
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 * Modifications:
23 * 08-Jan-2003 BJD Moved from central IRQ code
Ben Dooksbafa49c2005-09-07 17:24:48 +010024 * 21-Aug-2005 BJD Fixed missing code and compile errors
25*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27
28#include <linux/init.h>
29#include <linux/module.h>
30#include <linux/ioport.h>
31#include <linux/ptrace.h>
32#include <linux/sysdev.h>
33
Ben Dooksbafa49c2005-09-07 17:24:48 +010034#include <asm/mach-types.h>
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/hardware.h>
37#include <asm/irq.h>
38#include <asm/io.h>
39
40#include <asm/mach/irq.h>
Ben Dooksbafa49c2005-09-07 17:24:48 +010041
42#include <asm/arch/regs-irq.h>
43#include <asm/arch/bast-map.h>
44#include <asm/arch/bast-irq.h>
45
46#include "irq.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48#if 0
49#include <asm/debug-ll.h>
50#endif
51
52#define irqdbf(x...)
53#define irqdbf2(x...)
54
55
56/* handle PC104 ISA interrupts from the system CPLD */
57
58/* table of ISA irq nos to the relevant mask... zero means
59 * the irq is not implemented
60*/
61static unsigned char bast_pc104_irqmasks[] = {
62 0, /* 0 */
63 0, /* 1 */
64 0, /* 2 */
65 1, /* 3 */
66 0, /* 4 */
67 2, /* 5 */
68 0, /* 6 */
69 4, /* 7 */
70 0, /* 8 */
71 0, /* 9 */
72 8, /* 10 */
73 0, /* 11 */
74 0, /* 12 */
75 0, /* 13 */
76 0, /* 14 */
77 0, /* 15 */
78};
79
80static unsigned char bast_pc104_irqs[] = { 3, 5, 7, 10 };
81
82static void
83bast_pc104_mask(unsigned int irqno)
84{
85 unsigned long temp;
86
87 temp = __raw_readb(BAST_VA_PC104_IRQMASK);
88 temp &= ~bast_pc104_irqmasks[irqno];
89 __raw_writeb(temp, BAST_VA_PC104_IRQMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
92static void
Ben Dooksbafa49c2005-09-07 17:24:48 +010093bast_pc104_maskack(unsigned int irqno)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Ben Dooksbafa49c2005-09-07 17:24:48 +010095 struct irqdesc *desc = irq_desc + IRQ_ISA;
96
97 bast_pc104_mask(irqno);
98 desc->chip->ack(IRQ_ISA);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
101static void
102bast_pc104_unmask(unsigned int irqno)
103{
104 unsigned long temp;
105
106 temp = __raw_readb(BAST_VA_PC104_IRQMASK);
107 temp |= bast_pc104_irqmasks[irqno];
108 __raw_writeb(temp, BAST_VA_PC104_IRQMASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Ben Dooksbafa49c2005-09-07 17:24:48 +0100111static struct irqchip bast_pc104_chip = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 .mask = bast_pc104_mask,
113 .unmask = bast_pc104_unmask,
Ben Dooksbafa49c2005-09-07 17:24:48 +0100114 .ack = bast_pc104_maskack
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
117static void
118bast_irq_pc104_demux(unsigned int irq,
119 struct irqdesc *desc,
120 struct pt_regs *regs)
121{
122 unsigned int stat;
123 unsigned int irqno;
124 int i;
125
126 stat = __raw_readb(BAST_VA_PC104_IRQREQ) & 0xf;
127
Ben Dooksbafa49c2005-09-07 17:24:48 +0100128 if (unlikely(stat == 0)) {
129 /* ack if we get an irq with nothing (ie, startup) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Ben Dooksbafa49c2005-09-07 17:24:48 +0100131 desc = irq_desc + IRQ_ISA;
132 desc->chip->ack(IRQ_ISA);
133 } else {
134 /* handle the IRQ */
135
136 for (i = 0; stat != 0; i++, stat >>= 1) {
137 if (stat & 1) {
138 irqno = bast_pc104_irqs[i];
139
140 desc_handle_irq(irqno, irq_desc + irqno, regs);
141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144}
Ben Dooksbafa49c2005-09-07 17:24:48 +0100145
146static __init int bast_irq_init(void)
147{
148 unsigned int i;
149
150 if (machine_is_bast()) {
151 printk(KERN_INFO "BAST PC104 IRQ routing, (c) 2005 Simtec Electronics\n");
152
153 /* zap all the IRQs */
154
155 __raw_writeb(0x0, BAST_VA_PC104_IRQMASK);
156
157 set_irq_chained_handler(IRQ_ISA, bast_irq_pc104_demux);
158
159 /* reigster our IRQs */
160
161 for (i = 0; i < 4; i++) {
162 unsigned int irqno = bast_pc104_irqs[i];
163
164 set_irq_chip(irqno, &bast_pc104_chip);
165 set_irq_handler(irqno, do_level_IRQ);
166 set_irq_flags(irqno, IRQF_VALID);
167 }
168 }
169
170 return 0;
171}
172
173arch_initcall(bast_irq_init);