power_supply_core和thermal_core的关系
power_supply_core和thermal_core的关系
源代码版本k5.15
1、power_supply_core.c提供power supply的相关接口,比如:
struct power_supply *__must_check power_supply_register(struct device *parent,
const struct power_supply_desc *desc,
const struct power_supply_config *cfg)
2、thermal_core.c提供thermal相关的接口,比如:
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 passive_delay,
int polling_delay)
struct thermal_cooling_device *
thermal_cooling_device_register(const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops)
3、两者之间的关系
struct power_supply *__must_check power_supply_register() {
//......
rc = psy_register_thermal(psy);//-----> thermal_zone_device_register()
if (rc)
goto register_thermal_failed;
rc = psy_register_cooler(psy);//-----> thermal_cooling_device_register()
if (rc)
goto register_cooler_failed;
//......
}
4、应用示例
charger-manager
电池充电设备驱动的热管理需要注册thermal zone device和thermal cooling device,在驱动注册时probe函数会调用
power_supply_register()来注册
static int charger_manager_probe(struct platform_device *pdev)
{
struct charger_desc *desc = cm_get_drv_data(pdev);
struct charger_manager *cm;
//.........cm数据结构初始化
cm->charger_psy = power_supply_register(&pdev->dev,
&cm->charger_psy_desc,
&psy_cfg);
if (IS_ERR(cm->charger_psy)) {
dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
cm->charger_psy_desc.name);
return PTR_ERR(cm->charger_psy);
}
//............
}
所以,在编码时需要注意其他模块对thermal的依赖。
5、参考链接
https://elixir.bootlin.com/linux/v5.15/source/drivers/thermal/thermal_core.c
https://elixir.bootlin.com/linux/v5.15/source/drivers/power/supply/power_supply_core.c
https://elixir.bootlin.com/linux/v5.15/source/drivers/power/supply/charger-manager.c