adderII.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * (C) Copyright 2000-2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@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. #include <common.h>
  24. #include <config.h>
  25. #include <mpc8xx.h>
  26. /*
  27. * Check Board Identity:
  28. */
  29. int checkboard( void )
  30. {
  31. puts("Board: ");
  32. puts("AdderII(MPC852T)\n" );
  33. return 0;
  34. }
  35. #if defined( CONFIG_SDRAM_50MHZ )
  36. /******************************************************************************
  37. ** for chip Samsung K4S643232F - T70
  38. ** this table is for 32-50MHz operation
  39. *******************************************************************************/
  40. #define SDRAM_MPTPRVALUE 0x0200
  41. #define SDRAM_MAMRVALUE0 0x00802114 /* refresh at 32MHz */
  42. #define SDRAM_MAMRVALUE1 0x00802118
  43. #define SDRAM_OR1VALUE 0xff800e00
  44. #define SDRAM_BR1VALUE 0x00000081
  45. #define SDRAM_MARVALUE 94
  46. #define SDRAM_MCRVALUE0 0x80808105
  47. #define SDRAM_MCRVALUE1 0x80808130
  48. const uint sdram_table[] = {
  49. /* single read (offset 0x00 in upm ram) */
  50. 0x1f07fc24, 0xe0aefc04, 0x10adfc04, 0xe0bbbc00,
  51. 0x10f77c44, 0xf3fffc07, 0xfffffc04, 0xfffffc04,
  52. /* burst read (offset 0x08 in upm ram) */
  53. 0x1f07fc24, 0xe0aefc04, 0x10adfc04, 0xf0affc00,
  54. 0xf0affc00, 0xf0affc00, 0xf0affc00, 0x10a77c44,
  55. 0xf7bffc47, 0xfffffc35, 0xfffffc34, 0xfffffc35,
  56. 0xfffffc35, 0x1ff77c35, 0xfffffc34, 0x1fb57c35,
  57. /* single write (offset 0x18 in upm ram) */
  58. 0x1f27fc24, 0xe0aebc04, 0x00b93c00, 0x13f77c47,
  59. 0xfffdfc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  60. /* burst write (offset 0x20 in upm ram) */
  61. 0x1f07fc24, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
  62. 0xf0affc00, 0xe0abbc00, 0x1fb77c47, 0xfffffc04,
  63. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  64. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  65. /* refresh (offset 0x30 in upm ram) */
  66. 0x1ff5fca4, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  67. 0xfffffc84, 0xfffffc07, 0xfffffc04, 0xfffffc04,
  68. 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  69. /* exception (offset 0x3C in upm ram) */
  70. 0xfffffc27, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  71. };
  72. #else
  73. #error SDRAM not correctly configured
  74. #endif
  75. int _initsdram (uint base, uint noMbytes)
  76. {
  77. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  78. volatile memctl8xx_t *memctl = &immap->im_memctl;
  79. if (noMbytes != 8) {
  80. return -1;
  81. }
  82. upmconfig (UPMA, (uint *) sdram_table,
  83. sizeof (sdram_table) / sizeof (uint));
  84. memctl->memc_mptpr = SDRAM_MPTPRVALUE;
  85. /* Configure the refresh (mostly). This needs to be
  86. * based upon processor clock speed and optimized to provide
  87. * the highest level of performance. For multiple banks,
  88. * this time has to be divided by the number of banks.
  89. * Although it is not clear anywhere, it appears the
  90. * refresh steps through the chip selects for this UPM
  91. * on each refresh cycle.
  92. * We have to be careful changing
  93. * UPM registers after we ask it to run these commands.
  94. */
  95. memctl->memc_mamr = (SDRAM_MAMRVALUE0 | (SDRAM_MARVALUE << 24));
  96. memctl->memc_mar = 0x0;
  97. udelay (200);
  98. /* Now run the precharge/nop/mrs commands.
  99. */
  100. memctl->memc_mcr = 0x80002115;
  101. udelay (200);
  102. /* Run 8 refresh cycles */
  103. memctl->memc_mcr = 0x80002380;
  104. udelay (200);
  105. memctl->memc_mar = 0x88;
  106. udelay (200);
  107. memctl->memc_mcr = 0x80002116;
  108. udelay (200);
  109. memctl->memc_or1 = SDRAM_OR1VALUE;
  110. memctl->memc_br1 = SDRAM_BR1VALUE | base;
  111. return 0;
  112. }
  113. void _sdramdisable( void )
  114. {
  115. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  116. volatile memctl8xx_t *memctl = &immap->im_memctl;
  117. memctl->memc_br1 = 0x00000000;
  118. /* maybe we should turn off upma here or something */
  119. }
  120. int initsdram (uint base, uint * noMbytes)
  121. {
  122. uint m = 8;
  123. *noMbytes = m;
  124. if (!_initsdram (base, m)) {
  125. return 0;
  126. } else {
  127. _sdramdisable ();
  128. return -1;
  129. }
  130. }
  131. long int initdram (int board_type)
  132. {
  133. /* AdderII: has 8MB SDRAM */
  134. uint sdramsz;
  135. uint m = 0;
  136. if (!initsdram (0x00000000, &sdramsz)) {
  137. m += sdramsz;
  138. } else {
  139. return -1;
  140. }
  141. return (m << 20);
  142. }
  143. int testdram (void)
  144. {
  145. /* TODO: XXX XXX XXX not an actual SDRAM test */
  146. printf ("Test: 8MB SDRAM\n");
  147. return (0);
  148. }