From patchwork Tue Nov 21 02:05: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: 13462420 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="jc31jy2I" Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on2139.outbound.protection.outlook.com [40.107.114.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87F9CCA; Mon, 20 Nov 2023 18:05:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y0dLAmeSy2r9t0JpcGIOrf7fBLFtklBTMFkVnmEw+sSWmZwe3J64rFSMaL0YLMXg4ObBXmS9HAFyiJF7+ySnqaDDJYgDv+3/vzuo5YyAoy01r7A9a6/ydP/GatCVe/h5tmwwDDAbvECXE8o3dF3L+thBz0Mxi0u2TgcDauboDzE2gcToF7rsnIZpOiQSblzJ+Uervs6kIql1X6pSvlzfRNbI74lDhmxbBo0XDXLV/k+jetSPVf2VGXjMnwn4j/Gck1XHZnkA3Z1M9YoI+okq9N7kz89iKXK9HRE8BkwQCxxO4JmairjHLyXiLagwO/Rj7ojKLtwYnNTwhtW2Ov4GMQ== 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=Nf3xY1PAXbmc1h5o5cDQBQSYOOxzHqB7UyZxNdaryuc=; b=FpQvO1DUD1NcMdkOR+URbmEjgwyjvYcNBGaqFEuSCM1PrECamhxDJjp6z1t+QmHttEmqrNTTYF/gm5bi+dHXGZhtro2GsGSaAtnihUdR1zWiafyahr+L7OPdm+RwxCyhuX6p51IWQBBf1Yk3k7lggsMMJdiba4/l777sUFGnPPoB/62sp6j/glUCUd92dUfdfKJAc3BGZfVCSLP0qaXcAyi9Gg1gMjdkV5+YcGb9zE3qLGw7xAf4KQeidTr4ZFw/xhVV4DM4zJ2QsGZ9oCze6Z9WsrAco8vkOG7k9OMuCbxuMAC3Zw6UMxICg349CvsFZbbqkrp01dQTAaXGFVFq5A== 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=Nf3xY1PAXbmc1h5o5cDQBQSYOOxzHqB7UyZxNdaryuc=; b=jc31jy2I37dCaGVxFThEzNDQ3Q3EPMqbE+j1jNM+qfZFl9H+YzLsogmz7n1Bba2IYHCR4h2zBY6uRwlp8PGCdVeMhlm174wuhUG/vXqay95jSkbaG0F89m82Iz2b4jXF8c/uOB4njHQFxOh7QW0zLWcDL0DDF5HbHMLf8lSQZys= 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 OSZPR01MB8610.jpnprd01.prod.outlook.com (2603:1096:604:18d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.28; Tue, 21 Nov 2023 02:05:25 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::16b3:a84d:faa6:4846]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::16b3:a84d:faa6:4846%6]) with mapi id 15.20.7002.028; Tue, 21 Nov 2023 02:05:25 +0000 Message-ID: <87edgjc13v.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v2 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: <87fs0zc14m.wl-kuninori.morimoto.gx@renesas.com> References: <87fs0zc14m.wl-kuninori.morimoto.gx@renesas.com> Date: Tue, 21 Nov 2023 02:05:25 +0000 X-ClientProxiedBy: TYCPR01CA0164.jpnprd01.prod.outlook.com (2603:1096:400:2b1::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_|OSZPR01MB8610:EE_ X-MS-Office365-Filtering-Correlation-Id: edb22356-6bf9-4e48-ee56-08dbea365375 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HkWUMQT/ebpRnBjkP8uguCok4Qp1SVZUONbYL/8R1mYn/WyQNnIbR1qJr8UZ+ZGYrm6EKz2sLPYwfeesbhtpXGyeLfSnXrK7VibX+zyB0470gVc20Cf35aQjidkU6bP9jmQZ1r8AD3lscRiC4+8xrOHZZV8+EQh3j5UAUBiy55G1m+3RvZrniYraqp7T1dPpuGd2jdbdtugPz3XTpPfBVAghXxEWTPHvfKRIknfsvR9r6f97a0sqHTp8HytQa2Gv6CedB0aY+x8tvfQ0QS2YC6p2JLeocsuYziElFch1Hqkz54gNZBj+cih+C2djUnlFI+Gm5rxEAbkeaVGoxof/H+sjKsNT8yQ65AfXVNiIg93uEcij8kacVPm18SNSVQj7EjkeuqEcVWuO+zTrTlTIhoc26q76DE10SAJhr6UH17n0yFRsm7IS8lkD44PkZVq5zTLEepQGIMslGiZT4j5xpa2cb0ATIZcALNVA3frK5+WateYSrpStB1Ag0q7MbdJMuayKNZOxvBMvpIIeVQF+8JJKNg8pxvg1lo8XVVfgEpdoEqB5Ho7ptmjVjkJXgfkXDOh9XZRTVO7i+MK9sQ555SvhXnh+pDfOIaIdOvDX966ngBmsczoHaOIDgo4P641POLkyAHJodRK0I1pHESVljw== 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)(136003)(346002)(366004)(376002)(396003)(39860400002)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(2906002)(4326008)(8676002)(8936002)(86362001)(7416002)(5660300002)(38350700005)(41300700001)(36756003)(26005)(83380400001)(52116002)(6512007)(6506007)(2616005)(107886003)(38100700002)(316002)(66476007)(54906003)(66556008)(66946007)(478600001)(110136005)(6486002)(41533002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6u8bH50m/WJwbyY/pYUd2mZQ9Am37H/pXpHQ13wN1PtJG6gNy8qBZJpTQUjGS9cRC56LRyQeafYVfVfQWvnOCpOiVjMGibFJmidOCZ6tnEbu+noznULJsEB5TjfQ7j2ffO9c1nLZTqO/ZsYPp5b6BU2PpotwB9TdWU8C3QAHSnthWXuHN65KRQ8WzYd53jTEN+JoNsZ9a+27fWDq4jzI86uOye4EhGyV/S54BdP3Duc9GI0SAktX1hD9qar8kcO2NnLNGFi5BnI/gX80ksWhp89ssnxCrBv8OikVP4GJdWku91omqBuZfrn776OGVg60B+KBnHXUmTbMDNJQv7ewWDp7Gi5PhBqypRLib7NlcEHwWzZ9Y2D4x/PTyH5GouD/hl1StNM6CAC+G6IcfWNo4o7lgVVXbSgL+8mFlxSjTb9DMonK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sfWMpr75i6s/yik2KXaahJW/C5+Z/SkDv+/WxoI9zMLXgCVd1BjkkLcVmU3WbHtCIccEzjOxF218PLJzEqSZeXw0YHAtMg7RE4sJ5MU+FaOMa7jNCsTYQn1h8gj6hhd0jQhiJPYJCYUQ= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: edb22356-6bf9-4e48-ee56-08dbea365375 X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2023 02:05:25.3851 (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: polxUJJ+7002m3eL7G0+76TOC7WF4XY0dnmtS21XBkzBw9QBrW+e5BHaE//Y1awfxt6CRhqaFzC3ol3dHIFKvZegD9+Ajqo/H69wJDolyGn+ZYmPR/6YpSGw1OC/5445 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSZPR01MB8610 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 --- 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 Tue Nov 21 02:05:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13462421 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="UOrmnmEO" Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on2134.outbound.protection.outlook.com [40.107.114.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7856F85; Mon, 20 Nov 2023 18:05:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IpsOc9MoxDj25IDnBDKaDnGq0NkEgTaDxw41zj6abUMoZ1JNp2SJCYYkUKHrAJ8UwXMuAaL+CszyI/cGgiH2n/hv5EU9XhFqi7Px5Wry6JhwGV4p0T38UOyvTGHnVVPdeiq4XJnm6adQt7+S7cGkA6WRyWU3KQ3iohz3fyQRTeZbLq3/VtSCyyHyrvZWd/8tEzU0kEJrPsFOHQuqZNpIfx4BdxRzTFafseuhiH8/hhMFG442InZYhycD0N05HFcN0yW7O8/mLTdrxrwO3wEgHIjf24zy33kIzM/1YoYsuPKqj2wqSafD7akEyBl7tN+7ZY7HcMi5HZKK1R/EJtix0Q== 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=pJ9np3T+wOYwhmN8Vc0TSzIL7szs5pjdyC+crr80IMA=; b=GYd87EpwiIfnm48HwqocMrxW5CMSv03AI+u2lJFHUbbLRTrct4cgceu4qleVF7RkJuoXeFqW8V5Zrd98q4BJL54vBhspQQ84YSYfC8I+pJerPnwtsnVisQfvCasIdzDODRGAQ2SGyLB9/jf5o7zd4aY4qDnScBG3pQs9ckkDqNNilaB/ybKMhLfk4nfYK1U/FXVArjpLnSD9I8Xsnvo1AXX2XfR3AuXNzx5r579Si7e1a8+r6gfW1jCgTg7Bu7ntMphV7SWJsEQVbCyj0XIauyWUvtfVzjiE/G/8/luYf1DWFmTWUfhIiOiBBNFVfgfCoOkXV7Wn6WgdAZ1XtCyOWg== 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=pJ9np3T+wOYwhmN8Vc0TSzIL7szs5pjdyC+crr80IMA=; b=UOrmnmEOvUO2yoPJlfKYjzJOzxwioSkC4DtPMbtvawSvxpR5JdymfyYAuEvIwf95EGrCQpEm9MOFjrVGV3ERr6crZ3KgAKUttedo/KKAa87V0GfQPOdBlNO/huH3UhlmYfLIVD0Rt+RQ89eSEtjkCsm8gE/7/PiABWqJtz31G4M= 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 OSZPR01MB8610.jpnprd01.prod.outlook.com (2603:1096:604:18d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.28; Tue, 21 Nov 2023 02:05:30 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::16b3:a84d:faa6:4846]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::16b3:a84d:faa6:4846%6]) with mapi id 15.20.7002.028; Tue, 21 Nov 2023 02:05:30 +0000 Message-ID: <87cyw3c13p.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v2 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: <87fs0zc14m.wl-kuninori.morimoto.gx@renesas.com> References: <87fs0zc14m.wl-kuninori.morimoto.gx@renesas.com> Date: Tue, 21 Nov 2023 02:05:30 +0000 X-ClientProxiedBy: TYCP286CA0221.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3c5::7) 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_|OSZPR01MB8610:EE_ X-MS-Office365-Filtering-Correlation-Id: caceef08-ad15-44a8-8ecc-08dbea3656ac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ObcR/TxCYhRbDgNJWiIVSuKpk7mJqWNs82/rAu/gVtKR6ic8tn6dixgXGS8afM/u6iEijalTk+FPoymT2//cnpkekLoN+mgGZILZXPAUXloo6L1VnwpUN3FYg1IH8JQ+PYUwi1iBpLoYFi+kyh6/5iv875mYmsY1UeXqmHyxw7WNtM4jErwGp2V8NdniJVldpu2p4f0jb4jjf5eLZVh+/zoNMC6oOya86CgoTMZN5keONae4W8SPidMdi0757IU2p8QL0lKh4ddiG2oldOy3ybxtHtNoUXIdBtasucJtPKpRhFoXivR+qe6OzXJyRHsfCGgwIiNtVvpxsfa2lgbFQPHP4tgAywpe1TEkeYllwkHVYx2YtpTJOun+F5jDfKG3fW4YOjAa43WojvhudJs/w5YMjYYrWctkjglt1CmOxaG1u6NYLhhGZ7PtdZu6YK62AmP1y/ikTAZXBHYQCbHfDamSQoj5EYpbuvQmz1l22OWUWatznqdTlupZ9MuWxXUMMjB8AHZBWM3tLxPBpddRgAwsN9uFbLyhmjWWm2MmN5SYAvNeD4mZpSSUcyjmzfjLGvvzdg7I/6d2Onx/nLH1gGWZXmrQPLdry3T0E9KdnkUK4I6YVcEzwOqZ4g1z3OOe1heFsfeLmFMy+uyrAXPo0Q== 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)(136003)(346002)(366004)(376002)(396003)(39860400002)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(2906002)(4326008)(8676002)(8936002)(86362001)(7416002)(5660300002)(38350700005)(41300700001)(36756003)(26005)(83380400001)(52116002)(6512007)(6506007)(2616005)(107886003)(38100700002)(316002)(66476007)(54906003)(66556008)(66946007)(478600001)(110136005)(6486002)(41533002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Yb6UwgCjmB1/nTe+X8wxtE/IZ2gxcx+Y/mGOyafg1Sk4YyaIXrn+tgJVOSiT58sQR5XGuxJ9k6tFS/cNCozrW82/daI3GStFw5Yg5ehIzCGYijLDKe4l2asX1leYqlsKvw/VYxrlP9iaBBVRXDzwspFrKzdPX1JXK6JEsUCsJ8GceRWiUXXNG8FOyCqgTxeM7egBt9YemQ4FPMa6fZP+XySzrRBhD+4bA5oUG3I+H+C1SSn2FuYOAIdNyW4BmpRNVNQd+GXK2ZiqqnLnJhTNcNcnp20NBjWpOqxWwHgJJ757o/hAzUdvIp6wbvaF4vZdqmBPNhYvYRyhw+M7756OHunDfwRZX3hjms5KPEpbJpQLCNc3TT8Ld0eqDE629Sbz3FzPOdS1qeo5uEgZjmtQWGbye+Wa2crxqh1qXzJhkjadAi+v21PDtYwLKO+TxmVVfTUmED+oxg1xYrXHNpY2f+pJNxP9gcsIL5men3nS1KJOi5Fp3gQV/XfMGz/YY/k/J52P921rcfAe0AS9up8Jz57RRkqh+H+VNENIQbcWPAYw74x0sG90Okt2+HVMg1arjz+ClVgSiSqHkgun0NMX9XiC65nsJZ+TKdXh4nUeqeaj4pL14xEiN9F4W0N13UgdYY5UEhlHuXKNJ8T6u33Bp/oa+P0/7r0xgE3KBz0UKXkAoR7IFKQLWqkOVOnzl7l7rz0KkS37x+z22uGTEo7cL7Ny0Q5f1QllNPeToGqhrzBriY6M9YQG861wEDbgpnfnaIb2RiyJR+7/r/bUzKHpfcxxpdLvTwMD4ydNNnNWr20VBe6tpvsnKFzCpfeATUYwzr3cm6A7QSZsYf4c3CYk0RSA9MMVlP5KzauV4j0H6Zn8B7KtqRxmY0cR2qubCRn8HKIzvzRBNIsdHlrBS6IpMIGeSVgGgNZCO4LEj8Eegv/rdFpPDJCbTtYLjfzhCFCeO78COu8/oeRCo88ZttTjOe4aNpg+6Q0XgFeW7JhDTQetxbMk0wRE9Vqz0satj++BQupalyUjYxJxR9GRjV0b7T9B/Di32dOPXyiF/SGhwMg8q0uzesoYHRUOtfxgxoVelAHoXODN0MqO3x7Idjr7YjG0S9Q9eziyLFlDzP1QHmaYLtVKuwzMg92uBd1OVK5aeEP7pAZgiHdy+yWTFh55uevNTE1tbygZzC9hGX0QeJtdOSbMvA4lkRckCA53sPjAhCJHgLrfJshVQowsMhjuyfvNj7B1vRF9gnk1odJCqvJndqK2KO4/ii5o4bFpSNxvXM2oaORoYzIy/GY44AesH21tE/kQcAnVjBii4M4EHbYGRo4RFNQRfXj9GNSFx5Rds1Ph1PE0q1AXBMtEdlumDLo8WjZnltok5097+3FKfzbrhaqp8QOx2vACPnlx8sbt7KcjHqGS33AXcXmGS4Tnrh5Bciy1SYDunkIbpKOzQ22boEl/pE7P7X9c/e9PzZf2HBYsFh30dcA06WGEZCog5iYA81u9nkpprmhlXo+sOTczRTmKRuBo0tE9n6HVMwy+l+6ri0TDEiasteMYBVStNbTHdJJvYvSuWBNdoK44dWyVwIvJYbWF5OdvyUJTxsmdF7Xyb5+Q/A4kNFvpmOY34dzUb5iEyaQuyMGaT2f+EYU= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: caceef08-ad15-44a8-8ecc-08dbea3656ac X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2023 02:05:30.7390 (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: ODwub1ftPtt+pEQZmXiOEAuu7eOoyG5LZAvy8cvsICrbhAPe1jUO+qbIYJuKMGJmnl8ih2AIEPS1AkHAwJbYM95Mzw2VMSAUF8mOrrpxGesM0TDN/Kj9YDBue2NX3N8e X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSZPR01MB8610 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 --- 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..d0f7e7c890f1 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 Tue Nov 21 02:05:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13462422 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="ZU8FVDFk" Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on2120.outbound.protection.outlook.com [40.107.114.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A11D5C3; Mon, 20 Nov 2023 18:05:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lGZLxuasXh0e8XCcgp4SbdDqm5FlcnpMoQTSDJ+OdLKzYQu4xVSWLLY3No1Nt0YKRdoULDXbM+BDQquu9StlB7Z+7u4Qh7Y/HNkZ9njkFB8onGzlB0nvlMyZ89T2E5AegZjQJJWRMGptEB2HDxhykshwZGlgBfE32S39QGj/Aot7I4rfTwqLfR4tPGf88udKgiDX2W4TfXKKXQJBuKJ6iZZg8XI7WFBYg8Q6rjIVmSND9zFuMcvAgC5wVO8TDNguE5PYSzEcIrRShXvV9W4KtrSxzX3HlI7rkcQvM3f9pkNQD+VGNqD+Mxal/9RTBfGNfnEO4F0ZrtKy9dJm6MRsNA== 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=iwjAVtd6oYxbpVDXpHQW7augglxKXi/xbnUU/noBXy8=; b=a21A0AAk3sOXy7nw6ip8bqrvsm6K+4OE1ucEXmHzOL/L+S25SAKc7mjpRun+ZxX47KtpmnhhxcKNANkftg6Bpi1CPNXWVX4Q90xp4T3uOw9ARjZscy/UItbTUzy5cjIsoXVE3sOidg26z9TXwcNUo6g8iEDqZoZewTN+URexvEg/WwAbZvWHSm2HGhpEqULF7Rzbm8P8ZBVDKWc/DJpqHpXqR8kwH9hzyyaAe10ZG+nlhQqZ6qNwe9FgrcLDGfb49BUNvMnnjveNYIwal44QdsOyjB1bOcrhZAvCmtae5YCLwvx9PAgSvogEaglqVGoQp4frKxk2croYKBUbiFngJQ== 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=iwjAVtd6oYxbpVDXpHQW7augglxKXi/xbnUU/noBXy8=; b=ZU8FVDFkq7y31gNk7NnER4qMSS+tdb5PfqmDIGuLIgNCcPQXqzJqWb3ks8CQkahliEU6YOu4CLlbMsJd86G1uJ30SPLyXS6Vr+0E1oOd4yguv1HhMIqwNtUCA2svn0llvzWE+QqBZMVmlM1Euj8JFwydZwiWwBYY3aF4tZgd1m0= 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 OSZPR01MB8610.jpnprd01.prod.outlook.com (2603:1096:604:18d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.28; Tue, 21 Nov 2023 02:05:36 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::16b3:a84d:faa6:4846]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::16b3:a84d:faa6:4846%6]) with mapi id 15.20.7002.028; Tue, 21 Nov 2023 02:05:36 +0000 Message-ID: <87bkbnc13j.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v2 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: <87fs0zc14m.wl-kuninori.morimoto.gx@renesas.com> References: <87fs0zc14m.wl-kuninori.morimoto.gx@renesas.com> Date: Tue, 21 Nov 2023 02:05:36 +0000 X-ClientProxiedBy: TYCP286CA0218.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3c5::17) 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_|OSZPR01MB8610:EE_ X-MS-Office365-Filtering-Correlation-Id: f0da3551-89b6-4074-2d7b-08dbea365a40 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n3laqpDfVm8i+6mPYvRx5Rjf6mI96b8B/nRQ4ZG5GE8csrR2HMhdLKtn9kSDpBFaDgLzUYEUJxl/prP4g6DhHGiEWqBJqAelapZwh8L4XND8sxC88LviRfM5dcsIIEqTXkQ3xN6u8CwOeBz0LpXt6zxEZmJ04DMZMdn48wDVIjhYlFLdQ8Qvt7Y3tzoYkud4ffqqVrUhUsX1VaKRy+h2g1oMtk4cdnltqccpLhGIyd9f/ayJP/lVf1sYHv3k/MESgWgR4mth0QjWAi4GasDkXBztlyzwfnHoiEBB9+bUhrdvbiFqx83zVzNgiBf4gKJr5MPWb7nJP7UHIJc3oYGwwv2wdwyhDt+udWQC/0ulJY7WMpA0qhlWwKdhfoS/wqCb0Oj2Pk8A6ftZC+jHV117kjnPa1+QH+xIduxqAJhTJwEW4Q33dvRElem92kA5/YUJF/nK2V2dNZs4yvQpO0NRzeAgma7hfBgWUDJaszHBO9N8o/FIOJsPhC7uW4iyQrlxAsesSOJsGG1KgcXClFW0s5v4/FH5tl+fMRQ/WA5J+06uDOx4eYQSl4KK5Kvuqcdf3NXcg2eVXnlJuXREFVUnrU7B3oVN7JKVYK95tvFH/BMUvk4mgmwFdVqMo3k5QcRL 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)(136003)(346002)(366004)(376002)(396003)(39860400002)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(2906002)(4326008)(8676002)(8936002)(86362001)(7416002)(5660300002)(38350700005)(41300700001)(36756003)(26005)(83380400001)(52116002)(6512007)(6506007)(2616005)(107886003)(38100700002)(316002)(66476007)(54906003)(66556008)(66946007)(478600001)(110136005)(6486002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VHmWy6+3Bv4hSCzNAcsHEnIFZkQFnwvoBtZ/rnKHV/edqah5PvV0v4qqY7ZHPacaS0nd4Y1usdjwkDdb2LACb3gdAkJEd1qoE1QYlY2r/EiY8/mY+aLUKhSrGfj8B+sQOSbTmyjAecRPQI49CjTBNXFpHWxx/GCdrY6Gaai6Iswc4+TtwNhw1l1Wqbi7VZFZjmgTH2Vd1MtzFcS9mIMDvBogN8tY72fymVEg1E5MnjlO4N1uUOF4BauVZ0kt7jriC479cHRUUP5UiL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HaaY5qCj0pOoQVXPRcNLIEbJ9cjfpKUwZQBo65FbSIo4Dej9DdauhalNVP0PYE/LeHsfS5Ot27qlfdCfUOAXkFSSd+tPGEq2NkjCw1ZaCXeJdQF73JLyZy01Gc4sahHbuYbHmWgWgy3sZDPHXH1FK5pRaoFjc+dnkI9UOTcBzLcQZ3I7+qOwMhp34lrUd3C1kZ00azYPGkqVqqc/40Qq19Of58RyUwkxK+5MKJvXN2uPRIMaxHIr0JJS4lDBQIXOjR1u1XbSObSXEsfDtmvp7SaCmkFLjpnD11H4= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: f0da3551-89b6-4074-2d7b-08dbea365a40 X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2023 02:05:36.7527 (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: y5bftOAnly5ftbQfT6p0ytQjObgIE36FNSnISxrd77wk+7t4q0d2lrKeEGi+51XtiZVmHGg8n11Pqlv9Oj56dAYwice1rftG1sK251xEREpt+a7gXwQLCEcFVWL9hLz7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSZPR01MB8610 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 --- 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 d0f7e7c890f1..9406775f159d 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 Tue Nov 21 02:05:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 13462423 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=renesas.com header.i=@renesas.com header.b="e+/RA8jH" Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01on2136.outbound.protection.outlook.com [40.107.114.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D5E883; Mon, 20 Nov 2023 18:05:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YdmW1o46K13M0L3n163vrAjqu7Il8wDCvyAhn746Yagc9P+1XWf8fSWe/J3y2ia5klt9EYwTkiMvMx+zI8L75/FFmxT0HuteTGSozMe0Xk62JXh93/LgBXLtnNLU2GFNRqx/kl7C1FoE7HVFJ1eehIy2VVcvxLf9cC4HW6N2orDcK8jHrPbzcOhB0tBjM9AklHLlJvl+izQz5AMPSSWxu7/q7vS22T25UuAS30ot0BE/awZNIoFlkAihyat7uqdifYI01xHJNJMjKZK/TyS7DVj3d66mtEetPpxS2dRGa27xHYtULwT85l6qla36rnQSy0ibLvNq/s0tJ4AbF7NDeA== 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=AbsdI8SSlM4cf/NO692uXi4TJxPr/im+sMQ1WoaKraDXN5cxnEpkmBqJYJyBC7GR+jhnEi5paFTTBw8Vfd7YoLVws0C290ZRySjILmrpeVlTFxOjSVSfgqJC03LFmsHrBrk6FBrQXbipmKOtHRV9YBAZg9qVV86CxVxqdPzymGw6GgoktzEr+lpNkXi0qnLgt52qAdLkfcl8MoR9/s4LPspy1DwhA3uBGbUgFApSBY/DoH3t1RyLVmdwNepUereurpAqQ8r0qb1zj/hrezEuKMifGPWvJgYmGoOev6870zrDzSdjjkh4+5bRsGRuzaEtMJF3e/QnRBg72aYY2edz8g== 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=e+/RA8jHNa7fbUSKs+i1Ghtjfwj33tsbIdyz/enlB5Jy6dCHrOoJJC740sBaIpQckebJFe8//3vVv0ji+rKrocDH5ZI2DHVParSPpildh7ttC4ozsnPtwA6N1raoi1unfvaG/uLOoSQXp97JN2BxuV3PXvRgE5tbLvgI0j8GSOE= 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 OSZPR01MB8610.jpnprd01.prod.outlook.com (2603:1096:604:18d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.28; Tue, 21 Nov 2023 02:05:43 +0000 Received: from TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::16b3:a84d:faa6:4846]) by TYCPR01MB10914.jpnprd01.prod.outlook.com ([fe80::16b3:a84d:faa6:4846%6]) with mapi id 15.20.7002.028; Tue, 21 Nov 2023 02:05:43 +0000 Message-ID: <87a5r7c13d.wl-kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH v2 4/4] drivers: clk: renesas: enable 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: <87fs0zc14m.wl-kuninori.morimoto.gx@renesas.com> References: <87fs0zc14m.wl-kuninori.morimoto.gx@renesas.com> Date: Tue, 21 Nov 2023 02:05:42 +0000 X-ClientProxiedBy: TYCPR01CA0200.jpnprd01.prod.outlook.com (2603:1096:405:7a::7) 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_|OSZPR01MB8610:EE_ X-MS-Office365-Filtering-Correlation-Id: ac762b7d-8caf-47c9-cabe-08dbea365e11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m5UGuOQ3u5JWetRggFK5+Ndj8LLY+JDB6KG7CQOIgAwek/z98nZZSBFC/L4BgbKeXx+3y1ZQ2q7JUPizr5Db1CAi2DySJ9oX84u3XBnSi14TlrEmgexhblKhn9FDJ9BemUxCxqBMJBexvBbSu7V9jOL7YidGMGHuecF85ahbKOesYHQ6uZJPLYrnLl6dzusqr8ehno8S3Kcg4GZRYxNQhAmVKVsVeNxwKmDmJCyy/DK5kGeYK6dc6gROsjjcaMpsbCF01/alT2epGJOzzwLU5VqoiKs0sWpZmSUQgD/u0X1K69hicaham0Xj2Mo0gYF3/DPbyE/se4vjEAFyd58GioNdYOPYSEqoNTQuNzueo07iFW0a3BNm1hNtoN661aHt1H2vRdD15h6GfPw7VSm1ErIXDuJorsu6r/tsP+Y6//IRzTR+Xo8gwk6kTH4+fW5Yl5fVl+/fG52rgO3PpiNLDzaewLFz/RsMuCxx9yNbRzW+b83TP6kSH3pBDJ9L92asJbUxe8Ngu4qM/8AJymRbUxE029GjS3mYVLzqMFSh17xfUCWe4yYC6WXyM/rAusBUkQJeB3n39abeBHyI77GcMQEwPlK3Q093DUaeXZVYzxa8TkEDeN9lxJykx1A/0Y0o 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)(136003)(346002)(366004)(376002)(396003)(39860400002)(230922051799003)(64100799003)(451199024)(1800799012)(186009)(2906002)(4326008)(8676002)(8936002)(86362001)(7416002)(5660300002)(38350700005)(41300700001)(36756003)(26005)(83380400001)(52116002)(6512007)(6506007)(2616005)(107886003)(38100700002)(316002)(66476007)(54906003)(66556008)(66946007)(478600001)(110136005)(966005)(6486002)(21314003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0vDX296dsJtE75ntnKkks34P5hRBPuQkQoILKGQF6CtT1+kPjk/dvNizki5LjzLgvGk9d7/AyxBapTNtnthYrCSWf3bo/IoKgHGdbri1hxgfhPn8bugWEtUFnc97knSDrhaA6AO4MW330kiaiP06zGEIXIb9pS8l4xpns/Z/++hcKMXQYMo0xufk8pFlk4mX/8N8Tb3h8dN8hs8sjV3ztO8aUde2S86aBsEtmT4V0wtGRVro0ipaLFDZQj64vsKfHJ/cWSFb/h7Tpe5MT7R2/8d/prtwZVOTmSdkPRptaHZFwr2nhx1moLzR8vc9cPEruItagcE8EsdyUmX5bizb4SeRtRQsH1V7LIh1/OacLnFwUw4nol3jNLJPynrEiM5BUh6e0bHAboNi2k8CDqo3hUTra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9W5JzGt7pZK+uBYlZ705dwV7KUhLL/fbFZqo+Yl/YIJaEPyU7ccTkubZdXqSWlaMmZ6iIf5XuHbc3Ui30TJvccX5Uv6Q9uVUZYOlMJymS73yUg5HMWw54UZFoGVNHEYXCzK1+MegVdFqkwhAWCBXE7w= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac762b7d-8caf-47c9-cabe-08dbea365e11 X-MS-Exchange-CrossTenant-AuthSource: TYCPR01MB10914.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2023 02:05:43.2218 (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: fOkesvaM/yGBVlGGDtQS9Ufk+Zra039C4Gdpss0UtChRUR+8Z+VI8d5XR989vIEFRxfkb8bYfatplp3DBqMseIfzid/vM7GwqM1hv68W8rSSxWztx/JEzFXrxGXdLsr/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSZPR01MB8610 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 = {