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