sram34xx.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 "cm2xxx_3xxx.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. * Richard Woodruff notes that any changes to this code must be carefully
  97. * audited and tested to ensure that they don't cause a TLB miss while
  98. * the SDRAM is inaccessible. Such a situation will crash the system
  99. * since it will cause the ARM MMU to attempt to walk the page tables.
  100. * These crashes may be intermittent.
  101. */
  102. ENTRY(omap3_sram_configure_core_dpll)
  103. stmfd sp!, {r1-r12, lr} @ store regs to stack
  104. @ pull the extra args off the stack
  105. @ and store them in SRAM
  106. ldr r4, [sp, #52]
  107. str r4, omap_sdrc_rfr_ctrl_0_val
  108. ldr r4, [sp, #56]
  109. str r4, omap_sdrc_actim_ctrl_a_0_val
  110. ldr r4, [sp, #60]
  111. str r4, omap_sdrc_actim_ctrl_b_0_val
  112. ldr r4, [sp, #64]
  113. str r4, omap_sdrc_mr_0_val
  114. ldr r4, [sp, #68]
  115. str r4, omap_sdrc_rfr_ctrl_1_val
  116. cmp r4, #0 @ if SDRC_RFR_CTRL_1 is 0,
  117. beq skip_cs1_params @ do not use cs1 params
  118. ldr r4, [sp, #72]
  119. str r4, omap_sdrc_actim_ctrl_a_1_val
  120. ldr r4, [sp, #76]
  121. str r4, omap_sdrc_actim_ctrl_b_1_val
  122. ldr r4, [sp, #80]
  123. str r4, omap_sdrc_mr_1_val
  124. skip_cs1_params:
  125. mrc p15, 0, r8, c1, c0, 0 @ read ctrl register
  126. bic r10, r8, #0x800 @ clear Z-bit, disable branch prediction
  127. mcr p15, 0, r10, c1, c0, 0 @ write ctrl register
  128. dsb @ flush buffered writes to interconnect
  129. isb @ prevent speculative exec past here
  130. cmp r3, #1 @ if increasing SDRC clk rate,
  131. bleq configure_sdrc @ program the SDRC regs early (for RFR)
  132. cmp r1, #SDRC_UNLOCK_DLL @ set the intended DLL state
  133. bleq unlock_dll
  134. blne lock_dll
  135. bl sdram_in_selfrefresh @ put SDRAM in self refresh, idle SDRC
  136. bl configure_core_dpll @ change the DPLL3 M2 divider
  137. mov r12, r2
  138. bl wait_clk_stable @ wait for SDRC to stabilize
  139. bl enable_sdrc @ take SDRC out of idle
  140. cmp r1, #SDRC_UNLOCK_DLL @ wait for DLL status to change
  141. bleq wait_dll_unlock
  142. blne wait_dll_lock
  143. cmp r3, #1 @ if increasing SDRC clk rate,
  144. beq return_to_sdram @ return to SDRAM code, otherwise,
  145. bl configure_sdrc @ reprogram SDRC regs now
  146. return_to_sdram:
  147. mcr p15, 0, r8, c1, c0, 0 @ restore ctrl register
  148. isb @ prevent speculative exec past here
  149. mov r0, #0 @ return value
  150. ldmfd sp!, {r1-r12, pc} @ restore regs and return
  151. unlock_dll:
  152. ldr r11, omap3_sdrc_dlla_ctrl
  153. ldr r12, [r11]
  154. bic r12, r12, #FIXEDDELAY_MASK
  155. orr r12, r12, #FIXEDDELAY_DEFAULT
  156. orr r12, r12, #DLLIDLE_MASK
  157. str r12, [r11] @ (no OCP barrier needed)
  158. bx lr
  159. lock_dll:
  160. ldr r11, omap3_sdrc_dlla_ctrl
  161. ldr r12, [r11]
  162. bic r12, r12, #DLLIDLE_MASK
  163. str r12, [r11] @ (no OCP barrier needed)
  164. bx lr
  165. sdram_in_selfrefresh:
  166. ldr r11, omap3_sdrc_power @ read the SDRC_POWER register
  167. ldr r12, [r11] @ read the contents of SDRC_POWER
  168. mov r9, r12 @ keep a copy of SDRC_POWER bits
  169. orr r12, r12, #SRFRONIDLEREQ_MASK @ enable self refresh on idle
  170. str r12, [r11] @ write back to SDRC_POWER register
  171. ldr r12, [r11] @ posted-write barrier for SDRC
  172. idle_sdrc:
  173. ldr r11, omap3_cm_iclken1_core @ read the CM_ICLKEN1_CORE reg
  174. ldr r12, [r11]
  175. bic r12, r12, #EN_SDRC_MASK @ disable iclk bit for SDRC
  176. str r12, [r11]
  177. wait_sdrc_idle:
  178. ldr r11, omap3_cm_idlest1_core
  179. ldr r12, [r11]
  180. and r12, r12, #ST_SDRC_MASK @ check for SDRC idle
  181. cmp r12, #ST_SDRC_MASK
  182. bne wait_sdrc_idle
  183. bx lr
  184. configure_core_dpll:
  185. ldr r11, omap3_cm_clksel1_pll
  186. ldr r12, [r11]
  187. ldr r10, core_m2_mask_val @ modify m2 for core dpll
  188. and r12, r12, r10
  189. orr r12, r12, r0, lsl #CORE_DPLL_CLKOUT_DIV_SHIFT
  190. str r12, [r11]
  191. ldr r12, [r11] @ posted-write barrier for CM
  192. bx lr
  193. wait_clk_stable:
  194. subs r12, r12, #1
  195. bne wait_clk_stable
  196. bx lr
  197. enable_sdrc:
  198. ldr r11, omap3_cm_iclken1_core
  199. ldr r12, [r11]
  200. orr r12, r12, #EN_SDRC_MASK @ enable iclk bit for SDRC
  201. str r12, [r11]
  202. wait_sdrc_idle1:
  203. ldr r11, omap3_cm_idlest1_core
  204. ldr r12, [r11]
  205. and r12, r12, #ST_SDRC_MASK
  206. cmp r12, #0
  207. bne wait_sdrc_idle1
  208. restore_sdrc_power_val:
  209. ldr r11, omap3_sdrc_power
  210. str r9, [r11] @ restore SDRC_POWER, no barrier needed
  211. bx lr
  212. wait_dll_lock:
  213. ldr r11, omap3_sdrc_dlla_status
  214. ldr r12, [r11]
  215. and r12, r12, #LOCKSTATUS_MASK
  216. cmp r12, #LOCKSTATUS_MASK
  217. bne wait_dll_lock
  218. bx lr
  219. wait_dll_unlock:
  220. ldr r11, omap3_sdrc_dlla_status
  221. ldr r12, [r11]
  222. and r12, r12, #LOCKSTATUS_MASK
  223. cmp r12, #0x0
  224. bne wait_dll_unlock
  225. bx lr
  226. configure_sdrc:
  227. ldr r12, omap_sdrc_rfr_ctrl_0_val @ fetch value from SRAM
  228. ldr r11, omap3_sdrc_rfr_ctrl_0 @ fetch addr from SRAM
  229. str r12, [r11] @ store
  230. #ifdef CONFIG_OMAP3_SDRC_AC_TIMING
  231. ldr r12, omap_sdrc_actim_ctrl_a_0_val
  232. ldr r11, omap3_sdrc_actim_ctrl_a_0
  233. str r12, [r11]
  234. ldr r12, omap_sdrc_actim_ctrl_b_0_val
  235. ldr r11, omap3_sdrc_actim_ctrl_b_0
  236. str r12, [r11]
  237. ldr r12, omap_sdrc_mr_0_val
  238. ldr r11, omap3_sdrc_mr_0
  239. str r12, [r11]
  240. #endif
  241. ldr r12, omap_sdrc_rfr_ctrl_1_val
  242. cmp r12, #0 @ if SDRC_RFR_CTRL_1 is 0,
  243. beq skip_cs1_prog @ do not program cs1 params
  244. ldr r11, omap3_sdrc_rfr_ctrl_1
  245. str r12, [r11]
  246. #ifdef CONFIG_OMAP3_SDRC_AC_TIMING
  247. ldr r12, omap_sdrc_actim_ctrl_a_1_val
  248. ldr r11, omap3_sdrc_actim_ctrl_a_1
  249. str r12, [r11]
  250. ldr r12, omap_sdrc_actim_ctrl_b_1_val
  251. ldr r11, omap3_sdrc_actim_ctrl_b_1
  252. str r12, [r11]
  253. ldr r12, omap_sdrc_mr_1_val
  254. ldr r11, omap3_sdrc_mr_1
  255. str r12, [r11]
  256. #endif
  257. skip_cs1_prog:
  258. ldr r12, [r11] @ posted-write barrier for SDRC
  259. bx lr
  260. omap3_sdrc_power:
  261. .word OMAP34XX_SDRC_REGADDR(SDRC_POWER)
  262. omap3_cm_clksel1_pll:
  263. .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
  264. omap3_cm_idlest1_core:
  265. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST)
  266. omap3_cm_iclken1_core:
  267. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1)
  268. omap3_sdrc_rfr_ctrl_0:
  269. .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0)
  270. omap3_sdrc_rfr_ctrl_1:
  271. .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_1)
  272. omap3_sdrc_actim_ctrl_a_0:
  273. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0)
  274. omap3_sdrc_actim_ctrl_a_1:
  275. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_1)
  276. omap3_sdrc_actim_ctrl_b_0:
  277. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0)
  278. omap3_sdrc_actim_ctrl_b_1:
  279. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_1)
  280. omap3_sdrc_mr_0:
  281. .word OMAP34XX_SDRC_REGADDR(SDRC_MR_0)
  282. omap3_sdrc_mr_1:
  283. .word OMAP34XX_SDRC_REGADDR(SDRC_MR_1)
  284. omap_sdrc_rfr_ctrl_0_val:
  285. .word 0xDEADBEEF
  286. omap_sdrc_rfr_ctrl_1_val:
  287. .word 0xDEADBEEF
  288. omap_sdrc_actim_ctrl_a_0_val:
  289. .word 0xDEADBEEF
  290. omap_sdrc_actim_ctrl_a_1_val:
  291. .word 0xDEADBEEF
  292. omap_sdrc_actim_ctrl_b_0_val:
  293. .word 0xDEADBEEF
  294. omap_sdrc_actim_ctrl_b_1_val:
  295. .word 0xDEADBEEF
  296. omap_sdrc_mr_0_val:
  297. .word 0xDEADBEEF
  298. omap_sdrc_mr_1_val:
  299. .word 0xDEADBEEF
  300. omap3_sdrc_dlla_status:
  301. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
  302. omap3_sdrc_dlla_ctrl:
  303. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
  304. core_m2_mask_val:
  305. .word 0x07FFFFFF
  306. ENTRY(omap3_sram_configure_core_dpll_sz)
  307. .word . - omap3_sram_configure_core_dpll