icecube.c 8.6 KB

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