From c1e72b20c91289718b46e1d52185fbef59878daf Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Sun, 5 May 2019 12:50:43 +0800 Subject: [PATCH] dm: console/serial: add flushc() support Flush console data. Change-Id: If347b6c8d1126452a1f6386040693b30c66eb5fb Signed-off-by: Joseph Chen --- common/console.c | 37 ++++++++++++++++++++++++++++++++++ drivers/serial/serial-uclass.c | 12 +++++++++++ include/common.h | 1 + include/stdio.h | 5 +++++ include/stdio_dev.h | 3 +++ 5 files changed, 58 insertions(+) diff --git a/common/console.c b/common/console.c index 4990fdd69a..a6fd9c4322 100644 --- a/common/console.c +++ b/common/console.c @@ -256,6 +256,18 @@ static inline void console_doenv(int file, struct stdio_dev *dev) { iomux_doenv(file, dev->name); } + +static void console_clear(int file) +{ + int i; + struct stdio_dev *dev; + + for (i = 0; i < cd_count[file]; i++) { + dev = console_devices[file][i]; + if (dev->clear != NULL) + dev->clear(dev); + } +} #else static inline int console_getc(int file) { @@ -283,6 +295,12 @@ static inline void console_puts(int file, const char *s) stdio_devices[file]->puts(stdio_devices[file], s); } +static inline void console_clear(int file) +{ + if (stdio_devices[file]->clear) + stdio_devices[file]->clear(stdio_devices[file]); +} + static inline void console_doenv(int file, struct stdio_dev *dev) { console_setfile(file, dev); @@ -361,6 +379,12 @@ void fputs(int file, const char *s) console_puts(file, s); } +void fclear(int file) +{ + if (file < MAX_FILES) + console_clear(file); +} + int fprintf(int file, const char *fmt, ...) { va_list args; @@ -434,6 +458,19 @@ int tstc(void) return serial_tstc(); } +void flushc(void) +{ +#ifdef CONFIG_DISABLE_CONSOLE + if (gd->flags & GD_FLG_DISABLE_CONSOLE) + return; +#endif + + if (gd->flags & GD_FLG_DEVINIT) + fclear(stdout); + else + serial_clear(); +} + #define PRE_CONSOLE_FLUSHPOINT1_SERIAL 0 #define PRE_CONSOLE_FLUSHPOINT2_EVERYTHING_BUT_SERIAL 1 diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c index 0c7a4d7c87..c86766bb44 100644 --- a/drivers/serial/serial-uclass.c +++ b/drivers/serial/serial-uclass.c @@ -279,6 +279,18 @@ void serial_setbrg(void) ops->setbrg(gd->cur_serial_dev, gd->baudrate); } +void serial_clear(void) +{ + struct dm_serial_ops *ops; + + if (!gd->cur_serial_dev) + return; + + ops = serial_get_ops(gd->cur_serial_dev); + if (ops->setbrg) + ops->clear(gd->cur_serial_dev); +} + void serial_stdio_init(void) { } diff --git a/include/common.h b/include/common.h index e300aa3c25..62081face0 100644 --- a/include/common.h +++ b/include/common.h @@ -548,6 +548,7 @@ void smp_kick_all_cpus(void); int serial_init (void); void serial_setbrg (void); void serial_putc (const char); +void serial_clear (void); void serial_putc_raw(const char); void serial_puts (const char *); int serial_getc (void); diff --git a/include/stdio.h b/include/stdio.h index aedf374452..4ba2f0e283 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -15,6 +15,7 @@ int tstc(void); defined(CONFIG_SPL_SERIAL_SUPPORT)) void putc(const char c); void puts(const char *s); +void flushc(void); int __printf(1, 2) printf(const char *fmt, ...); int vprintf(const char *fmt, va_list args); #else @@ -26,6 +27,10 @@ static inline void puts(const char *s) { } +static inline void flushc(void) +{ +} + static inline int __printf(1, 2) printf(const char *fmt, ...) { return 0; diff --git a/include/stdio_dev.h b/include/stdio_dev.h index 3164fa2a55..5b13ebf2be 100644 --- a/include/stdio_dev.h +++ b/include/stdio_dev.h @@ -36,6 +36,9 @@ struct stdio_dev { /* To put a string (accelerator) */ void (*puts)(struct stdio_dev *dev, const char *s); +/* Clear functions */ + void (*clear)(struct stdio_dev *dev); + /* INPUT functions */ /* To test if a char is ready... */