1 // SPDX-License-Identifier: GPL-2.0+
3 * DRAM init helper functions
5 * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
10 #include <asm/barriers.h>
12 #include <asm/arch/dram.h>
15 * Wait up to 1s for value to be set in given part of reg.
17 void mctl_await_completion(u32 *reg, u32 mask, u32 val)
19 unsigned long tmo = timer_get_us() + 1000000;
21 while ((readl(reg) & mask) != val) {
22 if (timer_get_us() > tmo)
23 panic("Timeout initialising DRAM\n");
28 * Test if memory at offset offset matches memory at begin of DRAM
30 * Note: dsb() is not available on ARMv5 in Thumb mode
32 #ifndef CONFIG_MACH_SUNIV
33 bool mctl_mem_matches(u32 offset)
35 /* Try to write different values to RAM at two addresses */
36 writel(0, CFG_SYS_SDRAM_BASE);
37 writel(0xaa55aa55, (ulong)CFG_SYS_SDRAM_BASE + offset);
39 /* Check if the same value is actually observed when reading back */
40 return readl(CFG_SYS_SDRAM_BASE) ==
41 readl((ulong)CFG_SYS_SDRAM_BASE + offset);