diff options
author | Ulf Hansson <ulf.hansson@linaro.org> | 2013-03-12 15:26:02 -0400 |
---|---|---|
committer | Mike Turquette <mturquette@linaro.org> | 2013-03-19 15:58:42 -0400 |
commit | 3d6ee287a3e341c88eafd0b4620b12d640b3736b (patch) | |
tree | c5361658171613baf2437e14ac27563a43241bd3 | |
parent | 30ee400614385ac49f4c9b4bc03d77ff8f07a61e (diff) |
clk: Introduce optional is_prepared callback
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>
-rw-r--r-- | drivers/clk/clk.c | 21 | ||||
-rw-r--r-- | include/linux/clk-provider.h | 6 |
2 files changed, 27 insertions, 0 deletions
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index ed87b2405806..7571b5054f3c 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c | |||
@@ -451,6 +451,27 @@ unsigned long __clk_get_flags(struct clk *clk) | |||
451 | return !clk ? 0 : clk->flags; | 451 | return !clk ? 0 : clk->flags; |
452 | } | 452 | } |
453 | 453 | ||
454 | bool __clk_is_prepared(struct clk *clk) | ||
455 | { | ||
456 | int ret; | ||
457 | |||
458 | if (!clk) | ||
459 | return false; | ||
460 | |||
461 | /* | ||
462 | * .is_prepared is optional for clocks that can prepare | ||
463 | * fall back to software usage counter if it is missing | ||
464 | */ | ||
465 | if (!clk->ops->is_prepared) { | ||
466 | ret = clk->prepare_count ? 1 : 0; | ||
467 | goto out; | ||
468 | } | ||
469 | |||
470 | ret = clk->ops->is_prepared(clk->hw); | ||
471 | out: | ||
472 | return !!ret; | ||
473 | } | ||
474 | |||
454 | bool __clk_is_enabled(struct clk *clk) | 475 | bool __clk_is_enabled(struct clk *clk) |
455 | { | 476 | { |
456 | int ret; | 477 | int ret; |
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 7f197d7addb0..ee946862e058 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h | |||
@@ -45,6 +45,10 @@ struct clk_hw; | |||
45 | * undo any work done in the @prepare callback. Called with | 45 | * undo any work done in the @prepare callback. Called with |
46 | * prepare_lock held. | 46 | * prepare_lock held. |
47 | * | 47 | * |
48 | * @is_prepared: Queries the hardware to determine if the clock is prepared. | ||
49 | * This function is allowed to sleep. Optional, if this op is not | ||
50 | * set then the prepare count will be used. | ||
51 | * | ||
48 | * @enable: Enable the clock atomically. This must not return until the | 52 | * @enable: Enable the clock atomically. This must not return until the |
49 | * clock is generating a valid clock signal, usable by consumer | 53 | * clock is generating a valid clock signal, usable by consumer |
50 | * devices. Called with enable_lock held. This function must not | 54 | * devices. Called with enable_lock held. This function must not |
@@ -108,6 +112,7 @@ struct clk_hw; | |||
108 | struct clk_ops { | 112 | struct clk_ops { |
109 | int (*prepare)(struct clk_hw *hw); | 113 | int (*prepare)(struct clk_hw *hw); |
110 | void (*unprepare)(struct clk_hw *hw); | 114 | void (*unprepare)(struct clk_hw *hw); |
115 | int (*is_prepared)(struct clk_hw *hw); | ||
111 | int (*enable)(struct clk_hw *hw); | 116 | int (*enable)(struct clk_hw *hw); |
112 | void (*disable)(struct clk_hw *hw); | 117 | void (*disable)(struct clk_hw *hw); |
113 | int (*is_enabled)(struct clk_hw *hw); | 118 | int (*is_enabled)(struct clk_hw *hw); |
@@ -351,6 +356,7 @@ unsigned int __clk_get_enable_count(struct clk *clk); | |||
351 | unsigned int __clk_get_prepare_count(struct clk *clk); | 356 | unsigned int __clk_get_prepare_count(struct clk *clk); |
352 | unsigned long __clk_get_rate(struct clk *clk); | 357 | unsigned long __clk_get_rate(struct clk *clk); |
353 | unsigned long __clk_get_flags(struct clk *clk); | 358 | unsigned long __clk_get_flags(struct clk *clk); |
359 | bool __clk_is_prepared(struct clk *clk); | ||
354 | bool __clk_is_enabled(struct clk *clk); | 360 | bool __clk_is_enabled(struct clk *clk); |
355 | struct clk *__clk_lookup(const char *name); | 361 | struct clk *__clk_lookup(const char *name); |
356 | 362 | ||