Skip to content

Commit a2f0dd0

Browse files
RanderWangxiulipan
authored andcommitted
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 3b966f3 commit a2f0dd0

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>
@@ -186,4 +187,27 @@ static inline int poll_for_completion_delay(completion_t *comp, uint64_t us)
186187
return 0;
187188
}
188189

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

0 commit comments

Comments
 (0)