Nicolas Le Bayon | 8ce825f | 2021-05-18 10:01:30 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
Yann Gautier | dcdc2fd | 2022-01-19 14:15:48 +0100 | [diff] [blame] | 10 | #include <common/debug.h> |
Nicolas Le Bayon | 8ce825f | 2021-05-18 10:01:30 +0200 | [diff] [blame] | 11 | #include <common/fdt_wrappers.h> |
| 12 | #include <drivers/st/stm32mp_ram.h> |
| 13 | #include <libfdt.h> |
| 14 | |
| 15 | #include <platform_def.h> |
| 16 | |
| 17 | int stm32mp_ddr_dt_get_info(void *fdt, int node, struct stm32mp_ddr_info *info) |
| 18 | { |
| 19 | int ret; |
| 20 | |
| 21 | ret = fdt_read_uint32(fdt, node, "st,mem-speed", &info->speed); |
| 22 | if (ret < 0) { |
| 23 | VERBOSE("%s: no st,mem-speed\n", __func__); |
| 24 | return -EINVAL; |
| 25 | } |
| 26 | ret = fdt_read_uint32(fdt, node, "st,mem-size", &info->size); |
| 27 | if (ret < 0) { |
| 28 | VERBOSE("%s: no st,mem-size\n", __func__); |
| 29 | return -EINVAL; |
| 30 | } |
| 31 | info->name = fdt_getprop(fdt, node, "st,mem-name", NULL); |
| 32 | if (info->name == NULL) { |
| 33 | VERBOSE("%s: no st,mem-name\n", __func__); |
| 34 | return -EINVAL; |
| 35 | } |
| 36 | |
| 37 | INFO("RAM: %s\n", info->name); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | int stm32mp_ddr_dt_get_param(void *fdt, int node, const struct stm32mp_ddr_param *param, |
| 43 | uint32_t param_size, uintptr_t config) |
| 44 | { |
| 45 | int ret; |
| 46 | uint32_t idx; |
| 47 | |
| 48 | for (idx = 0U; idx < param_size; idx++) { |
| 49 | ret = fdt_read_uint32_array(fdt, node, param[idx].name, param[idx].size, |
| 50 | (void *)(config + param[idx].offset)); |
| 51 | |
| 52 | VERBOSE("%s: %s[0x%x] = %d\n", __func__, param[idx].name, param[idx].size, ret); |
| 53 | if (ret != 0) { |
| 54 | ERROR("%s: Cannot read %s, error=%d\n", __func__, param[idx].name, ret); |
| 55 | return -EINVAL; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return 0; |
| 60 | } |