thermal device tree
本文kernel版本:4.14
由于各个厂商在thermal governor和硬件上的差异(sensor的排布不同),thermal zone中的温度sensor、cooling devices的设备树配置也有所不同。kernel document总结了几种thermal zone设备树配置示例。
1、cpu thermal zone
thermal zone包含一个温度sensor和若干cooling devices的情况
#include <dt-bindings/thermal/thermal.h>
/*cpufreq cooling device-passive被动冷却*/
cpus {
/*
* Here is an example of describing a cooling device for a DVFS
* capable CPU. The CPU node describes its four OPPs.
* The cooling states possible are 0..3, and they are
* used as OPP indexes. The minimum cooling state is 0, which means
* all four OPPs can be available to the system. The maximum
* cooling state is 3, which means only the lowest OPPs (198MHz@0.85V)
* can be available in the system.
*/
/* */
cpu0: cpu@0 {
...
operating-points = <
/* kHz uV */
970000 1200000
792000 1100000
396000 950000
198000 850000
>;
cooling-min-level = <0>;/* 说明四组OPPs都可用 */
cooling-max-level = <3>;/* 说明OPPs中只有频率最低的那一组可用(198MHz@0.85V) */
#cooling-cells = <2>; /* min followed by max */
};
...
};
/*风扇控制器-active主动冷却*/
/*一个通过i2c总线1控制的风扇设备fan0,地址0x48,有10个冷却等级*/
&i2c1 {
...
/*
* A simple fan controller which supports 10 speeds of operation
* (represented as 0-9).
*/
fan0: fan@0x48 {
...
cooling-min-level = <0>;
cooling-max-level = <9>;/* 10 cooling states */
#cooling-cells = <2>; /* min followed by max */
};
};
/*温度传感器IC*/
/*ADC sensor(bandgap0),地址0x0000ED00,用来监视'cpu-thermal'的温度*/
ocp {
...
/*
* A simple IC with a single bandgap temperature sensor.
*/
bandgap0: bandgap@0x0000ED00 {
...
#thermal-sensor-cells = <0>;
};
};
thermal-zones {
cpu_thermal: cpu-thermal {
polling-delay-passive = <250>; /* milliseconds */
polling-delay = <1000>; /* milliseconds */
thermal-sensors = <&bandgap0>;
trips {
cpu_alert0: cpu-alert0 {
temperature = <90000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "active";
};
cpu_alert1: cpu-alert1 {
temperature = <100000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
cpu_crit: cpu-crit {
temperature = <125000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "critical";
};
};
cooling-maps {
map0 {
trip = <&cpu_alert0>;
cooling-device = <&fan0 THERMAL_NO_LIMIT 4>;/* 温度超过cpu_alert0时,等级0-4 */
};
map1 {
trip = <&cpu_alert1>;
cooling-device = <&fan0 5 THERMAL_NO_LIMIT>;/* 温度超过cpu_alert1时,等级5-9 */
};
map2 {
trip = <&cpu_alert1>;
cooling-device =
<&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;/* 所有冷却等级都可以用在cpu_alert1上,即温度在alert1-alert2之间,所有冷却等级可用 */
};
};
};
};
2、IC with several internal sensors
每个sensor对应一个thermal zone的情况。
硬件排布上,这三个sensor分别放置在芯片中的不同位置,可以监视不同的热点温度。
bandgap0监视CPU thermal zone; bandgap1监视GPU thermal zone; bandgap2监视DSP thermal zone。
它们有各自的延时、trips和cooling maps。
#include <dt-bindings/thermal/thermal.h>
ocp {
...
/*
* A simple IC with several bandgap temperature sensors.
*/
bandgap0: bandgap@0x0000ED00 {
...
#thermal-sensor-cells = <1>;
};
};
thermal-zones {
cpu_thermal: cpu-thermal {
polling-delay-passive = <250>; /* milliseconds */
polling-delay = <1000>; /* milliseconds */
/* sensor ID */
thermal-sensors = <&bandgap0 0>;
trips {
/* each zone within the SoC may have its own trips */
cpu_alert: cpu-alert {
temperature = <100000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
cpu_crit: cpu-crit {
temperature = <125000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "critical";
};
};
cooling-maps {
/* each zone within the SoC may have its own cooling */
...
};
};
gpu_thermal: gpu-thermal {
polling-delay-passive = <120>; /* milliseconds */
polling-delay = <1000>; /* milliseconds */
/* sensor ID */
thermal-sensors = <&bandgap0 1>;
trips {
/* each zone within the SoC may have its own trips */
gpu_alert: gpu-alert {
temperature = <90000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
gpu_crit: gpu-crit {
temperature = <105000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "critical";
};
};
cooling-maps {
/* each zone within the SoC may have its own cooling */
...
};
};
dsp_thermal: dsp-thermal {
polling-delay-passive = <50>; /* milliseconds */
polling-delay = <1000>; /* milliseconds */
/* sensor ID */
thermal-sensors = <&bandgap0 2>;
trips {
/* each zone within the SoC may have its own trips */
dsp_alert: dsp-alert {
temperature = <90000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
dsp_crit: gpu-crit {
temperature = <135000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "critical";
};
};
cooling-maps {
/* each zone within the SoC may have its own cooling */
...
};
};
};
3、Several sensors within one single thermal zone
一个thermal zone对应多个sensor的情况。
假设这里有两个sensor,一个在cpu内部,一个在靠近cpu的位置。该thermal zone的温度变化由这两个sensor共同决定。
#include <dt-bindings/thermal/thermal.h>
&i2c1 {
...
/*
* A simple IC with a single temperature sensor.
*/
adc: sensor@0x49 {
...
#thermal-sensor-cells = <0>;
};
};
ocp {
...
/*
* A simple IC with a single bandgap temperature sensor.
*/
bandgap0: bandgap@0x0000ED00 {
...
#thermal-sensor-cells = <0>;
};
};
thermal-zones {
cpu_thermal: cpu-thermal {
polling-delay-passive = <250>; /* milliseconds */
polling-delay = <1000>; /* milliseconds */
thermal-sensors = <&bandgap0>, /* cpu */
<&adc>; /* pcb north */
/* hotspot = 100 * bandgap - 120 * adc + 484 */
coefficients = <100 -120 484>;
trips {
...
};
cooling-maps {
...
};
};
};
4、board thermal
一个thermal zone有多个sensor和cooling device的情况。
电池的thermal zone对应sensor adc_dummy4
board的thermal zone对应sensor adc_dummy0、1、2
#include <dt-bindings/thermal/thermal.h>
&i2c1 {
...
/*
* An IC with several temperature sensor.
*/
adc_dummy: sensor@0x50 {
...
#thermal-sensor-cells = <1>; /* sensor internal ID */
};
};
thermal-zones {
batt-thermal {
polling-delay-passive = <500>; /* milliseconds */
polling-delay = <2500>; /* milliseconds */
/* sensor ID */
thermal-sensors = <&adc_dummy 4>;
trips {
...
};
cooling-maps {
...
};
};
board_thermal: board-thermal {
polling-delay-passive = <1000>; /* milliseconds */
polling-delay = <2500>; /* milliseconds */
/* sensor ID */
thermal-sensors = <&adc_dummy 0>, /* pcb top edge */
<&adc_dummy 1>, /* lcd */
<&adc_dummy 2>; /* back cover */
/*
* 三个sensor的线性对应关系:
* An array of coefficients describing the sensor
* linear relation. E.g.:
* z = c1*x1 + c2*x2 + c3*x3
*/
coefficients = <1200 -345 890>;
sustainable-power = <2500>;
trips {
/* Trips are based on resulting linear equation */
cpu_trip: cpu-trip {
temperature = <60000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
gpu_trip: gpu-trip {
temperature = <55000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
}
lcd_trip: lcp-trip {
temperature = <53000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "passive";
};
crit_trip: crit-trip {
temperature = <68000>; /* millicelsius */
hysteresis = <2000>; /* millicelsius */
type = "critical";
};
};
cooling-maps {
map0 {
trip = <&cpu_trip>;
cooling-device = <&cpu0 0 2>;
contribution = <55>;
};
map1 {
trip = <&gpu_trip>;
cooling-device = <&gpu0 0 2>;
contribution = <20>;
};
map2 {
trip = <&lcd_trip>;
cooling-device = <&lcd0 5 10>;
contribution = <15>;
};
};
};
};
参考链接:https://elixir.bootlin.com/linux/v4.14.262/source/Documentation/devicetree/bindings/thermal/thermal.txt