init_sdram.S 4.7 KB

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