emif4.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Author :
  3. * Vaibhav Hiremath <hvaibhav@ti.com>
  4. *
  5. * Based on mem.c and sdrc.c
  6. *
  7. * Copyright (C) 2010
  8. * Texas Instruments Incorporated - http://www.ti.com/
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/io.h>
  27. #include <asm/arch/mem.h>
  28. #include <asm/arch/sys_proto.h>
  29. #include <asm/arch/emif4.h>
  30. extern omap3_sysinfo sysinfo;
  31. static emif4_t *emif4_base = (emif4_t *)OMAP34XX_SDRC_BASE;
  32. /*
  33. * is_mem_sdr -
  34. * - Return 1 if mem type in use is SDR
  35. */
  36. u32 is_mem_sdr(void)
  37. {
  38. return 0;
  39. }
  40. /*
  41. * get_sdr_cs_size -
  42. * - Get size of chip select 0/1
  43. */
  44. u32 get_sdr_cs_size(u32 cs)
  45. {
  46. u32 size;
  47. /* TODO: Calculate the size based on EMIF4 configuration */
  48. size = CONFIG_SYS_CS0_SIZE;
  49. return size;
  50. }
  51. /*
  52. * get_sdr_cs_offset -
  53. * - Get offset of cs from cs0 start
  54. */
  55. u32 get_sdr_cs_offset(u32 cs)
  56. {
  57. u32 offset = 0;
  58. return offset;
  59. }
  60. /*
  61. * do_emif4_init -
  62. * - Init the emif4 module for DDR access
  63. * - Early init routines, called from flash or SRAM.
  64. */
  65. void do_emif4_init(void)
  66. {
  67. unsigned int regval;
  68. /* Set the DDR PHY parameters in PHY ctrl registers */
  69. regval = (EMIF4_DDR1_READ_LAT | EMIF4_DDR1_PWRDN_DIS |
  70. EMIF4_DDR1_EXT_STRB_DIS);
  71. writel(regval, &emif4_base->ddr_phyctrl1);
  72. writel(regval, &emif4_base->ddr_phyctrl1_shdw);
  73. writel(0, &emif4_base->ddr_phyctrl2);
  74. /* Reset the DDR PHY and wait till completed */
  75. regval = readl(&emif4_base->sdram_iodft_tlgc);
  76. regval |= (1<<10);
  77. writel(regval, &emif4_base->sdram_iodft_tlgc);
  78. /*Wait till that bit clears*/
  79. while ((readl(&emif4_base->sdram_iodft_tlgc) & (1<<10)) == 0x1);
  80. /*Re-verify the DDR PHY status*/
  81. while ((readl(&emif4_base->sdram_sts) & (1<<2)) == 0x0);
  82. regval |= (1<<0);
  83. writel(regval, &emif4_base->sdram_iodft_tlgc);
  84. /* Set SDR timing registers */
  85. regval = (EMIF4_TIM1_T_WTR | EMIF4_TIM1_T_RRD |
  86. EMIF4_TIM1_T_RC | EMIF4_TIM1_T_RAS |
  87. EMIF4_TIM1_T_WR | EMIF4_TIM1_T_RCD |
  88. EMIF4_TIM1_T_RP);
  89. writel(regval, &emif4_base->sdram_time1);
  90. writel(regval, &emif4_base->sdram_time1_shdw);
  91. regval = (EMIF4_TIM2_T_CKE | EMIF4_TIM2_T_RTP |
  92. EMIF4_TIM2_T_XSRD | EMIF4_TIM2_T_XSNR |
  93. EMIF4_TIM2_T_ODT | EMIF4_TIM2_T_XP);
  94. writel(regval, &emif4_base->sdram_time2);
  95. writel(regval, &emif4_base->sdram_time2_shdw);
  96. regval = (EMIF4_TIM3_T_RAS_MAX | EMIF4_TIM3_T_RFC);
  97. writel(regval, &emif4_base->sdram_time3);
  98. writel(regval, &emif4_base->sdram_time3_shdw);
  99. /* Set the PWR control register */
  100. regval = (EMIF4_PWR_PM_TIM | EMIF4_PWR_LP_MODE |
  101. EMIF4_PWR_DPD_DIS | EMIF4_PWR_IDLE_MODE);
  102. writel(regval, &emif4_base->sdram_pwr_mgmt);
  103. writel(regval, &emif4_base->sdram_pwr_mgmt_shdw);
  104. /* Set the DDR refresh rate control register */
  105. regval = (EMIF4_REFRESH_RATE | EMIF4_INITREF_DIS);
  106. writel(regval, &emif4_base->sdram_refresh_ctrl);
  107. writel(regval, &emif4_base->sdram_refresh_ctrl_shdw);
  108. /* set the SDRAM configuration register */
  109. regval = (EMIF4_CFG_PGSIZE | EMIF4_CFG_EBANK |
  110. EMIF4_CFG_IBANK | EMIF4_CFG_ROWSIZE |
  111. EMIF4_CFG_CL | EMIF4_CFG_NARROW_MD |
  112. EMIF4_CFG_SDR_DRV | EMIF4_CFG_DDR_DIS_DLL |
  113. EMIF4_CFG_DDR2_DDQS | EMIF4_CFG_DDR_TERM |
  114. EMIF4_CFG_IBANK_POS | EMIF4_CFG_SDRAM_TYP);
  115. writel(regval, &emif4_base->sdram_config);
  116. }
  117. /*
  118. * dram_init -
  119. * - Sets uboots idea of sdram size
  120. */
  121. #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
  122. int dram_init(void)
  123. {
  124. DECLARE_GLOBAL_DATA_PTR;
  125. unsigned int size0 = 0, size1 = 0;
  126. size0 = get_sdr_cs_size(CS0);
  127. /*
  128. * If a second bank of DDR is attached to CS1 this is
  129. * where it can be started. Early init code will init
  130. * memory on CS0.
  131. */
  132. if ((sysinfo.mtype == DDR_COMBO) || (sysinfo.mtype == DDR_STACKED))
  133. size1 = get_sdr_cs_size(CS1);
  134. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  135. gd->bd->bi_dram[0].size = size0;
  136. gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
  137. gd->bd->bi_dram[1].size = size1;
  138. return 0;
  139. }
  140. #else
  141. int dram_init(void)
  142. {
  143. DECLARE_GLOBAL_DATA_PTR;
  144. unsigned int size0 = 0, size1 = 0;
  145. size0 = get_sdr_cs_size(CS0);
  146. /*
  147. * If a second bank of DDR is attached to CS1 this is
  148. * where it can be started. Early init code will init
  149. * memory on CS0.
  150. */
  151. if ((sysinfo.mtype == DDR_COMBO) || (sysinfo.mtype == DDR_STACKED))
  152. size1 = get_sdr_cs_size(CS1);
  153. gd->ram_size = size0 + size1;
  154. return 0;
  155. }
  156. void dram_init_banksize (void)
  157. {
  158. DECLARE_GLOBAL_DATA_PTR;
  159. unsigned int size0 = 0, size1 = 0;
  160. size0 = get_sdr_cs_size(CS0);
  161. size1 = get_sdr_cs_size(CS1);
  162. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  163. gd->bd->bi_dram[0].size = size0;
  164. gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
  165. gd->bd->bi_dram[1].size = size1;
  166. }
  167. #endif
  168. /*
  169. * mem_init() -
  170. * - Initialize memory subsystem
  171. */
  172. void mem_init(void)
  173. {
  174. do_emif4_init();
  175. }