pcm030.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. * SPDX-License-Identifier: GPL-2.0+
  12. */
  13. #include <common.h>
  14. #include <mpc5xxx.h>
  15. #include <pci.h>
  16. #include <asm/io.h>
  17. #include "mt46v32m16-75.h"
  18. #ifndef CONFIG_SYS_RAMBOOT
  19. static void sdram_start(int hi_addr)
  20. {
  21. volatile struct mpc5xxx_cdm *cdm =
  22. (struct mpc5xxx_cdm *)MPC5XXX_CDM;
  23. volatile struct mpc5xxx_sdram *sdram =
  24. (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  25. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  26. /* unlock mode register */
  27. out_be32 (&sdram->ctrl,
  28. (SDRAM_CONTROL | 0x80000000 | hi_addr_bit));
  29. /* precharge all banks */
  30. out_be32 (&sdram->ctrl,
  31. (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
  32. #ifdef SDRAM_DDR
  33. /* set mode register: extended mode */
  34. out_be32 (&sdram->mode, (SDRAM_EMODE));
  35. /* set mode register: reset DLL */
  36. out_be32 (&sdram->mode,
  37. (SDRAM_MODE | 0x04000000));
  38. #endif
  39. /* precharge all banks */
  40. out_be32 (&sdram->ctrl,
  41. (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
  42. /* auto refresh */
  43. out_be32 (&sdram->ctrl,
  44. (SDRAM_CONTROL | 0x80000004 | hi_addr_bit));
  45. /* set mode register */
  46. out_be32 (&sdram->mode, (SDRAM_MODE));
  47. /* normal operation */
  48. out_be32 (&sdram->ctrl,
  49. (SDRAM_CONTROL | hi_addr_bit));
  50. /* set CDM clock enable register, set MPC5200B SDRAM bus */
  51. /* to reduced driver strength */
  52. out_be32 (&cdm->clock_enable, (0x00CFFFFF));
  53. }
  54. #endif
  55. /*
  56. * ATTENTION: Although partially referenced initdram does NOT make
  57. * real use of CONFIG_SYS_SDRAM_BASE. The code does not
  58. * work if CONFIG_SYS_SDRAM_BASE
  59. * is something else than 0x00000000.
  60. */
  61. phys_size_t initdram(int board_type)
  62. {
  63. volatile struct mpc5xxx_mmap_ctl *mm =
  64. (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR;
  65. volatile struct mpc5xxx_cdm *cdm =
  66. (struct mpc5xxx_cdm *)MPC5XXX_CDM;
  67. volatile struct mpc5xxx_sdram *sdram =
  68. (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  69. ulong dramsize = 0;
  70. ulong dramsize2 = 0;
  71. #ifndef CONFIG_SYS_RAMBOOT
  72. ulong test1, test2;
  73. /* setup SDRAM chip selects */
  74. /* 256MB at 0x0 */
  75. out_be32 (&mm->sdram0, 0x0000001b);
  76. /* disabled */
  77. out_be32 (&mm->sdram1, 0x10000000);
  78. /* setup config registers */
  79. out_be32 (&sdram->config1, SDRAM_CONFIG1);
  80. out_be32 (&sdram->config2, SDRAM_CONFIG2);
  81. #if defined(SDRAM_DDR) && defined(SDRAM_TAPDELAY)
  82. /* set tap delay */
  83. out_be32 (&cdm->porcfg, SDRAM_TAPDELAY);
  84. #endif
  85. /* find RAM size using SDRAM CS0 only */
  86. sdram_start(0);
  87. test1 = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, 0x10000000);
  88. sdram_start(1);
  89. test2 = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, 0x10000000);
  90. if (test1 > test2) {
  91. sdram_start(0);
  92. dramsize = test1;
  93. } else
  94. dramsize = test2;
  95. /* memory smaller than 1MB is impossible */
  96. if (dramsize < (1 << 20))
  97. dramsize = 0;
  98. /* set SDRAM CS0 size according to the amount of RAM found */
  99. if (dramsize > 0) {
  100. out_be32 (&mm->sdram0,
  101. (0x13 + __builtin_ffs(dramsize >> 20) - 1));
  102. } else {
  103. /* disabled */
  104. out_be32 (&mm->sdram0, 0);
  105. }
  106. #else /* CONFIG_SYS_RAMBOOT */
  107. /* retrieve size of memory connected to SDRAM CS0 */
  108. dramsize = in_be32(&mm->sdram0) & 0xFF;
  109. if (dramsize >= 0x13)
  110. dramsize = (1 << (dramsize - 0x13)) << 20;
  111. else
  112. dramsize = 0;
  113. /* retrieve size of memory connected to SDRAM CS1 */
  114. dramsize2 = in_be32(&mm->sdram1) & 0xFF;
  115. if (dramsize2 >= 0x13)
  116. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  117. else
  118. dramsize2 = 0;
  119. #endif /* CONFIG_SYS_RAMBOOT */
  120. return dramsize + dramsize2;
  121. }
  122. int checkboard(void)
  123. {
  124. puts("Board: phyCORE-MPC5200B-tiny\n");
  125. return 0;
  126. }
  127. #ifdef CONFIG_PCI
  128. static struct pci_controller hose;
  129. extern void pci_mpc5xxx_init(struct pci_controller *);
  130. void pci_init_board(void)
  131. {
  132. pci_mpc5xxx_init(&hose);
  133. }
  134. #endif
  135. #ifdef CONFIG_OF_BOARD_SETUP
  136. int ft_board_setup(void *blob, bd_t *bd)
  137. {
  138. ft_cpu_setup(blob, bd);
  139. return 0;
  140. }
  141. #endif /* CONFIG_OF_BOARD_SETUP */
  142. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  143. #define GPIO_PSC2_4 0x02000000UL
  144. void init_ide_reset(void)
  145. {
  146. volatile struct mpc5xxx_wu_gpio *wu_gpio =
  147. (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
  148. debug("init_ide_reset\n");
  149. /* Configure PSC2_4 as GPIO output for ATA reset */
  150. setbits_be32(&wu_gpio->enable, GPIO_PSC2_4);
  151. setbits_be32(&wu_gpio->ddr, GPIO_PSC2_4);
  152. /* Deassert reset */
  153. setbits_be32(&wu_gpio->dvo, GPIO_PSC2_4);
  154. }
  155. void ide_set_reset(int idereset)
  156. {
  157. volatile struct mpc5xxx_wu_gpio *wu_gpio =
  158. (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
  159. debug("ide_reset(%d)\n", idereset);
  160. if (idereset) {
  161. clrbits_be32(&wu_gpio->dvo, GPIO_PSC2_4);
  162. /* Make a delay. MPC5200 spec says 25 usec min */
  163. udelay(500000);
  164. } else
  165. setbits_be32(&wu_gpio->dvo, GPIO_PSC2_4);
  166. }
  167. #endif /* defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET) */