mpc837xerdb.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 <spd.h>
  17. #include <asm/io.h>
  18. #if defined(CONFIG_SPD_EEPROM)
  19. #include <spd_sdram.h>
  20. #endif
  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. int board_early_init_f(void)
  54. {
  55. return 0;
  56. }
  57. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  58. void ddr_enable_ecc(unsigned int dram_size);
  59. #endif
  60. int fixed_sdram(void);
  61. long int initdram(int board_type)
  62. {
  63. immap_t *im = (immap_t *) CFG_IMMR;
  64. u32 msize = 0;
  65. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  66. return -1;
  67. #if defined(CONFIG_SPD_EEPROM)
  68. msize = spd_sdram();
  69. #else
  70. msize = fixed_sdram();
  71. #endif
  72. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  73. /* Initialize DDR ECC byte */
  74. ddr_enable_ecc(msize * 1024 * 1024);
  75. #endif
  76. /* return total bus DDR size(bytes) */
  77. return (msize * 1024 * 1024);
  78. }
  79. #if !defined(CONFIG_SPD_EEPROM)
  80. /*************************************************************************
  81. * fixed sdram init -- doesn't use serial presence detect.
  82. ************************************************************************/
  83. int fixed_sdram(void)
  84. {
  85. immap_t *im = (immap_t *) CFG_IMMR;
  86. u32 msize = CFG_DDR_SIZE * 1024 * 1024;
  87. u32 msize_log2 = __ilog2(msize);
  88. im->sysconf.ddrlaw[0].bar = CFG_DDR_SDRAM_BASE >> 12;
  89. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  90. im->sysconf.ddrcdr = CFG_DDRCDR_VALUE;
  91. udelay(50000);
  92. im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
  93. udelay(1000);
  94. im->ddr.csbnds[0].csbnds = CFG_DDR_CS0_BNDS;
  95. im->ddr.cs_config[0] = CFG_DDR_CS0_CONFIG;
  96. udelay(1000);
  97. im->ddr.timing_cfg_0 = CFG_DDR_TIMING_0;
  98. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  99. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;
  100. im->ddr.timing_cfg_3 = CFG_DDR_TIMING_3;
  101. im->ddr.sdram_cfg = CFG_DDR_SDRAM_CFG;
  102. im->ddr.sdram_cfg2 = CFG_DDR_SDRAM_CFG2;
  103. im->ddr.sdram_mode = CFG_DDR_MODE;
  104. im->ddr.sdram_mode2 = CFG_DDR_MODE2;
  105. im->ddr.sdram_interval = CFG_DDR_INTERVAL;
  106. sync();
  107. udelay(1000);
  108. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  109. udelay(2000);
  110. return CFG_DDR_SIZE;
  111. }
  112. #endif /*!CFG_SPD_EEPROM */
  113. int checkboard(void)
  114. {
  115. puts("Board: Freescale MPC837xERDB\n");
  116. return 0;
  117. }
  118. #if defined(CONFIG_OF_BOARD_SETUP)
  119. void ft_board_setup(void *blob, bd_t *bd)
  120. {
  121. #ifdef CONFIG_PCI
  122. ft_pci_setup(blob, bd);
  123. #endif
  124. ft_cpu_setup(blob, bd);
  125. }
  126. #endif /* CONFIG_OF_BOARD_SETUP */