Skip to content

Commit 8289d81

Browse files
committed
thermal: core: Rework .get_trend() thermal zone callback
Passing a struct thermal_trip pointer instead of a trip index to the .get_trend() thermal zone callback allows one of its 2 implementations, the thermal_get_trend() function in the ACPI thermal driver, to be simplified quite a bit, and the other implementation of it in the ti-soc-thermal driver does not even use the relevant callback argument. For this reason, change the .get_trend() thermal zone callback definition and adjust the related code accordingly. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 35d8dbb commit 8289d81

File tree

5 files changed

+38
-41
lines changed

5 files changed

+38
-41
lines changed

drivers/acpi/thermal.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -492,26 +492,22 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp)
492492
}
493493

494494
static int thermal_get_trend(struct thermal_zone_device *thermal,
495-
int trip_index, enum thermal_trend *trend)
495+
struct thermal_trip *trip,
496+
enum thermal_trend *trend)
496497
{
497498
struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
498499
struct acpi_thermal_trip *acpi_trip;
499-
int t, i;
500+
int t;
500501

501-
if (!tz || trip_index < 0)
502+
if (!tz || !trip)
502503
return -EINVAL;
503504

504-
if (tz->trips.critical.valid)
505-
trip_index--;
506-
507-
if (tz->trips.hot.valid)
508-
trip_index--;
509-
510-
if (trip_index < 0)
505+
acpi_trip = trip->priv;
506+
if (!acpi_trip || !acpi_trip->valid)
511507
return -EINVAL;
512508

513-
acpi_trip = &tz->trips.passive.trip;
514-
if (acpi_trip->valid && !trip_index--) {
509+
switch (trip->type) {
510+
case THERMAL_TRIP_PASSIVE:
515511
t = tz->trips.passive.tc1 * (tz->temperature -
516512
tz->last_temperature) +
517513
tz->trips.passive.tc2 * (tz->temperature -
@@ -524,19 +520,18 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
524520
*trend = THERMAL_TREND_STABLE;
525521

526522
return 0;
527-
}
528-
529-
t = acpi_thermal_temp(tz, tz->temperature);
530523

531-
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
532-
acpi_trip = &tz->trips.active[i].trip;
533-
if (acpi_trip->valid && !trip_index--) {
534-
if (t > acpi_thermal_temp(tz, acpi_trip->temperature)) {
535-
*trend = THERMAL_TREND_RAISING;
536-
return 0;
537-
}
524+
case THERMAL_TRIP_ACTIVE:
525+
t = acpi_thermal_temp(tz, tz->temperature);
526+
if (t <= trip->temperature)
538527
break;
539-
}
528+
529+
*trend = THERMAL_TREND_RAISING;
530+
531+
return 0;
532+
533+
default:
534+
break;
540535
}
541536

542537
return -EINVAL;

drivers/thermal/thermal_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
7070
void thermal_cdev_update(struct thermal_cooling_device *);
7171
void __thermal_cdev_update(struct thermal_cooling_device *cdev);
7272

73-
int get_tz_trend(struct thermal_zone_device *tz, int trip);
73+
int get_tz_trend(struct thermal_zone_device *tz, int trip_index);
7474

7575
struct thermal_instance *
7676
get_thermal_instance(struct thermal_zone_device *tz,

drivers/thermal/thermal_helpers.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
#include "thermal_core.h"
2323
#include "thermal_trace.h"
2424

25-
int get_tz_trend(struct thermal_zone_device *tz, int trip)
25+
int get_tz_trend(struct thermal_zone_device *tz, int trip_index)
2626
{
27+
struct thermal_trip *trip = tz->trips ? &tz->trips[trip_index] : NULL;
2728
enum thermal_trend trend;
2829

2930
if (tz->emul_temperature || !tz->ops->get_trend ||

drivers/thermal/ti-soc-thermal/ti-thermal-common.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ static inline int __ti_thermal_get_temp(struct thermal_zone_device *tz, int *tem
109109
return ret;
110110
}
111111

112-
static int __ti_thermal_get_trend(struct thermal_zone_device *tz, int trip, enum thermal_trend *trend)
112+
static int __ti_thermal_get_trend(struct thermal_zone_device *tz,
113+
struct thermal_trip *trip, enum thermal_trend *trend)
113114
{
114115
struct ti_thermal_data *data = thermal_zone_device_priv(tz);
115116
struct ti_bandgap *bgp;

include/linux/thermal.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ enum thermal_notify_event {
5353
THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */
5454
};
5555

56+
/**
57+
* struct thermal_trip - representation of a point in temperature domain
58+
* @temperature: temperature value in miliCelsius
59+
* @hysteresis: relative hysteresis in miliCelsius
60+
* @type: trip point type
61+
* @priv: pointer to driver data associated with this trip
62+
*/
63+
struct thermal_trip {
64+
int temperature;
65+
int hysteresis;
66+
enum thermal_trip_type type;
67+
void *priv;
68+
};
69+
5670
struct thermal_zone_device_ops {
5771
int (*bind) (struct thermal_zone_device *,
5872
struct thermal_cooling_device *);
@@ -66,26 +80,12 @@ struct thermal_zone_device_ops {
6680
int (*set_trip_hyst) (struct thermal_zone_device *, int, int);
6781
int (*get_crit_temp) (struct thermal_zone_device *, int *);
6882
int (*set_emul_temp) (struct thermal_zone_device *, int);
69-
int (*get_trend) (struct thermal_zone_device *, int,
83+
int (*get_trend) (struct thermal_zone_device *, struct thermal_trip *,
7084
enum thermal_trend *);
7185
void (*hot)(struct thermal_zone_device *);
7286
void (*critical)(struct thermal_zone_device *);
7387
};
7488

75-
/**
76-
* struct thermal_trip - representation of a point in temperature domain
77-
* @temperature: temperature value in miliCelsius
78-
* @hysteresis: relative hysteresis in miliCelsius
79-
* @type: trip point type
80-
* @priv: pointer to driver data associated with this trip
81-
*/
82-
struct thermal_trip {
83-
int temperature;
84-
int hysteresis;
85-
enum thermal_trip_type type;
86-
void *priv;
87-
};
88-
8989
struct thermal_cooling_device_ops {
9090
int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
9191
int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);

0 commit comments

Comments
 (0)