Skip to content

Commit

Permalink
clk: Cache core in clk_fetch_parent_index() without names
Browse files Browse the repository at this point in the history
If a clk has specified parents via clk_hw pointers it won't specify the
globally unique names for the parents. Without the unique names, we
can't fallback to comparing them against the name of the 'parent'
pointer here. Therefore, do a pointer comparison against the clk_hw
pointers too and cache the clk_core structure if they match. This fixes
parent lookup code for clks that only specify clk_hw pointers and
nothing else, like muxes that are purely inside a clk controller.

Similarly, if the parent pointer isn't cached after trying to match
clk_core or clk_hw pointers, lookup the pointer from DT or via clkdev
lookups instead of relying purely on the globally unique clk name match.
This should allow us to move away from having to specify global names
for clk parents entirely.

While we're in the area, add some comments so it's clearer what's going
on. The if statements don't lend themselves to much clarity in their raw
form.

Fixes: fc0c209 ("clk: Allow parents to be specified without string names")
Reported-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
  • Loading branch information
Stephen Boyd committed May 3, 2019
1 parent e4818d6 commit 1a07956
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions drivers/clk/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ static struct clk_core *clk_core_lookup(const char *name)
/**
* clk_core_get - Find the clk_core parent of a clk
* @core: clk to find parent of
* @name: name to search for (if string based)
* @index: index to use for search (if DT index based)
* @p_index: parent index to search for
*
* This is the preferred method for clk providers to find the parent of a
* clk when that parent is external to the clk controller. The parent_names
Expand Down Expand Up @@ -360,9 +359,10 @@ static struct clk_core *clk_core_lookup(const char *name)
* provider knows about the clk but it isn't provided on this system.
* A valid clk_core pointer when the clk can be found in the provider.
*/
static struct clk_core *clk_core_get(struct clk_core *core, const char *name,
int index)
static struct clk_core *clk_core_get(struct clk_core *core, u8 p_index)
{
const char *name = core->parents[p_index].fw_name;
int index = core->parents[p_index].index;
struct clk_hw *hw = ERR_PTR(-ENOENT);
struct device *dev = core->dev;
const char *dev_id = dev ? dev_name(dev) : NULL;
Expand Down Expand Up @@ -400,7 +400,7 @@ static void clk_core_fill_parent_index(struct clk_core *core, u8 index)
if (!parent)
parent = ERR_PTR(-EPROBE_DEFER);
} else {
parent = clk_core_get(core, entry->fw_name, entry->index);
parent = clk_core_get(core, index);
if (IS_ERR(parent) && PTR_ERR(parent) == -ENOENT)
parent = clk_core_lookup(entry->name);
}
Expand Down Expand Up @@ -1612,20 +1612,37 @@ static int clk_fetch_parent_index(struct clk_core *core,
return -EINVAL;

for (i = 0; i < core->num_parents; i++) {
/* Found it first try! */
if (core->parents[i].core == parent)
return i;

/* Something else is here, so keep looking */
if (core->parents[i].core)
continue;

/* Fallback to comparing globally unique names */
if (!strcmp(parent->name, core->parents[i].name)) {
core->parents[i].core = parent;
return i;
/* Maybe core hasn't been cached but the hw is all we know? */
if (core->parents[i].hw) {
if (core->parents[i].hw == parent->hw)
break;

/* Didn't match, but we're expecting a clk_hw */
continue;
}

/* Maybe it hasn't been cached (clk_set_parent() path) */
if (parent == clk_core_get(core, i))
break;

/* Fallback to comparing globally unique names */
if (!strcmp(parent->name, core->parents[i].name))
break;
}

return -EINVAL;
if (i == core->num_parents)
return -EINVAL;

core->parents[i].core = parent;
return i;
}

/*
Expand Down

0 comments on commit 1a07956

Please sign in to comment.