Skip to content

Commit d644b13

Browse files
pcercueialexandrebelloni
authored andcommitted
rtc: jz4740: Use readl_poll_timeout
Use readl_poll_timeout() from <iopoll.h> instead of using custom poll loops. The timeout settings are different, but that shouldn't be much of a problem. Instead of polling 10000 times in a close loop, it polls for one millisecond. Signed-off-by: Paul Cercueil <paul@crapouillou.net> Link: https://lore.kernel.org/r/20230129120442.22858-3-paul@crapouillou.net Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
1 parent 4737a70 commit d644b13

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

drivers/rtc/rtc-jz4740.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <linux/clk.h>
99
#include <linux/io.h>
10+
#include <linux/iopoll.h>
1011
#include <linux/kernel.h>
1112
#include <linux/module.h>
1213
#include <linux/of_device.h>
@@ -69,31 +70,24 @@ static inline uint32_t jz4740_rtc_reg_read(struct jz4740_rtc *rtc, size_t reg)
6970
static int jz4740_rtc_wait_write_ready(struct jz4740_rtc *rtc)
7071
{
7172
uint32_t ctrl;
72-
int timeout = 10000;
7373

74-
do {
75-
ctrl = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_CTRL);
76-
} while (!(ctrl & JZ_RTC_CTRL_WRDY) && --timeout);
77-
78-
return timeout ? 0 : -EIO;
74+
return readl_poll_timeout(rtc->base + JZ_REG_RTC_CTRL, ctrl,
75+
ctrl & JZ_RTC_CTRL_WRDY, 0, 1000);
7976
}
8077

8178
static inline int jz4780_rtc_enable_write(struct jz4740_rtc *rtc)
8279
{
8380
uint32_t ctrl;
84-
int ret, timeout = 10000;
81+
int ret;
8582

8683
ret = jz4740_rtc_wait_write_ready(rtc);
8784
if (ret != 0)
8885
return ret;
8986

9087
writel(JZ_RTC_WENR_MAGIC, rtc->base + JZ_REG_RTC_WENR);
9188

92-
do {
93-
ctrl = readl(rtc->base + JZ_REG_RTC_WENR);
94-
} while (!(ctrl & JZ_RTC_WENR_WEN) && --timeout);
95-
96-
return timeout ? 0 : -EIO;
89+
return readl_poll_timeout(rtc->base + JZ_REG_RTC_WENR, ctrl,
90+
ctrl & JZ_RTC_WENR_WEN, 0, 1000);
9791
}
9892

9993
static inline int jz4740_rtc_reg_write(struct jz4740_rtc *rtc, size_t reg,

0 commit comments

Comments
 (0)