mpc7448hpc2.c 14 KB

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