blob: cac82afe5eb422959290738e7fe027cbeecf853a [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{
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
42void enable_lasat_irq(unsigned int irq_nr)
43{
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047static void end_lasat_irq(unsigned int irq)
48{
49 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
50 enable_lasat_irq(irq);
51}
52
Ralf Baechle94dee172006-07-02 14:41:42 +010053static struct irq_chip lasat_irq_type = {
Ralf Baechle8ab00b92005-02-28 13:39:57 +000054 .typename = "Lasat",
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +090055 .ack = disable_lasat_irq,
56 .mask = disable_lasat_irq,
57 .mask_ack = disable_lasat_irq,
58 .unmask = enable_lasat_irq,
Ralf Baechle8ab00b92005-02-28 13:39:57 +000059 .end = end_lasat_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
62static inline int ls1bit32(unsigned int x)
63{
64 int b = 31, s;
65
66 s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
67 s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
68 s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
69 s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
70 s = 1; if (x << 1 == 0) s = 0; b -= s;
71
72 return b;
73}
74
75static unsigned long (* get_int_status)(void);
76
77static unsigned long get_int_status_100(void)
78{
79 return *lasat_int_status & *lasat_int_mask;
80}
81
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070082static unsigned long get_int_status_200(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 unsigned long int_status;
85
86 int_status = *lasat_int_status;
87 int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff;
88 return int_status;
89}
90
Ralf Baechle937a8012006-10-07 19:44:33 +010091asmlinkage void plat_irq_dispatch(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 unsigned long int_status;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010094 unsigned int cause = read_c0_cause();
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 int irq;
96
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010097 if (cause & CAUSEF_IP7) { /* R4000 count / compare IRQ */
Ralf Baechle937a8012006-10-07 19:44:33 +010098 ll_timer_interrupt(7);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +010099 return;
100 }
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 int_status = get_int_status();
103
104 /* if int_status == 0, then the interrupt has already been cleared */
105 if (int_status) {
106 irq = ls1bit32(int_status);
107
Ralf Baechle937a8012006-10-07 19:44:33 +0100108 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
110}
111
112void __init arch_init_irq(void)
113{
114 int i;
115
116 switch (mips_machtype) {
117 case MACH_LASAT_100:
118 lasat_int_status = (void *)LASAT_INT_STATUS_REG_100;
119 lasat_int_mask = (void *)LASAT_INT_MASK_REG_100;
120 lasat_int_mask_shift = LASATINT_MASK_SHIFT_100;
121 get_int_status = get_int_status_100;
122 *lasat_int_mask = 0;
123 break;
124 case MACH_LASAT_200:
125 lasat_int_status = (void *)LASAT_INT_STATUS_REG_200;
126 lasat_int_mask = (void *)LASAT_INT_MASK_REG_200;
127 lasat_int_mask_shift = LASATINT_MASK_SHIFT_200;
128 get_int_status = get_int_status_200;
129 *lasat_int_mask &= 0xffff;
130 break;
131 default:
132 panic("arch_init_irq: mips_machtype incorrect");
133 }
134
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +0900135 for (i = 0; i <= LASATINT_END; i++)
136 set_irq_chip(i, &lasat_irq_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}