Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | b4782cd | 2015-09-11 20:17:49 +0900 | [diff] [blame] | 2 | * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Masahiro Yamada | b4782cd | 2015-09-11 20:17:49 +0900 | [diff] [blame] | 8 | #include <libfdt.h> |
| 9 | #include <linux/err.h> |
| 10 | |
| 11 | DECLARE_GLOBAL_DATA_PTR; |
| 12 | |
| 13 | static const void *get_memory_reg_prop(const void *fdt, int *lenp) |
| 14 | { |
| 15 | int offset; |
| 16 | |
| 17 | offset = fdt_path_offset(fdt, "/memory"); |
| 18 | if (offset < 0) |
| 19 | return NULL; |
| 20 | |
| 21 | return fdt_getprop(fdt, offset, "reg", lenp); |
| 22 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 23 | |
| 24 | int dram_init(void) |
| 25 | { |
Masahiro Yamada | b4782cd | 2015-09-11 20:17:49 +0900 | [diff] [blame] | 26 | const fdt32_t *val; |
| 27 | int len; |
| 28 | |
| 29 | val = get_memory_reg_prop(gd->fdt_blob, &len); |
| 30 | if (len < sizeof(*val)) |
| 31 | return -EINVAL; |
| 32 | |
| 33 | gd->ram_size = fdt32_to_cpu(*(val + 1)); |
| 34 | |
Masahiro Yamada | 0935010 | 2016-02-26 18:59:45 +0900 | [diff] [blame] | 35 | debug("DRAM size = %08lx\n", (unsigned long)gd->ram_size); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 36 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 37 | return 0; |
| 38 | } |
Masahiro Yamada | b4782cd | 2015-09-11 20:17:49 +0900 | [diff] [blame] | 39 | |
| 40 | void dram_init_banksize(void) |
| 41 | { |
| 42 | const fdt32_t *val; |
| 43 | int len, i; |
| 44 | |
| 45 | val = get_memory_reg_prop(gd->fdt_blob, &len); |
| 46 | if (len < 0) |
| 47 | return; |
| 48 | |
| 49 | len /= sizeof(*val); |
| 50 | len /= 2; |
| 51 | |
| 52 | for (i = 0; i < len; i++) { |
| 53 | gd->bd->bi_dram[i].start = fdt32_to_cpu(*val++); |
| 54 | gd->bd->bi_dram[i].size = fdt32_to_cpu(*val++); |
| 55 | |
| 56 | debug("DRAM bank %d: start = %08lx, size = %08lx\n", |
Masahiro Yamada | 0935010 | 2016-02-26 18:59:45 +0900 | [diff] [blame] | 57 | i, (unsigned long)gd->bd->bi_dram[i].start, |
| 58 | (unsigned long)gd->bd->bi_dram[i].size); |
Masahiro Yamada | b4782cd | 2015-09-11 20:17:49 +0900 | [diff] [blame] | 59 | } |
| 60 | } |