[4/6] FDT: Api to find compatible id for a given node

Message ID 1352352603-17114-5-git-send-email-rajeshwari.s@samsung.com
State New
Headers show

Commit Message

Rajeshwari Shinde Nov. 8, 2012, 5:30 a.m.
This patch adds api to find compatible id for a given
FDT node

Signed-off-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>
---
 include/fdtdec.h |   14 ++++++++++++++
 lib/fdtdec.c     |   12 ++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

Comments

Simon Glass Nov. 9, 2012, 12:59 a.m. | #1
On Wed, Nov 7, 2012 at 9:30 PM, Rajeshwari Shinde
<rajeshwari.s@samsung.com> wrote:
> This patch adds api to find compatible id for a given
> FDT node
>
> Signed-off-by: Rajeshwari Shinde <rajeshwari.s@samsung.com>

Acked-by: Simon Glass <sjg@chromium.org>

Patch

diff --git a/include/fdtdec.h b/include/fdtdec.h
index f9aac31..d501d7e 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -389,4 +389,18 @@  int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
  */
 const u8 *fdtdec_locate_byte_array(const void *blob, int node,
 			     const char *prop_name, int count);
+
+/**
+ * Find the compatible ID for a given node.
+ *
+ * Generally each node has at least one compatible string attached to it.
+ * This function looks through our list of known compatible strings and
+ * returns the corresponding ID which matches the compatible string.
+ *
+ * @param blob          FDT blob to use
+ * @param node          Node containing compatible string to find
+ * @return compatible ID, or COMPAT_UNKNOWN if we cannot find a match
+ */
+enum fdt_compat_id fdtdec_lookup(const void *blob, int node);
+
 #endif
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 6e8c24c..dbfca1a 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -516,3 +516,15 @@  const u8 *fdtdec_locate_byte_array(const void *blob, int node,
 		return NULL;
 	return cell;
 }
+
+enum fdt_compat_id fdtdec_lookup(const void *blob, int node)
+{
+	enum fdt_compat_id id;
+
+	/* Search our drivers */
+	for (id = COMPAT_UNKNOWN; id < COMPAT_COUNT; id++)
+		if (0 == fdt_node_check_compatible(blob, node,
+				compat_names[id]))
+			return id;
+	return COMPAT_UNKNOWN;
+}