mpc837xerdb.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (C) 2007 Freescale Semiconductor, Inc.
  3. * Kevin Lam <kevin.lam@freescale.com>
  4. * Joe D'Abbraccio <joe.d'abbraccio@freescale.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. */
  14. #include <common.h>
  15. #include <i2c.h>
  16. #include <asm/io.h>
  17. #include <asm/fsl_serdes.h>
  18. #include <spd_sdram.h>
  19. #include <vsc7385.h>
  20. #if defined(CFG_DRAM_TEST)
  21. int
  22. testdram(void)
  23. {
  24. uint *pstart = (uint *) CFG_MEMTEST_START;
  25. uint *pend = (uint *) CFG_MEMTEST_END;
  26. uint *p;
  27. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  28. CFG_MEMTEST_START,
  29. CFG_MEMTEST_END);
  30. printf("DRAM test phase 1:\n");
  31. for (p = pstart; p < pend; p++)
  32. *p = 0xaaaaaaaa;
  33. for (p = pstart; p < pend; p++) {
  34. if (*p != 0xaaaaaaaa) {
  35. printf("DRAM test fails at: %08x\n", (uint) p);
  36. return 1;
  37. }
  38. }
  39. printf("DRAM test phase 2:\n");
  40. for (p = pstart; p < pend; p++)
  41. *p = 0x55555555;
  42. for (p = pstart; p < pend; p++) {
  43. if (*p != 0x55555555) {
  44. printf("DRAM test fails at: %08x\n", (uint) p);
  45. return 1;
  46. }
  47. }
  48. printf("DRAM test passed.\n");
  49. return 0;
  50. }
  51. #endif
  52. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  53. void ddr_enable_ecc(unsigned int dram_size);
  54. #endif
  55. int fixed_sdram(void);
  56. long int initdram(int board_type)
  57. {
  58. immap_t *im = (immap_t *) CFG_IMMR;
  59. u32 msize = 0;
  60. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  61. return -1;
  62. #if defined(CONFIG_SPD_EEPROM)
  63. msize = spd_sdram();
  64. #else
  65. msize = fixed_sdram();
  66. #endif
  67. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  68. /* Initialize DDR ECC byte */
  69. ddr_enable_ecc(msize * 1024 * 1024);
  70. #endif
  71. /* return total bus DDR size(bytes) */
  72. return (msize * 1024 * 1024);
  73. }
  74. #if !defined(CONFIG_SPD_EEPROM)
  75. /*************************************************************************
  76. * fixed sdram init -- doesn't use serial presence detect.
  77. ************************************************************************/
  78. int fixed_sdram(void)
  79. {
  80. immap_t *im = (immap_t *) CFG_IMMR;
  81. u32 msize = CFG_DDR_SIZE * 1024 * 1024;
  82. u32 msize_log2 = __ilog2(msize);
  83. im->sysconf.ddrlaw[0].bar = CFG_DDR_SDRAM_BASE >> 12;
  84. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  85. im->sysconf.ddrcdr = CFG_DDRCDR_VALUE;
  86. udelay(50000);
  87. im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
  88. udelay(1000);
  89. im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
  90. im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
  91. udelay(1000);
  92. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  93. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  94. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  95. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  96. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  97. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  98. im->ddr.sdram_mode = CFG_DDR_MODE;
  99. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  100. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  101. sync();
  102. udelay(1000);
  103. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  104. udelay(2000);
  105. return CFG_DDR_SIZE;
  106. }
  107. #endif /*!CFG_SPD_EEPROM */
  108. int checkboard(void)
  109. {
  110. puts("Board: Freescale MPC837xERDB\n");
  111. return 0;
  112. }
  113. int board_early_init_f(void)
  114. {
  115. #ifdef CONFIG_FSL_SERDES
  116. immap_t *immr = (immap_t *)CFG_IMMR;
  117. u32 spridr = in_be32(&immr->sysconf.spridr);
  118. /* we check only part num, and don't look for CPU revisions */
  119. switch (spridr >> 16) {
  120. case SPR_8379E_REV10 >> 16:
  121. case SPR_8379_REV10 >> 16:
  122. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
  123. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  124. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
  125. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  126. break;
  127. case SPR_8378E_REV10 >> 16:
  128. case SPR_8378_REV10 >> 16:
  129. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
  130. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  131. break;
  132. case SPR_8377E_REV10 >> 16:
  133. case SPR_8377_REV10 >> 16:
  134. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
  135. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  136. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
  137. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  138. break;
  139. default:
  140. printf("serdes not configured: unknown CPU part number: "
  141. "%04x\n", spridr >> 16);
  142. break;
  143. }
  144. #endif /* CONFIG_FSL_SERDES */
  145. return 0;
  146. }
  147. /*
  148. * Miscellaneous late-boot configurations
  149. *
  150. * If a VSC7385 microcode image is present, then upload it.
  151. */
  152. int misc_init_r(void)
  153. {
  154. int rc = 0;
  155. #ifdef CONFIG_VSC7385_IMAGE
  156. if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
  157. CONFIG_VSC7385_IMAGE_SIZE)) {
  158. puts("Failure uploading VSC7385 microcode.\n");
  159. rc = 1;
  160. }
  161. #endif
  162. return rc;
  163. }
  164. #if defined(CONFIG_OF_BOARD_SETUP)
  165. void ft_board_setup(void *blob, bd_t *bd)
  166. {
  167. #ifdef CONFIG_PCI
  168. ft_pci_setup(blob, bd);
  169. #endif
  170. ft_cpu_setup(blob, bd);
  171. }
  172. #endif /* CONFIG_OF_BOARD_SETUP */