blob: cffdfc9841c57b62caeb4e200e2c331a8241c646 [file] [log] [blame]
Masahiro Yamada5894ca02014-10-03 19:21:06 +09001/*
Masahiro Yamadacf88aff2015-09-11 20:17:49 +09002 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada5894ca02014-10-03 19:21:06 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamadacf88aff2015-09-11 20:17:49 +09008#include <libfdt.h>
9#include <linux/err.h>
10
11DECLARE_GLOBAL_DATA_PTR;
12
13static 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 Yamada5894ca02014-10-03 19:21:06 +090023
24int dram_init(void)
25{
Masahiro Yamadacf88aff2015-09-11 20:17:49 +090026 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 Yamada11d3ede2016-02-26 18:59:45 +090035 debug("DRAM size = %08lx\n", (unsigned long)gd->ram_size);
Masahiro Yamada5894ca02014-10-03 19:21:06 +090036
Masahiro Yamada5894ca02014-10-03 19:21:06 +090037 return 0;
38}
Masahiro Yamadacf88aff2015-09-11 20:17:49 +090039
40void 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 Yamada11d3ede2016-02-26 18:59:45 +090057 i, (unsigned long)gd->bd->bi_dram[i].start,
58 (unsigned long)gd->bd->bi_dram[i].size);
Masahiro Yamadacf88aff2015-09-11 20:17:49 +090059 }
60}