pm520.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * (C) Copyright 2003-2004
  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 <netdev.h>
  30. #if defined(CONFIG_MPC5200_DDR)
  31. #include "mt46v16m16-75.h"
  32. #else
  33. #include "mt48lc16m16a2-75.h"
  34. #endif
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #ifndef CONFIG_SYS_RAMBOOT
  37. static void sdram_start (int hi_addr)
  38. {
  39. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  40. /* unlock mode register */
  41. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  42. __asm__ volatile ("sync");
  43. /* precharge all banks */
  44. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  45. __asm__ volatile ("sync");
  46. #if SDRAM_DDR
  47. /* set mode register: extended mode */
  48. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  49. __asm__ volatile ("sync");
  50. /* set mode register: reset DLL */
  51. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  52. __asm__ volatile ("sync");
  53. #endif
  54. /* precharge all banks */
  55. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  56. __asm__ volatile ("sync");
  57. /* auto refresh */
  58. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  59. __asm__ volatile ("sync");
  60. /* set mode register */
  61. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  62. __asm__ volatile ("sync");
  63. /* normal operation */
  64. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  65. __asm__ volatile ("sync");
  66. }
  67. #endif
  68. /*
  69. * ATTENTION: Although partially referenced initdram does NOT make real use
  70. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  71. * is something else than 0x00000000.
  72. */
  73. phys_size_t initdram (int board_type)
  74. {
  75. ulong dramsize = 0;
  76. ulong dramsize2 = 0;
  77. #ifndef CONFIG_SYS_RAMBOOT
  78. ulong test1, test2;
  79. /* setup SDRAM chip selects */
  80. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  81. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  82. __asm__ volatile ("sync");
  83. /* setup config registers */
  84. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  85. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  86. __asm__ volatile ("sync");
  87. #if SDRAM_DDR
  88. /* set tap delay */
  89. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  90. __asm__ volatile ("sync");
  91. #endif
  92. /* find RAM size using SDRAM CS0 only */
  93. sdram_start(0);
  94. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  95. sdram_start(1);
  96. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  97. if (test1 > test2) {
  98. sdram_start(0);
  99. dramsize = test1;
  100. } else {
  101. dramsize = test2;
  102. }
  103. /* memory smaller than 1MB is impossible */
  104. if (dramsize < (1 << 20)) {
  105. dramsize = 0;
  106. }
  107. /* set SDRAM CS0 size according to the amount of RAM found */
  108. if (dramsize > 0) {
  109. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  110. } else {
  111. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  112. }
  113. /* let SDRAM CS1 start right after CS0 */
  114. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  115. /* find RAM size using SDRAM CS1 only */
  116. if (!dramsize)
  117. sdram_start(0);
  118. test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  119. if (!dramsize) {
  120. sdram_start(1);
  121. test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
  122. }
  123. if (test1 > test2) {
  124. sdram_start(0);
  125. dramsize2 = test1;
  126. } else {
  127. dramsize2 = test2;
  128. }
  129. /* memory smaller than 1MB is impossible */
  130. if (dramsize2 < (1 << 20)) {
  131. dramsize2 = 0;
  132. }
  133. /* set SDRAM CS1 size according to the amount of RAM found */
  134. if (dramsize2 > 0) {
  135. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  136. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  137. } else {
  138. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  139. }
  140. #else /* CONFIG_SYS_RAMBOOT */
  141. /* retrieve size of memory connected to SDRAM CS0 */
  142. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  143. if (dramsize >= 0x13) {
  144. dramsize = (1 << (dramsize - 0x13)) << 20;
  145. } else {
  146. dramsize = 0;
  147. }
  148. /* retrieve size of memory connected to SDRAM CS1 */
  149. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  150. if (dramsize2 >= 0x13) {
  151. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  152. } else {
  153. dramsize2 = 0;
  154. }
  155. #endif /* CONFIG_SYS_RAMBOOT */
  156. return dramsize + dramsize2;
  157. }
  158. int checkboard (void)
  159. {
  160. puts ("Board: MicroSys PM520 \n");
  161. return 0;
  162. }
  163. void flash_preinit(void)
  164. {
  165. /*
  166. * Now, when we are in RAM, enable flash write
  167. * access for detection process.
  168. * Note that CS_BOOT cannot be cleared when
  169. * executing in flash.
  170. */
  171. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  172. }
  173. void flash_afterinit(ulong start, ulong size)
  174. {
  175. #if defined(CONFIG_BOOT_ROM)
  176. /* adjust mapping */
  177. *(vu_long *)MPC5XXX_CS1_START =
  178. START_REG(start);
  179. *(vu_long *)MPC5XXX_CS1_STOP =
  180. STOP_REG(start, size);
  181. #else
  182. /* adjust mapping */
  183. *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
  184. START_REG(start);
  185. *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
  186. STOP_REG(start, size);
  187. #endif
  188. }
  189. extern flash_info_t flash_info[]; /* info for FLASH chips */
  190. int misc_init_r (void)
  191. {
  192. /* adjust flash start */
  193. gd->bd->bi_flashstart = flash_info[0].start[0];
  194. return (0);
  195. }
  196. #ifdef CONFIG_PCI
  197. static struct pci_controller hose;
  198. extern void pci_mpc5xxx_init(struct pci_controller *);
  199. void pci_init_board(void)
  200. {
  201. pci_mpc5xxx_init(&hose);
  202. }
  203. #endif
  204. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  205. void init_ide_reset (void)
  206. {
  207. debug ("init_ide_reset\n");
  208. }
  209. void ide_set_reset (int idereset)
  210. {
  211. debug ("ide_reset(%d)\n", idereset);
  212. }
  213. #endif
  214. #if defined(CONFIG_CMD_DOC)
  215. void doc_init (void)
  216. {
  217. doc_probe (CONFIG_SYS_DOC_BASE);
  218. }
  219. #endif
  220. int board_eth_init(bd_t *bis)
  221. {
  222. cpu_eth_init(bis); /* Built in FEC comes first */
  223. return pci_eth_init(bis);
  224. }