jupiter.c 7.9 KB

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