diff mbox

[v6,06/15] of: add helper for getting endpoint node of specific identifiers

Message ID 1434113958-15877-7-git-send-email-human.hwang@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Hyungwon Hwang June 12, 2015, 12:59 p.m. UTC
When there are multiple ports or multiple endpoints in a port, they have to be
distinguished by the value of reg property. It is common. The drivers can get
the specific endpoint in the specific port via this function. Now the drivers
have to implement this code in themselves or have to force the order of dt nodes
to get the right node.

Signed-off-by: Hyungwon Hwang <human.hwang@samsung.com>
Acked-by: Rob Herring <robh+dt@kernel.org>
---
Changes before:
- Refer https://patchwork.kernel.org/patch/6191751/
Changes for v6:
- None
 drivers/of/base.c        | 33 +++++++++++++++++++++++++++++++++
 include/linux/of_graph.h |  8 ++++++++
 2 files changed, 41 insertions(+)

--
1.9.1

Comments

Dave Airlie June 23, 2015, 12:19 a.m. UTC | #1
On 12 June 2015 at 22:59, Hyungwon Hwang <human.hwang@samsung.com> wrote:
> When there are multiple ports or multiple endpoints in a port, they have to be
> distinguished by the value of reg property. It is common. The drivers can get
> the specific endpoint in the specific port via this function. Now the drivers
> have to implement this code in themselves or have to force the order of dt nodes
> to get the right node.
>
> Signed-off-by: Hyungwon Hwang <human.hwang@samsung.com>
> Acked-by: Rob Herring <robh+dt@kernel.org>

FYI, Since I'm merging this via exynos-next into my tree, it broke
module builds of exynos, because it doesn't export the symbol it adds,
I've added a patch to my -next tree to fix it up.

Inki, in future can you add a modular build to pre-pull testing.

Dave.

> ---
> Changes before:
> - Refer https://patchwork.kernel.org/patch/6191751/
> Changes for v6:
> - None
>  drivers/of/base.c        | 33 +++++++++++++++++++++++++++++++++
>  include/linux/of_graph.h |  8 ++++++++
>  2 files changed, 41 insertions(+)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 99764db..f3b583b 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2233,6 +2233,39 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
>  EXPORT_SYMBOL(of_graph_get_next_endpoint);
>
>  /**
> + * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
> + * @parent: pointer to the parent device node
> + * @port_reg: identifier (value of reg property) of the parent port node
> + * @reg: identifier (value of reg property) of the endpoint node
> + *
> + * Return: An 'endpoint' node pointer which is identified by reg and at the same
> + * is the child of a port node identified by port_reg. reg and port_reg are
> + * ignored when they are -1.
> + */
> +struct device_node *of_graph_get_endpoint_by_regs(
> +       const struct device_node *parent, int port_reg, int reg)
> +{
> +       struct of_endpoint endpoint;
> +       struct device_node *node, *prev_node = NULL;
> +
> +       while (1) {
> +               node = of_graph_get_next_endpoint(parent, prev_node);
> +               of_node_put(prev_node);
> +               if (!node)
> +                       break;
> +
> +               of_graph_parse_endpoint(node, &endpoint);
> +               if (((port_reg == -1) || (endpoint.port == port_reg)) &&
> +                       ((reg == -1) || (endpoint.id == reg)))
> +                       return node;
> +
> +               prev_node = node;
> +       }
> +
> +       return NULL;
> +}
> +
> +/**
>   * of_graph_get_remote_port_parent() - get remote port's parent node
>   * @node: pointer to a local endpoint device_node
>   *
> diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
> index 7bc92e0..1c1d5b9 100644
> --- a/include/linux/of_graph.h
> +++ b/include/linux/of_graph.h
> @@ -45,6 +45,8 @@ int of_graph_parse_endpoint(const struct device_node *node,
>  struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
>  struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
>                                         struct device_node *previous);
> +struct device_node *of_graph_get_endpoint_by_regs(
> +               const struct device_node *parent, int port_reg, int reg);
>  struct device_node *of_graph_get_remote_port_parent(
>                                         const struct device_node *node);
>  struct device_node *of_graph_get_remote_port(const struct device_node *node);
> @@ -69,6 +71,12 @@ static inline struct device_node *of_graph_get_next_endpoint(
>         return NULL;
>  }
>
> +struct device_node *of_graph_get_endpoint_by_regs(
> +               const struct device_node *parent, int port_reg, int reg)
> +{
> +       return NULL;
> +}
> +
>  static inline struct device_node *of_graph_get_remote_port_parent(
>                                         const struct device_node *node)
>  {
> --
> 1.9.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
Inki Dae June 23, 2015, 2:29 a.m. UTC | #2
On 2015? 06? 23? 09:19, Dave Airlie wrote:
> On 12 June 2015 at 22:59, Hyungwon Hwang <human.hwang@samsung.com> wrote:
>> When there are multiple ports or multiple endpoints in a port, they have to be
>> distinguished by the value of reg property. It is common. The drivers can get
>> the specific endpoint in the specific port via this function. Now the drivers
>> have to implement this code in themselves or have to force the order of dt nodes
>> to get the right node.
>>
>> Signed-off-by: Hyungwon Hwang <human.hwang@samsung.com>
>> Acked-by: Rob Herring <robh+dt@kernel.org>
> 
> FYI, Since I'm merging this via exynos-next into my tree, it broke
> module builds of exynos, because it doesn't export the symbol it adds,
> I've added a patch to my -next tree to fix it up.
> 
> Inki, in future can you add a modular build to pre-pull testing.

Yes I do. I should have tested the modular build. Sorry for this.

Thanks,
Inki Dae

> 
> Dave.
> 
>> ---
>> Changes before:
>> - Refer https://patchwork.kernel.org/patch/6191751/
>> Changes for v6:
>> - None
>>  drivers/of/base.c        | 33 +++++++++++++++++++++++++++++++++
>>  include/linux/of_graph.h |  8 ++++++++
>>  2 files changed, 41 insertions(+)
>>
>> diff --git a/drivers/of/base.c b/drivers/of/base.c
>> index 99764db..f3b583b 100644
>> --- a/drivers/of/base.c
>> +++ b/drivers/of/base.c
>> @@ -2233,6 +2233,39 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
>>  EXPORT_SYMBOL(of_graph_get_next_endpoint);
>>
>>  /**
>> + * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
>> + * @parent: pointer to the parent device node
>> + * @port_reg: identifier (value of reg property) of the parent port node
>> + * @reg: identifier (value of reg property) of the endpoint node
>> + *
>> + * Return: An 'endpoint' node pointer which is identified by reg and at the same
>> + * is the child of a port node identified by port_reg. reg and port_reg are
>> + * ignored when they are -1.
>> + */
>> +struct device_node *of_graph_get_endpoint_by_regs(
>> +       const struct device_node *parent, int port_reg, int reg)
>> +{
>> +       struct of_endpoint endpoint;
>> +       struct device_node *node, *prev_node = NULL;
>> +
>> +       while (1) {
>> +               node = of_graph_get_next_endpoint(parent, prev_node);
>> +               of_node_put(prev_node);
>> +               if (!node)
>> +                       break;
>> +
>> +               of_graph_parse_endpoint(node, &endpoint);
>> +               if (((port_reg == -1) || (endpoint.port == port_reg)) &&
>> +                       ((reg == -1) || (endpoint.id == reg)))
>> +                       return node;
>> +
>> +               prev_node = node;
>> +       }
>> +
>> +       return NULL;
>> +}
>> +
>> +/**
>>   * of_graph_get_remote_port_parent() - get remote port's parent node
>>   * @node: pointer to a local endpoint device_node
>>   *
>> diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
>> index 7bc92e0..1c1d5b9 100644
>> --- a/include/linux/of_graph.h
>> +++ b/include/linux/of_graph.h
>> @@ -45,6 +45,8 @@ int of_graph_parse_endpoint(const struct device_node *node,
>>  struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
>>  struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
>>                                         struct device_node *previous);
>> +struct device_node *of_graph_get_endpoint_by_regs(
>> +               const struct device_node *parent, int port_reg, int reg);
>>  struct device_node *of_graph_get_remote_port_parent(
>>                                         const struct device_node *node);
>>  struct device_node *of_graph_get_remote_port(const struct device_node *node);
>> @@ -69,6 +71,12 @@ static inline struct device_node *of_graph_get_next_endpoint(
>>         return NULL;
>>  }
>>
>> +struct device_node *of_graph_get_endpoint_by_regs(
>> +               const struct device_node *parent, int port_reg, int reg)
>> +{
>> +       return NULL;
>> +}
>> +
>>  static inline struct device_node *of_graph_get_remote_port_parent(
>>                                         const struct device_node *node)
>>  {
>> --
>> 1.9.1
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
>
diff mbox

Patch

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 99764db..f3b583b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2233,6 +2233,39 @@  struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
 EXPORT_SYMBOL(of_graph_get_next_endpoint);

 /**
+ * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
+ * @parent: pointer to the parent device node
+ * @port_reg: identifier (value of reg property) of the parent port node
+ * @reg: identifier (value of reg property) of the endpoint node
+ *
+ * Return: An 'endpoint' node pointer which is identified by reg and at the same
+ * is the child of a port node identified by port_reg. reg and port_reg are
+ * ignored when they are -1.
+ */
+struct device_node *of_graph_get_endpoint_by_regs(
+	const struct device_node *parent, int port_reg, int reg)
+{
+	struct of_endpoint endpoint;
+	struct device_node *node, *prev_node = NULL;
+
+	while (1) {
+		node = of_graph_get_next_endpoint(parent, prev_node);
+		of_node_put(prev_node);
+		if (!node)
+			break;
+
+		of_graph_parse_endpoint(node, &endpoint);
+		if (((port_reg == -1) || (endpoint.port == port_reg)) &&
+			((reg == -1) || (endpoint.id == reg)))
+			return node;
+
+		prev_node = node;
+	}
+
+	return NULL;
+}
+
+/**
  * of_graph_get_remote_port_parent() - get remote port's parent node
  * @node: pointer to a local endpoint device_node
  *
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
index 7bc92e0..1c1d5b9 100644
--- a/include/linux/of_graph.h
+++ b/include/linux/of_graph.h
@@ -45,6 +45,8 @@  int of_graph_parse_endpoint(const struct device_node *node,
 struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
 struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
 					struct device_node *previous);
+struct device_node *of_graph_get_endpoint_by_regs(
+		const struct device_node *parent, int port_reg, int reg);
 struct device_node *of_graph_get_remote_port_parent(
 					const struct device_node *node);
 struct device_node *of_graph_get_remote_port(const struct device_node *node);
@@ -69,6 +71,12 @@  static inline struct device_node *of_graph_get_next_endpoint(
 	return NULL;
 }

+struct device_node *of_graph_get_endpoint_by_regs(
+		const struct device_node *parent, int port_reg, int reg)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_graph_get_remote_port_parent(
 					const struct device_node *node)
 {