init_sdram.S 3.9 KB

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