linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: grant.likely@secretlab.ca (Grant Likely)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/2] dt: add helper function to read u32 arrays
Date: Wed, 6 Jul 2011 14:59:33 -0600	[thread overview]
Message-ID: <20110706205933.GA5371@ponder.secretlab.ca> (raw)
In-Reply-To: <1309984979-8847-1-git-send-email-robherring2@gmail.com>

On Wed, Jul 06, 2011 at 03:42:58PM -0500, Rob Herring wrote:
> From: Rob Herring <rob.herring@calxeda.com>
> 
> Rework of_property_read_u32 to read an array of values. Then
> of_property_read_u32 becomes an inline with array size of 1.
> 
> Also make struct device_node ptr const.
> 
> Signed-off-by: Rob Herring <rob.herring@calxeda.com>
> Cc: Thomas Abraham <thomas.abraham@linaro.org>
> Cc: Grant Likely <grant.likely@secretlab.ca>
> ---
> 
> Grant, 
> 
> Perhaps you want to roll this into the original patch?

Applied, thanks.  The original is already in devicetree/next, so I've
just applied this on top as a separate commit.

> 
> It would also be nice if there were empty versions of the helpers
> as well.

Go ahead and submit a patch to add them if you need it.

g.

> 
> Rob
> 
>  drivers/of/base.c  |   19 +++++++++++++------
>  include/linux/of.h |   14 ++++++++++++--
>  2 files changed, 25 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index b8b65fd..745537d 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -596,32 +596,39 @@ struct device_node *of_find_node_by_phandle(phandle handle)
>  EXPORT_SYMBOL(of_find_node_by_phandle);
>  
>  /**
> - * of_property_read_u32 - Find and read a 32 bit integer from a property
> + * of_property_read_u32_array - Find and read an array of 32 bit integers
> + * from a property.
> + *
>   * @np:		device node from which the property value is to be read.
>   * @propname:	name of the property to be searched.
>   * @out_value:	pointer to return value, modified only if return value is 0.
>   *
> - * Search for a property in a device node and read a 32-bit value from
> + * Search for a property in a device node and read 32-bit value(s) from
>   * it. Returns 0 on success, -EINVAL if the property does not exist,
>   * -ENODATA if property does not have a value, and -EOVERFLOW if the
>   * property data isn't large enough.
>   *
>   * The out_value is modified only if a valid u32 value can be decoded.
>   */
> -int of_property_read_u32(struct device_node *np, char *propname, u32 *out_value)
> +int of_property_read_u32_array(const struct device_node *np, char *propname,
> +			       u32 *out_values, size_t sz)
>  {
>  	struct property *prop = of_find_property(np, propname, NULL);
> +	const __be32 *val;
>  
>  	if (!prop)
>  		return -EINVAL;
>  	if (!prop->value)
>  		return -ENODATA;
> -	if (sizeof(*out_value) > prop->length)
> +	if ((sz * sizeof(*out_values)) > prop->length)
>  		return -EOVERFLOW;
> -	*out_value = be32_to_cpup(prop->value);
> +
> +	val = prop->value;
> +	while (sz--)
> +		*out_values++ = be32_to_cpup(val++);
>  	return 0;
>  }
> -EXPORT_SYMBOL_GPL(of_property_read_u32);
> +EXPORT_SYMBOL_GPL(of_property_read_u32_array);
>  
>  /**
>   * of_property_read_string - Find and read a string from a property
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 4fc4c1b..41f10e2 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -195,8 +195,18 @@ extern struct device_node *of_find_node_with_property(
>  extern struct property *of_find_property(const struct device_node *np,
>  					 const char *name,
>  					 int *lenp);
> -extern int of_property_read_u32(struct device_node *np, char *propname,
> -					u32 *out_value);
> +extern int of_property_read_u32_array(const struct device_node *np,
> +				      char *propname,
> +				      u32 *out_values,
> +				      size_t sz);
> +
> +static inline int of_property_read_u32(const struct device_node *np,
> +				       char *propname,
> +				       u32 *out_value)
> +{
> +	return of_property_read_u32_array(np, propname, out_value, 1);
> +}
> +
>  extern int of_property_read_string(struct device_node *np, char *propname,
>  					char **out_string);
>  extern int of_device_is_compatible(const struct device_node *device,
> -- 
> 1.7.4.1
> 

  parent reply	other threads:[~2011-07-06 20:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-06 20:42 [PATCH 1/2] dt: add helper function to read u32 arrays Rob Herring
2011-07-06 20:42 ` [PATCH v4 2/2] ARM: l2x0: Add OF based initialization Rob Herring
2011-07-06 20:52   ` Arnd Bergmann
2011-07-06 21:02   ` Grant Likely
2011-07-06 21:26     ` Arnd Bergmann
2011-07-08 17:59       ` Rob Herring
2011-07-18  2:01       ` Rob Herring
2011-08-03 18:41       ` Rob Herring
2011-07-07  0:20   ` Olof Johansson
2011-07-28  6:17   ` Barry Song
2011-07-06 20:59 ` Grant Likely [this message]
2011-07-08  1:45   ` [PATCH 1/2] dt: add helper function to read u32 arrays Shawn Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110706205933.GA5371@ponder.secretlab.ca \
    --to=grant.likely@secretlab.ca \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).