Merge tag 'microblaze-v5.12' of git://git.monstr.eu/linux-2.6-microblaze
[linux-2.6-microblaze.git] / drivers / thermal / gov_power_allocator.c
index 7a4170a..92acae5 100644 (file)
@@ -258,7 +258,7 @@ static u32 pid_controller(struct thermal_zone_device *tz,
         * power being applied, slowing down the controller)
         */
        d = mul_frac(tz->tzp->k_d, err - params->prev_err);
-       d = div_frac(d, tz->passive_delay);
+       d = div_frac(d, jiffies_to_msecs(tz->passive_delay_jiffies));
        params->prev_err = err;
 
        power_range = p + i + d;
@@ -589,6 +589,34 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
        mutex_unlock(&tz->lock);
 }
 
+/**
+ * check_power_actors() - Check all cooling devices and warn when they are
+ *                     not power actors
+ * @tz:                thermal zone to operate on
+ *
+ * Check all cooling devices in the @tz and warn every time they are missing
+ * power actor API. The warning should help to investigate the issue, which
+ * could be e.g. lack of Energy Model for a given device.
+ *
+ * Return: 0 on success, -EINVAL if any cooling device does not implement
+ * the power actor API.
+ */
+static int check_power_actors(struct thermal_zone_device *tz)
+{
+       struct thermal_instance *instance;
+       int ret = 0;
+
+       list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
+               if (!cdev_is_power_actor(instance->cdev)) {
+                       dev_warn(&tz->device, "power_allocator: %s is not a power actor\n",
+                                instance->cdev->type);
+                       ret = -EINVAL;
+               }
+       }
+
+       return ret;
+}
+
 /**
  * power_allocator_bind() - bind the power_allocator governor to a thermal zone
  * @tz:        thermal zone to bind it to
@@ -596,7 +624,8 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
  * Initialize the PID controller parameters and bind it to the thermal
  * zone.
  *
- * Return: 0 on success, or -ENOMEM if we ran out of memory.
+ * Return: 0 on success, or -ENOMEM if we ran out of memory, or -EINVAL
+ * when there are unsupported cooling devices in the @tz.
  */
 static int power_allocator_bind(struct thermal_zone_device *tz)
 {
@@ -604,6 +633,10 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
        struct power_allocator_params *params;
        int control_temp;
 
+       ret = check_power_actors(tz);
+       if (ret)
+               return ret;
+
        params = kzalloc(sizeof(*params), GFP_KERNEL);
        if (!params)
                return -ENOMEM;