All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chunfeng Yun <chunfeng.yun@mediatek.com>
To: u-boot@lists.denx.de
Subject: [PATCH v6 01/14] dm: core: Add function to get child count of ofnode or device
Date: Mon, 20 Apr 2020 11:21:10 +0800	[thread overview]
Message-ID: <1587352883-8641-2-git-send-email-chunfeng.yun@mediatek.com> (raw)
In-Reply-To: <1587352883-8641-1-git-send-email-chunfeng.yun@mediatek.com>

This patch add function used to get the child count of
a ofnode or a device

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Reviewed-by: Weijie Gao <weijie.gao@mediatek.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v6: add Reviewed-by Weijie & Simon

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(+)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 20871a6815..e3c42dae5c 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -474,6 +474,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 47b8e03446..3d421f7a69 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -352,3 +352,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 618fc10390..a0d3df7786 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -879,6 +879,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 03c15b8550..b952551d55 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -669,6 +669,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,
@@ -978,6 +986,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 */
 
 /**
-- 
2.25.1

  reply	other threads:[~2020-04-20  3:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-20  3:21 [PATCH v6 00/14] Add support for MediaTek xHCI host controller Chunfeng Yun
2020-04-20  3:21 ` Chunfeng Yun [this message]
2020-04-20  3:21 ` [PATCH v6 02/14] test: dm: add test item for ofnode_get_child_count() Chunfeng Yun
2020-04-20 13:10   ` Simon Glass
2020-04-20 14:07   ` Fabio Estevam
2020-04-21  1:39     ` Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 03/14] phy: Add get/enable/disable for a bulk of phys Chunfeng Yun
2020-04-25 13:28   ` Jagan Teki
2020-04-27  2:16     ` Chunfeng Yun
2020-04-28 19:45       ` Jagan Teki
2020-04-29  1:41         ` Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 04/14] test: dm: phy: add a test item for the phy_bulk API Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 05/14] usb: dwc3: use the phy bulk API to get phys Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 06/14] usb: dwc2_udc_otg: " Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 07/14] phy: phy-mtk-tphy: add support USB phys Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 08/14] phy: phy-mtk-tphy: add support new version Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 09/14] phy: phy-mtk-tphy: add a new reference clock Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 10/14] xhci: mediatek: Add support for MTK xHCI host controller Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 11/14] arm: dts: mt7629: add usb related nodes Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 12/14] dt-bindings: phy-mtk-tphy: add properties of address mapping and clocks Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 13/14] dt-bindings: usb: mtk-xhci: Add binding for MediaTek xHCI host controller Chunfeng Yun
2020-04-20  3:21 ` [PATCH v6 14/14] MAINTAINERS: MediaTek: add USB related files Chunfeng Yun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1587352883-8641-2-git-send-email-chunfeng.yun@mediatek.com \
    --to=chunfeng.yun@mediatek.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.