Commit 7f725a23 authored by Daniel Lezcano's avatar Daniel Lezcano Committed by Daniel Lezcano

thermal/core/governors: Use thermal_zone_get_trip() instead of ops functions

The governors are using the ops->get_trip_* functions, Replace these
calls with thermal_zone_get_trip().
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: default avatarZhang Rui <rui.zhang@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com> # IPA
Acked-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://lore.kernel.org/r/20221003092602.1323944-5-daniel.lezcano@linaro.org
parent 2e38a2a9
...@@ -13,26 +13,28 @@ ...@@ -13,26 +13,28 @@
#include "thermal_core.h" #include "thermal_core.h"
static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
{ {
int trip_temp, trip_hyst; struct thermal_trip trip;
struct thermal_instance *instance; struct thermal_instance *instance;
int ret;
tz->ops->get_trip_temp(tz, trip, &trip_temp); ret = __thermal_zone_get_trip(tz, trip_id, &trip);
if (ret) {
pr_warn_once("Failed to retrieve trip point %d\n", trip_id);
return ret;
}
if (!tz->ops->get_trip_hyst) { if (!trip.hysteresis)
pr_warn_once("Undefined get_trip_hyst for thermal zone %s - " dev_info_once(&tz->device,
"running with default hysteresis zero\n", tz->type); "Zero hysteresis value for thermal zone %s\n", tz->type);
trip_hyst = 0;
} else
tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n", dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
trip, trip_temp, tz->temperature, trip_id, trip.temperature, tz->temperature,
trip_hyst); trip.hysteresis);
list_for_each_entry(instance, &tz->thermal_instances, tz_node) { list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
if (instance->trip != trip) if (instance->trip != trip_id)
continue; continue;
/* in case fan is in initial state, switch the fan off */ /* in case fan is in initial state, switch the fan off */
...@@ -50,10 +52,10 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) ...@@ -50,10 +52,10 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
* enable fan when temperature exceeds trip_temp and disable * enable fan when temperature exceeds trip_temp and disable
* the fan in case it falls below trip_temp minus hysteresis * the fan in case it falls below trip_temp minus hysteresis
*/ */
if (instance->target == 0 && tz->temperature >= trip_temp) if (instance->target == 0 && tz->temperature >= trip.temperature)
instance->target = 1; instance->target = 1;
else if (instance->target == 1 && else if (instance->target == 1 &&
tz->temperature <= trip_temp - trip_hyst) tz->temperature <= trip.temperature - trip.hysteresis)
instance->target = 0; instance->target = 0;
dev_dbg(&instance->cdev->device, "target=%d\n", dev_dbg(&instance->cdev->device, "target=%d\n",
...@@ -63,6 +65,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) ...@@ -63,6 +65,8 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
instance->cdev->updated = false; /* cdev needs update */ instance->cdev->updated = false; /* cdev needs update */
mutex_unlock(&instance->cdev->lock); mutex_unlock(&instance->cdev->lock);
} }
return 0;
} }
/** /**
...@@ -95,10 +99,13 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) ...@@ -95,10 +99,13 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
static int bang_bang_control(struct thermal_zone_device *tz, int trip) static int bang_bang_control(struct thermal_zone_device *tz, int trip)
{ {
struct thermal_instance *instance; struct thermal_instance *instance;
int ret;
lockdep_assert_held(&tz->lock); lockdep_assert_held(&tz->lock);
thermal_zone_trip_update(tz, trip); ret = thermal_zone_trip_update(tz, trip);
if (ret)
return ret;
list_for_each_entry(instance, &tz->thermal_instances, tz_node) list_for_each_entry(instance, &tz->thermal_instances, tz_node)
thermal_cdev_update(instance->cdev); thermal_cdev_update(instance->cdev);
......
...@@ -21,16 +21,12 @@ ...@@ -21,16 +21,12 @@
*/ */
static int get_trip_level(struct thermal_zone_device *tz) static int get_trip_level(struct thermal_zone_device *tz)
{ {
int count = 0; struct thermal_trip trip;
int trip_temp; int count;
enum thermal_trip_type trip_type;
if (tz->num_trips == 0 || !tz->ops->get_trip_temp)
return 0;
for (count = 0; count < tz->num_trips; count++) { for (count = 0; count < tz->num_trips; count++) {
tz->ops->get_trip_temp(tz, count, &trip_temp); __thermal_zone_get_trip(tz, count, &trip);
if (tz->temperature < trip_temp) if (tz->temperature < trip.temperature)
break; break;
} }
...@@ -38,10 +34,8 @@ static int get_trip_level(struct thermal_zone_device *tz) ...@@ -38,10 +34,8 @@ static int get_trip_level(struct thermal_zone_device *tz)
* count > 0 only if temperature is greater than first trip * count > 0 only if temperature is greater than first trip
* point, in which case, trip_point = count - 1 * point, in which case, trip_point = count - 1
*/ */
if (count > 0) { if (count > 0)
tz->ops->get_trip_type(tz, count - 1, &trip_type); trace_thermal_zone_trip(tz, count - 1, trip.type);
trace_thermal_zone_trip(tz, count - 1, trip_type);
}
return count; return count;
} }
......
...@@ -124,16 +124,15 @@ static void estimate_pid_constants(struct thermal_zone_device *tz, ...@@ -124,16 +124,15 @@ static void estimate_pid_constants(struct thermal_zone_device *tz,
u32 sustainable_power, int trip_switch_on, u32 sustainable_power, int trip_switch_on,
int control_temp) int control_temp)
{ {
struct thermal_trip trip;
u32 temperature_threshold = control_temp;
int ret; int ret;
int switch_on_temp;
u32 temperature_threshold;
s32 k_i; s32 k_i;
ret = tz->ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp); ret = __thermal_zone_get_trip(tz, trip_switch_on, &trip);
if (ret) if (!ret)
switch_on_temp = 0; temperature_threshold -= trip.temperature;
temperature_threshold = control_temp - switch_on_temp;
/* /*
* estimate_pid_constants() tries to find appropriate default * estimate_pid_constants() tries to find appropriate default
* values for thermal zones that don't provide them. If a * values for thermal zones that don't provide them. If a
...@@ -519,10 +518,10 @@ static void get_governor_trips(struct thermal_zone_device *tz, ...@@ -519,10 +518,10 @@ static void get_governor_trips(struct thermal_zone_device *tz,
last_passive = INVALID_TRIP; last_passive = INVALID_TRIP;
for (i = 0; i < tz->num_trips; i++) { for (i = 0; i < tz->num_trips; i++) {
enum thermal_trip_type type; struct thermal_trip trip;
int ret; int ret;
ret = tz->ops->get_trip_type(tz, i, &type); ret = __thermal_zone_get_trip(tz, i, &trip);
if (ret) { if (ret) {
dev_warn(&tz->device, dev_warn(&tz->device,
"Failed to get trip point %d type: %d\n", i, "Failed to get trip point %d type: %d\n", i,
...@@ -530,14 +529,14 @@ static void get_governor_trips(struct thermal_zone_device *tz, ...@@ -530,14 +529,14 @@ static void get_governor_trips(struct thermal_zone_device *tz,
continue; continue;
} }
if (type == THERMAL_TRIP_PASSIVE) { if (trip.type == THERMAL_TRIP_PASSIVE) {
if (!found_first_passive) { if (!found_first_passive) {
params->trip_switch_on = i; params->trip_switch_on = i;
found_first_passive = true; found_first_passive = true;
} else { } else {
last_passive = i; last_passive = i;
} }
} else if (type == THERMAL_TRIP_ACTIVE) { } else if (trip.type == THERMAL_TRIP_ACTIVE) {
last_active = i; last_active = i;
} else { } else {
break; break;
...@@ -632,7 +631,7 @@ static int power_allocator_bind(struct thermal_zone_device *tz) ...@@ -632,7 +631,7 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
{ {
int ret; int ret;
struct power_allocator_params *params; struct power_allocator_params *params;
int control_temp; struct thermal_trip trip;
ret = check_power_actors(tz); ret = check_power_actors(tz);
if (ret) if (ret)
...@@ -658,13 +657,12 @@ static int power_allocator_bind(struct thermal_zone_device *tz) ...@@ -658,13 +657,12 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
get_governor_trips(tz, params); get_governor_trips(tz, params);
if (tz->num_trips > 0) { if (tz->num_trips > 0) {
ret = tz->ops->get_trip_temp(tz, ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature,
params->trip_max_desired_temperature, &trip);
&control_temp);
if (!ret) if (!ret)
estimate_pid_constants(tz, tz->tzp->sustainable_power, estimate_pid_constants(tz, tz->tzp->sustainable_power,
params->trip_switch_on, params->trip_switch_on,
control_temp); trip.temperature);
} }
reset_pid_controller(params); reset_pid_controller(params);
...@@ -694,11 +692,11 @@ static void power_allocator_unbind(struct thermal_zone_device *tz) ...@@ -694,11 +692,11 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
tz->governor_data = NULL; tz->governor_data = NULL;
} }
static int power_allocator_throttle(struct thermal_zone_device *tz, int trip) static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id)
{ {
int ret;
int switch_on_temp, control_temp;
struct power_allocator_params *params = tz->governor_data; struct power_allocator_params *params = tz->governor_data;
struct thermal_trip trip;
int ret;
bool update; bool update;
lockdep_assert_held(&tz->lock); lockdep_assert_held(&tz->lock);
...@@ -707,13 +705,12 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip) ...@@ -707,13 +705,12 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
* We get called for every trip point but we only need to do * We get called for every trip point but we only need to do
* our calculations once * our calculations once
*/ */
if (trip != params->trip_max_desired_temperature) if (trip_id != params->trip_max_desired_temperature)
return 0; return 0;
ret = tz->ops->get_trip_temp(tz, params->trip_switch_on, ret = __thermal_zone_get_trip(tz, params->trip_switch_on, &trip);
&switch_on_temp); if (!ret && (tz->temperature < trip.temperature)) {
if (!ret && (tz->temperature < switch_on_temp)) { update = (tz->last_temperature >= trip.temperature);
update = (tz->last_temperature >= switch_on_temp);
tz->passive = 0; tz->passive = 0;
reset_pid_controller(params); reset_pid_controller(params);
allow_maximum_power(tz, update); allow_maximum_power(tz, update);
...@@ -722,16 +719,14 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip) ...@@ -722,16 +719,14 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
tz->passive = 1; tz->passive = 1;
ret = tz->ops->get_trip_temp(tz, params->trip_max_desired_temperature, ret = __thermal_zone_get_trip(tz, params->trip_max_desired_temperature, &trip);
&control_temp);
if (ret) { if (ret) {
dev_warn(&tz->device, dev_warn(&tz->device, "Failed to get the maximum desired temperature: %d\n",
"Failed to get the maximum desired temperature: %d\n",
ret); ret);
return ret; return ret;
} }
return allocate_power(tz, control_temp); return allocate_power(tz, trip.temperature);
} }
static struct thermal_governor thermal_gov_power_allocator = { static struct thermal_governor thermal_gov_power_allocator = {
......
...@@ -95,30 +95,28 @@ static void update_passive_instance(struct thermal_zone_device *tz, ...@@ -95,30 +95,28 @@ static void update_passive_instance(struct thermal_zone_device *tz,
tz->passive += value; tz->passive += value;
} }
static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
{ {
int trip_temp;
enum thermal_trip_type trip_type;
enum thermal_trend trend; enum thermal_trend trend;
struct thermal_instance *instance; struct thermal_instance *instance;
struct thermal_trip trip;
bool throttle = false; bool throttle = false;
int old_target; int old_target;
tz->ops->get_trip_temp(tz, trip, &trip_temp); __thermal_zone_get_trip(tz, trip_id, &trip);
tz->ops->get_trip_type(tz, trip, &trip_type);
trend = get_tz_trend(tz, trip); trend = get_tz_trend(tz, trip_id);
if (tz->temperature >= trip_temp) { if (tz->temperature >= trip.temperature) {
throttle = true; throttle = true;
trace_thermal_zone_trip(tz, trip, trip_type); trace_thermal_zone_trip(tz, trip_id, trip.type);
} }
dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n", dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
trip, trip_type, trip_temp, trend, throttle); trip_id, trip.type, trip.temperature, trend, throttle);
list_for_each_entry(instance, &tz->thermal_instances, tz_node) { list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
if (instance->trip != trip) if (instance->trip != trip_id)
continue; continue;
old_target = instance->target; old_target = instance->target;
...@@ -132,11 +130,11 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) ...@@ -132,11 +130,11 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
/* Activate a passive thermal instance */ /* Activate a passive thermal instance */
if (old_target == THERMAL_NO_TARGET && if (old_target == THERMAL_NO_TARGET &&
instance->target != THERMAL_NO_TARGET) instance->target != THERMAL_NO_TARGET)
update_passive_instance(tz, trip_type, 1); update_passive_instance(tz, trip.type, 1);
/* Deactivate a passive thermal instance */ /* Deactivate a passive thermal instance */
else if (old_target != THERMAL_NO_TARGET && else if (old_target != THERMAL_NO_TARGET &&
instance->target == THERMAL_NO_TARGET) instance->target == THERMAL_NO_TARGET)
update_passive_instance(tz, trip_type, -1); update_passive_instance(tz, trip.type, -1);
instance->initialized = true; instance->initialized = true;
mutex_lock(&instance->cdev->lock); mutex_lock(&instance->cdev->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment