v38b.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * (C) Copyright 2003-2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2004
  6. * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <mpc5xxx.h>
  28. #include <asm/processor.h>
  29. #ifndef CFG_RAMBOOT
  30. static void sdram_start(int hi_addr)
  31. {
  32. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  33. /* unlock mode register */
  34. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  35. __asm__ volatile ("sync");
  36. /* precharge all banks */
  37. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  38. __asm__ volatile ("sync");
  39. #if SDRAM_DDR
  40. /* set mode register: extended mode */
  41. *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  42. __asm__ volatile ("sync");
  43. /* set mode register: reset DLL */
  44. *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  45. __asm__ volatile ("sync");
  46. #endif /* SDRAM_DDR */
  47. /* precharge all banks */
  48. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  49. __asm__ volatile ("sync");
  50. /* auto refresh */
  51. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  52. __asm__ volatile ("sync");
  53. /* set mode register */
  54. *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  55. __asm__ volatile ("sync");
  56. /* normal operation */
  57. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  58. __asm__ volatile ("sync");
  59. }
  60. #endif /* !CFG_RAMBOOT */
  61. long int initdram(int board_type)
  62. {
  63. ulong dramsize = 0;
  64. ulong dramsize2 = 0;
  65. uint svr, pvr;
  66. #ifndef CFG_RAMBOOT
  67. ulong test1, test2;
  68. /* setup SDRAM chip selects */
  69. *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
  70. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
  71. __asm__ volatile ("sync");
  72. /* setup config registers */
  73. *(vu_long *) MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  74. *(vu_long *) MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  75. __asm__ volatile ("sync");
  76. #if SDRAM_DDR
  77. /* set tap delay */
  78. *(vu_long *) MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  79. __asm__ volatile ("sync");
  80. #endif /* SDRAM_DDR */
  81. /* find RAM size using SDRAM CS0 only */
  82. sdram_start(0);
  83. test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  84. sdram_start(1);
  85. test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  86. if (test1 > test2) {
  87. sdram_start(0);
  88. dramsize = test1;
  89. } else
  90. dramsize = test2;
  91. /* memory smaller than 1MB is impossible */
  92. if (dramsize < (1 << 20))
  93. dramsize = 0;
  94. /* set SDRAM CS0 size according to the amount of RAM found */
  95. if (dramsize > 0)
  96. *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  97. else
  98. *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  99. /* let SDRAM CS1 start right after CS0 */
  100. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  101. /* find RAM size using SDRAM CS1 only */
  102. if (!dramsize)
  103. sdram_start(0);
  104. test2 = test1 = get_ram_size((long *) (CFG_SDRAM_BASE + dramsize), 0x80000000);
  105. if (!dramsize) {
  106. sdram_start(1);
  107. test2 = get_ram_size((long *) (CFG_SDRAM_BASE + dramsize), 0x80000000);
  108. }
  109. if (test1 > test2) {
  110. sdram_start(0);
  111. dramsize2 = test1;
  112. } else
  113. dramsize2 = test2;
  114. /* memory smaller than 1MB is impossible */
  115. if (dramsize2 < (1 << 20))
  116. dramsize2 = 0;
  117. /* set SDRAM CS1 size according to the amount of RAM found */
  118. if (dramsize2 > 0)
  119. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize
  120. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  121. else
  122. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  123. #else /* CFG_RAMBOOT */
  124. /* retrieve size of memory connected to SDRAM CS0 */
  125. dramsize = *(vu_long *) MPC5XXX_SDRAM_CS0CFG & 0xFF;
  126. if (dramsize >= 0x13)
  127. dramsize = (1 << (dramsize - 0x13)) << 20;
  128. else
  129. dramsize = 0;
  130. /* retrieve size of memory connected to SDRAM CS1 */
  131. dramsize2 = *(vu_long *) MPC5XXX_SDRAM_CS1CFG & 0xFF;
  132. if (dramsize2 >= 0x13)
  133. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  134. else
  135. dramsize2 = 0;
  136. #endif /* CFG_RAMBOOT */
  137. /*
  138. * On MPC5200B we need to set the special configuration delay in the
  139. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  140. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  141. *
  142. * "The SDelay should be written to a value of 0x00000004. It is
  143. * required to account for changes caused by normal wafer processing
  144. * parameters."
  145. */
  146. svr = get_svr();
  147. pvr = get_pvr();
  148. if ((SVR_MJREV(svr) >= 2) &&
  149. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  150. *(vu_long *) MPC5XXX_SDRAM_SDELAY = 0x04;
  151. __asm__ volatile ("sync");
  152. }
  153. return dramsize + dramsize2;
  154. }
  155. int checkboard (void)
  156. {
  157. puts("Board: MarelV38B\n");
  158. return 0;
  159. }
  160. int board_early_init_r(void)
  161. {
  162. /*
  163. * Now, when we are in RAM, enable flash write access for the
  164. * detection process. Note that CS_BOOT cannot be cleared when
  165. * executing in flash.
  166. */
  167. *(vu_long *) MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  168. #ifdef CONFIG_HW_WATCHDOG
  169. /*
  170. * Enable and configure the direction (output) of PSC3_9 - watchdog
  171. * reset input. Refer to 7.3.2.2.[1,3,4] of the MPC5200B User's
  172. * Manual.
  173. */
  174. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC3_9;
  175. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC3_9;
  176. #endif /* CONFIG_HW_WATCHDOG */
  177. /*
  178. * Enable GPIO_WKUP_7 to "read the status of the actual power
  179. * situation". Default direction is input, so no need to set it
  180. * explicitly.
  181. */
  182. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_WKUP_7;
  183. return 0;
  184. }
  185. #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
  186. void init_ide_reset(void)
  187. {
  188. debug("init_ide_reset\n");
  189. /* Configure PSC1_4 as GPIO output for ATA reset */
  190. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  191. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  192. /* Deassert reset */
  193. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  194. }
  195. void ide_set_reset(int idereset)
  196. {
  197. debug("ide_reset(%d)\n", idereset);
  198. if (idereset) {
  199. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
  200. /* Make a delay. MPC5200 spec says 25 usec min */
  201. udelay(500000);
  202. } else
  203. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  204. }
  205. #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
  206. #ifdef CONFIG_HW_WATCHDOG
  207. void hw_watchdog_reset(void)
  208. {
  209. /*
  210. * MarelV38B has a TPS3705 watchdog. Spec says that to kick the dog
  211. * we need a positive or negative transition on WDI i.e., our PSC3_9.
  212. */
  213. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O ^= GPIO_PSC3_9;
  214. }
  215. #endif /* CONFIG_HW_WATCHDOG */