sdram.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2007 Freescale Semiconductor, Inc.
  3. * Copyright (C) 2010 Ilya Yanok, Emcraft Systems, yanok@emcraft.com
  4. *
  5. * Authors: Nick.Spence@freescale.com
  6. * Wilson.Lo@freescale.com
  7. * scottwood@freescale.com
  8. *
  9. * This files is mostly identical to the original from
  10. * board\freescale\mpc8315erdb\sdram.c
  11. *
  12. * See file CREDITS for list of people who contributed to this
  13. * project.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  28. * MA 02111-1307 USA
  29. */
  30. #include <common.h>
  31. #include <mpc83xx.h>
  32. #include <asm/bitops.h>
  33. #include <asm/io.h>
  34. #include <asm/processor.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. static void resume_from_sleep(void)
  37. {
  38. u32 magic = *(u32 *)0;
  39. typedef void (*func_t)(void);
  40. func_t resume = *(func_t *)4;
  41. if (magic == 0xf5153ae5)
  42. resume();
  43. gd->flags &= ~GD_FLG_SILENT;
  44. puts("\nResume from sleep failed: bad magic word\n");
  45. }
  46. /* Fixed sdram init -- doesn't use serial presence detect.
  47. *
  48. * This is useful for faster booting in configs where the RAM is unlikely
  49. * to be changed, or for things like NAND booting where space is tight.
  50. */
  51. static long fixed_sdram(void)
  52. {
  53. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  54. u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
  55. u32 msize_log2 = __ilog2(msize);
  56. out_be32(&im->sysconf.ddrlaw[0].bar,
  57. CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000);
  58. out_be32(&im->sysconf.ddrlaw[0].ar, LBLAWAR_EN | (msize_log2 - 1));
  59. out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);
  60. /*
  61. * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg],
  62. * or the DDR2 controller may fail to initialize correctly.
  63. */
  64. udelay(50000);
  65. out_be32(&im->ddr.csbnds[0].csbnds, (msize - 1) >> 24);
  66. out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
  67. /* Currently we use only one CS, so disable the other bank. */
  68. out_be32(&im->ddr.cs_config[1], 0);
  69. out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
  70. out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
  71. out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
  72. out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
  73. out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
  74. if (in_be32(&im->pmc.pmccr1) & PMCCR1_POWER_OFF) {
  75. out_be32(&im->ddr.sdram_cfg,
  76. CONFIG_SYS_DDR_SDRAM_CFG | SDRAM_CFG_BI);
  77. } else {
  78. out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
  79. }
  80. out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
  81. out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
  82. out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
  83. out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
  84. sync();
  85. /* enable DDR controller */
  86. setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
  87. sync();
  88. return get_ram_size(CONFIG_SYS_DDR_SDRAM_BASE, msize);
  89. }
  90. phys_size_t initdram(int board_type)
  91. {
  92. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  93. u32 msize;
  94. if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
  95. return -1;
  96. /* DDR SDRAM */
  97. msize = fixed_sdram();
  98. if (in_be32(&im->pmc.pmccr1) & PMCCR1_POWER_OFF)
  99. resume_from_sleep();
  100. /* return total bus SDRAM size(bytes) -- DDR */
  101. return msize;
  102. }