mem.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. struct gpmc *gpmc_cfg;
  42. #if defined(CONFIG_CMD_NAND)
  43. static const u32 gpmc_m_nand[GPMC_MAX_REG] = {
  44. M_NAND_GPMC_CONFIG1,
  45. M_NAND_GPMC_CONFIG2,
  46. M_NAND_GPMC_CONFIG3,
  47. M_NAND_GPMC_CONFIG4,
  48. M_NAND_GPMC_CONFIG5,
  49. M_NAND_GPMC_CONFIG6, 0
  50. };
  51. #if defined(CONFIG_ENV_IS_IN_NAND)
  52. #define GPMC_CS 0
  53. #else
  54. #define GPMC_CS 1
  55. #endif
  56. #endif
  57. #if defined(CONFIG_CMD_ONENAND)
  58. static const u32 gpmc_onenand[GPMC_MAX_REG] = {
  59. ONENAND_GPMC_CONFIG1,
  60. ONENAND_GPMC_CONFIG2,
  61. ONENAND_GPMC_CONFIG3,
  62. ONENAND_GPMC_CONFIG4,
  63. ONENAND_GPMC_CONFIG5,
  64. ONENAND_GPMC_CONFIG6, 0
  65. };
  66. #if defined(CONFIG_ENV_IS_IN_ONENAND)
  67. #define GPMC_CS 0
  68. #else
  69. #define GPMC_CS 1
  70. #endif
  71. #endif
  72. /********************************************************
  73. * mem_ok() - test used to see if timings are correct
  74. * for a part. Helps in guessing which part
  75. * we are currently using.
  76. *******************************************************/
  77. u32 mem_ok(u32 cs)
  78. {
  79. u32 val1, val2, addr;
  80. u32 pattern = 0x12345678;
  81. addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
  82. writel(0x0, addr + 0x400); /* clear pos A */
  83. writel(pattern, addr); /* pattern to pos B */
  84. writel(0x0, addr + 4); /* remove pattern off the bus */
  85. val1 = readl(addr + 0x400); /* get pos A value */
  86. val2 = readl(addr); /* get val2 */
  87. if ((val1 != 0) || (val2 != pattern)) /* see if pos A val changed */
  88. return 0;
  89. else
  90. return 1;
  91. }
  92. void enable_gpmc_cs_config(const u32 *gpmc_config, struct gpmc_cs *cs, u32 base,
  93. u32 size)
  94. {
  95. writel(0, &cs->config7);
  96. sdelay(1000);
  97. /* Delay for settling */
  98. writel(gpmc_config[0], &cs->config1);
  99. writel(gpmc_config[1], &cs->config2);
  100. writel(gpmc_config[2], &cs->config3);
  101. writel(gpmc_config[3], &cs->config4);
  102. writel(gpmc_config[4], &cs->config5);
  103. writel(gpmc_config[5], &cs->config6);
  104. /* Enable the config */
  105. writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) |
  106. (1 << 6)), &cs->config7);
  107. sdelay(2000);
  108. }
  109. /*****************************************************
  110. * gpmc_init(): init gpmc bus
  111. * Init GPMC for x16, MuxMode (SDRAM in x32).
  112. * This code can only be executed from SRAM or SDRAM.
  113. *****************************************************/
  114. void gpmc_init(void)
  115. {
  116. /* putting a blanket check on GPMC based on ZeBu for now */
  117. gpmc_cfg = (struct gpmc *)GPMC_BASE;
  118. #if defined(CONFIG_CMD_NAND) || defined(CONFIG_CMD_ONENAND)
  119. const u32 *gpmc_config = NULL;
  120. u32 base = 0;
  121. u32 size = 0;
  122. #if defined(CONFIG_ENV_IS_IN_NAND) || defined(CONFIG_ENV_IS_IN_ONENAND)
  123. u32 f_off = CONFIG_SYS_MONITOR_LEN;
  124. u32 f_sec = 0;
  125. #endif
  126. #endif
  127. u32 config = 0;
  128. /* global settings */
  129. writel(0, &gpmc_cfg->irqenable); /* isr's sources masked */
  130. writel(0, &gpmc_cfg->timeout_control);/* timeout disable */
  131. config = readl(&gpmc_cfg->config);
  132. config &= (~0xf00);
  133. writel(config, &gpmc_cfg->config);
  134. /*
  135. * Disable the GPMC0 config set by ROM code
  136. * It conflicts with our MPDB (both at 0x08000000)
  137. */
  138. writel(0, &gpmc_cfg->cs[0].config7);
  139. sdelay(1000);
  140. #if defined(CONFIG_CMD_NAND) /* CS 0 */
  141. gpmc_config = gpmc_m_nand;
  142. base = PISMO1_NAND_BASE;
  143. size = PISMO1_NAND_SIZE;
  144. enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size);
  145. #if defined(CONFIG_ENV_IS_IN_NAND)
  146. f_off = SMNAND_ENV_OFFSET;
  147. f_sec = (128 << 10); /* 128 KiB */
  148. /* env setup */
  149. boot_flash_base = base;
  150. boot_flash_off = f_off;
  151. boot_flash_sec = f_sec;
  152. boot_flash_env_addr = f_off;
  153. #endif
  154. #endif
  155. #if defined(CONFIG_CMD_ONENAND)
  156. gpmc_config = gpmc_onenand;
  157. base = PISMO1_ONEN_BASE;
  158. size = PISMO1_ONEN_SIZE;
  159. enable_gpmc_cs_config(gpmc_config, &gpmc_cfg->cs[0], base, size);
  160. #if defined(CONFIG_ENV_IS_IN_ONENAND)
  161. f_off = ONENAND_ENV_OFFSET;
  162. f_sec = (128 << 10); /* 128 KiB */
  163. /* env setup */
  164. boot_flash_base = base;
  165. boot_flash_off = f_off;
  166. boot_flash_sec = f_sec;
  167. boot_flash_env_addr = f_off;
  168. #endif
  169. #endif
  170. }