icecube.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. #include <libfdt.h>
  31. #include <netdev.h>
  32. #if defined(CONFIG_LITE5200B)
  33. #include "mt46v32m16.h"
  34. #else
  35. # if defined(CONFIG_MPC5200_DDR)
  36. # include "mt46v16m16-75.h"
  37. # else
  38. #include "mt48lc16m16a2-75.h"
  39. # endif
  40. #endif
  41. #ifdef CONFIG_LITE5200B_PM
  42. /* u-boot part of low-power mode implementation */
  43. #define SAVED_ADDR (*(void **)0x00000000)
  44. #define PSC2_4 0x02
  45. void lite5200b_wakeup(void)
  46. {
  47. unsigned char wakeup_pin;
  48. void (*linux_wakeup)(void);
  49. /* check PSC2_4, if it's down "QT" is signaling we have a wakeup
  50. * from low power mode */
  51. *(vu_char *)MPC5XXX_WU_GPIO_ENABLE = PSC2_4;
  52. __asm__ volatile ("sync");
  53. wakeup_pin = *(vu_char *)MPC5XXX_WU_GPIO_DATA_I;
  54. if (wakeup_pin & PSC2_4)
  55. return;
  56. /* acknowledge to "QT"
  57. * by holding pin at 1 for 10 uS */
  58. *(vu_char *)MPC5XXX_WU_GPIO_DIR = PSC2_4;
  59. __asm__ volatile ("sync");
  60. *(vu_char *)MPC5XXX_WU_GPIO_DATA_O = PSC2_4;
  61. __asm__ volatile ("sync");
  62. udelay(10);
  63. /* put ram out of self-refresh */
  64. *(vu_long *)MPC5XXX_SDRAM_CTRL |= 0x80000000; /* mode_en */
  65. __asm__ volatile ("sync");
  66. *(vu_long *)MPC5XXX_SDRAM_CTRL |= 0x50000000; /* cke ref_en */
  67. __asm__ volatile ("sync");
  68. *(vu_long *)MPC5XXX_SDRAM_CTRL &= ~0x80000000; /* !mode_en */
  69. __asm__ volatile ("sync");
  70. udelay(10); /* wait a bit */
  71. /* jump back to linux kernel code */
  72. linux_wakeup = SAVED_ADDR;
  73. printf("\n\nLooks like we just woke, transferring control to 0x%08lx\n",
  74. linux_wakeup);
  75. linux_wakeup();
  76. }
  77. #else
  78. #define lite5200b_wakeup()
  79. #endif
  80. #ifndef CONFIG_SYS_RAMBOOT
  81. static void sdram_start (int hi_addr)
  82. {
  83. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  84. /* unlock mode register */
  85. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  86. __asm__ volatile ("sync");
  87. /* precharge all banks */
  88. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  89. __asm__ volatile ("sync");
  90. #if SDRAM_DDR
  91. /* set mode register: extended mode */
  92. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  93. __asm__ volatile ("sync");
  94. /* set mode register: reset DLL */
  95. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  96. __asm__ volatile ("sync");
  97. #endif
  98. /* precharge all banks */
  99. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  100. __asm__ volatile ("sync");
  101. /* auto refresh */
  102. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  103. __asm__ volatile ("sync");
  104. /* set mode register */
  105. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  106. __asm__ volatile ("sync");
  107. /* normal operation */
  108. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  109. __asm__ volatile ("sync");
  110. }
  111. #endif
  112. /*
  113. * ATTENTION: Although partially referenced initdram does NOT make real use
  114. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  115. * is something else than 0x00000000.
  116. */
  117. phys_size_t initdram (int board_type)
  118. {
  119. ulong dramsize = 0;
  120. ulong dramsize2 = 0;
  121. uint svr, pvr;
  122. #ifndef CONFIG_SYS_RAMBOOT
  123. ulong test1, test2;
  124. /* setup SDRAM chip selects */
  125. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  126. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  127. __asm__ volatile ("sync");
  128. /* setup config registers */
  129. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  130. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  131. __asm__ volatile ("sync");
  132. #if SDRAM_DDR
  133. /* set tap delay */
  134. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  135. __asm__ volatile ("sync");
  136. #endif
  137. /* find RAM size using SDRAM CS0 only */
  138. sdram_start(0);
  139. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  140. sdram_start(1);
  141. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  142. if (test1 > test2) {
  143. sdram_start(0);
  144. dramsize = test1;
  145. } else {
  146. dramsize = test2;
  147. }
  148. /* memory smaller than 1MB is impossible */
  149. if (dramsize < (1 << 20)) {
  150. dramsize = 0;
  151. }
  152. /* set SDRAM CS0 size according to the amount of RAM found */
  153. if (dramsize > 0) {
  154. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  155. } else {
  156. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  157. }
  158. /* let SDRAM CS1 start right after CS0 */
  159. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  160. /* find RAM size using SDRAM CS1 only */
  161. if (!dramsize)
  162. sdram_start(0);
  163. test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  164. if (!dramsize) {
  165. sdram_start(1);
  166. test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  167. }
  168. if (test1 > test2) {
  169. sdram_start(0);
  170. dramsize2 = test1;
  171. } else {
  172. dramsize2 = test2;
  173. }
  174. /* memory smaller than 1MB is impossible */
  175. if (dramsize2 < (1 << 20)) {
  176. dramsize2 = 0;
  177. }
  178. /* set SDRAM CS1 size according to the amount of RAM found */
  179. if (dramsize2 > 0) {
  180. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  181. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  182. } else {
  183. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  184. }
  185. #else /* CONFIG_SYS_RAMBOOT */
  186. /* retrieve size of memory connected to SDRAM CS0 */
  187. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  188. if (dramsize >= 0x13) {
  189. dramsize = (1 << (dramsize - 0x13)) << 20;
  190. } else {
  191. dramsize = 0;
  192. }
  193. /* retrieve size of memory connected to SDRAM CS1 */
  194. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  195. if (dramsize2 >= 0x13) {
  196. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  197. } else {
  198. dramsize2 = 0;
  199. }
  200. #endif /* CONFIG_SYS_RAMBOOT */
  201. /*
  202. * On MPC5200B we need to set the special configuration delay in the
  203. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  204. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  205. *
  206. * "The SDelay should be written to a value of 0x00000004. It is
  207. * required to account for changes caused by normal wafer processing
  208. * parameters."
  209. */
  210. svr = get_svr();
  211. pvr = get_pvr();
  212. if ((SVR_MJREV(svr) >= 2) &&
  213. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  214. *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
  215. __asm__ volatile ("sync");
  216. }
  217. lite5200b_wakeup();
  218. return dramsize + dramsize2;
  219. }
  220. int checkboard (void)
  221. {
  222. #if defined (CONFIG_LITE5200B)
  223. puts ("Board: Freescale Lite5200B\n");
  224. #else
  225. puts ("Board: Motorola MPC5200 (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. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  238. }
  239. void flash_afterinit(ulong size)
  240. {
  241. if (size == 0x800000) { /* adjust mapping */
  242. *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
  243. START_REG(CONFIG_SYS_BOOTCS_START | size);
  244. *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
  245. STOP_REG(CONFIG_SYS_BOOTCS_START | size, size);
  246. }
  247. }
  248. #ifdef CONFIG_PCI
  249. static struct pci_controller hose;
  250. extern void pci_mpc5xxx_init(struct pci_controller *);
  251. void pci_init_board(void)
  252. {
  253. pci_mpc5xxx_init(&hose);
  254. }
  255. #endif
  256. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  257. void init_ide_reset (void)
  258. {
  259. debug ("init_ide_reset\n");
  260. /* Configure PSC1_4 as GPIO output for ATA reset */
  261. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  262. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  263. /* Deassert reset */
  264. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  265. }
  266. void ide_set_reset (int idereset)
  267. {
  268. debug ("ide_reset(%d)\n", idereset);
  269. if (idereset) {
  270. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
  271. /* Make a delay. MPC5200 spec says 25 usec min */
  272. udelay(500000);
  273. } else {
  274. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  275. }
  276. }
  277. #endif
  278. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  279. void
  280. ft_board_setup(void *blob, bd_t *bd)
  281. {
  282. ft_cpu_setup(blob, bd);
  283. }
  284. #endif
  285. int board_eth_init(bd_t *bis)
  286. {
  287. cpu_eth_init(bis); /* Built in FEC comes first */
  288. return pci_eth_init(bis);
  289. }