概述
架构
温度测量(Thermal)驱动程序遵循 Linux 的 thermal 子系统。thermal 子系统为用户空间提供 thermal 接口。thermal 软件架构如下面的图所示。
thermal 软件架构包含以下部分:
Thermal 驱动程序分为三部分:
Thermal Governor
:温度控制。Thermal Zone Device
:获取文档。Thermal Cooling Devices
:降温。
Thermal 核心: Thermal 子系统核心驱动程序。
应用:用户空间。一个简单的示例,展示如何使用 thermal 系统。
备注
目前尚未实现 Thermal 管理器和 Thermal 降温设备。
有关 thermal 的更多细节请参考 Thermal v5.4 或 Thermal v6.6 。
实现
thermal 驱动程序的实现如下所列。
驱动程序位置 |
介绍 |
---|---|
<linux>/drivers/rtkdrivers/thermal/Kconfig |
Thermal 驱动程序 Kconfig |
<linux>/drivers/rtkdrivers/thermal/Makefile |
Thermal 驱动程序 Makefile |
<linux>/drivers/rtkdrivers/thermal/realtek-thermal.c |
Thermal 函数 |
<linux>/drivers/rtkdrivers/thermal/realtek-thermal.h |
与thermal相关的函数声明、宏定义、结构定义以及引用的其他头文件 |
配置
设备树配置
CPU Thermal
CPU thermal 设备树节点:
thermal-zones {
cpu_thermal: cpu-thermal {
polling-delay-passive = <0>;
polling-delay = <0>;
thermal-sensors = <&thermal>;
trips {
cpu_alert1: cpu-alert1 {
temperature = <105000>;
hysteresis = <0>;
type = "passive";
};
cpu-crit {
temperature = <125000>;
hysteresis = <0>;
type = "critical";
};
};
cooling-maps {
};
};
};
Thermal 区设备树包含热传感器、触发点和冷却设备的描述。of-thermal 模块将自动注册这些描述。
Thermal 区的设备树配置如下所示。
属性 |
描述 |
可配置? |
---|---|---|
polling-delay-passive |
在被动冷却激活时的轮询间隔 |
是 |
polling-delay |
区域轮询间隔 |
是 |
thermal-sensors |
指向thermal传感器设备节点 |
否 |
temperature |
触发温度值(单位:毫摄氏度) |
是 |
hysteresis |
相对迟滞(单位:毫摄氏度) |
是 |
type |
临界点类型。有四种类型:
|
是 |
cooling-maps |
定义临界点与冷却装置之间的关系 |
是 |
备注
温度为设定触发阈值的 1000 倍
小心
冷却策略暂时未实现
Thermal
Thermal 设备树节点
thermal: thermal@42013000 {
compatible = "realtek,ameba-thermal";
reg = <0x42013000 0x100>;
interrupts = <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH>; /* use timer7, MP chip: 21 */
clocks = <&rcc RTK_CKE_ATIM>, <&rcc RTK_CKE_THM>;
clock-names = "rtk_aon_tim_clk", "rtk_thermal_clk";
#thermal-sensor-cells = <0>;
};
thermal 的设备树配置如下所列。
属性 |
描述 |
默认值 |
可配置? |
---|---|---|---|
compatible |
有关thermal驱动的描述符 |
realtek,ameba-thermal |
否 |
reg |
thermal设备的硬件地址和大小 |
<0x42013000 0x100> |
否 |
interrupts |
thermal设备的GIC编号 |
<GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH> |
否 |
clocks |
thermal设备的时钟 |
<&rcc RTK_CKE_ATIM>, <&rcc RTK_CKE_THM> |
否 |
#thermal-sensor-cells |
指明需要多少单元来具体描述一个thermal传感器 |
0 |
否 |
编译配置
选择
:
API
用户空间 API
Thermal 管理使用 sysfs 接口与用户空间进行交互。
接口 |
介绍 |
---|---|
/sys/class/thermal/thermal_zone0/temp |
获取温度 |
/sys/class/thermal/thermal_zone0/type |
获取温度阈值类型 |
用户空间的 thermal 管理演示位于 <test>/thermal
。
内核空间 API
接口 |
介绍 |
---|---|
devm_thermal_zone_of_sensor_register |
thermal_zone_of_sensor_register() 的资源管理版本 |
devm_thermal_zone_of_sensor_unregister |
thermal_zone_of_sensor_unregister() 的资源管理版本 |
thermal_zone_of_sensor_register |
将传感器注册到设备树的thermal区 |
thermal_zone_of_sensor_unregister |
从设备树thermal区注销一个传感器 |
of_thermal_get_trip_points |
获取全局导出的临界点的函数 |
of_thermal_get_ntrips |
导出可用临界点数量的函数 |
thermal_add_hwmon_sysfs |
将一个thermal区设备添加到 hwmon sysfs 中 |
thermal_remove_hwmon_sysfs |
从 hwmon sysfs 中移除一个thermal区设备 |
参考 thermal sysfs v5.4 或 thermal sysfs v6.6 获取更多细节。