]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/console.c
rename CFG_ macros to CONFIG_SYS
[karo-tx-uboot.git] / common / console.c
index d8a0cb6c7e8a1d43e43ad066514e23a72f88327e..6f0846f5ee5db302b7cd486caaea9528cf0cc57d 100644 (file)
@@ -33,20 +33,20 @@ DECLARE_GLOBAL_DATA_PTR;
 int console_changed = 0;
 #endif
 
-#ifdef CFG_CONSOLE_IS_IN_ENV
+#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
 /*
  * if overwrite_console returns 1, the stdin, stderr and stdout
  * are switched to the serial port, else the settings in the
  * environment are used
  */
-#ifdef CFG_CONSOLE_OVERWRITE_ROUTINE
+#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
 extern int overwrite_console (void);
 #define OVERWRITE_CONSOLE overwrite_console ()
 #else
 #define OVERWRITE_CONSOLE 0
-#endif /* CFG_CONSOLE_OVERWRITE_ROUTINE */
+#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
 
-#endif /* CFG_CONSOLE_IS_IN_ENV */
+#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
 
 static int console_setfile (int file, device_t * dev)
 {
@@ -99,7 +99,7 @@ void serial_printf (const char *fmt, ...)
 {
        va_list args;
        uint i;
-       char printbuffer[CFG_PBSIZE];
+       char printbuffer[CONFIG_SYS_PBSIZE];
 
        va_start (args, fmt);
 
@@ -144,7 +144,7 @@ void fprintf (int file, const char *fmt, ...)
 {
        va_list args;
        uint i;
-       char printbuffer[CFG_PBSIZE];
+       char printbuffer[CONFIG_SYS_PBSIZE];
 
        va_start (args, fmt);
 
@@ -162,6 +162,11 @@ void fprintf (int file, const char *fmt, ...)
 
 int getc (void)
 {
+#ifdef CONFIG_DISABLE_CONSOLE
+       if (gd->flags & GD_FLG_DISABLE_CONSOLE)
+               return 0;
+#endif
+
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Get from the standard input */
                return fgetc (stdin);
@@ -173,6 +178,11 @@ int getc (void)
 
 int tstc (void)
 {
+#ifdef CONFIG_DISABLE_CONSOLE
+       if (gd->flags & GD_FLG_DISABLE_CONSOLE)
+               return 0;
+#endif
+
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Test the standard input */
                return ftstc (stdin);
@@ -189,6 +199,11 @@ void putc (const char c)
                return;
 #endif
 
+#ifdef CONFIG_DISABLE_CONSOLE
+       if (gd->flags & GD_FLG_DISABLE_CONSOLE)
+               return;
+#endif
+
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Send to the standard output */
                fputc (stdout, c);
@@ -205,6 +220,11 @@ void puts (const char *s)
                return;
 #endif
 
+#ifdef CONFIG_DISABLE_CONSOLE
+       if (gd->flags & GD_FLG_DISABLE_CONSOLE)
+               return;
+#endif
+
        if (gd->flags & GD_FLG_DEVINIT) {
                /* Send to the standard output */
                fputs (stdout, s);
@@ -218,7 +238,7 @@ void printf (const char *fmt, ...)
 {
        va_list args;
        uint i;
-       char printbuffer[CFG_PBSIZE];
+       char printbuffer[CONFIG_SYS_PBSIZE];
 
        va_start (args, fmt);
 
@@ -235,7 +255,7 @@ void printf (const char *fmt, ...)
 void vprintf (const char *fmt, va_list args)
 {
        uint i;
-       char printbuffer[CFG_PBSIZE];
+       char printbuffer[CONFIG_SYS_PBSIZE];
 
        /* For this to work, printbuffer must be larger than
         * anything we ever want to print.
@@ -294,7 +314,7 @@ inline void dbg(const char *fmt, ...)
 {
        va_list args;
        uint    i;
-       char    printbuffer[CFG_PBSIZE];
+       char    printbuffer[CONFIG_SYS_PBSIZE];
 
        if (!once) {
                memset(screen, 0, sizeof(screen));
@@ -325,9 +345,22 @@ inline void dbg(const char *fmt, ...)
 
 /** U-Boot INIT FUNCTIONS *************************************************/
 
+device_t *search_device (int flags, char *name)
+{
+       device_t *dev;
+
+       dev = device_get_by_name(name);
+
+       if(dev && (dev->flags & flags))
+               return dev;
+
+       return NULL;
+}
+
 int console_assign (int file, char *devname)
 {
-       int flag, i;
+       int flag;
+       device_t *dev;
 
        /* Check for valid file */
        switch (file) {
@@ -344,16 +377,10 @@ int console_assign (int file, char *devname)
 
        /* Check for valid device name */
 
-       for (i = 1; i <= ListNumItems (devlist); i++) {
-               device_t *dev = ListGetPtrToItem (devlist, i);
-
-               if (strcmp (devname, dev->name) == 0) {
-                       if (dev->flags & flag)
-                               return console_setfile (file, dev);
+       dev = search_device(flag, devname);
 
-                       return -1;
-               }
-       }
+       if(dev)
+               return console_setfile (file, dev);
 
        return -1;
 }
@@ -371,36 +398,15 @@ int console_init_f (void)
        return (0);
 }
 
-#if defined(CFG_CONSOLE_IS_IN_ENV) || defined(CONFIG_SPLASH_SCREEN) || defined(CONFIG_SILENT_CONSOLE)
-/* search a device */
-device_t *search_device (int flags, char *name)
-{
-       int i, items;
-       device_t *dev = NULL;
-
-       items = ListNumItems (devlist);
-       if (name == NULL)
-               return dev;
-
-       for (i = 1; i <= items; i++) {
-               dev = ListGetPtrToItem (devlist, i);
-               if ((dev->flags & flags) && (strcmp (name, dev->name) == 0)) {
-                       break;
-               }
-       }
-       return dev;
-}
-#endif /* CFG_CONSOLE_IS_IN_ENV || CONFIG_SPLASH_SCREEN */
-
-#ifdef CFG_CONSOLE_IS_IN_ENV
+#ifdef CONFIG_SYS_CONSOLE_IS_IN_ENV
 /* Called after the relocation - use desired console functions */
 int console_init_r (void)
 {
        char *stdinname, *stdoutname, *stderrname;
        device_t *inputdev = NULL, *outputdev = NULL, *errdev = NULL;
-#ifdef CFG_CONSOLE_ENV_OVERWRITE
+#ifdef CONFIG_SYS_CONSOLE_ENV_OVERWRITE
        int i;
-#endif /* CFG_CONSOLE_ENV_OVERWRITE */
+#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
 
        /* set default handlers at first */
        gd->jt[XF_getc] = serial_getc;
@@ -415,7 +421,7 @@ int console_init_r (void)
        stdoutname = getenv ("stdout");
        stderrname = getenv ("stderr");
 
-       if (OVERWRITE_CONSOLE == 0) {   /* if not overwritten by config switch */
+       if (OVERWRITE_CONSOLE == 0) {   /* if not overwritten by config switch */
                inputdev  = search_device (DEV_FLAGS_INPUT,  stdinname);
                outputdev = search_device (DEV_FLAGS_OUTPUT, stdoutname);
                errdev    = search_device (DEV_FLAGS_OUTPUT, stderrname);
@@ -443,7 +449,7 @@ int console_init_r (void)
 
        gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */
 
-#ifndef CFG_CONSOLE_INFO_QUIET
+#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
        /* Print information */
        puts ("In:    ");
        if (stdio_devices[stdin] == NULL) {
@@ -465,14 +471,14 @@ int console_init_r (void)
        } else {
                printf ("%s\n", stdio_devices[stderr]->name);
        }
-#endif /* CFG_CONSOLE_INFO_QUIET */
+#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
 
-#ifdef CFG_CONSOLE_ENV_OVERWRITE
+#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);
        }
-#endif /* CFG_CONSOLE_ENV_OVERWRITE */
+#endif /* CONFIG_SYS_CONSOLE_ENV_OVERWRITE */
 
 #if 0
        /* If nothing usable installed, use only the initial console */
@@ -482,13 +488,16 @@ int console_init_r (void)
        return (0);
 }
 
-#else /* CFG_CONSOLE_IS_IN_ENV */
+#else /* CONFIG_SYS_CONSOLE_IS_IN_ENV */
 
 /* Called after the relocation - use desired console functions */
 int console_init_r (void)
 {
        device_t *inputdev = NULL, *outputdev = NULL;
-       int i, items = ListNumItems (devlist);
+       int i;
+       struct list_head *list = device_get_list();
+       struct list_head *pos;
+       device_t *dev;
 
 #ifdef CONFIG_SPLASH_SCREEN
        /* suppress all output if splash screen is enabled and we have
@@ -498,11 +507,8 @@ int console_init_r (void)
 #endif
 
        /* Scan devices looking for input and output devices */
-       for (i = 1;
-            (i <= items) && ((inputdev == NULL) || (outputdev == NULL));
-            i++
-           ) {
-               device_t *dev = ListGetPtrToItem (devlist, i);
+       list_for_each(pos, list) {
+               dev = list_entry(pos, device_t, list);
 
                if ((dev->flags & DEV_FLAGS_INPUT) && (inputdev == NULL)) {
                        inputdev = dev;
@@ -510,6 +516,8 @@ int console_init_r (void)
                if ((dev->flags & DEV_FLAGS_OUTPUT) && (outputdev == NULL)) {
                        outputdev = dev;
                }
+               if(inputdev && outputdev)
+                       break;
        }
 
        /* Initializes output console first */
@@ -525,7 +533,7 @@ int console_init_r (void)
 
        gd->flags |= GD_FLG_DEVINIT;    /* device initialization completed */
 
-#ifndef CFG_CONSOLE_INFO_QUIET
+#ifndef CONFIG_SYS_CONSOLE_INFO_QUIET
        /* Print information */
        puts ("In:    ");
        if (stdio_devices[stdin] == NULL) {
@@ -547,7 +555,7 @@ int console_init_r (void)
        } else {
                printf ("%s\n", stdio_devices[stderr]->name);
        }
-#endif /* CFG_CONSOLE_INFO_QUIET */
+#endif /* CONFIG_SYS_CONSOLE_INFO_QUIET */
 
        /* Setting environment variables */
        for (i = 0; i < 3; i++) {
@@ -563,4 +571,4 @@ int console_init_r (void)
        return (0);
 }
 
-#endif /* CFG_CONSOLE_IS_IN_ENV */
+#endif /* CONFIG_SYS_CONSOLE_IS_IN_ENV */