From patchwork Tue Aug 6 04:58:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13754434 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 D3615C49EA1 for ; Tue, 6 Aug 2024 04:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Date:Subject: From:Content-Type:References:In-Reply-To:To:Message-ID:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7p6eoE6N+1xmYecGXR25d8woQupOR2IiFBY9GkbC3CQ=; b=UL4goBvbCJAuQHOcMoYO3vsjsU Nhca+VE0UeMmsHKzlqW50/X5F4F5hN5aEowkseRu7Ngut31x9FYponTHE/qUcXpzSG44Ce+BrNeO/ Ahph9tGFRFv/vqcCX64u9HltDyvE5tstlA3p+Bp20OhF8iyAHDpRfj+4JkRHEhh4s9sbPyi7uBGWE /XfvqcOpgFRBQl1j6VKsNBdow1JoP3+o5uHdIGS5sEKF8zvAPztgXWwsJBv4XEAnus9Q4nEdzc7x5 jz46Ilofrji8aX0AoItMbDm0J0u8qEpJkA4N0BNYuiYCqS1Z9ORpp4Y3sUCWlcewNamIB5/IlQ9sh eMvJ5z7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbCIW-00000000WmW-32Fu; Tue, 06 Aug 2024 04:59:48 +0000 Received: from mail-japaneastazlp170100001.outbound.protection.outlook.com ([2a01:111:f403:c405::1] helo=TY3P286CU002.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbCHH-00000000WN6-3YLM for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 04:58:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=klsja21M0A3l11cMkkxILdhjHjSzBrfUuBwmoR6G9LqoyIusVmErZoNLlWzBDO5xhFIhr8BnLkT3Eqdcu6K2ZOa/1s02dKIkKLX4LbLzQtKgGxKeksdSa9J8O1LvHk9aLGELmv3enPaC1nC3TNDJWMcUbasYiZgS+RgfSDDvyWu4bfJB8j/oPJi0E64qPBArFGg69rw1ueUqoz80FXjGg44huftYnyXFK73ySz3NzxrynnSP6ry4/sye0rnBQ4YXE+8y7qR6vv8cs5LLkkPxAbs3asTgB5aXfbZQFIitXoricF5sE1LJYD71296XCo12LANOXqeerzNt0so1peTH8w== 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=7p6eoE6N+1xmYecGXR25d8woQupOR2IiFBY9GkbC3CQ=; b=j/BxEyjzjLezYKwHRJMzlkIp46VLwRbPsCNOAQXYdIwmv0DpPpeL/Cx2jqEkp1d+cfbkGk5NS6fHHiSm7ckJ2jYAunqlcosYKThjiY93K6jahZQSUpbBiUf12T1VF45SvGYTPxa2zATMTN2GHt4icDIl9Ow+5FwqeldUvDGs7FLaM4yEUjV67nfREv9s2zkuox6jX+FLhBQkT0/JzbCzwWmjRm8qSFaNeycFVm2tESZnMnG/GGEhf+6UVg2U/9FqfoA9Kk4q5lb9u6ohOXqQVrzg0ssILmYh+vFOFychiQfOQssG6mNUMUDOOHWsxAkQMBcnVE4HPDYnhSlVkXfMwA== 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=7p6eoE6N+1xmYecGXR25d8woQupOR2IiFBY9GkbC3CQ=; b=JehxJfl9XXUUCSH75ha6VJmRwBlnYfvGIb3fCFB84kO7RBNvrGjPxYxlwXVeh9DR5/W9YzkVZCTRXdF/lnYMJ2i8Xynj9D26TEFeH5A4vXgMqKMYQYvkKELC3dNcEOoCztHlDO7bMCBJj4pai44VdpJHtsiRPMZAPcYz22nFQe0= 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 TYWPR01MB10409.jpnprd01.prod.outlook.com (2603:1096:400:24d::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.24; Tue, 6 Aug 2024 04:58:29 +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.7828.023; Tue, 6 Aug 2024 04:58:29 +0000 Message-ID: <87jzguw8ln.wl-kuninori.morimoto.gx@renesas.com> 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 , , , , , , , , 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 , , , , , , , In-Reply-To: <87mslqw8mj.wl-kuninori.morimoto.gx@renesas.com> References: <87mslqw8mj.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 2/9] of: property: add of_graph_get_next_port_endpoint() Date: Tue, 6 Aug 2024 04:58:29 +0000 X-ClientProxiedBy: TY2PR02CA0029.apcprd02.prod.outlook.com (2603:1096:404:a6::17) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|TYWPR01MB10409:EE_ X-MS-Office365-Filtering-Correlation-Id: 66e36304-b05c-499b-96dc-08dcb5d469da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|7416014|366016|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: SMgHLhdbIPkOiu4zFfOh//J8alWCI1DBA9UhGNtgdepQejmKWiryup0PNQwKNvTkP7MJR2n+MQyMNnbkFszPp6MHB86yn+ObyzE5XqGqKbo/99UtFPx4rtI1SBakhacZj36Ci7zRUQbzC9Q0JNJ7h6zdNWQTnBPRKG/B3UWwZ8SyL4jOqdxG08YU4Lq2NnbqVfDZapoD8eLDp9o99zpTwiK23s5rGmTybTJbKfO/EcthxWK90ns9hiPQrGtmOSyPfQgXnfcWx+9+NSldaY/1FauCD/nv24/SB3D9NOdIN92gdllbMi0SEQH0nX0qdE69ZjOCMYTQa4OO/kQEPw+00exdOx++Fc65jcHOkLP/bZ2a+xHALNROaLDmyANgnj7cOReHXT6K4f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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)(52116014)(7416014)(366016)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 996hjRTKvpcB/bds9g74VaRmCQNqgYDh0GKt8TgkGpetLJkUhsE6GOQhZKJZY3xBaq8i0v5me8nwLwiPgX75+g/GIgWumtWdfB9jCXDQG35ms4bMolh1ipC9Jk4/rOi/XNISRb6kIGD5WWGWThSUKAPRXBVqRHhYTMXq0YiWMqenmaG/V5Aw0GM6gwvU8OIA3x7AlpPgaf1ngGglnNEsdAq0s6XuVKpnySUyaoQzn3iEymtl/awAXGjs4oXFvaGTgFNCZG+8aUY1iIxjK5OPdrq+L5GjKdjG4UfGWT1Al9x4Wnm4gIUe8n84a2n+RR5l+C2ToXcz569mHNkA9nqWPJvpUCnSg06+YCJTaY9aSRntJTcz/QCQh9bIBgOtJJIHcXkxAr2VCPf2lEWUiDMqTmjAW/Dxy92H+mWBMpICWDcDZZ61WTYjVxpCokqd87OQyZeOaGLG6Ga9+ZdgsC8lLYIWVRX3PhNjUaaNVLRj6Xr1uIo/p+elPzt2rjnKSFwGOH+IrpQ0GRlUaL0ssiXM9TCMPoPOBUqS6zVzor8mspAdw2X18Q6CHIxqs0AB9CRx97CTtnkr+jVZik1k/BXXd5uPdm1dgTyT2kjMl72UKteqck9mX7EuXxK5A6hpxziwv097mrRN3bYRVsBjkwFRxTLxGwUAbOjfGnagf523WF0j+98dPycxuUNEthde+MK82g/0gNuv3aI3YfKy/rHk1rZjm7dub5PJfln7zUO/QeMc3ZfJ89OuYbBV5Dha71b32wzcmmzhk/D+nAtuw/+YtZ4jL3jtNWfQVbW4AB7Yb86HhyppkfsP3DpO+R87TL5mJTOiF0nB9tlJ6O5/UQG1xtKK5m1JB+SUZqz5dp9m60+CmcfBSH46mg8OKMFvg6P/FWiVa4aXZ2me8Xkk8uAfI1tpFuuJYQOwLdQAvSVw95WRCLeEUBIUBe33UiwtDjqsqObPL9W72ciYyfk35htrX4TtRski92jhtzupe9ReXmpqqttkNvbeeQyY7b7AfOwzSIpUTQGNfnV4OW822f3wY3BodaUg73vLxEhbEcjITAX9du1hsooqdBij7hJuPtpPaqgHmmiXq/poPh+vMGOzrRuyC3nt4lQBaxJpBWuE2jhDBs3wFmo1ficj4jJsnbkz+sY5i0isJQ0eF39Hqk/8cyoGr1LFHEK1s9YagDkKdkweR5XgucsStveITNZlVUhXx9rX5xcMQcwOcuWaQ+zfOUc2W8I+YVVd966rZBImEv6KyNqfWVzOcIChpNHuCU8cD1nBt0pw+vFRFwlJxak3mMFdSM/agKjpCx1WR+DYAyQ71n9qpGTJxFMgSH+QUy1CoLrMJtquFaC1OKG41nMAL/bD+GHyfz63MMrKLYMi5Y1GYKBtzLw0ZVji4yIZfEmG6Sr+WRseONC6yzUZSK2sBVF/C9MRiI0qk0GsOPB8B+9Kt/JKWTPN3frS8KeOMaFjB/X3zhe7uAModMT8qwJ29C8H1iJ9T4MJZip9jzOxeJIuYOTi8GQjAgcNRGXm/Tiie7AqegwM9HAiFepp9UUiCg+2JHrQTgK0JBxX0O5tBOtVjWfyNWvGijeGqyWTOeLEbzF525/xOqToI6NVTglmSrOPvl59mz0cvq21CjuLL6o= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66e36304-b05c-499b-96dc-08dcb5d469da X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 04:58:29.4257 (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: GNErPKKWFJ18kvCaD4BlJjL0fr3ZiUQXX1fH+lHtxSu3J9bN8s+/oRFN5vTbAQGauE9zuPNXMN5uaGIXzSDI/EvUJ9YVYkxOuFKe4O4XbRZglCyfLxtcOOZFAgeOvwqx X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWPR01MB10409 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240805_215832_200410_4F10E6C5 X-CRM114-Status: GOOD ( 19.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We already have of_graph_get_next_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_endpoint(port1, NULL); A2 = of_graph_get_next_endpoint(port1, A1); But 1st one will be error, because of_graph_get_next_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_endpoint(node, NULL); of_graph_get_next_endpoint(ports, NULL); In other words, we can't handle A1/A2 directly via of_graph_get_next_endpoint() so far. There is another non intuitive behavior on of_graph_get_next_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_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 A1 -> A2 -> NULL, but it will be A1 -> A2 -> B, because of_graph_get_next_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 it doesn't check node name (= "endpoint"). To handle endpoint more intuitive, create of_graph_get_next_port_endpoint() of_graph_get_next_port_endpoint(port1, NULL); // A1 of_graph_get_next_port_endpoint(port1, A1); // A2 of_graph_get_next_port_endpoint(port1, A2); // NULL Signed-off-by: Kuninori Morimoto --- drivers/of/property.c | 22 ++++++++++++++++++++++ include/linux/of_graph.h | 20 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/of/property.c b/drivers/of/property.c index 3b2d09c0376a..de56795a7362 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -692,6 +692,28 @@ 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 + * @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_port_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_port_endpoint); + /** * of_graph_get_next_endpoint() - get next endpoint node * diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h index 30169b50b042..8b4777938c5e 100644 --- a/include/linux/of_graph.h +++ b/include/linux/of_graph.h @@ -59,6 +59,17 @@ struct of_endpoint { for (child = 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 device or ports node + * @child: loop variable pointing to the current endpoint node + * + * When breaking out of the loop, of_node_put(child) has to be called manually. + */ +#define for_each_of_graph_port_endpoint(parent, child) \ + for (child = 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, @@ -73,6 +84,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( @@ -133,6 +146,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) {