summaryrefslogtreecommitdiffstats
path: root/arch/frv/kernel/irq-routing.c
blob: 53886adf47de8afd361c1db698e8f0883f24ca0a (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
/* irq-routing.c: IRQ routing
 *
 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
 * 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/sched.h>
#include <linux/random.h>
#include <linux/init.h>
#include <linux/serial_reg.h>
#include <asm/io.h>
#include <asm/irq-routing.h>
#include <asm/irc-regs.h>
#include <asm/serial-regs.h>
#include <asm/dma.h>

struct irq_level frv_irq_levels[16] = {
	[0 ... 15] = {
		.lock	= SPIN_LOCK_UNLOCKED,
	}
};

struct irq_group *irq_groups[NR_IRQ_GROUPS];

extern struct irq_group frv_cpu_irqs;

void __init frv_irq_route(struct irq_source *source, int irqlevel)
{
	source->level = &frv_irq_levels[irqlevel];
	source->next = frv_irq_levels[irqlevel].sources;
	frv_irq_levels[irqlevel].sources = source;
}

void __init frv_irq_route_external(struct irq_source *source, int irq)
{
	int irqlevel = 0;

	switch (irq) {
	case IRQ_CPU_EXTERNAL0:	irqlevel = IRQ_XIRQ0_LEVEL; break;
	case IRQ_CPU_EXTERNAL1:	irqlevel = IRQ_XIRQ1_LEVEL; break;
	case IRQ_CPU_EXTERNAL2:	irqlevel = IRQ_XIRQ2_LEVEL; break;
	case IRQ_CPU_EXTERNAL3:	irqlevel = IRQ_XIRQ3_LEVEL; break;
	case IRQ_CPU_EXTERNAL4:	irqlevel = IRQ_XIRQ4_LEVEL; break;
	case IRQ_CPU_EXTERNAL5:	irqlevel = IRQ_XIRQ5_LEVEL; break;
	case IRQ_CPU_EXTERNAL6:	irqlevel = IRQ_XIRQ6_LEVEL; break;
	case IRQ_CPU_EXTERNAL7:	irqlevel = IRQ_XIRQ7_LEVEL; break;
	default: BUG();
	}

	source->level = &frv_irq_levels[irqlevel];
	source->next = frv_irq_levels[irqlevel].sources;
	frv_irq_levels[irqlevel].sources = source;
}

void __init frv_irq_set_group(struct irq_group *group)
{
	irq_groups[group->first_irq >> NR_IRQ_LOG2_ACTIONS_PER_GROUP] = group;
}

void distribute_irqs(struct irq_group *group, unsigned long irqmask)
{
	struct irqaction *action;
	int irq;

	while (irqmask) {
		asm("scan %1,gr0,%0" : "=r"(irq) : "r"(irqmask));
		if (irq < 0 || irq > 31)
			asm volatile("break");
		irq = 31 - irq;

		irqmask &= ~(1 << irq);
		action = group->actions[irq];

		irq += group->first_irq;

		if (action) {
			int status = 0;

//			if (!(action->flags & IRQF_DISABLED))
//				local_irq_enable();

			do {
				status |= action->flags;
				action->handler(irq, action->dev_id, __frame);
				action = action->next;
			} while (action);

			if (status & IRQF_SAMPLE_RANDOM)
				add_interrupt_randomness(irq);
			local_irq_disable();
		}
	}
}

/*****************************************************************************/
/*
 * CPU UART interrupts
 */
static void frv_cpuuart_doirq(struct irq_source *source)
{
//	uint8_t iir = readb(source->muxdata + UART_IIR * 8);
//	if ((iir & 0x0f) != UART_IIR_NO_INT)
		distribute_irqs(&frv_cpu_irqs, source->irqmask);
}

struct irq_source frv_cpuuart[2] = {
#define __CPUUART(X, A)						\
	[X] = {							\
		.muxname	= "uart",			\
		.muxdata	= (volatile void __iomem *)(unsigned long)A,\
		.irqmask	= 1 << IRQ_CPU_UART##X,		\
		.doirq		= frv_cpuuart_doirq,		\
	}

	__CPUUART(0, UART0_BASE),
	__CPUUART(1, UART1_BASE),
};

/*****************************************************************************/
/*
 * CPU DMA interrupts
 */
static void frv_cpudma_doirq(struct irq_source *source)
{
	uint32_t cstr = readl(source->muxdata + DMAC_CSTRx);
	if (cstr & DMAC_CSTRx_INT)
		distribute_irqs(&frv_cpu_irqs, source->irqmask);
}

struct irq_source frv_cpudma[8] = {
#define __CPUDMA(X, A)						\
	[X] = {							\
		.muxname	= "dma",			\
		.muxdata	= (volatile void __iomem *)(unsigned long)A,\
		.irqmask	= 1 << IRQ_CPU_DMA##X,		\
		.doirq		= frv_cpudma_doirq,		\
	}

	__CPUDMA(0, 0xfe000900),
	__CPUDMA(1, 0xfe000980),
	__CPUDMA(2, 0xfe000a00),
	__CPUDMA(3, 0xfe000a80),
	__CPUDMA(4, 0xfe001000),
	__CPUDMA(5, 0xfe001080),
	__CPUDMA(6, 0xfe001100),
	__CPUDMA(7, 0xfe001180),
};

/*****************************************************************************/
/*
 * CPU timer interrupts - can't tell whether they've generated an interrupt or not
 */
static void frv_cputimer_doirq(struct irq_source *source)
{
	distribute_irqs(&frv_cpu_irqs, source->irqmask);
}

struct irq_source frv_cputimer[3] = {
#define __CPUTIMER(X)						\
	[X] = {							\
		.muxname	= "timer",			\
		.muxdata	= NULL,				\
		.irqmask	= 1 << IRQ_CPU_TIMER##X,	\
		.doirq		= frv_cputimer_doirq,		\
	}

	__CPUTIMER(0),
	__CPUTIMER(1),
	__CPUTIMER(2),
};

/*****************************************************************************/
/*
 * external CPU interrupts - can't tell directly whether they've generated an interrupt or not
 */
static void frv_cpuexternal_doirq(struct irq_source *source)
{
	distribute_irqs(&frv_cpu_irqs, source->irqmask);
}

struct irq_source frv_cpuexternal[8] = {
#define __CPUEXTERNAL(X)					\
	[X] = {							\
		.muxname	= "ext",			\
		.muxdata	= NULL,				\
		.irqmask	= 1 << IRQ_CPU_EXTERNAL##X,	\
		.doirq		= frv_cpuexternal_doirq,	\
	}

	__CPUEXTERNAL(0),
	__CPUEXTERNAL(1),
	__CPUEXTERNAL(2),
	__CPUEXTERNAL(3),
	__CPUEXTERNAL(4),
	__CPUEXTERNAL(5),
	__CPUEXTERNAL(6),
	__CPUEXTERNAL(7),
};

#define set_IRR(N,A,B,C,D) __set_IRR(N, (A << 28) | (B << 24) | (C << 20) | (D << 16))

struct irq_group frv_cpu_irqs = {
	.sources = {
		[IRQ_CPU_UART0]		= &frv_cpuuart[0],
		[IRQ_CPU_UART1]		= &frv_cpuuart[1],
		[IRQ_CPU_TIMER0]	= &frv_cputimer[0],
		[IRQ_CPU_TIMER1]	= &frv_cputimer[1],
		[IRQ_CPU_TIMER2]	= &frv_cputimer[2],
		[IRQ_CPU_DMA0]		= &frv_cpudma[0],
		[IRQ_CPU_DMA1]		= &frv_cpudma[1],
		[IRQ_CPU_DMA2]		= &frv_cpudma[2],
		[IRQ_CPU_DMA3]		= &frv_cpudma[3],
		[IRQ_CPU_DMA4]		= &frv_cpudma[4],
		[IRQ_CPU_DMA5]		= &frv_cpudma[5],
		[IRQ_CPU_DMA6]		= &frv_cpudma[6],
		[IRQ_CPU_DMA7]		= &frv_cpudma[7],
		[IRQ_CPU_EXTERNAL0]	= &frv_cpuexternal[0],
		[IRQ_CPU_EXTERNAL1]	= &frv_cpuexternal[1],
		[IRQ_CPU_EXTERNAL2]	= &frv_cpuexternal[2],
		[IRQ_CPU_EXTERNAL3]	= &frv_cpuexternal[3],
		[IRQ_CPU_EXTERNAL4]	= &frv_cpuexternal[4],
		[IRQ_CPU_EXTERNAL5]	= &frv_cpuexternal[5],
		[IRQ_CPU_EXTERNAL6]	= &frv_cpuexternal[6],
		[IRQ_CPU_EXTERNAL7]	= &frv_cpuexternal[7],
	},
};

/*****************************************************************************/
/*
 * route the CPU's interrupt sources
 */
void __init route_cpu_irqs(void)
{
	frv_irq_set_group(&frv_cpu_irqs);

	__set_IITMR(0, 0x003f0000);	/* DMA0-3, TIMER0-2 IRQ detect levels */
	__set_IITMR(1, 0x20000000);	/* ERR0-1, UART0-1, DMA4-7 IRQ detect levels */

	/* route UART and error interrupts */
	frv_irq_route(&frv_cpuuart[0],	IRQ_UART0_LEVEL);
	frv_irq_route(&frv_cpuuart[1],	IRQ_UART1_LEVEL);

	set_IRR(6, IRQ_GDBSTUB_LEVEL, IRQ_GDBSTUB_LEVEL, IRQ_UART1_LEVEL, IRQ_UART0_LEVEL);

	/* route DMA channel interrupts */
	frv_irq_route(&frv_cpudma[0],	IRQ_DMA0_LEVEL);
	frv_irq_route(&frv_cpudma[1],	IRQ_DMA1_LEVEL);
	frv_irq_route(&frv_cpudma[2],	IRQ_DMA2_LEVEL);
	frv_irq_route(&frv_cpudma[3],	IRQ_DMA3_LEVEL);
	frv_irq_route(&frv_cpudma[4],	IRQ_DMA4_LEVEL);
	frv_irq_route(&frv_cpudma[5],	IRQ_DMA5_LEVEL);
	frv_irq_route(&frv_cpudma[6],	IRQ_DMA6_LEVEL);
	frv_irq_route(&frv_cpudma[7],	IRQ_DMA7_LEVEL);

	set_IRR(4, IRQ_DMA3_LEVEL, IRQ_DMA2_LEVEL, IRQ_DMA1_LEVEL, IRQ_DMA0_LEVEL);
	set_IRR(7, IRQ_DMA7_LEVEL, IRQ_DMA6_LEVEL, IRQ_DMA5_LEVEL, IRQ_DMA4_LEVEL);

	/* route timer interrupts */
	frv_irq_route(&frv_cputimer[0],	IRQ_TIMER0_LEVEL);
	frv_irq_route(&frv_cputimer[1],	IRQ_TIMER1_LEVEL);
	frv_irq_route(&frv_cputimer[2],	IRQ_TIMER2_LEVEL);

	set_IRR(5, 0, IRQ_TIMER2_LEVEL, IRQ_TIMER1_LEVEL, IRQ_TIMER0_LEVEL);

	/* route external interrupts */
	frv_irq_route(&frv_cpuexternal[0], IRQ_XIRQ0_LEVEL);
	frv_irq_route(&frv_cpuexternal[1], IRQ_XIRQ1_LEVEL);
	frv_irq_route(&frv_cpuexternal[2], IRQ_XIRQ2_LEVEL);
	frv_irq_route(&frv_cpuexternal[3], IRQ_XIRQ3_LEVEL);
	frv_irq_route(&frv_cpuexternal[4], IRQ_XIRQ4_LEVEL);
	frv_irq_route(&frv_cpuexternal[5], IRQ_XIRQ5_LEVEL);
	frv_irq_route(&frv_cpuexternal[6], IRQ_XIRQ6_LEVEL);
	frv_irq_route(&frv_cpuexternal[7], IRQ_XIRQ7_LEVEL);

	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

} /* end route_cpu_irqs() */