clk: introduce CLK_ENABLE_HAND_OFF flag
Some clocks are critical to system operation (e.g. cpu, memory, etc) and should not be gated until a driver that knows best claims such a clock and expressly gates that clock through the normal clk.h api. The typical way to handle this is for the clk driver or some other early code to call clk_prepare_enable on this important clock as soon as it is registered and before the clk_disable_unused garbage collector kicks in. This patch introduces a formal way to handle this scenario that is provided by the clk framework. Clk driver authors can set the CLK_ENABLE_HAND_OFF flag in their clk data, which will cause the clk to be enabled in clk_register(). Then when the first clk consumer driver comes along and calls clk_get() & clk_prepare_enable(), the reference counts taken during clk registration are transfered (or handed off) to the clk consumer. At this point handling the clk is the same as any other clock which as not set the new CLK_ENABLE_HAND_OFF flag. In fact no changes to any clock consumer driver are needed for this to work. Change-Id: Ib5247f6bceb1f555c03103f061af089755b2de62 Signed-off-by: Michael Turquette <mturquette@baylibre.com> Patch-mainline: patchwork.kernel.org @ 02/11/16, 9:19 Signed-off-by: Taniya Das <tdas@codeaurora.org>
This commit is contained in:
parent
83134d5df1
commit
d8d0e55ed1
2 changed files with 58 additions and 2 deletions
|
@ -71,6 +71,8 @@ struct clk_core {
|
|||
bool orphan;
|
||||
unsigned int enable_count;
|
||||
unsigned int prepare_count;
|
||||
bool need_handoff_enable;
|
||||
bool need_handoff_prepare;
|
||||
unsigned long min_rate;
|
||||
unsigned long max_rate;
|
||||
unsigned long accuracy;
|
||||
|
@ -925,15 +927,29 @@ static int clk_core_prepare(struct clk_core *core)
|
|||
*/
|
||||
int clk_prepare(struct clk *clk)
|
||||
{
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
if (!clk)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* setting CLK_ENABLE_HAND_OFF flag triggers this conditional
|
||||
*
|
||||
* need_handoff_prepare implies this clk was already prepared by
|
||||
* __clk_init. now we have a proper user, so unset the flag in our
|
||||
* internal bookkeeping. See CLK_ENABLE_HAND_OFF flag in clk-provider.h
|
||||
* for details.
|
||||
*/
|
||||
if (clk->core->need_handoff_prepare) {
|
||||
clk->core->need_handoff_prepare = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
clk_prepare_lock();
|
||||
ret = clk_core_prepare(clk->core);
|
||||
clk_prepare_unlock();
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(clk_prepare);
|
||||
|
@ -1040,15 +1056,29 @@ static int clk_core_enable(struct clk_core *core)
|
|||
int clk_enable(struct clk *clk)
|
||||
{
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
int ret = 0;
|
||||
|
||||
if (!clk)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* setting CLK_ENABLE_HAND_OFF flag triggers this conditional
|
||||
*
|
||||
* need_handoff_enable implies this clk was already enabled by
|
||||
* __clk_init. now we have a proper user, so unset the flag in our
|
||||
* internal bookkeeping. See CLK_ENABLE_HAND_OFF flag in clk-provider.h
|
||||
* for details.
|
||||
*/
|
||||
if (clk->core->need_handoff_enable) {
|
||||
clk->core->need_handoff_enable = false;
|
||||
goto out;
|
||||
}
|
||||
|
||||
flags = clk_enable_lock();
|
||||
ret = clk_core_enable(clk->core);
|
||||
clk_enable_unlock(flags);
|
||||
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(clk_enable);
|
||||
|
@ -3146,6 +3176,29 @@ static int __clk_init(struct device *dev, struct clk *clk_user)
|
|||
clk_enable_unlock(flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* enable clocks with the CLK_ENABLE_HAND_OFF flag set
|
||||
*
|
||||
* This flag causes the framework to enable the clock at registration
|
||||
* time, which is sometimes necessary for clocks that would cause a
|
||||
* system crash when gated (e.g. cpu, memory, etc). The prepare_count
|
||||
* is migrated over to the first clk consumer to call clk_prepare().
|
||||
* Similarly the clk's enable_count is migrated to the first consumer
|
||||
* to call clk_enable().
|
||||
*/
|
||||
if (core->flags & CLK_ENABLE_HAND_OFF) {
|
||||
unsigned long flags;
|
||||
|
||||
core->need_handoff_prepare = true;
|
||||
core->need_handoff_enable = true;
|
||||
ret = clk_core_prepare(core);
|
||||
if (ret)
|
||||
goto out;
|
||||
flags = clk_enable_lock();
|
||||
clk_core_enable(core);
|
||||
clk_enable_unlock(flags);
|
||||
}
|
||||
|
||||
kref_init(&core->ref);
|
||||
out:
|
||||
clk_prepare_unlock();
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
#define CLK_GET_ACCURACY_NOCACHE BIT(8) /* do not use the cached clk accuracy */
|
||||
#define CLK_RECALC_NEW_RATES BIT(9) /* recalc rates after notifications */
|
||||
#define CLK_IS_CRITICAL BIT(11) /* do not gate, ever */
|
||||
#define CLK_ENABLE_HAND_OFF BIT(12) /* enable clock when registered.
|
||||
hand-off enable_count & prepare_count
|
||||
to first consumer that enables clk */
|
||||
#define CLK_IS_MEASURE BIT(14) /* measure clock */
|
||||
|
||||
struct clk;
|
||||
|
|
Loading…
Add table
Reference in a new issue