cpci750.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  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 <74xx_7xx.h>
  31. #include "../../Marvell/include/memory.h"
  32. #include "../../Marvell/include/pci.h"
  33. #include "../../Marvell/include/mv_gen_reg.h"
  34. #include <net.h>
  35. #include "eth.h"
  36. #include "mpsc.h"
  37. #include "i2c.h"
  38. #include "64360.h"
  39. #include "mv_regs.h"
  40. #undef DEBUG
  41. /*#define DEBUG */
  42. #ifdef CONFIG_PCI
  43. #define MAP_PCI
  44. #endif /* of CONFIG_PCI */
  45. #ifdef DEBUG
  46. #define DP(x) x
  47. #else
  48. #define DP(x)
  49. #endif
  50. extern void flush_data_cache (void);
  51. extern void invalidate_l1_instruction_cache (void);
  52. /* ------------------------------------------------------------------------- */
  53. /* this is the current GT register space location */
  54. /* it starts at CFG_DFL_GT_REGS but moves later to CFG_GT_REGS */
  55. /* Unfortunately, we cant change it while we are in flash, so we initialize it
  56. * to the "final" value. This means that any debug_led calls before
  57. * board_early_init_f wont work right (like in cpu_init_f).
  58. * See also my_remap_gt_regs below. (NTL)
  59. */
  60. void board_prebootm_init (void);
  61. unsigned int INTERNAL_REG_BASE_ADDR = CFG_GT_REGS;
  62. int display_mem_map (void);
  63. /* ------------------------------------------------------------------------- */
  64. /*
  65. * This is a version of the GT register space remapping function that
  66. * doesn't touch globals (meaning, it's ok to run from flash.)
  67. *
  68. * Unfortunately, this has the side effect that a writable
  69. * INTERNAL_REG_BASE_ADDR is impossible. Oh well.
  70. */
  71. void my_remap_gt_regs (u32 cur_loc, u32 new_loc)
  72. {
  73. u32 temp;
  74. /* check and see if it's already moved */
  75. /* original ppcboot 1.1.6 source
  76. temp = in_le32((u32 *)(new_loc + INTERNAL_SPACE_DECODE));
  77. if ((temp & 0xffff) == new_loc >> 20)
  78. return;
  79. temp = (in_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE)) &
  80. 0xffff0000) | (new_loc >> 20);
  81. out_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE), temp);
  82. while (GTREGREAD(INTERNAL_SPACE_DECODE) != temp);
  83. original ppcboot 1.1.6 source end */
  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, FuncNum 10:8, RegNum 7:2 */
  97. /* In PCIX mode devices provide their own bus and device numbers. We query the Discovery II's
  98. * config registers by writing ones to the bus and device.
  99. * We then update the Virtual register with the correct value for the bus and device.
  100. */
  101. if ((GTREGREAD (PCI_0_MODE) & (BIT4 | BIT5)) != 0) { /*if PCI-X */
  102. GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
  103. GT_REG_READ (PCI_0_CONFIG_DATA_VIRTUAL_REG, &stat);
  104. GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
  105. GT_REG_WRITE (PCI_0_CONFIG_DATA_VIRTUAL_REG,
  106. (stat & 0xffff0000) | CFG_PCI_IDSEL);
  107. }
  108. if ((GTREGREAD (PCI_1_MODE) & (BIT4 | BIT5)) != 0) { /*if PCI-X */
  109. GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
  110. GT_REG_READ (PCI_1_CONFIG_DATA_VIRTUAL_REG, &stat);
  111. GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
  112. GT_REG_WRITE (PCI_1_CONFIG_DATA_VIRTUAL_REG,
  113. (stat & 0xffff0000) | CFG_PCI_IDSEL);
  114. }
  115. /* Enable master */
  116. PCI_MASTER_ENABLE (0, SELF);
  117. PCI_MASTER_ENABLE (1, SELF);
  118. /* Enable PCI0/1 Mem0 and IO 0 disable all others */
  119. GT_REG_READ (BASE_ADDR_ENABLE, &stat);
  120. stat |= (1 << 11) | (1 << 12) | (1 << 13) | (1 << 16) | (1 << 17) | (1
  121. <<
  122. 18);
  123. stat &= ~((1 << 9) | (1 << 10) | (1 << 14) | (1 << 15));
  124. GT_REG_WRITE (BASE_ADDR_ENABLE, stat);
  125. /* ronen- add write to pci remap registers for 64460.
  126. in 64360 when writing to pci base go and overide remap automaticaly,
  127. in 64460 it doesn't */
  128. GT_REG_WRITE (PCI_0_IO_BASE_ADDR, CFG_PCI0_IO_SPACE >> 16);
  129. GT_REG_WRITE (PCI_0I_O_ADDRESS_REMAP, CFG_PCI0_IO_SPACE_PCI >> 16);
  130. GT_REG_WRITE (PCI_0_IO_SIZE, (CFG_PCI0_IO_SIZE - 1) >> 16);
  131. GT_REG_WRITE (PCI_0_MEMORY0_BASE_ADDR, CFG_PCI0_MEM_BASE >> 16);
  132. GT_REG_WRITE (PCI_0MEMORY0_ADDRESS_REMAP, CFG_PCI0_MEM_BASE >> 16);
  133. GT_REG_WRITE (PCI_0_MEMORY0_SIZE, (CFG_PCI0_MEM_SIZE - 1) >> 16);
  134. GT_REG_WRITE (PCI_1_IO_BASE_ADDR, CFG_PCI1_IO_SPACE >> 16);
  135. GT_REG_WRITE (PCI_1I_O_ADDRESS_REMAP, CFG_PCI1_IO_SPACE_PCI >> 16);
  136. GT_REG_WRITE (PCI_1_IO_SIZE, (CFG_PCI1_IO_SIZE - 1) >> 16);
  137. GT_REG_WRITE (PCI_1_MEMORY0_BASE_ADDR, CFG_PCI1_MEM_BASE >> 16);
  138. GT_REG_WRITE (PCI_1MEMORY0_ADDRESS_REMAP, CFG_PCI1_MEM_BASE >> 16);
  139. GT_REG_WRITE (PCI_1_MEMORY0_SIZE, (CFG_PCI1_MEM_SIZE - 1) >> 16);
  140. /* PCI interface settings */
  141. /* Timeout set to retry forever */
  142. GT_REG_WRITE (PCI_0TIMEOUT_RETRY, 0x0);
  143. GT_REG_WRITE (PCI_1TIMEOUT_RETRY, 0x0);
  144. /* ronen - enable only CS0 and Internal reg!! */
  145. GT_REG_WRITE (PCI_0BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
  146. GT_REG_WRITE (PCI_1BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
  147. /*ronen update the pci internal registers base address.*/
  148. #ifdef MAP_PCI
  149. for (stat = 0; stat <= PCI_HOST1; stat++)
  150. pciWriteConfigReg (stat,
  151. PCI_INTERNAL_REGISTERS_MEMORY_MAPPED_BASE_ADDRESS,
  152. SELF, CFG_GT_REGS);
  153. #endif
  154. }
  155. #endif
  156. /* Setup CPU interface paramaters */
  157. static void gt_cpu_config (void)
  158. {
  159. cpu_t cpu = get_cpu_type ();
  160. ulong tmp;
  161. /* cpu configuration register */
  162. tmp = GTREGREAD (CPU_CONFIGURATION);
  163. /* set the SINGLE_CPU bit see MV64360 P.399 */
  164. #ifndef CFG_GT_DUAL_CPU /* SINGLE_CPU seems to cause JTAG problems */
  165. tmp |= CPU_CONF_SINGLE_CPU;
  166. #endif
  167. tmp &= ~CPU_CONF_AACK_DELAY_2;
  168. tmp |= CPU_CONF_DP_VALID;
  169. tmp |= CPU_CONF_AP_VALID;
  170. tmp |= CPU_CONF_PIPELINE;
  171. GT_REG_WRITE (CPU_CONFIGURATION, tmp); /* Marvell (VXWorks) writes 0x20220FF */
  172. /* CPU master control register */
  173. tmp = GTREGREAD (CPU_MASTER_CONTROL);
  174. tmp |= CPU_MAST_CTL_ARB_EN;
  175. if ((cpu == CPU_7400) ||
  176. (cpu == CPU_7410) || (cpu == CPU_7455) || (cpu == CPU_7450)) {
  177. tmp |= CPU_MAST_CTL_CLEAN_BLK;
  178. tmp |= CPU_MAST_CTL_FLUSH_BLK;
  179. } else {
  180. /* cleanblock must be cleared for CPUs
  181. * that do not support this command (603e, 750)
  182. * see Res#1 */
  183. tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
  184. tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
  185. }
  186. GT_REG_WRITE (CPU_MASTER_CONTROL, tmp);
  187. }
  188. /*
  189. * board_early_init_f.
  190. *
  191. * set up gal. device mappings, etc.
  192. */
  193. int board_early_init_f (void)
  194. {
  195. /*
  196. * set up the GT the way the kernel wants it
  197. * the call to move the GT register space will obviously
  198. * fail if it has already been done, but we're going to assume
  199. * that if it's not at the power-on location, it's where we put
  200. * it last time. (huber)
  201. */
  202. my_remap_gt_regs (CFG_DFL_GT_REGS, CFG_GT_REGS);
  203. /* No PCI in first release of Port To_do: enable it. */
  204. #ifdef CONFIG_PCI
  205. gt_pci_config ();
  206. #endif
  207. /* mask all external interrupt sources */
  208. GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
  209. GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
  210. /* new in MV6436x */
  211. GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_LOW, 0);
  212. GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_HIGH, 0);
  213. /* --------------------- */
  214. GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
  215. GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
  216. GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
  217. GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
  218. /* does not exist in MV6436x
  219. GT_REG_WRITE(CPU_INT_0_MASK, 0);
  220. GT_REG_WRITE(CPU_INT_1_MASK, 0);
  221. GT_REG_WRITE(CPU_INT_2_MASK, 0);
  222. GT_REG_WRITE(CPU_INT_3_MASK, 0);
  223. --------------------- */
  224. /* ----- DEVICE BUS SETTINGS ------ */
  225. /*
  226. * EVB
  227. * 0 - SRAM ????
  228. * 1 - RTC ????
  229. * 2 - UART ????
  230. * 3 - Flash checked 32Bit Intel Strata
  231. * boot - BootCS checked 8Bit 29LV040B
  232. *
  233. */
  234. /*
  235. * the dual 7450 module requires burst access to the boot
  236. * device, so the serial rom copies the boot device to the
  237. * on-board sram on the eval board, and updates the correct
  238. * registers to boot from the sram. (device0)
  239. */
  240. memoryMapDeviceSpace (DEVICE0, CFG_DEV0_SPACE, CFG_DEV0_SIZE);
  241. memoryMapDeviceSpace (DEVICE1, CFG_DEV1_SPACE, CFG_DEV1_SIZE);
  242. memoryMapDeviceSpace (DEVICE2, CFG_DEV2_SPACE, CFG_DEV2_SIZE);
  243. memoryMapDeviceSpace (DEVICE3, CFG_DEV3_SPACE, CFG_DEV3_SIZE);
  244. /* configure device timing */
  245. GT_REG_WRITE (DEVICE_BANK0PARAMETERS, CFG_DEV0_PAR);
  246. GT_REG_WRITE (DEVICE_BANK1PARAMETERS, CFG_DEV1_PAR);
  247. GT_REG_WRITE (DEVICE_BANK2PARAMETERS, CFG_DEV2_PAR);
  248. GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_DEV3_PAR);
  249. #ifdef CFG_32BIT_BOOT_PAR /* set port parameters for Flash device module access */
  250. /* detect if we are booting from the 32 bit flash */
  251. if (GTREGREAD (DEVICE_BOOT_BANK_PARAMETERS) & (0x3 << 20)) {
  252. /* 32 bit boot flash */
  253. GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_8BIT_BOOT_PAR);
  254. GT_REG_WRITE (DEVICE_BOOT_BANK_PARAMETERS,
  255. CFG_32BIT_BOOT_PAR);
  256. } else {
  257. /* 8 bit boot flash */
  258. GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_32BIT_BOOT_PAR);
  259. GT_REG_WRITE (DEVICE_BOOT_BANK_PARAMETERS, CFG_8BIT_BOOT_PAR);
  260. }
  261. #else
  262. /* 8 bit boot flash only */
  263. /* GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_8BIT_BOOT_PAR);*/
  264. #endif
  265. gt_cpu_config ();
  266. /* MPP setup */
  267. GT_REG_WRITE (MPP_CONTROL0, CFG_MPP_CONTROL_0);
  268. GT_REG_WRITE (MPP_CONTROL1, CFG_MPP_CONTROL_1);
  269. GT_REG_WRITE (MPP_CONTROL2, CFG_MPP_CONTROL_2);
  270. GT_REG_WRITE (MPP_CONTROL3, CFG_MPP_CONTROL_3);
  271. GT_REG_WRITE (GPP_LEVEL_CONTROL, CFG_GPP_LEVEL_CONTROL);
  272. DEBUG_LED0_ON ();
  273. DEBUG_LED1_ON ();
  274. DEBUG_LED2_ON ();
  275. return 0;
  276. }
  277. /* various things to do after relocation */
  278. int misc_init_r ()
  279. {
  280. icache_enable ();
  281. #ifdef CFG_L2
  282. l2cache_enable ();
  283. #endif
  284. #ifdef CONFIG_MPSC
  285. mpsc_sdma_init ();
  286. mpsc_init2 ();
  287. #endif
  288. #if 0
  289. /* disable the dcache and MMU */
  290. dcache_lock ();
  291. #endif
  292. return 0;
  293. }
  294. void after_reloc (ulong dest_addr, gd_t * gd)
  295. {
  296. memoryMapDeviceSpace (BOOT_DEVICE, CFG_BOOT_SPACE, CFG_BOOT_SIZE);
  297. display_mem_map ();
  298. /* now, jump to the main ppcboot board init code */
  299. board_init_r (gd, dest_addr);
  300. /* NOTREACHED */
  301. }
  302. /* ------------------------------------------------------------------------- */
  303. /*
  304. * Check Board Identity:
  305. *
  306. * right now, assume borad type. (there is just one...after all)
  307. */
  308. int checkboard (void)
  309. {
  310. int l_type = 0;
  311. printf ("BOARD: %s\n", CFG_BOARD_NAME);
  312. return (l_type);
  313. }
  314. /* utility functions */
  315. void debug_led (int led, int mode)
  316. {
  317. }
  318. int display_mem_map (void)
  319. {
  320. int i, j;
  321. unsigned int base, size, width;
  322. /* SDRAM */
  323. printf ("SD (DDR) RAM\n");
  324. for (i = 0; i <= BANK3; i++) {
  325. base = memoryGetBankBaseAddress (i);
  326. size = memoryGetBankSize (i);
  327. if (size != 0) {
  328. printf ("BANK%d: base - 0x%08x\tsize - %dM bytes\n",
  329. i, base, size >> 20);
  330. }
  331. }
  332. #ifdef CONFIG_PCI
  333. /* CPU's PCI windows */
  334. for (i = 0; i <= PCI_HOST1; i++) {
  335. printf ("\nCPU's PCI %d windows\n", i);
  336. base = pciGetSpaceBase (i, PCI_IO);
  337. size = pciGetSpaceSize (i, PCI_IO);
  338. printf (" IO: base - 0x%08x\tsize - %dM bytes\n", base,
  339. size >> 20);
  340. for (j = 0;
  341. j <=
  342. PCI_REGION0
  343. /*ronen currently only first PCI MEM is used 3 */ ;
  344. j++) {
  345. base = pciGetSpaceBase (i, j);
  346. size = pciGetSpaceSize (i, j);
  347. printf ("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n", j, base, size >> 20);
  348. }
  349. }
  350. #endif /* of CONFIG_PCI */
  351. /* Devices */
  352. printf ("\nDEVICES\n");
  353. for (i = 0; i <= DEVICE3; i++) {
  354. base = memoryGetDeviceBaseAddress (i);
  355. size = memoryGetDeviceSize (i);
  356. width = memoryGetDeviceWidth (i) * 8;
  357. printf ("DEV %d: base - 0x%08x size - %dM bytes\twidth - %d bits", i, base, size >> 20, width);
  358. if (i == 0)
  359. printf ("\t- FLASH\n");
  360. else if (i == 1)
  361. printf ("\t- FLASH\n");
  362. else if (i == 2)
  363. printf ("\t- FLASH\n");
  364. else
  365. printf ("\t- RTC/REGS/CAN\n");
  366. }
  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 (CFG_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 (CFG_DRAM_TEST_DATA)
  405. unsigned long long pattern[] = {
  406. 0xaaaaaaaaaaaaaaaaLL,
  407. 0xccccccccccccccccLL,
  408. 0xf0f0f0f0f0f0f0f0LL,
  409. 0xff00ff00ff00ff00LL,
  410. 0xffff0000ffff0000LL,
  411. 0xffffffff00000000LL,
  412. 0x00000000ffffffffLL,
  413. 0x0000ffff0000ffffLL,
  414. 0x00ff00ff00ff00ffLL,
  415. 0x0f0f0f0f0f0f0f0fLL,
  416. 0x3333333333333333LL,
  417. 0x5555555555555555LL,
  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 *) CFG_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 /* CFG_DRAM_TEST_DATA */
  488. #if defined (CFG_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 *) CFG_MEMTEST_START;
  514. const unsigned int size = (CFG_MEMTEST_END - CFG_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. }
  520. /* verify each loaction */
  521. for (i = 0; i < size; i++) {
  522. if (pmem[i] != i) {
  523. printf ("\n Address Test Failed at 0x%x", i);
  524. return 1;
  525. }
  526. }
  527. return 0;
  528. }
  529. #endif /* CFG_DRAM_TEST_ADDRESS */
  530. #if defined (CFG_DRAM_TEST_WALK)
  531. /*********************************************************************/
  532. /* NAME: mem_march() - memory march */
  533. /* */
  534. /* DESCRIPTION: */
  535. /* Marches up through memory. At each location verifies rmask if */
  536. /* read = 1. At each location write wmask if write = 1. Displays */
  537. /* failing address and pattern. */
  538. /* */
  539. /* INPUTS: */
  540. /* volatile unsigned long long * base - start address of test */
  541. /* unsigned int size - number of dwords(64-bit) to test */
  542. /* unsigned long long rmask - read verify mask */
  543. /* unsigned long long wmask - wrtie verify mask */
  544. /* short read - verifies rmask if read = 1 */
  545. /* short write - writes wmask if write = 1 */
  546. /* */
  547. /* OUTPUTS: */
  548. /* Displays failing test pattern and address */
  549. /* */
  550. /* RETURNS: */
  551. /* 0 - Passed test */
  552. /* 1 - Failed test */
  553. /* */
  554. /* RESTRICTIONS/LIMITATIONS: */
  555. /* */
  556. /* */
  557. /*********************************************************************/
  558. int mem_march (volatile unsigned long long *base,
  559. unsigned int size,
  560. unsigned long long rmask,
  561. unsigned long long wmask, short read, short write)
  562. {
  563. unsigned int i;
  564. unsigned long long temp = 0;
  565. unsigned int hitemp, lotemp, himask, lomask;
  566. for (i = 0; i < size; i++) {
  567. if (read != 0) {
  568. /* temp = base[i]; */
  569. move64 ((unsigned long long *) &(base[i]), &temp);
  570. if (rmask != temp) {
  571. hitemp = (temp >> 32) & 0xffffffff;
  572. lotemp = temp & 0xffffffff;
  573. himask = (rmask >> 32) & 0xffffffff;
  574. lomask = rmask & 0xffffffff;
  575. 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);
  576. return 1;
  577. }
  578. }
  579. if (write != 0) {
  580. /* base[i] = wmask; */
  581. move64 (&wmask, (unsigned long long *) &(base[i]));
  582. }
  583. }
  584. return 0;
  585. }
  586. #endif /* CFG_DRAM_TEST_WALK */
  587. /*********************************************************************/
  588. /* NAME: mem_test_walk() - a simple walking ones test */
  589. /* */
  590. /* DESCRIPTION: */
  591. /* Performs a walking ones through entire physical memory. The */
  592. /* test uses as series of memory marches, mem_march(), to verify */
  593. /* and write the test patterns to memory. The test sequence is as */
  594. /* follows: */
  595. /* 1) march writing 0000...0001 */
  596. /* 2) march verifying 0000...0001 , writing 0000...0010 */
  597. /* 3) repeat step 2 shifting masks left 1 bit each time unitl */
  598. /* the write mask equals 1000...0000 */
  599. /* 4) march verifying 1000...0000 */
  600. /* The test fails if any of the memory marches return a failure. */
  601. /* */
  602. /* OUTPUTS: */
  603. /* Displays which pass on the memory test is executing */
  604. /* */
  605. /* RETURNS: */
  606. /* 0 - Passed test */
  607. /* 1 - Failed test */
  608. /* */
  609. /* RESTRICTIONS/LIMITATIONS: */
  610. /* */
  611. /* */
  612. /*********************************************************************/
  613. int mem_test_walk (void)
  614. {
  615. unsigned long long mask;
  616. volatile unsigned long long *pmem =
  617. (volatile unsigned long long *) CFG_MEMTEST_START;
  618. const unsigned long size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 8;
  619. unsigned int i;
  620. mask = 0x01;
  621. printf ("Initial Pass");
  622. mem_march (pmem, size, 0x0, 0x1, 0, 1);
  623. printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
  624. printf (" ");
  625. printf (" ");
  626. printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
  627. for (i = 0; i < 63; i++) {
  628. printf ("Pass %2d", i + 2);
  629. if (mem_march (pmem, size, mask, mask << 1, 1, 1) != 0) {
  630. /*printf("mask: 0x%x, pass: %d, ", mask, i); */
  631. return 1;
  632. }
  633. mask = mask << 1;
  634. printf ("\b\b\b\b\b\b\b");
  635. }
  636. printf ("Last Pass");
  637. if (mem_march (pmem, size, 0, mask, 0, 1) != 0) {
  638. /* printf("mask: 0x%x", mask); */
  639. return 1;
  640. }
  641. printf ("\b\b\b\b\b\b\b\b\b");
  642. printf (" ");
  643. printf ("\b\b\b\b\b\b\b\b\b");
  644. return 0;
  645. }
  646. /*********************************************************************/
  647. /* NAME: testdram() - calls any enabled memory tests */
  648. /* */
  649. /* DESCRIPTION: */
  650. /* Runs memory tests if the environment test variables are set to */
  651. /* 'y'. */
  652. /* */
  653. /* INPUTS: */
  654. /* testdramdata - If set to 'y', data test is run. */
  655. /* testdramaddress - If set to 'y', address test is run. */
  656. /* testdramwalk - If set to 'y', walking ones test is run */
  657. /* */
  658. /* OUTPUTS: */
  659. /* None */
  660. /* */
  661. /* RETURNS: */
  662. /* 0 - Passed test */
  663. /* 1 - Failed test */
  664. /* */
  665. /* RESTRICTIONS/LIMITATIONS: */
  666. /* */
  667. /* */
  668. /*********************************************************************/
  669. int testdram (void)
  670. {
  671. char *s;
  672. int rundata = 0;
  673. int runaddress = 0;
  674. int runwalk = 0;
  675. #ifdef CFG_DRAM_TEST_DATA
  676. s = getenv ("testdramdata");
  677. rundata = (s && (*s == 'y')) ? 1 : 0;
  678. #endif
  679. #ifdef CFG_DRAM_TEST_ADDRESS
  680. s = getenv ("testdramaddress");
  681. runaddress = (s && (*s == 'y')) ? 1 : 0;
  682. #endif
  683. #ifdef CFG_DRAM_TEST_WALK
  684. s = getenv ("testdramwalk");
  685. runwalk = (s && (*s == 'y')) ? 1 : 0;
  686. #endif
  687. if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
  688. printf ("Testing RAM from 0x%08x to 0x%08x ... (don't panic... that will take a moment !!!!)\n", CFG_MEMTEST_START, CFG_MEMTEST_END);
  689. }
  690. #ifdef CFG_DRAM_TEST_DATA
  691. if (rundata == 1) {
  692. printf ("Test DATA ... ");
  693. if (mem_test_data () == 1) {
  694. printf ("failed \n");
  695. return 1;
  696. } else
  697. printf ("ok \n");
  698. }
  699. #endif
  700. #ifdef CFG_DRAM_TEST_ADDRESS
  701. if (runaddress == 1) {
  702. printf ("Test ADDRESS ... ");
  703. if (mem_test_address () == 1) {
  704. printf ("failed \n");
  705. return 1;
  706. } else
  707. printf ("ok \n");
  708. }
  709. #endif
  710. #ifdef CFG_DRAM_TEST_WALK
  711. if (runwalk == 1) {
  712. printf ("Test WALKING ONEs ... ");
  713. if (mem_test_walk () == 1) {
  714. printf ("failed \n");
  715. return 1;
  716. } else
  717. printf ("ok \n");
  718. }
  719. #endif
  720. if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
  721. printf ("passed\n");
  722. }
  723. return 0;
  724. }
  725. #endif /* CFG_DRAM_TEST */
  726. /* ronen - the below functions are used by the bootm function */
  727. /* - we map the base register to fbe00000 (same mapping as in the LSP) */
  728. /* - we turn off the RX gig dmas - to prevent the dma from overunning */
  729. /* the kernel data areas. */
  730. /* - we diable and invalidate the icache and dcache. */
  731. void my_remap_gt_regs_bootm (u32 cur_loc, u32 new_loc)
  732. {
  733. u32 temp;
  734. temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
  735. if ((temp & 0xffff) == new_loc >> 16)
  736. return;
  737. temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
  738. 0xffff0000) | (new_loc >> 16);
  739. out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
  740. while ((WORD_SWAP (*((volatile unsigned int *) (NONE_CACHEABLE |
  741. new_loc |
  742. (INTERNAL_SPACE_DECODE)))))
  743. != temp);
  744. }
  745. void board_prebootm_init ()
  746. {
  747. /* change window size of PCI1 IO in order tp prevent overlaping with REG BASE. */
  748. GT_REG_WRITE (PCI_1_IO_SIZE, (_64K - 1) >> 16);
  749. /* Stop GigE Rx DMA engines */
  750. GT_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (0), 0x0000ff00);
  751. /* GT_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (1), 0x0000ff00); */
  752. /* GV_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (2), 0x0000ff00); */
  753. /* Relocate MV64360 internal regs */
  754. my_remap_gt_regs_bootm (CFG_GT_REGS, CFG_DFL_GT_REGS);
  755. icache_disable ();
  756. invalidate_l1_instruction_cache ();
  757. flush_data_cache ();
  758. dcache_disable ();
  759. }