summaryrefslogtreecommitdiff
path: root/drivers/thermal/gov_step_wise.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/thermal/gov_step_wise.c')
-rw-r--r--drivers/thermal/gov_step_wise.c26
1 files changed, 4 insertions, 22 deletions
diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
index 12acb12aac50..9729b46d0258 100644
--- a/drivers/thermal/gov_step_wise.c
+++ b/drivers/thermal/gov_step_wise.c
@@ -11,6 +11,7 @@
*/
#include <linux/thermal.h>
+#include <linux/minmax.h>
#include <trace/events/thermal.h>
#include "thermal_core.h"
@@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
if (!instance->initialized) {
if (throttle) {
- next_target = (cur_state + 1) >= instance->upper ?
- instance->upper :
- ((cur_state + 1) < instance->lower ?
- instance->lower : (cur_state + 1));
+ next_target = clamp((cur_state + 1), instance->lower, instance->upper);
} else {
next_target = THERMAL_NO_TARGET;
}
@@ -66,35 +64,19 @@ static unsigned long get_target_state(struct thermal_instance *instance,
switch (trend) {
case THERMAL_TREND_RAISING:
if (throttle) {
- next_target = cur_state < instance->upper ?
- (cur_state + 1) : instance->upper;
- if (next_target < instance->lower)
- next_target = instance->lower;
+ next_target = clamp((cur_state + 1), instance->lower, instance->upper);
}
break;
- case THERMAL_TREND_RAISE_FULL:
- if (throttle)
- next_target = instance->upper;
- break;
case THERMAL_TREND_DROPPING:
if (cur_state <= instance->lower) {
if (!throttle)
next_target = THERMAL_NO_TARGET;
} else {
if (!throttle) {
- next_target = cur_state - 1;
- if (next_target > instance->upper)
- next_target = instance->upper;
+ next_target = clamp((cur_state - 1), instance->lower, instance->upper);
}
}
break;
- case THERMAL_TREND_DROP_FULL:
- if (cur_state == instance->lower) {
- if (!throttle)
- next_target = THERMAL_NO_TARGET;
- } else
- next_target = instance->lower;
- break;
default:
break;
}