diff mbox series

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

Message ID 20180110030603.27864-6-peng.fan@nxp.com
State Superseded
Delegated to: Stefano Babic
Headers show
Series imx: add i.MX8M support and i.MX8MQ EVK | expand

Commit Message

Peng Fan Jan. 10, 2018, 3:05 a.m. UTC
Add heler functions for wait mask set/clr.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Simon Glass <sjg@chromium.org>
---
 include/linux/delay.h |  4 ++++
 lib/time.c            | 30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

Comments

Masahiro Yamada Jan. 10, 2018, 3:19 a.m. UTC | #1
2018-01-10 12:05 GMT+09:00 Peng Fan <peng.fan@nxp.com>:
> Add heler functions for wait mask set/clr.
>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Fabio Estevam <fabio.estevam@nxp.com>
> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
> Cc: Simon Glass <sjg@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
Peng Fan Jan. 10, 2018, 4:08 a.m. UTC | #2
On Wed, Jan 10, 2018 at 12:19:28PM +0900, Masahiro Yamada wrote:
>2018-01-10 12:05 GMT+09:00 Peng Fan <peng.fan@nxp.com>:
>> Add heler functions for wait mask set/clr.
>>
>> Signed-off-by: Peng Fan <peng.fan@nxp.com>
>> Cc: Stefano Babic <sbabic@denx.de>
>> Cc: Fabio Estevam <fabio.estevam@nxp.com>
>> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
>> Cc: Simon Glass <sjg@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

Thanks for the info. I'll discard this patch and fix the usage in the patchset.

Thanks,
Peng.

>
>
>
>
>
>-- 
>Best Regards
>Masahiro Yamada
>_______________________________________________
>U-Boot mailing list
>U-Boot@lists.denx.de
>https://lists.denx.de/listinfo/u-boot
diff mbox series

Patch

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;
+}