thermal: of: fix cooling device weights in device tree
authorKapileshwar Singh <kapileshwar.singh@arm.com>
Wed, 18 Feb 2015 16:04:21 +0000 (16:04 +0000)
committerEduardo Valentin <edubezval@gmail.com>
Tue, 5 May 2015 04:27:50 +0000 (21:27 -0700)
Currently you can specify the weight of the cooling device in the device
tree but that information is not populated to the
thermal_bind_params where the fair share governor expects it to
be.  The of thermal zone device doesn't have a thermal_bind_params
structure and arguably it's better to pass the weight inside the
thermal_instance as it is specific to the bind of a cooling device to a
thermal zone parameter.

Core thermal code is fixed to populate the weight in the instance from
the thermal_bind_params, so platform code that was passing the weight
inside the thermal_bind_params continue to work seamlessly.

While we are at it, create a default value for the weight parameter for
those thermal zones that currently don't define it and remove the
hardcoded default in of-thermal.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Len Brown <lenb@kernel.org>
Cc: Peter Feuerer <peter@piie.net>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Eduardo Valentin <edubezval@gmail.com>
Cc: Kukjin Kim <kgene@kernel.org>
Cc: Durgadoss R <durgadoss.r@intel.com>
Signed-off-by: Kapileshwar Singh <kapileshwar.singh@arm.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Documentation/thermal/sysfs-api.txt
drivers/acpi/thermal.c
drivers/platform/x86/acerhdf.c
drivers/thermal/db8500_thermal.c
drivers/thermal/fair_share.c
drivers/thermal/imx_thermal.c
drivers/thermal/of-thermal.c
drivers/thermal/thermal_core.c
drivers/thermal/thermal_core.h
drivers/thermal/ti-soc-thermal/ti-thermal-common.c
include/linux/thermal.h

index 87519cb379ee45ade675499949ae91bf1051725d..7ec632ed976911d09bd564ddfbde51acafb2f6ee 100644 (file)
@@ -95,7 +95,7 @@ temperature) and throttle appropriate devices.
 1.3 interface for binding a thermal zone device with a thermal cooling device
 1.3.1 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
        int trip, struct thermal_cooling_device *cdev,
-       unsigned long upper, unsigned long lower);
+       unsigned long upper, unsigned long lower, unsigned int weight);
 
     This interface function bind a thermal cooling device to the certain trip
     point of a thermal zone device.
@@ -110,6 +110,8 @@ temperature) and throttle appropriate devices.
     lower:the Minimum cooling state can be used for this trip point.
           THERMAL_NO_LIMIT means no lower limit,
          and the cooling device can be in cooling state 0.
+    weight: the influence of this cooling device in this thermal
+            zone.  See 1.4.1 below for more information.
 
 1.3.2 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
                int trip, struct thermal_cooling_device *cdev);
index d24fa1964eb8ff1e6195610f9e258cdd00f22b6c..6d4e44ea74acc8bff38f8be0aa7682f3d9560e3c 100644 (file)
@@ -800,7 +800,8 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
                                result =
                                        thermal_zone_bind_cooling_device
                                        (thermal, trip, cdev,
-                                        THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
+                                        THERMAL_NO_LIMIT, THERMAL_NO_LIMIT,
+                                        THERMAL_WEIGHT_DEFAULT);
                        else
                                result =
                                        thermal_zone_unbind_cooling_device
@@ -824,7 +825,8 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
                        if (bind)
                                result = thermal_zone_bind_cooling_device
                                        (thermal, trip, cdev,
-                                        THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
+                                        THERMAL_NO_LIMIT, THERMAL_NO_LIMIT,
+                                        THERMAL_WEIGHT_DEFAULT);
                        else
                                result = thermal_zone_unbind_cooling_device
                                        (thermal, trip, cdev);
@@ -841,7 +843,8 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
                                result = thermal_zone_bind_cooling_device
                                                (thermal, THERMAL_TRIPS_NONE,
                                                 cdev, THERMAL_NO_LIMIT,
-                                                THERMAL_NO_LIMIT);
+                                                THERMAL_NO_LIMIT,
+                                                THERMAL_WEIGHT_DEFAULT);
                        else
                                result = thermal_zone_unbind_cooling_device
                                                (thermal, THERMAL_TRIPS_NONE,
index 594c918b553d382fa06519d83a51274894644693..1ef02daddb60b81aeba3e627d0c7da5870d5248b 100644 (file)
@@ -372,7 +372,8 @@ static int acerhdf_bind(struct thermal_zone_device *thermal,
                return 0;
 
        if (thermal_zone_bind_cooling_device(thermal, 0, cdev,
-                       THERMAL_NO_LIMIT, THERMAL_NO_LIMIT)) {
+                       THERMAL_NO_LIMIT, THERMAL_NO_LIMIT,
+                       THERMAL_WEIGHT_DEFAULT)) {
                pr_err("error binding cooling dev\n");
                return -EINVAL;
        }
index 20adfbe27df1748bc00e5563cce12828973c8881..2fb273c4baa95b5583052102d793d8b9d288ad44 100644 (file)
@@ -76,7 +76,7 @@ static int db8500_cdev_bind(struct thermal_zone_device *thermal,
                upper = lower = i > max_state ? max_state : i;
 
                ret = thermal_zone_bind_cooling_device(thermal, i, cdev,
-                       upper, lower);
+                       upper, lower, THERMAL_WEIGHT_DEFAULT);
 
                dev_info(&cdev->device, "%s bind to %d: %d-%s\n", cdev->type,
                        i, ret, ret ? "fail" : "succeed");
index 6e0a3fbfae867f9ebab079a2d485677222a3e349..c3b25187b467556412b0b07bb4f5ab59ff7d6fe5 100644 (file)
@@ -109,7 +109,7 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
                        continue;
 
                instance->target = get_target_state(tz, cdev,
-                                       tzp->tbp[i].weight, cur_trip_level);
+                                       instance->weight, cur_trip_level);
 
                instance->cdev->updated = false;
                thermal_cdev_update(cdev);
index 2ccbc0788353e9488e3f730de80d52ecafaf9082..fde4c2876d14612c2c3bef5fb0ed55fe78ea216c 100644 (file)
@@ -306,7 +306,8 @@ static int imx_bind(struct thermal_zone_device *tz,
 
        ret = thermal_zone_bind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev,
                                               THERMAL_NO_LIMIT,
-                                              THERMAL_NO_LIMIT);
+                                              THERMAL_NO_LIMIT,
+                                              THERMAL_WEIGHT_DEFAULT);
        if (ret) {
                dev_err(&tz->device,
                        "binding zone %s with cdev %s failed:%d\n",
index 668fb1bdea9eff9b0443453430f1de92335c4104..c606b85ea9f47bf08370db605625049f6750c8e1 100644 (file)
@@ -227,7 +227,8 @@ static int of_thermal_bind(struct thermal_zone_device *thermal,
                        ret = thermal_zone_bind_cooling_device(thermal,
                                                tbp->trip_id, cdev,
                                                tbp->max,
-                                               tbp->min);
+                                               tbp->min,
+                                               tbp->usage);
                        if (ret)
                                return ret;
                }
@@ -581,7 +582,7 @@ static int thermal_of_populate_bind_params(struct device_node *np,
        u32 prop;
 
        /* Default weight. Usage is optional */
-       __tbp->usage = 0;
+       __tbp->usage = THERMAL_WEIGHT_DEFAULT;
        ret = of_property_read_u32(np, "contribution", &prop);
        if (ret == 0)
                __tbp->usage = prop;
index 4108db7e10c1094622d4abca08017db3125cf80e..a6cb9b78b6293bc7725e5859571d5528c3a7ef97 100644 (file)
@@ -218,7 +218,8 @@ static void print_bind_err_msg(struct thermal_zone_device *tz,
 
 static void __bind(struct thermal_zone_device *tz, int mask,
                        struct thermal_cooling_device *cdev,
-                       unsigned long *limits)
+                       unsigned long *limits,
+                       unsigned int weight)
 {
        int i, ret;
 
@@ -233,7 +234,8 @@ static void __bind(struct thermal_zone_device *tz, int mask,
                                upper = limits[i * 2 + 1];
                        }
                        ret = thermal_zone_bind_cooling_device(tz, i, cdev,
-                                                              upper, lower);
+                                                              upper, lower,
+                                                              weight);
                        if (ret)
                                print_bind_err_msg(tz, cdev, ret);
                }
@@ -280,7 +282,8 @@ static void bind_cdev(struct thermal_cooling_device *cdev)
                                continue;
                        tzp->tbp[i].cdev = cdev;
                        __bind(pos, tzp->tbp[i].trip_mask, cdev,
-                              tzp->tbp[i].binding_limits);
+                              tzp->tbp[i].binding_limits,
+                              tzp->tbp[i].weight);
                }
        }
 
@@ -319,7 +322,8 @@ static void bind_tz(struct thermal_zone_device *tz)
                                continue;
                        tzp->tbp[i].cdev = pos;
                        __bind(tz, tzp->tbp[i].trip_mask, pos,
-                              tzp->tbp[i].binding_limits);
+                              tzp->tbp[i].binding_limits,
+                              tzp->tbp[i].weight);
                }
        }
 exit:
@@ -713,7 +717,8 @@ passive_store(struct device *dev, struct device_attribute *attr,
                                thermal_zone_bind_cooling_device(tz,
                                                THERMAL_TRIPS_NONE, cdev,
                                                THERMAL_NO_LIMIT,
-                                               THERMAL_NO_LIMIT);
+                                               THERMAL_NO_LIMIT,
+                                               THERMAL_WEIGHT_DEFAULT);
                }
                mutex_unlock(&thermal_list_lock);
                if (!tz->passive_delay)
@@ -931,6 +936,9 @@ static const struct attribute_group *cooling_device_attr_groups[] = {
  * @lower:     the Minimum cooling state can be used for this trip point.
  *             THERMAL_NO_LIMIT means no lower limit,
  *             and the cooling device can be in cooling state 0.
+ * @weight:    The weight of the cooling device to be bound to the
+ *             thermal zone. Use THERMAL_WEIGHT_DEFAULT for the
+ *             default value
  *
  * This interface function bind a thermal cooling device to the certain trip
  * point of a thermal zone device.
@@ -941,7 +949,8 @@ static const struct attribute_group *cooling_device_attr_groups[] = {
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
                                     int trip,
                                     struct thermal_cooling_device *cdev,
-                                    unsigned long upper, unsigned long lower)
+                                    unsigned long upper, unsigned long lower,
+                                    unsigned int weight)
 {
        struct thermal_instance *dev;
        struct thermal_instance *pos;
@@ -986,6 +995,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
        dev->upper = upper;
        dev->lower = lower;
        dev->target = THERMAL_NO_TARGET;
+       dev->weight = weight;
 
        result = get_idr(&tz->idr, &tz->lock, &dev->id);
        if (result)
index 0531c752fbbb6680c40e939ad2a14fdc1830f357..7a465e9d456c84d7e1734379759025f271dd54b9 100644 (file)
@@ -48,6 +48,7 @@ struct thermal_instance {
        struct device_attribute attr;
        struct list_head tz_node; /* node in tz->thermal_instances */
        struct list_head cdev_node; /* node in cdev->thermal_instances */
+       unsigned int weight; /* The weight of the cooling device */
 };
 
 int thermal_register_governor(struct thermal_governor *);
index a38c1756442aa2611e0e207466aabba4e72b94cc..cb45e729adb55901472800f11c83e185406d2210 100644 (file)
@@ -146,7 +146,8 @@ static int ti_thermal_bind(struct thermal_zone_device *thermal,
        return thermal_zone_bind_cooling_device(thermal, 0, cdev,
        /* bind with min and max states defined by cpu_cooling */
                                                THERMAL_NO_LIMIT,
-                                               THERMAL_NO_LIMIT);
+                                               THERMAL_NO_LIMIT,
+                                               THERMAL_WEIGHT_DEFAULT);
 }
 
 /* Unbind callback functions for thermal zone */
index 5eac316490eab9ca0ad1a864be2b6fedb823f332..00dacd4dfdce54998c210bc4f807d268d6a2aa69 100644 (file)
@@ -40,6 +40,9 @@
 /* No upper/lower limit requirement */
 #define THERMAL_NO_LIMIT       ((u32)~0)
 
+/* Default weight of a bound cooling device */
+#define THERMAL_WEIGHT_DEFAULT 0
+
 /* Unit conversion macros */
 #define KELVIN_TO_CELSIUS(t)   (long)(((long)t-2732 >= 0) ?    \
                                ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
@@ -323,7 +326,8 @@ void thermal_zone_device_unregister(struct thermal_zone_device *);
 
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
                                     struct thermal_cooling_device *,
-                                    unsigned long, unsigned long);
+                                    unsigned long, unsigned long,
+                                    unsigned int);
 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
                                       struct thermal_cooling_device *);
 void thermal_zone_device_update(struct thermal_zone_device *);