sdram.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. phys_size_t fixed_sdram(void)
  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. #if defined(CONFIG_SYS_DRAM_TEST)
  70. int testdram (void)
  71. {
  72. uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
  73. uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
  74. uint *p;
  75. printf ("SDRAM test phase 1:\n");
  76. for (p = pstart; p < pend; p++)
  77. *p = 0xaaaaaaaa;
  78. for (p = pstart; p < pend; p++) {
  79. if (*p != 0xaaaaaaaa) {
  80. printf ("SDRAM test fails at: %08x\n", (uint) p);
  81. return 1;
  82. }
  83. }
  84. printf ("SDRAM test phase 2:\n");
  85. for (p = pstart; p < pend; p++)
  86. *p = 0x55555555;
  87. for (p = pstart; p < pend; p++) {
  88. if (*p != 0x55555555) {
  89. printf ("SDRAM test fails at: %08x\n", (uint) p);
  90. return 1;
  91. }
  92. }
  93. printf ("SDRAM test passed.\n");
  94. return 0;
  95. }
  96. #endif