All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-10 17:42 ` Gregory CLEMENT
  0 siblings, 0 replies; 17+ messages in thread
From: Gregory CLEMENT @ 2014-02-10 17:42 UTC (permalink / raw)
  To: Mike Turquette
  Cc: linux-kernel, Jason Cooper, Andrew Lunn, Gregory CLEMENT,
	Thomas Petazzoni, Ezequiel Garcia, Sebastian Hesselbarth,
	linux-arm-kernel

Until now the clock providers were initialized in the order found in
the device tree. This led to have the dependencies between the clocks
not respected: children clocks could be initialized before their
parent clocks.

Instead of forcing each platform to manage its own initialization order,
this patch adds this work inside the framework itself.

Using the data of the device tree the of_clk_init function now delayed
the initialization of a clock provider if its parent provider was not
ready yet.

The strict dependency check (all parents of a given clk must be
initialized) was added by Boris BREZILLON

Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
---

Since the v1, I have merged the  strict dependency check from Boris.
And of course tested on my Armada 370 and Armada XP based board

 drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 106 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 5517944495d8..684976993297 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2526,24 +2526,127 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
 }
 EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
 
+struct clock_provider {
+	of_clk_init_cb_t clk_init_cb;
+	struct device_node *np;
+	struct list_head node;
+};
+
+static LIST_HEAD(clk_provider_list);
+
+/*
+ * This function looks for a parent clock. If there is one, then it
+ * checks that the provider for this parent clock was initialized, in
+ * this case the parent clock will be ready.
+ */
+static int parent_ready(struct device_node *np)
+{
+	struct of_phandle_args clkspec;
+	struct of_clk_provider *provider;
+	int num_parents;
+	bool found;
+	int i;
+
+	/*
+	 * If there is no clock parent, no need to wait for them, then
+	 * we can consider their absence as being ready
+	 */
+	num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
+	if (num_parents <= 0)
+		return 1;
+
+	for (i = 0; i < num_parents; i++) {
+		if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
+					       &clkspec))
+			return 1;
+
+		/* Check if we have such a provider in our array */
+		found = false;
+		list_for_each_entry(provider, &of_clk_providers, link) {
+			if (provider->node == clkspec.np) {
+				found = true;
+				break;
+			}
+		}
+
+		if (!found)
+			return 0;
+	}
+
+	return 1;
+}
+
 /**
  * of_clk_init() - Scan and init clock providers from the DT
  * @matches: array of compatible values and init functions for providers.
  *
- * This function scans the device tree for matching clock providers and
- * calls their initialization functions
+ * This function scans the device tree for matching clock providers
+ * and calls their initialization functions. It also do it by trying
+ * to follow the dependencies.
  */
 void __init of_clk_init(const struct of_device_id *matches)
 {
 	const struct of_device_id *match;
 	struct device_node *np;
+	struct clock_provider *clk_provider, *next;
+	bool is_init_done;
 
 	if (!matches)
 		matches = &__clk_of_table;
 
 	for_each_matching_node_and_match(np, matches, &match) {
 		of_clk_init_cb_t clk_init_cb = match->data;
-		clk_init_cb(np);
+
+
+		if (parent_ready(np)) {
+			/*
+			 * The parent clock is ready or there is no
+			 * clock parent at all, in this case the
+			 * provider can be initialize immediately.
+			 */
+			clk_init_cb(np);
+		} else {
+			/*
+			 * The parent clock is not ready, this
+			 * provider is moved to a list to be
+			 * initialized later
+			 */
+			struct clock_provider *parent = kzalloc(sizeof(struct clock_provider),
+							GFP_KERNEL);
+
+			parent->clk_init_cb = match->data;
+			parent->np = np;
+			list_add(&parent->node, &clk_provider_list);
+		}
+	}
+
+	while (!list_empty(&clk_provider_list)) {
+		is_init_done = false;
+		list_for_each_entry_safe(clk_provider, next,
+					&clk_provider_list, node) {
+			if (parent_ready(clk_provider->np)) {
+				clk_provider->clk_init_cb(clk_provider->np);
+				list_del(&clk_provider->node);
+				kfree(clk_provider);
+				is_init_done = true;
+			}
+		}
+
+		if (!is_init_done) {
+			/*
+			 * We didn't managed to initialize any of the
+			 * remaining providers during the last loop,
+			 * so now we initialize all the remaining ones
+			 * unconditionally in case the clock parent
+			 * was not mandatory
+			 */
+			list_for_each_entry_safe(clk_provider, next,
+						&clk_provider_list, node) {
+				clk_provider->clk_init_cb(clk_provider->np);
+				list_del(&clk_provider->node);
+				kfree(clk_provider);
+			}
+		}
 	}
 }
 #endif
-- 
1.8.1.2


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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-10 17:42 ` Gregory CLEMENT
  0 siblings, 0 replies; 17+ messages in thread
From: Gregory CLEMENT @ 2014-02-10 17:42 UTC (permalink / raw)
  To: linux-arm-kernel

Until now the clock providers were initialized in the order found in
the device tree. This led to have the dependencies between the clocks
not respected: children clocks could be initialized before their
parent clocks.

Instead of forcing each platform to manage its own initialization order,
this patch adds this work inside the framework itself.

Using the data of the device tree the of_clk_init function now delayed
the initialization of a clock provider if its parent provider was not
ready yet.

The strict dependency check (all parents of a given clk must be
initialized) was added by Boris BREZILLON

Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
---

Since the v1, I have merged the  strict dependency check from Boris.
And of course tested on my Armada 370 and Armada XP based board

 drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 106 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 5517944495d8..684976993297 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2526,24 +2526,127 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
 }
 EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
 
+struct clock_provider {
+	of_clk_init_cb_t clk_init_cb;
+	struct device_node *np;
+	struct list_head node;
+};
+
+static LIST_HEAD(clk_provider_list);
+
+/*
+ * This function looks for a parent clock. If there is one, then it
+ * checks that the provider for this parent clock was initialized, in
+ * this case the parent clock will be ready.
+ */
+static int parent_ready(struct device_node *np)
+{
+	struct of_phandle_args clkspec;
+	struct of_clk_provider *provider;
+	int num_parents;
+	bool found;
+	int i;
+
+	/*
+	 * If there is no clock parent, no need to wait for them, then
+	 * we can consider their absence as being ready
+	 */
+	num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
+	if (num_parents <= 0)
+		return 1;
+
+	for (i = 0; i < num_parents; i++) {
+		if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
+					       &clkspec))
+			return 1;
+
+		/* Check if we have such a provider in our array */
+		found = false;
+		list_for_each_entry(provider, &of_clk_providers, link) {
+			if (provider->node == clkspec.np) {
+				found = true;
+				break;
+			}
+		}
+
+		if (!found)
+			return 0;
+	}
+
+	return 1;
+}
+
 /**
  * of_clk_init() - Scan and init clock providers from the DT
  * @matches: array of compatible values and init functions for providers.
  *
- * This function scans the device tree for matching clock providers and
- * calls their initialization functions
+ * This function scans the device tree for matching clock providers
+ * and calls their initialization functions. It also do it by trying
+ * to follow the dependencies.
  */
 void __init of_clk_init(const struct of_device_id *matches)
 {
 	const struct of_device_id *match;
 	struct device_node *np;
+	struct clock_provider *clk_provider, *next;
+	bool is_init_done;
 
 	if (!matches)
 		matches = &__clk_of_table;
 
 	for_each_matching_node_and_match(np, matches, &match) {
 		of_clk_init_cb_t clk_init_cb = match->data;
-		clk_init_cb(np);
+
+
+		if (parent_ready(np)) {
+			/*
+			 * The parent clock is ready or there is no
+			 * clock parent at all, in this case the
+			 * provider can be initialize immediately.
+			 */
+			clk_init_cb(np);
+		} else {
+			/*
+			 * The parent clock is not ready, this
+			 * provider is moved to a list to be
+			 * initialized later
+			 */
+			struct clock_provider *parent = kzalloc(sizeof(struct clock_provider),
+							GFP_KERNEL);
+
+			parent->clk_init_cb = match->data;
+			parent->np = np;
+			list_add(&parent->node, &clk_provider_list);
+		}
+	}
+
+	while (!list_empty(&clk_provider_list)) {
+		is_init_done = false;
+		list_for_each_entry_safe(clk_provider, next,
+					&clk_provider_list, node) {
+			if (parent_ready(clk_provider->np)) {
+				clk_provider->clk_init_cb(clk_provider->np);
+				list_del(&clk_provider->node);
+				kfree(clk_provider);
+				is_init_done = true;
+			}
+		}
+
+		if (!is_init_done) {
+			/*
+			 * We didn't managed to initialize any of the
+			 * remaining providers during the last loop,
+			 * so now we initialize all the remaining ones
+			 * unconditionally in case the clock parent
+			 * was not mandatory
+			 */
+			list_for_each_entry_safe(clk_provider, next,
+						&clk_provider_list, node) {
+				clk_provider->clk_init_cb(clk_provider->np);
+				list_del(&clk_provider->node);
+				kfree(clk_provider);
+			}
+		}
 	}
 }
 #endif
-- 
1.8.1.2

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

* Re: [PATCH v2] clk: respect the clock dependencies in of_clk_init
  2014-02-10 17:42 ` Gregory CLEMENT
@ 2014-02-11 16:32   ` Thomas Petazzoni
  -1 siblings, 0 replies; 17+ messages in thread
From: Thomas Petazzoni @ 2014-02-11 16:32 UTC (permalink / raw)
  To: Gregory CLEMENT
  Cc: Mike Turquette, linux-kernel, Jason Cooper, Andrew Lunn,
	Ezequiel Garcia, Sebastian Hesselbarth, linux-arm-kernel

Hello,

On Mon, 10 Feb 2014 18:42:59 +0100, Gregory CLEMENT wrote:
> Until now the clock providers were initialized in the order found in
> the device tree. This led to have the dependencies between the clocks
> not respected: children clocks could be initialized before their
> parent clocks.
> 
> Instead of forcing each platform to manage its own initialization order,
> this patch adds this work inside the framework itself.
> 
> Using the data of the device tree the of_clk_init function now delayed
> the initialization of a clock provider if its parent provider was not
> ready yet.
> 
> The strict dependency check (all parents of a given clk must be
> initialized) was added by Boris BREZILLON
> 
> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> ---
> 
> Since the v1, I have merged the  strict dependency check from Boris.
> And of course tested on my Armada 370 and Armada XP based board
> 
>  drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 106 insertions(+), 3 deletions(-)

Tested-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

On the newly proposed Armada 375 platform.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-11 16:32   ` Thomas Petazzoni
  0 siblings, 0 replies; 17+ messages in thread
From: Thomas Petazzoni @ 2014-02-11 16:32 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

On Mon, 10 Feb 2014 18:42:59 +0100, Gregory CLEMENT wrote:
> Until now the clock providers were initialized in the order found in
> the device tree. This led to have the dependencies between the clocks
> not respected: children clocks could be initialized before their
> parent clocks.
> 
> Instead of forcing each platform to manage its own initialization order,
> this patch adds this work inside the framework itself.
> 
> Using the data of the device tree the of_clk_init function now delayed
> the initialization of a clock provider if its parent provider was not
> ready yet.
> 
> The strict dependency check (all parents of a given clk must be
> initialized) was added by Boris BREZILLON
> 
> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> ---
> 
> Since the v1, I have merged the  strict dependency check from Boris.
> And of course tested on my Armada 370 and Armada XP based board
> 
>  drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 106 insertions(+), 3 deletions(-)

Tested-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

On the newly proposed Armada 375 platform.

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

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

* Re: [PATCH v2] clk: respect the clock dependencies in of_clk_init
  2014-02-11 16:32   ` Thomas Petazzoni
@ 2014-02-17 14:31     ` Gregory CLEMENT
  -1 siblings, 0 replies; 17+ messages in thread
From: Gregory CLEMENT @ 2014-02-17 14:31 UTC (permalink / raw)
  To: Mike Turquette
  Cc: Thomas Petazzoni, linux-kernel, Jason Cooper, Andrew Lunn,
	Ezequiel Garcia, Sebastian Hesselbarth, linux-arm-kernel

Hi Mike,

I would like to know if you consider to take the following patch.
If you don't then I will have to amend the patch set adding support
to Armada 375/38x SoC with the same kind of solution that Sebastian
used for the other mvebu clocks.

Thanks,

Gregory


On 11/02/2014 17:32, Thomas Petazzoni wrote:
> Hello,
> 
> On Mon, 10 Feb 2014 18:42:59 +0100, Gregory CLEMENT wrote:
>> Until now the clock providers were initialized in the order found in
>> the device tree. This led to have the dependencies between the clocks
>> not respected: children clocks could be initialized before their
>> parent clocks.
>>
>> Instead of forcing each platform to manage its own initialization order,
>> this patch adds this work inside the framework itself.
>>
>> Using the data of the device tree the of_clk_init function now delayed
>> the initialization of a clock provider if its parent provider was not
>> ready yet.
>>
>> The strict dependency check (all parents of a given clk must be
>> initialized) was added by Boris BREZILLON
>>
>> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
>> ---
>>
>> Since the v1, I have merged the  strict dependency check from Boris.
>> And of course tested on my Armada 370 and Armada XP based board
>>
>>  drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>>  1 file changed, 106 insertions(+), 3 deletions(-)
> 
> Tested-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> 
> On the newly proposed Armada 375 platform.
> 
> Thomas
> 


-- 
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-17 14:31     ` Gregory CLEMENT
  0 siblings, 0 replies; 17+ messages in thread
From: Gregory CLEMENT @ 2014-02-17 14:31 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Mike,

I would like to know if you consider to take the following patch.
If you don't then I will have to amend the patch set adding support
to Armada 375/38x SoC with the same kind of solution that Sebastian
used for the other mvebu clocks.

Thanks,

Gregory


On 11/02/2014 17:32, Thomas Petazzoni wrote:
> Hello,
> 
> On Mon, 10 Feb 2014 18:42:59 +0100, Gregory CLEMENT wrote:
>> Until now the clock providers were initialized in the order found in
>> the device tree. This led to have the dependencies between the clocks
>> not respected: children clocks could be initialized before their
>> parent clocks.
>>
>> Instead of forcing each platform to manage its own initialization order,
>> this patch adds this work inside the framework itself.
>>
>> Using the data of the device tree the of_clk_init function now delayed
>> the initialization of a clock provider if its parent provider was not
>> ready yet.
>>
>> The strict dependency check (all parents of a given clk must be
>> initialized) was added by Boris BREZILLON
>>
>> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
>> ---
>>
>> Since the v1, I have merged the  strict dependency check from Boris.
>> And of course tested on my Armada 370 and Armada XP based board
>>
>>  drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>>  1 file changed, 106 insertions(+), 3 deletions(-)
> 
> Tested-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> 
> On the newly proposed Armada 375 platform.
> 
> Thomas
> 


-- 
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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

* Re: [PATCH v2] clk: respect the clock dependencies in of_clk_init
  2014-02-10 17:42 ` Gregory CLEMENT
@ 2014-02-23 18:46   ` Tomasz Figa
  -1 siblings, 0 replies; 17+ messages in thread
From: Tomasz Figa @ 2014-02-23 18:46 UTC (permalink / raw)
  To: Gregory CLEMENT, Mike Turquette
  Cc: Thomas Petazzoni, Andrew Lunn, Jason Cooper, linux-kernel,
	Ezequiel Garcia, linux-arm-kernel, Sebastian Hesselbarth

Hi Gregory,

On 10.02.2014 18:42, Gregory CLEMENT wrote:
> Until now the clock providers were initialized in the order found in
> the device tree. This led to have the dependencies between the clocks
> not respected: children clocks could be initialized before their
> parent clocks.
>
> Instead of forcing each platform to manage its own initialization order,
> this patch adds this work inside the framework itself.
>
> Using the data of the device tree the of_clk_init function now delayed
> the initialization of a clock provider if its parent provider was not
> ready yet.

In general this is really great. It's a first step towards sorting out 
dependencies between clock providers correctly. I have some comments 
inline, though.

>
> The strict dependency check (all parents of a given clk must be
> initialized) was added by Boris BREZILLON

Shouldn't this be reflected by a tag of this patch? If you squash a 
patch signed off by someone then I believe their sign-off tag should be 
added to the base patch. Correct me if I'm wrong, though.

>
> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> ---
>
> Since the v1, I have merged the  strict dependency check from Boris.
> And of course tested on my Armada 370 and Armada XP based board
>
>   drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 106 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 5517944495d8..684976993297 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -2526,24 +2526,127 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
>   }
>   EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
>
> +struct clock_provider {

The name is a bit too generic and slightly misleading. IMHO struct 
deferred_clk_provider (and deferred_clk_providers for the list) would be 
better.

> +	of_clk_init_cb_t clk_init_cb;
> +	struct device_node *np;
> +	struct list_head node;
> +};
> +
> +static LIST_HEAD(clk_provider_list);
> +
> +/*
> + * This function looks for a parent clock. If there is one, then it
> + * checks that the provider for this parent clock was initialized, in
> + * this case the parent clock will be ready.
> + */
> +static int parent_ready(struct device_node *np)
> +{
> +	struct of_phandle_args clkspec;
> +	struct of_clk_provider *provider;
> +	int num_parents;
> +	bool found;
> +	int i;
> +
> +	/*
> +	 * If there is no clock parent, no need to wait for them, then
> +	 * we can consider their absence as being ready
> +	 */
> +	num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
> +	if (num_parents <= 0)
> +		return 1;

of_clk_get_parent_count() can be used here...

> +
> +	for (i = 0; i < num_parents; i++) {
> +		if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
> +					       &clkspec))
> +			return 1;
> +
> +		/* Check if we have such a provider in our array */
> +		found = false;
> +		list_for_each_entry(provider, &of_clk_providers, link) {
> +			if (provider->node == clkspec.np) {
> +				found = true;
> +				break;
> +			}
> +		}
> +
> +		if (!found)
> +			return 0;
> +	}

...or even better, __of_clk_get_from_provider() could modified to return 
-EPROBE_DEFER if requested provider is not registered and you could 
simply call of_clk_get(np, i) and handle its return value appropriately:

- on !IS_ERR(clk) call clk_put() and continue with iterations,
- on IS_ERR(clk) && PTR_ERR(clk) == -EPROBE_DEFER return 0 immediately,
- in any other case end the loop (end of clock specifiers).

This would make CCF even closer to proper handling of provider ordering, 
with a nice side effect of handling deferred probe for platform devices.

> +
> +	return 1;
> +}
> +
>   /**
>    * of_clk_init() - Scan and init clock providers from the DT
>    * @matches: array of compatible values and init functions for providers.
>    *
> - * This function scans the device tree for matching clock providers and
> - * calls their initialization functions
> + * This function scans the device tree for matching clock providers
> + * and calls their initialization functions. It also do it by trying
> + * to follow the dependencies.
>    */
>   void __init of_clk_init(const struct of_device_id *matches)
>   {
>   	const struct of_device_id *match;
>   	struct device_node *np;
> +	struct clock_provider *clk_provider, *next;
> +	bool is_init_done;
>
>   	if (!matches)
>   		matches = &__clk_of_table;
>
>   	for_each_matching_node_and_match(np, matches, &match) {
>   		of_clk_init_cb_t clk_init_cb = match->data;
> -		clk_init_cb(np);
> +
> +
> +		if (parent_ready(np)) {
> +			/*
> +			 * The parent clock is ready or there is no
> +			 * clock parent at all, in this case the
> +			 * provider can be initialize immediately.
> +			 */
> +			clk_init_cb(np);
> +		} else {
> +			/*
> +			 * The parent clock is not ready, this
> +			 * provider is moved to a list to be
> +			 * initialized later
> +			 */
> +			struct clock_provider *parent = kzalloc(sizeof(struct clock_provider),
> +							GFP_KERNEL);
> +
> +			parent->clk_init_cb = match->data;
> +			parent->np = np;
> +			list_add(&parent->node, &clk_provider_list);
> +		}
> +	}

I wonder if this couldn't be replaced with simply adding all the 
providers to the list first and then proceeding with the loop below to 
handle the registrations.

> +
> +	while (!list_empty(&clk_provider_list)) {
> +		is_init_done = false;
> +		list_for_each_entry_safe(clk_provider, next,
> +					&clk_provider_list, node) {
> +			if (parent_ready(clk_provider->np)) {
> +				clk_provider->clk_init_cb(clk_provider->np);
> +				list_del(&clk_provider->node);
> +				kfree(clk_provider);
> +				is_init_done = true;
> +			}
> +		}
> +
> +		if (!is_init_done) {
> +			/*
> +			 * We didn't managed to initialize any of the
> +			 * remaining providers during the last loop,
> +			 * so now we initialize all the remaining ones
> +			 * unconditionally in case the clock parent
> +			 * was not mandatory
> +			 */
> +			list_for_each_entry_safe(clk_provider, next,
> +						&clk_provider_list, node) {
> +				clk_provider->clk_init_cb(clk_provider->np);
> +				list_del(&clk_provider->node);
> +				kfree(clk_provider);

Hmm, this is basically the code above repeated without the if. What 
about something like the code snippet below?

bool force = false;
while (!list_empty(&clk_provider_list)) {
	is_init_done = false;
	list_for_each_entry_safe(clk_provider, next,
				&clk_provider_list, node) {
		if (force || parent_ready(clk_provider->np)) {
			clk_provider->clk_init_cb(clk_provider->np);
			list_del(&clk_provider->node);
			kfree(clk_provider);
			is_init_done = true;
		}
	}

	if (!is_init_done)
		force = true;
}

Best regards,
Tomasz

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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-23 18:46   ` Tomasz Figa
  0 siblings, 0 replies; 17+ messages in thread
From: Tomasz Figa @ 2014-02-23 18:46 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Gregory,

On 10.02.2014 18:42, Gregory CLEMENT wrote:
> Until now the clock providers were initialized in the order found in
> the device tree. This led to have the dependencies between the clocks
> not respected: children clocks could be initialized before their
> parent clocks.
>
> Instead of forcing each platform to manage its own initialization order,
> this patch adds this work inside the framework itself.
>
> Using the data of the device tree the of_clk_init function now delayed
> the initialization of a clock provider if its parent provider was not
> ready yet.

In general this is really great. It's a first step towards sorting out 
dependencies between clock providers correctly. I have some comments 
inline, though.

>
> The strict dependency check (all parents of a given clk must be
> initialized) was added by Boris BREZILLON

Shouldn't this be reflected by a tag of this patch? If you squash a 
patch signed off by someone then I believe their sign-off tag should be 
added to the base patch. Correct me if I'm wrong, though.

>
> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> ---
>
> Since the v1, I have merged the  strict dependency check from Boris.
> And of course tested on my Armada 370 and Armada XP based board
>
>   drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 106 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> index 5517944495d8..684976993297 100644
> --- a/drivers/clk/clk.c
> +++ b/drivers/clk/clk.c
> @@ -2526,24 +2526,127 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
>   }
>   EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
>
> +struct clock_provider {

The name is a bit too generic and slightly misleading. IMHO struct 
deferred_clk_provider (and deferred_clk_providers for the list) would be 
better.

> +	of_clk_init_cb_t clk_init_cb;
> +	struct device_node *np;
> +	struct list_head node;
> +};
> +
> +static LIST_HEAD(clk_provider_list);
> +
> +/*
> + * This function looks for a parent clock. If there is one, then it
> + * checks that the provider for this parent clock was initialized, in
> + * this case the parent clock will be ready.
> + */
> +static int parent_ready(struct device_node *np)
> +{
> +	struct of_phandle_args clkspec;
> +	struct of_clk_provider *provider;
> +	int num_parents;
> +	bool found;
> +	int i;
> +
> +	/*
> +	 * If there is no clock parent, no need to wait for them, then
> +	 * we can consider their absence as being ready
> +	 */
> +	num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
> +	if (num_parents <= 0)
> +		return 1;

of_clk_get_parent_count() can be used here...

> +
> +	for (i = 0; i < num_parents; i++) {
> +		if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
> +					       &clkspec))
> +			return 1;
> +
> +		/* Check if we have such a provider in our array */
> +		found = false;
> +		list_for_each_entry(provider, &of_clk_providers, link) {
> +			if (provider->node == clkspec.np) {
> +				found = true;
> +				break;
> +			}
> +		}
> +
> +		if (!found)
> +			return 0;
> +	}

...or even better, __of_clk_get_from_provider() could modified to return 
-EPROBE_DEFER if requested provider is not registered and you could 
simply call of_clk_get(np, i) and handle its return value appropriately:

- on !IS_ERR(clk) call clk_put() and continue with iterations,
- on IS_ERR(clk) && PTR_ERR(clk) == -EPROBE_DEFER return 0 immediately,
- in any other case end the loop (end of clock specifiers).

This would make CCF even closer to proper handling of provider ordering, 
with a nice side effect of handling deferred probe for platform devices.

> +
> +	return 1;
> +}
> +
>   /**
>    * of_clk_init() - Scan and init clock providers from the DT
>    * @matches: array of compatible values and init functions for providers.
>    *
> - * This function scans the device tree for matching clock providers and
> - * calls their initialization functions
> + * This function scans the device tree for matching clock providers
> + * and calls their initialization functions. It also do it by trying
> + * to follow the dependencies.
>    */
>   void __init of_clk_init(const struct of_device_id *matches)
>   {
>   	const struct of_device_id *match;
>   	struct device_node *np;
> +	struct clock_provider *clk_provider, *next;
> +	bool is_init_done;
>
>   	if (!matches)
>   		matches = &__clk_of_table;
>
>   	for_each_matching_node_and_match(np, matches, &match) {
>   		of_clk_init_cb_t clk_init_cb = match->data;
> -		clk_init_cb(np);
> +
> +
> +		if (parent_ready(np)) {
> +			/*
> +			 * The parent clock is ready or there is no
> +			 * clock parent at all, in this case the
> +			 * provider can be initialize immediately.
> +			 */
> +			clk_init_cb(np);
> +		} else {
> +			/*
> +			 * The parent clock is not ready, this
> +			 * provider is moved to a list to be
> +			 * initialized later
> +			 */
> +			struct clock_provider *parent = kzalloc(sizeof(struct clock_provider),
> +							GFP_KERNEL);
> +
> +			parent->clk_init_cb = match->data;
> +			parent->np = np;
> +			list_add(&parent->node, &clk_provider_list);
> +		}
> +	}

I wonder if this couldn't be replaced with simply adding all the 
providers to the list first and then proceeding with the loop below to 
handle the registrations.

> +
> +	while (!list_empty(&clk_provider_list)) {
> +		is_init_done = false;
> +		list_for_each_entry_safe(clk_provider, next,
> +					&clk_provider_list, node) {
> +			if (parent_ready(clk_provider->np)) {
> +				clk_provider->clk_init_cb(clk_provider->np);
> +				list_del(&clk_provider->node);
> +				kfree(clk_provider);
> +				is_init_done = true;
> +			}
> +		}
> +
> +		if (!is_init_done) {
> +			/*
> +			 * We didn't managed to initialize any of the
> +			 * remaining providers during the last loop,
> +			 * so now we initialize all the remaining ones
> +			 * unconditionally in case the clock parent
> +			 * was not mandatory
> +			 */
> +			list_for_each_entry_safe(clk_provider, next,
> +						&clk_provider_list, node) {
> +				clk_provider->clk_init_cb(clk_provider->np);
> +				list_del(&clk_provider->node);
> +				kfree(clk_provider);

Hmm, this is basically the code above repeated without the if. What 
about something like the code snippet below?

bool force = false;
while (!list_empty(&clk_provider_list)) {
	is_init_done = false;
	list_for_each_entry_safe(clk_provider, next,
				&clk_provider_list, node) {
		if (force || parent_ready(clk_provider->np)) {
			clk_provider->clk_init_cb(clk_provider->np);
			list_del(&clk_provider->node);
			kfree(clk_provider);
			is_init_done = true;
		}
	}

	if (!is_init_done)
		force = true;
}

Best regards,
Tomasz

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

* Re: [PATCH v2] clk: respect the clock dependencies in of_clk_init
  2014-02-23 18:46   ` Tomasz Figa
@ 2014-02-23 21:20     ` Mike Turquette
  -1 siblings, 0 replies; 17+ messages in thread
From: Mike Turquette @ 2014-02-23 21:20 UTC (permalink / raw)
  To: Tomasz Figa, Gregory CLEMENT
  Cc: Thomas Petazzoni, Andrew Lunn, Jason Cooper, linux-kernel,
	Ezequiel Garcia, linux-arm-kernel, Sebastian Hesselbarth

Quoting Tomasz Figa (2014-02-23 10:46:35)
> Hi Gregory,
> 
> On 10.02.2014 18:42, Gregory CLEMENT wrote:
> > Until now the clock providers were initialized in the order found in
> > the device tree. This led to have the dependencies between the clocks
> > not respected: children clocks could be initialized before their
> > parent clocks.
> >
> > Instead of forcing each platform to manage its own initialization order,
> > this patch adds this work inside the framework itself.
> >
> > Using the data of the device tree the of_clk_init function now delayed
> > the initialization of a clock provider if its parent provider was not
> > ready yet.
> 
> In general this is really great. It's a first step towards sorting out 
> dependencies between clock providers correctly. I have some comments 
> inline, though.

Just to add in here, I think the approach is good but agree with Tomasz'
review comments.

Regards,
Mike

> 
> >
> > The strict dependency check (all parents of a given clk must be
> > initialized) was added by Boris BREZILLON
> 
> Shouldn't this be reflected by a tag of this patch? If you squash a 
> patch signed off by someone then I believe their sign-off tag should be 
> added to the base patch. Correct me if I'm wrong, though.
> 
> >
> > Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> > ---
> >
> > Since the v1, I have merged the  strict dependency check from Boris.
> > And of course tested on my Armada 370 and Armada XP based board
> >
> >   drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
> >   1 file changed, 106 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index 5517944495d8..684976993297 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -2526,24 +2526,127 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
> >   }
> >   EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
> >
> > +struct clock_provider {
> 
> The name is a bit too generic and slightly misleading. IMHO struct 
> deferred_clk_provider (and deferred_clk_providers for the list) would be 
> better.
> 
> > +     of_clk_init_cb_t clk_init_cb;
> > +     struct device_node *np;
> > +     struct list_head node;
> > +};
> > +
> > +static LIST_HEAD(clk_provider_list);
> > +
> > +/*
> > + * This function looks for a parent clock. If there is one, then it
> > + * checks that the provider for this parent clock was initialized, in
> > + * this case the parent clock will be ready.
> > + */
> > +static int parent_ready(struct device_node *np)
> > +{
> > +     struct of_phandle_args clkspec;
> > +     struct of_clk_provider *provider;
> > +     int num_parents;
> > +     bool found;
> > +     int i;
> > +
> > +     /*
> > +      * If there is no clock parent, no need to wait for them, then
> > +      * we can consider their absence as being ready
> > +      */
> > +     num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
> > +     if (num_parents <= 0)
> > +             return 1;
> 
> of_clk_get_parent_count() can be used here...
> 
> > +
> > +     for (i = 0; i < num_parents; i++) {
> > +             if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
> > +                                            &clkspec))
> > +                     return 1;
> > +
> > +             /* Check if we have such a provider in our array */
> > +             found = false;
> > +             list_for_each_entry(provider, &of_clk_providers, link) {
> > +                     if (provider->node == clkspec.np) {
> > +                             found = true;
> > +                             break;
> > +                     }
> > +             }
> > +
> > +             if (!found)
> > +                     return 0;
> > +     }
> 
> ...or even better, __of_clk_get_from_provider() could modified to return 
> -EPROBE_DEFER if requested provider is not registered and you could 
> simply call of_clk_get(np, i) and handle its return value appropriately:
> 
> - on !IS_ERR(clk) call clk_put() and continue with iterations,
> - on IS_ERR(clk) && PTR_ERR(clk) == -EPROBE_DEFER return 0 immediately,
> - in any other case end the loop (end of clock specifiers).
> 
> This would make CCF even closer to proper handling of provider ordering, 
> with a nice side effect of handling deferred probe for platform devices.
> 
> > +
> > +     return 1;
> > +}
> > +
> >   /**
> >    * of_clk_init() - Scan and init clock providers from the DT
> >    * @matches: array of compatible values and init functions for providers.
> >    *
> > - * This function scans the device tree for matching clock providers and
> > - * calls their initialization functions
> > + * This function scans the device tree for matching clock providers
> > + * and calls their initialization functions. It also do it by trying
> > + * to follow the dependencies.
> >    */
> >   void __init of_clk_init(const struct of_device_id *matches)
> >   {
> >       const struct of_device_id *match;
> >       struct device_node *np;
> > +     struct clock_provider *clk_provider, *next;
> > +     bool is_init_done;
> >
> >       if (!matches)
> >               matches = &__clk_of_table;
> >
> >       for_each_matching_node_and_match(np, matches, &match) {
> >               of_clk_init_cb_t clk_init_cb = match->data;
> > -             clk_init_cb(np);
> > +
> > +
> > +             if (parent_ready(np)) {
> > +                     /*
> > +                      * The parent clock is ready or there is no
> > +                      * clock parent at all, in this case the
> > +                      * provider can be initialize immediately.
> > +                      */
> > +                     clk_init_cb(np);
> > +             } else {
> > +                     /*
> > +                      * The parent clock is not ready, this
> > +                      * provider is moved to a list to be
> > +                      * initialized later
> > +                      */
> > +                     struct clock_provider *parent = kzalloc(sizeof(struct clock_provider),
> > +                                                     GFP_KERNEL);
> > +
> > +                     parent->clk_init_cb = match->data;
> > +                     parent->np = np;
> > +                     list_add(&parent->node, &clk_provider_list);
> > +             }
> > +     }
> 
> I wonder if this couldn't be replaced with simply adding all the 
> providers to the list first and then proceeding with the loop below to 
> handle the registrations.
> 
> > +
> > +     while (!list_empty(&clk_provider_list)) {
> > +             is_init_done = false;
> > +             list_for_each_entry_safe(clk_provider, next,
> > +                                     &clk_provider_list, node) {
> > +                     if (parent_ready(clk_provider->np)) {
> > +                             clk_provider->clk_init_cb(clk_provider->np);
> > +                             list_del(&clk_provider->node);
> > +                             kfree(clk_provider);
> > +                             is_init_done = true;
> > +                     }
> > +             }
> > +
> > +             if (!is_init_done) {
> > +                     /*
> > +                      * We didn't managed to initialize any of the
> > +                      * remaining providers during the last loop,
> > +                      * so now we initialize all the remaining ones
> > +                      * unconditionally in case the clock parent
> > +                      * was not mandatory
> > +                      */
> > +                     list_for_each_entry_safe(clk_provider, next,
> > +                                             &clk_provider_list, node) {
> > +                             clk_provider->clk_init_cb(clk_provider->np);
> > +                             list_del(&clk_provider->node);
> > +                             kfree(clk_provider);
> 
> Hmm, this is basically the code above repeated without the if. What 
> about something like the code snippet below?
> 
> bool force = false;
> while (!list_empty(&clk_provider_list)) {
>         is_init_done = false;
>         list_for_each_entry_safe(clk_provider, next,
>                                 &clk_provider_list, node) {
>                 if (force || parent_ready(clk_provider->np)) {
>                         clk_provider->clk_init_cb(clk_provider->np);
>                         list_del(&clk_provider->node);
>                         kfree(clk_provider);
>                         is_init_done = true;
>                 }
>         }
> 
>         if (!is_init_done)
>                 force = true;
> }
> 
> Best regards,
> Tomasz

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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-23 21:20     ` Mike Turquette
  0 siblings, 0 replies; 17+ messages in thread
From: Mike Turquette @ 2014-02-23 21:20 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Tomasz Figa (2014-02-23 10:46:35)
> Hi Gregory,
> 
> On 10.02.2014 18:42, Gregory CLEMENT wrote:
> > Until now the clock providers were initialized in the order found in
> > the device tree. This led to have the dependencies between the clocks
> > not respected: children clocks could be initialized before their
> > parent clocks.
> >
> > Instead of forcing each platform to manage its own initialization order,
> > this patch adds this work inside the framework itself.
> >
> > Using the data of the device tree the of_clk_init function now delayed
> > the initialization of a clock provider if its parent provider was not
> > ready yet.
> 
> In general this is really great. It's a first step towards sorting out 
> dependencies between clock providers correctly. I have some comments 
> inline, though.

Just to add in here, I think the approach is good but agree with Tomasz'
review comments.

Regards,
Mike

> 
> >
> > The strict dependency check (all parents of a given clk must be
> > initialized) was added by Boris BREZILLON
> 
> Shouldn't this be reflected by a tag of this patch? If you squash a 
> patch signed off by someone then I believe their sign-off tag should be 
> added to the base patch. Correct me if I'm wrong, though.
> 
> >
> > Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> > ---
> >
> > Since the v1, I have merged the  strict dependency check from Boris.
> > And of course tested on my Armada 370 and Armada XP based board
> >
> >   drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
> >   1 file changed, 106 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
> > index 5517944495d8..684976993297 100644
> > --- a/drivers/clk/clk.c
> > +++ b/drivers/clk/clk.c
> > @@ -2526,24 +2526,127 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
> >   }
> >   EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
> >
> > +struct clock_provider {
> 
> The name is a bit too generic and slightly misleading. IMHO struct 
> deferred_clk_provider (and deferred_clk_providers for the list) would be 
> better.
> 
> > +     of_clk_init_cb_t clk_init_cb;
> > +     struct device_node *np;
> > +     struct list_head node;
> > +};
> > +
> > +static LIST_HEAD(clk_provider_list);
> > +
> > +/*
> > + * This function looks for a parent clock. If there is one, then it
> > + * checks that the provider for this parent clock was initialized, in
> > + * this case the parent clock will be ready.
> > + */
> > +static int parent_ready(struct device_node *np)
> > +{
> > +     struct of_phandle_args clkspec;
> > +     struct of_clk_provider *provider;
> > +     int num_parents;
> > +     bool found;
> > +     int i;
> > +
> > +     /*
> > +      * If there is no clock parent, no need to wait for them, then
> > +      * we can consider their absence as being ready
> > +      */
> > +     num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
> > +     if (num_parents <= 0)
> > +             return 1;
> 
> of_clk_get_parent_count() can be used here...
> 
> > +
> > +     for (i = 0; i < num_parents; i++) {
> > +             if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
> > +                                            &clkspec))
> > +                     return 1;
> > +
> > +             /* Check if we have such a provider in our array */
> > +             found = false;
> > +             list_for_each_entry(provider, &of_clk_providers, link) {
> > +                     if (provider->node == clkspec.np) {
> > +                             found = true;
> > +                             break;
> > +                     }
> > +             }
> > +
> > +             if (!found)
> > +                     return 0;
> > +     }
> 
> ...or even better, __of_clk_get_from_provider() could modified to return 
> -EPROBE_DEFER if requested provider is not registered and you could 
> simply call of_clk_get(np, i) and handle its return value appropriately:
> 
> - on !IS_ERR(clk) call clk_put() and continue with iterations,
> - on IS_ERR(clk) && PTR_ERR(clk) == -EPROBE_DEFER return 0 immediately,
> - in any other case end the loop (end of clock specifiers).
> 
> This would make CCF even closer to proper handling of provider ordering, 
> with a nice side effect of handling deferred probe for platform devices.
> 
> > +
> > +     return 1;
> > +}
> > +
> >   /**
> >    * of_clk_init() - Scan and init clock providers from the DT
> >    * @matches: array of compatible values and init functions for providers.
> >    *
> > - * This function scans the device tree for matching clock providers and
> > - * calls their initialization functions
> > + * This function scans the device tree for matching clock providers
> > + * and calls their initialization functions. It also do it by trying
> > + * to follow the dependencies.
> >    */
> >   void __init of_clk_init(const struct of_device_id *matches)
> >   {
> >       const struct of_device_id *match;
> >       struct device_node *np;
> > +     struct clock_provider *clk_provider, *next;
> > +     bool is_init_done;
> >
> >       if (!matches)
> >               matches = &__clk_of_table;
> >
> >       for_each_matching_node_and_match(np, matches, &match) {
> >               of_clk_init_cb_t clk_init_cb = match->data;
> > -             clk_init_cb(np);
> > +
> > +
> > +             if (parent_ready(np)) {
> > +                     /*
> > +                      * The parent clock is ready or there is no
> > +                      * clock parent at all, in this case the
> > +                      * provider can be initialize immediately.
> > +                      */
> > +                     clk_init_cb(np);
> > +             } else {
> > +                     /*
> > +                      * The parent clock is not ready, this
> > +                      * provider is moved to a list to be
> > +                      * initialized later
> > +                      */
> > +                     struct clock_provider *parent = kzalloc(sizeof(struct clock_provider),
> > +                                                     GFP_KERNEL);
> > +
> > +                     parent->clk_init_cb = match->data;
> > +                     parent->np = np;
> > +                     list_add(&parent->node, &clk_provider_list);
> > +             }
> > +     }
> 
> I wonder if this couldn't be replaced with simply adding all the 
> providers to the list first and then proceeding with the loop below to 
> handle the registrations.
> 
> > +
> > +     while (!list_empty(&clk_provider_list)) {
> > +             is_init_done = false;
> > +             list_for_each_entry_safe(clk_provider, next,
> > +                                     &clk_provider_list, node) {
> > +                     if (parent_ready(clk_provider->np)) {
> > +                             clk_provider->clk_init_cb(clk_provider->np);
> > +                             list_del(&clk_provider->node);
> > +                             kfree(clk_provider);
> > +                             is_init_done = true;
> > +                     }
> > +             }
> > +
> > +             if (!is_init_done) {
> > +                     /*
> > +                      * We didn't managed to initialize any of the
> > +                      * remaining providers during the last loop,
> > +                      * so now we initialize all the remaining ones
> > +                      * unconditionally in case the clock parent
> > +                      * was not mandatory
> > +                      */
> > +                     list_for_each_entry_safe(clk_provider, next,
> > +                                             &clk_provider_list, node) {
> > +                             clk_provider->clk_init_cb(clk_provider->np);
> > +                             list_del(&clk_provider->node);
> > +                             kfree(clk_provider);
> 
> Hmm, this is basically the code above repeated without the if. What 
> about something like the code snippet below?
> 
> bool force = false;
> while (!list_empty(&clk_provider_list)) {
>         is_init_done = false;
>         list_for_each_entry_safe(clk_provider, next,
>                                 &clk_provider_list, node) {
>                 if (force || parent_ready(clk_provider->np)) {
>                         clk_provider->clk_init_cb(clk_provider->np);
>                         list_del(&clk_provider->node);
>                         kfree(clk_provider);
>                         is_init_done = true;
>                 }
>         }
> 
>         if (!is_init_done)
>                 force = true;
> }
> 
> Best regards,
> Tomasz

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

* Re: [PATCH v2] clk: respect the clock dependencies in of_clk_init
  2014-02-23 21:20     ` Mike Turquette
@ 2014-02-23 23:41       ` Ezequiel Garcia
  -1 siblings, 0 replies; 17+ messages in thread
From: Ezequiel Garcia @ 2014-02-23 23:41 UTC (permalink / raw)
  To: Mike Turquette
  Cc: Tomasz Figa, Gregory CLEMENT, Thomas Petazzoni, Andrew Lunn,
	Jason Cooper, linux-kernel, linux-arm-kernel,
	Sebastian Hesselbarth

Tomasz, Mike:

On Sun, Feb 23, 2014 at 01:20:40PM -0800, Mike Turquette wrote:
> Quoting Tomasz Figa (2014-02-23 10:46:35)
> > On 10.02.2014 18:42, Gregory CLEMENT wrote:
> > > Until now the clock providers were initialized in the order found in
> > > the device tree. This led to have the dependencies between the clocks
> > > not respected: children clocks could be initialized before their
> > > parent clocks.
> > >
> > > Instead of forcing each platform to manage its own initialization order,
> > > this patch adds this work inside the framework itself.
> > >
> > > Using the data of the device tree the of_clk_init function now delayed
> > > the initialization of a clock provider if its parent provider was not
> > > ready yet.
> > 
> > In general this is really great. It's a first step towards sorting out 
> > dependencies between clock providers correctly. I have some comments 
> > inline, though.
> 
> Just to add in here, I think the approach is good but agree with Tomasz'
> review comments.
> 

I'm wondering if any of you has followed the discussion that Greg,
Emilio and I had about the need of this change.

If so, can you point out *why* we need to sort out registration
dependency?
-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-23 23:41       ` Ezequiel Garcia
  0 siblings, 0 replies; 17+ messages in thread
From: Ezequiel Garcia @ 2014-02-23 23:41 UTC (permalink / raw)
  To: linux-arm-kernel

Tomasz, Mike:

On Sun, Feb 23, 2014 at 01:20:40PM -0800, Mike Turquette wrote:
> Quoting Tomasz Figa (2014-02-23 10:46:35)
> > On 10.02.2014 18:42, Gregory CLEMENT wrote:
> > > Until now the clock providers were initialized in the order found in
> > > the device tree. This led to have the dependencies between the clocks
> > > not respected: children clocks could be initialized before their
> > > parent clocks.
> > >
> > > Instead of forcing each platform to manage its own initialization order,
> > > this patch adds this work inside the framework itself.
> > >
> > > Using the data of the device tree the of_clk_init function now delayed
> > > the initialization of a clock provider if its parent provider was not
> > > ready yet.
> > 
> > In general this is really great. It's a first step towards sorting out 
> > dependencies between clock providers correctly. I have some comments 
> > inline, though.
> 
> Just to add in here, I think the approach is good but agree with Tomasz'
> review comments.
> 

I'm wondering if any of you has followed the discussion that Greg,
Emilio and I had about the need of this change.

If so, can you point out *why* we need to sort out registration
dependency?
-- 
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
  2014-02-23 23:41       ` Ezequiel Garcia
  (?)
@ 2014-02-24  0:01       ` Mike Turquette
  -1 siblings, 0 replies; 17+ messages in thread
From: Mike Turquette @ 2014-02-24  0:01 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Ezequiel Garcia (2014-02-23 15:41:51)
> Tomasz, Mike:
> 
> On Sun, Feb 23, 2014 at 01:20:40PM -0800, Mike Turquette wrote:
> > Quoting Tomasz Figa (2014-02-23 10:46:35)
> > > On 10.02.2014 18:42, Gregory CLEMENT wrote:
> > > > Until now the clock providers were initialized in the order found in
> > > > the device tree. This led to have the dependencies between the clocks
> > > > not respected: children clocks could be initialized before their
> > > > parent clocks.
> > > >
> > > > Instead of forcing each platform to manage its own initialization order,
> > > > this patch adds this work inside the framework itself.
> > > >
> > > > Using the data of the device tree the of_clk_init function now delayed
> > > > the initialization of a clock provider if its parent provider was not
> > > > ready yet.
> > > 
> > > In general this is really great. It's a first step towards sorting out 
> > > dependencies between clock providers correctly. I have some comments 
> > > inline, though.
> > 
> > Just to add in here, I think the approach is good but agree with Tomasz'
> > review comments.
> > 
> 
> I'm wondering if any of you has followed the discussion that Greg,
> Emilio and I had about the need of this change.
> 
> If so, can you point out *why* we need to sort out registration
> dependency?

I went through the V1 thread and the "[PATCH 0/4] clk: mvebu: fix clk
init order" thread, and I agree that the driver does create something
like a false dependency by calling of_clk_get() against the parent in
mvebu_clk_gating_setup().

However, there have been issues with clk registration order before. The
orphan list helped out with some but sometimes it is just easier to
enforce registration order. The mvebu and armada problems that surfaced
this merge window may not be the best reason to merge this feature in,
but I do believe it's just going to keep coming up later, if not sooner.

Additionally, I fscking hate the use of strings to link children to
their parents in the core clock code. This was designed by me before DT
came to the ARM world and I took some hints from clkdev, but I shouldn't
have done it that way... This patch helps to reduce the dependency on
the orphan list mechanism (with its evil strcmp) for the DT case at
least.

Please let me know if you still disagree or if I have interpreted the
usefulness of the patch incorrectly.

Regards,
Mike

> -- 
> Ezequiel Garc?a, Free Electrons
> Embedded Linux, Kernel and Android Engineering
> http://free-electrons.com

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

* Re: [PATCH v2] clk: respect the clock dependencies in of_clk_init
  2014-02-23 18:46   ` Tomasz Figa
@ 2014-02-24 17:49     ` Gregory CLEMENT
  -1 siblings, 0 replies; 17+ messages in thread
From: Gregory CLEMENT @ 2014-02-24 17:49 UTC (permalink / raw)
  To: Tomasz Figa, Mike Turquette
  Cc: Thomas Petazzoni, Andrew Lunn, Jason Cooper, linux-kernel,
	Ezequiel Garcia, linux-arm-kernel, Sebastian Hesselbarth

Hi Tomasz,

On 23/02/2014 19:46, Tomasz Figa wrote:
> Hi Gregory,
> 
> On 10.02.2014 18:42, Gregory CLEMENT wrote:
>> Until now the clock providers were initialized in the order found in
>> the device tree. This led to have the dependencies between the clocks
>> not respected: children clocks could be initialized before their
>> parent clocks.
>>
>> Instead of forcing each platform to manage its own initialization order,
>> this patch adds this work inside the framework itself.
>>
>> Using the data of the device tree the of_clk_init function now delayed
>> the initialization of a clock provider if its parent provider was not
>> ready yet.
> 
> In general this is really great. It's a first step towards sorting out 
> dependencies between clock providers correctly. I have some comments 
> inline, though.
> 
>>
>> The strict dependency check (all parents of a given clk must be
>> initialized) was added by Boris BREZILLON
> 
> Shouldn't this be reflected by a tag of this patch? If you squash a 
> patch signed off by someone then I believe their sign-off tag should be 
> added to the base patch. Correct me if I'm wrong, though.

It was not really obvious for me to know how to deal with code merged from
someone else, but indeed adding a sign-off tag seems to be sensible.

> 
>>
>> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
>> ---
>>
>> Since the v1, I have merged the  strict dependency check from Boris.
>> And of course tested on my Armada 370 and Armada XP based board
>>
>>   drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>>   1 file changed, 106 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
>> index 5517944495d8..684976993297 100644
>> --- a/drivers/clk/clk.c
>> +++ b/drivers/clk/clk.c
>> @@ -2526,24 +2526,127 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
>>   }
>>   EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
>>
>> +struct clock_provider {
> 
> The name is a bit too generic and slightly misleading. IMHO struct 
> deferred_clk_provider (and deferred_clk_providers for the list) would be 
> better.

right

> 
>> +	of_clk_init_cb_t clk_init_cb;
>> +	struct device_node *np;
>> +	struct list_head node;
>> +};
>> +
>> +static LIST_HEAD(clk_provider_list);
>> +
>> +/*
>> + * This function looks for a parent clock. If there is one, then it
>> + * checks that the provider for this parent clock was initialized, in
>> + * this case the parent clock will be ready.
>> + */
>> +static int parent_ready(struct device_node *np)
>> +{
>> +	struct of_phandle_args clkspec;
>> +	struct of_clk_provider *provider;
>> +	int num_parents;
>> +	bool found;
>> +	int i;
>> +
>> +	/*
>> +	 * If there is no clock parent, no need to wait for them, then
>> +	 * we can consider their absence as being ready
>> +	 */
>> +	num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
>> +	if (num_parents <= 0)
>> +		return 1;
> 
> of_clk_get_parent_count() can be used here...

right

> 
>> +
>> +	for (i = 0; i < num_parents; i++) {
>> +		if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
>> +					       &clkspec))
>> +			return 1;
>> +
>> +		/* Check if we have such a provider in our array */
>> +		found = false;
>> +		list_for_each_entry(provider, &of_clk_providers, link) {
>> +			if (provider->node == clkspec.np) {
>> +				found = true;
>> +				break;
>> +			}
>> +		}
>> +
>> +		if (!found)
>> +			return 0;
>> +	}
> 
> ...or even better, __of_clk_get_from_provider() could modified to return
> -EPROBE_DEFER if requested provider is not registered and you could 

There is already a patch sent for this "clk: return probe defer when DT clock
not yet ready": http://article.gmane.org/gmane.linux.kernel/1643466

Mike will you take it?

Then I can use it to implement the suggestion made by Tomasz.

> simply call of_clk_get(np, i) and handle its return value appropriately:
> 
> - on !IS_ERR(clk) call clk_put() and continue with iterations,
> - on IS_ERR(clk) && PTR_ERR(clk) == -EPROBE_DEFER return 0 immediately,
> - in any other case end the loop (end of clock specifiers).

So here we make the assumption that the device tree is written correctly. I think
it should be acceptable because here we only try to deal with the order
of the clocks providers not the accuracy of the device tree. If the device
tree is wrong then it should trig errors message in other part of the kernel.

> 
> This would make CCF even closer to proper handling of provider ordering, 
> with a nice side effect of handling deferred probe for platform devices.
> 
>> +
>> +	return 1;
>> +}
>> +
>>   /**
>>    * of_clk_init() - Scan and init clock providers from the DT
>>    * @matches: array of compatible values and init functions for providers.
>>    *
>> - * This function scans the device tree for matching clock providers and
>> - * calls their initialization functions
>> + * This function scans the device tree for matching clock providers
>> + * and calls their initialization functions. It also do it by trying
>> + * to follow the dependencies.
>>    */
>>   void __init of_clk_init(const struct of_device_id *matches)
>>   {
>>   	const struct of_device_id *match;
>>   	struct device_node *np;
>> +	struct clock_provider *clk_provider, *next;
>> +	bool is_init_done;
>>
>>   	if (!matches)
>>   		matches = &__clk_of_table;
>>
>>   	for_each_matching_node_and_match(np, matches, &match) {
>>   		of_clk_init_cb_t clk_init_cb = match->data;
>> -		clk_init_cb(np);
>> +
>> +
>> +		if (parent_ready(np)) {
>> +			/*
>> +			 * The parent clock is ready or there is no
>> +			 * clock parent at all, in this case the
>> +			 * provider can be initialize immediately.
>> +			 */
>> +			clk_init_cb(np);
>> +		} else {
>> +			/*
>> +			 * The parent clock is not ready, this
>> +			 * provider is moved to a list to be
>> +			 * initialized later
>> +			 */
>> +			struct clock_provider *parent = kzalloc(sizeof(struct clock_provider),
>> +							GFP_KERNEL);
>> +
>> +			parent->clk_init_cb = match->data;
>> +			parent->np = np;
>> +			list_add(&parent->node, &clk_provider_list);
>> +		}
>> +	}
> 
> I wonder if this couldn't be replaced with simply adding all the 
> providers to the list first and then proceeding with the loop below to 
> handle the registrations.

Yes you're right

> 
>> +
>> +	while (!list_empty(&clk_provider_list)) {
>> +		is_init_done = false;
>> +		list_for_each_entry_safe(clk_provider, next,
>> +					&clk_provider_list, node) {
>> +			if (parent_ready(clk_provider->np)) {
>> +				clk_provider->clk_init_cb(clk_provider->np);
>> +				list_del(&clk_provider->node);
>> +				kfree(clk_provider);
>> +				is_init_done = true;
>> +			}
>> +		}
>> +
>> +		if (!is_init_done) {
>> +			/*
>> +			 * We didn't managed to initialize any of the
>> +			 * remaining providers during the last loop,
>> +			 * so now we initialize all the remaining ones
>> +			 * unconditionally in case the clock parent
>> +			 * was not mandatory
>> +			 */
>> +			list_for_each_entry_safe(clk_provider, next,
>> +						&clk_provider_list, node) {
>> +				clk_provider->clk_init_cb(clk_provider->np);
>> +				list_del(&clk_provider->node);
>> +				kfree(clk_provider);
> 
> Hmm, this is basically the code above repeated without the if. What 
> about something like the code snippet below?
> 
> bool force = false;
> while (!list_empty(&clk_provider_list)) {
> 	is_init_done = false;
> 	list_for_each_entry_safe(clk_provider, next,
> 				&clk_provider_list, node) {
> 		if (force || parent_ready(clk_provider->np)) {
> 			clk_provider->clk_init_cb(clk_provider->np);
> 			list_del(&clk_provider->node);
> 			kfree(clk_provider);
> 			is_init_done = true;
> 		}
> 	}
> 
> 	if (!is_init_done)
> 		force = true;
> }

indeed it's better.


Thanks for your review,

Gregory


> 
> Best regards,
> Tomasz
> 


-- 
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-24 17:49     ` Gregory CLEMENT
  0 siblings, 0 replies; 17+ messages in thread
From: Gregory CLEMENT @ 2014-02-24 17:49 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Tomasz,

On 23/02/2014 19:46, Tomasz Figa wrote:
> Hi Gregory,
> 
> On 10.02.2014 18:42, Gregory CLEMENT wrote:
>> Until now the clock providers were initialized in the order found in
>> the device tree. This led to have the dependencies between the clocks
>> not respected: children clocks could be initialized before their
>> parent clocks.
>>
>> Instead of forcing each platform to manage its own initialization order,
>> this patch adds this work inside the framework itself.
>>
>> Using the data of the device tree the of_clk_init function now delayed
>> the initialization of a clock provider if its parent provider was not
>> ready yet.
> 
> In general this is really great. It's a first step towards sorting out 
> dependencies between clock providers correctly. I have some comments 
> inline, though.
> 
>>
>> The strict dependency check (all parents of a given clk must be
>> initialized) was added by Boris BREZILLON
> 
> Shouldn't this be reflected by a tag of this patch? If you squash a 
> patch signed off by someone then I believe their sign-off tag should be 
> added to the base patch. Correct me if I'm wrong, though.

It was not really obvious for me to know how to deal with code merged from
someone else, but indeed adding a sign-off tag seems to be sensible.

> 
>>
>> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
>> ---
>>
>> Since the v1, I have merged the  strict dependency check from Boris.
>> And of course tested on my Armada 370 and Armada XP based board
>>
>>   drivers/clk/clk.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
>>   1 file changed, 106 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
>> index 5517944495d8..684976993297 100644
>> --- a/drivers/clk/clk.c
>> +++ b/drivers/clk/clk.c
>> @@ -2526,24 +2526,127 @@ const char *of_clk_get_parent_name(struct device_node *np, int index)
>>   }
>>   EXPORT_SYMBOL_GPL(of_clk_get_parent_name);
>>
>> +struct clock_provider {
> 
> The name is a bit too generic and slightly misleading. IMHO struct 
> deferred_clk_provider (and deferred_clk_providers for the list) would be 
> better.

right

> 
>> +	of_clk_init_cb_t clk_init_cb;
>> +	struct device_node *np;
>> +	struct list_head node;
>> +};
>> +
>> +static LIST_HEAD(clk_provider_list);
>> +
>> +/*
>> + * This function looks for a parent clock. If there is one, then it
>> + * checks that the provider for this parent clock was initialized, in
>> + * this case the parent clock will be ready.
>> + */
>> +static int parent_ready(struct device_node *np)
>> +{
>> +	struct of_phandle_args clkspec;
>> +	struct of_clk_provider *provider;
>> +	int num_parents;
>> +	bool found;
>> +	int i;
>> +
>> +	/*
>> +	 * If there is no clock parent, no need to wait for them, then
>> +	 * we can consider their absence as being ready
>> +	 */
>> +	num_parents = of_count_phandle_with_args(np, "clocks", "#clock-cells");
>> +	if (num_parents <= 0)
>> +		return 1;
> 
> of_clk_get_parent_count() can be used here...

right

> 
>> +
>> +	for (i = 0; i < num_parents; i++) {
>> +		if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
>> +					       &clkspec))
>> +			return 1;
>> +
>> +		/* Check if we have such a provider in our array */
>> +		found = false;
>> +		list_for_each_entry(provider, &of_clk_providers, link) {
>> +			if (provider->node == clkspec.np) {
>> +				found = true;
>> +				break;
>> +			}
>> +		}
>> +
>> +		if (!found)
>> +			return 0;
>> +	}
> 
> ...or even better, __of_clk_get_from_provider() could modified to return
> -EPROBE_DEFER if requested provider is not registered and you could 

There is already a patch sent for this "clk: return probe defer when DT clock
not yet ready": http://article.gmane.org/gmane.linux.kernel/1643466

Mike will you take it?

Then I can use it to implement the suggestion made by Tomasz.

> simply call of_clk_get(np, i) and handle its return value appropriately:
> 
> - on !IS_ERR(clk) call clk_put() and continue with iterations,
> - on IS_ERR(clk) && PTR_ERR(clk) == -EPROBE_DEFER return 0 immediately,
> - in any other case end the loop (end of clock specifiers).

So here we make the assumption that the device tree is written correctly. I think
it should be acceptable because here we only try to deal with the order
of the clocks providers not the accuracy of the device tree. If the device
tree is wrong then it should trig errors message in other part of the kernel.

> 
> This would make CCF even closer to proper handling of provider ordering, 
> with a nice side effect of handling deferred probe for platform devices.
> 
>> +
>> +	return 1;
>> +}
>> +
>>   /**
>>    * of_clk_init() - Scan and init clock providers from the DT
>>    * @matches: array of compatible values and init functions for providers.
>>    *
>> - * This function scans the device tree for matching clock providers and
>> - * calls their initialization functions
>> + * This function scans the device tree for matching clock providers
>> + * and calls their initialization functions. It also do it by trying
>> + * to follow the dependencies.
>>    */
>>   void __init of_clk_init(const struct of_device_id *matches)
>>   {
>>   	const struct of_device_id *match;
>>   	struct device_node *np;
>> +	struct clock_provider *clk_provider, *next;
>> +	bool is_init_done;
>>
>>   	if (!matches)
>>   		matches = &__clk_of_table;
>>
>>   	for_each_matching_node_and_match(np, matches, &match) {
>>   		of_clk_init_cb_t clk_init_cb = match->data;
>> -		clk_init_cb(np);
>> +
>> +
>> +		if (parent_ready(np)) {
>> +			/*
>> +			 * The parent clock is ready or there is no
>> +			 * clock parent at all, in this case the
>> +			 * provider can be initialize immediately.
>> +			 */
>> +			clk_init_cb(np);
>> +		} else {
>> +			/*
>> +			 * The parent clock is not ready, this
>> +			 * provider is moved to a list to be
>> +			 * initialized later
>> +			 */
>> +			struct clock_provider *parent = kzalloc(sizeof(struct clock_provider),
>> +							GFP_KERNEL);
>> +
>> +			parent->clk_init_cb = match->data;
>> +			parent->np = np;
>> +			list_add(&parent->node, &clk_provider_list);
>> +		}
>> +	}
> 
> I wonder if this couldn't be replaced with simply adding all the 
> providers to the list first and then proceeding with the loop below to 
> handle the registrations.

Yes you're right

> 
>> +
>> +	while (!list_empty(&clk_provider_list)) {
>> +		is_init_done = false;
>> +		list_for_each_entry_safe(clk_provider, next,
>> +					&clk_provider_list, node) {
>> +			if (parent_ready(clk_provider->np)) {
>> +				clk_provider->clk_init_cb(clk_provider->np);
>> +				list_del(&clk_provider->node);
>> +				kfree(clk_provider);
>> +				is_init_done = true;
>> +			}
>> +		}
>> +
>> +		if (!is_init_done) {
>> +			/*
>> +			 * We didn't managed to initialize any of the
>> +			 * remaining providers during the last loop,
>> +			 * so now we initialize all the remaining ones
>> +			 * unconditionally in case the clock parent
>> +			 * was not mandatory
>> +			 */
>> +			list_for_each_entry_safe(clk_provider, next,
>> +						&clk_provider_list, node) {
>> +				clk_provider->clk_init_cb(clk_provider->np);
>> +				list_del(&clk_provider->node);
>> +				kfree(clk_provider);
> 
> Hmm, this is basically the code above repeated without the if. What 
> about something like the code snippet below?
> 
> bool force = false;
> while (!list_empty(&clk_provider_list)) {
> 	is_init_done = false;
> 	list_for_each_entry_safe(clk_provider, next,
> 				&clk_provider_list, node) {
> 		if (force || parent_ready(clk_provider->np)) {
> 			clk_provider->clk_init_cb(clk_provider->np);
> 			list_del(&clk_provider->node);
> 			kfree(clk_provider);
> 			is_init_done = true;
> 		}
> 	}
> 
> 	if (!is_init_done)
> 		force = true;
> }

indeed it's better.


Thanks for your review,

Gregory


> 
> Best regards,
> Tomasz
> 


-- 
Gregory Clement, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

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

* Re: [PATCH v2] clk: respect the clock dependencies in of_clk_init
  2014-02-24 17:49     ` Gregory CLEMENT
@ 2014-02-25  1:03       ` Mike Turquette
  -1 siblings, 0 replies; 17+ messages in thread
From: Mike Turquette @ 2014-02-25  1:03 UTC (permalink / raw)
  To: Gregory CLEMENT, Tomasz Figa
  Cc: Thomas Petazzoni, Andrew Lunn, Jason Cooper, linux-kernel,
	Ezequiel Garcia, linux-arm-kernel, Sebastian Hesselbarth

Quoting Gregory CLEMENT (2014-02-24 09:49:27)
> On 23/02/2014 19:46, Tomasz Figa wrote:
> > On 10.02.2014 18:42, Gregory CLEMENT wrote:
> >> +
> >> +    for (i = 0; i < num_parents; i++) {
> >> +            if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
> >> +                                           &clkspec))
> >> +                    return 1;
> >> +
> >> +            /* Check if we have such a provider in our array */
> >> +            found = false;
> >> +            list_for_each_entry(provider, &of_clk_providers, link) {
> >> +                    if (provider->node == clkspec.np) {
> >> +                            found = true;
> >> +                            break;
> >> +                    }
> >> +            }
> >> +
> >> +            if (!found)
> >> +                    return 0;
> >> +    }
> > 
> > ...or even better, __of_clk_get_from_provider() could modified to return
> > -EPROBE_DEFER if requested provider is not registered and you could 
> 
> There is already a patch sent for this "clk: return probe defer when DT clock
> not yet ready": http://article.gmane.org/gmane.linux.kernel/1643466
> 
> Mike will you take it?
> 
> Then I can use it to implement the suggestion made by Tomasz.

I have just merged it to clk-next. I'll push out an updated clk-next
branch later tonight.

Regards,
Mike

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

* [PATCH v2] clk: respect the clock dependencies in of_clk_init
@ 2014-02-25  1:03       ` Mike Turquette
  0 siblings, 0 replies; 17+ messages in thread
From: Mike Turquette @ 2014-02-25  1:03 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Gregory CLEMENT (2014-02-24 09:49:27)
> On 23/02/2014 19:46, Tomasz Figa wrote:
> > On 10.02.2014 18:42, Gregory CLEMENT wrote:
> >> +
> >> +    for (i = 0; i < num_parents; i++) {
> >> +            if (of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
> >> +                                           &clkspec))
> >> +                    return 1;
> >> +
> >> +            /* Check if we have such a provider in our array */
> >> +            found = false;
> >> +            list_for_each_entry(provider, &of_clk_providers, link) {
> >> +                    if (provider->node == clkspec.np) {
> >> +                            found = true;
> >> +                            break;
> >> +                    }
> >> +            }
> >> +
> >> +            if (!found)
> >> +                    return 0;
> >> +    }
> > 
> > ...or even better, __of_clk_get_from_provider() could modified to return
> > -EPROBE_DEFER if requested provider is not registered and you could 
> 
> There is already a patch sent for this "clk: return probe defer when DT clock
> not yet ready": http://article.gmane.org/gmane.linux.kernel/1643466
> 
> Mike will you take it?
> 
> Then I can use it to implement the suggestion made by Tomasz.

I have just merged it to clk-next. I'll push out an updated clk-next
branch later tonight.

Regards,
Mike

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

end of thread, other threads:[~2014-02-25  1:03 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-10 17:42 [PATCH v2] clk: respect the clock dependencies in of_clk_init Gregory CLEMENT
2014-02-10 17:42 ` Gregory CLEMENT
2014-02-11 16:32 ` Thomas Petazzoni
2014-02-11 16:32   ` Thomas Petazzoni
2014-02-17 14:31   ` Gregory CLEMENT
2014-02-17 14:31     ` Gregory CLEMENT
2014-02-23 18:46 ` Tomasz Figa
2014-02-23 18:46   ` Tomasz Figa
2014-02-23 21:20   ` Mike Turquette
2014-02-23 21:20     ` Mike Turquette
2014-02-23 23:41     ` Ezequiel Garcia
2014-02-23 23:41       ` Ezequiel Garcia
2014-02-24  0:01       ` Mike Turquette
2014-02-24 17:49   ` Gregory CLEMENT
2014-02-24 17:49     ` Gregory CLEMENT
2014-02-25  1:03     ` Mike Turquette
2014-02-25  1:03       ` Mike Turquette

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.