summaryrefslogtreecommitdiff
path: root/drivers/thermal/thermal_helpers.c
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2022-10-03 11:25:34 +0200
committerDaniel Lezcano <daniel.lezcano@kernel.org>2023-01-06 14:14:47 +0100
commit7c3d5c20dc169e55064f7f38c1c56cfbc39ee5b2 (patch)
tree026ec0b93c36f54e00a6116abe44b74578d67813 /drivers/thermal/thermal_helpers.c
parentb878d3ba9bb41cddb73ba4b56e5552f0a638daca (diff)
thermal/core: Add a generic thermal_zone_get_trip() function
The thermal_zone_device_ops structure defines a set of ops family, get_trip_temp(), get_trip_hyst(), get_trip_type(). Each of them is returning a property of a trip point. The result is the code is calling the ops everywhere to get a trip point which is supposed to be defined in the backend driver. It is a non-sense as a thermal trip can be generic and used by the backend driver to declare its trip points. Part of the thermal framework has been changed and all the OF thermal drivers are using the same definition for the trip point and use a thermal zone registration variant to pass those trip points which are part of the thermal zone device structure. Consequently, we can use a generic function to get the trip points when they are stored in the thermal zone device structure. This approach can be generalized to all the drivers and we can get rid of the ops->get_trip_*. That will result to a much more simpler code and make possible to rework how the thermal trip are handled in the thermal core framework as discussed previously. This change adds a function thermal_zone_get_trip() where we get the thermal trip point structure which contains all the properties (type, temp, hyst) instead of doing multiple calls to ops->get_trip_*. That opens the door for trip point extension with more attributes. For instance, replacing the trip points disabled bitmask with a 'disabled' field in the structure. Here we replace all the calls to ops->get_trip_* in the thermal core code with a call to the thermal_zone_get_trip() function. The thermal zone ops defines a callback to retrieve the critical temperature. As the trip handling is being reworked, all the trip points will be the same whatever the driver and consequently finding the critical trip temperature will be just a loop to search for a critical trip point type. Provide such a generic function, so we encapsulate the ops get_crit_temp() which can be removed when all the backend drivers are using the generic trip points handling. While at it, add the thermal_zone_get_num_trips() to encapsulate the code more and reduce the grip with the thermal framework internals. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Zhang Rui <rui.zhang@intel.com> Link: https://lore.kernel.org/r/20221003092602.1323944-2-daniel.lezcano@linaro.org
Diffstat (limited to 'drivers/thermal/thermal_helpers.c')
-rw-r--r--drivers/thermal/thermal_helpers.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index 56aa2e88f34f..8977d5ddc23c 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -83,7 +83,7 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
int ret = -EINVAL;
int count;
int crit_temp = INT_MAX;
- enum thermal_trip_type type;
+ struct thermal_trip trip;
lockdep_assert_held(&tz->lock);
@@ -91,10 +91,9 @@ int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
for (count = 0; count < tz->num_trips; count++) {
- ret = tz->ops->get_trip_type(tz, count, &type);
- if (!ret && type == THERMAL_TRIP_CRITICAL) {
- ret = tz->ops->get_trip_temp(tz, count,
- &crit_temp);
+ ret = __thermal_zone_get_trip(tz, count, &trip);
+ if (!ret && trip.type == THERMAL_TRIP_CRITICAL) {
+ crit_temp = trip.temperature;
break;
}
}
@@ -164,29 +163,30 @@ EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
*/
void __thermal_zone_set_trips(struct thermal_zone_device *tz)
{
- int low = -INT_MAX;
- int high = INT_MAX;
- int trip_temp, hysteresis;
+ struct thermal_trip trip;
+ int low = -INT_MAX, high = INT_MAX;
int i, ret;
lockdep_assert_held(&tz->lock);
- if (!tz->ops->set_trips || !tz->ops->get_trip_hyst)
+ if (!tz->ops->set_trips)
return;
for (i = 0; i < tz->num_trips; i++) {
int trip_low;
- tz->ops->get_trip_temp(tz, i, &trip_temp);
- tz->ops->get_trip_hyst(tz, i, &hysteresis);
+ ret = __thermal_zone_get_trip(tz, i , &trip);
+ if (ret)
+ return;
- trip_low = trip_temp - hysteresis;
+ trip_low = trip.temperature - trip.hysteresis;
if (trip_low < tz->temperature && trip_low > low)
low = trip_low;
- if (trip_temp > tz->temperature && trip_temp < high)
- high = trip_temp;
+ if (trip.temperature > tz->temperature &&
+ trip.temperature < high)
+ high = trip.temperature;
}
/* No need to change trip points */