From nobody Wed Oct 8 23:48:14 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87F3E24A047; Mon, 23 Jun 2025 12:01:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750680097; cv=none; b=IdqYKTG2/ux2GUPwm3RqXCJra8meeEi9qNzcLEQNkvh9MbtYzsNyfto70UXp4C52D+uL6O6LBbdZT1wVIZzaRztzT4666cdsnY86XrGc6K7XbPyKVD2F4wQaXSZ3qXvxfe7vDnKdGxh/EEXllFwUBgebu4LnbVSSprIN6KsKhVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750680097; c=relaxed/simple; bh=Gs8IvznRVgT9QfG9eZ/tmPi3BniOH2KnrQJ6DGc6zRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RJF+nwAjZnBb9W7ruR3yRVQK8QHWN/u6jQJODkrOApWne4WX1x1gU841+q0tgvxvMLdBpMpo7YEvJf1UcGBnHIkII49TuuJG8lSyZEhEb7cxx+fbzgZrQVhu+1mms/+IhGbMh9uO8mCwUj7ghEFWF56y4hKSXPqsGGePylqrV9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=iYYPAhYB; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="iYYPAhYB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1750680094; bh=Gs8IvznRVgT9QfG9eZ/tmPi3BniOH2KnrQJ6DGc6zRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iYYPAhYBcEdWr2Pxq7RQr0NcnTAzg8eNQ3Lj+CKpm1G8aQueLVHP7a6Df41JAMuEt URG8wwmsX1EIRPagkUkfnlF/YzCMOAB2bKnjxgTYySeUCg+VfO+M1hb7xsO7EzGLzk etorfcCnmjlCwqzwh6SnhW/82GTNSE7ejCA5hhsQQj767em6vdi+7TPH/G2e4yob53 1Y9AjtswGVbgmvZBNvQsOKKc0a2zaAbM01hpUIFI5/d5FX5OqdzHf8zmc6+gw4rVhp nAfc7rll6eRC0P0RIrW+P84YwLDiXqH/t0xe5hN6IZqLIb5qjy8T6SaH/zFvVpZqNp g8ayy4k5RE+MQ== Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by bali.collaboradmins.com (Postfix) with ESMTPSA id 69F3817E0EC0; Mon, 23 Jun 2025 14:01:33 +0200 (CEST) From: AngeloGioacchino Del Regno To: jassisinghbrar@gmail.com Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com Subject: [PATCH v1 1/2] dt-bindings: mailbox: Add MediaTek TinySYS MHU mailbox Date: Mon, 23 Jun 2025 14:01:26 +0200 Message-ID: <20250623120127.109237-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250623120127.109237-1-angelogioacchino.delregno@collabora.com> References: <20250623120127.109237-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a binding for the MediaTek TinySYS MHU mailbox, used for IPC with the TinySYS hardware integrated in various MediaTek SoCs. This mailbox handles a custom MHU enabling communication through the TinySYS SCMI protocol. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Rob Herring (Arm) --- .../mediatek,mt6985-tinysys-mhu-mbox.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/mailbox/mediatek,mt69= 85-tinysys-mhu-mbox.yaml diff --git a/Documentation/devicetree/bindings/mailbox/mediatek,mt6985-tiny= sys-mhu-mbox.yaml b/Documentation/devicetree/bindings/mailbox/mediatek,mt69= 85-tinysys-mhu-mbox.yaml new file mode 100644 index 000000000000..20fa5cb0ca0a --- /dev/null +++ b/Documentation/devicetree/bindings/mailbox/mediatek,mt6985-tinysys-mhu= -mbox.yaml @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mailbox/mediatek,mt6985-tinysys-mhu-mbo= x.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek TinySYS MHU mailbox + +maintainers: + - AngeloGioacchino Del Regno + +description: + This mailbox is used for Inter-Processor Communication (IPC) with the + TinySYS hardware integrated in various MediaTek SoCs and handles custom + Message Handling Unit (MHU) enabling communication through the TinySYS + SCMI protocol. + +properties: + compatible: + enum: + - mediatek,mt6985-tinysys-mhu-mbox + - mediatek,mt6989-tinysys-mhu-mbox + - mediatek,mt8196-tinysys-mhu-mbox + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + "#mbox-cells": + const: 0 + +required: + - compatible + - reg + - interrupts + - "#mbox-cells" + +additionalProperties: false + +examples: + - | + #include + #include + + tinysys_mbox0: mailbox@1c351000 { + compatible =3D "mediatek,mt6985-tinysys-mhu-mbox"; + reg =3D <0x1c351000 0x1000>; + interrupts =3D ; + #mbox-cells =3D <0>; + }; --=20 2.49.0 From nobody Wed Oct 8 23:48:14 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8877124A066; Mon, 23 Jun 2025 12:01:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750680098; cv=none; b=QywjquIH51DqQU2/QgKAMVeXiI0B08fatYXUebT5JZURRk/JVJi0jJs81RbKqj6aTqR240HlaxnUwYZ5HgalrtsrGGGVgfzCuufjCLwO+h0onmjgMUne2hKn2eRJLb1j0u9fgbwpt+R/e5sEjVMuQoXwFUrV7+0WMHf2u1eu3Rk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750680098; c=relaxed/simple; bh=FQ29J768ccXcedl+otLjqd2LskWC+DX/bA4170iHLrs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BjglZ6PBlrV72a+TgEVlz0sRtZDbWWPw1gMOHBbMPURvS2h/IQ1eyzqeJ1NDKloChTC+sKsQku6kdjOkOTfer+/VfiT6nvCnh4syU0SWhsiEq3Kr4NyKchrH7TfYer7mgW9Q17UFcEHGYHvBd6b1QSkMA7ynWnJ0Xypmx4JnJbg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=bdMfhR+u; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="bdMfhR+u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1750680094; bh=FQ29J768ccXcedl+otLjqd2LskWC+DX/bA4170iHLrs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bdMfhR+u1188kpqw3HvE9dnxZm/F9A3F04C0VM8Fdpf4Hm2mc458cdGJSC3LekKlI kOn5TSOtPmgVyUwlRsk0xxRYR3096KHoAi+2HdQlZ5rJ/t1EJxUu5/21YqUQkay8WY xdRb/s0/AVIxNq+c7LBVW8PuDeuAo9uZ7Ld4IWR8HGPD6k/RdAi4+eUsAmtIw1b2Uh m2v9KaoDUEdk+bxJm9Pai0ExVhTzY32KnL1M3j5EQ45HOU+12Cm6/5YQYOKPyrUjcz 9ftr1BAK5/TOv8KwdbV+CGXOCfv2QKL3FSUww3ex0+MFGZzxW8CQYz+Bt7VE+torkC j9ArJL5YxZc8A== Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by bali.collaboradmins.com (Postfix) with ESMTPSA id 3D09317E10D5; Mon, 23 Jun 2025 14:01:34 +0200 (CEST) From: AngeloGioacchino Del Regno To: jassisinghbrar@gmail.com Cc: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com Subject: [PATCH v1 2/2] mailbox: Add MediaTek TinySYS MHU-like Mailbox Date: Mon, 23 Jun 2025 14:01:27 +0200 Message-ID: <20250623120127.109237-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250623120127.109237-1-angelogioacchino.delregno@collabora.com> References: <20250623120127.109237-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the MediaTek TinySYS mailbox, used for IPC with the TinySYS MCU that is integrated in variousSoCs, enabling communication with remote processors that use the MediaTek IPIC framework through the TinySYS SCMI protocol. Signed-off-by: AngeloGioacchino Del Regno --- drivers/mailbox/Kconfig | 9 ++ drivers/mailbox/Makefile | 2 + drivers/mailbox/mtk-tinysys-mailbox.c | 196 ++++++++++++++++++++++++++ 3 files changed, 207 insertions(+) create mode 100644 drivers/mailbox/mtk-tinysys-mailbox.c diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 68eeed660a4a..35149110cb3a 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -285,6 +285,15 @@ config MTK_CMDQ_MBOX critical time limitation, such as updating display configuration during the vblank. =20 +config MTK_TINYSYS_MBOX + tristate "MediaTek TINYSYS Mailbox Support" + depends on ARCH_MEDIATEK || COMPILE_TEST + help + The MediaTek TinySYS mailbox is used to communicate with remote + processors based on the MediaTek IPIC framework. + Say yes here to add support for the MediaTek TinySYS mailbox + driver. + config ZYNQMP_IPI_MBOX tristate "Xilinx ZynqMP IPI Mailbox" depends on ARCH_ZYNQMP && OF diff --git a/drivers/mailbox/Makefile b/drivers/mailbox/Makefile index 13a3448b3271..415eb1d9ed47 100644 --- a/drivers/mailbox/Makefile +++ b/drivers/mailbox/Makefile @@ -61,6 +61,8 @@ obj-$(CONFIG_MTK_ADSP_MBOX) +=3D mtk-adsp-mailbox.o =20 obj-$(CONFIG_MTK_CMDQ_MBOX) +=3D mtk-cmdq-mailbox.o =20 +obj-$(CONFIG_MTK_TINYSYS_MBOX) +=3D mtk-tinysys-mailbox.o + obj-$(CONFIG_ZYNQMP_IPI_MBOX) +=3D zynqmp-ipi-mailbox.o =20 obj-$(CONFIG_SUN6I_MSGBOX) +=3D sun6i-msgbox.o diff --git a/drivers/mailbox/mtk-tinysys-mailbox.c b/drivers/mailbox/mtk-ti= nysys-mailbox.c new file mode 100644 index 000000000000..ec84951230e6 --- /dev/null +++ b/drivers/mailbox/mtk-tinysys-mailbox.c @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021 MediaTek Inc. + * Copyright (c) 2025 Collabora Ltd + * AngeloGioacchino Del Regno + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MTK_SIP_TINYSYS_SSPM_CONTROL MTK_SIP_SMC_CMD(0x53c) +#define MTK_TINYSYS_SSPM_OP_MBOX_CLR 0 +#define MTK_TINYSYS_SSPM_OP_MD2SPM_CLR 1 + +#define INTR_SET_OFS 0x0 +#define INTR_CLR_OFS 0x4 + +struct mtk_tinysys_mhu_mbox_pdata { + bool is_secure_mbox; + bool notify_spm; +}; + +struct mtk_tinysys_mhu_mbox { + void __iomem *base; + int irq; + const struct mtk_tinysys_mhu_mbox_pdata *pdata; + struct mbox_controller mbox; +}; + +static inline struct mtk_tinysys_mhu_mbox *to_mtk_tinysys_mhu_mbox(struct = mbox_controller *mbox) +{ + return container_of(mbox, struct mtk_tinysys_mhu_mbox, mbox); +} + +static irqreturn_t mtk_tinysys_mhu_mbox_irq(int irq, void *data) +{ + u32 val; + struct arm_smccc_res res; + struct mbox_chan *chan =3D data; + struct mtk_tinysys_mhu_mbox *priv =3D to_mtk_tinysys_mhu_mbox(chan->mbox); + + val =3D readl_relaxed(priv->base + INTR_CLR_OFS); + if (!val) + return IRQ_NONE; + + if (priv->pdata->is_secure_mbox) { + /* Can't fail: ignore res.a0 checks */ + arm_smccc_smc(MTK_SIP_TINYSYS_SSPM_CONTROL, + MTK_TINYSYS_SSPM_OP_MBOX_CLR, + priv->irq, 0, 0, 0, 0, 0, &res); + } else { + writel(1, priv->base + INTR_CLR_OFS); + } + + mbox_chan_received_data(chan, (void *)&val); + + if (priv->pdata->notify_spm) + arm_smccc_smc(MTK_SIP_TINYSYS_SSPM_CONTROL, + MTK_TINYSYS_SSPM_OP_MD2SPM_CLR, + priv->irq, 0, 0, 0, 0, 0, &res); + return IRQ_HANDLED; +} + +static bool mtk_tinysys_mhu_mbox_last_tx_done(struct mbox_chan *chan) +{ + struct mtk_tinysys_mhu_mbox *priv =3D to_mtk_tinysys_mhu_mbox(chan->mbox); + u32 val =3D readl_relaxed(priv->base + INTR_SET_OFS); + + return val =3D=3D 0; +} + +static int mtk_tinysys_mhu_mbox_send_data(struct mbox_chan *chan, void *da= ta) +{ + struct mtk_tinysys_mhu_mbox *priv =3D to_mtk_tinysys_mhu_mbox(chan->mbox); + u32 *arg =3D data; + + writel_relaxed(*arg, priv->base + INTR_SET_OFS); + + return 0; +} + +static int mtk_tinysys_mhu_mbox_startup(struct mbox_chan *chan) +{ + struct mtk_tinysys_mhu_mbox *priv =3D to_mtk_tinysys_mhu_mbox(chan->mbox); + + irq_clear_status_flags(priv->irq, IRQ_NOAUTOEN); + enable_irq(priv->irq); + + return 0; +} + +static void mtk_tinysys_mhu_mbox_shutdown(struct mbox_chan *chan) +{ + struct mtk_tinysys_mhu_mbox *priv =3D to_mtk_tinysys_mhu_mbox(chan->mbox); + + disable_irq(priv->irq); +} + +static const struct mbox_chan_ops tinysys_mbox_chan_ops =3D { + .send_data =3D mtk_tinysys_mhu_mbox_send_data, + .startup =3D mtk_tinysys_mhu_mbox_startup, + .shutdown =3D mtk_tinysys_mhu_mbox_shutdown, + .last_tx_done =3D mtk_tinysys_mhu_mbox_last_tx_done, +}; + +static int mtk_tinysys_mhu_mbox_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct mtk_tinysys_mhu_mbox *priv; + struct mbox_controller *mbox; + int ret; + + /* Allocate memory for device */ + priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + priv->irq =3D platform_get_irq(pdev, 0); + if (priv->irq < 0) + return priv->irq; + + priv->pdata =3D device_get_match_data(dev); + if (!priv->pdata) + return -EINVAL; + + mbox =3D &priv->mbox; + mbox->dev =3D dev; + mbox->ops =3D &tinysys_mbox_chan_ops; + mbox->txdone_irq =3D false; + mbox->txdone_poll =3D true; + mbox->txpoll_period =3D 1; + mbox->num_chans =3D 1; + mbox->chans =3D devm_kzalloc(dev, sizeof(*mbox->chans), GFP_KERNEL); + if (!mbox->chans) + return -ENOMEM; + + platform_set_drvdata(pdev, priv); + + irq_set_status_flags(priv->irq, IRQ_NOAUTOEN); + ret =3D devm_request_irq(dev, priv->irq, mtk_tinysys_mhu_mbox_irq, + IRQF_TRIGGER_NONE, dev_name(dev), mbox->chans); + if (ret < 0) + return ret; + + ret =3D devm_mbox_controller_register(dev, &priv->mbox); + if (ret) + return dev_err_probe(dev, ret, "Failed to register mailbox\n"); + + return 0; +} + +static const struct mtk_tinysys_mhu_mbox_pdata mt6985_tsmhu_mbox_cfg =3D { + /* Unsecured mailbox, no SPM notification */ +}; + +static const struct mtk_tinysys_mhu_mbox_pdata mt6989_tsmhu_mbox_cfg =3D { + .is_secure_mbox =3D true, +}; + +static const struct mtk_tinysys_mhu_mbox_pdata mt8196_tsmhu_mbox_cfg =3D { + .notify_spm =3D true, +}; + +static const struct of_device_id mtk_tinysys_mhu_mbox_of_match[] =3D { + { .compatible =3D "mediatek,mt6985-tinysys-mhu-mbox", .data =3D &mt6985_t= smhu_mbox_cfg }, + { .compatible =3D "mediatek,mt6989-tinysys-mhu-mbox", .data =3D &mt6989_t= smhu_mbox_cfg }, + { .compatible =3D "mediatek,mt8196-tinysys-mhu-mbox", .data =3D &mt8196_t= smhu_mbox_cfg }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mtk_tinysys_mhu_mbox_of_match); + +static struct platform_driver mtk_tinysys_mhu_mbox_drv =3D { + .probe =3D mtk_tinysys_mhu_mbox_probe, + .driver =3D { + .name =3D "mtk-tinysys-mhu-mbox", + .of_match_table =3D mtk_tinysys_mhu_mbox_of_match, + } +}; +module_platform_driver(mtk_tinysys_mhu_mbox_drv); + +MODULE_AUTHOR("AngeloGioacchino Del Regno "); +MODULE_DESCRIPTION("MediaTek TinySYS Mailbox Controller"); +MODULE_LICENSE("GPL"); --=20 2.49.0