fdt: Add fdt_getprop_u32_default helpers
authorKumar Gala <galak@kernel.crashing.org>
Thu, 23 Oct 2008 05:05:47 +0000 (00:05 -0500)
committerAndrew Fleming-AFLEMING <afleming@freescale.com>
Fri, 24 Oct 2008 22:34:52 +0000 (17:34 -0500)
Add helper functions to return find a node and return it's property
or a default value.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Signed-off-by: Andrew Fleming-AFLEMING <afleming@freescale.com>
Acked-by: Gerald Van Baren <vanbaren@cideas.com>
common/fdt_support.c
include/fdt_support.h

index 8ceeb0f..f430777 100644 (file)
  */
 DECLARE_GLOBAL_DATA_PTR;
 
+/**
+ * fdt_getprop_u32_default - Find a node and return it's property or a default
+ *
+ * @fdt: ptr to device tree
+ * @path: path of node
+ * @prop: property name
+ * @dflt: default value if the property isn't found
+ *
+ * Convenience function to find a node and return it's property or a
+ * default value if it doesn't exist.
+ */
+u32 fdt_getprop_u32_default(void *fdt, const char *path, const char *prop,
+                               const u32 dflt)
+{
+       const u32 *val;
+       int off;
+
+       off = fdt_path_offset(fdt, path);
+       if (off < 0)
+               return dflt;
+
+       val = fdt_getprop(fdt, off, prop, NULL);
+       if (val)
+               return *val;
+       else
+               return dflt;
+}
 
 /**
  * fdt_find_and_setprop: Find a node and set it's property
index ceaadc2..816c9d0 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <fdt.h>
 
+u32 fdt_getprop_u32_default(void *fdt, const char *path, const char *prop,
+                               const u32 dflt);
 int fdt_chosen(void *fdt, int force);
 int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force);
 void do_fixup_by_path(void *fdt, const char *path, const char *prop,