blob: e0c823a4dd632b3c815cdb10589577e071434235 [file] [log] [blame]
Hans de Goededea16d22015-02-04 12:14:56 +01001/*
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>
Hans de Goede9be88492016-04-14 18:53:32 +020010#include <asm/armv7.h>
Hans de Goededea16d22015-02-04 12:14:56 +010011#include <asm/io.h>
12#include <asm/arch/dram.h>
13
14/*
15 * Wait up to 1s for value to be set in given part of reg.
16 */
17void mctl_await_completion(u32 *reg, u32 mask, u32 val)
18{
19 unsigned long tmo = timer_get_us() + 1000000;
20
21 while ((readl(reg) & mask) != val) {
22 if (timer_get_us() > tmo)
23 panic("Timeout initialising DRAM\n");
24 }
25}
26
27/*
28 * Test if memory at offset offset matches memory at begin of DRAM
29 */
30bool mctl_mem_matches(u32 offset)
31{
32 /* Try to write different values to RAM at two addresses */
33 writel(0, CONFIG_SYS_SDRAM_BASE);
Alexander Grafee1d8252016-03-29 17:29:09 +020034 writel(0xaa55aa55, (ulong)CONFIG_SYS_SDRAM_BASE + offset);
Hans de Goede9be88492016-04-14 18:53:32 +020035 DSB;
Hans de Goededea16d22015-02-04 12:14:56 +010036 /* Check if the same value is actually observed when reading back */
37 return readl(CONFIG_SYS_SDRAM_BASE) ==
Alexander Grafee1d8252016-03-29 17:29:09 +020038 readl((ulong)CONFIG_SYS_SDRAM_BASE + offset);
Hans de Goededea16d22015-02-04 12:14:56 +010039}