Merge remote-tracking branch 'spi/for-5.12' into spi-linus
[platform/kernel/linux-starfive.git] / drivers / thermal / thermal_helpers.c
index 7f50f41..3edd047 100644 (file)
@@ -192,18 +192,11 @@ static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
        thermal_cooling_device_stats_update(cdev, target);
 }
 
-void thermal_cdev_update(struct thermal_cooling_device *cdev)
+void __thermal_cdev_update(struct thermal_cooling_device *cdev)
 {
        struct thermal_instance *instance;
        unsigned long target = 0;
 
-       mutex_lock(&cdev->lock);
-       /* cooling device is updated*/
-       if (cdev->updated) {
-               mutex_unlock(&cdev->lock);
-               return;
-       }
-
        /* Make sure cdev enters the deepest cooling state */
        list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
                dev_dbg(&cdev->device, "zone%d->target=%lu\n",
@@ -216,11 +209,25 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
 
        thermal_cdev_set_cur_state(cdev, target);
 
-       cdev->updated = true;
-       mutex_unlock(&cdev->lock);
        trace_cdev_update(cdev, target);
        dev_dbg(&cdev->device, "set to state %lu\n", target);
 }
+
+/**
+ * thermal_cdev_update - update cooling device state if needed
+ * @cdev:      pointer to struct thermal_cooling_device
+ *
+ * Update the cooling device state if there is a need.
+ */
+void thermal_cdev_update(struct thermal_cooling_device *cdev)
+{
+       mutex_lock(&cdev->lock);
+       if (!cdev->updated) {
+               __thermal_cdev_update(cdev);
+               cdev->updated = true;
+       }
+       mutex_unlock(&cdev->lock);
+}
 EXPORT_SYMBOL(thermal_cdev_update);
 
 /**