devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dt: add helper to read 64-bit integers
@ 2011-08-02 11:06 Jamie Iles
       [not found] ` <1312283219-27045-1-git-send-email-jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Jamie Iles @ 2011-08-02 11:06 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

Add a helper similar to of_property_read_u32() that handles 64-bit
integers.

Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Signed-off-by: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
---
 drivers/of/base.c  |   28 ++++++++++++++++++++++++++++
 include/linux/of.h |    8 ++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 02ed367..bae5161 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -631,6 +631,34 @@ int of_property_read_u32_array(const struct device_node *np, char *propname,
 EXPORT_SYMBOL_GPL(of_property_read_u32_array);
 
 /**
+ * of_property_read_u64 - Find and read a 64 bit integer 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 64-bit value 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 u64 value can be decoded.
+ */
+int of_property_read_u64(struct device_node *np, char *propname, u64 *out_value)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+	if (sizeof(*out_value) > prop->length)
+		return -EOVERFLOW;
+	*out_value = of_read_number(prop->value, 2);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u64);
+
+/**
  * of_property_read_string - Find and read a string from a property
  * @np:		device node from which the property value is to be read.
  * @propname:	name of the property to be searched.
diff --git a/include/linux/of.h b/include/linux/of.h
index bd716f8..9fde908 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -199,6 +199,8 @@ extern int of_property_read_u32_array(const struct device_node *np,
 				      char *propname,
 				      u32 *out_values,
 				      size_t sz);
+extern int of_property_read_u64(struct device_node *np, char *propname,
+				u64 *out_value);
 
 extern int of_property_read_string(struct device_node *np, char *propname,
 					const char **out_string);
@@ -253,6 +255,12 @@ static inline int of_property_read_string(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline int of_property_read_u64(struct device_node *np, char *propname,
+				       u64 *out_value)
+{
+	return -ENOSYS;
+}
+
 #endif /* CONFIG_OF */
 
 static inline int of_property_read_u32(const struct device_node *np,
-- 
1.7.4.1

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

* Re: [PATCH] dt: add helper to read 64-bit integers
       [not found] ` <1312283219-27045-1-git-send-email-jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
@ 2011-08-02 19:16   ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2011-08-02 19:16 UTC (permalink / raw)
  To: Jamie Iles; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

Jamie,

On 08/02/2011 06:06 AM, Jamie Iles wrote:
> Add a helper similar to of_property_read_u32() that handles 64-bit
> integers.
> 
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> Signed-off-by: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
> ---
>  drivers/of/base.c  |   28 ++++++++++++++++++++++++++++
>  include/linux/of.h |    8 ++++++++
>  2 files changed, 36 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 02ed367..bae5161 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -631,6 +631,34 @@ int of_property_read_u32_array(const struct device_node *np, char *propname,
>  EXPORT_SYMBOL_GPL(of_property_read_u32_array);
>  
>  /**
> + * of_property_read_u64 - Find and read a 64 bit integer 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 64-bit value 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 u64 value can be decoded.
> + */
> +int of_property_read_u64(struct device_node *np, char *propname, u64 *out_value)

First 2 params should have a const.

Rob

> +{
> +	struct property *prop = of_find_property(np, propname, NULL);
> +
> +	if (!prop)
> +		return -EINVAL;
> +	if (!prop->value)
> +		return -ENODATA;
> +	if (sizeof(*out_value) > prop->length)
> +		return -EOVERFLOW;
> +	*out_value = of_read_number(prop->value, 2);
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(of_property_read_u64);
> +
> +/**
>   * of_property_read_string - Find and read a string from a property
>   * @np:		device node from which the property value is to be read.
>   * @propname:	name of the property to be searched.
> diff --git a/include/linux/of.h b/include/linux/of.h
> index bd716f8..9fde908 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -199,6 +199,8 @@ extern int of_property_read_u32_array(const struct device_node *np,
>  				      char *propname,
>  				      u32 *out_values,
>  				      size_t sz);
> +extern int of_property_read_u64(struct device_node *np, char *propname,
> +				u64 *out_value);
>  
>  extern int of_property_read_string(struct device_node *np, char *propname,
>  					const char **out_string);
> @@ -253,6 +255,12 @@ static inline int of_property_read_string(struct device_node *np,
>  	return -ENOSYS;
>  }
>  
> +static inline int of_property_read_u64(struct device_node *np, char *propname,
> +				       u64 *out_value)
> +{
> +	return -ENOSYS;
> +}
> +
>  #endif /* CONFIG_OF */
>  
>  static inline int of_property_read_u32(const struct device_node *np,

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

* [PATCH] dt: add helper to read 64-bit integers
@ 2011-08-03 13:44 Jamie Iles
       [not found] ` <1312379073-13502-1-git-send-email-jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Jamie Iles @ 2011-08-03 13:44 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

Add a helper similar to of_property_read_u32() that handles 64-bit
integers.

v2: constify device node and property name parameters.

Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Signed-off-by: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
---
 drivers/of/base.c  |   28 ++++++++++++++++++++++++++++
 include/linux/of.h |    8 ++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3ff22e3..3808e70 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -632,6 +632,34 @@ int of_property_read_u32_array(const struct device_node *np,
 EXPORT_SYMBOL_GPL(of_property_read_u32_array);
 
 /**
+ * of_property_read_u64 - Find and read a 64 bit integer 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 64-bit value 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 u64 value can be decoded.
+ */
+int of_property_read_u64(struct device_node *np, char *propname, u64 *out_value)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+	if (sizeof(*out_value) > prop->length)
+		return -EOVERFLOW;
+	*out_value = of_read_number(prop->value, 2);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u64);
+
+/**
  * of_property_read_string - Find and read a string from a property
  * @np:		device node from which the property value is to be read.
  * @propname:	name of the property to be searched.
diff --git a/include/linux/of.h b/include/linux/of.h
index 0085bb0..d1b98c0 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -199,6 +199,8 @@ extern int of_property_read_u32_array(const struct device_node *np,
 				      const char *propname,
 				      u32 *out_values,
 				      size_t sz);
+extern int of_property_read_u64(const struct device_node *np,
+				const char *propname, u64 *out_value);
 
 extern int of_property_read_string(struct device_node *np,
 				   const char *propname,
@@ -256,6 +258,12 @@ static inline int of_property_read_string(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline int of_property_read_u64(const struct device_node *np,
+				       const char *propname, u64 *out_value)
+{
+	return -ENOSYS;
+}
+
 #endif /* CONFIG_OF */
 
 static inline int of_property_read_u32(const struct device_node *np,
-- 
1.7.4.1

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

* Re: [PATCH] dt: add helper to read 64-bit integers
       [not found] ` <1312379073-13502-1-git-send-email-jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
@ 2011-08-03 16:17   ` Rob Herring
       [not found]     ` <4E39748A.3030002-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Rob Herring @ 2011-08-03 16:17 UTC (permalink / raw)
  To: Jamie Iles; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

On 08/03/2011 08:44 AM, Jamie Iles wrote:
> Add a helper similar to of_property_read_u32() that handles 64-bit
> integers.
> 
> v2: constify device node and property name parameters.
> 
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> Signed-off-by: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
> ---
>  drivers/of/base.c  |   28 ++++++++++++++++++++++++++++
>  include/linux/of.h |    8 ++++++++
>  2 files changed, 36 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 3ff22e3..3808e70 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -632,6 +632,34 @@ int of_property_read_u32_array(const struct device_node *np,
>  EXPORT_SYMBOL_GPL(of_property_read_u32_array);
>  
>  /**
> + * of_property_read_u64 - Find and read a 64 bit integer 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 64-bit value 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 u64 value can be decoded.
> + */
> +int of_property_read_u64(struct device_node *np, char *propname, u64 *out_value)

Missed a const here...

> +{
> +	struct property *prop = of_find_property(np, propname, NULL);
> +
> +	if (!prop)
> +		return -EINVAL;
> +	if (!prop->value)
> +		return -ENODATA;
> +	if (sizeof(*out_value) > prop->length)
> +		return -EOVERFLOW;
> +	*out_value = of_read_number(prop->value, 2);
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(of_property_read_u64);
> +
> +/**
>   * of_property_read_string - Find and read a string from a property
>   * @np:		device node from which the property value is to be read.
>   * @propname:	name of the property to be searched.
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 0085bb0..d1b98c0 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -199,6 +199,8 @@ extern int of_property_read_u32_array(const struct device_node *np,
>  				      const char *propname,
>  				      u32 *out_values,
>  				      size_t sz);
> +extern int of_property_read_u64(const struct device_node *np,
> +				const char *propname, u64 *out_value);
>  
>  extern int of_property_read_string(struct device_node *np,
>  				   const char *propname,
> @@ -256,6 +258,12 @@ static inline int of_property_read_string(struct device_node *np,
>  	return -ENOSYS;
>  }
>  
> +static inline int of_property_read_u64(const struct device_node *np,
> +				       const char *propname, u64 *out_value)
> +{
> +	return -ENOSYS;
> +}
> +
>  #endif /* CONFIG_OF */
>  
>  static inline int of_property_read_u32(const struct device_node *np,

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

* Re: [PATCH] dt: add helper to read 64-bit integers
       [not found]     ` <4E39748A.3030002-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2011-08-03 16:33       ` Jamie Iles
       [not found]         ` <20110803163344.GP2607-apL1N+EY0C9YtYNIL7UdTEEOCMrvLtNR@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Jamie Iles @ 2011-08-03 16:33 UTC (permalink / raw)
  To: Rob Herring; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

On Wed, Aug 03, 2011 at 11:17:14AM -0500, Rob Herring wrote:
> On 08/03/2011 08:44 AM, Jamie Iles wrote:
> > Add a helper similar to of_property_read_u32() that handles 64-bit
> > integers.
> > 
> > v2: constify device node and property name parameters.
> > 
> > Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> > Signed-off-by: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
> > ---
> >  drivers/of/base.c  |   28 ++++++++++++++++++++++++++++
> >  include/linux/of.h |    8 ++++++++
> >  2 files changed, 36 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/of/base.c b/drivers/of/base.c
> > index 3ff22e3..3808e70 100644
> > --- a/drivers/of/base.c
> > +++ b/drivers/of/base.c
> > @@ -632,6 +632,34 @@ int of_property_read_u32_array(const struct device_node *np,
> >  EXPORT_SYMBOL_GPL(of_property_read_u32_array);
> >  
> >  /**
> > + * of_property_read_u64 - Find and read a 64 bit integer 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 64-bit value 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 u64 value can be decoded.
> > + */
> > +int of_property_read_u64(struct device_node *np, char *propname, u64 *out_value)
> 
> Missed a const here...

Doh!  Not sure how I missed that, thanks Rob!  Revised patch below.

Jamie

8<--------

Date: Wed, 3 Aug 2011 14:44:33 +0100
Subject: [PATCH] dt: add helper to read 64-bit integers

Add a helper similar to of_property_read_u32() that handles 64-bit
integers.

v2/v3: constify device node and property name parameters.

Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
Signed-off-by: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
---
 drivers/of/base.c  |   29 +++++++++++++++++++++++++++++
 include/linux/of.h |    8 ++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3ff22e3..9361cfe 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -632,6 +632,35 @@ int of_property_read_u32_array(const struct device_node *np,
 EXPORT_SYMBOL_GPL(of_property_read_u32_array);
 
 /**
+ * of_property_read_u64 - Find and read a 64 bit integer 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 64-bit value 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 u64 value can be decoded.
+ */
+int of_property_read_u64(const struct device_node *np, const char *propname,
+			 u64 *out_value)
+{
+	struct property *prop = of_find_property(np, propname, NULL);
+
+	if (!prop)
+		return -EINVAL;
+	if (!prop->value)
+		return -ENODATA;
+	if (sizeof(*out_value) > prop->length)
+		return -EOVERFLOW;
+	*out_value = of_read_number(prop->value, 2);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_u64);
+
+/**
  * of_property_read_string - Find and read a string from a property
  * @np:		device node from which the property value is to be read.
  * @propname:	name of the property to be searched.
diff --git a/include/linux/of.h b/include/linux/of.h
index 0085bb0..d1b98c0 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -199,6 +199,8 @@ extern int of_property_read_u32_array(const struct device_node *np,
 				      const char *propname,
 				      u32 *out_values,
 				      size_t sz);
+extern int of_property_read_u64(const struct device_node *np,
+				const char *propname, u64 *out_value);
 
 extern int of_property_read_string(struct device_node *np,
 				   const char *propname,
@@ -256,6 +258,12 @@ static inline int of_property_read_string(struct device_node *np,
 	return -ENOSYS;
 }
 
+static inline int of_property_read_u64(const struct device_node *np,
+				       const char *propname, u64 *out_value)
+{
+	return -ENOSYS;
+}
+
 #endif /* CONFIG_OF */
 
 static inline int of_property_read_u32(const struct device_node *np,
-- 
1.7.4.1

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

* Re: [PATCH] dt: add helper to read 64-bit integers
       [not found]         ` <20110803163344.GP2607-apL1N+EY0C9YtYNIL7UdTEEOCMrvLtNR@public.gmane.org>
@ 2011-08-03 16:38           ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2011-08-03 16:38 UTC (permalink / raw)
  To: Jamie Iles; +Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

On 08/03/2011 11:33 AM, Jamie Iles wrote:
> On Wed, Aug 03, 2011 at 11:17:14AM -0500, Rob Herring wrote:
>> On 08/03/2011 08:44 AM, Jamie Iles wrote:
>>> Add a helper similar to of_property_read_u32() that handles 64-bit
>>> integers.
>>>
>>> v2: constify device node and property name parameters.
>>>
>>> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
>>> Signed-off-by: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
>>> ---
>>>  drivers/of/base.c  |   28 ++++++++++++++++++++++++++++
>>>  include/linux/of.h |    8 ++++++++
>>>  2 files changed, 36 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/drivers/of/base.c b/drivers/of/base.c
>>> index 3ff22e3..3808e70 100644
>>> --- a/drivers/of/base.c
>>> +++ b/drivers/of/base.c
>>> @@ -632,6 +632,34 @@ int of_property_read_u32_array(const struct device_node *np,
>>>  EXPORT_SYMBOL_GPL(of_property_read_u32_array);
>>>  
>>>  /**
>>> + * of_property_read_u64 - Find and read a 64 bit integer 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 64-bit value 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 u64 value can be decoded.
>>> + */
>>> +int of_property_read_u64(struct device_node *np, char *propname, u64 *out_value)
>>
>> Missed a const here...
> 
> Doh!  Not sure how I missed that, thanks Rob!  Revised patch below.
> 
> Jamie
> 
> 8<--------
> 
> Date: Wed, 3 Aug 2011 14:44:33 +0100
> Subject: [PATCH] dt: add helper to read 64-bit integers
> 
> Add a helper similar to of_property_read_u32() that handles 64-bit
> integers.
> 
> v2/v3: constify device node and property name parameters.
> 
> Cc: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
> Signed-off-by: Jamie Iles <jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>

Reviewed-by: Rob Herring <rob.herring-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>

> ---
>  drivers/of/base.c  |   29 +++++++++++++++++++++++++++++
>  include/linux/of.h |    8 ++++++++
>  2 files changed, 37 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 3ff22e3..9361cfe 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -632,6 +632,35 @@ int of_property_read_u32_array(const struct device_node *np,
>  EXPORT_SYMBOL_GPL(of_property_read_u32_array);
>  
>  /**
> + * of_property_read_u64 - Find and read a 64 bit integer 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 64-bit value 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 u64 value can be decoded.
> + */
> +int of_property_read_u64(const struct device_node *np, const char *propname,
> +			 u64 *out_value)
> +{
> +	struct property *prop = of_find_property(np, propname, NULL);
> +
> +	if (!prop)
> +		return -EINVAL;
> +	if (!prop->value)
> +		return -ENODATA;
> +	if (sizeof(*out_value) > prop->length)
> +		return -EOVERFLOW;
> +	*out_value = of_read_number(prop->value, 2);
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(of_property_read_u64);
> +
> +/**
>   * of_property_read_string - Find and read a string from a property
>   * @np:		device node from which the property value is to be read.
>   * @propname:	name of the property to be searched.
> diff --git a/include/linux/of.h b/include/linux/of.h
> index 0085bb0..d1b98c0 100644
> --- a/include/linux/of.h
> +++ b/include/linux/of.h
> @@ -199,6 +199,8 @@ extern int of_property_read_u32_array(const struct device_node *np,
>  				      const char *propname,
>  				      u32 *out_values,
>  				      size_t sz);
> +extern int of_property_read_u64(const struct device_node *np,
> +				const char *propname, u64 *out_value);
>  
>  extern int of_property_read_string(struct device_node *np,
>  				   const char *propname,
> @@ -256,6 +258,12 @@ static inline int of_property_read_string(struct device_node *np,
>  	return -ENOSYS;
>  }
>  
> +static inline int of_property_read_u64(const struct device_node *np,
> +				       const char *propname, u64 *out_value)
> +{
> +	return -ENOSYS;
> +}
> +
>  #endif /* CONFIG_OF */
>  
>  static inline int of_property_read_u32(const struct device_node *np,

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

end of thread, other threads:[~2011-08-03 16:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-03 13:44 [PATCH] dt: add helper to read 64-bit integers Jamie Iles
     [not found] ` <1312379073-13502-1-git-send-email-jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
2011-08-03 16:17   ` Rob Herring
     [not found]     ` <4E39748A.3030002-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-08-03 16:33       ` Jamie Iles
     [not found]         ` <20110803163344.GP2607-apL1N+EY0C9YtYNIL7UdTEEOCMrvLtNR@public.gmane.org>
2011-08-03 16:38           ` Rob Herring
  -- strict thread matches above, loose matches on Subject: below --
2011-08-02 11:06 Jamie Iles
     [not found] ` <1312283219-27045-1-git-send-email-jamie-wmLquQDDieKakBO8gow8eQ@public.gmane.org>
2011-08-02 19:16   ` Rob Herring

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).