From 9d99842f99d847191ebd0c28469d2c70fcc5bf9e Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Tue, 26 Jun 2012 16:35:57 +0800 Subject: Thermal: set upper and lower limits set upper and lower limits when binding a thermal cooling device to a thermal zone device. Signed-off-by: Zhang Rui Reviewed-by: Rafael J. Wysocki Reviewed-by: Eduardo Valentin --- drivers/thermal/thermal_sys.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c index d78c6dc6b00..b04fe2c4b0d 100644 --- a/drivers/thermal/thermal_sys.c +++ b/drivers/thermal/thermal_sys.c @@ -315,8 +315,9 @@ passive_store(struct device *dev, struct device_attribute *attr, if (!strncmp("Processor", cdev->type, sizeof("Processor"))) thermal_zone_bind_cooling_device(tz, - THERMAL_TRIPS_NONE, - cdev); + THERMAL_TRIPS_NONE, cdev, + THERMAL_NO_LIMIT, + THERMAL_NO_LIMIT); } mutex_unlock(&thermal_list_lock); if (!tz->passive_delay) @@ -801,7 +802,8 @@ static void thermal_zone_device_check(struct work_struct *work) */ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, int trip, - struct thermal_cooling_device *cdev) + struct thermal_cooling_device *cdev, + unsigned long upper, unsigned long lower) { struct thermal_cooling_device_instance *dev; struct thermal_cooling_device_instance *pos; @@ -825,6 +827,15 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, if (tz != pos1 || cdev != pos2) return -EINVAL; + cdev->ops->get_max_state(cdev, &max_state); + + /* lower default 0, upper default max_state */ + lower = lower == THERMAL_NO_LIMIT ? 0 : lower; + upper = upper == THERMAL_NO_LIMIT ? max_state : upper; + + if (lower > upper || upper > max_state) + return -EINVAL; + dev = kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL); if (!dev) @@ -832,10 +843,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, dev->tz = tz; dev->cdev = cdev; dev->trip = trip; - - cdev->ops->get_max_state(cdev, &max_state); - dev->upper = max_state; - dev->lower = 0; + dev->upper = upper; + dev->lower = lower; result = get_idr(&tz->idr, &tz->lock, &dev->id); if (result) -- cgit v1.2.3