aboutsummaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorSimon Glass2023-10-01 19:15:23 -0600
committerTom Rini2023-12-13 18:39:05 -0500
commitcde03fa23e2fa47707ef81b9a91b1f4b631adbb7 (patch)
tree85b32c19c85c378aee63a32a4de70195671df265 /common/console.c
parentc0e708eb9f3f7b502c018d93f8d4daaaabb29fee (diff)
video: Add a function to clear the display
Move the code from the 'cls' command into the console file, so it can be called from elsewhere. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/common/console.c b/common/console.c
index 98c3ee6ca6b..1ffda49c87e 100644
--- a/common/console.c
+++ b/common/console.c
@@ -19,12 +19,15 @@
#include <stdio_dev.h>
#include <exports.h>
#include <env_internal.h>
+#include <video_console.h>
#include <watchdog.h>
#include <asm/global_data.h>
#include <linux/delay.h>
DECLARE_GLOBAL_DATA_PTR;
+#define CSI "\x1b["
+
static int on_console(const char *name, const char *value, enum env_op op,
int flags)
{
@@ -1010,6 +1013,34 @@ int console_init_f(void)
return 0;
}
+int console_clear(void)
+{
+ /*
+ * Send clear screen and home
+ *
+ * FIXME(Heinrich Schuchardt <xypron.glpk@gmx.de>): This should go
+ * through an API and only be written to serial terminals, not video
+ * displays
+ */
+ printf(CSI "2J" CSI "1;1H");
+ if (IS_ENABLED(CONFIG_VIDEO_ANSI))
+ return 0;
+
+ if (IS_ENABLED(CONFIG_VIDEO)) {
+ struct udevice *dev;
+ int ret;
+
+ ret = uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev);
+ if (ret)
+ return ret;
+ ret = vidconsole_clear_and_reset(dev);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
static void stdio_print_current_devices(void)
{
char *stdinname, *stdoutname, *stderrname;