sram-fn.S 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*
  2. * linux/arch/arm/mach-omap2/sram-fn.S
  3. *
  4. * Omap2 specific functions that need to be run in internal SRAM
  5. *
  6. * (C) Copyright 2004
  7. * Texas Instruments, <www.ti.com>
  8. * Richard Woodruff <r-woodruff2@ti.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <linux/linkage.h>
  26. #include <asm/assembler.h>
  27. #include <asm/arch/io.h>
  28. #include <asm/hardware.h>
  29. #include "prcm-regs.h"
  30. #define TIMER_32KSYNCT_CR_V IO_ADDRESS(OMAP24XX_32KSYNCT_BASE + 0x010)
  31. #define CM_CLKSEL2_PLL_V IO_ADDRESS(OMAP24XX_PRCM_BASE + 0x544)
  32. #define PRCM_VOLTCTRL_V IO_ADDRESS(OMAP24XX_PRCM_BASE + 0x050)
  33. #define PRCM_CLKCFG_CTRL_V IO_ADDRESS(OMAP24XX_PRCM_BASE + 0x080)
  34. #define CM_CLKEN_PLL_V IO_ADDRESS(OMAP24XX_PRCM_BASE + 0x500)
  35. #define CM_IDLEST_CKGEN_V IO_ADDRESS(OMAP24XX_PRCM_BASE + 0x520)
  36. #define CM_CLKSEL1_PLL_V IO_ADDRESS(OMAP24XX_PRCM_BASE + 0x540)
  37. #define SDRC_DLLA_CTRL_V IO_ADDRESS(OMAP24XX_SDRC_BASE + 0x060)
  38. #define SDRC_RFR_CTRL_V IO_ADDRESS(OMAP24XX_SDRC_BASE + 0x0a4)
  39. .text
  40. ENTRY(sram_ddr_init)
  41. stmfd sp!, {r0 - r12, lr} @ save registers on stack
  42. mov r12, r2 @ capture CS1 vs CS0
  43. mov r8, r3 @ capture force parameter
  44. /* frequency shift down */
  45. ldr r2, cm_clksel2_pll @ get address of dpllout reg
  46. mov r3, #0x1 @ value for 1x operation
  47. str r3, [r2] @ go to L1-freq operation
  48. /* voltage shift down */
  49. mov r9, #0x1 @ set up for L1 voltage call
  50. bl voltage_shift @ go drop voltage
  51. /* dll lock mode */
  52. ldr r11, sdrc_dlla_ctrl @ addr of dlla ctrl
  53. ldr r10, [r11] @ get current val
  54. cmp r12, #0x1 @ cs1 base (2422 es2.05/1)
  55. addeq r11, r11, #0x8 @ if cs1 base, move to DLLB
  56. mvn r9, #0x4 @ mask to get clear bit2
  57. and r10, r10, r9 @ clear bit2 for lock mode.
  58. orr r10, r10, #0x8 @ make sure DLL on (es2 bit pos)
  59. orr r10, r10, #0x2 @ 90 degree phase for all below 133Mhz
  60. str r10, [r11] @ commit to DLLA_CTRL
  61. bl i_dll_wait @ wait for dll to lock
  62. /* get dll value */
  63. add r11, r11, #0x4 @ get addr of status reg
  64. ldr r10, [r11] @ get locked value
  65. /* voltage shift up */
  66. mov r9, #0x0 @ shift back to L0-voltage
  67. bl voltage_shift @ go raise voltage
  68. /* frequency shift up */
  69. mov r3, #0x2 @ value for 2x operation
  70. str r3, [r2] @ go to L0-freq operation
  71. /* reset entry mode for dllctrl */
  72. sub r11, r11, #0x4 @ move from status to ctrl
  73. cmp r12, #0x1 @ normalize if cs1 based
  74. subeq r11, r11, #0x8 @ possibly back to DLLA
  75. cmp r8, #0x1 @ if forced unlock exit
  76. orreq r1, r1, #0x4 @ make sure exit with unlocked value
  77. str r1, [r11] @ restore DLLA_CTRL high value
  78. add r11, r11, #0x8 @ move to DLLB_CTRL addr
  79. str r1, [r11] @ set value DLLB_CTRL
  80. bl i_dll_wait @ wait for possible lock
  81. /* set up for return, DDR should be good */
  82. str r10, [r0] @ write dll_status and return counter
  83. ldmfd sp!, {r0 - r12, pc} @ restore regs and return
  84. /* ensure the DLL has relocked */
  85. i_dll_wait:
  86. mov r4, #0x800 @ delay DLL relock, min 0x400 L3 clocks
  87. i_dll_delay:
  88. subs r4, r4, #0x1
  89. bne i_dll_delay
  90. mov pc, lr
  91. /*
  92. * shift up or down voltage, use R9 as input to tell level.
  93. * wait for it to finish, use 32k sync counter, 1tick=31uS.
  94. */
  95. voltage_shift:
  96. ldr r4, prcm_voltctrl @ get addr of volt ctrl.
  97. ldr r5, [r4] @ get value.
  98. ldr r6, prcm_mask_val @ get value of mask
  99. and r5, r5, r6 @ apply mask to clear bits
  100. orr r5, r5, r9 @ bulld value for L0/L1-volt operation.
  101. str r5, [r4] @ set up for change.
  102. mov r3, #0x4000 @ get val for force
  103. orr r5, r5, r3 @ build value for force
  104. str r5, [r4] @ Force transition to L1
  105. ldr r3, timer_32ksynct_cr @ get addr of counter
  106. ldr r5, [r3] @ get value
  107. add r5, r5, #0x3 @ give it at most 93uS
  108. volt_delay:
  109. ldr r7, [r3] @ get timer value
  110. cmp r5, r7 @ time up?
  111. bhi volt_delay @ not yet->branch
  112. mov pc, lr @ back to caller.
  113. /* relative load constants */
  114. cm_clksel2_pll:
  115. .word CM_CLKSEL2_PLL_V
  116. sdrc_dlla_ctrl:
  117. .word SDRC_DLLA_CTRL_V
  118. prcm_voltctrl:
  119. .word PRCM_VOLTCTRL_V
  120. prcm_mask_val:
  121. .word 0xFFFF3FFC
  122. timer_32ksynct_cr:
  123. .word TIMER_32KSYNCT_CR_V
  124. ENTRY(sram_ddr_init_sz)
  125. .word . - sram_ddr_init
  126. /*
  127. * Reprograms memory timings.
  128. * r0 = [PRCM_FULL | PRCM_HALF] r1 = SDRC_DLLA_CTRL value r2 = [DDR | SDR]
  129. * PRCM_FULL = 2, PRCM_HALF = 1, DDR = 1, SDR = 0
  130. */
  131. ENTRY(sram_reprogram_sdrc)
  132. stmfd sp!, {r0 - r10, lr} @ save registers on stack
  133. mov r3, #0x0 @ clear for mrc call
  134. mcr p15, 0, r3, c7, c10, 4 @ memory barrier, finish ARM SDR/DDR
  135. nop
  136. nop
  137. ldr r6, ddr_sdrc_rfr_ctrl @ get addr of refresh reg
  138. ldr r5, [r6] @ get value
  139. mov r5, r5, lsr #8 @ isolate rfr field and drop burst
  140. cmp r0, #0x1 @ going to half speed?
  141. movne r9, #0x0 @ if up set flag up for pre up, hi volt
  142. blne voltage_shift_c @ adjust voltage
  143. cmp r0, #0x1 @ going to half speed (post branch link)
  144. moveq r5, r5, lsr #1 @ divide by 2 if to half
  145. movne r5, r5, lsl #1 @ mult by 2 if to full
  146. mov r5, r5, lsl #8 @ put rfr field back into place
  147. add r5, r5, #0x1 @ turn on burst of 1
  148. ldr r4, ddr_cm_clksel2_pll @ get address of out reg
  149. ldr r3, [r4] @ get curr value
  150. orr r3, r3, #0x3
  151. bic r3, r3, #0x3 @ clear lower bits
  152. orr r3, r3, r0 @ new state value
  153. str r3, [r4] @ set new state (pll/x, x=1 or 2)
  154. nop
  155. nop
  156. moveq r9, #0x1 @ if speed down, post down, drop volt
  157. bleq voltage_shift_c
  158. mcr p15, 0, r3, c7, c10, 4 @ memory barrier
  159. str r5, [r6] @ set new RFR_1 value
  160. add r6, r6, #0x30 @ get RFR_2 addr
  161. str r5, [r6] @ set RFR_2
  162. nop
  163. cmp r2, #0x1 @ (SDR or DDR) do we need to adjust DLL
  164. bne freq_out @ leave if SDR, no DLL function
  165. /* With DDR, we need to take care of the DLL for the frequency change */
  166. ldr r2, ddr_sdrc_dlla_ctrl @ addr of dlla ctrl
  167. str r1, [r2] @ write out new SDRC_DLLA_CTRL
  168. add r2, r2, #0x8 @ addr to SDRC_DLLB_CTRL
  169. str r1, [r2] @ commit to SDRC_DLLB_CTRL
  170. mov r1, #0x2000 @ wait DLL relock, min 0x400 L3 clocks
  171. dll_wait:
  172. subs r1, r1, #0x1
  173. bne dll_wait
  174. freq_out:
  175. ldmfd sp!, {r0 - r10, pc} @ restore regs and return
  176. /*
  177. * shift up or down voltage, use R9 as input to tell level.
  178. * wait for it to finish, use 32k sync counter, 1tick=31uS.
  179. */
  180. voltage_shift_c:
  181. ldr r10, ddr_prcm_voltctrl @ get addr of volt ctrl
  182. ldr r8, [r10] @ get value
  183. ldr r7, ddr_prcm_mask_val @ get value of mask
  184. and r8, r8, r7 @ apply mask to clear bits
  185. orr r8, r8, r9 @ bulld value for L0/L1-volt operation.
  186. str r8, [r10] @ set up for change.
  187. mov r7, #0x4000 @ get val for force
  188. orr r8, r8, r7 @ build value for force
  189. str r8, [r10] @ Force transition to L1
  190. ldr r10, ddr_timer_32ksynct @ get addr of counter
  191. ldr r8, [r10] @ get value
  192. add r8, r8, #0x2 @ give it at most 62uS (min 31+)
  193. volt_delay_c:
  194. ldr r7, [r10] @ get timer value
  195. cmp r8, r7 @ time up?
  196. bhi volt_delay_c @ not yet->branch
  197. mov pc, lr @ back to caller
  198. ddr_cm_clksel2_pll:
  199. .word CM_CLKSEL2_PLL_V
  200. ddr_sdrc_dlla_ctrl:
  201. .word SDRC_DLLA_CTRL_V
  202. ddr_sdrc_rfr_ctrl:
  203. .word SDRC_RFR_CTRL_V
  204. ddr_prcm_voltctrl:
  205. .word PRCM_VOLTCTRL_V
  206. ddr_prcm_mask_val:
  207. .word 0xFFFF3FFC
  208. ddr_timer_32ksynct:
  209. .word TIMER_32KSYNCT_CR_V
  210. ENTRY(sram_reprogram_sdrc_sz)
  211. .word . - sram_reprogram_sdrc
  212. /*
  213. * Set dividers and pll. Also recalculate DLL value for DDR and unlock mode.
  214. */
  215. ENTRY(sram_set_prcm)
  216. stmfd sp!, {r0-r12, lr} @ regs to stack
  217. adr r4, pbegin @ addr of preload start
  218. adr r8, pend @ addr of preload end
  219. mcrr p15, 1, r8, r4, c12 @ preload into icache
  220. pbegin:
  221. /* move into fast relock bypass */
  222. ldr r8, pll_ctl @ get addr
  223. ldr r5, [r8] @ get val
  224. mvn r6, #0x3 @ clear mask
  225. and r5, r5, r6 @ clear field
  226. orr r7, r5, #0x2 @ fast relock val
  227. str r7, [r8] @ go to fast relock
  228. ldr r4, pll_stat @ addr of stat
  229. block:
  230. /* wait for bypass */
  231. ldr r8, [r4] @ stat value
  232. and r8, r8, #0x3 @ mask for stat
  233. cmp r8, #0x1 @ there yet
  234. bne block @ loop if not
  235. /* set new dpll dividers _after_ in bypass */
  236. ldr r4, pll_div @ get addr
  237. str r0, [r4] @ set dpll ctrl val
  238. ldr r4, set_config @ get addr
  239. mov r8, #1 @ valid cfg msk
  240. str r8, [r4] @ make dividers take
  241. mov r4, #100 @ dead spin a bit
  242. wait_a_bit:
  243. subs r4, r4, #1 @ dec loop
  244. bne wait_a_bit @ delay done?
  245. /* check if staying in bypass */
  246. cmp r2, #0x1 @ stay in bypass?
  247. beq pend @ jump over dpll relock
  248. /* relock DPLL with new vals */
  249. ldr r5, pll_stat @ get addr
  250. ldr r4, pll_ctl @ get addr
  251. orr r8, r7, #0x3 @ val for lock dpll
  252. str r8, [r4] @ set val
  253. mov r0, #1000 @ dead spin a bit
  254. wait_more:
  255. subs r0, r0, #1 @ dec loop
  256. bne wait_more @ delay done?
  257. wait_lock:
  258. ldr r8, [r5] @ get lock val
  259. and r8, r8, #3 @ isolate field
  260. cmp r8, #2 @ locked?
  261. bne wait_lock @ wait if not
  262. pend:
  263. /* update memory timings & briefly lock dll */
  264. ldr r4, sdrc_rfr @ get addr
  265. str r1, [r4] @ update refresh timing
  266. ldr r11, dlla_ctrl @ get addr of DLLA ctrl
  267. ldr r10, [r11] @ get current val
  268. mvn r9, #0x4 @ mask to get clear bit2
  269. and r10, r10, r9 @ clear bit2 for lock mode
  270. orr r10, r10, #0x8 @ make sure DLL on (es2 bit pos)
  271. str r10, [r11] @ commit to DLLA_CTRL
  272. add r11, r11, #0x8 @ move to dllb
  273. str r10, [r11] @ hit DLLB also
  274. mov r4, #0x800 @ relock time (min 0x400 L3 clocks)
  275. wait_dll_lock:
  276. subs r4, r4, #0x1
  277. bne wait_dll_lock
  278. nop
  279. ldmfd sp!, {r0-r12, pc} @ restore regs and return
  280. set_config:
  281. .word PRCM_CLKCFG_CTRL_V
  282. pll_ctl:
  283. .word CM_CLKEN_PLL_V
  284. pll_stat:
  285. .word CM_IDLEST_CKGEN_V
  286. pll_div:
  287. .word CM_CLKSEL1_PLL_V
  288. sdrc_rfr:
  289. .word SDRC_RFR_CTRL_V
  290. dlla_ctrl:
  291. .word SDRC_DLLA_CTRL_V
  292. ENTRY(sram_set_prcm_sz)
  293. .word . - sram_set_prcm