fdtdec_common.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 <linux/libfdt.h>
  12. #include <fdtdec.h>
  13. #else
  14. #include "libfdt.h"
  15. #include "fdt_support.h"
  16. #define debug(...)
  17. #endif
  18. int fdtdec_get_int(const void *blob, int node, const char *prop_name,
  19. int default_val)
  20. {
  21. const int *cell;
  22. int len;
  23. debug("%s: %s: ", __func__, prop_name);
  24. cell = fdt_getprop(blob, node, prop_name, &len);
  25. if (cell && len >= sizeof(int)) {
  26. int val = fdt32_to_cpu(cell[0]);
  27. debug("%#x (%d)\n", val, val);
  28. return val;
  29. }
  30. debug("(not found)\n");
  31. return default_val;
  32. }
  33. unsigned int fdtdec_get_uint(const void *blob, int node, const char *prop_name,
  34. unsigned int default_val)
  35. {
  36. const int *cell;
  37. int len;
  38. debug("%s: %s: ", __func__, prop_name);
  39. cell = fdt_getprop(blob, node, prop_name, &len);
  40. if (cell && len >= sizeof(unsigned int)) {
  41. unsigned int val = fdt32_to_cpu(cell[0]);
  42. debug("%#x (%d)\n", val, val);
  43. return val;
  44. }
  45. debug("(not found)\n");
  46. return default_val;
  47. }