All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/9] console: Introduce console_start() and console_stop()
@ 2020-12-21 12:30 Andy Shevchenko
  2020-12-21 12:30 ` [PATCH v3 2/9] console: Keep ->start() and ->stop() balanced Andy Shevchenko
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Andy Shevchenko @ 2020-12-21 12:30 UTC (permalink / raw)
  To: u-boot

In the future we would like to stop unused consoles and
also add a reference counting to avoid imbalanced calls
to ->start() and ->stop() in some cases.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v3: added comments to the function declarations
 common/console.c  | 30 +++++++++++++++++++++++-------
 include/console.h |  3 +++
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/common/console.c b/common/console.c
index 3348436da6f7..9973f96e7629 100644
--- a/common/console.c
+++ b/common/console.c
@@ -114,13 +114,9 @@ static int console_setfile(int file, struct stdio_dev * dev)
 	case stdin:
 	case stdout:
 	case stderr:
-		/* Start new device */
-		if (dev->start) {
-			error = dev->start(dev);
-			/* If it's not started dont use it */
-			if (error < 0)
-				break;
-		}
+		error = console_start(file, dev);
+		if (error)
+			break;
 
 		/* Assign the new device (leaving the existing one started) */
 		stdio_devices[file] = dev;
@@ -310,6 +306,26 @@ static inline void console_doenv(int file, struct stdio_dev *dev)
 #endif
 #endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */
 
+int console_start(int file, struct stdio_dev *sdev)
+{
+	int error;
+
+	/* Start new device */
+	if (sdev->start) {
+		error = sdev->start(sdev);
+		/* If it's not started don't use it */
+		if (error < 0)
+			return error;
+	}
+	return 0;
+}
+
+void console_stop(int file, struct stdio_dev *sdev)
+{
+	if (sdev->stop)
+		sdev->stop(sdev);
+}
+
 /** U-Boot INITIAL CONSOLE-NOT COMPATIBLE FUNCTIONS *************************/
 
 int serial_printf(const char *fmt, ...)
diff --git a/include/console.h b/include/console.h
index 432f892b6cce..58a4ec3f12ad 100644
--- a/include/console.h
+++ b/include/console.h
@@ -8,6 +8,7 @@
 #define __CONSOLE_H
 
 #include <stdbool.h>
+#include <stdio_dev.h>
 #include <linux/errno.h>
 
 extern char console_buffer[];
@@ -15,6 +16,8 @@ extern char console_buffer[];
 /* common/console.c */
 int console_init_f(void);	/* Before relocation; uses the serial  stuff */
 int console_init_r(void);	/* After  relocation; uses the console stuff */
+int console_start(int file, struct stdio_dev *sdev);	/* Start a console device */
+void console_stop(int file, struct stdio_dev *sdev);	/* Stop a console device */
 int console_assign(int file, const char *devname);	/* Assign the console */
 int ctrlc(void);
 int had_ctrlc(void);	/* have we had a Control-C since last clear? */
-- 
2.29.2

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-01-16 16:25 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21 12:30 [PATCH v3 1/9] console: Introduce console_start() and console_stop() Andy Shevchenko
2020-12-21 12:30 ` [PATCH v3 2/9] console: Keep ->start() and ->stop() balanced Andy Shevchenko
2020-12-21 16:47   ` Simon Glass
2021-01-16 16:24   ` Tom Rini
2020-12-21 12:30 ` [PATCH v3 3/9] console: move search_device() from iomux.h to console.h Andy Shevchenko
2021-01-16 16:24   ` Tom Rini
2020-12-21 12:30 ` [PATCH v3 4/9] console: rename search_device() to console_search_dev() Andy Shevchenko
2020-12-21 16:47   ` Simon Glass
2021-01-16 16:24   ` Tom Rini
2020-12-21 12:30 ` [PATCH v3 5/9] console: Provide a documentation for console_search_dev() Andy Shevchenko
2021-01-16 16:24   ` Tom Rini
2020-12-21 12:30 ` [PATCH v3 6/9] IOMUX: Preserve console list if realloc() fails Andy Shevchenko
2021-01-16 16:25   ` Tom Rini
2020-12-21 12:30 ` [PATCH v3 7/9] IOMUX: Refactor iomux_doenv() in order to increase readability Andy Shevchenko
2021-01-16 16:25   ` Tom Rini
2020-12-21 12:30 ` [PATCH v3 8/9] IOMUX: Drop indentation level by removing redundant 'else' Andy Shevchenko
2021-01-16 16:25   ` Tom Rini
2020-12-21 12:30 ` [PATCH v3 9/9] IOMUX: Stop dropped consoles Andy Shevchenko
2021-01-16 16:25   ` Tom Rini
2021-01-16 16:24 ` [PATCH v3 1/9] console: Introduce console_start() and console_stop() Tom Rini

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.