diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 7bbb0fd..83a7234 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1423,6 +1423,9 @@ static struct clk_core *clk_propagate_rate_change(struct clk_core *core, return fail_clk; } +static int clk_core_set_rate_nolock(struct clk_core *core, + unsigned long req_rate); + /* * walk down a subtree and set the new rates notifying the rate * change on the way @@ -1438,6 +1441,7 @@ static void clk_change_rate(struct clk_core *core) old_rate = core->rate; +printk("%s: %s requested %lu, new %lu\n", __func__, core->name, core->req_rate, core->new_rate); if (core->new_parent) best_parent_rate = core->new_parent->rate; else if (core->parent) @@ -1507,6 +1511,12 @@ static void clk_change_rate(struct clk_core *core) /* handle the new child who might not be in core->children yet */ if (core->new_child) clk_change_rate(core->new_child); + + /* FIXME: add flag to limit to specific clocks? */ + if (core->req_rate && core->new_rate != old_rate) { + printk("\t\ttrying to adapt %s\n", core->name); + clk_core_set_rate_nolock(core, core->req_rate); + } } static int clk_core_set_rate_nolock(struct clk_core *core, @@ -1520,8 +1530,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 +1624,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(); @@ -2451,7 +2468,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 @@ -2798,6 +2815,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))) @@ -2806,9 +2824,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);