Re: [PATCH v2 1/2] thermal: qcom: tsens: atomic temperature read with hardware-guided retries

From: Konrad Dybcio

Date: Fri May 08 2026 - 08:15:38 EST


On 5/8/26 12:06 PM, 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.
>
> Signed-off-by: Priyansh Jain <priyansh.jain@xxxxxxxxxxxxxxxx>
> ---

[...]

> struct tsens_features {
> unsigned int ver_major;
> @@ -522,6 +526,9 @@ struct tsens_features {
> unsigned int max_sensors;
> int trip_min_temp;
> int trip_max_temp;
> + int valid_bit;
> + int last_temp_mask;
> + u32 last_temp_resolution;

You don't need this now that you aren't altering the regfield
definitions

Konrad