dm: core: Add support for writing u32 with ofnode
Add a new function to write an integer to an ofnode (live tree or flat tree). Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
39e42be12b
commit
55f7990bfe
@ -1126,6 +1126,21 @@ int ofnode_write_string(ofnode node, const char *propname, const char *value)
|
|||||||
return ofnode_write_prop(node, propname, value, strlen(value) + 1);
|
return ofnode_write_prop(node, propname, value, strlen(value) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ofnode_write_u32(ofnode node, const char *propname, u32 value)
|
||||||
|
{
|
||||||
|
fdt32_t *val;
|
||||||
|
|
||||||
|
assert(ofnode_valid(node));
|
||||||
|
|
||||||
|
log_debug("%s = %x", propname, value);
|
||||||
|
val = malloc(sizeof(*val));
|
||||||
|
if (!val)
|
||||||
|
return -ENOMEM;
|
||||||
|
*val = cpu_to_fdt32(value);
|
||||||
|
|
||||||
|
return ofnode_write_prop(node, propname, val, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
int ofnode_set_enabled(ofnode node, bool value)
|
int ofnode_set_enabled(ofnode node, bool value)
|
||||||
{
|
{
|
||||||
assert(ofnode_valid(node));
|
assert(ofnode_valid(node));
|
||||||
|
@ -1154,6 +1154,16 @@ int ofnode_write_prop(ofnode node, const char *propname, const void *value,
|
|||||||
*/
|
*/
|
||||||
int ofnode_write_string(ofnode node, const char *propname, const char *value);
|
int ofnode_write_string(ofnode node, const char *propname, const char *value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ofnode_write_u32() - 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 32-bit integer property
|
||||||
|
* Return: 0 if successful, -ve on error
|
||||||
|
*/
|
||||||
|
int ofnode_write_u32(ofnode node, const char *propname, u32 value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ofnode_set_enabled() - Enable or disable a device tree node given by its
|
* ofnode_set_enabled() - Enable or disable a device tree node given by its
|
||||||
* ofnode
|
* ofnode
|
||||||
|
@ -585,3 +585,19 @@ static int dm_test_ofnode_livetree_writing(struct unit_test_state *uts)
|
|||||||
}
|
}
|
||||||
DM_TEST(dm_test_ofnode_livetree_writing,
|
DM_TEST(dm_test_ofnode_livetree_writing,
|
||||||
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_LIVE_OR_FLAT);
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_LIVE_OR_FLAT);
|
||||||
|
|
||||||
|
static int dm_test_ofnode_u32(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
ofnode node;
|
||||||
|
|
||||||
|
node = ofnode_path("/lcd");
|
||||||
|
ut_assert(ofnode_valid(node));
|
||||||
|
ut_asserteq(1366, ofnode_read_u32_default(node, "xres", 123));
|
||||||
|
ut_assertok(ofnode_write_u32(node, "xres", 1367));
|
||||||
|
ut_asserteq(1367, ofnode_read_u32_default(node, "xres", 123));
|
||||||
|
ut_assertok(ofnode_write_u32(node, "xres", 1366));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_ofnode_u32,
|
||||||
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_LIVE_OR_FLAT);
|
||||||
|
Loading…
Reference in New Issue
Block a user