[U-Boot] [PATCH 1/5] lib: Add wait_for_bit
Marek Vasut
marex at denx.de
Tue Dec 15 01:20:06 CET 2015
On Tuesday, December 15, 2015 at 01:09:23 AM, Mateusz Kulikowski wrote:
> Add function to poll register waiting for specific bit(s).
> Similar functions are implemented in few drivers - they are almost
> identical and can be generalized.
> Signed-off-by: Mateusz Kulikowski <mateusz.kulikowski at gmail.com>
> ---
Excellent !
> include/wait_bit.h | 34 ++++++++++++++++++++++++++++++++++
> lib/Kconfig | 4 ++++
> lib/Makefile | 1 +
> lib/wait_bit.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 83 insertions(+)
> create mode 100644 include/wait_bit.h
> create mode 100644 lib/wait_bit.c
[...]
> +int wait_for_bit(const char *prefix,
const u32 *
> u32 *reg, const u32 mask,
const bool, const unsigned int , const bool ;-)
> bool set,
> + unsigned int timeout, bool breakable)
> +{
> + u32 val;
> + unsigned long start = get_timer(0);
> +
> + while (1) {
> + val = readl(reg);
> +
> + if (!set)
> + val = ~val;
> +
> + if ((val & mask) == mask)
> + return 0;
> +
> + if (get_timer(start) > timeout)
> + break;
> +
> + if (breakable && ctrlc()) {
> + puts("Abort\n");
> + return -EINTR;
> + }
> +
> + udelay(1);
> + }
> +
> + debug("%s: Timeout (reg=%p mask=%08x wait_set=%i)\n", prefix, reg, mask,
> + set);
> +
> + return -ETIMEDOUT;
> +}
Best regards,
Marek Vasut
More information about the U-Boot
mailing list