[PATCH] arch/arm/mach-omap2/omap5/fdt.c: ft_fixup_clocks: use clock-output-names property as fallback (kernel 5.19+)

Romain Naour romain.naour at smile.fr
Mon Jan 22 11:30:44 CET 2024


From: Romain Naour <romain.naour at skf.com>

Clock names has been updated in kernel 5.19+ with the removal of
non-standard node names [1]. Due to this change, ft_opp_clock_fixups()
doesn't work anymore since ft_fixup_clocks() is looking to the clock
name and ft_opp_clock_fixups() error out with the following message:

  ft_fixup_clocks failed for DSP voltage domain: <valid offset/length>

We can't use the new clock name since several clock are using the same
generic name "clock". ft_opp_clock_fixups() is looking at the clocks
node in cm_core_aon at 0:

/sys/firmware/devicetree/base/ocp/interconnect at 4a000000/segment at 0/target-module at 5000/cm_core_aon at 0/clocks
  ...
  clock at 120
  clock at 160
  clock at 1a0
  clock at 1e0
  clock at 210
  clock at 234
  clock at 284
  clock at 2a8
  clock at 2d8

When fdt_subnode_offset() fail, we can look at clock-output-names
property as fallback since it contain the previous clock name.

libfdt doesn't provide any support to replace fdt_subnode_offset() by
a new function looking for clock-output-names property instead of the
node name. So we have to implement it in arch/arm/mach-omap2/omap5/fdt.c
for now.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=e4920169e7a2a839836d3a0d8cda1bae8caa3056

Cc: Suman Anna <s-anna at ti.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: Andrew Davis <afd at ti.com>
Signed-off-by: Romain Naour <romain.naour at skf.com>
---
 arch/arm/mach-omap2/omap5/fdt.c | 37 +++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-omap2/omap5/fdt.c b/arch/arm/mach-omap2/omap5/fdt.c
index a8c301c6c28..0ca02e664c4 100644
--- a/arch/arm/mach-omap2/omap5/fdt.c
+++ b/arch/arm/mach-omap2/omap5/fdt.c
@@ -206,9 +206,28 @@ u32 dra7_opp_gpu_clk_rates[NUM_OPPS][OPP_GPU_CLK_NUM] = {
 	{1064000000, 532000000}, /* OPP_HIGH */
 };
 
+static int fdt_clock_output_name_eq_(const void *fdt, int offset,
+				     const char *s, int len)
+{
+	int olen;
+	const char *p = fdt_getprop(fdt, offset, "clock-output-names", &olen);
+
+	if (!p)
+		/* short match */
+		return 0;
+
+	if (memcmp(p, s, len) != 0)
+		return 0;
+
+	if (p[len] == '\0')
+		return 1;
+	else
+		return 0;
+}
+
 static int ft_fixup_clocks(void *fdt, const char **names, u32 *rates, int num)
 {
-	int offs, node_offs, ret, i;
+	int offs, node_offs, subnode, ret, i;
 	uint32_t phandle;
 
 	offs = fdt_path_offset(fdt, "/ocp/interconnect at 4a000000/segment at 0/target-module at 5000/cm_core_aon at 0/clocks");
@@ -223,9 +242,19 @@ static int ft_fixup_clocks(void *fdt, const char **names, u32 *rates, int num)
 	for (i = 0; i < num; i++) {
 		node_offs = fdt_subnode_offset(fdt, offs, names[i]);
 		if (node_offs < 0) {
-			debug("Could not find clock sub-node %s: %s\n",
-			      names[i], fdt_strerror(node_offs));
-			return offs;
+			for (subnode = fdt_first_subnode(fdt, offs);
+			     subnode >= 0;
+			     subnode = fdt_next_subnode(fdt, subnode)) {
+				ret = fdt_clock_output_name_eq_(fdt, subnode, names[i],
+								strlen(names[i]));
+				if (ret)
+					node_offs = subnode;
+			}
+			if (node_offs < 0) {
+				debug("Could not find clock sub-node %s: %s\n",
+				      names[i], fdt_strerror(node_offs));
+				return offs;
+			}
 		}
 
 		phandle = fdt_get_phandle(fdt, node_offs);
-- 
2.43.0



More information about the U-Boot mailing list