public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Simon Glass <sjg@chromium.org>
Cc: u-boot@lists.denx.de
Subject: [PATCH v3 4/6] serial: Implement serial_flush() function for console flush() fallback
Date: Mon,  5 Sep 2022 11:31:19 +0200	[thread overview]
Message-ID: <20220905093121.11630-5-pali@kernel.org> (raw)
In-Reply-To: <20220905093121.11630-1-pali@kernel.org>

Like in all other console functions, implement also serial_flush() function
as a fallback int console flush() function.

Flush support is available only when config option CONSOLE_FLUSH_SUPPORT is
enabled. So when it is disabled then provides just empty static inline
function serial_flush().

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 common/console.c               |  3 +++
 common/stdio.c                 |  8 ++++++++
 drivers/serial/serial-uclass.c | 10 ++++++++++
 include/serial.h               |  5 +++++
 4 files changed, 26 insertions(+)

diff --git a/common/console.c b/common/console.c
index 0abfc224b53b..e4dc1da44a35 100644
--- a/common/console.c
+++ b/common/console.c
@@ -797,6 +797,9 @@ void flush(void)
 	if (gd->flags & GD_FLG_DEVINIT) {
 		/* Send to the standard output */
 		fflush(stdout);
+	} else {
+		/* Send directly to the handler */
+		serial_flush();
 	}
 }
 #endif
diff --git a/common/stdio.c b/common/stdio.c
index 92161a0df87d..13083842cbd9 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -87,6 +87,13 @@ static void stdio_serial_puts(struct stdio_dev *dev, const char *s)
 	serial_puts(s);
 }
 
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static void stdio_serial_flush(struct stdio_dev *dev)
+{
+	serial_flush();
+}
+#endif
+
 static int stdio_serial_getc(struct stdio_dev *dev)
 {
 	return serial_getc();
@@ -112,6 +119,7 @@ static void drv_system_init (void)
 	dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
 	dev.putc = stdio_serial_putc;
 	dev.puts = stdio_serial_puts;
+	STDIO_DEV_ASSIGN_FLUSH(&dev, stdio_serial_flush);
 	dev.getc = stdio_serial_getc;
 	dev.tstc = stdio_serial_tstc;
 	stdio_register (&dev);
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index be6502f3d24c..f028da0900cd 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -327,6 +327,16 @@ void serial_puts(const char *str)
 		_serial_puts(gd->cur_serial_dev, str);
 }
 
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+void serial_flush(void)
+{
+	if (!gd->cur_serial_dev)
+		return;
+
+	_serial_flush(gd->cur_serial_dev);
+}
+#endif
+
 int serial_getc(void)
 {
 	if (!gd->cur_serial_dev)
diff --git a/include/serial.h b/include/serial.h
index 8c2e7adbc321..f9009d4046e3 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -362,6 +362,11 @@ void serial_setbrg(void);
 void serial_putc(const char ch);
 void serial_putc_raw(const char ch);
 void serial_puts(const char *str);
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+void serial_flush(void);
+#else
+static inline void serial_flush(void) {}
+#endif
 int serial_getc(void);
 int serial_tstc(void);
 
-- 
2.20.1


  parent reply	other threads:[~2022-09-05  9:32 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05  9:31 [PATCH v3 0/6] console: Implement flush() function Pali Rohár
2022-09-05  9:31 ` [PATCH v3 1/6] sandbox: Add function os_flush() Pali Rohár
2022-09-07 21:10   ` Simon Glass
2022-09-24 18:00   ` Tom Rini
2022-09-05  9:31 ` [PATCH v3 2/6] console: Implement flush() function Pali Rohár
2022-09-07 21:11   ` Simon Glass
2022-09-05  9:31 ` [PATCH v3 3/6] serial: Implement flush callback Pali Rohár
2022-09-05 17:24   ` Michael Nazzareno Trimarchi
2022-09-05 17:28     ` Pali Rohár
2022-09-07 21:11   ` Simon Glass
2022-09-05  9:31 ` Pali Rohár [this message]
2022-09-07 21:10   ` [PATCH v3 4/6] serial: Implement serial_flush() function for console flush() fallback Simon Glass
2022-09-20 21:40   ` Tom Rini
2022-09-20 22:18     ` Pali Rohár
2022-09-20 22:29       ` Tom Rini
2022-09-20 22:32         ` Pali Rohár
2022-09-20 22:46           ` Tom Rini
2022-09-05  9:31 ` [PATCH v3 5/6] serial: Call flush() before changing baudrate Pali Rohár
2022-09-07 21:10   ` Simon Glass
2022-09-05  9:31 ` [PATCH v3 6/6] boot: Call flush() before booting Pali Rohár
2022-09-07 21:10   ` Simon Glass
2022-09-07 21:14     ` Pali Rohár
2022-09-21 13:49 ` [PATCH v3 0/6] console: Implement flush() function Tom Rini
2022-09-21 13:54   ` Pali Rohár
2022-09-21 13:56     ` Tom Rini
2022-09-22 11:27       ` Simon Glass
2022-09-22 13:13         ` Heinrich Schuchardt
2022-09-22 13:14         ` Pali Rohár
2022-09-22 15:06           ` Heinrich Schuchardt
2022-09-23 15:45             ` Pali Rohár
2022-09-23 15:57               ` Tom Rini
2022-09-23 16:07                 ` Pali Rohár
2022-09-23 16:19                   ` Tom Rini
2022-09-24 14:01                     ` Simon Glass

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=20220905093121.11630-5-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=sjg@chromium.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox