fdtdec_common.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #ifndef USE_HOSTCC
  10. #include <common.h>
  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. #define debug(...)
  18. #endif
  19. int fdtdec_get_int(const void *blob, int node, const char *prop_name,
  20. int default_val)
  21. {
  22. const int *cell;
  23. int len;
  24. debug("%s: %s: ", __func__, prop_name);
  25. cell = fdt_getprop(blob, node, prop_name, &len);
  26. if (cell && len >= sizeof(int)) {
  27. int val = fdt32_to_cpu(cell[0]);
  28. debug("%#x (%d)\n", val, val);
  29. return val;
  30. }
  31. debug("(not found)\n");
  32. return default_val;
  33. }
  34. unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name,
  35. unsigned int default_val)
  36. {
  37. const int *cell;
  38. int len;
  39. debug("%s: %s: ", __func__, prop_name);
  40. cell = fdt_getprop(blob, node, prop_name, &len);
  41. if (cell && len >= sizeof(unsigned int)) {
  42. unsigned int val = fdt32_to_cpu(cell[0]);
  43. debug("%#x (%d)\n", val, val);
  44. return val;
  45. }
  46. debug("(not found)\n");
  47. return default_val;
  48. }
  49. int fdtdec_get_child_count(const void *blob, int node)
  50. {
  51. int subnode;
  52. int num = 0;
  53. fdt_for_each_subnode(subnode, blob, node)
  54. num++;
  55. return num;
  56. }