]>
git.ipfire.org Git - people/ms/u-boot.git/blob - include/wait_bit.h
2 * Wait for bit with timeout and ctrlc
4 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0+
15 #include <linux/errno.h>
19 * wait_for_bit() waits for bit set/cleared in register
21 * Function polls register waiting for specific bit(s) change
22 * (either 0->1 or 1->0). It can fail under two conditions:
24 * - User interaction (CTRL-C)
25 * Function succeeds only if all bits of masked register are set/cleared
26 * (depending on set option).
28 * @param prefix Prefix added to timeout messagge (message visible only
30 * @param reg Register that will be read (using readl())
31 * @param mask Bit(s) of register that must be active
32 * @param set Selects wait condition (bit set or clear)
33 * @param timeout_ms Timeout (in miliseconds)
34 * @param breakable Enables CTRL-C interruption
35 * @return 0 on success, -ETIMEDOUT or -EINTR on failure
37 static inline int wait_for_bit(const char *prefix
, const u32
*reg
,
38 const u32 mask
, const bool set
,
39 const unsigned int timeout_ms
,
43 unsigned long start
= get_timer(0);
51 if ((val
& mask
) == mask
)
54 if (get_timer(start
) > timeout_ms
)
57 if (breakable
&& ctrlc()) {
66 debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n", prefix
, reg
, mask
,