summaryrefslogtreecommitdiff
path: root/include/regmap.h
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2018-12-05 15:06:24 -0500
committerTom Rini <[email protected]>2018-12-05 15:06:24 -0500
commit9450ab2ba8d720bd9f73bccc0af2e2b5a2c2aaf1 (patch)
treeb0566746ed9a8dd261e61113c19cf0a234a6417b /include/regmap.h
parenta77a8fde7bb850178c2e4ad3db354b536114ea32 (diff)
parent08898e8b22d74a4511eadee9b06b11aab43e809c (diff)
Merge branch 'master' of git://git.denx.de/u-boot-spi
- Various MTD fixes from Boris - Zap various unused / legacy paths. - pxa3xx NAND update from Miquel Signed-off-by: Tom Rini <[email protected]>
Diffstat (limited to 'include/regmap.h')
-rw-r--r--include/regmap.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/regmap.h b/include/regmap.h
index b2b733fda68..a3afb72df51 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -240,6 +240,44 @@ int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
regmap_range_get(map, 0, type, member, valp)
/**
+ * regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
+ *
+ * @map: Regmap to read from
+ * @addr: Offset to poll
+ * @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).
+ * @timeout_ms: Timeout in ms, 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 regmap_read_poll_timeout macros in linux but
+ * with millisecond timeout.
+ */
+#define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_ms) \
+({ \
+ unsigned long __start = get_timer(0); \
+ int __ret; \
+ for (;;) { \
+ __ret = regmap_read((map), (addr), &(val)); \
+ if (__ret) \
+ break; \
+ if (cond) \
+ break; \
+ if ((timeout_ms) && get_timer(__start) > (timeout_ms)) { \
+ __ret = regmap_read((map), (addr), &(val)); \
+ break; \
+ } \
+ if ((sleep_us)) \
+ udelay((sleep_us)); \
+ } \
+ __ret ?: ((cond) ? 0 : -ETIMEDOUT); \
+})
+
+/**
* regmap_update_bits() - Perform a read/modify/write using a mask
*
* @map: The map returned by regmap_init_mem*()