Message ID | 1586497552-12194-2-git-send-email-chunfeng.yun@mediatek.com |
---|---|
State | Superseded |
Headers | show |
Series | Add support for MediaTek xHCI host controller | expand |
On Fri, 2020-04-10 at 13:45 +0800, Chunfeng Yun wrote: > This patch add function used to get the child count of > a ofnode or a device > > Signed-off-by: Chunfeng Yun <chunfeng.yun at mediatek.com> > --- > v4~v5: no changes > > v3: > 1. add non/inline function dev_get_child_count() instead of macro suggested by Simon > > v2: > 1. move ofnode_get_child_count() into ofnode.c suggested by Simon > 2. add a new macro dev_get_child_count() > --- > drivers/core/ofnode.c | 11 +++++++++++ > drivers/core/read.c | 5 +++++ > include/dm/ofnode.h | 8 ++++++++ > include/dm/read.h | 13 +++++++++++++ > 4 files changed, 37 insertions(+) > Reviewed-by: Weijie Gao <weijie.gao at mediatek.com>
On Thu, 9 Apr 2020 at 23:46, Chunfeng Yun <chunfeng.yun at mediatek.com> wrote: > > This patch add function used to get the child count of > a ofnode or a device > > Signed-off-by: Chunfeng Yun <chunfeng.yun at mediatek.com> > --- > v4~v5: no changes > > v3: > 1. add non/inline function dev_get_child_count() instead of macro suggested by Simon > > v2: > 1. move ofnode_get_child_count() into ofnode.c suggested by Simon > 2. add a new macro dev_get_child_count() > --- > drivers/core/ofnode.c | 11 +++++++++++ > drivers/core/read.c | 5 +++++ > include/dm/ofnode.h | 8 ++++++++ > include/dm/read.h | 13 +++++++++++++ > 4 files changed, 37 insertions(+) > Reviewed-by: Simon Glass <sjg at chromium.org>
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 96a5dd20bd..6f4eb422a4 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -453,6 +453,17 @@ ofnode ofnode_get_chosen_node(const char *name) return ofnode_path(prop); } +int ofnode_get_child_count(ofnode parent) +{ + ofnode child; + int num = 0; + + ofnode_for_each_subnode(child, parent) + num++; + + return num; +} + static int decode_timing_property(ofnode node, const char *name, struct timing_entry *result) { diff --git a/drivers/core/read.c b/drivers/core/read.c index 1f999b1b31..046381f3a8 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -323,3 +323,8 @@ fdt_addr_t dev_read_addr_pci(const struct udevice *dev) return addr; } + +int dev_get_child_count(const struct udevice *dev) +{ + return ofnode_get_child_count(dev_ofnode(dev)); +} diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index b5a50e8849..0d521dbcf1 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -793,6 +793,14 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname, ofnode_valid(node); \ node = ofnode_next_subnode(node)) +/** + * ofnode_get_child_count() - get the child count of a ofnode + * + * @node: valid node to get its child count + * @return the number of subnodes + */ +int ofnode_get_child_count(ofnode parent); + /** * ofnode_translate_address() - Translate a device-tree address * diff --git a/include/dm/read.h b/include/dm/read.h index da8c7f25e7..38cf76d07a 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -607,6 +607,14 @@ u64 dev_translate_dma_address(const struct udevice *dev, */ int dev_read_alias_highest_id(const char *stem); +/** + * dev_get_child_count() - get the child count of a device + * + * @dev: device to use for interation (struct udevice *) + * @return the count of child subnode + */ +int dev_get_child_count(const struct udevice *dev); + #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ static inline int dev_read_u32(const struct udevice *dev, @@ -885,6 +893,11 @@ static inline int dev_read_alias_highest_id(const char *stem) return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); } +static inline int dev_get_child_count(const struct udevice *dev) +{ + return ofnode_get_child_count(dev_ofnode(dev)); +} + #endif /* CONFIG_DM_DEV_READ_INLINE */ /**
This patch add function used to get the child count of a ofnode or a device Signed-off-by: Chunfeng Yun <chunfeng.yun at mediatek.com> --- v4~v5: no changes v3: 1. add non/inline function dev_get_child_count() instead of macro suggested by Simon v2: 1. move ofnode_get_child_count() into ofnode.c suggested by Simon 2. add a new macro dev_get_child_count() --- drivers/core/ofnode.c | 11 +++++++++++ drivers/core/read.c | 5 +++++ include/dm/ofnode.h | 8 ++++++++ include/dm/read.h | 13 +++++++++++++ 4 files changed, 37 insertions(+)