Thermal: Introduce multiple cooling states support
Zhang Rui [Tue, 26 Jun 2012 08:26:40 +0000 (16:26 +0800)]
This is because general active cooling devices, like fans,
may have multiple speeds, which can be mapped to different cooling states.

bug 1059470

Change-Id: Ibebf71a0faca1980269db48a40dc8bb7db0d2357
Signed-off-by: Joshua Primero <jprimero@nvidia.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl>
Reviewed-by: Valentin, Eduardo <eduardo.valentin@ti.com>
Reviewed-on: http://git-master/r/159960
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>

drivers/thermal/thermal_sys.c

index 7b1f9c2..25ec031 100644 (file)
@@ -1059,6 +1059,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
        enum thermal_trip_type trip_type;
        struct thermal_cooling_device_instance *instance;
        struct thermal_cooling_device *cdev;
+       unsigned long cur_state, max_state;
 
        mutex_lock(&tz->lock);
 
@@ -1098,10 +1099,17 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
                                cdev = instance->cdev;
 
+                               cdev->ops->get_cur_state(cdev, &cur_state);
+                               cdev->ops->get_max_state(cdev, &max_state);
+
                                if (temp >= trip_temp)
-                                       cdev->ops->set_cur_state(cdev, 1);
+                                       cur_state = cur_state < max_state ?
+                                               (cur_state + 1) : max_state;
                                else
-                                       cdev->ops->set_cur_state(cdev, 0);
+                                       cur_state = cur_state > 0 ?
+                                               (cur_state - 1) : 0;
+
+                               cdev->ops->set_cur_state(cdev, cur_state);
                        }
                        break;
                case THERMAL_TRIP_PASSIVE: