gdc.c 8.5 KB

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