mpc837xerdb.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 <spd_sdram.h>
  18. #include <vsc7385.h>
  19. #if defined(CFG_DRAM_TEST)
  20. int
  21. testdram(void)
  22. {
  23. uint *pstart = (uint *) CFG_MEMTEST_START;
  24. uint *pend = (uint *) CFG_MEMTEST_END;
  25. uint *p;
  26. printf("Testing DRAM from 0x%08x to 0x%08x\n",
  27. CFG_MEMTEST_START,
  28. CFG_MEMTEST_END);
  29. printf("DRAM test phase 1:\n");
  30. for (p = pstart; p < pend; p++)
  31. *p = 0xaaaaaaaa;
  32. for (p = pstart; p < pend; p++) {
  33. if (*p != 0xaaaaaaaa) {
  34. printf("DRAM test fails at: %08x\n", (uint) p);
  35. return 1;
  36. }
  37. }
  38. printf("DRAM test phase 2:\n");
  39. for (p = pstart; p < pend; p++)
  40. *p = 0x55555555;
  41. for (p = pstart; p < pend; p++) {
  42. if (*p != 0x55555555) {
  43. printf("DRAM test fails at: %08x\n", (uint) p);
  44. return 1;
  45. }
  46. }
  47. printf("DRAM test passed.\n");
  48. return 0;
  49. }
  50. #endif
  51. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  52. void ddr_enable_ecc(unsigned int dram_size);
  53. #endif
  54. int fixed_sdram(void);
  55. long int initdram(int board_type)
  56. {
  57. immap_t *im = (immap_t *) CFG_IMMR;
  58. u32 msize = 0;
  59. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  60. return -1;
  61. #if defined(CONFIG_SPD_EEPROM)
  62. msize = spd_sdram();
  63. #else
  64. msize = fixed_sdram();
  65. #endif
  66. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  67. /* Initialize DDR ECC byte */
  68. ddr_enable_ecc(msize * 1024 * 1024);
  69. #endif
  70. /* return total bus DDR size(bytes) */
  71. return (msize * 1024 * 1024);
  72. }
  73. #if !defined(CONFIG_SPD_EEPROM)
  74. /*************************************************************************
  75. * fixed sdram init -- doesn't use serial presence detect.
  76. ************************************************************************/
  77. int fixed_sdram(void)
  78. {
  79. immap_t *im = (immap_t *) CFG_IMMR;
  80. u32 msize = CFG_DDR_SIZE * 1024 * 1024;
  81. u32 msize_log2 = __ilog2(msize);
  82. im->sysconf.ddrlaw[0].bar = CFG_DDR_SDRAM_BASE >> 12;
  83. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  84. im->sysconf.ddrcdr = CFG_DDRCDR_VALUE;
  85. udelay(50000);
  86. im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
  87. udelay(1000);
  88. im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
  89. im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
  90. udelay(1000);
  91. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  92. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  93. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  94. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  95. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  96. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  97. im->ddr.sdram_mode = CFG_DDR_MODE;
  98. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  99. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  100. sync();
  101. udelay(1000);
  102. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  103. udelay(2000);
  104. return CFG_DDR_SIZE;
  105. }
  106. #endif /*!CFG_SPD_EEPROM */
  107. int checkboard(void)
  108. {
  109. puts("Board: Freescale MPC837xERDB\n");
  110. return 0;
  111. }
  112. /*
  113. * Miscellaneous late-boot configurations
  114. *
  115. * If a VSC7385 microcode image is present, then upload it.
  116. */
  117. int misc_init_r(void)
  118. {
  119. int rc = 0;
  120. #ifdef CONFIG_VSC7385_IMAGE
  121. if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
  122. CONFIG_VSC7385_IMAGE_SIZE)) {
  123. puts("Failure uploading VSC7385 microcode.\n");
  124. rc = 1;
  125. }
  126. #endif
  127. return rc;
  128. }
  129. #if defined(CONFIG_OF_BOARD_SETUP)
  130. void ft_board_setup(void *blob, bd_t *bd)
  131. {
  132. #ifdef CONFIG_PCI
  133. ft_pci_setup(blob, bd);
  134. #endif
  135. ft_cpu_setup(blob, bd);
  136. }
  137. #endif /* CONFIG_OF_BOARD_SETUP */