sdram.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) Freescale Semiconductor, Inc. 2006-2007
  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. #ifndef CONFIG_SYS_8313ERDB_BROKEN_PMC
  18. static void resume_from_sleep(void)
  19. {
  20. u32 magic = *(u32 *)0;
  21. typedef void (*func_t)(void);
  22. func_t resume = *(func_t *)4;
  23. if (magic == 0xf5153ae5)
  24. resume();
  25. gd->flags &= ~GD_FLG_SILENT;
  26. puts("\nResume from sleep failed: bad magic word\n");
  27. }
  28. #endif
  29. /* Fixed sdram init -- doesn't use serial presence detect.
  30. *
  31. * This is useful for faster booting in configs where the RAM is unlikely
  32. * to be changed, or for things like NAND booting where space is tight.
  33. */
  34. static long fixed_sdram(void)
  35. {
  36. u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
  37. #ifndef CONFIG_SYS_RAMBOOT
  38. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  39. u32 msize_log2 = __ilog2(msize);
  40. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  41. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  42. im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
  43. /*
  44. * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg],
  45. * or the DDR2 controller may fail to initialize correctly.
  46. */
  47. __udelay(50000);
  48. #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
  49. #warning Chip select bounds is only configurable in 16MB increments
  50. #endif
  51. im->ddr.csbnds[0].csbnds =
  52. ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
  53. (((CONFIG_SYS_DDR_SDRAM_BASE + msize - 1) >> CSBNDS_EA_SHIFT) &
  54. CSBNDS_EA);
  55. im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
  56. /* Currently we use only one CS, so disable the other bank. */
  57. im->ddr.cs_config[1] = 0;
  58. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
  59. im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  60. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  61. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  62. im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  63. #ifndef CONFIG_SYS_8313ERDB_BROKEN_PMC
  64. if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
  65. im->ddr.sdram_cfg = CONFIG_SYS_SDRAM_CFG | SDRAM_CFG_BI;
  66. else
  67. #endif
  68. im->ddr.sdram_cfg = CONFIG_SYS_SDRAM_CFG;
  69. im->ddr.sdram_cfg2 = CONFIG_SYS_SDRAM_CFG2;
  70. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  71. im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE_2;
  72. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  73. sync();
  74. /* enable DDR controller */
  75. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  76. #endif
  77. return msize;
  78. }
  79. phys_size_t initdram(int board_type)
  80. {
  81. volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
  82. volatile fsl_lbc_t *lbc = &im->im_lbc;
  83. u32 msize;
  84. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
  85. return -1;
  86. /* DDR SDRAM - Main SODIMM */
  87. msize = fixed_sdram();
  88. /* Local Bus setup lbcr and mrtpr */
  89. lbc->lbcr = CONFIG_SYS_LBC_LBCR;
  90. lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
  91. sync();
  92. #ifndef CONFIG_SYS_8313ERDB_BROKEN_PMC
  93. if (im->pmc.pmccr1 & PMCCR1_POWER_OFF)
  94. resume_from_sleep();
  95. #endif
  96. /* return total bus SDRAM size(bytes) -- DDR */
  97. return msize;
  98. }