a4m072.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 2010
  9. * Sergei Poselenov, Emcraft Systems, sposelenov@emcraft.com.
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  27. * MA 02111-1307 USA
  28. */
  29. #include <common.h>
  30. #include <mpc5xxx.h>
  31. #include <pci.h>
  32. #include <asm/processor.h>
  33. #include <asm/io.h>
  34. #include <libfdt.h>
  35. #include <netdev.h>
  36. #include "mt46v32m16.h"
  37. #ifndef CONFIG_SYS_RAMBOOT
  38. static void sdram_start (int hi_addr)
  39. {
  40. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  41. long control = SDRAM_CONTROL | hi_addr_bit;
  42. /* unlock mode register */
  43. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000000);
  44. __asm__ volatile ("sync");
  45. /* precharge all banks */
  46. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  47. __asm__ volatile ("sync");
  48. #if SDRAM_DDR
  49. /* set mode register: extended mode */
  50. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_EMODE);
  51. __asm__ volatile ("sync");
  52. /* set mode register: reset DLL */
  53. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE | 0x04000000);
  54. __asm__ volatile ("sync");
  55. #endif
  56. /* precharge all banks */
  57. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000002);
  58. __asm__ volatile ("sync");
  59. /* auto refresh */
  60. out_be32((void *)MPC5XXX_SDRAM_CTRL, control | 0x80000004);
  61. __asm__ volatile ("sync");
  62. /* set mode register */
  63. out_be32((void *)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
  64. __asm__ volatile ("sync");
  65. /* normal operation */
  66. out_be32((void *)MPC5XXX_SDRAM_CTRL, control);
  67. __asm__ volatile ("sync");
  68. }
  69. #endif
  70. /*
  71. * ATTENTION: Although partially referenced initdram does NOT make real use
  72. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  73. * is something else than 0x00000000.
  74. */
  75. phys_size_t initdram (int board_type)
  76. {
  77. ulong dramsize = 0;
  78. uint svr, pvr;
  79. #ifndef CONFIG_SYS_RAMBOOT
  80. ulong test1, test2;
  81. /* setup SDRAM chip selects */
  82. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0x0000001e); /* 2GB at 0x0 */
  83. out_be32((void *)MPC5XXX_SDRAM_CS1CFG, 0x80000000); /* disabled */
  84. __asm__ volatile ("sync");
  85. /* setup config registers */
  86. out_be32((void *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  87. out_be32((void *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  88. __asm__ volatile ("sync");
  89. #if SDRAM_DDR
  90. /* set tap delay */
  91. out_be32((void *)MPC5XXX_CDM_PORCFG, SDRAM_TAPDELAY);
  92. __asm__ volatile ("sync");
  93. #endif
  94. /* find RAM size using SDRAM CS0 only */
  95. sdram_start(0);
  96. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  97. sdram_start(1);
  98. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
  99. if (test1 > test2) {
  100. sdram_start(0);
  101. dramsize = test1;
  102. } else {
  103. dramsize = test2;
  104. }
  105. /* memory smaller than 1MB is impossible */
  106. if (dramsize < (1 << 20)) {
  107. dramsize = 0;
  108. }
  109. /* set SDRAM CS0 size according to the amount of RAM found */
  110. if (dramsize > 0) {
  111. out_be32((void *)MPC5XXX_SDRAM_CS0CFG,
  112. 0x13 + __builtin_ffs(dramsize >> 20) - 1);
  113. } else {
  114. out_be32((void *)MPC5XXX_SDRAM_CS0CFG, 0); /* 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. }
  124. #endif /* CONFIG_SYS_RAMBOOT */
  125. /*
  126. * On MPC5200B we need to set the special configuration delay in the
  127. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  128. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  129. *
  130. * "The SDelay should be written to a value of 0x00000004. It is
  131. * required to account for changes caused by normal wafer processing
  132. * parameters."
  133. */
  134. svr = get_svr();
  135. pvr = get_pvr();
  136. if ((SVR_MJREV(svr) >= 2) &&
  137. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  138. out_be32((void *)MPC5XXX_SDRAM_SDELAY, 0x04);
  139. __asm__ volatile ("sync");
  140. }
  141. return dramsize;
  142. }
  143. int checkboard (void)
  144. {
  145. puts ("Board: A4M072\n");
  146. return 0;
  147. }
  148. #ifdef CONFIG_PCI
  149. static struct pci_controller hose;
  150. extern void pci_mpc5xxx_init(struct pci_controller *);
  151. void pci_init_board(void)
  152. {
  153. pci_mpc5xxx_init(&hose);
  154. }
  155. #endif
  156. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  157. void
  158. ft_board_setup(void *blob, bd_t *bd)
  159. {
  160. ft_cpu_setup(blob, bd);
  161. }
  162. #endif
  163. int board_eth_init(bd_t *bis)
  164. {
  165. int rv, num_if = 0;
  166. /* Initialize TSECs first */
  167. if ((rv = cpu_eth_init(bis)) >= 0)
  168. num_if += rv;
  169. else
  170. printf("ERROR: failed to initialize FEC.\n");
  171. if ((rv = pci_eth_init(bis)) >= 0)
  172. num_if += rv;
  173. else
  174. printf("ERROR: failed to initialize PCI Ethernet.\n");
  175. return num_if;
  176. }
  177. /*
  178. * Miscellaneous late-boot configurations
  179. *
  180. * Initialize EEPROM write-protect GPIO pin.
  181. */
  182. int misc_init_r(void)
  183. {
  184. #if defined(CONFIG_SYS_EEPROM_WREN)
  185. /* Enable GPIO pin */
  186. setbits_be32((void *)MPC5XXX_WU_GPIO_ENABLE, CONFIG_SYS_EEPROM_WP);
  187. /* Set direction, output */
  188. setbits_be32((void *)MPC5XXX_WU_GPIO_DIR, CONFIG_SYS_EEPROM_WP);
  189. /* De-assert write enable */
  190. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  191. #endif
  192. return 0;
  193. }
  194. #if defined(CONFIG_SYS_EEPROM_WREN)
  195. /* Input: <dev_addr> I2C address of EEPROM device to enable.
  196. * <state> -1: deliver current state
  197. * 0: disable write
  198. * 1: enable write
  199. * Returns: -1: wrong device address
  200. * 0: dis-/en- able done
  201. * 0/1: current state if <state> was -1.
  202. */
  203. int eeprom_write_enable (unsigned dev_addr, int state)
  204. {
  205. if (CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) {
  206. return -1;
  207. } else {
  208. switch (state) {
  209. case 1:
  210. /* Enable write access */
  211. clrbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  212. state = 0;
  213. break;
  214. case 0:
  215. /* Disable write access */
  216. setbits_be32((void *)MPC5XXX_WU_GPIO_DATA_O, CONFIG_SYS_EEPROM_WP);
  217. state = 0;
  218. break;
  219. default:
  220. /* Read current status back. */
  221. state = (0 == (in_be32((void *)MPC5XXX_WU_GPIO_DATA_O) &
  222. CONFIG_SYS_EEPROM_WP));
  223. break;
  224. }
  225. }
  226. return state;
  227. }
  228. #endif