aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/regmap.h
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2017-10-13 18:22:06 +0100
committerMark Brown <broonie@kernel.org>2017-10-13 18:22:06 +0100
commit89d5788315f10aece086376b3f5e592afd3dbd29 (patch)
tree9b70d94a3c1bbf33560535a8f4884e0b1996916d /include/linux/regmap.h
parentMerge branch 'topic/namespace' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into regmap-core (diff)
parentregmap: add iopoll-like polling macro for regmap_field (diff)
downloadlinux-dev-89d5788315f10aece086376b3f5e592afd3dbd29.tar.xz
linux-dev-89d5788315f10aece086376b3f5e592afd3dbd29.zip
Merge branch 'topic/field' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into regmap-core
Diffstat (limited to 'include/linux/regmap.h')
-rw-r--r--include/linux/regmap.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 1474ab0a3922..1e369f0e921d 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -140,6 +140,45 @@ struct reg_sequence {
__ret ?: ((cond) ? 0 : -ETIMEDOUT); \
})
+/**
+ * regmap_field_read_poll_timeout - Poll until a condition is met or timeout
+ *
+ * @field: Regmap field to read from
+ * @val: Unsigned integer variable to read the value into
+ * @cond: Break condition (usually involving @val)
+ * @sleep_us: Maximum time to sleep between reads in us (0
+ * tight-loops). Should be less than ~20ms since usleep_range
+ * is used (see Documentation/timers/timers-howto.txt).
+ * @timeout_us: Timeout in us, 0 means never timeout
+ *
+ * Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_field_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_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
+({ \
+ ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); \
+ int pollret; \
+ might_sleep_if(sleep_us); \
+ for (;;) { \
+ pollret = regmap_field_read((field), &(val)); \
+ if (pollret) \
+ break; \
+ if (cond) \
+ break; \
+ if (timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
+ pollret = regmap_field_read((field), &(val)); \
+ break; \
+ } \
+ if (sleep_us) \
+ usleep_range((sleep_us >> 2) + 1, sleep_us); \
+ } \
+ pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
+})
+
#ifdef CONFIG_REGMAP
enum regmap_endian {