Skip to contentSkip to conversation

clk: ccf: fix enable_count mismatch

PATCH Applied Yang Xiwen 2 participants 5 messages Dec 15, 2023 Common clk

lore
Share & tools
lore

Yang Xiwen

author
#0 lore raw

v3 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.

[1]: https://lore.kernel.org/all/SEZPR06MB695927A6DEEEF8489A06897396A7A@SEZPR06MB6959.apcprd06.prod.outlook.com/

---
Changes in v3:
- move i2v_root in front of devm clocks. So that clk_test driver needs a minimum modification
- squash patch 1, 3 and 4. -- Suggested by Sean
- rewrite commit log for clarity.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- add missing SoB in patch 1/4, no functional change
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Yang Xiwen (2):
clk: get correct ops for clk_enable() and clk_disable()
test: dm: clk_ccf: test ccf_clk_ops

 arch/sandbox/dts/test.dts      |  4 +++-
 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 |  1 +
 test/dm/clk_ccf.c              | 14 +++++++++++---
 6 files changed, 19 insertions(+), 4 deletions(-)

---
base-commit: 3b913c148249a2b9d12ff25517ec311646e83bee
change-id: 20231111-enable_count-ad5001326815

Best regards,

Signature · 1 line
Yang Xiwen <[email protected]>
author
#1 lore raw

PATCH v3 1/2 clk: get correct ops for clk_enable() and clk_disable()

assign 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].

[1]: https://lore.kernel.org/all/SEZPR06MB695927A6DEEEF8489A06897396A7A@SEZPR06MB6959.apcprd06.prod.outlook.com/

---
 drivers/clk/clk-uclass.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/clk-uclass.c +2 -0
index 3b5e3f9c86..3e9d68feb3 100644
@@ -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
author
#2 lore raw

PATCH v3 2/2 test: dm: clk_ccf: test ccf_clk_ops

In reply to Yang Xiwen

Assign ccf_clk_ops to .ops of clk_ccf driver so that it can act as an clk provider. Also add "#clock-cells=<1>" to its device tree node.

Add "i2c_root" to clk_test in the device tree and driver for testing.

Get "i2c_root" clock in CCF unit tests and add tests for it.

---
 arch/sandbox/dts/test.dts      |  4 +++-
 arch/sandbox/include/asm/clk.h |  1 +
 drivers/clk/clk_sandbox_ccf.c  |  1 +
 drivers/clk/clk_sandbox_test.c |  1 +
 test/dm/clk_ccf.c              | 14 +++++++++++---
 5 files changed, 17 insertions(+), 4 deletions(-)
arch/sandbox/dts/test.dts +3 -1
index c7197795ef..a3a865d65c 100644
@@ -631,9 +631,10 @@
 		clocks = <&clk_fixed>,
 			 <&clk_sandbox 1>,
 			 <&clk_sandbox 0>,
+			 <&ccf 11>,
 			 <&clk_sandbox 3>,
 			 <&clk_sandbox 2>;
-		clock-names = "fixed", "i2c", "spi", "uart2", "uart1";
+		clock-names = "fixed", "i2c", "spi", "i2c_root", "uart2", "uart1";
 	};
 
 	clk-test2 {
@@ -654,6 +655,7 @@
 
 	ccf: clk-ccf {
 		compatible = "sandbox,clk-ccf";
+		#clock-cells = <1>;
 	};
 
 	efi-media {
arch/sandbox/include/asm/clk.h +1 -0
index df7156fe31..1daf2e7ac7 100644
@@ -39,6 +39,7 @@ enum sandbox_clk_test_id {
 	SANDBOX_CLK_TEST_ID_FIXED,
 	SANDBOX_CLK_TEST_ID_SPI,
 	SANDBOX_CLK_TEST_ID_I2C,
+	SANDBOX_CLK_TEST_ID_I2C_ROOT,
 	SANDBOX_CLK_TEST_ID_DEVM1,
 	SANDBOX_CLK_TEST_ID_DEVM2,
 	SANDBOX_CLK_TEST_ID_DEVM_NULL,
drivers/clk/clk_sandbox_ccf.c +1 -0
index fedcdd4044..38184e27aa 100644
@@ -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,
 };
drivers/clk/clk_sandbox_test.c +1 -0
index 5807a454f3..c695b69321 100644
@@ -15,6 +15,7 @@ static const char * const sandbox_clk_test_names[] = {
 	[SANDBOX_CLK_TEST_ID_FIXED] = "fixed",
 	[SANDBOX_CLK_TEST_ID_SPI] = "spi",
 	[SANDBOX_CLK_TEST_ID_I2C] = "i2c",
+	[SANDBOX_CLK_TEST_ID_I2C_ROOT] = "i2c_root",
 };
 
 int sandbox_clk_test_get(struct udevice *dev)
test/dm/clk_ccf.c +11 -3
index e4ebb93cda..b8be6d6572 100644
@@ -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
Reviewed-by on v3 2/2
#3 lore raw

Re: [PATCH v3 2/2] test: dm: clk_ccf: test ccf_clk_ops

Quoted 112 lines · On 12/15/23 13:28, Yang Xiwen via B4 Relay wrote:

From: Yang Xiwen <[email protected]>

Assign ccf_clk_ops to .ops of clk_ccf driver so that it can act as an clk provider. Also add "#clock-cells=<1>" to its device tree node.

Add "i2c_root" to clk_test in the device tree and driver for testing.

Get "i2c_root" clock in CCF unit tests and add tests for it.

---
  arch/sandbox/dts/test.dts      |  4 +++-
  arch/sandbox/include/asm/clk.h |  1 +
  drivers/clk/clk_sandbox_ccf.c  |  1 +
  drivers/clk/clk_sandbox_test.c |  1 +
  test/dm/clk_ccf.c              | 14 +++++++++++---
  5 files changed, 17 insertions(+), 4 deletions(-)
arch/sandbox/dts/test.dts +3 -1
index c7197795ef..a3a865d65c 100644
@@ -631,9 +631,10 @@
  		clocks = <&clk_fixed>,
  			 <&clk_sandbox 1>,
  			 <&clk_sandbox 0>,
+			 <&ccf 11>,
  			 <&clk_sandbox 3>,
  			 <&clk_sandbox 2>;
-		clock-names = "fixed", "i2c", "spi", "uart2", "uart1";
+		clock-names = "fixed", "i2c", "spi", "i2c_root", "uart2", "uart1";
  	};
 
  	clk-test2 {
@@ -654,6 +655,7 @@
 
  	ccf: clk-ccf {
  		compatible = "sandbox,clk-ccf";
+		#clock-cells = <1>;
  	};
 
  	efi-media {
arch/sandbox/include/asm/clk.h +1 -0
index df7156fe31..1daf2e7ac7 100644
@@ -39,6 +39,7 @@ enum sandbox_clk_test_id {
  	SANDBOX_CLK_TEST_ID_FIXED,
  	SANDBOX_CLK_TEST_ID_SPI,
  	SANDBOX_CLK_TEST_ID_I2C,
+	SANDBOX_CLK_TEST_ID_I2C_ROOT,
  	SANDBOX_CLK_TEST_ID_DEVM1,
  	SANDBOX_CLK_TEST_ID_DEVM2,
  	SANDBOX_CLK_TEST_ID_DEVM_NULL,
drivers/clk/clk_sandbox_ccf.c +1 -0
index fedcdd4044..38184e27aa 100644
@@ -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,
  };
drivers/clk/clk_sandbox_test.c +1 -0
index 5807a454f3..c695b69321 100644
@@ -15,6 +15,7 @@ static const char * const sandbox_clk_test_names[] = {
  	[SANDBOX_CLK_TEST_ID_FIXED] = "fixed",
  	[SANDBOX_CLK_TEST_ID_SPI] = "spi",
  	[SANDBOX_CLK_TEST_ID_I2C] = "i2c",
+	[SANDBOX_CLK_TEST_ID_I2C_ROOT] = "i2c_root",
  };
 
  int sandbox_clk_test_get(struct udevice *dev)
test/dm/clk_ccf.c +9 -2
index e4ebb93cda..b8be6d6572 100644
@@ -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);
+

test/dm/clk_ccf.c static int dm_test_clk_ccf(struct unit_test_state *uts) · line 128

Quoted 10 lines
test/dm/clk_ccf.c +2 -1
  	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);
#4 lore raw

Re: (subset) [PATCH v3 2/2] test: dm: clk_ccf: test ccf_clk_ops

In reply to Yang Xiwen
Quoted 8 lines · Yang Xiwen

Assign ccf_clk_ops to .ops of clk_ccf driver so that it can act as an clk provider. Also add "#clock-cells=<1>" to its device tree node.

Add "i2c_root" to clk_test in the device tree and driver for testing.

Get "i2c_root" clock in CCF unit tests and add tests for it.

[...]

Applied, thanks!

[2/2] test: dm: clk_ccf: test ccf_clk_ops

      https://source.denx.de/u-boot/custodians/u-boot-clk/-/commit/d30618243990

Best regards,

Signature · 1 line
Sean Anderson <[email protected]>