[PATCH v8 10/11] media: chips-media: wave6: Add Wave6 thermal cooling device

From: Nas Chung

Date: Thu Nov 19 2026 - 04:01:57 EST


Add a thermal cooling device for the Wave6 VPU, so the thermal
framework can lower the VPU performance state when the SoC gets hot.

The control driver registers the cooling device on its device tree
node. The cooling states are built from the OPP table of the "perf"
power domain.

Tested-by: Ming Qian <ming.qian@xxxxxxxxxxx>
Tested-by: Marek Vasut <marek.vasut@xxxxxxxxxxx>
Signed-off-by: Nas Chung <nas.chung@xxxxxxxxxxxxxxx>
---
.../media/platform/chips-media/wave6/Makefile | 1 +
.../chips-media/wave6/wave6-vpu-thermal.c | 141 ++++++++++++++++++
.../chips-media/wave6/wave6-vpu-thermal.h | 24 +++
.../platform/chips-media/wave6/wave6-vpu.c | 22 +++
.../platform/chips-media/wave6/wave6-vpu.h | 3 +
5 files changed, 191 insertions(+)
create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.c
create mode 100644 drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.h

diff --git a/drivers/media/platform/chips-media/wave6/Makefile b/drivers/media/platform/chips-media/wave6/Makefile
index 426af279af6f..4bdf51c58f46 100644
--- a/drivers/media/platform/chips-media/wave6/Makefile
+++ b/drivers/media/platform/chips-media/wave6/Makefile
@@ -4,6 +4,7 @@
CFLAGS_wave6-vpu-core.o := -I$(src)

wave6-objs += wave6-vpu.o \
+ wave6-vpu-thermal.o \
wave6-vpu-core.o \
wave6-vpu-v4l2.o \
wave6-vpu-dbg.o \
diff --git a/drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.c b/drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.c
new file mode 100644
index 000000000000..3e21c7edb9e9
--- /dev/null
+++ b/drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.c
@@ -0,0 +1,141 @@
+// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
+/*
+ * Wave6 series multi-standard codec IP - wave6 thermal cooling interface
+ *
+ * Copyright (C) 2026 CHIPS&MEDIA INC
+ *
+ */
+
+#include <linux/pm_domain.h>
+#include <linux/pm_opp.h>
+#include <linux/units.h>
+
+#include "wave6-vpu-thermal.h"
+
+static int wave6_vpu_thermal_cooling_update(struct vpu_thermal_cooling *thermal,
+ int state)
+{
+ unsigned int level;
+ int ret;
+
+ level = thermal->level_table[state];
+ dev_dbg(thermal->dev, "receive cooling state: %d, new perf level %u\n",
+ state, level);
+
+ ret = dev_pm_genpd_set_performance_state(thermal->dev, level);
+ if (ret) {
+ dev_err(thermal->dev, "failed to set perf to %u, ret = %d\n",
+ level, ret);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int wave6_vpu_cooling_get_max_state(struct thermal_cooling_device *cdev,
+ unsigned long *state)
+{
+ struct vpu_thermal_cooling *thermal = cdev->devdata;
+
+ *state = thermal->thermal_max;
+
+ return 0;
+}
+
+static int wave6_vpu_cooling_get_cur_state(struct thermal_cooling_device *cdev,
+ unsigned long *state)
+{
+ struct vpu_thermal_cooling *thermal = cdev->devdata;
+
+ *state = thermal->thermal_event;
+
+ return 0;
+}
+
+static int wave6_vpu_cooling_set_cur_state(struct thermal_cooling_device *cdev,
+ unsigned long state)
+{
+ struct vpu_thermal_cooling *thermal = cdev->devdata;
+ int ret;
+
+ ret = wave6_vpu_thermal_cooling_update(thermal, state);
+ if (ret)
+ return ret;
+
+ thermal->thermal_event = state;
+
+ return 0;
+}
+
+static const struct thermal_cooling_device_ops wave6_cooling_ops = {
+ .get_max_state = wave6_vpu_cooling_get_max_state,
+ .get_cur_state = wave6_vpu_cooling_get_cur_state,
+ .set_cur_state = wave6_vpu_cooling_set_cur_state,
+};
+
+int wave6_vpu_cooling_init(struct device *dev, struct vpu_thermal_cooling *thermal)
+{
+ int num_opps;
+ unsigned long freq = ULONG_MAX;
+ int ret = -EINVAL;
+
+ if (WARN_ON(!thermal || !thermal->dev))
+ return -EINVAL;
+
+ num_opps = dev_pm_opp_get_opp_count(thermal->dev);
+ if (num_opps < 0) {
+ dev_err(thermal->dev, "fail to get pm opp count, ret = %d\n", num_opps);
+ return num_opps;
+ }
+ if (num_opps == 0) {
+ dev_err(thermal->dev, "no OPP entries found\n");
+ return -ENODEV;
+ }
+
+ thermal->level_table = devm_kcalloc(dev, num_opps,
+ sizeof(*thermal->level_table),
+ GFP_KERNEL);
+ if (!thermal->level_table) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ for (int i = 0; i < num_opps; i++, freq--) {
+ struct dev_pm_opp *opp;
+ unsigned int level;
+
+ opp = dev_pm_opp_find_freq_floor(thermal->dev, &freq);
+ if (IS_ERR(opp))
+ break;
+
+ level = dev_pm_opp_get_level(opp);
+ dev_pm_opp_put(opp);
+
+ dev_dbg(thermal->dev, "[%d] = %lu, level %u\n", i, freq, level);
+ if (freq < 100 * HZ_PER_MHZ)
+ break;
+
+ thermal->level_table[i] = level;
+ thermal->thermal_max = i;
+ }
+
+ if (!thermal->thermal_max)
+ goto error;
+
+ thermal->thermal_event = 0;
+ thermal->cooling = devm_thermal_of_child_cooling_device_register(dev,
+ dev->of_node,
+ dev_name(thermal->dev),
+ thermal,
+ &wave6_cooling_ops);
+ if (IS_ERR(thermal->cooling)) {
+ dev_err(thermal->dev, "register cooling device failed\n");
+ ret = PTR_ERR(thermal->cooling);
+ goto error;
+ }
+
+ return 0;
+
+error:
+ return ret;
+}
diff --git a/drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.h b/drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.h
new file mode 100644
index 000000000000..35377a104aca
--- /dev/null
+++ b/drivers/media/platform/chips-media/wave6/wave6-vpu-thermal.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
+/*
+ * Wave6 series multi-standard codec IP - wave6 thermal cooling interface
+ *
+ * Copyright (C) 2026 CHIPS&MEDIA INC
+ *
+ */
+
+#ifndef __WAVE6_VPU_THERMAL_H__
+#define __WAVE6_VPU_THERMAL_H__
+
+#include <linux/thermal.h>
+
+struct vpu_thermal_cooling {
+ struct device *dev;
+ int thermal_event;
+ int thermal_max;
+ struct thermal_cooling_device *cooling;
+ unsigned int *level_table;
+};
+
+int wave6_vpu_cooling_init(struct device *dev, struct vpu_thermal_cooling *thermal);
+
+#endif /* __WAVE6_VPU_THERMAL_H__ */
diff --git a/drivers/media/platform/chips-media/wave6/wave6-vpu.c b/drivers/media/platform/chips-media/wave6/wave6-vpu.c
index 54a6567bc64a..3e8cd67e0d71 100644
--- a/drivers/media/platform/chips-media/wave6/wave6-vpu.c
+++ b/drivers/media/platform/chips-media/wave6/wave6-vpu.c
@@ -613,6 +613,21 @@ static int wave6_vpu_attach_pm_domains(struct wave6_vpu_device *vpu)
return 0;
}

+static struct device *wave6_vpu_get_performance_dev(struct wave6_vpu_device *vpu)
+{
+ int index;
+
+ if (!vpu->num_pm_domains)
+ return vpu->dev;
+
+ index = of_property_match_string(vpu->dev->of_node,
+ "power-domain-names", "perf");
+ if (index < 0 || index >= vpu->num_pm_domains)
+ return NULL;
+
+ return vpu->pd_list->pd_devs[index];
+}
+
static int wave6_vpu_probe(struct platform_device *pdev)
{
struct device_node *np;
@@ -696,6 +711,13 @@ static int wave6_vpu_probe(struct platform_device *pdev)
}
}

+ vpu->thermal.dev = wave6_vpu_get_performance_dev(vpu);
+ if (vpu->thermal.dev) {
+ ret = wave6_vpu_cooling_init(vpu->dev, &vpu->thermal);
+ if (ret)
+ dev_err(&pdev->dev, "failed to initialize thermal cooling, %d\n", ret);
+ }
+
wave6_vpu_allocate_work_buffers(vpu);

pm_runtime_enable(&pdev->dev);
diff --git a/drivers/media/platform/chips-media/wave6/wave6-vpu.h b/drivers/media/platform/chips-media/wave6/wave6-vpu.h
index 35a1d9f8a003..64e71a8ae597 100644
--- a/drivers/media/platform/chips-media/wave6/wave6-vpu.h
+++ b/drivers/media/platform/chips-media/wave6/wave6-vpu.h
@@ -12,6 +12,7 @@
#include <linux/device.h>

#include "wave6-vpuconfig.h"
+#include "wave6-vpu-thermal.h"
#include "wave6-vdi.h"

#define WAVE6_VPU_PLATFORM_DRIVER_NAME "wave6-vpu"
@@ -93,6 +94,7 @@ struct wave6_vpu_core_resource {
* @work_buffers: Array of work buffers
* @work_buffers_alloc: Number of allocated work buffers
* @work_buffers_avail: Number of available work buffers
+ * @thermal: Thermal cooling device
* @core_count: Number of VPU cores holding a wave6_vpu_get() reference
* @num_pm_domains: Number of attached power domains
* @pd_list: List of attached power domains
@@ -121,6 +123,7 @@ struct wave6_vpu_device {
u32 work_buffers_alloc;
u32 work_buffers_avail;

+ struct vpu_thermal_cooling thermal;
atomic_t core_count;

int num_pm_domains;
--
2.41.0.windows.3