init_sdram.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 (BFIN_BOOT_MODE != BF537_UART_BOOT)
  8. #if (CONFIG_CCLK_DIV == 1)
  9. #define CONFIG_CCLK_ACT_DIV CCLK_DIV1
  10. #endif
  11. #if (CONFIG_CCLK_DIV == 2)
  12. #define CONFIG_CCLK_ACT_DIV CCLK_DIV2
  13. #endif
  14. #if (CONFIG_CCLK_DIV == 4)
  15. #define CONFIG_CCLK_ACT_DIV CCLK_DIV4
  16. #endif
  17. #if (CONFIG_CCLK_DIV == 8)
  18. #define CONFIG_CCLK_ACT_DIV CCLK_DIV8
  19. #endif
  20. #ifndef CONFIG_CCLK_ACT_DIV
  21. #define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly
  22. #endif
  23. #endif
  24. init_sdram:
  25. [--SP] = ASTAT;
  26. [--SP] = RETS;
  27. [--SP] = (R7:0);
  28. [--SP] = (P5:0);
  29. #if (BFIN_BOOT_MODE == BF537_SPI_MASTER_BOOT)
  30. p0.h = hi(SIC_IWR);
  31. p0.l = lo(SIC_IWR);
  32. r0.l = 0x1;
  33. w[p0] = r0.l;
  34. SSYNC;
  35. p0.h = hi(SPI_BAUD);
  36. p0.l = lo(SPI_BAUD);
  37. r0.l = CONFIG_SPI_BAUD;
  38. w[p0] = r0.l;
  39. SSYNC;
  40. #endif
  41. #if (BFIN_BOOT_MODE != BF537_UART_BOOT)
  42. #ifdef CONFIG_BF537
  43. /* Enable PHY CLK buffer output */
  44. p0.h = hi(VR_CTL);
  45. p0.l = lo(VR_CTL);
  46. r0.l = w[p0];
  47. bitset(r0, 14);
  48. w[p0] = r0.l;
  49. ssync;
  50. #endif
  51. /*
  52. * PLL_LOCKCNT - how many SCLK Cycles to delay while PLL becomes stable
  53. */
  54. p0.h = hi(PLL_LOCKCNT);
  55. p0.l = lo(PLL_LOCKCNT);
  56. r0 = 0x300(Z);
  57. w[p0] = r0.l;
  58. ssync;
  59. /*
  60. * Put SDRAM in self-refresh, incase anything is running
  61. */
  62. P2.H = hi(EBIU_SDGCTL);
  63. P2.L = lo(EBIU_SDGCTL);
  64. R0 = [P2];
  65. BITSET (R0, 24);
  66. [P2] = R0;
  67. SSYNC;
  68. /*
  69. * Set PLL_CTL with the value that we calculate in R0
  70. * - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors
  71. * - [8] = BYPASS : BYPASS the PLL, run CLKIN into CCLK/SCLK
  72. * - [7] = output delay (add 200ps of delay to mem signals)
  73. * - [6] = input delay (add 200ps of input delay to mem signals)
  74. * - [5] = PDWN : 1=All Clocks off
  75. * - [3] = STOPCK : 1=Core Clock off
  76. * - [1] = PLL_OFF : 1=Disable Power to PLL
  77. * - [0] = DF : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL
  78. * all other bits set to zero
  79. */
  80. r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
  81. r0 = r0 << 9; /* Shift it over */
  82. r1 = CONFIG_CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
  83. r0 = r1 | r0;
  84. r1 = CONFIG_PLL_BYPASS; /* Bypass the PLL? */
  85. r1 = r1 << 8; /* Shift it over */
  86. r0 = r1 | r0; /* add them all together */
  87. p0.h = hi(PLL_CTL);
  88. p0.l = lo(PLL_CTL); /* Load the address */
  89. cli r2; /* Disable interrupts */
  90. ssync;
  91. w[p0] = r0.l; /* Set the value */
  92. idle; /* Wait for the PLL to stablize */
  93. sti r2; /* Enable interrupts */
  94. check_again:
  95. p0.h = hi(PLL_STAT);
  96. p0.l = lo(PLL_STAT);
  97. R0 = W[P0](Z);
  98. CC = BITTST(R0,5);
  99. if ! CC jump check_again;
  100. /* Configure SCLK & CCLK Dividers */
  101. r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
  102. p0.h = hi(PLL_DIV);
  103. p0.l = lo(PLL_DIV);
  104. w[p0] = r0.l;
  105. ssync;
  106. #endif
  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;