ocm.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * (C) Copyright 2008 Ilya Yanok, EmCraft Systems, yanok@emcraft.com
  3. *
  4. * Developed for DENX Software Engineering GmbH
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. /*
  10. * This test attempts to verify on-chip memory (OCM). Result is written
  11. * to the scratch register and if test succeed it won't be run till next
  12. * power on.
  13. */
  14. #include <post.h>
  15. #include <asm/io.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. #define OCM_TEST_PATTERN1 0x55555555
  18. #define OCM_TEST_PATTERN2 0xAAAAAAAA
  19. #if CONFIG_POST & CONFIG_SYS_POST_OCM
  20. static uint ocm_status_read(void)
  21. {
  22. return in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) &
  23. CONFIG_SYS_OCM_STATUS_MASK;
  24. }
  25. static void ocm_status_write(uint value)
  26. {
  27. out_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR, value |
  28. (in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) &
  29. ~CONFIG_SYS_OCM_STATUS_MASK));
  30. }
  31. static inline int ocm_test_word(uint value, uint *address)
  32. {
  33. uint read_value;
  34. *address = value;
  35. sync();
  36. read_value = *address;
  37. return (read_value != value);
  38. }
  39. int ocm_post_test(int flags)
  40. {
  41. uint old_value;
  42. int ret = 0;
  43. uint *address = (uint*)CONFIG_SYS_OCM_BASE;
  44. if (ocm_status_read() == CONFIG_SYS_OCM_STATUS_OK)
  45. return 0;
  46. for (; address < (uint*)(CONFIG_SYS_OCM_BASE + CONFIG_SYS_OCM_SIZE); address++) {
  47. old_value = *address;
  48. if (ocm_test_word(OCM_TEST_PATTERN1, address) ||
  49. ocm_test_word(OCM_TEST_PATTERN2, address)) {
  50. ret = 1;
  51. *address = old_value;
  52. printf("OCM POST failed at %p!\n", address);
  53. break;
  54. }
  55. *address = old_value;
  56. }
  57. ocm_status_write(ret ? CONFIG_SYS_OCM_STATUS_FAIL : CONFIG_SYS_OCM_STATUS_OK);
  58. return ret;
  59. }
  60. #endif /* CONFIG_POST & CONFIG_SYS_POST_OCM */