From: Chunfeng Yun Date: Tue, 24 Mar 2020 11:57:48 +0800 Subject: [PATCH v2 01/10] dm: core: Add function to get child count of ofnode or device In-Reply-To: References: <1584780715-29632-1-git-send-email-chunfeng.yun@mediatek.com> <1584780715-29632-2-git-send-email-chunfeng.yun@mediatek.com> Message-ID: <1585022268.28859.9.camel@mhfsdcap03> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Mon, 2020-03-23 at 09:36 -0600, Simon Glass wrote: > Hi Chunfeng, > > On Sat, 21 Mar 2020 at 02:52, Chunfeng Yun wrote: > > > > This patch add function used to get the child count of > > a ofnode or a device > > > > Signed-off-by: Chunfeng Yun > > --- > > 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 +++++++++++ > > include/dm/ofnode.h | 8 ++++++++ > > include/dm/read.h | 9 +++++++++ > > 3 files changed, 28 insertions(+) > > > > Looks good so far, but please see below. > > > 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/include/dm/ofnode.h b/include/dm/ofnode.h > > index b5a50e8849..3fe8fcdc5d 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 ot get its child count > > to get will fix it > > > + * @return the count of child subnode > > the number of subnodes will fix it > > > + */ > > +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..0b7dec4c83 100644 > > --- a/include/dm/read.h > > +++ b/include/dm/read.h > > @@ -901,4 +901,13 @@ static inline int dev_read_alias_highest_id(const char *stem) > > ofnode_valid(subnode); \ > > subnode = ofnode_next_subnode(subnode)) > > > > +/** > > + * 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 > > + */ > > +#define dev_get_child_count(dev) \ > > + ofnode_get_child_count(dev_ofnode(dev)) > > + > > Please use static inline for this one. > > Also add a non-inline vresion above, inside #ifndef > CONFIG_DM_READ_INLINE with impl in read.c. See other functions for > examples. Ok, will do it, thanks a lot > > > #endif > > -- > > 2.25.1 > > Regards, > Simon