1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/mach-mmp/irq.c
5 * Generic IRQ handling, GPIO IRQ demultiplexing, etc.
6 * Copyright (C) 2008 - 2012 Marvell Technology Group Ltd.
8 * Author: Bin Yang <bin.yang@marvell.com>
9 * Haojian Zhuang <haojian.zhuang@gmail.com>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/irq.h>
15 #include <linux/irqchip.h>
16 #include <linux/irqchip/chained_irq.h>
17 #include <linux/irqdomain.h>
19 #include <linux/ioport.h>
20 #include <linux/of_address.h>
21 #include <linux/of_irq.h>
23 #include <asm/exception.h>
24 #include <asm/hardirq.h>
28 #define PJ1_INT_SEL 0x10c
29 #define PJ4_INT_SEL 0x104
31 /* bit fields in PJ1_INT_SEL and PJ4_INT_SEL */
32 #define SEL_INT_PENDING (1 << 6)
33 #define SEL_INT_NUM_MASK 0x3f
35 #define MMP2_ICU_INT_ROUTE_PJ4_IRQ (1 << 5)
36 #define MMP2_ICU_INT_ROUTE_PJ4_FIQ (1 << 6)
38 struct icu_chip_data {
40 unsigned int virq_base;
41 unsigned int cascade_irq;
42 void __iomem *reg_status;
43 void __iomem *reg_mask;
44 unsigned int conf_enable;
45 unsigned int conf_disable;
46 unsigned int conf_mask;
47 unsigned int conf2_mask;
48 unsigned int clr_mfp_irq_base;
49 unsigned int clr_mfp_hwirq;
50 struct irq_domain *domain;
53 struct mmp_intc_conf {
54 unsigned int conf_enable;
55 unsigned int conf_disable;
56 unsigned int conf_mask;
57 unsigned int conf2_mask;
60 static void __iomem *mmp_icu_base;
61 static void __iomem *mmp_icu2_base;
62 static struct icu_chip_data icu_data[MAX_ICU_NR];
63 static int max_icu_nr;
65 extern void mmp2_clear_pmic_int(void);
67 static void icu_mask_ack_irq(struct irq_data *d)
69 struct irq_domain *domain = d->domain;
70 struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
74 hwirq = d->irq - data->virq_base;
75 if (data == &icu_data[0]) {
76 r = readl_relaxed(mmp_icu_base + (hwirq << 2));
77 r &= ~data->conf_mask;
78 r |= data->conf_disable;
79 writel_relaxed(r, mmp_icu_base + (hwirq << 2));
81 #ifdef CONFIG_CPU_MMP2
82 if ((data->virq_base == data->clr_mfp_irq_base)
83 && (hwirq == data->clr_mfp_hwirq))
84 mmp2_clear_pmic_int();
86 r = readl_relaxed(data->reg_mask) | (1 << hwirq);
87 writel_relaxed(r, data->reg_mask);
91 static void icu_mask_irq(struct irq_data *d)
93 struct irq_domain *domain = d->domain;
94 struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
98 hwirq = d->irq - data->virq_base;
99 if (data == &icu_data[0]) {
100 r = readl_relaxed(mmp_icu_base + (hwirq << 2));
101 r &= ~data->conf_mask;
102 r |= data->conf_disable;
103 writel_relaxed(r, mmp_icu_base + (hwirq << 2));
105 if (data->conf2_mask) {
107 * ICU1 (above) only controls PJ4 MP1; if using SMP,
108 * we need to also mask the MP2 and MM cores via ICU2.
110 r = readl_relaxed(mmp_icu2_base + (hwirq << 2));
111 r &= ~data->conf2_mask;
112 writel_relaxed(r, mmp_icu2_base + (hwirq << 2));
115 r = readl_relaxed(data->reg_mask) | (1 << hwirq);
116 writel_relaxed(r, data->reg_mask);
120 static void icu_unmask_irq(struct irq_data *d)
122 struct irq_domain *domain = d->domain;
123 struct icu_chip_data *data = (struct icu_chip_data *)domain->host_data;
127 hwirq = d->irq - data->virq_base;
128 if (data == &icu_data[0]) {
129 r = readl_relaxed(mmp_icu_base + (hwirq << 2));
130 r &= ~data->conf_mask;
131 r |= data->conf_enable;
132 writel_relaxed(r, mmp_icu_base + (hwirq << 2));
134 r = readl_relaxed(data->reg_mask) & ~(1 << hwirq);
135 writel_relaxed(r, data->reg_mask);
139 struct irq_chip icu_irq_chip = {
141 .irq_mask = icu_mask_irq,
142 .irq_mask_ack = icu_mask_ack_irq,
143 .irq_unmask = icu_unmask_irq,
146 static void icu_mux_irq_demux(struct irq_desc *desc)
148 unsigned int irq = irq_desc_get_irq(desc);
149 struct irq_chip *chip = irq_desc_get_chip(desc);
150 struct irq_domain *domain;
151 struct icu_chip_data *data;
153 unsigned long mask, status, n;
155 chained_irq_enter(chip, desc);
157 for (i = 1; i < max_icu_nr; i++) {
158 if (irq == icu_data[i].cascade_irq) {
159 domain = icu_data[i].domain;
160 data = (struct icu_chip_data *)domain->host_data;
164 if (i >= max_icu_nr) {
165 pr_err("Spurious irq %d in MMP INTC\n", irq);
169 mask = readl_relaxed(data->reg_mask);
171 status = readl_relaxed(data->reg_status) & ~mask;
174 for_each_set_bit(n, &status, BITS_PER_LONG) {
175 generic_handle_irq(icu_data[i].virq_base + n);
180 chained_irq_exit(chip, desc);
183 static int mmp_irq_domain_map(struct irq_domain *d, unsigned int irq,
186 irq_set_chip_and_handler(irq, &icu_irq_chip, handle_level_irq);
190 static int mmp_irq_domain_xlate(struct irq_domain *d, struct device_node *node,
191 const u32 *intspec, unsigned int intsize,
192 unsigned long *out_hwirq,
193 unsigned int *out_type)
195 *out_hwirq = intspec[0];
199 static const struct irq_domain_ops mmp_irq_domain_ops = {
200 .map = mmp_irq_domain_map,
201 .xlate = mmp_irq_domain_xlate,
204 static const struct mmp_intc_conf mmp_conf = {
210 static const struct mmp_intc_conf mmp2_conf = {
213 .conf_mask = MMP2_ICU_INT_ROUTE_PJ4_IRQ |
214 MMP2_ICU_INT_ROUTE_PJ4_FIQ,
217 static struct mmp_intc_conf mmp3_conf = {
220 .conf_mask = MMP2_ICU_INT_ROUTE_PJ4_IRQ |
221 MMP2_ICU_INT_ROUTE_PJ4_FIQ,
225 static void __exception_irq_entry mmp_handle_irq(struct pt_regs *regs)
229 hwirq = readl_relaxed(mmp_icu_base + PJ1_INT_SEL);
230 if (!(hwirq & SEL_INT_PENDING))
232 hwirq &= SEL_INT_NUM_MASK;
233 generic_handle_domain_irq(icu_data[0].domain, hwirq);
236 static void __exception_irq_entry mmp2_handle_irq(struct pt_regs *regs)
240 hwirq = readl_relaxed(mmp_icu_base + PJ4_INT_SEL);
241 if (!(hwirq & SEL_INT_PENDING))
243 hwirq &= SEL_INT_NUM_MASK;
244 generic_handle_domain_irq(icu_data[0].domain, hwirq);
247 static int __init mmp_init_bases(struct device_node *node)
249 int ret, nr_irqs, irq, i = 0;
251 ret = of_property_read_u32(node, "mrvl,intc-nr-irqs", &nr_irqs);
253 pr_err("Not found mrvl,intc-nr-irqs property\n");
257 mmp_icu_base = of_iomap(node, 0);
259 pr_err("Failed to get interrupt controller register\n");
263 icu_data[0].virq_base = 0;
264 icu_data[0].domain = irq_domain_add_linear(node, nr_irqs,
267 for (irq = 0; irq < nr_irqs; irq++) {
268 ret = irq_create_mapping(icu_data[0].domain, irq);
270 pr_err("Failed to mapping hwirq\n");
274 icu_data[0].virq_base = ret;
276 icu_data[0].nr_irqs = nr_irqs;
279 if (icu_data[0].virq_base) {
280 for (i = 0; i < irq; i++)
281 irq_dispose_mapping(icu_data[0].virq_base + i);
283 irq_domain_remove(icu_data[0].domain);
284 iounmap(mmp_icu_base);
288 static int __init mmp_of_init(struct device_node *node,
289 struct device_node *parent)
293 ret = mmp_init_bases(node);
297 icu_data[0].conf_enable = mmp_conf.conf_enable;
298 icu_data[0].conf_disable = mmp_conf.conf_disable;
299 icu_data[0].conf_mask = mmp_conf.conf_mask;
300 set_handle_irq(mmp_handle_irq);
304 IRQCHIP_DECLARE(mmp_intc, "mrvl,mmp-intc", mmp_of_init);
306 static int __init mmp2_of_init(struct device_node *node,
307 struct device_node *parent)
311 ret = mmp_init_bases(node);
315 icu_data[0].conf_enable = mmp2_conf.conf_enable;
316 icu_data[0].conf_disable = mmp2_conf.conf_disable;
317 icu_data[0].conf_mask = mmp2_conf.conf_mask;
318 set_handle_irq(mmp2_handle_irq);
322 IRQCHIP_DECLARE(mmp2_intc, "mrvl,mmp2-intc", mmp2_of_init);
324 static int __init mmp3_of_init(struct device_node *node,
325 struct device_node *parent)
329 mmp_icu2_base = of_iomap(node, 1);
330 if (!mmp_icu2_base) {
331 pr_err("Failed to get interrupt controller register #2\n");
335 ret = mmp_init_bases(node);
337 iounmap(mmp_icu2_base);
341 icu_data[0].conf_enable = mmp3_conf.conf_enable;
342 icu_data[0].conf_disable = mmp3_conf.conf_disable;
343 icu_data[0].conf_mask = mmp3_conf.conf_mask;
344 icu_data[0].conf2_mask = mmp3_conf.conf2_mask;
347 /* This is the main interrupt controller. */
348 set_handle_irq(mmp2_handle_irq);
354 IRQCHIP_DECLARE(mmp3_intc, "marvell,mmp3-intc", mmp3_of_init);
356 static int __init mmp2_mux_of_init(struct device_node *node,
357 struct device_node *parent)
359 int i, ret, irq, j = 0;
360 u32 nr_irqs, mfp_irq;
367 ret = of_property_read_u32(node, "mrvl,intc-nr-irqs",
370 pr_err("Not found mrvl,intc-nr-irqs property\n");
375 * For historical reasons, the "regs" property of the
376 * mrvl,mmp2-mux-intc is not a regular "regs" property containing
377 * addresses on the parent bus, but offsets from the intc's base.
378 * That is why we can't use of_address_to_resource() here.
380 ret = of_property_read_variable_u32_array(node, "reg", reg,
384 pr_err("Not found reg property\n");
387 icu_data[i].reg_status = mmp_icu_base + reg[0];
388 icu_data[i].reg_mask = mmp_icu_base + reg[2];
389 icu_data[i].cascade_irq = irq_of_parse_and_map(node, 0);
390 if (!icu_data[i].cascade_irq)
393 icu_data[i].virq_base = 0;
394 icu_data[i].domain = irq_domain_add_linear(node, nr_irqs,
397 for (irq = 0; irq < nr_irqs; irq++) {
398 ret = irq_create_mapping(icu_data[i].domain, irq);
400 pr_err("Failed to mapping hwirq\n");
404 icu_data[i].virq_base = ret;
406 icu_data[i].nr_irqs = nr_irqs;
407 if (!of_property_read_u32(node, "mrvl,clr-mfp-irq",
409 icu_data[i].clr_mfp_irq_base = icu_data[i].virq_base;
410 icu_data[i].clr_mfp_hwirq = mfp_irq;
412 irq_set_chained_handler(icu_data[i].cascade_irq,
417 if (icu_data[i].virq_base) {
418 for (j = 0; j < irq; j++)
419 irq_dispose_mapping(icu_data[i].virq_base + j);
421 irq_domain_remove(icu_data[i].domain);
424 IRQCHIP_DECLARE(mmp2_mux_intc, "mrvl,mmp2-mux-intc", mmp2_mux_of_init);