]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Support writing a 64-bit value
authorSimon Glass <sjg@chromium.org>
Tue, 26 Sep 2023 14:14:45 +0000 (08:14 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 6 Oct 2023 18:38:13 +0000 (14:38 -0400)
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 <sjg@chromium.org>
drivers/core/ofnode.c
include/dm/ofnode.h
test/dm/ofnode.c

index 4dcb3dd1c03725882b4ad9a1e0c20405a0d6bebe..18d2eb0f1186327f0e4e03d93d807ab26c6470ba 100644 (file)
@@ -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)
index ebea29d32afc36d4bb3124f4fc9eda93cbf0800f..ef1437cc556231b1faa7544f09d0a77786b1dd4b 100644 (file)
@@ -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
  *
index 9477f791d6493541b2a0a31798a51b2c944c2237..e078a9755a830bf7118dee2a7e0354597f578bf3 100644 (file)
@@ -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)
 {