summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSimon Glass <[email protected]>2020-01-27 08:49:47 -0700
committerSimon Glass <[email protected]>2020-02-05 19:33:45 -0700
commitf262d4ca4b2bf8a99acb37c6151c54cd80251566 (patch)
treeb61079187edfb4d66f8fed45577f694e083beafb /include
parentbd933bfd834364bca6cc6f3a62e4255090a5bec1 (diff)
dm: core: Add a way to read platdata for all child devices
When generating ACPI tables we need to make sure that all devices have read their platform data, so that they can generate the tables correctly. Rather than adding this code in ACPI, create a core function to handle it. Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'include')
-rw-r--r--include/dm/device.h42
-rw-r--r--include/dm/read.h3
2 files changed, 44 insertions, 1 deletions
diff --git a/include/dm/device.h b/include/dm/device.h
index 611fc2e1973..2618952336c 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -578,6 +578,31 @@ int device_find_child_by_name(const struct udevice *parent, const char *name,
struct udevice **devp);
/**
+ * device_first_child_ofdata_err() - Find the first child and reads its platdata
+ *
+ * The ofdata_to_platdata() method is called on the child before it is returned,
+ * but the child is not probed.
+ *
+ * @parent: Parent to check
+ * @devp: Returns child that was found, if any
+ * @return 0 on success, -ENODEV if no children, other -ve on error
+ */
+int device_first_child_ofdata_err(struct udevice *parent,
+ struct udevice **devp);
+
+/*
+ * device_next_child_ofdata_err() - Find the next child and read its platdata
+ *
+ * The ofdata_to_platdata() method is called on the child before it is returned,
+ * but the child is not probed.
+ *
+ * @devp: On entry, points to the previous child; on exit returns the child that
+ * was found, if any
+ * @return 0 on success, -ENODEV if no children, other -ve on error
+ */
+int device_next_child_ofdata_err(struct udevice **devp);
+
+/**
* device_has_children() - check if a device has any children
*
* @dev: Device to check
@@ -707,6 +732,23 @@ static inline bool device_is_on_pci_bus(const struct udevice *dev)
list_for_each_entry(pos, &parent->child_head, sibling_node)
/**
+ * device_foreach_child_ofdata_to_platdata() - iterate through children
+ *
+ * This stops when it gets an error, with @pos set to the device that failed to
+ * read ofdata.
+
+ * This creates a for() loop which works through the available children of
+ * a device in order from start to end. Device ofdata is read by calling
+ * device_ofdata_to_platdata() on each one. The devices are not probed.
+ *
+ * @pos: struct udevice * for the current device
+ * @parent: parent device to scan
+ */
+#define device_foreach_child_ofdata_to_platdata(pos, parent) \
+ for (int _ret = device_first_child_ofdata_err(parent, &dev); !_ret; \
+ _ret = device_next_child_ofdata_err(&dev))
+
+/**
* dm_scan_fdt_dev() - Bind child device in a the device tree
*
* This handles device which have sub-nodes in the device tree. It scans all
diff --git a/include/dm/read.h b/include/dm/read.h
index 92a7328fc8f..da8c7f25e7c 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -844,7 +844,8 @@ static inline ofnode dev_read_next_subnode(ofnode node)
}
static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
- const char *propname, size_t sz)
+ const char *propname,
+ size_t sz)
{
return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
}