* [PATCH V6 2/5] of: move of_parse_phandle()
2013-08-14 21:27 [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args Stephen Warren
@ 2013-08-14 21:27 ` Stephen Warren
2013-08-28 19:30 ` Linus Walleij
2013-08-28 20:43 ` Grant Likely
2013-08-14 21:27 ` [PATCH V6 3/5] of: introduce of_parse_phandle_with_fixed_args Stephen Warren
` (4 subsequent siblings)
5 siblings, 2 replies; 14+ messages in thread
From: Stephen Warren @ 2013-08-14 21:27 UTC (permalink / raw)
To: Linus Walleij, Grant Likely, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
From: Stephen Warren <swarren@nvidia.com>
Move of_parse_phandle() after __of_parse_phandle_with_args(), since a
future patch will call __of_parse_phandle_with_args() from
of_parse_phandle(). Moving the function avoids adding a prototype. Doing
the move separately highlights the code changes separately.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
---
v5: New patch.
---
drivers/of/base.c | 48 ++++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index e485489..9eaf662 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1081,30 +1081,6 @@ int of_property_count_strings(struct device_node *np, const char *propname)
}
EXPORT_SYMBOL_GPL(of_property_count_strings);
-/**
- * of_parse_phandle - Resolve a phandle property to a device_node pointer
- * @np: Pointer to device node holding phandle property
- * @phandle_name: Name of property holding a phandle value
- * @index: For properties holding a table of phandles, this is the index into
- * the table
- *
- * Returns the device_node pointer with refcount incremented. Use
- * of_node_put() on it when done.
- */
-struct device_node *of_parse_phandle(const struct device_node *np,
- const char *phandle_name, int index)
-{
- const __be32 *phandle;
- int size;
-
- phandle = of_get_property(np, phandle_name, &size);
- if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
- return NULL;
-
- return of_find_node_by_phandle(be32_to_cpup(phandle + index));
-}
-EXPORT_SYMBOL(of_parse_phandle);
-
static int __of_parse_phandle_with_args(const struct device_node *np,
const char *list_name,
const char *cells_name, int index,
@@ -1208,6 +1184,30 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
}
/**
+ * of_parse_phandle - Resolve a phandle property to a device_node pointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ * the table
+ *
+ * Returns the device_node pointer with refcount incremented. Use
+ * of_node_put() on it when done.
+ */
+struct device_node *of_parse_phandle(const struct device_node *np,
+ const char *phandle_name, int index)
+{
+ const __be32 *phandle;
+ int size;
+
+ phandle = of_get_property(np, phandle_name, &size);
+ if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+ return NULL;
+
+ return of_find_node_by_phandle(be32_to_cpup(phandle + index));
+}
+EXPORT_SYMBOL(of_parse_phandle);
+
+/**
* of_parse_phandle_with_args() - Find a node pointed by phandle in a list
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
--
1.8.1.5
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH V6 2/5] of: move of_parse_phandle()
2013-08-14 21:27 ` [PATCH V6 2/5] of: move of_parse_phandle() Stephen Warren
@ 2013-08-28 19:30 ` Linus Walleij
2013-08-30 20:09 ` Stephen Warren
2013-08-28 20:43 ` Grant Likely
1 sibling, 1 reply; 14+ messages in thread
From: Linus Walleij @ 2013-08-28 19:30 UTC (permalink / raw)
To: Stephen Warren, Grant Likely, Rob Herring
Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
Pawel Moll, Ian Campbell, Kumar Gala, Mark Rutland,
Stephen Warren
On Wed, Aug 14, 2013 at 11:27 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Move of_parse_phandle() after __of_parse_phandle_with_args(), since a
> future patch will call __of_parse_phandle_with_args() from
> of_parse_phandle(). Moving the function avoids adding a prototype. Doing
> the move separately highlights the code changes separately.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> ---
> v5: New patch.
Still no feedback from Rob || Grant on this quite important cleanup?
I would like to nominate Stephen Warren as co-maintainer of
drivers/of/*, he definately knows his way around the code.
I'm just worried that he may not accept due to a lot of work in the
bindings already.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH V6 2/5] of: move of_parse_phandle()
2013-08-28 19:30 ` Linus Walleij
@ 2013-08-30 20:09 ` Stephen Warren
2013-08-31 0:32 ` Rob Herring
0 siblings, 1 reply; 14+ messages in thread
From: Stephen Warren @ 2013-08-30 20:09 UTC (permalink / raw)
To: Linus Walleij
Cc: Grant Likely, Rob Herring, linux-gpio@vger.kernel.org,
devicetree@vger.kernel.org, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
On 08/28/2013 01:30 PM, Linus Walleij wrote:
> On Wed, Aug 14, 2013 at 11:27 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
>
>> From: Stephen Warren <swarren@nvidia.com>
>>
>> Move of_parse_phandle() after __of_parse_phandle_with_args(), since a
>> future patch will call __of_parse_phandle_with_args() from
>> of_parse_phandle(). Moving the function avoids adding a prototype. Doing
>> the move separately highlights the code changes separately.
>>
>> Signed-off-by: Stephen Warren <swarren@nvidia.com>
>> Acked-by: Mark Rutland <mark.rutland@arm.com>
>> ---
>> v5: New patch.
>
> Still no feedback from Rob || Grant on this quite important cleanup?
>
> I would like to nominate Stephen Warren as co-maintainer of
> drivers/of/*, he definately knows his way around the code.
> I'm just worried that he may not accept due to a lot of work in the
> bindings already.
I would prefer not to be flooded with any more email. That said,
/swapping/ my DT binding reviewer position with a drivers/of reviewer
position would reduce the email load.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH V6 2/5] of: move of_parse_phandle()
2013-08-30 20:09 ` Stephen Warren
@ 2013-08-31 0:32 ` Rob Herring
0 siblings, 0 replies; 14+ messages in thread
From: Rob Herring @ 2013-08-31 0:32 UTC (permalink / raw)
To: Stephen Warren
Cc: Linus Walleij, Grant Likely, Rob Herring,
linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
Pawel Moll, Ian Campbell, Kumar Gala, Mark Rutland,
Stephen Warren
On Fri, Aug 30, 2013 at 3:09 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
> On 08/28/2013 01:30 PM, Linus Walleij wrote:
>> On Wed, Aug 14, 2013 at 11:27 PM, Stephen Warren <swarren@wwwdotorg.org> wrote:
>>
>>> From: Stephen Warren <swarren@nvidia.com>
>>>
>>> Move of_parse_phandle() after __of_parse_phandle_with_args(), since a
>>> future patch will call __of_parse_phandle_with_args() from
>>> of_parse_phandle(). Moving the function avoids adding a prototype. Doing
>>> the move separately highlights the code changes separately.
>>>
>>> Signed-off-by: Stephen Warren <swarren@nvidia.com>
>>> Acked-by: Mark Rutland <mark.rutland@arm.com>
>>> ---
>>> v5: New patch.
>>
>> Still no feedback from Rob || Grant on this quite important cleanup?
>>
>> I would like to nominate Stephen Warren as co-maintainer of
>> drivers/of/*, he definately knows his way around the code.
>> I'm just worried that he may not accept due to a lot of work in the
>> bindings already.
>
> I would prefer not to be flooded with any more email. That said,
> /swapping/ my DT binding reviewer position with a drivers/of reviewer
> position would reduce the email load.
I would be happy with your help either way. But don't get your hopes
up, drivers/of is not much of a relief from the flood of DT bindings.
:)
Rob
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH V6 2/5] of: move of_parse_phandle()
2013-08-14 21:27 ` [PATCH V6 2/5] of: move of_parse_phandle() Stephen Warren
2013-08-28 19:30 ` Linus Walleij
@ 2013-08-28 20:43 ` Grant Likely
1 sibling, 0 replies; 14+ messages in thread
From: Grant Likely @ 2013-08-28 20:43 UTC (permalink / raw)
To: Stephen Warren, Linus Walleij, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
On Wed, 14 Aug 2013 15:27:09 -0600, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Move of_parse_phandle() after __of_parse_phandle_with_args(), since a
> future patch will call __of_parse_phandle_with_args() from
> of_parse_phandle(). Moving the function avoids adding a prototype. Doing
> the move separately highlights the code changes separately.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
Applied, thanks.
g.
> ---
> v5: New patch.
> ---
> drivers/of/base.c | 48 ++++++++++++++++++++++++------------------------
> 1 file changed, 24 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index e485489..9eaf662 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1081,30 +1081,6 @@ int of_property_count_strings(struct device_node *np, const char *propname)
> }
> EXPORT_SYMBOL_GPL(of_property_count_strings);
>
> -/**
> - * of_parse_phandle - Resolve a phandle property to a device_node pointer
> - * @np: Pointer to device node holding phandle property
> - * @phandle_name: Name of property holding a phandle value
> - * @index: For properties holding a table of phandles, this is the index into
> - * the table
> - *
> - * Returns the device_node pointer with refcount incremented. Use
> - * of_node_put() on it when done.
> - */
> -struct device_node *of_parse_phandle(const struct device_node *np,
> - const char *phandle_name, int index)
> -{
> - const __be32 *phandle;
> - int size;
> -
> - phandle = of_get_property(np, phandle_name, &size);
> - if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
> - return NULL;
> -
> - return of_find_node_by_phandle(be32_to_cpup(phandle + index));
> -}
> -EXPORT_SYMBOL(of_parse_phandle);
> -
> static int __of_parse_phandle_with_args(const struct device_node *np,
> const char *list_name,
> const char *cells_name, int index,
> @@ -1208,6 +1184,30 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
> }
>
> /**
> + * of_parse_phandle - Resolve a phandle property to a device_node pointer
> + * @np: Pointer to device node holding phandle property
> + * @phandle_name: Name of property holding a phandle value
> + * @index: For properties holding a table of phandles, this is the index into
> + * the table
> + *
> + * Returns the device_node pointer with refcount incremented. Use
> + * of_node_put() on it when done.
> + */
> +struct device_node *of_parse_phandle(const struct device_node *np,
> + const char *phandle_name, int index)
> +{
> + const __be32 *phandle;
> + int size;
> +
> + phandle = of_get_property(np, phandle_name, &size);
> + if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
> + return NULL;
> +
> + return of_find_node_by_phandle(be32_to_cpup(phandle + index));
> +}
> +EXPORT_SYMBOL(of_parse_phandle);
> +
> +/**
> * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
> * @np: pointer to a device tree node containing a list
> * @list_name: property name that contains a list
> --
> 1.8.1.5
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH V6 3/5] of: introduce of_parse_phandle_with_fixed_args
2013-08-14 21:27 [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args Stephen Warren
2013-08-14 21:27 ` [PATCH V6 2/5] of: move of_parse_phandle() Stephen Warren
@ 2013-08-14 21:27 ` Stephen Warren
2013-08-28 20:44 ` Grant Likely
2013-08-14 21:27 ` [PATCH V6 4/5] of: call __of_parse_phandle_with_args from of_parse_phandle Stephen Warren
` (3 subsequent siblings)
5 siblings, 1 reply; 14+ messages in thread
From: Stephen Warren @ 2013-08-14 21:27 UTC (permalink / raw)
To: Linus Walleij, Grant Likely, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
From: Stephen Warren <swarren@nvidia.com>
This is identical to of_parse_phandle_with_args(), except that the
number of argument cells is fixed, rather than being parsed out of the
node referenced by each phandle.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
---
v3: s/cells_count/cell_count, add missing braces per coding style
---
drivers/of/base.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++-------
include/linux/of.h | 10 +++++++++
2 files changed, 68 insertions(+), 8 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 9eaf662..3a5cd9e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1083,7 +1083,8 @@ EXPORT_SYMBOL_GPL(of_property_count_strings);
static int __of_parse_phandle_with_args(const struct device_node *np,
const char *list_name,
- const char *cells_name, int index,
+ const char *cells_name,
+ int cell_count, int index,
struct of_phandle_args *out_args)
{
const __be32 *list, *list_end;
@@ -1119,11 +1120,17 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
np->full_name);
goto err;
}
- if (of_property_read_u32(node, cells_name, &count)) {
- pr_err("%s: could not get %s for %s\n",
- np->full_name, cells_name,
- node->full_name);
- goto err;
+
+ if (cells_name) {
+ if (of_property_read_u32(node, cells_name,
+ &count)) {
+ pr_err("%s: could not get %s for %s\n",
+ np->full_name, cells_name,
+ node->full_name);
+ goto err;
+ }
+ } else {
+ count = cell_count;
}
/*
@@ -1245,11 +1252,53 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
{
if (index < 0)
return -EINVAL;
- return __of_parse_phandle_with_args(np, list_name, cells_name, index, out_args);
+ return __of_parse_phandle_with_args(np, list_name, cells_name, 0,
+ index, out_args);
}
EXPORT_SYMBOL(of_parse_phandle_with_args);
/**
+ * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
+ * @np: pointer to a device tree node containing a list
+ * @list_name: property name that contains a list
+ * @cell_count: number of argument cells following the phandle
+ * @index: index of a phandle to parse out
+ * @out_args: optional pointer to output arguments structure (will be filled)
+ *
+ * This function is useful to parse lists of phandles and their arguments.
+ * Returns 0 on success and fills out_args, on error returns appropriate
+ * errno value.
+ *
+ * Caller is responsible to call of_node_put() on the returned out_args->node
+ * pointer.
+ *
+ * Example:
+ *
+ * phandle1: node1 {
+ * }
+ *
+ * phandle2: node2 {
+ * }
+ *
+ * node3 {
+ * list = <&phandle1 0 2 &phandle2 2 3>;
+ * }
+ *
+ * To get a device_node of the `node2' node you may call this:
+ * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
+ */
+int of_parse_phandle_with_fixed_args(const struct device_node *np,
+ const char *list_name, int cell_count,
+ int index, struct of_phandle_args *out_args)
+{
+ if (index < 0)
+ return -EINVAL;
+ return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
+ index, out_args);
+}
+EXPORT_SYMBOL(of_parse_phandle_with_fixed_args);
+
+/**
* of_count_phandle_with_args() - Find the number of phandles references in a property
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
@@ -1267,7 +1316,8 @@ EXPORT_SYMBOL(of_parse_phandle_with_args);
int of_count_phandle_with_args(const struct device_node *np, const char *list_name,
const char *cells_name)
{
- return __of_parse_phandle_with_args(np, list_name, cells_name, -1, NULL);
+ return __of_parse_phandle_with_args(np, list_name, cells_name, 0, -1,
+ NULL);
}
EXPORT_SYMBOL(of_count_phandle_with_args);
diff --git a/include/linux/of.h b/include/linux/of.h
index 17ce8a6..252adbc 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -280,6 +280,9 @@ extern struct device_node *of_parse_phandle(const struct device_node *np,
extern int of_parse_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name, int index,
struct of_phandle_args *out_args);
+extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
+ const char *list_name, int cells_count, int index,
+ struct of_phandle_args *out_args);
extern int of_count_phandle_with_args(const struct device_node *np,
const char *list_name, const char *cells_name);
@@ -479,6 +482,13 @@ static inline int of_parse_phandle_with_args(struct device_node *np,
return -ENOSYS;
}
+static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
+ const char *list_name, int cells_count, int index,
+ struct of_phandle_args *out_args)
+{
+ return -ENOSYS;
+}
+
static inline int of_count_phandle_with_args(struct device_node *np,
const char *list_name,
const char *cells_name)
--
1.8.1.5
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH V6 3/5] of: introduce of_parse_phandle_with_fixed_args
2013-08-14 21:27 ` [PATCH V6 3/5] of: introduce of_parse_phandle_with_fixed_args Stephen Warren
@ 2013-08-28 20:44 ` Grant Likely
0 siblings, 0 replies; 14+ messages in thread
From: Grant Likely @ 2013-08-28 20:44 UTC (permalink / raw)
To: Stephen Warren, Linus Walleij, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
On Wed, 14 Aug 2013 15:27:10 -0600, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> This is identical to of_parse_phandle_with_args(), except that the
> number of argument cells is fixed, rather than being parsed out of the
> node referenced by each phandle.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
> ---
Applied, thanks
g.
> v3: s/cells_count/cell_count, add missing braces per coding style
> ---
> drivers/of/base.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++-------
> include/linux/of.h | 10 +++++++++
> 2 files changed, 68 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 9eaf662..3a5cd9e 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1083,7 +1083,8 @@ EXPORT_SYMBOL_GPL(of_property_count_strings);
>
> static int __of_parse_phandle_with_args(const struct device_node *np,
> const char *list_name,
> - const char *cells_name, int index,
> + const char *cells_name,
> + int cell_count, int index,
> struct of_phandle_args *out_args)
> {
> const __be32 *list, *list_end;
> @@ -1119,11 +1120,17 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
> np->full_name);
> goto err;
> }
> - if (of_property_read_u32(node, cells_name, &count)) {
> - pr_err("%s: could not get %s for %s\n",
> - np->full_name, cells_name,
> - node->full_name);
> - goto err;
> +
> + if (cells_name) {
> + if (of_property_read_u32(node, cells_name,
> + &count)) {
> + pr_err("%s: could not get %s for %s\n",
> + np->full_name, cells_name,
> + node->full_name);
> + goto err;
> + }
> + } else {
> + count = cell_count;
> }
>
> /*
> @@ -1245,11 +1252,53 @@ int of_parse_phandle_with_args(const struct device_node *np, const char *list_na
> {
> if (index < 0)
> return -EINVAL;
> - return __of_parse_phandle_with_args(np, list_name, cells_name, index, out_args);
> + return __of_parse_phandle_with_args(np, list_name, cells_name, 0,
> + index, out_args);
> }
> EXPORT_SYMBOL(of_parse_phandle_with_args);
>
> /**
> + * of_parse_phandle_with_fixed_args() - Find a node pointed by phandle in a list
> + * @np: pointer to a device tree node containing a list
> + * @list_name: property name that contains a list
> + * @cell_count: number of argument cells following the phandle
> + * @index: index of a phandle to parse out
> + * @out_args: optional pointer to output arguments structure (will be filled)
> + *
> + * This function is useful to parse lists of phandles and their arguments.
> + * Returns 0 on success and fills out_args, on error returns appropriate
> + * errno value.
> + *
> + * Caller is responsible to call of_node_put() on the returned out_args->node
> + * pointer.
> + *
> + * Example:
> + *
> + * phandle1: node1 {
> + * }
> + *
> + * phandle2: node2 {
> + * }
> + *
> + * node3 {
> + * list = <&phandle1 0 2 &phandle2 2 3>;
> + * }
> + *
> + * To get a device_node of the `node2' node you may call this:
> + * of_parse_phandle_with_fixed_args(node3, "list", 2, 1, &args);
> + */
> +int of_parse_phandle_with_fixed_args(const struct device_node *np,
> + const char *list_name, int cell_count,
> + int index, struct of_phandle_args *out_args)
> +{
> + if (index < 0)
> + return -EINVAL;
> + return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
> + index, out_args);
> +}
> +EXPORT_SYMBOL(of_parse_phandle_with_fixed_args);
> +
> +/**
> * of_count_phandle_with_args() - Find the number of phandles references in a property
> * @np: pointer to a device tree node containing a list
> * @list_name: property name that contains a list
> @@ -1267,7 +1316,8 @@ EXPORT_SYMBOL(of_parse_phandle_with_args);
> int of_count_phandle_with_args(const struct device_node *np, const char *list_name,
> const char *cells_name)
> {
> - return __of_parse_phandle_with_args(np, list_name, cells_name, -1, NULL);
> + return __of_parse_phandle_with_args(np, list_name, cells_name, 0, -1,
> + NULL);
> }
> EXPORT_SYMBOL(of_count_phandle_with_args);
>
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 17ce8a6..252adbc 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -280,6 +280,9 @@ extern struct device_node *of_parse_phandle(const struct device_node *np,
> extern int of_parse_phandle_with_args(const struct device_node *np,
> const char *list_name, const char *cells_name, int index,
> struct of_phandle_args *out_args);
> +extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
> + const char *list_name, int cells_count, int index,
> + struct of_phandle_args *out_args);
> extern int of_count_phandle_with_args(const struct device_node *np,
> const char *list_name, const char *cells_name);
>
> @@ -479,6 +482,13 @@ static inline int of_parse_phandle_with_args(struct device_node *np,
> return -ENOSYS;
> }
>
> +static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
> + const char *list_name, int cells_count, int index,
> + struct of_phandle_args *out_args)
> +{
> + return -ENOSYS;
> +}
> +
> static inline int of_count_phandle_with_args(struct device_node *np,
> const char *list_name,
> const char *cells_name)
> --
> 1.8.1.5
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH V6 4/5] of: call __of_parse_phandle_with_args from of_parse_phandle
2013-08-14 21:27 [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args Stephen Warren
2013-08-14 21:27 ` [PATCH V6 2/5] of: move of_parse_phandle() Stephen Warren
2013-08-14 21:27 ` [PATCH V6 3/5] of: introduce of_parse_phandle_with_fixed_args Stephen Warren
@ 2013-08-14 21:27 ` Stephen Warren
2013-08-14 21:27 ` [PATCH V6 5/5] gpio: implement gpio-ranges binding document fix Stephen Warren
` (2 subsequent siblings)
5 siblings, 0 replies; 14+ messages in thread
From: Stephen Warren @ 2013-08-14 21:27 UTC (permalink / raw)
To: Linus Walleij, Grant Likely, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
From: Stephen Warren <swarren@nvidia.com>
The simplest case of __of_parse_phandle_with_args() now implements the
semantics of of_parse_phandle(). Rewrite of_parse_phandle() to call
__of_parse_phandle_with_args() rather than open-coding the simple case.
Optimize __of_parse_phandle_with_args() so that it doesn't call
of_find_node_by_phandle() except when it's strictly needed. This avoids
introducing too much overhead when replacing of_parse_phandle().
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
---
v6: Fixed commit description to match code change. Enhance
__of_parse_phandle_with_args() to avoid calling
of_find_node_by_phandle() except when needed.
v5: New patch.
---
drivers/of/base.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3a5cd9e..c8be59d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1112,13 +1112,20 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
if (phandle) {
/*
* Find the provider node and parse the #*-cells
- * property to determine the argument length
+ * property to determine the argument length.
+ *
+ * This is not needed if the cell count is hard-coded
+ * (i.e. cells_name not set, but cell_count is set),
+ * except when we're going to return the found node
+ * below.
*/
- node = of_find_node_by_phandle(phandle);
- if (!node) {
- pr_err("%s: could not find phandle\n",
- np->full_name);
- goto err;
+ if (cells_name || cur_index == index) {
+ node = of_find_node_by_phandle(phandle);
+ if (!node) {
+ pr_err("%s: could not find phandle\n",
+ np->full_name);
+ goto err;
+ }
}
if (cells_name) {
@@ -1203,14 +1210,16 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
struct device_node *of_parse_phandle(const struct device_node *np,
const char *phandle_name, int index)
{
- const __be32 *phandle;
- int size;
+ struct of_phandle_args args;
+
+ if (index < 0)
+ return NULL;
- phandle = of_get_property(np, phandle_name, &size);
- if ((!phandle) || (size < sizeof(*phandle) * (index + 1)))
+ if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
+ index, &args))
return NULL;
- return of_find_node_by_phandle(be32_to_cpup(phandle + index));
+ return args.np;
}
EXPORT_SYMBOL(of_parse_phandle);
--
1.8.1.5
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH V6 5/5] gpio: implement gpio-ranges binding document fix
2013-08-14 21:27 [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args Stephen Warren
` (2 preceding siblings ...)
2013-08-14 21:27 ` [PATCH V6 4/5] of: call __of_parse_phandle_with_args from of_parse_phandle Stephen Warren
@ 2013-08-14 21:27 ` Stephen Warren
2013-08-28 20:47 ` Grant Likely
2013-08-21 17:47 ` [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args Stephen Warren
2013-08-28 20:42 ` Grant Likely
5 siblings, 1 reply; 14+ messages in thread
From: Stephen Warren @ 2013-08-14 21:27 UTC (permalink / raw)
To: Linus Walleij, Grant Likely, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
From: Stephen Warren <swarren@nvidia.com>
Use the new of_parse_phandle_with_fixed_args() to implement the
corrected gpio-ranges DT property definition.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
---
drivers/gpio/gpiolib-of.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 665f953..48cda3c 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -194,8 +194,8 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
return;
for (;; index++) {
- ret = of_parse_phandle_with_args(np, "gpio-ranges",
- "#gpio-range-cells", index, &pinspec);
+ ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3,
+ index, &pinspec);
if (ret)
break;
--
1.8.1.5
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH V6 5/5] gpio: implement gpio-ranges binding document fix
2013-08-14 21:27 ` [PATCH V6 5/5] gpio: implement gpio-ranges binding document fix Stephen Warren
@ 2013-08-28 20:47 ` Grant Likely
2013-08-29 7:09 ` Linus Walleij
0 siblings, 1 reply; 14+ messages in thread
From: Grant Likely @ 2013-08-28 20:47 UTC (permalink / raw)
To: Stephen Warren, Linus Walleij, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
On Wed, 14 Aug 2013 15:27:12 -0600, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Use the new of_parse_phandle_with_fixed_args() to implement the
> corrected gpio-ranges DT property definition.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
I'll take this with the rest of the series.
g.
> ---
> drivers/gpio/gpiolib-of.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
> index 665f953..48cda3c 100644
> --- a/drivers/gpio/gpiolib-of.c
> +++ b/drivers/gpio/gpiolib-of.c
> @@ -194,8 +194,8 @@ static void of_gpiochip_add_pin_range(struct gpio_chip *chip)
> return;
>
> for (;; index++) {
> - ret = of_parse_phandle_with_args(np, "gpio-ranges",
> - "#gpio-range-cells", index, &pinspec);
> + ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3,
> + index, &pinspec);
> if (ret)
> break;
>
> --
> 1.8.1.5
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH V6 5/5] gpio: implement gpio-ranges binding document fix
2013-08-28 20:47 ` Grant Likely
@ 2013-08-29 7:09 ` Linus Walleij
0 siblings, 0 replies; 14+ messages in thread
From: Linus Walleij @ 2013-08-29 7:09 UTC (permalink / raw)
To: Grant Likely
Cc: Stephen Warren, Rob Herring, linux-gpio@vger.kernel.org,
devicetree@vger.kernel.org, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
On Wed, Aug 28, 2013 at 10:47 PM, Grant Likely <grant.likely@linaro.org> wrote:
> On Wed, 14 Aug 2013 15:27:12 -0600, Stephen Warren <swarren@wwwdotorg.org> wrote:
>> From: Stephen Warren <swarren@nvidia.com>
>>
>> Use the new of_parse_phandle_with_fixed_args() to implement the
>> corrected gpio-ranges DT property definition.
>>
>> Signed-off-by: Stephen Warren <swarren@nvidia.com>
>> Acked-by: Mark Rutland <mark.rutland@arm.com>
>
> I'll take this with the rest of the series.
Go ahead, acked-by...
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args
2013-08-14 21:27 [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args Stephen Warren
` (3 preceding siblings ...)
2013-08-14 21:27 ` [PATCH V6 5/5] gpio: implement gpio-ranges binding document fix Stephen Warren
@ 2013-08-21 17:47 ` Stephen Warren
2013-08-28 20:42 ` Grant Likely
5 siblings, 0 replies; 14+ messages in thread
From: Stephen Warren @ 2013-08-21 17:47 UTC (permalink / raw)
To: Linus Walleij, Grant Likely, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
On 08/14/2013 03:27 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Commit bd69f73 "of: Create function for counting number of phandles in
> a property" renamed of_parse_phandle_with_args(), and created a wrapper
> function that implemented the original name. However, the documentation
> of the original function was not moved, leaving it apparently documenting
> the newly renamed function.
>
> Move the documentation so that it is adjacent to the function it
> documents.
Rob, Grant, does this series look OK now? Are you taking it through the
OF tree, or should Linus take it through the GPIO tree?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args
2013-08-14 21:27 [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args Stephen Warren
` (4 preceding siblings ...)
2013-08-21 17:47 ` [PATCH V6 1/5] of: move documentation of of_parse_phandle_with_args Stephen Warren
@ 2013-08-28 20:42 ` Grant Likely
5 siblings, 0 replies; 14+ messages in thread
From: Grant Likely @ 2013-08-28 20:42 UTC (permalink / raw)
To: Stephen Warren, Linus Walleij, Rob Herring
Cc: linux-gpio, devicetree, Pawel Moll, Ian Campbell, Kumar Gala,
Mark Rutland, Stephen Warren
On Wed, 14 Aug 2013 15:27:08 -0600, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> Commit bd69f73 "of: Create function for counting number of phandles in
> a property" renamed of_parse_phandle_with_args(), and created a wrapper
> function that implemented the original name. However, the documentation
> of the original function was not moved, leaving it apparently documenting
> the newly renamed function.
>
> Move the documentation so that it is adjacent to the function it
> documents.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> Acked-by: Mark Rutland <mark.rutland@arm.com>
Applied, thanks.
g.
> ---
> drivers/of/base.c | 64 +++++++++++++++++++++++++++----------------------------
> 1 file changed, 32 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 1c3c79c..e485489 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1105,38 +1105,6 @@ struct device_node *of_parse_phandle(const struct device_node *np,
> }
> EXPORT_SYMBOL(of_parse_phandle);
>
> -/**
> - * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
> - * @np: pointer to a device tree node containing a list
> - * @list_name: property name that contains a list
> - * @cells_name: property name that specifies phandles' arguments count
> - * @index: index of a phandle to parse out
> - * @out_args: optional pointer to output arguments structure (will be filled)
> - *
> - * This function is useful to parse lists of phandles and their arguments.
> - * Returns 0 on success and fills out_args, on error returns appropriate
> - * errno value.
> - *
> - * Caller is responsible to call of_node_put() on the returned out_args->node
> - * pointer.
> - *
> - * Example:
> - *
> - * phandle1: node1 {
> - * #list-cells = <2>;
> - * }
> - *
> - * phandle2: node2 {
> - * #list-cells = <1>;
> - * }
> - *
> - * node3 {
> - * list = <&phandle1 1 2 &phandle2 3>;
> - * }
> - *
> - * To get a device_node of the `node2' node you may call this:
> - * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
> - */
> static int __of_parse_phandle_with_args(const struct device_node *np,
> const char *list_name,
> const char *cells_name, int index,
> @@ -1239,6 +1207,38 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
> return rc;
> }
>
> +/**
> + * of_parse_phandle_with_args() - Find a node pointed by phandle in a list
> + * @np: pointer to a device tree node containing a list
> + * @list_name: property name that contains a list
> + * @cells_name: property name that specifies phandles' arguments count
> + * @index: index of a phandle to parse out
> + * @out_args: optional pointer to output arguments structure (will be filled)
> + *
> + * This function is useful to parse lists of phandles and their arguments.
> + * Returns 0 on success and fills out_args, on error returns appropriate
> + * errno value.
> + *
> + * Caller is responsible to call of_node_put() on the returned out_args->node
> + * pointer.
> + *
> + * Example:
> + *
> + * phandle1: node1 {
> + * #list-cells = <2>;
> + * }
> + *
> + * phandle2: node2 {
> + * #list-cells = <1>;
> + * }
> + *
> + * node3 {
> + * list = <&phandle1 1 2 &phandle2 3>;
> + * }
> + *
> + * To get a device_node of the `node2' node you may call this:
> + * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
> + */
> int of_parse_phandle_with_args(const struct device_node *np, const char *list_name,
> const char *cells_name, int index,
> struct of_phandle_args *out_args)
> --
> 1.8.1.5
>
^ permalink raw reply [flat|nested] 14+ messages in thread