blob: 7ff43e6d3a90fa46c35785a92fce4b1818c8168f [file] [log] [blame]
Ian Campbell2f1afcc2014-05-05 11:52:25 +01001/*
2 * (C) Copyright 2007-2012
3 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
4 * Berg Xing <bergxing@allwinnertech.com>
5 * Tom Cubie <tangliang@allwinnertech.com>
6 *
7 * Sunxi platform dram register definition.
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 */
11
12#ifndef _SUNXI_DRAM_H
13#define _SUNXI_DRAM_H
14
Hans de Goede36b25702014-12-08 13:38:21 +010015#include <asm/io.h>
Ian Campbell2f1afcc2014-05-05 11:52:25 +010016#include <linux/types.h>
17
Hans de Goede5037c452014-11-02 20:31:16 +010018/* dram regs definition */
Hans de Goede31521222014-10-25 20:27:23 +020019#if defined(CONFIG_MACH_SUN6I)
20#include <asm/arch/dram_sun6i.h>
Hans de Goede966d2392014-12-07 14:34:27 +010021#elif defined(CONFIG_MACH_SUN8I)
22#include <asm/arch/dram_sun8i.h>
Hans de Goede31521222014-10-25 20:27:23 +020023#else
Hans de Goede5037c452014-11-02 20:31:16 +010024#include <asm/arch/dram_sun4i.h>
Hans de Goede31521222014-10-25 20:27:23 +020025#endif
Ian Campbell2f1afcc2014-05-05 11:52:25 +010026
27unsigned long sunxi_dram_init(void);
Ian Campbell2f1afcc2014-05-05 11:52:25 +010028
Hans de Goede36b25702014-12-08 13:38:21 +010029/*
30 * Wait up to 1s for value to be set in given part of reg.
31 */
32static inline void mctl_await_completion(u32 *reg, u32 mask, u32 val)
33{
34 unsigned long tmo = timer_get_us() + 1000000;
35
36 while ((readl(reg) & mask) != val) {
37 if (timer_get_us() > tmo)
38 panic("Timeout initialising DRAM\n");
39 }
40}
41
Hans de Goedeb29de012014-12-08 13:58:53 +010042/*
Hans de Goedeb29de012014-12-08 13:58:53 +010043 * Test if memory at offset offset matches memory at begin of DRAM
44 */
45static inline bool mctl_mem_matches(u32 offset)
46{
Siarhei Siamashka59ed6012014-12-24 18:58:17 +020047 /* Try to write different values to RAM at two addresses */
48 writel(0, CONFIG_SYS_SDRAM_BASE);
49 writel(0xaa55aa55, CONFIG_SYS_SDRAM_BASE + offset);
50 /* Check if the same value is actually observed when reading back */
51 return readl(CONFIG_SYS_SDRAM_BASE) ==
52 readl(CONFIG_SYS_SDRAM_BASE + offset);
Hans de Goedeb29de012014-12-08 13:58:53 +010053}
54
Ian Campbell2f1afcc2014-05-05 11:52:25 +010055#endif /* _SUNXI_DRAM_H */