Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 Ilya Yanok, EmCraft Systems, yanok@emcraft.com |
| 3 | * |
| 4 | * Developed for DENX Software Engineering GmbH |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 7 | */ |
| 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 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | #define OCM_TEST_PATTERN1 0x55555555 |
| 23 | #define OCM_TEST_PATTERN2 0xAAAAAAAA |
| 24 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 25 | #if CONFIG_POST & CONFIG_SYS_POST_OCM |
Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 26 | |
| 27 | static uint ocm_status_read(void) |
| 28 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 29 | return in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) & |
| 30 | CONFIG_SYS_OCM_STATUS_MASK; |
Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static void ocm_status_write(uint value) |
| 34 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 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)); |
Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static 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 | |
| 51 | int ocm_post_test(int flags) |
| 52 | { |
| 53 | uint old_value; |
| 54 | int ret = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | uint *address = (uint*)CONFIG_SYS_OCM_BASE; |
Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 56 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 57 | if (ocm_status_read() == CONFIG_SYS_OCM_STATUS_OK) |
Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 58 | return 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | for (; address < (uint*)(CONFIG_SYS_OCM_BASE + CONFIG_SYS_OCM_SIZE); address++) { |
Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 60 | 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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 70 | ocm_status_write(ret ? CONFIG_SYS_OCM_STATUS_FAIL : CONFIG_SYS_OCM_STATUS_OK); |
Yuri Tikhonov | c3655b8 | 2008-05-08 15:42:47 +0200 | [diff] [blame] | 71 | return ret; |
| 72 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | #endif /* CONFIG_POST & CONFIG_SYS_POST_OCM */ |