p3mx.c 24 KB

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