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 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3 2025-02-11 15:33:58 +08:00 committed by Alan C. Assis
parent c57c95755d
commit 0b633946c0
3 changed files with 36 additions and 11 deletions

View file

@ -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, &current);
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);

View file

@ -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");

View file

@ -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;