]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - drivers/core/root.c
dm: core: Ignore disabled devices when binding
[karo-tx-uboot.git] / drivers / core / root.c
index 60597563d6c42b0f1945363ed647ca981e6d9ace..73e3c7228e300e67da317098160d9c9c988446b3 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <common.h>
 #include <errno.h>
+#include <fdtdec.h>
 #include <malloc.h>
 #include <libfdt.h>
 #include <dm/device.h>
@@ -49,6 +50,9 @@ int dm_init(void)
        ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST);
        if (ret)
                return ret;
+#ifdef CONFIG_OF_CONTROL
+       DM_ROOT_NON_CONST->of_offset = 0;
+#endif
        ret = device_probe(DM_ROOT_NON_CONST);
        if (ret)
                return ret;
@@ -73,38 +77,48 @@ int dm_scan_platdata(bool pre_reloc_only)
                dm_warn("Some drivers were not found\n");
                ret = 0;
        }
-       if (ret)
-               return ret;
 
-       return 0;
+       return ret;
 }
 
 #ifdef CONFIG_OF_CONTROL
-int dm_scan_fdt(const void *blob, bool pre_reloc_only)
+int dm_scan_fdt_node(struct udevice *parent, const void *blob, int offset,
+                    bool pre_reloc_only)
 {
-       int offset = 0;
        int ret = 0, err;
-       int depth = 0;
-
-       do {
-               offset = fdt_next_node(blob, offset, &depth);
-               if (offset > 0 && depth == 1) {
-                       if (pre_reloc_only &&
-                           !fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
-                               continue;
-                       err = lists_bind_fdt(gd->dm_root, blob, offset);
-                       if (err && !ret)
-                               ret = err;
+
+       for (offset = fdt_first_subnode(blob, offset);
+            offset > 0;
+            offset = fdt_next_subnode(blob, offset)) {
+               if (pre_reloc_only &&
+                   !fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
+                       continue;
+               if (!fdtdec_get_is_enabled(blob, offset)) {
+                       dm_dbg("   - ignoring disabled device\n");
+                       continue;
                }
-       } while (offset > 0);
+               err = lists_bind_fdt(parent, blob, offset, NULL);
+               if (err && !ret)
+                       ret = err;
+       }
 
        if (ret)
                dm_warn("Some drivers failed to bind\n");
 
        return ret;
 }
+
+int dm_scan_fdt(const void *blob, bool pre_reloc_only)
+{
+       return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only);
+}
 #endif
 
+__weak int dm_scan_other(bool pre_reloc_only)
+{
+       return 0;
+}
+
 int dm_init_and_scan(bool pre_reloc_only)
 {
        int ret;
@@ -126,6 +140,9 @@ int dm_init_and_scan(bool pre_reloc_only)
                return ret;
        }
 #endif
+       ret = dm_scan_other(pre_reloc_only);
+       if (ret)
+               return ret;
 
        return 0;
 }