Skip to content

Commit aa87aa3

Browse files
committed
sh: clkfwk: Improve the generic clk_set_parent() implementation.
This causes the generic clk_set_parent() implementation to be a bit more intelligent. A clk_reparent() is added to move the clock over to the new parent's sibling list, which then allows the generic rate propagation code to succeed. This also becomes a nop if the new and old parents are unchanged. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent ae891a4 commit aa87aa3

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎arch/sh/include/asm/clock.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int clk_init(void);
4848
unsigned long followparent_recalc(struct clk *);
4949
void recalculate_root_clocks(void);
5050
void propagate_rate(struct clk *);
51+
int clk_reparent(struct clk *child, struct clk *parent);
5152
void clk_recalc_rate(struct clk *);
5253
int clk_register(struct clk *);
5354
void clk_unregister(struct clk *);

‎arch/sh/kernel/cpu/clock.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ unsigned long followparent_recalc(struct clk *clk)
8181
return clk->parent->rate;
8282
}
8383

84+
int clk_reparent(struct clk *child, struct clk *parent)
85+
{
86+
list_del_init(&child->sibling);
87+
if (parent)
88+
list_add(&child->sibling, &parent->children);
89+
child->parent = parent;
90+
91+
/* now do the debugfs renaming to reattach the child
92+
to the proper parent */
93+
94+
return 0;
95+
}
96+
8497
/* Propagate rate to children */
8598
void propagate_rate(struct clk *tclk)
8699
{
@@ -288,12 +301,19 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
288301

289302
if (!parent || !clk)
290303
return ret;
304+
if (clk->parent == parent)
305+
return 0;
291306

292307
spin_lock_irqsave(&clock_lock, flags);
293308
if (clk->usecount == 0) {
294309
if (clk->ops->set_parent)
295310
ret = clk->ops->set_parent(clk, parent);
311+
else
312+
ret = clk_reparent(clk, parent);
313+
296314
if (ret == 0) {
315+
pr_debug("clock: set parent of %s to %s (new rate %ld)\n",
316+
clk->name, clk->parent->name, clk->rate);
297317
if (clk->ops->recalc)
298318
clk->rate = clk->ops->recalc(clk);
299319
propagate_rate(clk);

0 commit comments

Comments
 (0)