lib, fdt: Adding fdtdec_get_uint function
authorChin Liang See <clsee@altera.com>
Sat, 17 Oct 2015 13:30:32 +0000 (08:30 -0500)
committerMarek Vasut <marex@denx.de>
Thu, 5 Nov 2015 01:34:14 +0000 (02:34 +0100)
Adding fdtdec_get_uint function which is the
unsigned version for fdtdec_get_int

Signed-off-by: Chin Liang See <clsee@altera.com>
Cc: Dinh Nguyen <dinguyen@opensource.altera.com>
Cc: Dinh Nguyen <dinh.linux@gmail.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Stefan Roese <sr@denx.de>
Cc: Vikas Manocha <vikas.manocha@st.com>
Cc: Jagannadh Teki <jteki@openedev.com>
Cc: Pavel Machek <pavel@denx.de>
Cc: Heiko Schocher <hs@denx.de>
include/fdtdec.h
lib/fdtdec_common.c

index 2de6dda04c5df11d7e677f4535c1dac841ce9d21..d51e643ac3baace497e125895fab665662c36b13 100644 (file)
@@ -489,6 +489,19 @@ int fdtdec_get_pci_bar32(const void *blob, int node,
 s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
                s32 default_val);
 
+/**
+ * Unsigned version of fdtdec_get_int. The property must have at least
+ * 4 bytes of data. The value of the first cell is returned.
+ *
+ * @param blob FDT blob
+ * @param node node to examine
+ * @param prop_name    name of property to find
+ * @param default_val  default value to return if the property is not found
+ * @return unsigned integer value, if found, or default_val if not
+ */
+unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name,
+                       unsigned int default_val);
+
 /**
  * Get a variable-sized number from a property
  *
index 757931a9cb25119b3283b12bc985310310dae4d0..63b704a3d719b178c79da4068a477aded2c80e9f 100644 (file)
@@ -36,3 +36,21 @@ int fdtdec_get_int(const void *blob, int node, const char *prop_name,
        debug("(not found)\n");
        return default_val;
 }
+
+unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name,
+                       unsigned int default_val)
+{
+       const int *cell;
+       int len;
+
+       debug("%s: %s: ", __func__, prop_name);
+       cell = fdt_getprop(blob, node, prop_name, &len);
+       if (cell && len >= sizeof(unsigned int)) {
+               unsigned int val = fdt32_to_cpu(cell[0]);
+
+               debug("%#x (%d)\n", val, val);
+               return val;
+       }
+       debug("(not found)\n");
+       return default_val;
+}