MLK-16372-1 thermal: imx_sc: add get_trend and set_trip_temp support
authorAnson Huang <Anson.Huang@nxp.com>
Tue, 5 Sep 2017 09:28:58 +0000 (17:28 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:38:29 +0000 (15:38 -0500)
Add get_trend and set_trip_temp callback to support
cpu-freq cooling function.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
drivers/thermal/imx_sc_thermal.c

index c956e42..ce9bf6d 100644 (file)
 #include <linux/thermal.h>
 #include <soc/imx8/sc/sci.h>
 
+#include "thermal_core.h"
+
 struct imx_sc_sensor {
        struct thermal_zone_device *tzd;
+       struct thermal_cooling_device *cdev;
        sc_rsrc_t hw_id;
+       int temp_passive;
+       int temp_critical;
 };
 
 struct imx_sc_tsens_device {
@@ -76,13 +81,41 @@ static int imx_sc_tsens_get_temp(void *data, int *temp)
 
 static int imx_sc_tsens_get_trend(void *p, int trip, enum thermal_trend *trend)
 {
+       int trip_temp;
+       struct imx_sc_sensor *sensor = p;
+
+       if (!sensor->tzd)
+               return 0;
+
+       trip_temp = (trip == IMX_TRIP_PASSIVE) ? sensor->temp_passive :
+                                            sensor->temp_critical;
+
+       if (sensor->tzd->temperature >= trip_temp)
+               *trend = THERMAL_TREND_RAISE_FULL;
+       else
+               *trend = THERMAL_TREND_DROP_FULL;
+
        return 0;
 }
 
+static int imx_sc_set_trip_temp(void *p, int trip,
+                            int temp)
+{
+       struct imx_sc_sensor *sensor = p;
+
+       if (trip == IMX_TRIP_CRITICAL)
+               sensor->temp_critical = temp;
+
+       if (trip == IMX_TRIP_PASSIVE)
+               sensor->temp_passive = temp;
+
+       return 0;
+}
 
 static const struct thermal_zone_of_device_ops imx_sc_tsens_ops = {
        .get_temp = imx_sc_tsens_get_temp,
        .get_trend = imx_sc_tsens_get_trend,
+       .set_trip_temp = imx_sc_set_trip_temp,
 };
 
 static const struct of_device_id imx_sc_tsens_table[] = {
@@ -98,6 +131,7 @@ static int imx_sc_tsens_probe(struct platform_device *pdev)
        struct device_node *np = pdev->dev.of_node;
        struct imx_sc_tsens_device *tsens_dev;
        struct imx_sc_sensor *sensor;
+       const struct thermal_trip *trip;
        struct thermal_zone_device *tzd;
        sc_err_t sciErr;
        uint32_t mu_id;
@@ -142,6 +176,9 @@ static int imx_sc_tsens_probe(struct platform_device *pdev)
                        goto failed;
                }
                sensor->tzd = tzd;
+               trip = of_thermal_get_trip_points(sensor->tzd);
+               sensor->temp_passive = trip[0].temperature;
+               sensor->temp_critical = trip[1].temperature;
        }
 
        return 0;