FROMLIST: clk: fix inconsistent use of req_rate

The req_rate property seems to be made to hold the rate requested through
clk_set_rate. Currently it gets initialized in clk_init to the clocks
current rate and then adapted in clk_set_rate calls. Orphan clocks and
their children get initialized to a rate of 0 and req_rate never gets
re-set when these lose their orphan-status.

Initializing req_rate to the clocks rate also is unintuitive as it just
copies the value that is already in the rate property and also looses the
information if a component actually requested a specific rate.

So separate the requested rate and only set it in clk_core_set_rate_nolock
when a real rate gets requested. The users of the req_rate __clk_put and
clk_set_rate_range that adjust a clock based on that value use req_rate
at first and fall back to rate if no rate had been requested now.

(am from https://patchwork.kernel.org/patch/8993751/)

Change-Id: I9e345e1e9d0c101d5c3c7064b6c2d2724f9eac4f
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Xing Zheng <zhengxing@rock-chips.com>
This commit is contained in:
Heiko Stuebner
2016-05-02 18:36:20 +02:00
committed by Gerrit Code Review
parent 0bc13c72ec
commit dd7fe1d5e1

View File

@@ -1520,8 +1520,10 @@ static int clk_core_set_rate_nolock(struct clk_core *core,
return 0;
/* bail early if nothing to do */
if (rate == clk_core_get_rate_nolock(core))
if (rate == clk_core_get_rate_nolock(core)) {
core->req_rate = req_rate;
return 0;
}
if ((core->flags & CLK_SET_RATE_GATE) && core->prepare_count)
return -EBUSY;
@@ -1612,9 +1614,14 @@ int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max)
clk_prepare_lock();
if (min != clk->min_rate || max != clk->max_rate) {
unsigned long rate = clk->core->req_rate;
if (!rate)
rate = clk->core->rate;
clk->min_rate = min;
clk->max_rate = max;
ret = clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
ret = clk_core_set_rate_nolock(clk->core, rate);
}
clk_prepare_unlock();
@@ -2456,7 +2463,7 @@ static int __clk_init(struct device *dev, struct clk *clk_user)
rate = core->parent->rate;
else
rate = 0;
core->rate = core->req_rate = rate;
core->rate = rate;
/*
* walk the list of orphan clocks and reparent any that are children of
@@ -2794,6 +2801,7 @@ int __clk_get(struct clk *clk)
void __clk_put(struct clk *clk)
{
unsigned long rate;
struct module *owner;
if (!clk || WARN_ON_ONCE(IS_ERR(clk)))
@@ -2802,9 +2810,13 @@ void __clk_put(struct clk *clk)
clk_prepare_lock();
hlist_del(&clk->clks_node);
if (clk->min_rate > clk->core->req_rate ||
clk->max_rate < clk->core->req_rate)
clk_core_set_rate_nolock(clk->core, clk->core->req_rate);
rate = clk->core->req_rate;
if (!rate)
rate = clk->core->rate;
if (clk->min_rate > rate || clk->max_rate < rate)
clk_core_set_rate_nolock(clk->core, rate);
owner = clk->core->owner;
kref_put(&clk->core->ref, __clk_release);