fdtdec_common.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef USE_HOSTCC
  11. #include <common.h>
  12. #include <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. }