sdram.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2007 Freescale Semiconductor, Inc.
  3. *
  4. * Authors: Nick.Spence@freescale.com
  5. * Wilson.Lo@freescale.com
  6. * scottwood@freescale.com
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <mpc83xx.h>
  12. #include <spd_sdram.h>
  13. #include <asm/bitops.h>
  14. #include <asm/io.h>
  15. #include <asm/processor.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. static void resume_from_sleep(void)
  18. {
  19. u32 magic = *(u32 *)0;
  20. typedef void (*func_t)(void);
  21. func_t resume = *(func_t *)4;
  22. if (magic == 0xf5153ae5)
  23. resume();
  24. gd->flags &= ~GD_FLG_SILENT;
  25. puts("\nResume from sleep failed: bad magic word\n");
  26. }
  27. /* Fixed sdram init -- doesn't use serial presence detect.
  28. *
  29. * This is useful for faster booting in configs where the RAM is unlikely
  30. * to be changed, or for things like NAND booting where space is tight.
  31. */
  32. #ifndef CONFIG_SYS_RAMBOOT
  33. static long fixed_sdram(void)
  34. {
  35. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  36. u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
  37. u32 msize_log2 = __ilog2(msize);
  38. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  39. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  40. im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
  41. /*
  42. * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg],
  43. * or the DDR2 controller may fail to initialize correctly.
  44. */
  45. __udelay(50000);
  46. im->ddr.csbnds[0].csbnds = (msize - 1) >> 24;
  47. im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
  48. /* Currently we use only one CS, so disable the other bank. */
  49. im->ddr.cs_config[1] = 0;
  50. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
  51. im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  52. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  53. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  54. im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  55. if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
  56. im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG | SDRAM_CFG_BI;
  57. else
  58. im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
  59. im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
  60. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  61. im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
  62. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  63. sync();
  64. /* enable DDR controller */
  65. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  66. sync();
  67. return msize;
  68. }
  69. #else
  70. static long fixed_sdram(void)
  71. {
  72. return CONFIG_SYS_DDR_SIZE * 1024 * 1024;
  73. }
  74. #endif /* CONFIG_SYS_RAMBOOT */
  75. phys_size_t initdram(int board_type)
  76. {
  77. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  78. u32 msize;
  79. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  80. return -1;
  81. /* DDR SDRAM */
  82. msize = fixed_sdram();
  83. if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
  84. resume_from_sleep();
  85. /* return total bus SDRAM size(bytes) -- DDR */
  86. return msize;
  87. }