ocm.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * (C) Copyright 2008 Ilya Yanok, EmCraft Systems, yanok@emcraft.com
  3. *
  4. * Developed for DENX Software Engineering GmbH
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. /*
  26. * This test attempts to verify on-chip memory (OCM). Result is written
  27. * to the scratch register and if test succeed it won't be run till next
  28. * power on.
  29. */
  30. #include <post.h>
  31. #include <asm/io.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #define OCM_TEST_PATTERN1 0x55555555
  34. #define OCM_TEST_PATTERN2 0xAAAAAAAA
  35. #if CONFIG_POST & CONFIG_SYS_POST_OCM
  36. static uint ocm_status_read(void)
  37. {
  38. return in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) &
  39. CONFIG_SYS_OCM_STATUS_MASK;
  40. }
  41. static void ocm_status_write(uint value)
  42. {
  43. out_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR, value |
  44. (in_be32((void *)CONFIG_SYS_OCM_STATUS_ADDR) &
  45. ~CONFIG_SYS_OCM_STATUS_MASK));
  46. }
  47. static inline int ocm_test_word(uint value, uint *address)
  48. {
  49. uint read_value;
  50. *address = value;
  51. sync();
  52. read_value = *address;
  53. return (read_value != value);
  54. }
  55. int ocm_post_test(int flags)
  56. {
  57. uint old_value;
  58. int ret = 0;
  59. uint *address = (uint*)CONFIG_SYS_OCM_BASE;
  60. if (ocm_status_read() == CONFIG_SYS_OCM_STATUS_OK)
  61. return 0;
  62. for (; address < (uint*)(CONFIG_SYS_OCM_BASE + CONFIG_SYS_OCM_SIZE); address++) {
  63. old_value = *address;
  64. if (ocm_test_word(OCM_TEST_PATTERN1, address) ||
  65. ocm_test_word(OCM_TEST_PATTERN2, address)) {
  66. ret = 1;
  67. *address = old_value;
  68. printf("OCM POST failed at %p!\n", address);
  69. break;
  70. }
  71. *address = old_value;
  72. }
  73. ocm_status_write(ret ? CONFIG_SYS_OCM_STATUS_FAIL : CONFIG_SYS_OCM_STATUS_OK);
  74. return ret;
  75. }
  76. #endif /* CONFIG_POST & CONFIG_SYS_POST_OCM */