git: a7b3eb616cf3 - main - aw_sid: Add the CPU speed grade fuse of the H6 and H616

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Wed, 18 Nov 2026 06:49:12 UTC
The branch main has been updated by manu:

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

commit a7b3eb616cf36377de58b1376169801db3786bb8
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-11-17 19:31:12 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-18 06:48:37 +0000

    aw_sid: Add the CPU speed grade fuse of the H6 and H616
    
    The OPP tables of the H6 and H616 use the speed grade, stored in the
    efuse, to select the voltage of each OPP. Add it as a fuse so it can be
    read from the cpu_speed_grade nvmem cell, and expose it in a sysctl.
    
    The speed grade of the H616 is the 2 first bytes of the efuse and
    overlaps with the root key. Match the size too when looking up the
    fuse of an nvmem read.
    
    Tested on:      Pine H64 (sysctl dev.aw_sid.0.speedgrade)
---
 sys/arm/allwinner/aw_sid.c | 22 +++++++++++++++++++++-
 sys/arm/allwinner/aw_sid.h |  1 +
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/sys/arm/allwinner/aw_sid.c b/sys/arm/allwinner/aw_sid.c
index 0e4549265790..069821bac740 100644
--- a/sys/arm/allwinner/aw_sid.c
+++ b/sys/arm/allwinner/aw_sid.c
@@ -179,6 +179,15 @@ static struct aw_sid_efuse h6_efuses[] = {
 		.id = AW_SID_FUSE_ROOTKEY,
 		.public = true,
 	},
+	{
+		.name = "speedgrade",
+		.desc = "CPU Speed Grade",
+		.base = EFUSE_OFFSET,
+		.offset = 0x1c,
+		.size = 4,
+		.id = AW_SID_FUSE_SPEEDGRADE,
+		.public = true,
+	},
 };
 
 static struct aw_sid_efuse h616_efuses[] = {
@@ -200,6 +209,15 @@ static struct aw_sid_efuse h616_efuses[] = {
 		.id = AW_SID_FUSE_THSSENSOR,
 		.public = true,
 	},
+	{
+		.name = "speedgrade",
+		.desc = "CPU Speed Grade",
+		.base = EFUSE_OFFSET,
+		.offset = 0x00,
+		.size = 2,
+		.id = AW_SID_FUSE_SPEEDGRADE,
+		.public = true,
+	},
 };
 
 static struct aw_sid_efuse d1_efuses[] = {
@@ -417,8 +435,10 @@ aw_sid_read(device_t dev, uint32_t offset, uint32_t size, uint8_t *buffer)
 
 	sc = device_get_softc(dev);
 
+	/* Some cells overlap, the H616 speed grade is part of the rootkey. */
 	for (i = 0; i < sc->sid_conf->nfuses; i++)
-		if (offset == sc->sid_conf->efuses[i].offset) {
+		if (offset == sc->sid_conf->efuses[i].offset &&
+		    size == sc->sid_conf->efuses[i].size) {
 			fuse_id = sc->sid_conf->efuses[i].id;
 			break;
 		}
diff --git a/sys/arm/allwinner/aw_sid.h b/sys/arm/allwinner/aw_sid.h
index 2022b0a663c9..3e79f8b70fa1 100644
--- a/sys/arm/allwinner/aw_sid.h
+++ b/sys/arm/allwinner/aw_sid.h
@@ -29,6 +29,7 @@
 enum aw_sid_fuse_id {
 	AW_SID_FUSE_ROOTKEY = 1,
 	AW_SID_FUSE_THSSENSOR,
+	AW_SID_FUSE_SPEEDGRADE,
 };
 
 int	aw_sid_read_tscalib(uint32_t *, uint32_t *);