Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | b047d67 | 2014-06-22 06:33:29 +0200 | [diff] [blame] | 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. |
Heiko Schocher | b047d67 | 2014-06-22 06:33:29 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef USE_HOSTCC |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
Heiko Schocher | b047d67 | 2014-06-22 06:33:29 +0200 | [diff] [blame] | 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 | { |
| 24 | const int *cell; |
| 25 | int len; |
| 26 | |
| 27 | debug("%s: %s: ", __func__, prop_name); |
| 28 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 29 | if (cell && len >= sizeof(int)) { |
| 30 | int val = fdt32_to_cpu(cell[0]); |
| 31 | |
| 32 | debug("%#x (%d)\n", val, val); |
| 33 | return val; |
| 34 | } |
| 35 | debug("(not found)\n"); |
| 36 | return default_val; |
| 37 | } |
Chin Liang See | bfa3e55 | 2015-10-17 08:30:32 -0500 | [diff] [blame] | 38 | |
| 39 | unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name, |
| 40 | unsigned int default_val) |
| 41 | { |
| 42 | const int *cell; |
| 43 | int len; |
| 44 | |
| 45 | debug("%s: %s: ", __func__, prop_name); |
| 46 | cell = fdt_getprop(blob, node, prop_name, &len); |
| 47 | if (cell && len >= sizeof(unsigned int)) { |
| 48 | unsigned int val = fdt32_to_cpu(cell[0]); |
| 49 | |
| 50 | debug("%#x (%d)\n", val, val); |
| 51 | return val; |
| 52 | } |
| 53 | debug("(not found)\n"); |
| 54 | return default_val; |
| 55 | } |
Kever Yang | 10d887d | 2020-03-30 11:56:23 +0800 | [diff] [blame] | 56 | |
| 57 | int fdtdec_get_child_count(const void *blob, int node) |
| 58 | { |
| 59 | int subnode; |
| 60 | int num = 0; |
| 61 | |
| 62 | fdt_for_each_subnode(subnode, blob, node) |
| 63 | num++; |
| 64 | |
| 65 | return num; |
| 66 | } |