sram34xx.S 11 KB

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