blob: 2d3472b21ebbe3ad62b98ff3046380b0039107a3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * 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
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 *
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070018 * Routines for generic manipulation of the interrupts found on the
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * Lasat boards.
20 */
21#include <linux/init.h>
22#include <linux/sched.h>
23#include <linux/slab.h>
24#include <linux/interrupt.h>
25#include <linux/kernel_stat.h>
26
27#include <asm/bootinfo.h>
28#include <asm/irq.h>
29#include <asm/lasat/lasatint.h>
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010030#include <asm/time.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/gdb-stub.h>
32
33static volatile int *lasat_int_status = NULL;
34static volatile int *lasat_int_mask = NULL;
35static volatile int lasat_int_mask_shift;
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037void disable_lasat_irq(unsigned int irq_nr)
38{
39 unsigned long flags;
40
41 local_irq_save(flags);
42 *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift;
43 local_irq_restore(flags);
44}
45
46void enable_lasat_irq(unsigned int irq_nr)
47{
48 unsigned long flags;
49
50 local_irq_save(flags);
51 *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift;
52 local_irq_restore(flags);
53}
54
55static unsigned int startup_lasat_irq(unsigned int irq)
56{
57 enable_lasat_irq(irq);
58
59 return 0; /* never anything pending */
60}
61
62#define shutdown_lasat_irq disable_lasat_irq
63
64#define mask_and_ack_lasat_irq disable_lasat_irq
65
66static void end_lasat_irq(unsigned int irq)
67{
68 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
69 enable_lasat_irq(irq);
70}
71
72static struct hw_interrupt_type lasat_irq_type = {
Ralf Baechle8ab00b92005-02-28 13:39:57 +000073 .typename = "Lasat",
74 .startup = startup_lasat_irq,
75 .shutdown = shutdown_lasat_irq,
76 .enable = enable_lasat_irq,
77 .disable = disable_lasat_irq,
78 .ack = mask_and_ack_lasat_irq,
79 .end = end_lasat_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080};
81
82static inline int ls1bit32(unsigned int x)
83{
84 int b = 31, s;
85
86 s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
87 s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
88 s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
89 s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
90 s = 1; if (x << 1 == 0) s = 0; b -= s;
91
92 return b;
93}
94
95static unsigned long (* get_int_status)(void);
96
97static unsigned long get_int_status_100(void)
98{
99 return *lasat_int_status & *lasat_int_mask;
100}
101
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700102static unsigned long get_int_status_200(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 unsigned long int_status;
105
106 int_status = *lasat_int_status;
107 int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff;
108 return int_status;
109}
110
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100111asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
113 unsigned long int_status;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100114 unsigned int cause = read_c0_cause();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 int irq;
116
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100117 if (cause & CAUSEF_IP7) { /* R4000 count / compare IRQ */
118 ll_timer_interrupt(7, regs);
119 return;
120 }
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 int_status = get_int_status();
123
124 /* if int_status == 0, then the interrupt has already been cleared */
125 if (int_status) {
126 irq = ls1bit32(int_status);
127
128 do_IRQ(irq, regs);
129 }
130}
131
132void __init arch_init_irq(void)
133{
134 int i;
135
136 switch (mips_machtype) {
137 case MACH_LASAT_100:
138 lasat_int_status = (void *)LASAT_INT_STATUS_REG_100;
139 lasat_int_mask = (void *)LASAT_INT_MASK_REG_100;
140 lasat_int_mask_shift = LASATINT_MASK_SHIFT_100;
141 get_int_status = get_int_status_100;
142 *lasat_int_mask = 0;
143 break;
144 case MACH_LASAT_200:
145 lasat_int_status = (void *)LASAT_INT_STATUS_REG_200;
146 lasat_int_mask = (void *)LASAT_INT_MASK_REG_200;
147 lasat_int_mask_shift = LASATINT_MASK_SHIFT_200;
148 get_int_status = get_int_status_200;
149 *lasat_int_mask &= 0xffff;
150 break;
151 default:
152 panic("arch_init_irq: mips_machtype incorrect");
153 }
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 for (i = 0; i <= LASATINT_END; i++) {
156 irq_desc[i].status = IRQ_DISABLED;
157 irq_desc[i].action = 0;
158 irq_desc[i].depth = 1;
159 irq_desc[i].handler = &lasat_irq_type;
160 }
161}