blob: d608b6ef0edd7712aa9d34c5668d2590a8e3a962 [file] [log] [blame]
Brian Murphy1f21d2b2007-08-21 22:34:16 +02001/*
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 *
18 * Routines for generic manipulation of the interrupts found on the
19 * Lasat boards.
20 */
21#include <linux/init.h>
Brian Murphy1f21d2b2007-08-21 22:34:16 +020022#include <linux/interrupt.h>
Yoichi Yuasa89becf52007-11-09 18:42:35 +090023#include <linux/irq.h>
Brian Murphy1f21d2b2007-08-21 22:34:16 +020024
Ralf Baechlea5ccfe52007-10-14 23:49:33 +010025#include <asm/irq_cpu.h>
Thomas Bogendoerferb27418a2008-07-14 16:58:47 +020026#include <asm/lasat/lasat.h>
Brian Murphy1f21d2b2007-08-21 22:34:16 +020027#include <asm/lasat/lasatint.h>
Yoichi Yuasa89becf52007-11-09 18:42:35 +090028
29#include <irq.h>
Brian Murphy1f21d2b2007-08-21 22:34:16 +020030
31static volatile int *lasat_int_status;
32static volatile int *lasat_int_mask;
33static volatile int lasat_int_mask_shift;
34
Thomas Gleixner9fcecaf2011-03-23 21:08:56 +000035void disable_lasat_irq(struct irq_data *d)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020036{
Thomas Gleixner9fcecaf2011-03-23 21:08:56 +000037 unsigned int irq_nr = d->irq - LASAT_IRQ_BASE;
38
Brian Murphy1f21d2b2007-08-21 22:34:16 +020039 *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift;
40}
41
Thomas Gleixner9fcecaf2011-03-23 21:08:56 +000042void enable_lasat_irq(struct irq_data *d)
Brian Murphy1f21d2b2007-08-21 22:34:16 +020043{
Thomas Gleixner9fcecaf2011-03-23 21:08:56 +000044 unsigned int irq_nr = d->irq - LASAT_IRQ_BASE;
45
Brian Murphy1f21d2b2007-08-21 22:34:16 +020046 *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift;
47}
48
49static struct irq_chip lasat_irq_type = {
50 .name = "Lasat",
Thomas Gleixner9fcecaf2011-03-23 21:08:56 +000051 .irq_mask = disable_lasat_irq,
52 .irq_unmask = enable_lasat_irq,
Brian Murphy1f21d2b2007-08-21 22:34:16 +020053};
54
55static inline int ls1bit32(unsigned int x)
56{
57 int b = 31, s;
58
59 s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
60 s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
61 s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
62 s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
63 s = 1; if (x << 1 == 0) s = 0; b -= s;
64
65 return b;
66}
67
68static unsigned long (*get_int_status)(void);
69
70static unsigned long get_int_status_100(void)
71{
72 return *lasat_int_status & *lasat_int_mask;
73}
74
75static unsigned long get_int_status_200(void)
76{
77 unsigned long int_status;
78
79 int_status = *lasat_int_status;
80 int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff;
81 return int_status;
82}
83
84asmlinkage void plat_irq_dispatch(void)
85{
86 unsigned long int_status;
87 unsigned int cause = read_c0_cause();
88 int irq;
89
90 if (cause & CAUSEF_IP7) { /* R4000 count / compare IRQ */
Ralf Baechlea5ccfe52007-10-14 23:49:33 +010091 do_IRQ(7);
Brian Murphy1f21d2b2007-08-21 22:34:16 +020092 return;
93 }
94
95 int_status = get_int_status();
96
97 /* if int_status == 0, then the interrupt has already been cleared */
98 if (int_status) {
Yoichi Yuasa89becf52007-11-09 18:42:35 +090099 irq = LASAT_IRQ_BASE + ls1bit32(int_status);
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200100
101 do_IRQ(irq);
102 }
103}
104
Yoichi Yuasa89becf52007-11-09 18:42:35 +0900105static struct irqaction cascade = {
106 .handler = no_action,
Yoichi Yuasa89becf52007-11-09 18:42:35 +0900107 .name = "cascade",
Wu Zhangjin5a4a4ad2011-07-23 12:41:24 +0000108 .flags = IRQF_NO_THREAD,
Yoichi Yuasa89becf52007-11-09 18:42:35 +0900109};
110
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200111void __init arch_init_irq(void)
112{
113 int i;
114
Thomas Bogendoerferb27418a2008-07-14 16:58:47 +0200115 if (IS_LASAT_200()) {
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200116 lasat_int_status = (void *)LASAT_INT_STATUS_REG_200;
117 lasat_int_mask = (void *)LASAT_INT_MASK_REG_200;
118 lasat_int_mask_shift = LASATINT_MASK_SHIFT_200;
119 get_int_status = get_int_status_200;
120 *lasat_int_mask &= 0xffff;
Thomas Bogendoerferb27418a2008-07-14 16:58:47 +0200121 } else {
122 lasat_int_status = (void *)LASAT_INT_STATUS_REG_100;
123 lasat_int_mask = (void *)LASAT_INT_MASK_REG_100;
124 lasat_int_mask_shift = LASATINT_MASK_SHIFT_100;
125 get_int_status = get_int_status_100;
126 *lasat_int_mask = 0;
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200127 }
128
Ralf Baechlea5ccfe52007-10-14 23:49:33 +0100129 mips_cpu_irq_init();
Yoichi Yuasa89becf52007-11-09 18:42:35 +0900130
131 for (i = LASAT_IRQ_BASE; i <= LASAT_IRQ_END; i++)
Thomas Gleixnere4ec7982011-03-27 15:19:28 +0200132 irq_set_chip_and_handler(i, &lasat_irq_type, handle_level_irq);
Yoichi Yuasa89becf52007-11-09 18:42:35 +0900133
134 setup_irq(LASAT_CASCADE_IRQ, &cascade);
Brian Murphy1f21d2b2007-08-21 22:34:16 +0200135}