1*1a59d1b8SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */ 2373a6702STony Lindgren/* 3c2d43e39STony Lindgren * linux/arch/arm/mach-omap2/sram242x.S 4373a6702STony Lindgren * 5373a6702STony Lindgren * Omap2 specific functions that need to be run in internal SRAM 6373a6702STony Lindgren * 7373a6702STony Lindgren * (C) Copyright 2004 8373a6702STony Lindgren * Texas Instruments, <www.ti.com> 9373a6702STony Lindgren * Richard Woodruff <r-woodruff2@ti.com> 10373a6702STony Lindgren * 111124d2f9SPaul Walmsley * Richard Woodruff notes that any changes to this code must be carefully 121124d2f9SPaul Walmsley * audited and tested to ensure that they don't cause a TLB miss while 131124d2f9SPaul Walmsley * the SDRAM is inaccessible. Such a situation will crash the system 141124d2f9SPaul Walmsley * since it will cause the ARM MMU to attempt to walk the page tables. 151124d2f9SPaul Walmsley * These crashes may be intermittent. 16373a6702STony Lindgren */ 17373a6702STony Lindgren#include <linux/linkage.h> 18ee0839c2STony Lindgren 19373a6702STony Lindgren#include <asm/assembler.h> 20ee0839c2STony Lindgren 21dbc04161STony Lindgren#include "soc.h" 22ee0839c2STony Lindgren#include "iomap.h" 23139563adSPaul Walmsley#include "prm2xxx.h" 24ff4ae5d9SPaul Walmsley#include "cm2xxx.h" 25c2d43e39STony Lindgren#include "sdrc.h" 26373a6702STony Lindgren 27373a6702STony Lindgren .text 28373a6702STony Lindgren 29b6338bdcSJean Pihet .align 3 30c2d43e39STony LindgrenENTRY(omap242x_sram_ddr_init) 31373a6702STony Lindgren stmfd sp!, {r0 - r12, lr} @ save registers on stack 32373a6702STony Lindgren 33373a6702STony Lindgren mov r12, r2 @ capture CS1 vs CS0 34373a6702STony Lindgren mov r8, r3 @ capture force parameter 35373a6702STony Lindgren 36373a6702STony Lindgren /* frequency shift down */ 37c2d43e39STony Lindgren ldr r2, omap242x_sdi_cm_clksel2_pll @ get address of dpllout reg 38373a6702STony Lindgren mov r3, #0x1 @ value for 1x operation 39373a6702STony Lindgren str r3, [r2] @ go to L1-freq operation 40373a6702STony Lindgren 41373a6702STony Lindgren /* voltage shift down */ 42373a6702STony Lindgren mov r9, #0x1 @ set up for L1 voltage call 43373a6702STony Lindgren bl voltage_shift @ go drop voltage 44373a6702STony Lindgren 45373a6702STony Lindgren /* dll lock mode */ 46c2d43e39STony Lindgren ldr r11, omap242x_sdi_sdrc_dlla_ctrl @ addr of dlla ctrl 47373a6702STony Lindgren ldr r10, [r11] @ get current val 48373a6702STony Lindgren cmp r12, #0x1 @ cs1 base (2422 es2.05/1) 49373a6702STony Lindgren addeq r11, r11, #0x8 @ if cs1 base, move to DLLB 50373a6702STony Lindgren mvn r9, #0x4 @ mask to get clear bit2 51373a6702STony Lindgren and r10, r10, r9 @ clear bit2 for lock mode. 52373a6702STony Lindgren orr r10, r10, #0x8 @ make sure DLL on (es2 bit pos) 536a53bc75SRussell King orr r10, r10, #0x2 @ 90 degree phase for all below 133MHz 54373a6702STony Lindgren str r10, [r11] @ commit to DLLA_CTRL 55373a6702STony Lindgren bl i_dll_wait @ wait for dll to lock 56373a6702STony Lindgren 57373a6702STony Lindgren /* get dll value */ 58373a6702STony Lindgren add r11, r11, #0x4 @ get addr of status reg 59373a6702STony Lindgren ldr r10, [r11] @ get locked value 60373a6702STony Lindgren 61373a6702STony Lindgren /* voltage shift up */ 62373a6702STony Lindgren mov r9, #0x0 @ shift back to L0-voltage 63373a6702STony Lindgren bl voltage_shift @ go raise voltage 64373a6702STony Lindgren 65373a6702STony Lindgren /* frequency shift up */ 66373a6702STony Lindgren mov r3, #0x2 @ value for 2x operation 67373a6702STony Lindgren str r3, [r2] @ go to L0-freq operation 68373a6702STony Lindgren 69373a6702STony Lindgren /* reset entry mode for dllctrl */ 70373a6702STony Lindgren sub r11, r11, #0x4 @ move from status to ctrl 71373a6702STony Lindgren cmp r12, #0x1 @ normalize if cs1 based 72373a6702STony Lindgren subeq r11, r11, #0x8 @ possibly back to DLLA 73373a6702STony Lindgren cmp r8, #0x1 @ if forced unlock exit 74373a6702STony Lindgren orreq r1, r1, #0x4 @ make sure exit with unlocked value 75373a6702STony Lindgren str r1, [r11] @ restore DLLA_CTRL high value 76373a6702STony Lindgren add r11, r11, #0x8 @ move to DLLB_CTRL addr 77373a6702STony Lindgren str r1, [r11] @ set value DLLB_CTRL 78373a6702STony Lindgren bl i_dll_wait @ wait for possible lock 79373a6702STony Lindgren 80373a6702STony Lindgren /* set up for return, DDR should be good */ 81373a6702STony Lindgren str r10, [r0] @ write dll_status and return counter 82373a6702STony Lindgren ldmfd sp!, {r0 - r12, pc} @ restore regs and return 83373a6702STony Lindgren 84373a6702STony Lindgren /* ensure the DLL has relocked */ 85373a6702STony Lindgreni_dll_wait: 86373a6702STony Lindgren mov r4, #0x800 @ delay DLL relock, min 0x400 L3 clocks 87373a6702STony Lindgreni_dll_delay: 88373a6702STony Lindgren subs r4, r4, #0x1 89373a6702STony Lindgren bne i_dll_delay 906ebbf2ceSRussell King ret lr 91373a6702STony Lindgren 92373a6702STony Lindgren /* 93373a6702STony Lindgren * shift up or down voltage, use R9 as input to tell level. 94373a6702STony Lindgren * wait for it to finish, use 32k sync counter, 1tick=31uS. 95373a6702STony Lindgren */ 96373a6702STony Lindgrenvoltage_shift: 97c2d43e39STony Lindgren ldr r4, omap242x_sdi_prcm_voltctrl @ get addr of volt ctrl. 98373a6702STony Lindgren ldr r5, [r4] @ get value. 99373a6702STony Lindgren ldr r6, prcm_mask_val @ get value of mask 100373a6702STony Lindgren and r5, r5, r6 @ apply mask to clear bits 101373a6702STony Lindgren orr r5, r5, r9 @ bulld value for L0/L1-volt operation. 102373a6702STony Lindgren str r5, [r4] @ set up for change. 103373a6702STony Lindgren mov r3, #0x4000 @ get val for force 104373a6702STony Lindgren orr r5, r5, r3 @ build value for force 105373a6702STony Lindgren str r5, [r4] @ Force transition to L1 106373a6702STony Lindgren 107c2d43e39STony Lindgren ldr r3, omap242x_sdi_timer_32ksynct_cr @ get addr of counter 108373a6702STony Lindgren ldr r5, [r3] @ get value 109373a6702STony Lindgren add r5, r5, #0x3 @ give it at most 93uS 110373a6702STony Lindgrenvolt_delay: 111373a6702STony Lindgren ldr r7, [r3] @ get timer value 112373a6702STony Lindgren cmp r5, r7 @ time up? 113373a6702STony Lindgren bhi volt_delay @ not yet->branch 1146ebbf2ceSRussell King ret lr @ back to caller. 115373a6702STony Lindgren 116c2d43e39STony Lindgrenomap242x_sdi_cm_clksel2_pll: 117373a6702STony Lindgren .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL2) 118c2d43e39STony Lindgrenomap242x_sdi_sdrc_dlla_ctrl: 119373a6702STony Lindgren .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL) 120c2d43e39STony Lindgrenomap242x_sdi_prcm_voltctrl: 1218e3bd351STony Lindgren .word OMAP2420_PRCM_VOLTCTRL 122373a6702STony Lindgrenprcm_mask_val: 123373a6702STony Lindgren .word 0xFFFF3FFC 124c2d43e39STony Lindgrenomap242x_sdi_timer_32ksynct_cr: 125233fd64eSSantosh Shilimkar .word OMAP2_L4_IO_ADDRESS(OMAP2420_32KSYNCT_BASE + 0x010) 126c2d43e39STony LindgrenENTRY(omap242x_sram_ddr_init_sz) 127c2d43e39STony Lindgren .word . - omap242x_sram_ddr_init 128373a6702STony Lindgren 129373a6702STony Lindgren/* 130373a6702STony Lindgren * Reprograms memory timings. 131373a6702STony Lindgren * r0 = [PRCM_FULL | PRCM_HALF] r1 = SDRC_DLLA_CTRL value r2 = [DDR | SDR] 132373a6702STony Lindgren * PRCM_FULL = 2, PRCM_HALF = 1, DDR = 1, SDR = 0 133373a6702STony Lindgren */ 134b6338bdcSJean Pihet .align 3 135c2d43e39STony LindgrenENTRY(omap242x_sram_reprogram_sdrc) 136373a6702STony Lindgren stmfd sp!, {r0 - r10, lr} @ save registers on stack 137373a6702STony Lindgren mov r3, #0x0 @ clear for mrc call 138373a6702STony Lindgren mcr p15, 0, r3, c7, c10, 4 @ memory barrier, finish ARM SDR/DDR 139373a6702STony Lindgren nop 140373a6702STony Lindgren nop 141c2d43e39STony Lindgren ldr r6, omap242x_srs_sdrc_rfr_ctrl @ get addr of refresh reg 142373a6702STony Lindgren ldr r5, [r6] @ get value 143373a6702STony Lindgren mov r5, r5, lsr #8 @ isolate rfr field and drop burst 144373a6702STony Lindgren 145373a6702STony Lindgren cmp r0, #0x1 @ going to half speed? 146373a6702STony Lindgren movne r9, #0x0 @ if up set flag up for pre up, hi volt 147373a6702STony Lindgren 148373a6702STony Lindgren blne voltage_shift_c @ adjust voltage 149373a6702STony Lindgren 150373a6702STony Lindgren cmp r0, #0x1 @ going to half speed (post branch link) 151373a6702STony Lindgren moveq r5, r5, lsr #1 @ divide by 2 if to half 152373a6702STony Lindgren movne r5, r5, lsl #1 @ mult by 2 if to full 153373a6702STony Lindgren mov r5, r5, lsl #8 @ put rfr field back into place 154373a6702STony Lindgren add r5, r5, #0x1 @ turn on burst of 1 155c2d43e39STony Lindgren ldr r4, omap242x_srs_cm_clksel2_pll @ get address of out reg 156373a6702STony Lindgren ldr r3, [r4] @ get curr value 157373a6702STony Lindgren orr r3, r3, #0x3 158373a6702STony Lindgren bic r3, r3, #0x3 @ clear lower bits 159373a6702STony Lindgren orr r3, r3, r0 @ new state value 160373a6702STony Lindgren str r3, [r4] @ set new state (pll/x, x=1 or 2) 161373a6702STony Lindgren nop 162373a6702STony Lindgren nop 163373a6702STony Lindgren 164373a6702STony Lindgren moveq r9, #0x1 @ if speed down, post down, drop volt 165373a6702STony Lindgren bleq voltage_shift_c 166373a6702STony Lindgren 167373a6702STony Lindgren mcr p15, 0, r3, c7, c10, 4 @ memory barrier 168373a6702STony Lindgren str r5, [r6] @ set new RFR_1 value 169373a6702STony Lindgren add r6, r6, #0x30 @ get RFR_2 addr 170373a6702STony Lindgren str r5, [r6] @ set RFR_2 171373a6702STony Lindgren nop 172373a6702STony Lindgren cmp r2, #0x1 @ (SDR or DDR) do we need to adjust DLL 173373a6702STony Lindgren bne freq_out @ leave if SDR, no DLL function 174373a6702STony Lindgren 175373a6702STony Lindgren /* With DDR, we need to take care of the DLL for the frequency change */ 176c2d43e39STony Lindgren ldr r2, omap242x_srs_sdrc_dlla_ctrl @ addr of dlla ctrl 177373a6702STony Lindgren str r1, [r2] @ write out new SDRC_DLLA_CTRL 178373a6702STony Lindgren add r2, r2, #0x8 @ addr to SDRC_DLLB_CTRL 179373a6702STony Lindgren str r1, [r2] @ commit to SDRC_DLLB_CTRL 180373a6702STony Lindgren mov r1, #0x2000 @ wait DLL relock, min 0x400 L3 clocks 181373a6702STony Lindgrendll_wait: 182373a6702STony Lindgren subs r1, r1, #0x1 183373a6702STony Lindgren bne dll_wait 184373a6702STony Lindgrenfreq_out: 185373a6702STony Lindgren ldmfd sp!, {r0 - r10, pc} @ restore regs and return 186373a6702STony Lindgren 187373a6702STony Lindgren /* 188373a6702STony Lindgren * shift up or down voltage, use R9 as input to tell level. 189373a6702STony Lindgren * wait for it to finish, use 32k sync counter, 1tick=31uS. 190373a6702STony Lindgren */ 191373a6702STony Lindgrenvoltage_shift_c: 192c2d43e39STony Lindgren ldr r10, omap242x_srs_prcm_voltctrl @ get addr of volt ctrl 193373a6702STony Lindgren ldr r8, [r10] @ get value 194373a6702STony Lindgren ldr r7, ddr_prcm_mask_val @ get value of mask 195373a6702STony Lindgren and r8, r8, r7 @ apply mask to clear bits 196373a6702STony Lindgren orr r8, r8, r9 @ bulld value for L0/L1-volt operation. 197373a6702STony Lindgren str r8, [r10] @ set up for change. 198373a6702STony Lindgren mov r7, #0x4000 @ get val for force 199373a6702STony Lindgren orr r8, r8, r7 @ build value for force 200373a6702STony Lindgren str r8, [r10] @ Force transition to L1 201373a6702STony Lindgren 202c2d43e39STony Lindgren ldr r10, omap242x_srs_timer_32ksynct @ get addr of counter 203373a6702STony Lindgren ldr r8, [r10] @ get value 204373a6702STony Lindgren add r8, r8, #0x2 @ give it at most 62uS (min 31+) 205373a6702STony Lindgrenvolt_delay_c: 206373a6702STony Lindgren ldr r7, [r10] @ get timer value 207373a6702STony Lindgren cmp r8, r7 @ time up? 208373a6702STony Lindgren bhi volt_delay_c @ not yet->branch 2096ebbf2ceSRussell King ret lr @ back to caller 210373a6702STony Lindgren 211c2d43e39STony Lindgrenomap242x_srs_cm_clksel2_pll: 212373a6702STony Lindgren .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL2) 213c2d43e39STony Lindgrenomap242x_srs_sdrc_dlla_ctrl: 214373a6702STony Lindgren .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL) 215c2d43e39STony Lindgrenomap242x_srs_sdrc_rfr_ctrl: 216373a6702STony Lindgren .word OMAP242X_SDRC_REGADDR(SDRC_RFR_CTRL_0) 217c2d43e39STony Lindgrenomap242x_srs_prcm_voltctrl: 2188e3bd351STony Lindgren .word OMAP2420_PRCM_VOLTCTRL 219373a6702STony Lindgrenddr_prcm_mask_val: 220373a6702STony Lindgren .word 0xFFFF3FFC 221c2d43e39STony Lindgrenomap242x_srs_timer_32ksynct: 222233fd64eSSantosh Shilimkar .word OMAP2_L4_IO_ADDRESS(OMAP2420_32KSYNCT_BASE + 0x010) 223373a6702STony Lindgren 224c2d43e39STony LindgrenENTRY(omap242x_sram_reprogram_sdrc_sz) 225c2d43e39STony Lindgren .word . - omap242x_sram_reprogram_sdrc 226373a6702STony Lindgren 227373a6702STony Lindgren/* 228373a6702STony Lindgren * Set dividers and pll. Also recalculate DLL value for DDR and unlock mode. 229373a6702STony Lindgren */ 230b6338bdcSJean Pihet .align 3 231c2d43e39STony LindgrenENTRY(omap242x_sram_set_prcm) 232373a6702STony Lindgren stmfd sp!, {r0-r12, lr} @ regs to stack 233373a6702STony Lindgren adr r4, pbegin @ addr of preload start 234373a6702STony Lindgren adr r8, pend @ addr of preload end 235373a6702STony Lindgren mcrr p15, 1, r8, r4, c12 @ preload into icache 236373a6702STony Lindgrenpbegin: 237373a6702STony Lindgren /* move into fast relock bypass */ 238c2d43e39STony Lindgren ldr r8, omap242x_ssp_pll_ctl @ get addr 239373a6702STony Lindgren ldr r5, [r8] @ get val 240373a6702STony Lindgren mvn r6, #0x3 @ clear mask 241373a6702STony Lindgren and r5, r5, r6 @ clear field 242373a6702STony Lindgren orr r7, r5, #0x2 @ fast relock val 243373a6702STony Lindgren str r7, [r8] @ go to fast relock 244c2d43e39STony Lindgren ldr r4, omap242x_ssp_pll_stat @ addr of stat 245373a6702STony Lindgrenblock: 246373a6702STony Lindgren /* wait for bypass */ 247373a6702STony Lindgren ldr r8, [r4] @ stat value 248373a6702STony Lindgren and r8, r8, #0x3 @ mask for stat 249373a6702STony Lindgren cmp r8, #0x1 @ there yet 250373a6702STony Lindgren bne block @ loop if not 251373a6702STony Lindgren 252373a6702STony Lindgren /* set new dpll dividers _after_ in bypass */ 253c2d43e39STony Lindgren ldr r4, omap242x_ssp_pll_div @ get addr 254373a6702STony Lindgren str r0, [r4] @ set dpll ctrl val 255373a6702STony Lindgren 256c2d43e39STony Lindgren ldr r4, omap242x_ssp_set_config @ get addr 257373a6702STony Lindgren mov r8, #1 @ valid cfg msk 258373a6702STony Lindgren str r8, [r4] @ make dividers take 259373a6702STony Lindgren 260373a6702STony Lindgren mov r4, #100 @ dead spin a bit 261373a6702STony Lindgrenwait_a_bit: 262373a6702STony Lindgren subs r4, r4, #1 @ dec loop 263373a6702STony Lindgren bne wait_a_bit @ delay done? 264373a6702STony Lindgren 265373a6702STony Lindgren /* check if staying in bypass */ 266373a6702STony Lindgren cmp r2, #0x1 @ stay in bypass? 267373a6702STony Lindgren beq pend @ jump over dpll relock 268373a6702STony Lindgren 269373a6702STony Lindgren /* relock DPLL with new vals */ 270c2d43e39STony Lindgren ldr r5, omap242x_ssp_pll_stat @ get addr 271c2d43e39STony Lindgren ldr r4, omap242x_ssp_pll_ctl @ get addr 272373a6702STony Lindgren orr r8, r7, #0x3 @ val for lock dpll 273373a6702STony Lindgren str r8, [r4] @ set val 274373a6702STony Lindgren mov r0, #1000 @ dead spin a bit 275373a6702STony Lindgrenwait_more: 276373a6702STony Lindgren subs r0, r0, #1 @ dec loop 277373a6702STony Lindgren bne wait_more @ delay done? 278373a6702STony Lindgrenwait_lock: 279373a6702STony Lindgren ldr r8, [r5] @ get lock val 280373a6702STony Lindgren and r8, r8, #3 @ isolate field 281373a6702STony Lindgren cmp r8, #2 @ locked? 282373a6702STony Lindgren bne wait_lock @ wait if not 283373a6702STony Lindgrenpend: 284373a6702STony Lindgren /* update memory timings & briefly lock dll */ 285c2d43e39STony Lindgren ldr r4, omap242x_ssp_sdrc_rfr @ get addr 286373a6702STony Lindgren str r1, [r4] @ update refresh timing 287c2d43e39STony Lindgren ldr r11, omap242x_ssp_dlla_ctrl @ get addr of DLLA ctrl 288373a6702STony Lindgren ldr r10, [r11] @ get current val 289373a6702STony Lindgren mvn r9, #0x4 @ mask to get clear bit2 290373a6702STony Lindgren and r10, r10, r9 @ clear bit2 for lock mode 291373a6702STony Lindgren orr r10, r10, #0x8 @ make sure DLL on (es2 bit pos) 292373a6702STony Lindgren str r10, [r11] @ commit to DLLA_CTRL 293373a6702STony Lindgren add r11, r11, #0x8 @ move to dllb 294373a6702STony Lindgren str r10, [r11] @ hit DLLB also 295373a6702STony Lindgren 296373a6702STony Lindgren mov r4, #0x800 @ relock time (min 0x400 L3 clocks) 297373a6702STony Lindgrenwait_dll_lock: 298373a6702STony Lindgren subs r4, r4, #0x1 299373a6702STony Lindgren bne wait_dll_lock 300373a6702STony Lindgren nop 301373a6702STony Lindgren ldmfd sp!, {r0-r12, pc} @ restore regs and return 302373a6702STony Lindgren 303c2d43e39STony Lindgrenomap242x_ssp_set_config: 3048e3bd351STony Lindgren .word OMAP2420_PRCM_CLKCFG_CTRL 305c2d43e39STony Lindgrenomap242x_ssp_pll_ctl: 306c2d43e39STony Lindgren .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKEN) 307c2d43e39STony Lindgrenomap242x_ssp_pll_stat: 308c2d43e39STony Lindgren .word OMAP2420_CM_REGADDR(PLL_MOD, CM_IDLEST) 309c2d43e39STony Lindgrenomap242x_ssp_pll_div: 310c2d43e39STony Lindgren .word OMAP2420_CM_REGADDR(PLL_MOD, CM_CLKSEL1) 311c2d43e39STony Lindgrenomap242x_ssp_sdrc_rfr: 312373a6702STony Lindgren .word OMAP242X_SDRC_REGADDR(SDRC_RFR_CTRL_0) 313c2d43e39STony Lindgrenomap242x_ssp_dlla_ctrl: 314373a6702STony Lindgren .word OMAP242X_SDRC_REGADDR(SDRC_DLLA_CTRL) 315373a6702STony Lindgren 316c2d43e39STony LindgrenENTRY(omap242x_sram_set_prcm_sz) 317c2d43e39STony Lindgren .word . - omap242x_sram_set_prcm 318