diff --git a/drivers/thermal/ti-soc-thermal/ti-bandgap.c b/drivers/thermal/ti-soc-thermal/ti-bandgap.c index 6e9255124f31..8a3646e26ddd 100644 --- a/drivers/thermal/ti-soc-thermal/ti-bandgap.c +++ b/drivers/thermal/ti-soc-thermal/ti-bandgap.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -604,7 +604,9 @@ static int ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id) { struct temp_sensor_registers *tsr = bgp->conf->sensors[id].registers; - u32 counter; + void __iomem *temp_sensor_ctrl = bgp->base + tsr->temp_sensor_ctrl; + int error; + u32 val; /* Select continuous or single conversion mode */ if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) { @@ -619,26 +621,22 @@ ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id) RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 1); /* Wait for EOCZ going up */ - counter = 1000; - while (--counter) { - if (ti_bandgap_readl(bgp, tsr->temp_sensor_ctrl) & - tsr->bgap_eocz_mask) - break; - udelay(1); - } + error = readl_poll_timeout_atomic(temp_sensor_ctrl, val, + val & tsr->bgap_eocz_mask, + 1, 1000); + if (error) + dev_warn(bgp->dev, "eocz timed out waiting high\n"); /* Clear Start of Conversion if available */ RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 0); } /* Wait for EOCZ going down, always needed even if no bgap_soc_mask */ - counter = 1000; - while (--counter) { - if (!(ti_bandgap_readl(bgp, tsr->temp_sensor_ctrl) & - tsr->bgap_eocz_mask)) - break; - udelay(1); - } + error = readl_poll_timeout_atomic(temp_sensor_ctrl, val, + !(val & tsr->bgap_eocz_mask), + 1, 1500); + if (error) + dev_warn(bgp->dev, "eocz timed out waiting low\n"); return 0; }