summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-06-12 06:21:57 -0600
committerSimon Glass <sjg@chromium.org>2017-07-11 10:08:20 -0600
commitd09608534cb4864d1fbde6459d3501129c344a0c (patch)
treefea45473632db38c91c8335a3955bf443a919ed4 /drivers
parentdb9f8f6ad5718909c57aee9a9f476309ac790e1f (diff)
downloadu-boot-d09608534cb4864d1fbde6459d3501129c344a0c.tar.gz
u-boot-d09608534cb4864d1fbde6459d3501129c344a0c.tar.xz
u-boot-d09608534cb4864d1fbde6459d3501129c344a0c.zip
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
Diffstat (limited to 'drivers')
-rw-r--r--drivers/serial/serial-uclass.c84
1 files changed, 44 insertions, 40 deletions
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 200f4b9fd7..7e4290684c 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -8,7 +8,6 @@
#include <dm.h>
#include <environment.h>
#include <errno.h>
-#include <fdtdec.h>
#include <os.h>
#include <serial.h>
#include <stdio_dev.h>
@@ -27,11 +26,53 @@ 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"
#endif
+static int serial_check_stdout(const void *blob, struct udevice **devp)
+{
+ int node;
+
+ /* Check for a chosen console */
+ node = fdtdec_get_chosen_node(blob, "stdout-path");
+ if (node < 0) {
+ const char *str, *p, *name;
+
+ /*
+ * Deal with things like
+ * stdout-path = "serial0:115200n8";
+ *
+ * We need to look up the alias and then follow it to the
+ * correct node.
+ */
+ str = fdtdec_get_chosen_prop(blob, "stdout-path");
+ if (str) {
+ p = strchr(str, ':');
+ name = fdt_get_alias_namelen(blob, str,
+ p ? p - str : strlen(str));
+ if (name)
+ node = fdt_path_offset(blob, name);
+ }
+ }
+ if (node < 0)
+ node = fdt_path_offset(blob, "console");
+ if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node, devp))
+ return 0;
+
+ /*
+ * If the console is not marked to be bound before relocation, bind it
+ * anyway.
+ */
+ if (node > 0 && !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node),
+ devp)) {
+ if (!device_probe(*devp))
+ return 0;
+ }
+
+ return -ENODEV;
+}
+
static void serial_find_console_or_panic(void)
{
const void *blob = gd->fdt_blob;
struct udevice *dev;
- int node;
if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
uclass_first_device(UCLASS_SERIAL, &dev);
@@ -40,47 +81,10 @@ static void serial_find_console_or_panic(void)
return;
}
} else if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) {
- /* Check for a chosen console */
- node = fdtdec_get_chosen_node(blob, "stdout-path");
- if (node < 0) {
- const char *str, *p, *name;
-
- /*
- * Deal with things like
- * stdout-path = "serial0:115200n8";
- *
- * We need to look up the alias and then follow it to
- * the correct node.
- */
- str = fdtdec_get_chosen_prop(blob, "stdout-path");
- if (str) {
- p = strchr(str, ':');
- name = fdt_get_alias_namelen(blob, str,
- p ? p - str : strlen(str));
- if (name)
- node = fdt_path_offset(blob, name);
- }
- }
- if (node < 0)
- node = fdt_path_offset(blob, "console");
- if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node,
- &dev)) {
+ if (!serial_check_stdout(blob, &dev)) {
gd->cur_serial_dev = dev;
return;
}
-
- /*
- * If the console is not marked to be bound before relocation,
- * bind it anyway.
- */
- if (node > 0 &&
- !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node),
- &dev)) {
- if (!device_probe(dev)) {
- gd->cur_serial_dev = dev;
- return;
- }
- }
}
if (!SPL_BUILD || !CONFIG_IS_ENABLED(OF_CONTROL) || !blob) {
/*