mem.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * (C) Copyright 2005-2007
  3. * Samsung Electronics,
  4. * Kyungmin Park <kyungmin.park@samsung.com>
  5. *
  6. * Derived from omap2420
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/arch/omap2420.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/bits.h>
  27. #include <asm/arch/mux.h>
  28. #include <asm/arch/mem.h>
  29. #include <asm/arch/clocks.h>
  30. #include <asm/arch/sys_proto.h>
  31. #include <asm/arch/sys_info.h>
  32. #include "mem.h"
  33. /************************************************************
  34. * sdelay() - simple spin loop. Will be constant time as
  35. * its generally used in 12MHz bypass conditions only. This
  36. * is necessary until timers are accessible.
  37. *
  38. * not inline to increase chances its in cache when called
  39. *************************************************************/
  40. void sdelay(unsigned long loops)
  41. {
  42. __asm__("1:\n" "subs %0, %1, #1\n"
  43. "bne 1b":"=r" (loops):"0"(loops));
  44. }
  45. /********************************************************************
  46. * prcm_init() - inits clocks for PRCM as defined in clocks.h
  47. * (config II default).
  48. * -- called from SRAM, or Flash (using temp SRAM stack).
  49. ********************************************************************/
  50. void prcm_init(void) { }
  51. /**************************************************************************
  52. * make_cs1_contiguous() - for es2 and above remap cs1 behind cs0 to allow
  53. * command line mem=xyz use all memory with out discontigious support
  54. * compiled in. Could do it at the ATAG, but there really is two banks...
  55. * Called as part of 2nd phase DDR init.
  56. **************************************************************************/
  57. void make_cs1_contiguous(void)
  58. {
  59. u32 size, a_add_low, a_add_high;
  60. size = get_sdr_cs_size(SDRC_CS0_OSET);
  61. size /= SZ_32M; /* find size to offset CS1 */
  62. a_add_high = (size & 3) << 8; /* set up low field */
  63. a_add_low = (size & 0x3C) >> 2; /* set up high field */
  64. __raw_writel((a_add_high | a_add_low), SDRC_CS_CFG);
  65. }
  66. /********************************************************
  67. * mem_ok() - test used to see if timings are correct
  68. * for a part. Helps in gussing which part
  69. * we are currently using.
  70. *******************************************************/
  71. u32 mem_ok(void)
  72. {
  73. u32 val1, val2;
  74. u32 pattern = 0x12345678;
  75. /* clear pos A */
  76. __raw_writel(0x0, OMAP2420_SDRC_CS0 + 0x400);
  77. /* pattern to pos B */
  78. __raw_writel(pattern, OMAP2420_SDRC_CS0);
  79. /* remove pattern off the bus */
  80. __raw_writel(0x0, OMAP2420_SDRC_CS0 + 4);
  81. /* get pos A value */
  82. val1 = __raw_readl(OMAP2420_SDRC_CS0 + 0x400);
  83. val2 = __raw_readl(OMAP2420_SDRC_CS0); /* get val2 */
  84. /* see if pos A value changed */
  85. if ((val1 != 0) || (val2 != pattern))
  86. return (0);
  87. else
  88. return (1);
  89. }
  90. /********************************************************
  91. * sdrc_init() - init the sdrc chip selects CS0 and CS1
  92. * - early init routines, called from flash or
  93. * SRAM.
  94. *******************************************************/
  95. void sdrc_init(void)
  96. {
  97. #define EARLY_INIT 1
  98. /* only init up first bank here */
  99. do_sdrc_init(SDRC_CS0_OSET, EARLY_INIT);
  100. }
  101. /*************************************************************************
  102. * do_sdrc_init(): initialize the SDRAM for use.
  103. * -called from low level code with stack only.
  104. * -code sets up SDRAM timing and muxing for 2422 or 2420.
  105. * -optimal settings can be placed here, or redone after i2c
  106. * inspection of board info
  107. *
  108. * This is a bit ugly, but should handle all memory moduels
  109. * used with the APOLLON. The first time though this code from s_init()
  110. * we configure the first chip select. Later on we come back and
  111. * will configure the 2nd chip select if it exists.
  112. *
  113. **************************************************************************/
  114. void do_sdrc_init(u32 offset, u32 early)
  115. {
  116. }
  117. /*****************************************************
  118. * gpmc_init(): init gpmc bus
  119. * Init GPMC for x16, MuxMode (SDRAM in x32).
  120. * This code can only be executed from SRAM or SDRAM.
  121. *****************************************************/
  122. void gpmc_init(void)
  123. {
  124. u32 mux = 0, mtype, mwidth, rev, tval;
  125. rev = get_cpu_rev();
  126. if (rev == CPU_2420_2422_ES1)
  127. tval = 1;
  128. else
  129. tval = 0; /* disable bit switched meaning */
  130. /* global settings */
  131. __raw_writel(0x10, GPMC_SYSCONFIG); /* smart idle */
  132. __raw_writel(0x0, GPMC_IRQENABLE); /* isr's sources masked */
  133. __raw_writel(tval, GPMC_TIMEOUT_CONTROL); /* timeout disable */
  134. #ifdef CONFIG_SYS_NAND_BOOT
  135. /* set nWP, disable limited addr */
  136. __raw_writel(0x001, GPMC_CONFIG);
  137. #else
  138. /* set nWP, disable limited addr */
  139. __raw_writel(0x111, GPMC_CONFIG);
  140. #endif
  141. /* discover bus connection from sysboot */
  142. if (is_gpmc_muxed() == GPMC_MUXED)
  143. mux = BIT9;
  144. mtype = get_gpmc0_type();
  145. mwidth = get_gpmc0_width();
  146. /* setup cs0 */
  147. __raw_writel(0x0, GPMC_CONFIG7_0); /* disable current map */
  148. sdelay(1000);
  149. #ifdef CONFIG_SYS_NOR_BOOT
  150. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_3, GPMC_CONFIG1_0);
  151. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_3, GPMC_CONFIG2_0);
  152. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_3, GPMC_CONFIG3_0);
  153. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_3, GPMC_CONFIG4_0);
  154. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_3, GPMC_CONFIG5_0);
  155. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_3, GPMC_CONFIG6_0);
  156. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_3, GPMC_CONFIG7_0);
  157. #else
  158. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_0 | mux | mtype | mwidth,
  159. GPMC_CONFIG1_0);
  160. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_0, GPMC_CONFIG2_0);
  161. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_0, GPMC_CONFIG3_0);
  162. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_0, GPMC_CONFIG4_0);
  163. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_0, GPMC_CONFIG5_0);
  164. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_0, GPMC_CONFIG6_0);
  165. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_0, GPMC_CONFIG7_0);
  166. #endif
  167. sdelay(2000);
  168. /* setup cs1 */
  169. __raw_writel(0, GPMC_CONFIG7_1); /* disable any mapping */
  170. sdelay(1000);
  171. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_1, GPMC_CONFIG1_1);
  172. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_1, GPMC_CONFIG2_1);
  173. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_1, GPMC_CONFIG3_1);
  174. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_1, GPMC_CONFIG4_1);
  175. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_1, GPMC_CONFIG5_1);
  176. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_1, GPMC_CONFIG6_1);
  177. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_1, GPMC_CONFIG7_1);
  178. sdelay(2000);
  179. /* setup cs2 */
  180. __raw_writel(0x0, GPMC_CONFIG7_2); /* disable current map */
  181. sdelay(1000);
  182. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_0 | mux | mtype | mwidth,
  183. GPMC_CONFIG1_2);
  184. /* It's same as cs 0 */
  185. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_0, GPMC_CONFIG2_2);
  186. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_0, GPMC_CONFIG3_2);
  187. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_0, GPMC_CONFIG4_2);
  188. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_0, GPMC_CONFIG5_2);
  189. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_0, GPMC_CONFIG6_2);
  190. #ifdef CONFIG_SYS_NOR_BOOT
  191. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_0, GPMC_CONFIG7_2);
  192. #else
  193. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_2, GPMC_CONFIG7_2);
  194. #endif
  195. #ifndef CONFIG_SYS_NOR_BOOT
  196. /* setup cs3 */
  197. __raw_writel(0, GPMC_CONFIG7_3); /* disable any mapping */
  198. sdelay(1000);
  199. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_3, GPMC_CONFIG1_3);
  200. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_3, GPMC_CONFIG2_3);
  201. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_3, GPMC_CONFIG3_3);
  202. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_3, GPMC_CONFIG4_3);
  203. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_3, GPMC_CONFIG5_3);
  204. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_3, GPMC_CONFIG6_3);
  205. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_3, GPMC_CONFIG7_3);
  206. #endif
  207. #ifndef ASYNC_NOR
  208. __raw_writew(0xaa, (APOLLON_CS3_BASE + 0xaaa));
  209. __raw_writew(0x55, (APOLLON_CS3_BASE + 0x554));
  210. __raw_writew(0xc0, (APOLLON_CS3_BASE | SYNC_NOR_VALUE));
  211. #endif
  212. sdelay(2000);
  213. }