[U-Boot] [PATCH V4 05/32] time: add wait_mask_set/clr_timeout helper functions

Masahiro Yamada yamada.masahiro at socionext.com
Wed Jan 10 03:19:28 UTC 2018


2018-01-10 12:05 GMT+09:00 Peng Fan <peng.fan at nxp.com>:
> Add heler functions for wait mask set/clr.
>
> Signed-off-by: Peng Fan <peng.fan at nxp.com>
> Cc: Stefano Babic <sbabic at denx.de>
> Cc: Fabio Estevam <fabio.estevam at nxp.com>
> Cc: Masahiro Yamada <yamada.masahiro at socionext.com>
> Cc: Simon Glass <sjg at 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)
> +{
> +       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;
> +}
> --

NACK.

You are re-inventing wheel.

Please use include/linux/iopoll.h





-- 
Best Regards
Masahiro Yamada


More information about the U-Boot mailing list