From: Stefan Roese Date: Wed, 18 Jan 2017 17:23:00 +0100 Subject: [U-Boot] [PATCH v2 07/18] core: device: Add dev_get_by_ofname function In-Reply-To: <20170111150102.7399-8-mario.six@gdsys.cc> References: <20170111150102.7399-1-mario.six@gdsys.cc> <20170111150102.7399-8-mario.six@gdsys.cc> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 11.01.2017 16:00, Mario Six wrote: > 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); I'm not 100% sure if the function naming is perfect here. Usually these dev_get_xxx function work on a "dev" provided by the caller and return something else (addr, size). The functions returning a "device" are called device_get_xxx. And perhaps its also better stick with using "struct udevice **devp" as parameter for consistency as the other device_ functions do. Simon, what do you think? Thanks, Stefan