[PATCH 01/11] clk: Allow force setting clock defaults before relocation

Sean Anderson seanga2 at gmail.com
Mon Apr 12 05:57:57 CEST 2021


Since 291da96b8e ("clk: Allow clock defaults to be set during re-reloc
state for SPL only") it has been impossible to set clock defaults before
relocation. This is annoying on boards without SPL, since there is no way
to set clock defaults before U-Boot proper. In particular, the aisram rate
must be changed before relocation on the K210, since U-Boot will hang if we
try and change the rate while we are using aisram.

To get around this, (ab)use the stage parameter to force setting defaults,
even if they would be otherwise posponed for later. A device tree property
was decided against because of the concerns in the original commit thread
about the overhead of repeatedly parsing the device tree.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---

 drivers/clk/clk-uclass.c | 9 +++++++--
 include/clk.h            | 4 +++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 53e7be764d..cf8d35b04b 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -353,9 +353,14 @@ int clk_set_defaults(struct udevice *dev, int stage)
 	if (!dev_has_ofnode(dev))
 		return 0;
 
-	/* If this not in SPL and pre-reloc state, don't take any action. */
+	/*
+	 * To avoid setting defaults twice, don't set them before relocation.
+	 * However, still set them for SPL. And still set them if explicitly
+	 * asked.
+	 */
 	if (!(IS_ENABLED(CONFIG_SPL_BUILD) || (gd->flags & GD_FLG_RELOC)))
-		return 0;
+		if (stage <= 1)
+			return 0;
 
 	debug("%s(%s)\n", __func__, dev_read_name(dev));
 
diff --git a/include/clk.h b/include/clk.h
index ca6b85fa6f..2021eb0506 100644
--- a/include/clk.h
+++ b/include/clk.h
@@ -287,7 +287,9 @@ static inline int clk_release_all(struct clk *clk, int count)
  *              will be processed).
  * @stage:	A integer. 0 indicates that this is called before the device
  *		is probed. 1 indicates that this is called just after the
- *		device has been probed
+ *		device has been probed. 2 indicates that this is called after
+ *		the device has been probed, and that defaults should still be
+ *		set even if they would otherwise be ignored.
  */
 int clk_set_defaults(struct udevice *dev, int stage);
 #else
-- 
2.31.0



More information about the U-Boot mailing list