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>
|
2019-11-14 19:57:30 +00:00
|
|
|
#include <time.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
|
2022-01-29 15:23:04 +00:00
|
|
|
*
|
|
|
|
* Note: dsb() is not available on ARMv5 in Thumb mode
|
2015-02-04 11:14:56 +00:00
|
|
|
*/
|
2022-01-29 15:23:04 +00:00
|
|
|
#ifndef CONFIG_MACH_SUNIV
|
2015-02-04 11:14:56 +00:00
|
|
|
bool mctl_mem_matches(u32 offset)
|
|
|
|
{
|
|
|
|
/* Try to write different values to RAM at two addresses */
|
2022-11-16 18:10:37 +00:00
|
|
|
writel(0, CFG_SYS_SDRAM_BASE);
|
|
|
|
writel(0xaa55aa55, (ulong)CFG_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 */
|
2022-11-16 18:10:37 +00:00
|
|
|
return readl(CFG_SYS_SDRAM_BASE) ==
|
|
|
|
readl((ulong)CFG_SYS_SDRAM_BASE + offset);
|
2015-02-04 11:14:56 +00:00
|
|
|
}
|
2022-01-29 15:23:04 +00:00
|
|
|
#endif
|