From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795649459; b=kvAJw/5AqCqstyZpOq2ky2CxXDKif7SatVgsPSoakCZaI3zO+HIbvcS02oyeeW/v7IP6 EYPJAW7FhaKpx/SuqmAEHm/7OCpTVnn8Y794wJJPi1Cbr9b/M961nCyFhDQv8RNiYJOpt Wnv66DO12aUdgCAq8lp/ZiOIPPybBHs3jReCG1vzaD8JkgDsv57NndAsXk0kIRjaQ2tYP w46J29NP9134x5/oUvoRvEEBHHe4+ffDNqT+g6zrDJM5radQm3EBjoAktXlMk10It7kaJ 5xjjpGdjHjznQ2w9u9kYxyQgitE+NQNZjxCOF9rXoodvOBwv4thfhUQ6h7RmWdPT82w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795649459; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=1z+y7fmEUMtLnG3lTMWhkUey//yqaPCMXeCiS+uEMnc=; b=e8h9CdUSIU6J9+dneMlhRh++5zhswOKhaKEiFft3Xtm6FSVc0IABi3olV+Gm74szO+Vc znCViePpxVRXei9ZaQVA34741B6JI48r9aMK+ufgxLlyeBljq+DGTMCn8D5zWyNzP0+YP U1tvKIZycRf9WGG5X19b1c+G2fmHiseE3/u8rAzu5jnedDrUa4VErwUYDO3TbR0xBvWtI 6vPlBGo7MWYu6ZdnQSu6TMtPZDyD9ughCTSupNblxBjovux629eQjhuuf1PHzMEwuXVku 3Y3+47yKGQ5NgoZzreXQzWFMHvHrzJ6j1UY2G5VndeA22S/jEsCdqsPPjxC3i6+BAbQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=z81dQqxI; arc=none smtp.remote-ip=209.85.221.44 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D304A606A31E for ; Wed, 25 Nov 2026 23:30:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D304A606A31E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=z81dQqxI Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-4b52fcb410dso2146974f8f.1 for ; Wed, 25 Nov 2026 15:30:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795649457; x=1796254257; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=1z+y7fmEUMtLnG3lTMWhkUey//yqaPCMXeCiS+uEMnc=; b=z81dQqxIjn1HN9zU17fyIjc0R7p6ncjaSSGREiCBJDp5w3AdpEqtc11ocs8EUBCEg8 xsInIbXt4699r3oFKY1wvkjF/ArNeFAQMscCogMGC8+33tn37RdDuJQG4DrJz/vW2XTJ kFQoXnAPPxmm3JRYcyK/+smhNTxPrsAojxIDA9I0rDhJ30ieFvQAynIqvtj9u4qI1gi6 FT3TXPGemo4mDKB2S/XNskbpnN9iIoxSL3srq/4/Ra7LFNwWS7N2RpS8OR+P5aoYidIN PsXDBC6BreoBpR6FYeSxnxRWQY6weAjI5uH0gi5jlF6CD0nZ8g02t+1nS02chNgzkYEE 5knQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795649457; x=1796254257; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1z+y7fmEUMtLnG3lTMWhkUey//yqaPCMXeCiS+uEMnc=; b=CvDI+FcGklbQFA0F9lSopYrpSWR7zlLa3wW6xQ7pOs9rh02QtR6BFdMXqRBSeZTba3 kGpXmc8byH/QA6q39k8oyZrX/yksbtJactZfaY1zFLKcCsEsR1z4CXhV98tSBBFiRZrI /mvfEco8XH6yqmrMwDLPWE3fm18bCX33rSCmuNg/djMYD0qBO3RwTZwz2J/sY2s8i3U2 FjXVBTOojFskQsD13DNSdzyNjAkr4lN6lly7tGcEPAgvlIaksLsKtnhx0TIo2+S4bChN zVh4Id8t8A9pGniurrvl46BEjgYx/NuahJhHxZ5org6Hmrp2oNQC7I4dHwq3R7SU5iEB l22w== X-Forwarded-Encrypted: i=1; AL+hErEaIKKetfKQ21aVq/36GhAkDpXMfdoOzVOdTb7qw3hkQPIJSyZ+mXNldVnHT+svl2AILPVzOOBefH5ljbA=@vger.kernel.org X-Gm-Message-State: APuU4Z/ZSzvZgMLNn+MPnFX4SP5HGMyySnohWnHsV0yrX960haCKR4aU nM21B3tpnp7qLEyHTQa/rqJ3J/o9Ubd1TxZ9i4AI6yv0kjsg2UshrwyO X-Gm-Gg: AZFdTZccfIOm/Sm5F6DcsotfxHJHXRPQZXqBI17Ef6xRJ3XtvN1ZUDvjI6DHmCJ/9XK qRdGDXDO/qnU1sE86lIjI2ez+rBEyMLTQFQUpXoDIL9rV+cUiPFOyNgm0X9ukZ3ga5QMIDem12f NgnuOIqsxJM0slDsQXeV+EUkDoiyeqw4sKMyjUhLmoApmfaCyRF0jhPMqciVXlhGquYf3+FDYQ5 DFSkKdu2+BMoOriZDc4+bCp6fM4Htzjcq5cN1JjT6FFOzIph9RGdX7dMfsqvacuPdtVjuE3DBQV +HNW1oUgZJ3dluovRuYF4d0o7ahk0pIrhcRBLyZv1ihFM13muGAtE+tX7pNxo3DIhWQQYg79UHk WZ0K8qnWjJJgqlRy7AqBwrVUBtfnzIdwsvZpqD41y8q8yTmdLC2SmOEQOB8rAcaZtxhc9/WQg2Y /MhBnAGIuANqQYdE1QylIoq7mS0+aRMg9fE1kYu6BKNcuZ8wzUbiI2cOCovFXv6F5QnuS+0r1In Zf68OtUOUXL+9DAwdOj0oMPXSJdir/zNQpbcA228o7YAA60WHyc4aOu9Lc7xVXq5ougyzO22DDc ApkpbaH3y9aeiymAFrwcPsNAP79sFl+ey8mTrTixzHaKApLCKUz75TFsrTxmQSJ2RZ7DQISGS3P XpdyUSZs0YSk= X-Received: by 2002:a05:600c:5901:b0:4bb:5e8a:7c9c with SMTP id 5b1f17b1804b1-4bb861467c8mr335670965e9.7.1795649457193; Wed, 25 Nov 2026 15:30:57 -0800 (PST) Received: from localhost (bl20-90-91.dsl.telepac.pt. [2.81.90.91]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6baa3c4dsm31083635f8f.46.2026.11.25.15.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2026 15:30:56 -0800 (PST) From: =?UTF-8?q?V=C3=ADtor=20Hugo=20Silva?= To: linux-riscv@lists.infradead.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , Conor Dooley , Thomas Gleixner , Radu Rendec Subject: [PATCH RFC 06/19] irqchip: Add Espressif ESP32-P4 interrupt matrix support Date: Wed, 25 Nov 2026 23:30:07 +0000 Message-ID: <20261125233020.1380594-7-vitorhg20080@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125233020.1380594-1-vitorhg20080@gmail.com> References: <20261125233020.1380594-1-vitorhg20080@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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