sram243x.S 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/arch/arm/mach-omap2/sram243x.S
  4. *
  5. * Omap2 specific functions that need to be run in internal SRAM
  6. *
  7. * (C) Copyright 2004
  8. * Texas Instruments, <www.ti.com>
  9. * Richard Woodruff <[email protected]>
  10. *
  11. * Richard Woodruff notes that any changes to this code must be carefully
  12. * audited and tested to ensure that they don't cause a TLB miss while
  13. * the SDRAM is inaccessible. Such a situation will crash the system
  14. * since it will cause the ARM MMU to attempt to walk the page tables.
  15. * These crashes may be intermittent.
  16. */
  17. #include <linux/linkage.h>
  18. #include <asm/assembler.h>
  19. #include "soc.h"
  20. #include "iomap.h"
  21. #include "prm2xxx.h"
  22. #include "cm2xxx.h"
  23. #include "sdrc.h"
  24. .text
  25. .align 3
  26. ENTRY(omap243x_sram_ddr_init)
  27. stmfd sp!, {r0 - r12, lr} @ save registers on stack
  28. mov r12, r2 @ capture CS1 vs CS0
  29. mov r8, r3 @ capture force parameter
  30. /* frequency shift down */
  31. ldr r2, omap243x_sdi_cm_clksel2_pll @ get address of dpllout reg
  32. mov r3, #0x1 @ value for 1x operation
  33. str r3, [r2] @ go to L1-freq operation
  34. /* voltage shift down */
  35. mov r9, #0x1 @ set up for L1 voltage call
  36. bl voltage_shift @ go drop voltage
  37. /* dll lock mode */
  38. ldr r11, omap243x_sdi_sdrc_dlla_ctrl @ addr of dlla ctrl
  39. ldr r10, [r11] @ get current val
  40. cmp r12, #0x1 @ cs1 base (2422 es2.05/1)
  41. addeq r11, r11, #0x8 @ if cs1 base, move to DLLB
  42. mvn r9, #0x4 @ mask to get clear bit2
  43. and r10, r10, r9 @ clear bit2 for lock mode.
  44. orr r10, r10, #0x8 @ make sure DLL on (es2 bit pos)
  45. orr r10, r10, #0x2 @ 90 degree phase for all below 133MHz
  46. str r10, [r11] @ commit to DLLA_CTRL
  47. bl i_dll_wait @ wait for dll to lock
  48. /* get dll value */
  49. add r11, r11, #0x4 @ get addr of status reg
  50. ldr r10, [r11] @ get locked value
  51. /* voltage shift up */
  52. mov r9, #0x0 @ shift back to L0-voltage
  53. bl voltage_shift @ go raise voltage
  54. /* frequency shift up */
  55. mov r3, #0x2 @ value for 2x operation
  56. str r3, [r2] @ go to L0-freq operation
  57. /* reset entry mode for dllctrl */
  58. sub r11, r11, #0x4 @ move from status to ctrl
  59. cmp r12, #0x1 @ normalize if cs1 based
  60. subeq r11, r11, #0x8 @ possibly back to DLLA
  61. cmp r8, #0x1 @ if forced unlock exit
  62. orreq r1, r1, #0x4 @ make sure exit with unlocked value
  63. str r1, [r11] @ restore DLLA_CTRL high value
  64. add r11, r11, #0x8 @ move to DLLB_CTRL addr
  65. str r1, [r11] @ set value DLLB_CTRL
  66. bl i_dll_wait @ wait for possible lock
  67. /* set up for return, DDR should be good */
  68. str r10, [r0] @ write dll_status and return counter
  69. ldmfd sp!, {r0 - r12, pc} @ restore regs and return
  70. /* ensure the DLL has relocked */
  71. i_dll_wait:
  72. mov r4, #0x800 @ delay DLL relock, min 0x400 L3 clocks
  73. i_dll_delay:
  74. subs r4, r4, #0x1
  75. bne i_dll_delay
  76. ret lr
  77. /*
  78. * shift up or down voltage, use R9 as input to tell level.
  79. * wait for it to finish, use 32k sync counter, 1tick=31uS.
  80. */
  81. voltage_shift:
  82. ldr r4, omap243x_sdi_prcm_voltctrl @ get addr of volt ctrl.
  83. ldr r5, [r4] @ get value.
  84. ldr r6, prcm_mask_val @ get value of mask
  85. and r5, r5, r6 @ apply mask to clear bits
  86. orr r5, r5, r9 @ bulld value for L0/L1-volt operation.
  87. str r5, [r4] @ set up for change.
  88. mov r3, #0x4000 @ get val for force
  89. orr r5, r5, r3 @ build value for force
  90. str r5, [r4] @ Force transition to L1
  91. ldr r3, omap243x_sdi_timer_32ksynct_cr @ get addr of counter
  92. ldr r5, [r3] @ get value
  93. add r5, r5, #0x3 @ give it at most 93uS
  94. volt_delay:
  95. ldr r7, [r3] @ get timer value
  96. cmp r5, r7 @ time up?
  97. bhi volt_delay @ not yet->branch
  98. ret lr @ back to caller.
  99. omap243x_sdi_cm_clksel2_pll:
  100. .word OMAP2430_CM_REGADDR(PLL_MOD, CM_CLKSEL2)
  101. omap243x_sdi_sdrc_dlla_ctrl:
  102. .word OMAP243X_SDRC_REGADDR(SDRC_DLLA_CTRL)
  103. omap243x_sdi_prcm_voltctrl:
  104. .word OMAP2430_PRCM_VOLTCTRL
  105. prcm_mask_val:
  106. .word 0xFFFF3FFC
  107. omap243x_sdi_timer_32ksynct_cr:
  108. .word OMAP2_L4_IO_ADDRESS(OMAP2430_32KSYNCT_BASE + 0x010)
  109. ENTRY(omap243x_sram_ddr_init_sz)
  110. .word . - omap243x_sram_ddr_init
  111. /*
  112. * Reprograms memory timings.
  113. * r0 = [PRCM_FULL | PRCM_HALF] r1 = SDRC_DLLA_CTRL value r2 = [DDR | SDR]
  114. * PRCM_FULL = 2, PRCM_HALF = 1, DDR = 1, SDR = 0
  115. */
  116. .align 3
  117. ENTRY(omap243x_sram_reprogram_sdrc)
  118. stmfd sp!, {r0 - r10, lr} @ save registers on stack
  119. mov r3, #0x0 @ clear for mrc call
  120. mcr p15, 0, r3, c7, c10, 4 @ memory barrier, finish ARM SDR/DDR
  121. nop
  122. nop
  123. ldr r6, omap243x_srs_sdrc_rfr_ctrl @ get addr of refresh reg
  124. ldr r5, [r6] @ get value
  125. mov r5, r5, lsr #8 @ isolate rfr field and drop burst
  126. cmp r0, #0x1 @ going to half speed?
  127. movne r9, #0x0 @ if up set flag up for pre up, hi volt
  128. blne voltage_shift_c @ adjust voltage
  129. cmp r0, #0x1 @ going to half speed (post branch link)
  130. moveq r5, r5, lsr #1 @ divide by 2 if to half
  131. movne r5, r5, lsl #1 @ mult by 2 if to full
  132. mov r5, r5, lsl #8 @ put rfr field back into place
  133. add r5, r5, #0x1 @ turn on burst of 1
  134. ldr r4, omap243x_srs_cm_clksel2_pll @ get address of out reg
  135. ldr r3, [r4] @ get curr value
  136. orr r3, r3, #0x3
  137. bic r3, r3, #0x3 @ clear lower bits
  138. orr r3, r3, r0 @ new state value
  139. str r3, [r4] @ set new state (pll/x, x=1 or 2)
  140. nop
  141. nop
  142. moveq r9, #0x1 @ if speed down, post down, drop volt
  143. bleq voltage_shift_c
  144. mcr p15, 0, r3, c7, c10, 4 @ memory barrier
  145. str r5, [r6] @ set new RFR_1 value
  146. add r6, r6, #0x30 @ get RFR_2 addr
  147. str r5, [r6] @ set RFR_2
  148. nop
  149. cmp r2, #0x1 @ (SDR or DDR) do we need to adjust DLL
  150. bne freq_out @ leave if SDR, no DLL function
  151. /* With DDR, we need to take care of the DLL for the frequency change */
  152. ldr r2, omap243x_srs_sdrc_dlla_ctrl @ addr of dlla ctrl
  153. str r1, [r2] @ write out new SDRC_DLLA_CTRL
  154. add r2, r2, #0x8 @ addr to SDRC_DLLB_CTRL
  155. str r1, [r2] @ commit to SDRC_DLLB_CTRL
  156. mov r1, #0x2000 @ wait DLL relock, min 0x400 L3 clocks
  157. dll_wait:
  158. subs r1, r1, #0x1
  159. bne dll_wait
  160. freq_out:
  161. ldmfd sp!, {r0 - r10, pc} @ restore regs and return
  162. /*
  163. * shift up or down voltage, use R9 as input to tell level.
  164. * wait for it to finish, use 32k sync counter, 1tick=31uS.
  165. */
  166. voltage_shift_c:
  167. ldr r10, omap243x_srs_prcm_voltctrl @ get addr of volt ctrl
  168. ldr r8, [r10] @ get value
  169. ldr r7, ddr_prcm_mask_val @ get value of mask
  170. and r8, r8, r7 @ apply mask to clear bits
  171. orr r8, r8, r9 @ bulld value for L0/L1-volt operation.
  172. str r8, [r10] @ set up for change.
  173. mov r7, #0x4000 @ get val for force
  174. orr r8, r8, r7 @ build value for force
  175. str r8, [r10] @ Force transition to L1
  176. ldr r10, omap243x_srs_timer_32ksynct @ get addr of counter
  177. ldr r8, [r10] @ get value
  178. add r8, r8, #0x2 @ give it at most 62uS (min 31+)
  179. volt_delay_c:
  180. ldr r7, [r10] @ get timer value
  181. cmp r8, r7 @ time up?
  182. bhi volt_delay_c @ not yet->branch
  183. ret lr @ back to caller
  184. omap243x_srs_cm_clksel2_pll:
  185. .word OMAP2430_CM_REGADDR(PLL_MOD, CM_CLKSEL2)
  186. omap243x_srs_sdrc_dlla_ctrl:
  187. .word OMAP243X_SDRC_REGADDR(SDRC_DLLA_CTRL)
  188. omap243x_srs_sdrc_rfr_ctrl:
  189. .word OMAP243X_SDRC_REGADDR(SDRC_RFR_CTRL_0)
  190. omap243x_srs_prcm_voltctrl:
  191. .word OMAP2430_PRCM_VOLTCTRL
  192. ddr_prcm_mask_val:
  193. .word 0xFFFF3FFC
  194. omap243x_srs_timer_32ksynct:
  195. .word OMAP2_L4_IO_ADDRESS(OMAP2430_32KSYNCT_BASE + 0x010)
  196. ENTRY(omap243x_sram_reprogram_sdrc_sz)
  197. .word . - omap243x_sram_reprogram_sdrc
  198. /*
  199. * Set dividers and pll. Also recalculate DLL value for DDR and unlock mode.
  200. */
  201. .align 3
  202. ENTRY(omap243x_sram_set_prcm)
  203. stmfd sp!, {r0-r12, lr} @ regs to stack
  204. adr r4, pbegin @ addr of preload start
  205. adr r8, pend @ addr of preload end
  206. mcrr p15, 1, r8, r4, c12 @ preload into icache
  207. pbegin:
  208. /* move into fast relock bypass */
  209. ldr r8, omap243x_ssp_pll_ctl @ get addr
  210. ldr r5, [r8] @ get val
  211. mvn r6, #0x3 @ clear mask
  212. and r5, r5, r6 @ clear field
  213. orr r7, r5, #0x2 @ fast relock val
  214. str r7, [r8] @ go to fast relock
  215. ldr r4, omap243x_ssp_pll_stat @ addr of stat
  216. block:
  217. /* wait for bypass */
  218. ldr r8, [r4] @ stat value
  219. and r8, r8, #0x3 @ mask for stat
  220. cmp r8, #0x1 @ there yet
  221. bne block @ loop if not
  222. /* set new dpll dividers _after_ in bypass */
  223. ldr r4, omap243x_ssp_pll_div @ get addr
  224. str r0, [r4] @ set dpll ctrl val
  225. ldr r4, omap243x_ssp_set_config @ get addr
  226. mov r8, #1 @ valid cfg msk
  227. str r8, [r4] @ make dividers take
  228. mov r4, #100 @ dead spin a bit
  229. wait_a_bit:
  230. subs r4, r4, #1 @ dec loop
  231. bne wait_a_bit @ delay done?
  232. /* check if staying in bypass */
  233. cmp r2, #0x1 @ stay in bypass?
  234. beq pend @ jump over dpll relock
  235. /* relock DPLL with new vals */
  236. ldr r5, omap243x_ssp_pll_stat @ get addr
  237. ldr r4, omap243x_ssp_pll_ctl @ get addr
  238. orr r8, r7, #0x3 @ val for lock dpll
  239. str r8, [r4] @ set val
  240. mov r0, #1000 @ dead spin a bit
  241. wait_more:
  242. subs r0, r0, #1 @ dec loop
  243. bne wait_more @ delay done?
  244. wait_lock:
  245. ldr r8, [r5] @ get lock val
  246. and r8, r8, #3 @ isolate field
  247. cmp r8, #2 @ locked?
  248. bne wait_lock @ wait if not
  249. pend:
  250. /* update memory timings & briefly lock dll */
  251. ldr r4, omap243x_ssp_sdrc_rfr @ get addr
  252. str r1, [r4] @ update refresh timing
  253. ldr r11, omap243x_ssp_dlla_ctrl @ get addr of DLLA ctrl
  254. ldr r10, [r11] @ get current val
  255. mvn r9, #0x4 @ mask to get clear bit2
  256. and r10, r10, r9 @ clear bit2 for lock mode
  257. orr r10, r10, #0x8 @ make sure DLL on (es2 bit pos)
  258. str r10, [r11] @ commit to DLLA_CTRL
  259. add r11, r11, #0x8 @ move to dllb
  260. str r10, [r11] @ hit DLLB also
  261. mov r4, #0x800 @ relock time (min 0x400 L3 clocks)
  262. wait_dll_lock:
  263. subs r4, r4, #0x1
  264. bne wait_dll_lock
  265. nop
  266. ldmfd sp!, {r0-r12, pc} @ restore regs and return
  267. omap243x_ssp_set_config:
  268. .word OMAP2430_PRCM_CLKCFG_CTRL
  269. omap243x_ssp_pll_ctl:
  270. .word OMAP2430_CM_REGADDR(PLL_MOD, CM_CLKEN)
  271. omap243x_ssp_pll_stat:
  272. .word OMAP2430_CM_REGADDR(PLL_MOD, CM_IDLEST)
  273. omap243x_ssp_pll_div:
  274. .word OMAP2430_CM_REGADDR(PLL_MOD, CM_CLKSEL1)
  275. omap243x_ssp_sdrc_rfr:
  276. .word OMAP243X_SDRC_REGADDR(SDRC_RFR_CTRL_0)
  277. omap243x_ssp_dlla_ctrl:
  278. .word OMAP243X_SDRC_REGADDR(SDRC_DLLA_CTRL)
  279. ENTRY(omap243x_sram_set_prcm_sz)
  280. .word . - omap243x_sram_set_prcm