Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal: of: fix cooling device weights in device tree

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>

authored by

Kapileshwar Singh and committed by
Eduardo Valentin
6cd9e9f6 5ebe6afa

+42 -18
+3 -1
Documentation/thermal/sysfs-api.txt
··· 95 95 1.3 interface for binding a thermal zone device with a thermal cooling device 96 96 1.3.1 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, 97 97 int trip, struct thermal_cooling_device *cdev, 98 - unsigned long upper, unsigned long lower); 98 + unsigned long upper, unsigned long lower, unsigned int weight); 99 99 100 100 This interface function bind a thermal cooling device to the certain trip 101 101 point of a thermal zone device. ··· 110 110 lower:the Minimum cooling state can be used for this trip point. 111 111 THERMAL_NO_LIMIT means no lower limit, 112 112 and the cooling device can be in cooling state 0. 113 + weight: the influence of this cooling device in this thermal 114 + zone. See 1.4.1 below for more information. 113 115 114 116 1.3.2 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, 115 117 int trip, struct thermal_cooling_device *cdev);
+6 -3
drivers/acpi/thermal.c
··· 800 800 result = 801 801 thermal_zone_bind_cooling_device 802 802 (thermal, trip, cdev, 803 - THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); 803 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT, 804 + THERMAL_WEIGHT_DEFAULT); 804 805 else 805 806 result = 806 807 thermal_zone_unbind_cooling_device ··· 825 824 if (bind) 826 825 result = thermal_zone_bind_cooling_device 827 826 (thermal, trip, cdev, 828 - THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); 827 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT, 828 + THERMAL_WEIGHT_DEFAULT); 829 829 else 830 830 result = thermal_zone_unbind_cooling_device 831 831 (thermal, trip, cdev); ··· 843 841 result = thermal_zone_bind_cooling_device 844 842 (thermal, THERMAL_TRIPS_NONE, 845 843 cdev, THERMAL_NO_LIMIT, 846 - THERMAL_NO_LIMIT); 844 + THERMAL_NO_LIMIT, 845 + THERMAL_WEIGHT_DEFAULT); 847 846 else 848 847 result = thermal_zone_unbind_cooling_device 849 848 (thermal, THERMAL_TRIPS_NONE,
+2 -1
drivers/platform/x86/acerhdf.c
··· 372 372 return 0; 373 373 374 374 if (thermal_zone_bind_cooling_device(thermal, 0, cdev, 375 - THERMAL_NO_LIMIT, THERMAL_NO_LIMIT)) { 375 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT, 376 + THERMAL_WEIGHT_DEFAULT)) { 376 377 pr_err("error binding cooling dev\n"); 377 378 return -EINVAL; 378 379 }
+1 -1
drivers/thermal/db8500_thermal.c
··· 76 76 upper = lower = i > max_state ? max_state : i; 77 77 78 78 ret = thermal_zone_bind_cooling_device(thermal, i, cdev, 79 - upper, lower); 79 + upper, lower, THERMAL_WEIGHT_DEFAULT); 80 80 81 81 dev_info(&cdev->device, "%s bind to %d: %d-%s\n", cdev->type, 82 82 i, ret, ret ? "fail" : "succeed");
+1 -1
drivers/thermal/fair_share.c
··· 109 109 continue; 110 110 111 111 instance->target = get_target_state(tz, cdev, 112 - tzp->tbp[i].weight, cur_trip_level); 112 + instance->weight, cur_trip_level); 113 113 114 114 instance->cdev->updated = false; 115 115 thermal_cdev_update(cdev);
+2 -1
drivers/thermal/imx_thermal.c
··· 306 306 307 307 ret = thermal_zone_bind_cooling_device(tz, IMX_TRIP_PASSIVE, cdev, 308 308 THERMAL_NO_LIMIT, 309 - THERMAL_NO_LIMIT); 309 + THERMAL_NO_LIMIT, 310 + THERMAL_WEIGHT_DEFAULT); 310 311 if (ret) { 311 312 dev_err(&tz->device, 312 313 "binding zone %s with cdev %s failed:%d\n",
+3 -2
drivers/thermal/of-thermal.c
··· 227 227 ret = thermal_zone_bind_cooling_device(thermal, 228 228 tbp->trip_id, cdev, 229 229 tbp->max, 230 - tbp->min); 230 + tbp->min, 231 + tbp->usage); 231 232 if (ret) 232 233 return ret; 233 234 } ··· 582 581 u32 prop; 583 582 584 583 /* Default weight. Usage is optional */ 585 - __tbp->usage = 0; 584 + __tbp->usage = THERMAL_WEIGHT_DEFAULT; 586 585 ret = of_property_read_u32(np, "contribution", &prop); 587 586 if (ret == 0) 588 587 __tbp->usage = prop;
+16 -6
drivers/thermal/thermal_core.c
··· 218 218 219 219 static void __bind(struct thermal_zone_device *tz, int mask, 220 220 struct thermal_cooling_device *cdev, 221 - unsigned long *limits) 221 + unsigned long *limits, 222 + unsigned int weight) 222 223 { 223 224 int i, ret; 224 225 ··· 234 233 upper = limits[i * 2 + 1]; 235 234 } 236 235 ret = thermal_zone_bind_cooling_device(tz, i, cdev, 237 - upper, lower); 236 + upper, lower, 237 + weight); 238 238 if (ret) 239 239 print_bind_err_msg(tz, cdev, ret); 240 240 } ··· 282 280 continue; 283 281 tzp->tbp[i].cdev = cdev; 284 282 __bind(pos, tzp->tbp[i].trip_mask, cdev, 285 - tzp->tbp[i].binding_limits); 283 + tzp->tbp[i].binding_limits, 284 + tzp->tbp[i].weight); 286 285 } 287 286 } 288 287 ··· 322 319 continue; 323 320 tzp->tbp[i].cdev = pos; 324 321 __bind(tz, tzp->tbp[i].trip_mask, pos, 325 - tzp->tbp[i].binding_limits); 322 + tzp->tbp[i].binding_limits, 323 + tzp->tbp[i].weight); 326 324 } 327 325 } 328 326 exit: ··· 717 713 thermal_zone_bind_cooling_device(tz, 718 714 THERMAL_TRIPS_NONE, cdev, 719 715 THERMAL_NO_LIMIT, 720 - THERMAL_NO_LIMIT); 716 + THERMAL_NO_LIMIT, 717 + THERMAL_WEIGHT_DEFAULT); 721 718 } 722 719 mutex_unlock(&thermal_list_lock); 723 720 if (!tz->passive_delay) ··· 936 931 * @lower: the Minimum cooling state can be used for this trip point. 937 932 * THERMAL_NO_LIMIT means no lower limit, 938 933 * and the cooling device can be in cooling state 0. 934 + * @weight: The weight of the cooling device to be bound to the 935 + * thermal zone. Use THERMAL_WEIGHT_DEFAULT for the 936 + * default value 939 937 * 940 938 * This interface function bind a thermal cooling device to the certain trip 941 939 * point of a thermal zone device. ··· 949 941 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, 950 942 int trip, 951 943 struct thermal_cooling_device *cdev, 952 - unsigned long upper, unsigned long lower) 944 + unsigned long upper, unsigned long lower, 945 + unsigned int weight) 953 946 { 954 947 struct thermal_instance *dev; 955 948 struct thermal_instance *pos; ··· 995 986 dev->upper = upper; 996 987 dev->lower = lower; 997 988 dev->target = THERMAL_NO_TARGET; 989 + dev->weight = weight; 998 990 999 991 result = get_idr(&tz->idr, &tz->lock, &dev->id); 1000 992 if (result)
+1
drivers/thermal/thermal_core.h
··· 48 48 struct device_attribute attr; 49 49 struct list_head tz_node; /* node in tz->thermal_instances */ 50 50 struct list_head cdev_node; /* node in cdev->thermal_instances */ 51 + unsigned int weight; /* The weight of the cooling device */ 51 52 }; 52 53 53 54 int thermal_register_governor(struct thermal_governor *);
+2 -1
drivers/thermal/ti-soc-thermal/ti-thermal-common.c
··· 146 146 return thermal_zone_bind_cooling_device(thermal, 0, cdev, 147 147 /* bind with min and max states defined by cpu_cooling */ 148 148 THERMAL_NO_LIMIT, 149 - THERMAL_NO_LIMIT); 149 + THERMAL_NO_LIMIT, 150 + THERMAL_WEIGHT_DEFAULT); 150 151 } 151 152 152 153 /* Unbind callback functions for thermal zone */
+5 -1
include/linux/thermal.h
··· 40 40 /* No upper/lower limit requirement */ 41 41 #define THERMAL_NO_LIMIT ((u32)~0) 42 42 43 + /* Default weight of a bound cooling device */ 44 + #define THERMAL_WEIGHT_DEFAULT 0 45 + 43 46 /* Unit conversion macros */ 44 47 #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \ 45 48 ((long)t-2732+5)/10 : ((long)t-2732-5)/10) ··· 326 323 327 324 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, 328 325 struct thermal_cooling_device *, 329 - unsigned long, unsigned long); 326 + unsigned long, unsigned long, 327 + unsigned int); 330 328 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, 331 329 struct thermal_cooling_device *); 332 330 void thermal_zone_device_update(struct thermal_zone_device *);