digsy_mtc.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * (C) Copyright 2003
  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. * (C) Copyright 2005-2009
  9. * Modified for InterControl digsyMTC MPC5200 board by
  10. * Frank Bodammer, GCD Hard- & Software GmbH,
  11. * frank.bodammer@gcd-solutions.de
  12. *
  13. * (C) Copyright 2009
  14. * Grzegorz Bernacki, Semihalf, gjb@semihalf.com
  15. *
  16. * See file CREDITS for list of people who contributed to this
  17. * project.
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License as
  21. * published by the Free Software Foundation; either version 2 of
  22. * the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  32. * MA 02111-1307 USA
  33. */
  34. #include <common.h>
  35. #include <mpc5xxx.h>
  36. #include <net.h>
  37. #include <pci.h>
  38. #include <asm/processor.h>
  39. #include <asm/io.h>
  40. #include "eeprom.h"
  41. #include "is42s16800a-7t.h"
  42. DECLARE_GLOBAL_DATA_PTR;
  43. extern int usb_cpu_init(void);
  44. #ifndef CONFIG_SYS_RAMBOOT
  45. static void sdram_start(int hi_addr)
  46. {
  47. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  48. long control = SDRAM_CONTROL | hi_addr_bit;
  49. /* unlock mode register */
  50. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
  51. /* precharge all banks */
  52. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  53. /* auto refresh */
  54. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
  55. /* set mode register */
  56. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  57. /* normal operation */
  58. out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
  59. }
  60. #endif
  61. /*
  62. * ATTENTION: Although partially referenced initdram does NOT make real use
  63. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
  64. * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
  65. */
  66. phys_size_t initdram(int board_type)
  67. {
  68. ulong dramsize = 0;
  69. ulong dramsize2 = 0;
  70. uint svr, pvr;
  71. #ifndef CONFIG_SYS_RAMBOOT
  72. ulong test1, test2;
  73. /* setup SDRAM chip selects */
  74. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001C); /* 512MB at 0x0 */
  75. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */
  76. /* setup config registers */
  77. out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  78. out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  79. /* find RAM size using SDRAM CS0 only */
  80. sdram_start(0);
  81. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
  82. sdram_start(1);
  83. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
  84. if (test1 > test2) {
  85. sdram_start(0);
  86. dramsize = test1;
  87. } else {
  88. dramsize = test2;
  89. }
  90. /* memory smaller than 1MB is impossible */
  91. if (dramsize < (1 << 20))
  92. dramsize = 0;
  93. /* set SDRAM CS0 size according to the amount of RAM found */
  94. if (dramsize > 0) {
  95. out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
  96. (0x13 + __builtin_ffs(dramsize >> 20) - 1));
  97. } else {
  98. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
  99. }
  100. /* let SDRAM CS1 start right after CS0 */
  101. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize + 0x0000001C);
  102. /* find RAM size using SDRAM CS1 only */
  103. test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
  104. 0x08000000);
  105. dramsize2 = test1;
  106. /* memory smaller than 1MB is impossible */
  107. if (dramsize2 < (1 << 20))
  108. dramsize2 = 0;
  109. /* set SDRAM CS1 size according to the amount of RAM found */
  110. if (dramsize2 > 0) {
  111. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, (dramsize |
  112. (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
  113. } else {
  114. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, dramsize); /* disabled */
  115. }
  116. #else /* CONFIG_SYS_RAMBOOT */
  117. /* retrieve size of memory connected to SDRAM CS0 */
  118. dramsize = in_be32((void *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
  119. if (dramsize >= 0x13)
  120. dramsize = (1 << (dramsize - 0x13)) << 20;
  121. else
  122. dramsize = 0;
  123. /* retrieve size of memory connected to SDRAM CS1 */
  124. dramsize2 = in_be32((void *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
  125. if (dramsize2 >= 0x13)
  126. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  127. else
  128. dramsize2 = 0;
  129. #endif /* CONFIG_SYS_RAMBOOT */
  130. /*
  131. * On MPC5200B we need to set the special configuration delay in the
  132. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  133. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  134. *
  135. * "The SDelay should be written to a value of 0x00000004. It is
  136. * required to account for changes caused by normal wafer processing
  137. * parameters."
  138. */
  139. svr = get_svr();
  140. pvr = get_pvr();
  141. if ((SVR_MJREV(svr) >= 2) &&
  142. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
  143. out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
  144. return dramsize + dramsize2;
  145. }
  146. int checkboard(void)
  147. {
  148. char *s = getenv("serial#");
  149. puts ("Board: InterControl digsyMTC");
  150. if (s != NULL) {
  151. puts(", ");
  152. puts(s);
  153. }
  154. putc('\n');
  155. return 0;
  156. }
  157. int board_early_init_r(void)
  158. {
  159. /*
  160. * Now, when we are in RAM, enable flash write access for detection
  161. * process. Note that CS_BOOT cannot be cleared when executing in
  162. * flash.
  163. */
  164. /* disable CS_BOOT */
  165. clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
  166. /* enable CS1 */
  167. setbits_be32((void *)MPC5XXX_ADDECR, (1 << 17));
  168. /* enable CS0 */
  169. setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
  170. #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
  171. /* Low level USB init, required for proper kernel operation */
  172. usb_cpu_init();
  173. #endif
  174. return (0);
  175. }
  176. void board_get_enetaddr (uchar * enet)
  177. {
  178. ushort read = 0;
  179. ushort addr_of_eth_addr = 0;
  180. ushort len_sys = 0;
  181. ushort len_sys_cfg = 0;
  182. /* check identification word */
  183. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_IDENT, (uchar *)&read, 2);
  184. if (read != EEPROM_IDENT)
  185. return;
  186. /* calculate offset of config area */
  187. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYS, (uchar *)&len_sys, 2);
  188. eeprom_read(EEPROM_ADDR, EEPROM_ADDR_LEN_SYSCFG,
  189. (uchar *)&len_sys_cfg, 2);
  190. addr_of_eth_addr = (len_sys + len_sys_cfg + EEPROM_ADDR_ETHADDR) << 1;
  191. if (addr_of_eth_addr >= EEPROM_LEN)
  192. return;
  193. eeprom_read(EEPROM_ADDR, addr_of_eth_addr, enet, 6);
  194. }
  195. int misc_init_r(void)
  196. {
  197. uchar enetaddr[6];
  198. if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
  199. board_get_enetaddr(enetaddr);
  200. eth_setenv_enetaddr("ethaddr", enetaddr);
  201. }
  202. return 0;
  203. }
  204. #ifdef CONFIG_PCI
  205. static struct pci_controller hose;
  206. extern void pci_mpc5xxx_init(struct pci_controller *);
  207. void pci_init_board(void)
  208. {
  209. pci_mpc5xxx_init(&hose);
  210. }
  211. #endif
  212. #ifdef CONFIG_CMD_IDE
  213. #ifdef CONFIG_IDE_RESET
  214. void init_ide_reset(void)
  215. {
  216. debug ("init_ide_reset\n");
  217. /* set gpio output value to 1 */
  218. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  219. /* open drain output */
  220. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  221. /* direction output */
  222. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  223. /* enable gpio */
  224. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  225. }
  226. void ide_set_reset(int idereset)
  227. {
  228. debug ("ide_reset(%d)\n", idereset);
  229. /* set gpio output value to 0 */
  230. clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  231. /* open drain output */
  232. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  233. /* direction output */
  234. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  235. /* enable gpio */
  236. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  237. udelay(10000);
  238. /* set gpio output value to 1 */
  239. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, (1 << 25));
  240. /* open drain output */
  241. setbits_be32((void *)MPC5XXX_WU_GPIO_ODE, (1 << 25));
  242. /* direction output */
  243. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, (1 << 25));
  244. /* enable gpio */
  245. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, (1 << 25));
  246. }
  247. #endif /* CONFIG_IDE_RESET */
  248. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  249. void ft_board_setup(void *blob, bd_t *bd)
  250. {
  251. ft_cpu_setup(blob, bd);
  252. }
  253. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  254. #endif /* CONFIG_CMD_IDE */