mpc7448hpc2.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * (C) Copyright 2005 Freescale Semiconductor, Inc.
  3. *
  4. * Roy Zang <tie-fei.zang@freescale.com>
  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. * modifications for the Tsi108 Emul Board by avb@Tundra
  25. */
  26. /*
  27. * board support/init functions for the
  28. * Freescale MPC7448 HPC2 (High-Performance Computing 2 Platform).
  29. */
  30. #include <common.h>
  31. #include <74xx_7xx.h>
  32. #if defined(CONFIG_OF_FLAT_TREE)
  33. #include <ft_build.h>
  34. extern void ft_cpu_setup (void *blob, bd_t *bd);
  35. #endif
  36. #undef DEBUG
  37. extern void flush_data_cache (void);
  38. extern void invalidate_l1_instruction_cache (void);
  39. extern void tsi108_init_f (void);
  40. int display_mem_map (void);
  41. void after_reloc (ulong dest_addr)
  42. {
  43. DECLARE_GLOBAL_DATA_PTR;
  44. /*
  45. * Jump to the main U-Boot board init code
  46. */
  47. board_init_r ((gd_t *) gd, dest_addr);
  48. /* NOTREACHED */
  49. }
  50. /*
  51. * Check Board Identity:
  52. * report board type
  53. */
  54. int checkboard (void)
  55. {
  56. int l_type = 0;
  57. printf ("BOARD: %s\n", CFG_BOARD_NAME);
  58. return (l_type);
  59. }
  60. /*
  61. * Read Processor ID:
  62. *
  63. * report calling processor number
  64. */
  65. int read_pid (void)
  66. {
  67. return 0; /* we are on single CPU platform for a while */
  68. }
  69. long int dram_size (int board_type)
  70. {
  71. return 0x20000000; /* 256M bytes */
  72. }
  73. long int initdram (int board_type)
  74. {
  75. return dram_size (board_type);
  76. }
  77. /* DRAM check routines copied from gw8260 */
  78. #if defined (CFG_DRAM_TEST)
  79. /*********************************************************************/
  80. /* NAME: move64() - moves a double word (64-bit) */
  81. /* */
  82. /* DESCRIPTION: */
  83. /* this function performs a double word move from the data at */
  84. /* the source pointer to the location at the destination pointer. */
  85. /* */
  86. /* INPUTS: */
  87. /* unsigned long long *src - pointer to data to move */
  88. /* */
  89. /* OUTPUTS: */
  90. /* unsigned long long *dest - pointer to locate to move data */
  91. /* */
  92. /* RETURNS: */
  93. /* None */
  94. /* */
  95. /* RESTRICTIONS/LIMITATIONS: */
  96. /* May cloober fr0. */
  97. /* */
  98. /*********************************************************************/
  99. static void move64 (unsigned long long *src, unsigned long long *dest)
  100. {
  101. asm ("lfd 0, 0(3)\n\t" /* fpr0 = *scr */
  102. "stfd 0, 0(4)" /* *dest = fpr0 */
  103. : : :"fr0"); /* Clobbers fr0 */
  104. return;
  105. }
  106. #if defined (CFG_DRAM_TEST_DATA)
  107. unsigned long long pattern[] = {
  108. 0xaaaaaaaaaaaaaaaaULL,
  109. 0xccccccccccccccccULL,
  110. 0xf0f0f0f0f0f0f0f0ULL,
  111. 0xff00ff00ff00ff00ULL,
  112. 0xffff0000ffff0000ULL,
  113. 0xffffffff00000000ULL,
  114. 0x00000000ffffffffULL,
  115. 0x0000ffff0000ffffULL,
  116. 0x00ff00ff00ff00ffULL,
  117. 0x0f0f0f0f0f0f0f0fULL,
  118. 0x3333333333333333ULL,
  119. 0x5555555555555555ULL
  120. };
  121. /*********************************************************************/
  122. /* NAME: mem_test_data() - test data lines for shorts and opens */
  123. /* */
  124. /* DESCRIPTION: */
  125. /* Tests data lines for shorts and opens by forcing adjacent data */
  126. /* to opposite states. Because the data lines could be routed in */
  127. /* an arbitrary manner the must ensure test patterns ensure that */
  128. /* every case is tested. By using the following series of binary */
  129. /* patterns every combination of adjacent bits is test regardless */
  130. /* of routing. */
  131. /* */
  132. /* ...101010101010101010101010 */
  133. /* ...110011001100110011001100 */
  134. /* ...111100001111000011110000 */
  135. /* ...111111110000000011111111 */
  136. /* */
  137. /* Carrying this out, gives us six hex patterns as follows: */
  138. /* */
  139. /* 0xaaaaaaaaaaaaaaaa */
  140. /* 0xcccccccccccccccc */
  141. /* 0xf0f0f0f0f0f0f0f0 */
  142. /* 0xff00ff00ff00ff00 */
  143. /* 0xffff0000ffff0000 */
  144. /* 0xffffffff00000000 */
  145. /* */
  146. /* The number test patterns will always be given by: */
  147. /* */
  148. /* log(base 2)(number data bits) = log2 (64) = 6 */
  149. /* */
  150. /* To test for short and opens to other signals on our boards. we */
  151. /* simply */
  152. /* test with the 1's complemnt of the paterns as well. */
  153. /* */
  154. /* OUTPUTS: */
  155. /* Displays failing test pattern */
  156. /* */
  157. /* RETURNS: */
  158. /* 0 - Passed test */
  159. /* 1 - Failed test */
  160. /* */
  161. /* RESTRICTIONS/LIMITATIONS: */
  162. /* Assumes only one one SDRAM bank */
  163. /* */
  164. /*********************************************************************/
  165. int mem_test_data (void)
  166. {
  167. unsigned long long *pmem = (unsigned long long *)CFG_MEMTEST_START;
  168. unsigned long long temp64;
  169. int num_patterns = sizeof (pattern) / sizeof (pattern[0]);
  170. int i;
  171. unsigned int hi, lo;
  172. for (i = 0; i < num_patterns; i++) {
  173. move64 (&(pattern[i]), pmem);
  174. move64 (pmem, &temp64);
  175. /* hi = (temp64>>32) & 0xffffffff; */
  176. /* lo = temp64 & 0xffffffff; */
  177. /* printf ("\ntemp64 = 0x%08x%08x", hi, lo); */
  178. hi = (pattern[i] >> 32) & 0xffffffff;
  179. lo = pattern[i] & 0xffffffff;
  180. /* printf ("\npattern[%d] = 0x%08x%08x", i, hi, lo); */
  181. if (temp64 != pattern[i]) {
  182. printf ("\n Data Test Failed, pattern 0x%08x%08x",
  183. hi, lo);
  184. return 1;
  185. }
  186. }
  187. return 0;
  188. }
  189. #endif /* CFG_DRAM_TEST_DATA */
  190. #if defined (CFG_DRAM_TEST_ADDRESS)
  191. /*********************************************************************/
  192. /* NAME: mem_test_address() - test address lines */
  193. /* */
  194. /* DESCRIPTION: */
  195. /* This function performs a test to verify that each word im */
  196. /* memory is uniquly addressable. The test sequence is as follows: */
  197. /* */
  198. /* 1) write the address of each word to each word. */
  199. /* 2) verify that each location equals its address */
  200. /* */
  201. /* OUTPUTS: */
  202. /* Displays failing test pattern and address */
  203. /* */
  204. /* RETURNS: */
  205. /* 0 - Passed test */
  206. /* 1 - Failed test */
  207. /* */
  208. /* RESTRICTIONS/LIMITATIONS: */
  209. /* */
  210. /* */
  211. /*********************************************************************/
  212. int mem_test_address (void)
  213. {
  214. volatile unsigned int *pmem =
  215. (volatile unsigned int *)CFG_MEMTEST_START;
  216. const unsigned int size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 4;
  217. unsigned int i;
  218. /* write address to each location */
  219. for (i = 0; i < size; i++) {
  220. pmem[i] = i;
  221. }
  222. /* verify each loaction */
  223. for (i = 0; i < size; i++) {
  224. if (pmem[i] != i) {
  225. printf ("\n Address Test Failed at 0x%x", i);
  226. return 1;
  227. }
  228. }
  229. return 0;
  230. }
  231. #endif /* CFG_DRAM_TEST_ADDRESS */
  232. #if defined (CFG_DRAM_TEST_WALK)
  233. /*********************************************************************/
  234. /* NAME: mem_march() - memory march */
  235. /* */
  236. /* DESCRIPTION: */
  237. /* Marches up through memory. At each location verifies rmask if */
  238. /* read = 1. At each location write wmask if write = 1. Displays */
  239. /* failing address and pattern. */
  240. /* */
  241. /* INPUTS: */
  242. /* volatile unsigned long long * base - start address of test */
  243. /* unsigned int size - number of dwords(64-bit) to test */
  244. /* unsigned long long rmask - read verify mask */
  245. /* unsigned long long wmask - wrtie verify mask */
  246. /* short read - verifies rmask if read = 1 */
  247. /* short write - writes wmask if write = 1 */
  248. /* */
  249. /* OUTPUTS: */
  250. /* Displays failing test pattern and address */
  251. /* */
  252. /* RETURNS: */
  253. /* 0 - Passed test */
  254. /* 1 - Failed test */
  255. /* */
  256. /* RESTRICTIONS/LIMITATIONS: */
  257. /* */
  258. /* */
  259. /*********************************************************************/
  260. int mem_march (volatile unsigned long long *base,
  261. unsigned int size,
  262. unsigned long long rmask,
  263. unsigned long long wmask, short read, short write)
  264. {
  265. unsigned int i;
  266. unsigned long long temp;
  267. unsigned int hitemp, lotemp, himask, lomask;
  268. for (i = 0; i < size; i++) {
  269. if (read != 0) {
  270. /* temp = base[i]; */
  271. move64 ((unsigned long long *)&(base[i]), &temp);
  272. if (rmask != temp) {
  273. hitemp = (temp >> 32) & 0xffffffff;
  274. lotemp = temp & 0xffffffff;
  275. himask = (rmask >> 32) & 0xffffffff;
  276. lomask = rmask & 0xffffffff;
  277. printf ("\n Walking one's test failed: \
  278. address = 0x%08x," "\n\texpected \
  279. 0x%08x%08x, found 0x%08x%08x", i << 3,\
  280. himask, lomask, hitemp, lotemp);
  281. return 1;
  282. }
  283. }
  284. if (write != 0) {
  285. /* base[i] = wmask; */
  286. move64 (&wmask, (unsigned long long *)&(base[i]));
  287. }
  288. }
  289. return 0;
  290. }
  291. #endif /* CFG_DRAM_TEST_WALK */
  292. /*********************************************************************/
  293. /* NAME: mem_test_walk() - a simple walking ones test */
  294. /* */
  295. /* DESCRIPTION: */
  296. /* Performs a walking ones through entire physical memory. The */
  297. /* test uses as series of memory marches, mem_march(), to verify */
  298. /* and write the test patterns to memory. The test sequence is as */
  299. /* follows: */
  300. /* 1) march writing 0000...0001 */
  301. /* 2) march verifying 0000...0001 , writing 0000...0010 */
  302. /* 3) repeat step 2 shifting masks left 1 bit each time unitl */
  303. /* the write mask equals 1000...0000 */
  304. /* 4) march verifying 1000...0000 */
  305. /* The test fails if any of the memory marches return a failure. */
  306. /* */
  307. /* OUTPUTS: */
  308. /* Displays which pass on the memory test is executing */
  309. /* */
  310. /* RETURNS: */
  311. /* 0 - Passed test */
  312. /* 1 - Failed test */
  313. /* */
  314. /* RESTRICTIONS/LIMITATIONS: */
  315. /* */
  316. /* */
  317. /*********************************************************************/
  318. int mem_test_walk (void)
  319. {
  320. unsigned long long mask;
  321. volatile unsigned long long *pmem =
  322. (volatile unsigned long long *)CFG_MEMTEST_START;
  323. const unsigned long size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 8;
  324. unsigned int i;
  325. mask = 0x01;
  326. printf ("Initial Pass");
  327. mem_march (pmem, size, 0x0, 0x1, 0, 1);
  328. printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
  329. printf (" ");
  330. printf (" ");
  331. printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
  332. for (i = 0; i < 63; i++) {
  333. printf ("Pass %2d", i + 2);
  334. if (mem_march(pmem, size, mask, mask << 1, 1, 1) != 0)
  335. /*printf ("mask: 0x%x, pass: %d, ", mask, i); */
  336. return 1;
  337. mask = mask << 1;
  338. printf ("\b\b\b\b\b\b\b");
  339. }
  340. printf ("Last Pass");
  341. if (mem_march(pmem, size, 0, mask, 0, 1) != 0) {
  342. /* printf ("mask: 0x%x", mask); */
  343. return 1;
  344. }
  345. printf ("\b\b\b\b\b\b\b\b\b");
  346. printf (" ");
  347. printf ("\b\b\b\b\b\b\b\b\b");
  348. return 0;
  349. }
  350. /*********************************************************************/
  351. /* NAME: testdram() - calls any enabled memory tests */
  352. /* */
  353. /* DESCRIPTION: */
  354. /* Runs memory tests if the environment test variables are set to */
  355. /* 'y'. */
  356. /* */
  357. /* INPUTS: */
  358. /* testdramdata - If set to 'y', data test is run. */
  359. /* testdramaddress - If set to 'y', address test is run. */
  360. /* testdramwalk - If set to 'y', walking ones test is run */
  361. /* */
  362. /* OUTPUTS: */
  363. /* None */
  364. /* */
  365. /* RETURNS: */
  366. /* 0 - Passed test */
  367. /* 1 - Failed test */
  368. /* */
  369. /* RESTRICTIONS/LIMITATIONS: */
  370. /* */
  371. /* */
  372. /*********************************************************************/
  373. int testdram (void)
  374. {
  375. char *s;
  376. int rundata, runaddress, runwalk;
  377. s = getenv ("testdramdata");
  378. rundata = (s && (*s == 'y')) ? 1 : 0;
  379. s = getenv ("testdramaddress");
  380. runaddress = (s && (*s == 'y')) ? 1 : 0;
  381. s = getenv ("testdramwalk");
  382. runwalk = (s && (*s == 'y')) ? 1 : 0;
  383. /* rundata = 1; */
  384. /* runaddress = 0; */
  385. /* runwalk = 0; */
  386. if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
  387. printf ("Testing RAM from 0x%08x to 0x%08x ... \
  388. (don't panic... that will take a moment !!!!)\n", \
  389. CFG_MEMTEST_START, CFG_MEMTEST_END);
  390. #ifdef CFG_DRAM_TEST_DATA
  391. if (rundata == 1) {
  392. printf ("Test DATA ... ");
  393. if (mem_test_data () == 1) {
  394. printf ("failed \n");
  395. return 1;
  396. } else
  397. printf ("ok \n");
  398. }
  399. #endif
  400. #ifdef CFG_DRAM_TEST_ADDRESS
  401. if (runaddress == 1) {
  402. printf ("Test ADDRESS ... ");
  403. if (mem_test_address () == 1) {
  404. printf ("failed \n");
  405. return 1;
  406. } else
  407. printf ("ok \n");
  408. }
  409. #endif
  410. #ifdef CFG_DRAM_TEST_WALK
  411. if (runwalk == 1) {
  412. printf ("Test WALKING ONEs ... ");
  413. if (mem_test_walk () == 1) {
  414. printf ("failed \n");
  415. return 1;
  416. } else
  417. printf ("ok \n");
  418. }
  419. #endif
  420. if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
  421. printf ("passed\n");
  422. return 0;
  423. }
  424. #endif /* CFG_DRAM_TEST */
  425. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  426. void
  427. ft_board_setup (void *blob, bd_t *bd)
  428. {
  429. u32 *p;
  430. int len;
  431. ft_cpu_setup (blob, bd);
  432. p = ft_get_prop (blob, "/memory/reg", &len);
  433. if (p != NULL) {
  434. *p++ = cpu_to_be32 (bd->bi_memstart);
  435. *p = cpu_to_be32 (bd->bi_memsize);
  436. }
  437. }
  438. #endif