mem.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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__ volatile ("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). Called from SRAM, or Flash (using temp SRAM stack).
  48. *****************************************************************************/
  49. void prcm_init(void)
  50. {
  51. }
  52. /**************************************************************************
  53. * make_cs1_contiguous() - for es2 and above remap cs1 behind cs0 to allow
  54. * command line mem=xyz use all memory with out discontigious support
  55. * compiled in. 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(SDRC_CS0_OSET);
  62. size /= SZ_32M; /* 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. __raw_writel((a_add_high | a_add_low), SDRC_CS_CFG);
  66. }
  67. /********************************************************
  68. * mem_ok() - test used to see if timings are correct
  69. * for a part. Helps in gussing which part
  70. * we are currently using.
  71. *******************************************************/
  72. u32 mem_ok(void)
  73. {
  74. u32 val1, val2;
  75. u32 pattern = 0x12345678;
  76. __raw_writel(0x0, OMAP2420_SDRC_CS0 + 0x400); /* clear pos A */
  77. __raw_writel(pattern, OMAP2420_SDRC_CS0); /* pattern to pos B */
  78. __raw_writel(0x0, OMAP2420_SDRC_CS0 + 4); /* remove pattern off the bus */
  79. val1 = __raw_readl(OMAP2420_SDRC_CS0 + 0x400); /* get pos A value */
  80. val2 = __raw_readl(OMAP2420_SDRC_CS0); /* get val2 */
  81. if ((val1 != 0) || (val2 != pattern)) /* see if pos A value changed */
  82. return (0);
  83. else
  84. return (1);
  85. }
  86. /********************************************************
  87. * sdrc_init() - init the sdrc chip selects CS0 and CS1
  88. * - early init routines, called from flash or
  89. * SRAM.
  90. *******************************************************/
  91. void sdrc_init(void)
  92. {
  93. #define EARLY_INIT 1
  94. /* only init up first bank here */
  95. do_sdrc_init(SDRC_CS0_OSET, EARLY_INIT);
  96. }
  97. /*************************************************************************
  98. * do_sdrc_init(): initialize the SDRAM for use.
  99. * -called from low level code with stack only.
  100. * -code sets up SDRAM timing and muxing for 2422 or 2420.
  101. * -optimal settings can be placed here, or redone after i2c
  102. * inspection of board info
  103. *
  104. * This is a bit ugly, but should handle all memory moduels
  105. * used with the APOLLON. The first time though this code from s_init()
  106. * we configure the first chip select. Later on we come back and
  107. * will configure the 2nd chip select if it exists.
  108. *
  109. **************************************************************************/
  110. void do_sdrc_init(u32 offset, u32 early)
  111. {
  112. }
  113. /*****************************************************
  114. * gpmc_init(): init gpmc bus
  115. * Init GPMC for x16, MuxMode (SDRAM in x32).
  116. * This code can only be executed from SRAM or SDRAM.
  117. *****************************************************/
  118. void gpmc_init(void)
  119. {
  120. u32 mux = 0, mtype, mwidth, rev, tval;
  121. rev = get_cpu_rev();
  122. if (rev == CPU_2420_2422_ES1)
  123. tval = 1;
  124. else
  125. tval = 0; /* disable bit switched meaning */
  126. /* global settings */
  127. __raw_writel(0x10, GPMC_SYSCONFIG); /* smart idle */
  128. __raw_writel(0x0, GPMC_IRQENABLE); /* isr's sources masked */
  129. __raw_writel(tval, GPMC_TIMEOUT_CONTROL); /* timeout disable */
  130. #ifdef CFG_NAND_BOOT
  131. __raw_writel(0x001, GPMC_CONFIG); /* set nWP, disable limited addr */
  132. #else
  133. __raw_writel(0x111, GPMC_CONFIG); /* set nWP, disable limited addr */
  134. #endif
  135. /* discover bus connection from sysboot */
  136. if (is_gpmc_muxed() == GPMC_MUXED)
  137. mux = BIT9;
  138. mtype = get_gpmc0_type();
  139. mwidth = get_gpmc0_width();
  140. /* setup cs0 */
  141. __raw_writel(0x0, GPMC_CONFIG7_0); /* disable current map */
  142. sdelay(1000);
  143. #ifdef CFG_NOR_BOOT
  144. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_3, GPMC_CONFIG1_0);
  145. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_3, GPMC_CONFIG2_0);
  146. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_3, GPMC_CONFIG3_0);
  147. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_3, GPMC_CONFIG4_0);
  148. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_3, GPMC_CONFIG5_0);
  149. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_3, GPMC_CONFIG6_0);
  150. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_3, GPMC_CONFIG7_0); #else
  151. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_0 | mux | mtype | mwidth,
  152. GPMC_CONFIG1_0);
  153. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_0, GPMC_CONFIG2_0);
  154. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_0, GPMC_CONFIG3_0);
  155. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_0, GPMC_CONFIG4_0);
  156. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_0, GPMC_CONFIG5_0);
  157. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_0, GPMC_CONFIG6_0);
  158. /* enable new mapping */
  159. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_0, GPMC_CONFIG7_0);
  160. #endif
  161. sdelay(2000);
  162. /* setup cs1 */
  163. __raw_writel(0, GPMC_CONFIG7_1); /* disable any mapping */
  164. sdelay(1000);
  165. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_1, GPMC_CONFIG1_1);
  166. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_1, GPMC_CONFIG2_1);
  167. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_1, GPMC_CONFIG3_1);
  168. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_1, GPMC_CONFIG4_1);
  169. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_1, GPMC_CONFIG5_1);
  170. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_1, GPMC_CONFIG6_1);
  171. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_1, GPMC_CONFIG7_1);
  172. sdelay(2000);
  173. /* setup cs2 */
  174. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_0 | mux | mtype | mwidth,
  175. GPMC_CONFIG1_2);
  176. /* It's same as cs 0 */
  177. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_0, GPMC_CONFIG2_2);
  178. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_0, GPMC_CONFIG3_2);
  179. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_0, GPMC_CONFIG4_2);
  180. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_0, GPMC_CONFIG5_2);
  181. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_0, GPMC_CONFIG6_2);
  182. #ifdef CFG_NOR_BOOT
  183. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_0, GPMC_CONFIG7_2);
  184. #else
  185. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_2, GPMC_CONFIG7_2);
  186. #endif
  187. #ifndef CFG_NOR_BOOT
  188. /* setup cs3 */
  189. __raw_writel(0, GPMC_CONFIG7_3); /* disable any mapping */
  190. sdelay(1000);
  191. __raw_writel(APOLLON_24XX_GPMC_CONFIG1_3, GPMC_CONFIG1_3);
  192. __raw_writel(APOLLON_24XX_GPMC_CONFIG2_3, GPMC_CONFIG2_3);
  193. __raw_writel(APOLLON_24XX_GPMC_CONFIG3_3, GPMC_CONFIG3_3);
  194. __raw_writel(APOLLON_24XX_GPMC_CONFIG4_3, GPMC_CONFIG4_3);
  195. __raw_writel(APOLLON_24XX_GPMC_CONFIG5_3, GPMC_CONFIG5_3);
  196. __raw_writel(APOLLON_24XX_GPMC_CONFIG6_3, GPMC_CONFIG6_3);
  197. __raw_writel(APOLLON_24XX_GPMC_CONFIG7_3, GPMC_CONFIG7_3);
  198. #endif
  199. #ifndef ASYNC_NOR
  200. __raw_writew(0xaa, (APOLLON_CS3_BASE + 0xaaa));
  201. __raw_writew(0x55, (APOLLON_CS3_BASE + 0x554));
  202. __raw_writew(0xc0, (APOLLON_CS3_BASE | SYNC_NOR_VALUE));
  203. #endif
  204. sdelay(2000);
  205. }