1、概述
Thermal是
内核开发者定义的⼀套⽀持根据指定governor控制系统温度,以防⽌芯⽚过热的框架模型。Thermal
Framework由governor、core、cooling
device、sensor
driver组成,软件架构如下:
Thermal governor:⽤于决定cooling device是否需要降频,降到什么程度。⽬前
linux4.4内核中包含了如下⼏种governor:
power_allocator:引⼊PID(⽐例-积分-微分)控制,根据当前温度,动态给各cooling device分配power, 并将power转换为频率,从而达到根据温度限制频率的效果。
step_wise :根据当前温度,cooling device逐级降频。
fair share :频率档位⽐较多的cooling device优先降频。
userspace:不限制频率。
Thermal core: 对thermal governors和thermal driver进⾏了封装和抽象,并定义了清晰的接口。
Thermal sensor driver:sensor驱动,⽤于获取温度,⽐如ts
ADC。
Thermal cooling device:发热源或者可以降温的设备,⽐如
CPU、
GPU、DDR等。
2、代码路径
Governor相关代码:
drivers/thermal/power_allocator.c /* power allocator温控策略 */
drivers/thermal/step_wise.c /* step wise温控策略 */
drivers/thermal/fair_share.c /* fair share温控策略 */
drivers/thermal/user_space.c /* userspace温控策略 */
Cooling device相关代码:
drivers/thermal/devfreq_cooling.c
drivers/thermal/cpu_cooling.c
Core相关代码:
drivers/thermal/thermal_core.c
Driver相关代码:
drivers/thermal/rockchip_thermal.c /* 除了
rk3368外的其他平台的tsadc驱动 */
drivers/thermal/rk3368_thermal.c /* RK3368平台tsadc驱动 */
3、配置⽅法
3.1 Menuconfig配置
<*> Generic Thermal sysfs driver --->
--- Generic Thermal sysfs driver
APIs to parse thermal data out of Device tree enable writable trip points Default Thermal governor (power_allocator) ---> /* default thermal governor */
[ ] Fair-share thermal governor
[ ] Step_wise thermal governor /* step_wise governor */
[ ] Bang Bang thermal governor User_space thermal governor /* user_space governor */
-*- Power allocator thermal governor /* power_allocator governor */ generic cpu cooling support /* cooling device */
[ ] Generic clock cooling support Generic device cooling support /* cooling device */
[ ] Thermal emulation mode support
< > Temperature sensor driver for Freescale i.MX SOCs
<*> Rockchip thermal driver /* thermal sensor driver */
< > rk_virtual thermal driver
<*> rk3368 thermal driver legacy /* thermal sensor driver */
通过“Default Thermal governor”配置项,可以选择温控策略,开发者可以根据实际产品需求进⾏修改。
3.2 Tsadc配置
Tsadc在温控中作为thermal sensor,⽤于获取温度,通常需要在DTSI和DTS都做配置。 以RK3399为例,DTSI包括如下配置:
tsadc: tsadc@ff260000 { compatible = "rockchip,rk3399-tsadc";
reg = <0x0 0xff260000 0x0 0x100>; /* 寄存器基地址和寄存器地址总⻓度 */
interrupts = <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH 0>; /* 中断号及中断触发⽅式 */
assigned-clocks = <&cru SCLK_TSADC>; /* ⼯作时钟,750KHz */
assigned-clock-rates = <750000>;
clocks = <&cru SCLK_TSADC>, <&cru PCLK_TSADC>; /* ⼯作时钟和配置时钟 */
clock-names = "tsadc", "apb_pclk";
resets = <&cru SRST_TSADC>; /* 复位信号 */
reset-names = "tsadc-apb";
rockchip,grf = <&grf>; /* 引⽤grf模块,部分平台需要 */
rockchip,hw-tshut-temp = <120000>; /* 过温重启阀值,120摄⽒度 */
......
更多详细内容请下载附件查看