serial: Reorder get_current()
[oweals/u-boot.git] / drivers / serial / serial.c
index 5bbf3aeb4456faaa9f154d9fcb2b4338e868c770..18b9ed4330f6449958e3e0fbf01b63f0b2d2e6bf 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdio_dev.h>
 #include <post.h>
 #include <linux/compiler.h>
+#include <errno.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -205,13 +206,13 @@ int serial_assign(const char *name)
        struct serial_device *s;
 
        for (s = serial_devices; s; s = s->next) {
-               if (strcmp(s->name, name) == 0) {
-                       serial_current = s;
-                       return 0;
-               }
+               if (strcmp(s->name, name))
+                       continue;
+               serial_current = s;
+               return 0;
        }
 
-       return 1;
+       return -EINVAL;
 }
 
 void serial_reinit_all(void)
@@ -226,20 +227,23 @@ static struct serial_device *get_current(void)
 {
        struct serial_device *dev;
 
-       if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
+       if (!(gd->flags & GD_FLG_RELOC))
                dev = default_serial_console();
+       else if (!serial_current)
+               dev = default_serial_console();
+       else
+               dev = serial_current;
 
-               /* We must have a console device */
-               if (!dev) {
+       /* We must have a console device */
+       if (!dev) {
 #ifdef CONFIG_SPL_BUILD
-                       puts("Cannot find console\n");
-                       hang();
+               puts("Cannot find console\n");
+               hang();
 #else
-                       panic("Cannot find console\n");
+               panic("Cannot find console\n");
 #endif
-               }
-       } else
-               dev = serial_current;
+       }
+
        return dev;
 }
 
@@ -273,6 +277,13 @@ void serial_puts(const char *s)
        get_current()->puts(s);
 }
 
+void default_serial_puts(const char *s)
+{
+       struct serial_device *dev = get_current();
+       while (*s)
+               dev->putc(*s++);
+}
+
 #if CONFIG_POST & CONFIG_SYS_POST_UART
 static const int bauds[] = CONFIG_SYS_BAUDRATE_TABLE;