mem.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*
  2. * (C) Copyright 2008
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * Author :
  6. * Manikandan Pillai <mani.pillai@ti.com>
  7. *
  8. * Initial Code from:
  9. * Richard Woodruff <r-woodruff2@ti.com>
  10. * Syed Mohammed Khasim <khasim@ti.com>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <asm/io.h>
  29. #include <asm/arch/mem.h>
  30. #include <asm/arch/sys_proto.h>
  31. #include <command.h>
  32. /*
  33. * Only One NAND allowed on board at a time.
  34. * The GPMC CS Base for the same
  35. */
  36. unsigned int boot_flash_base;
  37. unsigned int boot_flash_off;
  38. unsigned int boot_flash_sec;
  39. unsigned int boot_flash_type;
  40. volatile unsigned int boot_flash_env_addr;
  41. #if defined(CONFIG_CMD_NAND)
  42. static u32 gpmc_m_nand[GPMC_MAX_REG] = {
  43. M_NAND_GPMC_CONFIG1,
  44. M_NAND_GPMC_CONFIG2,
  45. M_NAND_GPMC_CONFIG3,
  46. M_NAND_GPMC_CONFIG4,
  47. M_NAND_GPMC_CONFIG5,
  48. M_NAND_GPMC_CONFIG6, 0
  49. };
  50. gpmc_csx_t *nand_cs_base;
  51. gpmc_t *gpmc_cfg_base;
  52. #if defined(CONFIG_ENV_IS_IN_NAND)
  53. #define GPMC_CS 0
  54. #else
  55. #define GPMC_CS 1
  56. #endif
  57. #endif
  58. #if defined(CONFIG_CMD_ONENAND)
  59. static u32 gpmc_onenand[GPMC_MAX_REG] = {
  60. ONENAND_GPMC_CONFIG1,
  61. ONENAND_GPMC_CONFIG2,
  62. ONENAND_GPMC_CONFIG3,
  63. ONENAND_GPMC_CONFIG4,
  64. ONENAND_GPMC_CONFIG5,
  65. ONENAND_GPMC_CONFIG6, 0
  66. };
  67. gpmc_csx_t *onenand_cs_base;
  68. #if defined(CONFIG_ENV_IS_IN_ONENAND)
  69. #define GPMC_CS 0
  70. #else
  71. #define GPMC_CS 1
  72. #endif
  73. #endif
  74. static sdrc_t *sdrc_base = (sdrc_t *)OMAP34XX_SDRC_BASE;
  75. /**************************************************************************
  76. * make_cs1_contiguous() - for es2 and above remap cs1 behind cs0 to allow
  77. * command line mem=xyz use all memory with out discontinuous support
  78. * compiled in. Could do it at the ATAG, but there really is two banks...
  79. * Called as part of 2nd phase DDR init.
  80. **************************************************************************/
  81. void make_cs1_contiguous(void)
  82. {
  83. u32 size, a_add_low, a_add_high;
  84. size = get_sdr_cs_size(CS0);
  85. size /= SZ_32M; /* find size to offset CS1 */
  86. a_add_high = (size & 3) << 8; /* set up low field */
  87. a_add_low = (size & 0x3C) >> 2; /* set up high field */
  88. writel((a_add_high | a_add_low), &sdrc_base->cs_cfg);
  89. }
  90. /********************************************************
  91. * mem_ok() - test used to see if timings are correct
  92. * for a part. Helps in guessing which part
  93. * we are currently using.
  94. *******************************************************/
  95. u32 mem_ok(u32 cs)
  96. {
  97. u32 val1, val2, addr;
  98. u32 pattern = 0x12345678;
  99. addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
  100. writel(0x0, addr + 0x400); /* clear pos A */
  101. writel(pattern, addr); /* pattern to pos B */
  102. writel(0x0, addr + 4); /* remove pattern off the bus */
  103. val1 = readl(addr + 0x400); /* get pos A value */
  104. val2 = readl(addr); /* get val2 */
  105. if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
  106. return 0;
  107. else
  108. return 1;
  109. }
  110. /********************************************************
  111. * sdrc_init() - init the sdrc chip selects CS0 and CS1
  112. * - early init routines, called from flash or
  113. * SRAM.
  114. *******************************************************/
  115. void sdrc_init(void)
  116. {
  117. /* only init up first bank here */
  118. do_sdrc_init(CS0, EARLY_INIT);
  119. }
  120. /*************************************************************************
  121. * do_sdrc_init(): initialize the SDRAM for use.
  122. * -code sets up SDRAM basic SDRC timings for CS0
  123. * -optimal settings can be placed here, or redone after i2c
  124. * inspection of board info
  125. *
  126. * - code called once in C-Stack only context for CS0 and a possible 2nd
  127. * time depending on memory configuration from stack+global context
  128. **************************************************************************/
  129. void do_sdrc_init(u32 cs, u32 early)
  130. {
  131. sdrc_actim_t *sdrc_actim_base;
  132. if(cs)
  133. sdrc_actim_base = (sdrc_actim_t *)SDRC_ACTIM_CTRL1_BASE;
  134. else
  135. sdrc_actim_base = (sdrc_actim_t *)SDRC_ACTIM_CTRL0_BASE;
  136. if (early) {
  137. /* reset sdrc controller */
  138. writel(SOFTRESET, &sdrc_base->sysconfig);
  139. wait_on_value(RESETDONE, RESETDONE, &sdrc_base->status,
  140. 12000000);
  141. writel(0, &sdrc_base->sysconfig);
  142. /* setup sdrc to ball mux */
  143. writel(SDP_SDRC_SHARING, &sdrc_base->sharing);
  144. /* Disable Power Down of CKE cuz of 1 CKE on combo part */
  145. writel(SRFRONRESET | PAGEPOLICY_HIGH, &sdrc_base->power);
  146. writel(ENADLL | DLLPHASE_90, &sdrc_base->dlla_ctrl);
  147. sdelay(0x20000);
  148. }
  149. writel(RASWIDTH_13BITS | CASWIDTH_10BITS | ADDRMUXLEGACY |
  150. RAMSIZE_128 | BANKALLOCATION | B32NOT16 | B32NOT16 |
  151. DEEPPD | DDR_SDRAM, &sdrc_base->cs[cs].mcfg);
  152. writel(ARCV | ARE_ARCV_1, &sdrc_base->cs[cs].rfr_ctrl);
  153. writel(V_ACTIMA_165, &sdrc_actim_base->ctrla);
  154. writel(V_ACTIMB_165, &sdrc_actim_base->ctrlb);
  155. writel(CMD_NOP, &sdrc_base ->cs[cs].manual);
  156. writel(CMD_PRECHARGE, &sdrc_base->cs[cs].manual);
  157. writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
  158. writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
  159. /*
  160. * CAS latency 3, Write Burst = Read Burst, Serial Mode,
  161. * Burst length = 4
  162. */
  163. writel(CASL3 | BURSTLENGTH4, &sdrc_base->cs[cs].mr);
  164. if (!mem_ok(cs))
  165. writel(0, &sdrc_base->cs[cs].mcfg);
  166. }
  167. void enable_gpmc_config(u32 *gpmc_config, gpmc_csx_t *gpmc_cs_base, u32 base,
  168. u32 size)
  169. {
  170. writel(0, &gpmc_cs_base->config7);
  171. sdelay(1000);
  172. /* Delay for settling */
  173. writel(gpmc_config[0], &gpmc_cs_base->config1);
  174. writel(gpmc_config[1], &gpmc_cs_base->config2);
  175. writel(gpmc_config[2], &gpmc_cs_base->config3);
  176. writel(gpmc_config[3], &gpmc_cs_base->config4);
  177. writel(gpmc_config[4], &gpmc_cs_base->config5);
  178. writel(gpmc_config[5], &gpmc_cs_base->config6);
  179. /* Enable the config */
  180. writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) |
  181. (1 << 6)), &gpmc_cs_base->config7);
  182. sdelay(2000);
  183. }
  184. /*****************************************************
  185. * gpmc_init(): init gpmc bus
  186. * Init GPMC for x16, MuxMode (SDRAM in x32).
  187. * This code can only be executed from SRAM or SDRAM.
  188. *****************************************************/
  189. void gpmc_init(void)
  190. {
  191. /* putting a blanket check on GPMC based on ZeBu for now */
  192. u32 *gpmc_config = NULL;
  193. gpmc_t *gpmc_base = (gpmc_t *)GPMC_BASE;
  194. gpmc_csx_t *gpmc_cs_base = (gpmc_csx_t *)GPMC_CONFIG_CS0_BASE;
  195. u32 base = 0;
  196. u32 size = 0;
  197. u32 f_off = CONFIG_SYS_MONITOR_LEN;
  198. u32 f_sec = 0;
  199. u32 config = 0;
  200. /* global settings */
  201. writel(0, &gpmc_base->irqenable); /* isr's sources masked */
  202. writel(0, &gpmc_base->timeout_control);/* timeout disable */
  203. config = readl(&gpmc_base->config);
  204. config &= (~0xf00);
  205. writel(config, &gpmc_base->config);
  206. /*
  207. * Disable the GPMC0 config set by ROM code
  208. * It conflicts with our MPDB (both at 0x08000000)
  209. */
  210. writel(0, &gpmc_cs_base->config7);
  211. sdelay(1000);
  212. #if defined(CONFIG_CMD_NAND) /* CS 0 */
  213. gpmc_config = gpmc_m_nand;
  214. gpmc_cfg_base = gpmc_base;
  215. nand_cs_base = (gpmc_csx_t *)(GPMC_CONFIG_CS0_BASE +
  216. (GPMC_CS * GPMC_CONFIG_WIDTH));
  217. base = PISMO1_NAND_BASE;
  218. size = PISMO1_NAND_SIZE;
  219. enable_gpmc_config(gpmc_config, nand_cs_base, base, size);
  220. #if defined(CONFIG_ENV_IS_IN_NAND)
  221. f_off = SMNAND_ENV_OFFSET;
  222. f_sec = SZ_128K;
  223. /* env setup */
  224. boot_flash_base = base;
  225. boot_flash_off = f_off;
  226. boot_flash_sec = f_sec;
  227. boot_flash_env_addr = f_off;
  228. #endif
  229. #endif
  230. #if defined(CONFIG_CMD_ONENAND)
  231. gpmc_config = gpmc_onenand;
  232. onenand_cs_base = (gpmc_csx_t *)(GPMC_CONFIG_CS0_BASE +
  233. (GPMC_CS * GPMC_CONFIG_WIDTH));
  234. base = PISMO1_ONEN_BASE;
  235. size = PISMO1_ONEN_SIZE;
  236. enable_gpmc_config(gpmc_config, onenand_cs_base, base, size);
  237. #if defined(CONFIG_ENV_IS_IN_ONENAND)
  238. f_off = ONENAND_ENV_OFFSET;
  239. f_sec = SZ_128K;
  240. /* env setup */
  241. boot_flash_base = base;
  242. boot_flash_off = f_off;
  243. boot_flash_sec = f_sec;
  244. boot_flash_env_addr = f_off;
  245. #endif
  246. #endif
  247. }