Skip to content

Commit 51f661e

Browse files
tmlindbebarino
authored andcommitted
clk: ti: Add ti_find_clock_provider() to use clock-output-names
Let's add ti_find_clock_provider() so we can use clock-output-names to name the clock provider instead of relying on non-standard devicetree node names. Signed-off-by: Tony Lindgren <tony@atomide.com> Link: https://lore.kernel.org/r/20220204071449.16762-5-tony@atomide.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 274d679 commit 51f661e

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

drivers/clk/ti/clk.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,51 @@ int ti_clk_setup_ll_ops(struct ti_clk_ll_ops *ops)
119119
return 0;
120120
}
121121

122+
/*
123+
* Eventually we could standardize to using '_' for clk-*.c files to follow the
124+
* TRM naming and leave out the tmp name here.
125+
*/
126+
static struct device_node *ti_find_clock_provider(struct device_node *from,
127+
const char *name)
128+
{
129+
struct device_node *np;
130+
bool found = false;
131+
const char *n;
132+
char *tmp;
133+
134+
tmp = kstrdup(name, GFP_KERNEL);
135+
if (!tmp)
136+
return NULL;
137+
strreplace(tmp, '-', '_');
138+
139+
/* Node named "clock" with "clock-output-names" */
140+
for_each_of_allnodes_from(from, np) {
141+
if (of_property_read_string_index(np, "clock-output-names",
142+
0, &n))
143+
continue;
144+
145+
if (!strncmp(n, tmp, strlen(tmp))) {
146+
found = true;
147+
break;
148+
}
149+
}
150+
of_node_put(from);
151+
kfree(tmp);
152+
153+
if (found)
154+
return np;
155+
156+
/* Fall back to using old node name base provider name */
157+
return of_find_node_by_name(from, name);
158+
}
159+
122160
/**
123161
* ti_dt_clocks_register - register DT alias clocks during boot
124162
* @oclks: list of clocks to register
125163
*
126164
* Register alias or non-standard DT clock entries during boot. By
127-
* default, DT clocks are found based on their node name. If any
165+
* default, DT clocks are found based on their clock-output-names
166+
* property, or the clock node name for legacy cases. If any
128167
* additional con-id / dev-id -> clock mapping is required, use this
129168
* function to list these.
130169
*/
@@ -168,7 +207,7 @@ void __init ti_dt_clocks_register(struct ti_dt_clk oclks[])
168207
if (num_args && clkctrl_nodes_missing)
169208
continue;
170209

171-
node = of_find_node_by_name(NULL, buf);
210+
node = ti_find_clock_provider(NULL, buf);
172211
if (num_args && compat_mode) {
173212
parent = node;
174213
child = of_get_child_by_name(parent, "clock");

0 commit comments

Comments
 (0)