Skip to content

Commit 530c932

Browse files
committed
thermal: gov_bang_bang: Use .trip_crossed() instead of .throttle()
The Bang-Bang governor really is only concerned about trip point crossing, so it can use the new .trip_crossed() callback instead of .throttle() that is not particularly suitable for it. Modify it to do so which also takes trip hysteresis into account, so the governor does not need to use it directly any more. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Acked-by: Daniel Lezcano <[email protected]>
1 parent 80f5fd4 commit 530c932

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
#include "thermal_core.h"
1515

16-
static int thermal_zone_trip_update(struct thermal_zone_device *tz,
17-
const struct thermal_trip *trip)
16+
static void thermal_zone_trip_update(struct thermal_zone_device *tz,
17+
const struct thermal_trip *trip,
18+
bool crossed_up)
1819
{
1920
int trip_index = thermal_zone_trip_id(tz, trip);
2021
struct thermal_instance *instance;
@@ -43,13 +44,12 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz,
4344
}
4445

4546
/*
46-
* enable fan when temperature exceeds trip_temp and disable
47-
* the fan in case it falls below trip_temp minus hysteresis
47+
* Enable the fan when the trip is crossed on the way up and
48+
* disable it when the trip is crossed on the way down.
4849
*/
49-
if (instance->target == 0 && tz->temperature >= trip->temperature)
50+
if (instance->target == 0 && crossed_up)
5051
instance->target = 1;
51-
else if (instance->target == 1 &&
52-
tz->temperature < trip->temperature - trip->hysteresis)
52+
else if (instance->target == 1 && !crossed_up)
5353
instance->target = 0;
5454

5555
dev_dbg(&instance->cdev->device, "target=%d\n",
@@ -59,14 +59,13 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz,
5959
instance->cdev->updated = false; /* cdev needs update */
6060
mutex_unlock(&instance->cdev->lock);
6161
}
62-
63-
return 0;
6462
}
6563

6664
/**
6765
* bang_bang_control - controls devices associated with the given zone
6866
* @tz: thermal_zone_device
6967
* @trip: the trip point
68+
* @crossed_up: whether or not the trip has been crossed on the way up
7069
*
7170
* Regulation Logic: a two point regulation, deliver cooling state depending
7271
* on the previous state shown in this diagram:
@@ -90,26 +89,22 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz,
9089
* (trip_temp - hyst) so that the fan gets turned off again.
9190
*
9291
*/
93-
static int bang_bang_control(struct thermal_zone_device *tz,
94-
const struct thermal_trip *trip)
92+
static void bang_bang_control(struct thermal_zone_device *tz,
93+
const struct thermal_trip *trip,
94+
bool crossed_up)
9595
{
9696
struct thermal_instance *instance;
97-
int ret;
9897

9998
lockdep_assert_held(&tz->lock);
10099

101-
ret = thermal_zone_trip_update(tz, trip);
102-
if (ret)
103-
return ret;
100+
thermal_zone_trip_update(tz, trip, crossed_up);
104101

105102
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
106103
thermal_cdev_update(instance->cdev);
107-
108-
return 0;
109104
}
110105

111106
static struct thermal_governor thermal_gov_bang_bang = {
112107
.name = "bang_bang",
113-
.throttle = bang_bang_control,
108+
.trip_crossed = bang_bang_control,
114109
};
115110
THERMAL_GOVERNOR_DECLARE(thermal_gov_bang_bang);

0 commit comments

Comments
 (0)