All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MFD: do not assign already already assigned compatible of_nodes
@ 2016-09-19 11:47 Valentin Longchamp
  2016-10-19  9:12 ` Valentin Longchamp
  2016-10-24 10:08 ` Lee Jones
  0 siblings, 2 replies; 4+ messages in thread
From: Valentin Longchamp @ 2016-09-19 11:47 UTC (permalink / raw)
  To: lee.jones, linux-kernel; +Cc: Valentin Longchamp

If 2 similar cells have the same of_compatible (2 instances of the same
functionality), they both are assigned the first found of_node with this
compatible. In the below example, the pdev of both cells get the child@0
of_node.

parent@0 { /* MFD devices with 2 cells
	reg = <0>;
	child@0 {
		reg = <0>;
		compatible = "child-driver";
	};
	child@1 {
		reg = <1>;
		compatible = "child-driver";
	};
};

To avoid this, the found of_nodes are checked to see if they are already
assigned in the children of the parent dev and are only assigned if
still "available" (not assigned to a child).

This allows the 2nd cell's pdev to get the child@1 of_node.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
---
 drivers/mfd/mfd-core.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 3ac486a..11c5ded 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -137,6 +137,19 @@ static inline void mfd_acpi_add_device(const struct mfd_cell *cell,
 }
 #endif
 
+static inline int is_my_of_node(struct device *dev, void *data)
+{
+	struct device_node *np = data;
+
+	return dev->of_node == np;
+}
+
+static inline int of_node_already_in_children(struct device *dev,
+					      struct device_node *node)
+{
+	return device_for_each_child(dev, node, is_my_of_node);
+}
+
 static int mfd_add_device(struct device *parent, int id,
 			  const struct mfd_cell *cell, atomic_t *usage_count,
 			  struct resource *mem_base,
@@ -178,8 +191,10 @@ static int mfd_add_device(struct device *parent, int id,
 	if (parent->of_node && cell->of_compatible) {
 		for_each_child_of_node(parent->of_node, np) {
 			if (of_device_is_compatible(np, cell->of_compatible)) {
-				pdev->dev.of_node = np;
-				break;
+				if (!of_node_already_in_children(parent, np)) {
+					pdev->dev.of_node = np;
+					break;
+				}
 			}
 		}
 	}
-- 
1.8.3.1

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

* Re: [PATCH] MFD: do not assign already already assigned compatible of_nodes
  2016-09-19 11:47 [PATCH] MFD: do not assign already already assigned compatible of_nodes Valentin Longchamp
@ 2016-10-19  9:12 ` Valentin Longchamp
  2016-10-24 10:08 ` Lee Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Valentin Longchamp @ 2016-10-19  9:12 UTC (permalink / raw)
  To: lee.jones, linux-kernel

On 19/09/16 13:47, Valentin Longchamp wrote:
> If 2 similar cells have the same of_compatible (2 instances of the same
> functionality), they both are assigned the first found of_node with this
> compatible. In the below example, the pdev of both cells get the child@0
> of_node.
> 
> parent@0 { /* MFD devices with 2 cells
> 	reg = <0>;
> 	child@0 {
> 		reg = <0>;
> 		compatible = "child-driver";
> 	};
> 	child@1 {
> 		reg = <1>;
> 		compatible = "child-driver";
> 	};
> };
> 
> To avoid this, the found of_nodes are checked to see if they are already
> assigned in the children of the parent dev and are only assigned if
> still "available" (not assigned to a child).
> 
> This allows the 2nd cell's pdev to get the child@1 of_node.
> 
> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>

Bump. I have not received any feedback on this patch. I am working on an MFD
driver with 2 identical cells in the device, so this patch would be required for
this kind of "use case".

Thanks

Valentin

> ---
>  drivers/mfd/mfd-core.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
> index 3ac486a..11c5ded 100644
> --- a/drivers/mfd/mfd-core.c
> +++ b/drivers/mfd/mfd-core.c
> @@ -137,6 +137,19 @@ static inline void mfd_acpi_add_device(const struct mfd_cell *cell,
>  }
>  #endif
>  
> +static inline int is_my_of_node(struct device *dev, void *data)
> +{
> +	struct device_node *np = data;
> +
> +	return dev->of_node == np;
> +}
> +
> +static inline int of_node_already_in_children(struct device *dev,
> +					      struct device_node *node)
> +{
> +	return device_for_each_child(dev, node, is_my_of_node);
> +}
> +
>  static int mfd_add_device(struct device *parent, int id,
>  			  const struct mfd_cell *cell, atomic_t *usage_count,
>  			  struct resource *mem_base,
> @@ -178,8 +191,10 @@ static int mfd_add_device(struct device *parent, int id,
>  	if (parent->of_node && cell->of_compatible) {
>  		for_each_child_of_node(parent->of_node, np) {
>  			if (of_device_is_compatible(np, cell->of_compatible)) {
> -				pdev->dev.of_node = np;
> -				break;
> +				if (!of_node_already_in_children(parent, np)) {
> +					pdev->dev.of_node = np;
> +					break;
> +				}
>  			}
>  		}
>  	}
> 

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

* Re: [PATCH] MFD: do not assign already already assigned compatible of_nodes
  2016-09-19 11:47 [PATCH] MFD: do not assign already already assigned compatible of_nodes Valentin Longchamp
  2016-10-19  9:12 ` Valentin Longchamp
@ 2016-10-24 10:08 ` Lee Jones
  2016-10-25  8:11   ` [PATCH v2] mfd: " Valentin Longchamp
  1 sibling, 1 reply; 4+ messages in thread
From: Lee Jones @ 2016-10-24 10:08 UTC (permalink / raw)
  To: Valentin Longchamp; +Cc: linux-kernel

On Mon, 19 Sep 2016, Valentin Longchamp wrote:

> If 2 similar cells have the same of_compatible (2 instances of the same
> functionality), they both are assigned the first found of_node with this
> compatible. In the below example, the pdev of both cells get the child@0
> of_node.
> 
> parent@0 { /* MFD devices with 2 cells
> 	reg = <0>;
> 	child@0 {
> 		reg = <0>;
> 		compatible = "child-driver";
> 	};
> 	child@1 {
> 		reg = <1>;
> 		compatible = "child-driver";
> 	};
> };
> 
> To avoid this, the found of_nodes are checked to see if they are already
> assigned in the children of the parent dev and are only assigned if
> still "available" (not assigned to a child).
> 
> This allows the 2nd cell's pdev to get the child@1 of_node.
> 
> Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
> ---
>  drivers/mfd/mfd-core.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
> index 3ac486a..11c5ded 100644
> --- a/drivers/mfd/mfd-core.c
> +++ b/drivers/mfd/mfd-core.c
> @@ -137,6 +137,19 @@ static inline void mfd_acpi_add_device(const struct mfd_cell *cell,
>  }
>  #endif
>  
> +static inline int is_my_of_node(struct device *dev, void *data)

Rename to mfd_check_node_callback().

> +{
> +	struct device_node *np = data;
> +
> +	return dev->of_node == np;
> +}
> +
> +static inline int of_node_already_in_children(struct device *dev,

Rename to mfd_is_node_allocated_to_dev()

> +					      struct device_node *node)
> +{
> +	return device_for_each_child(dev, node, is_my_of_node);
> +}
> +
>  static int mfd_add_device(struct device *parent, int id,
>  			  const struct mfd_cell *cell, atomic_t *usage_count,
>  			  struct resource *mem_base,
> @@ -178,8 +191,10 @@ static int mfd_add_device(struct device *parent, int id,
>  	if (parent->of_node && cell->of_compatible) {
>  		for_each_child_of_node(parent->of_node, np) {
>  			if (of_device_is_compatible(np, cell->of_compatible)) {
> -				pdev->dev.of_node = np;
> -				break;
> +				if (!of_node_already_in_children(parent, np)) {
> +					pdev->dev.of_node = np;
> +					break;
> +				}
>  			}
>  		}
>  	}

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* [PATCH v2] mfd: do not assign already already assigned compatible of_nodes
  2016-10-24 10:08 ` Lee Jones
@ 2016-10-25  8:11   ` Valentin Longchamp
  0 siblings, 0 replies; 4+ messages in thread
From: Valentin Longchamp @ 2016-10-25  8:11 UTC (permalink / raw)
  To: lee.jones, linux-kernel; +Cc: Valentin Longchamp

If 2 similar cells have the same of_compatible (2 instances of the same
functionality), they both are assigned the first found of_node with this
compatible. In the below example, the pdev of both cells get the child@0
of_node.

parent@0 { /* MFD devices with 2 cells
	reg = <0>;
	child@0 {
		reg = <0>;
		compatible = "child-driver";
	};
	child@1 {
		reg = <1>;
		compatible = "child-driver";
	};
};

To avoid this, the found of_nodes are checked to see if they are already
assigned in the children of the parent dev and are only assigned if
still "available" (not assigned to a child).

This allows the 2nd cell's pdev to get the child@1 of_node.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
---
 drivers/mfd/mfd-core.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 3ac486a..a684ce5 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -137,6 +137,19 @@ static inline void mfd_acpi_add_device(const struct mfd_cell *cell,
 }
 #endif
 
+static inline int mfd_check_node_callback(struct device *dev, void *data)
+{
+	struct device_node *np = data;
+
+	return dev->of_node == np;
+}
+
+static inline int mfd_is_node_allocated_to_dev(struct device *dev,
+					       struct device_node *node)
+{
+	return device_for_each_child(dev, node, mfd_check_node_callback);
+}
+
 static int mfd_add_device(struct device *parent, int id,
 			  const struct mfd_cell *cell, atomic_t *usage_count,
 			  struct resource *mem_base,
@@ -178,8 +191,10 @@ static int mfd_add_device(struct device *parent, int id,
 	if (parent->of_node && cell->of_compatible) {
 		for_each_child_of_node(parent->of_node, np) {
 			if (of_device_is_compatible(np, cell->of_compatible)) {
-				pdev->dev.of_node = np;
-				break;
+				if (!mfd_is_node_allocated_to_dev(parent, np)) {
+					pdev->dev.of_node = np;
+					break;
+				}
 			}
 		}
 	}
-- 
1.8.3.1

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

end of thread, other threads:[~2016-10-25  8:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-19 11:47 [PATCH] MFD: do not assign already already assigned compatible of_nodes Valentin Longchamp
2016-10-19  9:12 ` Valentin Longchamp
2016-10-24 10:08 ` Lee Jones
2016-10-25  8:11   ` [PATCH v2] mfd: " Valentin Longchamp

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.