[PATCH 2/2] console: implement of_console_by_stdout_path helper
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu Sep 21 02:25:39 PDT 2023
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 at 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
More information about the barebox
mailing list