init_sdram.S 3.8 KB

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