2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-02-04 11:14:56 +00:00
|
|
|
/*
|
|
|
|
* DRAM init helper functions
|
|
|
|
*
|
|
|
|
* (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-05-12 11:14:41 +00:00
|
|
|
#include <asm/barriers.h>
|
2015-02-04 11:14:56 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/dram.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait up to 1s for value to be set in given part of reg.
|
|
|
|
*/
|
|
|
|
void mctl_await_completion(u32 *reg, u32 mask, u32 val)
|
|
|
|
{
|
|
|
|
unsigned long tmo = timer_get_us() + 1000000;
|
|
|
|
|
|
|
|
while ((readl(reg) & mask) != val) {
|
|
|
|
if (timer_get_us() > tmo)
|
|
|
|
panic("Timeout initialising DRAM\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test if memory at offset offset matches memory at begin of DRAM
|
|
|
|
*/
|
|
|
|
bool mctl_mem_matches(u32 offset)
|
|
|
|
{
|
|
|
|
/* Try to write different values to RAM at two addresses */
|
|
|
|
writel(0, CONFIG_SYS_SDRAM_BASE);
|
2016-03-29 15:29:09 +00:00
|
|
|
writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset);
|
2016-08-01 22:54:53 +00:00
|
|
|
dsb();
|
2015-02-04 11:14:56 +00:00
|
|
|
/* Check if the same value is actually observed when reading back */
|
|
|
|
return readl(CONFIG_SYS_SDRAM_BASE) ==
|
2016-03-29 15:29:09 +00:00
|
|
|
readl((ulong)CONFIG_SYS_SDRAM_BASE + offset);
|
2015-02-04 11:14:56 +00:00
|
|
|
}
|