Skip to content

Commit e44ab4e

Browse files
Dejin Zhengbroonie
authored andcommitted
regmap: Simplify implementation of the regmap_read_poll_timeout() macro
Simplify the implementation of the macro regmap_read_poll_timeout() by using the macro read_poll_timeout(). Signed-off-by: Dejin Zheng <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 3ada1b1 commit e44ab4e

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

include/linux/regmap.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/err.h>
1818
#include <linux/bug.h>
1919
#include <linux/lockdep.h>
20+
#include <linux/iopoll.h>
2021

2122
struct module;
2223
struct clk;
@@ -130,26 +131,10 @@ struct reg_sequence {
130131
*/
131132
#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
132133
({ \
133-
u64 __timeout_us = (timeout_us); \
134-
unsigned long __sleep_us = (sleep_us); \
135-
ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
136-
int __ret; \
137-
might_sleep_if(__sleep_us); \
138-
for (;;) { \
139-
__ret = regmap_read((map), (addr), &(val)); \
140-
if (__ret) \
141-
break; \
142-
if (cond) \
143-
break; \
144-
if ((__timeout_us) && \
145-
ktime_compare(ktime_get(), __timeout) > 0) { \
146-
__ret = regmap_read((map), (addr), &(val)); \
147-
break; \
148-
} \
149-
if (__sleep_us) \
150-
usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
151-
} \
152-
__ret ?: ((cond) ? 0 : -ETIMEDOUT); \
134+
int __ret, __tmp; \
135+
__tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
136+
sleep_us, timeout_us, false, (map), (addr), &(val)); \
137+
__ret ?: __tmp; \
153138
})
154139

155140
/**

0 commit comments

Comments
 (0)