diff options
author | Masahiro Yamada | 2017-08-26 01:12:30 +0900 |
---|---|---|
committer | Masahiro Yamada | 2017-08-29 23:56:17 +0900 |
commit | 7b8b47bd29c0d26c59e855164d23759fd1f89fc4 (patch) | |
tree | 9b1ac4d2f29914b2b6202f6b476b801d106fa2d1 | |
parent | 8b3cec7da18645eda7f7cd0b65ee9f2dac573409 (diff) |
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 <yamada.masahiro@socionext.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | drivers/core/ofnode.c | 12 | ||||
-rw-r--r-- | drivers/core/read.c | 6 | ||||
-rw-r--r-- | include/dm/ofnode.h | 2 | ||||
-rw-r--r-- | include/dm/read.h | 20 |
4 files changed, 39 insertions, 1 deletions
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index c1a2e9f0dae..0685b689d84 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 fe40bed64de..6acb33388f5 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 210ddb2e5d7..de2769ed537 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 c3a4a5611a7..49d69c990f6 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 */ /** |