dm: serial: Support CONFIG_CONS_INDEX if available
authorSimon Glass <sjg@chromium.org>
Thu, 23 Oct 2014 03:37:06 +0000 (21:37 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 24 Oct 2014 01:29:07 +0000 (19:29 -0600)
Try to use this option to select the correct uart for the console. This
mimics the behaviour of drivers/serial.c.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@ti.com>
drivers/serial/serial-uclass.c

index 1983a3d55bde3850bcd7369e8a5a807260fcf4f5..c9383dcd00c13e41fbaccc0d07a86ba898edfbc5 100644 (file)
@@ -50,13 +50,22 @@ static void serial_find_console_or_panic(void)
        }
 #endif
        /*
+        * Try to use CONFIG_CONS_INDEX if available (it is numbered from 1!).
+        *
         * Failing that, get the device with sequence number 0, or in extremis
         * just the first serial device we can find. But we insist on having
         * a console (even if it is silent).
         */
-       if (uclass_get_device_by_seq(UCLASS_SERIAL, 0, &cur_dev) &&
+#ifdef CONFIG_CONS_INDEX
+#define INDEX (CONFIG_CONS_INDEX - 1)
+#else
+#define INDEX 0
+#endif
+       if (uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &cur_dev) &&
+           uclass_get_device(UCLASS_SERIAL, INDEX, &cur_dev) &&
            (uclass_first_device(UCLASS_SERIAL, &cur_dev) || !cur_dev))
                panic("No serial driver found");
+#undef INDEX
 }
 
 /* Called prior to relocation */