From c9248297e040af7071212003c78140c1e383535d Mon Sep 17 00:00:00 2001
From: "Steinar H. Gunderson" <steinar+kernel@gunderson.no>
Date: Mon, 4 Nov 2024 15:35:38 +0000
Subject: Fix broken allwinner,sram dependency on h616, h618

On BigTreeTech CB1, the thermal sensor has an allwinner,sram
property pointing to <&syscon>. However, Armbian has an out-of-tree
kernel patch that creates dependencies based on allwinner,sram
properties, which assumes that they point to sram nodes exactly
two levels below the syscon node (instead of the syscon itself).
This manifests itself as the thermal sensor refusing to load with
a nonsensical error message:

  [   23.775976] platform 5070400.thermal-sensor: deferred probe pending: platform: wait for supplier

Note that it does not say _which_ supplier it is waiting for
(the message ends in a space and then no supplier). The patch
was unproblematic in the 5.6 megous patch set, where it was
introduced, and in 6.6, which is current for Armbian, but in
6.8, the sun8i-thermal driver got mainlined, with this extra
property compared to the out-of-tree version we used before
(since it wants to clear a special bit at 0x300000 instead of
relying on the firmware to do so before kernel boot).

Fix by being a bit more flexible when we walk up the tree,
so that we always stop at the syscon node.

Tested on a Sovol SV08, which is CB1-based.

Signed-off-by: Steinar H. Gunderson <steinar+kernel@gunderson.no>
---
 drivers/of/property.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 8c9f3ea663a6..074fbf9d27f8 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -1470,8 +1470,9 @@ static struct device_node *parse_allwinner_sram(struct device_node *np,
 		return NULL;
 
 	sram_node = of_parse_phandle(np, prop_name, 0);
-	sram_node = of_get_parent(sram_node);
-	sram_node = of_get_parent(sram_node);
+	while (sram_node && !of_node_is_type(sram_node, "syscon")) {
+		sram_node = of_get_parent(sram_node);
+	}
 
 	return sram_node;
 }
-- 
2.35.3

