This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0b633946c0dc9315d07372977350cd183fc4bcdd Author: wangjianyu3 <wangjian...@xiaomi.com> AuthorDate: Tue Feb 11 15:33:58 2025 +0800 drivers/thermal: Add support for passive trip point Spliting `THERMAL_NORMAL` to `THERMAL_ACTIVE` and `THERMAL_PASSIVE`, to support different update intervals for thermal zone. Active/Passive from [kernel.org](https://www.kernel.org/doc/Documentation/devicetree/bindings/thermal/thermal.txt): * Cooling device nodes Cooling devices are nodes providing control on power dissipation. There are essentially two ways to provide control on power dissipation. First is by means of regulating device performance, which is known as passive cooling. A typical passive cooling is a CPU that has dynamic voltage and frequency scaling (DVFS), and uses lower frequencies as cooling states. Second is by means of activating devices in order to remove the dissipated heat, which is known as active cooling, e.g. regulating fan speeds. In both cases, cooling devices shall have a way to determine the state of cooling in which the device is. Signed-off-by: wangjianyu3 <wangjian...@xiaomi.com> --- drivers/thermal/thermal_core.c | 24 +++++++++++++++++++++++- drivers/thermal/thermal_dummy.c | 19 ++++++++++--------- include/nuttx/thermal.h | 4 +++- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 5bea526773..d7c57442da 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -815,6 +815,9 @@ void thermal_zone_device_update(FAR struct thermal_zone_device_s *zdev) { int trip_high = INT_MAX; int trip_low = INT_MIN; + FAR struct thermal_instance_s *pos; + unsigned int current; + clock_t delay; int trip; int temp; int ret; @@ -893,8 +896,27 @@ void thermal_zone_device_update(FAR struct thermal_zone_device_s *zdev) } } + /* Update worker invoke delay */ + + delay = zdev->params->passive_delay; + list_for_every_entry(&zdev->instance_list, pos, + struct thermal_instance_s, zdev_node) + { + if (zdev->params->trips[pos->trip].type == THERMAL_PASSIVE) + { + continue; + } + + pos->cdev->ops->get_state(pos->cdev, ¤t); + if ((current != 0 && current != THERMAL_NO_TARGET) || + (pos->target != 0 && pos->target != THERMAL_NO_TARGET)) + { + delay = zdev->params->polling_delay; + } + } + work_queue(LPWORK, &zdev->monitor, (worker_t)thermal_zone_device_update, - zdev, zdev->params->polling_delay); + zdev, delay); unlock: nxmutex_unlock(&g_thermal_lock); diff --git a/drivers/thermal/thermal_dummy.c b/drivers/thermal/thermal_dummy.c index 0de5daa06f..42b2ce9aad 100644 --- a/drivers/thermal/thermal_dummy.c +++ b/drivers/thermal/thermal_dummy.c @@ -112,7 +112,7 @@ static const struct thermal_zone_trip_s g_dummy_trips[] = { {.name = "cpu_crit", .temp = 90, .hyst = 5, .type = THERMAL_CRITICAL}, {.name = "cpu_alert1", .temp = 70, .hyst = 5, .type = THERMAL_HOT}, - {.name = "cpu_alert0", .temp = 60, .hyst = 5, .type = THERMAL_NORMAL}, + {.name = "cpu_alert0", .temp = 60, .hyst = 5, .type = THERMAL_PASSIVE}, }; static const struct thermal_zone_map_s g_dummy_maps[] = @@ -143,6 +143,7 @@ static const struct thermal_zone_map_s g_dummy_maps[] = static const struct thermal_zone_params_s g_dummy_params = { .gov_name = "step_wise", + .passive_delay = CONFIG_THERMAL_DUMMY_POLLING_DELAY * 2, .polling_delay = CONFIG_THERMAL_DUMMY_POLLING_DELAY, .trips = g_dummy_trips, .num_trips = nitems(g_dummy_trips), @@ -165,6 +166,13 @@ static struct dummy_zone_device_s g_dummy_zone = .temp_jump = true, }; +static const struct thermal_cooling_device_ops_s g_dummy_cooling_ops = +{ + .set_state = dummy_cdev_set_state, + .get_state = dummy_cdev_get_state, + .get_max_state = dummy_cdev_get_max_state, +}; + /* Cooling Device - fan0 */ static struct dummy_cooling_device_s g_dummy_fan0_data = @@ -173,13 +181,6 @@ static struct dummy_cooling_device_s g_dummy_fan0_data = .max_state = 16, }; -static const struct thermal_cooling_device_ops_s g_dummy_fan0_ops = -{ - .set_state = dummy_cdev_set_state, - .get_state = dummy_cdev_get_state, - .get_max_state = dummy_cdev_get_max_state, -}; - /* Cooling Device - cpufreq */ #ifdef CONFIG_THERMAL_DUMMY_CPUFREQ @@ -338,7 +339,7 @@ int thermal_dummy_init(void) /* Cooling Device */ cdev = thermal_cooling_device_register("fan0", &g_dummy_fan0_data, - &g_dummy_fan0_ops); + &g_dummy_cooling_ops); if (cdev == NULL) { therr("Register cooling device fan0 failed!\n"); diff --git a/include/nuttx/thermal.h b/include/nuttx/thermal.h index 673c841649..a9061a6d54 100644 --- a/include/nuttx/thermal.h +++ b/include/nuttx/thermal.h @@ -71,7 +71,8 @@ enum thermal_trend_e enum thermal_trip_type_e { - THERMAL_NORMAL, + THERMAL_ACTIVE, + THERMAL_PASSIVE, THERMAL_HOT, THERMAL_CRITICAL, THERMAL_TRIP_TYPE_MAX, @@ -163,6 +164,7 @@ struct thermal_zone_trip_s struct thermal_zone_params_s { FAR const char *gov_name; + int passive_delay; int polling_delay; FAR const struct thermal_zone_trip_s *trips; int num_trips;