init_sdram.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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;
  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. * Now, Initialize the SDRAM,
  113. * start with the SDRAM Refresh Rate Control Register
  114. */
  115. p0.l = lo(EBIU_SDRRC);
  116. p0.h = hi(EBIU_SDRRC);
  117. r0 = mem_SDRRC;
  118. w[p0] = r0.l;
  119. ssync;
  120. /*
  121. * SDRAM Memory Bank Control Register - bank specific parameters
  122. */
  123. p0.l = (EBIU_SDBCTL & 0xFFFF);
  124. p0.h = (EBIU_SDBCTL >> 16);
  125. r0 = mem_SDBCTL;
  126. w[p0] = r0.l;
  127. ssync;
  128. /*
  129. * SDRAM Global Control Register - global programmable parameters
  130. * Disable self-refresh
  131. */
  132. P2.H = hi(EBIU_SDGCTL);
  133. P2.L = lo(EBIU_SDGCTL);
  134. R0 = [P2];
  135. BITCLR (R0, 24);
  136. /*
  137. * Check if SDRAM is already powered up, if it is, enable self-refresh
  138. */
  139. p0.h = hi(EBIU_SDSTAT);
  140. p0.l = lo(EBIU_SDSTAT);
  141. r2.l = w[p0];
  142. cc = bittst(r2,3);
  143. if !cc jump skip;
  144. NOP;
  145. BITSET (R0, 23);
  146. skip:
  147. [P2] = R0;
  148. SSYNC;
  149. /* Write in the new value in the register */
  150. R0.L = lo(mem_SDGCTL);
  151. R0.H = hi(mem_SDGCTL);
  152. [P2] = R0;
  153. SSYNC;
  154. nop;
  155. (P5:0) = [SP++];
  156. (R7:0) = [SP++];
  157. RETS = [SP++];
  158. ASTAT = [SP++];
  159. RTS;