mcc200.c 7.6 KB

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