]>
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+
14 #include <linux/errno.h>
18 * wait_for_bit() waits for bit set/cleared in register
20 * Function polls register waiting for specific bit(s) change
21 * (either 0->1 or 1->0). It can fail under two conditions:
23 * - User interaction (CTRL-C)
24 * Function succeeds only if all bits of masked register are set/cleared
25 * (depending on set option).
27 * @param prefix Prefix added to timeout messagge (message visible only
29 * @param reg Register that will be read (using readl())
30 * @param mask Bit(s) of register that must be active
31 * @param set Selects wait condition (bit set or clear)
32 * @param timeout_ms Timeout (in miliseconds)
33 * @param breakable Enables CTRL-C interruption
34 * @return 0 on success, -ETIMEDOUT or -EINTR on failure
36 static inline int wait_for_bit(const char *prefix
, const u32
*reg
,
37 const u32 mask
, const bool set
,
38 const unsigned int timeout_ms
,
42 unsigned long start
= get_timer(0);
50 if ((val
& mask
) == mask
)
53 if (get_timer(start
) > timeout_ms
)
56 if (breakable
&& ctrlc()) {
64 debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n", prefix
, reg
, mask
,