Skip to content

Commit 514cbab

Browse files
tmlinddlezcano
authored andcommitted
thermal: ti-soc-thermal: Simplify polling with iopoll
We can use iopoll for checking the EOCZ (end of conversion) bit. And with this we now also want to handle the timeout errors properly. For omap3, we need about 1.2ms for the single mode sampling to wait for EOCZ down, so let's use 1.5ms timeout there. Waiting for sampling to start is faster and we can use 1ms timeout. Cc: Adam Ford <[email protected]> Cc: Carl Philipp Klemm <[email protected]> Cc: Eduardo Valentin <[email protected]> Cc: H. Nikolaus Schaller <[email protected]> Cc: Merlijn Wajer <[email protected]> Cc: Pavel Machek <[email protected]> Cc: Peter Ujfalusi <[email protected]> Cc: Sebastian Reichel <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Tested-by: Adam Ford <[email protected]> #logicpd-torpedo-37xx-devkit Acked-by: Pavel Machek <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 735c353 commit 514cbab

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

drivers/thermal/ti-soc-thermal/ti-bandgap.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <linux/kernel.h>
1616
#include <linux/interrupt.h>
1717
#include <linux/clk.h>
18-
#include <linux/delay.h>
1918
#include <linux/gpio/consumer.h>
2019
#include <linux/platform_device.h>
2120
#include <linux/err.h>
@@ -27,6 +26,7 @@
2726
#include <linux/of_platform.h>
2827
#include <linux/of_irq.h>
2928
#include <linux/io.h>
29+
#include <linux/iopoll.h>
3030
#include <linux/cpu_pm.h>
3131
#include <linux/device.h>
3232
#include <linux/pm_runtime.h>
@@ -604,7 +604,9 @@ static int
604604
ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id)
605605
{
606606
struct temp_sensor_registers *tsr = bgp->conf->sensors[id].registers;
607-
u32 counter;
607+
void __iomem *temp_sensor_ctrl = bgp->base + tsr->temp_sensor_ctrl;
608+
int error;
609+
u32 val;
608610

609611
/* Select continuous or single conversion mode */
610612
if (TI_BANDGAP_HAS(bgp, MODE_CONFIG)) {
@@ -619,26 +621,22 @@ ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id)
619621
RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 1);
620622

621623
/* Wait for EOCZ going up */
622-
counter = 1000;
623-
while (--counter) {
624-
if (ti_bandgap_readl(bgp, tsr->temp_sensor_ctrl) &
625-
tsr->bgap_eocz_mask)
626-
break;
627-
udelay(1);
628-
}
624+
error = readl_poll_timeout_atomic(temp_sensor_ctrl, val,
625+
val & tsr->bgap_eocz_mask,
626+
1, 1000);
627+
if (error)
628+
dev_warn(bgp->dev, "eocz timed out waiting high\n");
629629

630630
/* Clear Start of Conversion if available */
631631
RMW_BITS(bgp, id, temp_sensor_ctrl, bgap_soc_mask, 0);
632632
}
633633

634634
/* Wait for EOCZ going down, always needed even if no bgap_soc_mask */
635-
counter = 1000;
636-
while (--counter) {
637-
if (!(ti_bandgap_readl(bgp, tsr->temp_sensor_ctrl) &
638-
tsr->bgap_eocz_mask))
639-
break;
640-
udelay(1);
641-
}
635+
error = readl_poll_timeout_atomic(temp_sensor_ctrl, val,
636+
!(val & tsr->bgap_eocz_mask),
637+
1, 1500);
638+
if (error)
639+
dev_warn(bgp->dev, "eocz timed out waiting low\n");
642640

643641
return 0;
644642
}

0 commit comments

Comments
 (0)