dm: core: implement phandle ofnode_options helper
authorChristian Marangi <ansuelsmth@gmail.com>
Sun, 10 Nov 2024 11:50:24 +0000 (12:50 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 6 Dec 2024 19:00:41 +0000 (13:00 -0600)
Implement ofnode_options phandle helper to get an ofnode from a phandle
option in /options/u-boot.

This helper can be useful since new DT yaml usually require to link a
phandle of a node instead of referencing it by name or other indirect
way.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/core/ofnode.c
include/dm/ofnode.h

index dc6ac06..c816182 100644 (file)
@@ -1871,6 +1871,21 @@ const char *ofnode_options_read_str(const char *prop_name)
        return ofnode_read_string(uboot, prop_name);
 }
 
+int ofnode_options_get_by_phandle(const char *prop_name, ofnode *nodep)
+{
+       ofnode uboot;
+
+       uboot = ofnode_path("/options/u-boot");
+       if (!ofnode_valid(uboot))
+               return -EINVAL;
+
+       *nodep = ofnode_parse_phandle(uboot, prop_name, 0);
+       if (!ofnode_valid(*nodep))
+               return -EINVAL;
+
+       return 0;
+}
+
 int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset)
 {
        int ret;
index eea6b13..890f0e6 100644 (file)
@@ -1720,6 +1720,21 @@ int ofnode_options_read_int(const char *prop_name, int default_val);
  */
 const char *ofnode_options_read_str(const char *prop_name);
 
+/**
+ * ofnode_options_get_by_phandle() - Get a ofnode from phandle from the U-Boot options
+ *
+ * This reads a property from the /options/u-boot/ node of the devicetree.
+ *
+ * This only works with the control FDT.
+ *
+ * See dtschema/schemas/options/u-boot.yaml in dt-schema project for bindings
+ *
+ * @prop_name: property name to look up
+ * @nodep: pointer to ofnode where node is stored
+ * Return: 0, if found, or negative error if not
+ */
+int ofnode_options_get_by_phandle(const char *prop_name, ofnode *nodep);
+
 /**
  * ofnode_read_bootscript_address() - Read bootscr-address or bootscr-ram-offset
  *