init_sdram_bootrom_initblock.S 4.4 KB

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