ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / mips / momentum / ocelot_g / gt-irq.c
1 /*
2  *
3  * Copyright 2002 Momentum Computer
4  * Author: mdharm@momenco.com
5  *
6  * arch/mips/momentum/ocelot_g/gt_irq.c
7  *     Interrupt routines for gt64240.  Currently it only handles timer irq.
8  *
9  * This program is free software; you can redistribute  it and/or modify it
10  * under  the terms of  the GNU General  Public License as published by the
11  * Free Software Foundation;  either version 2 of the  License, or (at your
12  * option) any later version.
13  */
14 #include <linux/module.h>
15 #include <linux/interrupt.h>
16 #include <linux/kernel.h>
17 #include <asm/ptrace.h>
18 #include <linux/sched.h>
19 #include <linux/kernel_stat.h>
20 #include <asm/io.h>
21 #include "gt64240.h"
22
23 unsigned long bus_clock;
24
25 /*
26  * These are interrupt handlers for the GT on-chip interrupts.  They
27  * all come in to the MIPS on a single interrupt line, and have to
28  * be handled and ack'ed differently than other MIPS interrupts.
29  */
30
31 #if CURRENTLY_UNUSED
32
33 struct tq_struct irq_handlers[MAX_CAUSE_REGS][MAX_CAUSE_REG_WIDTH];
34 void hook_irq_handler(int int_cause, int bit_num, void *isr_ptr);
35
36 /*
37  * Hooks IRQ handler to the system. When the system is interrupted
38  * the interrupt service routine is called.
39  *
40  * Inputs :
41  * int_cause - The interrupt cause number. In EVB64120 two parameters
42  *             are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
43  * bit_num   - Indicates which bit number in the cause register
44  * isr_ptr   - Pointer to the interrupt service routine
45  */
46 void hook_irq_handler(int int_cause, int bit_num, void *isr_ptr)
47 {
48         irq_handlers[int_cause][bit_num].routine = isr_ptr;
49 }
50
51
52 /*
53  * Enables the IRQ on Galileo Chip
54  *
55  * Inputs :
56  * int_cause - The interrupt cause number. In EVB64120 two parameters
57  *             are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
58  * bit_num   - Indicates which bit number in the cause register
59  *
60  * Outputs :
61  * 1 if succesful, 0 if failure
62  */
63 int enable_galileo_irq(int int_cause, int bit_num)
64 {
65         if (int_cause == INT_CAUSE_MAIN)
66                 SET_REG_BITS(CPU_INTERRUPT_MASK_REGISTER, (1 << bit_num));
67         else if (int_cause == INT_CAUSE_HIGH)
68                 SET_REG_BITS(CPU_HIGH_INTERRUPT_MASK_REGISTER,
69                              (1 << bit_num));
70         else
71                 return 0;
72
73         return 1;
74 }
75
76 /*
77  * Disables the IRQ on Galileo Chip
78  *
79  * Inputs :
80  * int_cause - The interrupt cause number. In EVB64120 two parameters
81  *             are declared, INT_CAUSE_MAIN and INT_CAUSE_HIGH.
82  * bit_num   - Indicates which bit number in the cause register
83  *
84  * Outputs :
85  * 1 if succesful, 0 if failure
86  */
87 int disable_galileo_irq(int int_cause, int bit_num)
88 {
89         if (int_cause == INT_CAUSE_MAIN)
90                 RESET_REG_BITS(CPU_INTERRUPT_MASK_REGISTER,
91                                (1 << bit_num));
92         else if (int_cause == INT_CAUSE_HIGH)
93                 RESET_REG_BITS(CPU_HIGH_INTERRUPT_MASK_REGISTER,
94                                (1 << bit_num));
95         else
96                 return 0;
97         return 1;
98 }
99 #endif                          /*  UNUSED  */
100
101 /*
102  * Interrupt handler for interrupts coming from the Galileo chip via P0_INT#.
103  *
104  * We route the timer interrupt to P0_INT# (IRQ 6), and that's all this
105  * routine can handle, for now.
106  *
107  * In the future, we'll route more interrupts to this pin, and that's why
108  * we keep this particular structure in the function.
109  */
110
111 static void gt64240_p0int_irq(int irq, void *dev_id, struct pt_regs *regs)
112 {
113         uint32_t irq_src, irq_src_mask;
114         int handled;
115
116         /* get the low interrupt cause register */
117         GT_READ(LOW_INTERRUPT_CAUSE_REGISTER, &irq_src);
118
119         /* get the mask register for this pin */
120         GT_READ(PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, &irq_src_mask);
121
122         /* mask off only the interrupts we're interested in */
123         irq_src = irq_src & irq_src_mask;
124
125         handled = 0;
126
127         /* Check for timer interrupt */
128         if (irq_src & 0x00000100) {
129                 handled = 1;
130                 irq_src &= ~0x00000100;
131
132                 /* Clear any pending cause bits */
133                 GT_WRITE(TIMER_COUNTER_0_3_INTERRUPT_CAUSE, 0x0);
134
135                 /* handle the timer call */
136                 do_timer(regs);
137         }
138
139         if (irq_src) {
140                 printk(KERN_INFO
141                        "UNKNOWN P0_INT# interrupt received, irq_src=0x%x\n",
142                        irq_src);
143         }
144 }
145
146 /*
147  * Interrupt handler for interrupts coming from the Galileo chip.
148  * It could be built in ethernet ports etc...
149  */
150 static void gt64240_irq(int irq, void *dev_id, struct pt_regs *regs)
151 {
152         unsigned int irq_src, int_high_src, irq_src_mask,
153             int_high_src_mask;
154         int handled;
155
156 #if 0
157         GT_READ(GT_INTRCAUSE_OFS, &irq_src);
158         GT_READ(GT_INTRMASK_OFS, &irq_src_mask);
159         GT_READ(GT_HINTRCAUSE_OFS, &int_high_src);
160         GT_READ(GT_HINTRMASK_OFS, &int_high_src_mask);
161 #endif
162         irq_src = irq_src & irq_src_mask;
163         int_high_src = int_high_src & int_high_src_mask;
164
165         handled = 0;
166
167         /* Execute all interrupt handlers */
168         /* Check for timer interrupt */
169         if (irq_src & 0x00000800) {
170                 handled = 1;
171                 irq_src &= ~0x00000800;
172                 //    RESET_REG_BITS (INTERRUPT_CAUSE_REGISTER,BIT8);
173                 do_timer(regs);
174         }
175
176         if (irq_src) {
177                 printk(KERN_INFO
178                        "Other Galileo interrupt received irq_src %x\n",
179                        irq_src);
180 #if CURRENTLY_UNUSED
181                 for (count = 0; count < MAX_CAUSE_REG_WIDTH; count++) {
182                         if (irq_src & (1 << count)) {
183                                 if (irq_handlers[INT_CAUSE_MAIN][count].
184                                     routine) {
185                                         queue_task(&irq_handlers
186                                                    [INT_CAUSE_MAIN][count],
187                                                    &tq_immediate);
188                                         mark_bh(IMMEDIATE_BH);
189                                         handled = 1;
190                                 }
191                         }
192                 }
193 #endif                          /*  UNUSED  */
194         }
195 #if 0
196         GT_WRITE(GT_INTRCAUSE_OFS, 0);
197         GT_WRITE(GT_HINTRCAUSE_OFS, 0);
198 #endif
199
200 #undef GALILEO_I2O
201 #ifdef GALILEO_I2O
202         /*
203          * Future I2O support.  We currently attach I2O interrupt handlers to
204          * the Galileo interrupt (int 4) and handle them in do_IRQ.
205          */
206         if (isInBoundDoorBellInterruptSet()) {
207                 printk(KERN_INFO "I2O doorbell interrupt received.\n");
208                 handled = 1;
209         }
210
211         if (isInBoundPostQueueInterruptSet()) {
212                 printk(KERN_INFO "I2O Queue interrupt received.\n");
213                 handled = 1;
214         }
215
216         /*
217          * This normally would be outside of the ifdef, but since we're
218          * handling I2O outside of this handler, this printk shows up every
219          * time we get a valid I2O interrupt.  So turn this off for now.
220          */
221         if (handled == 0) {
222                 if (counter < 50) {
223                         printk("Spurious Galileo interrupt...\n");
224                         counter++;
225                 }
226         }
227 #endif
228 }
229
230 /*
231  * Initializes timer using galileo's built in timer.
232  */
233
234 /*
235  * This will ignore the standard MIPS timer interrupt handler
236  * that is passed in as *irq (=irq0 in ../kernel/time.c).
237  * We will do our own timer interrupt handling.
238  */
239 void gt64240_time_init(void)
240 {
241         extern irq_desc_t irq_desc[NR_IRQS];
242         static struct irqaction timer;
243
244         /* Stop the timer -- we'll use timer #0 */
245         GT_WRITE(TIMER_COUNTER_0_3_CONTROL, 0x0);
246
247         /* Load timer value for 100 Hz */
248         GT_WRITE(TIMER_COUNTER0, bus_clock / 100);
249
250         /*
251          * Create the IRQ structure entry for the timer.  Since we're too early
252          * in the boot process to use the "request_irq()" call, we'll hard-code
253          * the values to the correct interrupt line.
254          */
255         timer.handler = &gt64240_p0int_irq;
256         timer.flags = SA_SHIRQ | SA_INTERRUPT;
257         timer.name = "timer";
258         timer.dev_id = NULL;
259         timer.next = NULL;
260         timer.mask = 0;
261         irq_desc[6].action = &timer;
262
263         enable_irq(6);
264
265         /* Clear any pending cause bits */
266         GT_WRITE(TIMER_COUNTER_0_3_INTERRUPT_CAUSE, 0x0);
267
268         /* Enable the interrupt for timer 0 */
269         GT_WRITE(TIMER_COUNTER_0_3_INTERRUPT_MASK, 0x1);
270
271         /* Enable the timer interrupt for GT-64240 pin P0_INT# */
272         GT_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0x100);
273
274         /* Configure and start the timer */
275         GT_WRITE(TIMER_COUNTER_0_3_CONTROL, 0x3);
276 }
277
278 void gt64240_irq_init(void)
279 {
280 #if CURRENTLY_UNUSED
281         int i, j;
282
283         /* Reset irq handlers pointers to NULL */
284         for (i = 0; i < MAX_CAUSE_REGS; i++) {
285                 for (j = 0; j < MAX_CAUSE_REG_WIDTH; j++) {
286                         irq_handlers[i][j].next = NULL;
287                         irq_handlers[i][j].sync = 0;
288                         irq_handlers[i][j].routine = NULL;
289                         irq_handlers[i][j].data = NULL;
290                 }
291         }
292 #endif
293 }