sandbox: clk: add clk enable/disable test code
authorPeng Fan <peng.fan@nxp.com>
Wed, 21 Aug 2019 13:35:19 +0000 (13:35 +0000)
committerLukasz Majewski <lukma@denx.de>
Wed, 21 Aug 2019 22:10:09 +0000 (00:10 +0200)
Since we added clk enable_count and prograte clk child enabling
operation to clk parent, so add a new function sandbox_clk_enable_count
to get enable_count for test usage.

And add test code to get the enable_count after we enable/disable
the device clk.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/clk/clk_sandbox_ccf.c
include/sandbox-clk.h
test/dm/clk_ccf.c

index e126f18d8e96256f90914e0d0aaa548e849767db..9fa27229e18668305e41d65d7e6a8e1390f4d657 100644 (file)
@@ -25,6 +25,18 @@ struct clk_pllv3 {
        u32             div_shift;
 };
 
+int sandbox_clk_enable_count(struct clk *clk)
+{
+       struct clk *clkp = NULL;
+       int ret;
+
+       ret = clk_get_by_id(clk->id, &clkp);
+       if (ret)
+               return 0;
+
+       return clkp->enable_count;
+}
+
 static ulong clk_pllv3_get_rate(struct clk *clk)
 {
        unsigned long parent_rate = clk_get_parent_rate(clk);
@@ -254,6 +266,9 @@ static int sandbox_clk_ccf_probe(struct udevice *dev)
               sandbox_clk_composite("i2c", i2c_sels, ARRAY_SIZE(i2c_sels),
                                     &reg, 0));
 
+       clk_dm(SANDBOX_CLK_I2C_ROOT,
+              sandbox_clk_gate2("i2c_root", "i2c", base + 0x7c, 0));
+
        return 0;
 }
 
index f449de13649d2ff55a1078507e08fcf66d62a7c7..296cddfbb0ef7575a386e185c61e7af87df496a4 100644 (file)
@@ -20,6 +20,7 @@ enum {
        SANDBOX_CLK_USDHC1_SEL,
        SANDBOX_CLK_USDHC2_SEL,
        SANDBOX_CLK_I2C,
+       SANDBOX_CLK_I2C_ROOT,
 };
 
 enum sandbox_pllv3_type {
@@ -74,4 +75,6 @@ static inline struct clk *sandbox_clk_mux(const char *name, void __iomem *reg,
                                width, 0);
 }
 
+int sandbox_clk_enable_count(struct clk *clk);
+
 #endif /* __SANDBOX_CLK_H__ */
index bbc4b500e83d7985daf7cce4ea911e9d6fb759ad..ae3a4d8a76a429caee686eb5b0edc526dae660dc 100644 (file)
@@ -64,6 +64,34 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
        rate = clk_get_rate(clk);
        ut_asserteq(rate, 60000000);
 
+#if CONFIG_IS_ENABLED(CLK_CCF)
+       /* Test clk tree enable/disable */
+       ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk);
+       ut_assertok(ret);
+       ut_asserteq_str("i2c_root", clk->dev->name);
+
+       ret = clk_enable(clk);
+       ut_assertok(ret);
+
+       ret = sandbox_clk_enable_count(clk);
+       ut_asserteq(ret, 1);
+
+       ret = clk_get_by_id(SANDBOX_CLK_I2C, &pclk);
+       ut_assertok(ret);
+
+       ret = sandbox_clk_enable_count(pclk);
+       ut_asserteq(ret, 1);
+
+       ret = clk_disable(clk);
+       ut_assertok(ret);
+
+       ret = sandbox_clk_enable_count(clk);
+       ut_asserteq(ret, 0);
+
+       ret = sandbox_clk_enable_count(pclk);
+       ut_asserteq(ret, 0);
+#endif
+
        return 1;
 }