Add support for writing a single 64-bit value into a property.

Repurpose the existing tests to handle this case too.

Signed-off-by: Simon Glass <s...@chromium.org>
---

(no changes since v1)

 drivers/core/ofnode.c | 17 ++++++++++++++++-
 include/dm/ofnode.h   | 10 ++++++++++
 test/dm/ofnode.c      | 15 +++++++++++++--
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 4dcb3dd1c037..18d2eb0f1186 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -1621,7 +1621,22 @@ int ofnode_write_u32(ofnode node, const char *propname, 
u32 value)
                return -ENOMEM;
        *val = cpu_to_fdt32(value);
 
-       return ofnode_write_prop(node, propname, val, sizeof(value), false);
+       return ofnode_write_prop(node, propname, val, sizeof(value), true);
+}
+
+int ofnode_write_u64(ofnode node, const char *propname, u64 value)
+{
+       fdt64_t *val;
+
+       assert(ofnode_valid(node));
+
+       log_debug("%s = %llx", propname, (unsigned long long)value);
+       val = malloc(sizeof(*val));
+       if (!val)
+               return -ENOMEM;
+       *val = cpu_to_fdt64(value);
+
+       return ofnode_write_prop(node, propname, val, sizeof(value), true);
 }
 
 int ofnode_write_bool(ofnode node, const char *propname, bool value)
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index ebea29d32afc..ef1437cc5562 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -1461,6 +1461,16 @@ int ofnode_write_string(ofnode node, const char 
*propname, const char *value);
  */
 int ofnode_write_u32(ofnode node, const char *propname, u32 value);
 
+/**
+ * ofnode_write_u64() - Set an integer property of an ofnode
+ *
+ * @node:      The node for whose string property should be set
+ * @propname:  The name of the string property to set
+ * @value:     The new value of the 64-bit integer property
+ * Return: 0 if successful, -ve on error
+ */
+int ofnode_write_u64(ofnode node, const char *propname, u64 value);
+
 /**
  * ofnode_write_bool() - Set a boolean property of an ofnode
  *
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 9477f791d649..e078a9755a83 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -1009,7 +1009,8 @@ static int dm_test_ofnode_u32_array(struct 
unit_test_state *uts)
 }
 DM_TEST(dm_test_ofnode_u32_array, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
-static int dm_test_ofnode_read_u64(struct unit_test_state *uts)
+/* test ofnode_read_u64() and ofnode_write_u64() */
+static int dm_test_ofnode_u64(struct unit_test_state *uts)
 {
        ofnode node;
        u64 val;
@@ -1018,6 +1019,10 @@ static int dm_test_ofnode_read_u64(struct 
unit_test_state *uts)
        ut_assert(ofnode_valid(node));
        ut_assertok(ofnode_read_u64(node, "int64-value", &val));
        ut_asserteq_64(0x1111222233334444, val);
+       ut_assertok(ofnode_write_u64(node, "new-int64-value", 0x9876543210));
+       ut_assertok(ofnode_read_u64(node, "new-int64-value", &val));
+       ut_asserteq_64(0x9876543210, val);
+
        ut_asserteq(-EINVAL, ofnode_read_u64(node, "missing", &val));
 
        ut_assertok(ofnode_read_u64_index(node, "int64-array", 0, &val));
@@ -1028,9 +1033,15 @@ static int dm_test_ofnode_read_u64(struct 
unit_test_state *uts)
                    ofnode_read_u64_index(node, "int64-array", 2, &val));
        ut_asserteq(-EINVAL, ofnode_read_u64_index(node, "missing", 0, &val));
 
+       ut_assertok(ofnode_write_u64(node, "int64-array", 0x9876543210));
+       ut_assertok(ofnode_read_u64_index(node, "int64-array", 0, &val));
+       ut_asserteq_64(0x9876543210, val);
+       ut_asserteq(-EOVERFLOW,
+                   ofnode_read_u64_index(node, "int64-array", 1, &val));
+
        return 0;
 }
-DM_TEST(dm_test_ofnode_read_u64, UT_TESTF_SCAN_FDT);
+DM_TEST(dm_test_ofnode_u64, UT_TESTF_SCAN_FDT);
 
 static int dm_test_ofnode_add_subnode(struct unit_test_state *uts)
 {
-- 
2.42.0.515.g380fc7ccd1-goog

Reply via email to