]> git.sur5r.net Git - u-boot/blob - arch/arm/mach-sunxi/dram_helpers.c
Merge branch 'master' of git://www.denx.de/git/u-boot-imx
[u-boot] / arch / arm / mach-sunxi / dram_helpers.c
1 /*
2  * DRAM init helper functions
3  *
4  * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <asm/io.h>
11 #include <asm/arch/dram.h>
12
13 /*
14  * Wait up to 1s for value to be set in given part of reg.
15  */
16 void mctl_await_completion(u32 *reg, u32 mask, u32 val)
17 {
18         unsigned long tmo = timer_get_us() + 1000000;
19
20         while ((readl(reg) & mask) != val) {
21                 if (timer_get_us() > tmo)
22                         panic("Timeout initialising DRAM\n");
23         }
24 }
25
26 /*
27  * Test if memory at offset offset matches memory at begin of DRAM
28  */
29 bool mctl_mem_matches(u32 offset)
30 {
31         /* Try to write different values to RAM at two addresses */
32         writel(0, CONFIG_SYS_SDRAM_BASE);
33         writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset);
34         /* Check if the same value is actually observed when reading back */
35         return readl(CONFIG_SYS_SDRAM_BASE) ==
36                readl((ulong)CONFIG_SYS_SDRAM_BASE + offset);
37 }