diff options
author | Simon Glass | 2023-09-26 08:14:44 -0600 |
---|---|---|
committer | Tom Rini | 2023-10-06 14:38:13 -0400 |
commit | d9216c8683fced4cbf6d437b4357c9368bf1bf86 (patch) | |
tree | b988723a63eb879277b2e1d0437c370945e7ed27 /drivers/core | |
parent | 62b1db33778611a3023d1e3a98e869b495edc9ca (diff) |
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>
Diffstat (limited to 'drivers/core')
-rw-r--r-- | drivers/core/ofnode.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 39ba480c8f8..4dcb3dd1c03 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -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)); |