Repository navigation
iio: adc: nvt_adc: report the thermal zone in millidegrees - #323
Conversation
thermal_get_temp() returns whole degrees Celsius, but the thermal sysfs ABI (/sys/class/thermal/thermal_zone*/temp) and every in-kernel user of thermal_zone_get_temp() expect millidegrees. Userspace reading the nvt_thermal zone therefore sees 51 instead of 51000, i.e. 0.051 C. Keep the same calibration (1.319 C per ADC step on NA51089, 1.3 C on NA51055, 30 C at the OTP trim level) and scale it to millidegrees. This also drops the integer division, so the reading keeps its sub-degree resolution. Nothing in the tree consumes the "nvt_thermal" zone in degrees. Tested on NA51089 (NT98566). NA51055 is untested. Signed-off-by: DrSamJames <DrSamJames@gmail.com>
PR Summary by QodoReport nvt_adc thermal temperatures in millidegrees Celsius
AI Description
Merge Risk
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all |
… trim once On NA51055/NA51084/NA51089 the temperature came from the registers first: ungate the ADC, start channel 3, and run the eFuse open/row/read/close sequence for the trim on every call. The kernel serialises the eFuse with a semaphore userspace cannot take, and it reads the eFuse at run time, not only at boot: kdrv_h26x.ko calls h26x_efuse_check() from kdrv_videoenc_set() and kdrv_videodec_set(), kdrv_ai.ko calls efuse_check_available(), and nvt_usb2dev.ko calls efuse_readParamOps(). Our sequence interleaved with one of those can hand the kernel our row or close the controller under it. A metrics exporter that reports the temperature on every scrape (OpenIPC/majestic#386) would keep reopening that window. Where the kernel carries nvt_adc (OpenIPC/firmware#2950), its zone is the reading, found by type "nvt_thermal" rather than by number, and no register is touched; the kernel read the trim once, at probe, under its own lock. Without the zone, the register path is unchanged except that a completed trim read is kept for the life of the process. One that did not complete (the controller was open, or the two reads disagreed) is not kept, so the next call tries again rather than living with the default. A zone is read in either unit. The vendor driver reports whole degrees and OpenIPC/linux#323 makes ours millidegrees; a die reads -40..125 degC, so a whole-degree value stays inside [-100, 200], and nvt_adc's millidegrees land in there only at 100 (an NA51055 at 0.1 degC). The other Novatek dies' zone0 reader goes through the same conversion, which changes nothing for a whole-degree driver.
openipc-ai
left a comment
There was a problem hiding this comment.
The scaling is right: 13/10 → 1300 and 1319/1000 → 1319 m°C per code, +30000 m°C, the same calibration without the truncation. The zone registers no trips, so the unit change cannot start a thermal shutdown. The untested NA51055 branch is reachable by no OpenIPC firmware board: the tree ships nt98562/nt98566 (NA51089) only. ipctool reads the zone in either unit from OpenIPC/ipctool#296.
… trim once (#296) On NA51055/NA51084/NA51089 the temperature came from the registers first: ungate the ADC, start channel 3, and run the eFuse open/row/read/close sequence for the trim on every call. The kernel serialises the eFuse with a semaphore userspace cannot take, and it reads the eFuse at run time, not only at boot: kdrv_h26x.ko calls h26x_efuse_check() from kdrv_videoenc_set() and kdrv_videodec_set(), kdrv_ai.ko calls efuse_check_available(), and nvt_usb2dev.ko calls efuse_readParamOps(). Our sequence interleaved with one of those can hand the kernel our row or close the controller under it. A metrics exporter that reports the temperature on every scrape (OpenIPC/majestic#386) would keep reopening that window. Where the kernel carries nvt_adc (OpenIPC/firmware#2950), its zone is the reading, found by type "nvt_thermal" rather than by number, and no register is touched; the kernel read the trim once, at probe, under its own lock. Without the zone, the register path is unchanged except that a completed trim read is kept for the life of the process. One that did not complete (the controller was open, or the two reads disagreed) is not kept, so the next call tries again rather than living with the default. A zone is read in either unit. The vendor driver reports whole degrees and OpenIPC/linux#323 makes ours millidegrees; a die reads -40..125 degC, so a whole-degree value stays inside [-100, 200], and nvt_adc's millidegrees land in there only at 100 (an NA51055 at 0.1 degC). The other Novatek dies' zone0 reader goes through the same conversion, which changes nothing for a whole-degree driver. The scan steps over gaps in the zone numbering, and a kernel that withholds /dev/mem still falls back to thermal_zone0 of any type, as before.
thermal_get_temp()returns whole degrees Celsius, but the thermal sysfs ABI (/sys/class/thermal/thermal_zone*/temp) and every in-kernel user ofthermal_zone_get_temp()expect millidegrees. Userspace reading thenvt_thermalzone therefore sees 51 instead of 51000, i.e. 0.051 °C.Change. Keep the same calibration (1.319 °C per ADC step on NA51089, 1.3 °C on NA51055, 30 °C at the OTP trim level) and scale it to millidegrees:
(raw - trim) * 1319 + 30000(raw - trim) * 1300 + 30000This also drops the integer division, so the reading keeps its sub-degree resolution.
Nothing in the tree consumes the
nvt_thermalzone in degrees. I grepped fornvt_thermal,thermal_zone_get_tempandthermal_zone_get_zone_by_name, includingdrivers/soc/nvt/. None of the vendor.komodules on the test camera referencethermal_zoneornvt_thermaleither.Tested on a camera (NT98566 / NA51089 + IMX415). The kernel was built from the OpenIPC/firmware
nt98566_litedefconfig with this patch, plusCONFIG_THERMAL,CONFIG_IIOandCONFIG_NVT_ADC, which a separate firmware PR enables:nvt_adc_probe: f0260000.adc doneandthermal thermal_zone0: Thermal Sensor probe.thermal_zone0/typeisnvt_thermal.thermal_zone0/tempagainstipcinfo --temp, read together, e.g. 47147 / 47.15 and 45828 / 45.83. 9 of 10 pairs matched exactly; the other was one ADC step (1.32 °C) apart. Both read the same sensor, so this checks the scaling rather than the calibration.Not tested: the NA51055 branch. No NA51055 hardware was available.
🤖 Generated with Claude Code