Hi Peng,

On 9 January 2018 at 04:11, Peng Fan <peng....@nxp.com> wrote:
> Add heler functions for wait mask set/clr.
>
> Signed-off-by: Peng Fan <peng....@nxp.com>
> Cc: Stefano Babic <sba...@denx.de>
> Cc: Fabio Estevam <fabio.este...@nxp.com>
> Cc: Masahiro Yamada <yamada.masah...@socionext.com>
> Cc: Simon Glass <s...@chromium.org>
> ---
>  include/linux/delay.h |  4 ++++
>  lib/time.c            | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 34 insertions(+)
>
> diff --git a/include/linux/delay.h b/include/linux/delay.h
> index 3dcd435d0d..b08fcb8c09 100644
> --- a/include/linux/delay.h
> +++ b/include/linux/delay.h
> @@ -21,4 +21,8 @@ static inline void ndelay(unsigned long nsec)
>         udelay(DIV_ROUND_UP(nsec, 1000));
>  }
>
> +int wait_mask_set_timeout(void *addr, u32 mask, u32 timeout);
> +
> +int wait_mask_clr_timeout(void *addr, u32 mask, u32 timeout);
> +
>  #endif /* defined(_LINUX_DELAY_H) */
> diff --git a/lib/time.c b/lib/time.c
> index aed1a091f2..9701287629 100644
> --- a/lib/time.c
> +++ b/lib/time.c
> @@ -171,3 +171,33 @@ void udelay(unsigned long usec)
>                 usec -= kv;
>         } while(usec);
>  }
> +
> +int wait_mask_set_timeout(void *addr, u32 mask, u32 timeout)
> +{
> +       unsigned long long end_tick;
> +       u32 val;
> +
> +       end_tick = usec_to_tick(timeout) + get_ticks();
> +       do {
> +               val = readl(addr);
> +               if ((val & mask) == mask)
> +                       return 0;
> +       } while (end_tick > get_ticks());
> +
> +       return -ETIMEDOUT;
> +}
> +
> +int wait_mask_clr_timeout(void *addr, u32 mask, u32 timeout)

Do you think these would be better as wait_mask_timeout() and
wait_zero_timeout()?

> +{
> +       unsigned long long end_tick;
> +       u32 val;
> +
> +       end_tick = usec_to_tick(timeout) + get_ticks();
> +       do {
> +               val = readl(addr);
> +               if (!(val & mask))
> +                       return 0;
> +       } while (end_tick > get_ticks());
> +
> +       return -ETIMEDOUT;
> +}
> --
> 2.14.1
>
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to