summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2021-06-02 11:55:05 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-08 08:38:25 +0200
commit675bda4279c0e67316e574573702d08e23bcb5df (patch)
tree49e9c02b605a32c98a7dd34e6a59b3d5ab36813e /include
parent3041f8fea28b2e339f044c1b9d1fa784a5153c5e (diff)
downloadbarebox-675bda4279c0e67316e574573702d08e23bcb5df.tar.gz
barebox-675bda4279c0e67316e574573702d08e23bcb5df.tar.xz
regmap: Add regmap_read_poll_timeout
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210602095507.24609-23-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/regmap.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/regmap.h b/include/regmap.h
index b43cd936fa..057370afc7 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -116,4 +116,28 @@ int regmap_write_bits(struct regmap *map, unsigned int reg,
int regmap_update_bits(struct regmap *map, unsigned int reg,
unsigned int mask, unsigned int val);
+/**
+ * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
+ *
+ * @map: Regmap to read from
+ * @addr: Address to poll
+ * @val: Unsigned integer variable to read the value into
+ * @cond: Break condition (usually involving @val)
+ * @timeout_us: Timeout in us, 0 means never timeout
+ *
+ * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
+ * error return value in case of a error read. In the two former cases,
+ * the last read value at @addr is stored in @val. Must not be called
+ * from atomic context if sleep_us or timeout_us are used.
+ *
+ * This is modelled after the readx_poll_timeout macros in linux/iopoll.h.
+ */
+#define regmap_read_poll_timeout(map, addr, val, cond, timeout_us) \
+({ \
+ int __ret, __tmp; \
+ __tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
+ timeout_us, (map), (addr), &(val)); \
+ __ret ?: __tmp; \
+})
+
#endif /* __REGMAP_H */