Repository navigation
novatek: read nvt_adc's thermal zone when the kernel has one, and the trim once - #296
Conversation
… 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.
94dabfb to
db919d8
Compare
PR Summary by QodoPrefer Novatek thermal zones and cache eFuse trim
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
…k, store the trim once From review: a driver that unregisters its zone leaves a gap, and the scan stopped at the first missing number; a kernel that withholds /dev/mem got no reading even with a readable zone of another type, which the reader before this change returned; and the cache held the default for a moment before the fused value replaced it.
|
Qodo's review, point by point (fixed in 9391cc5; the second hardware run in the description covers it):
|
Problem
On NA51055, NA51084 and NA51089,
hal_temperaturereads the die sensor through/dev/mem(#276). Every call:The kernel orders eFuse access with a semaphore that userspace cannot take. It also reads the eFuse at run time, not only at boot. These vendor modules in
novatek-osdrv-nt9856ximport eFuse functions:kdrv_h26x.koh26x_efuse_checkkdrv_videoenc_set,kdrv_videodec_setkdrv_builtin.koefuse_check_available,efuse_check_available_extendh26x_efuse_check,cnn_eng_validkdrv_ai.koefuse_check_availablenvt_usb2dev.koefuse_readParamOpsIf our sequence overlaps one of these, the kernel can read our row, or have the controller closed under it. The guard that skips an already-open controller is check-then-act. The double read protects our own result, not the kernel's.
This hasn't caused a failure yet: no caller reads the temperature repeatedly. That changes with OpenIPC/majestic#386, which asks for the temperature in majestic's
/metricson nt9856x, so it would be read on every scrape while the camera is streaming.OpenIPC/firmware#2950 enables
nvt_adcon nt9856x, and OpenIPC/linux#323 makes itsnvt_thermalzone report millidegrees. Once both land, the old fallback, which takesthermal_zone0as whole degrees, would report 47147 °C.Change
nvt_thermalzone: that zone is the reading, and no register is touched. The kernel reads the trim once, at probe, under its own lock. The zone is found by its type, not by assumingthermal_zone0, and the scan ofthermal_zone0..15steps over missing numbers. If the zone exists but can't be read, the result is "no reading", not a fallback to the registers./sys/class/thermal): the register path works as before. The one difference is that a completed trim read is now kept for the rest of the process./dev/mem),thermal_zone0of any type is used, as before.nvt_adc's millidegree values are 30000 + k·1319, or 30000 + k·1300 on NA51055. The only one inside that window is 100, i.e. an NA51055 at 0.1 °C.nvt_adcnow says "until nt9856x: enable the SoC thermal sensor firmware#2950".Tests
novatek_testpasses, as do the other unit tests (cYAML_test,reginfo_test,longse_test,anyka_test,ambarella_test,sstar_test,hal_hisi_test,axera_test). New cases:mem_reg()), in millidegrees, in whole degrees, and below zero;thermal_zone1when zone0 is another type, and when zone0 is missing;/dev/memis withheld;Two existing cases changed a fuse in the middle of one process. They now reset the cache first, to stand for a new process.
Hardware: lab NT98566 (NA51089) + SC501AI,
nightly-20261021-57ae948, kernel 4.19.91. That image has no/sys/class/thermal. Static arm32 builds of this branch and ofmaster.The zone cases (C1 to D) run
ipcinfothrough a small helper that gives it a private mount namespace with a tmpfs over/sys/class. The rest of the camera never sees the fake zone. This exercises the realline_from_file()regexes against files with trailing newlines, which the unit test's mock does not.ADC_CTRL(0xF0260000) is private to the ADC, so it is put back to its boot value before the zone cases: any register-path read would visibly set it to0x5080F008.masteragree. The onemasterreading of 73.53 is one ADC step (1.32 °C) lower.ADC_CTRLstays at its boot value through C1 to C5. Onlymaster(D) and the fallback for a zone of another type (E) start the ADC.After the review fixes, same camera and same method, with a numbering gap added (C6):
Not tested
nvt_adczone. That needs a kernel with nt9856x: enable the SoC thermal sensor firmware#2950 and iio: adc: nvt_adc: report the thermal zone in millidegrees linux#323, and I didn't flash one onto this camera. Its only recovery path is PoE. The contributor's NT98566 output in nt9856x: enable the SoC thermal sensor firmware#2950 shows the zone's type (nvt_thermal) and its millidegree values, which is what this branch reads.ipcinforeads the temperature once per process, so only the unit test shows that a second call does no eFuse sequence.Size
ipcinfo, measured the way theipcinfo sizestep does (shared,SKIP_VERSION,text + data + bss) with the OpenIPC arm musl toolchain:IPCHW_VENDORS=all: 54322 → 54824 (+502)IPCHW_VENDORS=none: 38508 → 38508 (0)