thermal zone
生活随笔
收集整理的这篇文章主要介绍了
thermal zone
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
- 注册thermal zone设备
- 函数申明
- 函数定义thermal_corec
- 函数使用
- 功能描述
- 参数说明
- 使用注意事项
- 使用示例
- 注册cooling device
- 函数申明
- 函数定义thermal_corec
- 函数使用
- 功能描述
- 参数说明
- 使用示例
- thermal zone 和cool device 绑定
注册thermal zone设备
thermal_zone_device_register函数申明:
#include <linux/thermal.h>函数定义:thermal_core.c
struct thermal_zone_device* thermal_zone_device_register(const char *type,int trips,int mask, void *devdata,struct thermal_zone_device_ops *ops,struct thermal_zone_params *tzp,int polling_delay)函数使用
功能描述
- 注册一个thermal zone device
- 在/sys/class/thermal 目录下面创建 thermal_zone[0-*]. 设备节点
- 创建对应的thermal_zone* 下面对应的文件节点,定义读写函数回调相关tz的ops方法
- 尝试绑定所有的cool device 到该tz
- 创建一个工作队列,定时获取温度并采取策略
参数说明
* @type: tz设备类型,用来标识不同tz的字符串* @trips: tz设备支持的触发点个数* @mask: 要求mask 小于trips个数,一般为0* @devdata: 设备私有数据* @ops: tz设备回调函数,trip num大于0 的情况下,ops 中get_trip_type 和 get_trip_temp 必须不为null* @tzp: tz的特殊参数,可以用于标识控制策略等* @passive_delay: passive cooling模式间隔ms数,一般设置为0* @polling_delay: 出发点检测间隔ms数使用注意事项
* 不需要这个tz设备的时候需要调用thermal_zone_device_unregister()来注销* passive cooling 取决于 the .get_trend()函数的返回值* 返回一个指向thermal_zone设备的指针,需要使用IS_ERR来判断返回值使用示例
if (IS_ERR(thermal)) {dev_err(&pdev->dev,"Failed to register thermal zone device\n");return PTR_ERR(thermal); }注册cooling device
thermal_cooling_device_register函数申明:
#include <linux/thermal.h>函数定义:thermal_core.c
struct thermal_cooling_device * thermal_cooling_device_register(char *type, void *devdata,const struct thermal_cooling_device_ops *ops) {return __thermal_cooling_device_register(NULL, type, devdata, ops); } EXPORT_SYMBOL_GPL(thermal_cooling_device_register);实际调用的函数是:__thermal_cooling_device_register
static struct thermal_cooling_device * __thermal_cooling_device_register(struct device_node *np,char *type,void *devdata,const struct thermal_cooling_device_ops *ops)函数使用
功能描述
- 注册一个cooling 设备
- 创建设备节点/sys/class/thermal/cooling_device[0-*]
- 尝试将自己绑定到所有tz
- 返回一个指向cooling device 的指针
参数说明
@np: 指向设备数节点的指针@type: cooling device的设备类型@devdata: 设备私有数据@ops: 设备操作的回调函数,ops必须定义并且必须至少包含 get_max_state,get_cur_state,set_cur_state方法使用示例:
cdev = thermal_cooling_device_register("xxxx", NULL, &xxx_cooling_ops); if (IS_ERR(cdev)) {retval = PTR_ERR(cdev); goto err1; }thermal zone 和cool device 绑定
在thermal zone 和 cool device 设备注册的时候会分别调用bind_tz(tz)和bind_cdev(cdev) 进行绑定
这样就可以保证无论两个设备的注册顺序如何都不会出现绑定不成功的意外
绑定规则如下:
- 遍历thermal_tz_list,如果当前tz 定义了bind 回调函数,就使用该回调函数决定是否绑定成功
- 如果当前tz没有定义bind 回调函数,则通过tz 注册时候的tzp->tbp 相关规则绑定
- 如果tzp->tbp 和bind 都没有定义,直接调到下个tz进行绑定
总结
以上是生活随笔为你收集整理的thermal zone的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 5G(NR)网络中的SRB定义和类型
- 下一篇: V for vendetta