温度与湿度传感器驱动

温度与湿度传感器驱动

1. 驱动族

类别 代表
本地温度 LM75、TMP102/103/108
远端二极管 LM90、TMP401/421/464
DIMM 温度 JC42
SPI 温度 ADT7310、LM70、MAX31722
温湿度 SHT21/3x/4x、AHT10、HIH6130
热敏电阻 NTC thermistor

2. Probe

典型 I2C:

1
2
3
4
5
6
7
i2c probe
-> identify variant
-> devm_regmap_init_i2c()
-> read ID/config
-> set conversion rate/resolution
-> build hwmon_chip_info
-> devm_hwmon_device_register_with_info()

部分 legacy driver直接用 SMBus helpers 和自建 attributes。

3. 转换

数字温度寄存器常是:

  • two’s complement;
  • fixed-point;
  • 不同 resolution;
  • 左对齐;
  • 摄氏度 LSB 为 1/16、1/256 等。

驱动输出 millidegree Celsius,负温必须正确符号扩展。

4. 更新率

芯片 conversion rate 决定:

  • 新数据延迟;
  • 功耗;
  • I2C 流量;
  • self-heating;
  • alarm 响应。

update_interval 若可写,应取芯片支持档位并返回实际值。

5. 缓存

多寄存器 sensor常使用:

1
2
3
4
5
6
mutex
if !valid or time_after(jiffies, last_updated + interval):
bulk read
update cache
valid = true
return cached value

缓存避免用户一次 sensors 读取多个属性产生重复总线访问。

6. 阈值

温度 max/crit/hyst 对应芯片寄存器。写入时:

  1. clamp/check ABI value;
  2. 转成寄存器单位;
  3. round 到可表示精度;
  4. write;
  5. 更新/失效 cache。

硬件 hysteresis 可能表示绝对温度或相对差值,驱动必须转换成标准 ABI语义。

7. 远端二极管

远端 channel 可检测:

  • open/short fault;
  • diode ideality;
  • offset;
  • local/remote temperature;
  • emergency limit。

板级走线和晶体管模型影响精度,不是纯软件问题。

8. 湿度

湿度通常需要:

  • measurement command;
  • conversion wait;
  • CRC;
  • temperature compensation;
  • milli-percent 输出。

高频读取会使器件忙或自热,应尊重 conversion time。

9. NTC

ntc_thermistor.c 根据电阻/电压和查表换算温度,依赖 pull-up/pull-down、电阻值与 IIO/ADC 输入。DTS 参数错误会导致非线性温差。

10. RK3588

RK3588 内部 SoC 温度不是 LM/TMP hwmon 驱动,而是 TSADC thermal driver。只有板上明确安装外部 sensor 并在 DTS 声明时,本章这些驱动才会出现于 /sys/class/hwmon

文章互动

阅读 --

留言

0 条留言

正在加载留言…