Skip to content

Commit 50816a4

Browse files
pujarsbroonie
authored andcommitted
regmap: add iopoll-like atomic polling macro
This patch adds a macro 'regmap_read_poll_timeout_atomic' that works similar to 'readx_poll_timeout_atomic' defined in linux/iopoll.h; This is atomic version of already available 'regmap_read_poll_timeout' macro. It should be noted that above atomic macro cannot be used by all regmaps. If the regmap is set up for atomic use (flat or no cache and MMIO) then only it can use. Signed-off-by: Sameer Pujar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 14e01b5 commit 50816a4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

include/linux/regmap.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,51 @@ struct reg_sequence {
144144
__ret ?: ((cond) ? 0 : -ETIMEDOUT); \
145145
})
146146

147+
/**
148+
* regmap_read_poll_timeout_atomic - Poll until a condition is met or a timeout occurs
149+
*
150+
* @map: Regmap to read from
151+
* @addr: Address to poll
152+
* @val: Unsigned integer variable to read the value into
153+
* @cond: Break condition (usually involving @val)
154+
* @delay_us: Time to udelay between reads in us (0 tight-loops).
155+
* Should be less than ~10us since udelay is used
156+
* (see Documentation/timers/timers-howto.rst).
157+
* @timeout_us: Timeout in us, 0 means never timeout
158+
*
159+
* Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read
160+
* error return value in case of a error read. In the two former cases,
161+
* the last read value at @addr is stored in @val.
162+
*
163+
* This is modelled after the readx_poll_timeout_atomic macros in linux/iopoll.h.
164+
*
165+
* Note: In general regmap cannot be used in atomic context. If you want to use
166+
* this macro then first setup your regmap for atomic use (flat or no cache
167+
* and MMIO regmap).
168+
*/
169+
#define regmap_read_poll_timeout_atomic(map, addr, val, cond, delay_us, timeout_us) \
170+
({ \
171+
u64 __timeout_us = (timeout_us); \
172+
unsigned long __delay_us = (delay_us); \
173+
ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
174+
int __ret; \
175+
for (;;) { \
176+
__ret = regmap_read((map), (addr), &(val)); \
177+
if (__ret) \
178+
break; \
179+
if (cond) \
180+
break; \
181+
if ((__timeout_us) && \
182+
ktime_compare(ktime_get(), __timeout) > 0) { \
183+
__ret = regmap_read((map), (addr), &(val)); \
184+
break; \
185+
} \
186+
if (__delay_us) \
187+
udelay(__delay_us); \
188+
} \
189+
__ret ?: ((cond) ? 0 : -ETIMEDOUT); \
190+
})
191+
147192
/**
148193
* regmap_field_read_poll_timeout - Poll until a condition is met or timeout
149194
*

0 commit comments

Comments
 (0)