From patchwork Wed Aug 28 05:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 823388 Received: from TYVP286CU001.outbound.protection.outlook.com (mail-japaneastazon11011045.outbound.protection.outlook.com [52.101.125.45]) (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 C5C7214A0B9; Wed, 28 Aug 2024 05:11:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.125.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724821911; cv=fail; b=LSEf/jt9fNfDzmEqfBlEPUUrRO234gTohXrJTYnqN6I9ukbxxS0qa07HeEj52KXnMFN5ABF3gXX4YXWrrZ8zE6JFlauN3VThbpWFaYHrmFBZCPLdIwxnhOl76d8/x2Nq2kGQh8cCxDEOG0fu3NyCgDwSCzbKk15T+k5mK5lG8lE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724821911; c=relaxed/simple; bh=4WlR3th0gwV+gBtUbSJKN+Y51/xId5qBGAznd3u5kuo=; h=Message-ID:From:Subject:To:In-Reply-To:References:Content-Type: Date:MIME-Version; b=PI4+4l2UAbfWV7EazV0uIcyoB8R6oaUddJiJKKErjuU1LPSsFG64Am8+V5t42ebScYZ8KMxLe0ByTKeXLFWUvgdeRo9ntms2wU3rT0WyPr38q5vHDfsFJg8QWKJ5bjaMKI5fXzbIKnI+dclN14iv9sR6yD73sjzRmf/9mWcPg2k= 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=eJMR+mY4; arc=fail smtp.client-ip=52.101.125.45 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="eJMR+mY4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=r7xKNAit5lvTg5lK1wlyG07i7hBluCZ+Ie+wppg1g/Kld8pNXo4nSNCfF4pm3L021/7XCVZYhzOqwWeiMttkLZfCmV3GDgetQxkDdPRt76Va0QzqgDTpZVS86/UlyDUnts/SNlrJXCbjvLZHvm8LaIlYcJRIg8SlmrogM0K/W6C47GyAQBWTzRm2/0q1D+60Kt38u0V1FY1mh1qVSuGKNB2omNC8EwJP8dzkFo5dEZrAG+0NLrb3UxDJaX+3sIQfLNd4DqDmnfriauTqBwpUJWCtDxZwJz5HoSmXrRyp/LIG8IaItR+EaE2mWnFxVW0BQhLGbtWQX0jO1/GQ5T11Sg== 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=caINNuwjSdjF5e9AjP2qw+j3mL2DYJ7HEtdeMmZlYc4=; b=o5HFwKKhXQhdOqzwYa8GBoRH/6Qy5vTToXY9xwhzjRdY9eZR8Aog8KCt9gVUIw4Azg1gZRmAtmVw33wBRnBuEYn9hI6aIiZQebxR+C9XjAG894QY2Lz1kEokWFCfdezs+xLvva3zmviyjmLdg4sUVks4L3NWZ54dyaZ63fiN+99PrZLLjAMB+DlUNGKoirPqLcR525rIF5pdwYhMWF7nK7MrgynHnY08/SWDKUM5TfXxY/XRYLlKZ61UHoErrxJZ0cSMhozdwNo8JctHo6iSjJHnsIc1+4Qp+Coam9GE08GetJXXqVCCvEOOjzUsaZOj/SXimjpqv0YU25D5Tx+zUQ== 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=caINNuwjSdjF5e9AjP2qw+j3mL2DYJ7HEtdeMmZlYc4=; b=eJMR+mY45S8BIBiMnMqdNIFn4FRhKvkwGOS1dmLYsvIhyvcWns9lBIsQgzCznCfGTywYQyBsB8aCPgVQD+gCXJS2d6WGRv4BPhnhBRYgSfyX7q3ieX1xF3QbT12DOrztAd4bkFPYbhQJqSNOWhn2cZIKRXVJ/KAj5JV3quGd2WE= 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 OS7PR01MB11955.jpnprd01.prod.outlook.com (2603:1096:604:23e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26; Wed, 28 Aug 2024 05:11:44 +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.7897.027; Wed, 28 Aug 2024 05:11:44 +0000 Message-ID: <878qwh2pv4.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v4 2/9] of: property: add of_graph_get_next_port_endpoint() 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: <87bk1d2pvt.wl-kuninori.morimoto.gx@renesas.com> References: <87bk1d2pvt.wl-kuninori.morimoto.gx@renesas.com> Date: Wed, 28 Aug 2024 05:11:43 +0000 X-ClientProxiedBy: TYCPR01CA0179.jpnprd01.prod.outlook.com (2603:1096:400:2b2::14) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) Precedence: bulk X-Mailing-List: linux-omap@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|OS7PR01MB11955:EE_ X-MS-Office365-Filtering-Correlation-Id: d97b14c9-464b-415f-395a-08dcc71fe8ac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|7416014|376014|52116014|366016|921020|38350700014; X-Microsoft-Antispam-Message-Info: oa6eVMwPEpGJhsN1OwZLwXytS5P8bIrFEv7JyA1vboNndVoiG/eUAm24XlKtTB3cX65YJcdJ6pQUO0Q67uxrnCCwTBvRfvtQ22wuSyiRMi+YyNyBivb6FdgIXqf6zlP4FL9szkxQ0+egQNXkzVpPZQdyuen4elHwCk3lUixTR1GuhVpADbrYkJjpRJjTJcXZaVGVcefgzqL6ifC4pSqRz2TYTw2sUsR0nWyAur1hlwWhuwr7QcwFs148TsC+/OH08qx99FPL65RGWr/u/R/bRI3BqMJ+ojb53bn46h/HPsV2dZYipqJAls8+GhERH3a8Q2oQqEUaPitDF0isqVmX5qefN1TG2ICAWHIqtFXvLAvqK9Jq5WFJaam3TDO3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-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)(7416014)(376014)(52116014)(366016)(921020)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KUllNGSUJEfeW9XOgjL18bwLekuVomNOC+ILtLxrFETUjQs7BMXCItkfvu6kfD8smz4dEiU6RHing1wPib9/1yNfCVrw5IW1FtBBt1cyi5n8wDTfATZoLS3YjqJXY1DeaJlH93+8Ak+8DIoSncMR2JUJ+cc/xazAd63PNPMr5c3R4OmwV5gCkMEGFLtl3Mnxf42NJzp73XETZHYZT4Je5xP9/dwG/A6MyIciEcRxuoMvWSYK+lfCiFHDEpYxahhzLnthfRLFlCLvA94BccBfJPNjEPlhw+WXmmU5zIHQb1tVUX8txSo9EqLYxsfhA+b1GFzFQkGp3Fg5R9anTk5pNWBzA2hJhWjeFwAPlu1XquEwNfJ4vGWNJhXUWlxwKoZmE7Fvh8OUyAdgbZpP6rZNPMPW3f2pqhG0yL71i0xgLIYrkIUhW3YFo70wjAmlpfPWvJ20w/VCO6ntCNmDeFsHO9hcmfrRP1j11+Dr+EBdzny5dlpsKq8qrav4XYdxrnp3snkqO9HWKIlFGPoILnOjjwvIqgMm99cjmFhd04lUveWD+d1DB0wV7Qhq+kyMpn/+sRdGITOSyweXyCfaVVsRrwWMKJ2S/6/Aawr0kbXdxWfGDOy4iKIWoB5nOpH0bf97OnvIs50IfjAqV1F3lTZMi+aAqXZC/ABpFInEQxCUOygE6/t5MJXwOtWSxt/TcHaR0vUCm/xpjHa1qH+1MX6L39LkQj1lbYo2qobwQWyc147Bwv9OaT4Ui8isJxS8sRtOoiIW4tjB9B1P4aRFHzTRSCmft6Yo40yD7fZdTn/mqdDprUJScywlWu+aHY0Qae7JDZc39udVKwdcfdCQfrplYU3D2tqzWv52GsEaOYc7elMruZs818ahjLB3aFT7EeuUaw15cynzgiomezf6iEprM7jI4G0HSvZPGOOSOx5o62lKj5fN8wvO3+pOqmJOCVBBKhuACQab2rLv4MNvwnrszsX2betgZMi+RPiJLTvocU/Z8VIDsBH2PxqF3fARY58qSbhdNs93BSrYCwsCu39dvZ4a96URtrZjPREBb5+QLtVoxHUXRqJw6ZBYxOzs+vaJHrkp+uRgqaVTc+3XGUhknDLtb7txskRyTFZSW5wMKwfcMwWz5iHY0+YMwsSFOZTkqhNJM81l6m1j9i1btGwtAwIAYtW/Cq9aElJoyR+1dEnu5VSBcY5R7EAmXcAhiGA8eviZnjq7BgEgKQDhjAmzVgeeXEzxGd04CYTWL5pEqoEflWt5CahovVGFnXg3E2rVgcfpBPkbNyfJgNTvKngB2lGfefUT/wz5ur4oRKyQeLh4rNAH7+TNvC2HG466s6RK71eVZjqzcShR9/6n0xsyYWMcp4tH9QMF5QZBPE7NiAXR/PpAgC+zWVwkrZsVkpg9MtE5DNSbtKME4yIoJOXXrO7R7ytG3dAUdysrMn7AKPemyze3DiA48KFjjwKdILRIzEJnqSnjIshOqGNbKks6XSmlCjG9nD4AMT3KMVFHK6q2p0QoXRcmCRXUwMtj97hjs/mZXJ1pqDF8k1kCIR0o0jIY3bAFw4hytIMfkv2ptX20Flnm9oqJEUCal50l9Er6rYtD0ydFYKwBpuN8psiiLLqHOEJTgE7YQg0Bs2d3wbI= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: d97b14c9-464b-415f-395a-08dcc71fe8ac X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2024 05:11:44.1932 (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: Lcx24qF5zuu5rgBf6QPn7c/HOJpJtHwE3DlV+W3QjarPgadw9UzZgjGIT9B1JIkY1o/XTjfghDEHl/Q/rcm59QCm947haD9dGF0iXECc9imXbxWWQSkBb8v8Fqmy269m X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS7PR01MB11955 We already have of_graph_get_next_endpoint(), but it is not intuitive to use in some case. (X) node { (Y) ports { (P0) port@0 { endpoint { remote-endpoint = ...; };}; (P10) port@1 { endpoint { remote-endpoint = ...; }; (P11) endpoint { remote-endpoint = ...; };}; (P2) port@2 { endpoint { remote-endpoint = ...; };}; }; }; For example, if I want to handle port@1's 2 endpoints (= P10, P11), I want to use like below P10 = of_graph_get_next_endpoint(port1, NULL); P11 = of_graph_get_next_endpoint(port1, P10); But 1st one will be error, because of_graph_get_next_endpoint() requested 1st parameter is "node" (X) or "ports" (Y), not but "port". Below works well, but it will get P0 P0 = of_graph_get_next_endpoint(node, NULL); P0 = of_graph_get_next_endpoint(ports, NULL); In other words, we can't handle P10/P11 directly via of_graph_get_next_endpoint(). There is another non intuitive behavior on of_graph_get_next_endpoint(). In case of if I could get P10 pointer for some way, and if I want to handle port@1 things by loop, I would like use it like below /* * "ep" is now P10, and handle port1 things here, * but we don't know how many endpoints port1 have. * * Because "ep" is non NULL now, we can use port1 * as of_graph_get_next_endpoint(port1, xxx) */ do { /* do something for port1 specific things here */ } while (ep = of_graph_get_next_endpoint(port1, ep)) But it also not worked as I expected. I expect it will be P10 -> P11 -> NULL, but it will be P10 -> P11 -> P2, because of_graph_get_next_endpoint() will fetch "endpoint" beyond the "port". It is not useful for generic driver. To handle endpoint more intuitive, create of_graph_get_next_port_endpoint() of_graph_get_next_port_endpoint(port1, NULL); // P10 of_graph_get_next_port_endpoint(port1, P10); // P11 of_graph_get_next_port_endpoint(port1, P11); // NULL Signed-off-by: Kuninori Morimoto --- drivers/of/property.c | 27 +++++++++++++++++++++++++++ include/linux/of_graph.h | 21 +++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/of/property.c b/drivers/of/property.c index d99b34dd2d5b4..5d253ca365aca 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -716,6 +716,33 @@ struct device_node *of_graph_get_next_port(struct device_node *parent, } EXPORT_SYMBOL(of_graph_get_next_port); +/** + * of_graph_get_next_port_endpoint() - get next endpoint node in port. + * If it reached to end of the port, it will return NULL. + * @port: pointer to the target port node + * @prev: previous 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_port_endpoint(const struct device_node *port, + struct device_node *prev) +{ + while (1) { + prev = of_get_next_child(port, prev); + if (!prev) + break; + if (WARN(!of_node_name_eq(prev, "endpoint"), + "non endpoint node is used (%pOF)", prev)) + continue; + + break; + } + + return prev; +} +EXPORT_SYMBOL(of_graph_get_next_port_endpoint); + /** * of_graph_get_next_endpoint() - get next endpoint node * @parent: pointer to the parent device node diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index d5e9d0ed3145d..83bcdac22169d 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h @@ -62,6 +62,18 @@ struct of_endpoint { for (struct device_node *child __free(device_node) = of_graph_get_next_port(parent, NULL);\ child != NULL; child = of_graph_get_next_port(parent, child)) +/** + * for_each_of_graph_port_endpoint - iterate over every endpoint in a port node + * @parent: parent port node + * @child: loop variable pointing to the current endpoint node + * + * When breaking out of the loop, and continue to use the @child, you need to + * use return_ptr(@child) or no_free_ptr(@child) not to call __free() for it. + */ +#define for_each_of_graph_port_endpoint(parent, child) \ + for (struct device_node *child __free(device_node) = of_graph_get_next_port_endpoint(parent, NULL);\ + child != NULL; child = of_graph_get_next_port_endpoint(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, @@ -75,6 +87,8 @@ 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_next_port_endpoint(const struct device_node *port, + struct device_node *prev); 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( @@ -135,6 +149,13 @@ static inline struct device_node *of_graph_get_next_port( return NULL; } +static inline struct device_node *of_graph_get_next_port_endpoint( + const 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) {