fdt: Add function to locate an array in the device tree
[oweals/u-boot.git] / include / fdtdec.h
index 2f3842d9a306c28b05577c0c548995157259a971..84f07685268906387cdc3fb8cfd113282faf37b3 100644 (file)
@@ -57,6 +57,9 @@ struct fdt_memory {
  */
 enum fdt_compat_id {
        COMPAT_UNKNOWN,
+       COMPAT_NVIDIA_TEGRA20_USB,      /* Tegra2 USB port */
+       COMPAT_NVIDIA_TEGRA20_I2C,      /* Tegra2 i2c */
+       COMPAT_NVIDIA_TEGRA20_DVC,      /* Tegra2 dvc (really just i2c) */
 
        COMPAT_COUNT,
 };
@@ -154,8 +157,21 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name,
 int fdtdec_get_is_enabled(const void *blob, int node);
 
 /**
- * Checks whether we have a valid fdt available to control U-Boot, and panic
- * if not.
+ * Make sure we have a valid fdt available to control U-Boot.
+ *
+ * If not, a message is printed to the console if the console is ready.
+ *
+ * @return 0 if all ok, -1 if not
+ */
+int fdtdec_prepare_fdt(void);
+
+/**
+ * Checks that we have a valid fdt available to control U-Boot.
+
+ * However, if not then for the moment nothing is done, since this function
+ * is called too early to panic().
+ *
+ * @returns 0
  */
 int fdtdec_check_fdt(void);
 
@@ -198,6 +214,29 @@ int fdtdec_check_fdt(void);
 int fdtdec_find_aliases_for_id(const void *blob, const char *name,
                        enum fdt_compat_id id, int *node_list, int maxcount);
 
+/*
+ * This function is similar to fdtdec_find_aliases_for_id() except that it
+ * adds to the node_list that is passed in. Any 0 elements are considered
+ * available for allocation - others are considered already used and are
+ * skipped.
+ *
+ * You can use this by calling fdtdec_find_aliases_for_id() with an
+ * uninitialised array, then setting the elements that are returned to -1,
+ * say, then calling this function, perhaps with a different compat id.
+ * Any elements you get back that are >0 are new nodes added by the call
+ * to this function.
+ *
+ * Note that if you have some nodes with aliases and some without, you are
+ * sailing close to the wind. The call to fdtdec_find_aliases_for_id() with
+ * one compat_id may fill in positions for which you have aliases defined
+ * for another compat_id. When you later call *this* function with the second
+ * compat_id, the alias positions may already be used. A debug warning may
+ * be generated in this case, but it is safest to define aliases for all
+ * nodes when you care about the ordering.
+ */
+int fdtdec_add_aliases_for_id(const void *blob, const char *name,
+                       enum fdt_compat_id id, int *node_list, int maxcount);
+
 /*
  * Get the name for a compatible ID
  *
@@ -232,6 +271,25 @@ int fdtdec_lookup_phandle(const void *blob, int node, const char *prop_name);
 int fdtdec_get_int_array(const void *blob, int node, const char *prop_name,
                u32 *array, int count);
 
+/**
+ * Look up a property in a node and return a pointer to its contents as a
+ * unsigned int array of given length. The property must have at least enough
+ * data for the array ('count' cells). It may have more, but this will be
+ * ignored. The data is not copied.
+ *
+ * Note that you must access elements of the array with fdt32_to_cpu(),
+ * since the elements will be big endian even on a little endian machine.
+ *
+ * @param blob         FDT blob
+ * @param node         node to examine
+ * @param prop_name    name of property to find
+ * @param count                number of array elements
+ * @return pointer to array if found, or NULL if the property is not
+ *             found or there is not enough data
+ */
+const u32 *fdtdec_locate_array(const void *blob, int node,
+                              const char *prop_name, int count);
+
 /**
  * Look up a boolean property in a node and return it.
  *