diff mbox series

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

Message ID 20210412035807.708621-2-seanga2@gmail.com
State New
Delegated to: Andes
Headers show
Series clk: k210: Rewrite K210 clock without CCF | expand

Commit Message

Sean Anderson April 12, 2021, 3:57 a.m. UTC
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@gmail.com>
---

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

Comments

Simon Glass April 14, 2021, 7:38 p.m. UTC | #1
Hi Sean,

On Mon, 12 Apr 2021 at 04:58, Sean Anderson <seanga2@gmail.com> wrote:
>
> 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@gmail.com>
> ---
>
>  drivers/clk/clk-uclass.c | 9 +++++++--
>  include/clk.h            | 4 +++-
>  2 files changed, 10 insertions(+), 3 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

But I think this should be an enum.
diff mbox series

Patch

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