Skip to content

ingenic: restore the temperature HAL wiring, and report degrees not millidegrees - #241

Merged
widgetii merged 1 commit into
masterfrom
ingenic/restore-temperature-hal
Oct 10, 2026
Merged

widgetii merged 1 commit into
masterfrom
ingenic/restore-temperature-hal

Conversation

@widgetii

Copy link
Copy Markdown
Member

ingenic_get_temp() has been dead code since May 2023.

6e697a7 ("[INGENIC] Fix enable sensor clock") deleted the two lines in
setup_hal_ingenic() that assigned hal_temperature behind the same
access() guard the allwinner, rockchip, novatek, fh and gm HALs use. The
subject of that commit was the sensor clock; the deletion looks like collateral.

Nothing reported it, and that is the interesting part: no Ingenic SoC up to and
including T40 has a die temperature sensor, so no Ingenic kernel registers a
thermal zone, so the guard would have left hal_temperature NULL anyway. -t
answered "Temperature cannot be retrieved" before this change and answers it
after. The wiring is restored because it is the shape every sibling HAL has —
a kernel that ever grows a zone then needs no change here — and because a
function no caller can reach is a trap for the next reader.

Being unreachable, it had also kept two bugs:

  • it returned the sysfs value verbatim, where every sibling divides by 1000, so
    a 45 °C chip would have been reported as 45000;
  • on a failed read it returned -237.0, which -t would have printed as a
    temperature instead of letting gethwtemp()'s NAN produce the honest error.

Verification

Builds, all four as CI does them: native, arm32 (hi3516cv100 musleabi), mips32
(ingenic-t31 musl) and arm64 (Bootlin aarch64 musl) — clean, no new warnings.
cYAML_test and reginfo_test pass; tools/test_pipeline.sh passes.

On hardware — lab T31 (T31L, SC2332, kernel 3.10.14__isvp_swan_1.0__), mips32
build copied to the camera:

--- stock ipcinfo --temp:
Temperature cannot be retrieved
rc=1
--- patched --temp:
Temperature cannot be retrieved
rc=1
--- patched chip name:
t31l

Unchanged, as intended. /sys/class/thermal does not exist on that board at
all — with CONFIG_THERMAL off the class is never registered — so the guard is
what keeps --temp honest, and the reader itself cannot be exercised there.
It was exercised instead against a real zone through libipchw on the build
host: 27800 → 27.80, and with the zone hidden under unshare -rm plus a
tmpfs over /sys/class/thermal → NAN.

Note

The same dead -237.0 sentinel is in novatek.c, fh.c, gm.c,
allwinner.c and rockchip.c. It is near-unreachable there too (the access()
guard, and /1000 turns it into -0.237), so it is left alone here rather than
widening this diff — happy to sweep it separately if wanted.

…illidegrees

6e697a7 ("[INGENIC] Fix enable sensor clock") deleted the two lines in
setup_hal_ingenic() that assigned hal_temperature behind the same
access() guard the allwinner, rockchip, novatek, fh and gm HALs use.
Nothing was reported, because no Ingenic SoC up to and including T40 has
a die temperature sensor and so no Ingenic kernel registers a thermal
zone: the guard would have left hal_temperature NULL anyway, which is
also why ingenic_get_temp() has sat unreferenced ever since.

Being unreachable, it also kept two bugs. It returned the sysfs value
verbatim where every sibling HAL divides by 1000, so a 45 C chip would
have been reported as 45000, and on a failed read it returned -237.0,
which -t would have printed as a temperature instead of letting
gethwtemp()'s NAN produce the honest "Temperature cannot be retrieved".

Verified on the lab T31 (T31L, kernel 3.10.14 isvp_swan): /sys/class/
thermal does not exist there, so --temp still exits 1 with "Temperature
cannot be retrieved", unchanged from the stock build. The reader itself
was exercised against a real zone on the build host, 27800 -> 27.80, and
with the zone hidden in a private mount namespace -> NAN. Native, mips32
and arm32 builds clean; cYAML_test and reginfo_test pass.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Restore Ingenic temperature HAL wiring and report degrees Celsius

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Restore guarded temperature callback registration so Ingenic can use a thermal zone when
 available.
• Convert sysfs millidegrees to degrees Celsius and return NAN when reading fails.
• Preserve the existing unavailable-temperature response on devices without a thermal zone.
Diagram

graph TD
  CLI["Temperature CLI"] --> HW["gethwtemp"] --> Reader["Ingenic reader"] --> Sysfs[("Thermal sysfs")]
  Setup["Ingenic setup"] -->|checks readability| Sysfs
  Setup -->|registers if readable| Reader
Loading
High-Level Assessment

Keep the guarded registration: it matches sibling HALs and preserves the current behavior on Ingenic devices without a thermal zone. Unconditional registration could rely on the reader returning NAN, but would discard that established availability check without a clear benefit.

Files changed (1) +16 / -6

Bug fix (1) +16 / -6
ingenic.cRestore guarded temperature registration and correct reader results +16/-6

Restore guarded temperature registration and correct reader results

• Registers ingenic_get_temp when the thermal-zone temperature entry is readable. The reader now converts millidegrees to degrees Celsius and returns NAN instead of a printable sentinel when the read fails.

src/hal/ingenic.c

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@widgetii
widgetii merged commit 51a0af9 into master Oct 10, 2026
5 checks passed
@widgetii
widgetii deleted the ingenic/restore-temperature-hal branch October 10, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant