git: 0aa629f69dbe - stable/13 - arm64, qoriq_therm: fix handling sites on version 1 and 2

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 27 Jul 2022 00:14:02 UTC
The branch stable/13 has been updated by bz:

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

commit 0aa629f69dbe9b78aac2c008fdb0e8201b782154
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-07-10 13:38:56 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-07-26 22:41:47 +0000

    arm64, qoriq_therm: fix handling sites on version 1 and 2
    
    For version 2 extend the TMUV2_TMSAR() write loop over all site_ids
    registered for a particular SoC and actually use the site_id rather
    than always just the first [0] (which for the LX2080 would be a
    problem given there is no site0).
    
    Later, while version 2 adds the SITEs to enable to TMSR in bits 0..<n>,
    version 1 (e.g., LS1028, LS1046, LS1088) add MSITEs to TMR
    bits 16..31 or rather 15..0(16-<n>).  Adjust the loops to only enable
    the site_ids listed for the particular SoC for monitoring.  This now
    also deals with sparse site_ids (not starting at 0, or not being
    contiguous).
    
    Sponsored by:   Traverse Technologies (providing Ten64 HW for testing)
    Reviewed by:    mmel
    Differential Revision: https://reviews.freebsd.org/D35764
    
    (cherry picked from commit fe88072dc69fcd64b42d8512ad214c0fe009ad8e)
---
 sys/arm64/qoriq/qoriq_therm.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/sys/arm64/qoriq/qoriq_therm.c b/sys/arm64/qoriq/qoriq_therm.c
index 1374a6d96558..c5a79fa3287b 100644
--- a/sys/arm64/qoriq/qoriq_therm.c
+++ b/sys/arm64/qoriq/qoriq_therm.c
@@ -434,8 +434,8 @@ qoriq_therm_attach(device_t dev)
 		WR4(sc, TMUV2_TMTMIR, 0x0F);	/* disable */
 		/* these registers are not of settings is not in TRM */
 		WR4(sc, TMUV2_TEUMR(0), 0x51009c00);
-		for (int i = 0; i < 7; i++)
-			WR4(sc, TMUV2_TMSAR(0), 0xE);
+		for (int i = 0; i < sc->ntsensors; i++)
+			WR4(sc, TMUV2_TMSAR(sc->tsensors[i].site_id), 0xE);
 	}
 
 	/* prepare calibration tables */
@@ -446,10 +446,14 @@ qoriq_therm_attach(device_t dev)
 		goto fail;
 	}
 	/* start monitoring */
-	sites = (1U << sc->ntsensors) - 1;
+	sites = 0;
 	if (sc->ver == 1) {
+		for (int i = 0; i < sc->ntsensors; i++)
+			sites |= 1 << (15 - sc->tsensors[i].site_id);
 		WR4(sc, TMU_TMR, 0x8C000000 | sites);
 	} else {
+		for (int i = 0; i < sc->ntsensors; i++)
+			sites |= 1 << sc->tsensors[i].site_id;
 		WR4(sc, TMUV2_TMSR, sites);
 		WR4(sc, TMU_TMR, 0x83000000);
 	}