Skip to content

nt9856x: enable the SoC thermal sensor - #2950

Merged
openipc-ai merged 1 commit into
OpenIPC:masterfrom
DrSamjames:nt9856x-thermal
Nov 26, 2026
Merged

openipc-ai merged 1 commit into
OpenIPC:masterfrom
DrSamjames:nt9856x-thermal

Conversation

@DrSamjames

Copy link
Copy Markdown
Contributor

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/linux novatek-nt9856x as drivers/iio/adc/nvt_adc.c, which registers the nvt_thermal zone. The device tree node adc@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_IIO and CONFIG_NVT_ADC in nt98566.generic.config and nt98562.generic.config. The new symbols olddefconfig adds are kept:

  • THERMAL_OF=y
  • THERMAL_GOV_STEP_WISE=y
  • THERMAL_DEFAULT_GOV_STEP_WISE=y
  • THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
  • the "is not set" lines for the IIO and thermal options it makes visible

Nothing else in either file changes. olddefconfig would also bump GCC_VERSION and 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:

  • NA51089: (raw - trim) * 1319 + 30000
  • NA51055: (raw - trim) * 1300 + 30000

Nothing 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 with sysupgrade -z --kernel=… --rootfs=…, keeping the overlay.

Evidence

Before (nightly-20261123-9e6a052):

# dmesg | grep -E 'thermal|nvt_adc'
# ipcinfo --temp
52.42

After (same camera, then again after a reboot; each line is thermal_zone0/temp and ipcinfo --temp read together):

nvt_adc_probe: f0260000.adc done
thermal thermal_zone0: Thermal Sensor probe
# cat /sys/class/thermal/thermal_zone0/type
nvt_thermal

first boot                        after reboot
zone0 47147  ipcinfo 45.83        zone0 47147  ipcinfo 47.15
zone0 47147  ipcinfo 47.15        zone0 45828  ipcinfo 45.83
zone0 47147  ipcinfo 47.15        zone0 45828  ipcinfo 45.83
zone0 47147  ipcinfo 47.15        zone0 47147  ipcinfo 47.15
zone0 47147  ipcinfo 47.15        zone0 47147  ipcinfo 47.15

novatek: Manualy set SENSOR as imx415
majestic[1216]: First JPEG frame: 58203 bytes

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:

uImage            1,950,352 B (nightly, from mtd2)  ->  1,966,976 B (+16,624 B)   uImage: [1920KB/2048KB]
rootfs.squashfs   5,025,286 B used                  ->  5,025,310 B               rootfs.squashfs: [4908KB/5120KB]

majestic: majestic Lite master+6a1f8db doesn't use the zone yet on this platform. It draws no OSD on nt9856x (/api/v1/osd reports an overlay budget of 0) and has no node_hwmon_temp_celsius metric, so the WebUI temperature tile still says n/a. The zone is now there for it.

Not tested

  • NT98562: not built or run. Its config was identical to nt98566's and gets the same change.
  • NA51055: the NA51055 branch of the units fix is untested. No NA51055 hardware was available.

Scope

  • No kernel patches under general/package/all-patches/linux/ (those go to OpenIPC/linux)
  • No files specific to a single retail camera model (those go to OpenIPC/builder)
  • No probing or bring-up tooling (that goes to OpenIPC/ipctool)
  • Nothing under general/overlay/ or in a shared load_<vendor> script hardcodes a value specific to my board
  • Package sources come from an OpenIPC repository, and any version bump keeps at least the specificity of the pin it replaces (a new package should pin a full 40-character SHA)
  • No LD_PRELOAD, and no binaries that cannot be rebuilt from source
  • New code is selected by a defconfig, so CI actually builds it

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>
@DrSamjames
DrSamjames marked this pull request as ready for review November 24, 2026 19:08
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

nt9856x: Enable the SoC thermal sensor

⚙️ Configuration changes ✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Enable the existing Novatek ADC thermal driver in NT98562 and NT98566 kernel configs.
• Expose the nvt_thermal sysfs zone after the upstream millidegree fix merges.
• Validated on NT98566 hardware; NT98562 and NA51055 remain untested.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: Novatek board hardware sensing and thermal management.
  • This capability is the thermal-management outcome of the board kernel integration.
  • Its path begins at the changed kernel configuration and ends at the thermal framework; any thermal-zone consumer would remain within the same board sensing integration rather than constituting a separate deployment scope.
  • The presence of actual thermal zones is unresolved because the external kernel/device tree is not mounted.
  • This is a distinct user/system outcome—access to Novatek ADC channels through the IIO interface—but it is part of the same bounded board hardware-sensing integration as thermal management.
  • The path is separate because ADC readings and thermal control are different outcomes; no evidence shows an independent external integration or persistent-state consumer.
Sources

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[1459-1469]

CONFIG_THERMAL=y
# CONFIG_THERMAL_STATISTICS is not set
CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
CONFIG_THERMAL_OF=y
# CONFIG_THERMAL_WRITABLE_TRIPS is not set
CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE=y
# CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE is not set
# CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE is not set
# CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR is not set
# CONFIG_THERMAL_GOV_FAIR_SHARE is not set
CONFIG_THERMAL_GOV_STEP_WISE=y

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[2021-2023]

CONFIG_IIO=y
# CONFIG_IIO_BUFFER is not set
# CONFIG_IIO_CONFIGFS is not set

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[2092-2094]

# CONFIG_VF610_ADC is not set
CONFIG_NVT_ADC=y
# CONFIG_IIO_RESCALE is not set
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, the two board configurations explicitly disabled the thermal and IIO frameworks.
  • After, they enable established kernel configuration options and the Novatek ADC driver while leaving the individual sensor drivers and IIO buffer/trigger features disabled.
  • The changed correctness condition is the build-time selection of these existing kernel capabilities; no new algorithm, state machine, concurrency protocol, precedence rule, or coordinated invariant is introduced by the PR.
  • The external device-tree binding remains an unresolved activation prerequisite rather than newly implemented logic.
Sources

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[1459-1469]

CONFIG_THERMAL=y
# CONFIG_THERMAL_STATISTICS is not set
CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
CONFIG_THERMAL_OF=y
# CONFIG_THERMAL_WRITABLE_TRIPS is not set
CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE=y
# CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE is not set
# CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE is not set
# CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR is not set
# CONFIG_THERMAL_GOV_FAIR_SHARE is not set
CONFIG_THERMAL_GOV_STEP_WISE=y

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[2021-2023]

CONFIG_IIO=y
# CONFIG_IIO_BUFFER is not set
# CONFIG_IIO_CONFIGFS is not set

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[2092-2094]

# CONFIG_VF610_ADC is not set
CONFIG_NVT_ADC=y
# CONFIG_IIO_RESCALE is not set
Potential damage 🟡 Medium 🩹 Temporary loss

  • If the changed kernel configuration or its resulting driver integration regresses, the supported consequence is loss or degradation of temperature management and/or ADC sensor access when those capabilities are activated.
  • Rebuilding or reverting the image can restore code, and no persistent state corruption or irreversible external effect is evidenced.
  • Physical damage from absent thermal protection is not classified because the relevant thermal zones, trip points, and hardware behavior are not present in the inspected repository.
  • Code/image rollback or rebuilding can restore the enabled kernel capability.
  • Recovery of any missed thermal response is not automatic, and no state-repair or external-compensation mechanism is evidenced.
Sources

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[1459-1469]

CONFIG_THERMAL=y
# CONFIG_THERMAL_STATISTICS is not set
CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
CONFIG_THERMAL_OF=y
# CONFIG_THERMAL_WRITABLE_TRIPS is not set
CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE=y
# CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE is not set
# CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE is not set
# CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR is not set
# CONFIG_THERMAL_GOV_FAIR_SHARE is not set
CONFIG_THERMAL_GOV_STEP_WISE=y

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[2021-2023]

CONFIG_IIO=y
# CONFIG_IIO_BUFFER is not set
# CONFIG_IIO_CONFIGFS is not set

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[2092-2094]

# CONFIG_VF610_ADC is not set
CONFIG_NVT_ADC=y
# CONFIG_IIO_RESCALE is not set
Assessed commit 1e21a6b
Diagram

graph TD
  Configs["NT9856x configs"] --> Thermal["Thermal framework"] --> Driver["Novatek ADC driver"] --> Zone["Thermal sysfs zone"]
  Configs --> IIO["IIO framework"] --> Driver
  DT["Existing ADC node"] --> Driver
Loading
High-Level Assessment

Enabling the existing driver in both board configs is the narrowest approach; duplicating it or adding a firmware-side sensor reader would add unnecessary code. Merge OpenIPC/linux#323 first so the exposed sysfs temperature uses millidegrees.

Files changed (2) +484 / -4

Other (2) +484 / -4
nt98562.generic.configEnable NT98562 thermal and Novatek ADC support +242/-2

Enable NT98562 thermal and Novatek ADC support

• Enables THERMAL, IIO, and NVT_ADC, including the device-tree thermal support and step-wise governor selected by olddefconfig. Retains the newly visible disabled options; this target was not hardware-tested.

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config

nt98566.generic.configEnable NT98566 thermal and Novatek ADC support +242/-2

Enable NT98566 thermal and Novatek ADC support

• Enables the same thermal, IIO, and ADC options while retaining olddefconfig's newly visible settings. NT98566 hardware testing confirmed that the driver registers nvt_thermal and exposes temperature through thermal sysfs.

br-ext-chip-novatek/board/nt9856x/nt98566.generic.config

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. NT98562 thermal config ships without hardware testing 📘 Rule violation ≡ Correctness
Description
The NT98562 kernel config enables CONFIG_THERMAL, CONFIG_IIO and CONFIG_NVT_ADC and so changes
what the firmware does on a NT98562 camera, yet the PR description states that NT98562 was "not
built or run" and that its config "gets the same change" as NT98566 without its own test. The only
hardware evidence (dmesg, thermal_zone0/temp vs ipcinfo --temp, stream fps) comes from an
NT98566 (NA51089) board, so the NT98562 hunk rests on an assumption rather than output from a board.
The same unverified change also depends on OpenIPC/linux#323 being merged, which the NT98566 test
only covered by applying that fix locally.
Code

br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[R1459-1462]

+CONFIG_THERMAL=y
+# CONFIG_THERMAL_STATISTICS is not set
+CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS=0
+CONFIG_THERMAL_OF=y
Evidence
The diff enables thermal support in the NT98562 config. The PR description's Hardware tested section
covers only NT98566 (NA51089) and says NT98562 was not built or run, so the NT98562 change has no
board output behind it.

Rule 3: Hardware evidence is present and honest
br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[1456-1478]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR enables CONFIG_THERMAL, CONFIG_IIO and CONFIG_NVT_ADC in br-ext-chip-novatek/board/nt9856x/nt98562.generic.config, which changes firmware behaviour on NT98562 cameras. The PR description says NT98562 was not built or run, so this hunk has no hardware evidence (dmesg, thermal_zone0 reading vs ipcinfo --temp, stream behaviour).
## Fix Focus Areas
- br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[1456-1478]
- br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[2018-2246]
## Recommended Fix
Either boot an NT98562 board built from this config with the linux fix from OpenIPC/linux#323 applied, and add before/after thermal_zone0 and ipcinfo --temp output plus a streaming check to the PR description, or drop the nt98562.generic.config hunks from this PR and carry NT98562 in a follow-up that includes its own hardware evidence. Keep the PR description's NT98562 section consistent with whichever option is taken.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Thermal readings are 1000 times too low 🐞 Bug ≡ Correctness
Description
Enabling CONFIG_NVT_ADC builds the thermal driver from a moving kernel branch, while the PR
description says the unfixed driver reports degrees Celsius instead of the millidegrees required by
thermal sysfs. If either config is built before OpenIPC/linux#323 reaches that branch, the resulting
image has incorrect readings, and a later kernel-only fix does not by itself trigger another nightly
build.
Code

br-ext-chip-novatek/board/nt9856x/nt98566.generic.config[2093]

+CONFIG_NVT_ADC=y
Evidence
Both board defconfigs fetch the kernel from openipc/linux/archive/$(OPENIPC_KERNEL).tar.gz;
OPENIPC_KERNEL resolves to the moving novatek-nt9856x branch. CI refreshes that archive when it
builds, but its nightly gate can skip a build when the firmware commit and WebUI digest are
unchanged. The PR description identifies the missing upstream units fix and states that the current
driver returns whole degrees Celsius.

br-ext-chip-novatek/configs/nt98566_lite_defconfig[19-24]
br-ext-chip-novatek/configs/nt98562_lite_defconfig[19-24]
general/external.mk[10-11]
.github/workflows/build.yml[151-160]
.github/workflows/build.yml[362-374]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The newly enabled thermal driver produces readings in the wrong units if firmware builds before OpenIPC/linux#323 is present on the kernel branch.
## Fix Focus Areas
- br-ext-chip-novatek/board/nt9856x/nt98566.generic.config[2093-2093]
- br-ext-chip-novatek/board/nt9856x/nt98562.generic.config[2093-2093]
## Recommended Fix
Merge OpenIPC/linux#323 into `novatek-nt9856x` before merging these config changes, then verify fresh builds of both boards use the corrected kernel. If that ordering cannot be guaranteed, select a corrected kernel revision explicitly before enabling the driver.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@DrSamjames

Copy link
Copy Markdown
Contributor Author

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 adc@f0260000 node in their DTB. If one doesn't, the driver simply doesn't probe and nothing else changes. CI builds nt98562_lite either way. If the maintainers prefer, I'll drop the nt98562 hunk and keep this NT98566-only until someone with an NT98562 can test it.

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 novatek-nt9856x as it is at that moment. With #323 already on the branch, the first image with the driver enabled also has the corrected units. So please hold this one until #323 is in.

openipc-ai added a commit to OpenIPC/ipctool that referenced this pull request Nov 26, 2026
… 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 added a commit to OpenIPC/ipctool that referenced this pull request Nov 26, 2026
… 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 openipc-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@openipc-ai
openipc-ai merged commit 8ea2851 into OpenIPC:master Nov 26, 2026
40 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants