Commit 4da37821 authored by Russell King's avatar Russell King Committed by Russell King

[ARM] omap: clk_set_parent: deny changing parent if clock is enabled

Richard Woodruff writes:
| The historic usage of this has been against single use leaf clocks
| (1st instance of gptimer).  When it was used it did:
|       clk_get()
|       clk_set_parent()
|       clk_enable()
|
| This usage was ok for that. Use on a disabled clock is needed.
|
| If there are multiple users on the clock or it is enabled there are
| problems.
|
| The call can still be unfriendly if 2 different drivers are using the
| clock with their own clock get/enable. It might be the function should
| return an error if usecount != 0 to stop surprises.  It is all around
| better if the parenting is done when the clock is off.

This is a good reason to ensure that the clock is not enabled when
clk_set_parent() is called.
Acked-by: default avatarRichard Woodruff <r-woodruff2@ti.com>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 7aec53ac
...@@ -807,9 +807,6 @@ int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent) ...@@ -807,9 +807,6 @@ int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent)
if (!parent_div) if (!parent_div)
return -EINVAL; return -EINVAL;
if (clk->usecount > 0)
_omap2_clk_disable(clk);
/* Set new source value (previous dividers if any in effect) */ /* Set new source value (previous dividers if any in effect) */
v = __raw_readl(clk->clksel_reg); v = __raw_readl(clk->clksel_reg);
v &= ~clk->clksel_mask; v &= ~clk->clksel_mask;
...@@ -819,9 +816,6 @@ int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent) ...@@ -819,9 +816,6 @@ int omap2_clk_set_parent(struct clk *clk, struct clk *new_parent)
_omap2xxx_clk_commit(clk); _omap2xxx_clk_commit(clk);
if (clk->usecount > 0)
_omap2_clk_enable(clk);
clk_reparent(clk, new_parent); clk_reparent(clk, new_parent);
/* CLKSEL clocks follow their parents' rates, divided by a divisor */ /* CLKSEL clocks follow their parents' rates, divided by a divisor */
......
...@@ -144,13 +144,16 @@ int clk_set_parent(struct clk *clk, struct clk *parent) ...@@ -144,13 +144,16 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
return ret; return ret;
spin_lock_irqsave(&clockfw_lock, flags); spin_lock_irqsave(&clockfw_lock, flags);
if (arch_clock->clk_set_parent) if (clk->usecount == 0) {
ret = arch_clock->clk_set_parent(clk, parent); if (arch_clock->clk_set_parent)
if (ret == 0) { ret = arch_clock->clk_set_parent(clk, parent);
if (clk->recalc) if (ret == 0) {
clk->rate = clk->recalc(clk); if (clk->recalc)
propagate_rate(clk); clk->rate = clk->recalc(clk);
} propagate_rate(clk);
}
} else
ret = -EBUSY;
spin_unlock_irqrestore(&clockfw_lock, flags); spin_unlock_irqrestore(&clockfw_lock, flags);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment