stm32mp_ram.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2022-2023, STMicroelectronics - All Rights Reserved
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <errno.h>
  7. #include <stdbool.h>
  8. #include <common/debug.h>
  9. #include <common/fdt_wrappers.h>
  10. #include <drivers/st/stm32mp_ram.h>
  11. #include <libfdt.h>
  12. #include <platform_def.h>
  13. int stm32mp_ddr_dt_get_info(void *fdt, int node, struct stm32mp_ddr_info *info)
  14. {
  15. int ret;
  16. ret = fdt_read_uint32(fdt, node, "st,mem-speed", &info->speed);
  17. if (ret < 0) {
  18. VERBOSE("%s: no st,mem-speed\n", __func__);
  19. return -EINVAL;
  20. }
  21. info->size = dt_get_ddr_size();
  22. if (info->size == 0U) {
  23. VERBOSE("%s: no st,mem-size\n", __func__);
  24. return -EINVAL;
  25. }
  26. info->name = fdt_getprop(fdt, node, "st,mem-name", NULL);
  27. if (info->name == NULL) {
  28. VERBOSE("%s: no st,mem-name\n", __func__);
  29. return -EINVAL;
  30. }
  31. INFO("RAM: %s\n", info->name);
  32. return 0;
  33. }
  34. int stm32mp_ddr_dt_get_param(void *fdt, int node, const struct stm32mp_ddr_param *param,
  35. uint32_t param_size, uintptr_t config)
  36. {
  37. int ret;
  38. uint32_t idx;
  39. for (idx = 0U; idx < param_size; idx++) {
  40. ret = fdt_read_uint32_array(fdt, node, param[idx].name, param[idx].size,
  41. (void *)(config + param[idx].offset));
  42. VERBOSE("%s: %s[0x%x] = %d\n", __func__, param[idx].name, param[idx].size, ret);
  43. if (ret != 0) {
  44. ERROR("%s: Cannot read %s, error=%d\n", __func__, param[idx].name, ret);
  45. return -EINVAL;
  46. }
  47. }
  48. return 0;
  49. }