Skip to content

Commit d012f91

Browse files
Ansueldlezcano
authored andcommitted
thermal/drivers/tsens: Add timeout to get_temp_tsens_valid
The function can loop and lock the system if for whatever reason the bit for the target sensor is NEVER valid. This is the case if a sensor is disabled by the factory and the valid bit is never reported as actually valid. Add a timeout check and exit if a timeout occurs. As this is a very rare condition, handle the timeout only if the first read fails. While at it also rework the function to improve readability and convert to poll_timeout generic macro. Signed-off-by: Ansuel Smith <[email protected]> Reviewed-by: Bjorn Andersson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent 9e5a4fb commit d012f91

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

drivers/thermal/qcom/tsens.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -603,22 +603,21 @@ int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp)
603603
int ret;
604604

605605
/* VER_0 doesn't have VALID bit */
606-
if (tsens_version(priv) >= VER_0_1) {
607-
ret = regmap_field_read(priv->rf[valid_idx], &valid);
608-
if (ret)
609-
return ret;
610-
while (!valid) {
611-
/* Valid bit is 0 for 6 AHB clock cycles.
612-
* At 19.2MHz, 1 AHB clock is ~60ns.
613-
* We should enter this loop very, very rarely.
614-
*/
615-
ndelay(400);
616-
ret = regmap_field_read(priv->rf[valid_idx], &valid);
617-
if (ret)
618-
return ret;
619-
}
620-
}
606+
if (tsens_version(priv) == VER_0)
607+
goto get_temp;
608+
609+
/* Valid bit is 0 for 6 AHB clock cycles.
610+
* At 19.2MHz, 1 AHB clock is ~60ns.
611+
* We should enter this loop very, very rarely.
612+
* Wait 1 us since it's the min of poll_timeout macro.
613+
* Old value was 400 ns.
614+
*/
615+
ret = regmap_field_read_poll_timeout(priv->rf[valid_idx], valid,
616+
valid, 1, 20 * USEC_PER_MSEC);
617+
if (ret)
618+
return ret;
621619

620+
get_temp:
622621
/* Valid bit is set, OK to read the temperature */
623622
*temp = tsens_hw_to_mC(s, temp_idx);
624623

0 commit comments

Comments
 (0)