mpc837xerdb.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 <fdt_support.h>
  19. #include <spd_sdram.h>
  20. #include <vsc7385.h>
  21. #if defined(CFG_DRAM_TEST)
  22. int
  23. testdram(void)
  24. {
  25. uint *pstart = (uint *) CFG_MEMTEST_START;
  26. uint *pend = (uint *) CFG_MEMTEST_END;
  27. uint *p;
  28. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  29. CFG_MEMTEST_START,
  30. CFG_MEMTEST_END);
  31. printf("DRAM test phase 1:\n");
  32. for (p = pstart; p < pend; p++)
  33. *p = 0xaaaaaaaa;
  34. for (p = pstart; p < pend; p++) {
  35. if (*p != 0xaaaaaaaa) {
  36. printf("DRAM test fails at: %08x\n", (uint) p);
  37. return 1;
  38. }
  39. }
  40. printf("DRAM test phase 2:\n");
  41. for (p = pstart; p < pend; p++)
  42. *p = 0x55555555;
  43. for (p = pstart; p < pend; p++) {
  44. if (*p != 0x55555555) {
  45. printf("DRAM test fails at: %08x\n", (uint) p);
  46. return 1;
  47. }
  48. }
  49. printf("DRAM test passed.\n");
  50. return 0;
  51. }
  52. #endif
  53. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  54. void ddr_enable_ecc(unsigned int dram_size);
  55. #endif
  56. int fixed_sdram(void);
  57. long int initdram(int board_type)
  58. {
  59. immap_t *im = (immap_t *) CFG_IMMR;
  60. u32 msize = 0;
  61. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  62. return -1;
  63. #if defined(CONFIG_SPD_EEPROM)
  64. msize = spd_sdram();
  65. #else
  66. msize = fixed_sdram();
  67. #endif
  68. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  69. /* Initialize DDR ECC byte */
  70. ddr_enable_ecc(msize * 1024 * 1024);
  71. #endif
  72. /* return total bus DDR size(bytes) */
  73. return (msize * 1024 * 1024);
  74. }
  75. #if !defined(CONFIG_SPD_EEPROM)
  76. /*************************************************************************
  77. * fixed sdram init -- doesn't use serial presence detect.
  78. ************************************************************************/
  79. int fixed_sdram(void)
  80. {
  81. immap_t *im = (immap_t *) CFG_IMMR;
  82. u32 msize = CFG_DDR_SIZE * 1024 * 1024;
  83. u32 msize_log2 = __ilog2(msize);
  84. im->sysconf.ddrlaw[0].bar = CFG_DDR_SDRAM_BASE >> 12;
  85. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  86. im->sysconf.ddrcdr = CFG_DDRCDR_VALUE;
  87. udelay(50000);
  88. im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
  89. udelay(1000);
  90. im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
  91. im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
  92. udelay(1000);
  93. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  94. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  95. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  96. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  97. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  98. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  99. im->ddr.sdram_mode = CFG_DDR_MODE;
  100. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  101. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  102. sync();
  103. udelay(1000);
  104. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  105. udelay(2000);
  106. return CFG_DDR_SIZE;
  107. }
  108. #endif /*!CFG_SPD_EEPROM */
  109. int checkboard(void)
  110. {
  111. puts("Board: Freescale MPC837xERDB\n");
  112. return 0;
  113. }
  114. int board_early_init_f(void)
  115. {
  116. #ifdef CONFIG_FSL_SERDES
  117. immap_t *immr = (immap_t *)CFG_IMMR;
  118. u32 spridr = in_be32(&immr->sysconf.spridr);
  119. /* we check only part num, and don't look for CPU revisions */
  120. switch (PARTID_NO_E(spridr)) {
  121. case SPR_8377:
  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_PEX,
  125. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  126. break;
  127. case SPR_8378:
  128. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_PEX,
  129. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  130. break;
  131. case SPR_8379:
  132. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
  133. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  134. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
  135. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  136. break;
  137. default:
  138. printf("serdes not configured: unknown CPU part number: "
  139. "%04x\n", spridr >> 16);
  140. break;
  141. }
  142. #endif /* CONFIG_FSL_SERDES */
  143. return 0;
  144. }
  145. /*
  146. * Miscellaneous late-boot configurations
  147. *
  148. * If a VSC7385 microcode image is present, then upload it.
  149. */
  150. int misc_init_r(void)
  151. {
  152. int rc = 0;
  153. #ifdef CONFIG_VSC7385_IMAGE
  154. if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
  155. CONFIG_VSC7385_IMAGE_SIZE)) {
  156. puts("Failure uploading VSC7385 microcode.\n");
  157. rc = 1;
  158. }
  159. #endif
  160. return rc;
  161. }
  162. #if defined(CONFIG_OF_BOARD_SETUP)
  163. void ft_board_setup(void *blob, bd_t *bd)
  164. {
  165. #ifdef CONFIG_PCI
  166. ft_pci_setup(blob, bd);
  167. #endif
  168. ft_cpu_setup(blob, bd);
  169. fdt_fixup_dr_usb(blob, bd);
  170. }
  171. #endif /* CONFIG_OF_BOARD_SETUP */