xref: /openbmc/u-boot/arch/arm/include/asm/arch-sunxi/dram.h (revision 07f4fe7d7d94b03204dabd40b548bed4f796894c)
1286c3c3aSIan Campbell /*
2286c3c3aSIan Campbell  * (C) Copyright 2007-2012
3286c3c3aSIan Campbell  * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
4286c3c3aSIan Campbell  * Berg Xing <bergxing@allwinnertech.com>
5286c3c3aSIan Campbell  * Tom Cubie <tangliang@allwinnertech.com>
6286c3c3aSIan Campbell  *
7286c3c3aSIan Campbell  * Sunxi platform dram register definition.
8286c3c3aSIan Campbell  *
9286c3c3aSIan Campbell  * SPDX-License-Identifier:	GPL-2.0+
10286c3c3aSIan Campbell  */
11286c3c3aSIan Campbell 
12286c3c3aSIan Campbell #ifndef _SUNXI_DRAM_H
13286c3c3aSIan Campbell #define _SUNXI_DRAM_H
14286c3c3aSIan Campbell 
15*07f4fe7dSHans de Goede #include <asm/io.h>
16286c3c3aSIan Campbell #include <linux/types.h>
17286c3c3aSIan Campbell 
18bec72c79SHans de Goede /* dram regs definition */
199a07eb0bSHans de Goede #if defined(CONFIG_MACH_SUN6I)
209a07eb0bSHans de Goede #include <asm/arch/dram_sun6i.h>
219a07eb0bSHans de Goede #else
22bec72c79SHans de Goede #include <asm/arch/dram_sun4i.h>
239a07eb0bSHans de Goede #endif
24286c3c3aSIan Campbell 
25286c3c3aSIan Campbell unsigned long sunxi_dram_init(void);
26286c3c3aSIan Campbell 
27*07f4fe7dSHans de Goede /*
28*07f4fe7dSHans de Goede  * Wait up to 1s for value to be set in given part of reg.
29*07f4fe7dSHans de Goede  */
30*07f4fe7dSHans de Goede static inline void mctl_await_completion(u32 *reg, u32 mask, u32 val)
31*07f4fe7dSHans de Goede {
32*07f4fe7dSHans de Goede 	unsigned long tmo = timer_get_us() + 1000000;
33*07f4fe7dSHans de Goede 
34*07f4fe7dSHans de Goede 	while ((readl(reg) & mask) != val) {
35*07f4fe7dSHans de Goede 		if (timer_get_us() > tmo)
36*07f4fe7dSHans de Goede 			panic("Timeout initialising DRAM\n");
37*07f4fe7dSHans de Goede 	}
38*07f4fe7dSHans de Goede }
39*07f4fe7dSHans de Goede 
40286c3c3aSIan Campbell #endif /* _SUNXI_DRAM_H */
41