powerpc: Migrate SYS_L3_SIZE to Kconfig
[platform/kernel/u-boot.git] / common / console.c
index e5be6ff..0c9bf66 100644 (file)
@@ -199,6 +199,7 @@ static int console_setfile(int file, struct stdio_dev * dev)
                case stdout:
                        gd->jt->putc  = putc;
                        gd->jt->puts  = puts;
+                       STDIO_DEV_ASSIGN_FLUSH(gd->jt, flush);
                        gd->jt->printf = printf;
                        break;
                }
@@ -364,6 +365,19 @@ static void console_puts(int file, const char *s)
        }
 }
 
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static void console_flush(int file)
+{
+       int i;
+       struct stdio_dev *dev;
+
+       for_each_console_dev(i, file, dev) {
+               if (dev->flush != NULL)
+                       dev->flush(dev);
+       }
+}
+#endif
+
 #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
 static inline void console_doenv(int file, struct stdio_dev *dev)
 {
@@ -413,6 +427,14 @@ static inline void console_puts(int file, const char *s)
        stdio_devices[file]->puts(stdio_devices[file], s);
 }
 
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static inline void console_flush(int file)
+{
+       if (stdio_devices[file]->flush)
+               stdio_devices[file]->flush(stdio_devices[file]);
+}
+#endif
+
 #if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
 static inline void console_doenv(int file, struct stdio_dev *dev)
 {
@@ -526,6 +548,14 @@ void fputs(int file, const char *s)
                console_puts(file, s);
 }
 
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+void fflush(int file)
+{
+       if (file < MAX_FILES)
+               console_flush(file);
+}
+#endif
+
 int fprintf(int file, const char *fmt, ...)
 {
        va_list args;
@@ -740,6 +770,40 @@ void puts(const char *s)
        }
 }
 
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+void flush(void)
+{
+       if (!gd)
+               return;
+
+       /* sandbox can send characters to stdout before it has a console */
+       if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) {
+               os_flush();
+               return;
+       }
+
+       if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY))
+               return;
+
+       if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT))
+               return;
+
+       if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
+               return;
+
+       if (!gd->have_console)
+               return;
+
+       if (gd->flags & GD_FLG_DEVINIT) {
+               /* Send to the standard output */
+               fflush(stdout);
+       } else {
+               /* Send directly to the handler */
+               serial_flush();
+       }
+}
+#endif
+
 #ifdef CONFIG_CONSOLE_RECORD
 int console_record_init(void)
 {