git: 49ba2878e6ec - main - asmc: report temperatures in deciKelvin

From: Abdelkader Boudih <seuros_at_FreeBSD.org>
Date: Sun, 15 Nov 2026 21:21:55 UTC
The branch main has been updated by seuros:

URL: https://cgit.FreeBSD.org/src/commit/?id=49ba2878e6ec412565caccd2d0990e9355123290

commit 49ba2878e6ec412565caccd2d0990e9355123290
Author:     Abdelkader Boudih <seuros@FreeBSD.org>
AuthorDate: 2026-11-15 21:12:52 +0000
Commit:     Abdelkader Boudih <seuros@FreeBSD.org>
CommitDate: 2026-11-15 21:12:52 +0000

    asmc: report temperatures in deciKelvin
    
    The handler returned the raw key's high byte, dropping the sign and
    fraction of the sp78 encoding, and published -1 on a failed read.
    
    Read through asmc_sensor_read() instead, convert to deciKelvin, and
    register the leaves as "IK". Changes the unit of dev.asmc.N.temp.*.
    
    MFC after:      3 days
    
    Reviewed by:    ngie
    
    Differential Revision:  https://reviews.freebsd.org/D61487
---
 share/man/man4/asmc.4      | 10 ++++++++--
 sys/dev/asmc/asmc_sysctl.c | 31 ++++++++++++-------------------
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/share/man/man4/asmc.4 b/share/man/man4/asmc.4
index 052a52eb0e27..5edae8f2b3d6 100644
--- a/share/man/man4/asmc.4
+++ b/share/man/man4/asmc.4
@@ -4,7 +4,7 @@
 .\"
 .\" SPDX-License-Identifier: BSD-2-Clause
 .\"
-.Dd September 6, 2026
+.Dd November 10, 2026
 .Dt ASMC 4
 .Os
 .Sh NAME
@@ -47,7 +47,13 @@ the
 .Va dev.asmc.temp
 sysctl MIB.
 .Pp
-All values are in degrees celsius.
+The sensors are reported in deciKelvin, the convention every other
+temperature source in the kernel follows, so
+.Xr sysctl 8
+displays them in degrees Celsius:
+.Bd -literal -offset indent
+dev.asmc.0.temp.TC0P: 42.1C
+.Ed
 .Sh SYSTEM FANS
 The
 .Va dev.asmc.fan.%d
diff --git a/sys/dev/asmc/asmc_sysctl.c b/sys/dev/asmc/asmc_sysctl.c
index 37dbfca11a0f..4be3483e9ea9 100644
--- a/sys/dev/asmc/asmc_sysctl.c
+++ b/sys/dev/asmc/asmc_sysctl.c
@@ -30,6 +30,8 @@
 #include <dev/asmc/asmcmmio.h>
 #include <dev/asmc/asmc_sysctl.h>
 
+#define	ASMC_ZERO_C_TO_DK	2731	/* deciKelvin at 0 degrees C */
+
 /*
  * Shutdown/sleep cause codes (MSSD/MSSP values).
  *
@@ -331,7 +333,7 @@ asmc_sysctl_add_temp(device_t dev, struct sysctl_ctx_list *ctx)
 		    SYSCTL_CHILDREN(sc->sc_temp_tree),
 		    OID_AUTO, sc->sc_temp_sensors[i],
 		    CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE, dev, i,
-		    asmc_temp_sysctl, "I",
+		    asmc_temp_sysctl, "IK",
 		    asmc_temp_desc(sc->sc_temp_sensors[i]));
 	}
 }
@@ -845,34 +847,25 @@ asmc_mb_sysctl_fanmanual(SYSCTL_HANDLER_ARGS)
 /*
  * Temperature functions.
  */
-static int
-asmc_temp_getvalue(device_t dev, const char *key)
-{
-	uint8_t buf[2];
-
-	/*
-	 * Check for invalid temperatures.
-	 */
-	if (asmc_key_read(dev, key, buf, sizeof(buf)) != 0)
-		return (-1);
-
-	return (buf[0]);
-}
-
 static int
 asmc_temp_sysctl(SYSCTL_HANDLER_ARGS)
 {
 	device_t dev = (device_t)arg1;
 	struct asmc_softc *sc = device_get_softc(dev);
-	int error, val;
+	int error, millic, deci;
 
 	if (arg2 < 0 || arg2 >= sc->sc_temp_count)
 		return (EINVAL);
 
-	val = asmc_temp_getvalue(dev, sc->sc_temp_sensors[arg2]);
-	error = sysctl_handle_int(oidp, &val, 0, req);
+	error = asmc_sensor_read(dev, sc->sc_temp_sensors[arg2], &millic);
+	if (error != 0)
+		return (error);
 
-	return (error);
+	/* Round to the tenth of a degree that "IK" prints, then offset. */
+	deci = millic >= 0 ? (millic + 50) / 100 : (millic - 50) / 100;
+	deci += ASMC_ZERO_C_TO_DK;
+
+	return (sysctl_handle_int(oidp, &deci, 0, req));
 }
 
 static int