mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandre Mergnat <amergnat@baylibre.com>
To: Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	 Matthias Brugger <matthias.bgg@gmail.com>,
	 AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	 Thomas Gleixner <tglx@kernel.org>, Radu Rendec <radu@rendec.net>
Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org,
	linux-mediatek@lists.infradead.org,
	 Alexandre Mergnat <amergnat@baylibre.com>
Subject: [PATCH 2/2] irqchip: Add MediaTek SMMU wrapper driver
Date: Tue, 17 Nov 2026 17:31:05 +0000	[thread overview]
Message-ID: <20261117-mt8196-smmu-wrapper-v1-2-229f04d9f693@baylibre.com> (raw)
In-Reply-To: <20261117-mt8196-smmu-wrapper-v1-0-229f04d9f693@baylibre.com>

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@baylibre.com>
---
 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@baylibre.com>
 L:	linux-mediatek@lists.infradead.org (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@arinc9.com>
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


      parent reply	other threads:[~2026-11-17 17:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 17:31 [PATCH 0/2] Add MediaTek MT8196 SMMU wrapper interrupt controller Alexandre Mergnat
2026-11-17 17:31 ` [PATCH 1/2] dt-bindings: interrupt-controller: Add MT8196 SMMU wrapper Alexandre Mergnat
2026-12-01  2:50   ` Rob Herring (Arm)
2026-11-17 17:31 ` Alexandre Mergnat [this message]

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=20261117-mt8196-smmu-wrapper-v1-2-229f04d9f693@baylibre.com \
    --to=amergnat@baylibre.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --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®