xref: /linux/drivers/irqchip/irq-mmp.c (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2c052d13cSHaojian Zhuang /*
3c052d13cSHaojian Zhuang  *  linux/arch/arm/mach-mmp/irq.c
4c052d13cSHaojian Zhuang  *
5c052d13cSHaojian Zhuang  *  Generic IRQ handling, GPIO IRQ demultiplexing, etc.
6c052d13cSHaojian Zhuang  *  Copyright (C) 2008 - 2012 Marvell Technology Group Ltd.
7c052d13cSHaojian Zhuang  *
8c052d13cSHaojian Zhuang  *  Author:	Bin Yang <bin.yang@marvell.com>
9c052d13cSHaojian Zhuang  *              Haojian Zhuang <haojian.zhuang@gmail.com>
10c052d13cSHaojian Zhuang  */
11c052d13cSHaojian Zhuang 
12c052d13cSHaojian Zhuang #include <linux/module.h>
13c052d13cSHaojian Zhuang #include <linux/init.h>
14c052d13cSHaojian Zhuang #include <linux/irq.h>
1541a83e06SJoel Porquet #include <linux/irqchip.h>
16a46bc5fdSLubomir Rintel #include <linux/irqchip/chained_irq.h>
17c052d13cSHaojian Zhuang #include <linux/irqdomain.h>
18c052d13cSHaojian Zhuang #include <linux/io.h>
19c052d13cSHaojian Zhuang #include <linux/ioport.h>
20c052d13cSHaojian Zhuang #include <linux/of_address.h>
21c052d13cSHaojian Zhuang #include <linux/of_irq.h>
22c052d13cSHaojian Zhuang 
230f374561SHaojian Zhuang #include <asm/exception.h>
2413dde818SNeil Zhang #include <asm/hardirq.h>
250f374561SHaojian Zhuang 
26c052d13cSHaojian Zhuang #define MAX_ICU_NR		16
27c052d13cSHaojian Zhuang 
280f374561SHaojian Zhuang #define PJ1_INT_SEL		0x10c
290f374561SHaojian Zhuang #define PJ4_INT_SEL		0x104
300f374561SHaojian Zhuang 
310f374561SHaojian Zhuang /* bit fields in PJ1_INT_SEL and PJ4_INT_SEL */
320f374561SHaojian Zhuang #define SEL_INT_PENDING		(1 << 6)
330f374561SHaojian Zhuang #define SEL_INT_NUM_MASK	0x3f
340f374561SHaojian Zhuang 
352380a22bSLubomir Rintel #define MMP2_ICU_INT_ROUTE_PJ4_IRQ	(1 << 5)
362380a22bSLubomir Rintel #define MMP2_ICU_INT_ROUTE_PJ4_FIQ	(1 << 6)
372380a22bSLubomir Rintel 
38c052d13cSHaojian Zhuang struct icu_chip_data {
39c052d13cSHaojian Zhuang 	int			nr_irqs;
40c052d13cSHaojian Zhuang 	unsigned int		virq_base;
41c052d13cSHaojian Zhuang 	unsigned int		cascade_irq;
42c052d13cSHaojian Zhuang 	void __iomem		*reg_status;
43c052d13cSHaojian Zhuang 	void __iomem		*reg_mask;
44c052d13cSHaojian Zhuang 	unsigned int		conf_enable;
45c052d13cSHaojian Zhuang 	unsigned int		conf_disable;
46c052d13cSHaojian Zhuang 	unsigned int		conf_mask;
479e8e8912SAndres Salomon 	unsigned int		conf2_mask;
48c052d13cSHaojian Zhuang 	unsigned int		clr_mfp_irq_base;
49c052d13cSHaojian Zhuang 	unsigned int		clr_mfp_hwirq;
50c052d13cSHaojian Zhuang 	struct irq_domain	*domain;
51c052d13cSHaojian Zhuang };
52c052d13cSHaojian Zhuang 
53c052d13cSHaojian Zhuang struct mmp_intc_conf {
54c052d13cSHaojian Zhuang 	unsigned int	conf_enable;
55c052d13cSHaojian Zhuang 	unsigned int	conf_disable;
56c052d13cSHaojian Zhuang 	unsigned int	conf_mask;
579e8e8912SAndres Salomon 	unsigned int	conf2_mask;
58c052d13cSHaojian Zhuang };
59c052d13cSHaojian Zhuang 
600f374561SHaojian Zhuang static void __iomem *mmp_icu_base;
619e8e8912SAndres Salomon static void __iomem *mmp_icu2_base;
62c052d13cSHaojian Zhuang static struct icu_chip_data icu_data[MAX_ICU_NR];
63c052d13cSHaojian Zhuang static int max_icu_nr;
64c052d13cSHaojian Zhuang 
65c052d13cSHaojian Zhuang extern void mmp2_clear_pmic_int(void);
66c052d13cSHaojian Zhuang 
icu_mask_ack_irq(struct irq_data * d)67c052d13cSHaojian Zhuang static void icu_mask_ack_irq(struct irq_data *d)
68c052d13cSHaojian Zhuang {
69c052d13cSHaojian Zhuang 	struct irq_domain *domain = d->domain;
70c052d13cSHaojian Zhuang 	struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
71c052d13cSHaojian Zhuang 	int hwirq;
72c052d13cSHaojian Zhuang 	u32 r;
73c052d13cSHaojian Zhuang 
74c052d13cSHaojian Zhuang 	hwirq = d->irq - data->virq_base;
75c052d13cSHaojian Zhuang 	if (data == &icu_data[0]) {
76c052d13cSHaojian Zhuang 		r = readl_relaxed(mmp_icu_base + (hwirq << 2));
77c052d13cSHaojian Zhuang 		r &= ~data->conf_mask;
78c052d13cSHaojian Zhuang 		r |= data->conf_disable;
79c052d13cSHaojian Zhuang 		writel_relaxed(r, mmp_icu_base + (hwirq << 2));
80c052d13cSHaojian Zhuang 	} else {
81c052d13cSHaojian Zhuang #ifdef CONFIG_CPU_MMP2
82c052d13cSHaojian Zhuang 		if ((data->virq_base == data->clr_mfp_irq_base)
83c052d13cSHaojian Zhuang 			&& (hwirq == data->clr_mfp_hwirq))
84c052d13cSHaojian Zhuang 			mmp2_clear_pmic_int();
85c052d13cSHaojian Zhuang #endif
86c052d13cSHaojian Zhuang 		r = readl_relaxed(data->reg_mask) | (1 << hwirq);
87c052d13cSHaojian Zhuang 		writel_relaxed(r, data->reg_mask);
88c052d13cSHaojian Zhuang 	}
89c052d13cSHaojian Zhuang }
90c052d13cSHaojian Zhuang 
icu_mask_irq(struct irq_data * d)91c052d13cSHaojian Zhuang static void icu_mask_irq(struct irq_data *d)
92c052d13cSHaojian Zhuang {
93c052d13cSHaojian Zhuang 	struct irq_domain *domain = d->domain;
94c052d13cSHaojian Zhuang 	struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
95c052d13cSHaojian Zhuang 	int hwirq;
96c052d13cSHaojian Zhuang 	u32 r;
97c052d13cSHaojian Zhuang 
98c052d13cSHaojian Zhuang 	hwirq = d->irq - data->virq_base;
99c052d13cSHaojian Zhuang 	if (data == &icu_data[0]) {
100c052d13cSHaojian Zhuang 		r = readl_relaxed(mmp_icu_base + (hwirq << 2));
101c052d13cSHaojian Zhuang 		r &= ~data->conf_mask;
102c052d13cSHaojian Zhuang 		r |= data->conf_disable;
103c052d13cSHaojian Zhuang 		writel_relaxed(r, mmp_icu_base + (hwirq << 2));
1049e8e8912SAndres Salomon 
1059e8e8912SAndres Salomon 		if (data->conf2_mask) {
1069e8e8912SAndres Salomon 			/*
1079e8e8912SAndres Salomon 			 * ICU1 (above) only controls PJ4 MP1; if using SMP,
1089e8e8912SAndres Salomon 			 * we need to also mask the MP2 and MM cores via ICU2.
1099e8e8912SAndres Salomon 			 */
1109e8e8912SAndres Salomon 			r = readl_relaxed(mmp_icu2_base + (hwirq << 2));
1119e8e8912SAndres Salomon 			r &= ~data->conf2_mask;
1129e8e8912SAndres Salomon 			writel_relaxed(r, mmp_icu2_base + (hwirq << 2));
1139e8e8912SAndres Salomon 		}
114c052d13cSHaojian Zhuang 	} else {
115c052d13cSHaojian Zhuang 		r = readl_relaxed(data->reg_mask) | (1 << hwirq);
116c052d13cSHaojian Zhuang 		writel_relaxed(r, data->reg_mask);
117c052d13cSHaojian Zhuang 	}
118c052d13cSHaojian Zhuang }
119c052d13cSHaojian Zhuang 
icu_unmask_irq(struct irq_data * d)120c052d13cSHaojian Zhuang static void icu_unmask_irq(struct irq_data *d)
121c052d13cSHaojian Zhuang {
122c052d13cSHaojian Zhuang 	struct irq_domain *domain = d->domain;
123c052d13cSHaojian Zhuang 	struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
124c052d13cSHaojian Zhuang 	int hwirq;
125c052d13cSHaojian Zhuang 	u32 r;
126c052d13cSHaojian Zhuang 
127c052d13cSHaojian Zhuang 	hwirq = d->irq - data->virq_base;
128c052d13cSHaojian Zhuang 	if (data == &icu_data[0]) {
129c052d13cSHaojian Zhuang 		r = readl_relaxed(mmp_icu_base + (hwirq << 2));
130c052d13cSHaojian Zhuang 		r &= ~data->conf_mask;
131c052d13cSHaojian Zhuang 		r |= data->conf_enable;
132c052d13cSHaojian Zhuang 		writel_relaxed(r, mmp_icu_base + (hwirq << 2));
133c052d13cSHaojian Zhuang 	} else {
134c052d13cSHaojian Zhuang 		r = readl_relaxed(data->reg_mask) & ~(1 << hwirq);
135c052d13cSHaojian Zhuang 		writel_relaxed(r, data->reg_mask);
136c052d13cSHaojian Zhuang 	}
137c052d13cSHaojian Zhuang }
138c052d13cSHaojian Zhuang 
1390f102b6cSHaojian Zhuang struct irq_chip icu_irq_chip = {
140c052d13cSHaojian Zhuang 	.name		= "icu_irq",
141c052d13cSHaojian Zhuang 	.irq_mask	= icu_mask_irq,
142c052d13cSHaojian Zhuang 	.irq_mask_ack	= icu_mask_ack_irq,
143c052d13cSHaojian Zhuang 	.irq_unmask	= icu_unmask_irq,
144c052d13cSHaojian Zhuang };
145c052d13cSHaojian Zhuang 
icu_mux_irq_demux(struct irq_desc * desc)146bd0b9ac4SThomas Gleixner static void icu_mux_irq_demux(struct irq_desc *desc)
147c052d13cSHaojian Zhuang {
14814873aa1SThomas Gleixner 	unsigned int irq = irq_desc_get_irq(desc);
149a46bc5fdSLubomir Rintel 	struct irq_chip *chip = irq_desc_get_chip(desc);
150c052d13cSHaojian Zhuang 	struct irq_domain *domain;
151c052d13cSHaojian Zhuang 	struct icu_chip_data *data;
152c052d13cSHaojian Zhuang 	int i;
153c052d13cSHaojian Zhuang 	unsigned long mask, status, n;
154c052d13cSHaojian Zhuang 
155a46bc5fdSLubomir Rintel 	chained_irq_enter(chip, desc);
156a46bc5fdSLubomir Rintel 
157c052d13cSHaojian Zhuang 	for (i = 1; i < max_icu_nr; i++) {
158c052d13cSHaojian Zhuang 		if (irq == icu_data[i].cascade_irq) {
159c052d13cSHaojian Zhuang 			domain = icu_data[i].domain;
160c052d13cSHaojian Zhuang 			data = (struct icu_chip_data *)domain->host_data;
161c052d13cSHaojian Zhuang 			break;
162c052d13cSHaojian Zhuang 		}
163c052d13cSHaojian Zhuang 	}
164c052d13cSHaojian Zhuang 	if (i >= max_icu_nr) {
165c052d13cSHaojian Zhuang 		pr_err("Spurious irq %d in MMP INTC\n", irq);
166a46bc5fdSLubomir Rintel 		goto out;
167c052d13cSHaojian Zhuang 	}
168c052d13cSHaojian Zhuang 
169c052d13cSHaojian Zhuang 	mask = readl_relaxed(data->reg_mask);
170c052d13cSHaojian Zhuang 	while (1) {
171c052d13cSHaojian Zhuang 		status = readl_relaxed(data->reg_status) & ~mask;
172c052d13cSHaojian Zhuang 		if (status == 0)
173c052d13cSHaojian Zhuang 			break;
174c052d13cSHaojian Zhuang 		for_each_set_bit(n, &status, BITS_PER_LONG) {
175c052d13cSHaojian Zhuang 			generic_handle_irq(icu_data[i].virq_base + n);
176c052d13cSHaojian Zhuang 		}
177c052d13cSHaojian Zhuang 	}
178a46bc5fdSLubomir Rintel 
179a46bc5fdSLubomir Rintel out:
180a46bc5fdSLubomir Rintel 	chained_irq_exit(chip, desc);
181c052d13cSHaojian Zhuang }
182c052d13cSHaojian Zhuang 
mmp_irq_domain_map(struct irq_domain * d,unsigned int irq,irq_hw_number_t hw)183c052d13cSHaojian Zhuang static int mmp_irq_domain_map(struct irq_domain *d, unsigned int irq,
184c052d13cSHaojian Zhuang 			      irq_hw_number_t hw)
185c052d13cSHaojian Zhuang {
186c052d13cSHaojian Zhuang 	irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq);
187c052d13cSHaojian Zhuang 	return 0;
188c052d13cSHaojian Zhuang }
189c052d13cSHaojian Zhuang 
mmp_irq_domain_xlate(struct irq_domain * d,struct device_node * node,const u32 * intspec,unsigned int intsize,unsigned long * out_hwirq,unsigned int * out_type)190c052d13cSHaojian Zhuang static int mmp_irq_domain_xlate(struct irq_domain *d, struct device_node *node,
191c052d13cSHaojian Zhuang 				const u32 *intspec, unsigned int intsize,
192c052d13cSHaojian Zhuang 				unsigned long *out_hwirq,
193c052d13cSHaojian Zhuang 				unsigned int *out_type)
194c052d13cSHaojian Zhuang {
195c052d13cSHaojian Zhuang 	*out_hwirq = intspec[0];
196c052d13cSHaojian Zhuang 	return 0;
197c052d13cSHaojian Zhuang }
198c052d13cSHaojian Zhuang 
199096048cbSYueHaibing static const struct irq_domain_ops mmp_irq_domain_ops = {
200c052d13cSHaojian Zhuang 	.map		= mmp_irq_domain_map,
201c052d13cSHaojian Zhuang 	.xlate		= mmp_irq_domain_xlate,
202c052d13cSHaojian Zhuang };
203c052d13cSHaojian Zhuang 
204c8c7d93dSBhumika Goyal static const struct mmp_intc_conf mmp_conf = {
205c052d13cSHaojian Zhuang 	.conf_enable	= 0x51,
206c052d13cSHaojian Zhuang 	.conf_disable	= 0x0,
207c052d13cSHaojian Zhuang 	.conf_mask	= 0x7f,
208c052d13cSHaojian Zhuang };
209c052d13cSHaojian Zhuang 
210c8c7d93dSBhumika Goyal static const struct mmp_intc_conf mmp2_conf = {
211c052d13cSHaojian Zhuang 	.conf_enable	= 0x20,
212c052d13cSHaojian Zhuang 	.conf_disable	= 0x0,
2132380a22bSLubomir Rintel 	.conf_mask	= MMP2_ICU_INT_ROUTE_PJ4_IRQ |
2142380a22bSLubomir Rintel 			  MMP2_ICU_INT_ROUTE_PJ4_FIQ,
215c052d13cSHaojian Zhuang };
216c052d13cSHaojian Zhuang 
2179e8e8912SAndres Salomon static struct mmp_intc_conf mmp3_conf = {
2189e8e8912SAndres Salomon 	.conf_enable	= 0x20,
2199e8e8912SAndres Salomon 	.conf_disable	= 0x0,
2209e8e8912SAndres Salomon 	.conf_mask	= MMP2_ICU_INT_ROUTE_PJ4_IRQ |
2219e8e8912SAndres Salomon 			  MMP2_ICU_INT_ROUTE_PJ4_FIQ,
2229e8e8912SAndres Salomon 	.conf2_mask	= 0xf0,
2239e8e8912SAndres Salomon };
2249e8e8912SAndres Salomon 
mmp_handle_irq(struct pt_regs * regs)2258783dd3aSStephen Boyd static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs)
2260f374561SHaojian Zhuang {
227b918402cSMarc Zyngier 	int hwirq;
2280f374561SHaojian Zhuang 
2290f374561SHaojian Zhuang 	hwirq = readl_relaxed(mmp_icu_base + PJ1_INT_SEL);
2300f374561SHaojian Zhuang 	if (!(hwirq & SEL_INT_PENDING))
2310f374561SHaojian Zhuang 		return;
2320f374561SHaojian Zhuang 	hwirq &= SEL_INT_NUM_MASK;
233*0953fb26SMark Rutland 	generic_handle_domain_irq(icu_data[0].domain, hwirq);
2340f374561SHaojian Zhuang }
2350f374561SHaojian Zhuang 
mmp2_handle_irq(struct pt_regs * regs)2368783dd3aSStephen Boyd static void __exception_irq_entry mmp2_handle_irq(struct pt_regs *regs)
2370f374561SHaojian Zhuang {
238b918402cSMarc Zyngier 	int hwirq;
2390f374561SHaojian Zhuang 
2400f374561SHaojian Zhuang 	hwirq = readl_relaxed(mmp_icu_base + PJ4_INT_SEL);
2410f374561SHaojian Zhuang 	if (!(hwirq & SEL_INT_PENDING))
2420f374561SHaojian Zhuang 		return;
2430f374561SHaojian Zhuang 	hwirq &= SEL_INT_NUM_MASK;
244*0953fb26SMark Rutland 	generic_handle_domain_irq(icu_data[0].domain, hwirq);
2450f374561SHaojian Zhuang }
2460f374561SHaojian Zhuang 
mmp_init_bases(struct device_node * node)2470f374561SHaojian Zhuang static int __init mmp_init_bases(struct device_node *node)
248c052d13cSHaojian Zhuang {
2490f374561SHaojian Zhuang 	int ret, nr_irqs, irq, i = 0;
250c052d13cSHaojian Zhuang 
251c052d13cSHaojian Zhuang 	ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", &nr_irqs);
252c052d13cSHaojian Zhuang 	if (ret) {
253c052d13cSHaojian Zhuang 		pr_err("Not found mrvl,intc-nr-irqs property\n");
2540f374561SHaojian Zhuang 		return ret;
255c052d13cSHaojian Zhuang 	}
256c052d13cSHaojian Zhuang 
257c052d13cSHaojian Zhuang 	mmp_icu_base = of_iomap(node, 0);
258c052d13cSHaojian Zhuang 	if (!mmp_icu_base) {
259c052d13cSHaojian Zhuang 		pr_err("Failed to get interrupt controller register\n");
2600f374561SHaojian Zhuang 		return -ENOMEM;
261c052d13cSHaojian Zhuang 	}
262c052d13cSHaojian Zhuang 
263c052d13cSHaojian Zhuang 	icu_data[0].virq_base = 0;
2640f374561SHaojian Zhuang 	icu_data[0].domain = irq_domain_add_linear(node, nr_irqs,
265c052d13cSHaojian Zhuang 						   &mmp_irq_domain_ops,
266c052d13cSHaojian Zhuang 						   &icu_data[0]);
2670f374561SHaojian Zhuang 	for (irq = 0; irq < nr_irqs; irq++) {
2680f374561SHaojian Zhuang 		ret = irq_create_mapping(icu_data[0].domain, irq);
2690f374561SHaojian Zhuang 		if (!ret) {
2700f374561SHaojian Zhuang 			pr_err("Failed to mapping hwirq\n");
2710f374561SHaojian Zhuang 			goto err;
272c052d13cSHaojian Zhuang 		}
2730f374561SHaojian Zhuang 		if (!irq)
2740f374561SHaojian Zhuang 			icu_data[0].virq_base = ret;
2750f374561SHaojian Zhuang 	}
2760f374561SHaojian Zhuang 	icu_data[0].nr_irqs = nr_irqs;
2770f374561SHaojian Zhuang 	return 0;
2780f374561SHaojian Zhuang err:
2790f374561SHaojian Zhuang 	if (icu_data[0].virq_base) {
2800f374561SHaojian Zhuang 		for (i = 0; i < irq; i++)
2810f374561SHaojian Zhuang 			irq_dispose_mapping(icu_data[0].virq_base + i);
2820f374561SHaojian Zhuang 	}
2830f374561SHaojian Zhuang 	irq_domain_remove(icu_data[0].domain);
2840f374561SHaojian Zhuang 	iounmap(mmp_icu_base);
2850f374561SHaojian Zhuang 	return -EINVAL;
2860f374561SHaojian Zhuang }
2870f374561SHaojian Zhuang 
mmp_of_init(struct device_node * node,struct device_node * parent)2880f374561SHaojian Zhuang static int __init mmp_of_init(struct device_node *node,
2890f374561SHaojian Zhuang 			      struct device_node *parent)
2900f374561SHaojian Zhuang {
2910f374561SHaojian Zhuang 	int ret;
2920f374561SHaojian Zhuang 
2930f374561SHaojian Zhuang 	ret = mmp_init_bases(node);
2940f374561SHaojian Zhuang 	if (ret < 0)
2950f374561SHaojian Zhuang 		return ret;
2960f374561SHaojian Zhuang 
2970f374561SHaojian Zhuang 	icu_data[0].conf_enable = mmp_conf.conf_enable;
2980f374561SHaojian Zhuang 	icu_data[0].conf_disable = mmp_conf.conf_disable;
2990f374561SHaojian Zhuang 	icu_data[0].conf_mask = mmp_conf.conf_mask;
3000f374561SHaojian Zhuang 	set_handle_irq(mmp_handle_irq);
3010f374561SHaojian Zhuang 	max_icu_nr = 1;
3020f374561SHaojian Zhuang 	return 0;
3030f374561SHaojian Zhuang }
3040f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp_intc, "mrvl,mmp-intc", mmp_of_init);
3050f374561SHaojian Zhuang 
mmp2_of_init(struct device_node * node,struct device_node * parent)3060f374561SHaojian Zhuang static int __init mmp2_of_init(struct device_node *node,
3070f374561SHaojian Zhuang 			       struct device_node *parent)
3080f374561SHaojian Zhuang {
3090f374561SHaojian Zhuang 	int ret;
3100f374561SHaojian Zhuang 
3110f374561SHaojian Zhuang 	ret = mmp_init_bases(node);
3120f374561SHaojian Zhuang 	if (ret < 0)
3130f374561SHaojian Zhuang 		return ret;
3140f374561SHaojian Zhuang 
3150f374561SHaojian Zhuang 	icu_data[0].conf_enable = mmp2_conf.conf_enable;
3160f374561SHaojian Zhuang 	icu_data[0].conf_disable = mmp2_conf.conf_disable;
3170f374561SHaojian Zhuang 	icu_data[0].conf_mask = mmp2_conf.conf_mask;
3180f374561SHaojian Zhuang 	set_handle_irq(mmp2_handle_irq);
3190f374561SHaojian Zhuang 	max_icu_nr = 1;
3200f374561SHaojian Zhuang 	return 0;
3210f374561SHaojian Zhuang }
3220f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_intc, "mrvl,mmp2-intc", mmp2_of_init);
3230f374561SHaojian Zhuang 
mmp3_of_init(struct device_node * node,struct device_node * parent)3249e8e8912SAndres Salomon static int __init mmp3_of_init(struct device_node *node,
3259e8e8912SAndres Salomon 			       struct device_node *parent)
3269e8e8912SAndres Salomon {
3279e8e8912SAndres Salomon 	int ret;
3289e8e8912SAndres Salomon 
3299e8e8912SAndres Salomon 	mmp_icu2_base = of_iomap(node, 1);
3309e8e8912SAndres Salomon 	if (!mmp_icu2_base) {
3319e8e8912SAndres Salomon 		pr_err("Failed to get interrupt controller register #2\n");
3329e8e8912SAndres Salomon 		return -ENODEV;
3339e8e8912SAndres Salomon 	}
3349e8e8912SAndres Salomon 
3359e8e8912SAndres Salomon 	ret = mmp_init_bases(node);
3369e8e8912SAndres Salomon 	if (ret < 0) {
3379e8e8912SAndres Salomon 		iounmap(mmp_icu2_base);
3389e8e8912SAndres Salomon 		return ret;
3399e8e8912SAndres Salomon 	}
3409e8e8912SAndres Salomon 
3419e8e8912SAndres Salomon 	icu_data[0].conf_enable = mmp3_conf.conf_enable;
3429e8e8912SAndres Salomon 	icu_data[0].conf_disable = mmp3_conf.conf_disable;
3439e8e8912SAndres Salomon 	icu_data[0].conf_mask = mmp3_conf.conf_mask;
3449e8e8912SAndres Salomon 	icu_data[0].conf2_mask = mmp3_conf.conf2_mask;
3452178add0SLubomir Rintel 
3462178add0SLubomir Rintel 	if (!parent) {
3472178add0SLubomir Rintel 		/* This is the main interrupt controller. */
3489e8e8912SAndres Salomon 		set_handle_irq(mmp2_handle_irq);
3492178add0SLubomir Rintel 	}
3502178add0SLubomir Rintel 
3519e8e8912SAndres Salomon 	max_icu_nr = 1;
3529e8e8912SAndres Salomon 	return 0;
3539e8e8912SAndres Salomon }
3549e8e8912SAndres Salomon IRQCHIP_DECLARE(mmp3_intc, "marvell,mmp3-intc", mmp3_of_init);
3559e8e8912SAndres Salomon 
mmp2_mux_of_init(struct device_node * node,struct device_node * parent)3560f374561SHaojian Zhuang static int __init mmp2_mux_of_init(struct device_node *node,
3570f374561SHaojian Zhuang 				   struct device_node *parent)
3580f374561SHaojian Zhuang {
3590f374561SHaojian Zhuang 	int i, ret, irq, j = 0;
3600f374561SHaojian Zhuang 	u32 nr_irqs, mfp_irq;
361d6a95280SLubomir Rintel 	u32 reg[4];
3620f374561SHaojian Zhuang 
3630f374561SHaojian Zhuang 	if (!parent)
3640f374561SHaojian Zhuang 		return -ENODEV;
3650f374561SHaojian Zhuang 
3660f374561SHaojian Zhuang 	i = max_icu_nr;
3670f374561SHaojian Zhuang 	ret = of_property_read_u32(node, "mrvl,intc-nr-irqs",
3680f374561SHaojian Zhuang 				   &nr_irqs);
3690f374561SHaojian Zhuang 	if (ret) {
3700f374561SHaojian Zhuang 		pr_err("Not found mrvl,intc-nr-irqs property\n");
3710f374561SHaojian Zhuang 		return -EINVAL;
3720f374561SHaojian Zhuang 	}
373d6a95280SLubomir Rintel 
374d6a95280SLubomir Rintel 	/*
375d6a95280SLubomir Rintel 	 * For historical reasons, the "regs" property of the
376d6a95280SLubomir Rintel 	 * mrvl,mmp2-mux-intc is not a regular "regs" property containing
377d6a95280SLubomir Rintel 	 * addresses on the parent bus, but offsets from the intc's base.
378d6a95280SLubomir Rintel 	 * That is why we can't use of_address_to_resource() here.
379d6a95280SLubomir Rintel 	 */
380d6a95280SLubomir Rintel 	ret = of_property_read_variable_u32_array(node, "reg", reg,
381d6a95280SLubomir Rintel 						  ARRAY_SIZE(reg),
382d6a95280SLubomir Rintel 						  ARRAY_SIZE(reg));
3830f374561SHaojian Zhuang 	if (ret < 0) {
3840f374561SHaojian Zhuang 		pr_err("Not found reg property\n");
3850f374561SHaojian Zhuang 		return -EINVAL;
3860f374561SHaojian Zhuang 	}
387d6a95280SLubomir Rintel 	icu_data[i].reg_status = mmp_icu_base + reg[0];
388d6a95280SLubomir Rintel 	icu_data[i].reg_mask = mmp_icu_base + reg[2];
3890f374561SHaojian Zhuang 	icu_data[i].cascade_irq = irq_of_parse_and_map(node, 0);
3900f374561SHaojian Zhuang 	if (!icu_data[i].cascade_irq)
3910f374561SHaojian Zhuang 		return -EINVAL;
3920f374561SHaojian Zhuang 
3930f374561SHaojian Zhuang 	icu_data[i].virq_base = 0;
3940f374561SHaojian Zhuang 	icu_data[i].domain = irq_domain_add_linear(node, nr_irqs,
3950f374561SHaojian Zhuang 						   &mmp_irq_domain_ops,
3960f374561SHaojian Zhuang 						   &icu_data[i]);
3970f374561SHaojian Zhuang 	for (irq = 0; irq < nr_irqs; irq++) {
3980f374561SHaojian Zhuang 		ret = irq_create_mapping(icu_data[i].domain, irq);
3990f374561SHaojian Zhuang 		if (!ret) {
4000f374561SHaojian Zhuang 			pr_err("Failed to mapping hwirq\n");
4010f374561SHaojian Zhuang 			goto err;
4020f374561SHaojian Zhuang 		}
4030f374561SHaojian Zhuang 		if (!irq)
4040f374561SHaojian Zhuang 			icu_data[i].virq_base = ret;
4050f374561SHaojian Zhuang 	}
4060f374561SHaojian Zhuang 	icu_data[i].nr_irqs = nr_irqs;
4070f374561SHaojian Zhuang 	if (!of_property_read_u32(node, "mrvl,clr-mfp-irq",
4080f374561SHaojian Zhuang 				  &mfp_irq)) {
4090f374561SHaojian Zhuang 		icu_data[i].clr_mfp_irq_base = icu_data[i].virq_base;
4100f374561SHaojian Zhuang 		icu_data[i].clr_mfp_hwirq = mfp_irq;
4110f374561SHaojian Zhuang 	}
4120f374561SHaojian Zhuang 	irq_set_chained_handler(icu_data[i].cascade_irq,
4130f374561SHaojian Zhuang 				icu_mux_irq_demux);
4140f374561SHaojian Zhuang 	max_icu_nr++;
4150f374561SHaojian Zhuang 	return 0;
4160f374561SHaojian Zhuang err:
4170f374561SHaojian Zhuang 	if (icu_data[i].virq_base) {
4180f374561SHaojian Zhuang 		for (j = 0; j < irq; j++)
4190f374561SHaojian Zhuang 			irq_dispose_mapping(icu_data[i].virq_base + j);
4200f374561SHaojian Zhuang 	}
4210f374561SHaojian Zhuang 	irq_domain_remove(icu_data[i].domain);
4220f374561SHaojian Zhuang 	return -EINVAL;
4230f374561SHaojian Zhuang }
4240f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_mux_intc, "mrvl,mmp2-mux-intc", mmp2_mux_of_init);
425