1 // SPDX-License-Identifier: GPL-2.0+
3 * RDA8810PL SoC irqchip driver
5 * Copyright RDA Microelectronics Company Limited
6 * Copyright (c) 2017 Andreas Färber
7 * Copyright (c) 2018 Manivannan Sadhasivam
10 #include <linux/init.h>
11 #include <linux/interrupt.h>
12 #include <linux/irq.h>
13 #include <linux/irqchip.h>
14 #include <linux/irqdomain.h>
15 #include <linux/of_address.h>
17 #include <asm/exception.h>
19 #define RDA_INTC_FINALSTATUS 0x00
20 #define RDA_INTC_MASK_SET 0x08
21 #define RDA_INTC_MASK_CLR 0x0c
23 #define RDA_IRQ_MASK_ALL 0xFFFFFFFF
25 #define RDA_NR_IRQS 32
27 static void __iomem
*rda_intc_base
;
28 static struct irq_domain
*rda_irq_domain
;
30 static void rda_intc_mask_irq(struct irq_data
*d
)
32 writel_relaxed(BIT(d
->hwirq
), rda_intc_base
+ RDA_INTC_MASK_CLR
);
35 static void rda_intc_unmask_irq(struct irq_data
*d
)
37 writel_relaxed(BIT(d
->hwirq
), rda_intc_base
+ RDA_INTC_MASK_SET
);
40 static int rda_intc_set_type(struct irq_data
*data
, unsigned int flow_type
)
42 /* Hardware supports only level triggered interrupts */
43 if ((flow_type
& (IRQF_TRIGGER_HIGH
| IRQF_TRIGGER_LOW
)) == flow_type
)
49 static void __exception_irq_entry
rda_handle_irq(struct pt_regs
*regs
)
51 u32 stat
= readl_relaxed(rda_intc_base
+ RDA_INTC_FINALSTATUS
);
56 handle_domain_irq(rda_irq_domain
, hwirq
, regs
);
61 static struct irq_chip rda_irq_chip
= {
63 .irq_mask
= rda_intc_mask_irq
,
64 .irq_unmask
= rda_intc_unmask_irq
,
65 .irq_set_type
= rda_intc_set_type
,
68 static int rda_irq_map(struct irq_domain
*d
,
69 unsigned int virq
, irq_hw_number_t hw
)
71 irq_set_status_flags(virq
, IRQ_LEVEL
);
72 irq_set_chip_and_handler(virq
, &rda_irq_chip
, handle_level_irq
);
73 irq_set_chip_data(virq
, d
->host_data
);
79 static const struct irq_domain_ops rda_irq_domain_ops
= {
81 .xlate
= irq_domain_xlate_onecell
,
84 static int __init
rda8810_intc_init(struct device_node
*node
,
85 struct device_node
*parent
)
87 rda_intc_base
= of_io_request_and_map(node
, 0, "rda-intc");
88 if (IS_ERR(rda_intc_base
))
89 return PTR_ERR(rda_intc_base
);
91 /* Mask all interrupt sources */
92 writel_relaxed(RDA_IRQ_MASK_ALL
, rda_intc_base
+ RDA_INTC_MASK_CLR
);
94 rda_irq_domain
= irq_domain_create_linear(&node
->fwnode
, RDA_NR_IRQS
,
97 if (!rda_irq_domain
) {
98 iounmap(rda_intc_base
);
102 set_handle_irq(rda_handle_irq
);
107 IRQCHIP_DECLARE(rda_intc
, "rda,8810pl-intc", rda8810_intc_init
);