Merge tag 'thermal-v6.4-rc1-1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel...
[platform/kernel/linux-starfive.git] / drivers / thermal / imx_thermal.c
index fb0d5ca..a94ec0a 100644 (file)
@@ -252,7 +252,7 @@ static void imx_set_alarm_temp(struct imx_thermal_data *data,
 
 static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
 {
-       struct imx_thermal_data *data = tz->devdata;
+       struct imx_thermal_data *data = thermal_zone_device_priv(tz);
        const struct thermal_soc_data *soc_data = data->socdata;
        struct regmap *map = data->tempmon;
        unsigned int n_meas;
@@ -265,10 +265,8 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
 
        regmap_read(map, soc_data->temp_data, &val);
 
-       if ((val & soc_data->temp_valid_mask) == 0) {
-               dev_dbg(&tz->device, "temp measurement never finished\n");
+       if ((val & soc_data->temp_valid_mask) == 0)
                return -EAGAIN;
-       }
 
        n_meas = (val & soc_data->temp_value_mask)
                >> soc_data->temp_value_shift;
@@ -287,13 +285,13 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
                if (data->alarm_temp == trips[IMX_TRIP_CRITICAL].temperature &&
                        *temp < trips[IMX_TRIP_PASSIVE].temperature) {
                        imx_set_alarm_temp(data, trips[IMX_TRIP_PASSIVE].temperature);
-                       dev_dbg(&tz->device, "thermal alarm off: T < %d\n",
+                       dev_dbg(data->dev, "thermal alarm off: T < %d\n",
                                data->alarm_temp / 1000);
                }
        }
 
        if (*temp != data->last_temp) {
-               dev_dbg(&tz->device, "millicelsius: %d\n", *temp);
+               dev_dbg(data->dev, "millicelsius: %d\n", *temp);
                data->last_temp = *temp;
        }
 
@@ -311,7 +309,7 @@ static int imx_get_temp(struct thermal_zone_device *tz, int *temp)
 static int imx_change_mode(struct thermal_zone_device *tz,
                           enum thermal_device_mode mode)
 {
-       struct imx_thermal_data *data = tz->devdata;
+       struct imx_thermal_data *data = thermal_zone_device_priv(tz);
 
        if (mode == THERMAL_DEVICE_ENABLED) {
                pm_runtime_get(data->dev);
@@ -332,33 +330,29 @@ static int imx_change_mode(struct thermal_zone_device *tz,
        return 0;
 }
 
-static int imx_get_crit_temp(struct thermal_zone_device *tz, int *temp)
-{
-       *temp = trips[IMX_TRIP_CRITICAL].temperature;
-
-       return 0;
-}
-
-static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
+static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id,
                             int temp)
 {
-       struct imx_thermal_data *data = tz->devdata;
+       struct imx_thermal_data *data = thermal_zone_device_priv(tz);
+       struct thermal_trip trip;
        int ret;
 
        ret = pm_runtime_resume_and_get(data->dev);
        if (ret < 0)
                return ret;
 
+       ret = __thermal_zone_get_trip(tz, trip_id, &trip);
+       if (ret)
+               return ret;
+
        /* do not allow changing critical threshold */
-       if (trip == IMX_TRIP_CRITICAL)
+       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)
                return -EINVAL;
 
-       trips[IMX_TRIP_PASSIVE].temperature = temp;
-
        imx_set_alarm_temp(data, temp);
 
        pm_runtime_put(data->dev);
@@ -369,36 +363,16 @@ static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip,
 static int imx_bind(struct thermal_zone_device *tz,
                    struct thermal_cooling_device *cdev)
 {
-       int ret;
-
-       ret = thermal_zone_bind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev,
-                                              THERMAL_NO_LIMIT,
-                                              THERMAL_NO_LIMIT,
-                                              THERMAL_WEIGHT_DEFAULT);
-       if (ret) {
-               dev_err(&tz->device,
-                       "binding zone %s with cdev %s failed:%d\n",
-                       tz->type, cdev->type, ret);
-               return ret;
-       }
-
-       return 0;
+       return thermal_zone_bind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev,
+                                               THERMAL_NO_LIMIT,
+                                               THERMAL_NO_LIMIT,
+                                               THERMAL_WEIGHT_DEFAULT);
 }
 
 static int imx_unbind(struct thermal_zone_device *tz,
                      struct thermal_cooling_device *cdev)
 {
-       int ret;
-
-       ret = thermal_zone_unbind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev);
-       if (ret) {
-               dev_err(&tz->device,
-                       "unbinding zone %s with cdev %s failed:%d\n",
-                       tz->type, cdev->type, ret);
-               return ret;
-       }
-
-       return 0;
+       return thermal_zone_unbind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev);
 }
 
 static struct thermal_zone_device_ops imx_tz_ops = {
@@ -406,7 +380,6 @@ static struct thermal_zone_device_ops imx_tz_ops = {
        .unbind = imx_unbind,
        .get_temp = imx_get_temp,
        .change_mode = imx_change_mode,
-       .get_crit_temp = imx_get_crit_temp,
        .set_trip_temp = imx_set_trip_temp,
 };
 
@@ -560,8 +533,7 @@ static irqreturn_t imx_thermal_alarm_irq_thread(int irq, void *dev)
 {
        struct imx_thermal_data *data = dev;
 
-       dev_dbg(&data->tz->device, "THERMAL ALARM: T > %d\n",
-               data->alarm_temp / 1000);
+       dev_dbg(data->dev, "THERMAL ALARM: T > %d\n", data->alarm_temp / 1000);
 
        thermal_zone_device_update(data->tz, THERMAL_EVENT_UNSPECIFIED);
 
@@ -594,7 +566,7 @@ static int imx_thermal_register_legacy_cooling(struct imx_thermal_data *data)
 
        np = of_get_cpu_node(data->policy->cpu, NULL);
 
-       if (!np || !of_find_property(np, "#cooling-cells", NULL)) {
+       if (!np || !of_property_present(np, "#cooling-cells")) {
                data->cdev = cpufreq_cooling_register(data->policy);
                if (IS_ERR(data->cdev)) {
                        ret = PTR_ERR(data->cdev);
@@ -671,7 +643,7 @@ static int imx_thermal_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, data);
 
-       if (of_find_property(pdev->dev.of_node, "nvmem-cells", NULL)) {
+       if (of_property_present(pdev->dev.of_node, "nvmem-cells")) {
                ret = imx_init_from_nvmem_cells(pdev);
                if (ret)
                        return dev_err_probe(&pdev->dev, ret,