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

thermal: of-thermal: add support for reading coefficients property

In order to avoid having each driver adding their own
specific DT property to specify slope and offset,
this patch adds a basic coefficient reading from
DT thermal zone node. Right now, as the thermal
framework does not support multiple sensors,
the current coefficients apply only to the only
sensor in the thermal zone.

The supported equation is a simple linear model:
slope * <sensor reading> + offset.

slope and offset are read from the coefficients
DT property. In the same way as it is described in
the DT thermal binding.

So, as of today, the thermal framework will support
only cases like:
/* hotspot = 1 * adc + 6000 */
coefficients = <1 6000>;

Signed-off-by: Eduardo Valentin <edubezval@gmail.com>

+24 -2
+24 -2
drivers/thermal/of-thermal.c
··· 58 58 * @mode: current thermal zone device mode (enabled/disabled) 59 59 * @passive_delay: polling interval while passive cooling is activated 60 60 * @polling_delay: zone polling interval 61 + * @slope: slope of the temperature adjustment curve 62 + * @offset: offset of the temperature adjustment curve 61 63 * @ntrips: number of trip points 62 64 * @trips: an array of trip points (0..ntrips - 1) 63 65 * @num_tbps: number of thermal bind params ··· 72 70 enum thermal_device_mode mode; 73 71 int passive_delay; 74 72 int polling_delay; 73 + int slope; 74 + int offset; 75 75 76 76 /* trip data */ 77 77 int ntrips; ··· 720 716 * @np parameter and fills the read data into a __thermal_zone data structure 721 717 * and return this pointer. 722 718 * 723 - * TODO: Missing properties to parse: thermal-sensor-names and coefficients 719 + * TODO: Missing properties to parse: thermal-sensor-names 724 720 * 725 721 * Return: On success returns a valid struct __thermal_zone, 726 722 * otherwise, it returns a corresponding ERR_PTR(). Caller must ··· 732 728 struct device_node *child = NULL, *gchild; 733 729 struct __thermal_zone *tz; 734 730 int ret, i; 735 - u32 prop; 731 + u32 prop, coef[2]; 736 732 737 733 if (!np) { 738 734 pr_err("no thermal zone np\n"); ··· 756 752 goto free_tz; 757 753 } 758 754 tz->polling_delay = prop; 755 + 756 + /* 757 + * REVIST: for now, the thermal framework supports only 758 + * one sensor per thermal zone. Thus, we are considering 759 + * only the first two values as slope and offset. 760 + */ 761 + ret = of_property_read_u32_array(np, "coefficients", coef, 2); 762 + if (ret == 0) { 763 + tz->slope = coef[0]; 764 + tz->offset = coef[1]; 765 + } else { 766 + tz->slope = 1; 767 + tz->offset = 0; 768 + } 759 769 760 770 /* trips */ 761 771 child = of_get_child_by_name(np, "trips"); ··· 917 899 918 900 for (i = 0; i < tz->ntrips; i++) 919 901 mask |= 1 << i; 902 + 903 + /* these two are left for temperature drivers to use */ 904 + tzp->slope = tz->slope; 905 + tzp->offset = tz->offset; 920 906 921 907 zone = thermal_zone_device_register(child->name, tz->ntrips, 922 908 mask, tz,