dm: core: Support writing a boolean

Add functions to write a boolean property. This involves deleting it if
the value is false.

Add a new ofnode_has_property() as well. Add a comment about the behaviour
of of_read_property() when the property value is empty.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2023-09-26 08:14:44 -06:00
committed by Tom Rini
parent 62b1db3377
commit d9216c8683
3 changed files with 90 additions and 3 deletions

View File

@@ -491,12 +491,12 @@ u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def)
bool ofnode_read_bool(ofnode node, const char *propname)
{
const void *prop;
bool prop;
assert(ofnode_valid(node));
debug("%s: %s: ", __func__, propname);
prop = ofnode_get_property(node, propname, NULL);
prop = ofnode_has_property(node, propname);
debug("%s\n", prop ? "true" : "false");
@@ -1168,6 +1168,14 @@ const void *ofnode_get_property(ofnode node, const char *propname, int *lenp)
propname, lenp);
}
bool ofnode_has_property(ofnode node, const char *propname)
{
if (ofnode_is_np(node))
return of_find_property(ofnode_to_np(node), propname, NULL);
else
return ofnode_get_property(node, propname, NULL);
}
int ofnode_first_property(ofnode node, struct ofprop *prop)
{
prop->node = node;
@@ -1616,6 +1624,30 @@ int ofnode_write_u32(ofnode node, const char *propname, u32 value)
return ofnode_write_prop(node, propname, val, sizeof(value), false);
}
int ofnode_write_bool(ofnode node, const char *propname, bool value)
{
if (value)
return ofnode_write_prop(node, propname, NULL, 0, false);
else
return ofnode_delete_prop(node, propname);
}
int ofnode_delete_prop(ofnode node, const char *propname)
{
if (ofnode_is_np(node)) {
struct property *prop;
int len;
prop = of_find_property(ofnode_to_np(node), propname, &len);
if (prop)
return of_remove_property(ofnode_to_np(node), prop);
return 0;
} else {
return fdt_delprop(ofnode_to_fdt(node), ofnode_to_offset(node),
propname);
}
}
int ofnode_set_enabled(ofnode node, bool value)
{
assert(ofnode_valid(node));