summaryrefslogtreecommitdiff
path: root/drivers/serial
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2022-09-24 13:58:49 -0400
committerTom Rini <[email protected]>2022-09-24 13:58:49 -0400
commit81da5042e514bfd27516d3530dde4d62a6708ca4 (patch)
tree75203cc106a2c1c340024fdb562be7c9b6d0e4e2 /drivers/serial
parent694e9008674c2008b9ccdc25a9bb3ac078e20911 (diff)
parentefc3f9526f9cfcd8614668c03b9c66b209782c41 (diff)
Merge branch '2022-09-24-add-console-flush' into next
To quote the author: On certain places it is required to flush output print buffers to ensure that text strings were sent to console or serial devices. For example when printing message that U-Boot is going to boot kernel or when U-Boot is going to change baudrate of terminal device. Some console devices, like UART, have putc/puts functions which just put characters into HW transmit queue and do not wait until all data are transmitted. Doing some sensitive operations (like changing baudrate or starting kernel which resets UART HW) cause that U-Boot messages are lost. Therefore introduce a new flush() function, implement it for all serial devices via pending(false) callback and use this new flush() function on sensitive places after which output device may go into reset state. This change fixes printing of U-Boot messages: "## Starting application at ..." "## Switch baudrate to ..." In addition, take a patch from Heinrich to rename some EFI test functions in order to not conflict with this series.
Diffstat (limited to 'drivers/serial')
-rw-r--r--drivers/serial/serial-uclass.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 0d43e9b6258..da3e1eb3ab1 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -238,6 +238,18 @@ static void _serial_puts(struct udevice *dev, const char *str)
} while (*str);
}
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static void _serial_flush(struct udevice *dev)
+{
+ struct dm_serial_ops *ops = serial_get_ops(dev);
+
+ if (!ops->pending)
+ return;
+ while (ops->pending(dev, false) > 0)
+ ;
+}
+#endif
+
static int __serial_getc(struct udevice *dev)
{
struct dm_serial_ops *ops = serial_get_ops(dev);
@@ -315,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)
@@ -398,6 +420,13 @@ static void serial_stub_puts(struct stdio_dev *sdev, const char *str)
_serial_puts(sdev->priv, str);
}
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static void serial_stub_flush(struct stdio_dev *sdev)
+{
+ _serial_flush(sdev->priv);
+}
+#endif
+
static int serial_stub_getc(struct stdio_dev *sdev)
{
return _serial_getc(sdev->priv);
@@ -447,6 +476,7 @@ static int on_baudrate(const char *name, const char *value, enum env_op op,
printf("## Switch baudrate to %d bps and press ENTER ...\n",
baudrate);
udelay(50000);
+ flush();
}
gd->baudrate = baudrate;
@@ -520,6 +550,7 @@ static int serial_post_probe(struct udevice *dev)
sdev.priv = dev;
sdev.putc = serial_stub_putc;
sdev.puts = serial_stub_puts;
+ STDIO_DEV_ASSIGN_FLUSH(&sdev, serial_stub_flush);
sdev.getc = serial_stub_getc;
sdev.tstc = serial_stub_tstc;