From patchwork Wed Jan 31 05:06:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13538902 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B1DBC48285 for ; Wed, 31 Jan 2024 08:22:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E0FF61121AE; Wed, 31 Jan 2024 08:22:26 +0000 (UTC) Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on2097.outbound.protection.outlook.com [40.107.114.97]) by gabe.freedesktop.org (Postfix) with ESMTPS id AE5ED10F1AE; Wed, 31 Jan 2024 05:06:41 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DQSKYT7JwnXPLZhi+47RtpdOsCBRWv3IsU1ZbWaK4JV/9ULCqQi5aZA/JBXjDkNL1mTuMAZH6AKSxtBk6QBrU242nREzFiEEp7RBRiV6403GCAhOvMa/Qc8F3+1Dr40qKZxh8rk72jkWBaSaIvyWtDgtDWcwyjboB1YZ2rxJTAkc2jY+WJKvRtos8WS/o5dlgjVOLHNpHzeJGLaL2GlqNBJhWuQh5hEfXCsLC8Ul91i7wti8qj5Zc13meONqEKTzN5M0M2CML1jFpJ7VfGqaHnCzwimhKh69/3oz+bxPGp1CfTYJFhtJL81ROfZR56TeEiKxjwBq7hbe6MIaF+B6gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=VgdxHWYA7YfL4j/ktYaAZ4Nhk96/3I8fgZS3YdTZVXs=; b=WQYY4lGUMISOFVADeVHTWHKkaL9erU2vfVFqHnVUxKNjn0LLK1SjeDOvrGPCGXGX16Hb2sNE9n0oFyew59pX9sOlPvxQU/adZPac/M2EwqqIzpxjid7eiRUacK8LEVRj5KTbeGIJ86s1LJKdSx0wDN7hvxScstMVXXTLPHf78XA9fw6jcl1bpZKYuToYAkHCkPW7Xkpi1/OU/eIlMfyxM3Ox5gzGd14dZu2byYPQoTFmCZ4lUwoSDLSLuyWbLMLdYZ1G2F3swTRVE7DAiXQuaW/fXvA8g3h8fcFuwz32fCCEOECl1BOKMrAXoYQ2MrR6SLPuvnfU50PGO7YN4bePpg== 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=VgdxHWYA7YfL4j/ktYaAZ4Nhk96/3I8fgZS3YdTZVXs=; b=A3nRpaolR1AUuxKtgPRWQ1a1JqnCWVwfmBpOBLL0H5VDN5q1Gv6L9fe+yYmKf5s8cPLaq21fQbhhrWKSbm2+q+uMXTFEnLD3Kl2qD1ORVbuxo29WAA+84WLRQrqzQxqyGWR/9B3ybjtSji2jBwrOSEBbg1sGgUFYkEmRWZLPLwM= 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 OSZPR01MB8896.jpnprd01.prod.outlook.com (2603:1096:604:158::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.23; Wed, 31 Jan 2024 05:06:37 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::ce8:8f5e:99a0:aba4]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::ce8:8f5e:99a0:aba4%2]) with mapi id 15.20.7249.023; Wed, 31 Jan 2024 05:06:37 +0000 Message-ID: <874jeu6qhv.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto To: "Bryan O'Donoghue" , "Lad, Prabhakar" , =?iso-8859-1?q?=22Niklas_S=C3=B6d?= =?iso-8859-1?q?erlund=22?= , =?iso-8859-1?q?=22Uwe_Kleine-K=C3=B6nig=22?= , Abhinav Kumar , Alexander Shishkin , Alexander Stein , Alexandre Belloni , Alexandre Torgue , Alexey Brodkin , Andrzej Hajda , Andy Gross , Biju Das , Bjorn Andersson , Claudiu Beznea , Daniel Vetter , Dave Stevenson , David Airlie , Dmitry Baryshkov , Dmitry Torokhov , Emma Anholt , Eugen Hristev , Florian Fainelli , Frank Rowand , Greg Kroah-Hartman , Hans Verkuil , Helge Deller , Hugues Fruchet , Jacopo Mondi , Jacopo Mondi , James Clark , Jaroslav Kysela , Jonathan Hunter , Kevin Hilman , Kieran Bingham , Kieran Bingham , Konrad Dybcio , Krzysztof Kozlowski , Laurent Pinchart , Laurent Pinchart , Liam Girdwood , Liu Ying , Luca Ceresoli , Maarten Lankhorst , Marek Vasut , Mark Brown , Mauro Carvalho Chehab , Maxime Coquelin , Maxime Ripard , Michael Tretter , Michal Simek , Miguel Ojeda , Nathan Chancellor , Neil Armstrong , Nick Desaulniers , Nicolas Ferre , Philipp Zabel , Philippe Cornu , Raphael Gallais-Pou , Rob Clark , Rob Herring , Robert Foss , Russell King , Sakari Ailus , Saravana Kannan , Sascha Hauer , Shawn Guo , Sowjanya Komatineni , Stefan Agner , Suzuki K Poulose , Sylwester Nawrocki , Takashi Iwai , Thierry Reding , Thomas Zimmermann , Tim Harvey , Todor Tomov , Tomi Valkeinen , Yannick Fertre In-Reply-To: <87o7d26qla.wl-kuninori.morimoto.gx@renesas.com> References: <87o7d26qla.wl-kuninori.morimoto.gx@renesas.com> Subject: [PATCH v3 14/24] of: property: add of_graph_get_next_endpoint() User-Agent: Wanderlust/2.15.9 Emacs/27.1 Mule/6.0 Date: Wed, 31 Jan 2024 05:06:36 +0000 X-ClientProxiedBy: TYCPR01CA0096.jpnprd01.prod.outlook.com (2603:1096:405:3::36) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|OSZPR01MB8896:EE_ X-MS-Office365-Filtering-Correlation-Id: 718d6cfd-8a80-4310-d69b-08dc221a670e X-LD-Processed: 53d82571-da19-47e4-9cb4-625a166a4a2a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0Egs0/kruZUqrBNkrbIY4Fy/euydV5Kt1bXRN+QJsGNTNFgI8z5jUzpqhJyd8t7pv7FeQkCaDkz8cX2ggIVyJXpiKKd+/YDA6O12p0CS4B5DknwDI1AzVEXaQ2CS6AuNmgY8G+/+XldjLIo/Vbs0pcwFKHNVCN2plUo12NFRVc1Jre7/fQ79/WGNVeg/aVDTilw0Noscfy5ak+Cv6fCfy7A69JoOBf1qDfMn89a4kRqZuNXjfCW3sAVCOUfGcsrLw7UvoRYNT8n1i96xXsNF/3Mej43TX0vv+uEqN4vx97AcX8NJhtIIMP6eEhCLCYJnDwKXS81Zp2omRMFaDukuqwUH5wttwF7BwS8B+gMk1U+vN7JFqDsY1MKG2NHLaF/HCa0yOFv0Gh5PJ/qaSdjGgGXEwp2wwp/KVn98DF8S644C3iA7U/GiEJGqJftmVtzIu8uYUekS7dVYfC+AIpxqXUZql/L1uDq9kSeVXSbmaFrHueLGzBKagGgzCLu2jkjG/WU6tv/SUtt8yB5j11AYSyt1xO4EnZ21JmtgEYGv9PjxW1luCPhn3ArrKbEEw6d1n4m0MuJoZqx+7fcQzU/Y9fLD/b2URqvPFOA4I4D62legkI3U7mw5pXWi4kUXp6EGuHkmPa95UIgK4lvQiu7UvULYGhaqlXuHKu31y8iV/RQ= 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:(13230031)(39860400002)(366004)(136003)(346002)(396003)(376002)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(36756003)(7336002)(7366002)(7276002)(52116002)(7406005)(7416002)(6506007)(38100700002)(6512007)(5660300002)(86362001)(83380400001)(38350700005)(41300700001)(2906002)(2616005)(478600001)(6486002)(26005)(1191002)(921011)(66476007)(66946007)(66556008)(54906003)(110136005)(8936002)(8676002)(316002)(4326008)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Q2bgGngEQNZqwRQzQuHpQTfh9R/iTs4jHFnlktU4HpeX0bH3WovuZQXcfdqAsUPAa4fHkCtdiY3JY3loBZ/5nFRkA04BgndtiLlyZ4zqTxRXJ6BXacx1PyCqZ2utu5CVIQf2J3jzjpcAh+Jf5bM52QVQ0dgzjM0m0Nr8JsqE252QSQjvPNHix0Yw2IJ1r7InXT2YNrp+4gBULM1u8EpcK0fXclmG1+OQnhktb9Rk/AQmsW3DrBOHx/PQPEKFWUpxyCzkzlLpIZkugX5q+41R351XCr9mjoSxAmqWtyrAF+rg1gu/qCaga9l5q7UEhzDDEgpgAGYJ6xyIvCO/bcBLsYPJKK7Crbyv4aaHHsCYMV0vr7i+zmQ8ITm9qH7bWT8K30vwz3bttK2d38ZF+Ojok1mqf0ivu4ft/PnAQBbSPHtjB1ZlTizbetv779R+GbbEhtL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WU/qJUj0v2pluavDo4lgU2Kemi5d4wnZ0bXK/MOE+YJ5n+SvybnKBj4DhEDYTQI0wOSYgi0MTEEFcziDmiVMZ+/Ir/+K6gCvnSxON3VOKj9vTcGSbt5vA= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 718d6cfd-8a80-4310-d69b-08dc221a670e X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jan 2024 05:06:37.4449 (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: LVmZZ35VTToskq6N5o9mWHPVvD7j0HWGJGClPXq9toqHWmziqZEgHPVi4ocp0pRZxXTZ1ehGfGqOpu+ICqA0A+hzzgkMx2Q1h1Z4NFsZ38SaYHVkoeQaqAvRCCpTr127 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSZPR01MB8896 X-Mailman-Approved-At: Wed, 31 Jan 2024 08:20:59 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, Tom Rix , llvm@lists.linux.dev, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, Laurent Pinchart , Alim Akhtar , Marijn Suijten , Sam Ravnborg , linux-stm32@st-md-mailman.stormreply.com, Jerome Brunet , linux-samsung-soc@vger.kernel.org, Fabio Estevam , linux-staging@lists.linux.dev, Jernej Skrabec , Jessica Zhang , Mike Leach , devicetree@vger.kernel.org, Jonas Karlman , Martin Blumenstingl , linux-arm-msm@vger.kernel.org, coresight@lists.linaro.org, linux-sound@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, Jacopo Mondi , linux-amlogic@lists.infradead.org, linux-omap@vger.kernel.org, Sean Paul , linux-arm-kernel@lists.infradead.org, linux-renesas-soc@vger.kernel.org, Leo Yan , linux-media@vger.kernel.org, freedreno@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We already have of_graph_get_next_device_endpoint(), but it is not intuitive to use. (X) node { (Y) ports { port@0 { endpoint { remote-endpoint = ...; };}; (A1) port@1 { endpoint { remote-endpoint = ...; }; (A2) endpoint { remote-endpoint = ...; };}; (B) port@2 { endpoint { remote-endpoint = ...; };}; }; }; For example, if I want to handle port@1's 2 endpoints (= A1, A2), I want to use like below A1 = of_graph_get_next_device_endpoint(port1, NULL); A2 = of_graph_get_next_device_endpoint(port1, A1); But 1st one will be error, because of_graph_get_next_device_endpoint() requested "parent" means "node" (X) or "ports" (Y), not "port". Below are OK /* These will be node/ports/port@0/endpoint */ of_graph_get_next_device_endpoint(node, NULL); of_graph_get_next_device_endpoint(ports, NULL); In other words, we can't handle A1/A2 directly via of_graph_get_next_device_endpoint() so far. There is another non intuitive behavior on of_graph_get_next_device_endpoint(). In case of if I could get A1 pointer for some way, and if I want to handle port@1 things, I would like use it like below /* * "ep" is now A1, and handle port1 things here, * but we don't know how many endpoints port1 has. * * Because "ep" is non NULL, we can use port1 * as of_graph_get_next_device_endpoint(port1, xxx) */ do { /* do something for port1 specific things here */ } while (ep = of_graph_get_next_device_endpoint(port1, ep)) But it also not worked as I expected. I expect it will be A1 -> A2 -> NULL, but it will be A1 -> A2 -> B, because of_graph_get_next_device_endpoint() will fetch endpoint beyond the port. It is not useful on generic driver like Generic Sound Card. It uses of_get_next_child() instead for now, but it is not intuitive, and not check node name (= "endpoint"). To handle endpoint more intuitive, create of_graph_get_next_endpoint() of_graph_get_next_endpoint(port1, NULL); // A1 of_graph_get_next_endpoint(port1, A1); // A2 of_graph_get_next_endpoint(port1, A2); // NULL Signed-off-by: Kuninori Morimoto --- drivers/of/property.c | 24 +++++++++++++++++++++++- include/linux/of_graph.h | 9 +++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/of/property.c b/drivers/of/property.c index 083f92513f5e..ff37fd5194c1 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -669,6 +669,28 @@ struct device_node *of_graph_get_next_port(const struct device_node *parent, } EXPORT_SYMBOL(of_graph_get_next_port); +/** + * of_graph_get_next_endpoint() - get next endpoint node. If it reached to end of the port, + * it will return NULL. + * @port: pointer to the target port node + * @endpoint: current endpoint node, or NULL to get first + * + * Return: An 'endpoint' node pointer with refcount incremented. Refcount + * of the passed @prev node is decremented. + */ +struct device_node *of_graph_get_next_endpoint(const struct device_node *port, + struct device_node *endpoint) +{ + do { + endpoint = of_get_next_child(port, endpoint); + if (!endpoint) + break; + } while (!of_node_name_eq(endpoint, "endpoint")); + + return endpoint; +} +EXPORT_SYMBOL(of_graph_get_next_endpoint); + /** * of_graph_get_next_device_endpoint() - get next endpoint node. If it reached to end of the port, * it gets next endpoint from next port. @@ -712,7 +734,7 @@ struct device_node *of_graph_get_next_device_endpoint(const struct device_node * * getting the next child. If the previous endpoint is NULL this * will return the first child. */ - endpoint = of_get_next_child(port, prev); + endpoint = of_graph_get_next_endpoint(port, prev); if (endpoint) { of_node_put(port); return endpoint; diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index 48f7701feab1..ee4b219594f1 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h @@ -57,6 +57,8 @@ unsigned int of_graph_get_port_count(const 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_device_endpoint(const struct device_node *parent, struct device_node *previous); +struct device_node *of_graph_get_next_endpoint(const struct device_node *port, + struct device_node *prev); struct device_node *of_graph_get_next_port(const struct device_node *parent, struct device_node *previous); struct device_node *of_graph_get_endpoint_by_regs( @@ -105,6 +107,13 @@ static inline struct device_node *of_graph_get_next_device_endpoint( return NULL; } +static inline struct device_node *of_graph_get_next_endpoint( + const struct device_node *parent, + struct device_node *previous) +{ + return NULL; +} + static inline struct device_node *of_graph_get_next_port( const struct device_node *parent, struct device_node *previous)