From: Masahiro Yamada Date: Fri, 25 Aug 2017 16:12:30 +0000 (+0900) Subject: ofnode: add {ofnode, dev}_read_resource_byname() X-Git-Url: http://git.dujemihanovic.xyz/login.html?a=commitdiff_plain;h=7b8b47bd29c0d26c59e855164d23759fd1f89fc4;p=u-boot.git ofnode: add {ofnode, dev}_read_resource_byname() Linux supports platform_get_resource_byname() to look up a resource by name. We want a similar helper. It is useful when a device node has named register regions. Signed-off-by: Masahiro Yamada Reviewed-by: Simon Glass --- diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index c1a2e9f0da..0685b689d8 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -627,3 +627,15 @@ int ofnode_read_resource(ofnode node, uint index, struct resource *res) return 0; } } + +int ofnode_read_resource_byname(ofnode node, const char *name, + struct resource *res) +{ + int index; + + index = ofnode_stringlist_search(node, "reg-names", name); + if (index < 0) + return index; + + return ofnode_read_resource(node, index, res); +} diff --git a/drivers/core/read.c b/drivers/core/read.c index fe40bed64d..6acb33388f 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -164,3 +164,9 @@ int dev_read_resource(struct udevice *dev, uint index, struct resource *res) { return ofnode_read_resource(dev_ofnode(dev), index, res); } + +int dev_read_resource_byname(struct udevice *dev, const char *name, + struct resource *res) +{ + return ofnode_read_resource_byname(dev_ofnode(dev), name, res); +} diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 210ddb2e5d..de2769ed53 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -625,5 +625,7 @@ int ofnode_read_simple_size_cells(ofnode node); bool ofnode_pre_reloc(ofnode node); int ofnode_read_resource(ofnode node, uint index, struct resource *res); +int ofnode_read_resource_byname(ofnode node, const char *name, + struct resource *res); #endif diff --git a/include/dm/read.h b/include/dm/read.h index c3a4a5611a..49d69c990f 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -359,13 +359,24 @@ int dev_read_enabled(struct udevice *dev); /** * dev_read_resource() - obtain an indexed resource from a device. * - * @dev: devuce to examine + * @dev: device to examine * @index index of the resource to retrieve (0 = first) * @res returns the resource * @return 0 if ok, negative on error */ int dev_read_resource(struct udevice *dev, uint index, struct resource *res); +/** + * dev_read_resource_byname() - obtain a named resource from a device. + * + * @dev: device to examine + * @name: name of the resource to retrieve + * @res: returns the resource + * @return 0 if ok, negative on error + */ +int dev_read_resource_byname(struct udevice *dev, const char *name, + struct resource *res); + #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ static inline int dev_read_u32_default(struct udevice *dev, @@ -513,6 +524,13 @@ static inline int dev_read_resource(struct udevice *dev, uint index, return ofnode_read_resource(dev_ofnode(dev), index, res); } +static inline int dev_read_resource_byname(struct udevice *dev, + const char *name, + struct resource *res) +{ + return ofnode_read_resource_byname(dev_ofnode(dev), name, res); +} + #endif /* CONFIG_DM_DEV_READ_INLINE */ /**