sram34xx.S 10 KB

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