clk: ccf: fix enable_count mismatch
cover clk: ccf: fix enable_count mismatch
As described in [1], enable_count is incremented by 2 when ccf_clk_enable() is called. This series of patch fixed this issue and added a testcase for that.
---
Yang Xiwen (4):
clk: clk_sandbox_ccf: assign ccf_clk_ops to .ops of the driver
clk: get correct ops for clk_enable() and clk_disable()
clk: clk_sandbox: get devm clock i2c_root
test: dm: clk_ccf: get "i2c_root" clock from &clk_ccf
arch/sandbox/dts/test.dts | 6 ++++-- arch/sandbox/include/asm/clk.h | 1 + drivers/clk/clk-uclass.c | 2 ++ drivers/clk/clk_sandbox_ccf.c | 1 + drivers/clk/clk_sandbox_test.c | 5 +++++ test/dm/clk_ccf.c | 14 +++++++++++--- 6 files changed, 24 insertions(+), 5 deletions(-)
---
base-commit: 3b913c148249a2b9d12ff25517ec311646e83bee
change-id: 20231111-enable_count-ad5001326815
Best regards,
Signature · 1 line
Yang Xiwen <[email protected]>
PATCH 1/4 clk: clk_sandbox_ccf: assign ccf_clk_ops to .ops of the driver
It can now act as an clk provider on which ccf_clk_ops can be tested. Also add "#clock-cells=<1>" to test.dts.
--- arch/sandbox/dts/test.dts | 1 + drivers/clk/clk_sandbox_ccf.c | 1 + 2 files changed, 2 insertions(+)
arch/sandbox/dts/test.dts +1 -0
@@ -654,6 +654,7 @@ ccf: clk-ccf { compatible = "sandbox,clk-ccf"; + #clock-cells = <1>; }; efi-media {
drivers/clk/clk_sandbox_ccf.c +1 -0
@@ -284,6 +284,7 @@ static int sandbox_clk_ccf_probe(struct udevice *dev)U_BOOT_DRIVER (sandbox_clk_ccf) = { .name ="sandbox_clk_ccf" , .id =UCLASS_CLK , + .ops = &ccf_clk_ops, .probe = sandbox_clk_ccf_probe, .of_match = sandbox_clk_ccf_test_ids, };
Signature · 1 line
2.39.2
PATCH 2/4 clk: get correct ops for clk_enable() and clk_disable()
In reply to Yang Xiwenassign clk_dev_ops(clkp->dev) to ops to ensure correct clk operations are called on clocks.
This fixes the incorrect enable_count issue as described in [1].
--- drivers/clk/clk-uclass.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clk/clk-uclass.c +2 -0
@@ -640,6 +640,7 @@ int clk_enable(struct clk *clk)if (CONFIG_IS_ENABLED (CLK_CCF )) {/* Take id 0 as a non-valid clk, such as dummy */ if (clk->id && !clk_get_by_id (clk->id, &clkp)) { + ops =clk_dev_ops (clkp->dev);if (clkp->enable_count) { clkp->enable_count++;return 0 ;
@@ -699,6 +700,7 @@ int clk_disable(struct clk *clk)if (CONFIG_IS_ENABLED (CLK_CCF )) {if (clk->id && !clk_get_by_id (clk->id, &clkp)) { + ops =clk_dev_ops (clkp->dev);if (clkp->flags &CLK_IS_CRITICAL )return 0 ;
Signature · 1 line
2.39.2
PATCH 3/4 clk: clk_sandbox: get devm clock i2c_root
In reply to Yang XiwenThis clock is added to dts. Get it in the devm group in the driver or the testcases will fail.
--- arch/sandbox/dts/test.dts | 5 +++-- arch/sandbox/include/asm/clk.h | 1 + drivers/clk/clk_sandbox_test.c | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-)
arch/sandbox/dts/test.dts +3 -2
@@ -632,8 +632,9 @@ <&clk_sandbox 1>, <&clk_sandbox 0>, <&clk_sandbox 3>, - <&clk_sandbox 2>; - clock-names = "fixed", "i2c", "spi", "uart2", "uart1"; + <&clk_sandbox 2>, + <&ccf 11>; + clock-names = "fixed", "i2c", "spi", "uart2", "uart1", "i2c_root"; }; clk-test2 {
arch/sandbox/include/asm/clk.h +1 -0
@@ -41,6 +41,7 @@ enum sandbox_clk_test_id {SANDBOX_CLK_TEST_ID_I2C ,SANDBOX_CLK_TEST_ID_DEVM1 ,SANDBOX_CLK_TEST_ID_DEVM2 , +SANDBOX_CLK_TEST_ID_I2C_ROOT ,SANDBOX_CLK_TEST_ID_DEVM_NULL , SANDBOX_CLK_TEST_ID_COUNT,
drivers/clk/clk_sandbox_test.c +5 -0
@@ -53,6 +53,11 @@ int sandbox_clk_test_devm_get(struct udevice *dev)return PTR_ERR (clk); sbct->clkps[SANDBOX_CLK_TEST_ID_DEVM2 ] = clk; + clk =devm_clk_get_optional (dev,"i2c_root" ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + sbct->clkps[SANDBOX_CLK_TEST_ID_I2C_ROOT ] = clk; + sbct->clkps[SANDBOX_CLK_TEST_ID_DEVM_NULL ] =NULL ; clk =devm_clk_get_optional (dev,"not_an_existing_clock" );if (IS_ERR (clk))
Signature · 1 line
2.39.2
PATCH 4/4 test: dm: clk_ccf: get "i2c_root" clock from &clk_ccf
In reply to Yang Xiwenget i2c_root clock from device tree. In this way we get an CCF clock and also test ccf_clk_ops.
--- test/dm/clk_ccf.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
test/dm/clk_ccf.c +11 -3
@@ -18,8 +18,8 @@/* Tests for Common Clock Framework driver */ static int dm_test_clk_ccf (struct unit_test_state *uts) { -struct clk *clk, *pclk; -struct udevice *dev; +struct clk *clk, *pclk, clk_ccf; +struct udevice *dev, *test_dev;long long rate;int ret;#if CONFIG_IS_ENABLED (CLK_CCF )
@@ -29,6 +29,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)/* Get the device using the clk device */ ut_assertok (uclass_get_device_by_name (UCLASS_CLK ,"clk-ccf" , &dev)); +ut_assertok (uclass_get_device_by_name (UCLASS_MISC ,"clk-test" , &test_dev));/* Test for clk_get_by_id() */ ret =clk_get_by_id (SANDBOX_CLK_ECSPI_ROOT , &clk);
@@ -110,11 +111,18 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)#if CONFIG_IS_ENABLED (CLK_CCF )/* Test clk tree enable/disable */ + + ret =clk_get_by_index (test_dev,SANDBOX_CLK_TEST_ID_I2C_ROOT , &clk_ccf); +ut_assertok (ret); +ut_asserteq_str ("clk-ccf" , clk_ccf.dev->name); +ut_asserteq (clk_ccf.id,SANDBOX_CLK_I2C_ROOT ); + ret =clk_get_by_id (SANDBOX_CLK_I2C_ROOT , &clk);ut_assertok (ret);ut_asserteq_str ("i2c_root" , clk->dev->name); +ut_asserteq (clk->id,SANDBOX_CLK_I2C_ROOT ); - ret =clk_enable (clk); + ret =clk_enable (&clk_ccf);ut_assertok (ret); ret =sandbox_clk_enable_count (clk);
Signature · 1 line
2.39.2