From: Mario Six Date: Wed, 11 Jan 2017 16:00:51 +0100 Subject: [U-Boot] [PATCH v2 07/18] core: device: Add dev_get_by_ofname function In-Reply-To: <20170111150102.7399-1-mario.six@gdsys.cc> References: <20170111150102.7399-1-mario.six@gdsys.cc> Message-ID: <20170111150102.7399-8-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 On boards that use DM, it is sometimes convenient and quicker to get a device via its device tree path, since the devices used in the board initialization routines are usually known beforehand. This patch adds such a convenience function. Signed-off-by: Mario Six --- Changes in v2: New in v2 --- drivers/core/device.c | 7 +++++++ include/dm/device.h | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index ed553d7..39d30b3 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -627,6 +627,13 @@ const char *dev_get_uclass_name(struct udevice *dev) return dev->uclass->uc_drv->name; } +void dev_get_by_ofname(char *ofname, struct udevice *dev) +{ + int offset = fdt_path_offset(gd->fdt_blob, ofname); + + device_get_global_by_of_offset(offset, &dev); +} + fdt_addr_t dev_get_addr_index(struct udevice *dev, int index) { #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) diff --git a/include/dm/device.h b/include/dm/device.h index 9948bd4..402482c 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -340,6 +340,14 @@ enum uclass_id device_get_uclass_id(struct udevice *dev); const char *dev_get_uclass_name(struct udevice *dev); /** + * dev_get_by_ofname() - find a device via its device tree path + * + * @ofname: Device tree path to use ("/path1/path2/...") + * @dev: The found device or NULL + */ +void dev_get_by_ofname(char *ofname, struct udevice *dev); + +/** * device_get_child() - Get the child of a device by index * * Returns the numbered child, 0 being the first. This does not use -- 2.9.0