Skip to content

Commit 9730c35

Browse files
committed
Revert "Revert "drivers: thermal: step_wise: add support for hysteresis""
This reverts commit 0e2d9b4.
1 parent 55de5fe commit 9730c35

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

drivers/thermal/gov_step_wise.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
#include "thermal_core.h"
1818

1919
/*
20-
* If the temperature is higher than a trip point,
20+
* If the temperature is higher than a hysteresis temperature,
2121
* a. if the trend is THERMAL_TREND_RAISING, use higher cooling
2222
* state for this trip point
2323
* b. if the trend is THERMAL_TREND_DROPPING, use a lower cooling state
2424
* for this trip point, but keep the cooling state above the applicable
2525
* minimum
26-
* If the temperature is lower than a trip point,
26+
* If the temperature is lower than a hysteresis temperature,
2727
* a. if the trend is THERMAL_TREND_RAISING, do nothing
28-
* b. if the trend is THERMAL_TREND_DROPPING, use lower cooling
29-
* state for this trip point, if the cooling state already
28+
* b. if the trend is THERMAL_TREND_DROPPING, use the minimum applicable
29+
* cooling state for this trip point, or if the cooling state already
3030
* equals lower limit, deactivate the thermal instance
3131
*/
3232
static unsigned long get_target_state(struct thermal_instance *instance,
@@ -83,23 +83,36 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz,
8383
int trip_threshold)
8484
{
8585
const struct thermal_trip *trip = &td->trip;
86+
int hyst_temp = trip->temperature - trip->hysteresis;
87+
bool throttle = tz->temperature >= hyst_temp;
8688
enum thermal_trend trend = get_tz_trend(tz, trip);
8789
int trip_id = thermal_zone_trip_id(tz, trip);
8890
struct thermal_instance *instance;
89-
bool throttle = false;
9091

91-
if (tz->temperature >= trip_threshold) {
92-
throttle = true;
92+
if (throttle)
9393
trace_thermal_zone_trip(tz, trip_id, trip->type);
94-
}
9594

96-
dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
97-
trip_id, trip->type, trip_threshold, trend, throttle);
95+
dev_dbg(&tz->device,
96+
"Trip%d[type=%d,temp=%d,hyst=%d]:trend=%d,throttle=%d\n",
97+
trip_id, trip->type, trip->temperature, hyst_temp, trend, throttle);
9898

9999
list_for_each_entry(instance, &td->thermal_instances, trip_node) {
100100
int old_target;
101101

102102
old_target = instance->target;
103+
throttle = false;
104+
105+
/*
106+
* Lower the mitigation only if the temperature
107+
* goes below the hysteresis temperature.
108+
*/
109+
if (tz->temperature >= trip->temperature ||
110+
(tz->temperature >= hyst_temp &&
111+
old_target == instance->upper)) {
112+
throttle = true;
113+
trace_thermal_zone_trip(tz, trip_id, trip->type);
114+
}
115+
103116
instance->target = get_target_state(instance, trend, throttle);
104117

105118
dev_dbg(&instance->cdev->device, "old_target=%d, target=%ld\n",

0 commit comments

Comments
 (0)