Skip to contentSkip to conversation

lib, fdt: Adding fdtdec_get_uint function

PATCH New Chin Liang See 2 participants 2 messages Oct 17, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/5 lib, fdt: Adding fdtdec_get_uint function

Adding fdtdec_get_uint function which is the unsigned version for fdtdec_get_int

Cc Dinh Nguyen <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Heiko Schocher <[email protected]>

---
Changes for v5
- shuffling the patches
- fixed the commit message
Changes for v4
- Drop idea on enabling fdt_support in SPL build

---
 include/fdtdec.h    | 13 +++++++++++++
 lib/fdtdec_common.c | 18 ++++++++++++++++++
 2 files changed, 31 insertions(+)
include/fdtdec.h +13 -0
index 2de6dda..d51e643 100644
@@ -490,6 +490,19 @@ 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
  *
  * This reads a number from one or more cells.
lib/fdtdec_common.c +18 -0
index 757931a..63b704a 100644
@@ -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;
+}
Signature · 1 line
2.2.0
#1 lore raw

PATCH v5 1/5 lib, fdt: Adding fdtdec_get_uint function

Quoted 12 lines · Chin Liang See

Adding fdtdec_get_uint function which is the unsigned version for fdtdec_get_int

Cc Dinh Nguyen <[email protected]>
Cc Dinh Nguyen <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Stefan Roese <[email protected]>
Cc Vikas Manocha <[email protected]>
Cc Jagannadh Teki <[email protected]>
Cc Pavel Machek <[email protected]>
Cc Heiko Schocher <[email protected]>

Best regards,
Marek Vasut