xref: /openbmc/u-boot/lib/fdtdec_common.c (revision 9ee16897)
1 /*
2  * Copyright (c) 2014
3  * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4  *
5  * Based on lib/fdtdec.c:
6  * Copyright (c) 2011 The Chromium OS Authors.
7  *
8  * SPDX-License-Identifier:	GPL-2.0+
9  */
10 
11 #ifndef USE_HOSTCC
12 #include <common.h>
13 #include <libfdt.h>
14 #include <fdtdec.h>
15 #else
16 #include "libfdt.h"
17 #include "fdt_support.h"
18 
19 #define debug(...)
20 #endif
21 
22 int fdtdec_get_int(const void *blob, int node, const char *prop_name,
23 		int default_val)
24 {
25 	const int *cell;
26 	int len;
27 
28 	debug("%s: %s: ", __func__, prop_name);
29 	cell = fdt_getprop(blob, node, prop_name, &len);
30 	if (cell && len >= sizeof(int)) {
31 		int val = fdt32_to_cpu(cell[0]);
32 
33 		debug("%#x (%d)\n", val, val);
34 		return val;
35 	}
36 	debug("(not found)\n");
37 	return default_val;
38 }
39