From mboxrd@z Thu Jan 1 00:00:00 1970 From: Simon Glass Date: Sat, 28 Nov 2020 17:50:02 -0700 Subject: [PATCH 03/11] dm: core: Add a livetree function to check node status In-Reply-To: <20201129005011.2104545-1-sjg@chromium.org> References: <20201129005011.2104545-1-sjg@chromium.org> Message-ID: <20201128174958.3.Ida482bbbdb5e84e96b2d959c340fdf43b728cf62@changeid> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Add a way to find out if a node is enabled or not, based on its 'status' property. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 10 ++++++++++ include/dm/ofnode.h | 11 +++++++++++ test/dm/ofnode.c | 12 ++++++++++++ 3 files changed, 33 insertions(+) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index a68076bf351..87072094f32 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -226,6 +226,16 @@ int ofnode_read_u32_array(ofnode node, const char *propname, } } +bool ofnode_is_enabled(ofnode node) +{ + if (ofnode_is_np(node)) { + return of_device_is_available(ofnode_to_np(node)); + } else { + return fdtdec_get_is_enabled(gd->fdt_blob, + ofnode_to_offset(node)); + } +} + ofnode ofnode_first_subnode(ofnode node) { assert(ofnode_valid(node)); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ced7f6ffb25..ee8c44a71ec 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -345,6 +345,17 @@ const char *ofnode_read_string(ofnode node, const char *propname); */ int ofnode_read_u32_array(ofnode node, const char *propname, u32 *out_values, size_t sz); +/** + * ofnode_is_enabled() - Checks whether a node is enabled. + * This looks for a 'status' property. If this exists, then returns true if + * the status is 'okay' and false otherwise. If there is no status property, + * it returns true on the assumption that anything mentioned should be enabled + * by default. + * + * @node: node to examine + * @return false (not enabled) or true (enabled) + */ +bool ofnode_is_enabled(ofnode node); /** * ofnode_read_bool() - read a boolean value from a property diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index fb1ceb13180..c5391342962 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -249,3 +249,15 @@ static int dm_test_ofnode_get_child_count(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_get_child_count, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +static int dm_test_ofnode_is_enabled(struct unit_test_state *uts) +{ + ofnode root_node = ofnode_path("/"); + ofnode node = ofnode_path("/usb at 0"); + + ut_assert(ofnode_is_enabled(root_node)); + ut_assert(!ofnode_is_enabled(node)); + + return 0; +} +DM_TEST(dm_test_ofnode_is_enabled, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- 2.29.2.454.gaff20da3a2-goog