mcc200.c 8.5 KB

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