[PATCH 2/2] irqchip: Add MediaTek SMMU wrapper driver

From: Alexandre Mergnat

Date: Tue Nov 17 2026 - 12:31:40 EST


On MT8196, each interrupt of the multimedia SMMUv3 must be acknowledged
in a MediaTek wrapper, which otherwise keeps its GIC line asserted.

Add a driver for the wrapper as a chained interrupt controller.

Signed-off-by: Alexandre Mergnat <amergnat@xxxxxxxxxxxx>
---
MAINTAINERS | 1 +
drivers/irqchip/Kconfig | 11 +++
drivers/irqchip/Makefile | 1 +
drivers/irqchip/irq-mtk-smmu-wp.c | 145 ++++++++++++++++++++++++++++++++++++++
4 files changed, 158 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 5cc65a753ad2..36866ba47912 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17228,6 +17228,7 @@ M: Alexandre Mergnat <amergnat@xxxxxxxxxxxx>
L: linux-mediatek@xxxxxxxxxxxxxxxxxxx (moderated for non-subscribers)
S: Maintained
F: Documentation/devicetree/bindings/interrupt-controller/mediatek,mt8196-smmu-wp.yaml
+F: drivers/irqchip/irq-mtk-smmu-wp.c

MEDIATEK SWITCH DRIVER
M: Chester A. Unal <chester.a.unal@xxxxxxxxxx>
diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 2edf121c7841..2773515f1dd4 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -866,4 +866,15 @@ config IRQCHIP_XILINX_SMMU_CSR
ZynqMP-class platforms where a vendor CSR block mediates SMMU
interrupts.

+config MTK_SMMU_WP
+ bool "MediaTek SMMU wrapper interrupt controller"
+ depends on (ARCH_MEDIATEK && ARM64) || COMPILE_TEST
+ default ARCH_MEDIATEK && ARM64
+ select IRQ_DOMAIN
+ help
+ Support for the wrapper block that MediaTek integrates
+ with the multimedia SMMUv3 of MT8196.
+ The interrupts of that SMMU do not work without this
+ driver.
+
endmenu
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index eb539d41251e..573b6c06fe06 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -73,6 +73,7 @@ obj-$(CONFIG_BRCMSTB_L2_IRQ) += irq-brcmstb-l2.o
obj-$(CONFIG_KEYSTONE_IRQ) += irq-keystone.o
obj-$(CONFIG_MIPS_GIC) += irq-mips-gic.o
obj-$(CONFIG_MTK_IRQ) += irq-mtk-sysirq.o irq-mtk-cirq.o
+obj-$(CONFIG_MTK_SMMU_WP) += irq-mtk-smmu-wp.o
obj-$(CONFIG_ARCH_DIGICOLOR) += irq-digicolor.o
obj-$(CONFIG_ARCH_SA1100) += irq-sa11x0.o
obj-$(CONFIG_INGENIC_IRQ) += irq-ingenic.o
diff --git a/drivers/irqchip/irq-mtk-smmu-wp.c b/drivers/irqchip/irq-mtk-smmu-wp.c
new file mode 100644
index 000000000000..6e5172d18b14
--- /dev/null
+++ b/drivers/irqchip/irq-mtk-smmu-wp.c
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * MediaTek SMMU wrapper interrupt controller
+ *
+ * Copyright (C) 2026 BayLibre, SAS
+ *
+ * The wrapper latches each SMMUv3 interrupt source in IRQ_STA and keeps its
+ * single output line asserted while a latched source is not acknowledged.
+ * An acknowledgment clears every pending occurrence of the source, so each
+ * source is handled as an edge, acknowledged before its handler reads the
+ * SMMU state. No mask register is known.
+ */
+
+#include <linux/bitops.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/irqchip.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+
+#define MTK_SMMU_WP_IRQ_STA 0x80
+#define MTK_SMMU_WP_IRQ_ACK 0x84
+#define MTK_SMMU_WP_IRQ_ACK_CNT 0x88
+#define MTK_SMMU_WP_IRQ_ACK_CNT_MASK GENMASK(7, 0)
+
+#define MTK_SMMU_WP_NR_IRQS 8
+
+struct mtk_smmu_wp {
+ struct device *dev;
+ void __iomem *base;
+ struct irq_domain *domain;
+};
+
+static void mtk_smmu_wp_ack_source(struct mtk_smmu_wp *wp, unsigned int src)
+{
+ writel_relaxed(BIT(src), wp->base + MTK_SMMU_WP_IRQ_ACK);
+ /* Flush the posted ACK before the SMMU is read */
+ readl(wp->base + MTK_SMMU_WP_IRQ_STA);
+}
+
+static void mtk_smmu_wp_irq_ack(struct irq_data *d)
+{
+ mtk_smmu_wp_ack_source(irq_data_get_irq_chip_data(d), d->hwirq);
+}
+
+static const struct irq_chip mtk_smmu_wp_chip = {
+ .name = "mtk-smmu-wp",
+ .irq_ack = mtk_smmu_wp_irq_ack,
+};
+
+static void mtk_smmu_wp_handler(struct irq_desc *desc)
+{
+ struct mtk_smmu_wp *wp = irq_desc_get_handler_data(desc);
+ struct irq_chip *chip = irq_desc_get_chip(desc);
+ unsigned long pending;
+ unsigned int src;
+
+ chained_irq_enter(chip, desc);
+
+ pending = readl_relaxed(wp->base + MTK_SMMU_WP_IRQ_STA);
+ for_each_set_bit(src, &pending, MTK_SMMU_WP_NR_IRQS) {
+ if (generic_handle_domain_irq(wp->domain, src)) {
+ /* Release an unused source, which would hold the line */
+ mtk_smmu_wp_ack_source(wp, src);
+ dev_warn_ratelimited(wp->dev, "unexpected source %u\n", src);
+ }
+ }
+
+ chained_irq_exit(chip, desc);
+}
+
+static int mtk_smmu_wp_map(struct irq_domain *d, unsigned int virq, irq_hw_number_t hwirq)
+{
+ irq_set_chip_and_handler(virq, &mtk_smmu_wp_chip, handle_edge_irq);
+ irq_set_chip_data(virq, d->host_data);
+ return 0;
+}
+
+static const struct irq_domain_ops mtk_smmu_wp_domain_ops = {
+ .map = mtk_smmu_wp_map,
+ .xlate = irq_domain_xlate_onecell,
+};
+
+static void mtk_smmu_wp_setup(struct mtk_smmu_wp *wp)
+{
+ u32 val;
+
+ /* Make each IRQ_ACK write clear every pending occurrence */
+ val = readl_relaxed(wp->base + MTK_SMMU_WP_IRQ_ACK_CNT);
+ val |= MTK_SMMU_WP_IRQ_ACK_CNT_MASK;
+ writel_relaxed(val, wp->base + MTK_SMMU_WP_IRQ_ACK_CNT);
+}
+
+static int mtk_smmu_wp_probe(struct platform_device *pdev, struct device_node *parent)
+{
+ struct irq_domain_info info = {
+ .fwnode = dev_fwnode(&pdev->dev),
+ .size = MTK_SMMU_WP_NR_IRQS,
+ .hwirq_max = MTK_SMMU_WP_NR_IRQS,
+ .ops = &mtk_smmu_wp_domain_ops,
+ };
+ struct device *dev = &pdev->dev;
+ struct mtk_smmu_wp *wp;
+ unsigned long pending;
+ unsigned int src;
+ int parent_irq;
+
+ wp = devm_kzalloc_obj(dev, *wp);
+ if (!wp)
+ return -ENOMEM;
+
+ wp->dev = dev;
+
+ wp->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(wp->base))
+ return PTR_ERR(wp->base);
+
+ parent_irq = platform_get_irq(pdev, 0);
+ if (parent_irq < 0)
+ return parent_irq;
+
+ mtk_smmu_wp_setup(wp);
+
+ /* Release the sources that an earlier boot stage left latched */
+ pending = readl_relaxed(wp->base + MTK_SMMU_WP_IRQ_STA);
+ for_each_set_bit(src, &pending, MTK_SMMU_WP_NR_IRQS)
+ mtk_smmu_wp_ack_source(wp, src);
+
+ info.host_data = wp;
+ wp->domain = devm_irq_domain_instantiate(dev, &info);
+ if (IS_ERR(wp->domain))
+ return PTR_ERR(wp->domain);
+
+ irq_set_chained_handler_and_data(parent_irq, mtk_smmu_wp_handler, wp);
+
+ return 0;
+}
+
+IRQCHIP_PLATFORM_DRIVER_BEGIN(mtk_smmu_wp)
+IRQCHIP_MATCH("mediatek,mt8196-mm-smmu-wp", mtk_smmu_wp_probe)
+IRQCHIP_PLATFORM_DRIVER_END(mtk_smmu_wp)

--
2.43.0