gdc.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 attempts to verify board GDC. A scratch register tested, then
  26. * simple memory test (get_ram_size()) run over GDC memory.
  27. */
  28. #include <post.h>
  29. #include <watchdog.h>
  30. #include <asm/io.h>
  31. #include <video.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. #define GDC_SCRATCH_REG 0xC1FF8044
  34. #define GDC_VERSION_REG 0xC1FF8084
  35. #define GDC_HOST_BASE 0xC1FC0000
  36. #define GDC_RAM_START 0xC0000000
  37. #define GDC_RAM_END (GDC_HOST_BASE - 1)
  38. #define GDC_RAM_SIZE (GDC_RAM_END - GDC_RAM_START)
  39. #if CONFIG_POST & CONFIG_SYS_POST_BSPEC4
  40. const static unsigned long pattern[] = {
  41. 0xffffffff,
  42. 0xaaaaaaaa,
  43. 0xcccccccc,
  44. 0xf0f0f0f0,
  45. 0xff00ff00,
  46. 0xffff0000,
  47. 0x0000ffff,
  48. 0x00ff00ff,
  49. 0x0f0f0f0f,
  50. 0x33333333,
  51. 0x55555555,
  52. 0x00000000
  53. };
  54. const static unsigned long otherpattern = 0x01234567;
  55. /* test write/read og a given LIME Register */
  56. static int gdc_test_reg_one(uint value)
  57. {
  58. uint read_value;
  59. /* write test pattern */
  60. out_be32((void *)GDC_SCRATCH_REG, value);
  61. /* read other location (protect against data lines capacity) */
  62. in_be32((void *)GDC_RAM_START);
  63. /* verify test pattern */
  64. read_value = in_be32((void *)GDC_SCRATCH_REG);
  65. if (read_value != value) {
  66. post_log("GDC SCRATCH test failed write %08X, read %08X\n",
  67. value, read_value);
  68. }
  69. return (read_value != value);
  70. }
  71. /* test with a given static 32 bit pattern in a given memory addressrange */
  72. static int gdc_post_test1(ulong *start, ulong size, ulong val)
  73. {
  74. int ret = 0;
  75. ulong i = 0;
  76. ulong *mem = start;
  77. ulong readback;
  78. for (i = 0; i < size / sizeof(ulong); i++) {
  79. mem[i] = val;
  80. if (i % 1024 == 0)
  81. WATCHDOG_RESET();
  82. }
  83. for (i = 0; i < size / sizeof(ulong); i++) {
  84. readback = mem[i];
  85. if (readback != val) {
  86. post_log("GDC Memory error at %08x, "
  87. "wrote %08x, read %08x !\n",
  88. mem + i, val, readback);
  89. ret = -1;
  90. break;
  91. }
  92. if (i % 1024 == 0)
  93. WATCHDOG_RESET();
  94. }
  95. return ret;
  96. }
  97. /* test with dynamic 32 bit pattern in a given memory addressrange */
  98. static int gdc_post_test2(ulong *start, ulong size)
  99. {
  100. int ret = 0;
  101. ulong i = 0;
  102. ulong *mem = start;
  103. ulong readback;
  104. for (i = 0; i < size / sizeof(ulong); i++) {
  105. mem[i] = 1 << (i % 32);
  106. if (i % 1024 == 0)
  107. WATCHDOG_RESET();
  108. }
  109. for (i = 0; i < size / sizeof(ulong); i++) {
  110. readback = mem[i];
  111. if (readback != 1 << (i % 32)) {
  112. post_log("GDC Memory error at %08x, "
  113. "wrote %08x, read %08x !\n",
  114. mem + i, 1 << (i % 32), readback);
  115. ret = -1;
  116. break;
  117. }
  118. if (i % 1024 == 0)
  119. WATCHDOG_RESET();
  120. }
  121. return ret;
  122. }
  123. /* test with dynamic 32 bit pattern in a given memory addressrange */
  124. static int gdc_post_test3(ulong *start, ulong size)
  125. {
  126. int ret = 0;
  127. ulong i = 0;
  128. ulong *mem = start;
  129. ulong readback;
  130. for (i = 0; i < size / sizeof(ulong); i++) {
  131. mem[i] = i;
  132. if (i % 1024 == 0)
  133. WATCHDOG_RESET();
  134. }
  135. for (i = 0; i < size / sizeof(ulong); i++) {
  136. readback = mem[i];
  137. if (readback != i) {
  138. post_log("GDC Memory error at %08x, "
  139. "wrote %08x, read %08x !\n",
  140. mem + i, i, readback);
  141. ret = -1;
  142. break;
  143. }
  144. if (i % 1024 == 0)
  145. WATCHDOG_RESET();
  146. }
  147. return ret;
  148. }
  149. /* test with dynamic 32 bit pattern in a given memory addressrange */
  150. static int gdc_post_test4(ulong *start, ulong size)
  151. {
  152. int ret = 0;
  153. ulong i = 0;
  154. ulong *mem = start;
  155. ulong readback;
  156. for (i = 0; i < size / sizeof(ulong); i++) {
  157. mem[i] = ~i;
  158. if (i % 1024 == 0)
  159. WATCHDOG_RESET();
  160. }
  161. for (i = 0; i < size / sizeof(ulong); i++) {
  162. readback = mem[i];
  163. if (readback != ~i) {
  164. post_log("GDC Memory error at %08x, "
  165. "wrote %08x, read %08x !\n",
  166. mem + i, ~i, readback);
  167. ret = -1;
  168. break;
  169. }
  170. if (i % 1024 == 0)
  171. WATCHDOG_RESET();
  172. }
  173. return ret;
  174. }
  175. /* do some patterntests in a given addressrange */
  176. int gdc_mem_test(ulong *start, ulong size)
  177. {
  178. int ret = 0;
  179. /*
  180. * check addressrange and do different static and dynamic
  181. * pattern tests with it.
  182. */
  183. if (((void *)start) + size <= (void *)GDC_RAM_END) {
  184. if (ret == 0)
  185. ret = gdc_post_test1(start, size, 0x00000000);
  186. if (ret == 0)
  187. ret = gdc_post_test1(start, size, 0xffffffff);
  188. if (ret == 0)
  189. ret = gdc_post_test1(start, size, 0x55555555);
  190. if (ret == 0)
  191. ret = gdc_post_test1(start, size, 0xaaaaaaaa);
  192. if (ret == 0)
  193. ret = gdc_post_test2(start, size);
  194. if (ret == 0)
  195. ret = gdc_post_test3(start, size);
  196. if (ret == 0)
  197. ret = gdc_post_test4(start, size);
  198. }
  199. return ret;
  200. }
  201. /* test function of gdc memory addresslines*/
  202. static int gdc_post_addrline(ulong *address, ulong *base, ulong size)
  203. {
  204. ulong *target;
  205. ulong *end;
  206. ulong readback = 0;
  207. ulong xor = 0;
  208. int ret = 0;
  209. end = (ulong *)((ulong)base + size);
  210. for (xor = sizeof(long); xor > 0; xor <<= 1) {
  211. target = (ulong *)((ulong)address ^ xor);
  212. if ((target >= base) && (target < end)) {
  213. *address = ~*target;
  214. readback = *target;
  215. }
  216. if (readback == *address) {
  217. post_log("GDC Memory (address line) error at %08x"
  218. "XOR value %08x !\n",
  219. address, target , xor);
  220. ret = -1;
  221. break;
  222. }
  223. }
  224. return ret;
  225. }
  226. static int gdc_post_dataline(ulong *address)
  227. {
  228. unsigned long temp32 = 0;
  229. int i = 0;
  230. int ret = 0;
  231. for (i = 0; i < ARRAY_SIZE(pattern); i++) {
  232. *address = pattern[i];
  233. /*
  234. * Put a different pattern on the data lines: otherwise they
  235. * may float long enough to read back what we wrote.
  236. */
  237. *(address + 1) = otherpattern;
  238. temp32 = *address;
  239. if (temp32 != pattern[i]){
  240. post_log("GDC Memory (date line) error at %08x, "
  241. "wrote %08x, read %08x !\n",
  242. address, pattern[i], temp32);
  243. ret = 1;
  244. }
  245. }
  246. return ret;
  247. }
  248. /* Verify GDC, get memory size, verify GDC memory */
  249. int gdc_post_test(int flags)
  250. {
  251. uint old_value;
  252. int i = 0;
  253. int ret = 0;
  254. post_log("\n");
  255. old_value = in_be32((void *)GDC_SCRATCH_REG);
  256. /*
  257. * GPIOC2 register behaviour: the LIME graphics processor has a
  258. * maximum of 5 GPIO ports that can be used in this hardware
  259. * configuration. Thus only the bits for these 5 GPIOs can be
  260. * activated in the GPIOC2 register. All other bits will always be
  261. * read as zero.
  262. */
  263. if (gdc_test_reg_one(0x00150015))
  264. ret = 1;
  265. if (gdc_test_reg_one(0x000A000A))
  266. ret = 1;
  267. out_be32((void *)GDC_SCRATCH_REG, old_value);
  268. old_value = in_be32((void *)GDC_VERSION_REG);
  269. post_log("GDC chip version %u.%u, year %04X\n",
  270. (old_value >> 8) & 0xFF, old_value & 0xFF,
  271. (old_value >> 16) & 0xFFFF);
  272. old_value = get_ram_size((void *)GDC_RAM_START,
  273. 0x02000000);
  274. debug("GDC RAM size (ist): %d bytes\n", old_value);
  275. debug("GDC RAM size (soll): %d bytes\n", GDC_RAM_SIZE);
  276. post_log("GDC RAM size: %d bytes\n", old_value);
  277. /* Test SDRAM datalines */
  278. if (gdc_post_dataline((ulong *)GDC_RAM_START)) {
  279. ret = 1;
  280. goto out;
  281. }
  282. WATCHDOG_RESET();
  283. /* Test SDRAM adresslines */
  284. if (gdc_post_addrline((ulong *)GDC_RAM_START,
  285. (ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
  286. ret = 1;
  287. goto out;
  288. }
  289. WATCHDOG_RESET();
  290. if (gdc_post_addrline((ulong *)GDC_RAM_END - sizeof(long),
  291. (ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
  292. ret = 1;
  293. goto out;
  294. }
  295. WATCHDOG_RESET();
  296. /* memory pattern test */
  297. debug("GDC Memory test (flags %8x:%8x)\n", flags,
  298. POST_SLOWTEST | POST_MANUAL);
  299. if (flags & POST_MANUAL) {
  300. debug("Full memory test\n");
  301. if (gdc_mem_test((ulong *)GDC_RAM_START, GDC_RAM_SIZE)) {
  302. ret = 1;
  303. goto out;
  304. }
  305. /* load splashscreen again */
  306. } else {
  307. debug("smart memory test\n");
  308. for (i = 0; i < (GDC_RAM_SIZE >> 20) && ret == 0; i++) {
  309. if (ret == 0)
  310. ret = gdc_mem_test((ulong *)(GDC_RAM_START +
  311. (i << 20)),
  312. 0x800);
  313. if (ret == 0)
  314. ret = gdc_mem_test((ulong *)(GDC_RAM_START +
  315. (i << 20) + 0xff800),
  316. 0x800);
  317. }
  318. }
  319. WATCHDOG_RESET();
  320. out:
  321. return ret;
  322. }
  323. #endif /* CONFIG_POST & CONFIG_SYS_POST_BSPEC4 */