sram34xx.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. /*
  35. * This file needs be built unconditionally as ARM to interoperate correctly
  36. * with non-Thumb-2-capable firmware.
  37. */
  38. .arm
  39. .text
  40. /* r1 parameters */
  41. #define SDRC_NO_UNLOCK_DLL 0x0
  42. #define SDRC_UNLOCK_DLL 0x1
  43. /* SDRC_DLLA_CTRL bit settings */
  44. #define FIXEDDELAY_SHIFT 24
  45. #define FIXEDDELAY_MASK (0xff << FIXEDDELAY_SHIFT)
  46. #define DLLIDLE_MASK 0x4
  47. /*
  48. * SDRC_DLLA_CTRL default values: TI hardware team indicates that
  49. * FIXEDDELAY should be initialized to 0xf. This apparently was
  50. * empirically determined during process testing, so no derivation
  51. * was provided.
  52. */
  53. #define FIXEDDELAY_DEFAULT (0x0f << FIXEDDELAY_SHIFT)
  54. /* SDRC_DLLA_STATUS bit settings */
  55. #define LOCKSTATUS_MASK 0x4
  56. /* SDRC_POWER bit settings */
  57. #define SRFRONIDLEREQ_MASK 0x40
  58. /* CM_IDLEST1_CORE bit settings */
  59. #define ST_SDRC_MASK 0x2
  60. /* CM_ICLKEN1_CORE bit settings */
  61. #define EN_SDRC_MASK 0x2
  62. /* CM_CLKSEL1_PLL bit settings */
  63. #define CORE_DPLL_CLKOUT_DIV_SHIFT 0x1b
  64. /*
  65. * omap3_sram_configure_core_dpll - change DPLL3 M2 divider
  66. *
  67. * Params passed in registers:
  68. * r0 = new M2 divider setting (only 1 and 2 supported right now)
  69. * r1 = unlock SDRC DLL? (1 = yes, 0 = no). Only unlock DLL for
  70. * SDRC rates < 83MHz
  71. * r2 = number of MPU cycles to wait for SDRC to stabilize after
  72. * reprogramming the SDRC when switching to a slower MPU speed
  73. * r3 = increasing SDRC rate? (1 = yes, 0 = no)
  74. *
  75. * Params passed via the stack. The needed params will be copied in SRAM
  76. * before use by the code in SRAM (SDRAM is not accessible during SDRC
  77. * reconfiguration):
  78. * new SDRC_RFR_CTRL_0 register contents
  79. * new SDRC_ACTIM_CTRL_A_0 register contents
  80. * new SDRC_ACTIM_CTRL_B_0 register contents
  81. * new SDRC_MR_0 register value
  82. * new SDRC_RFR_CTRL_1 register contents
  83. * new SDRC_ACTIM_CTRL_A_1 register contents
  84. * new SDRC_ACTIM_CTRL_B_1 register contents
  85. * new SDRC_MR_1 register value
  86. *
  87. * If the param SDRC_RFR_CTRL_1 is 0, the parameters are not programmed into
  88. * the SDRC CS1 registers
  89. *
  90. * NOTE: This code no longer attempts to program the SDRC AC timing and MR
  91. * registers. This is because the code currently cannot ensure that all
  92. * L3 initiators (e.g., sDMA, IVA, DSS DISPC, etc.) are not accessing the
  93. * SDRAM when the registers are written. If the registers are changed while
  94. * an initiator is accessing SDRAM, memory can be corrupted and/or the SDRC
  95. * may enter an unpredictable state. In the future, the intent is to
  96. * re-enable this code in cases where we can ensure that no initiators are
  97. * touching the SDRAM. Until that time, users who know that their use case
  98. * can satisfy the above requirement can enable the CONFIG_OMAP3_SDRC_AC_TIMING
  99. * option.
  100. *
  101. * Richard Woodruff notes that any changes to this code must be carefully
  102. * audited and tested to ensure that they don't cause a TLB miss while
  103. * the SDRAM is inaccessible. Such a situation will crash the system
  104. * since it will cause the ARM MMU to attempt to walk the page tables.
  105. * These crashes may be intermittent.
  106. */
  107. ENTRY(omap3_sram_configure_core_dpll)
  108. stmfd sp!, {r1-r12, lr} @ store regs to stack
  109. @ pull the extra args off the stack
  110. @ and store them in SRAM
  111. /*
  112. * PC-relative stores are deprecated in ARMv7 and lead to undefined behaviour
  113. * in Thumb-2: use a r7 as a base instead.
  114. * Be careful not to clobber r7 when maintaing this file.
  115. */
  116. THUMB( adr r7, omap3_sram_configure_core_dpll )
  117. .macro strtext Rt:req, label:req
  118. ARM( str \Rt, \label )
  119. THUMB( str \Rt, [r7, \label - omap3_sram_configure_core_dpll] )
  120. .endm
  121. ldr r4, [sp, #52]
  122. strtext r4, omap_sdrc_rfr_ctrl_0_val
  123. ldr r4, [sp, #56]
  124. strtext r4, omap_sdrc_actim_ctrl_a_0_val
  125. ldr r4, [sp, #60]
  126. strtext r4, omap_sdrc_actim_ctrl_b_0_val
  127. ldr r4, [sp, #64]
  128. strtext r4, omap_sdrc_mr_0_val
  129. ldr r4, [sp, #68]
  130. strtext r4, omap_sdrc_rfr_ctrl_1_val
  131. cmp r4, #0 @ if SDRC_RFR_CTRL_1 is 0,
  132. beq skip_cs1_params @ do not use cs1 params
  133. ldr r4, [sp, #72]
  134. strtext r4, omap_sdrc_actim_ctrl_a_1_val
  135. ldr r4, [sp, #76]
  136. strtext r4, omap_sdrc_actim_ctrl_b_1_val
  137. ldr r4, [sp, #80]
  138. strtext r4, omap_sdrc_mr_1_val
  139. skip_cs1_params:
  140. mrc p15, 0, r8, c1, c0, 0 @ read ctrl register
  141. bic r10, r8, #0x800 @ clear Z-bit, disable branch prediction
  142. mcr p15, 0, r10, c1, c0, 0 @ write ctrl register
  143. dsb @ flush buffered writes to interconnect
  144. isb @ prevent speculative exec past here
  145. cmp r3, #1 @ if increasing SDRC clk rate,
  146. bleq configure_sdrc @ program the SDRC regs early (for RFR)
  147. cmp r1, #SDRC_UNLOCK_DLL @ set the intended DLL state
  148. bleq unlock_dll
  149. blne lock_dll
  150. bl sdram_in_selfrefresh @ put SDRAM in self refresh, idle SDRC
  151. bl configure_core_dpll @ change the DPLL3 M2 divider
  152. mov r12, r2
  153. bl wait_clk_stable @ wait for SDRC to stabilize
  154. bl enable_sdrc @ take SDRC out of idle
  155. cmp r1, #SDRC_UNLOCK_DLL @ wait for DLL status to change
  156. bleq wait_dll_unlock
  157. blne wait_dll_lock
  158. cmp r3, #1 @ if increasing SDRC clk rate,
  159. beq return_to_sdram @ return to SDRAM code, otherwise,
  160. bl configure_sdrc @ reprogram SDRC regs now
  161. return_to_sdram:
  162. mcr p15, 0, r8, c1, c0, 0 @ restore ctrl register
  163. isb @ prevent speculative exec past here
  164. mov r0, #0 @ return value
  165. ldmfd sp!, {r1-r12, pc} @ restore regs and return
  166. unlock_dll:
  167. ldr r11, omap3_sdrc_dlla_ctrl
  168. ldr r12, [r11]
  169. bic r12, r12, #FIXEDDELAY_MASK
  170. orr r12, r12, #FIXEDDELAY_DEFAULT
  171. orr r12, r12, #DLLIDLE_MASK
  172. str r12, [r11] @ (no OCP barrier needed)
  173. bx lr
  174. lock_dll:
  175. ldr r11, omap3_sdrc_dlla_ctrl
  176. ldr r12, [r11]
  177. bic r12, r12, #DLLIDLE_MASK
  178. str r12, [r11] @ (no OCP barrier needed)
  179. bx lr
  180. sdram_in_selfrefresh:
  181. ldr r11, omap3_sdrc_power @ read the SDRC_POWER register
  182. ldr r12, [r11] @ read the contents of SDRC_POWER
  183. mov r9, r12 @ keep a copy of SDRC_POWER bits
  184. orr r12, r12, #SRFRONIDLEREQ_MASK @ enable self refresh on idle
  185. str r12, [r11] @ write back to SDRC_POWER register
  186. ldr r12, [r11] @ posted-write barrier for SDRC
  187. idle_sdrc:
  188. ldr r11, omap3_cm_iclken1_core @ read the CM_ICLKEN1_CORE reg
  189. ldr r12, [r11]
  190. bic r12, r12, #EN_SDRC_MASK @ disable iclk bit for SDRC
  191. str r12, [r11]
  192. wait_sdrc_idle:
  193. ldr r11, omap3_cm_idlest1_core
  194. ldr r12, [r11]
  195. and r12, r12, #ST_SDRC_MASK @ check for SDRC idle
  196. cmp r12, #ST_SDRC_MASK
  197. bne wait_sdrc_idle
  198. bx lr
  199. configure_core_dpll:
  200. ldr r11, omap3_cm_clksel1_pll
  201. ldr r12, [r11]
  202. ldr r10, core_m2_mask_val @ modify m2 for core dpll
  203. and r12, r12, r10
  204. orr r12, r12, r0, lsl #CORE_DPLL_CLKOUT_DIV_SHIFT
  205. str r12, [r11]
  206. ldr r12, [r11] @ posted-write barrier for CM
  207. bx lr
  208. wait_clk_stable:
  209. subs r12, r12, #1
  210. bne wait_clk_stable
  211. bx lr
  212. enable_sdrc:
  213. ldr r11, omap3_cm_iclken1_core
  214. ldr r12, [r11]
  215. orr r12, r12, #EN_SDRC_MASK @ enable iclk bit for SDRC
  216. str r12, [r11]
  217. wait_sdrc_idle1:
  218. ldr r11, omap3_cm_idlest1_core
  219. ldr r12, [r11]
  220. and r12, r12, #ST_SDRC_MASK
  221. cmp r12, #0
  222. bne wait_sdrc_idle1
  223. restore_sdrc_power_val:
  224. ldr r11, omap3_sdrc_power
  225. str r9, [r11] @ restore SDRC_POWER, no barrier needed
  226. bx lr
  227. wait_dll_lock:
  228. ldr r11, omap3_sdrc_dlla_status
  229. ldr r12, [r11]
  230. and r12, r12, #LOCKSTATUS_MASK
  231. cmp r12, #LOCKSTATUS_MASK
  232. bne wait_dll_lock
  233. bx lr
  234. wait_dll_unlock:
  235. ldr r11, omap3_sdrc_dlla_status
  236. ldr r12, [r11]
  237. and r12, r12, #LOCKSTATUS_MASK
  238. cmp r12, #0x0
  239. bne wait_dll_unlock
  240. bx lr
  241. configure_sdrc:
  242. ldr r12, omap_sdrc_rfr_ctrl_0_val @ fetch value from SRAM
  243. ldr r11, omap3_sdrc_rfr_ctrl_0 @ fetch addr from SRAM
  244. str r12, [r11] @ store
  245. #ifdef CONFIG_OMAP3_SDRC_AC_TIMING
  246. ldr r12, omap_sdrc_actim_ctrl_a_0_val
  247. ldr r11, omap3_sdrc_actim_ctrl_a_0
  248. str r12, [r11]
  249. ldr r12, omap_sdrc_actim_ctrl_b_0_val
  250. ldr r11, omap3_sdrc_actim_ctrl_b_0
  251. str r12, [r11]
  252. ldr r12, omap_sdrc_mr_0_val
  253. ldr r11, omap3_sdrc_mr_0
  254. str r12, [r11]
  255. #endif
  256. ldr r12, omap_sdrc_rfr_ctrl_1_val
  257. cmp r12, #0 @ if SDRC_RFR_CTRL_1 is 0,
  258. beq skip_cs1_prog @ do not program cs1 params
  259. ldr r11, omap3_sdrc_rfr_ctrl_1
  260. str r12, [r11]
  261. #ifdef CONFIG_OMAP3_SDRC_AC_TIMING
  262. ldr r12, omap_sdrc_actim_ctrl_a_1_val
  263. ldr r11, omap3_sdrc_actim_ctrl_a_1
  264. str r12, [r11]
  265. ldr r12, omap_sdrc_actim_ctrl_b_1_val
  266. ldr r11, omap3_sdrc_actim_ctrl_b_1
  267. str r12, [r11]
  268. ldr r12, omap_sdrc_mr_1_val
  269. ldr r11, omap3_sdrc_mr_1
  270. str r12, [r11]
  271. #endif
  272. skip_cs1_prog:
  273. ldr r12, [r11] @ posted-write barrier for SDRC
  274. bx lr
  275. .align
  276. omap3_sdrc_power:
  277. .word OMAP34XX_SDRC_REGADDR(SDRC_POWER)
  278. omap3_cm_clksel1_pll:
  279. .word OMAP34XX_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
  280. omap3_cm_idlest1_core:
  281. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST)
  282. omap3_cm_iclken1_core:
  283. .word OMAP34XX_CM_REGADDR(CORE_MOD, CM_ICLKEN1)
  284. omap3_sdrc_rfr_ctrl_0:
  285. .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_0)
  286. omap3_sdrc_rfr_ctrl_1:
  287. .word OMAP34XX_SDRC_REGADDR(SDRC_RFR_CTRL_1)
  288. omap3_sdrc_actim_ctrl_a_0:
  289. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_0)
  290. omap3_sdrc_actim_ctrl_a_1:
  291. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_A_1)
  292. omap3_sdrc_actim_ctrl_b_0:
  293. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_0)
  294. omap3_sdrc_actim_ctrl_b_1:
  295. .word OMAP34XX_SDRC_REGADDR(SDRC_ACTIM_CTRL_B_1)
  296. omap3_sdrc_mr_0:
  297. .word OMAP34XX_SDRC_REGADDR(SDRC_MR_0)
  298. omap3_sdrc_mr_1:
  299. .word OMAP34XX_SDRC_REGADDR(SDRC_MR_1)
  300. omap_sdrc_rfr_ctrl_0_val:
  301. .word 0xDEADBEEF
  302. omap_sdrc_rfr_ctrl_1_val:
  303. .word 0xDEADBEEF
  304. omap_sdrc_actim_ctrl_a_0_val:
  305. .word 0xDEADBEEF
  306. omap_sdrc_actim_ctrl_a_1_val:
  307. .word 0xDEADBEEF
  308. omap_sdrc_actim_ctrl_b_0_val:
  309. .word 0xDEADBEEF
  310. omap_sdrc_actim_ctrl_b_1_val:
  311. .word 0xDEADBEEF
  312. omap_sdrc_mr_0_val:
  313. .word 0xDEADBEEF
  314. omap_sdrc_mr_1_val:
  315. .word 0xDEADBEEF
  316. omap3_sdrc_dlla_status:
  317. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
  318. omap3_sdrc_dlla_ctrl:
  319. .word OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
  320. core_m2_mask_val:
  321. .word 0x07FFFFFF
  322. ENDPROC(omap3_sram_configure_core_dpll)
  323. ENTRY(omap3_sram_configure_core_dpll_sz)
  324. .word . - omap3_sram_configure_core_dpll