irq.c 4.79 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
2
/* irq.c: FRV IRQ handling
 *
3
 * Copyright (C) 2003, 2004, 2006 Red Hat, Inc. All Rights Reserved.
Linus Torvalds's avatar
Linus Torvalds committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * Written by David Howells (dhowells@redhat.com)
 *
 * 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.
 */

#include <linux/ptrace.h>
#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/timex.h>
#include <linux/slab.h>
#include <linux/random.h>
#include <linux/init.h>
#include <linux/kernel_stat.h>
#include <linux/irq.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
26
#include <linux/module.h>
Jiri Slaby's avatar
Jiri Slaby committed
27
#include <linux/bitops.h>
Linus Torvalds's avatar
Linus Torvalds committed
28
29
30
31
32
33
34
35
36
37
38
39

#include <asm/atomic.h>
#include <asm/io.h>
#include <asm/smp.h>
#include <asm/system.h>
#include <asm/uaccess.h>
#include <asm/pgalloc.h>
#include <asm/delay.h>
#include <asm/irq.h>
#include <asm/irc-regs.h>
#include <asm/gdb-stub.h>

40
#define set_IRR(N,A,B,C,D) __set_IRR(N, (A << 28) | (B << 24) | (C << 20) | (D << 16))
Linus Torvalds's avatar
Linus Torvalds committed
41

42
43
44
45
extern void __init fpga_init(void);
#ifdef CONFIG_FUJITSU_MB93493
extern void __init mb93493_init(void);
#endif
Linus Torvalds's avatar
Linus Torvalds committed
46

47
#define __reg16(ADDR) (*(volatile unsigned short *)(ADDR))
Linus Torvalds's avatar
Linus Torvalds committed
48
49
50
51
52
53
54
55

atomic_t irq_err_count;

/*
 * Generic, controller-independent functions:
 */
int show_interrupts(struct seq_file *p, void *v)
{
56
57
	int i = *(loff_t *) v, cpu;
	struct irqaction * action;
Linus Torvalds's avatar
Linus Torvalds committed
58
59
	unsigned long flags;

60
61
	if (i == 0) {
		char cpuname[12];
Linus Torvalds's avatar
Linus Torvalds committed
62

63
64
65
66
67
		seq_printf(p, "    ");
		for_each_present_cpu(cpu) {
			sprintf(cpuname, "CPU%d", cpu);
			seq_printf(p, " %10s", cpuname);
		}
Linus Torvalds's avatar
Linus Torvalds committed
68
		seq_putc(p, '\n');
69
	}
Linus Torvalds's avatar
Linus Torvalds committed
70

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	if (i < NR_IRQS) {
		spin_lock_irqsave(&irq_desc[i].lock, flags);
		action = irq_desc[i].action;
		if (action) {
			seq_printf(p, "%3d: ", i);
			for_each_present_cpu(cpu)
				seq_printf(p, "%10u ", kstat_cpu(cpu).irqs[i]);
			seq_printf(p, " %10s", irq_desc[i].chip->name ? : "-");
			seq_printf(p, "  %s", action->name);
			for (action = action->next;
			     action;
			     action = action->next)
				seq_printf(p, ", %s", action->name);

			seq_putc(p, '\n');
		}
Linus Torvalds's avatar
Linus Torvalds committed
87

88
89
90
		spin_unlock_irqrestore(&irq_desc[i].lock, flags);
	} else if (i == NR_IRQS) {
		seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
Linus Torvalds's avatar
Linus Torvalds committed
91
92
93
94
95
96
	}

	return 0;
}

/*
97
 * on-CPU PIC operations
Linus Torvalds's avatar
Linus Torvalds committed
98
 */
99
static void frv_cpupic_ack(unsigned int irqlevel)
Linus Torvalds's avatar
Linus Torvalds committed
100
{
101
102
103
	__clr_RC(irqlevel);
	__clr_IRL();
}
Linus Torvalds's avatar
Linus Torvalds committed
104

105
106
107
108
static void frv_cpupic_mask(unsigned int irqlevel)
{
	__set_MASK(irqlevel);
}
Linus Torvalds's avatar
Linus Torvalds committed
109

110
111
112
113
114
115
static void frv_cpupic_mask_ack(unsigned int irqlevel)
{
	__set_MASK(irqlevel);
	__clr_RC(irqlevel);
	__clr_IRL();
}
Linus Torvalds's avatar
Linus Torvalds committed
116

117
118
119
120
static void frv_cpupic_unmask(unsigned int irqlevel)
{
	__clr_MASK(irqlevel);
}
Linus Torvalds's avatar
Linus Torvalds committed
121

122
123
124
static void frv_cpupic_end(unsigned int irqlevel)
{
	__clr_MASK(irqlevel);
Linus Torvalds's avatar
Linus Torvalds committed
125
126
}

127
128
129
130
131
132
133
134
static struct irq_chip frv_cpu_pic = {
	.name		= "cpu",
	.ack		= frv_cpupic_ack,
	.mask		= frv_cpupic_mask,
	.mask_ack	= frv_cpupic_mask_ack,
	.unmask		= frv_cpupic_unmask,
	.end		= frv_cpupic_end,
};
135

Linus Torvalds's avatar
Linus Torvalds committed
136
/*
Simon Arlott's avatar
Simon Arlott committed
137
 * handles all normal device IRQs
Linus Torvalds's avatar
Linus Torvalds committed
138
139
140
141
142
143
 * - registers are referred to by the __frame variable (GR28)
 * - IRQ distribution is complicated in this arch because of the many PICs, the
 *   way they work and the way they cascade
 */
asmlinkage void do_IRQ(void)
{
144
	irq_enter();
145
	generic_handle_irq(__get_IRL());
146
	irq_exit();
147
}
Linus Torvalds's avatar
Linus Torvalds committed
148
149
150
151
152
153
154
155
156
157

/*
 * handles all NMIs when not co-opted by the debugger
 * - registers are referred to by the __frame variable (GR28)
 */
asmlinkage void do_NMI(void)
{
}

/*
158
 * initialise the interrupt system
Linus Torvalds's avatar
Linus Torvalds committed
159
 */
160
void __init init_IRQ(void)
Linus Torvalds's avatar
Linus Torvalds committed
161
{
162
	int level;
Linus Torvalds's avatar
Linus Torvalds committed
163

164
165
166
	for (level = 1; level <= 14; level++)
		set_irq_chip_and_handler(level, &frv_cpu_pic,
					 handle_level_irq);
Linus Torvalds's avatar
Linus Torvalds committed
167

168
	set_irq_handler(IRQ_CPU_TIMER0, handle_edge_irq);
Linus Torvalds's avatar
Linus Torvalds committed
169

170
171
172
173
	/* set the trigger levels for internal interrupt sources
	 * - timers all falling-edge
	 * - ERR0 is rising-edge
	 * - all others are high-level
Linus Torvalds's avatar
Linus Torvalds committed
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
	__set_IITMR(0, 0x003f0000);	/* DMA0-3, TIMER0-2 */
	__set_IITMR(1, 0x20000000);	/* ERR0-1, UART0-1, DMA4-7 */

	/* route internal interrupts */
	set_IRR(4, IRQ_DMA3_LEVEL, IRQ_DMA2_LEVEL, IRQ_DMA1_LEVEL,
		IRQ_DMA0_LEVEL);
	set_IRR(5, 0, IRQ_TIMER2_LEVEL, IRQ_TIMER1_LEVEL, IRQ_TIMER0_LEVEL);
	set_IRR(6, IRQ_GDBSTUB_LEVEL, IRQ_GDBSTUB_LEVEL,
		IRQ_UART1_LEVEL, IRQ_UART0_LEVEL);
	set_IRR(7, IRQ_DMA7_LEVEL, IRQ_DMA6_LEVEL, IRQ_DMA5_LEVEL,
		IRQ_DMA4_LEVEL);

	/* route external interrupts */
	set_IRR(2, IRQ_XIRQ7_LEVEL, IRQ_XIRQ6_LEVEL, IRQ_XIRQ5_LEVEL,
		IRQ_XIRQ4_LEVEL);
	set_IRR(3, IRQ_XIRQ3_LEVEL, IRQ_XIRQ2_LEVEL, IRQ_XIRQ1_LEVEL,
		IRQ_XIRQ0_LEVEL);

#if defined(CONFIG_MB93091_VDK)
	__set_TM1(0x55550000);		/* XIRQ7-0 all active low */
#elif defined(CONFIG_MB93093_PDK)
	__set_TM1(0x15550000);		/* XIRQ7 active high, 6-0 all active low */
#else
#error dont know external IRQ trigger levels for this setup
#endif
Linus Torvalds's avatar
Linus Torvalds committed
200
201
202

	fpga_init();
#ifdef CONFIG_FUJITSU_MB93493
203
	mb93493_init();
Linus Torvalds's avatar
Linus Torvalds committed
204
#endif
205
}