[PATCH v2 4/5] thermal: khadas_mcu_fan: add support for Khadas Edge 2
muhammed.efecetin.67 at gmail.com
muhammed.efecetin.67 at gmail.com
Tue Jul 22 05:38:14 PDT 2025
From: Muhammed Efe Cetin <efectn at protonmail.com>
Fan control on the Khadas Edge 2 is controlled with the 0x8A register,
using percentage values from 0 to 100, whereas there are only 3 constant
steps in previous Khadas boards. Therefore, i adjusted max_level and
fan_ctrl_reg when the mcu node is defined with khadas-mcu-v2 compatible.
Signed-off-by: Muhammed Efe Cetin <efectn at protonmail.com>
---
drivers/thermal/khadas_mcu_fan.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/thermal/khadas_mcu_fan.c b/drivers/thermal/khadas_mcu_fan.c
index d35e5313b..f5c58be4f 100644
--- a/drivers/thermal/khadas_mcu_fan.c
+++ b/drivers/thermal/khadas_mcu_fan.c
@@ -15,10 +15,13 @@
#include <linux/thermal.h>
#define MAX_LEVEL 3
+#define MAX_LEVEL_V2 100
struct khadas_mcu_fan_ctx {
struct khadas_mcu *mcu;
unsigned int level;
+ unsigned int max_level;
+ unsigned int fan_ctrl_reg;
struct thermal_cooling_device *cdev;
};
@@ -26,8 +29,7 @@ static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx,
unsigned int level)
{
int ret;
-
- ret = regmap_write(ctx->mcu->regmap, KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG,
+ ret = regmap_write(ctx->mcu->regmap, ctx->fan_ctrl_reg,
level);
if (ret)
return ret;
@@ -40,7 +42,9 @@ static int khadas_mcu_fan_set_level(struct khadas_mcu_fan_ctx *ctx,
static int khadas_mcu_fan_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
- *state = MAX_LEVEL;
+ struct khadas_mcu_fan_ctx *ctx = cdev->devdata;
+
+ *state = ctx->max_level;
return 0;
}
@@ -61,7 +65,7 @@ khadas_mcu_fan_set_cur_state(struct thermal_cooling_device *cdev,
{
struct khadas_mcu_fan_ctx *ctx = cdev->devdata;
- if (state > MAX_LEVEL)
+ if (state > ctx->max_level)
return -EINVAL;
if (state == ctx->level)
@@ -88,6 +92,14 @@ static int khadas_mcu_fan_probe(struct platform_device *pdev)
if (!ctx)
return -ENOMEM;
ctx->mcu = mcu;
+ ctx->max_level = MAX_LEVEL;
+ ctx->fan_ctrl_reg = KHADAS_MCU_CMD_FAN_STATUS_CTRL_REG;
+
+ if (of_device_is_compatible(mcu->dev->of_node, "khadas,mcu-v2")) {
+ ctx->fan_ctrl_reg = KHADAS_MCU_V2_FAN_CTRL_REG;
+ ctx->max_level = MAX_LEVEL_V2;
+ }
+
platform_set_drvdata(pdev, ctx);
cdev = devm_thermal_of_cooling_device_register(dev->parent,
--
2.50.1
More information about the Linux-rockchip
mailing list