[PATCH 4/4] dm: Print device name in dev_xxx() like Linux

Sean Anderson seanga2 at gmail.com
Sun Sep 13 02:28:21 CEST 2020


This adorns messages generated by dev_xxx() with the device and driver
names. It also redirects dev_xxx() to log() when it is available. The names
of these functions very roughly take inspiration from Linux, but there is
no deeper correlation.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---

 include/dm/device_compat.h | 58 ++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 30 deletions(-)

diff --git a/include/dm/device_compat.h b/include/dm/device_compat.h
index 7c14aa464d..5d18eb68fa 100644
--- a/include/dm/device_compat.h
+++ b/include/dm/device_compat.h
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0+ */
 /*
+ * Copyright (C) 2020 Sean Anderson <seanga2 at gmail.com>
  * Copyright (c) 2013 Google, Inc
  *
  * (C) Copyright 2012
@@ -33,19 +34,33 @@
 #undef dev_warn
 #endif
 
-/*
- * REVISIT:
- * print device name like Linux
- */
-#define dev_printk(dev, fmt, ...)				\
-({								\
-	printk(fmt, ##__VA_ARGS__);				\
+#ifdef VERBOSE_DEBUG
+#define _VERBOSE_DEBUG 1
+#else
+#define _VERBOSE_DEBUG 0
+#endif
+
+#define dev_printk_emit(cat, level, fmt, ...) \
+({ \
+	if ((_DEBUG && level == LOGL_DEBUG) || \
+	    (_VERBOSE_DEBUG && level == LOGL_DEBUG_CONTENT)) \
+		printf(fmt, ##__VA_ARGS__); \
+	else if (CONFIG_IS_ENABLED(LOG)) \
+		log(cat, level, fmt, ##__VA_ARGS__); \
+	else if (level < CONFIG_VAL(LOGLEVEL)) \
+		printf(fmt, ##__VA_ARGS__); \
 })
 
-#define __dev_printk(level, dev, fmt, ...)			\
-({								\
-	if (level < CONFIG_VAL(LOGLEVEL))			\
-		dev_printk(dev, fmt, ##__VA_ARGS__);		\
+#define __dev_printk(level, dev, fmt, ...) \
+({ \
+	struct udevice *__dev = dev; \
+	if (__dev) \
+		dev_printk_emit(__dev->driver->id, level, "%s %s: " fmt, \
+				__dev->name, __dev->driver->name, \
+				##__VA_ARGS__); \
+	else \
+		dev_printk_emit(LOG_CATEGORY, level, \
+				"(NULL udevice *): " fmt, ##__VA_ARGS__); \
 })
 
 #define dev_emerg(dev, fmt, ...) \
@@ -62,26 +77,9 @@
 	__dev_printk(LOGL_NOTICE, dev, fmt, ##__VA_ARGS__)
 #define dev_info(dev, fmt, ...) \
 	__dev_printk(LOGL_INFO, dev, fmt, ##__VA_ARGS__)
-
-#ifdef DEBUG
 #define dev_dbg(dev, fmt, ...) \
 	__dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__)
-#else
-#define dev_dbg(dev, fmt, ...)					\
-({								\
-	if (0)							\
-		__dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__);	\
-})
-#endif
-
-#ifdef VERBOSE_DEBUG
-#define dev_vdbg	dev_dbg
-#else
-#define dev_vdbg(dev, fmt, ...)					\
-({								\
-	if (0)							\
-		__dev_printk(LOGL_DEBUG, dev, fmt, ##__VA_ARGS__);	\
-})
-#endif
+#define dev_vdbg(dev, fmt, ...) \
+	__dev_printk(LOGL_DEBUG_CONTENT, dev, fmt, ##__VA_ARGS__)
 
 #endif
-- 
2.28.0



More information about the U-Boot mailing list