p3mx.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. /*
  2. * (C) Copyright 2006
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * Based on original work by
  6. * Roel Loeffen, (C) Copyright 2006 Prodrive B.V.
  7. * Josh Huber, (C) Copyright 2001 Mission Critical Linux, Inc.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. *
  27. * modifications for the DB64360 eval board based by Ingo.Assmus@keymile.com
  28. * modifications for the cpci750 by reinhard.arlt@esd-electronics.com
  29. * modifications for the P3M750 by roel.loeffen@prodrive.nl
  30. */
  31. /*
  32. * p3m750.c - main board support/init for the Prodrive p3m750/p3m7448.
  33. */
  34. #include <common.h>
  35. #include <74xx_7xx.h>
  36. #include "../../Marvell/include/memory.h"
  37. #include "../../Marvell/include/pci.h"
  38. #include "../../Marvell/include/mv_gen_reg.h"
  39. #include <net.h>
  40. #include <i2c.h>
  41. #include "eth.h"
  42. #include "mpsc.h"
  43. #include "64460.h"
  44. #include "mv_regs.h"
  45. #include "p3mx.h"
  46. DECLARE_GLOBAL_DATA_PTR;
  47. #undef DEBUG
  48. /*#define DEBUG */
  49. #ifdef CONFIG_PCI
  50. #define MAP_PCI
  51. #endif /* of CONFIG_PCI */
  52. #ifdef DEBUG
  53. #define DP(x) x
  54. #else
  55. #define DP(x)
  56. #endif
  57. extern void flush_data_cache (void);
  58. extern void invalidate_l1_instruction_cache (void);
  59. extern flash_info_t flash_info[];
  60. /* ------------------------------------------------------------------------- */
  61. /* this is the current GT register space location */
  62. /* it starts at CFG_DFL_GT_REGS but moves later to CFG_GT_REGS */
  63. /* Unfortunately, we cant change it while we are in flash, so we initialize it
  64. * to the "final" value. This means that any debug_led calls before
  65. * board_early_init_f wont work right (like in cpu_init_f).
  66. * See also my_remap_gt_regs below. (NTL)
  67. */
  68. void board_prebootm_init (void);
  69. unsigned int INTERNAL_REG_BASE_ADDR = CFG_GT_REGS;
  70. int display_mem_map (void);
  71. void set_led(int);
  72. /* ------------------------------------------------------------------------- */
  73. /*
  74. * This is a version of the GT register space remapping function that
  75. * doesn't touch globals (meaning, it's ok to run from flash.)
  76. *
  77. * Unfortunately, this has the side effect that a writable
  78. * INTERNAL_REG_BASE_ADDR is impossible. Oh well.
  79. */
  80. void my_remap_gt_regs (u32 cur_loc, u32 new_loc)
  81. {
  82. u32 temp;
  83. /* check and see if it's already moved */
  84. temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
  85. if ((temp & 0xffff) == new_loc >> 16)
  86. return;
  87. temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
  88. 0xffff0000) | (new_loc >> 16);
  89. out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
  90. while (GTREGREAD (INTERNAL_SPACE_DECODE) != temp);
  91. }
  92. #ifdef CONFIG_PCI
  93. static void gt_pci_config (void)
  94. {
  95. unsigned int stat;
  96. unsigned int val = 0x00fff864; /* DINK32: BusNum 23:16, DevNum 15:11, */
  97. /* FuncNum 10:8, RegNum 7:2 */
  98. /*
  99. * In PCIX mode devices provide their own bus and device numbers.
  100. * We query the Discovery II's
  101. * config registers by writing ones to the bus and device.
  102. * We then update the Virtual register with the correct value for the
  103. * bus and device.
  104. */
  105. if ((GTREGREAD (PCI_0_MODE) & (BIT4 | BIT5)) != 0) { /* if PCI-X */
  106. GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
  107. GT_REG_READ (PCI_0_CONFIG_DATA_VIRTUAL_REG, &stat);
  108. GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
  109. GT_REG_WRITE (PCI_0_CONFIG_DATA_VIRTUAL_REG,
  110. (stat & 0xffff0000) | CFG_PCI_IDSEL);
  111. }
  112. if ((GTREGREAD (PCI_1_MODE) & (BIT4 | BIT5)) != 0) { /* if PCI-X */
  113. GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
  114. GT_REG_READ (PCI_1_CONFIG_DATA_VIRTUAL_REG, &stat);
  115. GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
  116. GT_REG_WRITE (PCI_1_CONFIG_DATA_VIRTUAL_REG,
  117. (stat & 0xffff0000) | CFG_PCI_IDSEL);
  118. }
  119. /* Enable master */
  120. PCI_MASTER_ENABLE (0, SELF);
  121. PCI_MASTER_ENABLE (1, SELF);
  122. /* Enable PCI0/1 Mem0 and IO 0 disable all others */
  123. GT_REG_READ (BASE_ADDR_ENABLE, &stat);
  124. stat |= (1 << 11) | (1 << 12) | (1 << 13) | (1 << 16) | (1 << 17) |
  125. (1 << 18);
  126. stat &= ~((1 << 9) | (1 << 10) | (1 << 14) | (1 << 15));
  127. GT_REG_WRITE (BASE_ADDR_ENABLE, stat);
  128. /* ronen:
  129. * add write to pci remap registers for 64460.
  130. * in 64360 when writing to pci base go and overide remap automaticaly,
  131. * in 64460 it doesn't
  132. */
  133. GT_REG_WRITE (PCI_0_IO_BASE_ADDR, CFG_PCI0_IO_SPACE >> 16);
  134. GT_REG_WRITE (PCI_0I_O_ADDRESS_REMAP, CFG_PCI0_IO_SPACE_PCI >> 16);
  135. GT_REG_WRITE (PCI_0_IO_SIZE, (CFG_PCI0_IO_SIZE - 1) >> 16);
  136. GT_REG_WRITE (PCI_0_MEMORY0_BASE_ADDR, CFG_PCI0_MEM_BASE >> 16);
  137. GT_REG_WRITE (PCI_0MEMORY0_ADDRESS_REMAP, CFG_PCI0_MEM_BASE >> 16);
  138. GT_REG_WRITE (PCI_0_MEMORY0_SIZE, (CFG_PCI0_MEM_SIZE - 1) >> 16);
  139. GT_REG_WRITE (PCI_1_IO_BASE_ADDR, CFG_PCI1_IO_SPACE >> 16);
  140. GT_REG_WRITE (PCI_1I_O_ADDRESS_REMAP, CFG_PCI1_IO_SPACE_PCI >> 16);
  141. GT_REG_WRITE (PCI_1_IO_SIZE, (CFG_PCI1_IO_SIZE - 1) >> 16);
  142. GT_REG_WRITE (PCI_1_MEMORY0_BASE_ADDR, CFG_PCI1_MEM_BASE >> 16);
  143. GT_REG_WRITE (PCI_1MEMORY0_ADDRESS_REMAP, CFG_PCI1_MEM_BASE >> 16);
  144. GT_REG_WRITE (PCI_1_MEMORY0_SIZE, (CFG_PCI1_MEM_SIZE - 1) >> 16);
  145. /* PCI interface settings */
  146. /* Timeout set to retry forever */
  147. GT_REG_WRITE (PCI_0TIMEOUT_RETRY, 0x0);
  148. GT_REG_WRITE (PCI_1TIMEOUT_RETRY, 0x0);
  149. /* ronen - enable only CS0 and Internal reg!! */
  150. GT_REG_WRITE (PCI_0BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
  151. GT_REG_WRITE (PCI_1BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
  152. /* ronen:
  153. * update the pci internal registers base address.
  154. */
  155. #ifdef MAP_PCI
  156. for (stat = 0; stat <= PCI_HOST1; stat++)
  157. pciWriteConfigReg (stat,
  158. PCI_INTERNAL_REGISTERS_MEMORY_MAPPED_BASE_ADDRESS,
  159. SELF, CFG_GT_REGS);
  160. #endif
  161. }
  162. #endif
  163. /* Setup CPU interface paramaters */
  164. static void gt_cpu_config (void)
  165. {
  166. cpu_t cpu = get_cpu_type ();
  167. ulong tmp;
  168. /* cpu configuration register */
  169. tmp = GTREGREAD (CPU_CONFIGURATION);
  170. /* set the SINGLE_CPU bit see MV64460 */
  171. #ifndef CFG_GT_DUAL_CPU /* SINGLE_CPU seems to cause JTAG problems */
  172. tmp |= CPU_CONF_SINGLE_CPU;
  173. #endif
  174. tmp &= ~CPU_CONF_AACK_DELAY_2;
  175. tmp |= CPU_CONF_DP_VALID;
  176. tmp |= CPU_CONF_AP_VALID;
  177. tmp |= CPU_CONF_PIPELINE;
  178. GT_REG_WRITE (CPU_CONFIGURATION, tmp); /* Marvell (VXWorks) writes 0x20220FF */
  179. /* CPU master control register */
  180. tmp = GTREGREAD (CPU_MASTER_CONTROL);
  181. tmp |= CPU_MAST_CTL_ARB_EN;
  182. if ((cpu == CPU_7400) ||
  183. (cpu == CPU_7410) || (cpu == CPU_7455) || (cpu == CPU_7450)) {
  184. tmp |= CPU_MAST_CTL_CLEAN_BLK;
  185. tmp |= CPU_MAST_CTL_FLUSH_BLK;
  186. } else {
  187. /* cleanblock must be cleared for CPUs
  188. * that do not support this command (603e, 750)
  189. * see Res#1 */
  190. tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
  191. tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
  192. }
  193. GT_REG_WRITE (CPU_MASTER_CONTROL, tmp);
  194. }
  195. /*
  196. * board_early_init_f.
  197. *
  198. * set up gal. device mappings, etc.
  199. */
  200. int board_early_init_f (void)
  201. {
  202. /* set up the GT the way the kernel wants it
  203. * the call to move the GT register space will obviously
  204. * fail if it has already been done, but we're going to assume
  205. * that if it's not at the power-on location, it's where we put
  206. * it last time. (huber)
  207. */
  208. my_remap_gt_regs (CFG_DFL_GT_REGS, CFG_GT_REGS);
  209. #ifdef CONFIG_PCI
  210. gt_pci_config ();
  211. #endif
  212. /* mask all external interrupt sources */
  213. GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
  214. GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
  215. /* new in >MV6436x */
  216. GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_LOW, 0);
  217. GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_HIGH, 0);
  218. /* --------------------- */
  219. GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
  220. GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
  221. GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
  222. GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
  223. /* Device and Boot bus settings
  224. */
  225. memoryMapDeviceSpace(DEVICE0, 0, 0);
  226. GT_REG_WRITE(DEVICE_BANK0PARAMETERS, 0);
  227. memoryMapDeviceSpace(DEVICE1, 0, 0);
  228. GT_REG_WRITE(DEVICE_BANK1PARAMETERS, 0);
  229. memoryMapDeviceSpace(DEVICE2, 0, 0);
  230. GT_REG_WRITE(DEVICE_BANK2PARAMETERS, 0);
  231. memoryMapDeviceSpace(DEVICE3, 0, 0);
  232. GT_REG_WRITE(DEVICE_BANK3PARAMETERS, 0);
  233. GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_BOOT_PAR);
  234. gt_cpu_config();
  235. /* MPP setup */
  236. GT_REG_WRITE (MPP_CONTROL0, CFG_MPP_CONTROL_0);
  237. GT_REG_WRITE (MPP_CONTROL1, CFG_MPP_CONTROL_1);
  238. GT_REG_WRITE (MPP_CONTROL2, CFG_MPP_CONTROL_2);
  239. GT_REG_WRITE (MPP_CONTROL3, CFG_MPP_CONTROL_3);
  240. GT_REG_WRITE (GPP_LEVEL_CONTROL, CFG_GPP_LEVEL_CONTROL);
  241. set_led(LED_RED);
  242. return 0;
  243. }
  244. /* various things to do after relocation */
  245. int misc_init_r ()
  246. {
  247. u8 val;
  248. icache_enable ();
  249. #ifdef CFG_L2
  250. l2cache_enable ();
  251. #endif
  252. #ifdef CONFIG_MPSC
  253. mpsc_sdma_init ();
  254. mpsc_init2 ();
  255. #endif
  256. /*
  257. * Enable trickle changing in RTC upon powerup
  258. * No diode, 250 ohm series resistor
  259. */
  260. val = 0xa5;
  261. i2c_write(CFG_I2C_RTC_ADDR, 8, 1, &val, 1);
  262. return 0;
  263. }
  264. int board_early_init_r(void)
  265. {
  266. /* now relocate the debug serial driver */
  267. mpsc_putchar += gd->reloc_off;
  268. mpsc_getchar += gd->reloc_off;
  269. mpsc_test_char += gd->reloc_off;
  270. return 0;
  271. }
  272. void after_reloc (ulong dest_addr, gd_t * gd)
  273. {
  274. memoryMapDeviceSpace (BOOT_DEVICE, CFG_BOOT_SPACE, CFG_BOOT_SIZE);
  275. /* display_mem_map(); */
  276. /* now, jump to the main U-Boot board init code */
  277. set_led(LED_GREEN);
  278. board_init_r (gd, dest_addr);
  279. /* NOTREACHED */
  280. }
  281. /*
  282. * Check Board Identity:
  283. * right now, assume borad type. (there is just one...after all)
  284. */
  285. int checkboard (void)
  286. {
  287. char *s = getenv("serial#");
  288. printf("Board: %s", CFG_BOARD_NAME);
  289. if (s != NULL) {
  290. puts(", serial# ");
  291. puts(s);
  292. }
  293. putc('\n');
  294. return (0);
  295. }
  296. void set_led(int col)
  297. {
  298. int tmp;
  299. int on_pin;
  300. int off_pin;
  301. /* Program Mpp[22] as Gpp[22]
  302. * Program Mpp[23] as Gpp[23]
  303. */
  304. tmp = GTREGREAD(MPP_CONTROL2);
  305. tmp &= 0x00ffffff;
  306. GT_REG_WRITE(MPP_CONTROL2,tmp);
  307. /* Program Gpp[22] and Gpp[23] as output
  308. */
  309. tmp = GTREGREAD(GPP_IO_CONTROL);
  310. tmp |= 0x00C00000;
  311. GT_REG_WRITE(GPP_IO_CONTROL, tmp);
  312. /* Program Gpp[22] and Gpp[23] as active high
  313. */
  314. tmp = GTREGREAD(GPP_LEVEL_CONTROL);
  315. tmp &= 0xff3fffff;
  316. GT_REG_WRITE(GPP_LEVEL_CONTROL, tmp);
  317. switch(col) {
  318. default:
  319. case LED_OFF :
  320. on_pin = 0;
  321. off_pin = ((1 << 23) | (1 << 22));
  322. break;
  323. case LED_RED :
  324. on_pin = (1 << 23);
  325. off_pin = (1 << 22);
  326. break;
  327. case LED_GREEN :
  328. on_pin = (1 << 22);
  329. off_pin = (1 << 23);
  330. break;
  331. case LED_ORANGE :
  332. on_pin = ((1 << 23) | (1 << 22));
  333. off_pin = 0;
  334. break;
  335. }
  336. /* Set output Gpp[22] and Gpp[23]
  337. */
  338. tmp = GTREGREAD(GPP_VALUE);
  339. tmp |= on_pin;
  340. tmp &= ~off_pin;
  341. GT_REG_WRITE(GPP_VALUE, tmp);
  342. }
  343. int display_mem_map (void)
  344. {
  345. int i;
  346. unsigned int base, size, width;
  347. #ifdef CONFIG_PCI
  348. int j;
  349. #endif
  350. /* SDRAM */
  351. printf ("SD (DDR) RAM\n");
  352. for (i = 0; i <= BANK3; i++) {
  353. base = memoryGetBankBaseAddress (i);
  354. size = memoryGetBankSize (i);
  355. if (size != 0)
  356. printf ("BANK%d: base - 0x%08x\tsize - %dM bytes\n",
  357. i, base, size >> 20);
  358. }
  359. #ifdef CONFIG_PCI
  360. /* CPU's PCI windows */
  361. for (i = 0; i <= PCI_HOST1; i++) {
  362. printf ("\nCPU's PCI %d windows\n", i);
  363. base = pciGetSpaceBase (i, PCI_IO);
  364. size = pciGetSpaceSize (i, PCI_IO);
  365. printf (" IO: base - 0x%08x\tsize - %dM bytes\n", base,
  366. size >> 20);
  367. /* ronen currently only first PCI MEM is used 3 */
  368. for (j = 0; j <= PCI_REGION0; j++) {
  369. base = pciGetSpaceBase (i, j);
  370. size = pciGetSpaceSize (i, j);
  371. printf ("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n",
  372. j, base, size >> 20);
  373. }
  374. }
  375. #endif /* of CONFIG_PCI */
  376. /* Bootrom */
  377. base = memoryGetDeviceBaseAddress (BOOT_DEVICE); /* Boot */
  378. size = memoryGetDeviceSize (BOOT_DEVICE);
  379. width = memoryGetDeviceWidth (BOOT_DEVICE) * 8;
  380. printf (" BOOT: base - 0x%08x size - %dM bytes\twidth - %d bits\t- FLASH\n",
  381. base, size >> 20, width);
  382. return (0);
  383. }
  384. /* DRAM check routines copied from gw8260 */
  385. #if defined (CFG_DRAM_TEST)
  386. /*********************************************************************/
  387. /* NAME: move64() - moves a double word (64-bit) */
  388. /* */
  389. /* DESCRIPTION: */
  390. /* this function performs a double word move from the data at */
  391. /* the source pointer to the location at the destination pointer. */
  392. /* */
  393. /* INPUTS: */
  394. /* unsigned long long *src - pointer to data to move */
  395. /* */
  396. /* OUTPUTS: */
  397. /* unsigned long long *dest - pointer to locate to move data */
  398. /* */
  399. /* RETURNS: */
  400. /* None */
  401. /* */
  402. /* RESTRICTIONS/LIMITATIONS: */
  403. /* May cloober fr0. */
  404. /* */
  405. /*********************************************************************/
  406. static void move64 (unsigned long long *src, unsigned long long *dest)
  407. {
  408. asm ("lfd 0, 0(3)\n\t" /* fpr0 = *scr */
  409. "stfd 0, 0(4)" /* *dest = fpr0 */
  410. : : : "fr0"); /* Clobbers fr0 */
  411. return;
  412. }
  413. #if defined (CFG_DRAM_TEST_DATA)
  414. unsigned long long pattern[] = {
  415. 0xaaaaaaaaaaaaaaaaULL,
  416. 0xccccccccccccccccULL,
  417. 0xf0f0f0f0f0f0f0f0ULL,
  418. 0xff00ff00ff00ff00ULL,
  419. 0xffff0000ffff0000ULL,
  420. 0xffffffff00000000ULL,
  421. 0x00000000ffffffffULL,
  422. 0x0000ffff0000ffffULL,
  423. 0x00ff00ff00ff00ffULL,
  424. 0x0f0f0f0f0f0f0f0fULL,
  425. 0x3333333333333333ULL,
  426. 0x5555555555555555ULL
  427. };
  428. /*********************************************************************/
  429. /* NAME: mem_test_data() - test data lines for shorts and opens */
  430. /* */
  431. /* DESCRIPTION: */
  432. /* Tests data lines for shorts and opens by forcing adjacent data */
  433. /* to opposite states. Because the data lines could be routed in */
  434. /* an arbitrary manner the must ensure test patterns ensure that */
  435. /* every case is tested. By using the following series of binary */
  436. /* patterns every combination of adjacent bits is test regardless */
  437. /* of routing. */
  438. /* */
  439. /* ...101010101010101010101010 */
  440. /* ...110011001100110011001100 */
  441. /* ...111100001111000011110000 */
  442. /* ...111111110000000011111111 */
  443. /* */
  444. /* Carrying this out, gives us six hex patterns as follows: */
  445. /* */
  446. /* 0xaaaaaaaaaaaaaaaa */
  447. /* 0xcccccccccccccccc */
  448. /* 0xf0f0f0f0f0f0f0f0 */
  449. /* 0xff00ff00ff00ff00 */
  450. /* 0xffff0000ffff0000 */
  451. /* 0xffffffff00000000 */
  452. /* */
  453. /* The number test patterns will always be given by: */
  454. /* */
  455. /* log(base 2)(number data bits) = log2 (64) = 6 */
  456. /* */
  457. /* To test for short and opens to other signals on our boards. we */
  458. /* simply */
  459. /* test with the 1's complemnt of the paterns as well. */
  460. /* */
  461. /* OUTPUTS: */
  462. /* Displays failing test pattern */
  463. /* */
  464. /* RETURNS: */
  465. /* 0 - Passed test */
  466. /* 1 - Failed test */
  467. /* */
  468. /* RESTRICTIONS/LIMITATIONS: */
  469. /* Assumes only one one SDRAM bank */
  470. /* */
  471. /*********************************************************************/
  472. int mem_test_data (void)
  473. {
  474. unsigned long long *pmem = (unsigned long long *) CFG_MEMTEST_START;
  475. unsigned long long temp64 = 0;
  476. int num_patterns = sizeof (pattern) / sizeof (pattern[0]);
  477. int i;
  478. unsigned int hi, lo;
  479. for (i = 0; i < num_patterns; i++) {
  480. move64 (&(pattern[i]), pmem);
  481. move64 (pmem, &temp64);
  482. /* hi = (temp64>>32) & 0xffffffff; */
  483. /* lo = temp64 & 0xffffffff; */
  484. /* printf("\ntemp64 = 0x%08x%08x", hi, lo); */
  485. hi = (pattern[i] >> 32) & 0xffffffff;
  486. lo = pattern[i] & 0xffffffff;
  487. /* printf("\npattern[%d] = 0x%08x%08x", i, hi, lo); */
  488. if (temp64 != pattern[i]) {
  489. printf ("\n Data Test Failed, pattern 0x%08x%08x",
  490. hi, lo);
  491. return 1;
  492. }
  493. }
  494. return 0;
  495. }
  496. #endif /* CFG_DRAM_TEST_DATA */
  497. #if defined (CFG_DRAM_TEST_ADDRESS)
  498. /*********************************************************************/
  499. /* NAME: mem_test_address() - test address lines */
  500. /* */
  501. /* DESCRIPTION: */
  502. /* This function performs a test to verify that each word im */
  503. /* memory is uniquly addressable. The test sequence is as follows: */
  504. /* */
  505. /* 1) write the address of each word to each word. */
  506. /* 2) verify that each location equals its address */
  507. /* */
  508. /* OUTPUTS: */
  509. /* Displays failing test pattern and address */
  510. /* */
  511. /* RETURNS: */
  512. /* 0 - Passed test */
  513. /* 1 - Failed test */
  514. /* */
  515. /* RESTRICTIONS/LIMITATIONS: */
  516. /* */
  517. /* */
  518. /*********************************************************************/
  519. int mem_test_address (void)
  520. {
  521. volatile unsigned int *pmem =
  522. (volatile unsigned int *) CFG_MEMTEST_START;
  523. const unsigned int size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 4;
  524. unsigned int i;
  525. /* write address to each location */
  526. for (i = 0; i < size; i++)
  527. pmem[i] = i;
  528. /* verify each loaction */
  529. for (i = 0; i < size; i++) {
  530. if (pmem[i] != i) {
  531. printf ("\n Address Test Failed at 0x%x", i);
  532. return 1;
  533. }
  534. }
  535. return 0;
  536. }
  537. #endif /* CFG_DRAM_TEST_ADDRESS */
  538. #if defined (CFG_DRAM_TEST_WALK)
  539. /*********************************************************************/
  540. /* NAME: mem_march() - memory march */
  541. /* */
  542. /* DESCRIPTION: */
  543. /* Marches up through memory. At each location verifies rmask if */
  544. /* read = 1. At each location write wmask if write = 1. Displays */
  545. /* failing address and pattern. */
  546. /* */
  547. /* INPUTS: */
  548. /* volatile unsigned long long * base - start address of test */
  549. /* unsigned int size - number of dwords(64-bit) to test */
  550. /* unsigned long long rmask - read verify mask */
  551. /* unsigned long long wmask - wrtie verify mask */
  552. /* short read - verifies rmask if read = 1 */
  553. /* short write - writes wmask if write = 1 */
  554. /* */
  555. /* OUTPUTS: */
  556. /* Displays failing test pattern and address */
  557. /* */
  558. /* RETURNS: */
  559. /* 0 - Passed test */
  560. /* 1 - Failed test */
  561. /* */
  562. /* RESTRICTIONS/LIMITATIONS: */
  563. /* */
  564. /* */
  565. /*********************************************************************/
  566. int mem_march (volatile unsigned long long *base,
  567. unsigned int size,
  568. unsigned long long rmask,
  569. unsigned long long wmask, short read, short write)
  570. {
  571. unsigned int i;
  572. unsigned long long temp = 0;
  573. unsigned int hitemp, lotemp, himask, lomask;
  574. for (i = 0; i < size; i++) {
  575. if (read != 0) {
  576. /* temp = base[i]; */
  577. move64 ((unsigned long long *) &(base[i]), &temp);
  578. if (rmask != temp) {
  579. hitemp = (temp >> 32) & 0xffffffff;
  580. lotemp = temp & 0xffffffff;
  581. himask = (rmask >> 32) & 0xffffffff;
  582. lomask = rmask & 0xffffffff;
  583. printf ("\n Walking one's test failed: address = 0x%08x," "\n\texpected 0x%08x%08x, found 0x%08x%08x", i << 3, himask, lomask, hitemp, lotemp);
  584. return 1;
  585. }
  586. }
  587. if (write != 0) {
  588. /* base[i] = wmask; */
  589. move64 (&wmask, (unsigned long long *) &(base[i]));
  590. }
  591. }
  592. return 0;
  593. }
  594. #endif /* CFG_DRAM_TEST_WALK */
  595. /*********************************************************************/
  596. /* NAME: mem_test_walk() - a simple walking ones test */
  597. /* */
  598. /* DESCRIPTION: */
  599. /* Performs a walking ones through entire physical memory. The */
  600. /* test uses as series of memory marches, mem_march(), to verify */
  601. /* and write the test patterns to memory. The test sequence is as */
  602. /* follows: */
  603. /* 1) march writing 0000...0001 */
  604. /* 2) march verifying 0000...0001 , writing 0000...0010 */
  605. /* 3) repeat step 2 shifting masks left 1 bit each time unitl */
  606. /* the write mask equals 1000...0000 */
  607. /* 4) march verifying 1000...0000 */
  608. /* The test fails if any of the memory marches return a failure. */
  609. /* */
  610. /* OUTPUTS: */
  611. /* Displays which pass on the memory test is executing */
  612. /* */
  613. /* RETURNS: */
  614. /* 0 - Passed test */
  615. /* 1 - Failed test */
  616. /* */
  617. /* RESTRICTIONS/LIMITATIONS: */
  618. /* */
  619. /* */
  620. /*********************************************************************/
  621. int mem_test_walk (void)
  622. {
  623. unsigned long long mask;
  624. volatile unsigned long long *pmem =
  625. (volatile unsigned long long *) CFG_MEMTEST_START;
  626. const unsigned long size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 8;
  627. unsigned int i;
  628. mask = 0x01;
  629. printf ("Initial Pass");
  630. mem_march (pmem, size, 0x0, 0x1, 0, 1);
  631. printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
  632. printf (" ");
  633. printf (" ");
  634. printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
  635. for (i = 0; i < 63; i++) {
  636. printf ("Pass %2d", i + 2);
  637. if (mem_march (pmem, size, mask, mask << 1, 1, 1) != 0) {
  638. /*printf("mask: 0x%x, pass: %d, ", mask, i); */
  639. return 1;
  640. }
  641. mask = mask << 1;
  642. printf ("\b\b\b\b\b\b\b");
  643. }
  644. printf ("Last Pass");
  645. if (mem_march (pmem, size, 0, mask, 0, 1) != 0) {
  646. /* printf("mask: 0x%x", mask); */
  647. return 1;
  648. }
  649. printf ("\b\b\b\b\b\b\b\b\b");
  650. printf (" ");
  651. printf ("\b\b\b\b\b\b\b\b\b");
  652. return 0;
  653. }
  654. /*********************************************************************/
  655. /* NAME: testdram() - calls any enabled memory tests */
  656. /* */
  657. /* DESCRIPTION: */
  658. /* Runs memory tests if the environment test variables are set to */
  659. /* 'y'. */
  660. /* */
  661. /* INPUTS: */
  662. /* testdramdata - If set to 'y', data test is run. */
  663. /* testdramaddress - If set to 'y', address test is run. */
  664. /* testdramwalk - If set to 'y', walking ones test is run */
  665. /* */
  666. /* OUTPUTS: */
  667. /* None */
  668. /* */
  669. /* RETURNS: */
  670. /* 0 - Passed test */
  671. /* 1 - Failed test */
  672. /* */
  673. /* RESTRICTIONS/LIMITATIONS: */
  674. /* */
  675. /* */
  676. /*********************************************************************/
  677. int testdram (void)
  678. {
  679. char *s;
  680. int rundata = 0;
  681. int runaddress = 0;
  682. int runwalk = 0;
  683. #ifdef CFG_DRAM_TEST_DATA
  684. s = getenv ("testdramdata");
  685. rundata = (s && (*s == 'y')) ? 1 : 0;
  686. #endif
  687. #ifdef CFG_DRAM_TEST_ADDRESS
  688. s = getenv ("testdramaddress");
  689. runaddress = (s && (*s == 'y')) ? 1 : 0;
  690. #endif
  691. #ifdef CFG_DRAM_TEST_WALK
  692. s = getenv ("testdramwalk");
  693. runwalk = (s && (*s == 'y')) ? 1 : 0;
  694. #endif
  695. if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
  696. printf ("Testing RAM from 0x%08x to 0x%08x ... "
  697. "(don't panic... that will take a moment !!!!)\n",
  698. CFG_MEMTEST_START, CFG_MEMTEST_END);
  699. #ifdef CFG_DRAM_TEST_DATA
  700. if (rundata == 1) {
  701. printf ("Test DATA ... ");
  702. if (mem_test_data () == 1) {
  703. printf ("failed \n");
  704. return 1;
  705. } else
  706. printf ("ok \n");
  707. }
  708. #endif
  709. #ifdef CFG_DRAM_TEST_ADDRESS
  710. if (runaddress == 1) {
  711. printf ("Test ADDRESS ... ");
  712. if (mem_test_address () == 1) {
  713. printf ("failed \n");
  714. return 1;
  715. } else
  716. printf ("ok \n");
  717. }
  718. #endif
  719. #ifdef CFG_DRAM_TEST_WALK
  720. if (runwalk == 1) {
  721. printf ("Test WALKING ONEs ... ");
  722. if (mem_test_walk () == 1) {
  723. printf ("failed \n");
  724. return 1;
  725. } else
  726. printf ("ok \n");
  727. }
  728. #endif
  729. if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
  730. printf ("passed\n");
  731. return 0;
  732. }
  733. #endif /* CFG_DRAM_TEST */
  734. /* ronen - the below functions are used by the bootm function */
  735. /* - we map the base register to fbe00000 (same mapping as in the LSP) */
  736. /* - we turn off the RX gig dmas - to prevent the dma from overunning */
  737. /* the kernel data areas. */
  738. /* - we diable and invalidate the icache and dcache. */
  739. void my_remap_gt_regs_bootm (u32 cur_loc, u32 new_loc)
  740. {
  741. u32 temp;
  742. temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
  743. if ((temp & 0xffff) == new_loc >> 16)
  744. return;
  745. temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
  746. 0xffff0000) | (new_loc >> 16);
  747. out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
  748. while ((WORD_SWAP (*((volatile unsigned int *) (NONE_CACHEABLE |
  749. new_loc |
  750. (INTERNAL_SPACE_DECODE)))))
  751. != temp);
  752. }