Skip to content

Commit b9fb774

Browse files
committed
wait: add a function to wait for a register ready by pulling method
The register status is checked by polling its value in request time Signed-off-by: Rander Wang <rander.wang@linux.intel.com>
1 parent ef3ab58 commit b9fb774

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/include/sof/wait.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <stdint.h>
3737
#include <errno.h>
3838
#include <arch/wait.h>
39+
#include <sof/io.h>
3940
#include <sof/debug.h>
4041
#include <sof/work.h>
4142
#include <sof/timer.h>
@@ -185,4 +186,27 @@ static inline int poll_for_completion_delay(completion_t *comp, uint64_t us)
185186
return 0;
186187
}
187188

189+
static inline int poll_for_register_delay(uint32_t reg,
190+
uint32_t mask,
191+
uint32_t val, uint64_t us)
192+
{
193+
uint64_t tick = clock_us_to_ticks(CLK_CPU, us);
194+
uint32_t tries = DEFAULT_TRY_TIMES;
195+
uint64_t delta = tick / tries;
196+
197+
if (!delta) {
198+
delta = us;
199+
tries = 1;
200+
}
201+
202+
while ((io_reg_read(reg) & mask) != val) {
203+
if (!tries--) {
204+
trace_error(TRACE_CLASS_WAIT, "ewt");
205+
return -EIO;
206+
}
207+
wait_delay(delta);
208+
}
209+
return 0;
210+
}
211+
188212
#endif

0 commit comments

Comments
 (0)