Re: [PATCH v3] thermal: qcom: tsens: atomic temperature read with hardware-guided retries
From: Daniel Lezcano
Date: Tue May 12 2026 - 05:24:42 EST
Hi Priyansh,
On 5/11/26 09:10, Priyansh Jain wrote:
The existing TSENS temperature read logic polls the valid bit and then
reads the temperature register. When temperature reads are triggered
at very short intervals, this can race with hardware updates and allow
the temperature field to be read while it is still being updated.
In this case, the valid bit may already be asserted even though the
temperature value is transitioning, resulting in an incorrect reading.
Hardware programming guidelines require the temperature value and the
valid bit to be sampled atomically in the same read transaction. A
reading is considered valid only if the valid bit is observed set in
that same sample.
The guidelines further specify that software should attempt the
temperature read up to three times to account for transient update
windows. If none of the attempts observe a valid sample, a stable
fallback value must be returned: if the first and second samples match,
the second value is returned; otherwise, if the second and third
samples match, the third value is returned.
Update the TSENS sensor read logic to implement atomic sampling along
with the recommended retry-and-compare fallback behavior. This removes
the race window and ensures deterministic temperature values in
accordance with hardware requirements.
In future, please add the '---' annotation in order to have the changelog below not included when git-apply'ing the patch
Changes in v2:
- Reverted merging of the valid-bit and LAST_TEMP register field logic
to preserve the regmap differences between TSENS versions
- Defined valid-bit support and last temperature resolution for all
TSENS v1 and v2 feature structures
- Defined last temperature resolution for Tsens v0 feature structure
- Dropped tsens version checks in favor of valid-bit capability
- Computed masks from resolution to keep a single source of truth
- Minor code cleanups based on review feedback
Changes in v3:
- Remove valid_bit, last_temp_mask, and last_temp_resolution fields from
struct tsens_features in tsens.h
- Compute last_temp_mask, resolution, and valid_bit on-the-fly using
regmap field definitions
- Remove field initializations from all platform data files
(tsens-v0_1.c, tsens-v1.c, tsens-v2.c)
- Remove the initialization line in init_common() that was computing
last_temp_mask
Signed-off-by: Priyansh Jain <priyansh.jain@xxxxxxxxxxxxxxxx>
---
Applied, thanks