summaryrefslogtreecommitdiffstats
path: root/target/linux/brcm63xx/patches-2.6.25/060-bcm963xx_rewrite_irq_handling_code.patch
blob: 349010486f47d72f594dd528b30d7c29d5454af3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
From 9a70f2dcb24a5aab29386373c86ba035acba4891 Mon Sep 17 00:00:00 2001
From: Axel Gembe <ago@bastart.eu.org>
Date: Sun, 18 May 2008 12:07:21 +0200
Subject: [PATCH] bcm963xx: rewrite irq handling code

This patch adds interrupt handling as on AR7. The old code was very messy and
didn't work too well.

Signed-off-by: Axel Gembe <ago@bastart.eu.org>
---
 arch/mips/bcm963xx/irq.c                  |  308 ++++++++++-------------------
 drivers/serial/bcm63xx_cons.c             |   13 +-
 include/asm-mips/mach-bcm963xx/bcm_intr.h |   18 +--
 3 files changed, 119 insertions(+), 220 deletions(-)

--- a/arch/mips/bcm963xx/irq.c
+++ b/arch/mips/bcm963xx/irq.c
@@ -1,259 +1,159 @@
 /*
-<:copyright-gpl 
- Copyright 2002 Broadcom Corp. All Rights Reserved. 
- 
- This program is free software; you can distribute it and/or modify it 
- under the terms of the GNU General Public License (Version 2) as 
- published by the Free Software Foundation. 
- 
- This program is distributed in the hope it will be useful, but WITHOUT 
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
- for more details. 
- 
- You should have received a copy of the GNU General Public License along 
- with this program; if not, write to the Free Software Foundation, Inc., 
- 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. 
-:>
-*/
-/*
- * Interrupt control functions for Broadcom 963xx MIPS boards
+ * Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2006,2007 Eugene Konev <ejka@openwrt.org>
+ * Copyright (C) 2008 Axel Gembe <ago@bastart.eu.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <asm/atomic.h>
-
-#include <linux/delay.h>
-#include <linux/init.h>
-#include <linux/ioport.h>
-#include <linux/irq.h>
 #include <linux/interrupt.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/module.h>
+#include <linux/io.h>
 
-#include <asm/irq.h>
+#include <asm/irq_cpu.h>
 #include <asm/mipsregs.h>
-#include <asm/addrspace.h>
-#include <asm/signal.h>
+
 #include <6348_map_part.h>
 #include <6348_intr.h>
 #include <bcm_map_part.h>
 #include <bcm_intr.h>
 
-static void irq_dispatch_int(void)
-{
-	unsigned int pendingIrqs;
-	static unsigned int irqBit;
-	static unsigned int isrNumber = 31;
-
-	pendingIrqs = PERF->IrqStatus & PERF->IrqMask;
-	if (!pendingIrqs) {
-		return;
-	}
+static int bcm963xx_irq_base;
 
-	while (1) {
-	irqBit <<= 1;
-	isrNumber++;
-	if (isrNumber == 32) {
-		isrNumber = 0;
-		irqBit = 0x1;
-	}
-	if (pendingIrqs & irqBit) {
-			PERF->IrqMask &= ~irqBit; // mask
-			do_IRQ(isrNumber + INTERNAL_ISR_TABLE_OFFSET);
-		break;
-	}
-	}
+void bcm963xx_unmask_irq(unsigned int irq)
+{
+	PERF->IrqMask |= (1 << (irq - bcm963xx_irq_base));
 }
 
-static void irq_dispatch_ext(uint32 irq)
+void bcm963xx_mask_irq(unsigned int irq)
 {
-	if (!(PERF->ExtIrqCfg & (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT)))) {
-	printk("**** Ext IRQ mask. Should not dispatch ****\n");
-	}
-	/* disable and clear interrupt in the controller */
-	PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT));
-	PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
-	do_IRQ(irq);
+	PERF->IrqMask &= ~(1 << (irq - bcm963xx_irq_base));
 }
 
-
-//extern void brcm_timer_interrupt(struct pt_regs *regs);
-
-asmlinkage void plat_irq_dispatch(void)
+void bcm963xx_ack_irq(unsigned int irq)
 {
-	unsigned long cause;
-
-	cause = read_c0_status() & read_c0_cause() & ST0_IM;
-	if (cause & CAUSEF_IP7)
-		do_IRQ(7);
-	else if (cause & CAUSEF_IP2)
-		irq_dispatch_int();
-	else if (cause & CAUSEF_IP3)
-		irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_0);
-	else if (cause & CAUSEF_IP4)
-		irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_1);
-	else if (cause & CAUSEF_IP5)
-		irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_2);
-	else if (cause & CAUSEF_IP6) {
-		irq_dispatch_ext(INTERRUPT_ID_EXTERNAL_3);
-		local_irq_disable();
-	}
+	PERF->IrqStatus &= ~(1 << (irq - bcm963xx_irq_base));
 }
 
-
-void enable_brcm_irq(unsigned int irq)
+void bcm963xx_unmask_ext_irq(unsigned int irq)
 {
-	unsigned long flags;
-
-	local_irq_save(flags);
-	if( irq >= INTERNAL_ISR_TABLE_OFFSET ) {
-	PERF->IrqMask |= (1 << (irq - INTERNAL_ISR_TABLE_OFFSET));
-	}
-	else if (irq >= INTERRUPT_ID_EXTERNAL_0 && irq <= INTERRUPT_ID_EXTERNAL_3) {
-	/* enable and clear interrupt in the controller */
-	PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT));
 	PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
-	}
-	local_irq_restore(flags);
 }
 
-void disable_brcm_irq(unsigned int irq)
+void bcm963xx_mask_ext_irq(unsigned int irq)
 {
-	unsigned long flags;
-
-	local_irq_save(flags);
-	if( irq >= INTERNAL_ISR_TABLE_OFFSET ) {
-	PERF->IrqMask &= ~(1 << (irq - INTERNAL_ISR_TABLE_OFFSET));
-	}
-	else if (irq >= INTERRUPT_ID_EXTERNAL_0 && irq <= INTERRUPT_ID_EXTERNAL_3) {
-	/* disable interrupt in the controller */
 	PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));
-	}
-	local_irq_restore(flags);
 }
 
-void ack_brcm_irq(unsigned int irq)
+void bcm963xx_ack_ext_irq(unsigned int irq)
 {
-	/* Already done in brcm_irq_dispatch */
+	PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT));
 }
 
-unsigned int startup_brcm_irq(unsigned int irq)
+static void bcm963xx_dispatch_ext_irq(unsigned int irq)
 {
-	enable_brcm_irq(irq);
-
-	return 0; /* never anything pending */
+	bcm963xx_ack_ext_irq(irq);
+	bcm963xx_mask_ext_irq(irq);
+	do_IRQ(irq);
 }
 
-unsigned int startup_brcm_none(unsigned int irq)
+static void bcm963xx_cascade(void)
 {
-	return 0;
-}
+	uint32_t pending, bit, irq;
 
-void end_brcm_irq(unsigned int irq)
-{
-	if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
-		enable_brcm_irq(irq);
-}
+	if (!(pending = PERF->IrqStatus & PERF->IrqMask))
+		return;
 
-void end_brcm_none(unsigned int irq)
-{
-}
+	for (irq = 0, bit = 1; irq < 32; irq++, bit <<= 1) {
+		if (pending & bit) {
+			bcm963xx_ack_irq(irq + bcm963xx_irq_base);
+			bcm963xx_mask_irq(irq + bcm963xx_irq_base);
+			do_IRQ(irq + bcm963xx_irq_base);
+			return;
+		}
+	}
+
+	spurious_interrupt();
+}
+
+static struct irq_chip bcm963xx_irq_type = {
+	.name = "bcm963xx",
+	.unmask = bcm963xx_unmask_irq,
+	.mask = bcm963xx_mask_irq,
+	.ack = bcm963xx_ack_irq
+};
 
-static struct hw_interrupt_type brcm_irq_type = {
-	.typename	= "MIPS",
-	.startup	= startup_brcm_irq,
-	.shutdown	= disable_brcm_irq,
-	.enable	= enable_brcm_irq,
-	.disable	= disable_brcm_irq,
-	.ack	= ack_brcm_irq,
-	.end	= end_brcm_irq,
-	.set_affinity = NULL
+static struct irq_chip bcm963xx_ext_irq_type = {
+	.name = "bcm963xx_ext",
+	.unmask = bcm963xx_unmask_ext_irq,
+	.mask = bcm963xx_mask_ext_irq,
+	.ack = bcm963xx_ack_ext_irq,
 };
 
-static struct hw_interrupt_type brcm_irq_no_end_type = {
-	.typename	= "MIPS",
-	.startup	= startup_brcm_none,
-	.shutdown	= disable_brcm_irq,
-	.enable	= enable_brcm_irq,
-	.disable	= disable_brcm_irq,
-	.ack	= ack_brcm_irq,
-	.end	= end_brcm_none,
-	.set_affinity = NULL
+static struct irqaction bcm963xx_cascade_action = {
+	.handler = no_action,
+	.name = "BCM963xx cascade interrupt"
 };
 
-void __init arch_init_irq(void)
+static void __init bcm963xx_irq_init(int base)
 {
 	int i;
 
-	clear_c0_status(ST0_BEV);
-	change_c0_status(ST0_IM, (IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4));
+	bcm963xx_irq_base = base;
 
-	for (i = 0; i < NR_IRQS; i++) {
-		irq_desc[i].status = IRQ_DISABLED;
-		irq_desc[i].action = 0;
-		irq_desc[i].depth = 1;
-		irq_desc[i].chip = &brcm_irq_type;
-	}
+	/* External IRQs */
+	set_irq_chip_and_handler(INTERRUPT_ID_EXTERNAL_0, &bcm963xx_ext_irq_type,
+				 handle_level_irq);
+	set_irq_chip_and_handler(INTERRUPT_ID_EXTERNAL_1, &bcm963xx_ext_irq_type,
+				 handle_level_irq);
+	set_irq_chip_and_handler(INTERRUPT_ID_EXTERNAL_2, &bcm963xx_ext_irq_type,
+				 handle_level_irq);
+	set_irq_chip_and_handler(INTERRUPT_ID_EXTERNAL_3, &bcm963xx_ext_irq_type,
+				 handle_level_irq);
+
+	for (i = 0; i < 32; i++) {
+		set_irq_chip_and_handler(base + i, &bcm963xx_irq_type,
+					 handle_level_irq);
+	}
+
+	setup_irq(2, &bcm963xx_cascade_action);
+	setup_irq(bcm963xx_irq_base, &bcm963xx_cascade_action);
+	set_c0_status(IE_IRQ0);
 }
 
-int request_external_irq(unsigned int irq, 
-	FN_HANDLER handler,
-		unsigned long irqflags, 
-		const char * devname,
-		void *dev_id)
+asmlinkage void plat_irq_dispatch(void)
 {
-	unsigned long flags;
-
-	local_irq_save(flags);
+	unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
 
-	PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_CLEAR_SHFT));      // Clear
-	PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_MASK_SHFT));      // Mask
-	PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_INSENS_SHFT));    // Edge insesnsitive
-	PERF->ExtIrqCfg |= (1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_LEVEL_SHFT));      // Level triggered
-	PERF->ExtIrqCfg &= ~(1 << (irq - INTERRUPT_ID_EXTERNAL_0 + EI_SENSE_SHFT));     // Low level
-
-	local_irq_restore(flags);
-
-	return( request_irq(irq, handler, irqflags, devname, dev_id) );
+	if (pending & STATUSF_IP7)		/* cpu timer */
+		do_IRQ(7);
+	else if (pending & STATUSF_IP2)		/* internal interrupt cascade */
+		bcm963xx_cascade();
+	else if (pending & STATUSF_IP3)
+		bcm963xx_dispatch_ext_irq(INTERRUPT_ID_EXTERNAL_0);
+	else if (pending & STATUSF_IP4)
+		bcm963xx_dispatch_ext_irq(INTERRUPT_ID_EXTERNAL_1);
+	else if (pending & STATUSF_IP5)
+		bcm963xx_dispatch_ext_irq(INTERRUPT_ID_EXTERNAL_2);
+	else if (pending & STATUSF_IP6)
+		bcm963xx_dispatch_ext_irq(INTERRUPT_ID_EXTERNAL_3);
+	else
+		spurious_interrupt();
 }
 
-/* VxWorks compatibility function(s). */
-
-unsigned int BcmHalMapInterrupt(FN_HANDLER pfunc, unsigned int param,
-	unsigned int interruptId)
+void __init arch_init_irq(void)
 {
-	int nRet = -1;
-	char *devname;
-
-	devname = kmalloc(16, GFP_KERNEL);
-	if (devname)
-		sprintf( devname, "brcm_%d", interruptId );
-
-	/* Set the IRQ description to not automatically enable the interrupt at
-	 * the end of an ISR.  The driver that handles the interrupt must
-	 * explicitly call BcmHalInterruptEnable or enable_brcm_irq.  This behavior
-	 * is consistent with interrupt handling on VxWorks.
-	 */
-	irq_desc[interruptId].chip = &brcm_irq_no_end_type;
-
-	if( interruptId >= INTERNAL_ISR_TABLE_OFFSET )
-	{	
-		printk("BcmHalMapInterrupt : internal IRQ\n");
-		nRet = request_irq( interruptId, pfunc, IRQF_DISABLED, devname, (void *) param );
-	}
-	else if (interruptId >= INTERRUPT_ID_EXTERNAL_0 && interruptId <= INTERRUPT_ID_EXTERNAL_3)
-	{
-		printk("BcmHalMapInterrupt : external IRQ\n");
-		nRet = request_external_irq( interruptId, pfunc, IRQF_DISABLED, devname, (void *) param );
-	}
-
-	return( nRet );
+	mips_cpu_irq_init();
+	bcm963xx_irq_init(INTERNAL_ISR_TABLE_OFFSET);
 }
-
-
-EXPORT_SYMBOL(enable_brcm_irq);
-EXPORT_SYMBOL(disable_brcm_irq);
-EXPORT_SYMBOL(request_external_irq);
-EXPORT_SYMBOL(BcmHalMapInterrupt);
-
--- a/drivers/serial/bcm63xx_cons.c
+++ b/drivers/serial/bcm63xx_cons.c
@@ -267,7 +267,7 @@
 	}
 
 	// Clear the interrupt
-	enable_brcm_irq(INTERRUPT_ID_UART);
+//	bcm963xx_unmask_irq(INTERRUPT_ID_UART);
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
 	return IRQ_HANDLED;
 #endif
@@ -880,7 +880,7 @@
 	info->count++;
 	tty->driver_data = info;
 	info->tty = tty;
-	enable_brcm_irq(INTERRUPT_ID_UART);
+	bcm963xx_unmask_irq(INTERRUPT_ID_UART);
 
 	// Start up serial port
 	retval = startup(info);
@@ -927,7 +927,7 @@
 -------------------------------------------------------------------------- */
 static int __init bcm63xx_serialinit(void)
 {
-	int i, flags;
+	int i, flags, res;
 	struct bcm_serial *info;
 
 	// Print the driver version information
@@ -981,7 +981,12 @@
 		 */
 		if (!info->port)
 			return 0;
-		BcmHalMapInterrupt(bcm_interrupt, 0, INTERRUPT_ID_UART);
+
+		res = request_irq(INTERRUPT_ID_UART, bcm_interrupt, 0, "bcm-uart", NULL);
+		if (res) {
+			spin_unlock_irqrestore(&bcm963xx_serial_lock, flags);
+			return res;
+		}
 	}
 
 	/* order matters here... the trick is that flags
--- a/include/asm-mips/mach-bcm963xx/bcm_intr.h
+++ b/include/asm-mips/mach-bcm963xx/bcm_intr.h
@@ -39,18 +39,12 @@
 typedef int (*FN_HANDLER) (int, void *);
 
 /* prototypes */
-extern void enable_brcm_irq(unsigned int irq);
-extern void disable_brcm_irq(unsigned int irq);
-extern int request_external_irq(unsigned int irq,
-    FN_HANDLER handler, unsigned long irqflags, 
-    const char * devname, void *dev_id);
-extern unsigned int BcmHalMapInterrupt(FN_HANDLER isr, unsigned int param,
-    unsigned int interruptId);
-extern void dump_intr_regs(void);
-
-/* compatibility definitions */
-#define BcmHalInterruptEnable(irq)      enable_brcm_irq( irq )
-#define BcmHalInterruptDisable(irq)     disable_brcm_irq( irq )
+extern void bcm963xx_unmask_irq(unsigned int irq);
+extern void bcm963xx_mask_irq(unsigned int irq);
+extern void bcm963xx_ack_irq(unsigned int irq);
+extern void bcm963xx_unmask_ext_irq(unsigned int irq);
+extern void bcm963xx_mask_ext_irq(unsigned int irq);
+extern void bcm963xx_ack_ext_irq(unsigned int irq);
 
 #ifdef __cplusplus
     }