From: Mario Six Date: Wed, 28 Mar 2018 14:37:13 +0200 Subject: [U-Boot] [PATCH 1/3] core: Add function to get device for ofnode Message-ID: <20180328123715.15861-1-mario.six@gdsys.cc> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de It's sometimes useful to get the device associated with a given ofnode. Implement a function to implement this lookup operation. Signed-off-by: Mario Six --- drivers/core/ofnode.c | 15 +++++++++++++++ include/dm/ofnode.h | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 4e4532651f..ca002063b3 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -16,6 +16,21 @@ #include #include +struct udevice *ofnode_dev(ofnode node) +{ + struct uclass *uc; + struct udevice *dev; + + list_for_each_entry(uc, &gd->uclass_root, sibling_node) { + list_for_each_entry(dev, &uc->dev_head, uclass_node) { + if (ofnode_equal(dev_ofnode(dev), node)) + return dev; + } + } + + return NULL; +} + int ofnode_read_u32(ofnode node, const char *propname, u32 *outp) { assert(ofnode_valid(node)); diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0d008404f9..aec205eb80 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -193,6 +193,14 @@ static inline ofnode ofnode_null(void) return node; } +/** + * ofnode_dev() - Get the device associated with a given ofnode + * + * @node: valid node reference to get the corresponding device for + * @return a pointer to the udevice if OK, NULL on error + */ +struct udevice *ofnode_dev(ofnode node); + /** * ofnode_read_u32() - Read a 32-bit integer from a property * -- 2.16.1