xref: /openbmc/linux/arch/mips/lantiq/irq.c (revision f97e5e8ef8e18b7a2799068880cc3e5b10ac4efc)
1171bb2f1SJohn Crispin /*
2171bb2f1SJohn Crispin  *  This program is free software; you can redistribute it and/or modify it
3171bb2f1SJohn Crispin  *  under the terms of the GNU General Public License version 2 as published
4171bb2f1SJohn Crispin  *  by the Free Software Foundation.
5171bb2f1SJohn Crispin  *
697b92108SJohn Crispin  * Copyright (C) 2010 John Crispin <john@phrozen.org>
7171bb2f1SJohn Crispin  * Copyright (C) 2010 Thomas Langer <thomas.langer@lantiq.com>
8171bb2f1SJohn Crispin  */
9171bb2f1SJohn Crispin 
10171bb2f1SJohn Crispin #include <linux/interrupt.h>
11171bb2f1SJohn Crispin #include <linux/ioport.h>
123645da02SJohn Crispin #include <linux/sched.h>
133645da02SJohn Crispin #include <linux/irqdomain.h>
143645da02SJohn Crispin #include <linux/of_platform.h>
153645da02SJohn Crispin #include <linux/of_address.h>
163645da02SJohn Crispin #include <linux/of_irq.h>
17171bb2f1SJohn Crispin 
18171bb2f1SJohn Crispin #include <asm/bootinfo.h>
19171bb2f1SJohn Crispin #include <asm/irq_cpu.h>
20171bb2f1SJohn Crispin 
21171bb2f1SJohn Crispin #include <lantiq_soc.h>
22171bb2f1SJohn Crispin #include <irq.h>
23171bb2f1SJohn Crispin 
243645da02SJohn Crispin /* register definitions - internal irqs */
25171bb2f1SJohn Crispin #define LTQ_ICU_IM0_ISR		0x0000
26171bb2f1SJohn Crispin #define LTQ_ICU_IM0_IER		0x0008
27171bb2f1SJohn Crispin #define LTQ_ICU_IM0_IOSR	0x0010
28171bb2f1SJohn Crispin #define LTQ_ICU_IM0_IRSR	0x0018
29171bb2f1SJohn Crispin #define LTQ_ICU_IM0_IMR		0x0020
30171bb2f1SJohn Crispin #define LTQ_ICU_IM1_ISR		0x0028
31171bb2f1SJohn Crispin #define LTQ_ICU_OFFSET		(LTQ_ICU_IM1_ISR - LTQ_ICU_IM0_ISR)
32171bb2f1SJohn Crispin 
333645da02SJohn Crispin /* register definitions - external irqs */
34171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_C		0x0000
35171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_INIC	0x0004
3626365625SJohn Crispin #define LTQ_EIU_EXIN_INC	0x0008
37171bb2f1SJohn Crispin #define LTQ_EIU_EXIN_INEN	0x000C
38171bb2f1SJohn Crispin 
3926365625SJohn Crispin /* number of external interrupts */
40171bb2f1SJohn Crispin #define MAX_EIU			6
41171bb2f1SJohn Crispin 
4259c11579SJohn Crispin /* the performance counter */
4359c11579SJohn Crispin #define LTQ_PERF_IRQ		(INT_NUM_IM4_IRL0 + 31)
4459c11579SJohn Crispin 
453645da02SJohn Crispin /*
463645da02SJohn Crispin  * irqs generated by devices attached to the EBU need to be acked in
47171bb2f1SJohn Crispin  * a special manner
48171bb2f1SJohn Crispin  */
49171bb2f1SJohn Crispin #define LTQ_ICU_EBU_IRQ		22
50171bb2f1SJohn Crispin 
5161fa969fSJohn Crispin #define ltq_icu_w32(m, x, y)	ltq_w32((x), ltq_icu_membase[m] + (y))
5261fa969fSJohn Crispin #define ltq_icu_r32(m, x)	ltq_r32(ltq_icu_membase[m] + (x))
53171bb2f1SJohn Crispin 
54171bb2f1SJohn Crispin #define ltq_eiu_w32(x, y)	ltq_w32((x), ltq_eiu_membase + (y))
55171bb2f1SJohn Crispin #define ltq_eiu_r32(x)		ltq_r32(ltq_eiu_membase + (x))
56171bb2f1SJohn Crispin 
57a8d096efSJohn Crispin /* our 2 ipi interrupts for VSMP */
58a8d096efSJohn Crispin #define MIPS_CPU_IPI_RESCHED_IRQ	0
59a8d096efSJohn Crispin #define MIPS_CPU_IPI_CALL_IRQ		1
60a8d096efSJohn Crispin 
613645da02SJohn Crispin /* we have a cascade of 8 irqs */
623645da02SJohn Crispin #define MIPS_CPU_IRQ_CASCADE		8
633645da02SJohn Crispin 
64b633648cSRalf Baechle #ifdef CONFIG_MIPS_MT_SMP
65a8d096efSJohn Crispin int gic_present;
66a8d096efSJohn Crispin #endif
67a8d096efSJohn Crispin 
683645da02SJohn Crispin static int exin_avail;
69fe46e503SJohn Crispin static u32 ltq_eiu_irq[MAX_EIU];
7061fa969fSJohn Crispin static void __iomem *ltq_icu_membase[MAX_IM];
71171bb2f1SJohn Crispin static void __iomem *ltq_eiu_membase;
72c2c9c788SJohn Crispin static struct irq_domain *ltq_domain;
73a669efc4SAndrew Bresticker static int ltq_perfcount_irq;
74171bb2f1SJohn Crispin 
7526365625SJohn Crispin int ltq_eiu_get_irq(int exin)
7626365625SJohn Crispin {
7726365625SJohn Crispin 	if (exin < exin_avail)
78fe46e503SJohn Crispin 		return ltq_eiu_irq[exin];
7926365625SJohn Crispin 	return -1;
8026365625SJohn Crispin }
8126365625SJohn Crispin 
82171bb2f1SJohn Crispin void ltq_disable_irq(struct irq_data *d)
83171bb2f1SJohn Crispin {
84171bb2f1SJohn Crispin 	u32 ier = LTQ_ICU_IM0_IER;
853645da02SJohn Crispin 	int offset = d->hwirq - MIPS_CPU_IRQ_CASCADE;
8661fa969fSJohn Crispin 	int im = offset / INT_NUM_IM_OFFSET;
87171bb2f1SJohn Crispin 
883645da02SJohn Crispin 	offset %= INT_NUM_IM_OFFSET;
8961fa969fSJohn Crispin 	ltq_icu_w32(im, ltq_icu_r32(im, ier) & ~BIT(offset), ier);
90171bb2f1SJohn Crispin }
91171bb2f1SJohn Crispin 
92171bb2f1SJohn Crispin void ltq_mask_and_ack_irq(struct irq_data *d)
93171bb2f1SJohn Crispin {
94171bb2f1SJohn Crispin 	u32 ier = LTQ_ICU_IM0_IER;
95171bb2f1SJohn Crispin 	u32 isr = LTQ_ICU_IM0_ISR;
963645da02SJohn Crispin 	int offset = d->hwirq - MIPS_CPU_IRQ_CASCADE;
9761fa969fSJohn Crispin 	int im = offset / INT_NUM_IM_OFFSET;
98171bb2f1SJohn Crispin 
993645da02SJohn Crispin 	offset %= INT_NUM_IM_OFFSET;
10061fa969fSJohn Crispin 	ltq_icu_w32(im, ltq_icu_r32(im, ier) & ~BIT(offset), ier);
10161fa969fSJohn Crispin 	ltq_icu_w32(im, BIT(offset), isr);
102171bb2f1SJohn Crispin }
103171bb2f1SJohn Crispin 
104171bb2f1SJohn Crispin static void ltq_ack_irq(struct irq_data *d)
105171bb2f1SJohn Crispin {
106171bb2f1SJohn Crispin 	u32 isr = LTQ_ICU_IM0_ISR;
1073645da02SJohn Crispin 	int offset = d->hwirq - MIPS_CPU_IRQ_CASCADE;
10861fa969fSJohn Crispin 	int im = offset / INT_NUM_IM_OFFSET;
109171bb2f1SJohn Crispin 
1103645da02SJohn Crispin 	offset %= INT_NUM_IM_OFFSET;
11161fa969fSJohn Crispin 	ltq_icu_w32(im, BIT(offset), isr);
112171bb2f1SJohn Crispin }
113171bb2f1SJohn Crispin 
114171bb2f1SJohn Crispin void ltq_enable_irq(struct irq_data *d)
115171bb2f1SJohn Crispin {
116171bb2f1SJohn Crispin 	u32 ier = LTQ_ICU_IM0_IER;
1173645da02SJohn Crispin 	int offset = d->hwirq - MIPS_CPU_IRQ_CASCADE;
11861fa969fSJohn Crispin 	int im = offset / INT_NUM_IM_OFFSET;
119171bb2f1SJohn Crispin 
1203645da02SJohn Crispin 	offset %= INT_NUM_IM_OFFSET;
12161fa969fSJohn Crispin 	ltq_icu_w32(im, ltq_icu_r32(im, ier) | BIT(offset), ier);
122171bb2f1SJohn Crispin }
123171bb2f1SJohn Crispin 
12426365625SJohn Crispin static int ltq_eiu_settype(struct irq_data *d, unsigned int type)
12526365625SJohn Crispin {
12626365625SJohn Crispin 	int i;
12726365625SJohn Crispin 
128*f97e5e8eSJohn Crispin 	for (i = 0; i < exin_avail; i++) {
129fe46e503SJohn Crispin 		if (d->hwirq == ltq_eiu_irq[i]) {
13026365625SJohn Crispin 			int val = 0;
13126365625SJohn Crispin 			int edge = 0;
13226365625SJohn Crispin 
13326365625SJohn Crispin 			switch (type) {
13426365625SJohn Crispin 			case IRQF_TRIGGER_NONE:
13526365625SJohn Crispin 				break;
13626365625SJohn Crispin 			case IRQF_TRIGGER_RISING:
13726365625SJohn Crispin 				val = 1;
13826365625SJohn Crispin 				edge = 1;
13926365625SJohn Crispin 				break;
14026365625SJohn Crispin 			case IRQF_TRIGGER_FALLING:
14126365625SJohn Crispin 				val = 2;
14226365625SJohn Crispin 				edge = 1;
14326365625SJohn Crispin 				break;
14426365625SJohn Crispin 			case IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING:
14526365625SJohn Crispin 				val = 3;
14626365625SJohn Crispin 				edge = 1;
14726365625SJohn Crispin 				break;
14826365625SJohn Crispin 			case IRQF_TRIGGER_HIGH:
14926365625SJohn Crispin 				val = 5;
15026365625SJohn Crispin 				break;
15126365625SJohn Crispin 			case IRQF_TRIGGER_LOW:
15226365625SJohn Crispin 				val = 6;
15326365625SJohn Crispin 				break;
15426365625SJohn Crispin 			default:
15526365625SJohn Crispin 				pr_err("invalid type %d for irq %ld\n",
15626365625SJohn Crispin 					type, d->hwirq);
15726365625SJohn Crispin 				return -EINVAL;
15826365625SJohn Crispin 			}
15926365625SJohn Crispin 
16026365625SJohn Crispin 			if (edge)
16126365625SJohn Crispin 				irq_set_handler(d->hwirq, handle_edge_irq);
16226365625SJohn Crispin 
16326365625SJohn Crispin 			ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_C) |
16426365625SJohn Crispin 				(val << (i * 4)), LTQ_EIU_EXIN_C);
16526365625SJohn Crispin 		}
16626365625SJohn Crispin 	}
16726365625SJohn Crispin 
16826365625SJohn Crispin 	return 0;
16926365625SJohn Crispin }
17026365625SJohn Crispin 
171171bb2f1SJohn Crispin static unsigned int ltq_startup_eiu_irq(struct irq_data *d)
172171bb2f1SJohn Crispin {
173171bb2f1SJohn Crispin 	int i;
174171bb2f1SJohn Crispin 
175171bb2f1SJohn Crispin 	ltq_enable_irq(d);
176*f97e5e8eSJohn Crispin 	for (i = 0; i < exin_avail; i++) {
177fe46e503SJohn Crispin 		if (d->hwirq == ltq_eiu_irq[i]) {
17826365625SJohn Crispin 			/* by default we are low level triggered */
17926365625SJohn Crispin 			ltq_eiu_settype(d, IRQF_TRIGGER_LOW);
180171bb2f1SJohn Crispin 			/* clear all pending */
18126365625SJohn Crispin 			ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INC) & ~BIT(i),
18226365625SJohn Crispin 				LTQ_EIU_EXIN_INC);
183171bb2f1SJohn Crispin 			/* enable */
1843645da02SJohn Crispin 			ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INEN) | BIT(i),
185171bb2f1SJohn Crispin 				LTQ_EIU_EXIN_INEN);
186171bb2f1SJohn Crispin 			break;
187171bb2f1SJohn Crispin 		}
188171bb2f1SJohn Crispin 	}
189171bb2f1SJohn Crispin 
190171bb2f1SJohn Crispin 	return 0;
191171bb2f1SJohn Crispin }
192171bb2f1SJohn Crispin 
193171bb2f1SJohn Crispin static void ltq_shutdown_eiu_irq(struct irq_data *d)
194171bb2f1SJohn Crispin {
195171bb2f1SJohn Crispin 	int i;
196171bb2f1SJohn Crispin 
197171bb2f1SJohn Crispin 	ltq_disable_irq(d);
198*f97e5e8eSJohn Crispin 	for (i = 0; i < exin_avail; i++) {
199fe46e503SJohn Crispin 		if (d->hwirq == ltq_eiu_irq[i]) {
200171bb2f1SJohn Crispin 			/* disable */
2013645da02SJohn Crispin 			ltq_eiu_w32(ltq_eiu_r32(LTQ_EIU_EXIN_INEN) & ~BIT(i),
202171bb2f1SJohn Crispin 				LTQ_EIU_EXIN_INEN);
203171bb2f1SJohn Crispin 			break;
204171bb2f1SJohn Crispin 		}
205171bb2f1SJohn Crispin 	}
206171bb2f1SJohn Crispin }
207171bb2f1SJohn Crispin 
208171bb2f1SJohn Crispin static struct irq_chip ltq_irq_type = {
209171bb2f1SJohn Crispin 	"icu",
210171bb2f1SJohn Crispin 	.irq_enable = ltq_enable_irq,
211171bb2f1SJohn Crispin 	.irq_disable = ltq_disable_irq,
212171bb2f1SJohn Crispin 	.irq_unmask = ltq_enable_irq,
213171bb2f1SJohn Crispin 	.irq_ack = ltq_ack_irq,
214171bb2f1SJohn Crispin 	.irq_mask = ltq_disable_irq,
215171bb2f1SJohn Crispin 	.irq_mask_ack = ltq_mask_and_ack_irq,
216171bb2f1SJohn Crispin };
217171bb2f1SJohn Crispin 
218171bb2f1SJohn Crispin static struct irq_chip ltq_eiu_type = {
219171bb2f1SJohn Crispin 	"eiu",
220171bb2f1SJohn Crispin 	.irq_startup = ltq_startup_eiu_irq,
221171bb2f1SJohn Crispin 	.irq_shutdown = ltq_shutdown_eiu_irq,
222171bb2f1SJohn Crispin 	.irq_enable = ltq_enable_irq,
223171bb2f1SJohn Crispin 	.irq_disable = ltq_disable_irq,
224171bb2f1SJohn Crispin 	.irq_unmask = ltq_enable_irq,
225171bb2f1SJohn Crispin 	.irq_ack = ltq_ack_irq,
226171bb2f1SJohn Crispin 	.irq_mask = ltq_disable_irq,
227171bb2f1SJohn Crispin 	.irq_mask_ack = ltq_mask_and_ack_irq,
22826365625SJohn Crispin 	.irq_set_type = ltq_eiu_settype,
229171bb2f1SJohn Crispin };
230171bb2f1SJohn Crispin 
231171bb2f1SJohn Crispin static void ltq_hw_irqdispatch(int module)
232171bb2f1SJohn Crispin {
233171bb2f1SJohn Crispin 	u32 irq;
234171bb2f1SJohn Crispin 
23561fa969fSJohn Crispin 	irq = ltq_icu_r32(module, LTQ_ICU_IM0_IOSR);
236171bb2f1SJohn Crispin 	if (irq == 0)
237171bb2f1SJohn Crispin 		return;
238171bb2f1SJohn Crispin 
2393645da02SJohn Crispin 	/*
2403645da02SJohn Crispin 	 * silicon bug causes only the msb set to 1 to be valid. all
241171bb2f1SJohn Crispin 	 * other bits might be bogus
242171bb2f1SJohn Crispin 	 */
243171bb2f1SJohn Crispin 	irq = __fls(irq);
2443645da02SJohn Crispin 	do_IRQ((int)irq + MIPS_CPU_IRQ_CASCADE + (INT_NUM_IM_OFFSET * module));
245171bb2f1SJohn Crispin 
246171bb2f1SJohn Crispin 	/* if this is a EBU irq, we need to ack it or get a deadlock */
2473645da02SJohn Crispin 	if ((irq == LTQ_ICU_EBU_IRQ) && (module == 0) && LTQ_EBU_PCC_ISTAT)
248171bb2f1SJohn Crispin 		ltq_ebu_w32(ltq_ebu_r32(LTQ_EBU_PCC_ISTAT) | 0x10,
249171bb2f1SJohn Crispin 			LTQ_EBU_PCC_ISTAT);
250171bb2f1SJohn Crispin }
251171bb2f1SJohn Crispin 
252171bb2f1SJohn Crispin #define DEFINE_HWx_IRQDISPATCH(x)					\
253171bb2f1SJohn Crispin 	static void ltq_hw ## x ## _irqdispatch(void)			\
254171bb2f1SJohn Crispin 	{								\
255171bb2f1SJohn Crispin 		ltq_hw_irqdispatch(x);					\
256171bb2f1SJohn Crispin 	}
257171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(0)
258171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(1)
259171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(2)
260171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(3)
261171bb2f1SJohn Crispin DEFINE_HWx_IRQDISPATCH(4)
262171bb2f1SJohn Crispin 
263c2c9c788SJohn Crispin #if MIPS_CPU_TIMER_IRQ == 7
264171bb2f1SJohn Crispin static void ltq_hw5_irqdispatch(void)
265171bb2f1SJohn Crispin {
266171bb2f1SJohn Crispin 	do_IRQ(MIPS_CPU_TIMER_IRQ);
267171bb2f1SJohn Crispin }
268c2c9c788SJohn Crispin #else
269c2c9c788SJohn Crispin DEFINE_HWx_IRQDISPATCH(5)
270c2c9c788SJohn Crispin #endif
271171bb2f1SJohn Crispin 
272a8d096efSJohn Crispin #ifdef CONFIG_MIPS_MT_SMP
273a8d096efSJohn Crispin void __init arch_init_ipiirq(int irq, struct irqaction *action)
274a8d096efSJohn Crispin {
275a8d096efSJohn Crispin 	setup_irq(irq, action);
276a8d096efSJohn Crispin 	irq_set_handler(irq, handle_percpu_irq);
277a8d096efSJohn Crispin }
278a8d096efSJohn Crispin 
279a8d096efSJohn Crispin static void ltq_sw0_irqdispatch(void)
280a8d096efSJohn Crispin {
281a8d096efSJohn Crispin 	do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_RESCHED_IRQ);
282a8d096efSJohn Crispin }
283a8d096efSJohn Crispin 
284a8d096efSJohn Crispin static void ltq_sw1_irqdispatch(void)
285a8d096efSJohn Crispin {
286a8d096efSJohn Crispin 	do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_CALL_IRQ);
287a8d096efSJohn Crispin }
288a8d096efSJohn Crispin static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
289a8d096efSJohn Crispin {
290a8d096efSJohn Crispin 	scheduler_ipi();
291a8d096efSJohn Crispin 	return IRQ_HANDLED;
292a8d096efSJohn Crispin }
293a8d096efSJohn Crispin 
294a8d096efSJohn Crispin static irqreturn_t ipi_call_interrupt(int irq, void *dev_id)
295a8d096efSJohn Crispin {
2964ace6139SAlex Smith 	generic_smp_call_function_interrupt();
297a8d096efSJohn Crispin 	return IRQ_HANDLED;
298a8d096efSJohn Crispin }
299a8d096efSJohn Crispin 
300a8d096efSJohn Crispin static struct irqaction irq_resched = {
301a8d096efSJohn Crispin 	.handler	= ipi_resched_interrupt,
302a8d096efSJohn Crispin 	.flags		= IRQF_PERCPU,
303a8d096efSJohn Crispin 	.name		= "IPI_resched"
304a8d096efSJohn Crispin };
305a8d096efSJohn Crispin 
306a8d096efSJohn Crispin static struct irqaction irq_call = {
307a8d096efSJohn Crispin 	.handler	= ipi_call_interrupt,
308a8d096efSJohn Crispin 	.flags		= IRQF_PERCPU,
309a8d096efSJohn Crispin 	.name		= "IPI_call"
310a8d096efSJohn Crispin };
311a8d096efSJohn Crispin #endif
312a8d096efSJohn Crispin 
313171bb2f1SJohn Crispin asmlinkage void plat_irq_dispatch(void)
314171bb2f1SJohn Crispin {
315171bb2f1SJohn Crispin 	unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
316171bb2f1SJohn Crispin 	unsigned int i;
317171bb2f1SJohn Crispin 
318c2c9c788SJohn Crispin 	if ((MIPS_CPU_TIMER_IRQ == 7) && (pending & CAUSEF_IP7)) {
319171bb2f1SJohn Crispin 		do_IRQ(MIPS_CPU_TIMER_IRQ);
320171bb2f1SJohn Crispin 		goto out;
321171bb2f1SJohn Crispin 	} else {
32261fa969fSJohn Crispin 		for (i = 0; i < MAX_IM; i++) {
323171bb2f1SJohn Crispin 			if (pending & (CAUSEF_IP2 << i)) {
324171bb2f1SJohn Crispin 				ltq_hw_irqdispatch(i);
325171bb2f1SJohn Crispin 				goto out;
326171bb2f1SJohn Crispin 			}
327171bb2f1SJohn Crispin 		}
328171bb2f1SJohn Crispin 	}
329171bb2f1SJohn Crispin 	pr_alert("Spurious IRQ: CAUSE=0x%08x\n", read_c0_status());
330171bb2f1SJohn Crispin 
331171bb2f1SJohn Crispin out:
332171bb2f1SJohn Crispin 	return;
333171bb2f1SJohn Crispin }
334171bb2f1SJohn Crispin 
3353645da02SJohn Crispin static int icu_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
3363645da02SJohn Crispin {
3373645da02SJohn Crispin 	struct irq_chip *chip = &ltq_irq_type;
3383645da02SJohn Crispin 	int i;
3393645da02SJohn Crispin 
3409c1628b6SJohn Crispin 	if (hw < MIPS_CPU_IRQ_CASCADE)
3419c1628b6SJohn Crispin 		return 0;
3429c1628b6SJohn Crispin 
3433645da02SJohn Crispin 	for (i = 0; i < exin_avail; i++)
344fe46e503SJohn Crispin 		if (hw == ltq_eiu_irq[i])
3453645da02SJohn Crispin 			chip = &ltq_eiu_type;
3463645da02SJohn Crispin 
3473645da02SJohn Crispin 	irq_set_chip_and_handler(hw, chip, handle_level_irq);
3483645da02SJohn Crispin 
3493645da02SJohn Crispin 	return 0;
3503645da02SJohn Crispin }
3513645da02SJohn Crispin 
3523645da02SJohn Crispin static const struct irq_domain_ops irq_domain_ops = {
3533645da02SJohn Crispin 	.xlate = irq_domain_xlate_onetwocell,
3543645da02SJohn Crispin 	.map = icu_map,
3553645da02SJohn Crispin };
3563645da02SJohn Crispin 
357171bb2f1SJohn Crispin static struct irqaction cascade = {
358171bb2f1SJohn Crispin 	.handler = no_action,
359171bb2f1SJohn Crispin 	.name = "cascade",
360171bb2f1SJohn Crispin };
361171bb2f1SJohn Crispin 
3623645da02SJohn Crispin int __init icu_of_init(struct device_node *node, struct device_node *parent)
363171bb2f1SJohn Crispin {
3643645da02SJohn Crispin 	struct device_node *eiu_node;
3653645da02SJohn Crispin 	struct resource res;
36626365625SJohn Crispin 	int i, ret;
367171bb2f1SJohn Crispin 
36861fa969fSJohn Crispin 	for (i = 0; i < MAX_IM; i++) {
36961fa969fSJohn Crispin 		if (of_address_to_resource(node, i, &res))
3703645da02SJohn Crispin 			panic("Failed to get icu memory range");
371171bb2f1SJohn Crispin 
3726e807852SHauke Mehrtens 		if (!request_mem_region(res.start, resource_size(&res),
3736e807852SHauke Mehrtens 					res.name))
3743645da02SJohn Crispin 			pr_err("Failed to request icu memory");
375171bb2f1SJohn Crispin 
37661fa969fSJohn Crispin 		ltq_icu_membase[i] = ioremap_nocache(res.start,
37761fa969fSJohn Crispin 					resource_size(&res));
37861fa969fSJohn Crispin 		if (!ltq_icu_membase[i])
379ab75dc02SRalf Baechle 			panic("Failed to remap icu memory");
38061fa969fSJohn Crispin 	}
381171bb2f1SJohn Crispin 
38216f70b56SJohn Crispin 	/* turn off all irqs by default */
38361fa969fSJohn Crispin 	for (i = 0; i < MAX_IM; i++) {
384171bb2f1SJohn Crispin 		/* make sure all irqs are turned off by default */
38561fa969fSJohn Crispin 		ltq_icu_w32(i, 0, LTQ_ICU_IM0_IER);
386171bb2f1SJohn Crispin 		/* clear all possibly pending interrupts */
38761fa969fSJohn Crispin 		ltq_icu_w32(i, ~0, LTQ_ICU_IM0_ISR);
38816f70b56SJohn Crispin 	}
389171bb2f1SJohn Crispin 
390171bb2f1SJohn Crispin 	mips_cpu_irq_init();
391171bb2f1SJohn Crispin 
39261fa969fSJohn Crispin 	for (i = 0; i < MAX_IM; i++)
39361fa969fSJohn Crispin 		setup_irq(i + 2, &cascade);
394171bb2f1SJohn Crispin 
395171bb2f1SJohn Crispin 	if (cpu_has_vint) {
396171bb2f1SJohn Crispin 		pr_info("Setting up vectored interrupts\n");
397171bb2f1SJohn Crispin 		set_vi_handler(2, ltq_hw0_irqdispatch);
398171bb2f1SJohn Crispin 		set_vi_handler(3, ltq_hw1_irqdispatch);
399171bb2f1SJohn Crispin 		set_vi_handler(4, ltq_hw2_irqdispatch);
400171bb2f1SJohn Crispin 		set_vi_handler(5, ltq_hw3_irqdispatch);
401171bb2f1SJohn Crispin 		set_vi_handler(6, ltq_hw4_irqdispatch);
402171bb2f1SJohn Crispin 		set_vi_handler(7, ltq_hw5_irqdispatch);
403171bb2f1SJohn Crispin 	}
404171bb2f1SJohn Crispin 
405c2c9c788SJohn Crispin 	ltq_domain = irq_domain_add_linear(node,
40661fa969fSJohn Crispin 		(MAX_IM * INT_NUM_IM_OFFSET) + MIPS_CPU_IRQ_CASCADE,
4073645da02SJohn Crispin 		&irq_domain_ops, 0);
408171bb2f1SJohn Crispin 
409a8d096efSJohn Crispin #if defined(CONFIG_MIPS_MT_SMP)
410a8d096efSJohn Crispin 	if (cpu_has_vint) {
411a8d096efSJohn Crispin 		pr_info("Setting up IPI vectored interrupts\n");
412a8d096efSJohn Crispin 		set_vi_handler(MIPS_CPU_IPI_RESCHED_IRQ, ltq_sw0_irqdispatch);
413a8d096efSJohn Crispin 		set_vi_handler(MIPS_CPU_IPI_CALL_IRQ, ltq_sw1_irqdispatch);
414a8d096efSJohn Crispin 	}
415a8d096efSJohn Crispin 	arch_init_ipiirq(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_RESCHED_IRQ,
416a8d096efSJohn Crispin 		&irq_resched);
417a8d096efSJohn Crispin 	arch_init_ipiirq(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_CALL_IRQ, &irq_call);
418a8d096efSJohn Crispin #endif
419a8d096efSJohn Crispin 
420b633648cSRalf Baechle #ifndef CONFIG_MIPS_MT_SMP
421171bb2f1SJohn Crispin 	set_c0_status(IE_IRQ0 | IE_IRQ1 | IE_IRQ2 |
422171bb2f1SJohn Crispin 		IE_IRQ3 | IE_IRQ4 | IE_IRQ5);
423171bb2f1SJohn Crispin #else
424171bb2f1SJohn Crispin 	set_c0_status(IE_SW0 | IE_SW1 | IE_IRQ0 | IE_IRQ1 |
425171bb2f1SJohn Crispin 		IE_IRQ2 | IE_IRQ3 | IE_IRQ4 | IE_IRQ5);
426171bb2f1SJohn Crispin #endif
42759c11579SJohn Crispin 
42859c11579SJohn Crispin 	/* tell oprofile which irq to use */
429a669efc4SAndrew Bresticker 	ltq_perfcount_irq = irq_create_mapping(ltq_domain, LTQ_PERF_IRQ);
430c2c9c788SJohn Crispin 
431c2c9c788SJohn Crispin 	/*
432c2c9c788SJohn Crispin 	 * if the timer irq is not one of the mips irqs we need to
433c2c9c788SJohn Crispin 	 * create a mapping
434c2c9c788SJohn Crispin 	 */
435c2c9c788SJohn Crispin 	if (MIPS_CPU_TIMER_IRQ != 7)
436c2c9c788SJohn Crispin 		irq_create_mapping(ltq_domain, MIPS_CPU_TIMER_IRQ);
437c2c9c788SJohn Crispin 
438d32caf94SJohn Crispin 	/* the external interrupts are optional and xway only */
439d32caf94SJohn Crispin 	eiu_node = of_find_compatible_node(NULL, NULL, "lantiq,eiu-xway");
440d32caf94SJohn Crispin 	if (eiu_node && !of_address_to_resource(eiu_node, 0, &res)) {
441d32caf94SJohn Crispin 		/* find out how many external irq sources we have */
442fe46e503SJohn Crispin 		exin_avail = of_property_count_u32_elems(eiu_node,
443fe46e503SJohn Crispin 							 "lantiq,eiu-irqs");
444d32caf94SJohn Crispin 
445d32caf94SJohn Crispin 		if (exin_avail > MAX_EIU)
446d32caf94SJohn Crispin 			exin_avail = MAX_EIU;
447d32caf94SJohn Crispin 
448fe46e503SJohn Crispin 		ret = of_property_read_u32_array(eiu_node, "lantiq,eiu-irqs",
449d32caf94SJohn Crispin 						ltq_eiu_irq, exin_avail);
450fe46e503SJohn Crispin 		if (ret)
451d32caf94SJohn Crispin 			panic("failed to load external irq resources");
452d32caf94SJohn Crispin 
4536e807852SHauke Mehrtens 		if (!request_mem_region(res.start, resource_size(&res),
4546e807852SHauke Mehrtens 							res.name))
455d32caf94SJohn Crispin 			pr_err("Failed to request eiu memory");
456d32caf94SJohn Crispin 
457d32caf94SJohn Crispin 		ltq_eiu_membase = ioremap_nocache(res.start,
458d32caf94SJohn Crispin 							resource_size(&res));
459d32caf94SJohn Crispin 		if (!ltq_eiu_membase)
460d32caf94SJohn Crispin 			panic("Failed to remap eiu memory");
461d32caf94SJohn Crispin 	}
462d32caf94SJohn Crispin 
4633645da02SJohn Crispin 	return 0;
464171bb2f1SJohn Crispin }
465171bb2f1SJohn Crispin 
466a669efc4SAndrew Bresticker int get_c0_perfcount_int(void)
467a669efc4SAndrew Bresticker {
468a669efc4SAndrew Bresticker 	return ltq_perfcount_irq;
469a669efc4SAndrew Bresticker }
4700cb0985fSFelix Fietkau EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
471a669efc4SAndrew Bresticker 
472078a55fcSPaul Gortmaker unsigned int get_c0_compare_int(void)
473171bb2f1SJohn Crispin {
474c2c9c788SJohn Crispin 	return MIPS_CPU_TIMER_IRQ;
475171bb2f1SJohn Crispin }
4763645da02SJohn Crispin 
4773645da02SJohn Crispin static struct of_device_id __initdata of_irq_ids[] = {
4783645da02SJohn Crispin 	{ .compatible = "lantiq,icu", .data = icu_of_init },
4793645da02SJohn Crispin 	{},
4803645da02SJohn Crispin };
4813645da02SJohn Crispin 
4823645da02SJohn Crispin void __init arch_init_irq(void)
4833645da02SJohn Crispin {
4843645da02SJohn Crispin 	of_irq_init(of_irq_ids);
4853645da02SJohn Crispin }
486