* [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol
@ 2025-06-23 12:01 AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol AngeloGioacchino Del Regno
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-06-23 12:01 UTC (permalink / raw)
To: robh
Cc: krzk+dt, conor+dt, matthias.bgg, angelogioacchino.delregno,
sudeep.holla, cristian.marussi, devicetree, linux-kernel,
linux-arm-kernel, linux-mediatek, arm-scmi, kernel
This series adds basic support for the MediaTek TinySYS SCMI Protocol,
found on the MediaTek Dimensity 9200, 9300 and 9400, other than on the
MT8196 Chromebook SoC.
This is used to communicate with the CM_MGR and other MCUs for power
management purposes.
AngeloGioacchino Del Regno (2):
dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol
firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support
.../firmware/mediatek,mt6895-scmi.yaml | 22 ++
drivers/firmware/arm_scmi/Kconfig | 1 +
drivers/firmware/arm_scmi/Makefile | 1 +
.../arm_scmi/vendors/mediatek/Kconfig | 16 +
.../arm_scmi/vendors/mediatek/Makefile | 2 +
.../arm_scmi/vendors/mediatek/mtk-tinysys.c | 344 ++++++++++++++++++
include/linux/scmi_mtk_protocol.h | 62 ++++
7 files changed, 448 insertions(+)
create mode 100644 Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Makefile
create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
create mode 100644 include/linux/scmi_mtk_protocol.h
--
2.49.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol
2025-06-23 12:01 [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol AngeloGioacchino Del Regno
@ 2025-06-23 12:01 ` AngeloGioacchino Del Regno
2025-06-27 10:19 ` Cristian Marussi
2025-06-27 20:14 ` Rob Herring
2025-06-23 12:01 ` [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support AngeloGioacchino Del Regno
2025-06-23 12:17 ` [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol Cristian Marussi
2 siblings, 2 replies; 12+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-06-23 12:01 UTC (permalink / raw)
To: robh
Cc: krzk+dt, conor+dt, matthias.bgg, angelogioacchino.delregno,
sudeep.holla, cristian.marussi, devicetree, linux-kernel,
linux-arm-kernel, linux-mediatek, arm-scmi, kernel
Add the MediaTek TinySYS SCMI Extension protocol as found on a
number of SoCs, including MT6895 and MT8196.
This includes controls and power state notifications for the GPU,
CPU Memory latency Manager (cm_mgr), SLBC, SSPM and others.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
.../firmware/mediatek,mt6895-scmi.yaml | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
diff --git a/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml b/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
new file mode 100644
index 000000000000..98a5b81983b1
--- /dev/null
+++ b/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright 2025 Collabora Ltd
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/firmware/mediatek,mt6895-scmi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek System Control and Management Interface(SCMI) Vendor Protocols Extension
+
+maintainers:
+ - AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
+
+properties:
+ protocol@80:
+ $ref: '/schemas/firmware/arm,scmi.yaml#/$defs/protocol-node'
+ unevaluatedProperties: false
+
+ properties:
+ reg:
+ const: 0x80
+
+additionalProperties: true
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support
2025-06-23 12:01 [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol AngeloGioacchino Del Regno
@ 2025-06-23 12:01 ` AngeloGioacchino Del Regno
2025-06-23 12:16 ` Sudeep Holla
` (3 more replies)
2025-06-23 12:17 ` [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol Cristian Marussi
2 siblings, 4 replies; 12+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-06-23 12:01 UTC (permalink / raw)
To: robh
Cc: krzk+dt, conor+dt, matthias.bgg, angelogioacchino.delregno,
sudeep.holla, cristian.marussi, devicetree, linux-kernel,
linux-arm-kernel, linux-mediatek, arm-scmi, kernel
Add a driver for the SCMI protocol extensions for MediaTek TinySYS.
This is used to communicate with various remote processors in some
MediaTek SoCs, which mainly handle power management related tasks.
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
drivers/firmware/arm_scmi/Kconfig | 1 +
drivers/firmware/arm_scmi/Makefile | 1 +
.../arm_scmi/vendors/mediatek/Kconfig | 16 +
.../arm_scmi/vendors/mediatek/Makefile | 2 +
.../arm_scmi/vendors/mediatek/mtk-tinysys.c | 344 ++++++++++++++++++
include/linux/scmi_mtk_protocol.h | 62 ++++
6 files changed, 426 insertions(+)
create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Makefile
create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
create mode 100644 include/linux/scmi_mtk_protocol.h
diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
index e3fb36825978..baadf4f7fef6 100644
--- a/drivers/firmware/arm_scmi/Kconfig
+++ b/drivers/firmware/arm_scmi/Kconfig
@@ -84,6 +84,7 @@ config ARM_SCMI_QUIRKS
source "drivers/firmware/arm_scmi/transports/Kconfig"
source "drivers/firmware/arm_scmi/vendors/imx/Kconfig"
+source "drivers/firmware/arm_scmi/vendors/mediatek/Kconfig"
endif #ARM_SCMI_PROTOCOL
diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
index 780cd62b2f78..d1b4ec16b8bc 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -13,6 +13,7 @@ scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += transports/
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += vendors/imx/
+obj-$(CONFIG_ARM_SCMI_PROTOCOL) += vendors/mediatek/
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o
obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o
diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig b/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
new file mode 100644
index 000000000000..8facdcd3819f
--- /dev/null
+++ b/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+menu "ARM SCMI MediaTek Vendor Protocols"
+
+config MTK_SCMI_TINYSYS
+ tristate "MediaTek SCMI TinySYS Extension"
+ depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF)
+ default y if ARCH_MEDIATEK
+ help
+ This enables communication with the MediaTek TinySYS MCU
+ to control the power status of various SoC sub-devices
+ other than passing other messages for initialization.
+
+ To compile this driver as a module, choose M here: the
+ module will be called mtk-tinysys.
+
+endmenu
diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/Makefile b/drivers/firmware/arm_scmi/vendors/mediatek/Makefile
new file mode 100644
index 000000000000..dc1ff63c3b69
--- /dev/null
+++ b/drivers/firmware/arm_scmi/vendors/mediatek/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_MTK_SCMI_TINYSYS) += mtk-tinysys.o
diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c b/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
new file mode 100644
index 000000000000..baeb36493952
--- /dev/null
+++ b/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
@@ -0,0 +1,344 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * System Control and Management Interface (SCMI) MediaTek TinySYS Protocol
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Copyright (c) 2025 Collabora Ltd
+ * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
+ */
+
+#define pr_fmt(fmt) "SCMI Notifications TinySYS - " fmt
+
+#include <linux/bits.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/scmi_protocol.h>
+#include <linux/scmi_mtk_protocol.h>
+
+#include "../../protocols.h"
+#include "../../notify.h"
+
+#define SCMI_MTK_CMD_SSPM_QUERY_ALIVE 0xdead
+
+enum scmi_mtk_tinysys_protocol_cmd {
+ MTK_TINYSYS_COMMON_SET = 0x3,
+ MTK_TINYSYS_COMMON_GET = 0x4,
+ MTK_TINYSYS_POWER_STATE_NOTIFY = 0x5,
+ MTK_TINYSYS_SLBC_CTRL = 0x6,
+};
+
+struct scmi_mtk_tinysys_common_get_payld {
+ __le32 rsvd;
+ __le32 param[SCMI_MTK_MSG_COMMON_REPLY_BYTES];
+};
+
+struct scmi_mtk_tinysys_common_set_payld {
+ __le32 rsvd;
+ __le32 ctrl_id;
+ __le32 param[SCMI_MTK_MSG_COMMON_PARAM_BYTES];
+};
+
+struct scmi_mtk_tinysys_slbc_payld {
+ __le32 rsvd;
+ __le32 cmd;
+ __le32 arg[SCMI_MTK_MSG_SLBC_PARAM_BYTES];
+};
+
+struct scmi_mtk_tinysys_pwrst_notify {
+ __le32 rsvd;
+ __le32 fid;
+ __le32 enable;
+};
+
+struct scmi_mtk_tinysys_notify_payld {
+ __le32 fid;
+ __le32 param[SCMI_MTK_MSG_NOTIF_ST_BYTES];
+};
+
+struct scmi_mtk_tinysys_protocol_attributes {
+ __le32 attributes;
+};
+
+struct scmi_mtk_tinysys_info {
+ int num_domains;
+};
+
+static int scmi_mtk_tinysys_attributes_get(const struct scmi_protocol_handle *ph,
+ struct scmi_mtk_tinysys_info *tinfo)
+{
+ struct scmi_mtk_tinysys_protocol_attributes *attr;
+ struct scmi_xfer *t;
+ int ret;
+
+ ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0, sizeof(*attr), &t);
+ if (ret)
+ return ret;
+
+ attr = t->rx.buf;
+
+ ret = ph->xops->do_xfer(ph, t);
+ if (!ret) {
+ attr->attributes = get_unaligned_le32(t->rx.buf);
+ tinfo->num_domains = attr->attributes;
+ }
+
+ ph->xops->xfer_put(ph, t);
+
+ return ret;
+}
+
+static int scmi_mtk_tinysys_get_num_sources(const struct scmi_protocol_handle *ph)
+{
+ struct scmi_mtk_tinysys_info *tinfo = ph->get_priv(ph);
+
+ if (!tinfo)
+ return -EINVAL;
+
+ return tinfo->num_domains;
+}
+
+static int scmi_mtk_tinysys_set_notify_enabled(const struct scmi_protocol_handle *ph,
+ u8 evt_id, u32 src_id, bool enable)
+{
+ struct scmi_mtk_tinysys_pwrst_notify *pwrst_notify;
+ struct scmi_xfer *t;
+ int ret;
+
+ /* There's only one possible event for now */
+ if (evt_id != 0)
+ return -EINVAL;
+
+ ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_POWER_STATE_NOTIFY,
+ sizeof(*pwrst_notify), 0, &t);
+ if (ret)
+ return ret;
+
+ pwrst_notify = t->tx.buf;
+ pwrst_notify->fid = src_id;
+ pwrst_notify->enable = cpu_to_le32(enable);
+
+ ret = ph->xops->do_xfer(ph, t);
+ ph->xops->xfer_put(ph, t);
+ return ret;
+}
+
+static void *scmi_mtk_tinysys_fill_custom_report(const struct scmi_protocol_handle *ph,
+ u8 evt_id, ktime_t timestamp,
+ const void *payld, size_t payld_sz,
+ void *report, u32 *src_id)
+{
+ const struct scmi_mtk_tinysys_notify_payld *p = payld;
+ struct scmi_mtk_tinysys_notif_report *r = report;
+ int i;
+
+ if (sizeof(*p) != payld_sz)
+ return NULL;
+
+ if (evt_id == SCMI_EVENT_MTK_TINYSYS_NOTIFIER) {
+ r->timestamp = timestamp;
+ r->fid = le32_to_cpu(p->fid);
+ for (i = 0; i < SCMI_MTK_MSG_NOTIF_ST_BYTES; i++)
+ r->status[i] = le32_to_cpu(p->param[i]);
+ if (src_id)
+ *src_id = p->fid;
+ } else {
+ WARN_ON_ONCE(1);
+ return NULL;
+ }
+
+ return r;
+}
+
+static const struct scmi_event scmi_mtk_tinysys_events[] = {
+ {
+ .id = SCMI_EVENT_MTK_TINYSYS_NOTIFIER,
+ .max_payld_sz = sizeof(struct scmi_mtk_tinysys_notify_payld),
+ .max_report_sz = sizeof(struct scmi_mtk_tinysys_notif_report),
+ },
+};
+
+static int scmi_mtk_tinysys_common_get(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, u32 cmd,
+ struct scmi_mtk_tinysys_status *retval)
+{
+ struct scmi_mtk_tinysys_common_get_payld *p;
+ struct scmi_xfer *t;
+ int ret;
+
+ ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_COMMON_GET,
+ sizeof(*p), sizeof(*retval), &t);
+ if (ret)
+ return ret;
+
+ p = t->tx.buf;
+ p->param[0] = ctrl_id;
+ p->param[1] = cmd;
+
+ ret = ph->xops->do_xfer(ph, t);
+ if (!ret) {
+ if (t->rx.len == sizeof(*retval))
+ memcpy(retval, t->rx.buf, sizeof(*retval));
+ else
+ ret = -EINVAL;
+ }
+
+ ph->xops->xfer_put(ph, t);
+ return ret;
+}
+
+static int scmi_mtk_tinysys_common_set(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, const u32 *params,
+ const u8 num_params)
+{
+ struct scmi_mtk_tinysys_common_set_payld *p;
+ struct scmi_xfer *t;
+ int i, ret;
+
+ if (!params || num_params > SCMI_MTK_MSG_COMMON_PARAM_BYTES)
+ return -EINVAL;
+
+ ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_COMMON_SET, sizeof(*p), 0, &t);
+ if (ret)
+ return ret;
+
+ p = t->tx.buf;
+ p->ctrl_id = cpu_to_le32(ctrl_id);
+ for (i = 0; i < num_params; i++)
+ p->param[i] = cpu_to_le32(params[i]);
+
+ ret = ph->xops->do_xfer(ph, t);
+
+ ph->xops->xfer_put(ph, t);
+ return ret;
+}
+
+static int scmi_mtk_tinysys_cm_mgr_set(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, u32 cmd, u32 arg)
+{
+ const u32 params[2] = { cmd, arg };
+
+ return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2);
+}
+
+static int scmi_mtk_tinysys_gpu_pwr_set(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, u8 pwr_indication, bool enable)
+{
+ const u32 params[2] = { pwr_indication, enable };
+
+ return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2);
+}
+
+static int scmi_mtk_tinysys_slbc_req(const struct scmi_protocol_handle *ph,
+ const struct scmi_mtk_tinysys_slbc *req,
+ struct scmi_mtk_tinysys_slbc *retval)
+{
+ struct scmi_mtk_tinysys_slbc_payld *p;
+ struct scmi_xfer *t;
+ int i, ret;
+
+ ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_SLBC_CTRL,
+ sizeof(*p), sizeof(*p), &t);
+ if (ret)
+ return ret;
+
+ p = t->tx.buf;
+ p->cmd = cpu_to_le32(req->cmd);
+ for (i = 0; i < SCMI_MTK_MSG_SLBC_PARAM_BYTES; i++)
+ p->arg[i] = cpu_to_le32(req->arg[i]);
+
+ ret = ph->xops->do_xfer(ph, t);
+ if (!ret && retval) {
+ if (t->rx.len == sizeof(*retval))
+ memcpy(retval, t->rx.buf, sizeof(*retval));
+ else
+ ret = -EINVAL;
+ }
+
+ ph->xops->xfer_put(ph, t);
+ return ret;
+}
+
+static int scmi_mtk_tinysys_sspm_mem_set(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, u32 pa, u32 mem_sz)
+{
+ const u32 params[2] = { pa, mem_sz };
+
+ if (mem_sz < SZ_1M)
+ return -EINVAL;
+
+ return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2);
+}
+
+static bool scmi_mtk_tinysys_sspm_is_alive(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id)
+{
+ const u32 param = SCMI_MTK_CMD_SSPM_QUERY_ALIVE;
+ int ret;
+
+ ret = scmi_mtk_tinysys_common_set(ph, ctrl_id, ¶m, 1);
+
+ return ret ? false : true;
+}
+
+static const struct scmi_mtk_tinysys_proto_ops mtk_tinysys_proto_ops = {
+ .common_get = scmi_mtk_tinysys_common_get,
+ .cm_mgr_set = scmi_mtk_tinysys_cm_mgr_set,
+ .gpu_pwr_set = scmi_mtk_tinysys_gpu_pwr_set,
+ .slbc_req = scmi_mtk_tinysys_slbc_req,
+ .sspm_is_alive = scmi_mtk_tinysys_sspm_is_alive,
+ .sspm_mem_set = scmi_mtk_tinysys_sspm_mem_set,
+};
+
+static const struct scmi_event_ops scmi_mtk_tinysys_event_ops = {
+ .get_num_sources = scmi_mtk_tinysys_get_num_sources,
+ .set_notify_enabled = scmi_mtk_tinysys_set_notify_enabled,
+ .fill_custom_report = scmi_mtk_tinysys_fill_custom_report,
+};
+
+static const struct scmi_protocol_events scmi_mtk_tinysys_protocol_events = {
+ .queue_sz = 4 * SCMI_PROTO_QUEUE_SZ,
+ .ops = &scmi_mtk_tinysys_event_ops,
+ .evts = scmi_mtk_tinysys_events,
+ .num_events = ARRAY_SIZE(scmi_mtk_tinysys_events),
+};
+
+static int scmi_mtk_tinysys_protocol_init(const struct scmi_protocol_handle *ph)
+{
+ struct scmi_mtk_tinysys_info *tinfo;
+ u32 version;
+ int ret;
+
+ ret = ph->xops->version_get(ph, &version);
+ if (ret)
+ return ret;
+
+ dev_info(ph->dev, "MediaTek TinySYS Protocol Version %d.%d\n",
+ PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
+
+ tinfo = devm_kzalloc(ph->dev, sizeof(*tinfo), GFP_KERNEL);
+ if (!tinfo)
+ return -ENOMEM;
+
+ ret = scmi_mtk_tinysys_attributes_get(ph, tinfo);
+ if (ret)
+ return ret;
+
+ return ph->set_priv(ph, tinfo, version);
+}
+
+static const struct scmi_protocol scmi_mtk_tinysys = {
+ .id = SCMI_PROTOCOL_MTK_TINYSYS,
+ .owner = THIS_MODULE,
+ .instance_init = &scmi_mtk_tinysys_protocol_init,
+ .ops = &mtk_tinysys_proto_ops,
+ .events = &scmi_mtk_tinysys_protocol_events,
+ .vendor_id = SCMI_MTK_VENDOR,
+};
+module_scmi_protocol(scmi_mtk_tinysys);
+
+MODULE_AUTHOR("AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>");
+MODULE_ALIAS("scmi-protocol-" __stringify(SCMI_PROTOCOL_MTK_TINYSYS) "-" SCMI_MTK_VENDOR);
+MODULE_DESCRIPTION("MediaTek SCMI TinySYS driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/scmi_mtk_protocol.h b/include/linux/scmi_mtk_protocol.h
new file mode 100644
index 000000000000..51ad0cb4b72d
--- /dev/null
+++ b/include/linux/scmi_mtk_protocol.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * SCMI Message Protocol driver MediaTek extension header
+ *
+ * Copyright (c) 2021 MediaTek Inc.
+ * Copyright (c) 2025 Collabora Ltd
+ * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
+ */
+
+#ifndef _LINUX_SCMI_MTK_PROTOCOL_H
+#define _LINUX_SCMI_MTK_PROTOCOL_H
+
+#include <linux/bitfield.h>
+#include <linux/device.h>
+#include <linux/notifier.h>
+#include <linux/types.h>
+
+#define SCMI_PROTOCOL_MTK_TINYSYS 0x80
+#define SCMI_MTK_VENDOR "MediaTek"
+
+#define SCMI_MTK_MSG_COMMON_PARAM_BYTES 5
+#define SCMI_MTK_MSG_COMMON_REPLY_BYTES 2
+#define SCMI_MTK_MSG_NOTIF_ST_BYTES 4
+#define SCMI_MTK_MSG_SLBC_PARAM_BYTES 4
+
+struct scmi_mtk_tinysys_status {
+ u32 rsvd;
+ u32 reply[SCMI_MTK_MSG_COMMON_REPLY_BYTES];
+};
+
+struct scmi_mtk_tinysys_slbc {
+ u32 cmd;
+ u32 arg[SCMI_MTK_MSG_SLBC_PARAM_BYTES];
+};
+
+struct scmi_mtk_tinysys_proto_ops {
+ int (*common_get)(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, u32 cmd,
+ struct scmi_mtk_tinysys_status *retval);
+ int (*cm_mgr_set)(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, u32 cmd, u32 arg);
+ int (*gpu_pwr_set)(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, u8 pwr_indication, bool enable);
+ int (*slbc_req)(const struct scmi_protocol_handle *ph,
+ const struct scmi_mtk_tinysys_slbc *req,
+ struct scmi_mtk_tinysys_slbc *retval);
+ bool (*sspm_is_alive)(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id);
+ int (*sspm_mem_set)(const struct scmi_protocol_handle *ph,
+ u32 ctrl_id, u32 pa, u32 mem_sz);
+};
+
+enum scmi_mtk_tinysys_notification_events {
+ SCMI_EVENT_MTK_TINYSYS_NOTIFIER = 0x0,
+};
+
+struct scmi_mtk_tinysys_notif_report {
+ ktime_t timestamp;
+ unsigned int fid;
+ unsigned int status[SCMI_MTK_MSG_NOTIF_ST_BYTES];
+};
+#endif
--
2.49.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support
2025-06-23 12:01 ` [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support AngeloGioacchino Del Regno
@ 2025-06-23 12:16 ` Sudeep Holla
2025-06-24 3:01 ` Peng Fan
` (2 subsequent siblings)
3 siblings, 0 replies; 12+ messages in thread
From: Sudeep Holla @ 2025-06-23 12:16 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: robh, krzk+dt, conor+dt, matthias.bgg, cristian.marussi,
Sudeep Holla, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, arm-scmi, kernel
On Mon, Jun 23, 2025 at 02:01:36PM +0200, AngeloGioacchino Del Regno wrote:
> Add a driver for the SCMI protocol extensions for MediaTek TinySYS.
> This is used to communicate with various remote processors in some
> MediaTek SoCs, which mainly handle power management related tasks.
>
Please provide the detailed documentation for this vendor protocol/extension.
Refer drivers/firmware/arm_scmi/vendors/imx/imx95.rst for example.
It is hard to do any useful review without the detailed documentation.
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol
2025-06-23 12:01 [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support AngeloGioacchino Del Regno
@ 2025-06-23 12:17 ` Cristian Marussi
2025-06-23 12:32 ` AngeloGioacchino Del Regno
2 siblings, 1 reply; 12+ messages in thread
From: Cristian Marussi @ 2025-06-23 12:17 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: robh, krzk+dt, conor+dt, matthias.bgg, sudeep.holla,
cristian.marussi, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, arm-scmi, kernel
On Mon, Jun 23, 2025 at 02:01:34PM +0200, AngeloGioacchino Del Regno wrote:
> This series adds basic support for the MediaTek TinySYS SCMI Protocol,
> found on the MediaTek Dimensity 9200, 9300 and 9400, other than on the
> MT8196 Chromebook SoC.
>
> This is used to communicate with the CM_MGR and other MCUs for power
> management purposes.
Hi Angelo,
thanks for this.
I will do a proper review in the coming days of this series anyway, but
upfront for future V2:
- you should provide some sort of documentation for this new
vendor protocol and its messages, as an example from IMX:
drivers/firmware/arm_scmi/vendors/imx/imx95.rst
- where is the SCMI driver that will call all the new vendor ops
defined in: scmi_mtk_protocol.h ?
Thanks,
Cristian
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol
2025-06-23 12:17 ` [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol Cristian Marussi
@ 2025-06-23 12:32 ` AngeloGioacchino Del Regno
2025-06-23 13:30 ` Cristian Marussi
0 siblings, 1 reply; 12+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-06-23 12:32 UTC (permalink / raw)
To: Cristian Marussi
Cc: robh, krzk+dt, conor+dt, matthias.bgg, sudeep.holla, devicetree,
linux-kernel, linux-arm-kernel, linux-mediatek, arm-scmi, kernel
Il 23/06/25 14:17, Cristian Marussi ha scritto:
> On Mon, Jun 23, 2025 at 02:01:34PM +0200, AngeloGioacchino Del Regno wrote:
>> This series adds basic support for the MediaTek TinySYS SCMI Protocol,
>> found on the MediaTek Dimensity 9200, 9300 and 9400, other than on the
>> MT8196 Chromebook SoC.
>>
>> This is used to communicate with the CM_MGR and other MCUs for power
>> management purposes.
>
> Hi Angelo,
>
> thanks for this.
>
> I will do a proper review in the coming days of this series anyway, but
> upfront for future V2:
>
> - you should provide some sort of documentation for this new
> vendor protocol and its messages, as an example from IMX:
>
> drivers/firmware/arm_scmi/vendors/imx/imx95.rst
Noted.
>
> - where is the SCMI driver that will call all the new vendor ops
> defined in: scmi_mtk_protocol.h ?
This was tested with code that is not clean at all (hence I can't push it upstream)
and well... I didn't think about the fact that, effectively, without an user, this
code ends up being unused.
I can't promise to send a clean user in this cycle, but I would really appreciate
if you could still check the protocol code, so that if there's anything that you
can spot I can fix it while the rest gets done :-)
Thank you,
Angelo
>
> Thanks,
> Cristian
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol
2025-06-23 12:32 ` AngeloGioacchino Del Regno
@ 2025-06-23 13:30 ` Cristian Marussi
0 siblings, 0 replies; 12+ messages in thread
From: Cristian Marussi @ 2025-06-23 13:30 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: Cristian Marussi, robh, krzk+dt, conor+dt, matthias.bgg,
sudeep.holla, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, arm-scmi, kernel
On Mon, Jun 23, 2025 at 02:32:24PM +0200, AngeloGioacchino Del Regno wrote:
> Il 23/06/25 14:17, Cristian Marussi ha scritto:
> > On Mon, Jun 23, 2025 at 02:01:34PM +0200, AngeloGioacchino Del Regno wrote:
> > > This series adds basic support for the MediaTek TinySYS SCMI Protocol,
> > > found on the MediaTek Dimensity 9200, 9300 and 9400, other than on the
> > > MT8196 Chromebook SoC.
> > >
> > > This is used to communicate with the CM_MGR and other MCUs for power
> > > management purposes.
> >
> > Hi Angelo,
> >
> > thanks for this.
> >
> > I will do a proper review in the coming days of this series anyway, but
> > upfront for future V2:
> >
> > - you should provide some sort of documentation for this new
> > vendor protocol and its messages, as an example from IMX:
> >
> > drivers/firmware/arm_scmi/vendors/imx/imx95.rst
>
> Noted.
>
> >
> > - where is the SCMI driver that will call all the new vendor ops
> > defined in: scmi_mtk_protocol.h ?
>
> This was tested with code that is not clean at all (hence I can't push it upstream)
> and well... I didn't think about the fact that, effectively, without an user, this
> code ends up being unused.
>
> I can't promise to send a clean user in this cycle, but I would really appreciate
> if you could still check the protocol code, so that if there's anything that you
> can spot I can fix it while the rest gets done :-)
Sure, I will anyway review, but a driver user exampe would be useful, maybe
posting it at the end of the series as a NOT-FOR-UPSTREAM/RFC (something like that)
so that we can have an iddea of the usage patterns while being aware that it is
still not clean for upstream.
Thanks,
Cristian
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support
2025-06-23 12:01 ` [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support AngeloGioacchino Del Regno
2025-06-23 12:16 ` Sudeep Holla
@ 2025-06-24 3:01 ` Peng Fan
2025-06-27 8:20 ` kernel test robot
2025-06-27 11:43 ` Cristian Marussi
3 siblings, 0 replies; 12+ messages in thread
From: Peng Fan @ 2025-06-24 3:01 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: robh, krzk+dt, conor+dt, matthias.bgg, sudeep.holla,
cristian.marussi, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, arm-scmi, kernel
On Mon, Jun 23, 2025 at 02:01:36PM +0200, AngeloGioacchino Del Regno wrote:
>Add a driver for the SCMI protocol extensions for MediaTek TinySYS.
>This is used to communicate with various remote processors in some
>MediaTek SoCs, which mainly handle power management related tasks.
>
>Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>---
> drivers/firmware/arm_scmi/Kconfig | 1 +
> drivers/firmware/arm_scmi/Makefile | 1 +
> .../arm_scmi/vendors/mediatek/Kconfig | 16 +
> .../arm_scmi/vendors/mediatek/Makefile | 2 +
> .../arm_scmi/vendors/mediatek/mtk-tinysys.c | 344 ++++++++++++++++++
> include/linux/scmi_mtk_protocol.h | 62 ++++
> 6 files changed, 426 insertions(+)
> create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
> create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Makefile
> create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
> create mode 100644 include/linux/scmi_mtk_protocol.h
>
>diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
>index e3fb36825978..baadf4f7fef6 100644
>--- a/drivers/firmware/arm_scmi/Kconfig
>+++ b/drivers/firmware/arm_scmi/Kconfig
>@@ -84,6 +84,7 @@ config ARM_SCMI_QUIRKS
>
> source "drivers/firmware/arm_scmi/transports/Kconfig"
> source "drivers/firmware/arm_scmi/vendors/imx/Kconfig"
>+source "drivers/firmware/arm_scmi/vendors/mediatek/Kconfig"
>
> endif #ARM_SCMI_PROTOCOL
>
>diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
>index 780cd62b2f78..d1b4ec16b8bc 100644
>--- a/drivers/firmware/arm_scmi/Makefile
>+++ b/drivers/firmware/arm_scmi/Makefile
>@@ -13,6 +13,7 @@ scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
>
> obj-$(CONFIG_ARM_SCMI_PROTOCOL) += transports/
> obj-$(CONFIG_ARM_SCMI_PROTOCOL) += vendors/imx/
>+obj-$(CONFIG_ARM_SCMI_PROTOCOL) += vendors/mediatek/
>
> obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o
> obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o
>diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig b/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
>new file mode 100644
>index 000000000000..8facdcd3819f
>--- /dev/null
>+++ b/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
>@@ -0,0 +1,16 @@
>+# SPDX-License-Identifier: GPL-2.0-only
>+menu "ARM SCMI MediaTek Vendor Protocols"
>+
>+config MTK_SCMI_TINYSYS
>+ tristate "MediaTek SCMI TinySYS Extension"
>+ depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF)
Should dependency to ARCH_MEDIATEK be added, as below
ARM_SCMI_PROTOCOL & ARCH_MEDIATEK ?
>+ default y if ARCH_MEDIATEK
>+ help
>+ This enables communication with the MediaTek TinySYS MCU
>+ to control the power status of various SoC sub-devices
>+ other than passing other messages for initialization.
>+
>+ To compile this driver as a module, choose M here: the
>+ module will be called mtk-tinysys.
>+
>+endmenu
>diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/Makefile b/drivers/firmware/arm_scmi/vendors/mediatek/Makefile
>new file mode 100644
>index 000000000000..dc1ff63c3b69
>--- /dev/null
>+++ b/drivers/firmware/arm_scmi/vendors/mediatek/Makefile
>@@ -0,0 +1,2 @@
>+# SPDX-License-Identifier: GPL-2.0-only
>+obj-$(CONFIG_MTK_SCMI_TINYSYS) += mtk-tinysys.o
>diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c b/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
>new file mode 100644
>index 000000000000..baeb36493952
>--- /dev/null
>+++ b/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
>@@ -0,0 +1,344 @@
>+// SPDX-License-Identifier: GPL-2.0
>+/*
>+ * System Control and Management Interface (SCMI) MediaTek TinySYS Protocol
>+ *
>+ * Copyright (c) 2021 MediaTek Inc.
>+ * Copyright (c) 2025 Collabora Ltd
>+ * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>+ */
>+
>+#define pr_fmt(fmt) "SCMI Notifications TinySYS - " fmt
>+
>+#include <linux/bits.h>
>+#include <linux/io.h>
>+#include <linux/module.h>
>+#include <linux/of.h>
>+#include <linux/platform_device.h>
This header is not needed, since no user here.
I just see i.MX also includes this header, but could be dropped.
>+#include <linux/scmi_protocol.h>
>+#include <linux/scmi_mtk_protocol.h>
>+
>+#include "../../protocols.h"
>+#include "../../notify.h"
>+
>+#define SCMI_MTK_CMD_SSPM_QUERY_ALIVE 0xdead
>+
>+enum scmi_mtk_tinysys_protocol_cmd {
>+ MTK_TINYSYS_COMMON_SET = 0x3,
>+ MTK_TINYSYS_COMMON_GET = 0x4,
>+ MTK_TINYSYS_POWER_STATE_NOTIFY = 0x5,
>+ MTK_TINYSYS_SLBC_CTRL = 0x6,
>+};
>+
>+struct scmi_mtk_tinysys_common_get_payld {
>+ __le32 rsvd;
>+ __le32 param[SCMI_MTK_MSG_COMMON_REPLY_BYTES];
>+};
>+
>+struct scmi_mtk_tinysys_common_set_payld {
>+ __le32 rsvd;
>+ __le32 ctrl_id;
>+ __le32 param[SCMI_MTK_MSG_COMMON_PARAM_BYTES];
>+};
>+
>+struct scmi_mtk_tinysys_slbc_payld {
>+ __le32 rsvd;
>+ __le32 cmd;
>+ __le32 arg[SCMI_MTK_MSG_SLBC_PARAM_BYTES];
>+};
>+
>+struct scmi_mtk_tinysys_pwrst_notify {
>+ __le32 rsvd;
Not sure why all upper structure has 'rsvd', meaning reserved?
>+ __le32 fid;
>+ __le32 enable;
>+};
>+
>+struct scmi_mtk_tinysys_notify_payld {
>+ __le32 fid;
>+ __le32 param[SCMI_MTK_MSG_NOTIF_ST_BYTES];
>+};
>+
>+struct scmi_mtk_tinysys_protocol_attributes {
>+ __le32 attributes;
>+};
>+
>+struct scmi_mtk_tinysys_info {
>+ int num_domains;
>+};
>+
>+static int scmi_mtk_tinysys_attributes_get(const struct scmi_protocol_handle *ph,
>+ struct scmi_mtk_tinysys_info *tinfo)
>+{
>+ struct scmi_mtk_tinysys_protocol_attributes *attr;
>+ struct scmi_xfer *t;
>+ int ret;
>+
>+ ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0, sizeof(*attr), &t);
>+ if (ret)
>+ return ret;
>+
>+ attr = t->rx.buf;
>+
>+ ret = ph->xops->do_xfer(ph, t);
>+ if (!ret) {
>+ attr->attributes = get_unaligned_le32(t->rx.buf);
>+ tinfo->num_domains = attr->attributes;
Not sure the spec use whole 32bits for num_domains, if not, better
use le32_get_bits to the expect fields
>+ }
>+
>+ ph->xops->xfer_put(ph, t);
>+
>+ return ret;
>+}
>+
>+static int scmi_mtk_tinysys_get_num_sources(const struct scmi_protocol_handle *ph)
>+{
>+ struct scmi_mtk_tinysys_info *tinfo = ph->get_priv(ph);
>+
>+ if (!tinfo)
>+ return -EINVAL;
>+
>+ return tinfo->num_domains;
>+}
>+
>+static int scmi_mtk_tinysys_set_notify_enabled(const struct scmi_protocol_handle *ph,
>+ u8 evt_id, u32 src_id, bool enable)
>+{
>+ struct scmi_mtk_tinysys_pwrst_notify *pwrst_notify;
>+ struct scmi_xfer *t;
>+ int ret;
>+
>+ /* There's only one possible event for now */
>+ if (evt_id != 0)
Use 'evt_id != SCMI_EVENT_MTK_TINYSYS_NOTIFIER' ?
>+ return -EINVAL;
>+
...
>+#endif
>--
>2.49.0
>
Regards,
Peng
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support
2025-06-23 12:01 ` [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support AngeloGioacchino Del Regno
2025-06-23 12:16 ` Sudeep Holla
2025-06-24 3:01 ` Peng Fan
@ 2025-06-27 8:20 ` kernel test robot
2025-06-27 11:43 ` Cristian Marussi
3 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2025-06-27 8:20 UTC (permalink / raw)
To: AngeloGioacchino Del Regno, robh
Cc: oe-kbuild-all, krzk+dt, conor+dt, matthias.bgg,
angelogioacchino.delregno, sudeep.holla, cristian.marussi,
devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
arm-scmi, kernel
Hi AngeloGioacchino,
kernel test robot noticed the following build warnings:
[auto build test WARNING on robh/for-next]
[also build test WARNING on linus/master v6.16-rc3 next-20250626]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/AngeloGioacchino-Del-Regno/dt-bindings-firmware-Add-MediaTek-TinySYS-SCMI-Extension-protocol/20250623-201014
base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
patch link: https://lore.kernel.org/r/20250623120136.109311-3-angelogioacchino.delregno%40collabora.com
patch subject: [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support
config: csky-randconfig-r111-20250627 (https://download.01.org/0day-ci/archive/20250627/202506271642.aFdjzjw7-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 15.1.0
reproduce: (https://download.01.org/0day-ci/archive/20250627/202506271642.aFdjzjw7-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506271642.aFdjzjw7-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
>> drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:83:34: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] attributes @@ got unsigned int @@
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:83:34: sparse: expected restricted __le32 [usertype] attributes
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:83:34: sparse: got unsigned int
>> drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:84:36: sparse: sparse: incorrect type in assignment (different base types) @@ expected int num_domains @@ got restricted __le32 [usertype] attributes @@
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:84:36: sparse: expected int num_domains
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:84:36: sparse: got restricted __le32 [usertype] attributes
>> drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:119:27: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 [usertype] fid @@ got unsigned int [usertype] src_id @@
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:119:27: sparse: expected restricted __le32 [usertype] fid
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:119:27: sparse: got unsigned int [usertype] src_id
>> drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:145:33: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] @@ got restricted __le32 const [usertype] fid @@
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:145:33: sparse: expected unsigned int [usertype]
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:145:33: sparse: got restricted __le32 const [usertype] fid
>> drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:176:21: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 @@ got unsigned int [usertype] ctrl_id @@
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:176:21: sparse: expected restricted __le32
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:176:21: sparse: got unsigned int [usertype] ctrl_id
>> drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:177:21: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted __le32 @@ got unsigned int [usertype] cmd @@
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:177:21: sparse: expected restricted __le32
drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c:177:21: sparse: got unsigned int [usertype] cmd
vim +83 drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
67
68 static int scmi_mtk_tinysys_attributes_get(const struct scmi_protocol_handle *ph,
69 struct scmi_mtk_tinysys_info *tinfo)
70 {
71 struct scmi_mtk_tinysys_protocol_attributes *attr;
72 struct scmi_xfer *t;
73 int ret;
74
75 ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0, sizeof(*attr), &t);
76 if (ret)
77 return ret;
78
79 attr = t->rx.buf;
80
81 ret = ph->xops->do_xfer(ph, t);
82 if (!ret) {
> 83 attr->attributes = get_unaligned_le32(t->rx.buf);
> 84 tinfo->num_domains = attr->attributes;
85 }
86
87 ph->xops->xfer_put(ph, t);
88
89 return ret;
90 }
91
92 static int scmi_mtk_tinysys_get_num_sources(const struct scmi_protocol_handle *ph)
93 {
94 struct scmi_mtk_tinysys_info *tinfo = ph->get_priv(ph);
95
96 if (!tinfo)
97 return -EINVAL;
98
99 return tinfo->num_domains;
100 }
101
102 static int scmi_mtk_tinysys_set_notify_enabled(const struct scmi_protocol_handle *ph,
103 u8 evt_id, u32 src_id, bool enable)
104 {
105 struct scmi_mtk_tinysys_pwrst_notify *pwrst_notify;
106 struct scmi_xfer *t;
107 int ret;
108
109 /* There's only one possible event for now */
110 if (evt_id != 0)
111 return -EINVAL;
112
113 ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_POWER_STATE_NOTIFY,
114 sizeof(*pwrst_notify), 0, &t);
115 if (ret)
116 return ret;
117
118 pwrst_notify = t->tx.buf;
> 119 pwrst_notify->fid = src_id;
120 pwrst_notify->enable = cpu_to_le32(enable);
121
122 ret = ph->xops->do_xfer(ph, t);
123 ph->xops->xfer_put(ph, t);
124 return ret;
125 }
126
127 static void *scmi_mtk_tinysys_fill_custom_report(const struct scmi_protocol_handle *ph,
128 u8 evt_id, ktime_t timestamp,
129 const void *payld, size_t payld_sz,
130 void *report, u32 *src_id)
131 {
132 const struct scmi_mtk_tinysys_notify_payld *p = payld;
133 struct scmi_mtk_tinysys_notif_report *r = report;
134 int i;
135
136 if (sizeof(*p) != payld_sz)
137 return NULL;
138
139 if (evt_id == SCMI_EVENT_MTK_TINYSYS_NOTIFIER) {
140 r->timestamp = timestamp;
141 r->fid = le32_to_cpu(p->fid);
142 for (i = 0; i < SCMI_MTK_MSG_NOTIF_ST_BYTES; i++)
143 r->status[i] = le32_to_cpu(p->param[i]);
144 if (src_id)
> 145 *src_id = p->fid;
146 } else {
147 WARN_ON_ONCE(1);
148 return NULL;
149 }
150
151 return r;
152 }
153
154 static const struct scmi_event scmi_mtk_tinysys_events[] = {
155 {
156 .id = SCMI_EVENT_MTK_TINYSYS_NOTIFIER,
157 .max_payld_sz = sizeof(struct scmi_mtk_tinysys_notify_payld),
158 .max_report_sz = sizeof(struct scmi_mtk_tinysys_notif_report),
159 },
160 };
161
162 static int scmi_mtk_tinysys_common_get(const struct scmi_protocol_handle *ph,
163 u32 ctrl_id, u32 cmd,
164 struct scmi_mtk_tinysys_status *retval)
165 {
166 struct scmi_mtk_tinysys_common_get_payld *p;
167 struct scmi_xfer *t;
168 int ret;
169
170 ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_COMMON_GET,
171 sizeof(*p), sizeof(*retval), &t);
172 if (ret)
173 return ret;
174
175 p = t->tx.buf;
> 176 p->param[0] = ctrl_id;
> 177 p->param[1] = cmd;
178
179 ret = ph->xops->do_xfer(ph, t);
180 if (!ret) {
181 if (t->rx.len == sizeof(*retval))
182 memcpy(retval, t->rx.buf, sizeof(*retval));
183 else
184 ret = -EINVAL;
185 }
186
187 ph->xops->xfer_put(ph, t);
188 return ret;
189 }
190
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol
2025-06-23 12:01 ` [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol AngeloGioacchino Del Regno
@ 2025-06-27 10:19 ` Cristian Marussi
2025-06-27 20:14 ` Rob Herring
1 sibling, 0 replies; 12+ messages in thread
From: Cristian Marussi @ 2025-06-27 10:19 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: robh, krzk+dt, conor+dt, matthias.bgg, sudeep.holla,
cristian.marussi, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, arm-scmi, kernel
On Mon, Jun 23, 2025 at 02:01:35PM +0200, AngeloGioacchino Del Regno wrote:
> Add the MediaTek TinySYS SCMI Extension protocol as found on a
> number of SoCs, including MT6895 and MT8196.
>
> This includes controls and power state notifications for the GPU,
> CPU Memory latency Manager (cm_mgr), SLBC, SSPM and others.
>
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
> .../firmware/mediatek,mt6895-scmi.yaml | 22 +++++++++++++++++++
> 1 file changed, 22 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
>
> diff --git a/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml b/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
> new file mode 100644
> index 000000000000..98a5b81983b1
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
> @@ -0,0 +1,22 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +# Copyright 2025 Collabora Ltd
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/firmware/mediatek,mt6895-scmi.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: MediaTek System Control and Management Interface(SCMI) Vendor Protocols Extension
> +
> +maintainers:
> + - AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> +
> +properties:
Can we add some general description too.
Thanks,
Cristian
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support
2025-06-23 12:01 ` [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support AngeloGioacchino Del Regno
` (2 preceding siblings ...)
2025-06-27 8:20 ` kernel test robot
@ 2025-06-27 11:43 ` Cristian Marussi
3 siblings, 0 replies; 12+ messages in thread
From: Cristian Marussi @ 2025-06-27 11:43 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: robh, krzk+dt, conor+dt, matthias.bgg, sudeep.holla,
cristian.marussi, devicetree, linux-kernel, linux-arm-kernel,
linux-mediatek, arm-scmi, kernel
On Mon, Jun 23, 2025 at 02:01:36PM +0200, AngeloGioacchino Del Regno wrote:
> Add a driver for the SCMI protocol extensions for MediaTek TinySYS.
> This is used to communicate with various remote processors in some
> MediaTek SoCs, which mainly handle power management related tasks.
>
Hi,
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
> drivers/firmware/arm_scmi/Kconfig | 1 +
> drivers/firmware/arm_scmi/Makefile | 1 +
> .../arm_scmi/vendors/mediatek/Kconfig | 16 +
> .../arm_scmi/vendors/mediatek/Makefile | 2 +
> .../arm_scmi/vendors/mediatek/mtk-tinysys.c | 344 ++++++++++++++++++
> include/linux/scmi_mtk_protocol.h | 62 ++++
> 6 files changed, 426 insertions(+)
> create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
> create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/Makefile
> create mode 100644 drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
> create mode 100644 include/linux/scmi_mtk_protocol.h
>
> diff --git a/drivers/firmware/arm_scmi/Kconfig b/drivers/firmware/arm_scmi/Kconfig
> index e3fb36825978..baadf4f7fef6 100644
> --- a/drivers/firmware/arm_scmi/Kconfig
> +++ b/drivers/firmware/arm_scmi/Kconfig
> @@ -84,6 +84,7 @@ config ARM_SCMI_QUIRKS
>
> source "drivers/firmware/arm_scmi/transports/Kconfig"
> source "drivers/firmware/arm_scmi/vendors/imx/Kconfig"
> +source "drivers/firmware/arm_scmi/vendors/mediatek/Kconfig"
>
> endif #ARM_SCMI_PROTOCOL
>
> diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile
> index 780cd62b2f78..d1b4ec16b8bc 100644
> --- a/drivers/firmware/arm_scmi/Makefile
> +++ b/drivers/firmware/arm_scmi/Makefile
> @@ -13,6 +13,7 @@ scmi-module-objs := $(scmi-driver-y) $(scmi-protocols-y) $(scmi-transport-y)
>
> obj-$(CONFIG_ARM_SCMI_PROTOCOL) += transports/
> obj-$(CONFIG_ARM_SCMI_PROTOCOL) += vendors/imx/
> +obj-$(CONFIG_ARM_SCMI_PROTOCOL) += vendors/mediatek/
>
> obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-core.o
> obj-$(CONFIG_ARM_SCMI_PROTOCOL) += scmi-module.o
> diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig b/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
> new file mode 100644
> index 000000000000..8facdcd3819f
> --- /dev/null
> +++ b/drivers/firmware/arm_scmi/vendors/mediatek/Kconfig
> @@ -0,0 +1,16 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +menu "ARM SCMI MediaTek Vendor Protocols"
> +
> +config MTK_SCMI_TINYSYS
> + tristate "MediaTek SCMI TinySYS Extension"
> + depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF)
> + default y if ARCH_MEDIATEK
> + help
> + This enables communication with the MediaTek TinySYS MCU
> + to control the power status of various SoC sub-devices
> + other than passing other messages for initialization.
> +
> + To compile this driver as a module, choose M here: the
> + module will be called mtk-tinysys.
> +
> +endmenu
> diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/Makefile b/drivers/firmware/arm_scmi/vendors/mediatek/Makefile
> new file mode 100644
> index 000000000000..dc1ff63c3b69
> --- /dev/null
> +++ b/drivers/firmware/arm_scmi/vendors/mediatek/Makefile
> @@ -0,0 +1,2 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +obj-$(CONFIG_MTK_SCMI_TINYSYS) += mtk-tinysys.o
> diff --git a/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c b/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
> new file mode 100644
> index 000000000000..baeb36493952
> --- /dev/null
> +++ b/drivers/firmware/arm_scmi/vendors/mediatek/mtk-tinysys.c
> @@ -0,0 +1,344 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * System Control and Management Interface (SCMI) MediaTek TinySYS Protocol
> + *
> + * Copyright (c) 2021 MediaTek Inc.
> + * Copyright (c) 2025 Collabora Ltd
> + * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> + */
> +
> +#define pr_fmt(fmt) "SCMI Notifications TinySYS - " fmt
> +
> +#include <linux/bits.h>
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/scmi_protocol.h>
> +#include <linux/scmi_mtk_protocol.h>
> +
> +#include "../../protocols.h"
> +#include "../../notify.h"
> +
> +#define SCMI_MTK_CMD_SSPM_QUERY_ALIVE 0xdead
> +
> +enum scmi_mtk_tinysys_protocol_cmd {
> + MTK_TINYSYS_COMMON_SET = 0x3,
> + MTK_TINYSYS_COMMON_GET = 0x4,
> + MTK_TINYSYS_POWER_STATE_NOTIFY = 0x5,
> + MTK_TINYSYS_SLBC_CTRL = 0x6,
> +};
> +
> +struct scmi_mtk_tinysys_common_get_payld {
> + __le32 rsvd;
> + __le32 param[SCMI_MTK_MSG_COMMON_REPLY_BYTES];
> +};
> +
> +struct scmi_mtk_tinysys_common_set_payld {
> + __le32 rsvd;
> + __le32 ctrl_id;
> + __le32 param[SCMI_MTK_MSG_COMMON_PARAM_BYTES];
> +};
> +
> +struct scmi_mtk_tinysys_slbc_payld {
> + __le32 rsvd;
> + __le32 cmd;
> + __le32 arg[SCMI_MTK_MSG_SLBC_PARAM_BYTES];
> +};
> +
> +struct scmi_mtk_tinysys_pwrst_notify {
> + __le32 rsvd;
> + __le32 fid;
> + __le32 enable;
> +};
> +
> +struct scmi_mtk_tinysys_notify_payld {
> + __le32 fid;
> + __le32 param[SCMI_MTK_MSG_NOTIF_ST_BYTES];
> +};
> +
> +struct scmi_mtk_tinysys_protocol_attributes {
> + __le32 attributes;
...this is a clear example where would be benificial to have a
doc describing the protocol fields (as mentioned already previously) so
that you can at least know here what is the nature of attributes: is it
completely made up of bitfield? has any subfield wider than one-bute
that has to be interpreted as a quantity (so le32_to_cpu and friends...)
..I see all of this is apparent by the code below but a bit of protocol
description would be better...you get my point...
...anyway...you can avoid single field structures in message descriptors...
> +};
> +
> +struct scmi_mtk_tinysys_info {
> + int num_domains;
> +};
> +
> +static int scmi_mtk_tinysys_attributes_get(const struct scmi_protocol_handle *ph,
> + struct scmi_mtk_tinysys_info *tinfo)
> +{
> + struct scmi_mtk_tinysys_protocol_attributes *attr;
> + struct scmi_xfer *t;
> + int ret;
> +
> + ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 0, sizeof(*attr), &t);
> + if (ret)
> + return ret;
> +
> + attr = t->rx.buf;
...especially if you are gonna use down below the get_unaligned_le32()
directly on the buffer at the end....
> +
> + ret = ph->xops->do_xfer(ph, t);
> + if (!ret) {
> + attr->attributes = get_unaligned_le32(t->rx.buf);
..also I think this will make smatch/sparse static analyzers screams
since yiu defined attr_attributes as __le32 BUT here you then assign to
it the u32 which you get out of get_unaligned_le32()
> + tinfo->num_domains = attr->attributes;
...so what about dropping attr struct definitions and declararion and just:
tinfo->num_domains = get_unaligned_le32(t->rx.buf);
> + }
> +
> + ph->xops->xfer_put(ph, t);
> +
> + return ret;
> +}
> +
> +static int scmi_mtk_tinysys_get_num_sources(const struct scmi_protocol_handle *ph)
> +{
> + struct scmi_mtk_tinysys_info *tinfo = ph->get_priv(ph);
> +
> + if (!tinfo)
> + return -EINVAL;
> +
> + return tinfo->num_domains;
> +}
> +
> +static int scmi_mtk_tinysys_set_notify_enabled(const struct scmi_protocol_handle *ph,
> + u8 evt_id, u32 src_id, bool enable)
> +{
> + struct scmi_mtk_tinysys_pwrst_notify *pwrst_notify;
> + struct scmi_xfer *t;
> + int ret;
> +
> + /* There's only one possible event for now */
> + if (evt_id != 0)
As also Peng pointed out...
if (evt != SCMI_EVENT_MTK_TINYSYS_NOTIFIER)
> + return -EINVAL;
> +
> + ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_POWER_STATE_NOTIFY,
> + sizeof(*pwrst_notify), 0, &t);
> + if (ret)
> + return ret;
> +
> + pwrst_notify = t->tx.buf;
> + pwrst_notify->fid = src_id;
... = cpu_to_le32(src_id)
> + pwrst_notify->enable = cpu_to_le32(enable);
...I suppose (since no doc) that this is mant to simply set BIT_0 if
enable....so maybe simply
pwrst_notify->enable = enable ? BIT(0) : 0;
... endianityshould not matter and you risk to set the wrong bit by
using cpu_to_le32()
> +
> + ret = ph->xops->do_xfer(ph, t);
> + ph->xops->xfer_put(ph, t);
> + return ret;
> +}
> +
> +static void *scmi_mtk_tinysys_fill_custom_report(const struct scmi_protocol_handle *ph,
> + u8 evt_id, ktime_t timestamp,
> + const void *payld, size_t payld_sz,
> + void *report, u32 *src_id)
> +{
> + const struct scmi_mtk_tinysys_notify_payld *p = payld;
> + struct scmi_mtk_tinysys_notif_report *r = report;
> + int i;
> +
> + if (sizeof(*p) != payld_sz)
> + return NULL;
> +
> + if (evt_id == SCMI_EVENT_MTK_TINYSYS_NOTIFIER) {
> + r->timestamp = timestamp;
> + r->fid = le32_to_cpu(p->fid);
> + for (i = 0; i < SCMI_MTK_MSG_NOTIF_ST_BYTES; i++)
> + r->status[i] = le32_to_cpu(p->param[i]);
> + if (src_id)
> + *src_id = p->fid;
*src_id = le32_to_cpu(p->fid);
or better
*src_id = r->fid;
> + } else {
> + WARN_ON_ONCE(1);
> + return NULL;
> + }
> +
> + return r;
> +}
> +
> +static const struct scmi_event scmi_mtk_tinysys_events[] = {
> + {
> + .id = SCMI_EVENT_MTK_TINYSYS_NOTIFIER,
> + .max_payld_sz = sizeof(struct scmi_mtk_tinysys_notify_payld),
> + .max_report_sz = sizeof(struct scmi_mtk_tinysys_notif_report),
> + },
> +};
> +
> +static int scmi_mtk_tinysys_common_get(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, u32 cmd,
> + struct scmi_mtk_tinysys_status *retval)
> +{
> + struct scmi_mtk_tinysys_common_get_payld *p;
> + struct scmi_xfer *t;
> + int ret;
> +
> + ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_COMMON_GET,
> + sizeof(*p), sizeof(*retval), &t);
> + if (ret)
> + return ret;
> +
> + p = t->tx.buf;
> + p->param[0] = ctrl_id;
cpu_to_le32(ctrl_id);
> + p->param[1] = cmd;
cpu_to_le32(ctrl_id);
...you should run smatch() or any other Kenel static analyzer ... it
would have screamed a lot around endianity...trivial errors really but
posshbly painful bugs if this ever get run on a BigEndian thing...
> +
> + ret = ph->xops->do_xfer(ph, t);
> + if (!ret) {
> + if (t->rx.len == sizeof(*retval))
> + memcpy(retval, t->rx.buf, sizeof(*retval));
mmmm...so you suddenly have stuff in a reply that is NON-littleEndian
defined in the protocol message fields so that you can brutally memcpy
to a u32 ?
..this would go against basic SCMI (all message fields are LE) and could be
painful since it is really NOT properly defined anywhere what is the expectation
here from the payload received from the server...and again...no docs...
....it would be clearer and safer to define a reply msg as _le32 fields and
just loop and le32_to_cpu() the single __le32 words
> + else
> + ret = -EINVAL;
> + }
> +
> + ph->xops->xfer_put(ph, t);
> + return ret;
> +}
> +
> +static int scmi_mtk_tinysys_common_set(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, const u32 *params,
> + const u8 num_params)
> +{
> + struct scmi_mtk_tinysys_common_set_payld *p;
> + struct scmi_xfer *t;
> + int i, ret;
> +
> + if (!params || num_params > SCMI_MTK_MSG_COMMON_PARAM_BYTES)
> + return -EINVAL;
> +
> + ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_COMMON_SET, sizeof(*p), 0, &t);
> + if (ret)
> + return ret;
> +
> + p = t->tx.buf;
> + p->ctrl_id = cpu_to_le32(ctrl_id);
> + for (i = 0; i < num_params; i++)
> + p->param[i] = cpu_to_le32(params[i]);
> +
> + ret = ph->xops->do_xfer(ph, t);
> +
> + ph->xops->xfer_put(ph, t);
> + return ret;
> +}
> +
> +static int scmi_mtk_tinysys_cm_mgr_set(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, u32 cmd, u32 arg)
> +{
> + const u32 params[2] = { cmd, arg };
> +
> + return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2);
> +}
> +
> +static int scmi_mtk_tinysys_gpu_pwr_set(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, u8 pwr_indication, bool enable)
> +{
> + const u32 params[2] = { pwr_indication, enable };
> +
> + return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2);
> +}
> +
> +static int scmi_mtk_tinysys_slbc_req(const struct scmi_protocol_handle *ph,
> + const struct scmi_mtk_tinysys_slbc *req,
> + struct scmi_mtk_tinysys_slbc *retval)
> +{
> + struct scmi_mtk_tinysys_slbc_payld *p;
> + struct scmi_xfer *t;
> + int i, ret;
> +
> + ret = ph->xops->xfer_get_init(ph, MTK_TINYSYS_SLBC_CTRL,
> + sizeof(*p), sizeof(*p), &t);
> + if (ret)
> + return ret;
> +
> + p = t->tx.buf;
> + p->cmd = cpu_to_le32(req->cmd);
> + for (i = 0; i < SCMI_MTK_MSG_SLBC_PARAM_BYTES; i++)
for (int i = 0;
> + p->arg[i] = cpu_to_le32(req->arg[i]);
> +
> + ret = ph->xops->do_xfer(ph, t);
> + if (!ret && retval) {
> + if (t->rx.len == sizeof(*retval))
> + memcpy(retval, t->rx.buf, sizeof(*retval));
...same as above on endianess of reply payload...did I miss somethinng ?
> + else
> + ret = -EINVAL;
> + }
> +
> + ph->xops->xfer_put(ph, t);
> + return ret;
> +}
> +
> +static int scmi_mtk_tinysys_sspm_mem_set(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, u32 pa, u32 mem_sz)
> +{
> + const u32 params[2] = { pa, mem_sz };
> +
> + if (mem_sz < SZ_1M)
> + return -EINVAL;
> +
> + return scmi_mtk_tinysys_common_set(ph, ctrl_id, params, 2);
> +}
> +
> +static bool scmi_mtk_tinysys_sspm_is_alive(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id)
> +{
> + const u32 param = SCMI_MTK_CMD_SSPM_QUERY_ALIVE;
> + int ret;
> +
> + ret = scmi_mtk_tinysys_common_set(ph, ctrl_id, ¶m, 1);
> +
> + return ret ? false : true;
> +}
> +
> +static const struct scmi_mtk_tinysys_proto_ops mtk_tinysys_proto_ops = {
> + .common_get = scmi_mtk_tinysys_common_get,
> + .cm_mgr_set = scmi_mtk_tinysys_cm_mgr_set,
> + .gpu_pwr_set = scmi_mtk_tinysys_gpu_pwr_set,
> + .slbc_req = scmi_mtk_tinysys_slbc_req,
> + .sspm_is_alive = scmi_mtk_tinysys_sspm_is_alive,
> + .sspm_mem_set = scmi_mtk_tinysys_sspm_mem_set,
> +};
> +
> +static const struct scmi_event_ops scmi_mtk_tinysys_event_ops = {
> + .get_num_sources = scmi_mtk_tinysys_get_num_sources,
> + .set_notify_enabled = scmi_mtk_tinysys_set_notify_enabled,
> + .fill_custom_report = scmi_mtk_tinysys_fill_custom_report,
> +};
I would keep this....
> +
> +static const struct scmi_protocol_events scmi_mtk_tinysys_protocol_events = {
> + .queue_sz = 4 * SCMI_PROTO_QUEUE_SZ,
> + .ops = &scmi_mtk_tinysys_event_ops,
> + .evts = scmi_mtk_tinysys_eventsSCMI_EVENT_MTK_TINYSYS_NOTIFIER,
> + .num_events = ARRAY_SIZE(scmi_mtk_tinysys_events),
> +};
> +
..and all all of these events related stuff above... near where the
protocol events and defs are defined...
> +static int scmi_mtk_tinysys_protocol_init(const struct scmi_protocol_handle *ph)
> +{
> + struct scmi_mtk_tinysys_info *tinfo;
> + u32 version;
> + int ret;
> +
> + ret = ph->xops->version_get(ph, &version);
> + if (ret)
> + return ret;
> +
> + dev_info(ph->dev, "MediaTek TinySYS Protocol Version %d.%d\n",
> + PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
> +
> + tinfo = devm_kzalloc(ph->dev, sizeof(*tinfo), GFP_KERNEL);
> + if (!tinfo)
> + return -ENOMEM;
> +
> + ret = scmi_mtk_tinysys_attributes_get(ph, tinfo);
> + if (ret)
> + return ret;
> +
> + return ph->set_priv(ph, tinfo, version);
> +}
> +
> +static const struct scmi_protocol scmi_mtk_tinysys = {
> + .id = SCMI_PROTOCOL_MTK_TINYSYS,
> + .owner = THIS_MODULE,
> + .instance_init = &scmi_mtk_tinysys_protocol_init,
> + .ops = &mtk_tinysys_proto_ops,
> + .events = &scmi_mtk_tinysys_protocol_events,
> + .vendor_id = SCMI_MTK_VENDOR,
> +};
> +module_scmi_protocol(scmi_mtk_tinysys);
> +
> +MODULE_AUTHOR("AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>");
> +MODULE_ALIAS("scmi-protocol-" __stringify(SCMI_PROTOCOL_MTK_TINYSYS) "-" SCMI_MTK_VENDOR);
> +MODULE_DESCRIPTION("MediaTek SCMI TinySYS driver");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/scmi_mtk_protocol.h b/include/linux/scmi_mtk_protocol.h
> new file mode 100644
> index 000000000000..51ad0cb4b72d
> --- /dev/null
> +++ b/include/linux/scmi_mtk_protocol.h
> @@ -0,0 +1,62 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * SCMI Message Protocol driver MediaTek extension header
> + *
> + * Copyright (c) 2021 MediaTek Inc.
> + * Copyright (c) 2025 Collabora Ltd
> + * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> + */
> +
> +#ifndef _LINUX_SCMI_MTK_PROTOCOL_H
> +#define _LINUX_SCMI_MTK_PROTOCOL_H
> +
> +#include <linux/bitfield.h>
> +#include <linux/device.h>
> +#include <linux/notifier.h>
> +#include <linux/types.h>
> +
> +#define SCMI_PROTOCOL_MTK_TINYSYS 0x80
> +#define SCMI_MTK_VENDOR "MediaTek"
> +
> +#define SCMI_MTK_MSG_COMMON_PARAM_BYTES 5
This definition can go into the protocol compilation unit, since it is
NOT used by the SCMI drivers using the ops below, right ? ... I mean
it's an internal define so no need to expose it here..
> +#define SCMI_MTK_MSG_COMMON_REPLY_BYTES 2
> +#define SCMI_MTK_MSG_NOTIF_ST_BYTES 4
> +#define SCMI_MTK_MSG_SLBC_PARAM_BYTES 4
> +
> +struct scmi_mtk_tinysys_status {
> + u32 rsvd;
> + u32 reply[SCMI_MTK_MSG_COMMON_REPLY_BYTES];
> +};
> +
> +struct scmi_mtk_tinysys_slbc {
> + u32 cmd;
> + u32 arg[SCMI_MTK_MSG_SLBC_PARAM_BYTES];
> +};
> +
> +struct scmi_mtk_tinysys_proto_ops {
> + int (*common_get)(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, u32 cmd,
> + struct scmi_mtk_tinysys_status *retval);
> + int (*cm_mgr_set)(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, u32 cmd, u32 arg);
> + int (*gpu_pwr_set)(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, u8 pwr_indication, bool enable);
> + int (*slbc_req)(const struct scmi_protocol_handle *ph,
> + const struct scmi_mtk_tinysys_slbc *req,
> + struct scmi_mtk_tinysys_slbc *retval);
> + bool (*sspm_is_alive)(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id);
> + int (*sspm_mem_set)(const struct scmi_protocol_handle *ph,
> + u32 ctrl_id, u32 pa, u32 mem_sz);
> +};
You could add some Doxy-style comments for these ops...NO strong
opinion here, though, since other vendor protos do NOT have it...
...much more important is to add the the protocol .rst docs detailing
the message format (...you may have guessed at this point that I would
have reiterated this :P)
Thanks,
Cristian
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol
2025-06-23 12:01 ` [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol AngeloGioacchino Del Regno
2025-06-27 10:19 ` Cristian Marussi
@ 2025-06-27 20:14 ` Rob Herring
1 sibling, 0 replies; 12+ messages in thread
From: Rob Herring @ 2025-06-27 20:14 UTC (permalink / raw)
To: AngeloGioacchino Del Regno
Cc: krzk+dt, conor+dt, matthias.bgg, sudeep.holla, cristian.marussi,
devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
arm-scmi, kernel
On Mon, Jun 23, 2025 at 02:01:35PM +0200, AngeloGioacchino Del Regno wrote:
> Add the MediaTek TinySYS SCMI Extension protocol as found on a
> number of SoCs, including MT6895 and MT8196.
>
> This includes controls and power state notifications for the GPU,
> CPU Memory latency Manager (cm_mgr), SLBC, SSPM and others.
>
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
> .../firmware/mediatek,mt6895-scmi.yaml | 22 +++++++++++++++++++
> 1 file changed, 22 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
>
> diff --git a/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml b/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
> new file mode 100644
> index 000000000000..98a5b81983b1
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/firmware/mediatek,mt6895-scmi.yaml
> @@ -0,0 +1,22 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +# Copyright 2025 Collabora Ltd
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/firmware/mediatek,mt6895-scmi.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: MediaTek System Control and Management Interface(SCMI) Vendor Protocols Extension
> +
> +maintainers:
> + - AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> +
This schema will never be applied.
> +properties:
> + protocol@80:
> + $ref: '/schemas/firmware/arm,scmi.yaml#/$defs/protocol-node'
> + unevaluatedProperties: false
> +
> + properties:
> + reg:
> + const: 0x80
> +
> +additionalProperties: true
> --
> 2.49.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-06-27 20:14 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-23 12:01 [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol AngeloGioacchino Del Regno
2025-06-23 12:01 ` [PATCH v1 1/2] dt-bindings: firmware: Add MediaTek TinySYS SCMI Extension protocol AngeloGioacchino Del Regno
2025-06-27 10:19 ` Cristian Marussi
2025-06-27 20:14 ` Rob Herring
2025-06-23 12:01 ` [PATCH v1 2/2] firmware: arm_scmi: Add MediaTek TinySYS SCMI Protocol support AngeloGioacchino Del Regno
2025-06-23 12:16 ` Sudeep Holla
2025-06-24 3:01 ` Peng Fan
2025-06-27 8:20 ` kernel test robot
2025-06-27 11:43 ` Cristian Marussi
2025-06-23 12:17 ` [PATCH v1 0/2] firmware: Add MediaTek TinySYS SCMI Protocol Cristian Marussi
2025-06-23 12:32 ` AngeloGioacchino Del Regno
2025-06-23 13:30 ` Cristian Marussi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).