linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCHv2 0/2]  clk: of: add helper function to fill parent clock array
@ 2015-06-04 19:12 dinguyen
  2015-06-04 19:12 ` [RFC/PATCHv2 1/2] clk: of: helper for filling parent clock array and return num of parents dinguyen
  2015-06-04 19:12 ` [RFC/PATCHv2 2/2] clk: socfpga: make use of of_clk_parent_fill helper function dinguyen
  0 siblings, 2 replies; 6+ messages in thread
From: dinguyen @ 2015-06-04 19:12 UTC (permalink / raw)
  To: sboyd, mturquette; +Cc: dinh.linux, geert, linux-clk, linux-kernel, Dinh Nguyen

From: Dinh Nguyen <dinguyen@opensource.altera.com>

Hi,

As suggested by Stephen Boyd, this patch adds a helper function that will fill
the parent clock array.

Since the following code is sprinkled all over the platform clock drivers:

for (i = 0; i < num_parents; ++i)
        parent_names[i] = of_clk_get_parent_name(np, i);

The above code can be replace by of_clk_parent_fill(). And since the logic
of the of_clk_parent_fill is to walk the clock node to find the parent, it is
easy to just return the number of parents as well.

The second patch makes use of the new helper function in the SoCFPGA platform.
If this patch is accepted, I can go through and replace the other platforms
after that.

v2: use unsigned int for 'size'

Thanks,

Dinh Nguyen (2):
  clk: of: helper for filling parent clock array and return num of
    parents
  clk: socfpga: make use of of_clk_parent_fill helper function

 drivers/clk/clk.c              | 20 ++++++++++++++++++++
 drivers/clk/socfpga/clk-gate.c |  6 +-----
 drivers/clk/socfpga/clk-pll.c  |  7 +------
 include/linux/clk-provider.h   |  1 +
 4 files changed, 23 insertions(+), 11 deletions(-)

-- 
2.2.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [RFC/PATCHv2 1/2] clk: of: helper for filling parent clock array and return num of parents
  2015-06-04 19:12 [RFC/PATCHv2 0/2] clk: of: add helper function to fill parent clock array dinguyen
@ 2015-06-04 19:12 ` dinguyen
  2015-06-04 21:24   ` Stephen Boyd
  2015-06-04 19:12 ` [RFC/PATCHv2 2/2] clk: socfpga: make use of of_clk_parent_fill helper function dinguyen
  1 sibling, 1 reply; 6+ messages in thread
From: dinguyen @ 2015-06-04 19:12 UTC (permalink / raw)
  To: sboyd, mturquette; +Cc: dinh.linux, geert, linux-clk, linux-kernel, Dinh Nguyen

From: Dinh Nguyen <dinguyen@opensource.altera.com>

Sprinkled all through the platform clock drivers are code like this to
fill the clock parent array:

for (i = 0; i < num_parents; ++i)
	parent_names[i] = of_clk_get_parent_name(np, i);

The of_clk_parent_fill() will do the same as the code above, and while
at it, return the number of parents as well since the logic of the
function is to the walk the clock node to look for the parent.

Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
---
v2: use unsigned int for size
---
 drivers/clk/clk.c            | 20 ++++++++++++++++++++
 include/linux/clk-provider.h |  1 +
 2 files changed, 21 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 459ce9d..778bebd 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -3060,6 +3060,26 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
 }
 EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
 
+/*
+ * of_clk_parent_fill(): Helper clock function that will fill the parent
+ * clock's array and return the number of parents it found.
+ * @np: Device node pointer associated with clock provider
+ * @parents: pointer to char array that hold the parent's name
+ * @size: size of the parents array
+ *
+ * Returns number of parents for the clock node.
+ */
+int of_clk_parent_fill(struct device_node *np, const char **parents, unsigned int size)
+{
+	unsigned int i = 0;
+
+	while (i < size && (parents[i] = of_clk_get_parent_name(np, i)) != NULL)
+		i++;
+
+	return i;
+}
+EXPORT_SYMBOL(of_clk_parent_fill);
+
 struct clock_provider {
 	of_clk_init_cb_t clk_init_cb;
 	struct device_node *np;
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index df69531..3ab66d3 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -624,6 +624,7 @@ struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
 				  void *data);
 struct clk *of_clk_src_onecell_get(struct of_phandle_args *clkspec, void *data);
 int of_clk_get_parent_count(struct device_node *np);
+int of_clk_parent_fill(struct device_node *np, const char **parents, unsigned int size);
 const char *of_clk_get_parent_name(struct device_node *np, int index);
 
 void of_clk_init(const struct of_device_id *matches);
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [RFC/PATCHv2 2/2] clk: socfpga: make use of of_clk_parent_fill helper function
  2015-06-04 19:12 [RFC/PATCHv2 0/2] clk: of: add helper function to fill parent clock array dinguyen
  2015-06-04 19:12 ` [RFC/PATCHv2 1/2] clk: of: helper for filling parent clock array and return num of parents dinguyen
@ 2015-06-04 19:12 ` dinguyen
  2015-06-04 21:25   ` Stephen Boyd
  1 sibling, 1 reply; 6+ messages in thread
From: dinguyen @ 2015-06-04 19:12 UTC (permalink / raw)
  To: sboyd, mturquette; +Cc: dinh.linux, geert, linux-clk, linux-kernel, Dinh Nguyen

From: Dinh Nguyen <dinguyen@opensource.altera.com>

Use of_clk_parent_fill to fill in the parent clock's array.

Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
---
v2: none
---
 drivers/clk/socfpga/clk-gate.c | 6 +-----
 drivers/clk/socfpga/clk-pll.c  | 7 +------
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
index dd3a78c..fb5a5d7 100644
--- a/drivers/clk/socfpga/clk-gate.c
+++ b/drivers/clk/socfpga/clk-gate.c
@@ -194,7 +194,6 @@ static void __init __socfpga_gate_init(struct device_node *node,
 	const char *parent_name[SOCFPGA_MAX_PARENTS];
 	struct clk_init_data init;
 	int rc;
-	int i = 0;
 
 	socfpga_clk = kzalloc(sizeof(*socfpga_clk), GFP_KERNEL);
 	if (WARN_ON(!socfpga_clk))
@@ -238,12 +237,9 @@ static void __init __socfpga_gate_init(struct device_node *node,
 	init.name = clk_name;
 	init.ops = ops;
 	init.flags = 0;
-	while (i < SOCFPGA_MAX_PARENTS && (parent_name[i] =
-			of_clk_get_parent_name(node, i)) != NULL)
-		i++;
 
+	init.num_parents = of_clk_parent_fill(node, parent_name, SOCFPGA_MAX_PARENTS);
 	init.parent_names = parent_name;
-	init.num_parents = i;
 	socfpga_clk->hw.hw.init = &init;
 
 	clk = clk_register(NULL, &socfpga_clk->hw.hw);
diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
index de6da95..8f26b52 100644
--- a/drivers/clk/socfpga/clk-pll.c
+++ b/drivers/clk/socfpga/clk-pll.c
@@ -92,7 +92,6 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
 	struct clk_init_data init;
 	struct device_node *clkmgr_np;
 	int rc;
-	int i = 0;
 
 	of_property_read_u32(node, "reg", &reg);
 
@@ -111,11 +110,7 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
 	init.ops = ops;
 	init.flags = 0;
 
-	while (i < SOCFPGA_MAX_PARENTS && (parent_name[i] =
-			of_clk_get_parent_name(node, i)) != NULL)
-		i++;
-
-	init.num_parents = i;
+	init.num_parents = of_clk_parent_fill(node, parent_name, SOCFPGA_MAX_PARENTS);
 	init.parent_names = parent_name;
 	pll_clk->hw.hw.init = &init;
 
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCHv2 1/2] clk: of: helper for filling parent clock array and return num of parents
  2015-06-04 19:12 ` [RFC/PATCHv2 1/2] clk: of: helper for filling parent clock array and return num of parents dinguyen
@ 2015-06-04 21:24   ` Stephen Boyd
  2015-06-05 15:35     ` Dinh Nguyen
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2015-06-04 21:24 UTC (permalink / raw)
  To: dinguyen; +Cc: mturquette, dinh.linux, geert, linux-clk, linux-kernel

On 06/04, dinguyen@opensource.altera.com wrote:
> From: Dinh Nguyen <dinguyen@opensource.altera.com>
> 
> Sprinkled all through the platform clock drivers are code like this to
> fill the clock parent array:
> 
> for (i = 0; i < num_parents; ++i)
> 	parent_names[i] = of_clk_get_parent_name(np, i);
> 
> The of_clk_parent_fill() will do the same as the code above, and while
> at it, return the number of parents as well since the logic of the
> function is to the walk the clock node to look for the parent.
> 
> Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
> ---
> v2: use unsigned int for size
> ---
>  drivers/clk/clk.c            | 20 ++++++++++++++++++++
>  include/linux/clk-provider.h |  1 +
>  2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 459ce9d..778bebd 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -3060,6 +3060,26 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
>  }
>  EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
>  
> +/*

Need a double ** here for kernel doc.

> + * of_clk_parent_fill(): Helper clock function that will fill the parent
> + * clock's array and return the number of parents it found.

Please try to shorten this sentence.

	Fill @parents with names of @np's parents and return number of parents

> + * @np: Device node pointer associated with clock provider
> + * @parents: pointer to char array that hold the parent's name

s/parent's name/parents' names/ ?

> + * @size: size of the parents array
> + *
> + * Returns number of parents for the clock node.
> + */
> +int of_clk_parent_fill(struct device_node *np, const char **parents, unsigned int size)
> +{
> +	unsigned int i = 0;
> +
> +	while (i < size && (parents[i] = of_clk_get_parent_name(np, i)) != NULL)
> +		i++;
> +
> +	return i;
> +}
> +EXPORT_SYMBOL(of_clk_parent_fill);

Can this be GPL?

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCHv2 2/2] clk: socfpga: make use of of_clk_parent_fill helper function
  2015-06-04 19:12 ` [RFC/PATCHv2 2/2] clk: socfpga: make use of of_clk_parent_fill helper function dinguyen
@ 2015-06-04 21:25   ` Stephen Boyd
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2015-06-04 21:25 UTC (permalink / raw)
  To: dinguyen; +Cc: mturquette, dinh.linux, geert, linux-clk, linux-kernel

On 06/04, dinguyen@opensource.altera.com wrote:
> From: Dinh Nguyen <dinguyen@opensource.altera.com>
> 
> Use of_clk_parent_fill to fill in the parent clock's array.
> 
> Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
> ---
> v2: none
> ---
>  drivers/clk/socfpga/clk-gate.c | 6 +-----
>  drivers/clk/socfpga/clk-pll.c  | 7 +------
>  2 files changed, 2 insertions(+), 11 deletions(-)
> 

Nice consolidation!

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC/PATCHv2 1/2] clk: of: helper for filling parent clock array and return num of parents
  2015-06-04 21:24   ` Stephen Boyd
@ 2015-06-05 15:35     ` Dinh Nguyen
  0 siblings, 0 replies; 6+ messages in thread
From: Dinh Nguyen @ 2015-06-05 15:35 UTC (permalink / raw)
  To: Stephen Boyd; +Cc: mturquette, dinh.linux, geert, linux-clk, linux-kernel



On 6/4/15 4:24 PM, Stephen Boyd wrote:
> On 06/04, dinguyen@opensource.altera.com wrote:
>> From: Dinh Nguyen <dinguyen@opensource.altera.com>
>>
>> Sprinkled all through the platform clock drivers are code like this to
>> fill the clock parent array:
>>
>> for (i = 0; i < num_parents; ++i)
>> 	parent_names[i] = of_clk_get_parent_name(np, i);
>>
>> The of_clk_parent_fill() will do the same as the code above, and while
>> at it, return the number of parents as well since the logic of the
>> function is to the walk the clock node to look for the parent.
>>
>> Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
>> ---
>> v2: use unsigned int for size
>> ---
>>  drivers/clk/clk.c            | 20 ++++++++++++++++++++
>>  include/linux/clk-provider.h |  1 +
>>  2 files changed, 21 insertions(+)
>>
>> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
>> index 459ce9d..778bebd 100644
>> --- a/drivers/clk/clk.c
>> +++ b/drivers/clk/clk.c
>> @@ -3060,6 +3060,26 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
>>  }
>>  EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
>>  
>> +/*
> 
> Need a double ** here for kernel doc.
> 

Ok...

>> + * of_clk_parent_fill(): Helper clock function that will fill the parent
>> + * clock's array and return the number of parents it found.
> 
> Please try to shorten this sentence.
> 
> 	Fill @parents with names of @np's parents and return number of parents
> 
>> + * @np: Device node pointer associated with clock provider
>> + * @parents: pointer to char array that hold the parent's name
> 
> s/parent's name/parents' names/ ?
> 

Will address in v3.

>> + * @size: size of the parents array
>> + *
>> + * Returns number of parents for the clock node.
>> + */
>> +int of_clk_parent_fill(struct device_node *np, const char **parents, unsigned int size)
>> +{
>> +	unsigned int i = 0;
>> +
>> +	while (i < size && (parents[i] = of_clk_get_parent_name(np, i)) != NULL)
>> +		i++;
>> +
>> +	return i;
>> +}
>> +EXPORT_SYMBOL(of_clk_parent_fill);
> 
> Can this be GPL?
> 

Yes.

Thanks,
Dinh

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-06-05 15:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-04 19:12 [RFC/PATCHv2 0/2] clk: of: add helper function to fill parent clock array dinguyen
2015-06-04 19:12 ` [RFC/PATCHv2 1/2] clk: of: helper for filling parent clock array and return num of parents dinguyen
2015-06-04 21:24   ` Stephen Boyd
2015-06-05 15:35     ` Dinh Nguyen
2015-06-04 19:12 ` [RFC/PATCHv2 2/2] clk: socfpga: make use of of_clk_parent_fill helper function dinguyen
2015-06-04 21:25   ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).