v38b.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 <net.h>
  29. #include <asm/processor.h>
  30. #ifndef CONFIG_SYS_RAMBOOT
  31. static void sdram_start(int hi_addr)
  32. {
  33. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  34. /* unlock mode register */
  35. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  36. __asm__ volatile ("sync");
  37. /* precharge all banks */
  38. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  39. __asm__ volatile ("sync");
  40. #if SDRAM_DDR
  41. /* set mode register: extended mode */
  42. *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  43. __asm__ volatile ("sync");
  44. /* set mode register: reset DLL */
  45. *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  46. __asm__ volatile ("sync");
  47. #endif /* SDRAM_DDR */
  48. /* precharge all banks */
  49. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  50. __asm__ volatile ("sync");
  51. /* auto refresh */
  52. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  53. __asm__ volatile ("sync");
  54. /* set mode register */
  55. *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  56. __asm__ volatile ("sync");
  57. /* normal operation */
  58. *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  59. __asm__ volatile ("sync");
  60. }
  61. #endif /* !CONFIG_SYS_RAMBOOT */
  62. phys_size_t initdram(int board_type)
  63. {
  64. ulong dramsize = 0;
  65. ulong dramsize2 = 0;
  66. uint svr, pvr;
  67. #ifndef CONFIG_SYS_RAMBOOT
  68. ulong test1, test2;
  69. /* setup SDRAM chip selects */
  70. *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
  71. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
  72. __asm__ volatile ("sync");
  73. /* setup config registers */
  74. *(vu_long *) MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  75. *(vu_long *) MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  76. __asm__ volatile ("sync");
  77. #if SDRAM_DDR
  78. /* set tap delay */
  79. *(vu_long *) MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  80. __asm__ volatile ("sync");
  81. #endif /* SDRAM_DDR */
  82. /* find RAM size using SDRAM CS0 only */
  83. sdram_start(0);
  84. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  85. sdram_start(1);
  86. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  87. if (test1 > test2) {
  88. sdram_start(0);
  89. dramsize = test1;
  90. } else
  91. dramsize = test2;
  92. /* memory smaller than 1MB is impossible */
  93. if (dramsize < (1 << 20))
  94. dramsize = 0;
  95. /* set SDRAM CS0 size according to the amount of RAM found */
  96. if (dramsize > 0)
  97. *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  98. else
  99. *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  100. /* let SDRAM CS1 start right after CS0 */
  101. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  102. /* find RAM size using SDRAM CS1 only */
  103. if (!dramsize)
  104. sdram_start(0);
  105. test2 = test1 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  106. if (!dramsize) {
  107. sdram_start(1);
  108. test2 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  109. }
  110. if (test1 > test2) {
  111. sdram_start(0);
  112. dramsize2 = test1;
  113. } else
  114. dramsize2 = test2;
  115. /* memory smaller than 1MB is impossible */
  116. if (dramsize2 < (1 << 20))
  117. dramsize2 = 0;
  118. /* set SDRAM CS1 size according to the amount of RAM found */
  119. if (dramsize2 > 0)
  120. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize
  121. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  122. else
  123. *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  124. #else /* CONFIG_SYS_RAMBOOT */
  125. /* retrieve size of memory connected to SDRAM CS0 */
  126. dramsize = *(vu_long *) MPC5XXX_SDRAM_CS0CFG & 0xFF;
  127. if (dramsize >= 0x13)
  128. dramsize = (1 << (dramsize - 0x13)) << 20;
  129. else
  130. dramsize = 0;
  131. /* retrieve size of memory connected to SDRAM CS1 */
  132. dramsize2 = *(vu_long *) MPC5XXX_SDRAM_CS1CFG & 0xFF;
  133. if (dramsize2 >= 0x13)
  134. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  135. else
  136. dramsize2 = 0;
  137. #endif /* CONFIG_SYS_RAMBOOT */
  138. /*
  139. * On MPC5200B we need to set the special configuration delay in the
  140. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  141. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  142. *
  143. * "The SDelay should be written to a value of 0x00000004. It is
  144. * required to account for changes caused by normal wafer processing
  145. * parameters."
  146. */
  147. svr = get_svr();
  148. pvr = get_pvr();
  149. if ((SVR_MJREV(svr) >= 2) &&
  150. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  151. *(vu_long *) MPC5XXX_SDRAM_SDELAY = 0x04;
  152. __asm__ volatile ("sync");
  153. }
  154. return dramsize + dramsize2;
  155. }
  156. int checkboard (void)
  157. {
  158. puts("Board: MarelV38B\n");
  159. return 0;
  160. }
  161. int board_early_init_f(void)
  162. {
  163. #ifdef CONFIG_HW_WATCHDOG
  164. /*
  165. * Enable and configure the direction (output) of PSC3_9 - watchdog
  166. * reset input. Refer to 7.3.2.2.[1,3,4] of the MPC5200B User's
  167. * Manual.
  168. */
  169. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC3_9;
  170. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC3_9;
  171. #endif /* CONFIG_HW_WATCHDOG */
  172. return 0;
  173. }
  174. int board_early_init_r(void)
  175. {
  176. /*
  177. * Now, when we are in RAM, enable flash write access for the
  178. * detection process. Note that CS_BOOT cannot be cleared when
  179. * executing in flash.
  180. */
  181. *(vu_long *) MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  182. /*
  183. * Enable GPIO_WKUP_7 to "read the status of the actual power
  184. * situation". Default direction is input, so no need to set it
  185. * explicitly.
  186. */
  187. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_WKUP_7;
  188. return 0;
  189. }
  190. extern void board_get_enetaddr(uchar *enetaddr);
  191. int misc_init_r(void)
  192. {
  193. uchar enetaddr[6];
  194. if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
  195. board_get_enetaddr(enetaddr);
  196. eth_setenv_enetaddr("ethaddr", enetaddr);
  197. }
  198. return 0;
  199. }
  200. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  201. void init_ide_reset(void)
  202. {
  203. debug("init_ide_reset\n");
  204. /* Configure PSC1_4 as GPIO output for ATA reset */
  205. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  206. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  207. /* Deassert reset */
  208. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  209. }
  210. void ide_set_reset(int idereset)
  211. {
  212. debug("ide_reset(%d)\n", idereset);
  213. if (idereset) {
  214. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
  215. /* Make a delay. MPC5200 spec says 25 usec min */
  216. udelay(500000);
  217. } else
  218. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  219. }
  220. #endif
  221. #ifdef CONFIG_HW_WATCHDOG
  222. void hw_watchdog_reset(void)
  223. {
  224. /*
  225. * MarelV38B has a TPS3705 watchdog. Spec says that to kick the dog
  226. * we need a positive or negative transition on WDI i.e., our PSC3_9.
  227. */
  228. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O ^= GPIO_PSC3_9;
  229. }
  230. #endif /* CONFIG_HW_WATCHDOG */