summaryrefslogtreecommitdiff
path: root/arch/arm/include/asm/arch-sunxi/dram.h
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2014-12-08 13:58:53 +0100
committerHans de Goede <hdegoede@redhat.com>2015-01-14 14:56:37 +0100
commit5665f50e81fc76932307fa2351357517af31fefa (patch)
treeda668ae39eb551bcc5ada96c3d24995137b3225e /arch/arm/include/asm/arch-sunxi/dram.h
parent07f4fe7d7d94b03204dabd40b548bed4f796894c (diff)
downloadu-boot-imx-5665f50e81fc76932307fa2351357517af31fefa.zip
u-boot-imx-5665f50e81fc76932307fa2351357517af31fefa.tar.gz
u-boot-imx-5665f50e81fc76932307fa2351357517af31fefa.tar.bz2
sunxi: Fill memory before comparing it when doing dram init on sun6i
The sun8i boot0 code fills the DRAM with a "random" pattern before comparing it at different offsets to do columns, etc. detection. The sun6i boot0 code does not do it, instead relying on the memory contents being random enough to begin with for the memcmp to properly detect the wrap-around address, iow it is working purely by chance. Since our sun6i dram code was modelled after the boot0 code it contained the same issue. This commit fixes this by filling the memory with a unique, distinct pattern. The new mctl_mem_fill function this introduces is added as an inline helper in dram.h, so that it can be shared with the sun8i dram code. While at it move mctl_mem_matches to dram.h for re-use in sun8i too. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Ian Campbell <ijc@hellion.org.uk>
Diffstat (limited to 'arch/arm/include/asm/arch-sunxi/dram.h')
-rw-r--r--arch/arm/include/asm/arch-sunxi/dram.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/arch/arm/include/asm/arch-sunxi/dram.h b/arch/arm/include/asm/arch-sunxi/dram.h
index 18924f5..0bf718c 100644
--- a/arch/arm/include/asm/arch-sunxi/dram.h
+++ b/arch/arm/include/asm/arch-sunxi/dram.h
@@ -22,6 +22,8 @@
#include <asm/arch/dram_sun4i.h>
#endif
+#define MCTL_MEM_FILL_MATCH_COUNT 64
+
unsigned long sunxi_dram_init(void);
/*
@@ -37,4 +39,31 @@ static inline void mctl_await_completion(u32 *reg, u32 mask, u32 val)
}
}
+/*
+ * Fill beginning of DRAM with "random" data for mctl_mem_matches()
+ */
+static inline void mctl_mem_fill(void)
+{
+ int i;
+
+ for (i = 0; i < MCTL_MEM_FILL_MATCH_COUNT; i++)
+ writel(0xaa55aa55 + i, CONFIG_SYS_SDRAM_BASE + i * 4);
+}
+
+/*
+ * Test if memory at offset offset matches memory at begin of DRAM
+ */
+static inline bool mctl_mem_matches(u32 offset)
+{
+ int i, matches = 0;
+
+ for (i = 0; i < MCTL_MEM_FILL_MATCH_COUNT; i++) {
+ if (readl(CONFIG_SYS_SDRAM_BASE + i * 4) ==
+ readl(CONFIG_SYS_SDRAM_BASE + offset + i * 4))
+ matches++;
+ }
+
+ return matches == MCTL_MEM_FILL_MATCH_COUNT;
+}
+
#endif /* _SUNXI_DRAM_H */