blob: bbf2d9a8ee027e7677c6a71052d93049c4d1b74b [file] [log] [blame]
Yuri Tikhonovc3655b82008-05-08 15:42:47 +02001/*
2 * (C) Copyright 2008 Ilya Yanok, EmCraft Systems, yanok@emcraft.com
3 *
4 * Developed for DENX Software Engineering GmbH
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Yuri Tikhonovc3655b82008-05-08 15:42:47 +02007 */
8#include <common.h>
9
10/*
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
13 * power on.
14 */
15
16#include <post.h>
17
18#include <asm/io.h>
19
20DECLARE_GLOBAL_DATA_PTR;
21
22#define OCM_TEST_PATTERN1 0x55555555
23#define OCM_TEST_PATTERN2 0xAAAAAAAA
24
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020025#if CONFIG_POST & CONFIG_SYS_POST_OCM
Yuri Tikhonovc3655b82008-05-08 15:42:47 +020026
27static uint ocm_status_read(void)
28{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029 return in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) &
30 CONFIG_SYS_OCM_STATUS_MASK;
Yuri Tikhonovc3655b82008-05-08 15:42:47 +020031}
32
33static void ocm_status_write(uint value)
34{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020035 out_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR, value |
36 (in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) &
37 ~CONFIG_SYS_OCM_STATUS_MASK));
Yuri Tikhonovc3655b82008-05-08 15:42:47 +020038}
39
40static inline int ocm_test_word(uint value, uint *address)
41{
42 uint read_value;
43
44 *address = value;
45 sync();
46 read_value = *address;
47
48 return (read_value != value);
49}
50
51int ocm_post_test(int flags)
52{
53 uint old_value;
54 int ret = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055 uint *address = (uint*)CONFIG_SYS_OCM_BASE;
Yuri Tikhonovc3655b82008-05-08 15:42:47 +020056
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057 if (ocm_status_read() == CONFIG_SYS_OCM_STATUS_OK)
Yuri Tikhonovc3655b82008-05-08 15:42:47 +020058 return 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059 for (; address < (uint*)(CONFIG_SYS_OCM_BASE + CONFIG_SYS_OCM_SIZE); address++) {
Yuri Tikhonovc3655b82008-05-08 15:42:47 +020060 old_value = *address;
61 if (ocm_test_word(OCM_TEST_PATTERN1, address) ||
62 ocm_test_word(OCM_TEST_PATTERN2, address)) {
63 ret = 1;
64 *address = old_value;
65 printf("OCM POST failed at %p!\n", address);
66 break;
67 }
68 *address = old_value;
69 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020070 ocm_status_write(ret ? CONFIG_SYS_OCM_STATUS_FAIL : CONFIG_SYS_OCM_STATUS_OK);
Yuri Tikhonovc3655b82008-05-08 15:42:47 +020071 return ret;
72}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020073#endif /* CONFIG_POST & CONFIG_SYS_POST_OCM */