init_sdram_bootrom_initblock.S 4.1 KB

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