[PATCH 3/3] thermal/drivers/imx: USe get_crit_temp() API instead of manual check

From: Daniel Lezcano
Date: Tue Jan 24 2023 - 08:53:58 EST


The thermal framework is reworked to use a generic trip point
description. That will consolidate the code and will allow to fix a
mishandling of the trip points crossed events.

In order self-encapsulate the thermal framework and prevent assumption
about the indexes we remove the trip id usage in the back end drivers.

As the i.MX driver is using the thermal trip generic structure, we can
rely on the thermal framework to get the critical temperature instead
of using the harcoded IMX_TRIP_CRITICAL index.

Signed-off-by: Daniel Lezcano <daniel.lezcano@xxxxxxxxxx>
---
drivers/thermal/imx_thermal.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index c115a696e83f..10ebf42f4915 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -337,7 +337,7 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id,
{
struct imx_thermal_data *data = tz->devdata;
struct thermal_trip trip;
- int ret;
+ int crit_temp, ret;

ret = pm_runtime_resume_and_get(data->dev);
if (ret < 0)
@@ -347,12 +347,16 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id,
if (ret)
return ret;

+ if (temp < 0)
+ return -EINVAL;
+
/* do not allow changing critical threshold */
if (trip.type == THERMAL_TRIP_CRITICAL)
return -EPERM;
-
+
/* do not allow passive to be set higher than critical */
- if (temp < 0 || temp > trips[IMX_TRIP_CRITICAL].temperature)
+ ret = thermal_zone_get_crit_temp(tz, &crit_temp);
+ if (!ret && (crit_temp < temp))
return -EINVAL;

imx_set_alarm_temp(data, temp);
--
2.34.1