galaxy5200.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 2006
  9. * Eric Schumann, Phytec Messtechnik GmbH
  10. *
  11. * (C) Copyright 2009
  12. * Eric Millbrandt, DEKA Research and Development Corporation
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. */
  32. #include <common.h>
  33. #include <mpc5xxx.h>
  34. #include <pci.h>
  35. #include <asm-ppc/io.h>
  36. #ifndef CONFIG_SYS_RAMBOOT
  37. static void sdram_start(int hi_addr)
  38. {
  39. volatile struct mpc5xxx_cdm *cdm =
  40. (struct mpc5xxx_cdm *)MPC5XXX_CDM;
  41. volatile struct mpc5xxx_sdram *sdram =
  42. (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  43. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  44. /* unlock mode register */
  45. out_be32 (&sdram->ctrl,
  46. (SDRAM_CONTROL | 0x80000000 | hi_addr_bit));
  47. /* precharge all banks */
  48. out_be32 (&sdram->ctrl,
  49. (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
  50. #ifdef SDRAM_DDR
  51. /* set mode register: extended mode */
  52. out_be32 (&sdram->mode, (SDRAM_EMODE));
  53. /* set mode register: reset DLL */
  54. out_be32 (&sdram->mode, (SDRAM_MODE | 0x04000000));
  55. #endif
  56. /* precharge all banks */
  57. out_be32 (&sdram->ctrl,
  58. (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
  59. /* auto refresh */
  60. out_be32 (&sdram->ctrl,
  61. (SDRAM_CONTROL | 0x80000004 | hi_addr_bit));
  62. /* set mode register */
  63. out_be32 (&sdram->mode, (SDRAM_MODE));
  64. /* normal operation */
  65. out_be32 (&sdram->ctrl,
  66. (SDRAM_CONTROL | hi_addr_bit));
  67. /* set CDM clock enable register, set MPC5200B SDRAM bus */
  68. /* to reduced driver strength */
  69. out_be32 (&cdm->clock_enable, (0x00CFFFFF));
  70. }
  71. #endif
  72. /*
  73. * ATTENTION: Although partially referenced initdram does NOT make
  74. * real use of CONFIG_SYS_SDRAM_BASE. The code does not
  75. * work if CONFIG_SYS_SDRAM_BASE
  76. * is something else than 0x00000000.
  77. */
  78. phys_size_t initdram(int board_type)
  79. {
  80. volatile struct mpc5xxx_mmap_ctl *mm =
  81. (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR;
  82. volatile struct mpc5xxx_sdram *sdram =
  83. (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  84. ulong dramsize = 0;
  85. ulong dramsize2 = 0;
  86. #ifndef CONFIG_SYS_RAMBOOT
  87. ulong test1, test2;
  88. /* setup SDRAM chip selects */
  89. /* 256MB at 0x0 */
  90. out_be32 (&mm->sdram0, 0x0000001b);
  91. /* disabled */
  92. out_be32 (&mm->sdram1, 0x10000000);
  93. /* setup config registers */
  94. out_be32 (&sdram->config1, SDRAM_CONFIG1);
  95. out_be32 (&sdram->config2, SDRAM_CONFIG2);
  96. /* find RAM size using SDRAM CS0 only */
  97. sdram_start(0);
  98. test1 = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, 0x10000000);
  99. sdram_start(1);
  100. test2 = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, 0x10000000);
  101. if (test1 > test2) {
  102. sdram_start(0);
  103. dramsize = test1;
  104. } else
  105. dramsize = test2;
  106. /* memory smaller than 1MB is impossible */
  107. if (dramsize < (1 << 20))
  108. dramsize = 0;
  109. /* set SDRAM CS0 size according to the amount of RAM found */
  110. if (dramsize > 0) {
  111. out_be32 (&mm->sdram0,
  112. (0x13 + __builtin_ffs(dramsize >> 20) - 1));
  113. } else {
  114. /* disabled */
  115. out_be32 (&mm->sdram0, 0);
  116. }
  117. #else /* CONFIG_SYS_RAMBOOT */
  118. /* retrieve size of memory connected to SDRAM CS0 */
  119. dramsize = in_be32(&mm->sdram0) & 0xFF;
  120. if (dramsize >= 0x13)
  121. dramsize = (1 << (dramsize - 0x13)) << 20;
  122. else
  123. dramsize = 0;
  124. /* retrieve size of memory connected to SDRAM CS1 */
  125. dramsize2 = in_be32(&mm->sdram1) & 0xFF;
  126. if (dramsize2 >= 0x13)
  127. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  128. else
  129. dramsize2 = 0;
  130. #endif /* CONFIG_SYS_RAMBOOT */
  131. return dramsize + dramsize2;
  132. }
  133. int checkboard(void)
  134. {
  135. puts("Board: galaxy5200\n");
  136. return 0;
  137. }
  138. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  139. void ft_board_setup(void *blob, bd_t * bd)
  140. {
  141. ft_cpu_setup(blob, bd);
  142. }
  143. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
  144. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  145. void init_ide_reset (void)
  146. {
  147. volatile struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt *)MPC5XXX_GPT;
  148. debug ("init_ide_reset\n");
  149. /* Configure TIMER_5 as GPIO output for ATA reset */
  150. /* Deassert reset */
  151. gpt[5].emsr = MPC5XXX_GPT_GPIO_OUT1 | MPC5XXX_GPT_TMS_GPIO;
  152. }
  153. void ide_set_reset (int idereset)
  154. {
  155. volatile struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt *)MPC5XXX_GPT;
  156. debug ("ide_reset(%d)\n", idereset);
  157. /* Configure TIMER_5 as GPIO output for ATA reset */
  158. if (idereset) {
  159. gpt[5].emsr = MPC5XXX_GPT_GPIO_OUT0 | MPC5XXX_GPT_TMS_GPIO;
  160. /* Make a delay. MPC5200 spec says 25 usec min */
  161. udelay(50);
  162. } else {
  163. gpt[5].emsr = MPC5XXX_GPT_GPIO_OUT1 | MPC5XXX_GPT_TMS_GPIO;
  164. udelay(50);
  165. }
  166. }
  167. #endif /* defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET) */