Repository navigation
novatek: read NA51089 die temperature from the registers - #276
Conversation
The only Novatek reader was the vendor nvt_adc driver's thermal zone, which OpenIPC's kernel does not build, so `ipctool --temp` and `ipcinfo --temp` had nothing to say on an NT98562/NT98566. The die thermometer is channel 3 of the SAR ADC, which averages it into 0xF0260040 [24:16]. The ADC is found gated and idle, so it is started the way the RTOS side's thermal_channel_init() does: ADC clock on (CG 0xF0020074 bit 13), channel 3 continuous and the converter on (0xF0260000 bits 3 and 23). adc_en alone converts nothing. Only missing bits are set and nothing is turned off afterwards, so a converter the vendor driver runs is read as it stands. The per-die calibration is eFuse row 6 (EFUSE_THERMAL_TRIM_DATA). Its read sequence exists only in the SDK's binary otp_protected.o_shipped; this is that blob's efuse_open(0, 0, 0) / efuse_read() / efuse_close(), read mode throughout. A row carries two copies, each with a programmed (bit 15) and an invalidated (bit 14) flag, and efuse_readParamOps() takes the first good one. With none, or with the controller already open (the kernel mid-read, behind a semaphore userspace cannot take), the trim is nvt_adc's default, 231. The formula is nvt_adc's for every die but NA51055: (code - trim) * 1.319 + 30. The sysfs reader stays for the other dies, and now reports no reading instead of -237 degC when the file cannot be read. novatek_test models the eFuse controller and the ADC, and fails on a write that leaves read mode or clears a bit someone else set. Lab NT98566 + SC501AI on OpenIPC's 2026-10-21 nightly: trim 0xE4 (228) from the eFuse, the same value `echo trim > /proc/nvt_otp_op/otp_trim` prints; code 262 for 74.85 degC, steady over ten reads; eFuse left closed. ipcinfo grows 928 bytes with IPCHW_VENDORS=all, none with none.
PR Summary by QodoRead NA51089 die temperature directly from ADC registers
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Code Review by Qodo
1.
|
…to sysfs From review on #276: - A kernel without nvt_pinmux names the die through its device-tree model ("Novatek NA51089") but left chip_generation unset, so no temperature reader was installed. The model now sets it. - With /dev/mem withheld, the direct reader returned no reading even where the vendor driver's thermal zone works. It now falls back to it. - A read-done bit left standing by an earlier reader passed the wait for ours while DATA still held that reader's row. It is cleared before the trigger. - Nothing here can take the kernel's eFuse semaphore or lock out a second ipctool, so the row is read twice and taken only if both agree; an interleaved sequence costs the calibration, not a wrong one. The register accesses go through two small helpers, which pays for all of it: ipcinfo now grows 880 bytes over master (IPCHW_VENDORS=all), not 928. novatek_test covers each case with a model whose eFuse reads take a few polls to land. Lab NT98566: code 259, trim 228, 70.89 degC.
|
Qodo's four findings, all addressed in 0b5eb87:
The register accesses now go through two small helpers, which pays for all of the above: I re-ran it on the lab NT98566 with the CI toolchain build. |
#276's reader is not NA51089's alone. The SDK's plat-na51055, which serves both NA51055 and NA51084, matches plat-na51089 on everything the reader touches: - the CG and eFuse bases, and the ADC gate (CG_CLK_EN_REG1 bit 13); - adc_reg.h, byte for byte; - EFUSE_THERMAL_TRIM_DATA (0x105); - the eFuse open/read/close sequence and the row-6 decode, both decompiled from na51055/otp_protected.o_shipped. nvt_adc's thermal_get_temp() differs only on NA51055: 1.3 degC per code and a default trim of 259. Every later die uses 1.319 and 231, a default the SDK names for the NT98528, an NA51084. The reader is now installed for all three IDs, choosing NA51055's slope and default by ID. The NA51055 and NA51084 device-tree models set the ID. NA51090, NA51103 and NA51023 keep the sysfs reader. Not measured on NA51055 or NA51084 hardware. NA51089 is unchanged: lab NT98566 code 257, trim 228, 68.25 degC. ipcinfo +180 bytes (IPCHW_VENDORS=all).
Closes #275.
ipctool --tempandipcinfo --tempon an NT98562/NT98566 only knew the vendornvt_adcdriver's thermal zone. OpenIPC's kernel doesn't build that driver, so on a stock image both printed "Temperature cannot be retrieved".This reads the sensor directly, the way the HiSilicon readers do:
0xF0260040 [24:16]. The ADC clock (CG0xF0020074bit 13) is turned on if it is off, andain3_mode | adc_enare set in0xF0260000if they are missing. Settingadc_enalone converts nothing. Nothing is ever cleared, so an ADC the vendor driver already runs is read as it is.echo trim > /proc/nvt_otp_op/otp_trimprints as[6]. The read sequence is taken from the SDK's binaryotp_protected.o_shipped(efuse_open(0,0,0)/efuse_read/efuse_close) and stays in read mode throughout. If no copy in the row is valid, or the kernel has the controller open at that moment, the trim falls back tonvt_adc's default of 231.nvt_adc's formula for NA51089 is(code - trim) * 1.319 + 30. The script in pls add cpu temp for novatek cpu #275 uses the NA51055 slope (* 13 / 10) with a hand-picked trim.-237.Tested
Lab NT98566 + SC501AI, OpenIPC nightly 2026-10-21, arm32 build from the CI toolchain (hi3516cv100):
Raw code 262 and trim
0xE4= 228 give 74.85. There was no external thermometer, so the absolute value is only as good as the vendor formula.novatek_test(new, in the unit-tests job) simulates the eFuse controller and the ADC. It fails on any write that takes the eFuse out of read mode, or that clears a clock or ADC bit someone else set. I confirmed it fails whenain3_modeis dropped or MODE is set to 1.Size
ipcinfo, measured as the size step does: +928 bytes withIPCHW_VENDORS=all, 0 withnone. That's under the 1024-byte budget. It lands inipcinfobecauseipcinfo --tempis what #275 asks for.Only NA51089 is covered. NA51055 and NA51084 may share the layout, but they are untested.