From nobody Wed Nov 18 06:49:16 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jTsdn0k4mz6y5mP for ; Wed, 18 Nov 2026 06:49:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTsdm5llhz3Nty for ; Wed, 18 Nov 2026 06:49:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794984556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vtsGycdk94A/EIkMYaPAdUOlsJslUrFW9W/pz23VPDA=; b=HOohxsCG8DvpPkSjWqqXWhyBxt1H1rMoHsEV9hzsr7KJoE8OmT597csxfoB4U+tNTeRO14 wGRnJUQoEtd4Ta0HhmwzpWGqG7LzdlyOK+pR89Pwz3GWNZhbH7BlU+9C5InGYzGw8aD2f1 4xbjxdjX+5I0oG4YZIhDHD/Uu5qlXSzv9ZOiD5ShErva9uOsnav4KGvYJzugx6g38AmZn3 7D+MiomFYcZ/EuWaPTRLe79ED9I/pKAf1Xm+2QSOsVrn4zBx7L/4zH9i/ka3yIbKtfbCOz cVptJOMzooFX2ZYCj4orLRnow9Kzv6Aow+FBhEens5z51VJD7cWZB5jrAx8IIw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794984556; b=NASnIKT0gdXwmqxjbZfmKMz8EfVKHJzBg28+V34v1n8YB7nv0a9BCAgftwACVGE3t1iCW8 oc6XxQPzdztoWYmGPk1pYt8G0mevQOfvIKA2/2OOVKQDU8DKXJTYZLYefeJqymMwaD4AWq T8+D54PthLQhge+/GD5x0Mq6Rj4/RPNc/yuVzcOeknulKGyhCuDJVZDRT6mbJuwH1/DA5x TNoUzCHTUaWQdl6pN3nO5+rOfWAIhhTCeg2xEYrU9RBZdXX1e9gkFGP6WMW60ud/yUFYqt GXrcBAcFutOMHH1L1Wpk1j5XsukGoRkv6w2QOwc1y3Gbtr46rd5nb4TpiFMDUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794984556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=vtsGycdk94A/EIkMYaPAdUOlsJslUrFW9W/pz23VPDA=; b=WYOTwua2OlmVKwUmERu97O1XyYGlptHHbBI60jHumwZjOj/SGYEXwFHM7uEMm6cezJ4x2Y othpBRhV62z6KvVcwcD8xf2kjLEKSFqvphW7g8oP2cb9yaV/1QU9SWHLbdzt0PpXrpmdc6 e5bIpiFLFGibqNJLgTXO4tDv22xYLX65r3ef7qQjpGMuiXuMaXmExsbH/xVQjkl8CGT3ze DXGSIil46RICieFC2gcQnqHQ1k6BOhHE1NGSdaaJl9uXkLxu/1TqflPXNpLwS6r/Zuzmed g9yCx4Og1R2M1cSsO3IQshZsTUbAznTZy1hhN0egfPFpItlSm6xhhvgO/DIEQw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTsdm57tBz1H6F for ; Wed, 18 Nov 2026 06:49:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id ef6d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 18 Nov 2026 06:49:16 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 40e1cc39ad54 - main - aw_thermal: Add support for the H6 List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 40e1cc39ad54182161eba3912155eea6674fc671 Auto-Submitted: auto-generated Date: Wed, 18 Nov 2026 06:49:16 +0000 Message-Id: <6afd4a6c.ef6d.3040292a@gitrepo.freebsd.org> The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=40e1cc39ad54182161eba3912155eea6674fc671 commit 40e1cc39ad54182161eba3912155eea6674fc671 Author: Emmanuel Vadot AuthorDate: 2026-11-17 21:50:14 +0000 Commit: Emmanuel Vadot CommitDate: 2026-11-18 06:49:06 +0000 aw_thermal: Add support for the H6 Add the thermal sensor controller of the H6, which has two sensors, for the CPU and the GPU. The controller has other registers than the one of the supported SoCs. The efuse has the temperature of the factory test and the value of each sensor at this temperature, from which the calibration value of each sensor is computed and written to the controller. The alarm and shutdown thresholds and the interrupts are not supported yet. Tested on: Pine H64 (CPU and GPU temperatures, idle and under load) --- sys/arm/allwinner/aw_thermal.c | 116 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/sys/arm/allwinner/aw_thermal.c b/sys/arm/allwinner/aw_thermal.c index c3535c374a21..1bf15cd25542 100644 --- a/sys/arm/allwinner/aw_thermal.c +++ b/sys/arm/allwinner/aw_thermal.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -131,6 +132,32 @@ #define H5_INIT_GPU_ALARM 84 /* degC */ #define H5_INIT_GPU_SHUT 100 /* degC */ +/* + * The controller of the H6 has other registers than the one of the other SoCs + * and has the calibration values in its own registers (THS_CDATA). + */ +#define H6_THS_CTRL 0x00 +#define H6_THS_CTRL_ACQ(x) (((x) - 1) & 0xffff) +#define H6_THS_CTRL_PERIOD(x) ((((x) - 1) & 0xffff) << 16) +#define H6_THS_EN 0x04 +#define H6_THS_PER 0x08 +#define H6_THS_PER_SHIFT 12 +#define H6_THS_FILTER 0x30 +#define H6_THS_FILTER_EN (1 << 2) +#define H6_THS_FILTER_AVG4 (1 << 0) +#define H6_THS_CDATA 0xa0 +#define H6_CDATA_MASK 0xfff +#define H6_CDATA_DEFAULT 0x800 +#define H6_THS_DATA 0xc0 + +#define H6_ADC_ACQUIRE_TIME 48 /* 2us at 24MHz */ +#define H6_SAMPLE_PERIOD 480 /* 20us at 24MHz */ +#define H6_THERMAL_PER 365 /* 0.25s, average of 4 samples */ +#define H6_FT_TEMP_MASK 0xfff +#define H6_TEMP_OFFSET 187744 /* mdegC */ +#define H6_TEMP_SCALE 672 +#define H6_TEMP_FT_DEVIATION 7000 /* mdegC */ + #define TEMP_C_TO_K 273 #define SENSOR_ENABLE_ALL (SENSOR0_EN|SENSOR1_EN|SENSOR2_EN) #define SHUT_INT_ALL (SHUT_INT0_STS|SHUT_INT1_STS|SHUT_INT2_STS) @@ -175,6 +202,7 @@ struct aw_thermal_config { }; static int aw_thermal_v1_init(struct aw_thermal_softc *); +static int aw_thermal_h6_init(struct aw_thermal_softc *); static int a83t_to_temp(uint32_t val, int sensor) @@ -358,11 +386,36 @@ static const struct aw_thermal_config h5_config = { .calib0_mask = 0xffffffff, }; +static int +h6_to_temp(uint32_t val, int sensor) +{ + return ((H6_TEMP_OFFSET - (int)(val * H6_TEMP_SCALE / 10) + + H6_TEMP_FT_DEVIATION) / 1000); +} + +static const struct aw_thermal_config h6_config = { + .nsensors = 2, + .sensors = { + [0] = { + .name = "cpu", + .desc = "CPU temperature", + }, + [1] = { + .name = "gpu", + .desc = "GPU temperature", + }, + }, + .init = aw_thermal_h6_init, + .data_reg = H6_THS_DATA, + .to_temp = h6_to_temp, +}; + static struct ofw_compat_data compat_data[] = { { "allwinner,sun8i-a83t-ths", (uintptr_t)&a83t_config }, { "allwinner,sun8i-h3-ths", (uintptr_t)&h3_config }, { "allwinner,sun50i-a64-ths", (uintptr_t)&a64_config }, { "allwinner,sun50i-h5-ths", (uintptr_t)&h5_config }, + { "allwinner,sun50i-h6-ths", (uintptr_t)&h6_config }, { NULL, (uintptr_t)NULL } }; @@ -443,6 +496,69 @@ aw_thermal_v1_init(struct aw_thermal_softc *sc) return (0); } +/* + * The efuse has the temperature of the factory test (in 0.1 degC) and the + * value of each sensor at this temperature. Compute for each sensor the value + * that makes the controller report the factory temperature. + */ +static void +aw_thermal_h6_calibrate(struct aw_thermal_softc *sc) +{ + uint8_t buf[8]; + uint16_t caldata[4]; + phandle_t node; + uint32_t val; + int ft_temp, sensor_temp, cdata, shift, i; + + node = ofw_bus_get_node(sc->dev); + if (nvmem_get_cell_len(node, "calibration") != sizeof(buf) || + nvmem_read_cell_by_name(node, "calibration", buf, + sizeof(buf)) != 0) { + device_printf(sc->dev, "Cannot read THS efuse, " + "the sensors are not calibrated\n"); + return; + } + for (i = 0; i < nitems(caldata); i++) + caldata[i] = le16dec(&buf[i * 2]); + if (caldata[0] == 0) + return; + + ft_temp = (caldata[0] & H6_FT_TEMP_MASK) * 100; + for (i = 0; i < sc->conf->nsensors; i++) { + sensor_temp = H6_TEMP_OFFSET - + (caldata[i + 1] & H6_CDATA_MASK) * H6_TEMP_SCALE / 10; + cdata = H6_CDATA_DEFAULT - + ((sensor_temp - ft_temp) * 10 / H6_TEMP_SCALE); + if ((cdata & ~H6_CDATA_MASK) != 0) { + device_printf(sc->dev, "sensor%d is not calibrated\n", + i); + continue; + } + if (bootverbose) + device_printf(sc->dev, "%s: calibration 0x%x\n", + sc->conf->sensors[i].name, cdata); + shift = (i % 2) * 16; + val = RD4(sc, H6_THS_CDATA + (i / 2) * 4); + val &= ~(H6_CDATA_MASK << shift); + val |= cdata << shift; + WR4(sc, H6_THS_CDATA + (i / 2) * 4, val); + } +} + +static int +aw_thermal_h6_init(struct aw_thermal_softc *sc) +{ + aw_thermal_h6_calibrate(sc); + + WR4(sc, H6_THS_CTRL, H6_THS_CTRL_ACQ(H6_ADC_ACQUIRE_TIME) | + H6_THS_CTRL_PERIOD(H6_SAMPLE_PERIOD)); + WR4(sc, H6_THS_FILTER, H6_THS_FILTER_EN | H6_THS_FILTER_AVG4); + WR4(sc, H6_THS_PER, H6_THERMAL_PER << H6_THS_PER_SHIFT); + WR4(sc, H6_THS_EN, (1 << sc->conf->nsensors) - 1); + + return (0); +} + static int aw_thermal_gettemp(struct aw_thermal_softc *sc, int sensor) {