mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] console: implement of_console_by_stdout_path helper
Date: Thu, 21 Sep 2023 11:25:39 +0200	[thread overview]
Message-ID: <20230921092539.4142293-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230921092539.4142293-1-a.fatoum@pengutronix.de>

Board code may want to get a handle on the standard console to disable
or enable some of its stream. Add a helper function for that.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/console.c  | 17 +++++++++++++++++
 include/console.h |  1 +
 2 files changed, 18 insertions(+)

diff --git a/common/console.c b/common/console.c
index 768550eb7df9..7e43a9b5fc0e 100644
--- a/common/console.c
+++ b/common/console.c
@@ -254,6 +254,23 @@ static void console_set_stdoutpath(struct console_device *cdev, unsigned baudrat
 	free(str);
 }
 
+struct console_device *of_console_by_stdout_path(void)
+{
+	struct console_device *console;
+	struct device_node *stdout_np;
+
+	stdout_np = of_get_stdoutpath(NULL);
+	if (!stdout_np)
+		return NULL;
+
+	for_each_console(console) {
+		if (dev_of_node(console->dev) == stdout_np)
+			return console;
+	}
+
+	return NULL;
+}
+
 static int __console_puts(struct console_device *cdev, const char *s,
 			  size_t nbytes)
 {
diff --git a/include/console.h b/include/console.h
index d3b08722b01a..586b68f73301 100644
--- a/include/console.h
+++ b/include/console.h
@@ -109,6 +109,7 @@ unsigned console_get_active(struct console_device *cdev);
 int console_set_baudrate(struct console_device *cdev, unsigned baudrate);
 unsigned console_get_baudrate(struct console_device *cdev);
 
+struct console_device *of_console_by_stdout_path(void);
 
 /**
  * console_fifo_fill - fill FIFO with as much console data as possible
-- 
2.39.2




  reply	other threads:[~2023-09-21  9:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21  9:25 [PATCH 1/2] startup: don't skip countdown if consoles were runtime enabled Ahmad Fatoum
2023-09-21  9:25 ` Ahmad Fatoum [this message]
2023-09-21 12:09 ` Sascha Hauer

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=20230921092539.4142293-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox