sdram.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #include <common.h>
  15. #include <mpc83xx.h>
  16. #include <spd_sdram.h>
  17. #include <asm/bitops.h>
  18. #include <asm/io.h>
  19. #include <asm/processor.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. /* Fixed sdram init -- doesn't use serial presence detect.
  22. *
  23. * This is useful for faster booting in configs where the RAM is unlikely
  24. * to be changed, or for things like NAND booting where space is tight.
  25. */
  26. static long fixed_sdram(void)
  27. {
  28. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  29. u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
  30. u32 msize_log2 = __ilog2(msize);
  31. out_be32(&im->sysconf.ddrlaw[0].bar,
  32. CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000);
  33. out_be32(&im->sysconf.ddrlaw[0].ar, LBLAWAR_EN | (msize_log2 - 1));
  34. out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);
  35. out_be32(&im->ddr.csbnds[0].csbnds, (msize - 1) >> 24);
  36. out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
  37. /* Currently we use only one CS, so disable the other bank. */
  38. out_be32(&im->ddr.cs_config[1], 0);
  39. out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
  40. out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
  41. out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
  42. out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
  43. out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
  44. out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
  45. out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
  46. out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
  47. out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
  48. out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
  49. sync();
  50. /* enable DDR controller */
  51. setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
  52. sync();
  53. return get_ram_size(CONFIG_SYS_DDR_SDRAM_BASE, msize);
  54. }
  55. phys_size_t initdram(int board_type)
  56. {
  57. immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
  58. u32 msize;
  59. if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
  60. return -1;
  61. /* DDR SDRAM */
  62. msize = fixed_sdram();
  63. /* return total bus SDRAM size(bytes) -- DDR */
  64. return msize;
  65. }