clk: Provide option for clk_get_rate to issue hw for new rate
authorUlf Hansson <ulf.hansson@linaro.org>
Fri, 31 Aug 2012 12:21:28 +0000 (14:21 +0200)
committerMike Turquette <mturquette@linaro.org>
Fri, 7 Sep 2012 00:56:22 +0000 (17:56 -0700)
By using CLK_GET_RATE_NOCACHE flag, we tell the clk_get_rate API to
issue the hw for an updated clock rate. This can be used for a clock
which rate may be updated without a client necessary modifying it.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Mike Turquette <mturquette@linaro.org>
drivers/clk/clk.c
include/linux/clk-provider.h

index efdfd009c2701a40b18a7ec8025ce7500fb98c53..d9cbae06549f954611f864c7b8029908463535ea 100644 (file)
@@ -557,25 +557,6 @@ int clk_enable(struct clk *clk)
 }
 EXPORT_SYMBOL_GPL(clk_enable);
 
-/**
- * clk_get_rate - return the rate of clk
- * @clk: the clk whose rate is being returned
- *
- * Simply returns the cached rate of the clk.  Does not query the hardware.  If
- * clk is NULL then returns 0.
- */
-unsigned long clk_get_rate(struct clk *clk)
-{
-       unsigned long rate;
-
-       mutex_lock(&prepare_lock);
-       rate = __clk_get_rate(clk);
-       mutex_unlock(&prepare_lock);
-
-       return rate;
-}
-EXPORT_SYMBOL_GPL(clk_get_rate);
-
 /**
  * __clk_round_rate - round the given rate for a clk
  * @clk: round the rate of this clock
@@ -701,6 +682,30 @@ static void __clk_recalc_rates(struct clk *clk, unsigned long msg)
                __clk_recalc_rates(child, msg);
 }
 
+/**
+ * clk_get_rate - return the rate of clk
+ * @clk: the clk whose rate is being returned
+ *
+ * Simply returns the cached rate of the clk, unless CLK_GET_RATE_NOCACHE flag
+ * is set, which means a recalc_rate will be issued.
+ * If clk is NULL then returns 0.
+ */
+unsigned long clk_get_rate(struct clk *clk)
+{
+       unsigned long rate;
+
+       mutex_lock(&prepare_lock);
+
+       if (clk && (clk->flags & CLK_GET_RATE_NOCACHE))
+               __clk_recalc_rates(clk, 0);
+
+       rate = __clk_get_rate(clk);
+       mutex_unlock(&prepare_lock);
+
+       return rate;
+}
+EXPORT_SYMBOL_GPL(clk_get_rate);
+
 /**
  * __clk_speculate_rates
  * @clk: first clk in the subtree
index 77335fac943e74b2ca7748ec74665657d828572f..1b15307cd466882f3579c156b99d73885a85e7a3 100644 (file)
@@ -26,6 +26,7 @@
 #define CLK_IGNORE_UNUSED      BIT(3) /* do not gate even if unused */
 #define CLK_IS_ROOT            BIT(4) /* root clk, has no parent */
 #define CLK_IS_BASIC           BIT(5) /* Basic clk, can't do a to_clk_foo() */
+#define CLK_GET_RATE_NOCACHE   BIT(6) /* do not use the cached clk rate */
 
 struct clk_hw;