xref: /linux/drivers/irqchip/irq-mmp.c (revision 14873aa1d1c97a11cec57ae1345da467d4b6d4d7)
1c052d13cSHaojian Zhuang /*
2c052d13cSHaojian Zhuang  *  linux/arch/arm/mach-mmp/irq.c
3c052d13cSHaojian Zhuang  *
4c052d13cSHaojian Zhuang  *  Generic IRQ handling, GPIO IRQ demultiplexing, etc.
5c052d13cSHaojian Zhuang  *  Copyright (C) 2008 - 2012 Marvell Technology Group Ltd.
6c052d13cSHaojian Zhuang  *
7c052d13cSHaojian Zhuang  *  Author:	Bin Yang <bin.yang@marvell.com>
8c052d13cSHaojian Zhuang  *              Haojian Zhuang <haojian.zhuang@gmail.com>
9c052d13cSHaojian Zhuang  *
10c052d13cSHaojian Zhuang  *  This program is free software; you can redistribute it and/or modify
11c052d13cSHaojian Zhuang  *  it under the terms of the GNU General Public License version 2 as
12c052d13cSHaojian Zhuang  *  published by the Free Software Foundation.
13c052d13cSHaojian Zhuang  */
14c052d13cSHaojian Zhuang 
15c052d13cSHaojian Zhuang #include <linux/module.h>
16c052d13cSHaojian Zhuang #include <linux/init.h>
17c052d13cSHaojian Zhuang #include <linux/irq.h>
1841a83e06SJoel Porquet #include <linux/irqchip.h>
19c052d13cSHaojian Zhuang #include <linux/irqdomain.h>
20c052d13cSHaojian Zhuang #include <linux/io.h>
21c052d13cSHaojian Zhuang #include <linux/ioport.h>
22c052d13cSHaojian Zhuang #include <linux/of_address.h>
23c052d13cSHaojian Zhuang #include <linux/of_irq.h>
24c052d13cSHaojian Zhuang 
250f374561SHaojian Zhuang #include <asm/exception.h>
2613dde818SNeil Zhang #include <asm/hardirq.h>
270f374561SHaojian Zhuang 
28c052d13cSHaojian Zhuang #define MAX_ICU_NR		16
29c052d13cSHaojian Zhuang 
300f374561SHaojian Zhuang #define PJ1_INT_SEL		0x10c
310f374561SHaojian Zhuang #define PJ4_INT_SEL		0x104
320f374561SHaojian Zhuang 
330f374561SHaojian Zhuang /* bit fields in PJ1_INT_SEL and PJ4_INT_SEL */
340f374561SHaojian Zhuang #define SEL_INT_PENDING		(1 << 6)
350f374561SHaojian Zhuang #define SEL_INT_NUM_MASK	0x3f
360f374561SHaojian Zhuang 
37c052d13cSHaojian Zhuang struct icu_chip_data {
38c052d13cSHaojian Zhuang 	int			nr_irqs;
39c052d13cSHaojian Zhuang 	unsigned int		virq_base;
40c052d13cSHaojian Zhuang 	unsigned int		cascade_irq;
41c052d13cSHaojian Zhuang 	void __iomem		*reg_status;
42c052d13cSHaojian Zhuang 	void __iomem		*reg_mask;
43c052d13cSHaojian Zhuang 	unsigned int		conf_enable;
44c052d13cSHaojian Zhuang 	unsigned int		conf_disable;
45c052d13cSHaojian Zhuang 	unsigned int		conf_mask;
46c052d13cSHaojian Zhuang 	unsigned int		clr_mfp_irq_base;
47c052d13cSHaojian Zhuang 	unsigned int		clr_mfp_hwirq;
48c052d13cSHaojian Zhuang 	struct irq_domain	*domain;
49c052d13cSHaojian Zhuang };
50c052d13cSHaojian Zhuang 
51c052d13cSHaojian Zhuang struct mmp_intc_conf {
52c052d13cSHaojian Zhuang 	unsigned int	conf_enable;
53c052d13cSHaojian Zhuang 	unsigned int	conf_disable;
54c052d13cSHaojian Zhuang 	unsigned int	conf_mask;
55c052d13cSHaojian Zhuang };
56c052d13cSHaojian Zhuang 
570f374561SHaojian Zhuang static void __iomem *mmp_icu_base;
58c052d13cSHaojian Zhuang static struct icu_chip_data icu_data[MAX_ICU_NR];
59c052d13cSHaojian Zhuang static int max_icu_nr;
60c052d13cSHaojian Zhuang 
61c052d13cSHaojian Zhuang extern void mmp2_clear_pmic_int(void);
62c052d13cSHaojian Zhuang 
63c052d13cSHaojian Zhuang static void icu_mask_ack_irq(struct irq_data *d)
64c052d13cSHaojian Zhuang {
65c052d13cSHaojian Zhuang 	struct irq_domain *domain = d->domain;
66c052d13cSHaojian Zhuang 	struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
67c052d13cSHaojian Zhuang 	int hwirq;
68c052d13cSHaojian Zhuang 	u32 r;
69c052d13cSHaojian Zhuang 
70c052d13cSHaojian Zhuang 	hwirq = d->irq - data->virq_base;
71c052d13cSHaojian Zhuang 	if (data == &icu_data[0]) {
72c052d13cSHaojian Zhuang 		r = readl_relaxed(mmp_icu_base + (hwirq << 2));
73c052d13cSHaojian Zhuang 		r &= ~data->conf_mask;
74c052d13cSHaojian Zhuang 		r |= data->conf_disable;
75c052d13cSHaojian Zhuang 		writel_relaxed(r, mmp_icu_base + (hwirq << 2));
76c052d13cSHaojian Zhuang 	} else {
77c052d13cSHaojian Zhuang #ifdef CONFIG_CPU_MMP2
78c052d13cSHaojian Zhuang 		if ((data->virq_base == data->clr_mfp_irq_base)
79c052d13cSHaojian Zhuang 			&& (hwirq == data->clr_mfp_hwirq))
80c052d13cSHaojian Zhuang 			mmp2_clear_pmic_int();
81c052d13cSHaojian Zhuang #endif
82c052d13cSHaojian Zhuang 		r = readl_relaxed(data->reg_mask) | (1 << hwirq);
83c052d13cSHaojian Zhuang 		writel_relaxed(r, data->reg_mask);
84c052d13cSHaojian Zhuang 	}
85c052d13cSHaojian Zhuang }
86c052d13cSHaojian Zhuang 
87c052d13cSHaojian Zhuang static void icu_mask_irq(struct irq_data *d)
88c052d13cSHaojian Zhuang {
89c052d13cSHaojian Zhuang 	struct irq_domain *domain = d->domain;
90c052d13cSHaojian Zhuang 	struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
91c052d13cSHaojian Zhuang 	int hwirq;
92c052d13cSHaojian Zhuang 	u32 r;
93c052d13cSHaojian Zhuang 
94c052d13cSHaojian Zhuang 	hwirq = d->irq - data->virq_base;
95c052d13cSHaojian Zhuang 	if (data == &icu_data[0]) {
96c052d13cSHaojian Zhuang 		r = readl_relaxed(mmp_icu_base + (hwirq << 2));
97c052d13cSHaojian Zhuang 		r &= ~data->conf_mask;
98c052d13cSHaojian Zhuang 		r |= data->conf_disable;
99c052d13cSHaojian Zhuang 		writel_relaxed(r, mmp_icu_base + (hwirq << 2));
100c052d13cSHaojian Zhuang 	} else {
101c052d13cSHaojian Zhuang 		r = readl_relaxed(data->reg_mask) | (1 << hwirq);
102c052d13cSHaojian Zhuang 		writel_relaxed(r, data->reg_mask);
103c052d13cSHaojian Zhuang 	}
104c052d13cSHaojian Zhuang }
105c052d13cSHaojian Zhuang 
106c052d13cSHaojian Zhuang static void icu_unmask_irq(struct irq_data *d)
107c052d13cSHaojian Zhuang {
108c052d13cSHaojian Zhuang 	struct irq_domain *domain = d->domain;
109c052d13cSHaojian Zhuang 	struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
110c052d13cSHaojian Zhuang 	int hwirq;
111c052d13cSHaojian Zhuang 	u32 r;
112c052d13cSHaojian Zhuang 
113c052d13cSHaojian Zhuang 	hwirq = d->irq - data->virq_base;
114c052d13cSHaojian Zhuang 	if (data == &icu_data[0]) {
115c052d13cSHaojian Zhuang 		r = readl_relaxed(mmp_icu_base + (hwirq << 2));
116c052d13cSHaojian Zhuang 		r &= ~data->conf_mask;
117c052d13cSHaojian Zhuang 		r |= data->conf_enable;
118c052d13cSHaojian Zhuang 		writel_relaxed(r, mmp_icu_base + (hwirq << 2));
119c052d13cSHaojian Zhuang 	} else {
120c052d13cSHaojian Zhuang 		r = readl_relaxed(data->reg_mask) & ~(1 << hwirq);
121c052d13cSHaojian Zhuang 		writel_relaxed(r, data->reg_mask);
122c052d13cSHaojian Zhuang 	}
123c052d13cSHaojian Zhuang }
124c052d13cSHaojian Zhuang 
1250f102b6cSHaojian Zhuang struct irq_chip icu_irq_chip = {
126c052d13cSHaojian Zhuang 	.name		= "icu_irq",
127c052d13cSHaojian Zhuang 	.irq_mask	= icu_mask_irq,
128c052d13cSHaojian Zhuang 	.irq_mask_ack	= icu_mask_ack_irq,
129c052d13cSHaojian Zhuang 	.irq_unmask	= icu_unmask_irq,
130c052d13cSHaojian Zhuang };
131c052d13cSHaojian Zhuang 
132*14873aa1SThomas Gleixner static void icu_mux_irq_demux(unsigned int __irq, struct irq_desc *desc)
133c052d13cSHaojian Zhuang {
134*14873aa1SThomas Gleixner 	unsigned int irq = irq_desc_get_irq(desc);
135c052d13cSHaojian Zhuang 	struct irq_domain *domain;
136c052d13cSHaojian Zhuang 	struct icu_chip_data *data;
137c052d13cSHaojian Zhuang 	int i;
138c052d13cSHaojian Zhuang 	unsigned long mask, status, n;
139c052d13cSHaojian Zhuang 
140c052d13cSHaojian Zhuang 	for (i = 1; i < max_icu_nr; i++) {
141c052d13cSHaojian Zhuang 		if (irq == icu_data[i].cascade_irq) {
142c052d13cSHaojian Zhuang 			domain = icu_data[i].domain;
143c052d13cSHaojian Zhuang 			data = (struct icu_chip_data *)domain->host_data;
144c052d13cSHaojian Zhuang 			break;
145c052d13cSHaojian Zhuang 		}
146c052d13cSHaojian Zhuang 	}
147c052d13cSHaojian Zhuang 	if (i >= max_icu_nr) {
148c052d13cSHaojian Zhuang 		pr_err("Spurious irq %d in MMP INTC\n", irq);
149c052d13cSHaojian Zhuang 		return;
150c052d13cSHaojian Zhuang 	}
151c052d13cSHaojian Zhuang 
152c052d13cSHaojian Zhuang 	mask = readl_relaxed(data->reg_mask);
153c052d13cSHaojian Zhuang 	while (1) {
154c052d13cSHaojian Zhuang 		status = readl_relaxed(data->reg_status) & ~mask;
155c052d13cSHaojian Zhuang 		if (status == 0)
156c052d13cSHaojian Zhuang 			break;
157c052d13cSHaojian Zhuang 		for_each_set_bit(n, &status, BITS_PER_LONG) {
158c052d13cSHaojian Zhuang 			generic_handle_irq(icu_data[i].virq_base + n);
159c052d13cSHaojian Zhuang 		}
160c052d13cSHaojian Zhuang 	}
161c052d13cSHaojian Zhuang }
162c052d13cSHaojian Zhuang 
163c052d13cSHaojian Zhuang static int mmp_irq_domain_map(struct irq_domain *d, unsigned int irq,
164c052d13cSHaojian Zhuang 			      irq_hw_number_t hw)
165c052d13cSHaojian Zhuang {
166c052d13cSHaojian Zhuang 	irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq);
167c052d13cSHaojian Zhuang 	set_irq_flags(irq, IRQF_VALID);
168c052d13cSHaojian Zhuang 	return 0;
169c052d13cSHaojian Zhuang }
170c052d13cSHaojian Zhuang 
171c052d13cSHaojian Zhuang static int mmp_irq_domain_xlate(struct irq_domain *d, struct device_node *node,
172c052d13cSHaojian Zhuang 				const u32 *intspec, unsigned int intsize,
173c052d13cSHaojian Zhuang 				unsigned long *out_hwirq,
174c052d13cSHaojian Zhuang 				unsigned int *out_type)
175c052d13cSHaojian Zhuang {
176c052d13cSHaojian Zhuang 	*out_hwirq = intspec[0];
177c052d13cSHaojian Zhuang 	return 0;
178c052d13cSHaojian Zhuang }
179c052d13cSHaojian Zhuang 
180c052d13cSHaojian Zhuang const struct irq_domain_ops mmp_irq_domain_ops = {
181c052d13cSHaojian Zhuang 	.map		= mmp_irq_domain_map,
182c052d13cSHaojian Zhuang 	.xlate		= mmp_irq_domain_xlate,
183c052d13cSHaojian Zhuang };
184c052d13cSHaojian Zhuang 
185c052d13cSHaojian Zhuang static struct mmp_intc_conf mmp_conf = {
186c052d13cSHaojian Zhuang 	.conf_enable	= 0x51,
187c052d13cSHaojian Zhuang 	.conf_disable	= 0x0,
188c052d13cSHaojian Zhuang 	.conf_mask	= 0x7f,
189c052d13cSHaojian Zhuang };
190c052d13cSHaojian Zhuang 
191c052d13cSHaojian Zhuang static struct mmp_intc_conf mmp2_conf = {
192c052d13cSHaojian Zhuang 	.conf_enable	= 0x20,
193c052d13cSHaojian Zhuang 	.conf_disable	= 0x0,
194c052d13cSHaojian Zhuang 	.conf_mask	= 0x7f,
195c052d13cSHaojian Zhuang };
196c052d13cSHaojian Zhuang 
1978783dd3aSStephen Boyd static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs)
1980f374561SHaojian Zhuang {
199b918402cSMarc Zyngier 	int hwirq;
2000f374561SHaojian Zhuang 
2010f374561SHaojian Zhuang 	hwirq = readl_relaxed(mmp_icu_base + PJ1_INT_SEL);
2020f374561SHaojian Zhuang 	if (!(hwirq & SEL_INT_PENDING))
2030f374561SHaojian Zhuang 		return;
2040f374561SHaojian Zhuang 	hwirq &= SEL_INT_NUM_MASK;
205b918402cSMarc Zyngier 	handle_domain_irq(icu_data[0].domain, hwirq, regs);
2060f374561SHaojian Zhuang }
2070f374561SHaojian Zhuang 
2088783dd3aSStephen Boyd static void __exception_irq_entry mmp2_handle_irq(struct pt_regs *regs)
2090f374561SHaojian Zhuang {
210b918402cSMarc Zyngier 	int hwirq;
2110f374561SHaojian Zhuang 
2120f374561SHaojian Zhuang 	hwirq = readl_relaxed(mmp_icu_base + PJ4_INT_SEL);
2130f374561SHaojian Zhuang 	if (!(hwirq & SEL_INT_PENDING))
2140f374561SHaojian Zhuang 		return;
2150f374561SHaojian Zhuang 	hwirq &= SEL_INT_NUM_MASK;
216b918402cSMarc Zyngier 	handle_domain_irq(icu_data[0].domain, hwirq, regs);
2170f374561SHaojian Zhuang }
2180f374561SHaojian Zhuang 
219c052d13cSHaojian Zhuang /* MMP (ARMv5) */
220c052d13cSHaojian Zhuang void __init icu_init_irq(void)
221c052d13cSHaojian Zhuang {
222c052d13cSHaojian Zhuang 	int irq;
223c052d13cSHaojian Zhuang 
224c052d13cSHaojian Zhuang 	max_icu_nr = 1;
225c052d13cSHaojian Zhuang 	mmp_icu_base = ioremap(0xd4282000, 0x1000);
226c052d13cSHaojian Zhuang 	icu_data[0].conf_enable = mmp_conf.conf_enable;
227c052d13cSHaojian Zhuang 	icu_data[0].conf_disable = mmp_conf.conf_disable;
228c052d13cSHaojian Zhuang 	icu_data[0].conf_mask = mmp_conf.conf_mask;
229c052d13cSHaojian Zhuang 	icu_data[0].nr_irqs = 64;
230c052d13cSHaojian Zhuang 	icu_data[0].virq_base = 0;
231c052d13cSHaojian Zhuang 	icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0,
232c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
233c052d13cSHaojian Zhuang 						   &icu_data[0]);
234c052d13cSHaojian Zhuang 	for (irq = 0; irq < 64; irq++) {
235c052d13cSHaojian Zhuang 		icu_mask_irq(irq_get_irq_data(irq));
236c052d13cSHaojian Zhuang 		irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq);
237c052d13cSHaojian Zhuang 		set_irq_flags(irq, IRQF_VALID);
238c052d13cSHaojian Zhuang 	}
239c052d13cSHaojian Zhuang 	irq_set_default_host(icu_data[0].domain);
2400f374561SHaojian Zhuang 	set_handle_irq(mmp_handle_irq);
241c052d13cSHaojian Zhuang }
242c052d13cSHaojian Zhuang 
243c052d13cSHaojian Zhuang /* MMP2 (ARMv7) */
244c052d13cSHaojian Zhuang void __init mmp2_init_icu(void)
245c052d13cSHaojian Zhuang {
246942f4221SHaojian Zhuang 	int irq, end;
247c052d13cSHaojian Zhuang 
248c052d13cSHaojian Zhuang 	max_icu_nr = 8;
249c052d13cSHaojian Zhuang 	mmp_icu_base = ioremap(0xd4282000, 0x1000);
250c052d13cSHaojian Zhuang 	icu_data[0].conf_enable = mmp2_conf.conf_enable;
251c052d13cSHaojian Zhuang 	icu_data[0].conf_disable = mmp2_conf.conf_disable;
252c052d13cSHaojian Zhuang 	icu_data[0].conf_mask = mmp2_conf.conf_mask;
253c052d13cSHaojian Zhuang 	icu_data[0].nr_irqs = 64;
254c052d13cSHaojian Zhuang 	icu_data[0].virq_base = 0;
255c052d13cSHaojian Zhuang 	icu_data[0].domain = irq_domain_add_legacy(NULL, 64, 0, 0,
256c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
257c052d13cSHaojian Zhuang 						   &icu_data[0]);
258c052d13cSHaojian Zhuang 	icu_data[1].reg_status = mmp_icu_base + 0x150;
259c052d13cSHaojian Zhuang 	icu_data[1].reg_mask = mmp_icu_base + 0x168;
260942f4221SHaojian Zhuang 	icu_data[1].clr_mfp_irq_base = icu_data[0].virq_base +
261942f4221SHaojian Zhuang 				icu_data[0].nr_irqs;
262942f4221SHaojian Zhuang 	icu_data[1].clr_mfp_hwirq = 1;		/* offset to IRQ_MMP2_PMIC_BASE */
263c052d13cSHaojian Zhuang 	icu_data[1].nr_irqs = 2;
264c052d13cSHaojian Zhuang 	icu_data[1].cascade_irq = 4;
265942f4221SHaojian Zhuang 	icu_data[1].virq_base = icu_data[0].virq_base + icu_data[0].nr_irqs;
266c052d13cSHaojian Zhuang 	icu_data[1].domain = irq_domain_add_legacy(NULL, icu_data[1].nr_irqs,
267c052d13cSHaojian Zhuang 						   icu_data[1].virq_base, 0,
268c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
269c052d13cSHaojian Zhuang 						   &icu_data[1]);
270c052d13cSHaojian Zhuang 	icu_data[2].reg_status = mmp_icu_base + 0x154;
271c052d13cSHaojian Zhuang 	icu_data[2].reg_mask = mmp_icu_base + 0x16c;
272c052d13cSHaojian Zhuang 	icu_data[2].nr_irqs = 2;
273c052d13cSHaojian Zhuang 	icu_data[2].cascade_irq = 5;
274942f4221SHaojian Zhuang 	icu_data[2].virq_base = icu_data[1].virq_base + icu_data[1].nr_irqs;
275c052d13cSHaojian Zhuang 	icu_data[2].domain = irq_domain_add_legacy(NULL, icu_data[2].nr_irqs,
276c052d13cSHaojian Zhuang 						   icu_data[2].virq_base, 0,
277c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
278c052d13cSHaojian Zhuang 						   &icu_data[2]);
279c052d13cSHaojian Zhuang 	icu_data[3].reg_status = mmp_icu_base + 0x180;
280c052d13cSHaojian Zhuang 	icu_data[3].reg_mask = mmp_icu_base + 0x17c;
281c052d13cSHaojian Zhuang 	icu_data[3].nr_irqs = 3;
282c052d13cSHaojian Zhuang 	icu_data[3].cascade_irq = 9;
283942f4221SHaojian Zhuang 	icu_data[3].virq_base = icu_data[2].virq_base + icu_data[2].nr_irqs;
284c052d13cSHaojian Zhuang 	icu_data[3].domain = irq_domain_add_legacy(NULL, icu_data[3].nr_irqs,
285c052d13cSHaojian Zhuang 						   icu_data[3].virq_base, 0,
286c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
287c052d13cSHaojian Zhuang 						   &icu_data[3]);
288c052d13cSHaojian Zhuang 	icu_data[4].reg_status = mmp_icu_base + 0x158;
289c052d13cSHaojian Zhuang 	icu_data[4].reg_mask = mmp_icu_base + 0x170;
290c052d13cSHaojian Zhuang 	icu_data[4].nr_irqs = 5;
291c052d13cSHaojian Zhuang 	icu_data[4].cascade_irq = 17;
292942f4221SHaojian Zhuang 	icu_data[4].virq_base = icu_data[3].virq_base + icu_data[3].nr_irqs;
293c052d13cSHaojian Zhuang 	icu_data[4].domain = irq_domain_add_legacy(NULL, icu_data[4].nr_irqs,
294c052d13cSHaojian Zhuang 						   icu_data[4].virq_base, 0,
295c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
296c052d13cSHaojian Zhuang 						   &icu_data[4]);
297c052d13cSHaojian Zhuang 	icu_data[5].reg_status = mmp_icu_base + 0x15c;
298c052d13cSHaojian Zhuang 	icu_data[5].reg_mask = mmp_icu_base + 0x174;
299c052d13cSHaojian Zhuang 	icu_data[5].nr_irqs = 15;
300c052d13cSHaojian Zhuang 	icu_data[5].cascade_irq = 35;
301942f4221SHaojian Zhuang 	icu_data[5].virq_base = icu_data[4].virq_base + icu_data[4].nr_irqs;
302c052d13cSHaojian Zhuang 	icu_data[5].domain = irq_domain_add_legacy(NULL, icu_data[5].nr_irqs,
303c052d13cSHaojian Zhuang 						   icu_data[5].virq_base, 0,
304c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
305c052d13cSHaojian Zhuang 						   &icu_data[5]);
306c052d13cSHaojian Zhuang 	icu_data[6].reg_status = mmp_icu_base + 0x160;
307c052d13cSHaojian Zhuang 	icu_data[6].reg_mask = mmp_icu_base + 0x178;
308c052d13cSHaojian Zhuang 	icu_data[6].nr_irqs = 2;
309c052d13cSHaojian Zhuang 	icu_data[6].cascade_irq = 51;
310942f4221SHaojian Zhuang 	icu_data[6].virq_base = icu_data[5].virq_base + icu_data[5].nr_irqs;
311c052d13cSHaojian Zhuang 	icu_data[6].domain = irq_domain_add_legacy(NULL, icu_data[6].nr_irqs,
312c052d13cSHaojian Zhuang 						   icu_data[6].virq_base, 0,
313c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
314c052d13cSHaojian Zhuang 						   &icu_data[6]);
315c052d13cSHaojian Zhuang 	icu_data[7].reg_status = mmp_icu_base + 0x188;
316c052d13cSHaojian Zhuang 	icu_data[7].reg_mask = mmp_icu_base + 0x184;
317c052d13cSHaojian Zhuang 	icu_data[7].nr_irqs = 2;
318c052d13cSHaojian Zhuang 	icu_data[7].cascade_irq = 55;
319942f4221SHaojian Zhuang 	icu_data[7].virq_base = icu_data[6].virq_base + icu_data[6].nr_irqs;
320c052d13cSHaojian Zhuang 	icu_data[7].domain = irq_domain_add_legacy(NULL, icu_data[7].nr_irqs,
321c052d13cSHaojian Zhuang 						   icu_data[7].virq_base, 0,
322c052d13cSHaojian Zhuang 						   &irq_domain_simple_ops,
323c052d13cSHaojian Zhuang 						   &icu_data[7]);
324942f4221SHaojian Zhuang 	end = icu_data[7].virq_base + icu_data[7].nr_irqs;
325942f4221SHaojian Zhuang 	for (irq = 0; irq < end; irq++) {
326c052d13cSHaojian Zhuang 		icu_mask_irq(irq_get_irq_data(irq));
327942f4221SHaojian Zhuang 		if (irq == icu_data[1].cascade_irq ||
328942f4221SHaojian Zhuang 		    irq == icu_data[2].cascade_irq ||
329942f4221SHaojian Zhuang 		    irq == icu_data[3].cascade_irq ||
330942f4221SHaojian Zhuang 		    irq == icu_data[4].cascade_irq ||
331942f4221SHaojian Zhuang 		    irq == icu_data[5].cascade_irq ||
332942f4221SHaojian Zhuang 		    irq == icu_data[6].cascade_irq ||
333942f4221SHaojian Zhuang 		    irq == icu_data[7].cascade_irq) {
334c052d13cSHaojian Zhuang 			irq_set_chip(irq, &icu_irq_chip);
335c052d13cSHaojian Zhuang 			irq_set_chained_handler(irq, icu_mux_irq_demux);
336942f4221SHaojian Zhuang 		} else {
337c052d13cSHaojian Zhuang 			irq_set_chip_and_handler(irq, &icu_irq_chip,
338c052d13cSHaojian Zhuang 						 handle_level_irq);
339c052d13cSHaojian Zhuang 		}
340c052d13cSHaojian Zhuang 		set_irq_flags(irq, IRQF_VALID);
341c052d13cSHaojian Zhuang 	}
342c052d13cSHaojian Zhuang 	irq_set_default_host(icu_data[0].domain);
3430f374561SHaojian Zhuang 	set_handle_irq(mmp2_handle_irq);
344c052d13cSHaojian Zhuang }
345c052d13cSHaojian Zhuang 
346c052d13cSHaojian Zhuang #ifdef CONFIG_OF
3470f374561SHaojian Zhuang static int __init mmp_init_bases(struct device_node *node)
348c052d13cSHaojian Zhuang {
3490f374561SHaojian Zhuang 	int ret, nr_irqs, irq, i = 0;
350c052d13cSHaojian Zhuang 
351c052d13cSHaojian Zhuang 	ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", &nr_irqs);
352c052d13cSHaojian Zhuang 	if (ret) {
353c052d13cSHaojian Zhuang 		pr_err("Not found mrvl,intc-nr-irqs property\n");
3540f374561SHaojian Zhuang 		return ret;
355c052d13cSHaojian Zhuang 	}
356c052d13cSHaojian Zhuang 
357c052d13cSHaojian Zhuang 	mmp_icu_base = of_iomap(node, 0);
358c052d13cSHaojian Zhuang 	if (!mmp_icu_base) {
359c052d13cSHaojian Zhuang 		pr_err("Failed to get interrupt controller register\n");
3600f374561SHaojian Zhuang 		return -ENOMEM;
361c052d13cSHaojian Zhuang 	}
362c052d13cSHaojian Zhuang 
363c052d13cSHaojian Zhuang 	icu_data[0].virq_base = 0;
3640f374561SHaojian Zhuang 	icu_data[0].domain = irq_domain_add_linear(node, nr_irqs,
365c052d13cSHaojian Zhuang 						   &mmp_irq_domain_ops,
366c052d13cSHaojian Zhuang 						   &icu_data[0]);
3670f374561SHaojian Zhuang 	for (irq = 0; irq < nr_irqs; irq++) {
3680f374561SHaojian Zhuang 		ret = irq_create_mapping(icu_data[0].domain, irq);
3690f374561SHaojian Zhuang 		if (!ret) {
3700f374561SHaojian Zhuang 			pr_err("Failed to mapping hwirq\n");
3710f374561SHaojian Zhuang 			goto err;
372c052d13cSHaojian Zhuang 		}
3730f374561SHaojian Zhuang 		if (!irq)
3740f374561SHaojian Zhuang 			icu_data[0].virq_base = ret;
3750f374561SHaojian Zhuang 	}
3760f374561SHaojian Zhuang 	icu_data[0].nr_irqs = nr_irqs;
3770f374561SHaojian Zhuang 	return 0;
3780f374561SHaojian Zhuang err:
3790f374561SHaojian Zhuang 	if (icu_data[0].virq_base) {
3800f374561SHaojian Zhuang 		for (i = 0; i < irq; i++)
3810f374561SHaojian Zhuang 			irq_dispose_mapping(icu_data[0].virq_base + i);
3820f374561SHaojian Zhuang 	}
3830f374561SHaojian Zhuang 	irq_domain_remove(icu_data[0].domain);
3840f374561SHaojian Zhuang 	iounmap(mmp_icu_base);
3850f374561SHaojian Zhuang 	return -EINVAL;
3860f374561SHaojian Zhuang }
3870f374561SHaojian Zhuang 
3880f374561SHaojian Zhuang static int __init mmp_of_init(struct device_node *node,
3890f374561SHaojian Zhuang 			      struct device_node *parent)
3900f374561SHaojian Zhuang {
3910f374561SHaojian Zhuang 	int ret;
3920f374561SHaojian Zhuang 
3930f374561SHaojian Zhuang 	ret = mmp_init_bases(node);
3940f374561SHaojian Zhuang 	if (ret < 0)
3950f374561SHaojian Zhuang 		return ret;
3960f374561SHaojian Zhuang 
3970f374561SHaojian Zhuang 	icu_data[0].conf_enable = mmp_conf.conf_enable;
3980f374561SHaojian Zhuang 	icu_data[0].conf_disable = mmp_conf.conf_disable;
3990f374561SHaojian Zhuang 	icu_data[0].conf_mask = mmp_conf.conf_mask;
4000f374561SHaojian Zhuang 	irq_set_default_host(icu_data[0].domain);
4010f374561SHaojian Zhuang 	set_handle_irq(mmp_handle_irq);
4020f374561SHaojian Zhuang 	max_icu_nr = 1;
4030f374561SHaojian Zhuang 	return 0;
4040f374561SHaojian Zhuang }
4050f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp_intc, "mrvl,mmp-intc", mmp_of_init);
4060f374561SHaojian Zhuang 
4070f374561SHaojian Zhuang static int __init mmp2_of_init(struct device_node *node,
4080f374561SHaojian Zhuang 			       struct device_node *parent)
4090f374561SHaojian Zhuang {
4100f374561SHaojian Zhuang 	int ret;
4110f374561SHaojian Zhuang 
4120f374561SHaojian Zhuang 	ret = mmp_init_bases(node);
4130f374561SHaojian Zhuang 	if (ret < 0)
4140f374561SHaojian Zhuang 		return ret;
4150f374561SHaojian Zhuang 
4160f374561SHaojian Zhuang 	icu_data[0].conf_enable = mmp2_conf.conf_enable;
4170f374561SHaojian Zhuang 	icu_data[0].conf_disable = mmp2_conf.conf_disable;
4180f374561SHaojian Zhuang 	icu_data[0].conf_mask = mmp2_conf.conf_mask;
4190f374561SHaojian Zhuang 	irq_set_default_host(icu_data[0].domain);
4200f374561SHaojian Zhuang 	set_handle_irq(mmp2_handle_irq);
4210f374561SHaojian Zhuang 	max_icu_nr = 1;
4220f374561SHaojian Zhuang 	return 0;
4230f374561SHaojian Zhuang }
4240f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_intc, "mrvl,mmp2-intc", mmp2_of_init);
4250f374561SHaojian Zhuang 
4260f374561SHaojian Zhuang static int __init mmp2_mux_of_init(struct device_node *node,
4270f374561SHaojian Zhuang 				   struct device_node *parent)
4280f374561SHaojian Zhuang {
4290f374561SHaojian Zhuang 	struct resource res;
4300f374561SHaojian Zhuang 	int i, ret, irq, j = 0;
4310f374561SHaojian Zhuang 	u32 nr_irqs, mfp_irq;
4320f374561SHaojian Zhuang 
4330f374561SHaojian Zhuang 	if (!parent)
4340f374561SHaojian Zhuang 		return -ENODEV;
4350f374561SHaojian Zhuang 
4360f374561SHaojian Zhuang 	i = max_icu_nr;
4370f374561SHaojian Zhuang 	ret = of_property_read_u32(node, "mrvl,intc-nr-irqs",
4380f374561SHaojian Zhuang 				   &nr_irqs);
4390f374561SHaojian Zhuang 	if (ret) {
4400f374561SHaojian Zhuang 		pr_err("Not found mrvl,intc-nr-irqs property\n");
4410f374561SHaojian Zhuang 		return -EINVAL;
4420f374561SHaojian Zhuang 	}
4430f374561SHaojian Zhuang 	ret = of_address_to_resource(node, 0, &res);
4440f374561SHaojian Zhuang 	if (ret < 0) {
4450f374561SHaojian Zhuang 		pr_err("Not found reg property\n");
4460f374561SHaojian Zhuang 		return -EINVAL;
4470f374561SHaojian Zhuang 	}
4480f374561SHaojian Zhuang 	icu_data[i].reg_status = mmp_icu_base + res.start;
4490f374561SHaojian Zhuang 	ret = of_address_to_resource(node, 1, &res);
4500f374561SHaojian Zhuang 	if (ret < 0) {
4510f374561SHaojian Zhuang 		pr_err("Not found reg property\n");
4520f374561SHaojian Zhuang 		return -EINVAL;
4530f374561SHaojian Zhuang 	}
4540f374561SHaojian Zhuang 	icu_data[i].reg_mask = mmp_icu_base + res.start;
4550f374561SHaojian Zhuang 	icu_data[i].cascade_irq = irq_of_parse_and_map(node, 0);
4560f374561SHaojian Zhuang 	if (!icu_data[i].cascade_irq)
4570f374561SHaojian Zhuang 		return -EINVAL;
4580f374561SHaojian Zhuang 
4590f374561SHaojian Zhuang 	icu_data[i].virq_base = 0;
4600f374561SHaojian Zhuang 	icu_data[i].domain = irq_domain_add_linear(node, nr_irqs,
4610f374561SHaojian Zhuang 						   &mmp_irq_domain_ops,
4620f374561SHaojian Zhuang 						   &icu_data[i]);
4630f374561SHaojian Zhuang 	for (irq = 0; irq < nr_irqs; irq++) {
4640f374561SHaojian Zhuang 		ret = irq_create_mapping(icu_data[i].domain, irq);
4650f374561SHaojian Zhuang 		if (!ret) {
4660f374561SHaojian Zhuang 			pr_err("Failed to mapping hwirq\n");
4670f374561SHaojian Zhuang 			goto err;
4680f374561SHaojian Zhuang 		}
4690f374561SHaojian Zhuang 		if (!irq)
4700f374561SHaojian Zhuang 			icu_data[i].virq_base = ret;
4710f374561SHaojian Zhuang 	}
4720f374561SHaojian Zhuang 	icu_data[i].nr_irqs = nr_irqs;
4730f374561SHaojian Zhuang 	if (!of_property_read_u32(node, "mrvl,clr-mfp-irq",
4740f374561SHaojian Zhuang 				  &mfp_irq)) {
4750f374561SHaojian Zhuang 		icu_data[i].clr_mfp_irq_base = icu_data[i].virq_base;
4760f374561SHaojian Zhuang 		icu_data[i].clr_mfp_hwirq = mfp_irq;
4770f374561SHaojian Zhuang 	}
4780f374561SHaojian Zhuang 	irq_set_chained_handler(icu_data[i].cascade_irq,
4790f374561SHaojian Zhuang 				icu_mux_irq_demux);
4800f374561SHaojian Zhuang 	max_icu_nr++;
4810f374561SHaojian Zhuang 	return 0;
4820f374561SHaojian Zhuang err:
4830f374561SHaojian Zhuang 	if (icu_data[i].virq_base) {
4840f374561SHaojian Zhuang 		for (j = 0; j < irq; j++)
4850f374561SHaojian Zhuang 			irq_dispose_mapping(icu_data[i].virq_base + j);
4860f374561SHaojian Zhuang 	}
4870f374561SHaojian Zhuang 	irq_domain_remove(icu_data[i].domain);
4880f374561SHaojian Zhuang 	return -EINVAL;
4890f374561SHaojian Zhuang }
4900f374561SHaojian Zhuang IRQCHIP_DECLARE(mmp2_mux_intc, "mrvl,mmp2-mux-intc", mmp2_mux_of_init);
491c052d13cSHaojian Zhuang #endif
492