From 9d33d1483d9cf99992ba1a5eae56838b3a02676f Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin <6576495+widgetii@users.noreply.github.com> Date: Sat, 10 Oct 2026 09:16:29 +0300 Subject: [PATCH] ingenic: restore the temperature HAL wiring, and report degrees not millidegrees 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. --- src/hal/ingenic.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/hal/ingenic.c b/src/hal/ingenic.c index aad94600..492e5f96 100644 --- a/src/hal/ingenic.c +++ b/src/hal/ingenic.c @@ -1,5 +1,6 @@ #include "hal/ingenic.h" +#include #include #include @@ -322,13 +323,13 @@ unsigned long ingenic_totalmem(unsigned long *media_mem) { } float ingenic_get_temp() { - float ret = -237.0; char buf[16]; - if (line_from_file("/sys/class/thermal/thermal_zone0/temp", "(.+)", buf, - sizeof(buf))) { - ret = strtof(buf, NULL); - } - return ret; + if (!line_from_file("/sys/class/thermal/thermal_zone0/temp", "(.+)", buf, + sizeof(buf))) + return NAN; + /* Millidegrees, like everything under /sys/class/thermal. Returning the + * raw value would have reported a 45 C chip as 45000. */ + return strtof(buf, NULL) / 1000; } /* Honours the adapter number instead of re-deriving it from the chip name on @@ -378,6 +379,15 @@ void setup_hal_ingenic() { possible_i2c_addrs = ingenic_possible_i2c_addrs; i2c_adapter_nr = !strncmp(chip_name, "T40", 3) ? 1 : 0; open_i2c_sensor_fd = ingenic_open_i2c_fd; + /* Dropped by accident in 6e697a7, whose subject was the sensor clock. No + * Ingenic SoC up to and including T40 has a die temperature sensor, so no + * Ingenic kernel registers a thermal zone and the guard leaves + * hal_temperature NULL -- which is why nothing noticed. Kept in the shape + * the other sysfs-reading HALs use so that a kernel which ever grows a + * zone needs no change here, and so -t keeps answering honestly rather + * than through a function no caller can reach. */ + if (!access("/sys/class/thermal/thermal_zone0/temp", R_OK)) + hal_temperature = ingenic_get_temp; /* Also as a hook, because the call above only ever runs once: getchipname() * caches the chip id and returns before ever reaching here again. Anything * that gates the clock off afterwards — the vendor SDK does, on the way