From e6500344edbbc405cde8d20a9c0d165a4efa9142 Mon Sep 17 00:00:00 2001 From: Heiko Stuebner Date: Wed, 22 Apr 2015 22:53:05 +0200 Subject: [PATCH] clk: track the orphan status of clocks and their children While children of orphan clocks are not carried in the orphan-list itself, they're nevertheless orphans in their own right as they also don't have an input-rate available. To ease tracking if a clock is an orphan or has an orphan in its parent path introduce an orphan field into struct clk and update it and the fields in child-clocks when a clock gets added or removed from the orphan-list. Suggested-by: Stephen Boyd Signed-off-by: Heiko Stuebner Cc: Boris Brezillon Cc: Alex Elder Cc: Alexandre Belloni Cc: Stephen Warren Cc: Max Filippov Cc: kernel@pengutronix.de Cc: Zhangfei Gao Cc: Santosh Shilimkar Cc: Chao Xie Cc: Jason Cooper Cc: Stefan Wahren Cc: Andrew Bresticker Cc: Robert Jarzmik Cc: Georgi Djakov Cc: Sylwester Nawrocki Cc: Geert Uytterhoeven Cc: Barry Song Cc: Dinh Nguyen Cc: Viresh Kumar Cc: Gabriel FERNANDEZ Cc: emilio@elopez.com.ar Cc: Peter De Schrijver Cc: Tero Kristo Cc: Ulf Hansson Cc: Pawel Moll Cc: Michal Simek [sboyd@codeaurora.org: s/clk/core/ in new function] Signed-off-by: Stephen Boyd --- drivers/clk/clk.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 898052ee0efa..4912c2e55e2c 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -57,6 +57,7 @@ struct clk_core { struct clk_core *new_parent; struct clk_core *new_child; unsigned long flags; + bool orphan; unsigned int enable_count; unsigned int prepare_count; unsigned long min_rate; @@ -1091,18 +1092,40 @@ static int clk_fetch_parent_index(struct clk_core *core, return -EINVAL; } +/* + * Update the orphan status of @core and all its children. + */ +static void clk_core_update_orphan_status(struct clk_core *core, bool is_orphan) +{ + struct clk_core *child; + + core->orphan = is_orphan; + + hlist_for_each_entry(child, &core->children, child_node) + clk_core_update_orphan_status(child, is_orphan); +} + static void clk_reparent(struct clk_core *core, struct clk_core *new_parent) { + bool was_orphan = core->orphan; + hlist_del(&core->child_node); if (new_parent) { + bool becomes_orphan = new_parent->orphan; + /* avoid duplicate POST_RATE_CHANGE notifications */ if (new_parent->new_child == core) new_parent->new_child = NULL; hlist_add_head(&core->child_node, &new_parent->children); + + if (was_orphan != becomes_orphan) + clk_core_update_orphan_status(core, becomes_orphan); } else { hlist_add_head(&core->child_node, &clk_orphan_list); + if (!was_orphan) + clk_core_update_orphan_status(core, true); } core->parent = new_parent; @@ -2359,13 +2382,17 @@ static int __clk_init(struct device *dev, struct clk *clk_user) * clocks and re-parent any that are children of the clock currently * being clk_init'd. */ - if (core->parent) + if (core->parent) { hlist_add_head(&core->child_node, &core->parent->children); - else if (core->flags & CLK_IS_ROOT) + core->orphan = core->parent->orphan; + } else if (core->flags & CLK_IS_ROOT) { hlist_add_head(&core->child_node, &clk_root_list); - else + core->orphan = false; + } else { hlist_add_head(&core->child_node, &clk_orphan_list); + core->orphan = true; + } /* * Set clk's accuracy. The preferred method is to use -- 2.20.1