Repository navigation
nt9856x: enable the SoC thermal sensor - #2950
Conversation
NT98566 and NT98562 (NA51089) have an on-die thermal sensor, and its driver (drivers/iio/adc/nvt_adc.c, zone "nvt_thermal") is already in OpenIPC/linux novatek-nt9856x, but the kernel configs leave it out, so these cameras have no /sys/class/thermal/thermal_zone0. Enable CONFIG_THERMAL, CONFIG_IIO and CONFIG_NVT_ADC, keeping what olddefconfig adds for them (THERMAL_OF, the step_wise governor as the default, and the "is not set" lines for the newly visible options). Needs OpenIPC/linux#323, which makes the zone report millidegrees. Signed-off-by: DrSamJames <DrSamJames@gmail.com>
PR Summary by Qodont9856x: Enable the SoC thermal sensor
AI Description
Merge Risk
|
Code Review by Qodo
1. NT98562 thermal config ships without hardware testing
|
|
Thanks, both points are fair. 1. NT98562 untested. Correct, I only have NT98566 hardware. Why it is included anyway: NT98562 and NT98566 are the same NA51089 die, the two configs were byte-identical before this change and still are, and the driver picks its formula by chip ID (NA51089), not by part number. The one thing I can't check without a board is whether NT98562 boards ship the 2. Units before linux#323. Agreed, which is why the description asks for OpenIPC/linux#323 to be merged first. Merging this PR changes the firmware commit, so the nightly gate won't skip that build, and it fetches |
… 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.
… 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.
openipc-ai
left a comment
There was a problem hiding this comment.
OpenIPC/linux#323 is merged, so the first image built with this has the zone in millidegrees, and ipctool reads it without touching the ADC or the eFuse since OpenIPC/ipctool#296 — no userspace eFuse sequence racing the kernel's own readers. Both boards build: uImage 1920/2048 KB, rootfs 4920/5120 KB, no headroom warning. NT98562 untested on hardware is acceptable here: same NA51089 die, a byte-identical config, and the driver does not probe without the adc@f0260000 node.
Problem
NT98566 and NT98562 (NA51089) have an on-die thermal sensor, but these cameras have no
/sys/class/thermal/thermal_zone0. Its driver is already in OpenIPC/linuxnovatek-nt9856xasdrivers/iio/adc/nvt_adc.c, which registers thenvt_thermalzone. The device tree nodeadc@f0260000(nvt,nvt_adc) is present and enabled in the DTB these boards ship with. Only the kernel config was missing.This enables
CONFIG_THERMAL,CONFIG_IIOandCONFIG_NVT_ADCinnt98566.generic.configandnt98562.generic.config. The new symbolsolddefconfigadds are kept:THERMAL_OF=yTHERMAL_GOV_STEP_WISE=yTHERMAL_DEFAULT_GOV_STEP_WISE=yTHERMAL_EMERGENCY_POWEROFF_DELAY_MS=0Nothing else in either file changes.
olddefconfigwould also bumpGCC_VERSIONand drop some stale F2FS, HID and INPUT lines, but it does that to the untouched file as well, so those changes are left out.Depends on
Depends on OpenIPC/linux#323, so please merge that first. As shipped,
thermal_get_temp()returns whole °C, but the thermal sysfs ABI is millidegrees. The fix scales it to m°C:(raw - trim) * 1319 + 30000(raw - trim) * 1300 + 30000Nothing in the kernel tree reads this zone in °C.
The firmware fetches
openipc/linux/archive/novatek-nt9856x.tar.gz, so once the linux PR merges, the next build picks up the fix with no further firmware change.Hardware tested on
NT98566 (NA51089) + IMX415,
nt98566_lite. Built from 9e6a052 with the linux fix applied locally; both configs are unchanged on master since then. Kernel and rootfs from the same build were flashed withsysupgrade -z --kernel=… --rootfs=…, keeping the overlay.Evidence
Before (nightly-20261123-9e6a052):
After (same camera, then again after a reboot; each line is
thermal_zone0/tempandipcinfo --tempread together):9 of 10 pairs match exactly; the other is one ADC step (1.32 °C) apart. Both read the same sensor, so this checks the scaling, not the calibration. The stream ran at 25/25 fps after the reboot, and dmesg and logread had no new errors or warnings compared with a fresh nightly boot.
Size:
majestic: majestic Lite
master+6a1f8dbdoesn't use the zone yet on this platform. It draws no OSD on nt9856x (/api/v1/osdreports an overlay budget of 0) and has nonode_hwmon_temp_celsiusmetric, so the WebUI temperature tile still says n/a. The zone is now there for it.Not tested
Scope
general/package/all-patches/linux/(those go to OpenIPC/linux)general/overlay/or in a sharedload_<vendor>script hardcodes a value specific to my boardLD_PRELOAD, and no binaries that cannot be rebuilt from source