mcc200.c 8.5 KB

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