[Uboot-stm32] [PATCH 20/36] clk: sandbox: fix set_rate and move to clk/basic
Casey Connolly
casey.connolly at linaro.org
Mon Jul 20 16:40:47 UTC 2026
Prepare for adding a CCF version of clk_sandbox by moving the existing
version to clk/basic. Additionally fix the clk_set_rate() tests which
erroneously expect set_rate to return the old clock rate, this doesn't
match the documentation nor any real implementations or users. Adjust it
to return the new rate instead.
Signed-off-by: Casey Connolly <casey.connolly at linaro.org>
---
drivers/clk/Makefile | 1 -
drivers/clk/basic/Makefile | 1 +
drivers/clk/{ => basic}/clk_sandbox.c | 47 ++---------------------------------
test/dm/clk.c | 8 +++---
4 files changed, 7 insertions(+), 50 deletions(-)
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 4bec2e4c61a8..52a9fc01106c 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -64,6 +64,5 @@ obj-$(CONFIG_CLK_XLNX_CLKWZRD) += clk-xlnx-clock-wizard.o
obj-$(CONFIG_CLK_ZYNQ) += clk_zynq.o
obj-$(CONFIG_CLK_ZYNQMP) += clk_zynqmp.o
obj-$(CONFIG_CLK_ICS8N3QV01) += ics8n3qv01.o
obj-$(CONFIG_MACH_PIC32) += clk_pic32.o
-obj-$(CONFIG_SANDBOX) += clk_sandbox.o
obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
diff --git a/drivers/clk/basic/Makefile b/drivers/clk/basic/Makefile
index 4cf9469d2312..bc0282d4e247 100644
--- a/drivers/clk/basic/Makefile
+++ b/drivers/clk/basic/Makefile
@@ -4,4 +4,5 @@
#
obj-$(CONFIG_$(PHASE_)CLK) += clk_fixed_rate.o
obj-$(CONFIG_$(PHASE_)CLK) += clk_fixed_factor.o
+obj-$(CONFIG_SANDBOX) += clk_sandbox.o
diff --git a/drivers/clk/clk_sandbox.c b/drivers/clk/basic/clk_sandbox.c
similarity index 80%
rename from drivers/clk/clk_sandbox.c
rename to drivers/clk/basic/clk_sandbox.c
index 36ca128892b5..1092a5a085fc 100644
--- a/drivers/clk/clk_sandbox.c
+++ b/drivers/clk/basic/clk_sandbox.c
@@ -43,9 +43,8 @@ static ulong sandbox_clk_round_rate(struct clk *clk, ulong rate)
static long sandbox_clk_set_rate(struct clk *clk, ulong rate)
{
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
- ulong old_rate;
ulong id = clk_get_id(clk);
if (!priv->probed)
return -ENODEV;
@@ -55,12 +54,11 @@ static long sandbox_clk_set_rate(struct clk *clk, ulong rate)
if (!rate)
return -EINVAL;
- old_rate = priv->rate[id];
priv->rate[id] = rate;
- return old_rate;
+ return rate;
}
static int sandbox_clk_enable(struct clk *clk)
{
@@ -165,9 +163,8 @@ int sandbox_clk_query_requested(struct udevice *dev, int id)
return -EINVAL;
return priv->requested[id];
}
-#if !CONFIG_IS_ENABLED(CLK_CCF_FULL)
static int clk_fixed_rate_of_to_plat(struct udevice *dev)
{
struct clk_fixed_rate *cplat;
@@ -196,45 +193,5 @@ U_BOOT_DRIVER(sandbox_fixed_clock) = {
.of_to_plat = clk_fixed_rate_of_to_plat,
.plat_auto = sizeof(struct sandbox_clk_fixed_rate_plat),
.ops = &clk_fixed_rate_ops,
.flags = DM_FLAG_PRE_RELOC,
-};
-#else
-static int clk_fixed_rate_probe(struct udevice *dev)
-{
- ofnode node = dev_ofnode(dev);
- const char *clk_name;
- struct clk_hw *hw;
- u32 rate = 0;
- int ret;
-
- ofnode_read_u32(node, "clock-frequency", &rate);
-
- clk_name = ofnode_read_string(node, "clock-output-names");
- if (!clk_name)
- clk_name = ofnode_get_name(node);
-
- hw = clk_hw_register_fixed_rate(dev, clk_name, NULL, 0, rate);
- if (IS_ERR(hw))
- return PTR_ERR(hw);
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, hw);
- if (ret) {
- clk_hw_unregister_fixed_rate(hw);
- return ret;
- }
-
- return 0;
-}
-
-static const struct udevice_id sandbox_clk_fixed_rate_match[] = {
- { .compatible = "sandbox,fixed-clock" },
- { /* sentinel */ }
-};
-
-U_BOOT_DRIVER(sandbox_fixed_clock) = {
- .name = "sandbox_fixed_clock",
- .id = UCLASS_NOP,
- .of_match = sandbox_clk_fixed_rate_match,
- .probe = clk_fixed_rate_probe,
-};
-#endif
+};
\ No newline at end of file
diff --git a/test/dm/clk.c b/test/dm/clk.c
index 790968e64774..67d9a2bb4815 100644
--- a/test/dm/clk.c
+++ b/test/dm/clk.c
@@ -99,24 +99,24 @@ static int dm_test_clk(struct unit_test_state *uts)
ut_assert(IS_ERR_VALUE(rate));
rate = sandbox_clk_test_get_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED);
ut_asserteq(1234, rate);
- ut_asserteq(0, sandbox_clk_test_set_rate(dev_test,
+ ut_asserteq(1000, sandbox_clk_test_set_rate(dev_test,
SANDBOX_CLK_TEST_ID_SPI,
1000));
- ut_asserteq(0, sandbox_clk_test_set_rate(dev_test,
+ ut_asserteq(2000, sandbox_clk_test_set_rate(dev_test,
SANDBOX_CLK_TEST_ID_I2C,
2000));
ut_asserteq(1000, sandbox_clk_test_get_rate(dev_test,
SANDBOX_CLK_TEST_ID_SPI));
ut_asserteq(2000, sandbox_clk_test_get_rate(dev_test,
SANDBOX_CLK_TEST_ID_I2C));
- ut_asserteq(1000, sandbox_clk_test_set_rate(dev_test,
+ ut_asserteq(10000, sandbox_clk_test_set_rate(dev_test,
SANDBOX_CLK_TEST_ID_SPI,
10000));
- ut_asserteq(2000, sandbox_clk_test_set_rate(dev_test,
+ ut_asserteq(20000, sandbox_clk_test_set_rate(dev_test,
SANDBOX_CLK_TEST_ID_I2C,
20000));
rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_SPI, 0);
--
2.55.0
More information about the Uboot-stm32
mailing list