All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 4/4] dm: Print device name in dev_xxx() like Linux
Date: Sat, 12 Sep 2020 20:28:21 -0400	[thread overview]
Message-ID: <20200913002821.404022-5-seanga2@gmail.com> (raw)
In-Reply-To: <20200913002821.404022-1-seanga2@gmail.com>

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@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@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

  parent reply	other threads:[~2020-09-13  0:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-13  0:28 [PATCH 0/4] dm: Print device name in dev_xxx() like Linux Sean Anderson
2020-09-13  0:28 ` [PATCH 1/4] remoteproc: Remove unused function rproc_elf_sanity_check Sean Anderson
2020-09-17  1:09   ` Simon Glass
2020-09-13  0:28 ` [PATCH 2/4] net: mdio: Supply appropriate devices for dev_dgb calls Sean Anderson
2020-09-17  1:09   ` Simon Glass
2020-09-17  1:40     ` Sean Anderson
2020-09-17  3:44       ` Simon Glass
2020-09-13  0:28 ` [PATCH 3/4] dm: Use symbolic constants for log levels in dev_xxx() Sean Anderson
2020-09-17  1:09   ` Simon Glass
2020-09-13  0:28 ` Sean Anderson [this message]
2020-09-13  1:43 ` [PATCH 0/4] dm: Print device name in dev_xxx() like Linux Sean Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200913002821.404022-5-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.