Skip to content

pls add cpu temp for novatek cpu #275

Closed

Description

@sansarus

tested at NT98566 (XM ipg-N8S )

root@nt98566-imx415:~# nt1
ain_avg_out=262, trim=236, temp=63 °C

trim - calibration value at eFuse (do not know way to read it but
https://github.com/OpenIPC/linux/blob/novatek-nt9856x/drivers/iio/adc/nvt_adc.c
used
#define DEFAULT_THERMAL_LEVEL 259
#define DEFAULT_THERMAL_528_LEVEL 231
values
)

#!/bin/sh
# nvt_adc_devmem.sh - Read Novatek NA51089/NT98566 CPU temperature via devmem
# No kernel module required. Enables ADC clock, configures ADC, reads thermal sensor.
# Tested on NT98566 (NA51089). trim_value = 236 for this chip.

# --- Step 1: Enable ADC clock (bit 13 in CG_CLK_EN_REG1) ---
VAL=$(devmem 0xf0020074)                                    # CG_CLK_EN_REG1: read current value
VAL_DEC=$(printf "%d" "$VAL")                                # convert hex to decimal
NEW=$(( VAL_DEC | 0x2000 ))                                  # set bit 13 (ADC clock enable)
devmem 0xf0020074 32 $(printf "0x%08X" "$NEW")               # CG_CLK_EN_REG1: write back with bit 13 set

# --- Step 2: Enable ADC interrupts (bits 0-6) ---
devmem 0xf0260008 32 0x0000007F                              # ADC_INTCTRL: enable ain0-3 + aintr0-2

# --- Step 3: Configure ADC: ain0-3_mode=1, clkdiv=1, adc_en=1 ---
devmem 0xf0260000 32 0x5080100F                              # ADC_CTRL: channels on, clkdiv=1, ADC enabled

# --- Step 4: Wait for first conversion ---
sleep 1

# --- Step 5: Read thermal sensor register ---
RAW=$(devmem 0xf0260040)                                     # THERMAL_SENSOR_CONFIGURE: read raw value
RAW_DEC=$(printf "%d" "$RAW")                                # convert hex to decimal
AIN_AVG=$(( (RAW_DEC >> 16) & 0x1FF ))                       # extract ain_avg_out (bits 24:16, 9 bits)

# --- Step 6: Convert to Celsius (NA51089 formula) ---
TRIM=236                                                     # eFuse trim value for this chip (calibrated)
TEMP=$(( (AIN_AVG - TRIM) * 13 / 10 + 30 ))                  # temp = (ain_avg_out - trim) * 13 / 10 + 30

# --- Output ---
echo "ain_avg_out=$AIN_AVG, trim=$TRIM, temp=${TEMP} °C"

pure driver may compile as kernel module

CONFIG_IIO=m
CONFIG_NVT_ADC=m
CONFIG_THERMAL=m

insmod industrialio.ko
insmod thermal_sys.ko
insmod nvt_adc.ko
cat /sys/class/thermal/thermal_zone0/temp

Activity

  1. widgetii commented on Nov 10, 2026

    @widgetii
    Member

    Thanks. That register path is the right one, and #276 builds it into ipctool --temp / ipcinfo --temp for NA51089. It differs from your script in two ways:

    • Trim comes from the eFuse. It's row 6 of the eFuse controller at 0xF0660000. The read sequence is in the SDK's binary otp_protected.o_shipped, and ipctool now runs it itself, read-only. Your kernel may already show the value: echo trim > /proc/nvt_otp_op/otp_trim; dmesg | tail -8 prints it as [6] data = 0x.... Our lab NT98566 has 0xe4 = 228.
    • The slope is 1.319, not 1.3. nvt_adc uses * 13 / 10 only for NA51055. On NA51089 it's (code - trim) * 1319 / 1000 + 30.

    It also only adds ain3_mode | adc_en to whatever is already in ADC_CTRL, rather than writing 0x5080100F over it. It doesn't need the interrupt enables or the 1 s sleep, because the first average arrives in well under a millisecond.

    On the jumping thermal_zone0 values you posted earlier (66, 43, 45, 12, 20): I couldn't reproduce them. On our NT98566 the raw average stays within ±1 code over 1500 back-to-back reads, both with the nvt_adc register settings and with these. If you still see the swings, please post a few raw reads from your board:

    for i in 1 2 3 4 5 6 7 8 9 10; do devmem 0xf0260040; done

    Once #276 is merged, the rolling latest release picks it up and ipctool --temp will use it. Please post what it reads on your IMX415 board alongside your script's number.

  2. sansarus commented on Nov 10, 2026

    @sansarus
    MemberAuthor

    nt1
    ain_avg_out=263, trim=236, temp=65 °C
    root@nt98566-imx415:#
    root@nt98566-imx415:
    #
    root@nt98566-imx415:~# for i in 1 2 3 4 5 6 7 8 9 10; do devmem 0xf0260040; done
    0x01070030
    0x01080030
    0x01070030
    0x01070030
    0x01070030
    0x01070030
    0x01080030
    0x01080030
    0x01080030
    0x01080030

    ipctool --temp
    The ipctool installed as remote GitHub plugin
    Temperature cannot be retrieved

    my temp from 66 to 12 - with freezer.....just to see real temp changes

  3. sansarus commented on Nov 10, 2026

    @sansarus
    MemberAuthor

    echo trim > /proc/nvt_otp_op/otp_trim; dmesg | tail -8
    [0] data = 0x000012e4
    [1] data = 0x000002a4
    [2] data = NULL
    [4] data = 0x00000383
    [3] data = 0x0000005b
    [5] data = NULL
    [6] data = 0x000000eb
    [7] data = 0x00000006

  4. widgetii commented on Nov 10, 2026

    @widgetii
    Member

    Thanks, that settles the calibration for your chip: [6] = 0xeb is the thermal trim, 235. That's one below the 236 you picked. Ours reads 0xe4 = 228, so it does differ from die to die.

    With NA51089's formula, the ain_avg_out=262 from your first post works out to:

    (262 - 235) * 1.319 + 30 = 65.6 °C
    

    Your script gave 63, because it used 236 and the NA51055 slope of 1.3.

    You don't need the proc file for this. ipctool now reads row 6 directly from the eFuse controller, the same value otp_trim prints, so ipctool --temp from the current latest release (#276) should land on that figure without any hardcoded trim. Please post its output next to a devmem 0xf0260040 from your camera. If thermal_zone0 still jumps around on your build, a few raw reads would show whether that's the board or the driver.

    NA51055 (NT9852x) and NA51084 (NT98528/529) are now covered too (#277).

  5. added a commit that references this issue on Nov 12, 2026
    0a708af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions