icecube.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * (C) Copyright 2003
  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 <pci.h>
  29. #if defined(CONFIG_MPC5200_DDR)
  30. #include "mt46v16m16-75.h"
  31. #else
  32. #include "mt48lc16m16a2-75.h"
  33. #endif
  34. #ifndef CFG_RAMBOOT
  35. static void sdram_start (int hi_addr)
  36. {
  37. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  38. /* unlock mode register */
  39. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  40. __asm__ volatile ("sync");
  41. /* precharge all banks */
  42. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  43. __asm__ volatile ("sync");
  44. #if SDRAM_DDR
  45. /* set mode register: extended mode */
  46. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  47. __asm__ volatile ("sync");
  48. /* set mode register: reset DLL */
  49. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  50. __asm__ volatile ("sync");
  51. #endif
  52. /* precharge all banks */
  53. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  54. __asm__ volatile ("sync");
  55. /* auto refresh */
  56. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  57. __asm__ volatile ("sync");
  58. /* set mode register */
  59. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  60. __asm__ volatile ("sync");
  61. /* normal operation */
  62. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  63. __asm__ volatile ("sync");
  64. }
  65. #endif
  66. /*
  67. * ATTENTION: Although partially referenced initdram does NOT make real use
  68. * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
  69. * is something else than 0x00000000.
  70. */
  71. #if defined(CONFIG_MPC5200)
  72. long int initdram (int board_type)
  73. {
  74. ulong dramsize = 0;
  75. ulong dramsize2 = 0;
  76. #ifndef CFG_RAMBOOT
  77. ulong test1, test2;
  78. /* setup SDRAM chip selects */
  79. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  80. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  81. __asm__ volatile ("sync");
  82. /* setup config registers */
  83. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  84. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  85. __asm__ volatile ("sync");
  86. #if SDRAM_DDR
  87. /* set tap delay */
  88. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  89. __asm__ volatile ("sync");
  90. #endif
  91. /* find RAM size using SDRAM CS0 only */
  92. sdram_start(0);
  93. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  94. sdram_start(1);
  95. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  96. if (test1 > test2) {
  97. sdram_start(0);
  98. dramsize = test1;
  99. } else {
  100. dramsize = test2;
  101. }
  102. /* memory smaller than 1MB is impossible */
  103. if (dramsize < (1 << 20)) {
  104. dramsize = 0;
  105. }
  106. /* set SDRAM CS0 size according to the amount of RAM found */
  107. if (dramsize > 0) {
  108. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  109. } else {
  110. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  111. }
  112. /* let SDRAM CS1 start right after CS0 */
  113. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  114. /* find RAM size using SDRAM CS1 only */
  115. sdram_start(0);
  116. test1 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
  117. sdram_start(1);
  118. test2 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
  119. if (test1 > test2) {
  120. sdram_start(0);
  121. dramsize2 = test1;
  122. } else {
  123. dramsize2 = test2;
  124. }
  125. /* memory smaller than 1MB is impossible */
  126. if (dramsize2 < (1 << 20)) {
  127. dramsize2 = 0;
  128. }
  129. /* set SDRAM CS1 size according to the amount of RAM found */
  130. if (dramsize2 > 0) {
  131. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  132. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  133. } else {
  134. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  135. }
  136. #else /* CFG_RAMBOOT */
  137. /* retrieve size of memory connected to SDRAM CS0 */
  138. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  139. if (dramsize >= 0x13) {
  140. dramsize = (1 << (dramsize - 0x13)) << 20;
  141. } else {
  142. dramsize = 0;
  143. }
  144. /* retrieve size of memory connected to SDRAM CS1 */
  145. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  146. if (dramsize2 >= 0x13) {
  147. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  148. } else {
  149. dramsize2 = 0;
  150. }
  151. #endif /* CFG_RAMBOOT */
  152. return dramsize + dramsize2;
  153. }
  154. #elif defined(CONFIG_MGT5100)
  155. long int initdram (int board_type)
  156. {
  157. ulong dramsize = 0;
  158. #ifndef CFG_RAMBOOT
  159. ulong test1, test2;
  160. /* setup and enable SDRAM chip selects */
  161. *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
  162. *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
  163. *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
  164. __asm__ volatile ("sync");
  165. /* setup config registers */
  166. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  167. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  168. /* address select register */
  169. *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
  170. __asm__ volatile ("sync");
  171. /* find RAM size */
  172. sdram_start(0);
  173. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  174. sdram_start(1);
  175. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
  176. if (test1 > test2) {
  177. sdram_start(0);
  178. dramsize = test1;
  179. } else {
  180. dramsize = test2;
  181. }
  182. /* set SDRAM end address according to size */
  183. *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
  184. #else /* CFG_RAMBOOT */
  185. /* Retrieve amount of SDRAM available */
  186. dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
  187. #endif /* CFG_RAMBOOT */
  188. return dramsize;
  189. }
  190. #else
  191. #error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
  192. #endif
  193. int checkboard (void)
  194. {
  195. #if defined(CONFIG_MPC5200)
  196. puts ("Board: Motorola MPC5200 (IceCube)\n");
  197. #elif defined(CONFIG_MGT5100)
  198. puts ("Board: Motorola MGT5100 (IceCube)\n");
  199. #endif
  200. return 0;
  201. }
  202. void flash_preinit(void)
  203. {
  204. /*
  205. * Now, when we are in RAM, enable flash write
  206. * access for detection process.
  207. * Note that CS_BOOT cannot be cleared when
  208. * executing in flash.
  209. */
  210. #if defined(CONFIG_MGT5100)
  211. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
  212. *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
  213. #endif
  214. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  215. }
  216. void flash_afterinit(ulong size)
  217. {
  218. if (size == 0x800000) { /* adjust mapping */
  219. *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
  220. START_REG(CFG_BOOTCS_START | size);
  221. *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
  222. STOP_REG(CFG_BOOTCS_START | size, size);
  223. }
  224. }
  225. #ifdef CONFIG_PCI
  226. static struct pci_controller hose;
  227. extern void pci_mpc5xxx_init(struct pci_controller *);
  228. void pci_init_board(void)
  229. {
  230. pci_mpc5xxx_init(&hose);
  231. }
  232. #endif
  233. #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
  234. #define GPIO_PSC1_4 0x01000000UL
  235. void init_ide_reset (void)
  236. {
  237. debug ("init_ide_reset\n");
  238. /* Configure PSC1_4 as GPIO output for ATA reset */
  239. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  240. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  241. }
  242. void ide_set_reset (int idereset)
  243. {
  244. debug ("ide_reset(%d)\n", idereset);
  245. if (idereset) {
  246. *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
  247. } else {
  248. *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
  249. }
  250. }
  251. #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */