sdram.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/fsl_ddr_sdram.h>
  27. #include <asm/processor.h>
  28. #include <asm/mmu.h>
  29. #include <spd_sdram.h>
  30. #if !defined(CONFIG_SPD_EEPROM)
  31. /*
  32. * Autodetect onboard DDR SDRAM on 85xx platforms
  33. *
  34. * NOTE: Some of the hardcoded values are hardware dependant,
  35. * so this should be extended for other future boards
  36. * using this routine!
  37. */
  38. long int sdram_setup(int casl)
  39. {
  40. volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
  41. /*
  42. * Disable memory controller.
  43. */
  44. ddr->cs0_config = 0;
  45. ddr->sdram_cfg = 0;
  46. ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
  47. ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
  48. ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  49. ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  50. ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  51. ddr->sdram_mode = CONFIG_SYS_DDR_MODE;
  52. ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  53. ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONFIG_2;
  54. ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CONTROL;
  55. asm ("sync;isync;msync");
  56. udelay(1000);
  57. ddr->sdram_cfg = CONFIG_SYS_DDR_CONFIG;
  58. asm ("sync; isync; msync");
  59. udelay(1000);
  60. if (get_ram_size(0, CONFIG_SYS_SDRAM_SIZE<<20) == CONFIG_SYS_SDRAM_SIZE<<20) {
  61. /*
  62. * OK, size detected -> all done
  63. */
  64. return CONFIG_SYS_SDRAM_SIZE<<20;
  65. }
  66. return 0; /* nothing found ! */
  67. }
  68. #endif
  69. phys_size_t initdram (int board_type)
  70. {
  71. long dram_size = 0;
  72. #if defined(CONFIG_SPD_EEPROM)
  73. dram_size = fsl_ddr_sdram();
  74. dram_size = setup_ddr_tlbs(dram_size / 0x100000);
  75. dram_size *= 0x100000;
  76. #else
  77. dram_size = sdram_setup(CONFIG_DDR_DEFAULT_CL);
  78. #endif
  79. return dram_size;
  80. }
  81. #if defined(CONFIG_SYS_DRAM_TEST)
  82. int testdram (void)
  83. {
  84. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  85. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  86. uint *p;
  87. printf ("SDRAM test phase 1:\n");
  88. for (p = pstart; p < pend; p++)
  89. *p = 0xaaaaaaaa;
  90. for (p = pstart; p < pend; p++) {
  91. if (*p != 0xaaaaaaaa) {
  92. printf ("SDRAM test fails at: %08x\n", (uint) p);
  93. return 1;
  94. }
  95. }
  96. printf ("SDRAM test phase 2:\n");
  97. for (p = pstart; p < pend; p++)
  98. *p = 0x55555555;
  99. for (p = pstart; p < pend; p++) {
  100. if (*p != 0x55555555) {
  101. printf ("SDRAM test fails at: %08x\n", (uint) p);
  102. return 1;
  103. }
  104. }
  105. printf ("SDRAM test passed.\n");
  106. return 0;
  107. }
  108. #endif