]> Pileus Git - ~andy/linux/commitdiff
clk: Introduce optional is_prepared callback
authorUlf Hansson <ulf.hansson@linaro.org>
Tue, 12 Mar 2013 19:26:02 +0000 (20:26 +0100)
committerMike Turquette <mturquette@linaro.org>
Tue, 19 Mar 2013 19:58:42 +0000 (12:58 -0700)
To reflect whether a clk_hw is prepared the clk_hw may implement
the optional is_prepared callback. If not implemented we fall back
to use the software prepare counter.

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

index ed87b2405806f6a80f24b607be5d23ccc922ce26..7571b5054f3cebce0375d1451701e96dea551d75 100644 (file)
@@ -451,6 +451,27 @@ unsigned long __clk_get_flags(struct clk *clk)
        return !clk ? 0 : clk->flags;
 }
 
+bool __clk_is_prepared(struct clk *clk)
+{
+       int ret;
+
+       if (!clk)
+               return false;
+
+       /*
+        * .is_prepared is optional for clocks that can prepare
+        * fall back to software usage counter if it is missing
+        */
+       if (!clk->ops->is_prepared) {
+               ret = clk->prepare_count ? 1 : 0;
+               goto out;
+       }
+
+       ret = clk->ops->is_prepared(clk->hw);
+out:
+       return !!ret;
+}
+
 bool __clk_is_enabled(struct clk *clk)
 {
        int ret;
index 7f197d7addb0be18141a66ad225135b9b0730b24..ee946862e058a79df89a7f22a5fdfad7b6607041 100644 (file)
@@ -45,6 +45,10 @@ struct clk_hw;
  *             undo any work done in the @prepare callback. Called with
  *             prepare_lock held.
  *
+ * @is_prepared: Queries the hardware to determine if the clock is prepared.
+ *             This function is allowed to sleep. Optional, if this op is not
+ *             set then the prepare count will be used.
+ *
  * @enable:    Enable the clock atomically. This must not return until the
  *             clock is generating a valid clock signal, usable by consumer
  *             devices. Called with enable_lock held. This function must not
@@ -108,6 +112,7 @@ struct clk_hw;
 struct clk_ops {
        int             (*prepare)(struct clk_hw *hw);
        void            (*unprepare)(struct clk_hw *hw);
+       int             (*is_prepared)(struct clk_hw *hw);
        int             (*enable)(struct clk_hw *hw);
        void            (*disable)(struct clk_hw *hw);
        int             (*is_enabled)(struct clk_hw *hw);
@@ -351,6 +356,7 @@ unsigned int __clk_get_enable_count(struct clk *clk);
 unsigned int __clk_get_prepare_count(struct clk *clk);
 unsigned long __clk_get_rate(struct clk *clk);
 unsigned long __clk_get_flags(struct clk *clk);
+bool __clk_is_prepared(struct clk *clk);
 bool __clk_is_enabled(struct clk *clk);
 struct clk *__clk_lookup(const char *name);