2 * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@emcraft.com
4 * Developed for DENX Software Engineering GmbH
6 * SPDX-License-Identifier: GPL-2.0+
10 /* This test attempts to verify board GDC. A scratch register tested, then
11 * simple memory test (get_ram_size()) run over GDC memory.
19 DECLARE_GLOBAL_DATA_PTR;
21 #define GDC_SCRATCH_REG 0xC1FF8044
22 #define GDC_VERSION_REG 0xC1FF8084
23 #define GDC_HOST_BASE 0xC1FC0000
24 #define GDC_RAM_START 0xC0000000
25 #define GDC_RAM_END (GDC_HOST_BASE - 1)
26 #define GDC_RAM_SIZE (GDC_RAM_END - GDC_RAM_START)
28 #if CONFIG_POST & CONFIG_SYS_POST_BSPEC4
30 const static unsigned long pattern[] = {
45 const static unsigned long otherpattern = 0x01234567;
47 /* test write/read og a given LIME Register */
48 static int gdc_test_reg_one(uint value)
52 /* write test pattern */
53 out_be32((void *)GDC_SCRATCH_REG, value);
54 /* read other location (protect against data lines capacity) */
55 in_be32((void *)GDC_RAM_START);
56 /* verify test pattern */
57 read_value = in_be32((void *)GDC_SCRATCH_REG);
58 if (read_value != value) {
59 post_log("GDC SCRATCH test failed write %08X, read %08X\n",
63 return (read_value != value);
66 /* test with a given static 32 bit pattern in a given memory addressrange */
67 static int gdc_post_test1(ulong *start, ulong size, ulong val)
74 for (i = 0; i < size / sizeof(ulong); i++) {
80 for (i = 0; i < size / sizeof(ulong); i++) {
82 if (readback != val) {
83 post_log("GDC Memory error at %08x, "
84 "wrote %08x, read %08x !\n",
85 mem + i, val, readback);
96 /* test with dynamic 32 bit pattern in a given memory addressrange */
97 static int gdc_post_test2(ulong *start, ulong size)
104 for (i = 0; i < size / sizeof(ulong); i++) {
105 mem[i] = 1 << (i % 32);
110 for (i = 0; i < size / sizeof(ulong); i++) {
112 if (readback != 1 << (i % 32)) {
113 post_log("GDC Memory error at %08x, "
114 "wrote %08x, read %08x !\n",
115 mem + i, 1 << (i % 32), readback);
126 /* test with dynamic 32 bit pattern in a given memory addressrange */
127 static int gdc_post_test3(ulong *start, ulong size)
134 for (i = 0; i < size / sizeof(ulong); i++) {
140 for (i = 0; i < size / sizeof(ulong); i++) {
143 post_log("GDC Memory error at %08x, "
144 "wrote %08x, read %08x !\n",
145 mem + i, i, readback);
156 /* test with dynamic 32 bit pattern in a given memory addressrange */
157 static int gdc_post_test4(ulong *start, ulong size)
164 for (i = 0; i < size / sizeof(ulong); i++) {
170 for (i = 0; i < size / sizeof(ulong); i++) {
172 if (readback != ~i) {
173 post_log("GDC Memory error at %08x, "
174 "wrote %08x, read %08x !\n",
175 mem + i, ~i, readback);
186 /* do some patterntests in a given addressrange */
187 int gdc_mem_test(ulong *start, ulong size)
192 * check addressrange and do different static and dynamic
193 * pattern tests with it.
195 if (((void *)start) + size <= (void *)GDC_RAM_END) {
197 ret = gdc_post_test1(start, size, 0x00000000);
200 ret = gdc_post_test1(start, size, 0xffffffff);
203 ret = gdc_post_test1(start, size, 0x55555555);
206 ret = gdc_post_test1(start, size, 0xaaaaaaaa);
209 ret = gdc_post_test2(start, size);
212 ret = gdc_post_test3(start, size);
215 ret = gdc_post_test4(start, size);
221 /* test function of gdc memory addresslines*/
222 static int gdc_post_addrline(ulong *address, ulong *base, ulong size)
230 end = (ulong *)((ulong)base + size);
232 for (xor = sizeof(long); xor > 0; xor <<= 1) {
233 target = (ulong *)((ulong)address ^ xor);
234 if ((target >= base) && (target < end)) {
239 if (readback == *address) {
240 post_log("GDC Memory (address line) error at %08x"
241 "XOR value %08x !\n",
242 address, target , xor);
251 static int gdc_post_dataline(ulong *address)
253 unsigned long temp32 = 0;
257 for (i = 0; i < ARRAY_SIZE(pattern); i++) {
258 *address = pattern[i];
260 * Put a different pattern on the data lines: otherwise they
261 * may float long enough to read back what we wrote.
263 *(address + 1) = otherpattern;
266 if (temp32 != pattern[i]){
267 post_log("GDC Memory (date line) error at %08x, "
268 "wrote %08x, read %08x !\n",
269 address, pattern[i], temp32);
277 /* Verify GDC, get memory size, verify GDC memory */
278 int gdc_post_test(int flags)
285 old_value = in_be32((void *)GDC_SCRATCH_REG);
288 * GPIOC2 register behaviour: the LIME graphics processor has a
289 * maximum of 5 GPIO ports that can be used in this hardware
290 * configuration. Thus only the bits for these 5 GPIOs can be
291 * activated in the GPIOC2 register. All other bits will always be
294 if (gdc_test_reg_one(0x00150015))
296 if (gdc_test_reg_one(0x000A000A))
299 out_be32((void *)GDC_SCRATCH_REG, old_value);
301 old_value = in_be32((void *)GDC_VERSION_REG);
302 post_log("GDC chip version %u.%u, year %04X\n",
303 (old_value >> 8) & 0xFF, old_value & 0xFF,
304 (old_value >> 16) & 0xFFFF);
306 old_value = get_ram_size((void *)GDC_RAM_START,
309 debug("GDC RAM size (ist): %d bytes\n", old_value);
310 debug("GDC RAM size (soll): %d bytes\n", GDC_RAM_SIZE);
311 post_log("GDC RAM size: %d bytes\n", old_value);
313 /* Test SDRAM datalines */
314 if (gdc_post_dataline((ulong *)GDC_RAM_START)) {
320 /* Test SDRAM adresslines */
321 if (gdc_post_addrline((ulong *)GDC_RAM_START,
322 (ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
327 if (gdc_post_addrline((ulong *)GDC_RAM_END - sizeof(long),
328 (ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
334 /* memory pattern test */
335 debug("GDC Memory test (flags %8x:%8x)\n", flags,
336 POST_SLOWTEST | POST_MANUAL);
338 if (flags & POST_MANUAL) {
339 debug("Full memory test\n");
340 if (gdc_mem_test((ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
344 /* load splashscreen again */
346 debug("smart memory test\n");
347 for (i = 0; i < (GDC_RAM_SIZE >> 20) && ret == 0; i++) {
349 ret = gdc_mem_test((ulong *)(GDC_RAM_START +
353 ret = gdc_mem_test((ulong *)(GDC_RAM_START +
354 (i << 20) + 0xff800),
363 #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC4 */