emif4.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * emif4.c
  3. *
  4. * AM33XX emif4 configuration file
  5. *
  6. * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <asm/arch/cpu.h>
  12. #include <asm/arch/ddr_defs.h>
  13. #include <asm/arch/hardware.h>
  14. #include <asm/arch/clock.h>
  15. #include <asm/arch/sys_proto.h>
  16. #include <asm/io.h>
  17. #include <asm/emif.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. int dram_init(void)
  20. {
  21. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  22. sdram_init();
  23. #endif
  24. /* dram_init must store complete ramsize in gd->ram_size */
  25. gd->ram_size = get_ram_size(
  26. (void *)CONFIG_SYS_SDRAM_BASE,
  27. CONFIG_MAX_RAM_BANK_SIZE);
  28. return 0;
  29. }
  30. int dram_init_banksize(void)
  31. {
  32. gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
  33. gd->bd->bi_dram[0].size = gd->ram_size;
  34. return 0;
  35. }
  36. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  37. #ifdef CONFIG_TI81XX
  38. static struct dmm_lisa_map_regs *hw_lisa_map_regs =
  39. (struct dmm_lisa_map_regs *)DMM_BASE;
  40. #endif
  41. #ifndef CONFIG_TI816X
  42. static struct vtp_reg *vtpreg[2] = {
  43. (struct vtp_reg *)VTP0_CTRL_ADDR,
  44. (struct vtp_reg *)VTP1_CTRL_ADDR};
  45. #endif
  46. #ifdef CONFIG_AM33XX
  47. static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
  48. #endif
  49. #ifdef CONFIG_AM43XX
  50. static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
  51. static struct cm_device_inst *cm_device =
  52. (struct cm_device_inst *)CM_DEVICE_INST;
  53. #endif
  54. #ifdef CONFIG_TI81XX
  55. void config_dmm(const struct dmm_lisa_map_regs *regs)
  56. {
  57. enable_dmm_clocks();
  58. writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
  59. writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
  60. writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
  61. writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
  62. writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3);
  63. writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2);
  64. writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1);
  65. writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0);
  66. }
  67. #endif
  68. #ifndef CONFIG_TI816X
  69. static void config_vtp(int nr)
  70. {
  71. writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE,
  72. &vtpreg[nr]->vtp0ctrlreg);
  73. writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
  74. &vtpreg[nr]->vtp0ctrlreg);
  75. writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN,
  76. &vtpreg[nr]->vtp0ctrlreg);
  77. /* Poll for READY */
  78. while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
  79. VTP_CTRL_READY)
  80. ;
  81. }
  82. #endif
  83. void __weak ddr_pll_config(unsigned int ddrpll_m)
  84. {
  85. }
  86. void config_ddr(unsigned int pll, const struct ctrl_ioregs *ioregs,
  87. const struct ddr_data *data, const struct cmd_control *ctrl,
  88. const struct emif_regs *regs, int nr)
  89. {
  90. ddr_pll_config(pll);
  91. #ifndef CONFIG_TI816X
  92. config_vtp(nr);
  93. #endif
  94. config_cmd_ctrl(ctrl, nr);
  95. config_ddr_data(data, nr);
  96. #ifdef CONFIG_AM33XX
  97. config_io_ctrl(ioregs);
  98. /* Set CKE to be controlled by EMIF/DDR PHY */
  99. writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
  100. #endif
  101. #ifdef CONFIG_AM43XX
  102. writel(readl(&cm_device->cm_dll_ctrl) & ~0x1, &cm_device->cm_dll_ctrl);
  103. while ((readl(&cm_device->cm_dll_ctrl) & CM_DLL_READYST) == 0)
  104. ;
  105. config_io_ctrl(ioregs);
  106. /* Set CKE to be controlled by EMIF/DDR PHY */
  107. writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
  108. if (emif_sdram_type(regs->sdram_config) == EMIF_SDRAM_TYPE_DDR3)
  109. /* Allow EMIF to control DDR_RESET */
  110. writel(0x00000000, &ddrctrl->ddrioctrl);
  111. #endif
  112. /* Program EMIF instance */
  113. config_ddr_phy(regs, nr);
  114. set_sdram_timings(regs, nr);
  115. if (get_emif_rev(EMIF1_BASE) == EMIF_4D5)
  116. config_sdram_emif4d5(regs, nr);
  117. else
  118. config_sdram(regs, nr);
  119. }
  120. #endif