Skip to content

Commit f9ba1e0

Browse files
dlezcanorafaeljw
authored andcommitted
thermal/core: Compute low and high boundaries in thermal_zone_device_update()
In order to set the scene for the thresholds support which have to manipulate the low and high temperature boundaries for the interrupt support, we must pass the low and high values to the incoming thresholds routine. The variables are set from the thermal_zone_set_trips() where the function loops the thermal trips to figure out the next and the previous temperatures to set the interrupt to be triggered when they are crossed. These variables will be needed by the function in charge of handling the thresholds in the incoming changes but they are local to the aforementioned function thermal_zone_set_trips(). Move the low and high boundaries computation out of the function in thermal_zone_device_update() so they are accessible from there. The positive side effect is they are computed in the same loop as handle_thermal_trip(), so we remove one loop. Co-developed-by: Rafael J. Wysocki <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 5ae98b5 commit f9ba1e0

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

drivers/thermal/thermal_core.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
547547
struct thermal_trip_desc *td;
548548
LIST_HEAD(way_down_list);
549549
LIST_HEAD(way_up_list);
550+
int low = -INT_MAX, high = INT_MAX;
550551
int temp, ret;
551552

552553
if (tz->suspended)
@@ -580,10 +581,17 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
580581

581582
tz->notify_event = event;
582583

583-
for_each_trip_desc(tz, td)
584+
for_each_trip_desc(tz, td) {
584585
handle_thermal_trip(tz, td, &way_up_list, &way_down_list);
585586

586-
thermal_zone_set_trips(tz);
587+
if (td->threshold <= tz->temperature && td->threshold > low)
588+
low = td->threshold;
589+
590+
if (td->threshold >= tz->temperature && td->threshold < high)
591+
high = td->threshold;
592+
}
593+
594+
thermal_zone_set_trips(tz, low, high);
587595

588596
list_sort(NULL, &way_up_list, thermal_trip_notify_cmp);
589597
list_for_each_entry(td, &way_up_list, notify_list_node)

drivers/thermal/thermal_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void thermal_governor_update_tz(struct thermal_zone_device *tz,
255255

256256
const char *thermal_trip_type_name(enum thermal_trip_type trip_type);
257257

258-
void thermal_zone_set_trips(struct thermal_zone_device *tz);
258+
void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high);
259259
int thermal_zone_trip_id(const struct thermal_zone_device *tz,
260260
const struct thermal_trip *trip);
261261
int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);

drivers/thermal/thermal_trip.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,15 @@ int thermal_zone_for_each_trip(struct thermal_zone_device *tz,
5555
}
5656
EXPORT_SYMBOL_GPL(thermal_zone_for_each_trip);
5757

58-
/**
59-
* thermal_zone_set_trips - Computes the next trip points for the driver
60-
* @tz: a pointer to a thermal zone device structure
61-
*
62-
* The function computes the next temperature boundaries by browsing
63-
* the trip points. The result is the closer low and high trip points
64-
* to the current temperature. These values are passed to the backend
65-
* driver to let it set its own notification mechanism (usually an
66-
* interrupt).
67-
*
68-
* This function must be called with tz->lock held. Both tz and tz->ops
69-
* must be valid pointers.
70-
*
71-
* It does not return a value
72-
*/
73-
void thermal_zone_set_trips(struct thermal_zone_device *tz)
58+
void thermal_zone_set_trips(struct thermal_zone_device *tz, int low, int high)
7459
{
75-
const struct thermal_trip_desc *td;
76-
int low = -INT_MAX, high = INT_MAX;
7760
int ret;
7861

7962
lockdep_assert_held(&tz->lock);
8063

8164
if (!tz->ops.set_trips)
8265
return;
8366

84-
for_each_trip_desc(tz, td) {
85-
if (td->threshold <= tz->temperature && td->threshold > low)
86-
low = td->threshold;
87-
88-
if (td->threshold >= tz->temperature && td->threshold < high)
89-
high = td->threshold;
90-
}
91-
9267
/* No need to change trip points */
9368
if (tz->prev_low_trip == low && tz->prev_high_trip == high)
9469
return;

0 commit comments

Comments
 (0)