regmap: Add field polling macro
-----BEGIN PGP SIGNATURE----- iQFHBAABCAAxFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAlnUvBgTHGJyb29uaWVA a2VybmVsLm9yZwAKCRAk1otyXVSH0AuJB/4u17LCa8PBI7pz0LVr7zwj3AEBZrAb zq/wqlrqZOhyLEfHtLI/So5LyIFYaF7MZJfylHBp6OiDIXEXzee3qLOc5mQB2jnv BSnH2Ors658o5TCDm1W0xtHXkujAr7MlaV7Wkaw4lLiq3OeNo8lYMdLVW4tLXf0d ib7hOsO6idt1H8DRYXlrVrGA7Fz8/m2YYahceAOyLAgLxlepoZGJ1xJxMfqr+ZVs c85y2JoGWFr0Ac/8E/TZUIuONF4forpaWwI1+/0zCfdNLmG9ceAFxiPPIluAGkeO EyZzahspaFHa0j+/WrOUlB6YcXPY69pUo89kzHYn7ugBrmGoAMtnLnsN =BA1X -----END PGP SIGNATURE----- Merge tag 'regmap-poll-field' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap into drm-misc-next regmap: Add field polling macro Requested by Maxime Ripard to make sun4i compile again (next time the other way round is better). Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: https://patchwork.freedesktop.org/patch/msgid/20171004104732.jkps4ufekfizcrkz@sirena.co.uk
This commit is contained in:
commit
7c0f24a4c4
|
@ -139,6 +139,45 @@ struct reg_sequence {
|
||||||
pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
|
pollret ?: ((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
|
#ifdef CONFIG_REGMAP
|
||||||
|
|
||||||
enum regmap_endian {
|
enum regmap_endian {
|
||||||
|
|
Loading…
Reference in a new issue