mcc200.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * (C) Copyright 2003-2006
  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 "mt48lc8m32b2-6-7.h"
  30. DECLARE_GLOBAL_DATA_PTR;
  31. extern flash_info_t flash_info[]; /* FLASH chips info */
  32. ulong flash_get_size (ulong base, int banknum);
  33. #ifndef CFG_RAMBOOT
  34. static void sdram_start (int hi_addr)
  35. {
  36. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  37. /* unlock mode register */
  38. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  39. __asm__ volatile ("sync");
  40. /* precharge all banks */
  41. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  42. __asm__ volatile ("sync");
  43. #if SDRAM_DDR
  44. /* set mode register: extended mode */
  45. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  46. __asm__ volatile ("sync");
  47. /* set mode register: reset DLL */
  48. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  49. __asm__ volatile ("sync");
  50. #endif
  51. /* precharge all banks */
  52. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  53. __asm__ volatile ("sync");
  54. /* auto refresh */
  55. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  56. __asm__ volatile ("sync");
  57. /* set mode register */
  58. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  59. __asm__ volatile ("sync");
  60. /* normal operation */
  61. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  62. __asm__ volatile ("sync");
  63. }
  64. #endif
  65. /*
  66. * ATTENTION: Although partially referenced initdram does NOT make real use
  67. * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
  68. * is something else than 0x00000000.
  69. */
  70. long int initdram (int board_type)
  71. {
  72. ulong dramsize = 0;
  73. ulong dramsize2 = 0;
  74. #ifndef CFG_RAMBOOT
  75. ulong test1, test2;
  76. /* setup SDRAM chip selects */
  77. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
  78. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
  79. __asm__ volatile ("sync");
  80. /* setup config registers */
  81. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  82. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  83. __asm__ volatile ("sync");
  84. #if SDRAM_DDR
  85. /* set tap delay */
  86. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  87. __asm__ volatile ("sync");
  88. #endif
  89. /* find RAM size using SDRAM CS0 only */
  90. sdram_start(0);
  91. test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  92. sdram_start(1);
  93. test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
  94. if (test1 > test2) {
  95. sdram_start(0);
  96. dramsize = test1;
  97. } else {
  98. dramsize = test2;
  99. }
  100. /* memory smaller than 1MB is impossible */
  101. if (dramsize < (1 << 20)) {
  102. dramsize = 0;
  103. }
  104. /* set SDRAM CS0 size according to the amount of RAM found */
  105. if (dramsize > 0) {
  106. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
  107. } else {
  108. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  109. }
  110. /* let SDRAM CS1 start right after CS0 */
  111. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
  112. /* find RAM size using SDRAM CS1 only */
  113. if (!dramsize)
  114. sdram_start(0);
  115. test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
  116. if (!dramsize) {
  117. sdram_start(1);
  118. test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
  119. }
  120. if (test1 > test2) {
  121. sdram_start(0);
  122. dramsize2 = test1;
  123. } else {
  124. dramsize2 = test2;
  125. }
  126. /* memory smaller than 1MB is impossible */
  127. if (dramsize2 < (1 << 20)) {
  128. dramsize2 = 0;
  129. }
  130. /* set SDRAM CS1 size according to the amount of RAM found */
  131. if (dramsize2 > 0) {
  132. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
  133. | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
  134. } else {
  135. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  136. }
  137. #else /* CFG_RAMBOOT */
  138. /* retrieve size of memory connected to SDRAM CS0 */
  139. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  140. if (dramsize >= 0x13) {
  141. dramsize = (1 << (dramsize - 0x13)) << 20;
  142. } else {
  143. dramsize = 0;
  144. }
  145. /* retrieve size of memory connected to SDRAM CS1 */
  146. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  147. if (dramsize2 >= 0x13) {
  148. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  149. } else {
  150. dramsize2 = 0;
  151. }
  152. #endif /* CFG_RAMBOOT */
  153. return dramsize + dramsize2;
  154. }
  155. int checkboard (void)
  156. {
  157. puts ("Board: MCC200\n");
  158. return 0;
  159. }
  160. int misc_init_r (void)
  161. {
  162. /*
  163. * Adjust flash start and offset to detected values
  164. */
  165. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  166. gd->bd->bi_flashoffset = 0;
  167. /*
  168. * Check if boot FLASH isn't max size
  169. */
  170. if (gd->bd->bi_flashsize < (0 - CFG_FLASH_BASE)) {
  171. /* adjust mapping */
  172. *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
  173. START_REG(gd->bd->bi_flashstart);
  174. *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
  175. STOP_REG(gd->bd->bi_flashstart, gd->bd->bi_flashsize);
  176. /*
  177. * Re-check to get correct base address
  178. */
  179. flash_get_size(gd->bd->bi_flashstart, CFG_MAX_FLASH_BANKS - 1);
  180. /*
  181. * Re-do flash protection upon new addresses
  182. */
  183. flash_protect (FLAG_PROTECT_CLEAR,
  184. gd->bd->bi_flashstart, 0xffffffff,
  185. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  186. /* Monitor protection ON by default */
  187. flash_protect (FLAG_PROTECT_SET,
  188. CFG_MONITOR_BASE, CFG_MONITOR_BASE + monitor_flash_len - 1,
  189. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  190. /* Environment protection ON by default */
  191. flash_protect (FLAG_PROTECT_SET,
  192. CFG_ENV_ADDR,
  193. CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
  194. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  195. /* Redundant environment protection ON by default */
  196. flash_protect (FLAG_PROTECT_SET,
  197. CFG_ENV_ADDR_REDUND,
  198. CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
  199. &flash_info[CFG_MAX_FLASH_BANKS - 1]);
  200. }
  201. if (gd->bd->bi_flashsize > (32 << 20)) {
  202. /* Unprotect the upper bank of the Flash */
  203. *(volatile int*)MPC5XXX_CS0_CFG |= (1 << 6);
  204. flash_protect (FLAG_PROTECT_CLEAR,
  205. flash_info[0].start[0] + flash_info[0].size / 2,
  206. (flash_info[0].start[0] + flash_info[0].size) / 2 - 1,
  207. &flash_info[0]);
  208. *(volatile int*)MPC5XXX_CS0_CFG &= ~(1 << 6);
  209. }
  210. return (0);
  211. }
  212. #ifdef CONFIG_PCI
  213. static struct pci_controller hose;
  214. extern void pci_mpc5xxx_init(struct pci_controller *);
  215. void pci_init_board(void)
  216. {
  217. pci_mpc5xxx_init(&hose);
  218. }
  219. #endif
  220. #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
  221. void init_ide_reset (void)
  222. {
  223. debug ("init_ide_reset\n");
  224. }
  225. void ide_set_reset (int idereset)
  226. {
  227. debug ("ide_reset(%d)\n", idereset);
  228. }
  229. #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
  230. #if (CONFIG_COMMANDS & CFG_CMD_DOC)
  231. extern void doc_probe (ulong physadr);
  232. void doc_init (void)
  233. {
  234. doc_probe (CFG_DOC_BASE);
  235. }
  236. #endif