Since
7678984e7c ("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, extend the stage parameter to allow force setting
defaults, even if they would be otherwise postponed 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>
Reviewed-by: Simon Glass <sjg@chromium.org>
return c;
}
-static int clk_set_default_parents(struct udevice *dev, int stage)
+static int clk_set_default_parents(struct udevice *dev,
+ enum clk_defaults_stage stage)
{
struct clk clk, parent_clk, *c, *p;
int index;
* It cannot be done right now but need to wait after the
* device is probed
*/
- if (stage == 0 && clk.dev == dev)
+ if (stage == CLK_DEFAULTS_PRE && clk.dev == dev)
continue;
- if (stage > 0 && clk.dev != dev)
+ if (stage != CLK_DEFAULTS_PRE && clk.dev != dev)
/* do not setup twice the parent clocks */
continue;
return 0;
}
-static int clk_set_default_rates(struct udevice *dev, int stage)
+static int clk_set_default_rates(struct udevice *dev,
+ enum clk_defaults_stage stage)
{
struct clk clk, *c;
int index;
* It cannot be done right now but need to wait after the
* device is probed
*/
- if (stage == 0 && clk.dev == dev)
+ if (stage == CLK_DEFAULTS_PRE && clk.dev == dev)
continue;
- if (stage > 0 && clk.dev != dev)
+ if (stage != CLK_DEFAULTS_PRE && clk.dev != dev)
/* do not setup twice the parent clocks */
continue;
return ret;
}
-int clk_set_defaults(struct udevice *dev, int stage)
+int clk_set_defaults(struct udevice *dev, enum clk_defaults_stage stage)
{
int ret;
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 != CLK_DEFAULTS_POST_FORCE)
+ return 0;
debug("%s(%s)\n", __func__, dev_read_name(dev));
* where the DT is used to setup default parents and rates
* using assigned-clocks
*/
- clk_set_defaults(dev, 1);
+ clk_set_defaults(dev, CLK_DEFAULTS_POST);
return 0;
}
rk3308_clk_init(dev);
/* Process 'assigned-{clocks/clock-parents/clock-rates}' properties */
- ret = clk_set_defaults(dev, 1);
+ ret = clk_set_defaults(dev, CLK_DEFAULTS_POST);
if (ret)
debug("%s clk_set_defaults failed %d\n", __func__, ret);
* Process 'assigned-{clocks/clock-parents/clock-rates}'
* properties
*/
- ret = clk_set_defaults(dev, 0);
+ ret = clk_set_defaults(dev, CLK_DEFAULTS_PRE);
if (ret)
goto fail;
}
ulong rate;
int ret;
- ret = clk_set_defaults(dev, 0);
+ ret = clk_set_defaults(dev, CLK_DEFAULTS_PRE);
if (ret)
debug("%s clk_set_defaults failed %d\n", __func__, ret);
}
#endif
+/**
+ * enum clk_defaults_stage - What stage clk_set_defaults() is called at
+ * @CLK_DEFAULTS_PRE: Called before probe. Setting of defaults for clocks owned
+ * by this clock driver will be defered until after probing.
+ * @CLK_DEFAULTS_POST: Called after probe. Only defaults for clocks owned by
+ * this clock driver will be set.
+ * @CLK_DEFAULTS_POST_FORCE: Called after probe, and always set defaults, even
+ * before relocation. Usually, defaults are not set
+ * pre-relocation to avoid setting them twice (when
+ * the device is probed again post-relocation). This
+ * may incur a performance cost as device tree
+ * properties must be parsed for a second time.
+ * However, when not using SPL, pre-relocation may be
+ * the only time we can set defaults for some clocks
+ * (such as those used for the RAM we will relocate
+ * into).
+ */
+enum clk_defaults_stage {
+ CLK_DEFAULTS_PRE = 0,
+ CLK_DEFAULTS_POST = 1,
+ CLK_DEFAULTS_POST_FORCE,
+};
+
#if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) && \
CONFIG_IS_ENABLED(CLK)
+
/**
* clk_set_defaults - Process 'assigned-{clocks/clock-parents/clock-rates}'
* properties to configure clocks
*
* @dev: A device to process (the ofnode associated with this device
* 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
+ * @stage: The stage of the probing process this function is called during.
*/
-int clk_set_defaults(struct udevice *dev, int stage);
+int clk_set_defaults(struct udevice *dev, enum clk_defaults_stage stage);
#else
static inline int clk_set_defaults(struct udevice *dev, int stage)
{