dm: serial: Separate out the core serial-device finding code

This function is quite long. Move the core code into a separate function
in preparation for adding livetree support.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Tested-on: Beaver, Jetson-TK1
This commit is contained in:
Simon Glass 2017-06-12 06:21:57 -06:00
parent db9f8f6ad5
commit d09608534c

View file

@ -8,7 +8,6 @@
#include <dm.h> #include <dm.h>
#include <environment.h> #include <environment.h>
#include <errno.h> #include <errno.h>
#include <fdtdec.h>
#include <os.h> #include <os.h>
#include <serial.h> #include <serial.h>
#include <stdio_dev.h> #include <stdio_dev.h>
@ -27,19 +26,10 @@ static const unsigned long baudrate_table[] = CONFIG_SYS_BAUDRATE_TABLE;
#error "Serial is required before relocation - define CONFIG_SYS_MALLOC_F_LEN to make this work" #error "Serial is required before relocation - define CONFIG_SYS_MALLOC_F_LEN to make this work"
#endif #endif
static void serial_find_console_or_panic(void) static int serial_check_stdout(const void *blob, struct udevice **devp)
{ {
const void *blob = gd->fdt_blob;
struct udevice *dev;
int node; int node;
if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
uclass_first_device(UCLASS_SERIAL, &dev);
if (dev) {
gd->cur_serial_dev = dev;
return;
}
} else if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) {
/* Check for a chosen console */ /* Check for a chosen console */
node = fdtdec_get_chosen_node(blob, "stdout-path"); node = fdtdec_get_chosen_node(blob, "stdout-path");
if (node < 0) { if (node < 0) {
@ -49,8 +39,8 @@ static void serial_find_console_or_panic(void)
* Deal with things like * Deal with things like
* stdout-path = "serial0:115200n8"; * stdout-path = "serial0:115200n8";
* *
* We need to look up the alias and then follow it to * We need to look up the alias and then follow it to the
* the correct node. * correct node.
*/ */
str = fdtdec_get_chosen_prop(blob, "stdout-path"); str = fdtdec_get_chosen_prop(blob, "stdout-path");
if (str) { if (str) {
@ -63,23 +53,37 @@ static void serial_find_console_or_panic(void)
} }
if (node < 0) if (node < 0)
node = fdt_path_offset(blob, "console"); node = fdt_path_offset(blob, "console");
if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, devp))
&dev)) { return 0;
gd->cur_serial_dev = dev;
return;
}
/* /*
* If the console is not marked to be bound before relocation, * If the console is not marked to be bound before relocation, bind it
* bind it anyway. * anyway.
*/ */
if (node > 0 && if (node > 0 && !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node),
!lists_bind_fdt(gd->dm_root, offset_to_ofnode(node), devp)) {
&dev)) { if (!device_probe(*devp))
if (!device_probe(dev)) { return 0;
}
return -ENODEV;
}
static void serial_find_console_or_panic(void)
{
const void *blob = gd->fdt_blob;
struct udevice *dev;
if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
uclass_first_device(UCLASS_SERIAL, &dev);
if (dev) {
gd->cur_serial_dev = dev; gd->cur_serial_dev = dev;
return; return;
} }
} else if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) {
if (!serial_check_stdout(blob, &dev)) {
gd->cur_serial_dev = dev;
return;
} }
} }
if (!SPL_BUILD || !CONFIG_IS_ENABLED(OF_CONTROL) || !blob) { if (!SPL_BUILD || !CONFIG_IS_ENABLED(OF_CONTROL) || !blob) {