HWMON Core 注册与生命周期
1. Class
hwmon_class:
- name:
hwmon; - 默认属性:
name、可选label; - release:释放自动属性、groups、label 和
hwmon_device。
IDA 动态分配 hwmonN,编号会随 probe 顺序变化。
2. 现代 API
推荐:
1 | devm_hwmon_device_register_with_info(parent, name, drvdata, |
非 devm:
1 | hwmon_device_register_with_info(); |
旧 hwmon_device_register() 已 deprecated。
3. 参数
- parent:真实 I2C/SPI/platform device;
- name:
name属性,不允许- * 空白; - drvdata:传给 ops;
hwmon_chip_info:ops + channel info;- extra groups:非标准属性,应该极少使用。
4. 注册链
1 | devm_hwmon_device_register_with_info() |
5. 属性生成
hwmon_channel_info.config[] 以 0 结尾。每个 channel 的 bit mask决定候选属性;is_visible() 最终决定:
- 0:不创建;
- 0444:只读;
- 0644:root 可写;
- 其它合理 sysfs mode。
Core 根据 type/attr 选择标准文件名模板。
6. 读写
1 | show -> hwmon_attr_show() |
字符串属性(主要 label)走 read_string()。
7. label
若 parent firmware property 有 label,Core复制并暴露顶层 label。各 channel label 则由 read_string(type, *_label, channel) 提供。
8. Thermal bridge
满足以下条件才尝试:
- OF node;
- chip info;
- ops->read;
- 第一个 info 是
hwmon_chip; - config 含
HWMON_C_REGISTER_TZ。
Core按温度 channel 调 devm_thermal_of_zone_register()。hwmon_notify_event() 也会更新关联 thermal zone。
9. 卸载
devm 在 parent detach 时调用 hwmon_device_unregister():
1 | device_unregister(hwmonN) |
driver 的 worker/timer/IRQ 必须先停止,避免 sysfs 消失后仍访问 drvdata。
10. 错误
-EINVAL:name/chip/ops/info 无效;-ENOMEM:属性或 device 分配失败;-ENOENT:is_visible隐藏属性时内部跳过;- thermal
-ENODEV:没有匹配 OF zone,通常不使 hwmon 注册失败; - probe defer:底层 regulator/I2C/PWM provider 未就绪。
正在加载留言…