2 * (C) Copyright 2008 Ilya Yanok, EmCraft Systems, yanok@emcraft.com
4 * Developed for DENX Software Engineering GmbH
6 * SPDX-License-Identifier: GPL-2.0+
11 * This test attempts to verify on-chip memory (OCM). Result is written
12 * to the scratch register and if test succeed it won't be run till next
20 DECLARE_GLOBAL_DATA_PTR;
22 #define OCM_TEST_PATTERN1 0x55555555
23 #define OCM_TEST_PATTERN2 0xAAAAAAAA
25 #if CONFIG_POST & CONFIG_SYS_POST_OCM
27 static uint ocm_status_read(void)
29 return in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) &
30 CONFIG_SYS_OCM_STATUS_MASK;
33 static void ocm_status_write(uint value)
35 out_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR, value |
36 (in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) &
37 ~CONFIG_SYS_OCM_STATUS_MASK));
40 static inline int ocm_test_word(uint value, uint *address)
46 read_value = *address;
48 return (read_value != value);
51 int ocm_post_test(int flags)
55 uint *address = (uint*)CONFIG_SYS_OCM_BASE;
57 if (ocm_status_read() == CONFIG_SYS_OCM_STATUS_OK)
59 for (; address < (uint*)(CONFIG_SYS_OCM_BASE + CONFIG_SYS_OCM_SIZE); address++) {
61 if (ocm_test_word(OCM_TEST_PATTERN1, address) ||
62 ocm_test_word(OCM_TEST_PATTERN2, address)) {
65 printf("OCM POST failed at %p!\n", address);
70 ocm_status_write(ret ? CONFIG_SYS_OCM_STATUS_FAIL : CONFIG_SYS_OCM_STATUS_OK);
73 #endif /* CONFIG_POST & CONFIG_SYS_POST_OCM */