[MIPS] ITE8172: Fix build error due to missmatching prototypes.
[sfrench/cifs-2.6.git] / arch / mips / ite-boards / generic / irq.c
1 /*
2  * BRIEF MODULE DESCRIPTION
3  *      ITE 8172G interrupt/setup routines.
4  *
5  * Copyright 2000,2001 MontaVista Software Inc.
6  * Author: MontaVista Software, Inc.
7  *              ppopov@mvista.com or source@mvista.com
8  *
9  * Part of this file was derived from Carsten Langgaard's
10  * arch/mips/mips-boards/atlas/atlas_int.c.
11  *
12  * Carsten Langgaard, carstenl@mips.com
13  * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
14  *
15  *  This program is free software; you can redistribute  it and/or modify it
16  *  under  the terms of  the GNU General  Public License as published by the
17  *  Free Software Foundation;  either version 2 of the  License, or (at your
18  *  option) any later version.
19  *
20  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
21  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
22  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
23  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
24  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
26  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
28  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  *  You should have received a copy of the  GNU General Public License along
32  *  with this program; if not, write  to the Free Software Foundation, Inc.,
33  *  675 Mass Ave, Cambridge, MA 02139, USA.
34  */
35 #include <linux/errno.h>
36 #include <linux/init.h>
37 #include <linux/irq.h>
38 #include <linux/kernel_stat.h>
39 #include <linux/module.h>
40 #include <linux/signal.h>
41 #include <linux/sched.h>
42 #include <linux/types.h>
43 #include <linux/interrupt.h>
44 #include <linux/ioport.h>
45 #include <linux/timex.h>
46 #include <linux/slab.h>
47 #include <linux/random.h>
48 #include <linux/serial_reg.h>
49 #include <linux/bitops.h>
50
51 #include <asm/bootinfo.h>
52 #include <asm/io.h>
53 #include <asm/mipsregs.h>
54 #include <asm/system.h>
55 #include <asm/it8172/it8172.h>
56 #include <asm/it8172/it8172_int.h>
57 #include <asm/it8172/it8172_dbg.h>
58
59 /* revisit */
60 #define EXT_IRQ0_TO_IP 2 /* IP 2 */
61 #define EXT_IRQ5_TO_IP 7 /* IP 7 */
62
63 #define ALLINTS_NOTIMER (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4)
64
65 extern void set_debug_traps(void);
66 extern void mips_timer_interrupt(int irq, struct pt_regs *regs);
67 extern asmlinkage void it8172_IRQ(void);
68
69 struct it8172_intc_regs volatile *it8172_hw0_icregs =
70         (struct it8172_intc_regs volatile *)(KSEG1ADDR(IT8172_PCI_IO_BASE + IT_INTC_BASE));
71
72 static void disable_it8172_irq(unsigned int irq_nr)
73 {
74         if ( (irq_nr >= IT8172_LPC_IRQ_BASE) && (irq_nr <= IT8172_SERIRQ_15)) {
75                 /* LPC interrupt */
76                 it8172_hw0_icregs->lpc_mask |=
77                         (1 << (irq_nr - IT8172_LPC_IRQ_BASE));
78         } else if ( (irq_nr >= IT8172_LB_IRQ_BASE) && (irq_nr <= IT8172_IOCHK_IRQ)) {
79                 /* Local Bus interrupt */
80                 it8172_hw0_icregs->lb_mask |=
81                         (1 << (irq_nr - IT8172_LB_IRQ_BASE));
82         } else if ( (irq_nr >= IT8172_PCI_DEV_IRQ_BASE) && (irq_nr <= IT8172_DMA_IRQ)) {
83                 /* PCI and other interrupts */
84                 it8172_hw0_icregs->pci_mask |=
85                         (1 << (irq_nr - IT8172_PCI_DEV_IRQ_BASE));
86         } else if ( (irq_nr >= IT8172_NMI_IRQ_BASE) && (irq_nr <= IT8172_POWER_NMI_IRQ)) {
87                 /* NMI interrupts */
88                 it8172_hw0_icregs->nmi_mask |=
89                         (1 << (irq_nr - IT8172_NMI_IRQ_BASE));
90         } else {
91                 panic("disable_it8172_irq: bad irq %d", irq_nr);
92         }
93 }
94
95 static void enable_it8172_irq(unsigned int irq_nr)
96 {
97         if ( (irq_nr >= IT8172_LPC_IRQ_BASE) && (irq_nr <= IT8172_SERIRQ_15)) {
98                 /* LPC interrupt */
99                 it8172_hw0_icregs->lpc_mask &=
100                         ~(1 << (irq_nr - IT8172_LPC_IRQ_BASE));
101         }
102         else if ( (irq_nr >= IT8172_LB_IRQ_BASE) && (irq_nr <= IT8172_IOCHK_IRQ)) {
103                 /* Local Bus interrupt */
104                 it8172_hw0_icregs->lb_mask &=
105                         ~(1 << (irq_nr - IT8172_LB_IRQ_BASE));
106         }
107         else if ( (irq_nr >= IT8172_PCI_DEV_IRQ_BASE) && (irq_nr <= IT8172_DMA_IRQ)) {
108                 /* PCI and other interrupts */
109                 it8172_hw0_icregs->pci_mask &=
110                         ~(1 << (irq_nr - IT8172_PCI_DEV_IRQ_BASE));
111         }
112         else if ( (irq_nr >= IT8172_NMI_IRQ_BASE) && (irq_nr <= IT8172_POWER_NMI_IRQ)) {
113                 /* NMI interrupts */
114                 it8172_hw0_icregs->nmi_mask &=
115                         ~(1 << (irq_nr - IT8172_NMI_IRQ_BASE));
116         }
117         else {
118                 panic("enable_it8172_irq: bad irq %d", irq_nr);
119         }
120 }
121
122 static unsigned int startup_ite_irq(unsigned int irq)
123 {
124         enable_it8172_irq(irq);
125         return 0;
126 }
127
128 #define shutdown_ite_irq        disable_it8172_irq
129 #define mask_and_ack_ite_irq    disable_it8172_irq
130
131 static void end_ite_irq(unsigned int irq)
132 {
133         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
134                 enable_it8172_irq(irq);
135 }
136
137 static struct hw_interrupt_type it8172_irq_type = {
138         .typename = "ITE8172",
139         .startup = startup_ite_irq,
140         .shutdown = shutdown_ite_irq,
141         .enable = enable_it8172_irq,
142         .disable = disable_it8172_irq,
143         .ack = mask_and_ack_ite_irq,
144         .end = end_ite_irq,
145 };
146
147
148 static void enable_none(unsigned int irq) { }
149 static unsigned int startup_none(unsigned int irq) { return 0; }
150 static void disable_none(unsigned int irq) { }
151 static void ack_none(unsigned int irq) { }
152
153 /* startup is the same as "enable", shutdown is same as "disable" */
154 #define shutdown_none   disable_none
155 #define end_none        enable_none
156
157 static struct hw_interrupt_type cp0_irq_type = {
158         .typename = "CP0 Count",
159         .startup = startup_none,
160         .shutdown = shutdown_none,
161         .enable = enable_none,
162         .disable = disable_none,
163         .ack = ack_none,
164         .end = end_none
165 };
166
167 void enable_cpu_timer(void)
168 {
169         unsigned long flags;
170
171         local_irq_save(flags);
172         set_c0_status(0x100 << EXT_IRQ5_TO_IP);
173         local_irq_restore(flags);
174 }
175
176 void __init arch_init_irq(void)
177 {
178         int i;
179         unsigned long flags;
180
181         set_except_vector(0, it8172_IRQ);
182
183         /* mask all interrupts */
184         it8172_hw0_icregs->lb_mask  = 0xffff;
185         it8172_hw0_icregs->lpc_mask = 0xffff;
186         it8172_hw0_icregs->pci_mask = 0xffff;
187         it8172_hw0_icregs->nmi_mask = 0xffff;
188
189         /* make all interrupts level triggered */
190         it8172_hw0_icregs->lb_trigger  = 0;
191         it8172_hw0_icregs->lpc_trigger = 0;
192         it8172_hw0_icregs->pci_trigger = 0;
193         it8172_hw0_icregs->nmi_trigger = 0;
194
195         /* active level setting */
196         /* uart, keyboard, and mouse are active high */
197         it8172_hw0_icregs->lpc_level = (0x10 | 0x2 | 0x1000);
198         it8172_hw0_icregs->lb_level |= 0x20;
199
200         /* keyboard and mouse are edge triggered */
201         it8172_hw0_icregs->lpc_trigger |= (0x2 | 0x1000);
202
203
204 #if 0
205         // Enable this piece of code to make internal USB interrupt
206         // edge triggered.
207         it8172_hw0_icregs->pci_trigger |=
208                 (1 << (IT8172_USB_IRQ - IT8172_PCI_DEV_IRQ_BASE));
209         it8172_hw0_icregs->pci_level &=
210                 ~(1 << (IT8172_USB_IRQ - IT8172_PCI_DEV_IRQ_BASE));
211 #endif
212
213         for (i = 0; i <= IT8172_LAST_IRQ; i++) {
214                 irq_desc[i].handler = &it8172_irq_type;
215                 spin_lock_init(&irq_desc[i].lock);
216         }
217         irq_desc[MIPS_CPU_TIMER_IRQ].handler = &cp0_irq_type;
218         set_c0_status(ALLINTS_NOTIMER);
219 }
220
221 void mips_spurious_interrupt(struct pt_regs *regs)
222 {
223 #if 1
224         return;
225 #else
226         unsigned long status, cause;
227
228         printk("got spurious interrupt\n");
229         status = read_c0_status();
230         cause = read_c0_cause();
231         printk("status %x cause %x\n", status, cause);
232         printk("epc %x badvaddr %x \n", regs->cp0_epc, regs->cp0_badvaddr);
233 #endif
234 }
235
236 void it8172_hw0_irqdispatch(struct pt_regs *regs)
237 {
238         int irq;
239         unsigned short intstatus = 0, status = 0;
240
241         intstatus = it8172_hw0_icregs->intstatus;
242         if (intstatus & 0x8) {
243                 panic("Got NMI interrupt");
244         } else if (intstatus & 0x4) {
245                 /* PCI interrupt */
246                 irq = 0;
247                 status |= it8172_hw0_icregs->pci_req;
248                 while (!(status & 0x1)) {
249                         irq++;
250                         status >>= 1;
251                 }
252                 irq += IT8172_PCI_DEV_IRQ_BASE;
253         } else if (intstatus & 0x1) {
254                 /* Local Bus interrupt */
255                 irq = 0;
256                 status |= it8172_hw0_icregs->lb_req;
257                 while (!(status & 0x1)) {
258                         irq++;
259                         status >>= 1;
260                 }
261                 irq += IT8172_LB_IRQ_BASE;
262         } else if (intstatus & 0x2) {
263                 /* LPC interrupt */
264                 /* Since some lpc interrupts are edge triggered,
265                  * we could lose an interrupt this way because
266                  * we acknowledge all ints at onces. Revisit.
267                  */
268                 status |= it8172_hw0_icregs->lpc_req;
269                 it8172_hw0_icregs->lpc_req = 0; /* acknowledge ints */
270                 irq = 0;
271                 while (!(status & 0x1)) {
272                         irq++;
273                         status >>= 1;
274                 }
275                 irq += IT8172_LPC_IRQ_BASE;
276         } else
277                 return;
278
279         do_IRQ(irq, regs);
280 }
281
282 void show_pending_irqs(void)
283 {
284         fputs("intstatus:  ");
285         put32(it8172_hw0_icregs->intstatus);
286         puts("");
287
288         fputs("pci_req:  ");
289         put32(it8172_hw0_icregs->pci_req);
290         puts("");
291
292         fputs("lb_req:  ");
293         put32(it8172_hw0_icregs->lb_req);
294         puts("");
295
296         fputs("lpc_req:  ");
297         put32(it8172_hw0_icregs->lpc_req);
298         puts("");
299 }