[PATCH v3 04/21] clk: do not disable clock if it is critical

Claudiu Beznea claudiu.beznea at microchip.com
Mon Sep 7 16:46:35 CEST 2020


Do not disable clock if it is a critical one.

Signed-off-by: Claudiu Beznea <claudiu.beznea at microchip.com>
Reviewed-by: Simon Glass <sjg at chromium.org>
---
 drivers/clk/clk-uclass.c |  3 +++
 test/dm/clk_ccf.c        | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 5e0c8419d65b..b8538f342a0c 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -606,6 +606,9 @@ int clk_disable(struct clk *clk)
 
 	if (CONFIG_IS_ENABLED(CLK_CCF)) {
 		if (clk->id && !clk_get_by_id(clk->id, &clkp)) {
+			if (clkp->flags & CLK_IS_CRITICAL)
+				return 0;
+
 			if (clkp->enable_count == 0) {
 				printf("clk %s already disabled\n",
 				       clkp->dev->name);
diff --git a/test/dm/clk_ccf.c b/test/dm/clk_ccf.c
index 1ce28d747dbe..e4ebb93cdad4 100644
--- a/test/dm/clk_ccf.c
+++ b/test/dm/clk_ccf.c
@@ -24,7 +24,7 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
 	int ret;
 #if CONFIG_IS_ENABLED(CLK_CCF)
 	const char *clkname;
-	int clkid;
+	int clkid, i;
 #endif
 
 	/* Get the device using the clk device */
@@ -157,6 +157,36 @@ static int dm_test_clk_ccf(struct unit_test_state *uts)
 	pclk = clk_get_parent(clk);
 	ut_assertok_ptr(pclk);
 	ut_asserteq_str(clkname, pclk->dev->name);
+
+	/* Test disabling critical clock. */
+	ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk);
+	ut_assertok(ret);
+	ut_asserteq_str("i2c_root", clk->dev->name);
+
+	/* Disable it, if any. */
+	ret = sandbox_clk_enable_count(clk);
+	for (i = 0; i < ret; i++) {
+		ret = clk_disable(clk);
+		ut_assertok(ret);
+	}
+
+	ret = sandbox_clk_enable_count(clk);
+	ut_asserteq(ret, 0);
+
+	clk->flags = CLK_IS_CRITICAL;
+	ret = clk_enable(clk);
+	ut_assertok(ret);
+
+	ret = clk_disable(clk);
+	ut_assertok(ret);
+	ret = sandbox_clk_enable_count(clk);
+	ut_asserteq(ret, 1);
+	clk->flags &= ~CLK_IS_CRITICAL;
+
+	ret = clk_disable(clk);
+	ut_assertok(ret);
+	ret = sandbox_clk_enable_count(clk);
+	ut_asserteq(ret, 0);
 #endif
 
 	return 1;
-- 
2.7.4



More information about the U-Boot mailing list