From patchwork Mon Aug 26 02:43:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 103649 X-Patchwork-Delegate: sakari.ailus@iki.fi Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1siPhl-0002vy-19 for patchwork@linuxtv.org; Mon, 26 Aug 2024 02:43:48 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0BECD1C20DC9 for ; Mon, 26 Aug 2024 02:43:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A21DDDBC; Mon, 26 Aug 2024 02:43:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="PMfB1JzN" X-Original-To: linux-media@vger.kernel.org Received: from OS0P286CU011.outbound.protection.outlook.com (mail-japanwestazon11010050.outbound.protection.outlook.com [52.101.228.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78745BA2D; Mon, 26 Aug 2024 02:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.228.50 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724640209; cv=fail; b=cUMJZFy75gGyZPhJX8GAZZZ154F6rnVm7vBP/9/LmdK05QmmI1MkaovLi1C4nrz9GWbJrLXxGJLn3XMdhGx1R6jLf0P6EL9UFzkyUZoM6V/2R+B4sXl4y9IEdqoI7DMijUmmzC9a9N7D1+tp7MfcXkExZ4Cz1sVpNuG/TA1vjtc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724640209; c=relaxed/simple; bh=ksIktrRrgvqaZVMGuC6wQWiGUXsOsLxo2ss6FDh3DS8=; h=Message-ID:From:Subject:To:In-Reply-To:References:Content-Type: Date:MIME-Version; b=sFp6QxggVD0zbd5w5IjKk0ALE2LWlUebl6mwT60HMGp60nQPJNLe7tMU1VmZRvjEOsG12XYGYwXMi0ep3N9J6evFojyfmjzchlHcsSBzIM5u8Ntby7JJlRoRaWtvlZTRIgAHYt0AIBGtj2zhqPNxr/oZH/LH5nA4teIddPcub2M= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com; spf=pass smtp.mailfrom=renesas.com; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b=PMfB1JzN; arc=fail smtp.client-ip=52.101.228.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=renesas.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CbvyqWNVfIwVVDLV7M4XNaYSv0A9NGW7FricS7y9CJ4uxabth1KF3+Z1EBNabSoB/3+FFcNdUiYSA6+vEDdqHt6D/5ZWXSe83xiY8kSfIORrm4RFQ4Txv9ZEL8fsbTLUmYHkzrjqscZFm7WSZHvdE0S1I15NaFz1a3vxbwKnGY6OOWk9InSmjGDi1V3qXk3nSuMXYVFTLMOG258Yb6iyIcrBOs/Yz7upa3LpGAuvMV34rGsM8k5/X+OBApqRNxsqgy4Vb0yRS+AjyAUfOnqCBqwm9WoF++nWevFX1yfkRUCeMLKo4zINl2PP2o/tTpFu9qvGR1OsURECuTnycmPstA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=bbM+qTIc7kxSIVX5wMZ9A9LBJGysBXbu+GTaNKKqHlc=; b=huy6NXH3+R/SFSiJoFjJHIbw+tFZmmXSs1KDUc69Gn0VbynX/hb6gsP1Bd/XYn8NPvh6CYa1NvwLJ2HJX5JSZ9TdbMksXj7qORghnd11PQofFBSCIIijQ164uO4IENKlgFjFMFjVH1/5mY9CW0mIc3YHIzt1MLjbrF6zpiYfUCi+OxTT1MBuR2cYE0awwiOuqUZXQvhG3gre+aeP6an9w56Bpxu+zA351wnqB7kb5OR/OFqH2D8sdgF4Udb1TjMVhswgO7+lzTSMHW/Ol8UbM76wGIVB1jWOt87/nRN5OgtEWYYgncHJJVwqtOCvXEPV4K71HpyH8/r7QfneFqAu+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=renesas.com; dmarc=pass action=none header.from=renesas.com; dkim=pass header.d=renesas.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesas.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bbM+qTIc7kxSIVX5wMZ9A9LBJGysBXbu+GTaNKKqHlc=; b=PMfB1JzNe/UnddCxt4CGsT2bEXzIjZ9TSN19szwtAna6cM0LVYxLEXTHVGjIVsXyYcisDgzPCD7E00aytxWGEPLFcV65ysqwe6Qh32oGd5qOJQyX/NQaZej4yoCmEkUYsWM2bk1SUQRQGuxxh47grKM6jI1on0/peiTZB0BwAHM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=renesas.com; Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) by TYCPR01MB10616.jpnprd01.prod.outlook.com (2603:1096:400:290::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.24; Mon, 26 Aug 2024 02:43:24 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::c568:1028:2fd1:6e11]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::c568:1028:2fd1:6e11%5]) with mapi id 15.20.7875.016; Mon, 26 Aug 2024 02:43:24 +0000 Message-ID: <87bk1gqa0k.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v3 1/9] of: property: add of_graph_get_next_port() User-Agent: Wanderlust/2.15.9 Emacs/29.3 Mule/6.0 To: Daniel Vetter , David Airlie , Helge Deller , Jaroslav Kysela , Laurent Pinchart , Liam Girdwood , Maarten Lankhorst , Mark Brown , Mauro Carvalho Chehab , Maxime Ripard , Michal Simek , Rob Herring , Saravana Kannan , Takashi Iwai , Thomas Zimmermann , Tomi Valkeinen , devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-fbdev@vger.kernel.org, linux-media@vger.kernel.org, linux-omap@vger.kernel.org, linux-sound@vger.kernel.org, Sakari Ailus In-Reply-To: <87cylwqa12.wl-kuninori.morimoto.gx@renesas.com> References: <87cylwqa12.wl-kuninori.morimoto.gx@renesas.com> Date: Mon, 26 Aug 2024 02:43:23 +0000 X-ClientProxiedBy: TY2PR06CA0038.apcprd06.prod.outlook.com (2603:1096:404:2e::26) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|TYCPR01MB10616:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b1a86e4-cf53-44cf-979b-08dcc578daf3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|7416014|376014|366016|38350700014|921020; X-Microsoft-Antispam-Message-Info: QdWPFICBG5GhrWf84GR2jdYuTA7AIYiYFc0gOX/Bw/rchmgurKD0n3wWaCviTy3tjyrBIRGGYNA3DK332O7RQ5N4QncgXgc6nF03ceMEI40Ki7MJ2eI+NAihHjlrqWikTnTU4N8RaXrM4pG8tttSaWfTSJ4486QmZktpNTQdYKM59mqrbxhOF4rXZGzc4/V5bSNt1cHj6HzGPGAW6O4WI29YrWJV8W8zL8KCI5/HJpr/C/Q7JY33c7rLZ1NKl2Tg1n8pMy0L0DkvF/+zWEGyXxieJ4Jiece64W/kXPK5gJqrq91sJNoRyXyAXEuj8705QjAiRyai0UW1JqSm/0gE257yrHhweE98v7B0xaBpPZLhGZZs9gmE8+nKk4sE/iwoIkOazLhV3evZZWssyRm3mRUUlb2U33FpLvmpqmtBuy1fY7f2SPnd9DCsTbsflxudqe4M7g+492tc5hfz1i7mu1/cH/OQ3/hRwYUCLG7k6D8x2kOUdKgtBJToqnKT9j1EXy5pJVPZQSMDiX870Huq3zBgpC8fprPkaCsI4WEZn0gKkLPWP8OyuNaYFyu0sonh2zub1dbmz0JRGLZBc0exHvvrr4hOm5QOw3FZ0HF1wm6ntaHlf7mLHpfED2s/rN2jv15ex1Go4NrRdFIG4Ds+SzAgCYwe98wSIkZHJSXi/jZBC02g8NwR8Rrf+qTGyOOtlzfrrDdA5Eej0pqLqu8M32izHxRJoi7QxBkVyN+oyJ3fC3AkusaORRNGlTlt/TL6JPMGMFFjU/wfks3YAH/UEhdAHfzUI4JmMgsEMPUz8AO+6Rm5lNIuUoNtulwy7DlfmXHa5tgQgSTaeBtDUAkAhM0f6+nUUlUus83r2EXTBtZeybPltIrzoA36XrjyI6amDze1WmAE5YkGBwNbKfVPYqJq7uHU8gtJ6bbet/bb9m+c41CBJowukH4gTEz+l3LySxHfYxftXZwL+uBwfmnHvrX4hJFyMvs9SHo4CRbq55jAfQgJrjsvOS4WBt5/wbyQW+tGUKxJFUboXUcsIPVrATWX4jEirkEioOJZCg+wSDD0k5vNcXhs74gbXU8f+qVYvO60bqkSEiCwtN9DUK8fN1LvheZhqlt9QonKAgCaWJ68Ab/6lsKnZDrRodcjo/fSwZ/wnVNm7E+CYAT4e9O/UOjg1HQGy0VsYYjcUbrIJb5n8UW23/0/T9hxymiYK7boeWtzgHkxO+xAI5899tfSBKJaGnwow4Uwf4+OP4UqMCPyZU1b3VmKKXZZdqs7QIM9/dXnf1r62rLnk60YkT4BzLo99eSXon7I0hCAaPgbE7/SLuShQGW8jxcO1OaHS0y0l5l0MZNVIZoBov9nLMCfgq+4w0ZXZ8tyYG0h5ChNpjcM05A1WRp/88K6k1OZ/6u5ruZMvSgumoziQhy3tDZ398RpX/nFnmek8t5IhYbFnSQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYCPR01MB10914.jpnprd01.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(7416014)(376014)(366016)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8Xf9S58mdpJ7KNGqG3ulcCzQXZC4JZaFe/b50yWPrILHoFM8O3bWU3ZUDA+i9nj/+/l7ANR2VpErbd6ThDTcdW4hOu4pGY/GIPXHyRfqwLws5JetRz39cT86HOhMpqIwNUFoPzQmX9S3ppOC8tFklkzAL5C9HWSxwieUTELeiC8woDA1m1tit5vMSnI7ox3leUq2dfZMZyq1ORumkIs7D+OqEIt+qt3kaEewndvmlERgoUdiIEFU7oQCar4tu4OBZia/XSTV5j6cFULoGW2tZvKiZppXZR49QLnWNv044uOV3UduhpI3E1CCQd9+QmJYPMTf1b0APjblaF4PEoexRizXX5cA325twzFy8+3nDbcMbR+mty0BP9BTw/Ws1X0Umn86dBxiYKnrBLBf6vXSqaN7iccN3yL3g8sFW/w9yzOt9/ksW6t4A6HHIT8UObdbDuFSDgdiGPnaHTi066HhfQDX7FHMvIGjJU2693BeFX3R1zIqgQZj0cdtPXSKhm/XRDfmWAG3WIAzv6X7Z+V4iB+WKgXOrhU/rSapnMW7DAZpW+VQXym5z+glCdIk/qg3mRNaN6eepl+raHImmRX47aEzCZBfX0624fjjSNvoiYaKz3TazPdB15gnzC8OpPk5hh1Ey3ADtn2qKSiyReXfqr0R56RoE813pFlmq5Oip4k8Fr5aS/4xflke5x/B9S1FpF9Mu4RaxwVW1jo2cHz1xIjfLbmSIIrdMqp1lR2MT0I3GZ+fe7i5FtKggxHgcr8HgHjoomPbAtWjoNpIWxpnycJF0JUDZyE/sKDAfdUAd1X4zo40IclbCuv1fWmd0R6Io7McuP4RSR69yg0R8nzTKA1OG5wnFMHzmHRrgS5uhLwDxWcXiKiNOM57rU5h6z7Zyhj0vjSUArUOy2Rp/tscZp8+YLYy/J/5CqwbSM2u5ApyrgyBGPaQVMNcO5xcrfEarY5J99neDYs9w9VqDlp15YG1ZJY0EzXsIDBi42kWGTQLWK75ALhsPi7NKq+vhn2p+/kwyp0xVnFqCzPQ40HCuMNxIB2yKOX20Otqhrfzv/6Dx9fEjeOqnMYuwaEwCIb5yNJczn3G0YH/VWYUHM5Jf6thvK9akycDNDaAah5vpo8xzEdXfzTVygLRAQ+IXhZt57xLnfxSBr5uKya6PpUIPMSmFNGb+397uxZMiIzsZ2CIu48FjWF82B2MEOfDTDjwvF1L45ZdY1NQJqEKzpGlBR5qrfCj0BQnpbg3uvJ0bkgi85dNj28stABlTH6t3Rtdd9AwzsrPRq0Gw7ZlBNpr33h7vJGQ+J4diELHTx/Xp5Gign/71SixtmB3ndvjsl2crQhHa5jlZtHQ0ZiLzhvN2GGmG8UjoPOMCiR6Iyzju6U/QZ3RNok0vxLhO6UGAHb/Rg0t/xkVgbhGII21spNU4IHq12pxgu2kVkzo9Iyj8DtfU3M5Fay9SAP/InD/HFMaloMYcyR/etcikRbKmGpbN+kJf5dKqRmhDdX3Lz1zJl7MXmOBF5y8zl7G2FN2icYAheha2ItW+VzxDExa7rd19MfpD923a7wrSU1M3/I3OSiVCnLP3E4gTwjg7maXWQoq2upd5oV1hgDM8Bf5ckst2+kok3+mn+o2vwVlX3ME0HY= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b1a86e4-cf53-44cf-979b-08dcc578daf3 X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Aug 2024 02:43:24.0654 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SqreCHxCxqYLa7YFNJS5UlvGcZyMC8HCeePFx5zSz8sA4y6PFGekJgL1eJcM2NpBWUbLH9BehwlRrnv1eDz/r8emi8pqQ4qeC99PnvL1OKUyLjGBnbgyiwJSFbJ68UA/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCPR01MB10616 X-LSpam-Score: -6.3 (------) X-LSpam-Report: No, score=-6.3 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001 autolearn=ham autolearn_force=no We have endpoint base functions - of_graph_get_next_device_endpoint() - of_graph_get_device_endpoint_count() - for_each_of_graph_device_endpoint() Here, for_each_of_graph_device_endpoint() loop finds each endpoints ports { port@0 { (1) endpoint {...}; }; port@1 { (2) endpoint {...}; }; ... }; In above case, it finds endpoint as (1) -> (2) -> ... Basically, user/driver knows which port is used for what, but not in all cases. For example on flexible/generic driver case, how many ports are used is not fixed. For example Sound Generic Card driver which is used from many venders can't know how many ports are used. Because the driver is very flexible/generic, it is impossible to know how many ports are used, it depends on each vender SoC and/or its used board. And more, the port can have multi endpoints. For example Generic Sound Card case, it supports many type of connection between CPU / Codec, and some of them uses multi endpoint in one port. Then, Generic Sound Card want to handle each connection via "port" instead of "endpoint". But, it is very difficult to handle each "port" via for_each_of_graph_device_endpoint(). Getting "port" by using of_get_parent() from "endpoint" doesn't work. see below. ports { port@0 { (1) endpoint@0 {...}; (2) endpoint@1 {...}; }; port@1 { (3) endpoint {...}; }; ... }; In the same time, same reason, we want to handle "ports" same as "port". node { => ports@0 { port@0 { endpoint@0 {...}; endpoint@1 {...}; ... }; port@1 { endpoint@0 {...}; endpoint@1 {...}; ... }; ... }; => ports@1 { ... }; }; Add "ports" / "port" base functions. For above case, we can use for_each_of_graph_ports(node, ports) { for_each_of_graph_port(ports, port) { ... } } This loop works both "node" have / doesn't have "ports", like below node { port { }; }; node { ports { port { }; }; }; Signed-off-by: Kuninori Morimoto --- drivers/of/property.c | 112 +++++++++++++++++++++++++++++++++++++++ include/linux/of_graph.h | 46 ++++++++++++++++ 2 files changed, 158 insertions(+) diff --git a/drivers/of/property.c b/drivers/of/property.c index 164d77cb94458..aec6ac9f70064 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -625,6 +625,100 @@ struct device_node *of_graph_get_port_by_id(struct device_node *parent, u32 id) } EXPORT_SYMBOL(of_graph_get_port_by_id); +/** + * of_graph_get_next_ports() - get next ports node. + * @parent: pointer to the parent device node + * @prev: previous ports node, or NULL to get first + * + * If "parent" node doesn't have "ports" node, it returns "parent" node itself as "ports" node. + * + * Return: A 'ports' node pointer with refcount incremented. Refcount + * of the passed @prev node is decremented. + */ +struct device_node *of_graph_get_next_ports(struct device_node *parent, + struct device_node *prev) +{ + if (!parent) + return NULL; + + if (!prev) { + /* + * Find "ports" node from parent + * + * parent { + * => ports { + * port {...}; + * }; + * }; + */ + prev = of_get_child_by_name(parent, "ports"); + + /* + * Use parent as its ports if it not exist + * + * => parent { + * port {...}; + * }; + */ + if (!prev) { + prev = of_node_get(parent); + + /* check wether it has port node */ + struct device_node *port __free(device_node) = + of_get_child_by_name(prev, "port"); + + if (!port) + prev = NULL; + } + + return prev; + } + + /* Find next ports */ + do { + prev = of_get_next_child(parent, prev); + if (!prev) + break; + } while (!of_node_name_eq(prev, "ports")); + + return prev; +} +EXPORT_SYMBOL(of_graph_get_next_ports); + +/** + * of_graph_get_next_port() - get next port node. + * @parent: pointer to the parent device node, or parent ports node + * @prev: previous port node, or NULL to get first + * + * Parent device node can be used as @parent whether device node has ports node or not. + * It will work same as ports@0 node. + * + * Return: A 'port' node pointer with refcount incremented. Refcount + * of the passed @prev node is decremented. + */ +struct device_node *of_graph_get_next_port(struct device_node *parent, + struct device_node *prev) +{ + if (!parent) + return NULL; + + if (!prev) { + struct device_node *ports __free(device_node) = + of_graph_get_next_ports(parent, NULL); + + return of_get_child_by_name(ports, "port"); + } + + do { + prev = of_get_next_child(parent, prev); + if (!prev) + break; + } while (!of_node_name_eq(prev, "port")); + + return prev; +} +EXPORT_SYMBOL(of_graph_get_next_port); + /** * of_graph_get_next_endpoint() - get next endpoint node * @parent: pointer to the parent device node @@ -823,6 +917,24 @@ unsigned int of_graph_get_endpoint_count(const struct device_node *np) } EXPORT_SYMBOL(of_graph_get_endpoint_count); +/** + * of_graph_get_port_count() - get the number of port in a device node + * @np: pointer to the parent device node + * + * Return: count of port of this device node + */ +unsigned int of_graph_get_port_count(struct device_node *np) +{ + struct device_node *port = NULL; + unsigned int num = 0; + + for_each_of_graph_port(np, port) + num++; + + return num; +} +EXPORT_SYMBOL(of_graph_get_port_count); + /** * of_graph_get_remote_node() - get remote parent device_node for given port/endpoint * @node: pointer to parent device_node containing graph port/endpoint diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index a4bea62bfa290..a6b91577700a8 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h @@ -37,14 +37,41 @@ struct of_endpoint { for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \ child = of_graph_get_next_endpoint(parent, child)) +/** + * for_each_of_graph_ports - iterate over every ports in a device node + * @parent: parent device node containing ports + * @child: loop variable pointing to the current ports node + * + * When breaking out of the loop, of_node_put(child) has to be called manually. + */ +#define for_each_of_graph_ports(parent, child) \ + for (child = of_graph_get_next_ports(parent, NULL); child != NULL; \ + child = of_graph_get_next_ports(parent, child)) + +/** + * for_each_of_graph_port - iterate over every port in a device or ports node + * @parent: parent device or ports node containing port + * @child: loop variable pointing to the current port node + * + * When breaking out of the loop, of_node_put(child) has to be called manually. + */ +#define for_each_of_graph_port(parent, child) \ + for (child = of_graph_get_next_port(parent, NULL); child != NULL; \ + child = of_graph_get_next_port(parent, child)) + #ifdef CONFIG_OF bool of_graph_is_present(const struct device_node *node); int of_graph_parse_endpoint(const struct device_node *node, struct of_endpoint *endpoint); unsigned int of_graph_get_endpoint_count(const struct device_node *np); +unsigned int of_graph_get_port_count(struct device_node *np); struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id); struct device_node *of_graph_get_next_endpoint(const struct device_node *parent, struct device_node *previous); +struct device_node *of_graph_get_next_ports(struct device_node *parent, + struct device_node *ports); +struct device_node *of_graph_get_next_port(struct device_node *parent, + struct device_node *port); struct device_node *of_graph_get_endpoint_by_regs( const struct device_node *parent, int port_reg, int reg); struct device_node *of_graph_get_remote_endpoint( @@ -73,6 +100,11 @@ static inline unsigned int of_graph_get_endpoint_count(const struct device_node return 0; } +static inline unsigned int of_graph_get_port_count(struct device_node *np) +{ + return 0; +} + static inline struct device_node *of_graph_get_port_by_id( struct device_node *node, u32 id) { @@ -86,6 +118,20 @@ static inline struct device_node *of_graph_get_next_endpoint( return NULL; } +static inline struct device_node *of_graph_get_next_ports( + struct device_node *parent, + struct device_node *previous) +{ + return NULL; +} + +static inline struct device_node *of_graph_get_next_port( + struct device_node *parent, + struct device_node *previous) +{ + return NULL; +} + static inline struct device_node *of_graph_get_endpoint_by_regs( const struct device_node *parent, int port_reg, int reg) {