[dm][thermal] update the thermal cooling

1. Fixup the cooling control flow.
2. Replace the spinlock to mutex.
3. Fixup the PWM args for PWM-FAN.
4. Add GPIO-FAN

Signed-off-by: GuEe-GUI <2991707448@qq.com>
This commit is contained in:
GuEe-GUI authored and Rbb666 committed 2026-08-06 11:09:50 +08:00
1 parent 73614c8684
commit 96cf830d89
5 files changed
+358 -28

No files matched your search

+7
View File
@@ -27,6 +27,13 @@ config RT_THERMAL_COOL_DVFS
depends on RT_USING_DVFS
default n
config RT_THERMAL_COOL_GPIO_FAN
bool "GPIO Fan"
depends on RT_USING_THERMAL
depends on RT_USING_PIN
depends on RT_USING_OFW
default n
config RT_THERMAL_COOL_PWM_FAN
bool "PWM Fan"
depends on RT_USING_THERMAL
+3
View File
@@ -16,6 +16,9 @@ if GetDepend(['RT_THERMAL_SCMI']):
if GetDepend(['RT_THERMAL_COOL_DVFS']):
src += ['thermal-cool-dvfs.c']
if GetDepend(['RT_THERMAL_COOL_GPIO_FAN']):
src += ['thermal-cool-gpio-fan.c']
if GetDepend(['RT_THERMAL_COOL_PWM_FAN']):
src += ['thermal-cool-pwm-fan.c']
File diff suppressed because it is too large. Load diff
@@ -30,7 +30,7 @@ struct pwm_fan_cool
struct rt_pwm_configuration pwm_conf;
struct rt_regulator *supply;
struct rt_spinlock lock;
struct rt_mutex lock;
};
#define raw_to_pwm_fan_cool(raw) rt_container_of(raw, struct pwm_fan_cool, parent)
@@ -100,12 +100,19 @@ static rt_err_t pwm_fan_cool_set_cur_level(struct rt_thermal_cooling_device *cde
rt_err_t err = RT_EOK;
struct pwm_fan_cool *pf_cool = raw_to_pwm_fan_cool(cdev);
if (pf_cool->pwm_fan_level == level)
if (level > pf_cool->pwm_fan_max_level)
{
return RT_EOK;
return -RT_EINVAL;
}
rt_spin_lock(&pf_cool->lock);
rt_mutex_take(&pf_cool->lock, RT_WAITING_FOREVER);
if (pf_cool->pwm_fan_level == level)
{
rt_mutex_release(&pf_cool->lock);
return RT_EOK;
}
if ((pwm = pf_cool->pwm_fan_cooling_levels[level]))
{
@@ -128,14 +135,14 @@ static rt_err_t pwm_fan_cool_set_cur_level(struct rt_thermal_cooling_device *cde
err = pwm_fan_power_off(pf_cool);
}
rt_spin_unlock(&pf_cool->lock);
if (!err)
{
pf_cool->pwm_fan_level = level;
}
return RT_EOK;
rt_mutex_release(&pf_cool->lock);
return err;
}
const static struct rt_thermal_cooling_device_ops pwm_fan_cool_ops =
@@ -157,6 +164,8 @@ static void pwm_fan_cool_free(struct pwm_fan_cool *pf_cool)
rt_free(pf_cool->pwm_fan_cooling_levels);
}
rt_mutex_detach(&pf_cool->lock);
rt_free(pf_cool);
}
@@ -174,6 +183,8 @@ static rt_err_t pwm_fan_cool_probe(struct rt_platform_device *pdev)
return -RT_ENOMEM;
}
rt_mutex_init(&pf_cool->lock, rt_dm_dev_get_name(dev), RT_IPC_FLAG_PRIO);
if (rt_ofw_parse_phandle_cells(np, "pwms", "#pwm-cells", 0, &pwm_args))
{
err = -RT_EINVAL;
@@ -231,8 +242,10 @@ static rt_err_t pwm_fan_cool_probe(struct rt_platform_device *pdev)
pf_cool->pwm_fan_level = MAX_PWM;
pf_cool->pwm_fan_max_level = levels_nr - 1;
rt_spin_lock_init(&pf_cool->lock);
pwm_fan_cool_set_cur_level(&pf_cool->parent, 0);
if ((err = pwm_fan_cool_set_cur_level(&pf_cool->parent, 0)))
{
goto _fail;
}
rt_dm_dev_set_name(&pf_cool->parent.parent, "%s", rt_dm_dev_get_name(&pdev->parent));
pf_cool->parent.parent.ofw_node = dev->ofw_node;
+25 -19
View File
@@ -773,6 +773,7 @@ void rt_thermal_cooling_device_kick(struct rt_thermal_zone_device *zdev)
{
rt_ubase_t level;
rt_ubase_t max_level;
rt_ubase_t cur_level;
struct rt_thermal_cooling_device *cdev;
struct rt_thermal_cooling_cell *cell;
struct rt_thermal_cooling_map *map = &zdev->cooling_maps[i];
@@ -795,32 +796,37 @@ void rt_thermal_cooling_device_kick(struct rt_thermal_zone_device *zdev)
cdev->max_level = max_level;
if (!zdev->cooling)
level = 0;
if (zdev->cooling)
{
/* Release cooling: restore full performance (highest OPP). */
if (!cdev->ops->get_cur_level(cdev, &level) && level != max_level)
for (int m = 0; m < zdev->cooling_maps_nr; ++m)
{
cdev->ops->set_cur_level(cdev, max_level);
struct rt_thermal_cooling_map *scan_map = &zdev->cooling_maps[m];
if (zdev->temperature <= scan_map->trips->temperature)
{
continue;
}
for (int sc = 0; sc < scan_map->cells_nr; ++sc)
{
struct rt_thermal_cooling_cell *scan_cell = &scan_map->cells[sc];
if (scan_cell->cooling_devices == cdev)
{
level = rt_max_t(rt_ubase_t, level, scan_cell->level_range[1]);
}
}
}
continue;
}
if (cdev->ops->get_cur_level(cdev, &level) || level > max_level)
{
continue;
}
/* Check if cooling is required */
if (level >= cell->level_range[0] && level <= cell->level_range[1])
{
/* Is cooling, not call */
continue;
}
cdev->gov->tuning(zdev, i, c, &level);
level = rt_min_t(rt_ubase_t, level, max_level);
cdev->ops->set_cur_level(cdev, level);
if (!cdev->ops->get_cur_level(cdev, &cur_level) && cur_level != level)
{
cdev->ops->set_cur_level(cdev, level);
}
}
}
}