fpga.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * (C) Copyright 2008 Dmitry Rakhchev, EmCraft Systems, rda@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. /* This test performs testing of FPGA SCRATCH register,
  26. * gets FPGA version and run get_ram_size() on FPGA memory
  27. */
  28. #include <post.h>
  29. #include <asm/io.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. #define FPGA_SCRATCH_REG 0xC4000050
  32. #define FPGA_VERSION_REG 0xC4000040
  33. #define FPGA_RAM_START 0xC4200000
  34. #define FPGA_RAM_END 0xC4203FFF
  35. #define FPGA_STAT 0xC400000C
  36. #if CONFIG_POST & CFG_POST_BSPEC3
  37. /* Testpattern for fpga memorytest */
  38. static uint pattern[] = {
  39. 0x55555555,
  40. 0xAAAAAAAA,
  41. 0xAA5555AA,
  42. 0x55AAAA55,
  43. 0x0
  44. };
  45. static int one_scratch_test(uint value)
  46. {
  47. uint read_value;
  48. int ret = 0;
  49. out_be32((void *)FPGA_SCRATCH_REG, value);
  50. /* read other location (protect against data lines capacity) */
  51. ret = in_be16((void *)FPGA_VERSION_REG);
  52. /* verify test pattern */
  53. read_value = in_be32((void *)FPGA_SCRATCH_REG);
  54. if (read_value != value) {
  55. post_log("FPGA SCRATCH test failed write %08X, read %08X\n",
  56. value, read_value);
  57. ret = 1;
  58. }
  59. return ret;
  60. }
  61. /* FPGA Memory-pattern-test */
  62. static int fpga_mem_test(void * address)
  63. {
  64. int ret = 1;
  65. uint read_value;
  66. uint old_value;
  67. uint i = 0;
  68. /* save content */
  69. old_value = in_be32(address);
  70. while (pattern[i] != 0) {
  71. out_be32(address, pattern[i]);
  72. /* read other location (protect against data lines capacity) */
  73. ret = in_be16((void *)FPGA_VERSION_REG);
  74. /* verify test pattern */
  75. read_value = in_be32(address);
  76. if (read_value != pattern[i]) {
  77. post_log("FPGA Memory test failed.");
  78. post_log(" write %08X, read %08X at address %08X\n",
  79. pattern[i], read_value, address);
  80. ret = 1;
  81. goto out;
  82. }
  83. i++;
  84. }
  85. ret = 0;
  86. out:
  87. out_be32(address, old_value);
  88. return ret;
  89. }
  90. /* Verify FPGA, get version & memory size */
  91. int fpga_post_test(int flags)
  92. {
  93. uint address;
  94. uint old_value;
  95. ushort version;
  96. uint read_value;
  97. int ret = 0;
  98. post_log("\n");
  99. old_value = in_be32((void *)FPGA_SCRATCH_REG);
  100. if (one_scratch_test(0x55555555))
  101. ret = 1;
  102. if (one_scratch_test(0xAAAAAAAA))
  103. ret = 1;
  104. out_be32((void *)FPGA_SCRATCH_REG, old_value);
  105. version = in_be16((void *)FPGA_VERSION_REG);
  106. post_log("FPGA : version %u.%u\n",
  107. (version >> 8) & 0xFF, version & 0xFF);
  108. /* Enable write to FPGA RAM */
  109. out_be32((void *)FPGA_STAT, in_be32((void *)FPGA_STAT) | 0x1000);
  110. read_value = get_ram_size((void *)CFG_FPGA_BASE_1, 0x4000);
  111. post_log("FPGA RAM size: %d bytes\n", read_value);
  112. for (address = 0; address < 0x1000; address++) {
  113. if (fpga_mem_test((void *)(FPGA_RAM_START + 4*address)) == 1) {
  114. ret = 1;
  115. goto out;
  116. }
  117. }
  118. out:
  119. return ret;
  120. }
  121. #endif /* CONFIG_POST & CFG_POST_BSPEC3 */