xen: Introduce a helper to read a u32 property in device tree.
authorChen Baozi <baozich@gmail.com>
Tue, 13 Aug 2013 11:14:23 +0000 (19:14 +0800)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 22 Aug 2013 12:17:29 +0000 (13:17 +0100)
Signed-off-by: Chen Baozi <baozich@gmail.com>
Acked-by: Julien Grall <julien.grall@linaro.org>
xen/common/device_tree.c
xen/include/xen/device_tree.h

index 84d704dc3d72e86d375c91280e79b4c71c0d9f33..12499853df471ce164b601dbe397b5da20f56abd 100644 (file)
@@ -574,6 +574,21 @@ const void *dt_get_property(const struct dt_device_node *np,
     return pp ? pp->value : NULL;
 }
 
+bool_t dt_property_read_u32(const struct dt_device_node *np,
+                         const char *name, u32 *out_value)
+{
+    u32 len;
+    const __be32 *val;
+
+    val = dt_get_property(np, name, &len);
+    if ( !val || len < sizeof(*out_value) )
+        return 0;
+
+    *out_value = be32_to_cpup(val);
+
+    return 1;
+}
+
 bool_t dt_device_is_compatible(const struct dt_device_node *device,
                                const char *compat)
 {
index 5a2a5c6971947311392dcfcd8a274283f738390c..faf727f10b329c6244dd275386e0a27f749f4864 100644 (file)
@@ -299,6 +299,17 @@ struct dt_device_node *dt_find_compatible_node(struct dt_device_node *from,
 const void *dt_get_property(const struct dt_device_node *np,
                             const char *name, u32 *lenp);
 
+/**
+ * dt_property_read_u32 - Helper to read a u32 property.
+ * @np: node to get the value
+ * @name: name of the property
+ * @out_value: pointer to return value
+ *
+ * Return true if get the desired value.
+ */
+bool_t dt_property_read_u32(const struct dt_device_node *np,
+                            const char *name, u32 *out_value);
+
 /**
  * Checks if the given "compat" string matches one of the strings in
  * the device's "compatible" property