]> git.karo-electronics.de Git - karo-tx-uboot.git/commitdiff
fdt: Add function to get config int from device tree
authorAbhilash Kesavan <a.kesavan@samsung.com>
Thu, 25 Oct 2012 16:30:58 +0000 (16:30 +0000)
committerGerald Van Baren <gvb@unssw.com>
Tue, 13 Nov 2012 04:00:34 +0000 (23:00 -0500)
Add a function to look up a configuration item such as machine id
and return its value.

Note: The code has been taken as is from the Chromium u-boot development
tree and needs Simon Glass' sign-off.

Signed-off-by: Abhilash Kesavan <a.kesavan@samsung.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
include/fdtdec.h
lib/fdtdec.c

index 0b140752ffb058c4fa673b10fe6a3ff6e751aab8..d880fe8d9ed66a2a150987b214a74c1049b3e1b0 100644 (file)
@@ -354,6 +354,19 @@ int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name,
  */
 int fdtdec_setup_gpio(struct fdt_gpio_state *gpio);
 
+/**
+ * Look in the FDT for a config item with the given name and return its value
+ * as a 32-bit integer. The property must have at least 4 bytes of data. The
+ * value of the first cell is returned.
+ *
+ * @param blob         FDT blob to use
+ * @param prop_name    Node property name
+ * @param default_val  default value to return if the property is not found
+ * @return integer value, if found, or default_val if not
+ */
+int fdtdec_get_config_int(const void *blob, const char *prop_name,
+               int default_val);
+
 /*
  * Look up a property in a node and return its contents in a byte
  * array of given length. The property must have at least enough data for
index 4c23f458f0f51b5ce52345333cdb44557a358859..1f500224d9477664bac478b9b7eb9e6f53d04c99 100644 (file)
@@ -512,3 +512,25 @@ const u8 *fdtdec_locate_byte_array(const void *blob, int node,
                return NULL;
        return cell;
 }
+
+/**
+ * Look in the FDT for a config item with the given name and return its value
+ * as a 32-bit integer. The property must have at least 4 bytes of data. The
+ * value of the first cell is returned.
+ *
+ * @param blob         FDT blob to use
+ * @param prop_name    Node property name
+ * @param default_val  default value to return if the property is not found
+ * @return integer value, if found, or default_val if not
+ */
+int fdtdec_get_config_int(const void *blob, const char *prop_name,
+               int default_val)
+{
+       int config_node;
+
+       debug("%s: %s\n", __func__, prop_name);
+       config_node = fdt_path_offset(blob, "/config");
+       if (config_node < 0)
+               return default_val;
+       return fdtdec_get_int(blob, config_node, prop_name, default_val);
+}