From: "Vítor Hugo Silva" <vitorhg20080@gmail.com>
To: linux-riscv@lists.infradead.org
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Thomas Gleixner <tglx@kernel.org>, Radu Rendec <radu@rendec.net>
Subject: [PATCH RFC 04/19] irqchip: Add Espressif ESP32-P4 CLIC support
Date: Wed, 25 Nov 2026 23:30:05 +0000 [thread overview]
Message-ID: <20261125233020.1380594-5-vitorhg20080@gmail.com> (raw)
In-Reply-To: <20261125233020.1380594-1-vitorhg20080@gmail.com>
Register a hierarchical IRQ domain for the ESP32-P4 CLIC. Handle
per-CPU software and timer interrupts and support active-high level
triggering on the 32 external interrupt inputs.
Tested on the Waveshare ESP32-P4-Module-DEV-KIT hardware.
Verified that the CLIC handled local timer interrupts from the
CLINT and external interrupts routed through the interrupt matrix.
AI assisted with driver development, validation and testing.
Signed-off-by: Vítor Hugo Silva <vitorhg20080@gmail.com>
---
drivers/irqchip/Makefile | 1 +
drivers/irqchip/irq-esp32p4-clic.c | 178 +++++++++++++++++++++++++++++
2 files changed, 179 insertions(+)
create mode 100644 drivers/irqchip/irq-esp32p4-clic.c
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 16a5fd126c9a..408d06c20ab8 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_QCOM_MPM) += irq-qcom-mpm.o
obj-$(CONFIG_CSKY_MPINTC) += irq-csky-mpintc.o
obj-$(CONFIG_CSKY_APB_INTC) += irq-csky-apb-intc.o
obj-$(CONFIG_RISCV_INTC) += irq-riscv-intc.o
+obj-$(CONFIG_RISCV_ESP32P4_CLIC) += irq-esp32p4-clic.o
obj-$(CONFIG_RISCV_APLIC) += irq-riscv-aplic-main.o irq-riscv-aplic-direct.o
obj-$(CONFIG_RISCV_APLIC_MSI) += irq-riscv-aplic-msi.o
obj-$(CONFIG_RISCV_IMSIC) += irq-riscv-imsic-state.o irq-riscv-imsic-early.o irq-riscv-imsic-platform.o
diff --git a/drivers/irqchip/irq-esp32p4-clic.c b/drivers/irqchip/irq-esp32p4-clic.c
new file mode 100644
index 000000000000..f9235f230d37
--- /dev/null
+++ b/drivers/irqchip/irq-esp32p4-clic.c
@@ -0,0 +1,178 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Espressif ESP32-P4 Core-Local Interrupt Controller
+ *
+ * Author: Vítor Hugo Silva <vitorhg20080@gmail.com>
+ * ESP32-P4 Technical Reference Manual, section 2.9.2 (CLIC)
+ * https://documentation.espressif.com/esp32-p4_technical_reference_manual_en.pdf
+ */
+#include <linux/bits.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqdomain.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/printk.h>
+
+#include <asm/csr.h>
+#include <asm/ptrace.h>
+
+#define CLIC_FIRST_EXT_IRQ 16
+#define CLIC_NR_IRQS 48
+#define CLIC_INTTHRESH 0x0008
+#define CLIC_INTIE(id) (0x1001 + 4 * (id))
+#define CLIC_INTATTR(id) (0x1002 + 4 * (id))
+#define CLIC_INTCTL(id) (0x1003 + 4 * (id))
+#define CLIC_INTATTR_MODE_M GENMASK(7, 6)
+#define CLIC_INTCTL_MAX GENMASK(7, 5)
+
+#define CSR_MINTTHRESH 0x347
+
+static struct irq_domain *esp32p4_clic_domain __ro_after_init;
+
+static void esp32p4_clic_irq_mask(struct irq_data *d)
+{
+ void __iomem *base = irq_data_get_irq_chip_data(d);
+
+ writeb(0, base + CLIC_INTIE(d->hwirq));
+}
+
+static void esp32p4_clic_irq_unmask(struct irq_data *d)
+{
+ void __iomem *base = irq_data_get_irq_chip_data(d);
+
+ writeb(1, base + CLIC_INTIE(d->hwirq));
+}
+
+static int esp32p4_clic_irq_set_type(struct irq_data *d, unsigned int type)
+{
+ if (type != IRQ_TYPE_LEVEL_HIGH)
+ return -EINVAL;
+
+ return IRQ_SET_MASK_OK;
+}
+
+static struct irq_chip esp32p4_clic_chip = {
+ .name = "ESP32-P4 CLIC",
+ .irq_mask = esp32p4_clic_irq_mask,
+ .irq_unmask = esp32p4_clic_irq_unmask,
+ .irq_set_type = esp32p4_clic_irq_set_type,
+};
+
+static int esp32p4_clic_domain_alloc(struct irq_domain *domain,
+ unsigned int virq, unsigned int nr_irqs,
+ void *arg)
+{
+ struct irq_fwspec *fwspec = arg;
+ irq_flow_handler_t handler;
+ irq_hw_number_t hwirq;
+ unsigned int type;
+ int ret;
+
+ if (nr_irqs != 1 || !fwspec)
+ return -EINVAL;
+
+ ret = irq_domain_translate_twocell(domain, fwspec, &hwirq, &type);
+ if (ret)
+ return ret;
+
+ if (type != IRQ_TYPE_LEVEL_HIGH)
+ return -EINVAL;
+
+ if (hwirq == IRQ_M_SOFT || hwirq == IRQ_M_TIMER) {
+ ret = irq_set_percpu_devid(virq);
+ if (ret)
+ return ret;
+ handler = handle_percpu_devid_irq;
+ } else {
+ if (hwirq < CLIC_FIRST_EXT_IRQ || hwirq >= CLIC_NR_IRQS)
+ return -EINVAL;
+ handler = handle_level_irq;
+ }
+
+ irq_domain_set_info(domain, virq, hwirq, &esp32p4_clic_chip,
+ domain->host_data, handler, NULL, NULL);
+
+ return 0;
+}
+
+static const struct irq_domain_ops esp32p4_clic_domain_ops = {
+ .alloc = esp32p4_clic_domain_alloc,
+ .free = irq_domain_free_irqs_top,
+ .translate = irq_domain_translate_twocell,
+};
+
+static void esp32p4_clic_handle_irq(struct pt_regs *regs)
+{
+ unsigned long hwirq = regs->cause & ~CAUSE_IRQ_FLAG;
+
+ if (generic_handle_domain_irq(esp32p4_clic_domain, hwirq))
+ pr_warn_ratelimited("ESP32-P4 CLIC: unhandled IRQ %lu\n", hwirq);
+}
+
+static void __init esp32p4_clic_init_irq(void __iomem *base, unsigned int hwirq)
+{
+ writeb(0, base + CLIC_INTIE(hwirq));
+
+ /* Use non-vectored, active-high level interrupts in M-mode. */
+ writeb(CLIC_INTATTR_MODE_M, base + CLIC_INTATTR(hwirq));
+
+ /* Use one level for all IRQs regardless of the inherited MNLBITS. */
+ writeb(CLIC_INTCTL_MAX, base + CLIC_INTCTL(hwirq));
+}
+
+static int __init esp32p4_clic_init(struct device_node *node,
+ struct device_node *parent)
+{
+ struct irq_domain *domain;
+ void __iomem *base;
+ unsigned int hwirq;
+ int ret;
+
+ base = of_iomap(node, 0);
+ if (!base)
+ return -ENOMEM;
+
+ domain = irq_domain_create_hierarchy(NULL, 0, CLIC_NR_IRQS,
+ of_fwnode_handle(node),
+ &esp32p4_clic_domain_ops, base);
+ if (!domain) {
+ ret = -ENOMEM;
+ goto err_unmap;
+ }
+
+ ret = set_handle_irq(esp32p4_clic_handle_irq);
+ if (ret)
+ goto err_remove_domain;
+
+ esp32p4_clic_init_irq(base, IRQ_M_SOFT);
+ esp32p4_clic_init_irq(base, IRQ_M_TIMER);
+ for (hwirq = CLIC_FIRST_EXT_IRQ; hwirq < CLIC_NR_IRQS; hwirq++)
+ esp32p4_clic_init_irq(base, hwirq);
+
+ /* Clear the threshold inherited from firmware. */
+ if (of_device_is_compatible(node, "esp,esp32p4-v3-clic")) {
+ csr_write(CSR_MINTTHRESH, 0);
+ } else {
+ writel(0, base + CLIC_INTTHRESH);
+ /* Ensure the new threshold is active before enabling IRQs. */
+ readl(base + CLIC_INTTHRESH);
+ }
+
+ esp32p4_clic_domain = domain;
+ pr_info("%pOF: ESP32-P4 CLIC registered\n", node);
+
+ return 0;
+
+err_remove_domain:
+ irq_domain_remove(domain);
+err_unmap:
+ iounmap(base);
+ return ret;
+}
+
+IRQCHIP_DECLARE(esp32p4_clic, "esp,esp32p4-clic", esp32p4_clic_init);
+IRQCHIP_DECLARE(esp32p4_v3_clic, "esp,esp32p4-v3-clic", esp32p4_clic_init);
--
2.56.1
next prev parent reply other threads:[~2026-11-25 23:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 23:30 [PATCH RFC 00/19] riscv: Add initial support for Espressif ESP32-P4 Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 01/19] riscv: Prepare ESP32-P4 early CLIC trap vectors Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 02/19] riscv: Handle ESP32-P4 CLIC trap context Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 03/19] dt-bindings: interrupt-controller: Add Espressif ESP32-P4 CLIC Vítor Hugo Silva
2026-11-25 23:30 ` Vítor Hugo Silva [this message]
2026-11-25 23:30 ` [PATCH RFC 05/19] dt-bindings: interrupt-controller: Add Espressif ESP32-P4 interrupt matrix Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 06/19] irqchip: Add Espressif ESP32-P4 interrupt matrix support Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 07/19] dt-bindings: timer: Add Espressif ESP32-P4 CLINT Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 08/19] clocksource/drivers/timer-clint: Add Espressif ESP32-P4 support Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 09/19] dt-bindings: serial: Add Espressif ESP32-P4 UART Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 10/19] serial: esp32: Restore the ESP32 UART driver Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 11/19] serial: esp32: Add support for the ESP32-P4 UART Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 12/19] serial: esp32: Rearm TX interrupts when the FIFO is full Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 13/19] serial: esp32: Add early console support for ESP32-P4 Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 14/19] riscv: Synchronize instructions written to ESP32-P4 PSRAM Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 15/19] riscv: Align init data to the ESP32-P4 PMP granularity Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 16/19] dt-bindings: riscv: Add Waveshare ESP32-P4-Module-DEV-KIT Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 17/19] dt-bindings: riscv: cpus: Document Espressif ESP32-P4 HP harts Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 18/19] riscv: dts: Add Waveshare ESP32-P4-Module-DEV-KIT Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 19/19] MAINTAINERS: Add the Espressif ESP32-P4 platform Vítor Hugo Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125233020.1380594-5-vitorhg20080@gmail.com \
--to=vitorhg20080@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=radu@rendec.net \
--cc=robh@kernel.org \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®