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