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: 13538621 X-Patchwork-Delegate: geert@linux-m68k.org Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on2097.outbound.protection.outlook.com [40.107.114.97]) (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 7BD123D986; Wed, 31 Jan 2024 05:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.114.97 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706677603; cv=fail; b=kPPUtPxvfNvWTUrnradhRRRISYmlrnrEbeVK/9i18Og4KuRvQIDEIMS8bHz/u7ddogEpRHZcMBxKSEeSGhCJHxLATbmMAW2KADBhT1QvGfbdOeHzY+9p7R9L6QAuttQLW3frN7QJn2CJ7MBLwLldZ9oVp7dhtiksX6FkLn1INP4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706677603; c=relaxed/simple; bh=/45nNKcAGvDL441P2vYjElFWTtSjWzeyIzJfyB0VM5k=; h=Message-ID:From:To:Cc:In-Reply-To:References:Subject:Content-Type: Date:MIME-Version; b=LJAs+LlyfPw+r+duXcj2NNA/Ta5j1XQR0ojLCTXhAYG+CIS4CGKauIXJrOSoycQkFR4mRClBbA5TfzpRA8IBJC9HJBbI8mxU2ycbHUFqMm3GGSP84pzV3H+iYpXBObgmIY9U0GPA15E2C5IBNjBpsaSi5ZfMffsRUJcbkMP/D5Q= 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=A3nRpaol; arc=fail smtp.client-ip=40.107.114.97 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="A3nRpaol" 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 Cc: Alim Akhtar , Fabio Estevam , Jacopo Mondi , Jernej Skrabec , Jerome Brunet , Jessica Zhang , Jonas Karlman , Laurent Pinchart , Leo Yan , Marijn Suijten , Martin Blumenstingl , Mike Leach , Sam Ravnborg , Sean Paul , Tom Rix , coresight@lists.linaro.org, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-media@vger.kernel.org, linux-omap@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-sound@vger.kernel.org, linux-staging@lists.linux.dev, linux-stm32@st-md-mailman.stormreply.com, linux-tegra@vger.kernel.org, llvm@lists.linux.dev 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) Precedence: bulk X-Mailing-List: linux-renesas-soc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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/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zNHV5IhkcaMDKVPH3LK2ARjkSLiMuV+w6Zu2kFh+ukO3hjrHF8vXLG1ZAweSKmBH5AnEZUCOT70Qm9KEnMwmmHy8mIhcrQGEJnJHs2DldMTw7EppWU/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 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)