Skip to contentSkip to conversation

thermal: core: Rework .get_trend() thermal zone callback

PATCH New Rafael J. Wysocki 1 participant 1 message Aug 22, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: core: Rework .get_trend() thermal zone callback

From: Rafael J. Wysocki <[email protected]>

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.

---

This is based on the thermal branch in linux-pm.git (which is also included in the linux-next branch of that tree).

---
 drivers/acpi/thermal.c                             |   41 +++++++++------------
 drivers/thermal/thermal_core.h                     |    2 -
 drivers/thermal/thermal_helpers.c                  |    3 +
 drivers/thermal/ti-soc-thermal/ti-thermal-common.c |    3 +
 include/linux/thermal.h                            |   30 +++++++--------
 5 files changed, 38 insertions(+), 41 deletions(-)
include/linux/thermal.h +15 -15
Index: linux-pm/include/linux/thermal.h
===================================================================
@@ -53,6 +53,20 @@ enum thermal_notify_event {
 	THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */
 };
 
+/**
+ * struct thermal_trip - representation of a point in temperature domain
+ * @temperature: temperature value in miliCelsius
+ * @hysteresis: relative hysteresis in miliCelsius
+ * @type: trip point type
+ * @priv: pointer to driver data associated with this trip
+ */
+struct thermal_trip {
+	int temperature;
+	int hysteresis;
+	enum thermal_trip_type type;
+	void *priv;
+};
+
 struct thermal_zone_device_ops {
 	int (*bind) (struct thermal_zone_device *,
 		     struct thermal_cooling_device *);
@@ -70,26 +84,12 @@ struct thermal_zone_device_ops {
 	int (*set_trip_hyst) (struct thermal_zone_device *, int, int);
 	int (*get_crit_temp) (struct thermal_zone_device *, int *);
 	int (*set_emul_temp) (struct thermal_zone_device *, int);
-	int (*get_trend) (struct thermal_zone_device *, int,
+	int (*get_trend) (struct thermal_zone_device *, struct thermal_trip *,
 			  enum thermal_trend *);
 	void (*hot)(struct thermal_zone_device *);
 	void (*critical)(struct thermal_zone_device *);
 };
 
-/**
- * struct thermal_trip - representation of a point in temperature domain
- * @temperature: temperature value in miliCelsius
- * @hysteresis: relative hysteresis in miliCelsius
- * @type: trip point type
- * @priv: pointer to driver data associated with this trip
- */
-struct thermal_trip {
-	int temperature;
-	int hysteresis;
-	enum thermal_trip_type type;
-	void *priv;
-};
-
 struct thermal_cooling_device_ops {
 	int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
 	int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
drivers/acpi/thermal.c +18 -23

63 lines not on this page · raw message

drivers/thermal/thermal_core.h +1 -1
Index: linux-pm/drivers/thermal/thermal_core.h
===================================================================
@@ -70,7 +70,7 @@ static inline bool cdev_is_power_actor(s
 void thermal_cdev_update(struct thermal_cooling_device *);
 void __thermal_cdev_update(struct thermal_cooling_device *cdev);
 
-int get_tz_trend(struct thermal_zone_device *tz, int trip);
+int get_tz_trend(struct thermal_zone_device *tz, int trip_index);
 
 struct thermal_instance *
 get_thermal_instance(struct thermal_zone_device *tz,
drivers/thermal/thermal_helpers.c +2 -1
Index: linux-pm/drivers/thermal/thermal_helpers.c
===================================================================
@@ -22,8 +22,9 @@
 #include "thermal_core.h"
 #include "thermal_trace.h"
 
-int get_tz_trend(struct thermal_zone_device *tz, int trip)
+int get_tz_trend(struct thermal_zone_device *tz, int trip_index)
 {
+	struct thermal_trip *trip = tz->trips ? &tz->trips[trip_index] : NULL;
 	enum thermal_trend trend;
 
 	if (tz->emul_temperature || !tz->ops->get_trend ||
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +2 -1
Index: linux-pm/drivers/thermal/ti-soc-thermal/ti-thermal-common.c
===================================================================
@@ -109,7 +109,8 @@ static inline int __ti_thermal_get_temp(
 	return ret;
 }
 
-static int __ti_thermal_get_trend(struct thermal_zone_device *tz, int trip, enum thermal_trend *trend)
+static int __ti_thermal_get_trend(struct thermal_zone_device *tz,
+				  struct thermal_trip *trip, enum thermal_trend *trend)
 {
 	struct ti_thermal_data *data = thermal_zone_device_priv(tz);
 	struct ti_bandgap *bgp;