* [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196
@ 2026-11-25 6:00 Echo Zhang
2026-11-25 6:00 ` [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs Echo Zhang
` (6 more replies)
0 siblings, 7 replies; 18+ messages in thread
From: Echo Zhang @ 2026-11-25 6:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
This series adds support for the MediaTek Multimedia Dynamic Voltage and
Frequency Scaling (MMDVFS) controller on MT8196. The controller provides
virtual clocks for multimedia hardware blocks and coordinates their
performance requests with platform voltage resources. The driver
aggregates consumer rate requests and programs the MT8196 hardware clock
control fabric (HWCCF) voter. Its VCP/MMUP backend coordinates shared
memory and IPI communication with firmware.
The series introduces the clock IDs and device tree bindings, followed by
the common clock provider, VCP backend and MT8196 topology and voting
data. It also adds a read-only debugfs status view and a MAINTAINERS entry.
This series depends on Xiangzhi Tang's MediaTek VCP remoteproc series,
which provides the public VCP API used by MMDVFS:
https://lore.kernel.org/r/20260427111446.22955-1-xiangzhi.tang@mediatek.com
Patch layout:
1/7: Define the MT8196 MMDVFS clock IDs used by DT consumers.
2/7: Document the common MMDVFS and MT8196 DT bindings.
3/7: Add the common driver, virtual clock provider and vote handling.
4/7: Add the VCP/MMUP shared-memory and IPI backend.
5/7: Add MT8196 topology data and HWCCF voting operations.
6/7: Add a read-only debugfs status view.
7/7: Add the MMDVFS files and contacts to MAINTAINERS.
Validation: the two MMDVFS bindings passed dt_binding_check. Each driver
commit built cumulatively with arm64 Clang on top of the VCP dependency.
The production changes were also ported to the MT8196 sapphire validation
tree, retaining its older VCP API compatibility and separate internal test
hooks. Its full package build and board boot passed. The status interface
reported initialization with three resource controllers, seven muxes. The
user, vote_step and force_step test completed with zero functional failures;
Echo Zhang (7):
dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs
dt-bindings: soc: mediatek: add MMDVFS binding
soc: mediatek: add MMDVFS core driver
soc: mediatek: mmdvfs: add VCP backend
soc: mediatek: mmdvfs: add MT8196 support
soc: mediatek: mmdvfs: add read-only status debug
MAINTAINERS: add MediaTek MMDVFS entry
.../soc/mediatek/mediatek,mmdvfs.yaml | 60 +
.../soc/mediatek/mediatek,mt8196-mmdvfs.yaml | 87 ++
MAINTAINERS | 11 +
drivers/soc/mediatek/Kconfig | 19 +
drivers/soc/mediatek/Makefile | 1 +
drivers/soc/mediatek/mmdvfs/Makefile | 10 +
drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c | 447 +++++++
drivers/soc/mediatek/mmdvfs/mmdvfs-core.c | 651 ++++++++++
drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c | 200 +++
drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h | 361 ++++++
drivers/soc/mediatek/mmdvfs/mmdvfs-mt8196.c | 637 ++++++++++
drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h | 57 +
drivers/soc/mediatek/mmdvfs/mmdvfs-up.c | 275 +++++
.../soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h | 104 ++
drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c | 1075 +++++++++++++++++
.../clock/mediatek,mt8196-mmdvfs.h | 74 ++
include/soc/mediatek/mmdvfs.h | 90 ++
17 files changed, 4159 insertions(+)
create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml
create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
create mode 100644 drivers/soc/mediatek/mmdvfs/Makefile
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-mt8196.c
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-up.c
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c
create mode 100644 include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h
create mode 100644 include/soc/mediatek/mmdvfs.h
--
2.45.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs
2026-11-25 6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
@ 2026-11-25 6:00 ` Echo Zhang
2026-11-25 10:55 ` Krzysztof Kozlowski
2026-11-25 6:00 ` [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding Echo Zhang
` (5 subsequent siblings)
6 siblings, 1 reply; 18+ messages in thread
From: Echo Zhang @ 2026-11-25 6:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
Add clock IDs for the MT8196 MMDVFS clock provider.
These IDs describe the clocks exposed by the MMDVFS block and are used by
device tree consumers to request multimedia performance levels through the
standard clock framework.
Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
---
.../clock/mediatek,mt8196-mmdvfs.h | 74 +++++++++++++++++++
1 file changed, 74 insertions(+)
create mode 100644 include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h
diff --git a/include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h b/include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h
new file mode 100644
index 000000000000..428d8a35abdb
--- /dev/null
+++ b/include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h
@@ -0,0 +1,74 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+/*
+ * Copyright (c) 2024 MediaTek Inc.
+ * Author: MediaTek MMDVFS Team
+ */
+
+#ifndef _DT_BINDINGS_MMDVFS_CLK_MT8196_H
+#define _DT_BINDINGS_MMDVFS_CLK_MT8196_H
+
+/*
+ * MMDVFS Clock IDs for MT8196
+ *
+ * These IDs are used by multimedia clients in device tree to reference
+ * MMDVFS virtual clocks for DVFS voting.
+ *
+ * MT8196 uses HWCCF (Hardware Clock Control Fabric) architecture.
+ *
+ * Usage in device tree:
+ * clocks = <&mmdvfs MMDVFS_USER_VDEC>;
+ * clock-names = "mmdvfs";
+ */
+
+/* Core user clocks used by multimedia hardware drivers */
+#define MMDVFS_USER_DISP 0 /* user-disp */
+#define MMDVFS_USER_MDP 1 /* user-mdp */
+#define MMDVFS_USER_MML 2 /* user-mml */
+#define MMDVFS_USER_SMI 3 /* user-smi */
+#define MMDVFS_USER_JPEGDEC 4 /* user-jpegdec */
+#define MMDVFS_USER_JPEGENC 5 /* user-jpegenc */
+#define MMDVFS_USER_VENC 6 /* user-venc */
+#define MMDVFS_USER_VFMT 7 /* user-vfmt */
+#define MMDVFS_USER_IMG 8 /* user-img */
+#define MMDVFS_USER_CAM 9 /* user-cam */
+#define MMDVFS_USER_VCORE 10 /* user-vcore */
+#define MMDVFS_USER_VMM 11 /* user-vmm */
+#define MMDVFS_USER_VDISP 12 /* user-vdisp */
+#define MMDVFS_USER_VDEC 13 /* user-vdec */
+#define DUMMY_USER_DIS 14 /* dummy-dis */
+#define DUMMY_USER_MDP 15 /* dummy-mdp */
+#define DUMMY_USER_MML 16 /* dummy-mml */
+#define DUMMY_USER_SMI 17 /* dummy-smi */
+#define DUMMY_USER_VEN 18 /* dummy-ven */
+#define DUMMY_USER_VDE 19 /* dummy-vde */
+#define DUMMY_USER_IMG 20 /* dummy-img */
+#define DUMMY_USER_CAM 21 /* dummy-cam */
+#define MMDVFS_USER_CAM_SMI 22 /* user-cam-smi */
+#define MMDVFS_USER_VCP_SMI 23 /* user-vcp-smi */
+
+/* AP voter clocks (24-33) - System level control */
+#define MMDVFS_AP_CAM 24
+#define MMDVFS_AP_CAMTM 25
+#define MMDVFS_AP_VDE 26
+#define MMDVFS_AP_IMG 27
+#define MMDVFS_AP_IPE 28
+#define MMDVFS_AP_DIS 29
+#define MMDVFS_AP_MML 30
+#define MMDVFS_AP_SMI 31
+#define MMDVFS_AP_VEN 32
+#define MMDVFS_AP_MDP 33
+
+/* VCP voter clocks (34-43) - VCP firmware control */
+#define MMDVFS_VCP_CAM 34
+#define MMDVFS_VCP_CAMTM 35
+#define MMDVFS_VCP_VDE 36
+#define MMDVFS_VCP_IMG 37
+#define MMDVFS_VCP_IPE 38
+#define MMDVFS_VCP_DIS 39
+#define MMDVFS_VCP_MML 40
+#define MMDVFS_VCP_SMI 41
+#define MMDVFS_VCP_VEN 42
+#define MMDVFS_VCP_MDP 43
+
+#define MMDVFS_USER_NUM 44
+#endif /* _DT_BINDINGS_MMDVFS_CLK_MT8196_H */
--
2.45.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding
2026-11-25 6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
2026-11-25 6:00 ` [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs Echo Zhang
@ 2026-11-25 6:00 ` Echo Zhang
2026-11-25 8:32 ` Roman Vivchar
` (2 more replies)
2026-11-25 6:00 ` [PATCH 3/7] soc: mediatek: add MMDVFS core driver Echo Zhang
` (4 subsequent siblings)
6 siblings, 3 replies; 18+ messages in thread
From: Echo Zhang @ 2026-11-25 6:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
Describe the MMDVFS clock provider and its connection to VCP firmware
in a common binding. Document the optional MMUP shared memory and IPI
settings used by the firmware backend.
Add an MT8196 binding for the HWCCF syscon and seven mux OPP tables so
the driver can map clock rate requests to hardware votes.
Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
---
.../soc/mediatek/mediatek,mmdvfs.yaml | 60 +++++++++++++
.../soc/mediatek/mediatek,mt8196-mmdvfs.yaml | 87 +++++++++++++++++++
2 files changed, 147 insertions(+)
create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml
create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
diff --git a/Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml
new file mode 100644
index 000000000000..d65f4c9084cc
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml
@@ -0,0 +1,60 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/mediatek/mediatek,mmdvfs.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek Multimedia Dynamic Voltage and Frequency Scaling (MMDVFS)
+
+maintainers:
+ - MediaTek MMDVFS Team <linux-mediatek@lists.infradead.org>
+
+description:
+ MediaTek MMDVFS provides dynamic voltage and frequency scaling for multimedia
+ hardware accelerators. The controller exposes virtual clocks that multimedia
+ consumers use through the common clock framework. The driver aggregates
+ consumer rate requests and sends the resulting DVFS votes to the multimedia
+ hardware voter and VCP firmware.
+
+select: false
+
+properties:
+ mediatek,vcp:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Phandle to the MediaTek VCP remote processor used for MMDVFS shared
+ memory, feature registration, notifier, and IPI operations.
+
+ mediatek,mmup-sram:
+ type: boolean
+ description:
+ Use the MMUP SRAM window for MMDVFS callback records and status data.
+
+ mediatek,mmup-enable:
+ type: boolean
+ description:
+ Enable the MMUP path for MMDVFS shared memory and IPI handling.
+
+ mediatek,vcp-ipi-id:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ VCP IPI channel id for MMDVFS. If omitted, the driver uses the platform
+ default.
+
+ mediatek,mmup-ipi-id:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ MMUP IPI channel id for MMDVFS. If omitted, the driver uses the platform
+ default.
+
+ "#clock-cells":
+ const: 1
+ description:
+ MMDVFS clock specifier. Consumers pass an SoC-specific MMDVFS clock
+ index.
+
+required:
+ - mediatek,vcp
+ - "#clock-cells"
+
+additionalProperties: true
diff --git a/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
new file mode 100644
index 000000000000..13381c78dbd1
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
@@ -0,0 +1,87 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/soc/mediatek/mediatek,mt8196-mmdvfs.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek MT8196 Multimedia Dynamic Voltage and Frequency Scaling
+
+maintainers:
+ - MediaTek MMDVFS Team <linux-mediatek@lists.infradead.org>
+
+allOf:
+ - $ref: mediatek,mmdvfs.yaml#
+
+select:
+ properties:
+ compatible:
+ contains:
+ enum:
+ - mediatek,mt8196-mmdvfs
+ required:
+ - compatible
+
+properties:
+ compatible:
+ enum:
+ - mediatek,mt8196-mmdvfs
+
+ mediatek,hwccf:
+ $ref: /schemas/types.yaml#/definitions/phandle
+ description:
+ Phandle to the MT8196 multimedia hardware clock control fabric syscon
+ used for AP-side hardware votes.
+
+ mediatek,mux-opp-tables:
+ $ref: /schemas/types.yaml#/definitions/phandle-array
+ minItems: 7
+ maxItems: 7
+ description: |
+ OPP tables for the seven MT8196 MMDVFS muxes, in this order:
+ display, MDP, SMI, VENC, VDEC, IMG, CAM. MDP and MML share
+ the MDP mux. Each OPP entry must have opp-hz and opp-level.
+
+required:
+ - compatible
+ - mediatek,hwccf
+ - mediatek,mux-opp-tables
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/clock/mediatek,mt8196-mmdvfs.h>
+
+ soc {
+ #address-cells = <2>;
+ #size-cells = <2>;
+
+ vcp: remoteproc@31800000 {
+ compatible = "mediatek,mt8196-vcp";
+ reg = <0 0x31800000 0 0x100000>;
+ };
+
+ mm_hwv: syscon@31b00000 {
+ compatible = "mediatek,mt8196-mm-hwv", "syscon";
+ reg = <0 0x31b00000 0 0x6000>;
+ };
+
+ mmdvfs_opp: opp-table {
+ compatible = "operating-points-v2";
+ opp-0 {
+ opp-hz = /bits/ 64 <100000000>;
+ opp-level = <0>;
+ };
+ };
+
+ mmdvfs: mmdvfs-mux {
+ compatible = "mediatek,mt8196-mmdvfs";
+ mediatek,vcp = <&vcp>;
+ mediatek,hwccf = <&mm_hwv>;
+ mediatek,mux-opp-tables = <&mmdvfs_opp>, <&mmdvfs_opp>,
+ <&mmdvfs_opp>, <&mmdvfs_opp>,
+ <&mmdvfs_opp>, <&mmdvfs_opp>,
+ <&mmdvfs_opp>;
+ #clock-cells = <1>;
+ };
+ };
--
2.45.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 3/7] soc: mediatek: add MMDVFS core driver
2026-11-25 6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
2026-11-25 6:00 ` [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs Echo Zhang
2026-11-25 6:00 ` [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding Echo Zhang
@ 2026-11-25 6:00 ` Echo Zhang
2026-11-25 8:35 ` Roman Vivchar
2026-11-25 10:54 ` Krzysztof Kozlowski
2026-11-25 6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
` (3 subsequent siblings)
6 siblings, 2 replies; 18+ messages in thread
From: Echo Zhang @ 2026-11-25 6:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
Add the common MediaTek MMDVFS driver framework.
The core driver handles device probing, SoC data selection, clock provider
registration, power-management notification, and dispatch to the
microprocessor transport used for runtime performance voting.
Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
---
drivers/soc/mediatek/Kconfig | 19 +
drivers/soc/mediatek/Makefile | 1 +
drivers/soc/mediatek/mmdvfs/Makefile | 6 +
drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c | 462 ++++++++++++++
drivers/soc/mediatek/mmdvfs/mmdvfs-core.c | 581 ++++++++++++++++++
drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h | 305 +++++++++
include/soc/mediatek/mmdvfs.h | 72 +++
7 files changed, 1446 insertions(+)
create mode 100644 drivers/soc/mediatek/mmdvfs/Makefile
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
create mode 100644 include/soc/mediatek/mmdvfs.h
diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig
index d7293977f06e..bb273a4461f0 100644
--- a/drivers/soc/mediatek/Kconfig
+++ b/drivers/soc/mediatek/Kconfig
@@ -60,6 +60,25 @@ config MTK_REGULATOR_COUPLER
default ARCH_MEDIATEK
depends on REGULATOR
+config MTK_MMDVFS
+ tristate "MediaTek MMDVFS support"
+ depends on ARCH_MEDIATEK || COMPILE_TEST
+ depends on MTK_VCP_RPROC
+ help
+ Say yes here to add support for the MediaTek Multimedia Dynamic
+ Voltage and Frequency Scaling controller. The controller provides
+ virtual clocks for multimedia hardware blocks and coordinates
+ performance votes with platform voltage resources.
+
+config MTK_MMDVFS_MT8196
+ bool "MediaTek MT8196 MMDVFS support"
+ depends on MTK_MMDVFS
+ help
+ Enable MMDVFS support for the MediaTek MT8196 platform.
+ This adds the MT8196 multimedia clock voter topology and
+ hardware voter operations used by the common MMDVFS driver.
+ Select this option only on MT8196 based systems.
+
config MTK_MMSYS
tristate "MediaTek MMSYS Support"
default ARCH_MEDIATEK
diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile
index 0665573e3c4b..f54ee4e2775c 100644
--- a/drivers/soc/mediatek/Makefile
+++ b/drivers/soc/mediatek/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_MTK_DVFSRC) += mtk-dvfsrc.o
obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o
obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
obj-$(CONFIG_MTK_REGULATOR_COUPLER) += mtk-regulator-coupler.o
+obj-$(CONFIG_MTK_MMDVFS) += mmdvfs/
obj-$(CONFIG_MTK_MMSYS) += mtk-mmsys.o
obj-$(CONFIG_MTK_MMSYS) += mtk-mutex.o
obj-$(CONFIG_MTK_SVS) += mtk-svs.o
diff --git a/drivers/soc/mediatek/mmdvfs/Makefile b/drivers/soc/mediatek/mmdvfs/Makefile
new file mode 100644
index 000000000000..33a280827006
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_MTK_MMDVFS) += mtk-mmdvfs.o
+
+mtk-mmdvfs-y += mmdvfs-core.o
+mtk-mmdvfs-y += mmdvfs-clk.o
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
new file mode 100644
index 000000000000..114f3148cf46
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
@@ -0,0 +1,462 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ *
+ * MediaTek MMDVFS Clock Provider
+ */
+
+#include <linux/clk.h>
+#include <linux/clk-provider.h>
+#include <linux/clkdev.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/property.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include "mmdvfs-internal.h"
+
+/* clkdev uses a 16-byte con_id buffer, including the trailing NUL. */
+#define MMDVFS_CLKDEV_CON_ID_MAX 16
+
+static const char *mmdvfs_get_clkdev_name(const char *name, char *buf, size_t size)
+{
+ if (strlen(name) < MMDVFS_CLKDEV_CON_ID_MAX)
+ return name;
+
+ return NULL;
+}
+
+/*
+ * mmdvfs_set_rate - Set operating frequency for a multimedia clock
+ * @hw: Clock hardware handle
+ * @rate: Requested frequency in Hz
+ * @parent_rate: Parent clock frequency (unused)
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+static int mmdvfs_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+ struct mmdvfs_user *user = to_mmdvfs_user(hw);
+ struct mmdvfs_device *mmdvfs;
+ struct mmdvfs_data *data;
+ struct mmdvfs_mux *mux;
+ struct mmdvfs_rc *rc;
+ u8 level = 0;
+ int i, ret = 0;
+
+ if (!user) {
+ pr_err("mmdvfs: Invalid user reference\n");
+ return -EINVAL;
+ }
+
+ mmdvfs = user->mmdvfs;
+ if (!mmdvfs || !mmdvfs->data) {
+ pr_err("mmdvfs: Invalid device reference for user %s\n",
+ user->name ?: "unknown");
+ return -EINVAL;
+ }
+
+ data = mmdvfs->data;
+
+ if (!data->init_done)
+ return -EPROBE_DEFER;
+
+ if (!mmdvfs_is_valid_user_id(user->id) ||
+ !mmdvfs_is_valid_mux_id(user->mux)) {
+ mmdvfs_err(mmdvfs->dev, "Invalid user config: id=%d, mux=%d\n",
+ user->id, user->mux);
+ return -EINVAL;
+ }
+
+ if (rate == 0) {
+ mmdvfs_dbg(mmdvfs->dev, "Zero rate request for user %s\n",
+ user->name);
+ return 0;
+ }
+
+ mux = &data->mux[user->mux];
+ if (!mmdvfs_is_valid_rc_id(mux->rc)) {
+ mmdvfs_err(mmdvfs->dev, "Invalid mux config: rc=%d for user %s\n",
+ mux->rc, user->name);
+ return -EINVAL;
+ }
+
+ rc = &data->rc[mux->rc];
+ if (rc->level_num == 0 || rc->level_num > MMDVFS_MAX_LEVELS) {
+ mmdvfs_err(mmdvfs->dev, "Invalid RC level_num=%d for user %s\n",
+ rc->level_num, user->name);
+ return -EINVAL;
+ }
+
+ if (mux->freq_num == 0 || mux->freq_num > MMDVFS_MAX_LEVELS) {
+ mmdvfs_err(mmdvfs->dev, "Invalid MUX freq_num=%d for user %s\n",
+ mux->freq_num, user->name);
+ return -EINVAL;
+ }
+
+ for (i = 0; i < mux->freq_num && i < MMDVFS_MAX_LEVELS; i++) {
+ if (rate <= mux->freq[i]) {
+ level = i;
+ break;
+ }
+ }
+
+ if (i == mux->freq_num)
+ level = mux->freq_num - 1;
+
+ if (!mmdvfs_is_valid_level(level)) {
+ mmdvfs_err(mmdvfs->dev, "Invalid level=%d for rate=%lu, user=%s\n",
+ level, rate, user->name);
+ return -EINVAL;
+ }
+
+ if (user->level == level) {
+ mmdvfs_dbg(mmdvfs->dev, "user %s: already at level %d, skip\n",
+ user->name, level);
+ return 0;
+ }
+
+ mmdvfs_dbg(mmdvfs->dev, "user %s: rate %lu -> level %d (freq=%llu)\n",
+ user->name, rate, level, mux->freq[level]);
+
+ mutex_lock(&mux->lock);
+
+ if (data->ops && data->ops->hw_vote) {
+ ret = data->ops->hw_vote(mmdvfs, user->id, level);
+ if (!ret) {
+ user->level = level;
+ mmdvfs_dbg(mmdvfs->dev,
+ "Hardware vote successful for user %s\n",
+ user->name);
+ } else {
+ mmdvfs_err(mmdvfs->dev,
+ "Hardware vote failed for user %s: %d\n",
+ user->name, ret);
+ }
+ } else {
+ mmdvfs_err(mmdvfs->dev,
+ "Hardware voting mechanism not implemented\n");
+ ret = -EOPNOTSUPP;
+ }
+
+ mutex_unlock(&mux->lock);
+
+ return ret;
+}
+
+/*
+ * mmdvfs_recalc_rate - Recalculate current operating frequency
+ * @hw: Clock hardware handle
+ * @parent_rate: Parent clock frequency (unused)
+ *
+ * Return: Current frequency in Hz, or 0 on error
+ */
+static unsigned long mmdvfs_recalc_rate(struct clk_hw *hw,
+ unsigned long parent_rate)
+{
+ struct mmdvfs_user *user = to_mmdvfs_user(hw);
+ struct mmdvfs_device *mmdvfs;
+ struct mmdvfs_data *data;
+ struct mmdvfs_mux *mux;
+
+ if (!user) {
+ pr_err("mmdvfs: Invalid user reference in recalc_rate\n");
+ return 0;
+ }
+
+ mmdvfs = user->mmdvfs;
+ if (!mmdvfs || !mmdvfs->data) {
+ pr_err("mmdvfs: Invalid device reference for user %s in recalc_rate\n",
+ user->name ?: "unknown");
+ return 0;
+ }
+
+ data = mmdvfs->data;
+
+ if (!mmdvfs_is_valid_user_id(user->id) ||
+ !mmdvfs_is_valid_mux_id(user->mux)) {
+ mmdvfs_err(mmdvfs->dev, "Invalid user config in recalc_rate\n");
+ return 0;
+ }
+
+ if (!mmdvfs_is_valid_level(user->level)) {
+ mmdvfs_err(mmdvfs->dev,
+ "Invalid level=%d for user=%s in recalc_rate\n",
+ user->level, user->name);
+ return 0;
+ }
+
+ mux = &data->mux[user->mux];
+
+ return mux->freq[user->level];
+}
+
+/*
+ * mmdvfs_round_rate - Round requested frequency to supported value
+ * @hw: Clock hardware handle
+ * @rate: Requested frequency in Hz
+ * @parent_rate: Parent clock frequency (unused, may be NULL)
+ *
+ * Return: Rounded frequency in Hz, or negative error code
+ */
+static long mmdvfs_round_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long *parent_rate)
+{
+ struct mmdvfs_user *user = to_mmdvfs_user(hw);
+ struct mmdvfs_device *mmdvfs;
+ struct mmdvfs_data *data;
+ struct mmdvfs_mux *mux;
+ struct mmdvfs_rc *rc;
+ int i;
+
+ if (!user) {
+ pr_err("mmdvfs: Invalid user reference in round_rate\n");
+ return -EINVAL;
+ }
+
+ mmdvfs = user->mmdvfs;
+ if (!mmdvfs || !mmdvfs->data) {
+ pr_err("mmdvfs: Invalid device reference for user %s in round_rate\n",
+ user->name ?: "unknown");
+ return -EINVAL;
+ }
+
+ data = mmdvfs->data;
+
+ if (!mmdvfs_is_valid_user_id(user->id) ||
+ !mmdvfs_is_valid_mux_id(user->mux)) {
+ mmdvfs_err(mmdvfs->dev, "Invalid user config in round_rate\n");
+ return -EINVAL;
+ }
+
+ if (rate == 0) {
+ mmdvfs_dbg(mmdvfs->dev,
+ "Zero rate request in round_rate for user %s\n",
+ user->name);
+ return 0;
+ }
+
+ mux = &data->mux[user->mux];
+ if (!mmdvfs_is_valid_rc_id(mux->rc)) {
+ mmdvfs_err(mmdvfs->dev,
+ "Invalid mux config in round_rate\n");
+ return -EINVAL;
+ }
+
+ rc = &data->rc[mux->rc];
+ if (rc->level_num == 0 || rc->level_num > MMDVFS_MAX_LEVELS) {
+ mmdvfs_err(mmdvfs->dev,
+ "Invalid RC level_num in round_rate\n");
+ return -EINVAL;
+ }
+
+ if (mux->freq_num == 0 || mux->freq_num > MMDVFS_MAX_LEVELS) {
+ mmdvfs_err(mmdvfs->dev,
+ "Invalid MUX freq_num in round_rate\n");
+ return -EINVAL;
+ }
+
+ for (i = 0; i < mux->freq_num && i < MMDVFS_MAX_LEVELS; i++) {
+ if (rate <= mux->freq[i]) {
+ mmdvfs_dbg(mmdvfs->dev,
+ "round_rate: user %s, rate %lu -> %llu\n",
+ user->name, rate, mux->freq[i]);
+ return mux->freq[i];
+ }
+ }
+
+ if (mux->freq_num > 0) {
+ unsigned long max_freq = mux->freq[mux->freq_num - 1];
+
+ mmdvfs_dbg(mmdvfs->dev,
+ "round_rate: user %s, rate %lu -> %lu (max)\n",
+ user->name, rate, max_freq);
+ return max_freq;
+ }
+
+ return -EINVAL;
+}
+
+static int mmdvfs_determine_rate(struct clk_hw *hw, struct clk_rate_request *req)
+{
+ long rate;
+
+ rate = mmdvfs_round_rate(hw, req->rate, &req->best_parent_rate);
+ if (rate < 0)
+ return rate;
+
+ req->rate = rate;
+
+ return 0;
+}
+
+static const struct clk_ops mmdvfs_req_ops = {
+ .set_rate = mmdvfs_set_rate,
+ .determine_rate = mmdvfs_determine_rate,
+ .recalc_rate = mmdvfs_recalc_rate,
+};
+
+/*
+ * mmdvfs_register_clocks - Register clock providers for MMDVFS
+ * @mmdvfs: MMDVFS device structure
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+int mmdvfs_register_clocks(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_data *data;
+ struct clk_init_data init = {};
+ int i, ret;
+
+ if (!mmdvfs || !mmdvfs->dev) {
+ pr_err("mmdvfs: Invalid device reference in register_clocks\n");
+ return -EINVAL;
+ }
+
+ data = mmdvfs->data;
+ if (!data) {
+ mmdvfs_err(mmdvfs->dev,
+ "Invalid data reference in register_clocks\n");
+ return -EINVAL;
+ }
+
+ if (data->user_num == 0 || data->user_num > MMDVFS_MAX_USERS) {
+ mmdvfs_err(mmdvfs->dev, "Invalid user count: %d (max: %d)\n",
+ data->user_num, MMDVFS_MAX_USERS);
+ return -EINVAL;
+ }
+
+ if (!data->user) {
+ mmdvfs_err(mmdvfs->dev, "User array not allocated\n");
+ return -EINVAL;
+ }
+
+ mmdvfs->clk_data = devm_kzalloc(mmdvfs->dev,
+ struct_size(mmdvfs->clk_data, hws,
+ data->user_num),
+ GFP_KERNEL);
+ if (!mmdvfs->clk_data) {
+ mmdvfs_err(mmdvfs->dev,
+ "Failed to allocate clock data structure\n");
+ return -ENOMEM;
+ }
+
+ mmdvfs->clk_data->num = data->user_num;
+
+ for (i = 0; i < data->user_num; i++) {
+ struct mmdvfs_user *user = &data->user[i];
+ char clkdev_name[MMDVFS_CLKDEV_CON_ID_MAX];
+ const char *con_id;
+
+ if (!user) {
+ mmdvfs_err(mmdvfs->dev, "User %d is NULL\n", i);
+ ret = -EINVAL;
+ goto cleanup_clocks;
+ }
+
+ user->mmdvfs = mmdvfs;
+
+ if (!user->name || strlen(user->name) == 0) {
+ mmdvfs_err(mmdvfs->dev, "User %d has invalid name\n",
+ i);
+ ret = -EINVAL;
+ goto cleanup_clocks;
+ }
+
+ if (!mmdvfs_is_valid_user_id(user->id) ||
+ !mmdvfs_is_valid_mux_id(user->mux)) {
+ mmdvfs_err(mmdvfs->dev,
+ "Invalid user config: name=%s, id=%d, mux=%d\n",
+ user->name, user->id, user->mux);
+ ret = -EINVAL;
+ goto cleanup_clocks;
+ }
+
+ if (user->mux >= data->mux_num || !data->mux) {
+ mmdvfs_err(mmdvfs->dev,
+ "User %s references invalid mux %d (max: %d)\n",
+ user->name, user->mux, data->mux_num);
+ ret = -EINVAL;
+ goto cleanup_clocks;
+ }
+
+ memset(&init, 0, sizeof(init));
+ init.name = user->name;
+ init.ops = &mmdvfs_req_ops;
+ init.flags = CLK_GET_RATE_NOCACHE;
+ init.num_parents = 0;
+ init.parent_names = NULL;
+
+ user->clk_hw.init = &init;
+
+ ret = devm_clk_hw_register(mmdvfs->dev, &user->clk_hw);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev,
+ "Failed to register clock %s (user %d): %d\n",
+ user->name, i, ret);
+ goto cleanup_clocks;
+ }
+
+ mmdvfs->clk_data->hws[i] = &user->clk_hw;
+
+ if (user->clk_hw.clk) {
+ con_id = mmdvfs_get_clkdev_name(user->name,
+ clkdev_name,
+ sizeof(clkdev_name));
+ if (!con_id) {
+ mmdvfs_warn(mmdvfs->dev,
+ "Skip clkdev alias for long clock name %s\n",
+ user->name);
+ } else {
+ ret = devm_clk_hw_register_clkdev(mmdvfs->dev,
+ &user->clk_hw,
+ con_id, NULL);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev,
+ "Failed to register clkdev for %s: %d\n",
+ con_id, ret);
+ /* Non-fatal, continue */
+ }
+ }
+ }
+
+ mmdvfs_dbg(mmdvfs->dev, "Registered %s id=%d mux=%d\n",
+ user->name, user->id, user->mux);
+ }
+
+ ret = devm_of_clk_add_hw_provider(mmdvfs->dev, of_clk_hw_onecell_get,
+ mmdvfs->clk_data);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev,
+ "Failed to register clock provider: %d\n", ret);
+ goto cleanup_clocks;
+ }
+
+ mmdvfs_info(mmdvfs->dev, "Successfully registered %d MMDVFS clocks\n",
+ data->user_num);
+
+ return 0;
+
+cleanup_clocks:
+ mmdvfs->clk_data = NULL;
+ mmdvfs_err(mmdvfs->dev, "Clock registration failed, cleanup completed\n");
+ return ret;
+}
+
+/*
+ * mmdvfs_unregister_clocks - Unregister clock providers
+ * @mmdvfs: MMDVFS device structure
+ */
+void mmdvfs_unregister_clocks(struct mmdvfs_device *mmdvfs)
+{
+ if (mmdvfs && mmdvfs->dev)
+ mmdvfs_dbg(mmdvfs->dev, "MMDVFS clocks unregistered\n");
+}
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
new file mode 100644
index 000000000000..c32fa11557af
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
@@ -0,0 +1,581 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ *
+ * MediaTek MMDVFS Core Framework
+ */
+
+#include <linux/atomic.h>
+#include <linux/clk-provider.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/platform_device.h>
+#include <linux/sched/clock.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/suspend.h>
+#include <linux/workqueue.h>
+
+#include "mmdvfs-internal.h"
+
+static int mmdvfs_register_device(struct mmdvfs_device *mmdvfs);
+static void mmdvfs_unregister_device(struct mmdvfs_device *mmdvfs);
+
+struct mmdvfs_device *mmdvfs_find_device_by_version(enum mmdvfs_version_type version);
+struct mmdvfs_device *mmdvfs_find_device_any(void);
+
+struct mmdvfs_device *mmdvfs_find_device_any(void)
+{
+ return mmdvfs_find_device_by_version(MMDVFS_VERSION_HWCCF_DVFS_VOTER);
+}
+EXPORT_SYMBOL_GPL(mmdvfs_find_device_any);
+
+/**
+ * mmdvfs_get_version - Get MMDVFS voting mechanism type
+ *
+ * Return:
+ * 0 - No hardware voter
+ * 1 - HWCCF DVFS voter
+ */
+u32 mmdvfs_get_version(void)
+{
+ struct mmdvfs_device *mmdvfs;
+
+ mmdvfs = mmdvfs_find_device_any();
+ if (!mmdvfs || !mmdvfs->data)
+ return MMDVFS_VERSION_NONE;
+
+ return mmdvfs->data->version;
+}
+EXPORT_SYMBOL_GPL(mmdvfs_get_version);
+
+/*
+ * mmdvfs_validate_topology - Validate RC/MUX/User topology consistency
+ * @mmdvfs: MMDVFS device structure
+ *
+ * Return: 0 on success, -EINVAL if topology validation fails
+ */
+static int mmdvfs_validate_topology(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_data *data = mmdvfs->data;
+ int i, j;
+
+ if (!data || !data->mux || !data->rc) {
+ mmdvfs_err(mmdvfs->dev, "Invalid data structures for validation\n");
+ return -EINVAL;
+ }
+
+ for (i = 0; i < data->mux_num; i++) {
+ struct mmdvfs_mux *mux = &data->mux[i];
+ struct mmdvfs_rc *rc;
+
+ if (!mux->name || strlen(mux->name) == 0) {
+ mmdvfs_err(mmdvfs->dev, "MUX %d has empty name\n", i);
+ return -EINVAL;
+ }
+
+ if (mux->rc >= data->rc_num) {
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %d (%s) has invalid RC reference: %d (max: %d)\n",
+ i, mux->name, mux->rc, data->rc_num);
+ return -EINVAL;
+ }
+
+ rc = &data->rc[mux->rc];
+
+ if (rc->level_num == 0 || rc->level_num > MMDVFS_MAX_LEVELS) {
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %d (%s): RC %d has invalid level_num: %d\n",
+ i, mux->name, mux->rc, rc->level_num);
+ return -EINVAL;
+ }
+
+ if (mux->freq_num == 0 || mux->freq_num > MMDVFS_MAX_LEVELS) {
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %d (%s): invalid freq_num: %d\n",
+ i, mux->name, mux->freq_num);
+ return -EINVAL;
+ }
+
+ for (j = 0; j < mux->freq_num; j++) {
+ if (mux->freq[j] == 0) {
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %d (%s): incomplete freq table at level %d/%d (freq=0)\n",
+ i, mux->name, j, mux->freq_num);
+ return -EINVAL;
+ }
+
+ if (j > 0 && mux->freq[j] <= mux->freq[j - 1]) {
+ mmdvfs_warn(mmdvfs->dev,
+ "MUX %d (%s): freq not ascending: freq[%d]=%llu <= freq[%d]=%llu\n",
+ i, mux->name, j, mux->freq[j],
+ j - 1, mux->freq[j - 1]);
+ }
+ }
+
+ mmdvfs_dbg(mmdvfs->dev,
+ "MUX[%d] validated: name=%s, rc=%d, freq_num=%d (RC levels=%d), freq_min=%llu, freq_max=%llu\n",
+ i, mux->name, mux->rc, mux->freq_num,
+ rc->level_num, mux->freq[0],
+ mux->freq[mux->freq_num - 1]);
+ }
+
+ for (i = 0; i < data->user_num; i++) {
+ struct mmdvfs_user *user = &data->user[i];
+
+ if (!user->name || strlen(user->name) == 0) {
+ mmdvfs_err(mmdvfs->dev, "User %d has empty name\n", i);
+ return -EINVAL;
+ }
+
+ if (user->mux >= data->mux_num) {
+ mmdvfs_err(mmdvfs->dev,
+ "User %d (%s) has invalid MUX reference: %d (max: %d)\n",
+ i, user->name, user->mux, data->mux_num);
+ return -EINVAL;
+ }
+
+ mmdvfs_dbg(mmdvfs->dev,
+ "User[%d] validated: name=%s, id=%d, mux=%d\n",
+ i, user->name, user->id, user->mux);
+ }
+
+ mmdvfs_info(mmdvfs->dev, "Topology validation successful\n");
+ return 0;
+}
+
+/*
+ * mmdvfs_init_from_soc_data - Initialize from per-SoC topology data
+ * @mmdvfs: MMDVFS device structure
+ * @soc_data: Per-SoC static topology data
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+static int mmdvfs_init_from_soc_data(struct mmdvfs_device *mmdvfs,
+ const struct mmdvfs_soc_data *soc_data)
+{
+ struct mmdvfs_data *data = mmdvfs->data;
+ int i, ret;
+
+ if (!soc_data || soc_data->rc_num == 0 || soc_data->mux_num == 0 ||
+ soc_data->user_num == 0) {
+ mmdvfs_err(mmdvfs->dev, "Invalid or missing SoC data\n");
+ return -EINVAL;
+ }
+
+ if (soc_data->rc_num > MMDVFS_MAX_RCS ||
+ soc_data->mux_num > MMDVFS_MAX_MUXES ||
+ soc_data->user_num > MMDVFS_MAX_USERS) {
+ mmdvfs_err(mmdvfs->dev, "SoC data exceeds max limits\n");
+ return -EINVAL;
+ }
+
+ data->rc = devm_kcalloc(mmdvfs->dev, soc_data->rc_num,
+ sizeof(*data->rc), GFP_KERNEL);
+ if (!data->rc)
+ return -ENOMEM;
+
+ data->mux = devm_kcalloc(mmdvfs->dev, soc_data->mux_num,
+ sizeof(*data->mux), GFP_KERNEL);
+ if (!data->mux)
+ return -ENOMEM;
+
+ data->user = devm_kcalloc(mmdvfs->dev, soc_data->user_num,
+ sizeof(*data->user), GFP_KERNEL);
+ if (!data->user)
+ return -ENOMEM;
+
+ for (i = 0; i < soc_data->rc_num; i++)
+ data->rc[i] = soc_data->rc_table[i];
+
+ for (i = 0; i < soc_data->mux_num; i++) {
+ data->mux[i] = soc_data->mux_table[i];
+ mutex_init(&data->mux[i].lock);
+ }
+
+ for (i = 0; i < soc_data->user_num; i++) {
+ data->user[i] = soc_data->user_table[i];
+ data->user[i].mmdvfs = mmdvfs;
+ }
+
+ data->rc_num = soc_data->rc_num;
+ data->mux_num = soc_data->mux_num;
+ data->user_num = soc_data->user_num;
+
+ mmdvfs_dbg(mmdvfs->dev, "Initialized SoC data: rc=%u mux=%u user=%u version=%d\n",
+ soc_data->rc_num, soc_data->mux_num, soc_data->user_num,
+ data->version);
+
+ if (data->ops && data->ops->probe) {
+ ret = data->ops->probe(mmdvfs);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Platform probe failed: %d\n", ret);
+ return ret;
+ }
+ }
+
+ ret = mmdvfs_validate_topology(mmdvfs);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Topology validation failed: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+ * mmdvfs_parse_dt - Parse device tree configuration
+ * @mmdvfs: MMDVFS device structure
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+int mmdvfs_parse_dt(struct mmdvfs_device *mmdvfs)
+{
+ struct device_node *node = mmdvfs->dev->of_node;
+
+ if (!node) {
+ mmdvfs_err(mmdvfs->dev, "No device tree node found\n");
+ return -ENODEV;
+ }
+
+ mmdvfs_info(mmdvfs->dev, "Device tree parsed (hardware attributes)\n");
+
+ return 0;
+}
+
+/*
+ * mmdvfs_pm_notifier_callback - PM notifier callback for suspend/resume handling
+ * @nb: Notifier block
+ * @event: PM event type
+ * @data: Event data
+ *
+ * Return: NOTIFY_DONE
+ */
+static int mmdvfs_pm_notifier_callback(struct notifier_block *nb, unsigned long event,
+ void *data)
+{
+ struct mmdvfs_data *mdata =
+ container_of(nb, struct mmdvfs_data, pm_notifier);
+ struct mmdvfs_device *mmdvfs = dev_get_drvdata(mdata->dev);
+
+ switch (event) {
+ case PM_SUSPEND_PREPARE:
+ mmdvfs_dbg(mmdvfs->dev, "System suspending...\n");
+
+ if (mdata->ops && mdata->ops->suspend_prepare)
+ mdata->ops->suspend_prepare(mmdvfs);
+
+ mdata->pm_suspended = true;
+ break;
+
+ case PM_POST_SUSPEND:
+ mmdvfs_dbg(mmdvfs->dev, "System resumed\n");
+
+ mdata->pm_suspended = false;
+
+ if (mdata->ops && mdata->ops->post_suspend)
+ mdata->ops->post_suspend(mmdvfs);
+ break;
+
+ default:
+ break;
+ }
+
+ return NOTIFY_DONE;
+}
+
+/*
+ * mmdvfs_probe - Main probe function
+ * @pdev: Platform device
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+static int mmdvfs_probe(struct platform_device *pdev)
+{
+ struct mmdvfs_device *mmdvfs;
+ struct mmdvfs_data *data;
+ const struct mmdvfs_platform_data *pdata;
+ int ret;
+
+ mmdvfs = devm_kzalloc(&pdev->dev, sizeof(*mmdvfs), GFP_KERNEL);
+ if (!mmdvfs)
+ return -ENOMEM;
+
+ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ mmdvfs->dev = &pdev->dev;
+ mmdvfs->data = data;
+ data->dev = &pdev->dev;
+
+ mutex_init(&data->lock);
+
+ platform_set_drvdata(pdev, mmdvfs);
+
+ pdata = of_device_get_match_data(&pdev->dev);
+ if (!pdata) {
+ mmdvfs_err(mmdvfs->dev, "No matching platform data\n");
+ return -ENODEV;
+ }
+
+ data->ops = pdata->ops;
+ data->version = pdata->soc_data->version;
+
+ if (data->version == MMDVFS_VERSION_HWCCF_DVFS_VOTER) {
+ data->hwccf_voter_priv = devm_kzalloc(&pdev->dev,
+ sizeof(*data->hwccf_voter_priv),
+ GFP_KERNEL);
+ if (!data->hwccf_voter_priv)
+ return -ENOMEM;
+
+ data->hwccf_voter_priv->mmdvfs = mmdvfs;
+ }
+
+ ret = mmdvfs_parse_dt(mmdvfs);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to parse device tree: %d\n", ret);
+ return ret;
+ }
+
+ ret = mmdvfs_init_from_soc_data(mmdvfs, pdata->soc_data);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to initialize from SoC data: %d\n", ret);
+ return ret;
+ }
+
+ if (data->ops && data->ops->init_hw) {
+ ret = data->ops->init_hw(mmdvfs);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to initialize hardware: %d\n", ret);
+ return ret;
+ }
+ }
+
+ data->init_done = true;
+
+ ret = mmdvfs_register_clocks(mmdvfs);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to register clocks: %d\n", ret);
+ goto err_deinit_hw;
+ }
+
+ data->pm_notifier.notifier_call = mmdvfs_pm_notifier_callback;
+ data->pm_notifier.priority = 0;
+ data->pm_suspended = false;
+ ret = register_pm_notifier(&data->pm_notifier);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to register PM notifier: %d\n", ret);
+ goto err_unregister_clocks;
+ }
+ mmdvfs_info(mmdvfs->dev, "PM notifier registered\n");
+
+ ret = mmdvfs_register_device(mmdvfs);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to register device: %d\n", ret);
+ goto err_unregister_pm_notifier;
+ }
+
+ mmdvfs_info(mmdvfs->dev, "MMDVFS driver probed successfully\n");
+ return 0;
+
+err_unregister_pm_notifier:
+ unregister_pm_notifier(&data->pm_notifier);
+
+err_unregister_clocks:
+ mmdvfs_unregister_clocks(mmdvfs);
+
+err_deinit_hw:
+ if (data->ops && data->ops->deinit_hw)
+ data->ops->deinit_hw(mmdvfs);
+
+ return ret;
+}
+
+/*
+ * mmdvfs_remove - Remove function
+ * @pdev: Platform device
+ *
+ * Return: 0 on success
+ */
+static void mmdvfs_remove(struct platform_device *pdev)
+{
+ struct mmdvfs_device *mmdvfs = platform_get_drvdata(pdev);
+ struct mmdvfs_data *data = mmdvfs->data;
+
+ unregister_pm_notifier(&data->pm_notifier);
+ mmdvfs_dbg(mmdvfs->dev, "PM notifier unregistered\n");
+
+ mmdvfs_unregister_clocks(mmdvfs);
+
+ if (data->ops && data->ops->deinit_hw)
+ data->ops->deinit_hw(mmdvfs);
+
+ mmdvfs_unregister_device(mmdvfs);
+
+ mmdvfs_info(mmdvfs->dev, "MMDVFS driver removed\n");
+}
+
+/* Platform data definitions for device match table */
+#if IS_ENABLED(CONFIG_MTK_MMDVFS_MT8196)
+static const struct mmdvfs_platform_data mmdvfs_mt8196_pdata = {
+ .soc_data = &mmdvfs_mt8196_soc_data,
+ .ops = &mmdvfs_mt8196_ops,
+};
+#endif
+
+static const struct of_device_id mmdvfs_of_match[] = {
+#if IS_ENABLED(CONFIG_MTK_MMDVFS_MT8196)
+ {
+ .compatible = "mediatek,mt8196-mmdvfs",
+ .data = &mmdvfs_mt8196_pdata,
+ },
+#endif
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, mmdvfs_of_match);
+
+static struct platform_driver mmdvfs_driver = {
+ .probe = mmdvfs_probe,
+ .remove = mmdvfs_remove,
+ .driver = {
+ .name = "mediatek-mmdvfs",
+ .of_match_table = mmdvfs_of_match,
+ },
+};
+
+module_platform_driver(mmdvfs_driver);
+
+/* Device lookup mechanism to replace global variable */
+static DEFINE_MUTEX(mmdvfs_device_list_lock);
+static LIST_HEAD(mmdvfs_device_list);
+
+struct mmdvfs_device_node {
+ struct list_head list;
+ struct mmdvfs_device *mmdvfs;
+};
+
+struct mmdvfs_device *mmdvfs_find_device_by_version(enum mmdvfs_version_type version)
+{
+ struct mmdvfs_device_node *node;
+ struct mmdvfs_device *found = NULL;
+
+ mutex_lock(&mmdvfs_device_list_lock);
+ list_for_each_entry(node, &mmdvfs_device_list, list) {
+ if (node->mmdvfs && node->mmdvfs->data &&
+ node->mmdvfs->data->version == version) {
+ found = node->mmdvfs;
+ break;
+ }
+ }
+ mutex_unlock(&mmdvfs_device_list_lock);
+
+ return found;
+}
+EXPORT_SYMBOL_GPL(mmdvfs_find_device_by_version);
+
+static int mmdvfs_register_device(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_device_node *node;
+
+ node = kzalloc_obj(*node, GFP_KERNEL);
+ if (!node)
+ return -ENOMEM;
+
+ node->mmdvfs = mmdvfs;
+
+ mutex_lock(&mmdvfs_device_list_lock);
+ list_add(&node->list, &mmdvfs_device_list);
+ mutex_unlock(&mmdvfs_device_list_lock);
+
+ return 0;
+}
+
+static void mmdvfs_unregister_device(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_device_node *node, *tmp;
+
+ mutex_lock(&mmdvfs_device_list_lock);
+ list_for_each_entry_safe(node, tmp, &mmdvfs_device_list, list) {
+ if (node->mmdvfs == mmdvfs) {
+ list_del(&node->list);
+ kfree(node);
+ break;
+ }
+ }
+ mutex_unlock(&mmdvfs_device_list_lock);
+}
+
+int mtk_mmdvfs_camera_notify(bool enable)
+{
+ struct mmdvfs_device *mmdvfs;
+
+ mmdvfs = mmdvfs_find_device_any();
+ if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
+ !mmdvfs->data->ops->camera_notify)
+ return -EOPNOTSUPP;
+
+ return mmdvfs->data->ops->camera_notify(mmdvfs, enable);
+}
+EXPORT_SYMBOL_GPL(mtk_mmdvfs_camera_notify);
+
+int mtk_mmdvfs_genpd_notify(u8 idx, bool enable)
+{
+ struct mmdvfs_device *mmdvfs;
+
+ mmdvfs = mmdvfs_find_device_any();
+ if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
+ !mmdvfs->data->ops->genpd_notify)
+ return -EOPNOTSUPP;
+
+ return mmdvfs->data->ops->genpd_notify(mmdvfs, idx, enable);
+}
+EXPORT_SYMBOL_GPL(mtk_mmdvfs_genpd_notify);
+
+int mtk_mmdvfs_set_avs(u8 idx, u32 aging, u32 fresh)
+{
+ struct mmdvfs_device *mmdvfs;
+
+ mmdvfs = mmdvfs_find_device_any();
+ if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
+ !mmdvfs->data->ops->set_avs)
+ return -EOPNOTSUPP;
+
+ return mmdvfs->data->ops->set_avs(mmdvfs, idx, aging, fresh);
+}
+EXPORT_SYMBOL_GPL(mtk_mmdvfs_set_avs);
+
+int mmdvfs_set_lp_mode(bool enable)
+{
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(mmdvfs_set_lp_mode);
+
+int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable)
+{
+ struct mmdvfs_device *mmdvfs;
+
+ mmdvfs = mmdvfs_find_device_any();
+ if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
+ !mmdvfs->data->ops->camsv_dc_enable)
+ return -EOPNOTSUPP;
+
+ return mmdvfs->data->ops->camsv_dc_enable(mmdvfs, idx, enable);
+}
+EXPORT_SYMBOL_GPL(mtk_mmdvfs_camsv_dc_enable);
+
+int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx)
+{
+ return -EOPNOTSUPP;
+}
+EXPORT_SYMBOL_GPL(mtk_mmdvfs_enable_ccu);
+
+MODULE_DESCRIPTION("MediaTek MMDVFS Driver");
+MODULE_AUTHOR("MediaTek Inc.");
+MODULE_LICENSE("GPL");
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h b/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
new file mode 100644
index 000000000000..df16e38d78c8
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
@@ -0,0 +1,305 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ *
+ * MediaTek MMDVFS (MultiMedia Dynamic Voltage and Frequency Scaling) Driver
+ */
+
+#ifndef __MMDVFS_H__
+#define __MMDVFS_H__
+
+#include <linux/clk-provider.h>
+#include <linux/device.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
+#include <linux/platform_device.h>
+
+struct dentry;
+
+#define MMDVFS_MAX_LEVELS 8
+#define MMDVFS_MAX_USERS 64
+#define MMDVFS_MAX_MUXES 16
+#define MMDVFS_MAX_RCS 4
+
+/* MMDVFS voting mechanism types */
+enum mmdvfs_version_type {
+ MMDVFS_VERSION_NONE = 0, /* No hardware voter */
+ MMDVFS_VERSION_HWCCF_DVFS_VOTER = 1, /* HWCCF DVFS voter */
+};
+
+#define MAX_OPP 8
+
+/* MMDVFS RC domains */
+enum mmdvfs_rc_domain {
+ MMDVFS_PWR_VCORE = 0, /* PWR_MMDVFS_VCORE */
+ MMDVFS_PWR_VMM = 1, /* PWR_MMDVFS_VMM */
+ MMDVFS_PWR_VDISP = 2, /* PWR_MMDVFS_VDISP */
+ MMDVFS_PWR_NUM = 3 /* PWR_MMDVFS_NUM */
+};
+
+/**
+ * struct mmdvfs_rc - Resource Controller
+ * @id: RC identifier
+ * @pa: Physical address base
+ * @level_num: Number of supported levels
+ * @rc_base: Virtual address base (mapped from pa)
+ */
+struct mmdvfs_rc {
+ u8 id;
+ u32 pa;
+ u8 level_num;
+ void __iomem *rc_base;
+};
+
+/**
+ * struct mmdvfs_mux - Multiplexer
+ * @id: MUX identifier
+ * @rc: Associated RC id
+ * @pos: Position in RC
+ * @shift: Bit shift for this mux in registers
+ * @hwccf: HWCCF voter register offsets and update bit
+ * @name: MUX name
+ * @freq: Frequency table for each level
+ * @freq_num: Actual number of frequencies in freq array (from OPP table)
+ * @lock: Serialize updates for this MUX
+ */
+struct mmdvfs_mux {
+ u8 id;
+ u8 rc;
+ u8 pos;
+ u8 shift;
+ struct {
+ u32 hwv_set_ofs;
+ u32 hwv_clr_ofs;
+ u32 hwv_sta_ofs;
+ u32 hwv_upd_ofs;
+ u8 hwv_upd_id;
+ } hwccf;
+ const char *name;
+ u64 freq[MMDVFS_MAX_LEVELS];
+ u8 freq_num;
+ /* Protects this mux vote state. */
+ struct mutex lock;
+};
+
+/**
+ * struct mmdvfs_user - MMDVFS User/Client
+ * @id: User identifier
+ * @name: User name (e.g., "CAM", "DISP")
+ * @mux: Associated MUX id
+ * @level: Current level
+ * @clk_hw: Clock hardware structure
+ * @clk: Clock pointer
+ * @mmdvfs: MMDVFS device reference
+ */
+struct mmdvfs_user {
+ u8 id;
+ const char *name;
+ u8 mux;
+ u8 level;
+ struct clk_hw clk_hw;
+ struct clk *clk;
+ struct mmdvfs_device *mmdvfs;
+};
+
+/**
+ * struct mmdvfs_hwccf_voter_priv - HWCCF DVFS Voter specific data
+ * @hwccf_voter_support: HWCCF voter support flag
+ * @step_idx: Step index
+ * @dpsw_thr: DPSW threshold
+ * @mmdvfs: MMDVFS device reference
+ * @genpd_wq: GenPD workqueue
+ */
+struct mmdvfs_hwccf_voter_priv {
+ bool hwccf_voter_support;
+ u8 step_idx;
+ int dpsw_thr;
+ struct mmdvfs_device *mmdvfs;
+ struct workqueue_struct *genpd_wq;
+};
+
+/**
+ * struct mmdvfs_ops - Platform-specific operations
+ * @probe: Platform-specific probe function
+ * @hw_vote: Submit frequency/voltage vote to hardware
+ * @get_current_level: Get current hardware level
+ * @init_hw: Initialize hardware
+ * @deinit_hw: Deinitialize hardware
+ * @suspend_prepare: Prepare for suspend
+ * @post_suspend: Post-suspend cleanup
+ * @camera_notify: Camera power notification
+ * @genpd_notify: Generic power domain notification
+ * @set_avs: Set AVS (Adaptive Voltage Scaling) parameters
+ * @camsv_dc_enable: Enable/disable CAMSV DC mode
+ *
+ * MT8196 implements hw_vote through the HWCCF voter.
+ */
+struct mmdvfs_ops {
+ /* Platform-specific probe function to attach IC-related ops */
+ int (*probe)(struct mmdvfs_device *mmdvfs);
+
+ int (*hw_vote)(struct mmdvfs_device *mmdvfs, const u8 user_id, const u8 level);
+ int (*get_current_level)(struct mmdvfs_device *mmdvfs, u32 pwr_id);
+ int (*dvfsrc_rg_dump)(struct mmdvfs_device *mmdvfs);
+ int (*dvfsrc_record_dump)(struct mmdvfs_device *mmdvfs);
+ int (*init_hw)(struct mmdvfs_device *mmdvfs);
+ void (*deinit_hw)(struct mmdvfs_device *mmdvfs);
+
+ /* Power management operations */
+ void (*suspend_prepare)(struct mmdvfs_device *mmdvfs);
+ void (*post_suspend)(struct mmdvfs_device *mmdvfs);
+
+ /* HWCCF DVFS voter - Extended operations */
+ int (*camera_notify)(struct mmdvfs_device *mmdvfs, bool enable);
+ int (*genpd_notify)(struct mmdvfs_device *mmdvfs, u8 idx, bool enable);
+ int (*set_avs)(struct mmdvfs_device *mmdvfs, u8 idx, u32 aging, u32 fresh);
+ int (*camsv_dc_enable)(struct mmdvfs_device *mmdvfs, u8 idx, bool enable);
+};
+
+/**
+ * struct mmdvfs_data - Main MMDVFS data structure
+ * @dev: Device pointer
+ * @rc: Array of Resource Controllers
+ * @mux: Array of Multiplexers
+ * @user: Array of Users
+ * @ops: Platform-specific operations
+ * @version: Hardware voting mechanism
+ * @platform_data: Platform-specific private data
+ * @rc_num: Number of RCs
+ * @mux_num: Number of MUXes
+ * @user_num: Number of Users
+ * @lock: Device-wide mutex for synchronization
+ * @hwccf_voter_priv: HWCCF DVFS Voter private data (dynamically allocated)
+ * @init_done: Initialization completion flag
+ * @pm_notifier: Suspend/resume notifier
+ * @pm_suspended: Whether system suspend is in progress
+ */
+struct mmdvfs_data {
+ struct device *dev;
+ struct mmdvfs_rc *rc;
+ struct mmdvfs_mux *mux;
+ struct mmdvfs_user *user;
+ const struct mmdvfs_ops *ops;
+ enum mmdvfs_version_type version;
+ void *platform_data;
+ u8 rc_num;
+ u8 mux_num;
+ u8 user_num;
+ /* Protects device-wide state. */
+ struct mutex lock;
+
+ /* Hardware-specific private data (dynamically allocated) */
+ struct mmdvfs_hwccf_voter_priv *hwccf_voter_priv;
+
+ /* Shared status and control */
+ bool init_done;
+
+ /* PM notifier for suspend/resume handling */
+ struct notifier_block pm_notifier;
+ bool pm_suspended;
+
+};
+
+/**
+ * struct mmdvfs_device - MMDVFS device structure
+ * @dev: Device pointer
+ * @data: MMDVFS data
+ * @clk_data: Clock provider data
+ */
+struct mmdvfs_device {
+ struct device *dev;
+ struct mmdvfs_data *data;
+ struct clk_hw_onecell_data *clk_data;
+};
+
+/* Helper macros */
+#define to_mmdvfs_user(hw) container_of(hw, struct mmdvfs_user, clk_hw)
+
+/**
+ * struct mmdvfs_soc_data - Per-SoC topology and configuration data
+ * @rc_table: Array of RC (Resource Controller) configurations
+ * @rc_num: Number of RCs in this SoC
+ * @mux_table: Array of MUX (Multiplexer) configurations
+ * @mux_num: Number of MUXes in this SoC
+ * @user_table: Array of User/Client configurations
+ * @user_num: Number of Users in this SoC
+ * @version: MMDVFS voting mechanism
+ *
+ * This structure defines the per-SoC topology statically in code.
+ * Allocated and configured by each per-SoC driver file.
+ */
+struct mmdvfs_soc_data {
+ const struct mmdvfs_rc *rc_table;
+ u8 rc_num;
+ const struct mmdvfs_mux *mux_table;
+ u8 mux_num;
+ const struct mmdvfs_user *user_table;
+ u8 user_num;
+ enum mmdvfs_version_type version;
+};
+
+/**
+ * struct mmdvfs_platform_data - Platform-specific data for device match table
+ * @soc_data: SoC topology and configuration data
+ * @ops: Platform-specific operations
+ *
+ * This structure is used in of_device_id match table to associate
+ * compatible strings with their corresponding SoC data and operations.
+ */
+struct mmdvfs_platform_data {
+ const struct mmdvfs_soc_data *soc_data;
+ const struct mmdvfs_ops *ops;
+};
+
+/* Core functions */
+int mmdvfs_register_clocks(struct mmdvfs_device *mmdvfs);
+void mmdvfs_unregister_clocks(struct mmdvfs_device *mmdvfs);
+int mmdvfs_parse_dt(struct mmdvfs_device *mmdvfs);
+
+/* Platform-specific functions to be implemented */
+extern const struct mmdvfs_ops mmdvfs_mt8196_ops;
+
+/* Per-SoC topology data */
+extern const struct mmdvfs_soc_data mmdvfs_mt8196_soc_data;
+
+/* Platform-specific operations */
+u32 mmdvfs_get_version(void);
+int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx);
+int mtk_mmdvfs_camera_notify(bool enable);
+int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable);
+int mtk_mmdvfs_genpd_notify(u8 idx, bool enable);
+int mtk_mmdvfs_set_avs(u8 idx, u32 aging, u32 fresh);
+int mmdvfs_set_lp_mode(bool enable);
+
+/* Utility functions */
+static inline bool mmdvfs_is_valid_user_id(u8 user_id)
+{
+ return user_id < MMDVFS_MAX_USERS;
+}
+
+static inline bool mmdvfs_is_valid_level(u8 level)
+{
+ return level < MMDVFS_MAX_LEVELS;
+}
+
+static inline bool mmdvfs_is_valid_rc_id(u8 rc_id)
+{
+ return rc_id < MMDVFS_MAX_RCS;
+}
+
+static inline bool mmdvfs_is_valid_mux_id(u8 mux_id)
+{
+ return mux_id < MMDVFS_MAX_MUXES;
+}
+
+/* Logging macros */
+#define mmdvfs_dbg(dev, fmt, args...) \
+ dev_dbg(dev, "[mmdvfs] " fmt, ##args)
+#define mmdvfs_info(dev, fmt, args...) \
+ dev_info(dev, "[mmdvfs] " fmt, ##args)
+#define mmdvfs_warn(dev, fmt, args...) \
+ dev_warn(dev, "[mmdvfs] " fmt, ##args)
+#define mmdvfs_err(dev, fmt, args...) \
+ dev_err(dev, "[mmdvfs] " fmt, ##args)
+
+#endif /* __MMDVFS_H__ */
diff --git a/include/soc/mediatek/mmdvfs.h b/include/soc/mediatek/mmdvfs.h
new file mode 100644
index 000000000000..459f1adcab34
--- /dev/null
+++ b/include/soc/mediatek/mmdvfs.h
@@ -0,0 +1,72 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ *
+ * MediaTek MMDVFS (Multimedia Dynamic Voltage and Frequency Scaling) API
+ */
+
+#ifndef MTK_MMDVFS_H
+#define MTK_MMDVFS_H
+
+#include <linux/errno.h>
+#include <linux/io.h>
+#include <linux/types.h>
+
+enum mmdvfs_version_type {
+ MMDVFS_VERSION_NONE = 0,
+ MMDVFS_VERSION_HWCCF_DVFS_VOTER = 1,
+};
+
+enum {
+ CCU_PWR_USR_MMDVFS,
+ CCU_PWR_USR_IMG,
+ CCU_PWR_USR_NUM
+};
+
+#if IS_ENABLED(CONFIG_MTK_MMDVFS) && IS_ENABLED(CONFIG_MTK_VCP_RPROC)
+int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx);
+int mtk_mmdvfs_camera_notify(const bool enable);
+int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable);
+int mtk_mmdvfs_genpd_notify(const u8 idx, const bool enable);
+int mtk_mmdvfs_set_avs(const u8 idx, const u32 aging, const u32 fresh);
+int mmdvfs_set_lp_mode(bool lp_mode);
+u32 mmdvfs_get_version(void);
+#else
+
+static inline int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int mtk_mmdvfs_camera_notify(const bool enable)
+{
+ return 0;
+}
+
+static inline int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable)
+{
+ return 0;
+}
+
+static inline int mtk_mmdvfs_genpd_notify(const u8 idx, const bool enable)
+{
+ return 0;
+}
+
+static inline int mtk_mmdvfs_set_avs(const u8 idx, const u32 aging, const u32 fresh)
+{
+ return 0;
+}
+
+static inline int mmdvfs_set_lp_mode(bool lp_mode)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline u32 mmdvfs_get_version(void)
+{
+ return MMDVFS_VERSION_NONE;
+}
+#endif
+
+#endif /* MTK_MMDVFS_H */
--
2.45.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend
2026-11-25 6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
` (2 preceding siblings ...)
2026-11-25 6:00 ` [PATCH 3/7] soc: mediatek: add MMDVFS core driver Echo Zhang
@ 2026-11-25 6:00 ` Echo Zhang
2026-11-25 8:38 ` Roman Vivchar
` (3 more replies)
2026-11-25 6:00 ` [PATCH 5/7] soc: mediatek: mmdvfs: add MT8196 support Echo Zhang
` (2 subsequent siblings)
6 siblings, 4 replies; 18+ messages in thread
From: Echo Zhang @ 2026-11-25 6:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
Add the VCP transport used by MMDVFS to map AP and firmware shared
memory, manage feature power references and send IPI commands.
Wait for VCP readiness and handle the selected MMUP or VCP READY
notification to initialize firmware after boot and resume. Serialize
IPI transactions while shared memory and acknowledgment state are in
use.
Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
---
drivers/soc/mediatek/mmdvfs/Makefile | 2 +
drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c | 39 +-
drivers/soc/mediatek/mmdvfs/mmdvfs-core.c | 272 +++--
drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h | 160 ++-
drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h | 57 +
drivers/soc/mediatek/mmdvfs/mmdvfs-up.c | 275 +++++
.../soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h | 104 ++
drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c | 1075 +++++++++++++++++
include/soc/mediatek/mmdvfs.h | 66 +-
9 files changed, 1846 insertions(+), 204 deletions(-)
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-up.c
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c
diff --git a/drivers/soc/mediatek/mmdvfs/Makefile b/drivers/soc/mediatek/mmdvfs/Makefile
index 33a280827006..16ecee30bff6 100644
--- a/drivers/soc/mediatek/mmdvfs/Makefile
+++ b/drivers/soc/mediatek/mmdvfs/Makefile
@@ -4,3 +4,5 @@ obj-$(CONFIG_MTK_MMDVFS) += mtk-mmdvfs.o
mtk-mmdvfs-y += mmdvfs-core.o
mtk-mmdvfs-y += mmdvfs-clk.o
+mtk-mmdvfs-y += mmdvfs-up.o
+mtk-mmdvfs-y += mmdvfs-vcp.o
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
index 114f3148cf46..b9025427782d 100644
--- a/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
@@ -15,7 +15,6 @@
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
-#include <linux/pm_runtime.h>
#include <linux/property.h>
#include <linux/slab.h>
#include <linux/string.h>
@@ -27,9 +26,18 @@
static const char *mmdvfs_get_clkdev_name(const char *name, char *buf, size_t size)
{
+ int ret;
+
if (strlen(name) < MMDVFS_CLKDEV_CON_ID_MAX)
return name;
+ if (str_has_prefix(name, "mmdvfs-vcp-")) {
+ ret = snprintf(buf, size, "mmdvfs-v-%s",
+ name + strlen("mmdvfs-vcp-"));
+ if (ret > 0 && ret < (int)size)
+ return buf;
+ }
+
return NULL;
}
@@ -66,7 +74,7 @@ static int mmdvfs_set_rate(struct clk_hw *hw, unsigned long rate,
data = mmdvfs->data;
- if (!data->init_done)
+ if (!READ_ONCE(data->init_done))
return -EPROBE_DEFER;
if (!mmdvfs_is_valid_user_id(user->id) ||
@@ -76,12 +84,6 @@ static int mmdvfs_set_rate(struct clk_hw *hw, unsigned long rate,
return -EINVAL;
}
- if (rate == 0) {
- mmdvfs_dbg(mmdvfs->dev, "Zero rate request for user %s\n",
- user->name);
- return 0;
- }
-
mux = &data->mux[user->mux];
if (!mmdvfs_is_valid_rc_id(mux->rc)) {
mmdvfs_err(mmdvfs->dev, "Invalid mux config: rc=%d for user %s\n",
@@ -118,17 +120,17 @@ static int mmdvfs_set_rate(struct clk_hw *hw, unsigned long rate,
return -EINVAL;
}
+ mutex_lock(&mux->lock);
if (user->level == level) {
mmdvfs_dbg(mmdvfs->dev, "user %s: already at level %d, skip\n",
user->name, level);
+ mutex_unlock(&mux->lock);
return 0;
}
mmdvfs_dbg(mmdvfs->dev, "user %s: rate %lu -> level %d (freq=%llu)\n",
user->name, rate, level, mux->freq[level]);
- mutex_lock(&mux->lock);
-
if (data->ops && data->ops->hw_vote) {
ret = data->ops->hw_vote(mmdvfs, user->id, level);
if (!ret) {
@@ -237,13 +239,6 @@ static long mmdvfs_round_rate(struct clk_hw *hw, unsigned long rate,
return -EINVAL;
}
- if (rate == 0) {
- mmdvfs_dbg(mmdvfs->dev,
- "Zero rate request in round_rate for user %s\n",
- user->name);
- return 0;
- }
-
mux = &data->mux[user->mux];
if (!mmdvfs_is_valid_rc_id(mux->rc)) {
mmdvfs_err(mmdvfs->dev,
@@ -450,13 +445,3 @@ int mmdvfs_register_clocks(struct mmdvfs_device *mmdvfs)
mmdvfs_err(mmdvfs->dev, "Clock registration failed, cleanup completed\n");
return ret;
}
-
-/*
- * mmdvfs_unregister_clocks - Unregister clock providers
- * @mmdvfs: MMDVFS device structure
- */
-void mmdvfs_unregister_clocks(struct mmdvfs_device *mmdvfs)
-{
- if (mmdvfs && mmdvfs->dev)
- mmdvfs_dbg(mmdvfs->dev, "MMDVFS clocks unregistered\n");
-}
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
index c32fa11557af..3388a5a3a145 100644
--- a/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
@@ -7,22 +7,23 @@
#include <linux/atomic.h>
#include <linux/clk-provider.h>
+#include <linux/delay.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/io.h>
+#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/mutex.h>
-#include <linux/notifier.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
+#include <linux/remoteproc/mtk_vcp_public.h>
#include <linux/sched/clock.h>
#include <linux/slab.h>
#include <linux/string.h>
-#include <linux/suspend.h>
-#include <linux/workqueue.h>
#include "mmdvfs-internal.h"
+#include "mmdvfs-up-priv.h"
static int mmdvfs_register_device(struct mmdvfs_device *mmdvfs);
static void mmdvfs_unregister_device(struct mmdvfs_device *mmdvfs);
@@ -34,14 +35,13 @@ struct mmdvfs_device *mmdvfs_find_device_any(void)
{
return mmdvfs_find_device_by_version(MMDVFS_VERSION_HWCCF_DVFS_VOTER);
}
-EXPORT_SYMBOL_GPL(mmdvfs_find_device_any);
/**
* mmdvfs_get_version - Get MMDVFS voting mechanism type
*
* Return:
* 0 - No hardware voter
- * 1 - HWCCF DVFS voter
+ * 1 - HWCCF DVFS voter (VCP IPI with MMUP SRAM)
*/
u32 mmdvfs_get_version(void)
{
@@ -96,7 +96,8 @@ static int mmdvfs_validate_topology(struct mmdvfs_device *mmdvfs)
return -EINVAL;
}
- if (mux->freq_num == 0 || mux->freq_num > MMDVFS_MAX_LEVELS) {
+ if (mux->freq_num == 0 || mux->freq_num > rc->level_num ||
+ mux->freq_num > MMDVFS_MAX_LEVELS) {
mmdvfs_err(mmdvfs->dev,
"MUX %d (%s): invalid freq_num: %d\n",
i, mux->name, mux->freq_num);
@@ -112,10 +113,11 @@ static int mmdvfs_validate_topology(struct mmdvfs_device *mmdvfs)
}
if (j > 0 && mux->freq[j] <= mux->freq[j - 1]) {
- mmdvfs_warn(mmdvfs->dev,
- "MUX %d (%s): freq not ascending: freq[%d]=%llu <= freq[%d]=%llu\n",
- i, mux->name, j, mux->freq[j],
- j - 1, mux->freq[j - 1]);
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %d (%s): freq not ascending: freq[%d]=%llu <= freq[%d]=%llu\n",
+ i, mux->name, j, mux->freq[j],
+ j - 1, mux->freq[j - 1]);
+ return -EINVAL;
}
}
@@ -249,45 +251,61 @@ int mmdvfs_parse_dt(struct mmdvfs_device *mmdvfs)
return 0;
}
-/*
- * mmdvfs_pm_notifier_callback - PM notifier callback for suspend/resume handling
- * @nb: Notifier block
- * @event: PM event type
- * @data: Event data
- *
- * Return: NOTIFY_DONE
- */
-static int mmdvfs_pm_notifier_callback(struct notifier_block *nb, unsigned long event,
- void *data)
+static int mmdvfs_init_up(struct mmdvfs_device *mmdvfs, bool stoppable)
{
- struct mmdvfs_data *mdata =
- container_of(nb, struct mmdvfs_data, pm_notifier);
- struct mmdvfs_device *mmdvfs = dev_get_drvdata(mdata->dev);
+ struct mmdvfs_data *mdata = mmdvfs->data;
+ int retry = 0;
+ int ret;
- switch (event) {
- case PM_SUSPEND_PREPARE:
- mmdvfs_dbg(mmdvfs->dev, "System suspending...\n");
+ ret = mmdvfs_up_register(mmdvfs, MMDVFS_UP_VCP);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to register HFRP: %d\n", ret);
+ return ret;
+ }
- if (mdata->ops && mdata->ops->suspend_prepare)
- mdata->ops->suspend_prepare(mmdvfs);
+ while (!mmdvfs_up_get_cb_ready(mmdvfs, MMDVFS_UP_VCP)) {
+ if (stoppable && kthread_should_stop()) {
+ ret = -ECANCELED;
+ goto err_unregister_up;
+ }
- mdata->pm_suspended = true;
- break;
+ if (++retry > 100) {
+ mmdvfs_err(mmdvfs->dev,
+ "Init timeout: VCP/MMUP callback not ready after %d seconds\n",
+ retry);
+ ret = -ETIMEDOUT;
+ goto err_unregister_up;
+ }
+ ssleep(1);
+ }
- case PM_POST_SUSPEND:
- mmdvfs_dbg(mmdvfs->dev, "System resumed\n");
+ mmdvfs_dbg(mmdvfs->dev, "Init complete after %d seconds\n", retry);
+ ret = mmdvfs_vcp_release_init(mmdvfs);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to release VCP INIT feature: %d\n", ret);
+ goto err_unregister_up;
+ }
- mdata->pm_suspended = false;
+ return 0;
- if (mdata->ops && mdata->ops->post_suspend)
- mdata->ops->post_suspend(mmdvfs);
- break;
+err_unregister_up:
+ if (mdata->up_count)
+ mmdvfs_up_unregister(mmdvfs, MMDVFS_UP_VCP);
- default:
- break;
- }
+ return ret;
+}
- return NOTIFY_DONE;
+/*
+ * mmdvfs_init_kthread - Async initialization thread
+ * @data: MMDVFS device pointer
+ *
+ * Wait for VCP/MMUP ready before completing initialization.
+ *
+ * Return: 0 on success, -ETIMEDOUT on timeout
+ */
+static int mmdvfs_init_kthread(void *data)
+{
+ return mmdvfs_init_up(data, true);
}
/*
@@ -328,16 +346,6 @@ static int mmdvfs_probe(struct platform_device *pdev)
data->ops = pdata->ops;
data->version = pdata->soc_data->version;
- if (data->version == MMDVFS_VERSION_HWCCF_DVFS_VOTER) {
- data->hwccf_voter_priv = devm_kzalloc(&pdev->dev,
- sizeof(*data->hwccf_voter_priv),
- GFP_KERNEL);
- if (!data->hwccf_voter_priv)
- return -ENOMEM;
-
- data->hwccf_voter_priv->mmdvfs = mmdvfs;
- }
-
ret = mmdvfs_parse_dt(mmdvfs);
if (ret) {
mmdvfs_err(mmdvfs->dev, "Failed to parse device tree: %d\n", ret);
@@ -358,38 +366,52 @@ static int mmdvfs_probe(struct platform_device *pdev)
}
}
- data->init_done = true;
+ if (pdata->soc_data->vote_requires_up_ready) {
+ ret = mmdvfs_init_up(mmdvfs, false);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev,
+ "Failed to initialize UP before clock registration: %d\n",
+ ret);
+ goto err_deinit_hw;
+ }
+ }
ret = mmdvfs_register_clocks(mmdvfs);
if (ret) {
mmdvfs_err(mmdvfs->dev, "Failed to register clocks: %d\n", ret);
- goto err_deinit_hw;
- }
-
- data->pm_notifier.notifier_call = mmdvfs_pm_notifier_callback;
- data->pm_notifier.priority = 0;
- data->pm_suspended = false;
- ret = register_pm_notifier(&data->pm_notifier);
- if (ret) {
- mmdvfs_err(mmdvfs->dev, "Failed to register PM notifier: %d\n", ret);
- goto err_unregister_clocks;
+ goto err_unregister_up;
}
- mmdvfs_info(mmdvfs->dev, "PM notifier registered\n");
ret = mmdvfs_register_device(mmdvfs);
if (ret) {
mmdvfs_err(mmdvfs->dev, "Failed to register device: %d\n", ret);
- goto err_unregister_pm_notifier;
+ goto err_unregister_up;
}
+ if (pdata->soc_data->vote_requires_up_ready) {
+ mmdvfs_dbg(mmdvfs->dev,
+ "UP ready before MMDVFS clock provider registration\n");
+ } else {
+ /* Initialize VCP/MMUP asynchronously and wait for callback ready. */
+ data->init_task = kthread_run(mmdvfs_init_kthread, mmdvfs,
+ "mmdvfs-init-kthread");
+ if (IS_ERR(data->init_task)) {
+ mmdvfs_warn(mmdvfs->dev,
+ "Failed to launch init kthread: %ld (non-fatal)\n",
+ PTR_ERR(data->init_task));
+ data->init_task = NULL;
+ } else {
+ mmdvfs_dbg(mmdvfs->dev, "Init kthread launched successfully\n");
+ }
+ }
+
+ mmdvfs_debug_init(mmdvfs);
mmdvfs_info(mmdvfs->dev, "MMDVFS driver probed successfully\n");
return 0;
-err_unregister_pm_notifier:
- unregister_pm_notifier(&data->pm_notifier);
-
-err_unregister_clocks:
- mmdvfs_unregister_clocks(mmdvfs);
+err_unregister_up:
+ if (data->up_count)
+ mmdvfs_up_unregister(mmdvfs, MMDVFS_UP_VCP);
err_deinit_hw:
if (data->ops && data->ops->deinit_hw)
@@ -409,14 +431,20 @@ static void mmdvfs_remove(struct platform_device *pdev)
struct mmdvfs_device *mmdvfs = platform_get_drvdata(pdev);
struct mmdvfs_data *data = mmdvfs->data;
- unregister_pm_notifier(&data->pm_notifier);
- mmdvfs_dbg(mmdvfs->dev, "PM notifier unregistered\n");
+ mmdvfs_debug_exit(mmdvfs);
- mmdvfs_unregister_clocks(mmdvfs);
+ if (data->init_task) {
+ kthread_stop(data->init_task);
+ data->init_task = NULL;
+ mmdvfs_dbg(mmdvfs->dev, "Init kthread stopped\n");
+ }
if (data->ops && data->ops->deinit_hw)
data->ops->deinit_hw(mmdvfs);
+ if (data->up_count)
+ mmdvfs_up_unregister(mmdvfs, MMDVFS_UP_VCP);
+
mmdvfs_unregister_device(mmdvfs);
mmdvfs_info(mmdvfs->dev, "MMDVFS driver removed\n");
@@ -447,6 +475,7 @@ static struct platform_driver mmdvfs_driver = {
.driver = {
.name = "mediatek-mmdvfs",
.of_match_table = mmdvfs_of_match,
+ .suppress_bind_attrs = true,
},
};
@@ -478,7 +507,6 @@ struct mmdvfs_device *mmdvfs_find_device_by_version(enum mmdvfs_version_type ver
return found;
}
-EXPORT_SYMBOL_GPL(mmdvfs_find_device_by_version);
static int mmdvfs_register_device(struct mmdvfs_device *mmdvfs)
{
@@ -512,69 +540,111 @@ static void mmdvfs_unregister_device(struct mmdvfs_device *mmdvfs)
mutex_unlock(&mmdvfs_device_list_lock);
}
-int mtk_mmdvfs_camera_notify(bool enable)
+/* HWCCF voter - Memory and SRAM management via multi-UP architecture */
+void *mmdvfs_get_mmup_base(phys_addr_t *pa)
{
struct mmdvfs_device *mmdvfs;
+ struct mmdvfs_up_instance *hfrp_instance;
mmdvfs = mmdvfs_find_device_any();
- if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
- !mmdvfs->data->ops->camera_notify)
- return -EOPNOTSUPP;
+ if (!mmdvfs || !mmdvfs->data)
+ return NULL;
- return mmdvfs->data->ops->camera_notify(mmdvfs, enable);
+ /* HFRP UP returns MMUP base with MMDVFS_MMUP_MEM_ID */
+ hfrp_instance = mmdvfs_up_get_instance(mmdvfs, MMDVFS_UP_VCP);
+ if (!hfrp_instance || !hfrp_instance->ops || !hfrp_instance->ops->get_base)
+ return NULL;
+
+ return hfrp_instance->ops->get_base(mmdvfs, MMDVFS_MMUP_MEM_ID, pa);
}
-EXPORT_SYMBOL_GPL(mtk_mmdvfs_camera_notify);
+EXPORT_SYMBOL_GPL(mmdvfs_get_mmup_base);
-int mtk_mmdvfs_genpd_notify(u8 idx, bool enable)
+void *mmdvfs_get_vcp_base(phys_addr_t *pa)
{
struct mmdvfs_device *mmdvfs;
+ struct mmdvfs_up_instance *hfrp_instance;
mmdvfs = mmdvfs_find_device_any();
- if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
- !mmdvfs->data->ops->genpd_notify)
- return -EOPNOTSUPP;
+ if (!mmdvfs || !mmdvfs->data)
+ return NULL;
+
+ /* HFRP UP returns VCP base with MMDVFS_VCP_MEM_ID */
+ hfrp_instance = mmdvfs_up_get_instance(mmdvfs, MMDVFS_UP_VCP);
+ if (!hfrp_instance || !hfrp_instance->ops || !hfrp_instance->ops->get_base)
+ return NULL;
- return mmdvfs->data->ops->genpd_notify(mmdvfs, idx, enable);
+ return hfrp_instance->ops->get_base(mmdvfs, MMDVFS_VCP_MEM_ID, pa);
}
-EXPORT_SYMBOL_GPL(mtk_mmdvfs_genpd_notify);
+EXPORT_SYMBOL_GPL(mmdvfs_get_vcp_base);
-int mtk_mmdvfs_set_avs(u8 idx, u32 aging, u32 fresh)
+bool mmdvfs_get_mmup_sram_enable(void)
{
struct mmdvfs_device *mmdvfs;
mmdvfs = mmdvfs_find_device_any();
- if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
- !mmdvfs->data->ops->set_avs)
- return -EOPNOTSUPP;
+ if (!mmdvfs)
+ return false;
- return mmdvfs->data->ops->set_avs(mmdvfs, idx, aging, fresh);
+ return mmdvfs_vcp_get_mmup_sram_enable(mmdvfs);
}
-EXPORT_SYMBOL_GPL(mtk_mmdvfs_set_avs);
+EXPORT_SYMBOL_GPL(mmdvfs_get_mmup_sram_enable);
-int mmdvfs_set_lp_mode(bool enable)
+void __iomem *mmdvfs_get_mmup_sram(void)
{
- return -EOPNOTSUPP;
+ struct mmdvfs_device *mmdvfs;
+ struct mmdvfs_up_instance *hfrp_instance;
+
+ mmdvfs = mmdvfs_find_device_any();
+ if (!mmdvfs || !mmdvfs->data)
+ return NULL;
+
+ /* HFRP UP manages MMUP SRAM */
+ hfrp_instance = mmdvfs_up_get_instance(mmdvfs, MMDVFS_UP_VCP);
+ if (!hfrp_instance || !hfrp_instance->ops || !hfrp_instance->ops->get_sram)
+ return NULL;
+
+ return hfrp_instance->ops->get_sram(mmdvfs);
}
-EXPORT_SYMBOL_GPL(mmdvfs_set_lp_mode);
+EXPORT_SYMBOL_GPL(mmdvfs_get_mmup_sram);
-int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable)
+/* HWCCF voter - Power management through HFRP UP architecture */
+int mtk_mmdvfs_enable_vcp(const bool enable, const u8 idx)
{
struct mmdvfs_device *mmdvfs;
+ struct mmdvfs_up_instance *hfrp_instance;
+ int ret;
mmdvfs = mmdvfs_find_device_any();
- if (!mmdvfs || !mmdvfs->data || !mmdvfs->data->ops ||
- !mmdvfs->data->ops->camsv_dc_enable)
+ if (!mmdvfs || !mmdvfs->data)
+ return -ENODEV;
+
+ mmdvfs_dbg(mmdvfs->dev, "[VCP] %s VCP (idx=%u)\n",
+ enable ? "enable" : "disable", idx);
+
+ /* Get HFRP UP instance (VCP + MMUP unified) */
+ hfrp_instance = mmdvfs_up_get_instance(mmdvfs, MMDVFS_UP_VCP);
+ if (!hfrp_instance || !hfrp_instance->ops || !hfrp_instance->ops->enable)
return -EOPNOTSUPP;
- return mmdvfs->data->ops->camsv_dc_enable(mmdvfs, idx, enable);
+ ret = hfrp_instance->ops->enable(mmdvfs, enable, idx);
+ mmdvfs_dbg(mmdvfs->dev, "[VCP] %s complete, ret=%d\n",
+ enable ? "enable" : "disable", ret);
+
+ return ret;
}
-EXPORT_SYMBOL_GPL(mtk_mmdvfs_camsv_dc_enable);
+EXPORT_SYMBOL_GPL(mtk_mmdvfs_enable_vcp);
-int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx)
+bool mmdvfs_get_mmup_enable(void)
{
- return -EOPNOTSUPP;
+ struct mmdvfs_device *mmdvfs;
+
+ mmdvfs = mmdvfs_find_device_any();
+ if (!mmdvfs)
+ return false;
+
+ return mmdvfs_vcp_get_mmup_enable(mmdvfs);
}
-EXPORT_SYMBOL_GPL(mtk_mmdvfs_enable_ccu);
+EXPORT_SYMBOL_GPL(mmdvfs_get_mmup_enable);
MODULE_DESCRIPTION("MediaTek MMDVFS Driver");
MODULE_AUTHOR("MediaTek Inc.");
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h b/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
index df16e38d78c8..2aaec44a8db7 100644
--- a/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
@@ -10,10 +10,12 @@
#include <linux/clk-provider.h>
#include <linux/device.h>
+#include <linux/kthread.h>
#include <linux/mutex.h>
-#include <linux/notifier.h>
#include <linux/platform_device.h>
+#include "mmdvfs-up-priv.h"
+
struct dentry;
#define MMDVFS_MAX_LEVELS 8
@@ -27,6 +29,60 @@ enum mmdvfs_version_type {
MMDVFS_VERSION_HWCCF_DVFS_VOTER = 1, /* HWCCF DVFS voter */
};
+/* HWCCF voter configuration - Power User Definitions */
+/*
+ * VCP Power User Index - must match VCP firmware definition
+ * Used by mtk_mmdvfs_enable_vcp() to track per-user power reference count
+ */
+enum mmdvfs_vcp_pwr_usr {
+ VCP_PWR_USR_MMDVFS_INIT = 0,
+ VCP_PWR_USR_MMDVFS_RESERVED1,
+ VCP_PWR_USR_MMDVFS_RESERVED2,
+ VCP_PWR_USR_MMDVFS_VOTE,
+ VCP_PWR_USR_MMDVFS_CCU,
+ VCP_PWR_USR_MMDVFS_RST,
+ VCP_PWR_USR_MMQOS,
+ VCP_PWR_USR_CAM,
+ VCP_PWR_USR_IMG,
+ VCP_PWR_USR_PDA,
+ VCP_PWR_USR_SENIF,
+ VCP_PWR_USR_VDEC,
+ VCP_PWR_USR_VFMT,
+ VCP_PWR_USR_SMI,
+ VCP_PWR_USR_DISP,
+ VCP_PWR_USR_MDP,
+ VCP_PWR_USR_MML,
+ VCP_PWR_USR_VENC,
+ VCP_PWR_USR_JPEGDEC,
+ VCP_PWR_USR_JPEGENC,
+ VCP_PWR_USR_NUM
+};
+
+/* IPI function codes used by this driver; values match VCP/MMUP firmware. */
+enum mmdvfs_ipi_func {
+ FUNC_MMDVFS_INIT = 0, /* Initialize firmware-side MMDVFS */
+ FUNC_MMDVFSRC_INIT = 9, /* Initialize resource controller */
+};
+
+/**
+ * struct mmdvfs_vcp_ipi_data - VCP IPI message format
+ * @func: Function code
+ * @idx: Index parameter
+ * @opp: OPP level
+ * @ack: High 32-bit of 64-bit parameter
+ * @base: Low 32-bit of 64-bit parameter
+ *
+ * For FUNC_MMDVFS_INIT/MMDVFSRC_INIT, the 64-bit shared memory IOVA is split
+ * across ack and base.
+ */
+struct mmdvfs_vcp_ipi_data {
+ u8 func;
+ u8 idx;
+ u8 opp;
+ u8 ack;
+ u32 base;
+} __packed;
+
#define MAX_OPP 8
/* MMDVFS RC domains */
@@ -102,35 +158,16 @@ struct mmdvfs_user {
struct mmdvfs_device *mmdvfs;
};
-/**
- * struct mmdvfs_hwccf_voter_priv - HWCCF DVFS Voter specific data
- * @hwccf_voter_support: HWCCF voter support flag
- * @step_idx: Step index
- * @dpsw_thr: DPSW threshold
- * @mmdvfs: MMDVFS device reference
- * @genpd_wq: GenPD workqueue
- */
-struct mmdvfs_hwccf_voter_priv {
- bool hwccf_voter_support;
- u8 step_idx;
- int dpsw_thr;
- struct mmdvfs_device *mmdvfs;
- struct workqueue_struct *genpd_wq;
-};
+/* Forward declarations for internal types */
+struct mmdvfs_up_instance;
+struct mmdvfs_up_ops;
/**
* struct mmdvfs_ops - Platform-specific operations
* @probe: Platform-specific probe function
* @hw_vote: Submit frequency/voltage vote to hardware
- * @get_current_level: Get current hardware level
* @init_hw: Initialize hardware
* @deinit_hw: Deinitialize hardware
- * @suspend_prepare: Prepare for suspend
- * @post_suspend: Post-suspend cleanup
- * @camera_notify: Camera power notification
- * @genpd_notify: Generic power domain notification
- * @set_avs: Set AVS (Adaptive Voltage Scaling) parameters
- * @camsv_dc_enable: Enable/disable CAMSV DC mode
*
* MT8196 implements hw_vote through the HWCCF voter.
*/
@@ -139,21 +176,9 @@ struct mmdvfs_ops {
int (*probe)(struct mmdvfs_device *mmdvfs);
int (*hw_vote)(struct mmdvfs_device *mmdvfs, const u8 user_id, const u8 level);
- int (*get_current_level)(struct mmdvfs_device *mmdvfs, u32 pwr_id);
- int (*dvfsrc_rg_dump)(struct mmdvfs_device *mmdvfs);
- int (*dvfsrc_record_dump)(struct mmdvfs_device *mmdvfs);
int (*init_hw)(struct mmdvfs_device *mmdvfs);
void (*deinit_hw)(struct mmdvfs_device *mmdvfs);
- /* Power management operations */
- void (*suspend_prepare)(struct mmdvfs_device *mmdvfs);
- void (*post_suspend)(struct mmdvfs_device *mmdvfs);
-
- /* HWCCF DVFS voter - Extended operations */
- int (*camera_notify)(struct mmdvfs_device *mmdvfs, bool enable);
- int (*genpd_notify)(struct mmdvfs_device *mmdvfs, u8 idx, bool enable);
- int (*set_avs)(struct mmdvfs_device *mmdvfs, u8 idx, u32 aging, u32 fresh);
- int (*camsv_dc_enable)(struct mmdvfs_device *mmdvfs, u8 idx, bool enable);
};
/**
@@ -169,10 +194,10 @@ struct mmdvfs_ops {
* @mux_num: Number of MUXes
* @user_num: Number of Users
* @lock: Device-wide mutex for synchronization
- * @hwccf_voter_priv: HWCCF DVFS Voter private data (dynamically allocated)
+ * @up_instances: Multiple UP instances (VCP+MMUP simultaneous support)
+ * @up_count: Number of UP instances
* @init_done: Initialization completion flag
- * @pm_notifier: Suspend/resume notifier
- * @pm_suspended: Whether system suspend is in progress
+ * @init_task: Async initialization thread
*/
struct mmdvfs_data {
struct device *dev;
@@ -185,19 +210,18 @@ struct mmdvfs_data {
u8 rc_num;
u8 mux_num;
u8 user_num;
- /* Protects device-wide state. */
+ /* Protects UP instance registration. */
struct mutex lock;
- /* Hardware-specific private data (dynamically allocated) */
- struct mmdvfs_hwccf_voter_priv *hwccf_voter_priv;
+ /* Multiple UP instances (VCP+MMUP simultaneous support) */
+ struct mmdvfs_up_instance up_instances[MMDVFS_UP_MAX];
+ u8 up_count;
/* Shared status and control */
bool init_done;
- /* PM notifier for suspend/resume handling */
- struct notifier_block pm_notifier;
- bool pm_suspended;
-
+ /* Async initialization thread */
+ struct task_struct *init_task;
};
/**
@@ -210,6 +234,9 @@ struct mmdvfs_device {
struct device *dev;
struct mmdvfs_data *data;
struct clk_hw_onecell_data *clk_data;
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+ struct dentry *debugfs_dir;
+#endif
};
/* Helper macros */
@@ -224,6 +251,7 @@ struct mmdvfs_device {
* @user_table: Array of User/Client configurations
* @user_num: Number of Users in this SoC
* @version: MMDVFS voting mechanism
+ * @vote_requires_up_ready: User votes require the UP backend to be ready
*
* This structure defines the per-SoC topology statically in code.
* Allocated and configured by each per-SoC driver file.
@@ -236,6 +264,7 @@ struct mmdvfs_soc_data {
const struct mmdvfs_user *user_table;
u8 user_num;
enum mmdvfs_version_type version;
+ bool vote_requires_up_ready;
};
/**
@@ -253,7 +282,6 @@ struct mmdvfs_platform_data {
/* Core functions */
int mmdvfs_register_clocks(struct mmdvfs_device *mmdvfs);
-void mmdvfs_unregister_clocks(struct mmdvfs_device *mmdvfs);
int mmdvfs_parse_dt(struct mmdvfs_device *mmdvfs);
/* Platform-specific functions to be implemented */
@@ -262,14 +290,26 @@ extern const struct mmdvfs_ops mmdvfs_mt8196_ops;
/* Per-SoC topology data */
extern const struct mmdvfs_soc_data mmdvfs_mt8196_soc_data;
+/* UP management functions (public API) */
+int mmdvfs_up_register(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type);
+void mmdvfs_up_unregister(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type);
+struct mmdvfs_up_instance *mmdvfs_up_get_instance(struct mmdvfs_device *mmdvfs,
+ enum mmdvfs_up_type type);
+const struct mmdvfs_up_ops *mmdvfs_up_get_ops(enum mmdvfs_up_type type);
+void *mmdvfs_up_get_priv(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type);
+int mmdvfs_up_set_priv(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type, void *priv);
+int mmdvfs_up_send_ipi(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type,
+ void *ipi_data, u32 len, const bool vcp);
+bool mmdvfs_up_get_cb_ready(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type);
+
/* Platform-specific operations */
u32 mmdvfs_get_version(void);
-int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx);
-int mtk_mmdvfs_camera_notify(bool enable);
-int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable);
-int mtk_mmdvfs_genpd_notify(u8 idx, bool enable);
-int mtk_mmdvfs_set_avs(u8 idx, u32 aging, u32 fresh);
-int mmdvfs_set_lp_mode(bool enable);
+void *mmdvfs_get_mmup_base(phys_addr_t *pa);
+void *mmdvfs_get_vcp_base(phys_addr_t *pa);
+bool mmdvfs_get_mmup_sram_enable(void);
+void __iomem *mmdvfs_get_mmup_sram(void);
+bool mmdvfs_get_mmup_enable(void);
+int mtk_mmdvfs_enable_vcp(const bool enable, const u8 idx);
/* Utility functions */
static inline bool mmdvfs_is_valid_user_id(u8 user_id)
@@ -292,6 +332,22 @@ static inline bool mmdvfs_is_valid_mux_id(u8 mux_id)
return mux_id < MMDVFS_MAX_MUXES;
}
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+void mmdvfs_debug_init(struct mmdvfs_device *mmdvfs);
+void mmdvfs_debug_exit(struct mmdvfs_device *mmdvfs);
+#else
+static inline void mmdvfs_debug_init(struct mmdvfs_device *mmdvfs) { }
+static inline void mmdvfs_debug_exit(struct mmdvfs_device *mmdvfs) { }
+#endif
+
+/* VCP power info for debug */
+int mmdvfs_vcp_get_power_info(struct mmdvfs_device *mmdvfs, int *power, int *pwr_usage);
+bool mmdvfs_vcp_get_mmup_enable(struct mmdvfs_device *mmdvfs);
+bool mmdvfs_vcp_get_mmup_sram_enable(struct mmdvfs_device *mmdvfs);
+void mmdvfs_vcp_lock_cb_mutex(struct mmdvfs_device *mmdvfs);
+void mmdvfs_vcp_unlock_cb_mutex(struct mmdvfs_device *mmdvfs);
+int mmdvfs_vcp_release_init(struct mmdvfs_device *mmdvfs);
+
/* Logging macros */
#define mmdvfs_dbg(dev, fmt, args...) \
dev_dbg(dev, "[mmdvfs] " fmt, ##args)
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h b/drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h
new file mode 100644
index 000000000000..592db7f46d29
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ *
+ * MediaTek MMDVFS Microprocessor Abstraction Layer - Private Header
+ */
+
+#ifndef __MMDVFS_UP_PRIV_H__
+#define __MMDVFS_UP_PRIV_H__
+
+#include <linux/types.h>
+
+/* Forward declarations */
+struct mmdvfs_device;
+
+/* UP (microprocessor) types */
+enum mmdvfs_up_type {
+ MMDVFS_UP_VCP = 0, /* Video Co-Processor (VCP RV55 with MMUP RV33 support) */
+ MMDVFS_UP_MAX,
+};
+
+/**
+ * struct mmdvfs_up_ops - Micrsoprocessor abstraction operations
+ * @init: Initialize microprocessor communication
+ * @deinit: Deinitialize microprocessor communication
+ * @send_ipi: Send IPI message to microprocessor
+ * @enable: Enable/disable microprocessor power
+ * @get_base: Get microprocessor base address by mem_id (MMDVFS_VCP_MEM_ID or MMDVFS_MMUP_MEM_ID)
+ * @get_sram: Get SRAM virtual address
+ * @get_cb_ready: Get callback ready status (VCP/MMUP ready)
+ *
+ * This structure defines the operations that each UP implementation must provide.
+ * Different microprocessor types (VCP, ADSP, SCP) implement these operations differently.
+ */
+struct mmdvfs_up_ops {
+ int (*init)(struct mmdvfs_device *mmdvfs);
+ void (*deinit)(struct mmdvfs_device *mmdvfs);
+ int (*send_ipi)(struct mmdvfs_device *mmdvfs, void *data, u32 len, const bool vcp);
+
+ /* Hardware-specific microprocessor operations */
+ int (*enable)(struct mmdvfs_device *mmdvfs, bool enable, u8 idx);
+ void *(*get_base)(struct mmdvfs_device *mmdvfs, u32 mem_id, phys_addr_t *pa);
+ void __iomem *(*get_sram)(struct mmdvfs_device *mmdvfs);
+ bool (*get_cb_ready)(struct mmdvfs_device *mmdvfs);
+};
+
+/* UP instance structure for multiple UP support */
+struct mmdvfs_up_instance {
+ enum mmdvfs_up_type type;
+ const struct mmdvfs_up_ops *ops;
+ void *priv_data;
+};
+
+/* UP implementation declarations */
+extern const struct mmdvfs_up_ops mmdvfs_vcp_ops; /* VCP (Video Co-Processor) with MMUP support */
+
+#endif /* __MMDVFS_UP_PRIV_H__ */
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-up.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-up.c
new file mode 100644
index 000000000000..cdf994889390
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-up.c
@@ -0,0 +1,275 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ *
+ * MediaTek MMDVFS Microprocessor Abstraction Layer
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+
+#include "mmdvfs-internal.h"
+#include "mmdvfs-up-priv.h"
+
+/* ========== UP (Microprocessor) Management Functions ========== */
+
+/*
+ * mmdvfs_up_register - Register UP instance
+ * @mmdvfs: MMDVFS device structure
+ * @type: UP type
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+int mmdvfs_up_register(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type)
+{
+ struct mmdvfs_data *data;
+ struct mmdvfs_up_instance *up;
+ const struct mmdvfs_up_ops *ops;
+ int ret = 0;
+
+ if (!mmdvfs || !mmdvfs->data) {
+ pr_err("mmdvfs: Invalid device reference\n");
+ return -EINVAL;
+ }
+
+ data = mmdvfs->data;
+
+ if (data->up_count >= MMDVFS_UP_MAX) {
+ mmdvfs_err(mmdvfs->dev, "Maximum UP instances reached\n");
+ return -ENOSPC;
+ }
+
+ ops = mmdvfs_up_get_ops(type);
+ if (!ops) {
+ mmdvfs_err(mmdvfs->dev, "UP operations not found for type %d\n", type);
+ return -ENODEV;
+ }
+
+ mutex_lock(&data->lock);
+
+ for (int i = 0; i < data->up_count; i++) {
+ if (data->up_instances[i].type == type) {
+ mmdvfs_err(mmdvfs->dev,
+ "UP type %d already registered\n", type);
+ ret = -EEXIST;
+ goto unlock;
+ }
+ }
+
+ up = &data->up_instances[data->up_count];
+ up->type = type;
+ up->ops = ops;
+ up->priv_data = NULL;
+
+ data->up_count++;
+
+ if (ops->init) {
+ ret = ops->init(mmdvfs);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev,
+ "Failed to initialize UP type %d: %d\n",
+ type, ret);
+ data->up_count--;
+ goto unlock;
+ }
+ }
+
+ mmdvfs_info(mmdvfs->dev, "Registered UP type %d\n", type);
+
+unlock:
+ mutex_unlock(&data->lock);
+ return ret;
+}
+
+/*
+ * mmdvfs_up_unregister - Unregister UP instance
+ * @mmdvfs: MMDVFS device structure
+ * @type: UP type
+ */
+void mmdvfs_up_unregister(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type)
+{
+ struct mmdvfs_data *data;
+ struct mmdvfs_up_instance *up;
+ int i, found = -1;
+
+ if (!mmdvfs || !mmdvfs->data) {
+ pr_err("mmdvfs: Invalid device reference\n");
+ return;
+ }
+
+ data = mmdvfs->data;
+
+ mutex_lock(&data->lock);
+
+ for (i = 0; i < data->up_count; i++) {
+ if (data->up_instances[i].type == type) {
+ found = i;
+ break;
+ }
+ }
+
+ if (found < 0) {
+ mmdvfs_err(mmdvfs->dev, "UP type %d not found\n", type);
+ goto unlock;
+ }
+
+ up = &data->up_instances[found];
+
+ if (up->ops && up->ops->deinit)
+ up->ops->deinit(mmdvfs);
+
+ for (i = found; i < data->up_count - 1; i++)
+ data->up_instances[i] = data->up_instances[i + 1];
+ data->up_count--;
+
+ mmdvfs_info(mmdvfs->dev, "Unregistered UP type %d\n", type);
+
+unlock:
+ mutex_unlock(&data->lock);
+}
+
+/*
+ * mmdvfs_up_get_instance - Get UP instance
+ * @mmdvfs: MMDVFS device structure
+ * @type: UP type
+ *
+ * Return: Pointer to UP instance, or NULL if not found
+ */
+struct mmdvfs_up_instance *
+mmdvfs_up_get_instance(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type)
+{
+ struct mmdvfs_data *data;
+ int i;
+
+ if (!mmdvfs || !mmdvfs->data) {
+ pr_err("mmdvfs: Invalid device reference\n");
+ return NULL;
+ }
+
+ data = mmdvfs->data;
+
+ for (i = 0; i < data->up_count; i++) {
+ if (data->up_instances[i].type == type)
+ return &data->up_instances[i];
+ }
+
+ return NULL;
+}
+
+void *mmdvfs_up_get_priv(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type)
+{
+ struct mmdvfs_up_instance *up;
+
+ up = mmdvfs_up_get_instance(mmdvfs, type);
+ if (!up)
+ return NULL;
+
+ return up->priv_data;
+}
+
+int mmdvfs_up_set_priv(struct mmdvfs_device *mmdvfs,
+ enum mmdvfs_up_type type, void *priv)
+{
+ struct mmdvfs_up_instance *up;
+
+ up = mmdvfs_up_get_instance(mmdvfs, type);
+ if (!up)
+ return -ENODEV;
+
+ up->priv_data = priv;
+ return 0;
+}
+
+/*
+ * mmdvfs_up_get_ops - Get UP operations
+ * @type: UP type
+ *
+ * Return: Pointer to UP operations, or NULL if not found
+ */
+const struct mmdvfs_up_ops *mmdvfs_up_get_ops(enum mmdvfs_up_type type)
+{
+ switch (type) {
+ case MMDVFS_UP_VCP:
+ return &mmdvfs_vcp_ops;
+ default:
+ pr_err("mmdvfs: Unknown UP type %d\n", type);
+ return NULL;
+ }
+}
+
+/*
+ * mmdvfs_up_send_ipi - Send IPI to UP
+ * @mmdvfs: MMDVFS device structure
+ * @type: UP type
+ * @data: IPI data
+ * @len: Data length
+ * @vcp: true = use VCP, false = auto select VCP/MMUP
+ */
+int mmdvfs_up_send_ipi(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type,
+ void *ipi_data, u32 len, const bool vcp)
+{
+ struct mmdvfs_up_instance *up;
+ int ret = 0;
+
+ if (!mmdvfs) {
+ pr_err("mmdvfs: Invalid device reference\n");
+ return -EINVAL;
+ }
+
+ mmdvfs_dbg(mmdvfs->dev, "[VCP_IPI] send_ipi: type=%d len=%u vcp=%d\n",
+ type, len, vcp);
+
+ up = mmdvfs_up_get_instance(mmdvfs, type);
+ if (!up) {
+ mmdvfs_err(mmdvfs->dev, "UP type %d not found\n", type);
+ return -ENODEV;
+ }
+ if (!mmdvfs_up_get_cb_ready(mmdvfs, type))
+ return -EAGAIN;
+
+ if (up->ops && up->ops->send_ipi) {
+ ret = up->ops->send_ipi(mmdvfs, ipi_data, len, vcp);
+ mmdvfs_dbg(mmdvfs->dev, "[VCP_IPI] send_ipi returned ret=%d\n", ret);
+ } else {
+ mmdvfs_err(mmdvfs->dev,
+ "UP send_ipi operation not implemented for type %d\n",
+ type);
+ ret = -EOPNOTSUPP;
+ }
+
+ return ret;
+}
+
+/*
+ * mmdvfs_up_get_cb_ready - Get UP callback ready status
+ * @mmdvfs: MMDVFS device structure
+ * @type: UP type
+ *
+ * Returns: true if UP callbacks are ready, false otherwise
+ *
+ * This function queries the UP layer to check if the microprocessor
+ * callback system is ready (VCP_EVENT_READY has been received).
+ * Used by async init kthread to wait for UP initialization.
+ */
+bool mmdvfs_up_get_cb_ready(struct mmdvfs_device *mmdvfs, enum mmdvfs_up_type type)
+{
+ struct mmdvfs_up_instance *up;
+
+ if (!mmdvfs) {
+ pr_err("mmdvfs: Invalid device reference\n");
+ return false;
+ }
+
+ up = mmdvfs_up_get_instance(mmdvfs, type);
+ if (!up) {
+ mmdvfs_err(mmdvfs->dev, "UP type %d not found\n", type);
+ return false;
+ }
+
+ if (up->ops && up->ops->get_cb_ready)
+ return up->ops->get_cb_ready(mmdvfs);
+
+ /* If not implemented, assume ready */
+ return true;
+}
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h b/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h
new file mode 100644
index 000000000000..363fb5445859
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h
@@ -0,0 +1,104 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ *
+ * MediaTek MMDVFS VCP/MMUP Shared Memory Layout
+ */
+
+#ifndef __MMDVFS_VCP_MEMORY_H
+#define __MMDVFS_VCP_MEMORY_H
+
+/*
+ * Shared Memory Register Offsets
+ *
+ * Base address is obtained via mtk_vcp_ops.vcp_get_mem_virt()
+ * Usage: writel(val, mem_base + MEM_VOTE_OPP_PWR(idx));
+ *
+ * These offsets match the VCP firmware memory layout exactly.
+ */
+
+/* Control and sync registers */
+#define MEM_LOG_FLAG 0x0
+#define MEM_FREERUN 0x4
+#define MEM_VSRAM_VOL 0x8
+
+/* IPI sync registers - used for VCP/MMUP communication */
+#define MEM_IPI_SYNC_FUNC 0xC
+#define MEM_IPI_SYNC_DATA 0x10
+#define MEM_VMRC_LOG_FLAG 0x14
+
+/* AVS aging/fresh count registers - 2 users (CAM, VDE/IMG) */
+#define MEM_AGING_CNT(x) (0x20 + 0x4 * (x))
+#define MEM_AGING_CNT_COUNT 2
+#define MEM_FRESH_CNT(x) (0x28 + 0x4 * (x))
+
+/*
+ * Firmware-owned control slots. Linux initializes them to MAX_OPP so the
+ * firmware treats them as inactive; RFC v1 does not expose an AP control API
+ * for these slots.
+ */
+#define MEM_FW_RSVD_OPP_PWR(x) (0x30 + 0x4 * (x))
+#define MEM_FW_RSVD_OPP_PWR_COUNT 4
+#define MEM_VOTE_OPP_PWR(x) (0x40 + 0x4 * (x))
+
+/* User OPP registers - 14 users */
+#define MEM_VOTE_OPP_USR(x) (0x50 + 0x4 * (x))
+#define MEM_VOTE_OPP_USR_COUNT 14
+
+/* Low power and VMM ceiling control */
+#define MEM_LP_MODE 0x88
+#define MEM_VMM_CEIL_ENABLE 0x8C
+
+/* Clock mux control */
+#define MEM_CLKMUX_ENABLE 0x90
+#define MEM_CLKMUX_ENABLE_DONE 0x94
+#define MEM_VMM_EFUSE_LOW 0x98
+#define MEM_VMM_EFUSE_HIGH 0x9C
+
+/* VMM OPP voltage and VDISP AVS step - 8 levels */
+#define MEM_VMM_OPP_VOLT(x) (0xA0 + 0x4 * (x))
+#define MEM_VDISP_AVS_STEP(x) (0xC0 + 0x4 * (x))
+
+/* Profile and exception registers */
+#define MEM_PROFILE_TIMES 0xE0
+#define MEM_VCP_EXC_SEC 0xE4
+#define MEM_VCP_EXC_USEC 0xE8
+#define MEM_VCP_EXC_VAL 0xEC
+
+/* User OPP timestamp and value - 32 users */
+#define MEM_USR_OPP_SEC(x) (0xF0 + 0x4 * (x))
+#define MEM_USR_OPP_USEC(x) (0x170 + 0x4 * (x))
+#define MEM_USR_OPP(x) (0x1F0 + 0x4 * (x))
+#define MEM_USR_FREQ(x) (0x270 + 0x4 * (x))
+
+/* Mux OPP registers - 16 muxes */
+#define MEM_MUX_OPP_SEC(x) (0x2F0 + 0x4 * (x))
+#define MEM_MUX_OPP_USEC(x) (0x330 + 0x4 * (x))
+#define MEM_MUX_OPP(x) (0x370 + 0x4 * (x))
+#define MEM_MUX_MIN(x) (0x3B0 + 0x4 * (x))
+#define MEM_FW_RSVD_CLK(x) (0x3F0 + 0x4 * (x))
+
+/* Power domain status - 4 domains */
+#define MEM_PWR_OPP_SEC(x) (0x430 + 0x4 * (x))
+#define MEM_PWR_OPP_USEC(x) (0x440 + 0x4 * (x))
+#define MEM_PWR_OPP(x) (0x450 + 0x4 * (x))
+#define MEM_PWR_CUR_GEAR(x) (0x460 + 0x4 * (x))
+#define MEM_FW_RSVD_VOL(x) (0x470 + 0x4 * (x))
+
+/* VMM buck control */
+#define MEM_VMM_BUCK_ON 0x480
+
+/* Power domain total time - 4 domains * 8 OPP levels, u64 */
+#define MEM_PWR_TOTAL_TIME(x, y) (0x484 + 0x40 * (x) + 0x8 * (y))
+
+/* Mux callback registers */
+#define MEM_MUX_CB_MUX_OPP 0x584
+#define MEM_MUX_CB_SEC 0x588
+#define MEM_MUX_CB_USEC 0x58C
+#define MEM_MUX_CB_END_SEC 0x590
+#define MEM_MUX_CB_END_USEC 0x594
+
+/* SRAM offset */
+#define MEM_SRAM_OFFSET 0xFFC
+
+#endif /* __MMDVFS_VCP_MEMORY_H */
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c
new file mode 100644
index 000000000000..fc6db1c89294
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c
@@ -0,0 +1,1075 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ * Author: Echo Zhang <echo.zhang@mediatek.com>
+ *
+ * MMDVFS VCP Abstraction Layer
+ * VCP (RV55) + MMUP (RV33) microprocessor management
+ */
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/remoteproc/mtk_vcp_public.h>
+#include <linux/slab.h>
+
+#include "mmdvfs-internal.h"
+#include "mmdvfs-up-priv.h"
+#include "mmdvfs-vcp-memory.h"
+
+#define VCP_IPI_TIMEOUT_MS 100
+#define VCP_MMDVFS_CMD_SET_FREQ 0x1001
+#define VCP_MMDVFS_CMD_GET_FREQ 0x1002
+#define PIN_OUT_SIZE_MMDVFS 2
+#ifndef VCP_SYNC_TIMEOUT_MS
+#define VCP_SYNC_TIMEOUT_MS 1000
+#endif
+#define VCP_IPIDEV_RETRY_MAX 100
+
+enum boot_mode_t {
+ NORMAL_BOOT = 0,
+ META_BOOT = 1,
+ RECOVERY_BOOT = 2,
+ SW_REBOOT = 3,
+ FACTORY_BOOT = 4,
+ ADVMETA_BOOT = 5,
+ ATE_FACTORY_BOOT = 6,
+ ALARM_BOOT = 7,
+ UNKNOWN_BOOT = 8,
+};
+
+static int bootmode = UNKNOWN_BOOT;
+
+/**
+ * struct mmdvfs_vcp_priv - VCP private data
+ * @mmup_enable: MMUP enable flag
+ * @vcp_feature_id: VCP feature ID
+ * @mmup_feature_id: MMUP feature ID
+ * @current_feature_id: Current registered feature ID
+ * @vcp_pdev: VCP platform device
+ * @vcp_ipi_id: VCP IPI channel ID
+ * @vcp_va: VCP shared memory virtual address
+ * @vcp_pa: VCP shared memory physical address
+ * @vcp_iova: VCP shared memory IOVA address
+ * @mmup_pdev: MMUP platform device
+ * @mmup_ipi_id: MMUP IPI channel ID
+ * @mmup_va: MMUP shared memory virtual address
+ * @mmup_pa: MMUP shared memory physical address
+ * @mmup_iova: MMUP shared memory IOVA address
+ * @mmup_sram_va: MMUP SRAM virtual address
+ * @mmup_sram_enable: MMUP SRAM enable flag
+ * @power: VCP power reference count
+ * @pwr_usage: Per-user power reference count
+ * @pwr_mutex: Power management mutex
+ * @ipi_mutex: Serializes shared-memory IPI transactions
+ * @init_ready_mask: Successful initialization IPI path
+ * @cb_ready: Initialization IPI completed
+ * @cb_mutex: Protects init_ready_mask and cb_ready
+ * @mmdvfs: MMDVFS device reference
+ * @initialized: Initialization flag
+ */
+struct mmdvfs_vcp_priv {
+ bool mmup_enable;
+ enum vcp_feature_id vcp_feature_id;
+ enum vcp_feature_id mmup_feature_id;
+ enum vcp_feature_id current_feature_id;
+
+ struct mtk_vcp_device *vcp_device;
+ struct platform_device *vcp_pdev;
+ u32 vcp_ipi_id;
+ void __iomem *vcp_va;
+ phys_addr_t vcp_pa;
+ phys_addr_t vcp_iova;
+
+ struct platform_device *mmup_pdev;
+ u32 mmup_ipi_id;
+ void __iomem *mmup_va;
+ phys_addr_t mmup_pa;
+ phys_addr_t mmup_iova;
+ void __iomem *mmup_sram_va;
+ bool mmup_sram_enable;
+
+ int power;
+ int pwr_usage[VCP_PWR_USR_NUM];
+ /* Protects power and pwr_usage. */
+ struct mutex pwr_mutex;
+ /* Serializes shared-memory writes and the following IPI sync. */
+ struct mutex ipi_mutex;
+
+ u8 init_ready_mask;
+ bool cb_ready;
+ /* Protects init_ready_mask and cb_ready. */
+ struct mutex cb_mutex;
+
+ /* VCP state flags */
+ bool vcp_stop;
+ bool rst_clk_done;
+ bool release_step_done;
+
+ struct notifier_block mmup_notifier;
+
+ struct mmdvfs_device *mmdvfs;
+ bool initialized;
+};
+
+static inline struct mmdvfs_vcp_priv *mmdvfs_vcp_priv(struct mmdvfs_device *mmdvfs)
+{
+ return mmdvfs_up_get_priv(mmdvfs, MMDVFS_UP_VCP);
+}
+
+static bool mmdvfs_vcp_is_ready(struct mmdvfs_vcp_priv *priv, enum vcp_feature_id id)
+{
+ if (!priv || !priv->vcp_device || !priv->vcp_device->ops ||
+ !priv->vcp_device->ops->vcp_is_ready)
+ return false;
+
+ return priv->vcp_device->ops->vcp_is_ready(priv->vcp_device, id);
+}
+
+static int mmdvfs_vcp_register_feature(struct mmdvfs_vcp_priv *priv, enum vcp_feature_id id)
+{
+ if (!priv || !priv->vcp_device || !priv->vcp_device->ops ||
+ !priv->vcp_device->ops->register_feature)
+ return -ENODEV;
+
+ return priv->vcp_device->ops->register_feature(priv->vcp_device, id);
+}
+
+static int mmdvfs_vcp_deregister_feature(struct mmdvfs_vcp_priv *priv, enum vcp_feature_id id)
+{
+ if (!priv || !priv->vcp_device || !priv->vcp_device->ops ||
+ !priv->vcp_device->ops->deregister_feature)
+ return -ENODEV;
+
+ return priv->vcp_device->ops->deregister_feature(priv->vcp_device, id);
+}
+
+static void mmdvfs_vcp_register_notify(struct mmdvfs_vcp_priv *priv, enum vcp_feature_id id,
+ struct notifier_block *nb)
+{
+ if (priv && priv->vcp_device && priv->vcp_device->ops &&
+ priv->vcp_device->ops->register_notify)
+ priv->vcp_device->ops->register_notify(priv->vcp_device, id, nb);
+}
+
+static void mmdvfs_vcp_unregister_notify(struct mmdvfs_vcp_priv *priv, enum vcp_feature_id id,
+ struct notifier_block *nb)
+{
+ if (priv && priv->vcp_device && priv->vcp_device->ops &&
+ priv->vcp_device->ops->unregister_notify)
+ priv->vcp_device->ops->unregister_notify(priv->vcp_device, id, nb);
+}
+
+static struct mtk_ipi_device *mmdvfs_vcp_get_ipidev(struct mmdvfs_vcp_priv *priv)
+{
+ if (!priv || !priv->vcp_device)
+ return NULL;
+
+ return vcp_get_ipidev(priv->vcp_device);
+}
+
+/*
+ * mmdvfs_get_bootmode - Get system boot mode
+ *
+ * Query boot mode from device tree /chosen node
+ */
+static void mmdvfs_get_bootmode(void)
+{
+ struct device_node *np_chosen;
+ struct tag_bootmode {
+ u32 size;
+ u32 tag;
+ u32 bootmode;
+ u32 boottype;
+ } *tag;
+
+ if (bootmode < UNKNOWN_BOOT)
+ return;
+
+ np_chosen = of_find_node_by_path("/chosen");
+ if (!np_chosen) {
+ bootmode = NORMAL_BOOT;
+ return;
+ }
+
+ tag = (struct tag_bootmode *)of_get_property(np_chosen, "atag,boot", NULL);
+ of_node_put(np_chosen);
+
+ if (tag)
+ bootmode = tag->bootmode;
+ else
+ bootmode = NORMAL_BOOT;
+}
+
+/*
+ * mmdvfs_vcp_wait_target_ready - Wait for VCP/MMUP ready
+ */
+static int
+mmdvfs_vcp_wait_target_ready(struct mmdvfs_device *mmdvfs,
+ struct mmdvfs_vcp_priv *priv,
+ enum vcp_feature_id target_feature,
+ const char *target_name,
+ struct mmdvfs_vcp_ipi_data *ipi_data)
+{
+ int retry = 0;
+ bool hw_ready = mmdvfs_vcp_is_ready(priv, target_feature);
+
+ while (!hw_ready || !READ_ONCE(priv->cb_ready) || priv->rst_clk_done) {
+ if (!READ_ONCE(priv->cb_ready) &&
+ (ipi_data->func == FUNC_MMDVFS_INIT ||
+ ipi_data->func == FUNC_MMDVFSRC_INIT))
+ break;
+
+ if (++retry > VCP_SYNC_TIMEOUT_MS) {
+ mmdvfs_err(mmdvfs->dev,
+ "%s not ready after %d ms (func=%u)\n",
+ target_name, VCP_SYNC_TIMEOUT_MS, ipi_data->func);
+ return -ETIMEDOUT;
+ }
+ mdelay(1);
+ hw_ready = mmdvfs_vcp_is_ready(priv, target_feature);
+ }
+
+ return 0;
+}
+
+/*
+ * mmdvfs_vcp_send_and_sync - Send IPI and sync
+ */
+static int
+mmdvfs_vcp_send_and_sync(struct mmdvfs_device *mmdvfs,
+ struct mmdvfs_vcp_priv *priv,
+ struct mtk_ipi_device *ipidev,
+ enum vcp_feature_id target_feature,
+ u32 target_ipi_id,
+ const char *target_name,
+ void *data,
+ struct mmdvfs_vcp_ipi_data *ipi_data,
+ void __iomem *mem_base,
+ u32 sync_func_val)
+{
+ int ret, retry;
+
+ if (!priv) {
+ mmdvfs_err(mmdvfs->dev, "%s IPI path invalid: priv is NULL\n",
+ target_name);
+ return -ENODEV;
+ }
+
+ if (!mem_base || !ipidev || !priv->vcp_device ||
+ !priv->vcp_device->ipi_ops || !priv->vcp_device->ipi_ops->ipi_send) {
+ mmdvfs_err(mmdvfs->dev,
+ "%s IPI path invalid: mem=%p ipidev=%p ipi_ops=%p ipi_send=%p\n",
+ target_name, mem_base, ipidev,
+ priv->vcp_device ? priv->vcp_device->ipi_ops : NULL,
+ priv->vcp_device && priv->vcp_device->ipi_ops ?
+ priv->vcp_device->ipi_ops->ipi_send : NULL);
+ return -ENODEV;
+ }
+
+ mutex_lock(&priv->pwr_mutex);
+
+ writel(0, mem_base + MEM_IPI_SYNC_DATA);
+ writel(sync_func_val | (1 << ipi_data->func),
+ mem_base + MEM_IPI_SYNC_FUNC);
+
+ mutex_lock(&priv->cb_mutex);
+ if (!priv->cb_ready &&
+ ipi_data->func != FUNC_MMDVFS_INIT &&
+ ipi_data->func != FUNC_MMDVFSRC_INIT) {
+ mutex_unlock(&priv->cb_mutex);
+ mmdvfs_err(mmdvfs->dev, "%s cb_ready false before IPI\n", target_name);
+ mutex_unlock(&priv->pwr_mutex);
+ return -ETIMEDOUT;
+ }
+ mutex_unlock(&priv->cb_mutex);
+ mutex_unlock(&priv->pwr_mutex);
+
+ ret = priv->vcp_device->ipi_ops->ipi_send(ipidev, target_ipi_id,
+ data, PIN_OUT_SIZE_MMDVFS);
+ if (ret != IPI_ACTION_DONE) {
+ mmdvfs_err(mmdvfs->dev, "IPI send to %s failed: %d\n",
+ target_name, ret);
+ ret = -EIO;
+ goto cleanup_sync;
+ }
+
+ retry = 0;
+ while (1) {
+ u32 sync_data = readl(mem_base + MEM_IPI_SYNC_DATA);
+
+ if (sync_data & (1 << ipi_data->func))
+ break;
+
+ if (++retry > 1000000) {
+ mmdvfs_err(mmdvfs->dev, "IPI timeout (func=%u)\n", ipi_data->func);
+ ret = -ETIMEDOUT;
+ goto cleanup_sync;
+ }
+
+ if (!mmdvfs_vcp_is_ready(priv, target_feature)) {
+ mmdvfs_err(mmdvfs->dev, "%s not ready during wait (func=%u)\n",
+ target_name, ipi_data->func);
+ ret = -ETIMEDOUT;
+ goto cleanup_sync;
+ }
+ udelay(1);
+ }
+
+ ret = 0;
+
+cleanup_sync:
+ mutex_lock(&priv->pwr_mutex);
+ if (ret == 0) {
+ u32 sync_func = readl(mem_base + MEM_IPI_SYNC_FUNC);
+ u32 sync_data = readl(mem_base + MEM_IPI_SYNC_DATA);
+
+ writel(sync_func & ~sync_data, mem_base + MEM_IPI_SYNC_FUNC);
+ }
+ mutex_unlock(&priv->pwr_mutex);
+
+ return ret;
+}
+
+/*
+ * mmdvfs_vcp_send_ipi_impl - Send IPI to VCP/MMUP
+ */
+static int
+mmdvfs_vcp_send_ipi_impl(struct mmdvfs_device *mmdvfs, void *data, u32 len,
+ const bool vcp)
+{
+ struct mmdvfs_vcp_priv *priv = mmdvfs_vcp_priv(mmdvfs);
+ struct mmdvfs_vcp_ipi_data *ipi_data;
+ struct mtk_ipi_device *ipidev;
+ enum vcp_feature_id target_feature;
+ u32 target_ipi_id;
+ const char *target_name;
+ void __iomem *mem_base;
+ u32 sync_func_val;
+ int ret;
+
+ mmdvfs_get_bootmode();
+ if (bootmode == RECOVERY_BOOT) {
+ mmdvfs_err(mmdvfs->dev, "IPI skipped: bootmode=%d\n", bootmode);
+ return -EACCES;
+ }
+
+ if (!priv || !priv->initialized)
+ return -ENODEV;
+
+ if (!data || len < sizeof(*ipi_data)) {
+ mmdvfs_err(mmdvfs->dev, "Invalid IPI data (len=%u, minimum=%zu)\n",
+ len, sizeof(*ipi_data));
+ return -EINVAL;
+ }
+
+ ipi_data = (struct mmdvfs_vcp_ipi_data *)data;
+
+ if (len != sizeof(*ipi_data)) {
+ mmdvfs_err(mmdvfs->dev, "Invalid IPI data (len=%u, expected=%zu)\n",
+ len, sizeof(*ipi_data));
+ return -EINVAL;
+ }
+
+ if (vcp || !priv->mmup_enable) {
+ target_feature = priv->vcp_feature_id;
+ target_ipi_id = priv->vcp_ipi_id;
+ target_name = "VCP";
+ mem_base = priv->vcp_va;
+ } else {
+ target_feature = priv->mmup_feature_id;
+ target_ipi_id = priv->mmup_ipi_id;
+ target_name = "MMUP";
+ mem_base = priv->mmup_va;
+ }
+
+ mutex_lock(&priv->ipi_mutex);
+ if (!mem_base) {
+ mmdvfs_err(mmdvfs->dev, "Shared memory base is NULL\n");
+ ret = -ENOMEM;
+ goto unlock_ipi;
+ }
+
+ sync_func_val = readl(mem_base + MEM_IPI_SYNC_FUNC);
+
+ ret = mmdvfs_vcp_wait_target_ready(mmdvfs, priv, target_feature,
+ target_name, ipi_data);
+ if (ret)
+ goto unlock_ipi;
+
+ ipidev = mmdvfs_vcp_get_ipidev(priv);
+ if (!ipidev) {
+ mmdvfs_err(mmdvfs->dev, "vcp_get_ipidev failed for %s\n", target_name);
+ ret = -ENODEV;
+ goto unlock_ipi;
+ }
+
+ ret = mmdvfs_vcp_send_and_sync(mmdvfs, priv, ipidev, target_feature,
+ target_ipi_id, target_name, data,
+ ipi_data, mem_base, sync_func_val);
+
+unlock_ipi:
+ mutex_unlock(&priv->ipi_mutex);
+ return ret;
+}
+
+/*
+ * mmdvfs_reset_vcp - Check VCP power usage on suspend
+ * @priv: VCP private data
+ */
+static void mmdvfs_reset_vcp(struct mmdvfs_vcp_priv *priv)
+{
+ int i;
+
+ for (i = 0; i < VCP_PWR_USR_NUM; i++) {
+ if (priv->pwr_usage[i])
+ mmdvfs_err(priv->mmdvfs->dev,
+ "VCP reset: user %d still has usage=%d\n",
+ i, priv->pwr_usage[i]);
+ }
+}
+
+#define MMDVFS_UP_INIT_READY BIT(0)
+
+static void mmdvfs_vcp_set_init_ready(struct mmdvfs_vcp_priv *priv, u8 path, bool done)
+{
+ u8 mask;
+ bool ready;
+
+ mutex_lock(&priv->cb_mutex);
+ mask = READ_ONCE(priv->init_ready_mask);
+ if (done)
+ mask |= path;
+ else
+ mask &= ~path;
+ WRITE_ONCE(priv->init_ready_mask, mask);
+
+ ready = !!(mask & MMDVFS_UP_INIT_READY);
+ WRITE_ONCE(priv->cb_ready, ready);
+ WRITE_ONCE(priv->mmdvfs->data->init_done, ready);
+ mutex_unlock(&priv->cb_mutex);
+}
+
+/*
+ * mmdvfs_mmup_notifier_callback - MMUP/VCP system event handler
+ * @nb: notifier block
+ * @event: Event type (VCP_EVENT_READY/STOP/SUSPEND/RESUME)
+ * @data: Event data
+ */
+static int mmdvfs_mmup_notifier_callback(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct mmdvfs_vcp_priv *priv =
+ container_of(nb, struct mmdvfs_vcp_priv, mmup_notifier);
+ struct mmdvfs_device *mmdvfs = priv->mmdvfs;
+ int ret;
+
+ switch (event) {
+ case VCP_EVENT_READY:
+ mmdvfs_vcp_set_init_ready(priv, MMDVFS_UP_INIT_READY, false);
+ priv->rst_clk_done = false;
+ priv->release_step_done = false;
+
+ /* Send FUNC_MMDVFS_INIT */
+ {
+ u64 target_iova = priv->mmup_enable ? priv->mmup_iova : priv->vcp_iova;
+ struct mmdvfs_vcp_ipi_data ipi_data = {
+ .func = FUNC_MMDVFS_INIT,
+ .idx = MAX_OPP,
+ .opp = MAX_OPP,
+ .ack = target_iova >> 32,
+ .base = (u32)target_iova
+ };
+
+ ret = mmdvfs_vcp_send_ipi_impl(mmdvfs, &ipi_data,
+ sizeof(ipi_data), false);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "MMDVFS init IPI failed: %d\n", ret);
+ break;
+ }
+ }
+
+ priv->vcp_stop = false;
+
+ /* Send FUNC_MMDVFSRC_INIT */
+ {
+ u64 target_iova = priv->mmup_enable ? priv->mmup_iova : priv->vcp_iova;
+ struct mmdvfs_vcp_ipi_data ipi_data = {
+ .func = FUNC_MMDVFSRC_INIT,
+ .idx = MAX_OPP,
+ .opp = MAX_OPP,
+ .ack = target_iova >> 32,
+ .base = (u32)target_iova
+ };
+
+ ret = mmdvfs_vcp_send_ipi_impl(mmdvfs, &ipi_data,
+ sizeof(ipi_data), false);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "MMDVFSRC init IPI failed: %d\n", ret);
+ break;
+ }
+ }
+
+ /* Initialize MMUP SRAM */
+ if (priv->mmup_enable && priv->mmup_sram_enable && !priv->mmup_sram_va) {
+ void __iomem *sram_base;
+ void __iomem *mem_base;
+ u32 sram_offset;
+
+ sram_base = priv->vcp_device->ops->get_vcp_sram_virt(priv->vcp_device);
+ if (sram_base) {
+ mem_base = priv->mmup_enable ? priv->mmup_va : priv->vcp_va;
+ sram_offset = readl(mem_base + MEM_SRAM_OFFSET);
+ priv->mmup_sram_va = sram_base + sram_offset;
+ }
+ }
+
+ mmdvfs_vcp_set_init_ready(priv, MMDVFS_UP_INIT_READY, true);
+
+ break;
+
+ case VCP_EVENT_STOP:
+ priv->vcp_stop = true;
+ mmdvfs_vcp_set_init_ready(priv, MMDVFS_UP_INIT_READY, false);
+ break;
+
+ case VCP_EVENT_SUSPEND:
+ priv->release_step_done = true;
+ mmdvfs_reset_vcp(priv);
+ WRITE_ONCE(priv->init_ready_mask, 0);
+ WRITE_ONCE(priv->cb_ready, false);
+ WRITE_ONCE(mmdvfs->data->init_done, false);
+ break;
+
+ case VCP_EVENT_RESUME:
+ break;
+
+ default:
+ break;
+ }
+
+ return NOTIFY_OK;
+}
+
+/*
+ * mmdvfs_vcp_enable_impl - VCP enable/disable implementation
+ * @mmdvfs: MMDVFS device
+ * @enable: Enable/disable
+ * @idx: User index
+ */
+static int mmdvfs_vcp_enable_impl(struct mmdvfs_device *mmdvfs,
+ bool enable, u8 idx)
+{
+ struct mmdvfs_vcp_priv *priv;
+ enum vcp_feature_id feature_id;
+ int ret = 0;
+
+ /* Get priv - may be NULL during init before set_priv() */
+ priv = mmdvfs_vcp_priv(mmdvfs);
+ if (!priv || idx >= VCP_PWR_USR_NUM)
+ return -EINVAL;
+
+ feature_id = priv->mmup_enable ?
+ priv->mmup_feature_id : priv->vcp_feature_id;
+
+ mutex_lock(&priv->pwr_mutex);
+ if (enable) {
+ if (!priv->power) {
+ ret = mmdvfs_vcp_register_feature(priv, feature_id);
+ if (ret < 0) {
+ mmdvfs_err(mmdvfs->dev,
+ "Failed to register VCP feature %d: %d\n",
+ feature_id, ret);
+ goto unlock;
+ }
+ priv->current_feature_id = feature_id;
+ }
+ priv->power++;
+ priv->pwr_usage[idx]++;
+
+ mmdvfs_dbg(mmdvfs->dev,
+ "VCP enable: power=%d, usage[%u]=%d\n",
+ priv->power, idx, priv->pwr_usage[idx]);
+ } else {
+ if (!priv->power || !priv->pwr_usage[idx]) {
+ mmdvfs_err(mmdvfs->dev,
+ "VCP disable failed: power=%d, usage[%u]=%d\n",
+ priv->power, idx, priv->pwr_usage[idx]);
+ ret = -EINVAL;
+ goto unlock;
+ }
+
+ priv->power--;
+ priv->pwr_usage[idx]--;
+
+ if (!priv->power) {
+ ret = mmdvfs_vcp_deregister_feature(priv, priv->current_feature_id);
+ if (ret < 0) {
+ mmdvfs_err(mmdvfs->dev,
+ "Failed to deregister VCP feature %d: %d\n",
+ priv->current_feature_id, ret);
+ priv->power++;
+ priv->pwr_usage[idx]++;
+ goto unlock;
+ }
+ }
+
+ mmdvfs_dbg(mmdvfs->dev,
+ "VCP disable: power=%d, usage[%u]=%d\n",
+ priv->power, idx, priv->pwr_usage[idx]);
+ }
+
+unlock:
+ mutex_unlock(&priv->pwr_mutex);
+ return ret < 0 ? ret : 0;
+}
+
+int mmdvfs_vcp_release_init(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv = mmdvfs_vcp_priv(mmdvfs);
+
+ if (!priv || !priv->initialized)
+ return -ENODEV;
+
+ return mmdvfs_vcp_enable_impl(mmdvfs, false, VCP_PWR_USR_MMDVFS_INIT);
+}
+
+/*
+ * mmdvfs_vcp_get_base_impl - Get VCP base address
+ * @mmdvfs: MMDVFS device structure
+ * @mem_id: Memory ID (MMDVFS_VCP_MEM_ID or MMDVFS_MMUP_MEM_ID)
+ * @pa: Physical address output
+ */
+static void *mmdvfs_vcp_get_base_impl(struct mmdvfs_device *mmdvfs, u32 mem_id, phys_addr_t *pa)
+{
+ struct mmdvfs_vcp_priv *priv = mmdvfs_vcp_priv(mmdvfs);
+
+ if (!priv)
+ return NULL;
+
+ if (mem_id == MMDVFS_MMUP_MEM_ID) {
+ if (pa)
+ *pa = priv->mmup_pa;
+ return priv->mmup_va;
+ } else if (mem_id == MMDVFS_VCP_MEM_ID) {
+ if (pa)
+ *pa = priv->vcp_pa;
+ return priv->vcp_va;
+ }
+
+ mmdvfs_warn(mmdvfs->dev, "Unknown mem_id %u, defaulting to VCP\n", mem_id);
+ if (pa)
+ *pa = priv->vcp_pa;
+ return priv->vcp_va;
+}
+
+/*
+ * mmdvfs_vcp_get_sram_impl - Get VCP SRAM virtual address
+ * @mmdvfs: MMDVFS device structure
+ */
+static void __iomem *mmdvfs_vcp_get_sram_impl(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv = mmdvfs_vcp_priv(mmdvfs);
+
+ if (!priv)
+ return NULL;
+
+ return priv->mmup_sram_va;
+}
+
+/*
+ * mmdvfs_vcp_init_impl - Initialize VCP abstraction
+ * @mmdvfs: MMDVFS device structure
+ */
+static int mmdvfs_vcp_init_impl(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv;
+ struct device_node *vcp_node;
+ struct device_node *mmup_node;
+ struct mtk_ipi_device *vcp_ipi_dev = NULL;
+ u32 ipi_id;
+ int ret, retry;
+
+ priv = devm_kzalloc(mmdvfs->dev, sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ priv->mmdvfs = mmdvfs;
+ mutex_init(&priv->pwr_mutex);
+ mutex_init(&priv->ipi_mutex);
+ mutex_init(&priv->cb_mutex);
+ priv->cb_ready = false;
+
+ /* Set feature IDs */
+ priv->vcp_feature_id = MMDVFS_VCP_FEATURE_ID;
+ priv->mmup_feature_id = MMDVFS_MMUP_FEATURE_ID;
+
+ vcp_node = of_parse_phandle(mmdvfs->dev->of_node, "mediatek,vcp", 0);
+ if (!vcp_node) {
+ mmdvfs_err(mmdvfs->dev, "missing mediatek,vcp phandle in %pOF\n",
+ mmdvfs->dev->of_node);
+ return -ENODEV;
+ }
+ of_node_put(vcp_node);
+
+ priv->vcp_device = vcp_get(to_platform_device(mmdvfs->dev));
+ if (!priv->vcp_device) {
+ return dev_err_probe(mmdvfs->dev, -EPROBE_DEFER,
+ "VCP device is not ready\n");
+ }
+ if (!priv->vcp_device->dev || !priv->vcp_device->ops || !priv->vcp_device->ipi_ops) {
+ mmdvfs_err(mmdvfs->dev, "VCP object incomplete: dev=%p ops=%p ipi_ops=%p\n",
+ priv->vcp_device->dev, priv->vcp_device->ops,
+ priv->vcp_device->ipi_ops);
+ ret = -ENODEV;
+ goto put_vcp;
+ }
+ if (!priv->vcp_device->ops->get_mem_phys ||
+ !priv->vcp_device->ops->get_mem_iova ||
+ !priv->vcp_device->ops->get_mem_virt ||
+ !priv->vcp_device->ipi_ops->ipi_send) {
+ mmdvfs_err(mmdvfs->dev,
+ "VCP callbacks missing: get_phys=%p get_iova=%p get_virt=%p ipi_send=%p\n",
+ priv->vcp_device->ops->get_mem_phys,
+ priv->vcp_device->ops->get_mem_iova,
+ priv->vcp_device->ops->get_mem_virt,
+ priv->vcp_device->ipi_ops->ipi_send);
+ ret = -ENODEV;
+ goto put_vcp;
+ }
+
+ ret = of_property_read_u32(mmdvfs->dev->of_node, "mediatek,vcp-ipi-id", &ipi_id);
+ if (ret)
+ priv->vcp_ipi_id = IPI_OUT_MMDVFS_VCP;
+ else
+ priv->vcp_ipi_id = ipi_id;
+
+ priv->mmup_enable = of_property_read_bool(mmdvfs->dev->of_node,
+ "mediatek,mmup-enable");
+
+ /* Set priv early so enable_impl can access it */
+ ret = mmdvfs_up_set_priv(mmdvfs, MMDVFS_UP_VCP, priv);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to set VCP priv: %d\n", ret);
+ goto put_vcp;
+ }
+
+ ret = mmdvfs_vcp_enable_impl(mmdvfs, true, VCP_PWR_USR_MMDVFS_INIT);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev, "Failed to enable VCP power: %d\n", ret);
+ goto put_vcp;
+ }
+ retry = 0;
+ while (!mmdvfs_vcp_is_ready(priv, priv->vcp_feature_id)) {
+ if (++retry > VCP_SYNC_TIMEOUT_MS) {
+ mmdvfs_err(mmdvfs->dev, "VCP not ready after %d ms\n",
+ VCP_SYNC_TIMEOUT_MS);
+ ret = -ETIMEDOUT;
+ goto disable_vcp_power;
+ }
+ mdelay(1);
+ }
+ mmdvfs_info(mmdvfs->dev, "VCP ready after %d ms\n", retry);
+
+ retry = 0;
+ while (!(vcp_ipi_dev = mmdvfs_vcp_get_ipidev(priv))) {
+ if (++retry > VCP_IPIDEV_RETRY_MAX) {
+ mmdvfs_err(mmdvfs->dev,
+ "Cannot get VCP IPI device after %d retries\n",
+ VCP_IPIDEV_RETRY_MAX);
+ ret = -ETIMEDOUT;
+ goto disable_vcp_power;
+ }
+ ssleep(1);
+ }
+
+ priv->vcp_iova = priv->vcp_device->ops->get_mem_iova(priv->vcp_device,
+ MMDVFS_VCP_MEM_ID);
+ priv->vcp_pa = priv->vcp_device->ops->get_mem_phys(priv->vcp_device,
+ MMDVFS_VCP_MEM_ID);
+ priv->vcp_va = priv->vcp_device->ops->get_mem_virt(priv->vcp_device,
+ MMDVFS_VCP_MEM_ID);
+ if (!priv->vcp_va) {
+ mmdvfs_err(mmdvfs->dev, "VCP shared memory VA is NULL\n");
+ ret = -ENOMEM;
+ goto disable_vcp_power;
+ }
+
+ if (priv->mmup_enable) {
+ retry = 0;
+ while (!mmdvfs_vcp_is_ready(priv, priv->mmup_feature_id)) {
+ if (++retry > VCP_SYNC_TIMEOUT_MS) {
+ mmdvfs_err(mmdvfs->dev,
+ "MMUP not ready after %d ms\n",
+ VCP_SYNC_TIMEOUT_MS);
+ ret = -ETIMEDOUT;
+ goto disable_vcp_power;
+ }
+ mdelay(1);
+ }
+
+ /* Get MMUP IPI device through feature ID */
+ retry = 0;
+ while (!(vcp_ipi_dev = mmdvfs_vcp_get_ipidev(priv))) {
+ if (++retry > VCP_IPIDEV_RETRY_MAX) {
+ mmdvfs_err(mmdvfs->dev,
+ "Cannot get MMUP IPI device after %d retries\n",
+ VCP_IPIDEV_RETRY_MAX);
+ ret = -ETIMEDOUT;
+ goto disable_vcp_power;
+ }
+ ssleep(1);
+ }
+
+ priv->mmup_iova = priv->vcp_device->ops->get_mem_iova(priv->vcp_device,
+ MMDVFS_MMUP_MEM_ID);
+ priv->mmup_pa = priv->vcp_device->ops->get_mem_phys(priv->vcp_device,
+ MMDVFS_MMUP_MEM_ID);
+ priv->mmup_va = priv->vcp_device->ops->get_mem_virt(priv->vcp_device,
+ MMDVFS_MMUP_MEM_ID);
+ if (!priv->mmup_va) {
+ mmdvfs_err(mmdvfs->dev, "MMUP shared memory VA is NULL\n");
+ ret = -ENOMEM;
+ goto disable_vcp_power;
+ }
+
+ ret = of_property_read_u32(mmdvfs->dev->of_node,
+ "mediatek,mmup-ipi-id", &ipi_id);
+ if (ret)
+ priv->mmup_ipi_id = IPI_OUT_MMDVFS_MMUP;
+ else
+ priv->mmup_ipi_id = ipi_id;
+
+ mmup_node = of_find_compatible_node(NULL, NULL, "mediatek,mmup-core");
+ if (mmup_node) {
+ priv->mmup_pdev = of_find_device_by_node(mmup_node);
+ of_node_put(mmup_node);
+ }
+ }
+ /* Parse MMUP SRAM if enabled */
+ priv->mmup_sram_enable = of_property_read_bool(mmdvfs->dev->of_node,
+ "mediatek,mmup-sram");
+
+ /* Initialize shared memory registers */
+ {
+ void __iomem *mem_base = priv->mmup_enable ? priv->mmup_va : priv->vcp_va;
+ int i;
+
+ if (!mem_base) {
+ mmdvfs_err(mmdvfs->dev,
+ "shared memory base is NULL before default init (mmup_enable=%d)\n",
+ priv->mmup_enable);
+ ret = -ENOMEM;
+ goto disable_vcp_power;
+ }
+
+ /* Keep firmware-owned control slots inactive unless firmware changes them. */
+ for (i = 0; i < MEM_FW_RSVD_OPP_PWR_COUNT; i++) {
+ writel(MAX_OPP, mem_base + MEM_FW_RSVD_OPP_PWR(i));
+ writel(MAX_OPP, mem_base + MEM_VOTE_OPP_PWR(i));
+ writel(MAX_OPP, mem_base + MEM_PWR_OPP(i));
+ writel(MAX_OPP, mem_base + MEM_PWR_CUR_GEAR(i));
+ writel(MAX_OPP, mem_base + MEM_FW_RSVD_VOL(i));
+ }
+ for (i = 0; i < MEM_VOTE_OPP_USR_COUNT; i++) {
+ writel(MAX_OPP, mem_base + MEM_VOTE_OPP_USR(i));
+ writel(MAX_OPP, mem_base + MEM_MUX_OPP(i));
+ writel(MAX_OPP, mem_base + MEM_MUX_MIN(i));
+ writel(MAX_OPP, mem_base + MEM_FW_RSVD_CLK(i));
+ }
+ for (i = 0; i < 32; i++)
+ writel(MAX_OPP, mem_base + MEM_USR_OPP(i));
+ }
+
+ /*
+ * CRITICAL: Set initialized flag BEFORE registering notifiers!
+ *
+ * The notifier callbacks (especially MMUP_EVENT_READY) may fire immediately
+ * upon registration, and they need to send IPI (FUNC_MMDVFS_INIT).
+ * If initialized is false, send_ipi_impl() will return -ENODEV and the
+ * IPI won't be sent, causing VCP to never receive the shared memory address.
+ */
+ priv->initialized = true;
+
+ /* Register notifiers */
+ priv->mmup_notifier.notifier_call = mmdvfs_mmup_notifier_callback;
+ mmdvfs_vcp_register_notify(priv,
+ priv->mmup_enable ? priv->mmup_feature_id :
+ priv->vcp_feature_id,
+ &priv->mmup_notifier);
+
+ return 0;
+
+disable_vcp_power:
+ mmdvfs_vcp_enable_impl(mmdvfs, false, VCP_PWR_USR_MMDVFS_INIT);
+put_vcp:
+ if (priv->vcp_pdev)
+ platform_device_put(priv->vcp_pdev);
+ if (priv->mmup_pdev)
+ platform_device_put(priv->mmup_pdev);
+ if (priv->vcp_device && priv->vcp_device->dev)
+ vcp_put(priv->vcp_device);
+ /* Clear priv on error */
+ mmdvfs_up_set_priv(mmdvfs, MMDVFS_UP_VCP, NULL);
+ return ret;
+}
+
+/*
+ * mmdvfs_vcp_deinit_impl - Deinitialize VCP abstraction
+ * @mmdvfs: MMDVFS device structure
+ */
+static void mmdvfs_vcp_deinit_impl(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv = mmdvfs_vcp_priv(mmdvfs);
+
+ if (!priv)
+ return;
+
+ if (!priv->initialized) {
+ mmdvfs_up_set_priv(mmdvfs, MMDVFS_UP_VCP, NULL);
+ return;
+ }
+
+ mmdvfs_vcp_unregister_notify(priv,
+ priv->mmup_enable ? priv->mmup_feature_id :
+ priv->vcp_feature_id,
+ &priv->mmup_notifier);
+
+ if (priv->pwr_usage[VCP_PWR_USR_MMDVFS_INIT])
+ mmdvfs_vcp_enable_impl(mmdvfs, false, VCP_PWR_USR_MMDVFS_INIT);
+
+ if (priv->vcp_pdev)
+ platform_device_put(priv->vcp_pdev);
+ if (priv->mmup_pdev)
+ platform_device_put(priv->mmup_pdev);
+ if (priv->vcp_device && priv->vcp_device->dev)
+ vcp_put(priv->vcp_device);
+
+ priv->initialized = false;
+ mmdvfs_up_set_priv(mmdvfs, MMDVFS_UP_VCP, NULL);
+}
+
+/*
+ * mmdvfs_vcp_lock_cb_mutex - Lock VCP callback mutex
+ * @mmdvfs: MMDVFS device
+ */
+void mmdvfs_vcp_lock_cb_mutex(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv = mmdvfs_vcp_priv(mmdvfs);
+
+ if (priv)
+ mutex_lock(&priv->cb_mutex);
+}
+
+/*
+ * mmdvfs_vcp_unlock_cb_mutex - Unlock VCP callback mutex
+ * @mmdvfs: MMDVFS device
+ */
+void mmdvfs_vcp_unlock_cb_mutex(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv = mmdvfs_vcp_priv(mmdvfs);
+
+ if (priv)
+ mutex_unlock(&priv->cb_mutex);
+}
+
+/*
+ * mmdvfs_vcp_get_cb_ready_impl - Get VCP callback ready state
+ * @mmdvfs: MMDVFS device
+ *
+ * Note: This function does not acquire cb_mutex. The caller should hold
+ * the mutex if synchronization is required.
+ */
+static bool mmdvfs_vcp_get_cb_ready_impl(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv = mmdvfs_vcp_priv(mmdvfs);
+
+ if (!priv)
+ return false;
+
+ return READ_ONCE(priv->cb_ready);
+}
+
+/*
+ * mmdvfs_vcp_get_power_info - Get VCP power management info for debug
+ * @mmdvfs: MMDVFS device
+ * @power: Output power refcount
+ * @pwr_usage: Output power usage array (must be VCP_PWR_USR_NUM size)
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+int mmdvfs_vcp_get_power_info(struct mmdvfs_device *mmdvfs, int *power, int *pwr_usage)
+{
+ struct mmdvfs_vcp_priv *priv;
+ int i;
+
+ priv = mmdvfs_vcp_priv(mmdvfs);
+ if (!priv || !power || !pwr_usage)
+ return -EINVAL;
+
+ mutex_lock(&priv->pwr_mutex);
+ *power = priv->power;
+ for (i = 0; i < VCP_PWR_USR_NUM; i++)
+ pwr_usage[i] = priv->pwr_usage[i];
+ mutex_unlock(&priv->pwr_mutex);
+
+ return 0;
+}
+
+/*
+ * mmdvfs_vcp_get_mmup_enable - Get MMUP enable status
+ * @mmdvfs: MMDVFS device
+ *
+ * Return: true if MMUP is enabled, false otherwise
+ */
+bool mmdvfs_vcp_get_mmup_enable(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv;
+
+ priv = mmdvfs_vcp_priv(mmdvfs);
+ if (!priv)
+ return false;
+
+ return priv->mmup_enable;
+}
+
+/*
+ * mmdvfs_vcp_get_mmup_sram_enable - Get MMUP SRAM enable status
+ * @mmdvfs: MMDVFS device
+ *
+ * Return: true if MMUP SRAM is enabled, false otherwise
+ */
+bool mmdvfs_vcp_get_mmup_sram_enable(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_vcp_priv *priv;
+
+ priv = mmdvfs_vcp_priv(mmdvfs);
+ if (!priv)
+ return false;
+
+ return priv->mmup_sram_enable;
+}
+
+/*
+ * mmdvfs_vcp_ops - VCP UP operations
+ */
+const struct mmdvfs_up_ops mmdvfs_vcp_ops = {
+ .init = mmdvfs_vcp_init_impl,
+ .deinit = mmdvfs_vcp_deinit_impl,
+ .send_ipi = mmdvfs_vcp_send_ipi_impl,
+ .enable = mmdvfs_vcp_enable_impl,
+ .get_base = mmdvfs_vcp_get_base_impl,
+ .get_sram = mmdvfs_vcp_get_sram_impl,
+ .get_cb_ready = mmdvfs_vcp_get_cb_ready_impl,
+};
+
+MODULE_DESCRIPTION("MediaTek MMDVFS VCP Abstraction Layer");
+MODULE_AUTHOR("MediaTek Inc.");
+MODULE_LICENSE("GPL");
diff --git a/include/soc/mediatek/mmdvfs.h b/include/soc/mediatek/mmdvfs.h
index 459f1adcab34..79ecdc3dbf21 100644
--- a/include/soc/mediatek/mmdvfs.h
+++ b/include/soc/mediatek/mmdvfs.h
@@ -18,54 +18,72 @@ enum mmdvfs_version_type {
};
enum {
- CCU_PWR_USR_MMDVFS,
- CCU_PWR_USR_IMG,
- CCU_PWR_USR_NUM
+ VCP_PWR_USR_MMDVFS_INIT,
+ VCP_PWR_USR_MMDVFS_RESERVED1,
+ VCP_PWR_USR_MMDVFS_RESERVED2,
+ VCP_PWR_USR_MMDVFS_VOTE,
+ VCP_PWR_USR_MMDVFS_CCU,
+ VCP_PWR_USR_MMDVFS_RST,
+ VCP_PWR_USR_MMQOS,
+ VCP_PWR_USR_CAM,
+ VCP_PWR_USR_IMG,
+ VCP_PWR_USR_PDA,
+ VCP_PWR_USR_SENIF,
+ VCP_PWR_USR_VDEC,
+ VCP_PWR_USR_VFMT,
+ VCP_PWR_USR_SMI,
+ VCP_PWR_USR_DISP,
+ VCP_PWR_USR_MDP,
+ VCP_PWR_USR_MML,
+ VCP_PWR_USR_VENC,
+ VCP_PWR_USR_JPEGDEC,
+ VCP_PWR_USR_JPEGENC,
+ VCP_PWR_USR_NUM
};
-#if IS_ENABLED(CONFIG_MTK_MMDVFS) && IS_ENABLED(CONFIG_MTK_VCP_RPROC)
-int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx);
-int mtk_mmdvfs_camera_notify(const bool enable);
-int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable);
-int mtk_mmdvfs_genpd_notify(const u8 idx, const bool enable);
-int mtk_mmdvfs_set_avs(const u8 idx, const u32 aging, const u32 fresh);
-int mmdvfs_set_lp_mode(bool lp_mode);
+#if IS_REACHABLE(CONFIG_MTK_MMDVFS)
+int mtk_mmdvfs_enable_vcp(const bool enable, const u8 idx);
u32 mmdvfs_get_version(void);
+void *mmdvfs_get_mmup_base(phys_addr_t *pa);
+void *mmdvfs_get_vcp_base(phys_addr_t *pa);
+bool mmdvfs_get_mmup_sram_enable(void);
+void __iomem *mmdvfs_get_mmup_sram(void);
+bool mmdvfs_get_mmup_enable(void);
#else
-static inline int mtk_mmdvfs_enable_ccu(const bool enable, const u8 idx)
+static inline int mtk_mmdvfs_enable_vcp(const bool enable, const u8 idx)
{
- return -EOPNOTSUPP;
+ return -ENODEV;
}
-static inline int mtk_mmdvfs_camera_notify(const bool enable)
+static inline u32 mmdvfs_get_version(void)
{
- return 0;
+ return MMDVFS_VERSION_NONE;
}
-static inline int mtk_mmdvfs_camsv_dc_enable(const u8 idx, const bool enable)
+static inline void *mmdvfs_get_mmup_base(phys_addr_t *pa)
{
- return 0;
+ return NULL;
}
-static inline int mtk_mmdvfs_genpd_notify(const u8 idx, const bool enable)
+static inline void *mmdvfs_get_vcp_base(phys_addr_t *pa)
{
- return 0;
+ return NULL;
}
-static inline int mtk_mmdvfs_set_avs(const u8 idx, const u32 aging, const u32 fresh)
+static inline bool mmdvfs_get_mmup_sram_enable(void)
{
- return 0;
+ return false;
}
-static inline int mmdvfs_set_lp_mode(bool lp_mode)
+static inline void __iomem *mmdvfs_get_mmup_sram(void)
{
- return -EOPNOTSUPP;
+ return NULL;
}
-static inline u32 mmdvfs_get_version(void)
+static inline bool mmdvfs_get_mmup_enable(void)
{
- return MMDVFS_VERSION_NONE;
+ return false;
}
#endif
--
2.45.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 5/7] soc: mediatek: mmdvfs: add MT8196 support
2026-11-25 6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
` (3 preceding siblings ...)
2026-11-25 6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
@ 2026-11-25 6:00 ` Echo Zhang
2026-11-25 6:00 ` [PATCH 6/7] soc: mediatek: mmdvfs: add read-only status debug Echo Zhang
2026-11-25 6:00 ` [PATCH 7/7] MAINTAINERS: add MediaTek MMDVFS entry Echo Zhang
6 siblings, 0 replies; 18+ messages in thread
From: Echo Zhang @ 2026-11-25 6:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
Describe the MT8196 resource controllers, seven multimedia muxes and
their users. Read mux performance levels from device tree OPP tables
and program HWCCF votes for aggregated user clock requests.
Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
---
drivers/soc/mediatek/mmdvfs/Makefile | 1 +
drivers/soc/mediatek/mmdvfs/mmdvfs-mt8196.c | 637 ++++++++++++++++++++
2 files changed, 638 insertions(+)
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-mt8196.c
diff --git a/drivers/soc/mediatek/mmdvfs/Makefile b/drivers/soc/mediatek/mmdvfs/Makefile
index 16ecee30bff6..d02ebd63e6ae 100644
--- a/drivers/soc/mediatek/mmdvfs/Makefile
+++ b/drivers/soc/mediatek/mmdvfs/Makefile
@@ -6,3 +6,4 @@ mtk-mmdvfs-y += mmdvfs-core.o
mtk-mmdvfs-y += mmdvfs-clk.o
mtk-mmdvfs-y += mmdvfs-up.o
mtk-mmdvfs-y += mmdvfs-vcp.o
+mtk-mmdvfs-$(CONFIG_MTK_MMDVFS_MT8196) += mmdvfs-mt8196.o
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-mt8196.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-mt8196.c
new file mode 100644
index 000000000000..1075884791e4
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-mt8196.c
@@ -0,0 +1,637 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ *
+ * MediaTek MMDVFS MT8196 Platform Driver
+ */
+
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
+
+#include "mmdvfs-internal.h"
+
+/* HWCCF timing constants */
+#define MTK_WAIT_HWV_PREPARE_CNT 200
+#define MTK_WAIT_HWV_PREPARE_US 1
+#define MTK_WAIT_HWV_DONE_CNT 5000000
+#define MTK_WAIT_HWV_DONE_US 1
+#define MT8196_HWV_LEVELS 7
+
+/* HWCCF DVFS Voter control bits */
+#define HWCCF_VOTER_ENABLE BIT(0)
+#define HWCCF_VOTER_REQ_VALID BIT(1)
+#define HWCCF_VOTER_ACK_VALID BIT(2)
+
+struct mt8196_mmdvfs_data {
+ struct regmap *hwv_regmap;
+};
+
+/* Resource controllers (uses HWCCF, no direct RC base address) */
+static struct mmdvfs_rc mt8196_rc[MMDVFS_PWR_NUM] = {
+ [MMDVFS_PWR_VCORE] = { /* [0] PWR_MMDVFS_VCORE */
+ .id = MMDVFS_PWR_VCORE,
+ .pa = 0x0,
+ .level_num = MT8196_HWV_LEVELS,
+ },
+ [MMDVFS_PWR_VMM] = { /* [1] PWR_MMDVFS_VMM */
+ .id = MMDVFS_PWR_VMM,
+ .pa = 0x0,
+ .level_num = MT8196_HWV_LEVELS,
+ },
+ [MMDVFS_PWR_VDISP] = { /* [2] PWR_MMDVFS_VDISP */
+ .id = MMDVFS_PWR_VDISP,
+ .pa = 0x0,
+ .level_num = MT8196_HWV_LEVELS,
+ },
+};
+
+/*
+ * mt8196_hwccf_vote - perform HWCCF DVFS voter operation
+ * @mmdvfs: MMDVFS device structure
+ * @user: user structure
+ * @level: target performance level (higher value = higher performance)
+ *
+ * Implement HWCCF DVFS voter logic using the standard voting sequence:
+ *
+ * 1. WRITE: issue vote to SET/CLEAR register based on OPP delta
+ * 2. PREPARE: poll hwv_set_ofs until HW accepts (200us timeout)
+ * 3. DONE: poll hwv_sta_ofs until operation completes (5s timeout)
+ *
+ * OPP encoding uses cumulative bitmasks where index = level_num - 1 - level.
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+static int mt8196_hwccf_vote(struct mmdvfs_device *mmdvfs,
+ struct mmdvfs_user *user, u8 level)
+{
+ struct mt8196_mmdvfs_data *mt8196_data = mmdvfs->data->platform_data;
+ struct mmdvfs_data *data = mmdvfs->data;
+ struct mmdvfs_mux *mux;
+ struct mmdvfs_rc *rc;
+ u32 mask, opp_mask;
+ u32 val = 0, orig = 0, renew = 0;
+ u8 index;
+ int i = 0, ret = 0;
+
+ if (!mt8196_data || !mt8196_data->hwv_regmap) {
+ dev_err(mmdvfs->dev, "MT8196 HWCCF regmap not initialized\n");
+ return -ENODEV;
+ }
+
+ if (user->mux >= data->mux_num) {
+ dev_err(mmdvfs->dev, "Invalid mux_id: %u\n", user->mux);
+ return -EINVAL;
+ }
+
+ mux = &data->mux[user->mux];
+ if (mux->rc >= data->rc_num) {
+ dev_err(mmdvfs->dev, "Invalid rc_id: %u\n", mux->rc);
+ return -EINVAL;
+ }
+
+ rc = &data->rc[mux->rc];
+
+ if (level >= rc->level_num) {
+ dev_err(mmdvfs->dev, "Invalid level: user=%s level=%u max=%u\n",
+ user->name, level, rc->level_num - 1);
+ return -EINVAL;
+ }
+
+ /*
+ * Prepare HWCCF voting masks
+ * Level is the freq[] array index. level=0 is the lowest frequency,
+ * and level=N-1 is the highest frequency.
+ * Hardware index = level (no conversion needed, same as CLK framework)
+ *
+ * mask: Hardware register bit field width (fixed by hardware design)
+ * GENMASK(6, 0) = 7 bits, supporting up to 7 OPP levels (level 0-6)
+ * This is determined by hardware register layout, NOT by OPP table.
+ * Bit shift + 7 is the HWV gate bit for the 8-bit slot.
+ *
+ * opp_mask: Cumulative bitmask for current level
+ * level=0 -> GENMASK(0,0) = 0x01
+ * level=6 -> GENMASK(6,0) = 0x7F
+ * Must not exceed mask range (level must be < 7)
+ */
+ index = level;
+ mask = GENMASK(6, 0) << mux->shift;
+ opp_mask = GENMASK(index, 0) << mux->shift;
+
+ /* Phase 1: Read current setting and calculate delta */
+ ret = regmap_read(mt8196_data->hwv_regmap, mux->hwccf.hwv_set_ofs, &orig);
+ if (ret) {
+ dev_err(mmdvfs->dev, "Failed to read HWV set register: %d\n", ret);
+ goto hwv_fail;
+ }
+
+ val = orig & mask;
+ val ^= opp_mask;
+
+ /* Write to SET or CLEAR register based on delta direction */
+ if (val > opp_mask)
+ ret = regmap_write(mt8196_data->hwv_regmap, mux->hwccf.hwv_clr_ofs, val);
+ else
+ ret = regmap_write(mt8196_data->hwv_regmap, mux->hwccf.hwv_set_ofs, val);
+
+ if (ret) {
+ dev_err(mmdvfs->dev, "Failed to write HWV register (ofs=0x%x): %d\n",
+ val > opp_mask ? mux->hwccf.hwv_clr_ofs : mux->hwccf.hwv_set_ofs, ret);
+ goto hwv_fail;
+ }
+
+ /* Write UPDATE register to trigger hardware processing. */
+ if (mux->hwccf.hwv_upd_id != 0xFF) {
+ ret = regmap_write(mt8196_data->hwv_regmap,
+ mux->hwccf.hwv_upd_ofs,
+ BIT(mux->hwccf.hwv_upd_id));
+ if (ret) {
+ dev_err(mmdvfs->dev, "Failed to write HWV update register (ofs=0x%x bit=%u): %d\n",
+ mux->hwccf.hwv_upd_ofs, mux->hwccf.hwv_upd_id, ret);
+ goto hwv_fail;
+ }
+ }
+
+ /* Phase 2: Poll until hardware accepts the vote (200us timeout) */
+ i = 0;
+ while (1) {
+ ret = regmap_read(mt8196_data->hwv_regmap, mux->hwccf.hwv_set_ofs, &renew);
+ if (ret) {
+ dev_err(mmdvfs->dev, "Failed to read HWV set status: %d\n", ret);
+ goto hwv_fail;
+ }
+
+ if ((renew & opp_mask) == opp_mask)
+ break;
+
+ if (i < MTK_WAIT_HWV_PREPARE_CNT) {
+ udelay(MTK_WAIT_HWV_PREPARE_US);
+ i++;
+ } else {
+ dev_err(mmdvfs->dev,
+ "HWV prepare timeout(%d loops, %dus): renew=0x%x opp_mask=0x%x mask=0x%x\n",
+ i, i * MTK_WAIT_HWV_PREPARE_US, renew, opp_mask, mask);
+ dev_err(mmdvfs->dev,
+ " mux_id=%u shift=%u hwv_set_ofs=0x%x renew&mask=0x%x\n",
+ user->mux, mux->shift, mux->hwccf.hwv_set_ofs, renew & mask);
+ ret = -ETIMEDOUT;
+ goto hwv_fail;
+ }
+ }
+
+ /* Phase 3: Poll until operation completes (5s timeout) */
+ i = 0;
+ while (1) {
+ ret = regmap_read(mt8196_data->hwv_regmap, mux->hwccf.hwv_sta_ofs, &renew);
+ if (ret) {
+ dev_err(mmdvfs->dev, "Failed to read HWV status: %d\n", ret);
+ goto hwv_fail;
+ }
+
+ if ((renew & val) == val)
+ break;
+
+ if (i < MTK_WAIT_HWV_DONE_CNT) {
+ udelay(MTK_WAIT_HWV_DONE_US);
+ i++;
+ } else {
+ dev_err(mmdvfs->dev,
+ "HWV done timeout(%d loops, %dms): renew=0x%x val=0x%x\n",
+ i, i * MTK_WAIT_HWV_DONE_US / 1000, renew, val);
+ ret = -ETIMEDOUT;
+ goto hwv_fail;
+ }
+ }
+
+hwv_fail:
+ if (ret && ret != -ETIMEDOUT)
+ dev_err(mmdvfs->dev, "HWCCF vote failed with ret=%d\n", ret);
+
+ return ret;
+}
+
+/*
+ * Mux-to-users mapping table for vote aggregation (7 MUXes)
+ * MUX order: dis, mdp/mml, smi, ven, vde, img, cam
+ */
+static const struct {
+ const u8 users[16];
+ u8 count;
+} mt8196_mux_user_map[] = {
+ /*
+ * mux 0: dis
+ * (user-disp, dummy-dis, mmdvfs-ap-dis, mmdvfs-vcp-dis)
+ */
+ { .users = {0, 14, 29, 39}, .count = 4 },
+ /*
+ * mux 1: mdp/mml
+ * (user-mdp, user-mml, user-vdisp, dummy-mdp, dummy-mml,
+ * mmdvfs-ap-mdp, mmdvfs-ap-mml, mmdvfs-vcp-mdp, mmdvfs-vcp-mml)
+ */
+ { .users = {1, 2, 12, 15, 16, 30, 33, 40, 43}, .count = 9 },
+ /*
+ * mux 2: smi
+ * (user-smi, dummy-smi, user-img-smi, user-vcp-smi,
+ * mmdvfs-ap-smi, mmdvfs-vcp-smi)
+ */
+ { .users = {3, 17, 22, 23, 31, 41}, .count = 6 },
+ /*
+ * mux 3: ven
+ * (user-jpegdec, user-jpegenc, user-venc, user-vcore,
+ * dummy-ven, mmdvfs-ap-ven, mmdvfs-vcp-ven)
+ */
+ { .users = {4, 5, 6, 10, 18, 32, 42}, .count = 7 },
+ /* mux 4: vde (user-vfmt, user-vdec, dummy-vde, mmdvfs-ap-vde, mmdvfs-vcp-vde) */
+ { .users = {7, 13, 19, 26, 36}, .count = 5 },
+ /* mux 5: img (user-img, dummy-img, mmdvfs-ap-img, mmdvfs-vcp-img) */
+ { .users = {8, 20, 27, 28, 37, 38}, .count = 6 },
+ /* mux 6: cam (user-cam, user-vmm, dummy-cam, mmdvfs-ap-cam, mmdvfs-vcp-cam) */
+ { .users = {9, 11, 21, 24, 25, 34, 35}, .count = 7 },
+};
+
+/*
+ * mt8196_get_mux_aggregated_level - aggregate user votes for a mux
+ * @mmdvfs: MMDVFS device context
+ * @mux_id: mux identifier
+ * @pending_user_id: user whose new level is being voted
+ * @pending_level: pending level for @pending_user_id
+ *
+ * Aggregate votes from multiple users targeting the same mux. Uses static
+ * mux-to-users mapping for O(users_per_mux) complexity instead of O(total_users).
+ *
+ * Return: aggregated level to write to hardware voter
+ */
+static u8 mt8196_get_mux_aggregated_level(struct mmdvfs_device *mmdvfs, u8 mux_id,
+ u8 pending_user_id, u8 pending_level)
+{
+ struct mmdvfs_data *data = mmdvfs->data;
+ u8 max_level = 0;
+ int i;
+
+ if (mux_id >= ARRAY_SIZE(mt8196_mux_user_map))
+ return 0;
+
+ for (i = 0; i < mt8196_mux_user_map[mux_id].count; i++) {
+ u8 user_id = mt8196_mux_user_map[mux_id].users[i];
+ struct mmdvfs_user *user;
+
+ if (user_id >= data->user_num)
+ continue;
+
+ user = &data->user[user_id];
+ if (user_id == pending_user_id) {
+ if (pending_level > max_level)
+ max_level = pending_level;
+ } else if (user->level > max_level) {
+ max_level = user->level;
+ }
+ }
+
+ return max_level;
+}
+
+/*
+ * mt8196_hw_vote - submit hardware vote
+ * @mmdvfs: MMDVFS device context
+ * @user_id: user identifier
+ * @level: target performance level
+ *
+ * Submit vote via HWCCF DVFS voter. Multiple users may map to the same mux,
+ * so votes are aggregated (taking maximum level) before writing to hardware.
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+static int mt8196_hw_vote(struct mmdvfs_device *mmdvfs, const u8 user_id, const u8 level)
+{
+ struct mmdvfs_data *data = mmdvfs->data;
+ struct mmdvfs_user *user;
+ u8 mux_id, aggregated_level;
+ int ret;
+
+ if (!data || user_id >= data->user_num) {
+ dev_err(mmdvfs->dev, "Invalid user_id: %u (max=%u)\n",
+ user_id, data ? data->user_num : 0);
+ return -EINVAL;
+ }
+
+ user = &data->user[user_id];
+ if (!user || user->id != user_id) {
+ dev_err(mmdvfs->dev, "User table mismatch: array[%u].id=%u (expected %u)\n",
+ user_id, user ? user->id : 999, user_id);
+ return -ENODEV;
+ }
+
+ mux_id = user->mux;
+
+ aggregated_level = mt8196_get_mux_aggregated_level(mmdvfs, mux_id, user_id, level);
+
+ /* Submit aggregated vote to hardware */
+ ret = mt8196_hwccf_vote(mmdvfs, user, aggregated_level);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev,
+ "HWCCF vote failed: user=%u(%s) mux=%u user_level=%u aggregated_level=%u ret=%d\n",
+ user_id, user->name, mux_id, level,
+ aggregated_level, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+/*
+ * mt8196_init_hw - Initialize hardware
+ */
+static int mt8196_init_hw(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_data *data = mmdvfs->data;
+ struct mt8196_mmdvfs_data *mt8196_data;
+ struct device_node *node = mmdvfs->dev->of_node;
+
+ /* Allocate platform data */
+ mt8196_data = devm_kzalloc(mmdvfs->dev, sizeof(*mt8196_data), GFP_KERNEL);
+ if (!mt8196_data)
+ return -ENOMEM;
+
+ /* Get HWCCF regmap */
+ mt8196_data->hwv_regmap = syscon_regmap_lookup_by_phandle(node, "mediatek,hwccf");
+ if (IS_ERR(mt8196_data->hwv_regmap)) {
+ dev_err(mmdvfs->dev, "Failed to get HWCCF regmap: %ld\n",
+ PTR_ERR(mt8196_data->hwv_regmap));
+ return PTR_ERR(mt8196_data->hwv_regmap);
+ }
+
+ /* Store platform data */
+ data->platform_data = mt8196_data;
+
+ dev_info(mmdvfs->dev, "MT8196 HWCCF DVFS Voter initialized\n");
+
+ return 0;
+}
+
+/*
+ * mt8196_deinit_hw - Deinitialize hardware
+ */
+static void mt8196_deinit_hw(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_data *data = mmdvfs->data;
+
+ if (data->platform_data) {
+ devm_kfree(mmdvfs->dev, data->platform_data);
+ data->platform_data = NULL;
+ }
+
+ dev_info(mmdvfs->dev, "MT8196 HWCCF DVFS Voter deinitialized\n");
+}
+
+/*
+ * mt8196_populate_opp_freq - Populate MUX frequency from OPP table
+ * @mmdvfs: MMDVFS device
+ * @mux: MUX to populate
+ * @rc: Associated RC
+ *
+ * Read frequencies from the OPP table referenced by this mux's DT phandle.
+ * The OPP level determines its hardware voter index.
+ */
+static int mt8196_populate_opp_freq(struct mmdvfs_device *mmdvfs,
+ struct mmdvfs_mux *mux,
+ struct mmdvfs_rc *rc)
+{
+ struct device_node *opp_table, *opp = NULL;
+ unsigned long seen = 0;
+ u32 opp_level;
+ u64 freq;
+ int level = 0, ret;
+
+ opp_table = of_parse_phandle(mmdvfs->dev->of_node,
+ "mediatek,mux-opp-tables", mux->id);
+ if (!opp_table) {
+ mmdvfs_err(mmdvfs->dev, "MUX %u (%s): missing OPP table phandle\n",
+ mux->id, mux->name);
+ return -EINVAL;
+ }
+
+ /* Parse all available OPP entries */
+ do {
+ opp = of_get_next_available_child(opp_table, opp);
+ if (opp) {
+ ret = of_property_read_u32(opp, "opp-level", &opp_level);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %u (%s): missing opp-level in %pOF: %d\n",
+ mux->id, mux->name, opp, ret);
+ of_node_put(opp);
+ of_node_put(opp_table);
+ return ret;
+ }
+
+ if (opp_level >= MMDVFS_MAX_LEVELS ||
+ opp_level >= rc->level_num || seen & BIT(opp_level)) {
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %u (%s): invalid or duplicate OPP level %u\n",
+ mux->id, mux->name, opp_level);
+ of_node_put(opp);
+ of_node_put(opp_table);
+ return -EINVAL;
+ }
+
+ ret = of_property_read_u64(opp, "opp-hz", &freq);
+ if (ret) {
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %u (%s): missing opp-hz in %pOF: %d\n",
+ mux->id, mux->name, opp, ret);
+ of_node_put(opp);
+ of_node_put(opp_table);
+ return ret;
+ }
+
+ mux->freq[opp_level] = freq;
+ seen |= BIT(opp_level);
+ level++;
+ }
+ } while (opp);
+
+ if (!level || seen != GENMASK(level - 1, 0)) {
+ mmdvfs_err(mmdvfs->dev,
+ "MUX %u (%s): OPP levels in %pOF are not contiguous\n",
+ mux->id, mux->name, opp_table);
+ of_node_put(opp_table);
+ return -EINVAL;
+ }
+
+ of_node_put(opp_table);
+ mux->freq_num = level;
+ mmdvfs_info(mmdvfs->dev, "MUX %u (%s): parsed %u OPP frequencies\n",
+ mux->id, mux->name, mux->freq_num);
+ return 0;
+}
+
+/* IC-specific probe function */
+static int mt8196_probe(struct mmdvfs_device *mmdvfs)
+{
+ struct mmdvfs_data *data = mmdvfs->data;
+ int i, ret;
+
+ mmdvfs_info(mmdvfs->dev, "MT8196 IC-specific probe start\n");
+
+ /* Populate frequency tables from OPP tables */
+ for (i = 0; i < data->mux_num; i++) {
+ struct mmdvfs_mux *mux = &data->mux[i];
+ struct mmdvfs_rc *rc = &data->rc[mux->rc];
+
+ ret = mt8196_populate_opp_freq(mmdvfs, mux, rc);
+ if (ret)
+ return ret;
+ }
+
+ mmdvfs_info(mmdvfs->dev, "MT8196 IC-specific probe completed\n");
+ return 0;
+}
+
+/* Platform operations */
+const struct mmdvfs_ops mmdvfs_mt8196_ops = {
+ .probe = mt8196_probe,
+ .hw_vote = mt8196_hw_vote,
+ .init_hw = mt8196_init_hw,
+ .deinit_hw = mt8196_deinit_hw,
+};
+
+/* Per-SoC topology data */
+
+/*
+ * MUX Table (7 MUXes)
+ * MUX order matches DTS clock-names: dis, mdp, mml, smi, ven, vde, img, cam
+ * Note: mux-mdp serves both MDP and MML users (ck2_mdp_sel is shared)
+ * hwv_upd_ofs: 0x0240 (MM_HW_CCF_HW_CCF_MUX_UPDATE_31_0)
+ */
+static const struct mmdvfs_mux mt8196_mux_table[] = {
+ { /* mux-dis: HW_CCF_34, shift=24, upd_id=19 */
+ .id = 0, .rc = MMDVFS_PWR_VDISP, .pos = 0, .shift = 24,
+ .hwccf.hwv_set_ofs = 0x0110,
+ .hwccf.hwv_clr_ofs = 0x0114,
+ .hwccf.hwv_sta_ofs = 0x2c88,
+ .hwccf.hwv_upd_ofs = 0x0240, .hwccf.hwv_upd_id = 19,
+ .name = "ck2_disp_sel"
+ },
+ { /* mux-mdp: HW_CCF_35, shift=0, upd_id=20 (serves both MDP and MML users) */
+ .id = 1, .rc = MMDVFS_PWR_VDISP, .pos = 1, .shift = 0,
+ .hwccf.hwv_set_ofs = 0x0118,
+ .hwccf.hwv_clr_ofs = 0x011c,
+ .hwccf.hwv_sta_ofs = 0x2c8c,
+ .hwccf.hwv_upd_ofs = 0x0240, .hwccf.hwv_upd_id = 20,
+ .name = "ck2_mdp_sel"
+ },
+ { /* mux-smi: HW_CCF_35, shift=8, upd_id=21 */
+ .id = 2, .rc = MMDVFS_PWR_VCORE, .pos = 0, .shift = 8,
+ .hwccf.hwv_set_ofs = 0x0118,
+ .hwccf.hwv_clr_ofs = 0x011c,
+ .hwccf.hwv_sta_ofs = 0x2c8c,
+ .hwccf.hwv_upd_ofs = 0x0240, .hwccf.hwv_upd_id = 21,
+ .name = "ck2_mminfra_sel"
+ },
+ { /* mux-ven: HW_CCF_33, shift=16, upd_id=14 */
+ .id = 3, .rc = MMDVFS_PWR_VCORE, .pos = 1, .shift = 16,
+ .hwccf.hwv_set_ofs = 0x0108,
+ .hwccf.hwv_clr_ofs = 0x010c,
+ .hwccf.hwv_sta_ofs = 0x2c84,
+ .hwccf.hwv_upd_ofs = 0x0240, .hwccf.hwv_upd_id = 14,
+ .name = "ck2_venc_sel"
+ },
+ { /* mux-vde: HW_CCF_32, shift=24, upd_id=11 */
+ .id = 4, .rc = MMDVFS_PWR_VMM, .pos = 0, .shift = 24,
+ .hwccf.hwv_set_ofs = 0x0100,
+ .hwccf.hwv_clr_ofs = 0x0104,
+ .hwccf.hwv_sta_ofs = 0x2c80,
+ .hwccf.hwv_upd_ofs = 0x0240, .hwccf.hwv_upd_id = 11,
+ .name = "ck2_vdec_sel"
+ },
+ { /* mux-img: HW_CCF_31, shift=16, upd_id=6 */
+ .id = 5, .rc = MMDVFS_PWR_VMM, .pos = 1, .shift = 16,
+ .hwccf.hwv_set_ofs = 0x00f8,
+ .hwccf.hwv_clr_ofs = 0x00fc,
+ .hwccf.hwv_sta_ofs = 0x2c7c,
+ .hwccf.hwv_upd_ofs = 0x0240, .hwccf.hwv_upd_id = 6,
+ .name = "ck2_img1_sel"
+ },
+ { /* mux-cam: HW_CCF_32, shift=0, upd_id=8 */
+ .id = 6, .rc = MMDVFS_PWR_VMM, .pos = 2, .shift = 0,
+ .hwccf.hwv_set_ofs = 0x0100,
+ .hwccf.hwv_clr_ofs = 0x0104,
+ .hwccf.hwv_sta_ofs = 0x2c80,
+ .hwccf.hwv_upd_ofs = 0x0240, .hwccf.hwv_upd_id = 8,
+ .name = "ck2_cam_sel"
+ },
+};
+
+/*
+ * Users - Static configuration (topology defined in code, not DTS)
+ * MUX mapping (7 MUXes): 0=dis 1=mdp/mml 2=smi 3=ven 4=vde 5=img 6=cam
+ * Note: MML users share mux[1] with MDP users (ck2_mdp_sel)
+ */
+static const struct mmdvfs_user mt8196_user_table[] = {
+ /* Core users (0-23) */
+ [0] = {.id = 0, .name = "user-disp", .mux = 0, .level = 0}, /* MMDVFS_USER_DISP */
+ [1] = {.id = 1, .name = "user-mdp", .mux = 1, .level = 0}, /* MMDVFS_USER_MDP */
+ [2] = {.id = 2, .name = "user-mml", .mux = 1, .level = 0}, /* MMDVFS_USER_MML */
+ [3] = {.id = 3, .name = "user-smi", .mux = 2, .level = 0}, /* MMDVFS_USER_SMI */
+ [4] = {.id = 4, .name = "user-jpegdec", .mux = 3, .level = 0}, /* MMDVFS_USER_JPEGDEC */
+ [5] = {.id = 5, .name = "user-jpegenc", .mux = 3, .level = 0}, /* MMDVFS_USER_JPEGENC */
+ [6] = {.id = 6, .name = "user-venc", .mux = 3, .level = 0}, /* MMDVFS_USER_VENC */
+ [7] = {.id = 7, .name = "user-vfmt", .mux = 4, .level = 0}, /* MMDVFS_USER_VFMT */
+ [8] = {.id = 8, .name = "user-img", .mux = 5, .level = 0}, /* MMDVFS_USER_IMG */
+ [9] = {.id = 9, .name = "user-cam", .mux = 6, .level = 0}, /* MMDVFS_USER_CAM */
+ [10] = {.id = 10, .name = "user-vcore", .mux = 3, .level = 0}, /* MMDVFS_USER_VCORE */
+ [11] = {.id = 11, .name = "user-vmm", .mux = 6, .level = 0}, /* MMDVFS_USER_VMM */
+ [12] = {.id = 12, .name = "user-vdisp", .mux = 1, .level = 0}, /* MMDVFS_USER_VDISP */
+ [13] = {.id = 13, .name = "user-vdec", .mux = 4, .level = 0}, /* MMDVFS_USER_VDEC */
+ [14] = {.id = 14, .name = "dummy-dis", .mux = 0, .level = 0}, /* DUMMY_USER_DIS */
+ [15] = {.id = 15, .name = "dummy-mdp", .mux = 1, .level = 0}, /* DUMMY_USER_MDP */
+ [16] = {.id = 16, .name = "dummy-mml", .mux = 1, .level = 0}, /* DUMMY_USER_MML */
+ [17] = {.id = 17, .name = "dummy-smi", .mux = 2, .level = 0}, /* DUMMY_USER_SMI */
+ [18] = {.id = 18, .name = "dummy-ven", .mux = 3, .level = 0}, /* DUMMY_USER_VEN */
+ [19] = {.id = 19, .name = "dummy-vde", .mux = 4, .level = 0}, /* DUMMY_USER_VDE */
+ [20] = {.id = 20, .name = "dummy-img", .mux = 5, .level = 0}, /* DUMMY_USER_IMG */
+ [21] = {.id = 21, .name = "dummy-cam", .mux = 6, .level = 0}, /* DUMMY_USER_CAM */
+ [22] = {.id = 22, .name = "user-cam-smi", .mux = 2, .level = 0}, /* MMDVFS_USER_CAM_SMI */
+ [23] = {.id = 23, .name = "user-vcp-smi", .mux = 2, .level = 0}, /* MMDVFS_USER_VCP_SMI */
+
+ /* AP voters (24-33) */
+ [24] = {.id = 24, .name = "mmdvfs-ap-cam", .mux = 6, .level = 0},
+ [25] = {.id = 25, .name = "mmdvfs-ap-camtm", .mux = 6, .level = 0},
+ [26] = {.id = 26, .name = "mmdvfs-ap-vde", .mux = 4, .level = 0},
+ [27] = {.id = 27, .name = "mmdvfs-ap-img", .mux = 5, .level = 0},
+ [28] = {.id = 28, .name = "mmdvfs-ap-ipe", .mux = 5, .level = 0},
+ [29] = {.id = 29, .name = "mmdvfs-ap-dis", .mux = 0, .level = 0},
+ [30] = {.id = 30, .name = "mmdvfs-ap-mml", .mux = 1, .level = 0},
+ [31] = {.id = 31, .name = "mmdvfs-ap-smi", .mux = 2, .level = 0},
+ [32] = {.id = 32, .name = "mmdvfs-ap-ven", .mux = 3, .level = 0},
+ [33] = {.id = 33, .name = "mmdvfs-ap-mdp", .mux = 1, .level = 0},
+
+ /* VCP voters (34-43) */
+ [34] = {.id = 34, .name = "mmdvfs-vcp-cam", .mux = 6, .level = 0},
+ [35] = {.id = 35, .name = "mmdvfs-vcp-camtm", .mux = 6, .level = 0},
+ [36] = {.id = 36, .name = "mmdvfs-vcp-vde", .mux = 4, .level = 0},
+ [37] = {.id = 37, .name = "mmdvfs-vcp-img", .mux = 5, .level = 0},
+ [38] = {.id = 38, .name = "mmdvfs-vcp-ipe", .mux = 5, .level = 0},
+ [39] = {.id = 39, .name = "mmdvfs-vcp-dis", .mux = 0, .level = 0},
+ [40] = {.id = 40, .name = "mmdvfs-vcp-mml", .mux = 1, .level = 0},
+ [41] = {.id = 41, .name = "mmdvfs-vcp-smi", .mux = 2, .level = 0},
+ [42] = {.id = 42, .name = "mmdvfs-vcp-ven", .mux = 3, .level = 0},
+ [43] = {.id = 43, .name = "mmdvfs-vcp-mdp", .mux = 1, .level = 0},
+};
+
+/*
+ * mmdvfs_mt8196_soc_data - SoC topology and configuration
+ * Uses HWCCF DVFS Voter
+ */
+const struct mmdvfs_soc_data mmdvfs_mt8196_soc_data = {
+ .rc_table = mt8196_rc,
+ .rc_num = ARRAY_SIZE(mt8196_rc),
+ .mux_table = mt8196_mux_table,
+ .mux_num = ARRAY_SIZE(mt8196_mux_table),
+ .user_table = mt8196_user_table,
+ .user_num = ARRAY_SIZE(mt8196_user_table),
+ .version = MMDVFS_VERSION_HWCCF_DVFS_VOTER,
+ .vote_requires_up_ready = true,
+};
--
2.45.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 6/7] soc: mediatek: mmdvfs: add read-only status debug
2026-11-25 6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
` (4 preceding siblings ...)
2026-11-25 6:00 ` [PATCH 5/7] soc: mediatek: mmdvfs: add MT8196 support Echo Zhang
@ 2026-11-25 6:00 ` Echo Zhang
2026-11-25 6:00 ` [PATCH 7/7] MAINTAINERS: add MediaTek MMDVFS entry Echo Zhang
6 siblings, 0 replies; 18+ messages in thread
From: Echo Zhang @ 2026-11-25 6:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
Expose MMDVFS topology and software power references through a read-only
debugfs status file. Use seq_file so large topologies are not limited by
a PAGE_SIZE module parameter buffer. Firmware shared memory and SRAM
contents remain outside this diagnostic path.
Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
---
drivers/soc/mediatek/mmdvfs/Makefile | 1 +
drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c | 200 +++++++++++++++++++++
2 files changed, 201 insertions(+)
create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c
diff --git a/drivers/soc/mediatek/mmdvfs/Makefile b/drivers/soc/mediatek/mmdvfs/Makefile
index d02ebd63e6ae..3d780b29efe7 100644
--- a/drivers/soc/mediatek/mmdvfs/Makefile
+++ b/drivers/soc/mediatek/mmdvfs/Makefile
@@ -7,3 +7,4 @@ mtk-mmdvfs-y += mmdvfs-clk.o
mtk-mmdvfs-y += mmdvfs-up.o
mtk-mmdvfs-y += mmdvfs-vcp.o
mtk-mmdvfs-$(CONFIG_MTK_MMDVFS_MT8196) += mmdvfs-mt8196.o
+mtk-mmdvfs-$(CONFIG_DEBUG_FS) += mmdvfs-debug.o
diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c
new file mode 100644
index 000000000000..7d7324ff6577
--- /dev/null
+++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-debug.c
@@ -0,0 +1,200 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (c) 2026 MediaTek Inc. */
+
+#include <linux/debugfs.h>
+#include <linux/module.h>
+#include <linux/seq_file.h>
+
+#include "mmdvfs-internal.h"
+
+static const char *mmdvfs_status_rc_name(u8 id)
+{
+ switch (id) {
+ case MMDVFS_PWR_VCORE:
+ return "VCORE";
+ case MMDVFS_PWR_VMM:
+ return "VMM";
+ case MMDVFS_PWR_VDISP:
+ return "VDISP";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+static const char *mmdvfs_status_power_user_name(int id)
+{
+ static const char *const names[VCP_PWR_USR_NUM] = {
+ [VCP_PWR_USR_MMDVFS_INIT] = "INIT",
+ [VCP_PWR_USR_MMDVFS_VOTE] = "VOTE",
+ [VCP_PWR_USR_MMDVFS_CCU] = "CCU",
+ [VCP_PWR_USR_MMDVFS_RST] = "RST",
+ [VCP_PWR_USR_MMQOS] = "MMQOS",
+ [VCP_PWR_USR_CAM] = "CAM",
+ [VCP_PWR_USR_IMG] = "IMG",
+ [VCP_PWR_USR_PDA] = "PDA",
+ [VCP_PWR_USR_SENIF] = "SENIF",
+ [VCP_PWR_USR_VDEC] = "VDEC",
+ [VCP_PWR_USR_VFMT] = "VFMT",
+ [VCP_PWR_USR_SMI] = "SMI",
+ [VCP_PWR_USR_DISP] = "DISP",
+ [VCP_PWR_USR_MDP] = "MDP",
+ [VCP_PWR_USR_MML] = "MML",
+ [VCP_PWR_USR_VENC] = "VENC",
+ [VCP_PWR_USR_JPEGDEC] = "JPEGDEC",
+ [VCP_PWR_USR_JPEGENC] = "JPEGENC",
+ };
+
+ return id >= 0 && (unsigned int)id < ARRAY_SIZE(names) && names[id] ?
+ names[id] :
+ "OTHER";
+}
+
+static int mmdvfs_status_show(struct seq_file *s, void *unused)
+{
+ struct mmdvfs_device *mmdvfs = s->private;
+ struct mmdvfs_data *data;
+ int pwr_usage[VCP_PWR_USR_NUM] = {};
+ int vcp_power = 0, active_power_users = 0, active_users = 0;
+ int ret, rc_idx, mux_idx, user_idx, i;
+
+ if (!mmdvfs || !mmdvfs->data) {
+ seq_puts(s, "ERROR: Device not ready\n");
+ return 0;
+ }
+
+ data = mmdvfs->data;
+ seq_puts(s, "=== MMDVFS Status ===\n\n");
+ seq_puts(s, "Version: ");
+ switch (data->version) {
+ case MMDVFS_VERSION_HWCCF_DVFS_VOTER:
+ seq_puts(s, "HWCCF DVFS Voter\n");
+ break;
+ case MMDVFS_VERSION_NONE:
+ seq_puts(s, "No hardware voter\n");
+ break;
+ default:
+ seq_printf(s, "Unknown (%u)\n", data->version);
+ break;
+ }
+ seq_printf(s, "Initialized: %s\n", data->init_done ? "yes" : "no");
+ seq_printf(s, "Total: %u RCs, %u MUXes, %u Users\n", data->rc_num,
+ data->mux_num, data->user_num);
+
+ seq_puts(s, "\n--- Power Management ---\n");
+ ret = mmdvfs_vcp_get_power_info(mmdvfs, &vcp_power, pwr_usage);
+ if (ret)
+ seq_printf(s, "VCP Power Refcount: unavailable (%d)\n", ret);
+ else
+ seq_printf(s, "VCP Power Refcount: %d\n", vcp_power);
+ if (!ret) {
+ for (i = 0; i < VCP_PWR_USR_NUM; i++)
+ if (pwr_usage[i] > 0)
+ active_power_users++;
+ if (active_power_users) {
+ seq_printf(s, "VCP Power Users (%d active):\n",
+ active_power_users);
+ for (i = 0; i < VCP_PWR_USR_NUM; i++) {
+ if (pwr_usage[i] > 0)
+ seq_printf(s, " [%2d] %s: %d\n", i,
+ mmdvfs_status_power_user_name(i),
+ pwr_usage[i]);
+ }
+ }
+ }
+
+ seq_puts(s, "\n--- Active Users (level > 0) ---\n");
+ for (user_idx = 0; user_idx < data->user_num; user_idx++) {
+ struct mmdvfs_user *user = &data->user[user_idx];
+ struct mmdvfs_mux *mux;
+
+ if (user->level == 0 || user->level == 0xff ||
+ user->mux >= data->mux_num)
+ continue;
+ mux = &data->mux[user->mux];
+ if (mux->rc >= data->rc_num)
+ continue;
+ seq_printf(s, "User[%2u] %-20s RC=%s MUX=%s lvl=%u\n", user->id,
+ user->name ?: "(null)",
+ mmdvfs_status_rc_name(data->rc[mux->rc].id),
+ mux->name ?: "(null)", user->level);
+ active_users++;
+ }
+ if (!active_users)
+ seq_puts(s, "(No active users)\n");
+ else
+ seq_printf(s, "Total: %d active users\n", active_users);
+
+ seq_puts(s, "\n--- Resource Controllers ---\n");
+ for (rc_idx = 0; rc_idx < data->rc_num; rc_idx++) {
+ struct mmdvfs_rc *rc = &data->rc[rc_idx];
+ int mux_count = 0;
+ u8 freq_num = 0;
+
+ for (mux_idx = 0; mux_idx < data->mux_num; mux_idx++) {
+ struct mmdvfs_mux *mux = &data->mux[mux_idx];
+
+ if (mux->rc != rc_idx)
+ continue;
+ mux_count++;
+ if (!freq_num)
+ freq_num = mux->freq_num;
+ }
+ seq_printf(s, "RC[%u] %s (freq_num=%u, muxes=%u)\n", rc->id,
+ mmdvfs_status_rc_name(rc->id), freq_num, mux_count);
+
+ for (mux_idx = 0; mux_idx < data->mux_num; mux_idx++) {
+ struct mmdvfs_mux *mux = &data->mux[mux_idx];
+ int user_count = 0;
+
+ if (mux->rc != rc_idx)
+ continue;
+ for (user_idx = 0; user_idx < data->user_num;
+ user_idx++)
+ if (data->user[user_idx].mux == mux_idx)
+ user_count++;
+ seq_printf(s, " +- MUX[%u] %s (users=%u)\n", mux->id,
+ mux->name ?: "(null)", user_count);
+ for (user_idx = 0; user_idx < data->user_num;
+ user_idx++) {
+ struct mmdvfs_user *user =
+ &data->user[user_idx];
+
+ if (user->mux != mux_idx)
+ continue;
+ seq_printf(s,
+ " |-- User[%2u] %s (level=%u)\n",
+ user->id, user->name ?: "(null)",
+ user->level);
+ }
+ }
+ seq_puts(s, "\n");
+ }
+
+ return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(mmdvfs_status);
+
+void mmdvfs_debug_init(struct mmdvfs_device *mmdvfs)
+{
+ struct dentry *dir, *file;
+
+ dir = debugfs_create_dir("mtk_mmdvfs", NULL);
+ if (IS_ERR_OR_NULL(dir))
+ return;
+
+ file = debugfs_create_file("status", 0444, dir, mmdvfs,
+ &mmdvfs_status_fops);
+ if (IS_ERR_OR_NULL(file)) {
+ debugfs_remove(dir);
+ return;
+ }
+
+ mmdvfs->debugfs_dir = dir;
+}
+
+void mmdvfs_debug_exit(struct mmdvfs_device *mmdvfs)
+{
+ debugfs_remove_recursive(mmdvfs->debugfs_dir);
+ mmdvfs->debugfs_dir = NULL;
+}
--
2.45.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 7/7] MAINTAINERS: add MediaTek MMDVFS entry
2026-11-25 6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
` (5 preceding siblings ...)
2026-11-25 6:00 ` [PATCH 6/7] soc: mediatek: mmdvfs: add read-only status debug Echo Zhang
@ 2026-11-25 6:00 ` Echo Zhang
6 siblings, 0 replies; 18+ messages in thread
From: Echo Zhang @ 2026-11-25 6:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
Add a maintainer entry for the MediaTek MMDVFS driver, including the
device-tree bindings, driver sources, clock IDs, and public header.
Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
---
MAINTAINERS | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 27461b2161a7..eed0df58178b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17179,6 +17179,17 @@ F: Documentation/devicetree/bindings/media/mediatek,mt8173-vpu.yaml
F: drivers/media/platform/mediatek/vcodec/
F: drivers/media/platform/mediatek/vpu/
+MEDIATEK MMDVFS DRIVER
+M: Echo Zhang <echo.zhang@mediatek.com>
+L: kyrie.wu@mediatek.com
+L: ming-fan.chen@mediatek.com
+S: Supported
+F: Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml
+F: Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
+F: drivers/soc/mediatek/mmdvfs/
+F: include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h
+F: include/soc/mediatek/mmdvfs.h
+
MEDIATEK MIPI-CSI CDPHY DRIVER
M: Julien Stephan <jstephan@baylibre.com>
M: Andy Hsieh <andy.hsieh@mediatek.com>
--
2.45.2
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding
2026-11-25 6:00 ` [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding Echo Zhang
@ 2026-11-25 8:32 ` Roman Vivchar
2026-11-25 10:58 ` Krzysztof Kozlowski
2026-11-25 11:58 ` Krzysztof Kozlowski
2 siblings, 0 replies; 18+ messages in thread
From: Roman Vivchar @ 2026-11-25 8:32 UTC (permalink / raw)
To: Echo Zhang
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
AngeloGioacchino Del Regno, Stephen Boyd, Brian Masney,
Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
Hi,
On Wednesday, November 25th, 2026 at 8:01 AM, Echo Zhang <echo.zhang@mediatek.com> wrote:
> Describe the MMDVFS clock provider and its connection to VCP firmware
> in a common binding. Document the optional MMUP shared memory and IPI
> settings used by the firmware backend.
>
> Add an MT8196 binding for the HWCCF syscon and seven mux OPP tables so
> the driver can map clock rate requests to hardware votes.
>
> Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
> ---
> .../soc/mediatek/mediatek,mmdvfs.yaml | 60 +++++++++++++
> .../soc/mediatek/mediatek,mt8196-mmdvfs.yaml | 87 +++++++++++++++++++
> 2 files changed, 147 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml
> create mode 100644 Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
>
> diff --git a/Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml
> new file mode 100644
> index 000000000000..d65f4c9084cc
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mmdvfs.yaml
> @@ -0,0 +1,60 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/soc/mediatek/mediatek,mmdvfs.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: MediaTek Multimedia Dynamic Voltage and Frequency Scaling (MMDVFS)
> +
> +maintainers:
> + - MediaTek MMDVFS Team <linux-mediatek@lists.infradead.org>
Maintainers should be real people, not a mailing list.
> +
> +description:
> + MediaTek MMDVFS provides dynamic voltage and frequency scaling for multimedia
> + hardware accelerators. The controller exposes virtual clocks that multimedia
> + consumers use through the common clock framework. The driver aggregates
> + consumer rate requests and sends the resulting DVFS votes to the multimedia
> + hardware voter and VCP firmware.
> +
> +select: false
> +
> +properties:
> + mediatek,vcp:
> + $ref: /schemas/types.yaml#/definitions/phandle
> + description:
> + Phandle to the MediaTek VCP remote processor used for MMDVFS shared
> + memory, feature registration, notifier, and IPI operations.
> +
> + mediatek,mmup-sram:
> + type: boolean
> + description:
> + Use the MMUP SRAM window for MMDVFS callback records and status data.
> +
> + mediatek,mmup-enable:
> + type: boolean
> + description:
> + Enable the MMUP path for MMDVFS shared memory and IPI handling.
> +
> + mediatek,vcp-ipi-id:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + VCP IPI channel id for MMDVFS. If omitted, the driver uses the platform
> + default.
> +
> + mediatek,mmup-ipi-id:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + MMUP IPI channel id for MMDVFS. If omitted, the driver uses the platform
> + default.
> +
> + "#clock-cells":
> + const: 1
> + description:
> + MMDVFS clock specifier. Consumers pass an SoC-specific MMDVFS clock
> + index.
> +
> +required:
> + - mediatek,vcp
> + - "#clock-cells"
> +
> +additionalProperties: true
> diff --git a/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
> new file mode 100644
> index 000000000000..13381c78dbd1
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
> @@ -0,0 +1,87 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/soc/mediatek/mediatek,mt8196-mmdvfs.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: MediaTek MT8196 Multimedia Dynamic Voltage and Frequency Scaling
Why there's mediatek,mmdvfs.yaml file if this exists?
> +
> +maintainers:
> + - MediaTek MMDVFS Team <linux-mediatek@lists.infradead.org>
> +
> +allOf:
> + - $ref: mediatek,mmdvfs.yaml#
> +
> +select:
> + properties:
> + compatible:
> + contains:
> + enum:
> + - mediatek,mt8196-mmdvfs
> + required:
> + - compatible
Drop. select is automatically inferred from the compatible.
Best regards,
Roman
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 3/7] soc: mediatek: add MMDVFS core driver
2026-11-25 6:00 ` [PATCH 3/7] soc: mediatek: add MMDVFS core driver Echo Zhang
@ 2026-11-25 8:35 ` Roman Vivchar
2026-11-25 10:54 ` Krzysztof Kozlowski
1 sibling, 0 replies; 18+ messages in thread
From: Roman Vivchar @ 2026-11-25 8:35 UTC (permalink / raw)
To: Echo Zhang
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
AngeloGioacchino Del Regno, Stephen Boyd, Brian Masney,
Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
On Wednesday, November 25th, 2026 at 8:01 AM, Echo Zhang <echo.zhang@mediatek.com> wrote:
> Add the common MediaTek MMDVFS driver framework.
>
> The core driver handles device probing, SoC data selection, clock provider
> registration, power-management notification, and dispatch to the
> microprocessor transport used for runtime performance voting.
>
> Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
> ---
...
> diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
> new file mode 100644
> index 000000000000..c32fa11557af
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
> @@ -0,0 +1,581 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2026 MediaTek Inc.
> + *
> + * MediaTek MMDVFS Core Framework
> + */
> +
> +#include <linux/atomic.h>
> +#include <linux/clk-provider.h>
> +#include <linux/device.h>
> +#include <linux/err.h>
> +#include <linux/io.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/notifier.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/platform_device.h>
> +#include <linux/sched/clock.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <linux/suspend.h>
> +#include <linux/workqueue.h>
> +
> +#include "mmdvfs-internal.h"
> +
> +static int mmdvfs_register_device(struct mmdvfs_device *mmdvfs);
> +static void mmdvfs_unregister_device(struct mmdvfs_device *mmdvfs);
> +
> +struct mmdvfs_device *mmdvfs_find_device_by_version(enum mmdvfs_version_type version);
> +struct mmdvfs_device *mmdvfs_find_device_any(void);
> +
> +struct mmdvfs_device *mmdvfs_find_device_any(void)
> +{
> + return mmdvfs_find_device_by_version(MMDVFS_VERSION_HWCCF_DVFS_VOTER);
> +}
> +EXPORT_SYMBOL_GPL(mmdvfs_find_device_any);
Ambiguous function name. any would mean *any* version, but it uses
hardware here.
> +
> +/**
> + * mmdvfs_get_version - Get MMDVFS voting mechanism type
> + *
> + * Return:
> + * 0 - No hardware voter
> + * 1 - HWCCF DVFS voter
> + */
> +u32 mmdvfs_get_version(void)
> +{
> + struct mmdvfs_device *mmdvfs;
> +
> + mmdvfs = mmdvfs_find_device_any();
> + if (!mmdvfs || !mmdvfs->data)
> + return MMDVFS_VERSION_NONE;
> +
> + return mmdvfs->data->version;
> +}
> +EXPORT_SYMBOL_GPL(mmdvfs_get_version);
> +
> +/*
> + * mmdvfs_validate_topology - Validate RC/MUX/User topology consistency
> + * @mmdvfs: MMDVFS device structure
> + *
> + * Return: 0 on success, -EINVAL if topology validation fails
> + */
> +static int mmdvfs_validate_topology(struct mmdvfs_device *mmdvfs)
> +{
> + struct mmdvfs_data *data = mmdvfs->data;
> + int i, j;
> +
> + if (!data || !data->mux || !data->rc) {
> + mmdvfs_err(mmdvfs->dev, "Invalid data structures for validation\n");
> + return -EINVAL;
> + }
> +
> + for (i = 0; i < data->mux_num; i++) {
> + struct mmdvfs_mux *mux = &data->mux[i];
> + struct mmdvfs_rc *rc;
> +
> + if (!mux->name || strlen(mux->name) == 0) {
> + mmdvfs_err(mmdvfs->dev, "MUX %d has empty name\n", i);
> + return -EINVAL;
> + }
> +
> + if (mux->rc >= data->rc_num) {
> + mmdvfs_err(mmdvfs->dev,
> + "MUX %d (%s) has invalid RC reference: %d (max: %d)\n",
> + i, mux->name, mux->rc, data->rc_num);
> + return -EINVAL;
> + }
> +
> + rc = &data->rc[mux->rc];
> +
> + if (rc->level_num == 0 || rc->level_num > MMDVFS_MAX_LEVELS) {
> + mmdvfs_err(mmdvfs->dev,
> + "MUX %d (%s): RC %d has invalid level_num: %d\n",
> + i, mux->name, mux->rc, rc->level_num);
> + return -EINVAL;
> + }
> +
> + if (mux->freq_num == 0 || mux->freq_num > MMDVFS_MAX_LEVELS) {
> + mmdvfs_err(mmdvfs->dev,
> + "MUX %d (%s): invalid freq_num: %d\n",
> + i, mux->name, mux->freq_num);
> + return -EINVAL;
> + }
> +
> + for (j = 0; j < mux->freq_num; j++) {
> + if (mux->freq[j] == 0) {
> + mmdvfs_err(mmdvfs->dev,
> + "MUX %d (%s): incomplete freq table at level %d/%d (freq=0)\n",
> + i, mux->name, j, mux->freq_num);
> + return -EINVAL;
> + }
> +
> + if (j > 0 && mux->freq[j] <= mux->freq[j - 1]) {
> + mmdvfs_warn(mmdvfs->dev,
> + "MUX %d (%s): freq not ascending: freq[%d]=%llu <= freq[%d]=%llu\n",
> + i, mux->name, j, mux->freq[j],
> + j - 1, mux->freq[j - 1]);
> + }
> + }
> +
> + mmdvfs_dbg(mmdvfs->dev,
> + "MUX[%d] validated: name=%s, rc=%d, freq_num=%d (RC levels=%d), freq_min=%llu, freq_max=%llu\n",
> + i, mux->name, mux->rc, mux->freq_num,
> + rc->level_num, mux->freq[0],
> + mux->freq[mux->freq_num - 1]);
> + }
> +
> + for (i = 0; i < data->user_num; i++) {
> + struct mmdvfs_user *user = &data->user[i];
> +
> + if (!user->name || strlen(user->name) == 0) {
> + mmdvfs_err(mmdvfs->dev, "User %d has empty name\n", i);
> + return -EINVAL;
> + }
> +
> + if (user->mux >= data->mux_num) {
> + mmdvfs_err(mmdvfs->dev,
> + "User %d (%s) has invalid MUX reference: %d (max: %d)\n",
> + i, user->name, user->mux, data->mux_num);
> + return -EINVAL;
> + }
> +
> + mmdvfs_dbg(mmdvfs->dev,
> + "User[%d] validated: name=%s, id=%d, mux=%d\n",
> + i, user->name, user->id, user->mux);
> + }
> +
> + mmdvfs_info(mmdvfs->dev, "Topology validation successful\n");
Do we really need these logs? This applies to the rest of the driver
too.
...
> +/*
> + * mmdvfs_parse_dt - Parse device tree configuration
> + * @mmdvfs: MMDVFS device structure
> + *
> + * Return: 0 on success, negative error code on failure
> + */
> +int mmdvfs_parse_dt(struct mmdvfs_device *mmdvfs)
> +{
> + struct device_node *node = mmdvfs->dev->of_node;
> +
> + if (!node) {
> + mmdvfs_err(mmdvfs->dev, "No device tree node found\n");
> + return -ENODEV;
> + }
> +
> + mmdvfs_info(mmdvfs->dev, "Device tree parsed (hardware attributes)\n");
> +
> + return 0;
This is not DT parsing.
> +}
> +
> +/*
> + * mmdvfs_pm_notifier_callback - PM notifier callback for suspend/resume handling
> + * @nb: Notifier block
> + * @event: PM event type
> + * @data: Event data
> + *
> + * Return: NOTIFY_DONE
> + */
> +static int mmdvfs_pm_notifier_callback(struct notifier_block *nb, unsigned long event,
> + void *data)
> +{
> + struct mmdvfs_data *mdata =
> + container_of(nb, struct mmdvfs_data, pm_notifier);
> + struct mmdvfs_device *mmdvfs = dev_get_drvdata(mdata->dev);
> +
> + switch (event) {
> + case PM_SUSPEND_PREPARE:
> + mmdvfs_dbg(mmdvfs->dev, "System suspending...\n");
> +
> + if (mdata->ops && mdata->ops->suspend_prepare)
> + mdata->ops->suspend_prepare(mmdvfs);
> +
> + mdata->pm_suspended = true;
> + break;
> +
> + case PM_POST_SUSPEND:
> + mmdvfs_dbg(mmdvfs->dev, "System resumed\n");
> +
> + mdata->pm_suspended = false;
> +
> + if (mdata->ops && mdata->ops->post_suspend)
> + mdata->ops->post_suspend(mmdvfs);
> + break;
> +
> + default:
> + break;
> + }
> +
> + return NOTIFY_DONE;
> +}
> +
> +/*
> + * mmdvfs_probe - Main probe function
> + * @pdev: Platform device
> + *
> + * Return: 0 on success, negative error code on failure
> + */
> +static int mmdvfs_probe(struct platform_device *pdev)
> +{
> + struct mmdvfs_device *mmdvfs;
> + struct mmdvfs_data *data;
> + const struct mmdvfs_platform_data *pdata;
> + int ret;
> +
> + mmdvfs = devm_kzalloc(&pdev->dev, sizeof(*mmdvfs), GFP_KERNEL);
> + if (!mmdvfs)
> + return -ENOMEM;
> +
> + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + mmdvfs->dev = &pdev->dev;
> + mmdvfs->data = data;
> + data->dev = &pdev->dev;
> +
> + mutex_init(&data->lock);
> +
> + platform_set_drvdata(pdev, mmdvfs);
> +
> + pdata = of_device_get_match_data(&pdev->dev);
> + if (!pdata) {
This is not possible, since you already have mt8196 platform data in
the table. Drop the check.
> + mmdvfs_err(mmdvfs->dev, "No matching platform data\n");
> + return -ENODEV;
> + }
> +
> + data->ops = pdata->ops;
> + data->version = pdata->soc_data->version;
> +
> + if (data->version == MMDVFS_VERSION_HWCCF_DVFS_VOTER) {
> + data->hwccf_voter_priv = devm_kzalloc(&pdev->dev,
> + sizeof(*data->hwccf_voter_priv),
> + GFP_KERNEL);
> + if (!data->hwccf_voter_priv)
> + return -ENOMEM;
> +
> + data->hwccf_voter_priv->mmdvfs = mmdvfs;
> + }
> +
> + ret = mmdvfs_parse_dt(mmdvfs);
> + if (ret) {
> + mmdvfs_err(mmdvfs->dev, "Failed to parse device tree: %d\n", ret);
> + return ret;
dev_err_probe
> + }
> +
> + ret = mmdvfs_init_from_soc_data(mmdvfs, pdata->soc_data);
> + if (ret) {
> + mmdvfs_err(mmdvfs->dev, "Failed to initialize from SoC data: %d\n", ret);
> + return ret;
...same...
> + }
> +
> + if (data->ops && data->ops->init_hw) {
> + ret = data->ops->init_hw(mmdvfs);
> + if (ret) {
> + mmdvfs_err(mmdvfs->dev, "Failed to initialize hardware: %d\n", ret);
> + return ret;
here too.
> + }
> + }
> +
> + data->init_done = true;
> +
> + ret = mmdvfs_register_clocks(mmdvfs);
> + if (ret) {
> + mmdvfs_err(mmdvfs->dev, "Failed to register clocks: %d\n", ret);
> + goto err_deinit_hw;
> + }
> +
> + data->pm_notifier.notifier_call = mmdvfs_pm_notifier_callback;
> + data->pm_notifier.priority = 0;
> + data->pm_suspended = false;
> + ret = register_pm_notifier(&data->pm_notifier);
> + if (ret) {
> + mmdvfs_err(mmdvfs->dev, "Failed to register PM notifier: %d\n", ret);
> + goto err_unregister_clocks;
> + }
> + mmdvfs_info(mmdvfs->dev, "PM notifier registered\n");
> +
> + ret = mmdvfs_register_device(mmdvfs);
> + if (ret) {
> + mmdvfs_err(mmdvfs->dev, "Failed to register device: %d\n", ret);
> + goto err_unregister_pm_notifier;
> + }
> +
> + mmdvfs_info(mmdvfs->dev, "MMDVFS driver probed successfully\n");
> + return 0;
> +
> +err_unregister_pm_notifier:
> + unregister_pm_notifier(&data->pm_notifier);
> +
> +err_unregister_clocks:
> + mmdvfs_unregister_clocks(mmdvfs);
> +
> +err_deinit_hw:
> + if (data->ops && data->ops->deinit_hw)
> + data->ops->deinit_hw(mmdvfs);
> +
> + return ret;
> +}
> +
...
> +struct mmdvfs_device *mmdvfs_find_device_by_version(enum mmdvfs_version_type version)
> +{
> + struct mmdvfs_device_node *node;
> + struct mmdvfs_device *found = NULL;
> +
> + mutex_lock(&mmdvfs_device_list_lock);
guard(mutex)(&mmdvfs_device_list_lock)
> + list_for_each_entry(node, &mmdvfs_device_list, list) {
> + if (node->mmdvfs && node->mmdvfs->data &&
> + node->mmdvfs->data->version == version) {
> + found = node->mmdvfs;
> + break;
> + }
> + }
> + mutex_unlock(&mmdvfs_device_list_lock);
> +
> + return found;
> +}
> +EXPORT_SYMBOL_GPL(mmdvfs_find_device_by_version);
> +
...
> diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h b/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
> new file mode 100644
> index 000000000000..df16e38d78c8
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
> @@ -0,0 +1,305 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (c) 2026 MediaTek Inc.
> + *
> + * MediaTek MMDVFS (MultiMedia Dynamic Voltage and Frequency Scaling) Driver
> + */
> +
> +#ifndef __MMDVFS_H__
> +#define __MMDVFS_H__
> +
> +#include <linux/clk-provider.h>
> +#include <linux/device.h>
> +#include <linux/mutex.h>
> +#include <linux/notifier.h>
> +#include <linux/platform_device.h>
> +
> +struct dentry;
> +
> +#define MMDVFS_MAX_LEVELS 8
> +#define MMDVFS_MAX_USERS 64
> +#define MMDVFS_MAX_MUXES 16
> +#define MMDVFS_MAX_RCS 4
> +
> +/* MMDVFS voting mechanism types */
> +enum mmdvfs_version_type {
> + MMDVFS_VERSION_NONE = 0, /* No hardware voter */
> + MMDVFS_VERSION_HWCCF_DVFS_VOTER = 1, /* HWCCF DVFS voter */
> +};
> +
> +#define MAX_OPP 8
> +
> +/* MMDVFS RC domains */
> +enum mmdvfs_rc_domain {
> + MMDVFS_PWR_VCORE = 0, /* PWR_MMDVFS_VCORE */
> + MMDVFS_PWR_VMM = 1, /* PWR_MMDVFS_VMM */
> + MMDVFS_PWR_VDISP = 2, /* PWR_MMDVFS_VDISP */
> + MMDVFS_PWR_NUM = 3 /* PWR_MMDVFS_NUM */
> +};
> +
> +/**
> + * struct mmdvfs_rc - Resource Controller
> + * @id: RC identifier
> + * @pa: Physical address base
> + * @level_num: Number of supported levels
> + * @rc_base: Virtual address base (mapped from pa)
> + */
> +struct mmdvfs_rc {
> + u8 id;
> + u32 pa;
phys_addr_t
> + u8 level_num;
> + void __iomem *rc_base;
> +};
...
> +/* Logging macros */
> +#define mmdvfs_dbg(dev, fmt, args...) \
> + dev_dbg(dev, "[mmdvfs] " fmt, ##args)
> +#define mmdvfs_info(dev, fmt, args...) \
> + dev_info(dev, "[mmdvfs] " fmt, ##args)
> +#define mmdvfs_warn(dev, fmt, args...) \
> + dev_warn(dev, "[mmdvfs] " fmt, ##args)
> +#define mmdvfs_err(dev, fmt, args...) \
> + dev_err(dev, "[mmdvfs] " fmt, ##args)
The driver name is already printed when using dev_* APIs. Use them
directly.
Best regards,
Roman
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend
2026-11-25 6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
@ 2026-11-25 8:38 ` Roman Vivchar
2026-11-25 10:59 ` Krzysztof Kozlowski
` (2 subsequent siblings)
3 siblings, 0 replies; 18+ messages in thread
From: Roman Vivchar @ 2026-11-25 8:38 UTC (permalink / raw)
To: Echo Zhang
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
AngeloGioacchino Del Regno, Stephen Boyd, Brian Masney,
Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
On Wednesday, November 25th, 2026 at 8:01 AM, Echo Zhang <echo.zhang@mediatek.com> wrote:
> Add the VCP transport used by MMDVFS to map AP and firmware shared
> memory, manage feature power references and send IPI commands.
>
> Wait for VCP readiness and handle the selected MMUP or VCP READY
> notification to initialize firmware after boot and resume. Serialize
> IPI transactions while shared memory and acknowledgment state are in
> use.
>
> Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
> ---
...
> diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
> index c32fa11557af..3388a5a3a145 100644
> --- a/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
> +++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
> @@ -7,22 +7,23 @@
>
> #include <linux/atomic.h>
> #include <linux/clk-provider.h>
> +#include <linux/delay.h>
> #include <linux/device.h>
> #include <linux/err.h>
> #include <linux/io.h>
> +#include <linux/kthread.h>
> #include <linux/module.h>
> #include <linux/mutex.h>
> -#include <linux/notifier.h>
> #include <linux/of.h>
> #include <linux/of_address.h>
> #include <linux/platform_device.h>
> +#include <linux/remoteproc/mtk_vcp_public.h>
> #include <linux/sched/clock.h>
> #include <linux/slab.h>
> #include <linux/string.h>
> -#include <linux/suspend.h>
> -#include <linux/workqueue.h>
>
> #include "mmdvfs-internal.h"
> +#include "mmdvfs-up-priv.h"
>
> static int mmdvfs_register_device(struct mmdvfs_device *mmdvfs);
> static void mmdvfs_unregister_device(struct mmdvfs_device *mmdvfs);
> @@ -34,14 +35,13 @@ struct mmdvfs_device *mmdvfs_find_device_any(void)
> {
> return mmdvfs_find_device_by_version(MMDVFS_VERSION_HWCCF_DVFS_VOTER);
> }
> -EXPORT_SYMBOL_GPL(mmdvfs_find_device_any);
>
> /**
> * mmdvfs_get_version - Get MMDVFS voting mechanism type
> *
> * Return:
> * 0 - No hardware voter
> - * 1 - HWCCF DVFS voter
> + * 1 - HWCCF DVFS voter (VCP IPI with MMUP SRAM)
> */
> u32 mmdvfs_get_version(void)
> {
> @@ -96,7 +96,8 @@ static int mmdvfs_validate_topology(struct mmdvfs_device *mmdvfs)
> return -EINVAL;
> }
>
> - if (mux->freq_num == 0 || mux->freq_num > MMDVFS_MAX_LEVELS) {
> + if (mux->freq_num == 0 || mux->freq_num > rc->level_num ||
> + mux->freq_num > MMDVFS_MAX_LEVELS) {
> mmdvfs_err(mmdvfs->dev,
> "MUX %d (%s): invalid freq_num: %d\n",
> i, mux->name, mux->freq_num);
> @@ -112,10 +113,11 @@ static int mmdvfs_validate_topology(struct mmdvfs_device *mmdvfs)
> }
>
> if (j > 0 && mux->freq[j] <= mux->freq[j - 1]) {
> - mmdvfs_warn(mmdvfs->dev,
> - "MUX %d (%s): freq not ascending: freq[%d]=%llu <= freq[%d]=%llu\n",
> - i, mux->name, j, mux->freq[j],
> - j - 1, mux->freq[j - 1]);
> + mmdvfs_err(mmdvfs->dev,
> + "MUX %d (%s): freq not ascending: freq[%d]=%llu <= freq[%d]=%llu\n",
> + i, mux->name, j, mux->freq[j],
> + j - 1, mux->freq[j - 1]);
> + return -EINVAL;
Why this can't be in the previous patch?
...
> diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c
> new file mode 100644
> index 000000000000..fc6db1c89294
> --- /dev/null
> +++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c
...
> +/*
> + * mmdvfs_get_bootmode - Get system boot mode
> + *
> + * Query boot mode from device tree /chosen node
> + */
> +static void mmdvfs_get_bootmode(void)
> +{
> + struct device_node *np_chosen;
> + struct tag_bootmode {
> + u32 size;
> + u32 tag;
> + u32 bootmode;
> + u32 boottype;
> + } *tag;
> +
> + if (bootmode < UNKNOWN_BOOT)
> + return;
> +
> + np_chosen = of_find_node_by_path("/chosen");
> + if (!np_chosen) {
> + bootmode = NORMAL_BOOT;
> + return;
> + }
> +
> + tag = (struct tag_bootmode *)of_get_property(np_chosen, "atag,boot", NULL);
> + of_node_put(np_chosen);
> +
> + if (tag)
> + bootmode = tag->bootmode;
> + else
> + bootmode = NORMAL_BOOT;
> +}
No. Please don't add your downstream code.
I'll stop here. This patch modifies too many things from the previous
one, and the series overall needs more cleanup.
Best regards,
Roman
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 3/7] soc: mediatek: add MMDVFS core driver
2026-11-25 6:00 ` [PATCH 3/7] soc: mediatek: add MMDVFS core driver Echo Zhang
2026-11-25 8:35 ` Roman Vivchar
@ 2026-11-25 10:54 ` Krzysztof Kozlowski
1 sibling, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-25 10:54 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
On 25/11/2026 07:00, Echo Zhang wrote:
> Add the common MediaTek MMDVFS driver framework.
>
> The core driver handles device probing, SoC data selection, clock provider
> registration, power-management notification, and dispatch to the
> microprocessor transport used for runtime performance voting.
I don't get why DVFS driver is a soc driver. This should use proper
Linux subsystems and be placed there.
>
> Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
> ---
> drivers/soc/mediatek/Kconfig | 19 +
> drivers/soc/mediatek/Makefile | 1 +
> drivers/soc/mediatek/mmdvfs/Makefile | 6 +
> drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c | 462 ++++++++++++++
> drivers/soc/mediatek/mmdvfs/mmdvfs-core.c | 581 ++++++++++++++++++
> drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h | 305 +++++++++
> include/soc/mediatek/mmdvfs.h | 72 +++
> 7 files changed, 1446 insertions(+)
> create mode 100644 drivers/soc/mediatek/mmdvfs/Makefile
> create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
> create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-core.c
> create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h
> create mode 100644 include/soc/mediatek/mmdvfs.h
>
> diff --git a/drivers/soc/mediatek/Kconfig b/drivers/soc/mediatek/Kconfig
> index d7293977f06e..bb273a4461f0 100644
> --- a/drivers/soc/mediatek/Kconfig
> +++ b/drivers/soc/mediatek/Kconfig
> @@ -60,6 +60,25 @@ config MTK_REGULATOR_COUPLER
> default ARCH_MEDIATEK
> depends on REGULATOR
>
> +config MTK_MMDVFS
> + tristate "MediaTek MMDVFS support"
> + depends on ARCH_MEDIATEK || COMPILE_TEST
> + depends on MTK_VCP_RPROC
Does not exist.
> + help
> + Say yes here to add support for the MediaTek Multimedia Dynamic
> + Voltage and Frequency Scaling controller. The controller provides
> + virtual clocks for multimedia hardware blocks and coordinates
> + performance votes with platform voltage resources.
> +
...
> +/* Logging macros */
> +#define mmdvfs_dbg(dev, fmt, args...) \
> + dev_dbg(dev, "[mmdvfs] " fmt, ##args)
> +#define mmdvfs_info(dev, fmt, args...) \
> + dev_info(dev, "[mmdvfs] " fmt, ##args)
> +#define mmdvfs_warn(dev, fmt, args...) \
> + dev_warn(dev, "[mmdvfs] " fmt, ##args)
> +#define mmdvfs_err(dev, fmt, args...) \
> + dev_err(dev, "[mmdvfs] " fmt, ##args)
> +
No, do not reimplement standard Linux kernel APIs/frameworks.
This applies EVERYWHERE here.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs
2026-11-25 6:00 ` [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs Echo Zhang
@ 2026-11-25 10:55 ` Krzysztof Kozlowski
0 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-25 10:55 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
On 25/11/2026 07:00, Echo Zhang wrote:
> Add clock IDs for the MT8196 MMDVFS clock provider.
>
> These IDs describe the clocks exposed by the MMDVFS block and are used by
> device tree consumers to request multimedia performance levels through the
> standard clock framework.
>
> Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
> ---
> .../clock/mediatek,mt8196-mmdvfs.h | 74 +++++++++++++++++++
This is not a separate commit.
> 1 file changed, 74 insertions(+)
> create mode 100644 include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h
>
> diff --git a/include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h b/include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h
> new file mode 100644
> index 000000000000..428d8a35abdb
> --- /dev/null
> +++ b/include/dt-bindings/clock/mediatek,mt8196-mmdvfs.h
> @@ -0,0 +1,74 @@
> +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
> +/*
> + * Copyright (c) 2024 MediaTek Inc.
> + * Author: MediaTek MMDVFS Team
> + */
> +
> +#ifndef _DT_BINDINGS_MMDVFS_CLK_MT8196_H
> +#define _DT_BINDINGS_MMDVFS_CLK_MT8196_H
> +
> +/*
> + * MMDVFS Clock IDs for MT8196
> + *
> + * These IDs are used by multimedia clients in device tree to reference
> + * MMDVFS virtual clocks for DVFS voting.
> + *
> + * MT8196 uses HWCCF (Hardware Clock Control Fabric) architecture.
> + *
> + * Usage in device tree:
> + * clocks = <&mmdvfs MMDVFS_USER_VDEC>;
> + * clock-names = "mmdvfs";
> + */
> +
> +/* Core user clocks used by multimedia hardware drivers */
> +#define MMDVFS_USER_DISP 0 /* user-disp */
> +#define MMDVFS_USER_MDP 1 /* user-mdp */
> +#define MMDVFS_USER_MML 2 /* user-mml */
> +#define MMDVFS_USER_SMI 3 /* user-smi */
> +#define MMDVFS_USER_JPEGDEC 4 /* user-jpegdec */
> +#define MMDVFS_USER_JPEGENC 5 /* user-jpegenc */
> +#define MMDVFS_USER_VENC 6 /* user-venc */
> +#define MMDVFS_USER_VFMT 7 /* user-vfmt */
> +#define MMDVFS_USER_IMG 8 /* user-img */
> +#define MMDVFS_USER_CAM 9 /* user-cam */
> +#define MMDVFS_USER_VCORE 10 /* user-vcore */
> +#define MMDVFS_USER_VMM 11 /* user-vmm */
> +#define MMDVFS_USER_VDISP 12 /* user-vdisp */
> +#define MMDVFS_USER_VDEC 13 /* user-vdec */
> +#define DUMMY_USER_DIS 14 /* dummy-dis */
> +#define DUMMY_USER_MDP 15 /* dummy-mdp */
> +#define DUMMY_USER_MML 16 /* dummy-mml */
> +#define DUMMY_USER_SMI 17 /* dummy-smi */
> +#define DUMMY_USER_VEN 18 /* dummy-ven */
> +#define DUMMY_USER_VDE 19 /* dummy-vde */
> +#define DUMMY_USER_IMG 20 /* dummy-img */
> +#define DUMMY_USER_CAM 21 /* dummy-cam */
> +#define MMDVFS_USER_CAM_SMI 22 /* user-cam-smi */
> +#define MMDVFS_USER_VCP_SMI 23 /* user-vcp-smi */
> +
> +/* AP voter clocks (24-33) - System level control */
> +#define MMDVFS_AP_CAM 24
> +#define MMDVFS_AP_CAMTM 25
> +#define MMDVFS_AP_VDE 26
> +#define MMDVFS_AP_IMG 27
> +#define MMDVFS_AP_IPE 28
> +#define MMDVFS_AP_DIS 29
> +#define MMDVFS_AP_MML 30
> +#define MMDVFS_AP_SMI 31
> +#define MMDVFS_AP_VEN 32
> +#define MMDVFS_AP_MDP 33
> +
> +/* VCP voter clocks (34-43) - VCP firmware control */
> +#define MMDVFS_VCP_CAM 34
> +#define MMDVFS_VCP_CAMTM 35
> +#define MMDVFS_VCP_VDE 36
> +#define MMDVFS_VCP_IMG 37
> +#define MMDVFS_VCP_IPE 38
> +#define MMDVFS_VCP_DIS 39
> +#define MMDVFS_VCP_MML 40
> +#define MMDVFS_VCP_SMI 41
> +#define MMDVFS_VCP_VEN 42
> +#define MMDVFS_VCP_MDP 43
> +
> +#define MMDVFS_USER_NUM 44
Not a binding, drop.
Are you sending us some downstream old driver? Which upstream code was
used as a base/example for this work?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding
2026-11-25 6:00 ` [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding Echo Zhang
2026-11-25 8:32 ` Roman Vivchar
@ 2026-11-25 10:58 ` Krzysztof Kozlowski
2026-11-25 11:58 ` Krzysztof Kozlowski
2 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-25 10:58 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
On 25/11/2026 07:00, Echo Zhang wrote:
> +description:
> + MediaTek MMDVFS provides dynamic voltage and frequency scaling for multimedia
> + hardware accelerators. The controller exposes virtual clocks that multimedia
> + consumers use through the common clock framework. The driver aggregates
> + consumer rate requests and sends the resulting DVFS votes to the multimedia
> + hardware voter and VCP firmware.
> +
> +select: false
What?
> +
> +properties:
> + mediatek,vcp:
> + $ref: /schemas/types.yaml#/definitions/phandle
> + description:
> + Phandle to the MediaTek VCP remote processor used for MMDVFS shared
> + memory, feature registration, notifier, and IPI operations.
> +
> + mediatek,mmup-sram:
> + type: boolean
> + description:
> + Use the MMUP SRAM window for MMDVFS callback records and status data.
> +
> + mediatek,mmup-enable:
> + type: boolean
> + description:
> + Enable the MMUP path for MMDVFS shared memory and IPI handling.
> +
> + mediatek,vcp-ipi-id:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + VCP IPI channel id for MMDVFS. If omitted, the driver uses the platform
> + default.
> +
> + mediatek,mmup-ipi-id:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + MMUP IPI channel id for MMDVFS. If omitted, the driver uses the platform
> + default.
> +
> + "#clock-cells":
> + const: 1
> + description:
> + MMDVFS clock specifier. Consumers pass an SoC-specific MMDVFS clock
> + index.
> +
> +required:
> + - mediatek,vcp
> + - "#clock-cells"
> +
> +additionalProperties: true
> diff --git a/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
> new file mode 100644
> index 000000000000..13381c78dbd1
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/soc/mediatek/mediatek,mt8196-mmdvfs.yaml
> @@ -0,0 +1,87 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/soc/mediatek/mediatek,mt8196-mmdvfs.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: MediaTek MT8196 Multimedia Dynamic Voltage and Frequency Scaling
> +
> +maintainers:
> + - MediaTek MMDVFS Team <linux-mediatek@lists.infradead.org>
> +
> +allOf:
> + - $ref: mediatek,mmdvfs.yaml#
What?
> +
> +select:
> + properties:
> + compatible:
> + contains:
> + enum:
> + - mediatek,mt8196-mmdvfs
> + required:
> + - compatible
What?
> +
> +properties:
> + compatible:
> + enum:
> + - mediatek,mt8196-mmdvfs
> +
> + mediatek,hwccf:
clock control is via clocks, no?
> + $ref: /schemas/types.yaml#/definitions/phandle
> + description:
> + Phandle to the MT8196 multimedia hardware clock control fabric syscon
> + used for AP-side hardware votes.
> +
> + mediatek,mux-opp-tables:
> + $ref: /schemas/types.yaml#/definitions/phandle-array
NAK, you are messing with us...
> + minItems: 7
> + maxItems: 7
> + description: |
> + OPP tables for the seven MT8196 MMDVFS muxes, in this order:
> + display, MDP, SMI, VENC, VDEC, IMG, CAM. MDP and MML share
> + the MDP mux. Each OPP entry must have opp-hz and opp-level.
> +
> +required:
> + - compatible
> + - mediatek,hwccf
> + - mediatek,mux-opp-tables
> +
> +unevaluatedProperties: false
> +
> +examples:
> + - |
> + #include <dt-bindings/clock/mediatek,mt8196-mmdvfs.h>
> +
> + soc {
> + #address-cells = <2>;
> + #size-cells = <2>;
> +
> + vcp: remoteproc@31800000 {
> + compatible = "mediatek,mt8196-vcp";
> + reg = <0 0x31800000 0 0x100000>;
> + };
> +
> + mm_hwv: syscon@31b00000 {
> + compatible = "mediatek,mt8196-mm-hwv", "syscon";
> + reg = <0 0x31b00000 0 0x6000>;
> + };
> +
What are all these nodes? Drop.
> + mmdvfs_opp: opp-table {
> + compatible = "operating-points-v2";
> + opp-0 {
> + opp-hz = /bits/ 64 <100000000>;
> + opp-level = <0>;
> + };
> + };
> +
> + mmdvfs: mmdvfs-mux {
Node names should be generic. See also an explanation and list of
examples (not exhaustive) in DT specification:
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
If you cannot find a name matching your device, please check in kernel
sources for similar cases or you can grow the spec (via pull request to
DT spec repo).
Honestly, not a separate device. You just added it for Linux drivers.
NAK for entire binding.
> + compatible = "mediatek,mt8196-mmdvfs";
> + mediatek,vcp = <&vcp>;
> + mediatek,hwccf = <&mm_hwv>;
> + mediatek,mux-opp-tables = <&mmdvfs_opp>, <&mmdvfs_opp>,
> + <&mmdvfs_opp>, <&mmdvfs_opp>,
> + <&mmdvfs_opp>, <&mmdvfs_opp>,
> + <&mmdvfs_opp>;
> + #clock-cells = <1>;
> + };
> + };
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend
2026-11-25 6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
2026-11-25 8:38 ` Roman Vivchar
@ 2026-11-25 10:59 ` Krzysztof Kozlowski
2026-11-25 11:00 ` Krzysztof Kozlowski
2026-11-25 14:32 ` Ben Grisdale
3 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-25 10:59 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
On 25/11/2026 07:00, Echo Zhang wrote:
> Add the VCP transport used by MMDVFS to map AP and firmware shared
> memory, manage feature power references and send IPI commands.
>
> Wait for VCP readiness and handle the selected MMUP or VCP READY
> notification to initialize firmware after boot and resume. Serialize
> IPI transactions while shared memory and acknowledgment state are in
> use.
>
> Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
> ---
> drivers/soc/mediatek/mmdvfs/Makefile | 2 +
> drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c | 39 +-
> drivers/soc/mediatek/mmdvfs/mmdvfs-core.c | 272 +++--
> drivers/soc/mediatek/mmdvfs/mmdvfs-internal.h | 160 ++-
> drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h | 57 +
> drivers/soc/mediatek/mmdvfs/mmdvfs-up.c | 275 +++++
> .../soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h | 104 ++
> drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c | 1075 +++++++++++++++++
> include/soc/mediatek/mmdvfs.h | 66 +-
> 9 files changed, 1846 insertions(+), 204 deletions(-)
> create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-up-priv.h
> create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-up.c
> create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-vcp-memory.h
> create mode 100644 drivers/soc/mediatek/mmdvfs/mmdvfs-vcp.c
>
> diff --git a/drivers/soc/mediatek/mmdvfs/Makefile b/drivers/soc/mediatek/mmdvfs/Makefile
> index 33a280827006..16ecee30bff6 100644
> --- a/drivers/soc/mediatek/mmdvfs/Makefile
> +++ b/drivers/soc/mediatek/mmdvfs/Makefile
> @@ -4,3 +4,5 @@ obj-$(CONFIG_MTK_MMDVFS) += mtk-mmdvfs.o
>
> mtk-mmdvfs-y += mmdvfs-core.o
> mtk-mmdvfs-y += mmdvfs-clk.o
> +mtk-mmdvfs-y += mmdvfs-up.o
> +mtk-mmdvfs-y += mmdvfs-vcp.o
> diff --git a/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c b/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
> index 114f3148cf46..b9025427782d 100644
> --- a/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
> +++ b/drivers/soc/mediatek/mmdvfs/mmdvfs-clk.c
> @@ -15,7 +15,6 @@
> #include <linux/of.h>
> #include <linux/of_platform.h>
> #include <linux/platform_device.h>
> -#include <linux/pm_runtime.h>
Srsly, you just added this. So you add buggy code just to fix it...
> #include <linux/property.h>
> #include <linux/slab.h>
> #include <linux/string.h>
> @@ -27,9 +26,18 @@
>
> static const char *mmdvfs_get_clkdev_name(const char *name, char *buf, size_t size)
> {
> + int ret;
> +
> if (strlen(name) < MMDVFS_CLKDEV_CON_ID_MAX)
> return name;
>
> + if (str_has_prefix(name, "mmdvfs-vcp-")) {
> + ret = snprintf(buf, size, "mmdvfs-v-%s",
> + name + strlen("mmdvfs-vcp-"));
> + if (ret > 0 && ret < (int)size)
> + return buf;
> + }
> +
> return NULL;
> }
>
> @@ -66,7 +74,7 @@ static int mmdvfs_set_rate(struct clk_hw *hw, unsigned long rate,
>
> data = mmdvfs->data;
>
> - if (!data->init_done)
> + if (!READ_ONCE(data->init_done))
> return -EPROBE_DEFER;
>
> if (!mmdvfs_is_valid_user_id(user->id) ||
> @@ -76,12 +84,6 @@ static int mmdvfs_set_rate(struct clk_hw *hw, unsigned long rate,
> return -EINVAL;
> }
>
> - if (rate == 0) {
> - mmdvfs_dbg(mmdvfs->dev, "Zero rate request for user %s\n",
> - user->name);
> - return 0;
> - }
NAK, this is just random coding, without any architectural oversight.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend
2026-11-25 6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
2026-11-25 8:38 ` Roman Vivchar
2026-11-25 10:59 ` Krzysztof Kozlowski
@ 2026-11-25 11:00 ` Krzysztof Kozlowski
2026-11-25 14:32 ` Ben Grisdale
3 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-25 11:00 UTC (permalink / raw)
To: Echo Zhang, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno, Stephen Boyd,
Brian Masney, Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
On 25/11/2026 07:00, Echo Zhang wrote:
> +
> + if (bootmode < UNKNOWN_BOOT)
> + return;
> +
> + np_chosen = of_find_node_by_path("/chosen");
> + if (!np_chosen) {
> + bootmode = NORMAL_BOOT;
> + return;
> + }
> +
> + tag = (struct tag_bootmode *)of_get_property(np_chosen, "atag,boot", NULL);
NAK, stop sending us downstream.
>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding
2026-11-25 6:00 ` [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding Echo Zhang
2026-11-25 8:32 ` Roman Vivchar
2026-11-25 10:58 ` Krzysztof Kozlowski
@ 2026-11-25 11:58 ` Krzysztof Kozlowski
2 siblings, 0 replies; 18+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-25 11:58 UTC (permalink / raw)
To: Echo Zhang
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
AngeloGioacchino Del Regno, Stephen Boyd, Brian Masney,
Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm, Krzysztof Kozlowski
On 2026-11-25 14:00 +0800, Echo Zhang wrote:
> Describe the MMDVFS clock provider and its connection to VCP firmware
> in a common binding. Document the optional MMUP shared memory and IPI
> settings used by the firmware backend.
>
> Add an MT8196 binding for the HWCCF syscon and seven mux OPP tables so
> the driver can map clock rate requests to hardware votes.
>
> Signed-off-by: Echo Zhang <echo.zhang@mediatek.com>
> ---
> .../soc/mediatek/mediatek,mmdvfs.yaml | 60 +++++++++++++
> .../soc/mediatek/mediatek,mt8196-mmdvfs.yaml | 87 +++++++++++++++++++
.... and this has build check failures :/
Best regards,
Krzysztof
--
Krzysztof Kozlowski <krzk@kernel.org>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend
2026-11-25 6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
` (2 preceding siblings ...)
2026-11-25 11:00 ` Krzysztof Kozlowski
@ 2026-11-25 14:32 ` Ben Grisdale
3 siblings, 0 replies; 18+ messages in thread
From: Ben Grisdale @ 2026-11-25 14:32 UTC (permalink / raw)
To: Echo Zhang
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
AngeloGioacchino Del Regno, Stephen Boyd, Brian Masney,
Jerome Brunet, Nathan Chancellor, Nick Desaulniers,
Bill Wendling, Justin Stitt, MMDVFS Team, kyrie.wu,
ming-fan.chen, devicetree, linux-kernel, linux-arm-kernel,
linux-clk, llvm
On Wed, 25 Nov 2026 14:00:09 +0800 "Echo Zhang" <echo.zhang@mediatek.com> wrote:
> Add the VCP transport used by MMDVFS to map AP and firmware shared
> memory, manage feature power references and send IPI commands.
>
> Wait for VCP readiness and handle the selected MMUP or VCP READY
> notification to initialize firmware after boot and resume. Serialize
> IPI transactions while shared memory and acknowledgment state are in
> use.
[...]
> +static void mmdvfs_get_bootmode(void)
> +{
> + struct device_node *np_chosen;
> + struct tag_bootmode {
> + u32 size;
> + u32 tag;
> + u32 bootmode;
> + u32 boottype;
> + } *tag;
> +
> + if (bootmode < UNKNOWN_BOOT)
> + return;
> +
> + np_chosen = of_find_node_by_path("/chosen");
> + if (!np_chosen) {
> + bootmode = NORMAL_BOOT;
> + return;
> + }
> +
> + tag = (struct tag_bootmode *)of_get_property(np_chosen, "atag,boot", NULL);
> + of_node_put(np_chosen);
> +
> + if (tag)
> + bootmode = tag->bootmode;
> + else
> + bootmode = NORMAL_BOOT;
> +}
> +
[...]
> +static int
> +mmdvfs_vcp_send_ipi_impl(struct mmdvfs_device *mmdvfs, void *data, u32 len,
> + const bool vcp)
> +{
[...]
> + mmdvfs_get_bootmode();
> + if (bootmode == RECOVERY_BOOT) {
> + mmdvfs_err(mmdvfs->dev, "IPI skipped: bootmode=%d\n", bootmode);
> + return -EACCES;
> + }
> +
Allow me to give my two cents here, even if I am a nobody :)
Android bootmodes. Whilst I do respect the reason for Android bootmodes
existing, what I do not like to see is people checking for the *Android*
bootmode in their drivers.
Android kernels these days are *modular* thanks to GKI. I *do not*
understand why people still check for bootmodes in their drivers when
there is a much better option of *not loading them* if they are not
wanted in the current bootmode.
Having your driver depend on the behaviour of one specific userspace is
terrible. And tracking it in firmware (given that this code is checking
for an "atag,boot" property presumably added by the bootloader) is even
worse.
Aside from enabling these questionable bootmode checks in the drivers,
I have no idea why the bootloader needs to get involved with putting
non-standard state / boot info inside of /chosen (i.e. that "atag,boot"
property), when Android solved this problem by using bootargs, and more
recently, bootconfig.
I will acknowledge that "just not loading modules" does get a bit more
nuanced if you bring something like udev / Android init into the mix,
but there are still better solutions to this problem: either gracefully
handling the state where the hardware isn't ready in your driver, making
your bootloader set status = "disabled"; on the relavent DT node, or
blocklisting the module from userspace in boot modes where it can't
work.
Inter-driver dependencies are not a good excuse either (e.g. a core
clock driver depending on some DVFS driver that is a no-op in recovery,
forcing you to load it ANYWAY, even if the bootloader doesn't start the
required firmware on recovery boot). If that is the case, then there is
some serious refactoring work to do.
First I began seeing these sorts of checks in vendor touch screen
drivers, but now it seems to be infecting SoC side drivers as well.
*Kernel* drivers should work the same regardless of what *userspace*
environment is running (with the only real exception being the absence
of firmware or explicit configurations from userspace). And in situations
where they genuinely can't work, they should not be loaded at all.
There should be no such thing as "kernel drivers designed for Android",
only "kernel drivers designed for Linux".
Best regards,
Ben Grisdale
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-11-25 14:33 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 6:00 [PATCH 0/7] soc: mediatek: add MMDVFS support for MT8196 Echo Zhang
2026-11-25 6:00 ` [PATCH 1/7] dt-bindings: clock: mediatek: add MT8196 MMDVFS clock IDs Echo Zhang
2026-11-25 10:55 ` Krzysztof Kozlowski
2026-11-25 6:00 ` [PATCH 2/7] dt-bindings: soc: mediatek: add MMDVFS binding Echo Zhang
2026-11-25 8:32 ` Roman Vivchar
2026-11-25 10:58 ` Krzysztof Kozlowski
2026-11-25 11:58 ` Krzysztof Kozlowski
2026-11-25 6:00 ` [PATCH 3/7] soc: mediatek: add MMDVFS core driver Echo Zhang
2026-11-25 8:35 ` Roman Vivchar
2026-11-25 10:54 ` Krzysztof Kozlowski
2026-11-25 6:00 ` [PATCH 4/7] soc: mediatek: mmdvfs: add VCP backend Echo Zhang
2026-11-25 8:38 ` Roman Vivchar
2026-11-25 10:59 ` Krzysztof Kozlowski
2026-11-25 11:00 ` Krzysztof Kozlowski
2026-11-25 14:32 ` Ben Grisdale
2026-11-25 6:00 ` [PATCH 5/7] soc: mediatek: mmdvfs: add MT8196 support Echo Zhang
2026-11-25 6:00 ` [PATCH 6/7] soc: mediatek: mmdvfs: add read-only status debug Echo Zhang
2026-11-25 6:00 ` [PATCH 7/7] MAINTAINERS: add MediaTek MMDVFS entry Echo Zhang
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®