sram34xx.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 FIXEDDELAY_SHIFT 24
  40. #define FIXEDDELAY_MASK (0xff << FIXEDDELAY_SHIFT)
  41. #define DLLIDLE_MASK 0x4
  42. /*
  43. * SDRC_DLLA_CTRL default values: TI hardware team indicates that
  44. * FIXEDDELAY should be initialized to 0xf. This apparently was
  45. * empirically determined during process testing, so no derivation
  46. * was provided.
  47. */
  48. #define FIXEDDELAY_DEFAULT (0x0f << FIXEDDELAY_SHIFT)
  49. /* SDRC_DLLA_STATUS bit settings */
  50. #define LOCKSTATUS_MASK 0x4
  51. /* SDRC_POWER bit settings */
  52. #define SRFRONIDLEREQ_MASK 0x40
  53. #define PWDENA_MASK 0x4
  54. /* CM_IDLEST1_CORE bit settings */
  55. #define ST_SDRC_MASK 0x2
  56. /* CM_ICLKEN1_CORE bit settings */
  57. #define EN_SDRC_MASK 0x2
  58. /* CM_CLKSEL1_PLL bit settings */
  59. #define CORE_DPLL_CLKOUT_DIV_SHIFT 0x1b
  60. /*
  61. * omap3_sram_configure_core_dpll - change DPLL3 M2 divider
  62. * r0 = new SDRC_RFR_CTRL register contents
  63. * r1 = new SDRC_ACTIM_CTRLA register contents
  64. * r2 = new SDRC_ACTIM_CTRLB register contents
  65. * r3 = new M2 divider setting (only 1 and 2 supported right now)
  66. * r4 = unlock SDRC DLL? (1 = yes, 0 = no). Only unlock DLL for
  67. * SDRC rates < 83MHz
  68. * r5 = number of MPU cycles to wait for SDRC to stabilize after
  69. * reprogramming the SDRC when switching to a slower MPU speed
  70. * r6 = new SDRC_MR_0 register value
  71. * r7 = increasing SDRC rate? (1 = yes, 0 = no)
  72. *
  73. */
  74. ENTRY(omap3_sram_configure_core_dpll)
  75. stmfd sp!, {r1-r12, lr} @ store regs to stack
  76. ldr r4, [sp, #52] @ pull extra args off the stack
  77. ldr r5, [sp, #56] @ load extra args from the stack
  78. ldr r6, [sp, #60] @ load extra args from the stack
  79. ldr r7, [sp, #64] @ load extra args from the stack
  80. dsb @ flush buffered writes to interconnect
  81. cmp r7, #1 @ if increasing SDRC clk rate,
  82. bleq configure_sdrc @ program the SDRC regs early (for RFR)
  83. cmp r4, #SDRC_UNLOCK_DLL @ set the intended DLL state
  84. bleq unlock_dll
  85. blne lock_dll
  86. bl sdram_in_selfrefresh @ put SDRAM in self refresh, idle SDRC
  87. bl configure_core_dpll @ change the DPLL3 M2 divider
  88. bl enable_sdrc @ take SDRC out of idle
  89. cmp r4, #SDRC_UNLOCK_DLL @ wait for DLL status to change
  90. bleq wait_dll_unlock
  91. blne wait_dll_lock
  92. cmp r7, #1 @ if increasing SDRC clk rate,
  93. beq return_to_sdram @ return to SDRAM code, otherwise,
  94. bl configure_sdrc @ reprogram SDRC regs now
  95. mov r12, r5
  96. bl wait_clk_stable @ wait for SDRC to stabilize
  97. return_to_sdram:
  98. isb @ prevent speculative exec past here
  99. mov r0, #0 @ return value
  100. ldmfd sp!, {r1-r12, pc} @ restore regs and return
  101. unlock_dll:
  102. ldr r11, omap3_sdrc_dlla_ctrl
  103. ldr r12, [r11]
  104. and r12, r12, #FIXEDDELAY_MASK
  105. orr r12, r12, #FIXEDDELAY_DEFAULT
  106. orr r12, r12, #DLLIDLE_MASK
  107. str r12, [r11] @ (no OCP barrier needed)
  108. bx lr
  109. lock_dll:
  110. ldr r11, omap3_sdrc_dlla_ctrl
  111. ldr r12, [r11]
  112. bic r12, r12, #DLLIDLE_MASK
  113. str r12, [r11] @ (no OCP barrier needed)
  114. bx lr
  115. sdram_in_selfrefresh:
  116. ldr r11, omap3_sdrc_power @ read the SDRC_POWER register
  117. ldr r12, [r11] @ read the contents of SDRC_POWER
  118. mov r9, r12 @ keep a copy of SDRC_POWER bits
  119. orr r12, r12, #SRFRONIDLEREQ_MASK @ enable self refresh on idle
  120. bic r12, r12, #PWDENA_MASK @ clear PWDENA
  121. str r12, [r11] @ write back to SDRC_POWER register
  122. ldr r12, [r11] @ posted-write barrier for SDRC
  123. idle_sdrc:
  124. ldr r11, omap3_cm_iclken1_core @ read the CM_ICLKEN1_CORE reg
  125. ldr r12, [r11]
  126. bic r12, r12, #EN_SDRC_MASK @ disable iclk bit for SDRC
  127. str r12, [r11]
  128. wait_sdrc_idle:
  129. ldr r11, omap3_cm_idlest1_core
  130. ldr r12, [r11]
  131. and r12, r12, #ST_SDRC_MASK @ check for SDRC idle
  132. cmp r12, #ST_SDRC_MASK
  133. bne wait_sdrc_idle
  134. bx lr
  135. configure_core_dpll:
  136. ldr r11, omap3_cm_clksel1_pll
  137. ldr r12, [r11]
  138. ldr r10, core_m2_mask_val @ modify m2 for core dpll
  139. and r12, r12, r10
  140. orr r12, r12, r3, lsl #CORE_DPLL_CLKOUT_DIV_SHIFT
  141. str r12, [r11]
  142. ldr r12, [r11] @ posted-write barrier for CM
  143. bx lr
  144. wait_clk_stable:
  145. subs r12, r12, #1
  146. bne wait_clk_stable
  147. bx lr
  148. enable_sdrc:
  149. ldr r11, omap3_cm_iclken1_core
  150. ldr r12, [r11]
  151. orr r12, r12, #EN_SDRC_MASK @ enable iclk bit for SDRC
  152. str r12, [r11]
  153. wait_sdrc_idle1:
  154. ldr r11, omap3_cm_idlest1_core
  155. ldr r12, [r11]
  156. and r12, r12, #ST_SDRC_MASK
  157. cmp r12, #0
  158. bne wait_sdrc_idle1
  159. restore_sdrc_power_val:
  160. ldr r11, omap3_sdrc_power
  161. str r9, [r11] @ restore SDRC_POWER, no barrier needed
  162. bx lr
  163. wait_dll_lock:
  164. ldr r11, omap3_sdrc_dlla_status
  165. ldr r12, [r11]
  166. and r12, r12, #LOCKSTATUS_MASK
  167. cmp r12, #LOCKSTATUS_MASK
  168. bne wait_dll_lock
  169. bx lr
  170. wait_dll_unlock:
  171. ldr r11, omap3_sdrc_dlla_status
  172. ldr r12, [r11]
  173. and r12, r12, #LOCKSTATUS_MASK
  174. cmp r12, #0x0
  175. bne wait_dll_unlock
  176. bx lr
  177. configure_sdrc:
  178. ldr r11, omap3_sdrc_rfr_ctrl
  179. str r0, [r11]
  180. ldr r11, omap3_sdrc_actim_ctrla
  181. str r1, [r11]
  182. ldr r11, omap3_sdrc_actim_ctrlb
  183. str r2, [r11]
  184. ldr r11, omap3_sdrc_mr_0
  185. str r6, [r11]
  186. ldr r6, [r11] @ posted-write barrier for SDRC
  187. bx lr
  188. omap3_sdrc_power:
  189. .word OMAP34XX_SDRC_REGADDR(SDRC_POWER)
  190. omap3_cm_clksel1_pll:
  191. .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
  192. omap3_cm_idlest1_core:
  193. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST)
  194. omap3_cm_iclken1_core:
  195. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1)
  196. omap3_sdrc_rfr_ctrl:
  197. .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0)
  198. omap3_sdrc_actim_ctrla:
  199. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0)
  200. omap3_sdrc_actim_ctrlb:
  201. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0)
  202. omap3_sdrc_mr_0:
  203. .word OMAP34XX_SDRC_REGADDR(SDRC_MR_0)
  204. omap3_sdrc_dlla_status:
  205. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
  206. omap3_sdrc_dlla_ctrl:
  207. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
  208. core_m2_mask_val:
  209. .word 0x07FFFFFF
  210. ENTRY(omap3_sram_configure_core_dpll_sz)
  211. .word . - omap3_sram_configure_core_dpll