sdram.c 2.2 KB

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