mcc200.c 8.5 KB

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