jupiter.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <mpc5xxx.h>
  12. #include <pci.h>
  13. #include <asm/processor.h>
  14. #include <libfdt.h>
  15. #define SDRAM_DDR 0
  16. #if 1
  17. /* Settings Icecube */
  18. #define SDRAM_MODE 0x00CD0000
  19. #define SDRAM_CONTROL 0x504F0000
  20. #define SDRAM_CONFIG1 0xD2322800
  21. #define SDRAM_CONFIG2 0x8AD70000
  22. #else
  23. /*Settings Jupiter UB 1.0.0 */
  24. #define SDRAM_MODE 0x008D0000
  25. #define SDRAM_CONTROL 0xD04F0000
  26. #define SDRAM_CONFIG1 0xf7277f00
  27. #define SDRAM_CONFIG2 0x88b70004
  28. #endif
  29. DECLARE_GLOBAL_DATA_PTR;
  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
  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
  62. /*
  63. * ATTENTION: Although partially referenced dram_init does NOT make real use
  64. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  65. * is something else than 0x00000000.
  66. */
  67. int dram_init(void)
  68. {
  69. ulong dramsize = 0;
  70. ulong dramsize2 = 0;
  71. uint svr, pvr;
  72. #ifndef CONFIG_SYS_RAMBOOT
  73. ulong test1, test2;
  74. /* setup SDRAM chip selects */
  75. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  76. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  77. __asm__ volatile ("sync");
  78. /* setup config registers */
  79. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  80. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  81. __asm__ volatile ("sync");
  82. #if SDRAM_DDR
  83. /* set tap delay */
  84. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  85. __asm__ volatile ("sync");
  86. #endif
  87. /* find RAM size using SDRAM CS0 only */
  88. sdram_start(0);
  89. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  90. sdram_start(1);
  91. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  92. if (test1 > test2) {
  93. sdram_start(0);
  94. dramsize = test1;
  95. } else {
  96. dramsize = test2;
  97. }
  98. /* memory smaller than 1MB is impossible */
  99. if (dramsize < (1 << 20)) {
  100. dramsize = 0;
  101. }
  102. /* set SDRAM CS0 size according to the amount of RAM found */
  103. if (dramsize > 0) {
  104. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  105. } else {
  106. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  107. }
  108. /* let SDRAM CS1 start right after CS0 */
  109. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  110. /* find RAM size using SDRAM CS1 only */
  111. if (!dramsize)
  112. sdram_start(0);
  113. test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  114. if (!dramsize) {
  115. sdram_start(1);
  116. test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  117. }
  118. if (test1 > test2) {
  119. sdram_start(0);
  120. dramsize2 = test1;
  121. } else {
  122. dramsize2 = test2;
  123. }
  124. /* memory smaller than 1MB is impossible */
  125. if (dramsize2 < (1 << 20)) {
  126. dramsize2 = 0;
  127. }
  128. /* set SDRAM CS1 size according to the amount of RAM found */
  129. if (dramsize2 > 0) {
  130. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  131. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  132. } else {
  133. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  134. }
  135. #else /* CONFIG_SYS_RAMBOOT */
  136. /* retrieve size of memory connected to SDRAM CS0 */
  137. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  138. if (dramsize >= 0x13) {
  139. dramsize = (1 << (dramsize - 0x13)) << 20;
  140. } else {
  141. dramsize = 0;
  142. }
  143. /* retrieve size of memory connected to SDRAM CS1 */
  144. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  145. if (dramsize2 >= 0x13) {
  146. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  147. } else {
  148. dramsize2 = 0;
  149. }
  150. #endif /* CONFIG_SYS_RAMBOOT */
  151. /*
  152. * On MPC5200B we need to set the special configuration delay in the
  153. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  154. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  155. *
  156. * "The SDelay should be written to a value of 0x00000004. It is
  157. * required to account for changes caused by normal wafer processing
  158. * parameters."
  159. */
  160. svr = get_svr();
  161. pvr = get_pvr();
  162. if ((SVR_MJREV(svr) >= 2) &&
  163. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  164. *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
  165. __asm__ volatile ("sync");
  166. }
  167. gd->ram_size = dramsize + dramsize2;
  168. return 0;
  169. }
  170. int checkboard (void)
  171. {
  172. puts ("Board: Sauter (Jupiter)\n");
  173. return 0;
  174. }
  175. void flash_preinit(void)
  176. {
  177. /*
  178. * Now, when we are in RAM, enable flash write
  179. * access for detection process.
  180. * Note that CS_BOOT cannot be cleared when
  181. * executing in flash.
  182. */
  183. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  184. }
  185. int board_early_init_r (void)
  186. {
  187. flash_preinit ();
  188. return 0;
  189. }
  190. void flash_afterinit(ulong size)
  191. {
  192. if (size == 0x1000000) { /* adjust mapping */
  193. *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
  194. START_REG(CONFIG_SYS_BOOTCS_START | size);
  195. *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
  196. STOP_REG(CONFIG_SYS_BOOTCS_START | size, size);
  197. }
  198. *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
  199. *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
  200. }
  201. int update_flash_size (int flash_size)
  202. {
  203. flash_afterinit (flash_size);
  204. return 0;
  205. }
  206. int board_early_init_f (void)
  207. {
  208. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  209. return 0;
  210. }
  211. #ifdef CONFIG_PCI
  212. static struct pci_controller hose;
  213. extern void pci_mpc5xxx_init(struct pci_controller *);
  214. void pci_init_board(void)
  215. {
  216. pci_mpc5xxx_init(&hose);
  217. }
  218. #endif
  219. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  220. void init_ide_reset (void)
  221. {
  222. debug ("init_ide_reset\n");
  223. /* Configure PSC1_4 as GPIO output for ATA reset */
  224. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  225. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  226. /* Deassert reset */
  227. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  228. }
  229. void ide_set_reset (int idereset)
  230. {
  231. debug ("ide_reset(%d)\n", idereset);
  232. if (idereset) {
  233. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
  234. /* Make a delay. MPC5200 spec says 25 usec min */
  235. udelay(500000);
  236. } else {
  237. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  238. }
  239. }
  240. #endif
  241. #ifdef CONFIG_OF_BOARD_SETUP
  242. int ft_board_setup(void *blob, bd_t *bd)
  243. {
  244. ft_cpu_setup(blob, bd);
  245. return 0;
  246. }
  247. #endif /* CONFIG_OF_BOARD_SETUP */