]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/include/asm/arch-sunxi/dram.h
sun8i: Add dram initialization support
[karo-tx-uboot.git] / arch / arm / include / asm / arch-sunxi / dram.h
1 /*
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
15 #include <asm/io.h>
16 #include <linux/types.h>
17
18 /* dram regs definition */
19 #if defined(CONFIG_MACH_SUN6I)
20 #include <asm/arch/dram_sun6i.h>
21 #elif defined(CONFIG_MACH_SUN8I)
22 #include <asm/arch/dram_sun8i.h>
23 #else
24 #include <asm/arch/dram_sun4i.h>
25 #endif
26
27 #define MCTL_MEM_FILL_MATCH_COUNT 64
28
29 unsigned long sunxi_dram_init(void);
30
31 /*
32  * Wait up to 1s for value to be set in given part of reg.
33  */
34 static inline void mctl_await_completion(u32 *reg, u32 mask, u32 val)
35 {
36         unsigned long tmo = timer_get_us() + 1000000;
37
38         while ((readl(reg) & mask) != val) {
39                 if (timer_get_us() > tmo)
40                         panic("Timeout initialising DRAM\n");
41         }
42 }
43
44 /*
45  * Fill beginning of DRAM with "random" data for mctl_mem_matches()
46  */
47 static inline void mctl_mem_fill(void)
48 {
49         int i;
50
51         for (i = 0; i < MCTL_MEM_FILL_MATCH_COUNT; i++)
52                 writel(0xaa55aa55 + i, CONFIG_SYS_SDRAM_BASE + i * 4);
53 }
54
55 /*
56  * Test if memory at offset offset matches memory at begin of DRAM
57  */
58 static inline bool mctl_mem_matches(u32 offset)
59 {
60         return memcmp((u32 *)CONFIG_SYS_SDRAM_BASE,
61                       (u32 *)(CONFIG_SYS_SDRAM_BASE + offset),
62                       MCTL_MEM_FILL_MATCH_COUNT * 4) == 0;
63 }
64
65 #endif /* _SUNXI_DRAM_H */