blob: bc739701c3014861fce43f525f0273e7dd8502e9 [file] [log] [blame]
Dan Williams285f5fa2006-12-07 02:59:39 +01001/*
2 * iop13xx IRQ handling / support functions
3 * Copyright (c) 2005-2006, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307 USA.
17 *
18 */
19#include <linux/init.h>
20#include <linux/interrupt.h>
21#include <linux/list.h>
22#include <linux/sysctl.h>
23#include <asm/uaccess.h>
24#include <asm/mach/irq.h>
25#include <asm/irq.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010026#include <mach/hardware.h>
27#include <mach/irqs.h>
28#include <mach/msi.h>
Dan Williams285f5fa2006-12-07 02:59:39 +010029
30/* INTCTL0 CP6 R0 Page 4
31 */
Dan Williamsd73d8012007-05-15 01:03:36 +010032static u32 read_intctl_0(void)
Dan Williams285f5fa2006-12-07 02:59:39 +010033{
34 u32 val;
35 asm volatile("mrc p6, 0, %0, c0, c4, 0":"=r" (val));
36 return val;
37}
Dan Williamsd73d8012007-05-15 01:03:36 +010038static void write_intctl_0(u32 val)
Dan Williams285f5fa2006-12-07 02:59:39 +010039{
40 asm volatile("mcr p6, 0, %0, c0, c4, 0"::"r" (val));
41}
42
43/* INTCTL1 CP6 R1 Page 4
44 */
Dan Williamsd73d8012007-05-15 01:03:36 +010045static u32 read_intctl_1(void)
Dan Williams285f5fa2006-12-07 02:59:39 +010046{
47 u32 val;
48 asm volatile("mrc p6, 0, %0, c1, c4, 0":"=r" (val));
49 return val;
50}
Dan Williamsd73d8012007-05-15 01:03:36 +010051static void write_intctl_1(u32 val)
Dan Williams285f5fa2006-12-07 02:59:39 +010052{
53 asm volatile("mcr p6, 0, %0, c1, c4, 0"::"r" (val));
54}
55
56/* INTCTL2 CP6 R2 Page 4
57 */
Dan Williamsd73d8012007-05-15 01:03:36 +010058static u32 read_intctl_2(void)
Dan Williams285f5fa2006-12-07 02:59:39 +010059{
60 u32 val;
61 asm volatile("mrc p6, 0, %0, c2, c4, 0":"=r" (val));
62 return val;
63}
Dan Williamsd73d8012007-05-15 01:03:36 +010064static void write_intctl_2(u32 val)
Dan Williams285f5fa2006-12-07 02:59:39 +010065{
66 asm volatile("mcr p6, 0, %0, c2, c4, 0"::"r" (val));
67}
68
69/* INTCTL3 CP6 R3 Page 4
70 */
Dan Williamsd73d8012007-05-15 01:03:36 +010071static u32 read_intctl_3(void)
Dan Williams285f5fa2006-12-07 02:59:39 +010072{
73 u32 val;
74 asm volatile("mrc p6, 0, %0, c3, c4, 0":"=r" (val));
75 return val;
76}
Dan Williamsd73d8012007-05-15 01:03:36 +010077static void write_intctl_3(u32 val)
Dan Williams285f5fa2006-12-07 02:59:39 +010078{
79 asm volatile("mcr p6, 0, %0, c3, c4, 0"::"r" (val));
80}
81
82/* INTSTR0 CP6 R0 Page 5
83 */
Dan Williamsd73d8012007-05-15 01:03:36 +010084static void write_intstr_0(u32 val)
Dan Williams285f5fa2006-12-07 02:59:39 +010085{
86 asm volatile("mcr p6, 0, %0, c0, c5, 0"::"r" (val));
87}
88
89/* INTSTR1 CP6 R1 Page 5
90 */
Dan Williams285f5fa2006-12-07 02:59:39 +010091static void write_intstr_1(u32 val)
92{
93 asm volatile("mcr p6, 0, %0, c1, c5, 0"::"r" (val));
94}
95
96/* INTSTR2 CP6 R2 Page 5
97 */
Dan Williams285f5fa2006-12-07 02:59:39 +010098static void write_intstr_2(u32 val)
99{
100 asm volatile("mcr p6, 0, %0, c2, c5, 0"::"r" (val));
101}
102
103/* INTSTR3 CP6 R3 Page 5
104 */
Dan Williams285f5fa2006-12-07 02:59:39 +0100105static void write_intstr_3(u32 val)
106{
107 asm volatile("mcr p6, 0, %0, c3, c5, 0"::"r" (val));
108}
109
110/* INTBASE CP6 R0 Page 2
111 */
Dan Williams285f5fa2006-12-07 02:59:39 +0100112static void write_intbase(u32 val)
113{
114 asm volatile("mcr p6, 0, %0, c0, c2, 0"::"r" (val));
115}
116
117/* INTSIZE CP6 R2 Page 2
118 */
Dan Williams285f5fa2006-12-07 02:59:39 +0100119static void write_intsize(u32 val)
120{
121 asm volatile("mcr p6, 0, %0, c2, c2, 0"::"r" (val));
122}
123
124/* 0 = Interrupt Masked and 1 = Interrupt not masked */
125static void
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100126iop13xx_irq_mask0 (struct irq_data *d)
Dan Williams285f5fa2006-12-07 02:59:39 +0100127{
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100128 write_intctl_0(read_intctl_0() & ~(1 << (d->irq - 0)));
Dan Williams285f5fa2006-12-07 02:59:39 +0100129}
130
131static void
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100132iop13xx_irq_mask1 (struct irq_data *d)
Dan Williams285f5fa2006-12-07 02:59:39 +0100133{
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100134 write_intctl_1(read_intctl_1() & ~(1 << (d->irq - 32)));
Dan Williams285f5fa2006-12-07 02:59:39 +0100135}
136
137static void
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100138iop13xx_irq_mask2 (struct irq_data *d)
Dan Williams285f5fa2006-12-07 02:59:39 +0100139{
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100140 write_intctl_2(read_intctl_2() & ~(1 << (d->irq - 64)));
Dan Williams285f5fa2006-12-07 02:59:39 +0100141}
142
143static void
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100144iop13xx_irq_mask3 (struct irq_data *d)
Dan Williams285f5fa2006-12-07 02:59:39 +0100145{
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100146 write_intctl_3(read_intctl_3() & ~(1 << (d->irq - 96)));
Dan Williams285f5fa2006-12-07 02:59:39 +0100147}
148
149static void
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100150iop13xx_irq_unmask0(struct irq_data *d)
Dan Williams285f5fa2006-12-07 02:59:39 +0100151{
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100152 write_intctl_0(read_intctl_0() | (1 << (d->irq - 0)));
Dan Williams285f5fa2006-12-07 02:59:39 +0100153}
154
155static void
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100156iop13xx_irq_unmask1(struct irq_data *d)
Dan Williams285f5fa2006-12-07 02:59:39 +0100157{
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100158 write_intctl_1(read_intctl_1() | (1 << (d->irq - 32)));
Dan Williams285f5fa2006-12-07 02:59:39 +0100159}
160
161static void
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100162iop13xx_irq_unmask2(struct irq_data *d)
Dan Williams285f5fa2006-12-07 02:59:39 +0100163{
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100164 write_intctl_2(read_intctl_2() | (1 << (d->irq - 64)));
Dan Williams285f5fa2006-12-07 02:59:39 +0100165}
166
167static void
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100168iop13xx_irq_unmask3(struct irq_data *d)
Dan Williams285f5fa2006-12-07 02:59:39 +0100169{
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100170 write_intctl_3(read_intctl_3() | (1 << (d->irq - 96)));
Dan Williams285f5fa2006-12-07 02:59:39 +0100171}
172
Dan Williams3a2aeda2006-12-14 23:31:20 +0100173static struct irq_chip iop13xx_irqchip1 = {
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100174 .name = "IOP13xx-1",
175 .irq_ack = iop13xx_irq_mask0,
176 .irq_mask = iop13xx_irq_mask0,
177 .irq_unmask = iop13xx_irq_unmask0,
Dan Williams285f5fa2006-12-07 02:59:39 +0100178};
179
Dan Williams3a2aeda2006-12-14 23:31:20 +0100180static struct irq_chip iop13xx_irqchip2 = {
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100181 .name = "IOP13xx-2",
182 .irq_ack = iop13xx_irq_mask1,
183 .irq_mask = iop13xx_irq_mask1,
184 .irq_unmask = iop13xx_irq_unmask1,
Dan Williams285f5fa2006-12-07 02:59:39 +0100185};
186
Dan Williams3a2aeda2006-12-14 23:31:20 +0100187static struct irq_chip iop13xx_irqchip3 = {
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100188 .name = "IOP13xx-3",
189 .irq_ack = iop13xx_irq_mask2,
190 .irq_mask = iop13xx_irq_mask2,
191 .irq_unmask = iop13xx_irq_unmask2,
Dan Williams285f5fa2006-12-07 02:59:39 +0100192};
193
Dan Williams3a2aeda2006-12-14 23:31:20 +0100194static struct irq_chip iop13xx_irqchip4 = {
Lennert Buytenhek418c9902010-11-29 10:32:01 +0100195 .name = "IOP13xx-4",
196 .irq_ack = iop13xx_irq_mask3,
197 .irq_mask = iop13xx_irq_mask3,
198 .irq_unmask = iop13xx_irq_unmask3,
Dan Williams285f5fa2006-12-07 02:59:39 +0100199};
200
Dan Williams588ef762007-02-13 17:12:04 +0100201extern void iop_init_cp6_handler(void);
202
Dan Williams285f5fa2006-12-07 02:59:39 +0100203void __init iop13xx_init_irq(void)
204{
205 unsigned int i;
206
Dan Williams588ef762007-02-13 17:12:04 +0100207 iop_init_cp6_handler();
Dan Williams285f5fa2006-12-07 02:59:39 +0100208
209 /* disable all interrupts */
210 write_intctl_0(0);
211 write_intctl_1(0);
212 write_intctl_2(0);
213 write_intctl_3(0);
214
215 /* treat all as IRQ */
216 write_intstr_0(0);
217 write_intstr_1(0);
218 write_intstr_2(0);
219 write_intstr_3(0);
220
221 /* initialize the interrupt vector generator */
222 write_intbase(INTBASE);
223 write_intsize(INTSIZE_4);
224
Daniel Wolstenholme2fd02372007-05-10 22:33:02 -0700225 for(i = 0; i <= IRQ_IOP13XX_HPI; i++) {
Dan Williams285f5fa2006-12-07 02:59:39 +0100226 if (i < 32)
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100227 irq_set_chip(i, &iop13xx_irqchip1);
Dan Williams3a2aeda2006-12-14 23:31:20 +0100228 else if (i < 64)
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100229 irq_set_chip(i, &iop13xx_irqchip2);
Dan Williams3a2aeda2006-12-14 23:31:20 +0100230 else if (i < 96)
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100231 irq_set_chip(i, &iop13xx_irqchip3);
Dan Williams3a2aeda2006-12-14 23:31:20 +0100232 else
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100233 irq_set_chip(i, &iop13xx_irqchip4);
Dan Williams285f5fa2006-12-07 02:59:39 +0100234
Thomas Gleixner6845664a2011-03-24 13:25:22 +0100235 irq_set_handler(i, handle_level_irq);
Dan Williams285f5fa2006-12-07 02:59:39 +0100236 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
237 }
Daniel Wolstenholme2fd02372007-05-10 22:33:02 -0700238
239 iop13xx_msi_init();
Dan Williams285f5fa2006-12-07 02:59:39 +0100240}