Skip to content

Commit 3770201

Browse files
committed
Merge branch 'thermal-core'
Merge thermal core changes for v6.7 depended on by subsequent ACPI thermal driver changes: - Drop trips_disabled bitmask that is not really useful any more from the thermal zone structure. - Drop a reduntant NULL pointer check from for_each_thermal_trip(). - Redefine struct thermal_instance to hold a thernal trip pointer instead of a trip index. - Add helpers for binding and unbinding cooling devices to and from trip points, reslectively, that take trip pointers as arguments. * thermal-core: thermal: core: Allow trip pointers to be used for cooling device binding thermal: core: Store trip pointer in struct thermal_instance thermal: trip: Drop redundant trips check from for_each_thermal_trip() thermal: core: Drop trips_disabled bitmask
2 parents 2713b83 + d069ed6 commit 3770201

File tree

10 files changed

+92
-65
lines changed

10 files changed

+92
-65
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,21 @@
1313

1414
#include "thermal_core.h"
1515

16-
static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
16+
static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_index)
1717
{
18-
struct thermal_trip trip;
18+
const struct thermal_trip *trip = &tz->trips[trip_index];
1919
struct thermal_instance *instance;
20-
int ret;
21-
22-
ret = __thermal_zone_get_trip(tz, trip_id, &trip);
23-
if (ret) {
24-
pr_warn_once("Failed to retrieve trip point %d\n", trip_id);
25-
return ret;
26-
}
2720

28-
if (!trip.hysteresis)
21+
if (!trip->hysteresis)
2922
dev_info_once(&tz->device,
3023
"Zero hysteresis value for thermal zone %s\n", tz->type);
3124

3225
dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
33-
trip_id, trip.temperature, tz->temperature,
34-
trip.hysteresis);
26+
trip_index, trip->temperature, tz->temperature,
27+
trip->hysteresis);
3528

3629
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
37-
if (instance->trip != trip_id)
30+
if (instance->trip != trip)
3831
continue;
3932

4033
/* in case fan is in initial state, switch the fan off */
@@ -52,10 +45,10 @@ static int thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
5245
* enable fan when temperature exceeds trip_temp and disable
5346
* the fan in case it falls below trip_temp minus hysteresis
5447
*/
55-
if (instance->target == 0 && tz->temperature >= trip.temperature)
48+
if (instance->target == 0 && tz->temperature >= trip->temperature)
5649
instance->target = 1;
5750
else if (instance->target == 1 &&
58-
tz->temperature <= trip.temperature - trip.hysteresis)
51+
tz->temperature <= trip->temperature - trip->hysteresis)
5952
instance->target = 0;
6053

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

drivers/thermal/gov_fair_share.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static long get_target_state(struct thermal_zone_device *tz,
4949
/**
5050
* fair_share_throttle - throttles devices associated with the given zone
5151
* @tz: thermal_zone_device
52-
* @trip: trip point index
52+
* @trip_index: trip point index
5353
*
5454
* Throttling Logic: This uses three parameters to calculate the new
5555
* throttle state of the cooling devices associated with the given zone.
@@ -65,8 +65,9 @@ static long get_target_state(struct thermal_zone_device *tz,
6565
* (Heavily assumes the trip points are in ascending order)
6666
* new_state of cooling device = P3 * P2 * P1
6767
*/
68-
static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
68+
static int fair_share_throttle(struct thermal_zone_device *tz, int trip_index)
6969
{
70+
const struct thermal_trip *trip = &tz->trips[trip_index];
7071
struct thermal_instance *instance;
7172
int total_weight = 0;
7273
int total_instance = 0;

drivers/thermal/gov_power_allocator.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,14 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
9090
u32 sustainable_power = 0;
9191
struct thermal_instance *instance;
9292
struct power_allocator_params *params = tz->governor_data;
93+
const struct thermal_trip *trip_max_desired_temperature =
94+
&tz->trips[params->trip_max_desired_temperature];
9395

9496
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
9597
struct thermal_cooling_device *cdev = instance->cdev;
9698
u32 min_power;
9799

98-
if (instance->trip != params->trip_max_desired_temperature)
100+
if (instance->trip != trip_max_desired_temperature)
99101
continue;
100102

101103
if (!cdev_is_power_actor(cdev))
@@ -383,12 +385,13 @@ static int allocate_power(struct thermal_zone_device *tz,
383385
{
384386
struct thermal_instance *instance;
385387
struct power_allocator_params *params = tz->governor_data;
388+
const struct thermal_trip *trip_max_desired_temperature =
389+
&tz->trips[params->trip_max_desired_temperature];
386390
u32 *req_power, *max_power, *granted_power, *extra_actor_power;
387391
u32 *weighted_req_power;
388392
u32 total_req_power, max_allocatable_power, total_weighted_req_power;
389393
u32 total_granted_power, power_range;
390394
int i, num_actors, total_weight, ret = 0;
391-
int trip_max_desired_temperature = params->trip_max_desired_temperature;
392395

393396
num_actors = 0;
394397
total_weight = 0;
@@ -564,12 +567,14 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update)
564567
{
565568
struct thermal_instance *instance;
566569
struct power_allocator_params *params = tz->governor_data;
570+
const struct thermal_trip *trip_max_desired_temperature =
571+
&tz->trips[params->trip_max_desired_temperature];
567572
u32 req_power;
568573

569574
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
570575
struct thermal_cooling_device *cdev = instance->cdev;
571576

572-
if ((instance->trip != params->trip_max_desired_temperature) ||
577+
if ((instance->trip != trip_max_desired_temperature) ||
573578
(!cdev_is_power_actor(instance->cdev)))
574579
continue;
575580

drivers/thermal/gov_step_wise.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,24 @@ static void update_passive_instance(struct thermal_zone_device *tz,
8181

8282
static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id)
8383
{
84+
const struct thermal_trip *trip = &tz->trips[trip_id];
8485
enum thermal_trend trend;
8586
struct thermal_instance *instance;
86-
struct thermal_trip trip;
8787
bool throttle = false;
8888
int old_target;
8989

90-
__thermal_zone_get_trip(tz, trip_id, &trip);
91-
9290
trend = get_tz_trend(tz, trip_id);
9391

94-
if (tz->temperature >= trip.temperature) {
92+
if (tz->temperature >= trip->temperature) {
9593
throttle = true;
96-
trace_thermal_zone_trip(tz, trip_id, trip.type);
94+
trace_thermal_zone_trip(tz, trip_id, trip->type);
9795
}
9896

9997
dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
100-
trip_id, trip.type, trip.temperature, trend, throttle);
98+
trip_id, trip->type, trip->temperature, trend, throttle);
10199

102100
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
103-
if (instance->trip != trip_id)
101+
if (instance->trip != trip)
104102
continue;
105103

106104
old_target = instance->target;
@@ -114,11 +112,11 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip_id
114112
/* Activate a passive thermal instance */
115113
if (old_target == THERMAL_NO_TARGET &&
116114
instance->target != THERMAL_NO_TARGET)
117-
update_passive_instance(tz, trip.type, 1);
115+
update_passive_instance(tz, trip->type, 1);
118116
/* Deactivate a passive thermal instance */
119117
else if (old_target != THERMAL_NO_TARGET &&
120118
instance->target == THERMAL_NO_TARGET)
121-
update_passive_instance(tz, trip.type, -1);
119+
update_passive_instance(tz, trip->type, -1);
122120

123121
instance->initialized = true;
124122
mutex_lock(&instance->cdev->lock);

drivers/thermal/thermal_core.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,6 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip_id)
347347
{
348348
struct thermal_trip trip;
349349

350-
/* Ignore disabled trip points */
351-
if (test_bit(trip_id, &tz->trips_disabled))
352-
return;
353-
354350
__thermal_zone_get_trip(tz, trip_id, &trip);
355351

356352
if (trip.temperature == THERMAL_TEMP_INVALID)
@@ -604,10 +600,9 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
604600
*/
605601

606602
/**
607-
* thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
603+
* thermal_bind_cdev_to_trip - bind a cooling device to a thermal zone
608604
* @tz: pointer to struct thermal_zone_device
609-
* @trip: indicates which trip point the cooling devices is
610-
* associated with in this thermal zone.
605+
* @trip: trip point the cooling devices is associated with in this zone.
611606
* @cdev: pointer to struct thermal_cooling_device
612607
* @upper: the Maximum cooling state for this trip point.
613608
* THERMAL_NO_LIMIT means no upper limit,
@@ -625,8 +620,8 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
625620
*
626621
* Return: 0 on success, the proper error value otherwise.
627622
*/
628-
int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
629-
int trip,
623+
int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
624+
const struct thermal_trip *trip,
630625
struct thermal_cooling_device *cdev,
631626
unsigned long upper, unsigned long lower,
632627
unsigned int weight)
@@ -638,9 +633,6 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
638633
bool upper_no_limit;
639634
int result;
640635

641-
if (trip >= tz->num_trips || trip < 0)
642-
return -EINVAL;
643-
644636
list_for_each_entry(pos1, &thermal_tz_list, node) {
645637
if (pos1 == tz)
646638
break;
@@ -737,14 +729,26 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
737729
kfree(dev);
738730
return result;
739731
}
732+
EXPORT_SYMBOL_GPL(thermal_bind_cdev_to_trip);
733+
734+
int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
735+
int trip_index,
736+
struct thermal_cooling_device *cdev,
737+
unsigned long upper, unsigned long lower,
738+
unsigned int weight)
739+
{
740+
if (trip_index < 0 || trip_index >= tz->num_trips)
741+
return -EINVAL;
742+
743+
return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index], cdev,
744+
upper, lower, weight);
745+
}
740746
EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
741747

742748
/**
743-
* thermal_zone_unbind_cooling_device() - unbind a cooling device from a
744-
* thermal zone.
749+
* thermal_unbind_cdev_from_trip - unbind a cooling device from a thermal zone.
745750
* @tz: pointer to a struct thermal_zone_device.
746-
* @trip: indicates which trip point the cooling devices is
747-
* associated with in this thermal zone.
751+
* @trip: trip point the cooling devices is associated with in this zone.
748752
* @cdev: pointer to a struct thermal_cooling_device.
749753
*
750754
* This interface function unbind a thermal cooling device from the certain
@@ -753,9 +757,9 @@ EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
753757
*
754758
* Return: 0 on success, the proper error value otherwise.
755759
*/
756-
int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
757-
int trip,
758-
struct thermal_cooling_device *cdev)
760+
int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
761+
const struct thermal_trip *trip,
762+
struct thermal_cooling_device *cdev)
759763
{
760764
struct thermal_instance *pos, *next;
761765

@@ -783,6 +787,17 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
783787
kfree(pos);
784788
return 0;
785789
}
790+
EXPORT_SYMBOL_GPL(thermal_unbind_cdev_from_trip);
791+
792+
int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
793+
int trip_index,
794+
struct thermal_cooling_device *cdev)
795+
{
796+
if (trip_index < 0 || trip_index >= tz->num_trips)
797+
return -EINVAL;
798+
799+
return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index], cdev);
800+
}
786801
EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);
787802

788803
static void thermal_release(struct device *dev)
@@ -1231,7 +1246,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
12311246
struct thermal_zone_device *tz;
12321247
int id;
12331248
int result;
1234-
int count;
12351249
struct thermal_governor *governor;
12361250

12371251
if (!type || strlen(type) == 0) {
@@ -1328,14 +1342,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
13281342
if (result)
13291343
goto release_device;
13301344

1331-
for (count = 0; count < num_trips; count++) {
1332-
struct thermal_trip trip;
1333-
1334-
result = thermal_zone_get_trip(tz, count, &trip);
1335-
if (result || !trip.temperature)
1336-
set_bit(count, &tz->trips_disabled);
1337-
}
1338-
13391345
/* Update 'this' zone's governor information */
13401346
mutex_lock(&thermal_governor_lock);
13411347

drivers/thermal/thermal_core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct thermal_instance {
8787
char name[THERMAL_NAME_LENGTH];
8888
struct thermal_zone_device *tz;
8989
struct thermal_cooling_device *cdev;
90-
int trip;
90+
const struct thermal_trip *trip;
9191
bool initialized;
9292
unsigned long upper; /* Highest cooling state for this trip point */
9393
unsigned long lower; /* Lowest cooling state for this trip point */
@@ -119,6 +119,8 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
119119
void __thermal_zone_set_trips(struct thermal_zone_device *tz);
120120
int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
121121
struct thermal_trip *trip);
122+
int thermal_zone_trip_id(struct thermal_zone_device *tz,
123+
const struct thermal_trip *trip);
122124
int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
123125

124126
/* sysfs I/F */

drivers/thermal/thermal_helpers.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ int get_tz_trend(struct thermal_zone_device *tz, int trip_index)
4242

4343
struct thermal_instance *
4444
get_thermal_instance(struct thermal_zone_device *tz,
45-
struct thermal_cooling_device *cdev, int trip)
45+
struct thermal_cooling_device *cdev, int trip_index)
4646
{
4747
struct thermal_instance *pos = NULL;
4848
struct thermal_instance *target_instance = NULL;
49+
const struct thermal_trip *trip;
4950

5051
mutex_lock(&tz->lock);
5152
mutex_lock(&cdev->lock);
5253

54+
trip = &tz->trips[trip_index];
55+
5356
list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
5457
if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
5558
target_instance = pos;

drivers/thermal/thermal_sysfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ trip_point_show(struct device *dev, struct device_attribute *attr, char *buf)
943943
instance =
944944
container_of(attr, struct thermal_instance, attr);
945945

946-
return sprintf(buf, "%d\n", instance->trip);
946+
return sprintf(buf, "%d\n",
947+
thermal_zone_trip_id(instance->tz, instance->trip));
947948
}
948949

949950
ssize_t

drivers/thermal/thermal_trip.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ int for_each_thermal_trip(struct thermal_zone_device *tz,
1717

1818
lockdep_assert_held(&tz->lock);
1919

20-
if (!tz->trips)
21-
return -ENODATA;
22-
2320
for (i = 0; i < tz->num_trips; i++) {
2421
ret = cb(&tz->trips[i], data);
2522
if (ret)
@@ -160,3 +157,18 @@ int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id,
160157

161158
return 0;
162159
}
160+
161+
int thermal_zone_trip_id(struct thermal_zone_device *tz,
162+
const struct thermal_trip *trip)
163+
{
164+
int i;
165+
166+
lockdep_assert_held(&tz->lock);
167+
168+
for (i = 0; i < tz->num_trips; i++) {
169+
if (&tz->trips[i] == trip)
170+
return i;
171+
}
172+
173+
return -ENODATA;
174+
}

0 commit comments

Comments
 (0)