diff mbox

[10/10] clk: move CLK_SET_RATE_GATE protection from prepare to enable

Message ID 20170518163804.14123-11-jbrunet@baylibre.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jerome Brunet May 18, 2017, 4:38 p.m. UTC
CLK_SET_RATE_GATE name suggest that the rate can be set when the provider
is gated (disabled). With the current implementation, the rate can only be
set when the provider is unprepared, while it should be allowed to set a
prepared and disable provider.
Fix this by moving the rate protection mechanism in the enable/disable
core functions

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
 drivers/clk/clk.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 1db3ad28dd85..3e2eb21ca8cd 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -491,9 +491,6 @@  static void clk_core_unprepare(struct clk_core *core)
 	if (WARN_ON(core->prepare_count == 1 && core->flags & CLK_IS_CRITICAL))
 		return;
 
-	if (core->flags & CLK_SET_RATE_GATE)
-		clk_core_rate_unprotect(core);
-
 	if (--core->prepare_count > 0)
 		return;
 
@@ -564,14 +561,6 @@  static int clk_core_prepare(struct clk_core *core)
 
 	core->prepare_count++;
 
-	/*
-	 * CLK_SET_RATE_GATE is a special case of clock protection
-	 * Instead of a consumer protection, the provider is protecting
-	 * itself when prepared
-	 */
-	if (core->flags & CLK_SET_RATE_GATE)
-		clk_core_rate_protect(core);
-
 	return 0;
 }
 
@@ -716,6 +705,9 @@  static void clk_core_disable(struct clk_core *core)
 	if (WARN_ON(core->enable_count == 1 && core->flags & CLK_IS_CRITICAL))
 		return;
 
+	if (core->flags & CLK_SET_RATE_GATE)
+		clk_core_rate_unprotect(core);
+
 	if (--core->enable_count > 0)
 		return;
 
@@ -791,6 +783,15 @@  static int clk_core_enable(struct clk_core *core)
 	}
 
 	core->enable_count++;
+
+	/*
+	 * CLK_SET_RATE_GATE is a special case of clock protection
+	 * Instead of a consumer protection, the provider is protecting
+	 * itself when enabled
+	 */
+	if (core->flags & CLK_SET_RATE_GATE)
+		clk_core_rate_protect(core);
+
 	return 0;
 }