15
15
#include <linux/kernel.h>
16
16
#include <linux/interrupt.h>
17
17
#include <linux/clk.h>
18
- #include <linux/delay.h>
19
18
#include <linux/gpio/consumer.h>
20
19
#include <linux/platform_device.h>
21
20
#include <linux/err.h>
27
26
#include <linux/of_platform.h>
28
27
#include <linux/of_irq.h>
29
28
#include <linux/io.h>
29
+ #include <linux/iopoll.h>
30
30
#include <linux/cpu_pm.h>
31
31
#include <linux/device.h>
32
32
#include <linux/pm_runtime.h>
@@ -604,7 +604,9 @@ static int
604
604
ti_bandgap_force_single_read (struct ti_bandgap * bgp , int id )
605
605
{
606
606
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 ;
608
610
609
611
/* Select continuous or single conversion mode */
610
612
if (TI_BANDGAP_HAS (bgp , MODE_CONFIG )) {
@@ -619,26 +621,22 @@ ti_bandgap_force_single_read(struct ti_bandgap *bgp, int id)
619
621
RMW_BITS (bgp , id , temp_sensor_ctrl , bgap_soc_mask , 1 );
620
622
621
623
/* 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" );
629
629
630
630
/* Clear Start of Conversion if available */
631
631
RMW_BITS (bgp , id , temp_sensor_ctrl , bgap_soc_mask , 0 );
632
632
}
633
633
634
634
/* 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" );
642
640
643
641
return 0 ;
644
642
}
0 commit comments