sram34xx.S 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. /* r1 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. /* CM_IDLEST1_CORE bit settings */
  54. #define ST_SDRC_MASK 0x2
  55. /* CM_ICLKEN1_CORE bit settings */
  56. #define EN_SDRC_MASK 0x2
  57. /* CM_CLKSEL1_PLL bit settings */
  58. #define CORE_DPLL_CLKOUT_DIV_SHIFT 0x1b
  59. /*
  60. * omap3_sram_configure_core_dpll - change DPLL3 M2 divider
  61. *
  62. * Params passed in registers:
  63. * r0 = new M2 divider setting (only 1 and 2 supported right now)
  64. * r1 = unlock SDRC DLL? (1 = yes, 0 = no). Only unlock DLL for
  65. * SDRC rates < 83MHz
  66. * r2 = number of MPU cycles to wait for SDRC to stabilize after
  67. * reprogramming the SDRC when switching to a slower MPU speed
  68. * r3 = increasing SDRC rate? (1 = yes, 0 = no)
  69. *
  70. * Params passed via the stack. The needed params will be copied in SRAM
  71. * before use by the code in SRAM (SDRAM is not accessible during SDRC
  72. * reconfiguration):
  73. * new SDRC_RFR_CTRL_0 register contents
  74. * new SDRC_ACTIM_CTRL_A_0 register contents
  75. * new SDRC_ACTIM_CTRL_B_0 register contents
  76. * new SDRC_MR_0 register value
  77. * new SDRC_RFR_CTRL_1 register contents
  78. * new SDRC_ACTIM_CTRL_A_1 register contents
  79. * new SDRC_ACTIM_CTRL_B_1 register contents
  80. * new SDRC_MR_1 register value
  81. *
  82. * If the param SDRC_RFR_CTRL_1 is 0, the parameters are not programmed into
  83. * the SDRC CS1 registers
  84. *
  85. * NOTE: This code no longer attempts to program the SDRC AC timing and MR
  86. * registers. This is because the code currently cannot ensure that all
  87. * L3 initiators (e.g., sDMA, IVA, DSS DISPC, etc.) are not accessing the
  88. * SDRAM when the registers are written. If the registers are changed while
  89. * an initiator is accessing SDRAM, memory can be corrupted and/or the SDRC
  90. * may enter an unpredictable state. In the future, the intent is to
  91. * re-enable this code in cases where we can ensure that no initiators are
  92. * touching the SDRAM. Until that time, users who know that their use case
  93. * can satisfy the above requirement can enable the CONFIG_OMAP3_SDRC_AC_TIMING
  94. * option.
  95. */
  96. ENTRY(omap3_sram_configure_core_dpll)
  97. stmfd sp!, {r1-r12, lr} @ store regs to stack
  98. @ pull the extra args off the stack
  99. @ and store them in SRAM
  100. ldr r4, [sp, #52]
  101. str r4, omap_sdrc_rfr_ctrl_0_val
  102. ldr r4, [sp, #56]
  103. str r4, omap_sdrc_actim_ctrl_a_0_val
  104. ldr r4, [sp, #60]
  105. str r4, omap_sdrc_actim_ctrl_b_0_val
  106. ldr r4, [sp, #64]
  107. str r4, omap_sdrc_mr_0_val
  108. ldr r4, [sp, #68]
  109. str r4, omap_sdrc_rfr_ctrl_1_val
  110. cmp r4, #0 @ if SDRC_RFR_CTRL_1 is 0,
  111. beq skip_cs1_params @ do not use cs1 params
  112. ldr r4, [sp, #72]
  113. str r4, omap_sdrc_actim_ctrl_a_1_val
  114. ldr r4, [sp, #76]
  115. str r4, omap_sdrc_actim_ctrl_b_1_val
  116. ldr r4, [sp, #80]
  117. str r4, omap_sdrc_mr_1_val
  118. skip_cs1_params:
  119. dsb @ flush buffered writes to interconnect
  120. cmp r3, #1 @ if increasing SDRC clk rate,
  121. bleq configure_sdrc @ program the SDRC regs early (for RFR)
  122. cmp r1, #SDRC_UNLOCK_DLL @ set the intended DLL state
  123. bleq unlock_dll
  124. blne lock_dll
  125. bl sdram_in_selfrefresh @ put SDRAM in self refresh, idle SDRC
  126. bl configure_core_dpll @ change the DPLL3 M2 divider
  127. mov r12, r2
  128. bl wait_clk_stable @ wait for SDRC to stabilize
  129. bl enable_sdrc @ take SDRC out of idle
  130. cmp r1, #SDRC_UNLOCK_DLL @ wait for DLL status to change
  131. bleq wait_dll_unlock
  132. blne wait_dll_lock
  133. cmp r3, #1 @ if increasing SDRC clk rate,
  134. beq return_to_sdram @ return to SDRAM code, otherwise,
  135. bl configure_sdrc @ reprogram SDRC regs now
  136. return_to_sdram:
  137. isb @ prevent speculative exec past here
  138. mov r0, #0 @ return value
  139. ldmfd sp!, {r1-r12, pc} @ restore regs and return
  140. unlock_dll:
  141. ldr r11, omap3_sdrc_dlla_ctrl
  142. ldr r12, [r11]
  143. bic r12, r12, #FIXEDDELAY_MASK
  144. orr r12, r12, #FIXEDDELAY_DEFAULT
  145. orr r12, r12, #DLLIDLE_MASK
  146. str r12, [r11] @ (no OCP barrier needed)
  147. bx lr
  148. lock_dll:
  149. ldr r11, omap3_sdrc_dlla_ctrl
  150. ldr r12, [r11]
  151. bic r12, r12, #DLLIDLE_MASK
  152. str r12, [r11] @ (no OCP barrier needed)
  153. bx lr
  154. sdram_in_selfrefresh:
  155. ldr r11, omap3_sdrc_power @ read the SDRC_POWER register
  156. ldr r12, [r11] @ read the contents of SDRC_POWER
  157. mov r9, r12 @ keep a copy of SDRC_POWER bits
  158. orr r12, r12, #SRFRONIDLEREQ_MASK @ enable self refresh on idle
  159. str r12, [r11] @ write back to SDRC_POWER register
  160. ldr r12, [r11] @ posted-write barrier for SDRC
  161. idle_sdrc:
  162. ldr r11, omap3_cm_iclken1_core @ read the CM_ICLKEN1_CORE reg
  163. ldr r12, [r11]
  164. bic r12, r12, #EN_SDRC_MASK @ disable iclk bit for SDRC
  165. str r12, [r11]
  166. wait_sdrc_idle:
  167. ldr r11, omap3_cm_idlest1_core
  168. ldr r12, [r11]
  169. and r12, r12, #ST_SDRC_MASK @ check for SDRC idle
  170. cmp r12, #ST_SDRC_MASK
  171. bne wait_sdrc_idle
  172. bx lr
  173. configure_core_dpll:
  174. ldr r11, omap3_cm_clksel1_pll
  175. ldr r12, [r11]
  176. ldr r10, core_m2_mask_val @ modify m2 for core dpll
  177. and r12, r12, r10
  178. orr r12, r12, r0, lsl #CORE_DPLL_CLKOUT_DIV_SHIFT
  179. str r12, [r11]
  180. ldr r12, [r11] @ posted-write barrier for CM
  181. bx lr
  182. wait_clk_stable:
  183. subs r12, r12, #1
  184. bne wait_clk_stable
  185. bx lr
  186. enable_sdrc:
  187. ldr r11, omap3_cm_iclken1_core
  188. ldr r12, [r11]
  189. orr r12, r12, #EN_SDRC_MASK @ enable iclk bit for SDRC
  190. str r12, [r11]
  191. wait_sdrc_idle1:
  192. ldr r11, omap3_cm_idlest1_core
  193. ldr r12, [r11]
  194. and r12, r12, #ST_SDRC_MASK
  195. cmp r12, #0
  196. bne wait_sdrc_idle1
  197. restore_sdrc_power_val:
  198. ldr r11, omap3_sdrc_power
  199. str r9, [r11] @ restore SDRC_POWER, no barrier needed
  200. bx lr
  201. wait_dll_lock:
  202. ldr r11, omap3_sdrc_dlla_status
  203. ldr r12, [r11]
  204. and r12, r12, #LOCKSTATUS_MASK
  205. cmp r12, #LOCKSTATUS_MASK
  206. bne wait_dll_lock
  207. bx lr
  208. wait_dll_unlock:
  209. ldr r11, omap3_sdrc_dlla_status
  210. ldr r12, [r11]
  211. and r12, r12, #LOCKSTATUS_MASK
  212. cmp r12, #0x0
  213. bne wait_dll_unlock
  214. bx lr
  215. configure_sdrc:
  216. ldr r12, omap_sdrc_rfr_ctrl_0_val @ fetch value from SRAM
  217. ldr r11, omap3_sdrc_rfr_ctrl_0 @ fetch addr from SRAM
  218. str r12, [r11] @ store
  219. #ifdef CONFIG_OMAP3_SDRC_AC_TIMING
  220. ldr r12, omap_sdrc_actim_ctrl_a_0_val
  221. ldr r11, omap3_sdrc_actim_ctrl_a_0
  222. str r12, [r11]
  223. ldr r12, omap_sdrc_actim_ctrl_b_0_val
  224. ldr r11, omap3_sdrc_actim_ctrl_b_0
  225. str r12, [r11]
  226. ldr r12, omap_sdrc_mr_0_val
  227. ldr r11, omap3_sdrc_mr_0
  228. str r12, [r11]
  229. #endif
  230. ldr r12, omap_sdrc_rfr_ctrl_1_val
  231. cmp r12, #0 @ if SDRC_RFR_CTRL_1 is 0,
  232. beq skip_cs1_prog @ do not program cs1 params
  233. ldr r11, omap3_sdrc_rfr_ctrl_1
  234. str r12, [r11]
  235. #ifdef CONFIG_OMAP3_SDRC_AC_TIMING
  236. ldr r12, omap_sdrc_actim_ctrl_a_1_val
  237. ldr r11, omap3_sdrc_actim_ctrl_a_1
  238. str r12, [r11]
  239. ldr r12, omap_sdrc_actim_ctrl_b_1_val
  240. ldr r11, omap3_sdrc_actim_ctrl_b_1
  241. str r12, [r11]
  242. ldr r12, omap_sdrc_mr_1_val
  243. ldr r11, omap3_sdrc_mr_1
  244. str r12, [r11]
  245. #endif
  246. skip_cs1_prog:
  247. ldr r12, [r11] @ posted-write barrier for SDRC
  248. bx lr
  249. omap3_sdrc_power:
  250. .word OMAP34XX_SDRC_REGADDR(SDRC_POWER)
  251. omap3_cm_clksel1_pll:
  252. .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
  253. omap3_cm_idlest1_core:
  254. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST)
  255. omap3_cm_iclken1_core:
  256. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1)
  257. omap3_sdrc_rfr_ctrl_0:
  258. .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0)
  259. omap3_sdrc_rfr_ctrl_1:
  260. .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_1)
  261. omap3_sdrc_actim_ctrl_a_0:
  262. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0)
  263. omap3_sdrc_actim_ctrl_a_1:
  264. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_1)
  265. omap3_sdrc_actim_ctrl_b_0:
  266. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0)
  267. omap3_sdrc_actim_ctrl_b_1:
  268. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_1)
  269. omap3_sdrc_mr_0:
  270. .word OMAP34XX_SDRC_REGADDR(SDRC_MR_0)
  271. omap3_sdrc_mr_1:
  272. .word OMAP34XX_SDRC_REGADDR(SDRC_MR_1)
  273. omap_sdrc_rfr_ctrl_0_val:
  274. .word 0xDEADBEEF
  275. omap_sdrc_rfr_ctrl_1_val:
  276. .word 0xDEADBEEF
  277. omap_sdrc_actim_ctrl_a_0_val:
  278. .word 0xDEADBEEF
  279. omap_sdrc_actim_ctrl_a_1_val:
  280. .word 0xDEADBEEF
  281. omap_sdrc_actim_ctrl_b_0_val:
  282. .word 0xDEADBEEF
  283. omap_sdrc_actim_ctrl_b_1_val:
  284. .word 0xDEADBEEF
  285. omap_sdrc_mr_0_val:
  286. .word 0xDEADBEEF
  287. omap_sdrc_mr_1_val:
  288. .word 0xDEADBEEF
  289. omap3_sdrc_dlla_status:
  290. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
  291. omap3_sdrc_dlla_ctrl:
  292. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
  293. core_m2_mask_val:
  294. .word 0x07FFFFFF
  295. ENTRY(omap3_sram_configure_core_dpll_sz)
  296. .word . - omap3_sram_configure_core_dpll