[PATCH] thermal: imx8mm_thermal: wait for a valid measurement

From: Marcus Folkesson
Date: Fri Sep 30 2022 - 06:03:23 EST


Check if first measurement is still pending or if temperature is out of
range.
Return and try again later if that is the case.

Fixes: 5eed800a6811 ("thermal: imx8mm: Add support for i.MX8MM thermal monitoring unit")
Signed-off-by: Marcus Folkesson <marcus.folkesson@xxxxxxxxx>
---
drivers/thermal/imx8mm_thermal.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c
index af666bd9e8d4..9dd60b940ef4 100644
--- a/drivers/thermal/imx8mm_thermal.c
+++ b/drivers/thermal/imx8mm_thermal.c
@@ -62,9 +62,15 @@ static int imx8mm_tmu_get_temp(void *data, int *temp)
{
struct tmu_sensor *sensor = data;
struct imx8mm_tmu *tmu = sensor->priv;
- u32 val;
+ bool ready;
+ unsigned long val;
+
+ val = readl_relaxed(tmu->base + TRITSR);
+ ready = test_bit(probe_status_offset(1), &val);
+ if (!ready)
+ return -EAGAIN;

- val = readl_relaxed(tmu->base + TRITSR) & TRITSR_TEMP0_VAL_MASK;
+ val = val & TRITSR_TEMP0_VAL_MASK;
*temp = val * 1000;
if (*temp < VER1_TEMP_LOW_LIMIT)
return -EAGAIN;
--
2.37.1