[U-Boot] [PATCH v2 1/5] delay: collect {m, n, u}delay declarations to include/linux/delay.h

Masahiro Yamada yamada.masahiro at socionext.com
Tue Dec 27 16:35:59 CET 2016


Currently, mdelay() and udelay() are declared in include/common.h,
while ndelay() in include/linux/compat.h.  It would be nice to
collect them into include/linux/delay.h like Linux.

While we are here, fix the ndelay() implementation; I used the
DIV_ROUND_UP() instead of (x)/1000 because it must wait *longer*
than the given period of time.

Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
Reviewed-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None

 include/common.h       |  6 +-----
 include/linux/compat.h |  2 --
 include/linux/delay.h  | 24 ++++++++++++++++++++++++
 lib/time.c             |  6 ------
 4 files changed, 25 insertions(+), 13 deletions(-)
 create mode 100644 include/linux/delay.h

diff --git a/include/common.h b/include/common.h
index a8d833b..682205d 100644
--- a/include/common.h
+++ b/include/common.h
@@ -19,6 +19,7 @@ typedef volatile unsigned char	vu_char;
 #include <errno.h>
 #include <asm-offsets.h>
 #include <linux/bitops.h>
+#include <linux/delay.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/stringify.h>
@@ -776,7 +777,6 @@ uint64_t get_ticks(void);
 void	wait_ticks    (unsigned long);
 
 /* arch/$(ARCH)/lib/time.c */
-void	__udelay      (unsigned long);
 ulong	usec2ticks    (unsigned long usec);
 ulong	ticks2usec    (unsigned long ticks);
 int	init_timebase (void);
@@ -833,10 +833,6 @@ void qsort(void *base, size_t nmemb, size_t size,
 	   int(*compar)(const void *, const void *));
 int strcmp_compar(const void *, const void *);
 
-/* lib/time.c */
-void	udelay        (unsigned long);
-void mdelay(unsigned long);
-
 /* lib/uuid.c */
 #include <uuid.h>
 
diff --git a/include/linux/compat.h b/include/linux/compat.h
index 533983f..a43e4d6 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -15,8 +15,6 @@ struct p_current{
 
 extern struct p_current *current;
 
-#define ndelay(x)	udelay((x) < 1000 ? 1 : (x)/1000)
-
 #define dev_dbg(dev, fmt, args...)		\
 	debug(fmt, ##args)
 #define dev_vdbg(dev, fmt, args...)		\
diff --git a/include/linux/delay.h b/include/linux/delay.h
new file mode 100644
index 0000000..3dcd435
--- /dev/null
+++ b/include/linux/delay.h
@@ -0,0 +1,24 @@
+/*
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _LINUX_DELAY_H
+#define _LINUX_DELAY_H
+
+#include <linux/kernel.h>
+
+void __udelay(unsigned long usec);
+void udelay(unsigned long usec);
+
+static inline void mdelay(unsigned long msec)
+{
+	while (msec--)
+		udelay(1000);
+}
+
+static inline void ndelay(unsigned long nsec)
+{
+	udelay(DIV_ROUND_UP(nsec, 1000));
+}
+
+#endif /* defined(_LINUX_DELAY_H) */
diff --git a/lib/time.c b/lib/time.c
index f37150f..3c49243 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -154,9 +154,3 @@ void udelay(unsigned long usec)
 		usec -= kv;
 	} while(usec);
 }
-
-void mdelay(unsigned long msec)
-{
-	while (msec--)
-		udelay(1000);
-}
-- 
2.7.4



More information about the U-Boot mailing list