sram34xx.S 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * linux/arch/arm/mach-omap3/sram.S
  3. *
  4. * Omap3 specific functions that need to be run in internal SRAM
  5. *
  6. * Copyright (C) 2004, 2007, 2008 Texas Instruments, Inc.
  7. * Copyright (C) 2008 Nokia Corporation
  8. *
  9. * Rajendra Nayak <rnayak@ti.com>
  10. * Richard Woodruff <r-woodruff2@ti.com>
  11. * Paul Walmsley
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <linux/linkage.h>
  29. #include <asm/assembler.h>
  30. #include <mach/hardware.h>
  31. #include <mach/io.h>
  32. #include "sdrc.h"
  33. #include "cm.h"
  34. .text
  35. /* r4 parameters */
  36. #define SDRC_NO_UNLOCK_DLL 0x0
  37. #define SDRC_UNLOCK_DLL 0x1
  38. /* SDRC_DLLA_CTRL bit settings */
  39. #define DLLIDLE_MASK 0x4
  40. /* SDRC_DLLA_STATUS bit settings */
  41. #define LOCKSTATUS_MASK 0x4
  42. /* SDRC_POWER bit settings */
  43. #define SRFRONIDLEREQ_MASK 0x40
  44. #define PWDENA_MASK 0x4
  45. /* CM_IDLEST1_CORE bit settings */
  46. #define ST_SDRC_MASK 0x2
  47. /* CM_ICLKEN1_CORE bit settings */
  48. #define EN_SDRC_MASK 0x2
  49. /* CM_CLKSEL1_PLL bit settings */
  50. #define CORE_DPLL_CLKOUT_DIV_SHIFT 0x1b
  51. /*
  52. * omap3_sram_configure_core_dpll - change DPLL3 M2 divider
  53. * r0 = new SDRC_RFR_CTRL register contents
  54. * r1 = new SDRC_ACTIM_CTRLA register contents
  55. * r2 = new SDRC_ACTIM_CTRLB register contents
  56. * r3 = new M2 divider setting (only 1 and 2 supported right now)
  57. * r4 = unlock SDRC DLL? (1 = yes, 0 = no). Only unlock DLL for
  58. * SDRC rates < 83MHz
  59. * r5 = number of MPU cycles to wait for SDRC to stabilize after
  60. * reprogramming the SDRC when switching to a slower MPU speed
  61. * r6 = new SDRC_MR_0 register value
  62. *
  63. */
  64. ENTRY(omap3_sram_configure_core_dpll)
  65. stmfd sp!, {r1-r12, lr} @ store regs to stack
  66. ldr r4, [sp, #52] @ pull extra args off the stack
  67. ldr r5, [sp, #56] @ load extra args from the stack
  68. ldr r6, [sp, #60] @ load extra args from the stack
  69. dsb @ flush buffered writes to interconnect
  70. cmp r3, #0x2 @ if increasing SDRC clk rate,
  71. blne configure_sdrc @ program the SDRC regs early (for RFR)
  72. cmp r4, #SDRC_UNLOCK_DLL @ set the intended DLL state
  73. bleq unlock_dll
  74. blne lock_dll
  75. bl sdram_in_selfrefresh @ put SDRAM in self refresh, idle SDRC
  76. bl configure_core_dpll @ change the DPLL3 M2 divider
  77. bl enable_sdrc @ take SDRC out of idle
  78. cmp r4, #SDRC_UNLOCK_DLL @ wait for DLL status to change
  79. bleq wait_dll_unlock
  80. blne wait_dll_lock
  81. cmp r3, #0x1 @ if increasing SDRC clk rate,
  82. beq return_to_sdram @ return to SDRAM code, otherwise,
  83. bl configure_sdrc @ reprogram SDRC regs now
  84. mov r12, r5
  85. bl wait_clk_stable @ wait for SDRC to stabilize
  86. return_to_sdram:
  87. isb @ prevent speculative exec past here
  88. mov r0, #0 @ return value
  89. ldmfd sp!, {r1-r12, pc} @ restore regs and return
  90. unlock_dll:
  91. ldr r11, omap3_sdrc_dlla_ctrl
  92. ldr r12, [r11]
  93. orr r12, r12, #DLLIDLE_MASK
  94. str r12, [r11] @ (no OCP barrier needed)
  95. bx lr
  96. lock_dll:
  97. ldr r11, omap3_sdrc_dlla_ctrl
  98. ldr r12, [r11]
  99. bic r12, r12, #DLLIDLE_MASK
  100. str r12, [r11] @ (no OCP barrier needed)
  101. bx lr
  102. sdram_in_selfrefresh:
  103. ldr r11, omap3_sdrc_power @ read the SDRC_POWER register
  104. ldr r12, [r11] @ read the contents of SDRC_POWER
  105. mov r9, r12 @ keep a copy of SDRC_POWER bits
  106. orr r12, r12, #SRFRONIDLEREQ_MASK @ enable self refresh on idle
  107. bic r12, r12, #PWDENA_MASK @ clear PWDENA
  108. str r12, [r11] @ write back to SDRC_POWER register
  109. ldr r12, [r11] @ posted-write barrier for SDRC
  110. idle_sdrc:
  111. ldr r11, omap3_cm_iclken1_core @ read the CM_ICLKEN1_CORE reg
  112. ldr r12, [r11]
  113. bic r12, r12, #EN_SDRC_MASK @ disable iclk bit for SDRC
  114. str r12, [r11]
  115. wait_sdrc_idle:
  116. ldr r11, omap3_cm_idlest1_core
  117. ldr r12, [r11]
  118. and r12, r12, #ST_SDRC_MASK @ check for SDRC idle
  119. cmp r12, #ST_SDRC_MASK
  120. bne wait_sdrc_idle
  121. bx lr
  122. configure_core_dpll:
  123. ldr r11, omap3_cm_clksel1_pll
  124. ldr r12, [r11]
  125. ldr r10, core_m2_mask_val @ modify m2 for core dpll
  126. and r12, r12, r10
  127. orr r12, r12, r3, lsl #CORE_DPLL_CLKOUT_DIV_SHIFT
  128. str r12, [r11]
  129. ldr r12, [r11] @ posted-write barrier for CM
  130. bx lr
  131. wait_clk_stable:
  132. subs r12, r12, #1
  133. bne wait_clk_stable
  134. bx lr
  135. enable_sdrc:
  136. ldr r11, omap3_cm_iclken1_core
  137. ldr r12, [r11]
  138. orr r12, r12, #EN_SDRC_MASK @ enable iclk bit for SDRC
  139. str r12, [r11]
  140. wait_sdrc_idle1:
  141. ldr r11, omap3_cm_idlest1_core
  142. ldr r12, [r11]
  143. and r12, r12, #ST_SDRC_MASK
  144. cmp r12, #0
  145. bne wait_sdrc_idle1
  146. restore_sdrc_power_val:
  147. ldr r11, omap3_sdrc_power
  148. str r9, [r11] @ restore SDRC_POWER, no barrier needed
  149. bx lr
  150. wait_dll_lock:
  151. ldr r11, omap3_sdrc_dlla_status
  152. ldr r12, [r11]
  153. and r12, r12, #LOCKSTATUS_MASK
  154. cmp r12, #LOCKSTATUS_MASK
  155. bne wait_dll_lock
  156. bx lr
  157. wait_dll_unlock:
  158. ldr r11, omap3_sdrc_dlla_status
  159. ldr r12, [r11]
  160. and r12, r12, #LOCKSTATUS_MASK
  161. cmp r12, #0x0
  162. bne wait_dll_unlock
  163. bx lr
  164. configure_sdrc:
  165. ldr r11, omap3_sdrc_rfr_ctrl
  166. str r0, [r11]
  167. ldr r11, omap3_sdrc_actim_ctrla
  168. str r1, [r11]
  169. ldr r11, omap3_sdrc_actim_ctrlb
  170. str r2, [r11]
  171. ldr r11, omap3_sdrc_mr_0
  172. str r6, [r11]
  173. ldr r6, [r11] @ posted-write barrier for SDRC
  174. bx lr
  175. omap3_sdrc_power:
  176. .word OMAP34XX_SDRC_REGADDR(SDRC_POWER)
  177. omap3_cm_clksel1_pll:
  178. .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
  179. omap3_cm_idlest1_core:
  180. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST)
  181. omap3_cm_iclken1_core:
  182. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1)
  183. omap3_sdrc_rfr_ctrl:
  184. .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0)
  185. omap3_sdrc_actim_ctrla:
  186. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0)
  187. omap3_sdrc_actim_ctrlb:
  188. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0)
  189. omap3_sdrc_mr_0:
  190. .word OMAP34XX_SDRC_REGADDR(SDRC_MR_0)
  191. omap3_sdrc_dlla_status:
  192. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
  193. omap3_sdrc_dlla_ctrl:
  194. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
  195. core_m2_mask_val:
  196. .word 0x07FFFFFF
  197. ENTRY(omap3_sram_configure_core_dpll_sz)
  198. .word . - omap3_sram_configure_core_dpll