sdrc.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Functions related to OMAP3 SDRC.
  3. *
  4. * This file has been created after exctracting and consolidating
  5. * the SDRC related content from mem.c and board.c, also created
  6. * generic init function (mem_init).
  7. *
  8. * Copyright (C) 2004-2010
  9. * Texas Instruments Incorporated - http://www.ti.com/
  10. *
  11. * Author :
  12. * Vaibhav Hiremath <hvaibhav@ti.com>
  13. *
  14. * Original implementation by (mem.c, board.c) :
  15. * Sunil Kumar <sunilsaini05@gmail.com>
  16. * Shashi Ranjan <shashiranjanmca05@gmail.com>
  17. * Manikandan Pillai <mani.pillai@ti.com>
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License as
  21. * published by the Free Software Foundation; either version 2 of
  22. * the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  32. * MA 02111-1307 USA
  33. */
  34. #include <common.h>
  35. #include <asm/io.h>
  36. #include <asm/arch/mem.h>
  37. #include <asm/arch/sys_proto.h>
  38. DECLARE_GLOBAL_DATA_PTR;
  39. extern omap3_sysinfo sysinfo;
  40. static struct sdrc *sdrc_base = (struct sdrc *)OMAP34XX_SDRC_BASE;
  41. /*
  42. * is_mem_sdr -
  43. * - Return 1 if mem type in use is SDR
  44. */
  45. u32 is_mem_sdr(void)
  46. {
  47. if (readl(&sdrc_base->cs[CS0].mr) == SDRC_MR_0_SDR)
  48. return 1;
  49. return 0;
  50. }
  51. /*
  52. * make_cs1_contiguous -
  53. * - For es2 and above remap cs1 behind cs0 to allow command line
  54. * mem=xyz use all memory with out discontinuous support compiled in.
  55. * Could do it at the ATAG, but there really is two banks...
  56. * - Called as part of 2nd phase DDR init.
  57. */
  58. void make_cs1_contiguous(void)
  59. {
  60. u32 size, a_add_low, a_add_high;
  61. size = get_sdr_cs_size(CS0);
  62. size >>= 25; /* divide by 32 MiB to find size to offset CS1 */
  63. a_add_high = (size & 3) << 8; /* set up low field */
  64. a_add_low = (size & 0x3C) >> 2; /* set up high field */
  65. writel((a_add_high | a_add_low), &sdrc_base->cs_cfg);
  66. }
  67. /*
  68. * get_sdr_cs_size -
  69. * - Get size of chip select 0/1
  70. */
  71. u32 get_sdr_cs_size(u32 cs)
  72. {
  73. u32 size;
  74. /* get ram size field */
  75. size = readl(&sdrc_base->cs[cs].mcfg) >> 8;
  76. size &= 0x3FF; /* remove unwanted bits */
  77. size <<= 21; /* multiply by 2 MiB to find size in MB */
  78. return size;
  79. }
  80. /*
  81. * get_sdr_cs_offset -
  82. * - Get offset of cs from cs0 start
  83. */
  84. u32 get_sdr_cs_offset(u32 cs)
  85. {
  86. u32 offset;
  87. if (!cs)
  88. return 0;
  89. offset = readl(&sdrc_base->cs_cfg);
  90. offset = (offset & 15) << 27 | (offset & 0x30) << 17;
  91. return offset;
  92. }
  93. /*
  94. * do_sdrc_init -
  95. * - Initialize the SDRAM for use.
  96. * - code called once in C-Stack only context for CS0 and a possible 2nd
  97. * time depending on memory configuration from stack+global context
  98. */
  99. void do_sdrc_init(u32 cs, u32 early)
  100. {
  101. struct sdrc_actim *sdrc_actim_base0, *sdrc_actim_base1;
  102. if (early) {
  103. /* reset sdrc controller */
  104. writel(SOFTRESET, &sdrc_base->sysconfig);
  105. wait_on_value(RESETDONE, RESETDONE, &sdrc_base->status,
  106. 12000000);
  107. writel(0, &sdrc_base->sysconfig);
  108. /* setup sdrc to ball mux */
  109. writel(SDRC_SHARING, &sdrc_base->sharing);
  110. /* Disable Power Down of CKE cuz of 1 CKE on combo part */
  111. writel(WAKEUPPROC | SRFRONRESET | PAGEPOLICY_HIGH,
  112. &sdrc_base->power);
  113. writel(ENADLL | DLLPHASE_90, &sdrc_base->dlla_ctrl);
  114. sdelay(0x20000);
  115. }
  116. /*
  117. * SDRC timings are set up by x-load or config header
  118. * We don't need to redo them here.
  119. * Older x-loads configure only CS0
  120. * configure CS1 to handle this ommission
  121. */
  122. if (cs) {
  123. sdrc_actim_base0 = (struct sdrc_actim *)SDRC_ACTIM_CTRL0_BASE;
  124. sdrc_actim_base1 = (struct sdrc_actim *)SDRC_ACTIM_CTRL1_BASE;
  125. writel(readl(&sdrc_base->cs[CS0].mcfg),
  126. &sdrc_base->cs[CS1].mcfg);
  127. writel(readl(&sdrc_base->cs[CS0].rfr_ctrl),
  128. &sdrc_base->cs[CS1].rfr_ctrl);
  129. writel(readl(&sdrc_actim_base0->ctrla),
  130. &sdrc_actim_base1->ctrla);
  131. writel(readl(&sdrc_actim_base0->ctrlb),
  132. &sdrc_actim_base1->ctrlb);
  133. writel(CMD_NOP, &sdrc_base->cs[cs].manual);
  134. writel(CMD_PRECHARGE, &sdrc_base->cs[cs].manual);
  135. writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
  136. writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
  137. writel(readl(&sdrc_base->cs[CS0].mr),
  138. &sdrc_base->cs[CS1].mr);
  139. }
  140. /*
  141. * Test ram in this bank
  142. * Disable if bad or not present
  143. */
  144. if (!mem_ok(cs))
  145. writel(0, &sdrc_base->cs[cs].mcfg);
  146. }
  147. /*
  148. * dram_init -
  149. * - Sets uboots idea of sdram size
  150. */
  151. int dram_init(void)
  152. {
  153. unsigned int size0 = 0, size1 = 0;
  154. size0 = get_sdr_cs_size(CS0);
  155. /*
  156. * If a second bank of DDR is attached to CS1 this is
  157. * where it can be started. Early init code will init
  158. * memory on CS0.
  159. */
  160. if ((sysinfo.mtype == DDR_COMBO) || (sysinfo.mtype == DDR_STACKED)) {
  161. do_sdrc_init(CS1, NOT_EARLY);
  162. make_cs1_contiguous();
  163. size1 = get_sdr_cs_size(CS1);
  164. }
  165. gd->ram_size = size0 + size1;
  166. return 0;
  167. }
  168. void dram_init_banksize (void)
  169. {
  170. unsigned int size0 = 0, size1 = 0;
  171. size0 = get_sdr_cs_size(CS0);
  172. size1 = get_sdr_cs_size(CS1);
  173. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  174. gd->bd->bi_dram[0].size = size0;
  175. gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
  176. gd->bd->bi_dram[1].size = size1;
  177. }
  178. /*
  179. * mem_init -
  180. * - Init the sdrc chip,
  181. * - Selects CS0 and CS1,
  182. */
  183. void mem_init(void)
  184. {
  185. /* only init up first bank here */
  186. do_sdrc_init(CS0, EARLY_INIT);
  187. }