mgsuvd.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * (C) Copyright 2007
  3. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #if 0
  24. #define DEBUG
  25. #endif
  26. #include <common.h>
  27. #include <mpc8xx.h>
  28. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  29. #include <libfdt.h>
  30. #endif
  31. DECLARE_GLOBAL_DATA_PTR;
  32. const uint sdram_table[] =
  33. {
  34. 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x0ff77c00,
  35. 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  36. /* 0x08 Burst Read */
  37. 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x00fffc00,
  38. 0x00fffc00, 0x00fffc00, 0x0ff77c00, 0x1ffffc05,
  39. /* 0x10 Load mode register */
  40. 0x0ffffc34, 0x0ff57c04, 0x0ffffc04, 0x1ffffc05,
  41. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  42. /* 0x18 Single Write */
  43. 0x0f07fc04, 0x0ffffc00, 0x00bd7c04, 0x0ffffc04,
  44. 0x0ff77c04, 0x1ffffc05, 0xfffffc04, 0xfffffc04,
  45. /* 0x20 Burst Write */
  46. 0x0f07fc04, 0x0ffffc00, 0x00bd7c00, 0x00fffc00,
  47. 0x00fffc00, 0x00fffc04, 0x0ffffc04, 0x0ff77c04,
  48. 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  49. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  50. /* 0x30 Precharge all and Refresh */
  51. 0x0ff77c04, 0x0ffffc04, 0x0ff5fc84, 0x0ffffc04,
  52. 0x0ffffc04, 0x0ffffc84, 0x1ffffc05, 0xfffffc04,
  53. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  54. /* 0x3C Exception */
  55. 0x7ffffc04, 0xfffffc07, 0xfffffc04, 0xfffffc04,
  56. };
  57. int checkboard (void)
  58. {
  59. puts ("Board: Keymile mgsuvd\n");
  60. return (0);
  61. }
  62. long int initdram (int board_type)
  63. {
  64. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  65. volatile memctl8xx_t *memctl = &immap->im_memctl;
  66. long int size;
  67. upmconfig (UPMB, (uint *) sdram_table,
  68. sizeof (sdram_table) / sizeof (uint));
  69. /*
  70. * Preliminary prescaler for refresh (depends on number of
  71. * banks): This value is selected for four cycles every 62.4 us
  72. * with two SDRAM banks or four cycles every 31.2 us with one
  73. * bank. It will be adjusted after memory sizing.
  74. */
  75. memctl->memc_mptpr = CFG_MPTPR;
  76. /*
  77. * The following value is used as an address (i.e. opcode) for
  78. * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If
  79. * the port size is 32bit the SDRAM does NOT "see" the lower two
  80. * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for
  81. * MICRON SDRAMs:
  82. * -> 0 00 010 0 010
  83. * | | | | +- Burst Length = 4
  84. * | | | +----- Burst Type = Sequential
  85. * | | +------- CAS Latency = 2
  86. * | +----------- Operating Mode = Standard
  87. * +-------------- Write Burst Mode = Programmed Burst Length
  88. */
  89. memctl->memc_mar = CFG_MAR;
  90. /*
  91. * Map controller banks 1 to the SDRAM banks 1 at
  92. * preliminary addresses - these have to be modified after the
  93. * SDRAM size has been determined.
  94. */
  95. memctl->memc_or1 = CFG_OR1_PRELIM;
  96. memctl->memc_br1 = CFG_BR1_PRELIM;
  97. memctl->memc_mbmr = CFG_MBMR & (~(MBMR_PTBE)); /* no refresh yet */
  98. udelay (200);
  99. /* perform SDRAM initializsation sequence */
  100. memctl->memc_mcr = 0x80802830; /* SDRAM bank 0 */
  101. udelay (1);
  102. memctl->memc_mcr = 0x80802110; /* SDRAM bank 0 - execute twice */
  103. udelay (1);
  104. memctl->memc_mbmr |= MBMR_PTBE; /* enable refresh */
  105. udelay (1000);
  106. /*
  107. * Check Bank 0 Memory Size for re-configuration
  108. *
  109. */
  110. size = get_ram_size(SDRAM_BASE1_PRELIM, SDRAM_MAX_SIZE);
  111. udelay (1000);
  112. debug ("SDRAM Bank 0: %ld MB\n", size >> 20);
  113. return (size);
  114. }
  115. #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
  116. /*
  117. * update "memory" property in the blob
  118. */
  119. void ft_blob_update(void *blob, bd_t *bd)
  120. {
  121. int ret, nodeoffset = 0;
  122. ulong brg_data[1] = {0};
  123. ulong memory_data[2] = {0};
  124. ulong flash_data[4] = {0};
  125. memory_data[0] = cpu_to_be32(bd->bi_memstart);
  126. memory_data[1] = cpu_to_be32(bd->bi_memsize);
  127. nodeoffset = fdt_path_offset (blob, "/memory");
  128. if (nodeoffset >= 0) {
  129. ret = fdt_setprop(blob, nodeoffset, "reg", memory_data,
  130. sizeof(memory_data));
  131. if (ret < 0)
  132. printf("ft_blob_update): cannot set /memory/reg "
  133. "property err:%s\n", fdt_strerror(ret));
  134. }
  135. else {
  136. /* memory node is required in dts */
  137. printf("ft_blob_update(): cannot find /memory node "
  138. "err:%s\n", fdt_strerror(nodeoffset));
  139. }
  140. flash_data[2] = cpu_to_be32(bd->bi_flashstart);
  141. flash_data[3] = cpu_to_be32(bd->bi_flashsize);
  142. nodeoffset = fdt_path_offset (blob, "/localbus");
  143. if (nodeoffset >= 0) {
  144. ret = fdt_setprop(blob, nodeoffset, "ranges", flash_data,
  145. sizeof(flash_data));
  146. if (ret < 0)
  147. printf("ft_blob_update): cannot set /localbus/ranges "
  148. "property err:%s\n", fdt_strerror(ret));
  149. }
  150. else {
  151. /* memory node is required in dts */
  152. printf("ft_blob_update(): cannot find /localbus node "
  153. "err:%s\n", fdt_strerror(nodeoffset));
  154. }
  155. /* BRG */
  156. brg_data[0] = cpu_to_be32(bd->bi_busfreq);
  157. nodeoffset = fdt_path_offset (blob, "/soc866/cpm");
  158. if (nodeoffset >= 0) {
  159. ret = fdt_setprop(blob, nodeoffset, "brg-frequency", brg_data,
  160. sizeof(brg_data));
  161. if (ret < 0)
  162. printf("ft_blob_update): cannot set /soc866/cpm/brg-frequency "
  163. "property err:%s\n", fdt_strerror(ret));
  164. }
  165. else {
  166. /* memory node is required in dts */
  167. printf("ft_blob_update(): cannot find /localbus node "
  168. "err:%s\n", fdt_strerror(nodeoffset));
  169. }
  170. /* MAC Adresse */
  171. nodeoffset = fdt_path_offset (blob, "/soc866/cpm/ethernet");
  172. if (nodeoffset >= 0) {
  173. ret = fdt_setprop(blob, nodeoffset, "mac-address", bd->bi_enetaddr,
  174. sizeof(uchar) * 6);
  175. if (ret < 0)
  176. printf("ft_blob_update): cannot set /soc866/cpm/scc/mac-address "
  177. "property err:%s\n", fdt_strerror(ret));
  178. }
  179. else {
  180. /* memory node is required in dts */
  181. printf("ft_blob_update(): cannot find /localbus node "
  182. "err:%s\n", fdt_strerror(nodeoffset));
  183. }
  184. }
  185. void ft_board_setup(void *blob, bd_t *bd)
  186. {
  187. ft_cpu_setup( blob, bd);
  188. ft_blob_update(blob, bd);
  189. }
  190. #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */