]> git.sur5r.net Git - u-boot/blobdiff - common/console.c
SPDX: Convert all of our single license tags to Linux Kernel style
[u-boot] / common / console.c
index 762d5f291c2284b3b0860ed4249fc332ecdd30e4..2688af56e1582ad2f2330477010c112533eeb279 100644 (file)
@@ -1,13 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2000
  * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <console.h>
 #include <debug_uart.h>
+#include <dm.h>
 #include <stdarg.h>
 #include <iomux.h>
 #include <malloc.h>
@@ -67,11 +67,11 @@ U_BOOT_ENV_CALLBACK(console, on_console);
 static int on_silent(const char *name, const char *value, enum env_op op,
        int flags)
 {
-#if !CONFIG_IS_ENABLED(CONFIG_SILENT_CONSOLE_UPDATE_ON_SET)
+#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_SET)
        if (flags & H_INTERACTIVE)
                return 0;
 #endif
-#if !CONFIG_IS_ENABLED(CONFIG_SILENT_CONSOLE_UPDATE_ON_RELOC)
+#if !CONFIG_IS_ENABLED(SILENT_CONSOLE_UPDATE_ON_RELOC)
        if ((flags & H_INTERACTIVE) == 0)
                return 0;
 #endif
@@ -146,6 +146,29 @@ static int console_setfile(int file, struct stdio_dev * dev)
        return error;
 }
 
+/**
+ * console_dev_is_serial() - Check if a stdio device is a serial device
+ *
+ * @sdev: Device to check
+ * @return true if this device is in the serial uclass (or for pre-driver-model,
+ * whether it is called "serial".
+ */
+static bool console_dev_is_serial(struct stdio_dev *sdev)
+{
+       bool is_serial;
+
+#ifdef CONFIG_DM_SERIAL
+       if (sdev->flags & DEV_FLAGS_DM) {
+               struct udevice *dev = sdev->priv;
+
+               is_serial = device_get_uclass_id(dev) == UCLASS_SERIAL;
+       } else
+#endif
+       is_serial = !strcmp(sdev->name, "serial");
+
+       return is_serial;
+}
+
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
 /** Console I/O multiplexing *******************************************/
 
@@ -210,7 +233,7 @@ static void console_puts_noserial(int file, const char *s)
 
        for (i = 0; i < cd_count[file]; i++) {
                dev = console_devices[file][i];
-               if (dev->puts != NULL && strcmp(dev->name, "serial") != 0)
+               if (dev->puts != NULL && !console_dev_is_serial(dev))
                        dev->puts(dev, s);
        }
 }
@@ -249,7 +272,7 @@ static inline void console_putc(int file, const char c)
 
 static inline void console_puts_noserial(int file, const char *s)
 {
-       if (strcmp(stdio_devices[file]->name, "serial") != 0)
+       if (!console_dev_is_serial(stdio_devices[file]))
                stdio_devices[file]->puts(stdio_devices[file], s);
 }
 
@@ -508,12 +531,6 @@ void putc(const char c)
 
 void puts(const char *s)
 {
-#ifdef CONFIG_SANDBOX
-       if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
-               os_puts(s);
-               return;
-       }
-#endif
 #ifdef CONFIG_DEBUG_UART
        if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
                while (*s) {
@@ -695,7 +712,7 @@ int console_assign(int file, const char *devname)
 static void console_update_silent(void)
 {
 #ifdef CONFIG_SILENT_CONSOLE
-       if (getenv("silent") != NULL)
+       if (env_get("silent") != NULL)
                gd->flags |= GD_FLG_SILENT;
        else
                gd->flags &= ~GD_FLG_SILENT;
@@ -774,9 +791,9 @@ int console_init_r(void)
 
        /* stdin stdout and stderr are in environment */
        /* scan for it */
-       stdinname  = getenv("stdin");
-       stdoutname = getenv("stdout");
-       stderrname = getenv("stderr");
+       stdinname  = env_get("stdin");
+       stdoutname = env_get("stdout");
+       stderrname = env_get("stderr");
 
        if (OVERWRITE_CONSOLE == 0) {   /* if not overwritten by config switch */
                inputdev  = search_device(DEV_FLAGS_INPUT,  stdinname);
@@ -829,8 +846,8 @@ done:
 
 #ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
        /* set the environment variables (will overwrite previous env settings) */
-       for (i = 0; i < 3; i++) {
-               setenv(stdio_names[i], stdio_devices[i]->name);
+       for (i = 0; i < MAX_FILES; i++) {
+               env_set(stdio_names[i], stdio_devices[i]->name);
        }
 #endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
 
@@ -865,7 +882,7 @@ int console_init_r(void)
         * console to serial console in this case or suppress it if
         * "silent" mode was requested.
         */
-       if (getenv("splashimage") != NULL) {
+       if (env_get("splashimage") != NULL) {
                if (!(gd->flags & GD_FLG_SILENT))
                        outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
        }
@@ -908,8 +925,8 @@ int console_init_r(void)
 #endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
 
        /* Setting environment variables */
-       for (i = 0; i < 3; i++) {
-               setenv(stdio_names[i], stdio_devices[i]->name);
+       for (i = 0; i < MAX_FILES; i++) {
+               env_set(stdio_names[i], stdio_devices[i]->name);
        }
 
        gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */