summaryrefslogtreecommitdiff
path: root/arch/arm/mach-uniphier/dram_init.c
blob: 32cc448aeb5b3b71b2f40c696dbaa0b84ed1db7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <libfdt.h>
#include <linux/err.h>

DECLARE_GLOBAL_DATA_PTR;

static const void *get_memory_reg_prop(const void *fdt, int *lenp)
{
	int offset;

	offset = fdt_path_offset(fdt, "/memory");
	if (offset < 0)
		return NULL;

	return fdt_getprop(fdt, offset, "reg", lenp);
}

int dram_init(void)
{
	const fdt32_t *val;
	int len;

	val = get_memory_reg_prop(gd->fdt_blob, &len);
	if (len < sizeof(*val))
		return -EINVAL;

	gd->ram_size = fdt32_to_cpu(*(val + 1));

	debug("DRAM size = %08lx\n", gd->ram_size);

	return 0;
}

void dram_init_banksize(void)
{
	const fdt32_t *val;
	int len, i;

	val = get_memory_reg_prop(gd->fdt_blob, &len);
	if (len < 0)
		return;

	len /= sizeof(*val);
	len /= 2;

	for (i = 0; i < len; i++) {
		gd->bd->bi_dram[i].start = fdt32_to_cpu(*val++);
		gd->bd->bi_dram[i].size = fdt32_to_cpu(*val++);

		debug("DRAM bank %d: start = %08lx, size = %08lx\n",
		      i, gd->bd->bi_dram[i].start, gd->bd->bi_dram[i].size);
	}
}