init_sdram.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #define ASSEMBLY
  2. #include <linux/config.h>
  3. #include <config.h>
  4. #include <asm/blackfin.h>
  5. #include <asm/mem_init.h>
  6. #include <asm/mach-common/bits/bootrom.h>
  7. #include <asm/mach-common/bits/ebiu.h>
  8. #include <asm/mach-common/bits/pll.h>
  9. #include <asm/mach-common/bits/uart.h>
  10. .global init_sdram;
  11. #if (CONFIG_CCLK_DIV == 1)
  12. #define CONFIG_CCLK_ACT_DIV CCLK_DIV1
  13. #endif
  14. #if (CONFIG_CCLK_DIV == 2)
  15. #define CONFIG_CCLK_ACT_DIV CCLK_DIV2
  16. #endif
  17. #if (CONFIG_CCLK_DIV == 4)
  18. #define CONFIG_CCLK_ACT_DIV CCLK_DIV4
  19. #endif
  20. #if (CONFIG_CCLK_DIV == 8)
  21. #define CONFIG_CCLK_ACT_DIV CCLK_DIV8
  22. #endif
  23. #ifndef CONFIG_CCLK_ACT_DIV
  24. #define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly
  25. #endif
  26. init_sdram:
  27. [--SP] = ASTAT;
  28. [--SP] = RETS;
  29. [--SP] = (R7:0);
  30. [--SP] = (P5:0);
  31. #if (BFIN_BOOT_MODE == BF533_SPI_BOOT)
  32. p0.h = hi(SPI_BAUD);
  33. p0.l = lo(SPI_BAUD);
  34. r0.l = CONFIG_SPI_BAUD;
  35. w[p0] = r0.l;
  36. SSYNC;
  37. #endif
  38. /*
  39. * PLL_LOCKCNT - how many SCLK Cycles to delay while PLL becomes stable
  40. */
  41. p0.h = hi(PLL_LOCKCNT);
  42. p0.l = lo(PLL_LOCKCNT);
  43. r0 = 0x300(Z);
  44. w[p0] = r0.l;
  45. ssync;
  46. /*
  47. * Put SDRAM in self-refresh, incase anything is running
  48. */
  49. P2.H = hi(EBIU_SDGCTL);
  50. P2.L = lo(EBIU_SDGCTL);
  51. R0 = [P2];
  52. BITSET (R0, 24);
  53. [P2] = R0;
  54. SSYNC;
  55. /*
  56. * Set PLL_CTL with the value that we calculate in R0
  57. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  58. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  59. * - [7] = output delay (add 200ps of delay to mem signals)
  60. * - [6] = input delay (add 200ps of input delay to mem signals)
  61. * - [5] = PDWN : 1=All Clocks off
  62. * - [3] = STOPCK : 1=Core Clock off
  63. * - [1] = PLL_OFF : 1=Disable Power to PLL
  64. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  65. * all other bits set to zero
  66. */
  67. r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
  68. r0 = r0 << 9; /* Shift it over, */
  69. r1 = CONFIG_CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
  70. r0 = r1 | r0;
  71. r1 = CONFIG_PLL_BYPASS; /* Bypass the PLL? */
  72. r1 = r1 << 8; /* Shift it over */
  73. r0 = r1 | r0; /* add them all together */
  74. p0.h = hi(PLL_CTL);
  75. p0.l = lo(PLL_CTL); /* Load the address */
  76. cli r2; /* Disable interrupts */
  77. ssync;
  78. w[p0] = r0.l; /* Set the value */
  79. idle; /* Wait for the PLL to stablize */
  80. sti r2; /* Enable interrupts */
  81. check_again:
  82. p0.h = hi(PLL_STAT);
  83. p0.l = lo(PLL_STAT);
  84. R0 = W[P0](Z);
  85. CC = BITTST(R0,5);
  86. if ! CC jump check_again;
  87. /* Configure SCLK & CCLK Dividers */
  88. r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  89. p0.h = hi(PLL_DIV);
  90. p0.l = lo(PLL_DIV);
  91. w[p0] = r0.l;
  92. ssync;
  93. /*
  94. * We now are running at speed, time to set the Async mem bank wait states
  95. * This will speed up execution, since we are normally running from FLASH.
  96. */
  97. p2.h = (EBIU_AMBCTL1 >> 16);
  98. p2.l = (EBIU_AMBCTL1 & 0xFFFF);
  99. r0.h = (AMBCTL1VAL >> 16);
  100. r0.l = (AMBCTL1VAL & 0xFFFF);
  101. [p2] = r0;
  102. ssync;
  103. p2.h = (EBIU_AMBCTL0 >> 16);
  104. p2.l = (EBIU_AMBCTL0 & 0xFFFF);
  105. r0.h = (AMBCTL0VAL >> 16);
  106. r0.l = (AMBCTL0VAL & 0xFFFF);
  107. [p2] = r0;
  108. ssync;
  109. p2.h = (EBIU_AMGCTL >> 16);
  110. p2.l = (EBIU_AMGCTL & 0xffff);
  111. r0 = AMGCTLVAL;
  112. w[p2] = r0;
  113. ssync;
  114. /*
  115. * Now, Initialize the SDRAM,
  116. * start with the SDRAM Refresh Rate Control Register
  117. */
  118. p0.l = lo(EBIU_SDRRC);
  119. p0.h = hi(EBIU_SDRRC);
  120. r0 = mem_SDRRC;
  121. w[p0] = r0.l;
  122. ssync;
  123. /*
  124. * SDRAM Memory Bank Control Register - bank specific parameters
  125. */
  126. p0.l = (EBIU_SDBCTL & 0xFFFF);
  127. p0.h = (EBIU_SDBCTL >> 16);
  128. r0 = mem_SDBCTL;
  129. w[p0] = r0.l;
  130. ssync;
  131. /*
  132. * SDRAM Global Control Register - global programmable parameters
  133. * Disable self-refresh
  134. */
  135. P2.H = hi(EBIU_SDGCTL);
  136. P2.L = lo(EBIU_SDGCTL);
  137. R0 = [P2];
  138. BITCLR (R0, 24);
  139. /*
  140. * Check if SDRAM is already powered up, if it is, enable self-refresh
  141. */
  142. p0.h = hi(EBIU_SDSTAT);
  143. p0.l = lo(EBIU_SDSTAT);
  144. r2.l = w[p0];
  145. cc = bittst(r2,3);
  146. if !cc jump skip;
  147. NOP;
  148. BITSET (R0, 23);
  149. skip:
  150. [P2] = R0;
  151. SSYNC;
  152. /* Write in the new value in the register */
  153. R0.L = lo(mem_SDGCTL);
  154. R0.H = hi(mem_SDGCTL);
  155. [P2] = R0;
  156. SSYNC;
  157. nop;
  158. (P5:0) = [SP++];
  159. (R7:0) = [SP++];
  160. RETS = [SP++];
  161. ASTAT = [SP++];
  162. RTS;