From patchwork Sat May 2 09:35:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Wunderlich X-Patchwork-Id: 1281799 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=shgpcV4n; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49F85M3jbNz9sPF for ; Sun, 3 May 2020 11:48:07 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 76CD081E4B; Sun, 3 May 2020 03:47:39 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="shgpcV4n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 09A3381D31; Sat, 2 May 2020 11:35:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 34AD381D26 for ; Sat, 2 May 2020 11:35:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=frank.wunderlich@gmail.com Received: by mail-wr1-x443.google.com with SMTP id j1so14730990wrt.1 for ; Sat, 02 May 2020 02:35:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oDIB4YnsmsDujbqeLYqwcW81a+wtfRykFmSRb+uu1Wg=; b=shgpcV4nhYyTIy11uyjwDlrS0r+5VEhxcXzd/rTZ6j6ttqhGsV2wueGXN23qrTRqTf pzFBb97xarYZ4b7PbpO88GePL51tEduqVkAYBMHhU+3idvgrXhhWC6+2kmP1VTAgLA1p kXj+VtzFs7RjmRqzgqeL4VZakYaDB0EeDXN3ToWCVWNy+bjaanXN8wBbLD27lAVSYnjf GLL2Ycdt4ojfbLda5VxDFkgjw+jirkXTUc4bouA4Sb7CBY7LVQXUMu4u0k+FPB9aINSk yGQmxcuotAZ4V7i7ugJBJM247lilrthonU07ybpKghYT9Y9S6Jh/YFNv/SIEYtLKhNB5 4OWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oDIB4YnsmsDujbqeLYqwcW81a+wtfRykFmSRb+uu1Wg=; b=GgS28bizhHJRg6Hpl35coxffjKu0n8r3PKbTLPsMdOHztw6srFajb23iSMBySxGfn3 r9liwmAkPkk6X0/mxAeM4pfId6zZXD2x29Pi8/ASL8+l3XFDZMQ7qIgSnE1TzUJY554+ Ro9zEo36gT8Mccm3jbZY3lYzguko08+TY591S+7uT+WpeYENdeeq0YPniORsDiD4vtuy fvfbXOG4hC/TFi4OPJ8XcpMEySWP4PR9/h+LDsqpn3jjPpsHe8EA6wmYRox1Vj0gM8eF 3ccubrFpMLe6k2cDHjahxDI7ELW66nsP+FVVsOadQ3JUvJaHWyksGMNnGDbPp05Ywhav c6yg== X-Gm-Message-State: AGi0PuZKp4WEvupXcLAcNOgCXz2WXA6CmTpfXwf8Bwvbqbj8EUdVyklU 8qvuZKXpbkv917+5ZvXkmTA= X-Google-Smtp-Source: APiQypIyHZlLQ+meUGpTbbpn+AonEK9DkoCiY7wWq9+8MkC06F9BltIxPXWQTrG2nFVBd652homfCg== X-Received: by 2002:a5d:498b:: with SMTP id r11mr8497086wrq.368.1588412141807; Sat, 02 May 2020 02:35:41 -0700 (PDT) Received: from localhost.localdomain (fttx-pool-185.76.96.142.bambit.de. [185.76.96.142]) by smtp.gmail.com with ESMTPSA id l16sm8196681wrp.91.2020.05.02.02.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 May 2020 02:35:41 -0700 (PDT) From: Frank Wunderlich X-Google-Original-From: Frank Wunderlich To: Simon Glass , Ryder Lee , Marek Vasut , Bin Meng Cc: Frank Wunderlich , Weijie Gao , GSS_MTK_Uboot_upstream , Jagan Teki , Stefan Roese , Neil Armstrong , Sam Shih , Chunfeng Yun , Jean-Jacques Hiblot , Alex Marginean , Patrick Delaunay , Lukasz Majewski , AKASHI Takahiro , Anatolij Gustschin , Ye Li , Fabio Estevam , Marcel Ziswiler , Heiko Schocher , Mark Kettenis , Adam Ford , u-boot@lists.denx.de, Masahiro Yamada , Vignesh Raghavendra Subject: [PATCH v8 01/14] dm: core: Add function to get child count of ofnode or device Date: Sat, 2 May 2020 11:35:09 +0200 Message-Id: <20200502093522.3568-2-frank-w@public-files.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200502093522.3568-1-frank-w@public-files.de> References: <20200502093522.3568-1-frank-w@public-files.de> X-Mailman-Approved-At: Sun, 03 May 2020 03:47:25 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean From: Chunfeng Yun This patch add function used to get the child count of a ofnode or a device Signed-off-by: Chunfeng Yun Signed-off-by: Frank Wunderlich Reviewed-by: Weijie Gao Reviewed-by: Simon Glass --- v8: no changes v7: no changes 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 */ /**