sdram.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * (C) Copyright 2008
  3. * Sergei Poselenov, Emcraft Systems, sposelenov@emcraft.com.
  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. #include <common.h>
  24. #include <asm/processor.h>
  25. #include <asm/immap_85xx.h>
  26. #include <asm/processor.h>
  27. #include <asm/mmu.h>
  28. #include <spd_sdram.h>
  29. #if !defined(CONFIG_SPD_EEPROM)
  30. /*
  31. * Autodetect onboard DDR SDRAM on 85xx platforms
  32. *
  33. * NOTE: Some of the hardcoded values are hardware dependant,
  34. * so this should be extended for other future boards
  35. * using this routine!
  36. */
  37. long int sdram_setup(int casl)
  38. {
  39. volatile ccsr_ddr_t *ddr = (void *)(CFG_MPC85xx_DDR_ADDR);
  40. /*
  41. * Disable memory controller.
  42. */
  43. ddr->cs0_config = 0;
  44. ddr->sdram_cfg = 0;
  45. ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
  46. ddr->cs0_config = CFG_DDR_CS0_CONFIG;
  47. ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
  48. ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
  49. ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
  50. ddr->sdram_mode = CFG_DDR_MODE;
  51. ddr->sdram_interval = CFG_DDR_INTERVAL;
  52. ddr->sdram_cfg_2 = CFG_DDR_CONFIG_2;
  53. ddr->sdram_clk_cntl = CFG_DDR_CLK_CONTROL;
  54. asm ("sync;isync;msync");
  55. udelay(1000);
  56. ddr->sdram_cfg = CFG_DDR_CONFIG;
  57. asm ("sync; isync; msync");
  58. udelay(1000);
  59. if (get_ram_size(0, CFG_SDRAM_SIZE<<20) == CFG_SDRAM_SIZE<<20) {
  60. /*
  61. * OK, size detected -> all done
  62. */
  63. return CFG_SDRAM_SIZE<<20;
  64. }
  65. return 0; /* nothing found ! */
  66. }
  67. #endif
  68. long int initdram (int board_type)
  69. {
  70. long dram_size = 0;
  71. #if defined(CONFIG_SPD_EEPROM)
  72. dram_size = spd_sdram ();
  73. #else
  74. dram_size = sdram_setup(CONFIG_DDR_DEFAULT_CL);
  75. #endif
  76. return dram_size;
  77. }
  78. #if defined(CFG_DRAM_TEST)
  79. int testdram (void)
  80. {
  81. uint *pstart = (uint *) CFG_MEMTEST_START;
  82. uint *pend = (uint *) CFG_MEMTEST_END;
  83. uint *p;
  84. printf ("SDRAM test phase 1:\n");
  85. for (p = pstart; p < pend; p++)
  86. *p = 0xaaaaaaaa;
  87. for (p = pstart; p < pend; p++) {
  88. if (*p != 0xaaaaaaaa) {
  89. printf ("SDRAM test fails at: %08x\n", (uint) p);
  90. return 1;
  91. }
  92. }
  93. printf ("SDRAM test phase 2:\n");
  94. for (p = pstart; p < pend; p++)
  95. *p = 0x55555555;
  96. for (p = pstart; p < pend; p++) {
  97. if (*p != 0x55555555) {
  98. printf ("SDRAM test fails at: %08x\n", (uint) p);
  99. return 1;
  100. }
  101. }
  102. printf ("SDRAM test passed.\n");
  103. return 0;
  104. }
  105. #endif