/src/u-boot/lib/fdtdec_common.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-2.0+ |
2 | | /* |
3 | | * Copyright (c) 2014 |
4 | | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
5 | | * |
6 | | * Based on lib/fdtdec.c: |
7 | | * Copyright (c) 2011 The Chromium OS Authors. |
8 | | */ |
9 | | |
10 | | #ifndef USE_HOSTCC |
11 | | #include <log.h> |
12 | | #include <linux/libfdt.h> |
13 | | #include <fdtdec.h> |
14 | | #else |
15 | | #include "libfdt.h" |
16 | | #include "fdt_support.h" |
17 | | |
18 | | #define debug(...) |
19 | | #endif |
20 | | |
21 | | int fdtdec_get_int(const void *blob, int node, const char *prop_name, |
22 | | int default_val) |
23 | 0 | { |
24 | 0 | const int *cell; |
25 | 0 | int len; |
26 | |
|
27 | 0 | debug("%s: %s: ", __func__, prop_name); |
28 | 0 | cell = fdt_getprop(blob, node, prop_name, &len); |
29 | 0 | if (cell && len >= sizeof(int)) { |
30 | 0 | int val = fdt32_to_cpu(cell[0]); |
31 | |
|
32 | 0 | debug("%#x (%d)\n", val, val); |
33 | 0 | return val; |
34 | 0 | } |
35 | 0 | debug("(not found)\n"); |
36 | 0 | return default_val; |
37 | 0 | } |
38 | | |
39 | | unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name, |
40 | | unsigned int default_val) |
41 | 0 | { |
42 | 0 | const int *cell; |
43 | 0 | int len; |
44 | |
|
45 | 0 | debug("%s: %s: ", __func__, prop_name); |
46 | 0 | cell = fdt_getprop(blob, node, prop_name, &len); |
47 | 0 | if (cell && len >= sizeof(unsigned int)) { |
48 | 0 | unsigned int val = fdt32_to_cpu(cell[0]); |
49 | |
|
50 | 0 | debug("%#x (%d)\n", val, val); |
51 | 0 | return val; |
52 | 0 | } |
53 | 0 | debug("(not found)\n"); |
54 | 0 | return default_val; |
55 | 0 | } |
56 | | |
57 | | int fdtdec_get_child_count(const void *blob, int node) |
58 | 0 | { |
59 | 0 | int subnode; |
60 | 0 | int num = 0; |
61 | |
|
62 | 0 | fdt_for_each_subnode(subnode, blob, node) |
63 | 0 | num++; |
64 | |
|
65 | 0 | return num; |
66 | 0 | } |