USB: fsl_udc_core: Fix kernel oops on module removal
[safe/jmp/linux-2.6] / drivers / thermal / thermal_sys.c
index 6378741..4e83c29 100644 (file)
@@ -214,9 +214,69 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
        return sprintf(buf, "%ld\n", temperature);
 }
 
+static ssize_t
+passive_store(struct device *dev, struct device_attribute *attr,
+                   const char *buf, size_t count)
+{
+       struct thermal_zone_device *tz = to_thermal_zone(dev);
+       struct thermal_cooling_device *cdev = NULL;
+       int state;
+
+       if (!sscanf(buf, "%d\n", &state))
+               return -EINVAL;
+
+       if (state && !tz->forced_passive) {
+               mutex_lock(&thermal_list_lock);
+               list_for_each_entry(cdev, &thermal_cdev_list, node) {
+                       if (!strncmp("Processor", cdev->type,
+                                    sizeof("Processor")))
+                               thermal_zone_bind_cooling_device(tz,
+                                                                THERMAL_TRIPS_NONE,
+                                                                cdev);
+               }
+               mutex_unlock(&thermal_list_lock);
+       } else if (!state && tz->forced_passive) {
+               mutex_lock(&thermal_list_lock);
+               list_for_each_entry(cdev, &thermal_cdev_list, node) {
+                       if (!strncmp("Processor", cdev->type,
+                                    sizeof("Processor")))
+                               thermal_zone_unbind_cooling_device(tz,
+                                                                  THERMAL_TRIPS_NONE,
+                                                                  cdev);
+               }
+               mutex_unlock(&thermal_list_lock);
+       }
+
+       tz->tc1 = 1;
+       tz->tc2 = 1;
+
+       if (!tz->passive_delay)
+               tz->passive_delay = 1000;
+
+       if (!tz->polling_delay)
+               tz->polling_delay = 10000;
+
+       tz->forced_passive = state;
+
+       thermal_zone_device_update(tz);
+
+       return count;
+}
+
+static ssize_t
+passive_show(struct device *dev, struct device_attribute *attr,
+                  char *buf)
+{
+       struct thermal_zone_device *tz = to_thermal_zone(dev);
+
+       return sprintf(buf, "%d\n", tz->forced_passive);
+}
+
 static DEVICE_ATTR(type, 0444, type_show, NULL);
 static DEVICE_ATTR(temp, 0444, temp_show, NULL);
 static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
+static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, \
+                  passive_store);
 
 static struct device_attribute trip_point_attrs[] = {
        __ATTR(trip_point_0_type, 0444, trip_point_type_show, NULL),
@@ -357,7 +417,7 @@ static LIST_HEAD(thermal_hwmon_list);
 static ssize_t
 name_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct thermal_hwmon_device *hwmon = dev->driver_data;
+       struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
        return sprintf(buf, "%s\n", hwmon->type);
 }
 static DEVICE_ATTR(name, 0444, name_show, NULL);
@@ -428,7 +488,7 @@ thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
                result = PTR_ERR(hwmon->device);
                goto free_mem;
        }
-       hwmon->device->driver_data = hwmon;
+       dev_set_drvdata(hwmon->device, hwmon);
        result = device_create_file(hwmon->device, &dev_attr_name);
        if (result)
                goto unregister_hwmon_device;
@@ -893,7 +953,12 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
        mutex_lock(&tz->lock);
 
-       tz->ops->get_temp(tz, &temp);
+       if (tz->ops->get_temp(tz, &temp)) {
+               /* get_temp failed - retry it later */
+               printk(KERN_WARNING PREFIX "failed to read out thermal zone "
+                      "%d\n", tz->id);
+               goto leave;
+       }
 
        for (count = 0; count < tz->trips; count++) {
                tz->ops->get_trip_type(tz, count, &trip_type);
@@ -901,7 +966,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
                switch (trip_type) {
                case THERMAL_TRIP_CRITICAL:
-                       if (temp > trip_temp) {
+                       if (temp >= trip_temp) {
                                if (tz->ops->notify)
                                        ret = tz->ops->notify(tz, count,
                                                              trip_type);
@@ -914,7 +979,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
                        }
                        break;
                case THERMAL_TRIP_HOT:
-                       if (temp > trip_temp)
+                       if (temp >= trip_temp)
                                if (tz->ops->notify)
                                        tz->ops->notify(tz, count, trip_type);
                        break;
@@ -926,20 +991,27 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
                                cdev = instance->cdev;
 
-                               if (temp > trip_temp)
+                               if (temp >= trip_temp)
                                        cdev->ops->set_cur_state(cdev, 1);
                                else
                                        cdev->ops->set_cur_state(cdev, 0);
                        }
                        break;
                case THERMAL_TRIP_PASSIVE:
-                       if (temp > trip_temp || tz->passive)
+                       if (temp >= trip_temp || tz->passive)
                                thermal_zone_device_passive(tz, temp,
                                                            trip_temp, count);
                        break;
                }
        }
+
+       if (tz->forced_passive)
+               thermal_zone_device_passive(tz, temp, tz->forced_passive,
+                                           THERMAL_TRIPS_NONE);
+
        tz->last_temperature = temp;
+
+      leave:
        if (tz->passive)
                thermal_zone_device_set_polling(tz, tz->passive_delay);
        else if (tz->polling_delay)
@@ -977,8 +1049,10 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
 {
        struct thermal_zone_device *tz;
        struct thermal_cooling_device *pos;
+       enum thermal_trip_type trip_type;
        int result;
        int count;
+       int passive = 0;
 
        if (strlen(type) >= THERMAL_NAME_LENGTH)
                return ERR_PTR(-EINVAL);
@@ -1041,8 +1115,18 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
                TRIP_POINT_ATTR_ADD(&tz->device, count, result);
                if (result)
                        goto unregister;
+               tz->ops->get_trip_type(tz, count, &trip_type);
+               if (trip_type == THERMAL_TRIP_PASSIVE)
+                       passive = 1;
        }
 
+       if (!passive)
+               result = device_create_file(&tz->device,
+                                           &dev_attr_passive);
+
+       if (result)
+               goto unregister;
+
        result = thermal_add_hwmon_sysfs(tz);
        if (result)
                goto unregister;