]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
dt: add helper to read 64-bit integers
authorJamie Iles <jamie@jamieiles.com>
Wed, 14 Sep 2011 19:49:59 +0000 (20:49 +0100)
committerGrant Likely <grant.likely@secretlab.ca>
Tue, 4 Oct 2011 22:59:53 +0000 (16:59 -0600)
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@secretlab.ca>
Reviewed-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Jamie Iles <jamie@jamieiles.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
drivers/of/base.c
include/linux/of.h

index 8abde58cbe82415bfe27c05446bce123af8ef60a..b970562e0111c1f0386dbe019e0af7e97021aded 100644 (file)
@@ -656,6 +656,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.
index 53107b09cbdf4f6c4841539638c1379c2cbace61..1cc9930ba06ac73a60093398d5eb886be7b29bb3 100644 (file)
@@ -200,6 +200,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,
@@ -281,6 +283,12 @@ static inline const void *of_get_property(const struct device_node *node,
        return NULL;
 }
 
+static inline int of_property_read_u64(const struct device_node *np,
+                                      const char *propname, u64 *out_value)
+{
+       return -ENOSYS;
+}
+
 #define of_match_ptr(_ptr)     NULL
 #endif /* CONFIG_OF */