test: clk: test clock self assignment
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Tue, 22 Oct 2019 12:00:07 +0000 (14:00 +0200)
committerLukasz Majewski <lukma@denx.de>
Tue, 22 Oct 2019 14:14:05 +0000 (16:14 +0200)
Make sure that the clock self-assignment works by having a clock of
clk-sbox be configured automatically when clk-sbox is probed.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
arch/sandbox/dts/test.dts
drivers/clk/clk_sandbox.c
test/dm/clk.c

index a5b9fbd2257407bf606a53e49ca5a18a41c6f384..fdb08f21115985924466463e8919edcef732109c 100644 (file)
        clk_sandbox: clk-sbox {
                compatible = "sandbox,clk";
                #clock-cells = <1>;
+               assigned-clocks = <&clk_sandbox 3>;
+               assigned-clock-rates = <321>;
        };
 
        clk-test {
index d152fd7e5b894379d122622858a58282df085430..de6b2f7c82f29f4604a455214e734b961152a428 100644 (file)
@@ -10,6 +10,7 @@
 #include <asm/clk.h>
 
 struct sandbox_clk_priv {
+       bool probed;
        ulong rate[SANDBOX_CLK_ID_COUNT];
        bool enabled[SANDBOX_CLK_ID_COUNT];
        bool requested[SANDBOX_CLK_ID_COUNT];
@@ -19,6 +20,9 @@ static ulong sandbox_clk_get_rate(struct clk *clk)
 {
        struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
 
+       if (!priv->probed)
+               return -ENODEV;
+
        if (clk->id >= SANDBOX_CLK_ID_COUNT)
                return -EINVAL;
 
@@ -30,6 +34,9 @@ static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
        struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
        ulong old_rate;
 
+       if (!priv->probed)
+               return -ENODEV;
+
        if (clk->id >= SANDBOX_CLK_ID_COUNT)
                return -EINVAL;
 
@@ -46,6 +53,9 @@ static int sandbox_clk_enable(struct clk *clk)
 {
        struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
 
+       if (!priv->probed)
+               return -ENODEV;
+
        if (clk->id >= SANDBOX_CLK_ID_COUNT)
                return -EINVAL;
 
@@ -58,6 +68,9 @@ static int sandbox_clk_disable(struct clk *clk)
 {
        struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
 
+       if (!priv->probed)
+               return -ENODEV;
+
        if (clk->id >= SANDBOX_CLK_ID_COUNT)
                return -EINVAL;
 
@@ -97,6 +110,14 @@ static struct clk_ops sandbox_clk_ops = {
        .free           = sandbox_clk_free,
 };
 
+static int sandbox_clk_probe(struct udevice *dev)
+{
+       struct sandbox_clk_priv *priv = dev_get_priv(dev);
+
+       priv->probed = true;
+       return 0;
+}
+
 static const struct udevice_id sandbox_clk_ids[] = {
        { .compatible = "sandbox,clk" },
        { }
@@ -107,6 +128,7 @@ U_BOOT_DRIVER(clk_sandbox) = {
        .id             = UCLASS_CLK,
        .of_match       = sandbox_clk_ids,
        .ops            = &sandbox_clk_ops,
+       .probe          = sandbox_clk_probe,
        .priv_auto_alloc_size = sizeof(struct sandbox_clk_priv),
 };
 
index 3ad0ad8ca36f3490344019836f245c60c8ba3a28..31335a543f176ad49fd4eee78b58cbcb6917cbb9 100644 (file)
@@ -74,8 +74,8 @@ static int dm_test_clk(struct unit_test_state *uts)
                                                 SANDBOX_CLK_TEST_ID_SPI));
        ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
                                                 SANDBOX_CLK_TEST_ID_I2C));
-       ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
-                                                SANDBOX_CLK_TEST_ID_DEVM1));
+       ut_asserteq(321, sandbox_clk_test_get_rate(dev_test,
+                                                  SANDBOX_CLK_TEST_ID_DEVM1));
        ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
                                                 SANDBOX_CLK_TEST_ID_DEVM2));