cpci750.c 27 KB

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