]> Git Repo - u-boot.git/blobdiff - drivers/core/devres.c
Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
[u-boot.git] / drivers / core / devres.c
index 36a8b1eb5f8cfcb0e1456d2d61f7e7a21dcb76ff..8df08b91021c3758a9d37216f426a21e9592c9a9 100644 (file)
@@ -9,20 +9,33 @@
 
 #define LOG_CATEGORY LOGC_DEVRES
 
-#include <common.h>
+#include <log.h>
+#include <malloc.h>
 #include <linux/compat.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <dm/device.h>
+#include <dm/devres.h>
 #include <dm/root.h>
 #include <dm/util.h>
 
+/** enum devres_phase - Shows where resource was allocated
+ *
+ * DEVRES_PHASE_BIND: In the bind() method
+ * DEVRES_PHASE_OFDATA: In the of_to_plat() method
+ * DEVRES_PHASE_PROBE: In the probe() method
+ */
+enum devres_phase {
+       DEVRES_PHASE_BIND,
+       DEVRES_PHASE_OFDATA,
+       DEVRES_PHASE_PROBE,
+};
+
 /**
  * struct devres - Bookkeeping info for managed device resource
  * @entry: List to associate this structure with a device
  * @release: Callback invoked when this resource is released
- * @probe: Flag to show when this resource was allocated
-          (true = probe, false = bind)
+ * @probe: Show where this resource was allocated
  * @name: Name of release function
  * @size: Size of resource data
  * @data: Resource data
@@ -30,7 +43,7 @@
 struct devres {
        struct list_head                entry;
        dr_release_t                    release;
-       bool                            probe;
+       enum devres_phase               phase;
 #ifdef CONFIG_DEBUG_DEVRES
        const char                      *name;
        size_t                          size;
@@ -93,7 +106,12 @@ void devres_add(struct udevice *dev, void *res)
 
        devres_log(dev, dr, "ADD");
        assert_noisy(list_empty(&dr->entry));
-       dr->probe = dev->flags & DM_FLAG_BOUND ? true : false;
+       if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
+               dr->phase = DEVRES_PHASE_PROBE;
+       else if (dev_get_flags(dev) & DM_FLAG_BOUND)
+               dr->phase = DEVRES_PHASE_OFDATA;
+       else
+               dr->phase = DEVRES_PHASE_BIND;
        list_add_tail(&dr->entry, &dev->devres_head);
 }
 
@@ -174,12 +192,12 @@ int devres_release(struct udevice *dev, dr_release_t release,
 }
 
 static void release_nodes(struct udevice *dev, struct list_head *head,
-                         bool probe_only)
+                         bool probe_and_ofdata_only)
 {
        struct devres *dr, *tmp;
 
        list_for_each_entry_safe_reverse(dr, tmp, head, entry)  {
-               if (probe_only && !dr->probe)
+               if (probe_and_ofdata_only && dr->phase == DEVRES_PHASE_BIND)
                        break;
                devres_log(dev, dr, "REL");
                dr->release(dev, dr->data);
@@ -199,6 +217,8 @@ void devres_release_all(struct udevice *dev)
 }
 
 #ifdef CONFIG_DEBUG_DEVRES
+static char *const devres_phase_name[] = {"BIND", "OFDATA", "PROBE"};
+
 static void dump_resources(struct udevice *dev, int depth)
 {
        struct devres *dr;
@@ -209,9 +229,9 @@ static void dump_resources(struct udevice *dev, int depth)
        list_for_each_entry(dr, &dev->devres_head, entry)
                printf("    %p (%lu byte) %s  %s\n", dr,
                       (unsigned long)dr->size, dr->name,
-                      dr->probe ? "PROBE" : "BIND");
+                      devres_phase_name[dr->phase]);
 
-       list_for_each_entry(child, &dev->child_head, sibling_node)
+       device_foreach_child(child, dev)
                dump_resources(child, depth + 1);
 }
 
This page took 0.026633 seconds and 4 git commands to generate.