[U-Boot] [PATCH] fdt: implement dev_get_addr_name()

From: Stephen Warren swarren@nvidia.com
This function parses the reg property based on an index found in the reg-names property. This is required for bindings that are written using reg-names rather than hard-coding indices in reg.
Signed-off-by: Stephen Warren swarren@nvidia.com --- drivers/core/device.c | 16 ++++++++++++++++ include/dm/device.h | 12 ++++++++++++ 2 files changed, 28 insertions(+)
diff --git a/drivers/core/device.c b/drivers/core/device.c index cb24a617ceef..87755f514ba4 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -649,6 +649,22 @@ fdt_addr_t dev_get_addr_index(struct udevice *dev, int index) #endif }
+fdt_addr_t dev_get_addr_name(struct udevice *dev, const char *name) +{ +#if CONFIG_IS_ENABLED(OF_CONTROL) + int index; + + index = fdt_find_string(gd->fdt_blob, dev->parent->of_offset, + "reg-names", name); + if (index < 0) + return index; + + return dev_get_addr_index(dev, index); +#else + return FDT_ADDR_T_NONE; +#endif +} + fdt_addr_t dev_get_addr(struct udevice *dev) { return dev_get_addr_index(dev, 0); diff --git a/include/dm/device.h b/include/dm/device.h index 1cf81501ed92..dad7591dfacb 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -465,6 +465,18 @@ fdt_addr_t dev_get_addr(struct udevice *dev); fdt_addr_t dev_get_addr_index(struct udevice *dev, int index);
/** + * dev_get_addr_name() - Get the reg property of a device, indexed by name + * + * @dev: Pointer to a device + * @name: the 'reg' property can hold a list of <addr, size> pairs, with the + * 'reg-names' property providing named-based identification. @index + * indicates the value to search for in 'reg-names'. + * + * @return addr + */ +fdt_addr_t dev_get_addr_name(struct udevice *dev, const char *name); + +/** * device_has_children() - check if a device has any children * * @dev: Device to check

On 6 April 2016 at 12:49, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
This function parses the reg property based on an index found in the reg-names property. This is required for bindings that are written using reg-names rather than hard-coding indices in reg.
Signed-off-by: Stephen Warren swarren@nvidia.com
drivers/core/device.c | 16 ++++++++++++++++ include/dm/device.h | 12 ++++++++++++ 2 files changed, 28 insertions(+)
Acked-by: Simon Glass sjg@chromium.org

On 6 April 2016 at 17:16, Simon Glass sjg@chromium.org wrote:
On 6 April 2016 at 12:49, Stephen Warren swarren@wwwdotorg.org wrote:
From: Stephen Warren swarren@nvidia.com
This function parses the reg property based on an index found in the reg-names property. This is required for bindings that are written using reg-names rather than hard-coding indices in reg.
Signed-off-by: Stephen Warren swarren@nvidia.com
drivers/core/device.c | 16 ++++++++++++++++ include/dm/device.h | 12 ++++++++++++ 2 files changed, 28 insertions(+)
Acked-by: Simon Glass sjg@chromium.org
Applied to u-boot-dm, thanks!
participants (2)
-
Simon Glass
-
Stephen Warren