]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
thermal: Convert .get_temp() return value to millicelsius
authorMarek Vasut <marek.vasut+renesas@mailbox.org>
Sat, 6 Sep 2025 00:05:33 +0000 (02:05 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 8 Oct 2025 19:54:59 +0000 (13:54 -0600)
Linux kernel .get_temp() callback reports values in millicelsius,
U-Boot currently reports them in celsius. Align the two and report
in millicelsius. Update drivers accordingly. Update callsites that
use thermal_get_temp() as well.

The 'temperature' command now reports temperature in millicelsius
as well, with additional accuracy. This changes command line ABI
slightly.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
Reviewed-by: David Zang <davidzangcs@gmail.com>
[trini: Update test/cmd/temperature.c]
Signed-off-by: Tom Rini <trini@konsulko.com>
14 files changed:
arch/arm/mach-imx/cpu.c
arch/arm/mach-imx/imx8ulp/soc.c
cmd/temperature.c
drivers/cpu/imx8_cpu.c
drivers/mmc/omap_hsmmc.c
drivers/thermal/imx_scu_thermal.c
drivers/thermal/imx_thermal.c
drivers/thermal/imx_tmu.c
drivers/thermal/rcar_gen3_thermal.c
drivers/thermal/thermal_sandbox.c
drivers/thermal/ti-bandgap.c
drivers/thermal/ti-lm74.c
include/thermal.h
test/cmd/temperature.c

index 17de9ff98ec90ba4423d4c5d1229dec666cf7ffa..cc215b771eff06e65fe7e4b784bc39cd2adeda2d 100644 (file)
@@ -230,6 +230,7 @@ int print_cpuinfo(void)
        ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
        if (!ret) {
                ret = thermal_get_temp(thermal_dev, &cpu_tmp);
+               cpu_tmp /= 1000;
 
                if (!ret)
                        printf(" at %dC", cpu_tmp);
index 7640f9b84dadb15c41cd191202eb41cb4e2649ee..04c6f0641304d2794bc44beab4288b6964b0a4ef 100644 (file)
@@ -279,7 +279,7 @@ int print_cpuinfo(void)
        if (!ret) {
                ret = thermal_get_temp(udev, &temp);
                if (!ret)
-                       printf("CPU current temperature: %dC\n", temp);
+                       printf("CPU current temperature: %dC\n", temp / 1000);
                else
                        debug(" - failed to get CPU current temperature\n");
        } else {
index 41e422fc937d9073a3bf0dad7c3893e116619093..c145d019364fb9f552f2c24e6b24aaf901ee058b 100644 (file)
@@ -32,7 +32,7 @@ static int do_get(struct cmd_tbl *cmdtp, int flag, int argc,
        if (ret)
                return CMD_RET_FAILURE;
 
-       printf("%s: %d C\n", dev->name, temp);
+       printf("%s: %d mC\n", dev->name, temp);
 
        return CMD_RET_SUCCESS;
 }
index 630919a3642984dea1eb16fdb1d33a41696af801..5f17122c36c5c87a27f24c66da1858fd6422a1a8 100644 (file)
@@ -192,7 +192,7 @@ static int cpu_imx_get_temp(struct cpu_imx_plat *plat)
                return 0xdeadbeef;
        }
 
-       return cpu_tmp;
+       return cpu_tmp / 1000;
 }
 #else
 static int cpu_imx_get_temp(struct cpu_imx_plat *plat)
index 92bc72b267c929f22e8fe2fa0843a98983c29152..ae7420806432a3dc0d78d0cf0777d27d53c19c1e 100644 (file)
@@ -651,6 +651,7 @@ static int omap_hsmmc_execute_tuning(struct udevice *dev, uint opcode)
                printf("Couldn't get temperature for tuning\n");
                return ret;
        }
+       temperature /= 1000;
        val = readl(&mmc_base->dll);
        val |= DLL_SWT;
        writel(val, &mmc_base->dll);
index fc2b0e227b2934584b4c8a6cef4ff5d178c924ed..6b0b1d10d9ddf70fe403c04985ab59cb20375abf 100644 (file)
@@ -72,7 +72,7 @@ int imx_sc_thermal_get_temp(struct udevice *dev, int *temp)
                        break;
        }
 
-       *temp = cpu_temp / 1000;
+       *temp = cpu_temp;
 
        return 0;
 }
index ea1fcc3dcb295e5fcf66d1a2ed0c2d7d4ce09a0d..d04035950ee15b43cdd7df63537440c7acc07427 100644 (file)
@@ -223,7 +223,7 @@ int imx_thermal_get_temp(struct udevice *dev, int *temp)
                cpu_tmp = read_cpu_temperature(dev);
        }
 
-       *temp = cpu_tmp;
+       *temp = cpu_tmp * 1000;
 
        return 0;
 }
index 70d002aee25ba94271d687c45bd1cc8833ebc31d..51a072e23c6c798629383b94a789bc6778b06733 100644 (file)
@@ -245,7 +245,7 @@ int imx_tmu_get_temp(struct udevice *dev, int *temp)
                        return ret;
        }
 
-       *temp = cpu_tmp / 1000;
+       *temp = cpu_tmp;
 
        return 0;
 }
index 522337c8395128a1e8ae87c7195518710e4bd771..45e590535a046a83811f92cdf815b5007ade6778 100644 (file)
@@ -160,7 +160,7 @@ static int rcar_gen3_thermal_get_temp(struct udevice *dev, int *temp)
        const struct equation_set_coef *coef;
        int adj, decicelsius, reg, thcode;
 
-       /* Read register and convert to degree Celsius */
+       /* Read register and convert to millidegree Celsius */
        reg = rcar_gen3_thermal_read(tsc, REG_GEN3_TEMP) & CTEMP_MASK;
 
        if (reg < tsc->thcode[1]) {
@@ -183,8 +183,8 @@ static int rcar_gen3_thermal_get_temp(struct udevice *dev, int *temp)
 
        /* Guaranteed operating range is -40C to 125C. */
 
-       /* Reporting is done in degree Celsius */
-       *temp = (decicelsius * 100 + adj * 1000) / 1000;
+       /* Reporting is done in millidegree Celsius */
+       *temp = decicelsius * 100 + adj * 1000;
 
        return 0;
 }
index b7c567d76cd75e1bddd5ef60369814151eccf35e..2e1f1559e530bd004fa8c7e58bb9955153d48527 100644 (file)
@@ -12,7 +12,7 @@
 static int sandbox_thermal_get_temp(struct udevice *dev, int *temp)
 {
        /* Simply return 100 deg C */
-       *temp = 100;
+       *temp = 100 * 1000;
 
        return 0;
 }
index 0ea17a909dd7df6906ad401ce07a2647459d5ead..dc869f108e4f43772483d457221280f5c739798c 100644 (file)
@@ -163,7 +163,7 @@ static int ti_bandgap_get_temp(struct udevice *dev,  int *temp)
        struct ti_bandgap *bgp = dev_get_priv(dev);
 
        bgp->adc_val = 0x3ff & readl(bgp->base + CTRL_CORE_TEMP_SENSOR_MPU);
-       *temp = dra752_adc_to_temp[bgp->adc_val - DRA752_ADC_START_VALUE];
+       *temp = dra752_adc_to_temp[bgp->adc_val - DRA752_ADC_START_VALUE] * 1000;
 
        return 0;
 }
index 0310d3330c015a5e90ee5cf114efc57fed188375..104c27429f4a54e5ff3338b3ec2763293df4a5c0 100644 (file)
@@ -28,7 +28,7 @@ static int ti_lm74_get_temp(struct udevice *dev, int *temp)
 
        raw = ((buf[0] << 8) + buf[1]) >> 3;
 
-       *temp = (((int)raw * 125) + 1000) / 2000;
+       *temp = (((int)raw * 125) + 1000) / 2;
 
        return 0;
 }
index 52a3317fd5485810d697c97ce2b2aa2f3603e305..74b1c62466b20305d509ede0c3181d7ad342b10b 100644 (file)
@@ -25,7 +25,7 @@ struct dm_thermal_ops {
         * It will enable and initialize any Thermal hardware as necessary.
         *
         * @dev:        The Thermal device
-        * @temp:       pointer that returns the measured temperature
+        * @temp:       pointer that returns the measured temperature in millidegree Celsius
         */
        int (*get_temp)(struct udevice *dev, int *temp);
 };
index 309693aa1e807cba867afe358cde6ed08dc5bc34..464d055b94d618c148a568feac36ec1323046aa6 100644 (file)
@@ -27,7 +27,7 @@ static int dm_test_cmd_temperature(struct unit_test_state *uts)
        /* Test that "temperature get thermal" returns expected value */
        console_record_reset();
        ut_assertok(run_command("temperature get thermal", 0));
-       ut_assert_nextline("thermal: 100 C");
+       ut_assert_nextline("thermal: 100000 mC");
        ut_assert_console_end();
 
        return 0;