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