emif4.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Author :
  4. * Vaibhav Hiremath <hvaibhav@ti.com>
  5. *
  6. * Based on mem.c and sdrc.c
  7. *
  8. * Copyright (C) 2010
  9. * Texas Instruments Incorporated - http://www.ti.com/
  10. */
  11. #include <common.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/mem.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <asm/arch/emif4.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. extern omap3_sysinfo sysinfo;
  18. static emif4_t *emif4_base = (emif4_t *)OMAP34XX_SDRC_BASE;
  19. /*
  20. * is_mem_sdr -
  21. * - Return 1 if mem type in use is SDR
  22. */
  23. u32 is_mem_sdr(void)
  24. {
  25. return 0;
  26. }
  27. /*
  28. * get_sdr_cs_size -
  29. * - Get size of chip select 0/1
  30. */
  31. u32 get_sdr_cs_size(u32 cs)
  32. {
  33. u32 size = 0;
  34. /* TODO: Calculate the size based on EMIF4 configuration */
  35. if (cs == CS0)
  36. size = CONFIG_SYS_CS0_SIZE;
  37. return size;
  38. }
  39. /*
  40. * get_sdr_cs_offset -
  41. * - Get offset of cs from cs0 start
  42. */
  43. u32 get_sdr_cs_offset(u32 cs)
  44. {
  45. u32 offset = 0;
  46. return offset;
  47. }
  48. /*
  49. * do_emif4_init -
  50. * - Init the emif4 module for DDR access
  51. * - Early init routines, called from flash or SRAM.
  52. */
  53. static void do_emif4_init(void)
  54. {
  55. unsigned int regval;
  56. /* Set the DDR PHY parameters in PHY ctrl registers */
  57. regval = (EMIF4_DDR1_READ_LAT | EMIF4_DDR1_PWRDN_DIS |
  58. EMIF4_DDR1_EXT_STRB_DIS);
  59. writel(regval, &emif4_base->ddr_phyctrl1);
  60. writel(regval, &emif4_base->ddr_phyctrl1_shdw);
  61. writel(0, &emif4_base->ddr_phyctrl2);
  62. /* Reset the DDR PHY and wait till completed */
  63. regval = readl(&emif4_base->sdram_iodft_tlgc);
  64. regval |= (1<<10);
  65. writel(regval, &emif4_base->sdram_iodft_tlgc);
  66. /*Wait till that bit clears*/
  67. while ((readl(&emif4_base->sdram_iodft_tlgc) & (1<<10)) != 0x0);
  68. /*Re-verify the DDR PHY status*/
  69. while ((readl(&emif4_base->sdram_sts) & (1<<2)) == 0x0);
  70. regval |= (1<<0);
  71. writel(regval, &emif4_base->sdram_iodft_tlgc);
  72. /* Set SDR timing registers */
  73. regval = (EMIF4_TIM1_T_WTR | EMIF4_TIM1_T_RRD |
  74. EMIF4_TIM1_T_RC | EMIF4_TIM1_T_RAS |
  75. EMIF4_TIM1_T_WR | EMIF4_TIM1_T_RCD |
  76. EMIF4_TIM1_T_RP);
  77. writel(regval, &emif4_base->sdram_time1);
  78. writel(regval, &emif4_base->sdram_time1_shdw);
  79. regval = (EMIF4_TIM2_T_CKE | EMIF4_TIM2_T_RTP |
  80. EMIF4_TIM2_T_XSRD | EMIF4_TIM2_T_XSNR |
  81. EMIF4_TIM2_T_ODT | EMIF4_TIM2_T_XP);
  82. writel(regval, &emif4_base->sdram_time2);
  83. writel(regval, &emif4_base->sdram_time2_shdw);
  84. regval = (EMIF4_TIM3_T_RAS_MAX | EMIF4_TIM3_T_RFC);
  85. writel(regval, &emif4_base->sdram_time3);
  86. writel(regval, &emif4_base->sdram_time3_shdw);
  87. /* Set the PWR control register */
  88. regval = (EMIF4_PWR_PM_TIM | EMIF4_PWR_LP_MODE |
  89. EMIF4_PWR_DPD_DIS | EMIF4_PWR_IDLE_MODE);
  90. writel(regval, &emif4_base->sdram_pwr_mgmt);
  91. writel(regval, &emif4_base->sdram_pwr_mgmt_shdw);
  92. /* Set the DDR refresh rate control register */
  93. regval = (EMIF4_REFRESH_RATE | EMIF4_INITREF_DIS);
  94. writel(regval, &emif4_base->sdram_refresh_ctrl);
  95. writel(regval, &emif4_base->sdram_refresh_ctrl_shdw);
  96. /* set the SDRAM configuration register */
  97. regval = (EMIF4_CFG_PGSIZE | EMIF4_CFG_EBANK |
  98. EMIF4_CFG_IBANK | EMIF4_CFG_ROWSIZE |
  99. EMIF4_CFG_CL | EMIF4_CFG_NARROW_MD |
  100. EMIF4_CFG_SDR_DRV | EMIF4_CFG_DDR_DIS_DLL |
  101. EMIF4_CFG_DDR2_DDQS | EMIF4_CFG_DDR_TERM |
  102. EMIF4_CFG_IBANK_POS | EMIF4_CFG_SDRAM_TYP);
  103. writel(regval, &emif4_base->sdram_config);
  104. }
  105. /*
  106. * dram_init -
  107. * - Sets uboots idea of sdram size
  108. */
  109. int dram_init(void)
  110. {
  111. unsigned int size0 = 0, size1 = 0;
  112. size0 = get_sdr_cs_size(CS0);
  113. /*
  114. * If a second bank of DDR is attached to CS1 this is
  115. * where it can be started. Early init code will init
  116. * memory on CS0.
  117. */
  118. if ((sysinfo.mtype == DDR_COMBO) || (sysinfo.mtype == DDR_STACKED))
  119. size1 = get_sdr_cs_size(CS1);
  120. gd->ram_size = size0 + size1;
  121. return 0;
  122. }
  123. int dram_init_banksize(void)
  124. {
  125. unsigned int size0 = 0, size1 = 0;
  126. size0 = get_sdr_cs_size(CS0);
  127. size1 = get_sdr_cs_size(CS1);
  128. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  129. gd->bd->bi_dram[0].size = size0;
  130. gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
  131. gd->bd->bi_dram[1].size = size1;
  132. return 0;
  133. }
  134. /*
  135. * mem_init() -
  136. * - Initialize memory subsystem
  137. */
  138. void mem_init(void)
  139. {
  140. do_emif4_init();
  141. }