From patchwork Mon Dec 11 03:03:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13486592 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="MCN53NVg" Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2098.outbound.protection.outlook.com [40.107.113.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DB8DCE; Sun, 10 Dec 2023 19:03:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C8f9rIzSa9Q58dgOabOb+/+onPE+uUwn0wDf3zP3lGuQKlFYwGwv5bPyJKd86zhnj+bbvgxi6G6WAfzgz9tf5V9v/outbdMqIzvR1w+PV3oQtUJRGvRGcvLvpvb79yhLIPYOzPsY1y0RV35gUj60ukQKb6SaiVTs8YanqtDVtV2XbLDCTaZkgZ6AH1zMVORxdUcCP4iPdDhVPUrNP56zhVZ/h8609lcxymeTEpy3mUyT1CL9w5t11OQo9ReEnXgtb/IE1rTwmRnViK3BjZfjMkxeGaC9nRaP6iKPv9Nv7C/P5GzVXmSsbTJlV85vTUoKLTiFe+WnpEcJNfpKPNwMwg== 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=1XQHWRTVIn3IR/BVQKSU7VmzH27RAnJGrU21XEgwWMw=; b=OqDzuFV3yOhvlbAbPb6Dm3uSIVngQy/1zjvqkTfTxB+NSNxNNJQ1Tg7dAB5rtdRJIA85rOvlmRMpfA5YmwW9Zwcro8ZZrEmJGXufX4Y2fJZW1/mQYk5et9VpvQUB3XERxybYh/h8GfPBBNixnK/OFO+0R0wBYawNBcEvI/b1OWFeak7M/Sa+2BGoBI0bWyyjKV++SItUgfRdEotte0sswjoV6Ev6JihqigbNMocgjE5d/7rdr8S+S5PWRMIvqWVYPE6EK6TzvCKyYFr9C6Y34CCMfH78tKjG/rMOY/LgP2Ww4WzC7hj+kQQJOZDvdWMXk5QqjiQBPbHvbdkxevA8jQ== 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=1XQHWRTVIn3IR/BVQKSU7VmzH27RAnJGrU21XEgwWMw=; b=MCN53NVgfevxdrI1UICVc9IR+6QQ3F0gAkHXB4gkxTLQfWOfqRRc6q2rxEswoYk7pY7y+SjEc3bY2l2RNoMZy9FXGQ5wHOsa8uj9pFP8F+VFfbUNxRATbVdYY1fvNuAlATVx1R/L8LmbPq5m1CuJD86OvIfWDyrbgUchWjbDtig= 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 TYCPR01MB11269.jpnprd01.prod.outlook.com (2603:1096:400:3c0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.21; Mon, 11 Dec 2023 03:03:07 +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.7091.020; Mon, 11 Dec 2023 03:03:07 +0000 Message-ID: <87v895o2z8.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v4 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: <87wmtlo2zs.wl-kuninori.morimoto.gx@renesas.com> References: <87wmtlo2zs.wl-kuninori.morimoto.gx@renesas.com> Date: Mon, 11 Dec 2023 03:03:07 +0000 X-ClientProxiedBy: TYCP286CA0008.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:26c::15) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|TYCPR01MB11269:EE_ X-MS-Office365-Filtering-Correlation-Id: a058cbbb-ed54-4510-14e7-08dbf9f5b38a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ep02xroLNWZ5NGelCZwJxaf7ovTSlEYB+YCxtxpEllv7LfbFl+hC/gVvzArEXxnipoeseJMLLzmmVvYg/Q6M1W1S0TdVlSvk8PzNWy8ILAlUTrv+3NXeLd5C6JaPDg0EzfHyc77JgabPDEFMIbERUfsUsgVZ4bPeuHWh5LBhIbQYlMSSREaU34G4IErHGKFB7yQYCi/sb7+O1FnQzJZEaL3jddeE0S7Fol0kqGnCl5vMzqryNl17ly5D/0dTRnq715tLDYeTzxidaC1OXTL4gbgxaFJaatJpsnq4AUhxp9PiFutRPJARGjwc+jEndt01Hcj89EoJu0NLpd6WelCvwNDqsTkrTi7GAKZ6IqeFa+RfusOYXFJbMakx758XYo4BRERvhsCDusmtgiGaf668XTB2sWQPnaJ3sW9Y1/d40b7JXEcSMJQx5Q+zwxryEy24kKOsAZAOkel3wfLS+jSKelIm8wAG9H8fr8ou6oeKRVOojaZ7dGNgxD2gSsnwu/kH1QZ5Q03Hd6oXzPuOehazt98M5H8TAcWlsNvAHfRacwMyVcNhbB+pnN8j3P6hd1Yo7b/tm546yI6zMBufSUJ+GacZe+/aYCsJBb+kYUnERpLY+keLMp2Zomh1752HlHVJa2NGW6X/8PQe6SA0uGmj/w== 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)(396003)(136003)(376002)(346002)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(6512007)(6506007)(5660300002)(26005)(2616005)(107886003)(36756003)(7416002)(54906003)(66476007)(66556008)(66946007)(6486002)(2906002)(83380400001)(41300700001)(38350700005)(478600001)(86362001)(8676002)(8936002)(4326008)(52116002)(110136005)(316002)(38100700002)(41533002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Dg2AYBC2UkTk62xJVSvg46ganfTFJfdnjRMedTXWx76p0dHQgkyUonVBggWkgGczXmMjvFgYUB3eO0KOxGrihNAOcbNQx9LLKGduV9C8CQqYeqiUJlryyhdeby/VX/JwO2b+nB1jc+gFG6caO7gyRFqAkIn7i4knCCpf91DVArwa+rm3YuqdpZFkXpGEHnfUNgq/AFYZzc0bU8L/5zMBVghucez3IEo/LOSGCBveqP+wxzcYDvOvTr9aZxC0nYgbbR3LVdjbKrRvcM8fLJxBjK+vJlX8W1fh9z4vdUZwQORnDbV313UIe2WP4vw0guMkRUXVxOFxkolbbc5FQgkT+SnHYLhRiud5qne4D2+1jH2nJ0oHMSXT8NZZCorwSK+5gVubNNdHm8xSP4lSjxJ/P1HkzbsOMvlioA3Ked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+QQjVbK/GQ86h9s6EgAZQ/8jTNw4c5BX4awi9V0sWj7ByzMu9Fhu2BIe8/2W+IHoDpMMJRP6Mn0Tec/PSYcRM4W1PE7udfKXxXmaRFJUZd4anb6gOtimWJNKZqJQ5WJJieXnuC5s4Xk= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: a058cbbb-ed54-4510-14e7-08dbf9f5b38a X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 03:03:07.8447 (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: hsZbqcKOff0aCf/Dmywa5myLRLrhzzhexqhhOgOjnkTf0nxugxs9NywcnsobpPF7eve747WMcn7VfLitYa4/jl7BpMZP+6F+dCSQRIMU/tSOAhN7Q67Tsl6rPOdPKLnB X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCPR01MB11269 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 Mon Dec 11 03:03:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13486593 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="YIx1Ykod" Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2090.outbound.protection.outlook.com [40.107.113.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77370CE; Sun, 10 Dec 2023 19:03:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JiuqkiFgC53ir1KLH3wy3NMZ4nyMGi6MbZE5hho2JMiSQo/cOvAmbmRoM33J63ry5iUp2XFsap/V2GFwErATBINmcsLeuTh9BclVtlZBu7jTRb2lptc9+5SP5TvmmmxNbKk0RmGHf+Eg4pSuWnUBf7nKnKx5PeMB4AlD08mTYUZEaB1OCsdrvakG7lXP5QteEmrOL038NUKNxYZ1okyYPzg0AXz5MddjU31JTiZKc4r22QasUsdpe9ehjY3bhf8KBugdOc9MzG8KLMX92Ft9nNwyJx43lwA1Z+jKpfavbdyK/LgS9VVs1yujgGarUDW3XbKuzXnzq8HLkpIKF+0jOA== 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=RgUkUYtygoxiqzMiBVycBlhtPag3tFrU4SqtSRyEFyI=; b=E34D5280JIHs71lgEWIdWkZ9YlmvzrXQQL0whSCY1sTrsqUuTn1Ztewn63gNyfSMaEJF+6wzG3iT4BY1q5KkTW9vkXRD+nRcfQ3G4+/2YVT0gjg9rLSQy/joYyZfYjW4xrvGqVp2gfEZpfs3VDggQJm1iL18hdf2NtW2MQGo0viA9uRzL2J52zDPav+cBQdaIPQjcgahtbFAgLGYwyk3RL2iNgBN6qqMm/qpqxxxSexRy3MoqDiN0lD7btuWr7/Cs5CI4FXmw/hKsd7iUfDcKMs8wrKvnMFeiWUIs85SSMUED2hq6EPbzGHGN58eA6xHReyRYhqLJsYEiIQGaCyXqA== 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=RgUkUYtygoxiqzMiBVycBlhtPag3tFrU4SqtSRyEFyI=; b=YIx1YkodZ66RJ83czVEFP+VhadOXwfHD7zwQ3pmbt7u1XX8uo91dSrTuRC/cOYSg63j7MCY290AHDsZLRquU3ARhAp4EcOdBiYNYpB0ubH6M1QKBtG/xzHnR0BhPodN89WOW9AP2VEk2qVA+5fkrCByVxHd59c62CpRVFNijFKk= 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 TYCPR01MB11269.jpnprd01.prod.outlook.com (2603:1096:400:3c0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.21; Mon, 11 Dec 2023 03:03:13 +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.7091.020; Mon, 11 Dec 2023 03:03:13 +0000 Message-ID: <87ttopo2z2.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v4 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: <87wmtlo2zs.wl-kuninori.morimoto.gx@renesas.com> References: <87wmtlo2zs.wl-kuninori.morimoto.gx@renesas.com> Date: Mon, 11 Dec 2023 03:03:13 +0000 X-ClientProxiedBy: TYCPR01CA0122.jpnprd01.prod.outlook.com (2603:1096:400:26d::11) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|TYCPR01MB11269:EE_ X-MS-Office365-Filtering-Correlation-Id: 7136e5bd-c198-4154-3ec6-08dbf9f5b6e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5/vK3RGKRGh9+VUq/6lkABbJh72pAs+uB+EsYvuVyEmWP80PIlDY1pmLbKlnJ9qcYIH0FLZGEeSpJozb0G2x6u62FZWmI+//U1PCSDGNi5RyksA4DLY6VdZqJDJdsT4/NQoMK4sVDfJnpjjEsJcbVjVElxnMBarRsyqAYiqrLinELoESWZwAmRYMFpYLELR7rZ1rnZFwCUUvK4MGdRLtBQ4QaFDDYuT5EZ8Fun1C8Rv0VIn6rcKEWV6ggYYy5OocityxeiT1SRM8JUsKf/YrbsjiCVQqdlMEWqNxWJUpxt9WNSEQHpWXiVHtOfp6wEjM47W3ELP5KryFUE6n/UdkLCg6zJcBdOwFRwwCaqhH4ln42F7qa/9mKfiaAIA6IOTFh0v05NDLJrt4b7cAKct2uYOvCbChL00r92R/Jwf7ngzJgHrD2JPYgEueB58TxTD7WWhhnvMRkSpQRKPddIT9WzV8NhdwICDn7BEuNWRqdYCmQyVQ9WBDjWyKB6U+a4rtnGPLjhXbAQbTKpYavy3gZNkOQsPNxCHf22OdT+MTPDb+VkiChiEJ0cq8jbJC7Q7/1KYwN0dU7vHNkAKMPnmrzz4cbBSAOyaLD6w/QZVG+h2G411PZGO8A9ipaRR+QZWdC0wnyjgYxXFMa/GT0ibwOw== 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)(396003)(136003)(376002)(346002)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(6512007)(6506007)(5660300002)(26005)(2616005)(107886003)(36756003)(7416002)(54906003)(66476007)(66556008)(66946007)(6486002)(2906002)(83380400001)(41300700001)(38350700005)(478600001)(86362001)(8676002)(8936002)(4326008)(52116002)(110136005)(316002)(38100700002)(41533002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FvGi/+xvX+oANquMatNSLCoeOodglxwPF4BmlHq9pIlKuxd3VwNj14ubvcPeul+Q4QL2q/pO7EOlMgf9dIkM30hCU0mMaLSiY+zaPU+ik3iuSkyA44c2zJ6KVARs2G9Q7npGbsOh8FtoRkms1Y1X1MTYsK4CHQrHDKvANh8hSswx8L+ab0goOJwEQHKVvaWTeNxIg+NfJk8Bm77MQQatiM81/4UC8Ryy/Erp4+fbRFI1kiLTUFipanxfAUu5/YSkP1Ok65NJWwr9gss45AQIIgnugrsB6YjUJf2cUm2rgtSNEAYgY4XuM3gQvE1zxnq5hTpc7SxaIU61+4CDX4Ai0NRFWa2SbafxoighpifvMT9C3Ye2zjKuzqB76z6yHF8oP1Y99DXil6n/XNhx2CSx5hYAVtGY3rMwhmlULXq1WB+0ziSXmzKNi+i1mmH0mhWToVaNee13b0I0pzMVE8UdrjHLG/C/y7FQcRRrKFV32Q0zD0r8+USM+BuFywdoSa1ps5sl9yBwBuhSiQHHToq0EYI7hk3ako8kZWPDz5ZhSzCUskNb8A+LfcOdpA4z637PQs59+cNCC4/zoEDO2Q04iJR5YOoI4l4poz47QP6k4jyZINVMzpL36fsn+9Sd/2+z+vrbH0CcDvxu3phW/Rmfgf/x++w6CwmRgwSsc3pyetrVrGyAxM/0QwmW4HJ29dTMNZugGzpEtJOszYG9Sewhr4yMWfw1tEAK+VYATsCAfqouHxiPMSHIjG42qoCJfsEOgpIOzLH/qT1TQIXovpwI6AeIyFMFefsm0pX+LoZkAkc8p5uLDG77kCbmbCxBky5+g8/Eb12Z2memMTo/pxEH9IHV6UtNQGIiYg+iNyMQmQav4ZJf7k4GwUtlgBoP4woMm1yx9HCivuLmGlWysvMIgM5nsIHPUnqdf+1zs7pAteJ8BkZEyawXx0y0yzZLYjEMS64F3FUIxejKu6hgH5JIRV09gRlgyF0z8RX7E4LI9DojH/i18ymd7uU3FHlZr39EjYDNTlgADZlih3Ig3psvzBJRCV0EoXxLRswK5c1zDVKgJmh3dsHv+021hvpk5LZrNyvDiZpkEn3j8R/4xituvP7XlgQNAHuamPcBPLxPvrTFbdflYd6UbnWWYS6L3A2++OgCak+jvj16hYnPRN5UKPyqLBOtn7tgQqW34B33uT1yvbwa8I5CF7kxtT3ZCHHsmwE1L/NWW34EfdmrNpj1rGKPoq4/4dHuVetlkcX4Qa9cGTSkb/ftA/+t5VeF5ioKCl1LibLKCT+H8L5Yw35OcIjJvDcsdQDZ0jZsG2NHUgEadoAIE7IDvStGtkuOUimaNXT03vKvIDXeYDY3oBLd5cjwPvFZnYDZ0H96TySoBna3RNUpf8IRgOyHZLN5NTSEGma7uPtAz/UJWcJsma7OF+LI7RUKyR9lWAjbvFk14To0feZrQAXqyFFv2Cmq9IB0Mw/Z12uJvDg8rKsUvvH0/biWua53jDonejkN+/Tw373KH+sDN9hSAFGdFiCmrCxDuORgdjCKUBuApKPJhIScqcMje5TSollD4vSmeO3ZeGg9Yvd3GUOY4CCsZNuIyCU3RVtAiwJk/5PgUyKhdEI4DjxF59XkclbvOnZgluUZGnw= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7136e5bd-c198-4154-3ec6-08dbf9f5b6e9 X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 03:03:13.5153 (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: ++Udblxw6TjYuyEqDaLX6p6Sq+LujbcaYFnl1wz2gU8c6BObF29mc+qGZQbXamSm5X5DzS73TT4npTR7hgD7+JyCiuyfh9f6CEOvd3SHcVgWSQrCjAxn7mbuWMDg1NiX X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCPR01MB11269 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 Mon Dec 11 03:03:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13486594 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="YCWnTDzZ" Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2126.outbound.protection.outlook.com [40.107.113.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D00ACE; Sun, 10 Dec 2023 19:03:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CB24vPZOdWpHHkmixmNRv+BRD242/YtwSiy3MAZYwHk8YmygnpwdH7YBBh/qQ/7hcVyBJNcYCC+tHWP9XCQPS5VbWjVwdr6gv+R7IorHD4HfwIcIjT8Ylh7iWH8dFGVJe+Chfg/nBrEJeNoGTJJd7bVwQq8LJVnAdHDoBJkW/FANEvDYAKADLdlnRc9ewYSyQDON+62oOLvyKoYNFB0JdRKIvvyGwGipjqUaNvexnixXXBMYY1ZKScDZGBgog7Wnko02V9IX2SVxyVBiuIpBTu7mGIE7u2n796lV4CnmGh5cJMqMRdmrdTgC0PaWu8UfHPfljzVvSOc+EibmU2txtw== 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=r13OWdxPFLvNkCATiQvwBjyKSaerWJzbIouZsgZlUWw=; b=Nzl3lWFj/dC5drcirlUqf5F0B/vlESKENhMnQc7ST6qm/BctCv2zOc6Y9QK8pXcD5JFhH5o15wEqmfRilcNgbi3AdGPi7NgE5ZOCMiPuWedvDounYanS4l1gaPDWYhUKa5+4JK1n8hSiUyBDqZ+yRWFnIZx8hwvVYFBQfU5Pi+XvCv0YewKpntYCk8Odk+lARCEjmcAm+txVhjQBucJIN8H7OC1SSiglY9uN74wrRvYzNfA65veEasURwimxUpoNZzPAbkD3ifMHKUwZihTo2VlTG4B5OsiqJqD1y4YWMgOJfZ/MMI7zv+NcqR7DJnhJX1RzCcPEAt2achq2RfKhmw== 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=r13OWdxPFLvNkCATiQvwBjyKSaerWJzbIouZsgZlUWw=; b=YCWnTDzZ++Su63nfNlM70xLrEX1pL9n9GKZiqAucOIKkb4KPdX544h0ztrdnAT8yirkhGqVBoUR8Nj21lL8De/Chs+uo3+oZEMCeIHwgx+jjGBiYq0sWB30mmudax6q07q2q/RvUOd16k7barFioJv8lFomveywftn/QCiHXCAQ= 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 TYCPR01MB11269.jpnprd01.prod.outlook.com (2603:1096:400:3c0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.21; Mon, 11 Dec 2023 03:03: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.7091.020; Mon, 11 Dec 2023 03:03:18 +0000 Message-ID: <87sf49o2yx.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v4 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: <87wmtlo2zs.wl-kuninori.morimoto.gx@renesas.com> References: <87wmtlo2zs.wl-kuninori.morimoto.gx@renesas.com> Date: Mon, 11 Dec 2023 03:03:18 +0000 X-ClientProxiedBy: TYAPR04CA0007.apcprd04.prod.outlook.com (2603:1096:404:15::19) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|TYCPR01MB11269:EE_ X-MS-Office365-Filtering-Correlation-Id: e891d529-ed1c-44f7-1b91-08dbf9f5b9fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DX/mSaTq8aX2XDf6fcIYo+8AqvcHgQ3SeEnmi3rh2n6Amg6LHlt4cKCJdz3xEDu/zc0RE3Rs/+FmruNIxUJyodcsBBZVRjJZq4PB9UaC0B+7l9PVF/YevK+P/EkziDuIPc4lRlgaMLa6eNgvKNUPtiMp6DPYmwE8FteXTVDpUO2P2aVOYmsTYuTwLDU5rgW4FQE9mx7oEk5hagI9i0GTbwRPaG8SEUW8GA2y53SwwDOghbdEV79vKUHRl3DukMWsJQJ5TDm9illeGx0UVrDtFvUgXN7gW9kUi3U0fnrcUlp0ORhPJ0KHULGjwsDRKC/W4PXQPKd7LEbzKRw3NGjeP7hgU7XelVWFVhwAZz2Vdolt5hK0jLVx5I40DPGazawnPg+9tm9D29aB7IFct3sP37Uc5XSWWJO8AaWriSwAfUYOxlsKJs7AqWDgYW2VqYcy9/IRb/kjYMT8cYD9wAw+xs1EUMmt9IW06NCak95dzYykokugf9FXhx0DXy3PLX+kPnBT13dx5efViKk/7ItbyF7ZGqyDrNrv/HQ8vtvHIxUDXfm78LCLjo5Pr3tt8aOqKafuW4uZiytO5IDE9McSGFyCzicHk8yvc/f3gK7yCcsjF85tIPDYHAy6uzesW00Y 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)(396003)(136003)(376002)(346002)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(6512007)(6506007)(5660300002)(26005)(2616005)(107886003)(36756003)(7416002)(54906003)(66476007)(66556008)(66946007)(6486002)(2906002)(83380400001)(41300700001)(38350700005)(478600001)(86362001)(8676002)(8936002)(4326008)(52116002)(110136005)(316002)(38100700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zmpCW2w0SAHhCwX7HXLOBkmmlSJoyQXJ752HqN9LaVyCDzRjn+SD/bX2DoCtWcWhQ19nh/N+2MyTshGsb4D3kd0Z68sasFROxRWBo32Pxwnx+cZ+IAiqHOnWRoXZPVyZchTqmsSyhzv+yV8WjTiivkVaZGtpj0E6ySJG54l93mMpGcj9oir3vGfEV6hq/gzByfOIOYBG8sKCsWcuONEpN4Vuigghf9xYAT8FgFgD3UleTkZkReDFBFJvwZl3m7KU5iBOVAv/xPgLJfUjE21Rhi3jTneULEwYID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rpLDMyeV3ISbg07DBTPQgPZzEXswIG1otm8aS+4ZQuS1hDH5UnMFt0OpwVuUpXPc4O9+VJJbioGUyWxONqRkiHEiLZfLb7sKnz7Nj//cvQ/twUG6a3nLPRK0RoQtCmqbOsW/Twd3m2WBSU7spsz+KpAWDAEMI3tguNMigLvfYuXmNkICVxyhMLhpVbBg6MdYCW46JNMzE0YY/SfZUyb92LQxJMF2aF+p6HFsGau5m782NOzR6q3qiQ9feiyiTjxcSFWsOE5NHW99jo= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: e891d529-ed1c-44f7-1b91-08dbf9f5b9fc X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 03:03:18.6724 (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: eRo4NuRH0tT15hxqFx3gafRh8J4P4yTOvnbC3yajre0euzLOhvKeuqDiQMDr10v1/BV3VBmIfY9J/iT1jXj0W9DbYGl7rHKQuBpk6O2GLi2dmLvyBG0OaSdVZny9pJUv X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCPR01MB11269 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 Mon Dec 11 03:03: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: 13486595 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="B1Ea8Ibn" Received: from JPN01-OS0-obe.outbound.protection.outlook.com (mail-os0jpn01on2138.outbound.protection.outlook.com [40.107.113.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B796ACE; Sun, 10 Dec 2023 19:03:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MJd8js0NjI1Vs73wu9QvSCHBnsHF85z7KUB4cMdopAvj8cK4S0J9vYbBhkTM9Lk0ufw0ryKmvVsYTOeW3lzD6aVE3NmjkXZ+yYlOFGTToOEGz0jbPtqLeh9LZWNz9T6UmoZhqi2H5cP7FZBK1iGf5IwE/Ow05L/U3z5+/NAIyDEIWTIiDCuD+pLrg0gI8qSvCIPgkd+zjTKyt7cxmdIE4i0U+XJtyW1MSC8d1ddkzf/4rekGMHykXZ+ivxGb2AZIgkOz+UhARU+U9fwUFP/IjRrq653jLgr200o/gkR+1nsjQ2Fx47Wi7oNw3Luoxo+rkeQKdmbYDCU2WtD/bq+SDQ== 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=3ioM8yS16w1RnxT4vNqh/GEBFRKyqI5PFJ/PkXKgyhI=; b=ZgpN1Sk/9SX2kcU4yc334JyoI17jPerkeOsxij48ekKVk2g1/Dwrws7LMtwrnkLMgvrOmAvsbsN/640J2CTJHhlblD6d1OK6B+Fs93MoT9h/wKxihCNZPJ5bC5I2qU3m4iiXwqZu3DDmiNFpVo/bHfOcR6SYAFTuwdUHnOCDxeF3NbaNeZoW7rckiXz2ONWmtcsR1676CSCbgQPziuB4/m9K1Oh3uAJVcf8XavxpIh2ZUV722UTPec5DEbWpNpITzdNbfgAyBUWSUIRE2x0q7xh6pPX0FO5RSTpLRB7pxS+35vL0ZSt1wzwxM+/tGCmtiD+R7eDgmR+SPeWJz8PDBw== 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=3ioM8yS16w1RnxT4vNqh/GEBFRKyqI5PFJ/PkXKgyhI=; b=B1Ea8IbnX0SGGyvwFBrLRJcc83K10qAPLTrYxliGYmSyeQyzeHRD6b6axIkWrJFIhL8QfJ4IEFuPVLl35YKLOaSoUYBGlMu2O6oZE8H5JdWc3j6W/ucnaq6clAhYaZGkUbNpgQFZbYdGiBt0q/hZZem0nc1+DFmDIbENbhPbMfA= 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 TYCPR01MB11269.jpnprd01.prod.outlook.com (2603:1096:400:3c0::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.21; Mon, 11 Dec 2023 03:03: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.7091.020; Mon, 11 Dec 2023 03:03:25 +0000 Message-ID: <87r0jto2yq.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v4 4/4] drivers: clk: renesas: ignore all clocks which are 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: <87wmtlo2zs.wl-kuninori.morimoto.gx@renesas.com> References: <87wmtlo2zs.wl-kuninori.morimoto.gx@renesas.com> Date: Mon, 11 Dec 2023 03:03:25 +0000 X-ClientProxiedBy: TYCP286CA0115.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:29c::19) To TYCPR01MB10914.jpnprd01.prod.outlook.com (2603:1096:400:3a9::11) Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYCPR01MB10914:EE_|TYCPR01MB11269:EE_ X-MS-Office365-Filtering-Correlation-Id: b66398f7-8121-440c-191b-08dbf9f5be4c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qlpHa/TOGnGT4bIzKnR1xSDaYRh0kgl2gdq94vy4BAoBGgWEaHzdbhWB0hGCP2euuoQQ3dmonrlneH/kpVs4pVOVpP+k3/1iwTC5iKN+N40MVxd3I1CCxzq7VeiohrHv3LLZQfsoSxXb7dmvVBVR9PXTFWSyTzgsdvPl0S26iaBURUVaFo0LEba/h6za5+zTVRvFIIcW1ohe8b+vcBsK/g9S51SSKGmFMjCk6Gc+S3BQUJ+MB3lUhh6bLGY07V6qBBBfgsGxPz0jE8ces8HNITNTdxUDgOha1JW/S8I1FTl6DCscJx+EAPuqwABrZ/mWnGwPgpQjbXDzyWkONm1QkuirYl5UpirmyqbepsREWnaobJkEtgdSyaFnzkaoDsOx0dFFU/7Hq2Vz7L6PNj5EfkEf6xLSJDcLVvg5vHLST9yo2fTZFUjZrk0o8Kc7zLAm2YQU3TaLUGl0QKSwH+5XlNtlygMCEqsTypf9PajCTj2G7cfQBUhtEfZoU9h2MWZksVuPVI8kAmspaqDayPUzNYnBqj2ro6Wtc7uuR5PRQnFDsWFkNqM5mOTyjtLPDIfiRb2s3aOBMm8pWsYZYHik3SBZjWMhgk1rTUAjoFWi1J84Ze8FkY0Xm0AXbdX9pFef 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)(396003)(136003)(376002)(346002)(230922051799003)(451199024)(64100799003)(1800799012)(186009)(6512007)(6506007)(5660300002)(26005)(2616005)(107886003)(36756003)(7416002)(54906003)(66476007)(66556008)(66946007)(6486002)(966005)(2906002)(83380400001)(41300700001)(38350700005)(478600001)(86362001)(8676002)(8936002)(4326008)(52116002)(110136005)(316002)(38100700002)(21314003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nsMLr08h5M1t6w2aOfN0yBxMSrLp8aTZuINU+BQ2BxKqxr6dpM6P0CBNfIvQis0rjToDKGl2JT4TbXIO3jGHAC4W59A9FuWd/cHBa5Vem5637lAxuX9XE+mmRqwSw0htSsbgIl6+XC3YxwamosBRVaYHCqXAi3+KN9qJdLJsuXHvzWOuoJeQ0o5oXG2X8sqvpf6JOZV+5UM0hGY0fbE/40czncx4NddpfyzV7uEneX/bQO3/Kev+DTrcj+nH97119CrWgXYmXYjdxs0et49Y6OQDp5sfjEpnjJ3wZDi00kCLCC1cDuIH/ovXe8e0AQnFpd9HAQ0E4N5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9/toG8urlItQs1Vf8Hc415lp35eusDIum/wo08jTQWXjHsxA77zmB+PpHQNp2EBpNSpX96tNAXQ9POpWAqh3z347O2R+E3RugVWGSfC1jwQrPvXbr2Ag6oh2i01zrRGDaonJRgDKEVm/UN2deRlrHSjUfaOWeO/GyyB3y241hiSF28Lt+bOs9nb4DN/bXOfkWzXEg0bRzSUSl2PhjGb+Tac7MpdHnDs91XZuVM/Gib0= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: b66398f7-8121-440c-191b-08dbf9f5be4c X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 03:03:25.8930 (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: 2z1kwuRSStW6SRMeM69iXbZbksSptYAj1XEqFIQfRuRM4XLRBnlt04WPGhDWd2tqcnJfKt8OoOlN5ZVxoWz3FFzdKrY+X/E8/RDAPHHCX9CBAwT3Y7JVV6JxpJVNMjvV X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCPR01MB11269 Some boards might use Linux and another OS at the same time. In such case, currently, during booting, Linux will stop necessary module clocks which are not used on the Linux side, but are used by another OS. To avoid such situation, renesas-cpg-mssr tries to find status = "reserved" devices (A), and adds 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 | 101 +++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 6 deletions(-) diff --git a/drivers/clk/renesas/renesas-cpg-mssr.c b/drivers/clk/renesas/renesas-cpg-mssr.c index cb80d1bf6c7c..0db2aec00d10 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,72 @@ 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 *soc = of_find_node_by_path("/soc"); + struct device_node *node; + uint32_t args[MAX_PHANDLE_ARGS]; + unsigned int *ids = NULL; + unsigned int num = 0; + + /* + * Because clk_disable_unused() will disable all unused clocks, the device which is assigned + * to a non-Linux system will be disabled when Linux is booted. + * + * To avoid such situation, renesas-cpg-mssr assumes the device which has + * status = "reserved" is assigned to a non-Linux system, and adds CLK_IGNORE_UNUSED flag + * to its CPG_MOD clocks. + * 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(soc, node) { + struct of_phandle_iterator it; + int rc; + + of_for_each_phandle(&it, rc, node, "clocks", "#clock-cells", -1) { + int idx; + + of_phandle_iterator_args(&it, args, MAX_PHANDLE_ARGS); + + if (!(it.node == priv->np && args[0] == CPG_MOD)) + continue; + + ids = krealloc_array(ids, (num + 1), sizeof(*ids), GFP_KERNEL); + if (!ids) + return -ENOMEM; + + if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) + idx = MOD_CLK_PACK_10(args[1]); /* for DEF_MOD_STB() */ + else + idx = MOD_CLK_PACK(args[1]); /* for DEF_MOD() */ + + ids[num] = info->num_total_core_clks + idx; + + num++; + } + } + + priv->num_reserved_ids = num; + priv->reserved_ids = ids; + + return 0; +} + static int __init cpg_mssr_common_init(struct device *dev, struct device_node *np, const struct cpg_mssr_info *info) @@ -1007,6 +1091,10 @@ static int __init cpg_mssr_common_init(struct device *dev, if (error) goto out_err; + error = cpg_mssr_reserved_init(priv, info); + if (error) + goto out_err; + cpg_mssr_priv = priv; return 0; @@ -1070,22 +1158,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 = {