From patchwork Thu Nov 30 02:14:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13473965 X-Patchwork-Delegate: geert@linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="lGXIHi+5" Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2116.outbound.protection.outlook.com [40.107.113.116]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00505D50; Wed, 29 Nov 2023 18:14:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nROYsg3I8JIJCDqCmaisUSdRaKnJzuBL4EcqGiGxRFM8TcTSheklOscPdMzUAvvqR8NdBP0bRGw2BRpjPX6FHE7cBq2RxCBjT5dEuWCZULCg91X2HhULGHSclcQOGi2iRp6T0lPsuZbTAhM9PCQprzsiNyKuDGANqfnbsEW65VmCG5LLD2muaAQ4bfnTfP1gY3qUCx3tyXq4JJ/aZWSLmjkOi8Qt/rGC2Td9QPGoNHdkdqHazB9PLcg3L+wJbeJiVW/780Z3zUbZoWBXK5hBDCNFSvXCZM8nnAFevnmlz5FfwuP63IyrhImnAoWRvE3aFkWopJrSIf9KikduuyudOQ== 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=Xa8GT0VxUza85Ru2MUTrCo0fkoYNH+NXki+bfQgVGe4=; b=e3sIJHGxmFg9MCkBhpZhLk84xY9n52JkXK4bLjyZFVQ7IkIMZVvpGDTIvXaghDDFNHq2B7Jg/z3AD/BC4JoWpVRtqV4Y7Uq8vbVr8ieclQi1XuJrYRUj/46pyEVMrbucMUYOR8Ntk6XQBM9Job6d/2xgLKLjETODeDuxTLzKqpgRbEG1qyjCFzQjHiCf7Mg3fD7wQrabLr5Yl9QXck8nl+gw6SrYHioDi4whZk3QY9/H3kz52TRkgxsba/yPeGA04qLKhvff1bfFyeLLokPxiV5vtJjnEFT/r7CebZI1VtXEv42DgxXLVXlYjqBaBVuePcYy8xK4TCpb1g7lrG6ofw== 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=Xa8GT0VxUza85Ru2MUTrCo0fkoYNH+NXki+bfQgVGe4=; b=lGXIHi+5FXZ2K4WgrreWcSfv0BwZlrKb+x4usudXPAZEUsp9V3HHr3jo+/Ebb/1tZdN/f3OUV/H0wODh0Xo+U6F+57EPsOM1PJsHe2nwUQaEFBvf28DzKOvjbircu0as9pSTCB+MXI/PKZlYwzDbYCJw8IPZCrPL2+po0tfKtsg= 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 TYVPR01MB10717.jpnprd01.prod.outlook.com (2603:1096:400:2ae::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.24; Thu, 30 Nov 2023 02:14:54 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::5732:673b:846c:ed92]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::5732:673b:846c:ed92%4]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 02:14:54 +0000 Message-ID: <87ttp40yxt.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v3 1/4] of: add __of_device_is_status() and makes more generic status check User-Agent: Wanderlust/2.15.9 Emacs/27.1 Mule/6.0 To: Frank Rowand , Geert Uytterhoeven , Michael Turquette , Rob Herring , Stephen Boyd Cc: Rob Herring , devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Aymeric Aillet , Yusuke Goda In-Reply-To: <87v89k0yyj.wl-kuninori.morimoto.gx@renesas.com> References: <87v89k0yyj.wl-kuninori.morimoto.gx@renesas.com> Date: Thu, 30 Nov 2023 02:14:54 +0000 X-ClientProxiedBy: TYCP286CA0270.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:455::16) 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_|TYVPR01MB10717:EE_ X-MS-Office365-Filtering-Correlation-Id: e1437b47-5072-4c98-57d5-08dbf14a247e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i+tBgdDRLjmFW3aF+3uc2npPRARK0z/NpdJNGbOeovDTMROLLmJn8d/NbHmmo+HA8bqDyHCdwg46hKx3n+Z5pokcO0Q6OEW4d7Em1SBPjzgSB+JTnbfdki0OYVNWU3iW7sNIUOKLRk9RzxRsRk84EOHtHIeN94JLPa8aUBQIWJa424Jl0nOsy3X3Sh/k4wsrhH4uYYrIOPnLVFzJpj7O6BY2qCksYzcSqLh3SAMDQNBREkIQDZdD3YG63PlH9M9GGREZe29d60rOF3H7KejfxgXjWI5lW6x9uJp6J/VyTnlW943wDkmZi+i400QI/w2RqcdSENSR0URf2YPhHJ40wPBDWSBCkyy9pXlS8FoQ8w6pctDsbRNq5aygrOBbbbvc+nekekSBgkt6EkOJSFYnBvgdr5SF90H5Dw1jX/5tzxMW5lFTSEm08994wLZHHzxTfUmS2mUF/UlR2pUNlkXS8wgTVPVpjd7wJ+QunZPdj/VXmAnOIs1qH49YJYNbtTf4zey60QnlYLed6CQcnSrozd/+HoOoVpS8GkasnbQG4bmHAYOox8pCVEH5/XpUDuLX2+N84ioTvbbxxDUZP/cbobs37JnD1acJKQRjYl3X7RVkhlWWRg3PKIJhXhaN8QZIOoHA3sui1Ytkv0HVQZZ/OllFSIk9rfnMmMWjQj3cm+Hau2ENHBHhgK7c68bT2SHx 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)(346002)(396003)(376002)(136003)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(5660300002)(2906002)(7416002)(8936002)(8676002)(4326008)(38350700005)(36756003)(41300700001)(202311291699003)(86362001)(6512007)(52116002)(6506007)(478600001)(6486002)(83380400001)(38100700002)(110136005)(26005)(316002)(66946007)(66556008)(66476007)(54906003)(2616005)(107886003)(41533002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Bh754bFT3tcwFt7bQ3DB7ANz80Cx9L2MkIRX/7EY1TsEGaXfzwIru9148VSicJ3i0smHOxJFZJEhFyAU0bzKx5WZaPym/bTTVy79NRRlgYcWyMTQVkVIaButiKB3dHX02ucyhDk5rX9FQNfhoOySRWOJhIgZDDAOj9gbhsl3zUjXtFSgmk4W1SkUAhWRivwO6tG5MAW4D0O7/FZX8gvkPLPU15+rop6lYIffw+4/73IOIncswcBYz4fl2b7wSMnYO0iUkYL6W8rkEeNke2PDkEmplQBCIyENDpyqj64n3f24xmMsodZ/SashUIiUoaw3lFUYX3ecbQbK8oicIYB0lwWoccr6O/Hq1RA1R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OhB4CIKqbgap3qM6PST2icfyENxu4S7j5JXYXf+KxHAs5PAwAtcUnKk02917gMKzRlvKygT7Y0V1gUYe8HqsvhcNGS8IFye+2MXnZE35knlEzmf3LnjVrY3RSxVyaJne+WGZbpntkXERXamne3ZdR0P++xUN5F+6fAzq7xfkJBEDwTlVPRiI+oGA4GVF2LRKjfVuplNu+K0ddW8HMN1zUUIS8= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1437b47-5072-4c98-57d5-08dbf14a247e X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 02:14:54.5912 (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: 6vhj7aQGDmAslF2pQyzWsIxk6BskOgBJ/coqB/TvZzVOPEWpTBCAnG3Ajhl065qNt46eW4rUTlRt29bKCXxV8buUtdnzyclyy9fi1xiNllH36UMXi/GbK1ToSWzKlpA3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYVPR01MB10717 Linux Kernel has __of_device_is_available() / __of_device_is_fail(), these are checking if the status was "okay" / "ok" / "fail" / "fail-". Add more generic __of_device_is_status() function for these. Signed-off-by: Kuninori Morimoto Tested-by: Yusuke Goda Reviewed-by: Rob Herring Reviewed-by: Geert Uytterhoeven --- drivers/of/base.c | 57 ++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 8d93cb6ea9cd..3cb467a7e747 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -415,15 +415,8 @@ int of_machine_is_compatible(const char *compat) } EXPORT_SYMBOL(of_machine_is_compatible); -/** - * __of_device_is_available - check if a device is available for use - * - * @device: Node to check for availability, with locks already held - * - * Return: True if the status property is absent or set to "okay" or "ok", - * false otherwise - */ -static bool __of_device_is_available(const struct device_node *device) +static bool __of_device_is_status(const struct device_node *device, + const char * const*strings) { const char *status; int statlen; @@ -433,16 +426,45 @@ static bool __of_device_is_available(const struct device_node *device) status = __of_get_property(device, "status", &statlen); if (status == NULL) - return true; + return false; if (statlen > 0) { - if (!strcmp(status, "okay") || !strcmp(status, "ok")) - return true; + while (*strings) { + unsigned int len = strlen(*strings); + + if ((*strings)[len - 1] == '-') { + if (!strncmp(status, *strings, len)) + return true; + } else { + if (!strcmp(status, *strings)) + return true; + } + strings++; + } } return false; } +/** + * __of_device_is_available - check if a device is available for use + * + * @device: Node to check for availability, with locks already held + * + * Return: True if the status property is absent or set to "okay" or "ok", + * false otherwise + */ +static bool __of_device_is_available(const struct device_node *device) +{ + static const char * const ok[] = {"okay", "ok", NULL}; + + if (!device) + return false; + + return !__of_get_property(device, "status", NULL) || + __of_device_is_status(device, ok); +} + /** * of_device_is_available - check if a device is available for use * @@ -474,16 +496,9 @@ EXPORT_SYMBOL(of_device_is_available); */ static bool __of_device_is_fail(const struct device_node *device) { - const char *status; - - if (!device) - return false; - - status = __of_get_property(device, "status", NULL); - if (status == NULL) - return false; + static const char * const fail[] = {"fail", "fail-", NULL}; - return !strcmp(status, "fail") || !strncmp(status, "fail-", 5); + return __of_device_is_status(device, fail); } /** From patchwork Thu Nov 30 02:15:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13473966 X-Patchwork-Delegate: geert@linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="Tt/HbjtQ" Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2113.outbound.protection.outlook.com [40.107.113.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB9BD5E; Wed, 29 Nov 2023 18:15:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JXR7rxzlIbZaNifKOmrLWwO4jo4ONO4Ud08drzyM7mgbk3v1Lcdwd0om0r1AX6MpfK2q5vUFYm88Mu7pbAZrFggQ5R2Y9MEZOiI0dnpT+sfuS51ig+qRuYCX34DqkLr6oH1u6gR8iNwAfY43njnWTVahHrHNstT82u9PsEtOfitWHIXu00TFOjbvAPmVqygHFz6celVrIDTW744bB51kcSEsayzI0vDJ2fZ8RgV/MGZYo97dMeRK9RFFQ2r8aChIk/P51Dbj6XjBd3eUYsSyOK7RZz63owPpMuBhRHorru/elh10FUfY0dr7hnMx7XplLLRKfbLsR8SFdVEYBj7Jhg== 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=23BgSzNETCaiwng3und09gmFw66dLZ/Ypszr/Sqb+Tw=; b=bkpwUW4+V0kEqqW7aKEqxLoWt37szWzv4oiT2juc1WZFe8sdthN/8LxI+LiOjAvPpoAD38JYOkSsTND9TRKk+QrgweSX2SAzGzG18j05ovHUF6M5gGQSZ27zS8UQpD125f3iQVy5cZXO7Wozbc8JFFdL96/jf9C1brF0LZZi6FfZO9+XhVrK0d0pXUBjEnBVFY1e9qW/AznFhCma/nVOSl6GJfMnUPnt7UIA+w97VutLYVFX3IeEzZsW2BdWbosqvjyI3VWZ4Mlr7o3MD6WMKRq3oWkkfdm39N2SSIoPZug5/Ou6W8seOBX9qE7e10nJ99vYxud8/LMMeRYmKbbyHQ== 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=23BgSzNETCaiwng3und09gmFw66dLZ/Ypszr/Sqb+Tw=; b=Tt/HbjtQG0izvldBRzL4yiK39UhHkDQL3Rj9QfCDIelL9NqAShsZ44RgieGVshU/kupmJSyN0sZYqnOX9tcgyKQraBh44BRhTYGVCCqYpGlWloRhN0he5KpLs10SmIAbrelg5YFGnfXDAbg5TfgFPT2fd56wWqXRb/wPd+F30FY= 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 TYWPR01MB10743.jpnprd01.prod.outlook.com (2603:1096:400:2a7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.24; Thu, 30 Nov 2023 02:15:18 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::5732:673b:846c:ed92]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::5732:673b:846c:ed92%4]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 02:15:17 +0000 Message-ID: <87sf4o0yx6.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v3 2/4] of: add of_get_next_status_child() and makes more generic of_get_next User-Agent: Wanderlust/2.15.9 Emacs/27.1 Mule/6.0 To: Frank Rowand , Geert Uytterhoeven , Michael Turquette , Rob Herring , Stephen Boyd Cc: Rob Herring , devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Aymeric Aillet , Yusuke Goda In-Reply-To: <87v89k0yyj.wl-kuninori.morimoto.gx@renesas.com> References: <87v89k0yyj.wl-kuninori.morimoto.gx@renesas.com> Date: Thu, 30 Nov 2023 02:15:17 +0000 X-ClientProxiedBy: TYCP286CA0072.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:31a::20) 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_|TYWPR01MB10743:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d766909-8e2e-4935-7868-08dbf14a325b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UymrmUHn/KCCbRZXnpfc+FF93KScBiRqNK3k0Or9gYfyBRqsTzks4e2J+D3/VSIjShVpS3/yrGvyJb63vCimqJH6oc4265RDZYJlSmsYZZl5xWN0IgyQV2erWel3bH882jLsRB1iH9rOvtP1vjZKo4dJpHlfVwyz1m/WZ/RCZf0Mov0ILrTYPLO4HHPZrB7EYVqOLm8BN1K6TtQcfAaLgbWG9ON6TlfKfvJv+gcZjNTWdNaj0Dccpas5oqN+oFpsnA9WN8/w5MdWac7W4pnQihvpLmXyDWyMHdVUXc6IJVKvUa4t6qRzMiEU3k0GkyHGrCkyonjPegbzoB8CjUyKXrYN4lDV0FqWEAfp+mVHK+AxoMdhKi5eWvc2N+imme/R1bO3pN8NOT/QqfRQH5PVMeVHODEBJSg+0RE3jNE8LgV6WI4LK6uI5H9uIHyh9pO0yGvvV7Yk3NwpM5HePaMwZoZLwv7lAUJeeCoEjE2WrMRliWhVKQglpf2u7NGbfd7F06udc3dMKUgl3gKs6io+JMRaNMudREE0OdMagi0YjMgS0xmhdMeCBQUpBAVRyUoAwzteStMBUqIxkTlOcOuxiqjsrCR5mJJKLC0qcUxmpp30LWG3kYuViB2cMODFGln8BCPQ2/COghF29nUqWAXJfnd1GxqnvN0Cnefsy6c4Y6C9RgRpjfskWvYiw6ufbUwe 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)(346002)(136003)(396003)(39860400002)(366004)(376002)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(38350700005)(202311291699003)(66476007)(66946007)(54906003)(66556008)(38100700002)(86362001)(36756003)(83380400001)(6506007)(26005)(2616005)(6512007)(107886003)(52116002)(6486002)(2906002)(110136005)(316002)(478600001)(5660300002)(4326008)(8676002)(41300700001)(7416002)(8936002)(41533002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b/8PQkp9EHFTPWOP6J9Fd75nYyS2iojQrruyNxmKWcUbv3qs5z0ejyDVYKINms2shqPaEs1VwCWo6LEfYEcQ9HZreXsa6JgV6zAoI9O9z5MyORpqj0LO0+B/kXJDszHrTdrX04SOiG9Vfubkxpbz6B0WMRqTpPdy1LSyCdBRk7m3aHETGYyHdLD8e3YIOAeSZzBHS7s4CKO6kNYrfcCdzsDVN/G24lFMxnPEWkXVS1zmmyCQQFiM3LdzbNa4d/KkK5wFOkOhDuJRD0TblN8M1rpSaVN44GifWp7go5cLWZJAP093cVjRWwAS/l01ArgdyVI50ObOnU4g8UYTB/GzVHEPfFoPbQuf/ovqVM9MXvkdpGHNd5MhXcU96gET0mpoNxuOWUZZHsDaT1sZO5vSwv9SsxccBZh69P53Agi+0W18fv/EVCAtJ2dYOiphGjzjXHcSBdrzim8xCnS2QrPPmkftTFlgcK7LuC6qJcnLSg+BKmsHRyQCh5X8j0eeP7jgU5Esr8vTPQV+WKFsn5XGODSEfUQWRx+H0Qqa7249nvSzENspM+umQ9fH0gkon+gxKyl8efxf+FzRBmueH4/DLrExppEqwWgq5awYvNbX5SD3/FInm7SKYXqEArTq5pvYo3u7HlqjGmpqXnk4roZap7Z2G+2sg7sxPeHj6kudumXmdSlL22wS/yC7yRD92LHk+Ckhw6OnD25frDPIM0iAw8I4zyc5v+H065/oZ4MHqfTW7JTR9viwuvHRKMyNad0/6BpnL6NV+4sHV3Y5twQZ4IB4m/mKabHyyMvD4zPc6S7dV7joL3aZkg2LohmZd9nWqEqMO1vowUHhwVKAbc/+WmhNUKePE3baHbU6FnXtRJxyLdyDyHyxW2PzWA8Z1+mDr9XIvIFpKZVCJEFvKrpmwPDWQi5SBzZuKmg6iYZMxl/BC83FPuQK7e2iPKzJYlBgojwqei5lIp0KWQMk4utgDOoCKnSBGDYMSWByWexBxCp5GezOYTtJIuCiKylQ6NIu63Endaoz8FpBw7pcszml+AWM6Z2WG11p4XByNESiwZIT7DbNBC9jHioJxDGZtDnAW6eEWkMGVENB8cutgwTwxRski8J6TKlkF49EW02SRPVDMT2q83Fh073e42tXbgAsBYZE+I5p7QYcJYZz0irmqhit3SPaS9TEVLyWUW1LAUhZqNk+hXBXhjF2xS/012746TXeK52Iij+4BJoRbD1aVspd1m9M3ZpDcqb4iuODqwiRSMCXvC7dF29U5kLxUt/M9QDx2oM1smEB4n/mDPg0+RI8MqUbOtf2fe1e9INdamrb0tsqZvFIbXaoaYOlVSgelR5nieBImJ4lz1Zc6yQrXqAaIpG/KS1P+KrUJhSubYBu7+NU/o3oSCXHF79TNnVkuNd4/fn3/124uh/N41EAaOEe6S/6QvlAhxG/P6gTIDywFVqGALVizFEhN2oM5iBDC1I61JGxD+7DcNQIq91bLX7VTjseHQmjMyyCKRv4A6kLUyRtIU9u4TPZFtbgcw5ULekCNZBTnADycR+oeKG+nBNIDB20JEs0cw40ArKi48b0lt6K488llVCdb3YZ6Q8DbRb+c916mHZGaYVt5Y23F+M4Q88YyyG2wt3moUy3+eE= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d766909-8e2e-4935-7868-08dbf14a325b X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 02:15:17.8648 (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: JZeXeP46Dsb2zndHD0YGpH3lWKWWYdEXJhy4MW14CWLhGBxEX3M/6ECCAOWsyJC4cCAbsPuw5rMXmY6+bbLAaxph81A9I/TK+aH4C+Y9S8Yt1wdPZkhvpDLtvApDi7o2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWPR01MB10743 Linux Kernel has of_get_next_available_child(). Add more generic of_get_next_status_child() to enable to use same logic for other status. Signed-off-by: Kuninori Morimoto Tested-by: Yusuke Goda Reviewed-by: Rob Herring Reviewed-by: Geert Uytterhoeven --- drivers/of/base.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 3cb467a7e747..25c841a3882f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -612,16 +612,9 @@ struct device_node *of_get_next_child(const struct device_node *node, } EXPORT_SYMBOL(of_get_next_child); -/** - * of_get_next_available_child - Find the next available child node - * @node: parent node - * @prev: previous child of the parent node, or NULL to get first - * - * This function is like of_get_next_child(), except that it - * automatically skips any disabled nodes (i.e. status = "disabled"). - */ -struct device_node *of_get_next_available_child(const struct device_node *node, - struct device_node *prev) +static struct device_node *of_get_next_status_child(const struct device_node *node, + struct device_node *prev, + bool (*checker)(const struct device_node *)) { struct device_node *next; unsigned long flags; @@ -632,7 +625,7 @@ struct device_node *of_get_next_available_child(const struct device_node *node, raw_spin_lock_irqsave(&devtree_lock, flags); next = prev ? prev->sibling : node->child; for (; next; next = next->sibling) { - if (!__of_device_is_available(next)) + if (!checker(next)) continue; if (of_node_get(next)) break; @@ -641,6 +634,20 @@ struct device_node *of_get_next_available_child(const struct device_node *node, raw_spin_unlock_irqrestore(&devtree_lock, flags); return next; } + +/** + * of_get_next_available_child - Find the next available child node + * @node: parent node + * @prev: previous child of the parent node, or NULL to get first + * + * This function is like of_get_next_child(), except that it + * automatically skips any disabled nodes (i.e. status = "disabled"). + */ +struct device_node *of_get_next_available_child(const struct device_node *node, + struct device_node *prev) +{ + return of_get_next_status_child(node, prev, __of_device_is_available); +} EXPORT_SYMBOL(of_get_next_available_child); /** From patchwork Thu Nov 30 02:15:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13473967 X-Patchwork-Delegate: geert@linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="hQQM9pTE" Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2120.outbound.protection.outlook.com [40.107.113.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5939AD67; Wed, 29 Nov 2023 18:15:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UY+4TsQeuFpGVNrgK7L12p47P7rVagmfTzPEuQMo3Jxu5pTflOXAwBvsqHSNNQ35ALMiKfBJRVod0WjjBD77EL36scRCOncmGMEDFaHinaAE+B8VY8j4V0YRoGUDF1doHh1ZUdpB6v3wqvKFBLhKOyoZm1Z+bwDThFUe3+Nyi//C+kTzP9DDmHXgWUtH/3nGG23s3t2/beXNaKGmNfSJXMFhgMYb1LwcHD7LBvMfpqXr38PRTxUyGXqyeJ2ebHNbgUMg5md0mA+k+hWi+c8yOdkaJxNbJaGjvvg27reshBrIdi54CDzYXp7wZe13SR8qeLI+Bjv0hxC5goNVtuld3w== 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=ZI9xPtKOgr8eof7JFG0cBtJx1+MubVm25jpG7g5dWY0=; b=drwAB/OJHavz4EjM9GiNOcUP0yy5KaMWTVprQWLwjPtEsSrFLzVge24a0vOOEI2fQR7dWYARLibLUYVDvyfl0dKAcGF1G/68M8n+CpKtlhRtTrkI3P89hJc2+iW8ccJjvt/IGZe84Aq6qmuhRHF0hoJa/zvNVGj/GAQUvQkX5cuUJi5y9hPRhlCM40xsdhFSeDLgR9KbwpqrR+/apFL8uQVikLy6BYfmmEhLJZaw+bLesItmVpTOIiFU/in+ecD20Mha4WiFqZ22iURWr26WBpbKeVM53yfwJWFY16NvroHgzc2YhNe8Ypq1xH1A8D1Y8yWaDTGsoue+xEBQESCOcw== 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=ZI9xPtKOgr8eof7JFG0cBtJx1+MubVm25jpG7g5dWY0=; b=hQQM9pTEo4TeDpYyTys59RCtnyv3zI5DdT3tguyAfKFUgIqMFZwFDDKF6j5fynieLf/DeH9V92vGPkmGdicLwJGJ5xMHMQ/ryxtapm+a1R51mhdjgE2ERp/iCCTg1KwI819aaFBiA/hJi0YB8sH/urus/8HMWO1eGiAOhi0Iaa8= 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 TYWPR01MB10743.jpnprd01.prod.outlook.com (2603:1096:400:2a7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.24; Thu, 30 Nov 2023 02:15:25 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::5732:673b:846c:ed92]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::5732:673b:846c:ed92%4]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 02:15:25 +0000 Message-ID: <87r0k80ywy.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v3 3/4] of: add for_each_reserved_child_of_node() User-Agent: Wanderlust/2.15.9 Emacs/27.1 Mule/6.0 To: Frank Rowand , Geert Uytterhoeven , Michael Turquette , Rob Herring , Stephen Boyd Cc: Rob Herring , devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Aymeric Aillet , Yusuke Goda In-Reply-To: <87v89k0yyj.wl-kuninori.morimoto.gx@renesas.com> References: <87v89k0yyj.wl-kuninori.morimoto.gx@renesas.com> Date: Thu, 30 Nov 2023 02:15:25 +0000 X-ClientProxiedBy: TYWPR01CA0019.jpnprd01.prod.outlook.com (2603:1096:400:aa::6) 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_|TYWPR01MB10743:EE_ X-MS-Office365-Filtering-Correlation-Id: 95daab44-bf31-4b7f-606a-08dbf14a36fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hqF0qXWk8f25z64gCOvTufgeAYvAwNXHRN/qqNZae/20B3JviauynRko91qMi5WqlQTsVTJV4FlNUvrKXgGinZP1xiisg6l6p4emmIfzAHpNmxf6ykgzG5qfSC4MBkGOhfzVgokX7MLr2ZJR5PgnDyoWPLx0EqnkX05uM02hF4OZjT6W240Mc8Evh6te3iQXDfgMK73ffb9onZRc95THspQZ7I3tEqHXP9tPhvTyiH3J0PhOzG4vuRBmiTBQ+5OMMsqOTVLJ0IBj1SaoNh+8EZ5dlhszqBQG0F4PB0iS7XC+nKlzIDyyNt0uxdQNA9N99HANOk6V8GLg+8foXlXgj1PMmVSV8Ez1BURRc6ksYeSr6lG8e6m7U8SdvUuHwpEW6kklJ4cjtkfaPGcbBnj4Ic/pYvupbJaniSbkSv50A60W63jO+UYRbmMSJGDWSzxqWwwxc83J8EEELnH2vhZl/5BSOg2md8YUKStEecMhPFv4ekpgLW8lsT6huJ2UfImL6FOJGbZM8fg1NLn2MaLhwhLtDJCwe+w7La2q4yJzl1mH6I3z1zz1laaLWmZuVBob/q5JbiRcDLiX/AhWYR54QxGlXs4N03p5PeGldWeQ1t4V58gvwK3HkGwojatWR1CiDo0iQHgxgZVF5AmJ0h6uM+CpG4BcInrxZ1o7Ej7hcaA= 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)(346002)(136003)(396003)(39860400002)(366004)(376002)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(38350700005)(202311291699003)(66476007)(66946007)(54906003)(66556008)(38100700002)(86362001)(36756003)(83380400001)(6506007)(26005)(2616005)(6512007)(107886003)(52116002)(6486002)(2906002)(110136005)(316002)(478600001)(5660300002)(4326008)(8676002)(41300700001)(7416002)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Need05WfrXLdMNPnl9z2zmzeOlxYqpM2FHxHPZ0Bb79juayxYJx+V+dGfKsYxecQ+StqKtj511DxSWeQvtBoEbEZcpb4KY90T2k+PW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3feGybrEmkb3kfSeqozjcwh817aWdtpWNTBLfWClO2eV9ARLbtjmpS2nwpAInLW2EiiGCrpuaT7kyAkEBL/BmkV2ee0Me1TSXG98sNH827clH5HTqXIFC14JdL9zg/nkTDM9fqwH6mDmytAymsZRJodm4bF7Sw5sAC/fU2gkCIsASomMO1yck+IDPNcw+XbPFIfz1wz+1HFnV01htWTDMQBHusac3i7jqfc+ThhNWPHU1GNwcJMRx+Dk1C0uuCHIfCbgvp5G3oWuAe+FA4Lvq9egfV1pq8soCvxEPowZp7GkZc7QFUErRQQydk8eeguF1ObkiyVP+2Gr0MyTqS+uOhp7vQoiTVrSTlzjhdprAU5JEWvKZY1vQCmbTQyl6CanZEQcaCDZEiEIMa5hibY1wDV6Nanv/O2cRuBm8wIAb6S511l/DkyXKntKGlx3hOtmOo/gfTCkdQI2KYMGclRAQ= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95daab44-bf31-4b7f-606a-08dbf14a36fa X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 02:15:25.6146 (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: 6417LTeKS/SC2GAlZ+GH/OKQigF81WoM7ucXr3kKyPANDHLcEi8Tf6qDsRAvUH5HK+sHO6mUEIgsiwb8RL3jWrn5jvnv6rMlNNKeQckTtlVs5NTJsUiofOmDHiGlH5mb X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWPR01MB10743 We would like to use for_each loop for status = "reserved" nodes. Add for_each_reserved_child_of_node() for it. Signed-off-by: Kuninori Morimoto Tested-by: Yusuke Goda Reviewed-by: Geert Uytterhoeven --- drivers/of/base.c | 29 +++++++++++++++++++++++++++++ include/linux/of.h | 11 +++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 25c841a3882f..b1ecfcfbb90f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -465,6 +465,20 @@ static bool __of_device_is_available(const struct device_node *device) __of_device_is_status(device, ok); } +/** + * __of_device_is_reserved - check if a device is reserved + * + * @device: Node to check for availability, with locks already held + * + * Return: True if the status property is set to "reserved", false otherwise + */ +static bool __of_device_is_reserved(const struct device_node *device) +{ + static const char * const reserved[] = {"reserved", NULL}; + + return __of_device_is_status(device, reserved); +} + /** * of_device_is_available - check if a device is available for use * @@ -650,6 +664,21 @@ struct device_node *of_get_next_available_child(const struct device_node *node, } EXPORT_SYMBOL(of_get_next_available_child); +/** + * of_get_next_reserved_child - Find the next reserved child node + * @node: parent node + * @prev: previous child of the parent node, or NULL to get first + * + * This function is like of_get_next_child(), except that it + * automatically skips any disabled nodes (i.e. status = "disabled"). + */ +struct device_node *of_get_next_reserved_child(const struct device_node *node, + struct device_node *prev) +{ + return of_get_next_status_child(node, prev, __of_device_is_reserved); +} +EXPORT_SYMBOL(of_get_next_reserved_child); + /** * of_get_next_cpu_node - Iterate on cpu nodes * @prev: previous child of the /cpus node, or NULL to get first diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..331e05918f11 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -294,6 +294,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev); extern struct device_node *of_get_next_available_child( const struct device_node *node, struct device_node *prev); +extern struct device_node *of_get_next_reserved_child( + const struct device_node *node, struct device_node *prev); extern struct device_node *of_get_compatible_child(const struct device_node *parent, const char *compatible); @@ -541,6 +543,12 @@ static inline struct device_node *of_get_next_available_child( return NULL; } +static inline struct device_node *of_get_next_reserved_child( + const struct device_node *node, struct device_node *prev) +{ + return NULL; +} + static inline struct device_node *of_find_node_with_property( struct device_node *from, const char *prop_name) { @@ -1431,6 +1439,9 @@ static inline int of_property_read_s32(const struct device_node *np, #define for_each_available_child_of_node(parent, child) \ for (child = of_get_next_available_child(parent, NULL); child != NULL; \ child = of_get_next_available_child(parent, child)) +#define for_each_reserved_child_of_node(parent, child) \ + for (child = of_get_next_reserved_child(parent, NULL); child != NULL; \ + child = of_get_next_reserved_child(parent, child)) #define for_each_of_cpu_node(cpu) \ for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \ From patchwork Thu Nov 30 02:15:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13473968 X-Patchwork-Delegate: geert@linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="fP9IxvuL" Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2130.outbound.protection.outlook.com [40.107.113.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A5ACD5E; Wed, 29 Nov 2023 18:15:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FY4PEA2QMMrodVC0OZIwQyIC3T//ZK8/BbxUPR8sbY9iwde/3iv2Y8LTffFmLkszr2oeoFfjZQbsE6uAWEt8iNzK/cUVphyhuEpQd3tfG2HmOZHSM+0LLrnCMSvDSpOr7vxGWFXEKUOjV7xhS+yFM8N9sjP/6Q+nMtHYa/24GavRXWnLw7TanSue+N1DjJggPnCVFsKyHHYfeKShPqMoJcgqmm3xwqzaeqbJ0nqgKL50oX1I8yaeqk/gOCV3IKbhXRFABps586oobbXC4GRnSkLTGVDphd5duEda7XZHZt9c5tVA4kHvGpWSEgtLtbl8gbgMjDCXyR4URHv518m0lg== 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=XTWnMTnCxeH1ufjME++NKJA16TJrDDuNLjYP9pYIRzE=; b=mYiTew5uJG/pdot0sm4hzK4xvE8177FXDHvrD94XwcXk4MRSI3VGnHq0lKPU3HpeOgBGdYYjvnHXGZmw0xt10iU/24/QB+Q4MCO6443JXYfGtXiONtcZ1be3gDk6ppXcZADqYDIIX2AP0/avgChBSh5xuhLesrOszVaf7uThoQe3i3fkJ74GHeqP+Vp6CplFEVAdrmrjdGD+aE2cdJKocYC4kU5Vh/jeokkTvtsoaCSjZWSHieCPBEepVCXyuJfIXNKVazyKk6rDjtLbwBMKQfHMSE1PDbkaDuATCsjyO9pRTarYATHrbU1KBueqUZBajaGguYCqDZLKrpAbO7yAEA== 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=XTWnMTnCxeH1ufjME++NKJA16TJrDDuNLjYP9pYIRzE=; b=fP9IxvuLxxFdANlqEUUo8q0mqOwXg6W1BkI9gUdD8krQrovkoOcAPWJoiB3UyCVpndj73t1yDgmTlg7JkuqRxuqTgMwL6TEXFldXr3ntb5PPLgIp0m+lRdr51PUO32F5p4ElJyHVeCv0cT9INf9bg6RiiSlkDA1UnMaSA2qVMsI= 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 TYWPR01MB10743.jpnprd01.prod.outlook.com (2603:1096:400:2a7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.24; Thu, 30 Nov 2023 02:15:32 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::5732:673b:846c:ed92]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::5732:673b:846c:ed92%4]) with mapi id 15.20.7046.015; Thu, 30 Nov 2023 02:15:32 +0000 Message-ID: <87plzs0ywr.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v3 4/4] drivers: clk: renesas: ignore all clocks which is assinged to non Linux system User-Agent: Wanderlust/2.15.9 Emacs/27.1 Mule/6.0 To: Frank Rowand , Geert Uytterhoeven , Michael Turquette , Rob Herring , Stephen Boyd Cc: Rob Herring , devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Aymeric Aillet , Yusuke Goda In-Reply-To: <87v89k0yyj.wl-kuninori.morimoto.gx@renesas.com> References: <87v89k0yyj.wl-kuninori.morimoto.gx@renesas.com> Date: Thu, 30 Nov 2023 02:15:32 +0000 X-ClientProxiedBy: TY2PR02CA0035.apcprd02.prod.outlook.com (2603:1096:404:a6::23) 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_|TYWPR01MB10743:EE_ X-MS-Office365-Filtering-Correlation-Id: fdb729e6-66de-44a8-db18-08dbf14a3b3c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: P/mJL3NbMuvbXWv4whPUiO9WVUcB5awHE2lK/c0d2VCCtQHwiwsjve9uwVt0W1h9pxvbazz0pFSbUSacXrzULspnLiepmE507Qo5fvb7yOLrgoxt3q0L3Kbn9PwOlweJxZxZUtrfIRfwDdRvMlEbJL2NecKC4poec81vOd/gdogVbGYkYXifyfbE9wlk3NeDW+lauoMQdMmcVsmWfSwG9ZbB44mzZ3eZTf/PVG3SfIevpeVsqmHWF0fVQb8pBxj7UGB7NYp3B3t63yD+bYUc9vrUnaOUzBfQErSZLbCaEGXX7EZlKd8uCdlaUgtZcNErXn3adiZHBUHfidCfUi/eLLBMlp/nXnfaV+PBj856gx4ghVYwsRFR4idkjHmvzEbvre2YMqccfS84rVfH4aXXIcZ1Nq8gkxiXrWOdLTSsnSyLNAqqvkioncmPhZjv+3R11A4gSXvgY0qeZnCbkXxY5zMCY/hq9lHKY57TBqbJILKRYdkIV2Hvu6YeFkEOQmd8frDMNooYpAaT+Vb62xjVNy3BKMpRJhKfbzMsOwm5XPBqTw/ZqFJNCKEWkh98znm+P/Mva4rcLzevCwMLJQNhljphA52FLTNKqQPfYUYirD9RquCr77dHUfUOjcEfzRqqPZLL7NCK2I9EfpF67FwNFcozo6LI/ZCBbN8f3gZUQdM= 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)(346002)(136003)(396003)(39860400002)(366004)(376002)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(38350700005)(202311291699003)(66476007)(66946007)(54906003)(66556008)(38100700002)(86362001)(36756003)(83380400001)(6506007)(26005)(2616005)(6512007)(107886003)(52116002)(6486002)(2906002)(966005)(110136005)(316002)(478600001)(5660300002)(4326008)(8676002)(41300700001)(7416002)(8936002)(21314003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S3Q8ZsVn6lFGf8g9YvFooakiIo6LatKicvEN+p2wgp8G6Ox7y6+MMxYYrfX37TSfNPE4QGsOFT4VpZuB2jREWEBrEvkXXQS/wZWzFIqJcJzcYeW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7mVo2+LyopE5+1i/Jdi403lZSmeEJpJ7paT4XAoqcXH8d+1TXkVn9beFkcXH1TRGbM6rp5z1e+jiXjye787ilYuVZI0ebWYYKGnG8XwAvnU/LaWvpjOrtcxDocqVEGikiVnDUnB6YRstNVfFbuPIYBp7gI7V/RFUAZR0C0hBMUT24GPeJ3kThmS1/GMHELtWW4WD41puuJkK4GxtikDoFm3LyCa+dOm43/U8O5/K40CwnDJW6Kgvjb54+4ZVC4xzd4RuiC9aAG6TymOxFCcB6R/Wd3tNZHBoKzAc+v42b0x51Njfwt5hwlgxQN55jR9pzcvFRJjH3Ckb40WQhr+FoRbDYVO0bx+1PTRN7l9MEP+nNI+qUA4+RJA/0ljDWj9qf0qlkkpfokiLVbdbFS4qxe67cU3+rHUKBgPlWY13dKSpuOKr+Z35a/+9QAOlcAf2ltkG7MQMe0XXNgzO+al4QEQ= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: fdb729e6-66de-44a8-db18-08dbf14a3b3c X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 02:15:32.8758 (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: elX8ogcFAcSnPoqkrDRT0/UvHfwbYpTY2yvcxMU9Mcm8mZ6TJSnswBhw+sQwJ4Zv/ldLCwF1ay3qfBh5pISuxQkvAlwImbId9wIQmjKWPuK/xHI7UiteTw8ix8uurFTB X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYWPR01MB10743 Some board might use Linux and another OS in the same time. In such case, current Linux will stop necessary module clock when booting which is not used on Linux side, but is used on another OS side. To avoid such situation, renesas-cpg-mssr try to find status = "reserved" devices (A), and add CLK_IGNORE_UNUSED flag to its <&cgp CPG_MOD xxx> clock (B). Table 2.4: Values for status property https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4/devicetree-specification-v0.4.pdf "reserved" Indicates that the device is operational, but should not be used. Typically this is used for devices that are controlled by another software component, such as platform firmware. ex) scif5: serial@e6f30000 { ... (B) clocks = <&cpg CPG_MOD 202>, <&cpg CPG_CORE R8A7795_CLK_S3D1>, <&scif_clk>; ... (A) status = "reserved"; }; Cc: Aymeric Aillet Signed-off-by: Kuninori Morimoto Tested-by: Yusuke Goda --- drivers/clk/renesas/renesas-cpg-mssr.c | 118 +++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 9 deletions(-) diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c index cb80d1bf6c7c..26098b7f4323 100644 --- a/drivers/clk/renesas/renesas-cpg-mssr.c +++ b/drivers/clk/renesas/renesas-cpg-mssr.c @@ -142,6 +142,8 @@ static const u16 srstclr_for_gen4[] = { * @reset_clear_regs: Pointer to reset clearing registers array * @smstpcr_saved: [].mask: Mask of SMSTPCR[] bits under our control * [].val: Saved values of SMSTPCR[] + * @reserved_ids: Temporary used, reserved id list + * @num_reserved_ids: Temporary used, number of reserved id list * @clks: Array containing all Core and Module Clocks */ struct cpg_mssr_priv { @@ -168,6 +170,9 @@ struct cpg_mssr_priv { u32 val; } smstpcr_saved[ARRAY_SIZE(mstpsr_for_gen4)]; + unsigned int *reserved_ids; + unsigned int num_reserved_ids; + struct clk *clks[]; }; @@ -453,6 +458,19 @@ static void __init cpg_mssr_register_mod_clk(const struct mssr_mod_clk *mod, break; } + /* + * Ignore reserved device. + * see + * cpg_mssr_reserved_init() + */ + for (i = 0; i < priv->num_reserved_ids; i++) { + if (id == priv->reserved_ids[i]) { + dev_info(dev, "Ignore Linux non-assigned mod (%s)\n", mod->name); + init.flags |= CLK_IGNORE_UNUSED; + break; + } + } + clk = clk_register(NULL, &clock->hw); if (IS_ERR(clk)) goto fail; @@ -949,6 +967,75 @@ static const struct dev_pm_ops cpg_mssr_pm = { #define DEV_PM_OPS NULL #endif /* CONFIG_PM_SLEEP && CONFIG_ARM_PSCI_FW */ +static void __init cpg_mssr_reserved_exit(struct cpg_mssr_priv *priv) +{ + kfree(priv->reserved_ids); +} + +static int __init cpg_mssr_reserved_init(struct cpg_mssr_priv *priv, + const struct cpg_mssr_info *info) +{ + struct device_node *root = of_find_node_by_path("/soc"); + struct device_node *node = NULL; + struct of_phandle_args clkspec; + unsigned int *ids = NULL; + unsigned int num = 0; + + /* + * Because cpg_mssr_info has .num_hw_mod_clks which indicates number of all Module Clocks, + * and clk_disable_unused() will disable all unused clocks, the device which is assigned to + * non-Linux system will be disabled when Linux was booted. + * + * To avoid such situation, renesas-cpg-mssr assumes the device which has + * status = "reserved" is assigned to non-Linux system, and add CLK_IGNORE_UNUSED flag + * to its clocks if it was CPG_MOD. + * see also + * cpg_mssr_register_mod_clk() + * + * scif5: serial@e6f30000 { + * ... + * => clocks = <&cpg CPG_MOD 202>, + * <&cpg CPG_CORE R8A7795_CLK_S3D1>, + * <&scif_clk>; + * ... + * status = "reserved"; + * }; + */ + for_each_reserved_child_of_node(root, node) { + unsigned int i = 0; + + while (!of_parse_phandle_with_args(node, "clocks", "#clock-cells", i++, &clkspec)) { + + of_node_put(clkspec.np); + + if (clkspec.np == priv->dev->of_node && + clkspec.args[0] == CPG_MOD) { + + ids = krealloc_array(ids, (num + 1), sizeof(*ids), GFP_KERNEL); + if (!ids) + return -ENOMEM; + + ids[num] = info->num_total_core_clks + + MOD_CLK_PACK(clkspec.args[1]); + + num++; + } + } + } + + priv->num_reserved_ids = num; + priv->reserved_ids = ids; + + return 0; +} + +static void __init cpg_mssr_common_exit(struct cpg_mssr_priv *priv) +{ + if (priv->base) + iounmap(priv->base); + kfree(priv); +} + static int __init cpg_mssr_common_init(struct device *dev, struct device_node *np, const struct cpg_mssr_info *info) @@ -1012,9 +1099,7 @@ static int __init cpg_mssr_common_init(struct device *dev, return 0; out_err: - if (priv->base) - iounmap(priv->base); - kfree(priv); + cpg_mssr_common_exit(priv); return error; } @@ -1029,6 +1114,10 @@ void __init cpg_mssr_early_init(struct device_node *np, if (error) return; + error = cpg_mssr_reserved_init(cpg_mssr_priv, info); + if (error) + goto err; + for (i = 0; i < info->num_early_core_clks; i++) cpg_mssr_register_core_clk(&info->early_core_clks[i], info, cpg_mssr_priv); @@ -1037,6 +1126,12 @@ void __init cpg_mssr_early_init(struct device_node *np, cpg_mssr_register_mod_clk(&info->early_mod_clks[i], info, cpg_mssr_priv); + cpg_mssr_reserved_exit(cpg_mssr_priv); + + return; + +err: + cpg_mssr_common_exit(cpg_mssr_priv); } static int __init cpg_mssr_probe(struct platform_device *pdev) @@ -1060,6 +1155,10 @@ static int __init cpg_mssr_probe(struct platform_device *pdev) priv->dev = dev; dev_set_drvdata(dev, priv); + error = cpg_mssr_reserved_init(priv, info); + if (error) + return error; + for (i = 0; i < info->num_core_clks; i++) cpg_mssr_register_core_clk(&info->core_clks[i], info, priv); @@ -1070,22 +1169,23 @@ static int __init cpg_mssr_probe(struct platform_device *pdev) cpg_mssr_del_clk_provider, np); if (error) - return error; + goto reserve_err; error = cpg_mssr_add_clk_domain(dev, info->core_pm_clks, info->num_core_pm_clks); if (error) - return error; + goto reserve_err; /* Reset Controller not supported for Standby Control SoCs */ if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) - return 0; + goto reserve_err; error = cpg_mssr_reset_controller_register(priv); - if (error) - return error; - return 0; +reserve_err: + cpg_mssr_reserved_exit(priv); + + return error; } static struct platform_driver cpg_mssr_driver = {