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 06/19] irqchip: Add Espressif ESP32-P4 interrupt matrix support
Date: Wed, 25 Nov 2026 23:30:07 +0000 [thread overview]
Message-ID: <20261125233020.1380594-7-vitorhg20080@gmail.com> (raw)
In-Reply-To: <20261125233020.1380594-1-vitorhg20080@gmail.com>
Register a child IRQ domain for the ESP32-P4 interrupt matrix.
Allocate a CLIC external interrupt input for each peripheral interrupt
and program the route when the interrupt is activated. Support
active-high level interrupts for source numbers 0 through 127.
Disconnect firmware routes before registering the IRQ domain. On
ESP32-P4 revision 3.x, also clear the three additional routing registers.
Tested on a Waveshare ESP32-P4-Module-DEV-KIT. Verified that peripheral
interrupts were delivered to the CLIC through the matrix.
AI assisted with driver development and validation.
Signed-off-by: Vítor Hugo Silva <vitorhg20080@gmail.com>
---
drivers/irqchip/Makefile | 1 +
drivers/irqchip/irq-esp32p4-intmtx.c | 139 +++++++++++++++++++++++++++
2 files changed, 140 insertions(+)
create mode 100644 drivers/irqchip/irq-esp32p4-intmtx.c
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 408d06c20ab8..772d9558bbc8 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -103,6 +103,7 @@ 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_ESP32P4_CLIC) += irq-esp32p4-intmtx.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-intmtx.c b/drivers/irqchip/irq-esp32p4-intmtx.c
new file mode 100644
index 000000000000..0fc1a7b78f8f
--- /dev/null
+++ b/drivers/irqchip/irq-esp32p4-intmtx.c
@@ -0,0 +1,139 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Espressif ESP32-P4 interrupt matrix */
+
+#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>
+
+#define CLIC_FIRST_EXT_IRQ 16
+#define CLIC_LAST_EXT_IRQ 47
+#define INTMTX_NR_MAP_REGS 128
+#define INTMTX_MAP_MASK GENMASK(5, 0)
+#define INTMTX_MAP_DISABLED 0
+#define INTMTX_V3_FIRST_EXTRA_SOURCE 133
+#define INTMTX_V3_LAST_EXTRA_SOURCE 135
+
+static const struct irq_chip esp32p4_intmtx_chip = {
+ .name = "ESP32-P4 interrupt matrix",
+ .irq_mask = irq_chip_mask_parent,
+ .irq_unmask = irq_chip_unmask_parent,
+ .irq_set_type = irq_chip_set_type_parent,
+};
+
+static int esp32p4_intmtx_domain_alloc(struct irq_domain *domain,
+ unsigned int virq, unsigned int nr_irqs,
+ void *arg)
+{
+ struct irq_fwspec *fwspec = arg;
+ struct irq_fwspec parent_fwspec = {
+ .fwnode = domain->parent->fwnode,
+ .param_count = 2,
+ .param[1] = IRQ_TYPE_LEVEL_HIGH,
+ };
+ unsigned int clic_irq;
+ int ret;
+
+ if (nr_irqs != 1 || !fwspec || fwspec->param_count != 2)
+ return -EINVAL;
+ if (fwspec->param[0] >= INTMTX_NR_MAP_REGS ||
+ fwspec->param[1] != IRQ_TYPE_LEVEL_HIGH)
+ return -EINVAL;
+
+ /* The IRQ domain core serializes allocation across the hierarchy. */
+ for (clic_irq = CLIC_FIRST_EXT_IRQ; clic_irq <= CLIC_LAST_EXT_IRQ;
+ clic_irq++) {
+ if (!irq_find_mapping(domain->parent, clic_irq))
+ break;
+ }
+ if (clic_irq > CLIC_LAST_EXT_IRQ)
+ return -ENOSPC;
+
+ ret = irq_domain_set_hwirq_and_chip(domain, virq, fwspec->param[0],
+ &esp32p4_intmtx_chip, NULL);
+ if (ret)
+ return ret;
+
+ parent_fwspec.param[0] = clic_irq;
+ return irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &parent_fwspec);
+}
+
+static void esp32p4_intmtx_set_route(void __iomem *base, unsigned int source,
+ unsigned int clic_irq)
+{
+ void __iomem *reg = base + 4 * source;
+ u32 val = readl(reg);
+
+ writel((val & ~INTMTX_MAP_MASK) | clic_irq, reg);
+}
+
+static int esp32p4_intmtx_activate(struct irq_domain *domain,
+ struct irq_data *data, bool reserve)
+{
+ esp32p4_intmtx_set_route(domain->host_data, irqd_to_hwirq(data),
+ irqd_to_hwirq(data->parent_data));
+ return 0;
+}
+
+static void esp32p4_intmtx_deactivate(struct irq_domain *domain,
+ struct irq_data *data)
+{
+ esp32p4_intmtx_set_route(domain->host_data, irqd_to_hwirq(data),
+ INTMTX_MAP_DISABLED);
+}
+
+static const struct irq_domain_ops esp32p4_intmtx_domain_ops = {
+ .alloc = esp32p4_intmtx_domain_alloc,
+ .free = irq_domain_free_irqs_common,
+ .translate = irq_domain_translate_twocell,
+ .activate = esp32p4_intmtx_activate,
+ .deactivate = esp32p4_intmtx_deactivate,
+};
+
+static int __init esp32p4_intmtx_init(struct device_node *node,
+ struct device_node *parent)
+{
+ struct irq_domain *parent_domain, *domain;
+ void __iomem *base;
+ unsigned int source;
+
+ if (!parent)
+ return -ENODEV;
+
+ parent_domain = irq_find_host(parent);
+ if (!parent_domain)
+ return -ENODEV;
+
+ base = of_iomap(node, 0);
+ if (!base)
+ return -ENOMEM;
+
+ /* Disconnect routes left by firmware before allocating IRQs. */
+ for (source = 0; source < INTMTX_NR_MAP_REGS; source++)
+ esp32p4_intmtx_set_route(base, source, INTMTX_MAP_DISABLED);
+
+ /* Skip the status and clock registers between routing banks. */
+ if (of_device_is_compatible(node, "esp,esp32p4-v3-intmtx")) {
+ for (source = INTMTX_V3_FIRST_EXTRA_SOURCE;
+ source <= INTMTX_V3_LAST_EXTRA_SOURCE; source++)
+ esp32p4_intmtx_set_route(base, source, INTMTX_MAP_DISABLED);
+ }
+
+ domain = irq_domain_create_hierarchy(parent_domain, 0, 0,
+ of_fwnode_handle(node),
+ &esp32p4_intmtx_domain_ops, base);
+ if (!domain) {
+ iounmap(base);
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+IRQCHIP_DECLARE(esp32p4_intmtx, "esp,esp32p4-intmtx", esp32p4_intmtx_init);
+IRQCHIP_DECLARE(esp32p4_v3_intmtx, "esp,esp32p4-v3-intmtx", esp32p4_intmtx_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 ` [PATCH RFC 04/19] irqchip: Add Espressif ESP32-P4 CLIC support Vítor Hugo Silva
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 ` Vítor Hugo Silva [this message]
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-7-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