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

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 <rui.zhang@intel.com>
Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl>
Reviewed-by: Eduardo Valentin <eduardo.valentin@ti.com>

Zhang Rui 9d99842f 74051ba5

+65 -28
+8 -1
Documentation/thermal/sysfs-api.txt
··· 84 84 85 85 1.3 interface for binding a thermal zone device with a thermal cooling device 86 86 1.3.1 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, 87 - int trip, struct thermal_cooling_device *cdev); 87 + int trip, struct thermal_cooling_device *cdev, 88 + unsigned long upper, unsigned long lower); 88 89 89 90 This interface function bind a thermal cooling device to the certain trip 90 91 point of a thermal zone device. ··· 94 93 cdev: thermal cooling device 95 94 trip: indicates which trip point the cooling devices is associated with 96 95 in this thermal zone. 96 + upper:the Maximum cooling state for this trip point. 97 + THERMAL_NO_LIMIT means no upper limit, 98 + and the cooling device can be in max_state. 99 + lower:the Minimum cooling state can be used for this trip point. 100 + THERMAL_NO_LIMIT means no lower limit, 101 + and the cooling device can be in cooling state 0. 97 102 98 103 1.3.2 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, 99 104 int trip, struct thermal_cooling_device *cdev);
+35 -18
drivers/acpi/thermal.c
··· 729 729 return 0; 730 730 } 731 731 732 - typedef int (*cb)(struct thermal_zone_device *, int, 733 - struct thermal_cooling_device *); 734 732 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, 735 733 struct thermal_cooling_device *cdev, 736 - cb action) 734 + bool bind) 737 735 { 738 736 struct acpi_device *device = cdev->devdata; 739 737 struct acpi_thermal *tz = thermal->devdata; ··· 755 757 i++) { 756 758 handle = tz->trips.passive.devices.handles[i]; 757 759 status = acpi_bus_get_device(handle, &dev); 758 - if (ACPI_SUCCESS(status) && (dev == device)) { 759 - result = action(thermal, trip, cdev); 760 - if (result) 761 - goto failed; 762 - } 760 + if (ACPI_FAILURE(status) || dev != device) 761 + continue; 762 + if (bind) 763 + result = 764 + thermal_zone_bind_cooling_device 765 + (thermal, trip, cdev, 766 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); 767 + else 768 + result = 769 + thermal_zone_unbind_cooling_device 770 + (thermal, trip, cdev); 771 + if (result) 772 + goto failed; 763 773 } 764 774 } 765 775 ··· 780 774 j++) { 781 775 handle = tz->trips.active[i].devices.handles[j]; 782 776 status = acpi_bus_get_device(handle, &dev); 783 - if (ACPI_SUCCESS(status) && (dev == device)) { 784 - result = action(thermal, trip, cdev); 785 - if (result) 786 - goto failed; 787 - } 777 + if (ACPI_FAILURE(status) || dev != device) 778 + continue; 779 + if (bind) 780 + result = thermal_zone_bind_cooling_device 781 + (thermal, trip, cdev, 782 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); 783 + else 784 + result = thermal_zone_unbind_cooling_device 785 + (thermal, trip, cdev); 786 + if (result) 787 + goto failed; 788 788 } 789 789 } 790 790 ··· 798 786 handle = tz->devices.handles[i]; 799 787 status = acpi_bus_get_device(handle, &dev); 800 788 if (ACPI_SUCCESS(status) && (dev == device)) { 801 - result = action(thermal, -1, cdev); 789 + if (bind) 790 + result = thermal_zone_bind_cooling_device 791 + (thermal, -1, cdev, 792 + THERMAL_NO_LIMIT, 793 + THERMAL_NO_LIMIT); 794 + else 795 + result = thermal_zone_unbind_cooling_device 796 + (thermal, -1, cdev); 802 797 if (result) 803 798 goto failed; 804 799 } ··· 819 800 acpi_thermal_bind_cooling_device(struct thermal_zone_device *thermal, 820 801 struct thermal_cooling_device *cdev) 821 802 { 822 - return acpi_thermal_cooling_device_cb(thermal, cdev, 823 - thermal_zone_bind_cooling_device); 803 + return acpi_thermal_cooling_device_cb(thermal, cdev, true); 824 804 } 825 805 826 806 static int 827 807 acpi_thermal_unbind_cooling_device(struct thermal_zone_device *thermal, 828 808 struct thermal_cooling_device *cdev) 829 809 { 830 - return acpi_thermal_cooling_device_cb(thermal, cdev, 831 - thermal_zone_unbind_cooling_device); 810 + return acpi_thermal_cooling_device_cb(thermal, cdev, false); 832 811 } 833 812 834 813 static const struct thermal_zone_device_ops acpi_thermal_zone_ops = {
+2 -1
drivers/platform/x86/acerhdf.c
··· 329 329 if (cdev != cl_dev) 330 330 return 0; 331 331 332 - if (thermal_zone_bind_cooling_device(thermal, 0, cdev)) { 332 + if (thermal_zone_bind_cooling_device(thermal, 0, cdev, 333 + THERMAL_NO_LIMIT, THERMAL_NO_LIMIT)) { 333 334 pr_err("error binding cooling dev\n"); 334 335 return -EINVAL; 335 336 }
+16 -7
drivers/thermal/thermal_sys.c
··· 315 315 if (!strncmp("Processor", cdev->type, 316 316 sizeof("Processor"))) 317 317 thermal_zone_bind_cooling_device(tz, 318 - THERMAL_TRIPS_NONE, 319 - cdev); 318 + THERMAL_TRIPS_NONE, cdev, 319 + THERMAL_NO_LIMIT, 320 + THERMAL_NO_LIMIT); 320 321 } 321 322 mutex_unlock(&thermal_list_lock); 322 323 if (!tz->passive_delay) ··· 802 801 */ 803 802 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, 804 803 int trip, 805 - struct thermal_cooling_device *cdev) 804 + struct thermal_cooling_device *cdev, 805 + unsigned long upper, unsigned long lower) 806 806 { 807 807 struct thermal_cooling_device_instance *dev; 808 808 struct thermal_cooling_device_instance *pos; ··· 827 825 if (tz != pos1 || cdev != pos2) 828 826 return -EINVAL; 829 827 828 + cdev->ops->get_max_state(cdev, &max_state); 829 + 830 + /* lower default 0, upper default max_state */ 831 + lower = lower == THERMAL_NO_LIMIT ? 0 : lower; 832 + upper = upper == THERMAL_NO_LIMIT ? max_state : upper; 833 + 834 + if (lower > upper || upper > max_state) 835 + return -EINVAL; 836 + 830 837 dev = 831 838 kzalloc(sizeof(struct thermal_cooling_device_instance), GFP_KERNEL); 832 839 if (!dev) ··· 843 832 dev->tz = tz; 844 833 dev->cdev = cdev; 845 834 dev->trip = trip; 846 - 847 - cdev->ops->get_max_state(cdev, &max_state); 848 - dev->upper = max_state; 849 - dev->lower = 0; 835 + dev->upper = upper; 836 + dev->lower = lower; 850 837 851 838 result = get_idr(&tz->idr, &tz->lock, &dev->id); 852 839 if (result)
+4 -1
include/linux/thermal.h
··· 75 75 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long); 76 76 }; 77 77 78 + #define THERMAL_NO_LIMIT -1UL /* no upper/lower limit requirement */ 79 + 78 80 #define THERMAL_TRIPS_NONE -1 79 81 #define THERMAL_MAX_TRIPS 12 80 82 #define THERMAL_NAME_LENGTH 20 ··· 159 157 void thermal_zone_device_unregister(struct thermal_zone_device *); 160 158 161 159 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, 162 - struct thermal_cooling_device *); 160 + struct thermal_cooling_device *, 161 + unsigned long, unsigned long); 163 162 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, 164 163 struct thermal_cooling_device *); 165 164 void thermal_zone_device_update(struct thermal_zone_device *);