init_sdram_bootrom_initblock.S 4.0 KB

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